点击(此处)折叠或打开
- /* Process an incoming IP datagram fragment. */
- int ip_defrag(struct sk_buff *skb, u32 user)
- {
- struct ipq *qp;
- IP_INC_STATS_BH(IPSTATS_MIB_REASMREQDS);
- /* Start by cleaning up the memory. */
- /*
- * 首先检查所有IP分片所消耗的内存是否大于系统允许的最高阀值,如果是,则调用
- * ip_evictor()丢弃未完全到达的IP分片,从最旧的分片开始释放。此举一来是为了节
- * 约内存,二来是未了防止黑客的恶意攻击。使分片在系统中累计,降低系统性能。
- */
- if (atomic_read(&ip4_frags.mem) > ip4_frags_ctl.high_thresh)
- ip_evictor();
- /* Lookup (or create) queue header */
- /* 如果该分片是数据报的第一个分片,则ip_find返回一个新的队列来搜集分片,否则
- * 返回其所属于的分片队列。 */
- if ((qp = ip_find(ip_hdr(skb), user)) != NULL) {
- int ret;
- spin_lock(&qp->q.lock);
- /* 将该分片加入到队列中,重组分片队列,如果所有的包都收到了,则该函数
- * 负责重组IP包 */
- ret = ip_frag_queue(qp, skb);
- spin_unlock(&qp->q.lock);
- ipq_put(qp); /* 引用计数减1 */
- return ret;
- }
- IP_INC_STATS_BH(IPSTATS_MIB_REASMFAILS);
- kfree_skb(skb);
- return -ENOMEM;
- }