点击(此处)折叠或打开
- /* Find the correct entry in the "incomplete datagrams" queue for
- * this IP datagram, and create new one, if nothing is found.
- */
- /* u32 user这个参数有点迷惑,其表示以何种理由需要对数据包进行重组,在ip_local_deliver的调用序列当中,这个值是IP_DEFRAG_LOCAL_DELIVER。*/
- static inline struct ipq *ip_find(struct iphdr *iph, u32 user)
- {
- struct inet_frag_queue *q;
- struct ip4_create_arg arg;
- unsigned int hash;
- arg.iph = iph;
- arg.user = user;
- /*
- * hash算法,该算法除了使用所给的这四个参数之外,还使用了一个随机值
- * ip4_frags.rnd,,其初始化为
- * (u32) ((num_physpages ^ (num_physpages>>7)) ^ (jiffies ^ (jiffies >> 6)));
- * 这是为了防止黑客根据固定的hash算法,通过设置ip头部的这些字段,生成同样
- * HASH值,从而使某一HASH队列长度急剧增大而影响性能。
- */
- hash = ipqhashfn(iph->id, iph->saddr, iph->daddr, iph->protocol);
- /* 若存在该分片所属的分片队列则返回这个队列,否则创建一个新的队列 */
- q = inet_frag_find(&ip4_frags, &arg, hash);
- if (q == NULL)
- goto out_nomem;
- return container_of(q, struct ipq, q);
- out_nomem:
- LIMIT_NETDEBUG(KERN_ERR "ip_frag_create: no memory left !\n");
- return NULL;
- }