datatype: fix print of raw numerical symbol values
Florian Westphal
maintainerPATCH 1/1 datatype: fix print of raw numerical symbol values
The two rules:
arp operation 1-2 accept
arp operation 256-512 accept
are both shown as 256-512:
chain in_public {
arp operation 256-512 accept
arp operation 256-512 accept
meta mark "1"
tcp flags 2,4
}
This is because range expression enforces numeric output, yet nft_print doesn't respect byte order.
Behave as if we had no symbol in the first place and call the base type print function instead.
This means we now respect format specifier as well:
chain in_public {
arp operation 1-2 accept
arp operation 256-512 accept
meta mark "0x00000001"
tcp flags 0x2,0x4
}Without fix, added test case will fail:
'add rule arp test-arp input arp operation 1-2': 'arp operation 1-2' mismatches 'arp operation 256-512'
---
Note there is a discrepancy between output when we have a symbol and when we do not.
Example, add rule:
meta mark "foo"
(with '1 "foo"' in rt_marks), nft will print quotes when symbol printing is inhibited via -n, but elides them in case the symbol is not available.
src/datatype.c | 2 +- tests/py/arp/arp.t | 1 + tests/py/arp/arp.t.payload | 6 ++++++ tests/py/arp/arp.t.payload.netdev | 8 ++++++++ 4 files changed, 16 insertions(+), 1 deletion(-)
src/datatype.c +1 -1
@@ -198,7 +198,7 @@ void symbolic_constant_print(const struct symbol_table *tbl,nft_print (octx,"\"" );if (nft_output_numeric_symbol (octx)) -nft_print (octx,"%" PRIu64"" , val); +expr_basetype (expr)->else nft_print (octx,"%s" , s->identifier);
tests/py/arp/arp.t +1 -0
@@ -38,6 +38,7 @@ arp plen != {33-55};ok arp operation {nak, inreply, inrequest, rreply, rrequest, reply, request};ok arp operation != {nak, inreply, inrequest, rreply, rrequest, reply, request};ok +arp operation 1-2;ok arp operation request;ok arp operation reply;ok arp operation rrequest;ok
tests/py/arp/arp.t.payload +6 -0
@@ -188,6 +188,12 @@ arp test-arp input [ payload load 2b @ network header + 6 => reg 1 ] [ lookup reg 1 set __set%d 0x1 ] +# arp operation 1-2 +arp test-arp input + [ payload load 2b @ network header + 6 => reg 1 ] + [ cmp gte reg 1 0x00000100 ] + [ cmp lte reg 1 0x00000200 ] + # arp operation request arp test-arp input [ payload load 2b @ network header + 6 => reg 1 ]
tests/py/arp/arp.t.payload.netdev +8 -0
@@ -246,6 +246,14 @@ netdev test-netdev ingress [ payload load 2b @ network header + 6 => reg 1 ] [ lookup reg 1 set __set%d 0x1 ] +# arp operation 1-2 +netdev test-netdev ingress + [ meta load protocol => reg 1 ] + [ cmp eq reg 1 0x00000608 ] + [ payload load 2b @ network header + 6 => reg 1 ] + [ cmp gte reg 1 0x00000100 ] + [ cmp lte reg 1 0x00000200 ] + # arp operation request netdev test-netdev ingress [ meta load protocol => reg 1 ]
Signature · 1 line
2.21.0
Pablo Neira Ayuso
maintainerQuoted 16 lines · Florian Westphal
The two rules:
arp operation 1-2 accept
arp operation 256-512 acceptare both shown as 256-512:
chain
in_public{
arp operation 256-512 accept
arp operation 256-512 accept
meta mark "1"
tcp flags 2,4
}This is because range expression enforces numeric output, yet
nft_printdoesn't respect byte order.
Quoted 8 lines
Behave as if we had no symbol in the first place and call the base type print function instead.
This means we now respect format specifier as well:
chain in_public { arp operation 1-2 accept arp operation 256-512 accept meta mark "0x00000001"
Hm, why is "1" turned into "0x00000001"?
I would expect quoted mark means: look at rt_marks.
Thanks!
Quoted 10 lines
tcp flags 0x2,0x4 }Without fix, added test case will fail:
'add rule arp test-arp input arp operation 1-2': 'arp operation 1-2' mismatches 'arp operation 256-512'Signed-off-by Florian Westphal <[email protected]>---
Note there is a discrepancy between output when we have a symbol and when we do not.
Quoted 6 lines
Example, add rule:
meta mark "foo"(with '1 "foo"' in
rt_marks), nft will print quotes when symbol printing is inhibited via -n, but elides them in case the symbol is not available.
Then, we also need a patch to regard NFT_CTX_OUTPUT_NUMERIC_ALL, right?
Quoted 19 lines
src/datatype.c | 2 +- tests/py/arp/arp.t | 1 + tests/py/arp/arp.t.payload | 6 ++++++ tests/py/arp/arp.t.payload.netdev | 8 ++++++++ 4 files changed, 16 insertions(+), 1 deletion(-)src/datatype.c +1
-1@@ -198,7 +198,7 @@ void symbolic_constant_print(const struct symbol_table *tbl,nft_print (octx,"\"" );if (nft_output_numeric_symbol (octx)) -nft_print (octx,"%" PRIu64"" , val); +expr_basetype (expr)->else nft_print (octx,"%s" , s->identifier);
Florian Westphal
maintainerQuoted 7 lines · Pablo Neira Ayuso
Quoted 5 lines
This means we now respect format specifier as well:
chain in_public { arp operation 1-2 accept arp operation 256-512 accept meta mark "0x00000001"Hm, why is "1" turned into "
0x00000001"?
Because it will now respect basefmt, and that is:
const struct datatype mark_type = {
...
.basefmt = "0x%.8Zx",Quoted 11 lines
Quoted 9 lines
Note there is a discrepancy between output when we have a symbol and when we do not.
Example, add rule:
meta mark "foo"(with '1 "foo"' in
rt_marks), nft will print quotes when symbol printing is inhibited via -n, but elides them in case the symbol is not available.Then, we also need a patch to regard
NFT_CTX_OUTPUT_NUMERIC_ALL, right?
Not sure what you mean.
symbolic_constant_print()
does:
if (no_symbol_found)
return print_raw(); if (quotes) nft_print(octx, "\""); if (nft_output_numeric_symbol(octx)) expr_basetype(expr)->print(expr, octx); else nft_print(octx, "%s", s->identifier);
...
maybe either do:
if (no_symbol_found) {
if (quotes)
....
print_raw();
...
return;}
(i.e., print quotes if no symbol found), or
if (nft_output_numeric_symbol(octx)) {
expr_basetype(expr)->print(expr, octx);
} else {
if (quotes) ..
nft_print(octx, "\"%s\"", s->identifier); else nft_print(octx, "%s", s->identifier); }
i.e., only print the "" if we found a symbol translation.
Pablo Neira Ayuso
maintainerQuoted 7 lines · Florian Westphal
Quoted 6 lines · Pablo Neira Ayuso
Quoted 5 lines
This means we now respect format specifier as well:
chain in_public { arp operation 1-2 accept arp operation 256-512 accept meta mark "0x00000001"
Quoted 7 lines
Quoted 1 line
Hm, why is "1" turned into "
0x00000001"?Because it will now respect basefmt, and that is:
const struct datatype mark_type = { ... .basefmt = "0x%.8Zx",
We don't want this, right? I mean, no quotes in that case.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Note there is a discrepancy between output when we have a symbol and when we do not.
Example, add rule:
meta mark "foo"
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
(with '1 "foo"' in
rt_marks), nft will print quotes when symbol printing is inhibited via -n, but elides them in case the symbol is not available.Then, we also need a patch to regard
NFT_CTX_OUTPUT_NUMERIC_ALL, right?Not sure what you mean.
I mean:
# nft list ruleset
table ip x {
chain y {
meta mark "test"
}
}
# nft list ruleset -n
table ip x {
chain y {
meta mark "20"
}
}This output with -n should not print quotes, ie. no "20".
Quoted 35 lines
symbolic_constant_print()does:
if (
no_symbol_found)return print_raw(); if (quotes) nft_print(octx, "\""); if (nft_output_numeric_symbol(octx)) expr_basetype(expr)->print(expr, octx); else nft_print(octx, "%s", s->identifier);...
maybe either do:
if (no_symbol_found) { if (quotes) .... print_raw(); ... return;}
(i.e., print quotes if no symbol found), or
if (nft_output_numeric_symbol(octx)) { expr_basetype(expr)->print(expr, octx); } else { if (quotes) .. nft_print(octx, "\"%s\"", s->identifier); else nft_print(octx, "%s", s->identifier); }
Quoted 1 line
i.e., only print the "" if we found a symbol translation.
Agreed :-).
BTW, this probably takes me back to the proposal not to strip off quotes from the scanner step. Hence, quoted strings will trigger a rt_mark lookup, otherwise we assume this is a 32-bit integer mark type. I'm refering to the parser side, so meta mark "0x20" means:
Search for 0x20 key in rt_marks.