Chinaunix首页 | 论坛 | 博客
  • 博客访问: 795128
  • 博文数量: 264
  • 博客积分: 592
  • 博客等级: 中士
  • 技术积分: 1574
  • 用 户 组: 普通用户
  • 注册时间: 2011-10-24 22:02
文章分类

全部博文(264)

文章存档

2019年(2)

2018年(1)

2017年(1)

2016年(4)

2015年(14)

2014年(57)

2013年(88)

2012年(97)

分类: LINUX

2014-02-12 15:47:40

转:http://blog.csdn.net/nerdx/article/details/12613029
  1. //more = skb_shinfo(skb)->tso_segs,由tcp传递  
  2. 1.1 static inline void ip_select_ident_more(struct iphdr *iph, struct dst_entry *dst, struct sock *sk, int more)  
  3. {  
  4.     if (iph->frag_off & htons(IP_DF)) {//禁止分片  
  5.         if (sk && inet_sk(sk)->daddr) {  
  6.             iph->id = htons(inet_sk(sk)->id);//使用sock中指定的id  
  7.             inet_sk(sk)->id += 1 + more;//sock中id递增  
  8.         } else  
  9.             iph->id = 0;  
  10.     } else  
  11.         __ip_select_ident(iph, dst, more);//可分片ip报文选择id  
  12. }  
  13. //调用路径ip_select_ident_more->__ip_select_ident  
  14. //函数主要任务:  
  15. //  1.处理路由项与inet_peer的绑定  
  16. //  2.通过inet_peer,或者全局ip_fallback_id获取id  
  17. 1.2 void __ip_select_ident(struct iphdr *iph, struct dst_entry *dst, int more)  
  18. {  
  19.     struct rtable *rt = (struct rtable *) dst;  
  20.   
  21.     if (rt) {//存在到目的地址的路由  
  22.         if (rt->peer == NULL)//inet_peer结构,表示该缓存路由项的目的ip地址对应的主机  
  23.             rt_bind_peer(rt, 1);//寻找和该端点相匹配的inet_peer结构,如果不存在,尝试创建一个新的inet_peer  
  24.   
  25.         if (rt->peer) {//通过inet_peer的计数器,生成与接收方相关的递增id  
  26.             iph->id = htons(inet_getid(rt->peer, more));  
  27.             return;  
  28.         }  
  29.     } else  
  30.         printk(KERN_DEBUG "rt_bind_peer(0) @%p\n"NET_CALLER(iph));  
  31.     //之前尝试都失败,通过一个静态变量ip_fallback_id,再和端点的目的地ip地址结合,通过secure_ip_id获取id  
  32.     ip_select_fb_ident(iph);  
  33. }  
  34.   
  35. //调用路径ip_select_ident_more->__ip_select_ident->inet_getid  
  36. 1.3 static inline __u16 inet_getid(struct inet_peer *p, int more)  
  37. {  
  38.     __u16 id;  
  39.   
  40.     spin_lock_bh(&inet_peer_idlock);//获取一个全局的锁  
  41.     id = p->ip_id_count;  
  42.     p->ip_id_count += 1 + more;//更新inet_peer中的id计数器  
  43.     spin_unlock_bh(&inet_peer_idlock);  
  44.     return id;  
  45. }  
阅读(524) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~