//为分片确定正确的ipq结构
// 定位5元组
// 1.<id, 源ip, 目的ip, l4协议> 可通过ip报文获取
// 2.user 通过ip_defrag给出,指出重组是由谁发起的,最常见的时IP_DEFRAG_LOCAL_DELIVER,当重组的入口分包要传递给本地时
// ipq中所有分片最迟完成重组的时间为30HZ
1.1 static inline struct ipq *ip_find(struct iphdr *iph, u32 user)
{
//定位4元组
__u16 id = iph->id;
__u32 saddr = iph->saddr;
__u32 daddr = iph->daddr;
__u8 protocol = iph->protocol;
//对4元组进行hash
unsigned int hash = ipqhashfn(id, saddr, daddr, protocol);
struct ipq *qp; read_lock(&ipfrag_lock);
//选择正确的bucket
for(qp = ipq_hash[hash]; qp; qp = qp->next) {
if(qp->id == id &&
qp->saddr == saddr &&
qp->daddr == daddr &&
qp->protocol == protocol &&
qp->user == user) {
atomic_inc(&qp->refcnt);//递增ipq的引用计数,当skb被添加到frags链表之后,会通过ipq_put递减该计数
read_unlock(&ipfrag_lock);
return qp;
}
}
read_unlock(&ipfrag_lock);
//该4元组的第一个分片,创建新的ipq
return ip_frag_create(hash, iph, user);
} //调用路径:ip_find->ip_frag_create
// 新ip分片到达时,根据4元组创建一个ipq
1.2 static struct ipq *ip_frag_create(unsigned hash, struct iphdr *iph, u32 user)
{
struct ipq *qp; if ((qp = frag_alloc_queue()) == NULL)//SLAB缓存
goto out_nomem;
//5元组
qp->protocol = iph->protocol;
qp->last_in = 0;
qp->id = iph->id;
qp->saddr = iph->saddr;
qp->daddr = iph->daddr;
//重组的发起者
qp->user = user;
//新ipq还没有任何分片与之关联
qp->len = 0;
qp->meat = 0;
qp->fragments = NULL;
qp->iif = 0;//入口设备 init_timer(&qp->timer);//定时器,当一定时间范围内,重组没有完成,则释放与之关联的内存
qp->timer.data = (unsigned long) qp;
qp->timer.function = ip_expire;
spin_lock_init(&qp->lock);
atomic_set(&qp->refcnt, 1); return ip_frag_intern(hash, qp);//将ipq插入到hash表中 out_nomem:
NETDEBUG(if (net_ratelimit()) printk(KERN_ERR "ip_frag_create: no memory left !\n"));
return NULL;
} //调用路径:ip_frag_create->ip_frag_intern
// 将ipq插入到hash表中
1.3 static struct ipq *ip_frag_intern(unsigned int hash, struct ipq *qp_in)
{
struct ipq *qp; write_lock(&ipfrag_lock); qp = qp_in;
//sysctl_ipfrag_time = 30HZ
if (!mod_timer(&qp->timer, jiffies + sysctl_ipfrag_time))//对一个不活跃的定时器修改到期时间
atomic_inc(&qp->refcnt);//增加引用计数,表示定时器对其的引用 atomic_inc(&qp->refcnt);//增加引用计数,表示hash表对其的引用
if((qp->next = ipq_hash[hash]) != NULL)
qp->next->pprev = &qp->next;
ipq_hash[hash] = qp;//将ipq插入到hash表中
qp->pprev = &ipq_hash[hash];
INIT_LIST_HEAD(&qp->lru_list);//将新加入的ipq加入到lru尾
list_add_tail(&qp->lru_list, &ipq_lru_list);
ip_frag_nqueues++;
write_unlock(&ipfrag_lock);
return qp;
} //ipq中所有分片的到期时间
//接收到的ip分片不能永久的存在内存中,如果在一定时间范围内,没有为其完成重组,则需要释放所有分片占用的内存
// 1.删除定时器
// 2.从hash表中unlink
// 3.使用分片的入口设备向发送方发送icmp消息,告诉对方过期
// 4.释放ipq中的所有分片,释放ipq结构
1.4 static void ip_expire(unsigned long arg)
{
struct ipq *qp = (struct ipq *) arg; spin_lock(&qp->lock); if (qp->last_in & COMPLETE)
goto out;
//删除定时器,从ipq hash表中unlink
ipq_kill(qp); if ((qp->last_in&FIRST_IN) && qp->fragments != NULL) {
struct sk_buff *head = qp->fragments;
if ((head->dev = dev_get_by_index(qp->iif)) != NULL) {
icmp_send(head, ICMP_TIME_EXCEEDED, ICMP_EXC_FRAGTIME, 0);//发送ICMP消息
dev_put(head->dev);
}
}
out:
spin_unlock(&qp->lock);
ipq_put(qp, NULL);//释放与ipq关联的所有分片,释放ipq结构
}

