From 3fb998d5e2d077d85b39c3d2e5b2c828f5db9522 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Mon, 20 Aug 2012 18:57:05 +0200 Subject: extra: pktbuff: pktb_expand_tail return 0 if there is no room in the tail 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 --- src/extra/pktbuff.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/extra') diff --git a/src/extra/pktbuff.c b/src/extra/pktbuff.c index e9ca5da..af2e7a6 100644 --- a/src/extra/pktbuff.c +++ b/src/extra/pktbuff.c @@ -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; -- cgit v1.2.3