【转帖LINUX】IP分片重组分析
本文档的Copyleft归yfydz所有,使用GPL发布,可以自由拷贝,转载,转载时请保持文档的完整性,严禁用于任何商业用途。
msn: yfydz_no1@hotmail.com
来源:http://yfydz.cublog.cn
1. 前言
对IP碎片的重组是防火墙提高安全性的一个重要手段,通过提前进行碎片重组,可以有效防御各种碎片攻击,Linux内核的防火墙netfilter就自动对IP碎片包进行了重组,本文介绍Linux内核中的IP重组过程,内核代码版本2.4.26。
2. 处理流程
实现IP重组的基本函数为ip_defrag(),在net/ipv4/ip_fragment.c中实现,基本过程是建立碎片处理队列,队列中每个节点是一个链表,这个链表保存同一个连接的碎片,当碎片都到达之后进行数据包重组,或者在一定时间(缺省30秒)内所有碎片包不能到达而释放掉。
2.1 数据结构
在处理分片包时,将skb包的cb字段保存碎片控制信息struct ipfrag_skb_cb。
#define FRAG_CB(skb) ((struct ipfrag_skb_cb*)((skb)->cb))
struct ipfrag_skb_cb
{
struct inet_skb_parm h;
int offset;
};
ipq队列节点结构:
/* Describe an entry in the "incomplete datagrams" queue. */
struct ipq {
// 下一个
struct ipq *next; /* linked list pointers */
// 最新使用链表
struct list_head lru_list; /* lru list member */
// 以下4项用来匹配一组IP分配
u32 saddr;
u32 daddr;
u16 id;
u8 protocol;
// 状态标志
u8 last_in;
#define COMPLETE 4 // 数据已经完整
#define FIRST_IN 2 // 第一个包到达
#define LAST_IN 1 // 最后一个包到达
// 接收到的IP碎片链表
struct sk_buff *fragments; /* linked list of received fragments */
// len是根据最新IP碎片中的偏移信息得出的数据总长
int len; /* total length of original datagram */
// meat是所有碎片实际长度的累加
int meat;
spinlock_t lock;
atomic_t refcnt;
// 超时
struct timer_list timer; /* when will this queue expire? */
// 前一项队列地址
struct ipq **pprev;
// 数据进入网卡的索引号
&
相关文档:
1. LinuxCommand
LinuxCommand是一个学习Linux命令行最好的网站之一。网站分为:学习Shell、写Shell脚本、脚本库、超级MAN页面。
http://linuxcommand.org/
2. O’Reilly的Linux命令指南目录
O’Reilly的Linux命令指南目录是一个极好的快速参考指南,列出了大 ......
指令名称 : chmod
使用权限 : 所有使用者
使用方式 : chmod [-cfvR] [--help] [--version] mode file...
说明 : Linux/Unix 的档案调用权限分为三级 : 档案拥有者、群组、其他。利用 chmod 可以藉以控制档案如何被他人所调用。
参数 :
mode : 权限设定字串,格式如下 : [ugoa...][[+-=][rwxX]...][,...],其中
......
建立ARM+Linux应用程序调试环境
Gdb+gdbserver+insight环境的搭建
1. 下载gdb源代码 http://ftp.gnu.org/gnu/gdb/
2. 配置安装gdb+gdbser
$ tar jxvf gdb-6.6.tar.bz2
$ cd x/gdb
$ ./configure --target=arm-linux --prefix=/usr/lo ......
4. Threads
To use the POSIX standard thread API (pthreads), link libpthread.so
to your program.
4.1. Thread Creation
Each thread in a process is identified by a thread ID,
pthread_t.
The pthread_self function returns the thread ID of the current
thread.
This thread IDs can be compared ......
6. Devices
A device driver hides the hardware device’s communication
protocols from the operating system and allows the system to interact with the
device through a standardized interface.
Processes can communicate with a device driver via
file-like objects.
6.1 Device Types
A c ......