diff mbox

[nft,5/7] src: implement shortcut for tcp mss size mangling

Message ID 20170819231413.15164-6-fw@strlen.de
State Accepted
Delegated to: Pablo Neira
Headers show

Commit Message

Florian Westphal Aug. 19, 2017, 11:14 p.m. UTC
short-hand version of tcp option maxseg size 1:
tcp option mss set 1

Reverse also prints the more compact representation.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 src/exthdr.c       |  1 +
 src/parser_bison.y |  7 +++++++
 src/scanner.l      |  1 +
 src/tcpopt.c       | 11 +++++++++--
 4 files changed, 18 insertions(+), 2 deletions(-)

Comments

Pablo Neira Ayuso Aug. 21, 2017, 2:12 p.m. UTC | #1
On Sun, Aug 20, 2017 at 01:14:11AM +0200, Florian Westphal wrote:
> short-hand version of tcp option maxseg size 1:
> tcp option mss set 1
> 
> Reverse also prints the more compact representation.

Why not just keep with the shortcut (more compact) representation?

> Signed-off-by: Florian Westphal <fw@strlen.de>
> ---
>  src/exthdr.c       |  1 +
>  src/parser_bison.y |  7 +++++++
>  src/scanner.l      |  1 +
>  src/tcpopt.c       | 11 +++++++++--
>  4 files changed, 18 insertions(+), 2 deletions(-)
> 
> diff --git a/src/exthdr.c b/src/exthdr.c
> index 7d13c83c9943..a4d4fa5b0864 100644
> --- a/src/exthdr.c
> +++ b/src/exthdr.c
> @@ -20,6 +20,7 @@
>  
>  #include <utils.h>
>  #include <headers.h>
> +#include <tcpopt.h>
>  #include <expression.h>
>  #include <statement.h>
>  
> diff --git a/src/parser_bison.y b/src/parser_bison.y
> index 7898ea3fe7bc..533347264729 100644
> --- a/src/parser_bison.y
> +++ b/src/parser_bison.y
> @@ -334,6 +334,7 @@ static void location_update(struct location *loc, struct location *rhs, int n)
>  %token RIGHT			"right"
>  %token TSVAL			"tsval"
>  %token TSECR			"tsecr"
> +%token MSS			"mss"
>  
>  %token DCCP			"dccp"
>  
> @@ -3214,6 +3215,12 @@ payload_stmt		:	payload_expr		SET	expr
>  				else
>  					$$ = payload_stmt_alloc(&@$, $1, $3);
>  			}
> +			|	TCP	OPTION	MSS	SET	expr
> +			{
> +				$$ = exthdr_stmt_alloc(&@$,
> +							tcpopt_expr_alloc(&@$, TCPOPTHDR_MAXSEG, TCPOPTHDR_FIELD_SIZE),
> +							$5);
> +			}
>  			;
>  
>  payload_expr		:	payload_raw_expr
> diff --git a/src/scanner.l b/src/scanner.l
> index b6ba32d88f4a..ede6ed73e5df 100644
> --- a/src/scanner.l
> +++ b/src/scanner.l
> @@ -433,6 +433,7 @@ addrstring	({macaddr}|{ip4addr}|{ip6addr})
>  "window"		{ return WINDOW; }
>  "urgptr"		{ return URGPTR; }
>  "option"		{ return OPTION; }
> +"mss"			{ return MSS; }
>  
>  "dccp"			{ return DCCP; }
>  
> diff --git a/src/tcpopt.c b/src/tcpopt.c
> index 63f0c236c9cf..c0540b7a31b2 100644
> --- a/src/tcpopt.c
> +++ b/src/tcpopt.c
> @@ -249,8 +249,15 @@ void tcpopt_expr_print(const struct expr *expr, struct output_ctx *octx)
>  
>  void tcpopt_stmt_print(const struct stmt *stmt, struct output_ctx *octx)
>  {
> -	tcpopt_expr_print(stmt->exthdr.expr, octx);
> -	printf(" set ");
> +	if (stmt->exthdr.expr->exthdr.desc->type == TCPOPT_MAXSEG &&
> +	    stmt->exthdr.expr->exthdr.tmpl ==
> +	    &stmt->exthdr.expr->exthdr.desc->templates[TCPOPTHDR_FIELD_SIZE]) {
> +		printf("tcp option mss set ");
> +	} else {
> +		tcpopt_expr_print(stmt->exthdr.expr, octx);
> +		printf(" set ");
> +	}
> +
>  	expr_print(stmt->exthdr.val, octx);
>  }
>  
> -- 
> 2.13.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
> the body of a message to majordomo@vger.kernel.org
> 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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Florian Westphal Aug. 21, 2017, 2:23 p.m. UTC | #2
Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> On Sun, Aug 20, 2017 at 01:14:11AM +0200, Florian Westphal wrote:
> > short-hand version of tcp option maxseg size 1:
> > tcp option mss set 1
> > 
> > Reverse also prints the more compact representation.
> 
> Why not just keep with the shortcut (more compact) representation?