网络子系统54_ip协议分片重组_定位ipq的更多相关文章

  1. 网络子系统55_ip协议分片重组_加入ipq

    //ip分片加入到正确的ipq结构 //调用路径:ip_defrag->ip_frag_queue // 处理过程: // 1.正在被释放的ipq,不处理新加入的分片(ipq正在被释放由last ...

  2. 网络子系统53_ip协议分片重组_内存阈值

    //调用路径:ip_defrag->ip_evictor // 分片重组时,可使用内存上下限: // 1.sysctl_ipfrag_high_thresh 可用内存上限 // 2.sysctl ...

  3. 网络子系统42_ip协议处理函数_数据帧的接收

    //向协议栈注册l3处理函数 1.1 void dev_add_pack(struct packet_type *pt) { int hash; //ptype_all ptype_base共用一把锁 ...

  4. 网络子系统48_ip协议数据帧的发送

    //ip协议与l4协议接口,l4通过此接口向下l3传递数据帧 //函数主要任务: // 1.通过路由子系统路由封包 // 2.填充l3报头 // 3.ip分片 // 4.计算校验和 // 5.衔接邻居 ...

  5. 网络子系统45_ip协议tos处理

    //ip报头tos字段,一个字节 // 二进制位:[0 1 2] [3] [4] [5] [6] [7] // 1.[0 1 2] 表示优先级: // 000 路由 // 001 优先级 // 010 ...

  6. 网络子系统46_ip协议数据帧的转发

    //调用路径ip_rcv->ip_rcv_finish->dst_input->(skb->dst->input) //ip_forward以回调函数的形式,保存在skb ...

  7. Linux 网络子系统之网络协议接口层(一)

    Linux 网络设备驱动之网络协议接口层介绍. 网络协议接口层最主要的功能是给上层协议提供透明的数据包发送和接收接口. 当上层ARP或IP需要发送数据包时,它将调用网络协议接口层的dev_queue_ ...

  8. Linux内核笔记--网络子系统初探

    内核版本:linux-2.6.11 本文对Linux网络子系统的收发包的流程进行一个大致梳理,以流水账的形式记录从应用层write一个socket开始到这些数据被应用层read出来的这个过程中linu ...

  9. IP分片重组的分析和常见碎片攻击 v0.2

    IP分片重组的分析和常见碎片攻击 v0.2http://www.nsfocus.net/index.php?act=magazine&do=view&mid=584 作者:yawl ( ...

随机推荐

  1. Android百度地图

        帖子   热搜: 二维码 聊天 二维码扫描 传感器 游戏 定位 手势绘图 小项目 相框 绘图 涂鸦 拨打电话 记事本 定时器 通话记录 短信群发 listview 音乐播放器 项目例子 百度地 ...

  2. jquery 滚动条插件 jquery.nanoscroller.js

    $(".listcontent .nano").nanoScroller();   $(".chatcontent .nano").nanoScroller({ ...

  3. [转:CSS3-前端] CSS3发光和多种图片处理

    原文链接:http://www.qianduan.net/css3-image-styles.html 一些上流的CSS3图片样式 神飞 发表于 24. Sep, 2011, 分类: CSS , 46 ...

  4. RTP协议分析

      目录(?)[-] 第1章     RTP概述 RTP是什么 RTP的应用环境 相关概念 流媒体 第2章     RTP详解 RTP的协议层次 传输层的子层 应用层的一部分 RTP的封装 RTCP的 ...

  5. <摘录>PS和TS流的区别

    在 MPEG-2系统中,信息复合/分离的过程称为系统复接/分接,由视频,音频的ES流和辅助数据复接生成的用于实际传输的标准信息流称为MPEG-2传送 流(TS:TransportStream).据传输 ...

  6. cimge 这次能够图片大小尺寸

    CImage imSrc,imDest;imSrc.Load(……);//读入原始图片imDest.Create(……)//创建新大小的图片imSrc.StretchBlt(imDest.GetDC( ...

  7. WAPI

    中国制定的WLAN安全标准WAPI 针对WLAN安全问题,中国制定了自己的WLAN安全标准:WAPI. 与其他无线局域网安全机制(如802.11i)相比,WAPI主要的差别体现在以下几个方面: • 双 ...

  8. memcache 分布式,算法实现

    memcached 虽然称为 “ 分布式 ” 缓存服务器,但服务器端并没有 “ 分布式 ” 功能.每个服务器都是完全独立和隔离的服务. memcached 的分布式,则是完全由客户端程序库实现的. 这 ...

  9. 【LeetCode 201】Bitwise AND of Numbers Range

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

  10. [原创]cocos2d-x + Lua接入iOS原生SDK的实现方案

    相信很多朋友在使用cocos2d-x+lua开发游戏时都遇到过接入iOS原生SDK的问题,比如常见的接应用内支付SDK,广告SDK或是一些社交平台SDK等等,我也没少接过这类SDK.这篇文章主要是对我 ...