With the advent of nfq_run_cb() and pktb_populate(), there is no longer ever a buffer tacked on the end of a struct pktbuff. Now that struct pktbuff is purely a buffer descriptor, there seems little point in keeping it opaque so expose it. Some code simplification ensues: the new callback function prototype only differs from the old one in having 1 extra arg being available free space. An application creates a struct pktbuff instance by just declaring it. pktb_populate() zeroises pktb because it's no longer guaranteed zero. As before, no new doxygen documentation until function prototypes are agreed, but examples/nf-queue.c is updated. Signed-off-by: Duncan Roe <duncan_roe@xxxxxxxxxxxxxxx> --- v3: New patch examples/nf-queue.c | 6 +++--- include/libnetfilter_queue/callback.h | 2 +- include/libnetfilter_queue/pktbuff.h | 13 ++++++++++++- src/extra/callback.c | 4 +--- src/extra/pktbuff.c | 1 + src/internal.h | 14 +------------- 6 files changed, 19 insertions(+), 21 deletions(-) diff --git a/examples/nf-queue.c b/examples/nf-queue.c index 4074e5a..f330b97 100644 --- a/examples/nf-queue.c +++ b/examples/nf-queue.c @@ -49,11 +49,12 @@ nfq_send_verdict(int queue_num, uint32_t id) } static int queue_cb(const struct nlmsghdr *nlh, void *data, - struct pkt_buff *supplied_pktb, size_t supplied_extra) + size_t supplied_extra) { struct nfqnl_msg_packet_hdr *ph = NULL; struct nlattr *attr[NFQA_MAX+1] = {}; struct pkt_buff *pktb; + struct pkt_buff pkt_b; uint32_t id = 0, skbinfo; struct nfgenmsg *nfg; uint8_t *payload; @@ -77,8 +78,7 @@ static int queue_cb(const struct nlmsghdr *nlh, void *data, plen = mnl_attr_get_payload_len(attr[NFQA_PAYLOAD]); payload = mnl_attr_get_payload(attr[NFQA_PAYLOAD]); - pktb = pktb_populate(supplied_pktb, AF_INET, payload, plen, - supplied_extra); + pktb = pktb_populate(&pkt_b, AF_INET, payload, plen, supplied_extra); skbinfo = attr[NFQA_SKB_INFO] ? ntohl(mnl_attr_get_u32(attr[NFQA_SKB_INFO])) : 0; diff --git a/include/libnetfilter_queue/callback.h b/include/libnetfilter_queue/callback.h index 27bfe31..756cb38 100644 --- a/include/libnetfilter_queue/callback.h +++ b/include/libnetfilter_queue/callback.h @@ -4,7 +4,7 @@ struct nlattr; struct pkt_buff; -typedef int (*nfq_cb_t)(const struct nlmsghdr *nlh, void *data, struct pkt_buff *pktb, size_t extra); +typedef int (*nfq_cb_t)(const struct nlmsghdr *nlh, void *data, size_t extra); int nfq_cb_run(const void *buf, size_t buflen, size_t bufcap, unsigned int portid, nfq_cb_t cb_data, void *data); diff --git a/include/libnetfilter_queue/pktbuff.h b/include/libnetfilter_queue/pktbuff.h index 33829cc..7ad7cb1 100644 --- a/include/libnetfilter_queue/pktbuff.h +++ b/include/libnetfilter_queue/pktbuff.h @@ -1,7 +1,18 @@ #ifndef _PKTBUFF_H_ #define _PKTBUFF_H_ -struct pkt_buff; +struct pkt_buff { + uint8_t *mac_header; + uint8_t *network_header; + uint8_t *transport_header; + + uint8_t *data; + + uint32_t len; + uint32_t data_len; + + bool mangled; +}; struct pkt_buff *pktb_alloc(int family, void *data, size_t len, size_t extra); void pktb_free(struct pkt_buff *pktb); diff --git a/src/extra/callback.c b/src/extra/callback.c index dee6fc2..23e88f7 100644 --- a/src/extra/callback.c +++ b/src/extra/callback.c @@ -31,10 +31,9 @@ struct data_carrier static int local_cb(const struct nlmsghdr *nlh, void *data) { - struct pkt_buff pktb_instance = { }; struct data_carrier *d = (struct data_carrier *)data; - return d->cb_func(nlh, d->data, &pktb_instance, d->bufcap - d->buflen); + return d->cb_func(nlh, d->data, d->bufcap - d->buflen); } EXPORT_SYMBOL int nfq_cb_run(const void *buf, size_t buflen, size_t bufcap, @@ -54,6 +53,5 @@ EXPORT_SYMBOL int nfq_cb_run(const void *buf, size_t buflen, size_t bufcap, return MNL_CB_ERROR; } - return mnl_cb_run(buf, buflen, 0, portid, local_cb, &dc); } diff --git a/src/extra/pktbuff.c b/src/extra/pktbuff.c index 86d8fe6..ae3e454 100644 --- a/src/extra/pktbuff.c +++ b/src/extra/pktbuff.c @@ -125,6 +125,7 @@ EXPORT_SYMBOL struct pkt_buff *pktb_populate(struct pkt_buff *pktb, int family, void *data, size_t len, size_t extra) { + memset(pktb, 0, sizeof *pktb); pktb_setup_metadata(pktb, data, len, extra); if (__pktb_setup(family, pktb) < 0) pktb = NULL; diff --git a/src/internal.h b/src/internal.h index ae849d6..6adf3d1 100644 --- a/src/internal.h +++ b/src/internal.h @@ -4,6 +4,7 @@ #include "config.h" #include <stdint.h> #include <stdbool.h> +#include <libnetfilter_queue/pktbuff.h> #ifdef HAVE_VISIBILITY_HIDDEN # define EXPORT_SYMBOL __attribute__((visibility("default"))) #else @@ -18,19 +19,6 @@ uint16_t nfq_checksum_tcpudp_ipv4(struct iphdr *iph, uint16_t protonum); uint16_t nfq_checksum_tcpudp_ipv6(struct ip6_hdr *ip6h, void *transport_hdr, uint16_t protonum); -struct pkt_buff { - uint8_t *mac_header; - uint8_t *network_header; - uint8_t *transport_header; - - uint8_t *data; - - uint32_t len; - uint32_t data_len; - - bool mangled; -}; - static inline uint8_t *pktb_tail(struct pkt_buff *pktb) { return pktb->data + pktb->len; -- 2.17.5