linux TCP/IP协议栈 ---ip_find()

2238阅读 0评论2012-05-22 PCliangtao
分类:LINUX


点击(此处)折叠或打开

  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. }

上一篇:linux TCP/IP协议栈 ---ip_defrag()
下一篇:linux TCP/IP协议栈 ---inet_frag_find()