extra: pktbuff: pktb_expand_tail return 0 if there is no room in the tail
authorPablo Neira Ayuso <pablo@netfilter.org>
Mon, 20 Aug 2012 16:57:05 +0000 (18:57 +0200)
committerr.kubiak <r.kubiak@samsung.com>
Mon, 16 Nov 2015 13:12:06 +0000 (14:12 +0100)
pktb_expand_tail returns 0 if there is no room for the mangling.
Note that we don't support dynamic reallocation, instead the
caller is responsible for allocating the extra room via pktb_alloc
according to the maximum amount of bytes it needs for the mangling.

Since pkt_buff layout is not exposed, we can change this in the
future if we prefer dynamic reallocation.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/extra/pktbuff.c

index e9ca5da2315b59784eed081d26a32bb425078ce6..af2e7a65f3b7e00b670fe613681cbd4a73db968f 100644 (file)
@@ -140,10 +140,16 @@ uint8_t *pktb_transport_header(struct pkt_buff *pktb)
 
 static int pktb_expand_tail(struct pkt_buff *pkt, int extra)
 {
-       /* XXX: support reallocation case. */
+       /* No room in packet, cannot mangle it. We don't support dynamic
+        * reallocation. Instead, increase the size of the extra room in
+        * the tail in pktb_alloc.
+        */
+       if (pkt->len + extra > pkt->data_len)
+               return 0;
+
        pkt->len += extra;
        pkt->tail = pkt->tail + extra;
-       return 0;
+       return 1;
 }
 
 static int enlarge_pkt(struct pkt_buff *pkt, unsigned int extra)
@@ -151,7 +157,7 @@ static int enlarge_pkt(struct pkt_buff *pkt, unsigned int extra)
        if (pkt->len + extra > 65535)
                return 0;
 
-       if (pktb_expand_tail(pkt, extra - pktb_tailroom(pkt)))
+       if (!pktb_expand_tail(pkt, extra - pktb_tailroom(pkt)))
                return 0;
 
        return 1;