diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2012-08-20 18:57:05 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2012-08-20 18:57:05 +0200 |
commit | 3fb998d5e2d077d85b39c3d2e5b2c828f5db9522 (patch) | |
tree | 1902766ffc8d802fddef94aa7bbd4ec66bc8e758 /src/extra/pktbuff.c | |
parent | ffa83b5968b534f679bc34acc506801db3d28d58 (diff) |
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 <pablo@netfilter.org>
Diffstat (limited to 'src/extra/pktbuff.c')
-rw-r--r-- | src/extra/pktbuff.c | 12 |
1 files changed, 9 insertions, 3 deletions
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; |