From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org, Florian Westphal <fw@strlen.de>
Subject: [nft PATCH 3/6] parser_bison: Introduce tokens for osf ttl values
Date: Tue, 9 Dec 2025 17:45:38 +0100 [thread overview]
Message-ID: <20251209164541.13425-4-phil@nwl.cc> (raw)
In-Reply-To: <20251209164541.13425-1-phil@nwl.cc>
Eliminate the open-coded string parsing and error handling.
Signed-off-by: Phil Sutter <phil@nwl.cc>
Reviewed-by: Florian Westphal <fw@strlen.de>
---
src/parser_bison.y | 24 ++++++------------------
src/scanner.l | 6 ++++++
2 files changed, 12 insertions(+), 18 deletions(-)
diff --git a/src/parser_bison.y b/src/parser_bison.y
index 405fe8f2690ca..ba485a8c25b50 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -719,6 +719,9 @@ int nft_lex(void *, void *, void *);
%token NAT "nat"
%token ROUTE "route"
+%token LOOSE "loose"
+%token SKIP "skip"
+
%type <limit_rate> limit_rate_pkts
%type <limit_rate> limit_rate_bytes
@@ -4485,24 +4488,9 @@ osf_expr : OSF osf_ttl HDRVERSION close_scope_osf
}
;
-osf_ttl : /* empty */
- {
- $$ = NF_OSF_TTL_TRUE;
- }
- | TTL STRING
- {
- if (!strcmp($2, "loose"))
- $$ = NF_OSF_TTL_LESS;
- else if (!strcmp($2, "skip"))
- $$ = NF_OSF_TTL_NOCHECK;
- else {
- erec_queue(error(&@2, "invalid ttl option"),
- state->msgs);
- free_const($2);
- YYERROR;
- }
- free_const($2);
- }
+osf_ttl : /* empty */ { $$ = NF_OSF_TTL_TRUE; }
+ | TTL LOOSE { $$ = NF_OSF_TTL_LESS; }
+ | TTL SKIP { $$ = NF_OSF_TTL_NOCHECK; }
;
shift_expr : primary_expr
diff --git a/src/scanner.l b/src/scanner.l
index b397a147ef9bd..e0f0aabb683a3 100644
--- a/src/scanner.l
+++ b/src/scanner.l
@@ -533,6 +533,12 @@ addrstring ({macaddr}|{ip4addr}|{ip6addr})
<SCANSTATE_EXPR_OSF,SCANSTATE_IP>{
"ttl" { return TTL; }
}
+
+<SCANSTATE_EXPR_OSF>{
+ "loose" { return LOOSE; }
+ "skip" { return SKIP; }
+}
+
<SCANSTATE_CT,SCANSTATE_IP,SCANSTATE_META,SCANSTATE_TYPE,SCANSTATE_GRE>"protocol" { return PROTOCOL; }
<SCANSTATE_EXPR_MH,SCANSTATE_EXPR_UDP,SCANSTATE_EXPR_UDPLITE,SCANSTATE_ICMP,SCANSTATE_IGMP,SCANSTATE_IP,SCANSTATE_SCTP,SCANSTATE_TCP>{
"checksum" { return CHECKSUM; }
--
2.51.0
next prev parent reply other threads:[~2025-12-09 16:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-09 16:45 [nft PATCH 0/6] parser_bison: Less STRING more tokens Phil Sutter
2025-12-09 16:45 ` [nft PATCH 1/6] parser_bison: Introduce tokens for monitor events Phil Sutter
2025-12-09 16:45 ` [nft PATCH 2/6] parser_bison: Introduce tokens for chain types Phil Sutter
2025-12-09 16:45 ` Phil Sutter [this message]
2025-12-09 16:45 ` [nft PATCH 4/6] parser_bison: Introduce tokens for log levels Phil Sutter
2025-12-09 16:45 ` [nft PATCH 5/6] parser_bison: Introduce bytes_unit Phil Sutter
2025-12-09 16:45 ` [nft PATCH 6/6] scanner: Introduce SCANSTATE_RATE Phil Sutter
2026-01-20 14:35 ` Florian Westphal
2026-01-20 16:28 ` Phil Sutter
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=20251209164541.13425-4-phil@nwl.cc \
--to=phil@nwl.cc \
--cc=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox