Linux netfilter源码分析(2)
转贴自http://alexanderlaw.blog.hexun.com/8968771_d.html
二、ipt_table数据结构和表的初始化
2.1 include/linux/netfilter_ipv4/ip_tables.h struct ipt_table 表结构
struct ipt_table
{
struct list_head list;
/* 表链 */
char name[IPT_TABLE_MAXNAMELEN];
/* 表名,如"filter"、"nat"等,为了满足自动模块加载的设计,包含该表的模块应命名为iptable_'name'.o */
struct ipt_replace *table;
/* 表模子,初始为initial_table.repl */
unsigned int valid_hooks;
/* 位向量,标示本表所影响的HOOK */
rwlock_t lock;
/* 读写锁,初始为打开状态 */
struct ipt_table_info *private;
/* iptable的数据区,见下 */
struct module *me;
/* 是否在模块中定义 */
};
2.2 struct ipt_table_info是实际描述表的数据结构 ip_tables.c
struct ipt_table_info
{
unsigned int size;
/* 表大小 */
unsigned int number;
/* 表中的规则数 */
unsigned int initial_entries;
/* 初始的规则数,用于模块计数 */
unsigned int hook_entry[NF_IP_NUMHOOKS];
/* 记录所影响的HOOK的规则入口相对于下面的entries变量的偏移量 */
unsigned int underflow[NF_IP_NUMHOOKS];
/* 与hook_entry相对应的规则表上限偏移量,当无规则录入时,相应的hook_entry和underflow均为0 */
char entries[0] ____cacheline_aligned;
/* 规则表入口 */
};
2.3 include/linux/netfilter_ipv4 规则用struct ipt_entry结构表示,包含匹配用的IP头部分、一个Target和0个或多个Match。由于Match数不定,所以一条规则实际的占用空间是可变的。结构定义如下
struct ipt_entry
{
struct ipt_ip ip;
/* 所要匹配的报文的IP头信息 */
unsigned int nfcache;
/* 位向量,标示本规则关心报文的什么部分,暂未使用 */
u_int16_t target_offset;
/* target区的偏移,通常target区位于match区之后,而match区则在ipt_entry的末尾;
初始化为sizeof(struct ipt_entry),即假定没有match */
u_int16_t next_offset;
/* 下一条规则相对于本规则的偏移,也即本规则所用空间的总和,
初始化为sizeof(struct ipt_entry)+sizeof(struct ipt_target),即没有match */
unsigned int comefrom;
/* 规则返回点,标记调用本规则的HOOK号,可用于检查规则的
相关文档:
1. HCI层协议概述:
HCI提供一套统一的方法来访问Bluetooth底层。如图所示:
从图上可以看出,Host Controller Interface(HCI) 就是用来沟通Host和Module。Host通常就是PC, Module则是以各种物理连接形式(USB,serial,pc-card等)连接到PC上的bluetooth Dongle。
在Host这一端:application,SDP,L2cap等协议 ......
一:前言
最近在研究android的sensor driver,主要是E-compass,其中用到了Linux input子系统.在网上也看了很多这方面的资料,感觉还是这篇分析的比较细致透彻,因此转载一下以便自己学习,同时和大家分享!
(这篇博客主要是以键盘驱动为例的,不过讲解的是Linux Input Subsystem,可以仔细的研究一下!)
键盘驱动将检 ......
A 加后缀
1.问题:同以目录下有海量以日期命名的文件,其中有的有后缀,有的以点结尾,如20020101.,20020102.,……,20020101.td,20020102.td……
要求: 把所有以点结尾的加上后缀.ts
我的方法:
#!/bin/bash
for files in `ls *.`
do
mv $files `echo “$filests” `
done ......
linux下有专门的文件系统用来对设备进行管理,devfs和sysfs就是其中两种。
1,devfs:devfs是在2.4内核就出现了,它是用来解决linux中设备管理混乱的问题,linux内核开发人员开发了devfs。
2,sysfs:是Linux 内核中设计较新的一种虚拟的基于内存的文件系统,它的作用与proc 有些类似,但 ......
转贴自:http://alexanderlaw.blog.hexun.com/8960896_d.html
Linux netfilter源码分析(1)
内容基本上来自两篇文章:
《Netfilter源码分析》—(独孤九贱http://www.skynet.org.cn/index.php)
《Linux Netfilter实现机制和扩展技术》——(杨沙洲 国防科技大学计算机学院)
一、 IP报文的接 ......