Signed-off-by: Duncan Roe <duncan_roe@xxxxxxxxxxxxxxx> --- fixmanpages.sh | 2 +- include/libnetfilter_queue/pktbuff.h | 4 +++- src/extra/pktbuff.c | 37 ++++++++++++++++++------------------ src/nlmsg.c | 2 +- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/fixmanpages.sh b/fixmanpages.sh index 86f902b..851e334 100755 --- a/fixmanpages.sh +++ b/fixmanpages.sh @@ -31,7 +31,7 @@ function main add2group nfq_nlmsg_verdict_put_mark nfq_nlmsg_verdict_put_pkt setgroup nlmsg nfq_nlmsg_parse add2group nfq_nlmsg_put - setgroup pktbuff pktb_alloc2 + setgroup pktbuff pktb_setup add2group pktb_data pktb_len pktb_mangle pktb_mangled pktb_head_size setgroup otherfns pktb_tailroom add2group pktb_mac_header pktb_network_header pktb_transport_header diff --git a/include/libnetfilter_queue/pktbuff.h b/include/libnetfilter_queue/pktbuff.h index fd0a3f3..a7a8f8f 100644 --- a/include/libnetfilter_queue/pktbuff.h +++ b/include/libnetfilter_queue/pktbuff.h @@ -4,10 +4,12 @@ struct pkt_buff; struct pkt_buff *pktb_alloc(int family, void *data, size_t len, size_t extra); -struct pkt_buff *pktb_alloc2(int family, void *buf, size_t buflen, void *data, size_t len); void pktb_free(struct pkt_buff *pktb); #define NFQ_BUFFER_SIZE (0xffff + (MNL_SOCKET_BUFFER_SIZE / 2) +struct pkt_buff *pktb_setup(int family, void *buf, size_t buflen, void *data, size_t len); + +#define pktb_head_alloc() (struct pkt_buff *)(malloc(pktb_head_size())) uint8_t *pktb_data(struct pkt_buff *pktb); uint32_t pktb_len(struct pkt_buff *pktb); diff --git a/src/extra/pktbuff.c b/src/extra/pktbuff.c index cc8ad13..a0cb3c7 100644 --- a/src/extra/pktbuff.c +++ b/src/extra/pktbuff.c @@ -31,18 +31,17 @@ * @{ */ -static int pktb_setup_family(struct pkt_buff *pktb, int family) +static int __pktb_setup(int family, struct pkt_buff *pktb) { struct ethhdr *ethhdr; - switch(family) { + switch (family) { case AF_INET: case AF_INET6: pktb->network_header = pktb->data; break; case AF_BRIDGE: ethhdr = (struct ethhdr *)pktb->data; - pktb->mac_header = pktb->data; switch(ethhdr->h_proto) { @@ -92,7 +91,7 @@ static void pktb_setup_metadata(struct pkt_buff *pktb, void *pkt_data, * \n * __EPROTONOSUPPORT__ _family_ was __AF_BRIDGE__ and this is not an IP packet * (v4 or v6) - * \note __pktb_alloc__ is deprecated. Use pktb_alloc2() in new code + * \note __pktb_alloc__ is deprecated. Use pktb_setup() in new code * \sa __calloc__(3) */ EXPORT_SYMBOL @@ -112,7 +111,7 @@ struct pkt_buff *pktb_alloc(int family, void *data, size_t len, size_t extra) pktb_setup_metadata(pktb, pkt_data, len, extra); - if (pktb_setup_family(pktb, family) < 0) { + if (__pktb_setup(family, pktb) < 0) { free(pktb); return NULL; } @@ -125,7 +124,17 @@ struct pkt_buff *pktb_alloc(int family, void *data, size_t len, size_t extra) */ /** - * pktb_alloc2 - make a packet buffer from an existing buffer + * pktb_head_size - get size of struct pkt_buff + * \return Size of (opaque) __struct pkt_buff__ + */ +EXPORT_SYMBOL +size_t pktb_head_size(void) +{ + return sizeof(struct pkt_buff); +} + +/** + * pktb_setup - make a packet buffer from an existing buffer * \param family Indicate what family. Currently supported families are * AF_BRIDGE, AF_INET & AF_INET6. * \param buf Buffer to hold packet metadata, and packet contents _if_ @@ -176,7 +185,7 @@ static char buf[NFQ_BUFFER_SIZE]; * \sa nfq_nlmsg_verdict_put_pkt() (has sample code using __pktb_alloc2__) */ EXPORT_SYMBOL -struct pkt_buff *pktb_alloc2(int family, void *buf, size_t buflen, +struct pkt_buff *pktb_setup(int family, void *buf, size_t buflen, void *data, size_t len) { struct pkt_buff *pktb; @@ -194,7 +203,7 @@ struct pkt_buff *pktb_alloc2(int family, void *buf, size_t buflen, pktb_setup_metadata(pktb, pkt_data, len, 0); pktb->buf_len = buflen; - if (pktb_setup_family(pktb, family) < 0) + if (__pktb_setup(family, pktb) < 0) pktb = NULL; return pktb; } @@ -231,16 +240,6 @@ uint32_t pktb_len(struct pkt_buff *pktb) return pktb->len; } -/** - * pktb_head_size - get size of struct pkt_buff - * \return Size of (opaque) __struct pkt_buff__ - */ -EXPORT_SYMBOL -size_t pktb_head_size(void) -{ - return sizeof(struct pkt_buff); -} - /** * \defgroup otherfns Other functions * @@ -261,7 +260,7 @@ size_t pktb_head_size(void) * pktb_free - release packet buffer [DEPRECATED] * \param pktb Pointer to userspace packet buffer * \note __pktb_free__ is deprecated. - * It is not required and must not be used with pktb_alloc2() + * It is not required and must not be used with pktb_setup() */ EXPORT_SYMBOL void pktb_free(struct pkt_buff *pktb) diff --git a/src/nlmsg.c b/src/nlmsg.c index f3a2c62..a6188cc 100644 --- a/src/nlmsg.c +++ b/src/nlmsg.c @@ -117,7 +117,7 @@ EXPORT_SYMBOL // The next line was commented-out (with payload void*) payload = mnl_attr_get_payload(attr[NFQA_PAYLOAD]); // Set up a packet buffer (the large pktbuf allows for any mangling). - pktb = pktb_alloc2(AF_INET, pktbuf, sizeof pktbuf, payload, plen); + pktb = pktb_setup(AF_INET, pktbuf, sizeof pktbuf, payload, plen); // (decide that this packet needs mangling) nfq_udp_mangle_ipv4(pktb, match_offset, match_len, rep_data, rep_len); // nfq_udp_mangle_ipv4 updates packet length, no need to track locally -- 2.14.5