I am not following, what do you suggest?

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

Patch

diff --git a/src/exthdr.c b/src/exthdr.c
index 7d13c83c9943..a4d4fa5b0864 100644
--- a/src/exthdr.c
+++ b/src/exthdr.c
@@ -20,6 +20,7 @@ 
 
 #include <utils.h>
 #include <headers.h>
+#include <tcpopt.h>
 #include <expression.h>
 #include <statement.h>
 
diff --git a/src/parser_bison.y b/src/parser_bison.y
index 7898ea3fe7bc..533347264729 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -334,6 +334,7 @@  static void location_update(struct location *loc, struct location *rhs, int n)
 %token RIGHT			"right"
 %token TSVAL			"tsval"
 %token TSECR			"tsecr"
+%token MSS			"mss"
 
 %token DCCP			"dccp"
 
@@ -3214,6 +3215,12 @@  payload_stmt		:	payload_expr		SET	expr
 				else
 					$$ = payload_stmt_alloc(&@$, $1, $3);
 			}
+			|	TCP	OPTION	MSS	SET	expr
+			{
+				$$ = exthdr_stmt_alloc(&@$,
+							tcpopt_expr_alloc(&@$, TCPOPTHDR_MAXSEG, TCPOPTHDR_FIELD_SIZE),
+							$5);
+			}
 			;
 
 payload_expr		:	payload_raw_expr
diff --git a/src/scanner.l b/src/scanner.l
index b6ba32d88f4a..ede6ed73e5df 100644
--- a/src/scanner.l
+++ b/src/scanner.l
@@ -433,6 +433,7 @@  addrstring	({macaddr}|{ip4addr}|{ip6addr})
 "window"		{ return WINDOW; }
 "urgptr"		{ return URGPTR; }
 "option"		{ return OPTION; }
+"mss"			{ return MSS; }
 
 "dccp"			{ return DCCP; }
 
diff --git a/src/tcpopt.c b/src/tcpopt.c
index 63f0c236c9cf..c0540b7a31b2 100644
--- a/src/tcpopt.c
+++ b/src/tcpopt.c
@@ -249,8 +249,15 @@  void tcpopt_expr_print(const struct expr *expr, struct output_ctx *octx)
 
 void tcpopt_stmt_print(const struct stmt *stmt, struct output_ctx *octx)
 {
-	tcpopt_expr_print(stmt->exthdr.expr, octx);
-	printf(" set ");
+	if (stmt->exthdr.expr->exthdr.desc->type == TCPOPT_MAXSEG &&
+	    stmt->exthdr.expr->exthdr.tmpl ==
+	    &stmt->exthdr.expr->exthdr.desc->templates[TCPOPTHDR_FIELD_SIZE]) {
+		printf("tcp option mss set ");
+	} else {
+		tcpopt_expr_print(stmt->exthdr.expr, octx);
+		printf(" set ");
+	}
+
 	expr_print(stmt->exthdr.val, octx);
 }