Skip to contentSkip to conversation

src: Comment-out code not needed since Linux 3.8 in examples/nf-queue.c

PATCH Superseded Duncan Roe 3 participants 7 messages Nov 23, 2019 – Nov 26, 2019 netfilter

lore
Share & tools
lore

Duncan Roe

author
#0 lore raw

cover src: Comment-out code not needed since Linux 3.8 in examples/nf-queue.c

This is the first in what I expect will be a number of patches to examples/nf-queue.c as I update the documentation and maybe introduce new helper functions.
An aspirational goal is to have all netfilter functions in nf-queue.c be documented in the libnetfilter_queue web page.

Duncan Roe (1):
src: Comment-out code not needed since Linux 3.8 in
examples/nf-queue.c

 examples/nf-queue.c | 48 +++++++++++++++++++++++++-----------------------
 1 file changed, 25 insertions(+), 23 deletions(-)
Signature · 1 line
2.14.5
author
#1 lore raw

PATCH 1/1 src: Comment-out code not needed since Linux 3.8 in examples/nf-queue.c

This makes it clear which lines are no longer required. It also obviates the need to document NFQNL_CFG_CMD_PF_(UN)BIND.

Add comment with sed command to re-enable commented-out code.

Use // comments because my sed-fu is not up to reversing a /* comment block

---
 examples/nf-queue.c | 48 +++++++++++++++++++++++++-----------------------
 1 file changed, 25 insertions(+), 23 deletions(-)
examples/nf-queue.c +25 -23
index f6d254a..ee9e4f4 100644
@@ -151,29 +151,31 @@ int main(int argc, char *argv[])
 	}
 
 	/* PF_(UN)BIND is not needed with kernels 3.8 and later */
-	nlh = nfq_hdr_put(buf, NFQNL_MSG_CONFIG, 0);
-	nfq_nlmsg_cfg_put_cmd(nlh, AF_INET, NFQNL_CFG_CMD_PF_UNBIND);
-
-	if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
-		perror("mnl_socket_send");
-		exit(EXIT_FAILURE);
-	}
-
-	nlh = nfq_hdr_put(buf, NFQNL_MSG_CONFIG, 0);
-	nfq_nlmsg_cfg_put_cmd(nlh, AF_INET, NFQNL_CFG_CMD_PF_BIND);
-
-	if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
-		perror("mnl_socket_send");
-		exit(EXIT_FAILURE);
-	}
-
-	nlh = nfq_hdr_put(buf, NFQNL_MSG_CONFIG, queue_num);
-	nfq_nlmsg_cfg_put_cmd(nlh, AF_INET, NFQNL_CFG_CMD_BIND);
-
-	if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
-		perror("mnl_socket_send");
-		exit(EXIT_FAILURE);
-	}
+	/* Uncomment this code block if you need to cater for an older kernel */
+	/* E.g. sed -i '156,178s+//++' examples/nf-queue.c */
+	//nlh = nfq_hdr_put(buf, NFQNL_MSG_CONFIG, 0);
+	//nfq_nlmsg_cfg_put_cmd(nlh, AF_INET, NFQNL_CFG_CMD_PF_UNBIND);
+	//
+	//if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
+	//	perror("mnl_socket_send");
+	//	exit(EXIT_FAILURE);
+	//}
+	//
+	//nlh = nfq_hdr_put(buf, NFQNL_MSG_CONFIG, 0);
+	//nfq_nlmsg_cfg_put_cmd(nlh, AF_INET, NFQNL_CFG_CMD_PF_BIND);
+	//
+	//if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
+	//	perror("mnl_socket_send");
+	//	exit(EXIT_FAILURE);
+	//}
+	//
+	//nlh = nfq_hdr_put(buf, NFQNL_MSG_CONFIG, queue_num);
+	//nfq_nlmsg_cfg_put_cmd(nlh, AF_INET, NFQNL_CFG_CMD_BIND);
+	//
+	//if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
+	//	perror("mnl_socket_send");
+	//	exit(EXIT_FAILURE);
+	//}
 
 	nlh = nfq_hdr_put(buf, NFQNL_MSG_CONFIG, queue_num);
 	nfq_nlmsg_cfg_put_params(nlh, NFQNL_COPY_PACKET, 0xffff);
Signature · 1 line
2.14.5
maintainer
#2 lore raw
Quoted 2 lines · Duncan Roe

