Skip to contentSkip to conversation

src: add redirect support

DISCUSSION Patrick McHardy 3 participants 9 messages Dec 12, 2014 netfilter

lore
Share & tools
lore
#0 lore raw

Looking at the redir bug report on netfilter-devel, I noticed some odd syntax for the redir statement.

The changelog states:

The syntax is:

% nft add rule nat prerouting redirect [port] [nat_flags]

The actual syntax though is:

redir_stmt_arg : COLON expr

What do we need that colon for? redirect by definition redirects to the local host, the argument is always only a port expression.

#1 lore raw
Quoted 7 lines · Patrick McHardy

Looking at the redir bug report on netfilter-devel, I noticed some odd syntax for the redir statement.

The changelog states:

The syntax is:

Quoted 8 lines

% nft add rule nat prerouting redirect [port] [nat_flags]

The actual syntax though is:

redir_stmt_arg : COLON expr

What do we need that colon for? redirect by definition redirects to the local host, the argument is always only a port expression.

Yes, there is a inconsistency between the commit message and the code. My fault.

I don't exactly remember where that syntax came from. I guess the colon was used in consistency with other nat-like expressions. Actually, I don't have a particular preference (the colon or not).

Do you want me to change the syntax? I can do it this weekend. Just let me know :-)

If you are going to change it yourself, I would suggest to also update regression tests [0], which BTW seems broken due to the random-fully/fully-random change.

best regards.

[0] http://git.netfilter.org/nftables/tree/tests/regression/ip/redirect.t

Signature · 5 lines
Arturo Borrero González
--
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

Am 12. Dezember 2014 17:02:04 GMT+00:00, schrieb Arturo Borrero Gonzalez <[email protected]>:

Quoted 20 lines · Patrick McHardy
Quoted 7 lines

Looking at the redir bug report on netfilter-devel, I noticed some odd syntax for the redir statement.

The changelog states:

The syntax is:

Quoted 8 lines

% nft add rule nat prerouting redirect [port] [nat_flags]

The actual syntax though is:

redir_stmt_arg : COLON expr

What do we need that colon for? redirect by definition redirects to the local host, the argument is always only a port expression.

Yes, there is a inconsistency between the commit message and the code. My fault.

Quoted 6 lines

I don't exactly remember where that syntax came from. I guess the colon was used in consistency with other nat-like expressions. Actually, I don't have a particular preference (the colon or not).

Do you want me to change the syntax? I can do it this weekend. Just let me know :-)

Well, I don't think the colon is really bad, however it suggests an address can be put in front of it. I guess the reason is an ambiguity in the grammar with following expressions otherwise. Even though redirect is terminal the grammar so far doesn't know about it. From a readability POV I like a simple "to".

Quoted 3 lines

If you are going to change it yourself, I would suggest to also update regression tests [0], which BTW seems broken due to the random-fully/fully-random change.

I missed that, will fix it up later.

Quoted 5 lines

best regards.

[0]
http://git.netfilter.org/nftables/tree/tests/regression/ip/redirect.t

#3 lore raw
Quoted 25 lines · Patrick McHardy

Am 12. Dezember 2014 17:02:04 GMT+00:00, schrieb Arturo Borrero Gonzalez <[email protected]>:

Quoted 24 lines · Patrick McHardy
Quoted 7 lines

Looking at the redir bug report on netfilter-devel, I noticed some odd syntax for the redir statement.

The changelog states:

The syntax is:

Quoted 8 lines

% nft add rule nat prerouting redirect [port] [nat_flags]

The actual syntax though is:

redir_stmt_arg : COLON expr

What do we need that colon for? redirect by definition redirects to the local host, the argument is always only a port expression.

Yes, there is a inconsistency between the commit message and the code. My fault.

I don't exactly remember where that syntax came from. I guess the colon was used in consistency with other nat-like expressions. Actually, I don't have a particular preference (the colon or not).

Quoted 8 lines
Quoted 2 lines

Do you want me to change the syntax? I can do it this weekend. Just let me know :-)

Well, I don't think the colon is really bad, however it suggests an address can be put in front of it. I guess the reason is an ambiguity in the grammar with following expressions otherwise. Even though redirect is terminal the grammar so far doesn't know about it. From a readability POV I like a simple "to".

I also like "to". Patch attached to address this.

Quoted 5 lines
Quoted 3 lines

If you are going to change it yourself, I would suggest to also update regression tests [0], which BTW seems broken due to the random-fully/fully-random change.

I missed that, will fix it up later.

No problem, just fixed it here, will push it now.

Quoted 1 line

From 8f120b86b7165cc650fe8a73b65f0e204c068730 Mon Sep 17 00:00:00 2001

From: Pablo Neira Ayuso <[email protected]>
Date: Fri, 12 Dec 2014 19:26:46 +0100
Subject: [PATCH] parser: use 'redirect to PORT' instead of 'redirect :PORT'

Small syntax update suggested by Patrick.

---
 src/parser_bison.y              |    5 +++--
 src/scanner.l                   |    1 +
 tests/regression/ip/redirect.t  |   24 ++++++++++++------------
 tests/regression/ip6/redirect.t |   18 +++++++++---------
 4 files changed, 25 insertions(+), 23 deletions(-)
src/parser_bison.y +3 -2
index 515a11a..99dbd08 100644
@@ -196,6 +196,7 @@ static void location_update(struct location *loc, struct location *rhs, int n)
 %token JUMP			"jump"
 %token GOTO			"goto"
 %token RETURN			"return"
+%token TO			"to"
 
 %token CONSTANT			"constant"
 %token INTERVAL			"interval"
@@ -1439,7 +1440,7 @@ redir_stmt		:	redir_stmt_alloc	redir_stmt_arg
 redir_stmt_alloc	:	REDIRECT	{ $$ = redir_stmt_alloc(&@$); }
 			;
 
-redir_stmt_arg		:	COLON	expr
+redir_stmt_arg		:	TO	expr
 			{
 				$<stmt>0->redir.proto = $2;
 			}
@@ -1447,7 +1448,7 @@ redir_stmt_arg		:	COLON	expr
 			{
 				$<stmt>0->redir.flags = $1;
 			}
-			|	COLON	expr	nf_nat_flags
+			|	TO	expr	nf_nat_flags
 			{
 				$<stmt>0->redir.proto = $2;
 				$<stmt>0->redir.flags = $3;
src/scanner.l +1 -0
index 1723159..ed87da6 100644
@@ -250,6 +250,7 @@ addrstring	({macaddr}|{ip4addr}|{ip6addr})
 "jump"			{ return JUMP; }
 "goto"			{ return GOTO; }
 "return"		{ return RETURN; }
+"to"			{ return TO; }
 
 "inet"			{ return INET; }
 
tests/regression/ip/redirect.t +12 -12
index ec88db1..bbf440d 100644
@@ -17,22 +17,22 @@ udp dport 53 redirect persistent,fully-random;ok;udp dport 53 redirect fully-ran
 udp dport 53 redirect persistent,fully-random,random;ok;udp dport 53 redirect random,fully-random,persistent
 
 # port specification
-tcp dport 22 redirect :22;ok
-udp dport 1234 redirect :4321;ok
-ip daddr 172.16.0.1 udp dport 9998 redirect :6515;ok
-tcp dport 39128 redirect :993;ok
-redirect :1234;fail
-redirect :12341111;fail
+tcp dport 22 redirect to 22;ok
+udp dport 1234 redirect to 4321;ok
+ip daddr 172.16.0.1 udp dport 9998 redirect to 6515;ok
+tcp dport 39128 redirect to 993;ok
+redirect to 1234;fail
+redirect to 12341111;fail
 
 # both port and nf_nat flags
-tcp dport 9128 redirect :993 random;ok
-tcp dport 9128 redirect :993 fully-random;ok
-tcp dport 9128 redirect :123 persistent;ok
-tcp dport 9128 redirect :123 random,persistent;ok
+tcp dport 9128 redirect to 993 random;ok
+tcp dport 9128 redirect to 993 fully-random;ok
+tcp dport 9128 redirect to 123 persistent;ok
+tcp dport 9128 redirect to 123 random,persistent;ok
 
 # nf_nat flags is the last argument
-udp dport 1234 redirect random :123;fail
-udp dport 21234 redirect persistent,fully-random :431;fail
+udp dport 1234 redirect random to 123;fail
+udp dport 21234 redirect persistent,fully-random to 431;fail
 
 # redirect is a terminal statement
 tcp dport 22 redirect counter packets 0 bytes 0 accept;fail
tests/regression/ip6/redirect.t +9 -9
index f6c98c0..730d733 100644
@@ -19,19 +19,19 @@ udp dport 53 redirect persistent,fully-random;ok;udp dport 53 redirect fully-ran
 udp dport 53 redirect persistent,fully-random,random;ok;udp dport 53 redirect random,fully-random,persistent
 
 # port specification
-udp dport 1234 redirect :1234;ok
-ip6 daddr fe00::cafe udp dport 9998 redirect :6515;ok
-tcp dport 39128 redirect :993;ok
-redirect :1234;fail
-redirect :12341111;fail
+udp dport 1234 redirect to 1234;ok
+ip6 daddr fe00::cafe udp dport 9998 redirect to 6515;ok
+tcp dport 39128 redirect to 993;ok
+redirect to 1234;fail
+redirect to 12341111;fail
 
 # both port and nf_nat flags
-tcp dport 9128 redirect :993 random;ok
-tcp dport 9128 redirect :993 fully-random,persistent;ok
+tcp dport 9128 redirect to 993 random;ok
+tcp dport 9128 redirect to 993 fully-random,persistent;ok
 
 # nf_nat flags are the last argument
-tcp dport 9128 redirect persistent :123;fail
-tcp dport 9128 redirect random,persistent :123;fail
+tcp dport 9128 redirect persistent to 123;fail
+tcp dport 9128 redirect random,persistent to 123;fail
 
 # redirect is a terminal statement
 tcp dport 22 redirect counter packets 0 bytes 0 accept;fail
Signature · 1 line
1.7.10.4
#4 lore raw
Quoted 14 lines · Pablo Neira Ayuso
Quoted 10 lines · Patrick McHardy

Am 12. Dezember 2014 17:02:04 GMT+00:00, schrieb Arturo Borrero Gonzalez <[email protected]>:

Quoted 3 lines

Do you want me to change the syntax? I can do it this weekend. Just let me know :-)

Well, I don't think the colon is really bad, however it suggests an address can be put in front of it. I guess the reason is an ambiguity in the grammar with following expressions otherwise. Even though redirect is terminal the grammar so far doesn't know about it. From a readability POV I like a simple "to".

I also like "to". Patch attached to address this.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

If you are going to change it yourself, I would suggest to also update regression tests [0], which BTW seems broken due to the random-fully/fully-random change.

I missed that, will fix it up later.

No problem, just fixed it here, will push it now.

Great, thanks.

I'll push my concat changes soon unless I hear objections :)

#5 lore raw
Quoted 19 lines · Patrick McHardy
Quoted 18 lines · Pablo Neira Ayuso
Quoted 10 lines · Patrick McHardy

Am 12. Dezember 2014 17:02:04 GMT+00:00, schrieb Arturo Borrero Gonzalez <[email protected]>:

Quoted 3 lines

Do you want me to change the syntax? I can do it this weekend. Just let me know :-)

Well, I don't think the colon is really bad, however it suggests an address can be put in front of it. I guess the reason is an ambiguity in the grammar with following expressions otherwise. Even though redirect is terminal the grammar so far doesn't know about it. From a readability POV I like a simple "to".

I also like "to". Patch attached to address this.

Quoted 4 lines
Quoted 3 lines

If you are going to change it yourself, I would suggest to also update regression tests [0], which BTW seems broken due to the random-fully/fully-random change.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

I missed that, will fix it up later.

No problem, just fixed it here, will push it now.

Great, thanks.

I'll push my concat changes soon unless I hear objections :)

Thanks Patrick.

Let's release 0.4, OK?

Do you want to include your concat changes already in this release?

P.S: It's great to see concat extension finally landing, that's a killer feature :-).

#6 lore raw
Quoted 9 lines · Pablo Neira Ayuso
Quoted 2 lines · Patrick McHardy

I'll push my concat changes soon unless I hear objections :)

Thanks Patrick.

Let's release 0.4, OK?

Do you want to include your concat changes already in this release?

No, let's do the release first. Any concrete plans when to release it?

Quoted 2 lines

P.S: It's great to see concat extension finally landing, that's a killer feature :-).

Yep, also quite happy to finally get this done :)

#7 lore raw
Quoted 5 lines · Patrick McHardy
Quoted 4 lines · Pablo Neira Ayuso
Quoted 2 lines · Patrick McHardy

I'll push my concat changes soon unless I hear objections :)

Quoted 7 lines
Quoted 5 lines

Thanks Patrick.

Let's release 0.4, OK?

Do you want to include your concat changes already in this release?

No, let's do the release first. Any concrete plans when to release it?

I'd suggest to schedule nft 0.4 release by monday, unless you want to give another review to the accumulated changes.

Let me know!

#8 lore raw
Quoted 10 lines · Pablo Neira Ayuso
Quoted 9 lines · Patrick McHardy
Quoted 8 lines · Pablo Neira Ayuso
Quoted 2 lines · Patrick McHardy

I'll push my concat changes soon unless I hear objections :)

Thanks Patrick.

Let's release 0.4, OK?

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Do you want to include your concat changes already in this release?

No, let's do the release first. Any concrete plans when to release it?

I'd suggest to schedule nft 0.4 release by monday, unless you want to give another review to the accumulated changes.

Let me know!

Monday sounds good, I'll use the weekend to go over the latest changes again.

Cheers,
Patrick