Re: [PATCH 1/2 nft v2] src: osf: add ttl option support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Please send a v3 including tests/py. More comments below.

On Sat, Sep 29, 2018 at 12:15:17PM +0200, Fernando Fernandez Mancera wrote:
> Add support for ttl option in "osf" expression. Example:
> 
> table ip foo {
> 	chain bar {
> 		type filter hook input priority filter; policy accept;
> 		osf ttl nocheck name "Linux"

Listing and output should match, ie. what you list should work with
nft -f, see below.

> diff --git a/src/parser_bison.y b/src/parser_bison.y
> index 831090b..a7ec858 100644
> --- a/src/parser_bison.y
> +++ b/src/parser_bison.y
> @@ -739,6 +739,7 @@ int nft_lex(void *, void *, void *);
>  %type <val>			fib_tuple	fib_result	fib_flag
>  
>  %type <expr>			osf_expr
> +%type <val>			osf_ttl
>  %destructor { expr_free($$); }	osf_expr
>  
>  %type <val>			markup_format
> @@ -3112,9 +3113,21 @@ fib_tuple		:  	fib_flag	DOT	fib_tuple
>  			|	fib_flag
>  			;
>  
> -osf_expr		:	OSF	NAME
> +osf_expr		:	OSF	osf_ttl		NAME
>  			{
> -				$$ = osf_expr_alloc(&@$);
> +				$$ = osf_expr_alloc(&@$, $2);
> +			}
> +			;
> +
> +osf_ttl			:	/* empty */	{ $$ = 0; }
> +			|	STRING
> +			{
> +				if (!strcmp($1, "ttl-global"))

This should be "global". But I would suggest you rename this to "loose".

> +					$$ = 1;

Can we use NFT_OSF_* definitions, instead of magic number?

> +				else if (!strcmp($1, "ttl-nocheck"))

This should be "nocheck". But I'd suggest you rename this to "skip"

> +					$$ = 2;

Same here, avoid magic number, use definition.

> +				else
> +					$$ = 3;

Same thing.

>  			}
>  			;
> diff --git a/src/osf.c b/src/osf.c
> index 85c9573..c7dd25f 100644
> --- a/src/osf.c
> +++ b/src/osf.c
> @@ -5,13 +5,32 @@
>  #include <osf.h>
>  #include <json.h>
>  
> +static const char *osf_ttl_int_to_str(const uint8_t ttl)
> +{
> +	if (ttl == 1)
> +		return "ttl global";
> +	else if (ttl == 2)
> +		return "ttl nocheck";
> +
> +	return "";
> +}
> +
>  static void osf_expr_print(const struct expr *expr, struct output_ctx *octx)
>  {
> -	nft_print(octx, "osf name");
> +	const char *ttl_str;
> +
> +	ttl_str = osf_ttl_int_to_str(expr->osf.ttl);
> +	nft_print(octx, "osf %s name", ttl_str);
>  }
>  
>  static void osf_expr_clone(struct expr *new, const struct expr *expr)
>  {
> +	new->osf.ttl = expr->osf.ttl;
> +}
> +
> +static bool osf_expr_cmp(const struct expr *e1, const struct expr *e2)
> +{
> +	return e1->osf.ttl == e2->osf.ttl;
>  }
>  
>  static const struct expr_ops osf_expr_ops = {
> @@ -19,10 +38,11 @@ static const struct expr_ops osf_expr_ops = {
>  	.name		= "osf",
>  	.print		= osf_expr_print,
>  	.clone		= osf_expr_clone,
> +	.cmp		= osf_expr_cmp,
>  	.json		= osf_expr_json,

BTW, could you extend json to support 'ttl' too?



[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux