From: Duncan Roe <duncan_roe@optusnet.com.au>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH libnetfilter_queue 1/1] src & doc: Rename pktb_alloc2 to pktb_setup
Date: Wed, 13 May 2020 16:49:41 +1000 [thread overview]
Message-ID: <20200513064941.28408-2-duncan_roe@optusnet.com.au> (raw)
In-Reply-To: <20200513064941.28408-1-duncan_roe@optusnet.com.au>
In-Reply-To: <20200510151001.GA6216@salvia>
Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au>
---
fixmanpages.sh | 2 +-
include/libnetfilter_queue/pktbuff.h | 4 +++-
| 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);
--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
prev parent reply other threads:[~2020-05-13 6:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-10 13:53 [PATCH libnetfilter_queue 0/1] pktb_alloc2() Duncan Roe
2020-05-10 13:53 ` [PATCH libnetfilter_queue 1/1] src: add pktb_alloc2() and pktb_head_size() Duncan Roe
2020-05-10 15:10 ` Pablo Neira Ayuso
2020-05-10 21:30 ` Duncan Roe
2020-05-13 6:49 ` Duncan Roe
2020-05-13 6:49 ` Duncan Roe [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200513064941.28408-2-duncan_roe@optusnet.com.au \
--to=duncan_roe@optusnet.com.au \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).