Re: [PATCH 1/3 v5 libnftnl] Implement rule comparison

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

 



On Wed, Aug 17, 2016 at 01:00:08PM +0200, Carlos Falgueras García wrote:
> This patch implements the function 'bool nftnl_rule_cmp(const struct
> nftnl_rule *r, const struct nftnl_rule *r2)' for rule comparison.
> 
> Expressions within rules need to be compared, so also has been created the
> function 'nftnl_expr_cmp' which calls new field within
> 'nfntl_expr_<expression>': a function pointer to a comparator.

Applied, thanks.

I made some slight changes, see below.

> diff --git a/src/expr.c b/src/expr.c
> index e5c1dd3..1f57fb2 100644
> --- a/src/expr.c
> +++ b/src/expr.c
> @@ -203,6 +203,17 @@ const char *nftnl_expr_get_str(const struct nftnl_expr *expr, uint16_t type)
>  }
>  EXPORT_SYMBOL_ALIAS(nftnl_expr_get_str, nft_rule_expr_get_str);
>  
> +bool nftnl_expr_cmp(const struct nftnl_expr *e1, const struct nftnl_expr *e2)
> +{
> +	if (e1->flags != e2->flags || strcmp(e1->ops->name, e2->ops->name))
> +		return false;
> +	if (e1->ops->cmp)
> +		return e1->ops->cmp(e1, e2);
> +
> +	return false;
> +}
> +EXPORT_SYMBOL(nftnl_expr_cmp);

_cmp() is now mandatory, so I have simplified this:

bool nftnl_expr_cmp(const struct nftnl_expr *e1, const struct nftnl_expr *e2)
{
	if (e1->flags != e2->flags ||
            strcmp(e1->ops->name, e2->ops->name) != 0)
		return false;

	return e1->ops->cmp(e1, e2);
}
EXPORT_SYMBOL(nftnl_expr_cmp);

> diff --git a/src/expr/bitwise.c b/src/expr/bitwise.c
> index 2fd4b74..1cfef0f 100644
> --- a/src/expr/bitwise.c
> +++ b/src/expr/bitwise.c
> @@ -310,10 +310,32 @@ nftnl_expr_bitwise_snprintf(char *buf, size_t size, uint32_t type,
>  	return -1;
>  }
>  
> +static bool nftnl_expr_bitwise_cmp(const struct nftnl_expr *e1,
> +				   const struct nftnl_expr *e2)
> +{
> +	struct nftnl_expr_bitwise *b1 = nftnl_expr_data(e1);
> +	struct nftnl_expr_bitwise *b2 = nftnl_expr_data(e2);
> +	bool eq = true;
> +
> +	if (e1->flags & (1 << NFTNL_EXPR_BITWISE_SREG))
> +		eq &= b1->sreg == b2->sreg;

I have wrapped all this comparisons with parens.

		eq &= (b1->sreg == b2->sreg);

Not that the compiler was asking for this here, but I think it makes
it a bit more readable for this specific case.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



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

  Powered by Linux