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等协议 ......
linux命令行下中文文件名乱码的解决方法
首先查询支持的编码:
locale -a
如果没有你需要的编码,例如zh_CN.utf8
root运行: #dpkg-reconfigure locales
选择你需要的编码,用空格选中,可多选。tab选择“OK”,回车。
默认编码选择zh_CN.utf8
安装你所需要的编码。
修改/etc/profile,
注释掉
export LC ......
硬件技术一直和软件技术相依相随,随着服务器硬件和芯片技术的进步,推动着服务器操作系统技术的变革。
芯片技术的发展:从x86到龙芯
2009年,各大芯片厂商都推出了多款芯片产品:如Intel公司基于Nehalem架构发布的桌面端芯片产品酷睿i7;AMD公司也推出了基
于新Fiorano平台的代号为“伊斯坦布尔”的六 ......
1.可执行程序
os.system('pgrep %s > %s' % (process, output))
pidfile = open("output", 'r')
totalpid = len(pidfile.readlines())
pidfile.close()
if totalpid == 0 :
&nbs ......
应用层:
#include <unistd.h>
1、unsigned int sleep(unsigned int seconds); 秒级
2、int usleep(useconds_t usec); 微秒级:1/10^-6
#define _PO ......