This makes it clear which lines are no longer required. It also obviates the need to document NFQNL_CFG_CMD_PF_(UN)BIND.

Why not simply #if 0 this code?

Or just delete it, v3.8 was released almost 7 years ago.

author
#3 lore raw

Hi Floerian,

Quoted 5 lines · Florian Westphal
Quoted 2 lines · Duncan Roe

This makes it clear which lines are no longer required. It also obviates the need to document NFQNL_CFG_CMD_PF_(UN)BIND.

Why not simply #if 0 this code?

Simple reason: I think it's important to have an indicator on each commented-out line that it is,in fact, commented-out.

Quoted 2 lines

Or just delete it, v3.8 was released almost 7 years ago.

I could do that. But, I'm uneasy about it. There are systems around with very old Linuxes - in May last year there was that Tomato Firmware non-issue and the embedded environment was at 2.6!

Your call (or Pablo's) - I'm happy either way.

Cheers ... Duncan.

Quoted 16 lines · Edriss Mirzadeh

Hi there,

I???m actually cross compiling Tomato Firmware using 64 bit Debian 9.

The build instructions are good at the below URL, except for the repo name which recently changed but hasn???t yet been updated in the readme instructions.

https://bitbucket.org/kille72/freshtomato-arm/src

This could well be due to either the cross-compilation or the very old tool chain, or ancient kernel 2.6 (with many back ports), but I do agree that local headers should be double quoted, so your thought on patch rings true in terms of portability.

Cheers!

#4 lore raw
Quoted 12 lines · Duncan Roe

Hi Floerian,

Quoted 5 lines · Florian Westphal
Quoted 2 lines · Duncan Roe

This makes it clear which lines are no longer required. It also obviates the need to document NFQNL_CFG_CMD_PF_(UN)BIND.

Why not simply #if 0 this code?

Simple reason: I think it's important to have an indicator on each commented-out line that it is,in fact, commented-out.

Quoted 1 line
Quoted 7 lines
Quoted 1 line

Or just delete it, v3.8 was released almost 7 years ago.

I could do that. But, I'm uneasy about it. There are systems around with very old Linuxes - in May last year there was that Tomato Firmware non-issue and the embedded environment was at 2.6!

Your call (or Pablo's) - I'm happy either way.

I think it's fine to remove it.

There will be a commit message describing this is only required by very old kernel, which should be good enough for people with exotic environments to catch up I would expect.

Thanks.

author
#5 lore raw

PATCH v2 1/1 src: Delete code not needed since Linux 3.8 in examples/nf-queue.c

The removed code sent configuration commands NFQNL_CFG_CMD_PF_UNBIND & NFQNL_CFG_CMD_PF_BIND which the kernel required prior to 3.8.

---
 examples/nf-queue.c | 17 -----------------
 1 file changed, 17 deletions(-)
examples/nf-queue.c +0 -17
index f6d254a..960e244 100644
@@ -150,23 +150,6 @@ int main(int argc, char *argv[])
 		exit(EXIT_FAILURE);
 	}
 
-	/* PF_(UN)BIND is not needed with kernels 3.8 and later */
-	nlh = nfq_hdr_put(buf, NFQNL_MSG_CONFIG, 0);
-	nfq_nlmsg_cfg_put_cmd(nlh, AF_INET, NFQNL_CFG_CMD_PF_UNBIND);
-
-	if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
-		perror("mnl_socket_send");
-		exit(EXIT_FAILURE);
-	}
-
-	nlh = nfq_hdr_put(buf, NFQNL_MSG_CONFIG, 0);
-	nfq_nlmsg_cfg_put_cmd(nlh, AF_INET, NFQNL_CFG_CMD_PF_BIND);
-
-	if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
-		perror("mnl_socket_send");
-		exit(EXIT_FAILURE);
-	}
-
 	nlh = nfq_hdr_put(buf, NFQNL_MSG_CONFIG, queue_num);
 	nfq_nlmsg_cfg_put_cmd(nlh, AF_INET, NFQNL_CFG_CMD_BIND);
 
Signature · 1 line
2.14.5
maintainer Applied
#6 lore raw

Re: [PATCH libnetfilter_queue v2] src: Delete code not needed since Linux 3.8 in examples/nf-queue.c

Quoted 2 lines · Duncan Roe

The removed code sent configuration commands NFQNL_CFG_CMD_PF_UNBIND & NFQNL_CFG_CMD_PF_BIND which the kernel required prior to 3.8.

Applied, thanks.