From dd0e717827d8dff3b762a8ebbf15bf57aa4012cb Mon Sep 17 00:00:00 2001 From: Jeremy Sowden Date: Fri, 29 Oct 2021 21:40:09 +0100 Subject: parser: extend limit syntax The documentation describes the syntax of limit statements thus: limit rate [over] packet_number / TIME_UNIT [burst packet_number packets] limit rate [over] byte_number BYTE_UNIT / TIME_UNIT [burst byte_number BYTE_UNIT] TIME_UNIT := second | minute | hour | day BYTE_UNIT := bytes | kbytes | mbytes From this one might infer that a limit may be specified by any of the following: limit rate 1048576/second limit rate 1048576 mbytes/second limit rate 1048576 / second limit rate 1048576 mbytes / second However, the last does not currently parse: $ sudo /usr/sbin/nft add filter input limit rate 1048576 mbytes / second Error: wrong rate format add filter input limit rate 1048576 mbytes / second ^^^^^^^^^^^^^^^^^^^^^^^^^ Extend the `limit_rate_bytes` parser rule to support it, and add some new Python test-cases. Signed-off-by: Jeremy Sowden Signed-off-by: Pablo Neira Ayuso --- src/parser_bison.y | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/parser_bison.y b/src/parser_bison.y index cf1e139d..65fd35a3 100644 --- a/src/parser_bison.y +++ b/src/parser_bison.y @@ -3268,6 +3268,11 @@ limit_rate_bytes : NUM STRING $$.rate = rate * $1; $$.unit = unit; } + | limit_bytes SLASH time_unit + { + $$.rate = $1; + $$.unit = $3; + } ; limit_bytes : NUM BYTES { $$ = $1; } -- cgit v1.2.3