Merge tag 'rdma-for-3.5' of git://git.kernel.org/pub/scm/linux/kernel/git/roland...
[firefly-linux-kernel-4.4.55.git] / net / ipv4 / ip_fragment.c
index 9f9bd139335f42fb881f613da04fbe1c5a1049c8..9dbd3dd6022d40f2f9fdbfa0e3a433a33963c886 100644 (file)
@@ -148,17 +148,17 @@ static unsigned int ip4_hashfn(struct inet_frag_queue *q)
        return ipqhashfn(ipq->id, ipq->saddr, ipq->daddr, ipq->protocol);
 }
 
-static int ip4_frag_match(struct inet_frag_queue *q, void *a)
+static bool ip4_frag_match(struct inet_frag_queue *q, void *a)
 {
        struct ipq *qp;
        struct ip4_create_arg *arg = a;
 
        qp = container_of(q, struct ipq, q);
        return  qp->id == arg->iph->id &&
-                       qp->saddr == arg->iph->saddr &&
-                       qp->daddr == arg->iph->daddr &&
-                       qp->protocol == arg->iph->protocol &&
-                       qp->user == arg->user;
+               qp->saddr == arg->iph->saddr &&
+               qp->daddr == arg->iph->daddr &&
+               qp->protocol == arg->iph->protocol &&
+               qp->user == arg->user;
 }
 
 /* Memory Tracking Functions. */
@@ -545,6 +545,7 @@ static int ip_frag_reasm(struct ipq *qp, struct sk_buff *prev,
        int len;
        int ihlen;
        int err;
+       int sum_truesize;
        u8 ecn;
 
        ipq_kill(qp);
@@ -611,19 +612,32 @@ static int ip_frag_reasm(struct ipq *qp, struct sk_buff *prev,
                atomic_add(clone->truesize, &qp->q.net->mem);
        }
 
-       skb_shinfo(head)->frag_list = head->next;
        skb_push(head, head->data - skb_network_header(head));
 
-       for (fp=head->next; fp; fp = fp->next) {
-               head->data_len += fp->len;
-               head->len += fp->len;
+       sum_truesize = head->truesize;
+       for (fp = head->next; fp;) {
+               bool headstolen;
+               int delta;
+               struct sk_buff *next = fp->next;
+
+               sum_truesize += fp->truesize;
                if (head->ip_summed != fp->ip_summed)
                        head->ip_summed = CHECKSUM_NONE;
                else if (head->ip_summed == CHECKSUM_COMPLETE)
                        head->csum = csum_add(head->csum, fp->csum);
-               head->truesize += fp->truesize;
+
+               if (skb_try_coalesce(head, fp, &headstolen, &delta)) {
+                       kfree_skb_partial(fp, headstolen);
+               } else {
+                       if (!skb_shinfo(head)->frag_list)
+                               skb_shinfo(head)->frag_list = fp;
+                       head->data_len += fp->len;
+                       head->len += fp->len;
+                       head->truesize += fp->truesize;
+               }
+               fp = next;
        }
-       atomic_sub(head->truesize, &qp->q.net->mem);
+       atomic_sub(sum_truesize, &qp->q.net->mem);
 
        head->next = NULL;
        head->dev = dev;