Re: [PATCH nf-next v4 00/10] netfilter: nft_bitwise: shift support

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

 



On Mon, Jan 27, 2020 at 11:13:14AM +0000, Jeremy Sowden wrote:
> On 2020-01-26, at 12:12:51 +0100, Pablo Neira Ayuso wrote:
> > I've been looking into (ab)using bitwise to implement add/sub. I would
> > like to not add nft_arith for only this, and it seems to me much of
> > your code can be reused.
> >
> > Do you think something like this would work?
> 
> Absolutely.
> 
> A couple of questions.  What's the use-case?

inc/dec ip ttl field.

> I find the combination of applying the delta to every u32 and having
> a carry curious.  Do you want to support bigendian arithmetic (i.e.,
> carrying to the left) as well?

Userspace should convert to host endianess before doing arithmetics.

> I've suggested a couple of changes below.
[...]
> > diff --git a/net/netfilter/nft_bitwise.c b/net/netfilter/nft_bitwise.c
> > index 0ed2281f03be..fd0cd2b4722a 100644
> > --- a/net/netfilter/nft_bitwise.c
> > +++ b/net/netfilter/nft_bitwise.c
> > @@ -60,6 +60,38 @@ static void nft_bitwise_eval_rshift(u32 *dst, const
> > u32 *src,
> >  	}
> >  }
> >
> > +static void nft_bitwise_eval_add(u32 *dst, const u32 *src,
> > +				 const struct nft_bitwise *priv)
> > +{
> > +	u32 delta = priv->data.data[0];
> > +	unsigned int i, words;
> > +	u32 tmp = 0;
> > +
> > +	words = DIV_ROUND_UP(priv->len, sizeof(u32));
> > +	for (i = 0; i < words; i++) {
> > +		tmp = src[i];
> > +		dst[i] = src[i] + delta;
> > +		if (dst[i] < tmp && i + 1 < words)
> > +			dst[i + 1]++;
> > +	}
> > +}
> 
> for (i = 0; i < words; i++) {
> 	dst[i] = src[i] + delta + tmp;
> 	tmp = dst[i] < src[i] ? 1 : 0;
> }

Much simpler indeed, thanks.

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux