Chinaunix首页 | 论坛 | 博客
  • 博客访问: 370203
  • 博文数量: 56
  • 博客积分: 1449
  • 博客等级: 中尉
  • 技术积分: 822
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-08 10:24
文章分类

全部博文(56)

文章存档

2014年(7)

2012年(13)

2011年(10)

2010年(26)

分类: LINUX

2012-05-22 19:10:12


点击(此处)折叠或打开

  1. /* Find the correct entry in the "incomplete datagrams" queue for
  2.  * this IP datagram, and create new one, if nothing is found.
  3.  */
  4. /* u32 user这个参数有点迷惑,其表示以何种理由需要对数据包进行重组,在ip_local_deliver的调用序列当中,这个值是IP_DEFRAG_LOCAL_DELIVER。*/
  5. static inline struct ipq *ip_find(struct iphdr *iph, u32 user)
  6. {
  7.     struct inet_frag_queue *q;
  8.     struct ip4_create_arg arg;
  9.     unsigned int hash;

  10.     arg.iph = iph;
  11.     arg.user = user;
  12.     /*
  13.      * hash算法,该算法除了使用所给的这四个参数之外,还使用了一个随机值
  14.      * ip4_frags.rnd,,其初始化为
  15.      * (u32) ((num_physpages ^ (num_physpages>>7)) ^ (jiffies ^ (jiffies >> 6)));
  16.      * 这是为了防止黑客根据固定的hash算法,通过设置ip头部的这些字段,生成同样
  17.      * HASH值,从而使某一HASH队列长度急剧增大而影响性能。
  18.      */
  19.     hash = ipqhashfn(iph->id, iph->saddr, iph->daddr, iph->protocol);
  20.     /* 若存在该分片所属的分片队列则返回这个队列,否则创建一个新的队列 */
  21.     q = inet_frag_find(&ip4_frags, &arg, hash);
  22.     if (q == NULL)
  23.         goto out_nomem;

  24.     return container_of(q, struct ipq, q);

  25. out_nomem:
  26.     LIMIT_NETDEBUG(KERN_ERR "ip_frag_create: no memory left !\n");
  27.     return NULL;
  28. }

阅读(2081) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~