Skip to contentSkip to conversation

utils: add the parameter queue number in nfqnl_test

PATCH In review Alvaro Neira Ayuso 3 participants 7 messages Jun 6, 2014 – Jun 9, 2014 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 utils: add the parameter queue number in nfqnl_test

From: Álvaro Neira Ayuso <[email protected]>

This patch allows to stablish the number of the queue that we want to read the packets.

---
 utils/nfqnl_test.c |   14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
utils/nfqnl_test.c +11 -2
index 4decd50..8272fa1 100644
@@ -85,8 +85,18 @@ int main(int argc, char **argv)
 	struct nfq_q_handle *qh;
 	int fd;
 	int rv;
+	int queue = 0;
 	char buf[4096] __attribute__ ((aligned));
 
+	if (argc == 2) {
+		queue = atoi(argv[1]);
+		if (queue > 65535) {
+			fprintf(stderr, "queue number is bigger than 65535\n");
+			exit(1);
+		}
+	}
+
 	printf("opening library handle\n");
 	h = nfq_open();
 	if (!h) {
@@ -106,8 +116,8 @@ int main(int argc, char **argv)
 		exit(1);
 	}
 
-	printf("binding this socket to queue '0'\n");
-	qh = nfq_create_queue(h,  0, &cb, NULL);
+	printf("binding this socket to queue '%d'\n", queue);
+	qh = nfq_create_queue(h,  queue, &cb, NULL);
 	if (!qh) {
 		fprintf(stderr, "error during nfq_create_queue()\n");
 		exit(1);
Signature · 6 lines
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw
Quoted 15 lines · Alvaro Neira Ayuso

From: Álvaro Neira Ayuso <[email protected]>

This patch allows to stablish the number of the queue that we want to read the packets.

---
 utils/nfqnl_test.c |   14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
utils/nfqnl_test.c +0 -0
index 4decd50..8272fa1 100644

utils/nfqnl_test.c int main(int argc, char **argv) · line 88

Quoted 4 lines
utils/nfqnl_test.c +1 -0
@@ -85,8 +85,18 @@ int main(int argc, char **argv)
 	struct nfq_q_handle *qh;
 	int fd;
 	int rv;
+	int queue = 0;

This signed, change it to unsigned.

utils/nfqnl_test.c int main(int argc, char **argv) · line 94

Quoted 6 lines
utils/nfqnl_test.c +4 -0
 	char buf[4096] __attribute__ ((aligned));
 
+	if (argc == 2) {
+		queue = atoi(argv[1]);
+		if (queue > 65535) {
+			fprintf(stderr, "queue number is bigger than 65535\n");

I'd suggest something like.

                                        Usage: %s [<0-65535>]

utils/nfqnl_test.c int main(int argc, char **argv) · line 95

Quoted 1 line
utils/nfqnl_test.c +1 -0
+			exit(1);

Please, use exit(EXIT_FAILURE);

Quoted 24 lines
utils/nfqnl_test.c +5 -2
+		}
+	}
+
 	printf("opening library handle\n");
 	h = nfq_open();
 	if (!h) {
@@ -106,8 +116,8 @@ int main(int argc, char **argv)
 		exit(1);
 	}
 
-	printf("binding this socket to queue '0'\n");
-	qh = nfq_create_queue(h,  0, &cb, NULL);
+	printf("binding this socket to queue '%d'\n", queue);
+	qh = nfq_create_queue(h,  queue, &cb, NULL);
 	if (!qh) {
 		fprintf(stderr, "error during nfq_create_queue()\n");
 		exit(1);
Signature · 6 lines
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw

PATCH v2 1/1 utils: add the parameter queue number in nfqnl_test

In reply to Alvaro Neira Ayuso

From: Álvaro Neira Ayuso <[email protected]>

This patch allows to stablish the number of the queue that we want to read the packets.

---
[changes in v2]
* I have changed the variable queue to unsigned
* I have changed the message in case that queue > 65535 and also I have used exit(EXIT_FAILURE) in error case.

 utils/nfqnl_test.c |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
utils/nfqnl_test.c +11 -2
index 4decd50..557db1d 100644
@@ -85,8 +85,17 @@ int main(int argc, char **argv)
 	struct nfq_q_handle *qh;
 	int fd;
 	int rv;
+	uint32_t queue = 0;
 	char buf[4096] __attribute__ ((aligned));
 
+	if (argc == 2) {
+		queue = atoi(argv[1]);
+		if (queue > 65535) {
+			fprintf(stderr, "Usage: %s [<0-65535>]\n", argv[1]);
+			exit(EXIT_FAILURE);
+		}
+	}
+
 	printf("opening library handle\n");
 	h = nfq_open();
 	if (!h) {
@@ -106,8 +115,8 @@ int main(int argc, char **argv)
 		exit(1);
 	}
 
-	printf("binding this socket to queue '0'\n");
-	qh = nfq_create_queue(h,  0, &cb, NULL);
+	printf("binding this socket to queue '%d'\n", queue);
+	qh = nfq_create_queue(h,  queue, &cb, NULL);
 	if (!qh) {
 		fprintf(stderr, "error during nfq_create_queue()\n");
 		exit(1);
Signature · 6 lines
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw
Quoted 20 lines · Alvaro Neira Ayuso

From: Álvaro Neira Ayuso <[email protected]>

This patch allows to stablish the number of the queue that we want to read the packets.

---
[changes in v2]
* I have changed the variable queue to unsigned
* I have changed the message in case that queue > 65535 and also I have used exit(EXIT_FAILURE) in error case.

 utils/nfqnl_test.c |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
utils/nfqnl_test.c +0 -0
index 4decd50..557db1d 100644

utils/nfqnl_test.c int main(int argc, char **argv) · line 94

Quoted 10 lines
utils/nfqnl_test.c +5 -0
@@ -85,8 +85,17 @@ int main(int argc, char **argv)
 	struct nfq_q_handle *qh;
 	int fd;
 	int rv;
+	uint32_t queue = 0;
 	char buf[4096] __attribute__ ((aligned));
 
+	if (argc == 2) {
+		queue = atoi(argv[1]);
+		if (queue > 65535) {
+			fprintf(stderr, "Usage: %s [<0-65535>]\n", argv[1]);
                                                                   ^^^^^^^

You did *not* test the error path, this is argv[0].
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 27 lines · Pablo Neira Ayuso
Quoted 26 lines · Alvaro Neira Ayuso

From: Álvaro Neira Ayuso <[email protected]>

This patch allows to stablish the number of the queue that we want to read the packets.

---
[changes in v2]
* I have changed the variable queue to unsigned
* I have changed the message in case that queue > 65535 and also I have used exit(EXIT_FAILURE) in error case.

  utils/nfqnl_test.c |   13 +++++++++++--
  1 file changed, 11 insertions(+), 2 deletions(-)
utils/nfqnl_test.c +1 -0
index 4decd50..557db1d 100644
@@ -85,8 +85,17 @@ int main(int argc, char **argv)
  	struct nfq_q_handle *qh;
  	int fd;
  	int rv;
+	uint32_t queue = 0;
  	char buf[4096] __attribute__ ((aligned));
 
Quoted 8 lines

utils/nfqnl_test.c int main(int argc, char **argv) · line 94

Quoted 4 lines
utils/nfqnl_test.c +4 -0
+	if (argc == 2) {
+		queue = atoi(argv[1]);
+		if (queue > 65535) {
+			fprintf(stderr, "Usage: %s [<0-65535>]\n", argv[1]);
                                                                    ^^^^^^^

You did *not* test the error path, this is argv[0].

Sure, sorry. I have understood wrong.

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw

PATCH v3 2/2 utils: add the parameter queue number in nfqnl_test

In reply to Alvaro Neira Ayuso

From: Álvaro Neira Ayuso <[email protected]>

This patch allows to stablish the number of the queue that we want to read the packets.

---
[changes in v3]
* I have changed the argument 1 to 0 in the error message.

 utils/nfqnl_test.c |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
utils/nfqnl_test.c +11 -2
index 4decd50..8c503f3 100644
@@ -85,8 +85,17 @@ int main(int argc, char **argv)
 	struct nfq_q_handle *qh;
 	int fd;
 	int rv;
+	uint32_t queue = 0;
 	char buf[4096] __attribute__ ((aligned));
 
+	if (argc == 2) {
+		queue = atoi(argv[1]);
+		if (queue > 65535) {
+			fprintf(stderr, "Usage: %s [<0-65535>]\n", argv[0]);
+			exit(EXIT_FAILURE);
+		}
+	}
+
 	printf("opening library handle\n");
 	h = nfq_open();
 	if (!h) {
@@ -106,8 +115,8 @@ int main(int argc, char **argv)
 		exit(1);
 	}
 
-	printf("binding this socket to queue '0'\n");
-	qh = nfq_create_queue(h,  0, &cb, NULL);
+	printf("binding this socket to queue '%d'\n", queue);
+	qh = nfq_create_queue(h,  queue, &cb, NULL);
 	if (!qh) {
 		fprintf(stderr, "error during nfq_create_queue()\n");
 		exit(1);
Signature · 6 lines
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html