All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Phil Sutter <phil@nwl.cc>, netfilter-devel@vger.kernel.org
Subject: Re: [PATCH nft,v2 1/2] datatype: reject rate in quota statement
Date: Wed, 14 Aug 2024 18:09:09 +0200	[thread overview]
Message-ID: <ZrzWpcQehJBmss13@calendula> (raw)
In-Reply-To: <ZrzUt-8mZoqdY0ai@orbyte.nwl.cc>

On Wed, Aug 14, 2024 at 06:00:55PM +0200, Phil Sutter wrote:
> On Wed, Aug 14, 2024 at 01:51:21PM +0200, Pablo Neira Ayuso wrote:
> > Bail out if rate are used:
> > 
> >  ruleset.nft:5:77-106: Error: Wrong rate format, expecting bytes or kbytes or mbytes
> >  add rule netdev firewall PROTECTED_IPS update @quota_temp_before { ip daddr quota over 45000 mbytes/second } add @quota_trigger { ip daddr }
> >                                                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > 
> > improve error reporting while at this.
> > 
> > Fixes: 6615676d825e ("src: add per-bytes limit")
> > Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
> > ---
> > v2: - change patch subject
> >     - use strndup() to fetch units in rate_parse() so limit rate does not break.
> > 
> >  src/datatype.c | 20 +++++++++++++-------
> >  1 file changed, 13 insertions(+), 7 deletions(-)
> > 
> > diff --git a/src/datatype.c b/src/datatype.c
> > index d398a9c8c618..297c5d0409d5 100644
> > --- a/src/datatype.c
> > +++ b/src/datatype.c
> > @@ -1485,14 +1485,14 @@ static struct error_record *time_unit_parse(const struct location *loc,
> >  struct error_record *data_unit_parse(const struct location *loc,
> >  				     const char *str, uint64_t *rate)
> >  {
> > -	if (strncmp(str, "bytes", strlen("bytes")) == 0)
> > +	if (strcmp(str, "bytes") == 0)
> >  		*rate = 1ULL;
> > -	else if (strncmp(str, "kbytes", strlen("kbytes")) == 0)
> > +	else if (strcmp(str, "kbytes") == 0)
> >  		*rate = 1024;
> > -	else if (strncmp(str, "mbytes", strlen("mbytes")) == 0)
> > +	else if (strcmp(str, "mbytes") == 0)
> >  		*rate = 1024 * 1024;
> >  	else
> > -		return error(loc, "Wrong rate format");
> > +		return error(loc, "Wrong unit format, expecting bytes, kbytes or mbytes");
> >  
> >  	return NULL;
> >  }
> 
> I have local commits which introduce KBYTES and MBYTES keywords and
> thereby kill the need for quota_unit and limit_bytes cases in
> parser_bison.y. It still needs testing and is surely not solving all
> issues there are, but I find it nicer than the partially redundant code
> we have right now.

Is this allowing for compact representation? ie. kbytes/second,
because I remember this was the issue to follow this poor man
approach.

> My motivation for this was to maybe improve parser's ability to handle
> lack of spaces in input. I still see the scanner fall into the generic
> "string" token case which requires manual dissection in the parser.
> 
> What is your motivation for the above changes?

A user that accidentally used:

        quota over 10mbytes/second

which is currently accepted, the /second part is misleading, as the
commit described, this is now rejected after this patch.

> Maybe we could collect parser limitations around these units and see
> what helps "the most"?

I am fine with handling this from the parser instead, there is now
flex start conditions that can help to enable these tokens on demand.

  reply	other threads:[~2024-08-14 16:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-14 11:51 [PATCH nft,v2 1/2] datatype: reject rate in quota statement Pablo Neira Ayuso
2024-08-14 11:51 ` [PATCH nft,v2 2/2] datatype: improve error reporting when time unit is not correct Pablo Neira Ayuso
2024-08-14 16:00 ` [PATCH nft,v2 1/2] datatype: reject rate in quota statement Phil Sutter
2024-08-14 16:09   ` Pablo Neira Ayuso [this message]
2024-08-14 19:26     ` Phil Sutter
2024-08-16 12:25       ` Phil Sutter
2024-08-19 10:47         ` Pablo Neira Ayuso
2024-08-19 15:18           ` Phil Sutter
2024-08-19 15:57             ` Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZrzWpcQehJBmss13@calendula \
    --to=pablo@netfilter.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=phil@nwl.cc \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.