tests: shell: Stabilize nft-only/0009-needless-bitwise_0
Phil Sutter
reviewerPATCH 1/1 tests: shell: Stabilize nft-only/0009-needless-bitwise_0
Netlink debug output varies depending on host's endianness and therefore the test fails on Big Endian machines. Since for the sake of asserting no needless bitwise expressions in output the actual data values are not relevant, simply crop the output to just the expression names.
--- .../nft-only/0009-needless-bitwise_0 | 413 +++++++++--------- 1 file changed, 208 insertions(+), 205 deletions(-)
iptables/tests/shell/testcases/nft-only/0009-needless-bitwise_0 +208 -205
@@ -1,4 +1,4 @@ -#!/bin/bash -x +#!/bin/bash [[ $XT_MULTI == *xtables-nft-multi ]] || { echo "skip $XT_MULTI"; exit 0; } set -e
@@ -53,287 +53,290 @@ ff:00:00:00:00:00 ) | $XT_MULTI ebtables-restore EXPECT="ip filter OUTPUT 4 - [ payload load 4b @ network header + 16 => reg 1 ] - [ cmp eq reg 1 0x0302010a ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip filter OUTPUT 5 4 - [ payload load 4b @ network header + 16 => reg 1 ] - [ cmp eq reg 1 0x0302010a ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip filter OUTPUT 6 5 - [ payload load 4b @ network header + 16 => reg 1 ] - [ bitwise reg 1 = ( reg 1 & 0xfcffffff ) ^ 0x00000000 ] - [ cmp eq reg 1 0x0002010a ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ bitwise ] + [ cmp ] + [ counter ] ip filter OUTPUT 7 6 - [ payload load 3b @ network header + 16 => reg 1 ] - [ cmp eq reg 1 0x0002010a ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip filter OUTPUT 8 7 - [ payload load 2b @ network header + 16 => reg 1 ] - [ cmp eq reg 1 0x0000010a ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip filter OUTPUT 9 8 - [ payload load 1b @ network header + 16 => reg 1 ] - [ cmp eq reg 1 0x0000000a ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip filter OUTPUT 10 9 - [ counter pkts 0 bytes 0 ] + [ counter ] ip6 filter OUTPUT 4 - [ payload load 16b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0xffc0edfe 0x020100ee 0x06050403 0x0a090807 ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip6 filter OUTPUT 5 4 - [ payload load 16b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0xffc0edfe 0x020100ee 0x06050403 0x0a090807 ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip6 filter OUTPUT 6 5 - [ payload load 16b @ network header + 24 => reg 1 ] - [ bitwise reg 1 = ( reg 1 & 0xffffffff 0xffffffff 0xffffffff 0xf0ffffff ) ^ 0x00000000 0x00000000 0x00000000 0x00000000 ] - [ cmp eq reg 1 0xffc0edfe 0x020100ee 0x06050403 0x00090807 ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ bitwise ] + [ cmp ] + [ counter ] ip6 filter OUTPUT 7 6 - [ payload load 15b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0xffc0edfe 0x020100ee 0x06050403 0x00090807 ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip6 filter OUTPUT 8 7 - [ payload load 14b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0xffc0edfe 0x020100ee 0x06050403 0x00000807 ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip6 filter OUTPUT 9 8 - [ payload load 11b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0xffc0edfe 0x020100ee 0x00050403 ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip6 filter OUTPUT 10 9 - [ payload load 10b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0xffc0edfe 0x020100ee 0x00000403 ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip6 filter OUTPUT 11 10 - [ payload load 8b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0xffc0edfe 0x020100ee ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip6 filter OUTPUT 12 11 - [ payload load 6b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0xffc0edfe 0x000000ee ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip6 filter OUTPUT 13 12 - [ payload load 2b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0x0000edfe ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip6 filter OUTPUT 14 13 - [ payload load 1b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0x000000fe ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip6 filter OUTPUT 15 14 - [ counter pkts 0 bytes 0 ] + [ counter ] arp filter OUTPUT 3 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 4b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0x0302010a ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ counter ] arp filter OUTPUT 4 3 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 4b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0x0302010a ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ counter ] arp filter OUTPUT 5 4 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 4b @ network header + 24 => reg 1 ] - [ bitwise reg 1 = ( reg 1 & 0xfcffffff ) ^ 0x00000000 ] - [ cmp eq reg 1 0x0002010a ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ bitwise ] + [ cmp ] + [ counter ] arp filter OUTPUT 6 5 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 3b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0x0002010a ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ counter ] arp filter OUTPUT 7 6 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 2b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0x0000010a ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ counter ] arp filter OUTPUT 8 7 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 1b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0x0000000a ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ counter ] arp filter OUTPUT 9 8 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ counter ] arp filter OUTPUT 10 9 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 6b @ network header + 18 => reg 1 ] - [ cmp eq reg 1 0xc000edfe 0x0000eeff ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ counter ] arp filter OUTPUT 11 10 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 6b @ network header + 18 => reg 1 ] - [ bitwise reg 1 = ( reg 1 & 0xffffffff 0x0000f0ff ) ^ 0x00000000 0x00000000 ] - [ cmp eq reg 1 0xc000edfe 0x0000e0ff ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ bitwise ] + [ cmp ] + [ counter ] arp filter OUTPUT 12 11 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 5b @ network header + 18 => reg 1 ] - [ cmp eq reg 1 0xc000edfe 0x000000ff ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ counter ] arp filter OUTPUT 13 12 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 4b @ network header + 18 => reg 1 ] - [ cmp eq reg 1 0xc000edfe ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ counter ] arp filter OUTPUT 14 13 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 3b @ network header + 18 => reg 1 ] - [ cmp eq reg 1 0x0000edfe ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ counter ] arp filter OUTPUT 15 14 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 2b @ network header + 18 => reg 1 ] - [ cmp eq reg 1 0x0000edfe ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ counter ] arp filter OUTPUT 16 15 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 1b @ network header + 18 => reg 1 ] - [ cmp eq reg 1 0x000000fe ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ counter ] bridge filter OUTPUT 4 - [ payload load 6b @ link header + 0 => reg 1 ] - [ cmp eq reg 1 0xc000edfe 0x0000eeff ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] bridge filter OUTPUT 5 4 - [ payload load 6b @ link header + 0 => reg 1 ] - [ bitwise reg 1 = ( reg 1 & 0xffffffff 0x0000f0ff ) ^ 0x00000000 0x00000000 ] - [ cmp eq reg 1 0xc000edfe 0x0000e0ff ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ bitwise ] + [ cmp ] + [ counter ] bridge filter OUTPUT 6 5 - [ payload load 5b @ link header + 0 => reg 1 ] - [ cmp eq reg 1 0xc000edfe 0x000000ff ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] bridge filter OUTPUT 7 6 - [ payload load 4b @ link header + 0 => reg 1 ] - [ cmp eq reg 1 0xc000edfe ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] bridge filter OUTPUT 8 7 - [ payload load 3b @ link header + 0 => reg 1 ] - [ cmp eq reg 1 0x0000edfe ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] bridge filter OUTPUT 9 8 - [ payload load 2b @ link header + 0 => reg 1 ] - [ cmp eq reg 1 0x0000edfe ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] bridge filter OUTPUT 10 9 - [ payload load 1b @ link header + 0 => reg 1 ] - [ cmp eq reg 1 0x000000fe ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] " -diff -u -Z <(echo "$EXPECT") <(nft --debug=netlink list ruleset | awk '/^table/{exit} {print}') +diff -u -Z <(echo "$EXPECT") <(nft --debug=netlink list ruleset | awk ' + /^table/{exit} + {print gensub(/\[ ([^ ]+) .* ]/,"[ \\1 ]", "g")}' +)
Signature · 1 line
2.28.0
Pablo Neira Ayuso
maintainerQuoted 4 lines · Phil Sutter
Netlink debug output varies depending on host's endianness and therefore the test fails on Big Endian machines. Since for the sake of asserting no needless bitwise expressions in output the actual data values are not relevant, simply crop the output to just the expression names.
Probably we can fix this in libnftnl before we apply patches like this to nft as well?
Quoted 514 lines
Fixes 81a2e12851283 ("tests/shell: Add test for bitwise avoidance fixes")Signed-off-by Phil Sutter <[email protected]>--- .../nft-only/0009-needless-bitwise_0 | 413 +++++++++--------- 1 file changed, 208 insertions(+), 205 deletions(-)iptables/tests/shell/testcases/nft-only/0009-needless-bitwise_0 +208
-205@@ -1,4 +1,4 @@ -#!/bin/bash -x +#!/bin/bash [[ $XT_MULTI == *xtables-nft-multi ]] || { echo "skip $XT_MULTI"; exit 0; } set -e@@ -53,287 +53,290 @@ ff:00:00:00:00:00 ) | $XT_MULTI ebtables-restore EXPECT="ip filter OUTPUT 4 - [ payload load 4b @ network header + 16 => reg 1 ] - [ cmp eq reg 1 0x0302010a ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip filter OUTPUT 5 4 - [ payload load 4b @ network header + 16 => reg 1 ] - [ cmp eq reg 1 0x0302010a ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip filter OUTPUT 6 5 - [ payload load 4b @ network header + 16 => reg 1 ] - [ bitwise reg 1 = ( reg 1 & 0xfcffffff ) ^ 0x00000000 ] - [ cmp eq reg 1 0x0002010a ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ bitwise ] + [ cmp ] + [ counter ] ip filter OUTPUT 7 6 - [ payload load 3b @ network header + 16 => reg 1 ] - [ cmp eq reg 1 0x0002010a ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip filter OUTPUT 8 7 - [ payload load 2b @ network header + 16 => reg 1 ] - [ cmp eq reg 1 0x0000010a ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip filter OUTPUT 9 8 - [ payload load 1b @ network header + 16 => reg 1 ] - [ cmp eq reg 1 0x0000000a ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip filter OUTPUT 10 9 - [ counter pkts 0 bytes 0 ] + [ counter ] ip6 filter OUTPUT 4 - [ payload load 16b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0xffc0edfe 0x020100ee 0x06050403 0x0a090807 ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip6 filter OUTPUT 5 4 - [ payload load 16b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0xffc0edfe 0x020100ee 0x06050403 0x0a090807 ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip6 filter OUTPUT 6 5 - [ payload load 16b @ network header + 24 => reg 1 ] - [ bitwise reg 1 = ( reg 1 & 0xffffffff 0xffffffff 0xffffffff 0xf0ffffff ) ^ 0x00000000 0x00000000 0x00000000 0x00000000 ] - [ cmp eq reg 1 0xffc0edfe 0x020100ee 0x06050403 0x00090807 ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ bitwise ] + [ cmp ] + [ counter ] ip6 filter OUTPUT 7 6 - [ payload load 15b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0xffc0edfe 0x020100ee 0x06050403 0x00090807 ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip6 filter OUTPUT 8 7 - [ payload load 14b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0xffc0edfe 0x020100ee 0x06050403 0x00000807 ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip6 filter OUTPUT 9 8 - [ payload load 11b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0xffc0edfe 0x020100ee 0x00050403 ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip6 filter OUTPUT 10 9 - [ payload load 10b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0xffc0edfe 0x020100ee 0x00000403 ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip6 filter OUTPUT 11 10 - [ payload load 8b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0xffc0edfe 0x020100ee ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip6 filter OUTPUT 12 11 - [ payload load 6b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0xffc0edfe 0x000000ee ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip6 filter OUTPUT 13 12 - [ payload load 2b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0x0000edfe ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip6 filter OUTPUT 14 13 - [ payload load 1b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0x000000fe ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] ip6 filter OUTPUT 15 14 - [ counter pkts 0 bytes 0 ] + [ counter ] arp filter OUTPUT 3 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 4b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0x0302010a ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ counter ] arp filter OUTPUT 4 3 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 4b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0x0302010a ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ counter ] arp filter OUTPUT 5 4 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 4b @ network header + 24 => reg 1 ] - [ bitwise reg 1 = ( reg 1 & 0xfcffffff ) ^ 0x00000000 ] - [ cmp eq reg 1 0x0002010a ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ bitwise ] + [ cmp ] + [ counter ] arp filter OUTPUT 6 5 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 3b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0x0002010a ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ counter ] arp filter OUTPUT 7 6 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 2b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0x0000010a ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ counter ] arp filter OUTPUT 8 7 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 1b @ network header + 24 => reg 1 ] - [ cmp eq reg 1 0x0000000a ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ counter ] arp filter OUTPUT 9 8 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ counter ] arp filter OUTPUT 10 9 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 6b @ network header + 18 => reg 1 ] - [ cmp eq reg 1 0xc000edfe 0x0000eeff ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ counter ] arp filter OUTPUT 11 10 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 6b @ network header + 18 => reg 1 ] - [ bitwise reg 1 = ( reg 1 & 0xffffffff 0x0000f0ff ) ^ 0x00000000 0x00000000 ] - [ cmp eq reg 1 0xc000edfe 0x0000e0ff ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ bitwise ] + [ cmp ] + [ counter ] arp filter OUTPUT 12 11 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 5b @ network header + 18 => reg 1 ] - [ cmp eq reg 1 0xc000edfe 0x000000ff ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ counter ] arp filter OUTPUT 13 12 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 4b @ network header + 18 => reg 1 ] - [ cmp eq reg 1 0xc000edfe ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ counter ] arp filter OUTPUT 14 13 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 3b @ network header + 18 => reg 1 ] - [ cmp eq reg 1 0x0000edfe ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ counter ] arp filter OUTPUT 15 14 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 2b @ network header + 18 => reg 1 ] - [ cmp eq reg 1 0x0000edfe ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ counter ] arp filter OUTPUT 16 15 - [ payload load 2b @ network header + 0 => reg 1 ] - [ cmp eq reg 1 0x00000100 ] - [ payload load 1b @ network header + 4 => reg 1 ] - [ cmp eq reg 1 0x00000006 ] - [ payload load 1b @ network header + 5 => reg 1 ] - [ cmp eq reg 1 0x00000004 ] - [ payload load 1b @ network header + 18 => reg 1 ] - [ cmp eq reg 1 0x000000fe ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ payload ] + [ cmp ] + [ counter ] bridge filter OUTPUT 4 - [ payload load 6b @ link header + 0 => reg 1 ] - [ cmp eq reg 1 0xc000edfe 0x0000eeff ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] bridge filter OUTPUT 5 4 - [ payload load 6b @ link header + 0 => reg 1 ] - [ bitwise reg 1 = ( reg 1 & 0xffffffff 0x0000f0ff ) ^ 0x00000000 0x00000000 ] - [ cmp eq reg 1 0xc000edfe 0x0000e0ff ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ bitwise ] + [ cmp ] + [ counter ] bridge filter OUTPUT 6 5 - [ payload load 5b @ link header + 0 => reg 1 ] - [ cmp eq reg 1 0xc000edfe 0x000000ff ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] bridge filter OUTPUT 7 6 - [ payload load 4b @ link header + 0 => reg 1 ] - [ cmp eq reg 1 0xc000edfe ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] bridge filter OUTPUT 8 7 - [ payload load 3b @ link header + 0 => reg 1 ] - [ cmp eq reg 1 0x0000edfe ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] bridge filter OUTPUT 9 8 - [ payload load 2b @ link header + 0 => reg 1 ] - [ cmp eq reg 1 0x0000edfe ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] bridge filter OUTPUT 10 9 - [ payload load 1b @ link header + 0 => reg 1 ] - [ cmp eq reg 1 0x000000fe ] - [ counter pkts 0 bytes 0 ] + [ payload ] + [ cmp ] + [ counter ] " -diff -u -Z <(echo "$EXPECT") <(nft --debug=netlink list ruleset | awk '/^table/{exit} {print}') +diff -u -Z <(echo "$EXPECT") <(nft --debug=netlink list ruleset | awk ' + /^table/{exit} + {print gensub(/\[ ([^ ]+) .* ]/,"[ \\1 ]", "g")}' +)Signature · 1 line
2.28.0
Phil Sutter
reviewerHi,
Quoted 8 lines · Pablo Neira Ayuso
Quoted 4 lines · Phil Sutter
Netlink debug output varies depending on host's endianness and therefore the test fails on Big Endian machines. Since for the sake of asserting no needless bitwise expressions in output the actual data values are not relevant, simply crop the output to just the expression names.
Probably we can fix this in libnftnl before we apply patches like this to nft as well?
You're right, ignoring the problems in nft testsuite is pretty inconsistent. OTOH this is the first test that breaks iptables testsuite on Big Endian while nft testsuite is entirely broken. ;)
I had a look at libnftnl and it seems like even kernel support is needed to carry the endianness info from input to output. IMHO data should be in a consistent format in netlink messages, but I fear we can't change this anymore. I tried to print the data byte-by-byte, but we obviously still get problems with any data in host byte order. Do you see an easier way to fix this than adding extra info to all expressions containing data?
Thanks, Phil
Pablo Neira Ayuso
maintainerQuoted 9 lines · Phil Sutter
Hi,
Quoted 6 lines · Pablo Neira Ayuso
Quoted 4 lines · Phil Sutter
Netlink debug output varies depending on host's endianness and therefore the test fails on Big Endian machines. Since for the sake of asserting no needless bitwise expressions in output the actual data values are not relevant, simply crop the output to just the expression names.
Quoted 6 lines
Quoted 2 lines
Probably we can fix this in libnftnl before we apply patches like this to nft as well?
You're right, ignoring the problems in nft testsuite is pretty inconsistent. OTOH this is the first test that breaks iptables testsuite on Big Endian while nft testsuite is entirely broken. ;)
Do you think we can fix this from the testsuite site? It would require to replicate payload files. The snprintf printing is used for debugging only at this stage. That would fix nft and this specific case.
Quoted 7 lines
I had a look at libnftnl and it seems like even kernel support is needed to carry the endianness info from input to output. IMHO data should be in a consistent format in netlink messages, but I fear we can't change this anymore. I tried to print the data byte-by-byte, but we obviously still get problems with any data in host byte order. Do you see an easier way to fix this than adding extra info to all expressions containing data?
Probably we can make assumptions based on context, such as payload expression always express things in network byte order, and annotate that such register stores something in network byteorder. For meta, assume host byte order. Unless there is an explicit byteorder expression.
Phil Sutter
reviewerHi Pablo,
Quoted 29 lines · Pablo Neira Ayuso
Quoted 9 lines · Phil Sutter
Hi,
Quoted 6 lines · Pablo Neira Ayuso
Quoted 4 lines · Phil Sutter
Netlink debug output varies depending on host's endianness and therefore the test fails on Big Endian machines. Since for the sake of asserting no needless bitwise expressions in output the actual data values are not relevant, simply crop the output to just the expression names.
Quoted 6 lines
Quoted 2 lines
Probably we can fix this in libnftnl before we apply patches like this to nft as well?
You're right, ignoring the problems in nft testsuite is pretty inconsistent. OTOH this is the first test that breaks iptables testsuite on Big Endian while nft testsuite is entirely broken. ;)
Do you think we can fix this from the testsuite site? It would require to replicate payload files. The snprintf printing is used for debugging only at this stage. That would fix nft and this specific case.
Quoted 7 lines
I had a look at libnftnl and it seems like even kernel support is needed to carry the endianness info from input to output. IMHO data should be in a consistent format in netlink messages, but I fear we can't change this anymore. I tried to print the data byte-by-byte, but we obviously still get problems with any data in host byte order. Do you see an easier way to fix this than adding extra info to all expressions containing data?
Quoted 5 lines
Probably we can make assumptions based on context, such as payload expression always express things in network byte order, and annotate that such register stores something in network byteorder. For meta, assume host byte order. Unless there is an explicit byteorder expression.
I like this simple approach, but it's not easy to implement: libnftnl doesn't know about other expressions, so 'cmp' for instance doesn't know which expression stored data in reg 1 and therefore can't deduce the likely endianness of its stored data.
Any idea how to solve that?
Thanks, Phil
Pablo Neira Ayuso
maintainerQuoted 38 lines · Phil Sutter
Hi Pablo,
Quoted 29 lines · Pablo Neira Ayuso
Quoted 9 lines · Phil Sutter
Hi,
Quoted 6 lines · Pablo Neira Ayuso
Quoted 4 lines · Phil Sutter
Netlink debug output varies depending on host's endianness and therefore the test fails on Big Endian machines. Since for the sake of asserting no needless bitwise expressions in output the actual data values are not relevant, simply crop the output to just the expression names.
Quoted 6 lines
Quoted 2 lines
Probably we can fix this in libnftnl before we apply patches like this to nft as well?
You're right, ignoring the problems in nft testsuite is pretty inconsistent. OTOH this is the first test that breaks iptables testsuite on Big Endian while nft testsuite is entirely broken. ;)
Do you think we can fix this from the testsuite site? It would require to replicate payload files. The snprintf printing is used for debugging only at this stage. That would fix nft and this specific case.
Quoted 7 lines
I had a look at libnftnl and it seems like even kernel support is needed to carry the endianness info from input to output. IMHO data should be in a consistent format in netlink messages, but I fear we can't change this anymore. I tried to print the data byte-by-byte, but we obviously still get problems with any data in host byte order. Do you see an easier way to fix this than adding extra info to all expressions containing data?
Quoted 5 lines
Probably we can make assumptions based on context, such as payload expression always express things in network byte order, and annotate that such register stores something in network byteorder. For meta, assume host byte order. Unless there is an explicit byteorder expression.
Quoted 6 lines
I like this simple approach, but it's not easy to implement: libnftnl doesn't know about other expressions, so 'cmp' for instance doesn't know which expression stored data in reg 1 and therefore can't deduce the likely endianness of its stored data.
Any idea how to solve that?
Probably tracking endianess like this? See attached patch. Then, default to network byteorder in all cases when printing.
We know the key endianess for meta, ct, ... this allows to annotate this information on the register.
For "meta mark set 10", the immediate expression is used which comes _before_ the "meta mark" that provides the endianness information, this still needs to be fixed somehow.
Note also that this patch sets host byteorder for all ct keys, which is not correct. We should set the endianess based on the key.
We'll have to fix nft tests after this too.
include/common.h +15 -0
@@ -18,4 +18,19 @@ enum nftnl_parse_input { NFTNL_PARSE_FILE, }; +enum nftnl_byteorder { +NFTNL_BYTEORDER_UNSET =0 , +NFTNL_BYTEORDER_HOST , +NFTNL_BYTEORDER_NETWORK , +}; + +struct nftnl_print_ctx { +enum nftnl_byteorder byteorder[NFT_REG32_15 +1 ]; +}; + +void nftnl_print_ctx_set (struct nftnl_print_ctx *ctx,uint32_t reg, +enum nftnl_byteorder byteorder); +enum nftnl_byteorder nftnl_print_ctx_get (struct nftnl_print_ctx *ctx, +uint32_t reg); +#endif
include/data_reg.h +2 -1
@@ -5,6 +5,7 @@#include <stdint.h> #include <stdbool.h> #include <unistd.h> +#include "common.h" enum {DATA_NONE ,
@@ -28,7 +29,7 @@ union nftnl_data_reg {int nftnl_data_reg_snprintf (char *buf,size_t size,const union nftnl_data_reg *reg,uint32_t output_format,uint32_t flags, -int reg_type); +int reg_type,enum nftnl_byteorder byteorder);struct nlattr ;int nftnl_parse_data (union nftnl_data_reg *data,struct nlattr *attr,int *type);
include/expr.h +3 -1
@@ -14,6 +14,8 @@ struct nlmsghdr;void nftnl_expr_build_payload (struct nlmsghdr *nlh,struct nftnl_expr *expr);struct nftnl_expr *nftnl_expr_parse (struct nlattr *attr); - +int __nftnl_expr_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t size, +const struct nftnl_expr *expr, +uint32_t type,uint32_t flags);#endif
include/expr_ops.h +2 -1
@@ -7,6 +7,7 @@struct nlattr ;struct nlmsghdr ;struct nftnl_expr ; +struct nftnl_print_ctx ;struct expr_ops {const char *name;
@@ -17,7 +18,7 @@ struct expr_ops {const void *(*get)(const struct nftnl_expr *e,uint16_t type,uint32_t *data_len);int (*parse)(struct nftnl_expr *e,struct nlattr *attr);void (*build)(struct nlmsghdr *nlh,const struct nftnl_expr *e); -int (*snprintf)(char *buf,size_t len,uint32_t type,uint32_t flags,const struct nftnl_expr *e); +int (*snprintf)(struct nftnl_print_ctx *ctx,char *buf,size_t len,uint32_t type,uint32_t flags,const struct nftnl_expr *e); };struct expr_ops *nftnl_expr_ops_lookup (const char *name);
src/expr.c +14 -5
@@ -266,12 +266,12 @@ err1:return NULL ; } -EXPORT_SYMBOL (nftnl_expr_snprintf); -int nftnl_expr_snprintf (char *buf,size_t size,const struct nftnl_expr *expr, -uint32_t type,uint32_t flags) +int __nftnl_expr_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t size, +const struct nftnl_expr *expr, +uint32_t type,uint32_t flags) { -int ret;unsigned int offset =0 , remain = size; +int ret;if (size) buf[0 ] ='\0' ;
@@ -279,12 +279,21 @@ int nftnl_expr_snprintf(char *buf, size_t size, const struct nftnl_expr *expr,if (!expr->ops->snprintf)return 0 ; - ret = expr->ops->snprintf (buf + offset, remain, type, flags, expr); + ret = expr->ops->snprintf (ctx, buf + offset, remain, type, flags, expr);SNPRINTF_BUFFER_SIZE (ret, remain, offset);return offset; } +EXPORT_SYMBOL (nftnl_expr_snprintf); +int nftnl_expr_snprintf (char *buf,size_t size,const struct nftnl_expr *expr, +uint32_t type,uint32_t flags) +{ +struct nftnl_print_ctx ctx = {}; + +return __nftnl_expr_snprintf (&ctx, buf, size, expr, type, flags); +} +static int nftnl_expr_do_snprintf (char *buf,size_t size,const void *e,uint32_t cmd,uint32_t type,uint32_t flags) {
src/expr/bitwise.c +25 -12
@@ -210,40 +210,51 @@ nftnl_expr_bitwise_parse(struct nftnl_expr *e, struct nlattr *attr) }static int -nftnl_expr_bitwise_snprintf_bool (char *buf,size_t size, +nftnl_expr_bitwise_snprintf_bool (struct nftnl_print_ctx *ctx, +char *buf,size_t size,const struct nftnl_expr_bitwise *bitwise) {int remain = size, offset =0 , ret; +enum nftnl_byteorder byteorder; ret =snprintf (buf, remain,"reg %u = ( reg %u & " , bitwise->dreg, bitwise->sreg);SNPRINTF_BUFFER_SIZE (ret, remain, offset); + byteorder =nftnl_print_ctx_get (ctx, bitwise->sreg); + ret =nftnl_data_reg_snprintf (buf + offset, remain, &bitwise->mask, -NFTNL_OUTPUT_DEFAULT ,0 ,DATA_VALUE ); +NFTNL_OUTPUT_DEFAULT ,0 ,DATA_VALUE , + byteorder);SNPRINTF_BUFFER_SIZE (ret, remain, offset); ret =snprintf (buf + offset, remain,") ^ " );SNPRINTF_BUFFER_SIZE (ret, remain, offset); ret =nftnl_data_reg_snprintf (buf + offset, remain, &bitwise->xor, -NFTNL_OUTPUT_DEFAULT ,0 ,DATA_VALUE ); +NFTNL_OUTPUT_DEFAULT ,0 ,DATA_VALUE , + byteorder);SNPRINTF_BUFFER_SIZE (ret, remain, offset);return offset; }static int -nftnl_expr_bitwise_snprintf_shift (char *buf,size_t size,const char *op, +nftnl_expr_bitwise_snprintf_shift (struct nftnl_print_ctx *ctx, +char *buf,size_t size,const char *op,const struct nftnl_expr_bitwise *bitwise) {int remain = size, offset =0 , ret; +enum nftnl_byteorder byteorder; ret =snprintf (buf, remain,"reg %u = ( reg %u %s " , bitwise->dreg, bitwise->sreg, op);SNPRINTF_BUFFER_SIZE (ret, remain, offset); + byteorder =nftnl_print_ctx_get (ctx, bitwise->sreg); + ret =nftnl_data_reg_snprintf (buf + offset, remain, &bitwise->data, -NFTNL_OUTPUT_DEFAULT ,0 ,DATA_VALUE ); +NFTNL_OUTPUT_DEFAULT ,0 ,DATA_VALUE , + byteorder);SNPRINTF_BUFFER_SIZE (ret, remain, offset); ret =snprintf (buf + offset, remain,") " );
@@ -252,7 +263,8 @@ nftnl_expr_bitwise_snprintf_shift(char *buf, size_t size, const char *op,return offset; } -static int nftnl_expr_bitwise_snprintf_default (char *buf,size_t size, +static int nftnl_expr_bitwise_snprintf_default (struct nftnl_print_ctx *ctx, +char *buf,size_t size,const struct nftnl_expr *e) {struct nftnl_expr_bitwise *bitwise =nftnl_expr_data (e);
@@ -260,13 +272,13 @@ static int nftnl_expr_bitwise_snprintf_default(char *buf, size_t size,switch (bitwise->op) {case NFT_BITWISE_BOOL : - err =nftnl_expr_bitwise_snprintf_bool (buf, size, bitwise); + err =nftnl_expr_bitwise_snprintf_bool (ctx, buf, size, bitwise);break ;case NFT_BITWISE_LSHIFT : - err =nftnl_expr_bitwise_snprintf_shift (buf, size,"<<" , bitwise); + err =nftnl_expr_bitwise_snprintf_shift (ctx, buf, size,"<<" , bitwise);break ;case NFT_BITWISE_RSHIFT : - err =nftnl_expr_bitwise_snprintf_shift (buf, size,">>" , bitwise); + err =nftnl_expr_bitwise_snprintf_shift (ctx, buf, size,">>" , bitwise);break ; }
@@ -274,12 +286,13 @@ static int nftnl_expr_bitwise_snprintf_default(char *buf, size_t size, }static int -nftnl_expr_bitwise_snprintf (char *buf,size_t size,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_bitwise_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t size, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT : -return nftnl_expr_bitwise_snprintf_default (buf, size, e); +return nftnl_expr_bitwise_snprintf_default (ctx, buf, size, e);default :break ; }
src/expr/byteorder.c +19 -3
@@ -197,11 +197,26 @@ static inline int nftnl_str2ntoh(const char *op) } } -static int nftnl_expr_byteorder_snprintf_default (char *buf,size_t size, +static int nftnl_expr_byteorder_snprintf_default (struct nftnl_print_ctx *ctx, +char *buf,size_t size,const struct nftnl_expr *e) {struct nftnl_expr_byteorder *byteorder =nftnl_expr_data (e);int remain = size, offset =0 , ret; +enum nftnl_byteorder bo; + +switch (byteorder->op) { +case NFT_BYTEORDER_NTOH : + bo =NFTNL_BYTEORDER_HOST ; +break ; +case NFT_BYTEORDER_HTON : + bo =NFTNL_BYTEORDER_NETWORK ; +break ; +default : + bo =NFTNL_BYTEORDER_UNSET ; +break ; + } +nftnl_print_ctx_set (ctx, byteorder->dreg, bo); ret = snprintf(buf, remain, "reg %u = %s(reg %u, %u, %u) ", byteorder->dreg, bo2str(byteorder->op),
@@ -212,12 +227,13 @@ static int nftnl_expr_byteorder_snprintf_default(char *buf, size_t size, }static int -nftnl_expr_byteorder_snprintf (char *buf,size_t size,uint32_t type, +nftnl_expr_byteorder_snprintf (struct nftnl_print_ctx *ctx,char *buf, +size_t size,uint32_t type,uint32_t flags,const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT : -return nftnl_expr_byteorder_snprintf_default (buf, size, e); +return nftnl_expr_byteorder_snprintf_default (ctx, buf, size, e);case NFTNL_OUTPUT_XML :case NFTNL_OUTPUT_JSON :default :
src/expr/cmp.c +11 -5
@@ -176,30 +176,36 @@ static inline int nftnl_str2cmp(const char *op) } } -static int nftnl_expr_cmp_snprintf_default (char *buf,size_t size, +static int nftnl_expr_cmp_snprintf_default (struct nftnl_print_ctx *ctx, +char *buf,size_t size,const struct nftnl_expr *e) {struct nftnl_expr_cmp *cmp =nftnl_expr_data (e);int remain = size, offset =0 , ret; +enum nftnl_byteorder byteorder; ret =snprintf (buf, remain,"%s reg %u " ,cmp2str (cmp->op), cmp->sreg);SNPRINTF_BUFFER_SIZE (ret, remain, offset); + byteorder =nftnl_print_ctx_get (ctx, cmp->sreg); + ret =nftnl_data_reg_snprintf (buf + offset, remain, &cmp->data, -NFTNL_OUTPUT_DEFAULT ,0 ,DATA_VALUE ); +NFTNL_OUTPUT_DEFAULT ,0 ,DATA_VALUE , + byteorder);SNPRINTF_BUFFER_SIZE (ret, remain, offset);return offset; }static int -nftnl_expr_cmp_snprintf (char *buf,size_t size,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_cmp_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t size, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT : -return nftnl_expr_cmp_snprintf_default (buf, size, e); +return nftnl_expr_cmp_snprintf_default (ctx, buf, size, e);case NFTNL_OUTPUT_XML :case NFTNL_OUTPUT_JSON :default :
src/expr/connlimit.c +4 -3
@@ -126,9 +126,10 @@ static int nftnl_expr_connlimit_snprintf_default(char *buf, size_t len, connlimit->count, connlimit->flags); } -static int nftnl_expr_connlimit_snprintf (char *buf,size_t len,uint32_t type, -uint32_t flags, -const struct nftnl_expr *e) +static int nftnl_expr_connlimit_snprintf (struct nftnl_print_ctx *ctx,char *buf, +size_t len,uint32_t type, +uint32_t flags, +const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT :
src/expr/counter.c +2 -1
@@ -124,7 +124,8 @@ static int nftnl_expr_counter_snprintf_default(char *buf, size_t len, ctr->pkts, ctr->bytes); } -static int nftnl_expr_counter_snprintf (char *buf,size_t len,uint32_t type, +static int nftnl_expr_counter_snprintf (struct nftnl_print_ctx *ctx,char *buf, +size_t len,uint32_t type,uint32_t flags,const struct nftnl_expr *e) {
src/expr/ct.c +8 -5
@@ -223,19 +223,21 @@ static inline int str2ctdir(const char *str, uint8_t *ctdir) }static int -nftnl_expr_ct_snprintf_default (char *buf,size_t size, -const struct nftnl_expr *e) +nftnl_expr_ct_snprintf_default (struct nftnl_print_ctx *ctx,char *buf, +size_t size,const struct nftnl_expr *e) {int ret, remain = size, offset =0 ;struct nftnl_expr_ct *ct =nftnl_expr_data (e);if (e->flags & (1 <<NFTNL_EXPR_CT_SREG )) { +nftnl_print_ctx_set (ctx, ct->sreg,NFTNL_BYTEORDER_HOST ); ret =snprintf (buf, size,"set %s with reg %u " ,ctkey2str (ct->key), ct->sreg);SNPRINTF_BUFFER_SIZE (ret, remain, offset); }if (e->flags & (1 <<NFTNL_EXPR_CT_DREG )) { +nftnl_print_ctx_set (ctx, ct->dreg,NFTNL_BYTEORDER_HOST ); ret =snprintf (buf, remain,"load %s => reg %u " ,ctkey2str (ct->key), ct->dreg);SNPRINTF_BUFFER_SIZE (ret, remain, offset);
@@ -251,12 +253,13 @@ nftnl_expr_ct_snprintf_default(char *buf, size_t size, }static int -nftnl_expr_ct_snprintf (char *buf,size_t len,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_ct_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t len, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT : -return nftnl_expr_ct_snprintf_default (buf, len, e); +return nftnl_expr_ct_snprintf_default (ctx, buf, len, e);case NFTNL_OUTPUT_XML :case NFTNL_OUTPUT_JSON :default :
src/expr/data_reg.c +12 -4
@@ -27,12 +27,19 @@static int nftnl_data_reg_value_snprintf_default (char *buf,size_t size,const union nftnl_data_reg *reg, -uint32_t flags) +uint32_t flags, +enum nftnl_byteorder byteorder) {int remain = size, offset =0 , ret, i; +uint32_t value;for (i =0 ; i <div_round_up (reg->len,sizeof (uint32_t )); i++) { - ret =snprintf (buf + offset, remain,"0x%.8x " , reg->val[i]); +if (byteorder ==NFTNL_BYTEORDER_HOST ) + value =htonl (reg->val[i]); +else + value = reg->val[i]; + + ret =snprintf (buf + offset, remain,"0x%.8x " , value);SNPRINTF_BUFFER_SIZE (ret, remain, offset); }
@@ -60,14 +67,15 @@ nftnl_data_reg_verdict_snprintf_def(char *buf, size_t size,int nftnl_data_reg_snprintf (char *buf,size_t size,const union nftnl_data_reg *reg,uint32_t output_format,uint32_t flags, -int reg_type) +int reg_type,enum nftnl_byteorder byteorder) {switch (reg_type) {case DATA_VALUE :switch (output_format) {case NFTNL_OUTPUT_DEFAULT :return nftnl_data_reg_value_snprintf_default (buf, size, - reg, flags); + reg, flags, + byteorder);case NFTNL_OUTPUT_JSON :case NFTNL_OUTPUT_XML :default :
src/expr/dup.c +2 -1
@@ -131,7 +131,8 @@ static int nftnl_expr_dup_snprintf_default(char *buf, size_t len,return offset; } -static int nftnl_expr_dup_snprintf (char *buf,size_t len,uint32_t type, +static int nftnl_expr_dup_snprintf (struct nftnl_print_ctx *ctx,char *buf, +size_t len,uint32_t type,uint32_t flags,const struct nftnl_expr *e) {switch (type) {
src/expr/dynset.c +3 -2
@@ -258,8 +258,9 @@ nftnl_expr_dynset_snprintf_default(char *buf, size_t size, }static int -nftnl_expr_dynset_snprintf (char *buf,size_t size,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_dynset_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t size, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT :
src/expr/exthdr.c +3 -2
@@ -254,8 +254,9 @@ static int nftnl_expr_exthdr_snprintf_default(char *buf, size_t len, }static int -nftnl_expr_exthdr_snprintf (char *buf,size_t len,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_exthdr_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t len, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT :
src/expr/fib.c +3 -2
@@ -191,8 +191,9 @@ nftnl_expr_fib_snprintf_default(char *buf, size_t size, }static int -nftnl_expr_fib_snprintf (char *buf,size_t len,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_fib_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t len, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT :
src/expr/flow_offload.c +2 -1
@@ -104,7 +104,8 @@ static int nftnl_expr_flow_snprintf_default(char *buf, size_t size,return offset; } -static int nftnl_expr_flow_snprintf (char *buf,size_t size,uint32_t type, +static int nftnl_expr_flow_snprintf (struct nftnl_print_ctx *ctx,char *buf, +size_t size,uint32_t type,uint32_t flags,const struct nftnl_expr *e) {switch (type) {
src/expr/fwd.c +2 -1
@@ -151,7 +151,8 @@ static int nftnl_expr_fwd_snprintf_default(char *buf, size_t len,return offset; } -static int nftnl_expr_fwd_snprintf (char *buf,size_t len,uint32_t type, +static int nftnl_expr_fwd_snprintf (struct nftnl_print_ctx *ctx,char *buf, +size_t len,uint32_t type,uint32_t flags,const struct nftnl_expr *e) {switch (type) {
src/expr/hash.c +3 -2
@@ -219,8 +219,9 @@ nftnl_expr_hash_snprintf_default(char *buf, size_t size, }static int -nftnl_expr_hash_snprintf (char *buf,size_t len,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_hash_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t len, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT :
src/expr/immediate.c +12 -7
@@ -184,29 +184,33 @@ nftnl_expr_immediate_parse(struct nftnl_expr *e, struct nlattr *attr) }static int -nftnl_expr_immediate_snprintf_default (char *buf,size_t len, +nftnl_expr_immediate_snprintf_default (struct nftnl_print_ctx *ctx, +char *buf,size_t len,const struct nftnl_expr *e,uint32_t flags) { -int remain = len, offset =0 , ret;struct nftnl_expr_immediate *imm =nftnl_expr_data (e); +int remain = len, offset =0 , ret; ret =snprintf (buf, remain,"reg %u " , imm->dreg);SNPRINTF_BUFFER_SIZE (ret, remain, offset);if (e->flags & (1 <<NFTNL_EXPR_IMM_DATA )) { ret =nftnl_data_reg_snprintf (buf + offset, remain, &imm->data, -NFTNL_OUTPUT_DEFAULT , flags,DATA_VALUE ); +NFTNL_OUTPUT_DEFAULT , flags,DATA_VALUE , +NFTNL_BYTEORDER_UNSET );SNPRINTF_BUFFER_SIZE (ret, remain, offset); }else if (e->flags & (1 <<NFTNL_EXPR_IMM_VERDICT )) { ret =nftnl_data_reg_snprintf (buf + offset, remain, &imm->data, -NFTNL_OUTPUT_DEFAULT , flags,DATA_VERDICT ); +NFTNL_OUTPUT_DEFAULT , flags,DATA_VERDICT , +NFTNL_BYTEORDER_UNSET );SNPRINTF_BUFFER_SIZE (ret, remain, offset); }else if (e->flags & (1 <<NFTNL_EXPR_IMM_CHAIN )) { ret =nftnl_data_reg_snprintf (buf + offset, remain, &imm->data, -NFTNL_OUTPUT_DEFAULT , flags,DATA_CHAIN ); +NFTNL_OUTPUT_DEFAULT , flags,DATA_CHAIN , +NFTNL_BYTEORDER_UNSET );SNPRINTF_BUFFER_SIZE (ret, remain, offset); }
@@ -214,12 +218,13 @@ nftnl_expr_immediate_snprintf_default(char *buf, size_t len, }static int -nftnl_expr_immediate_snprintf (char *buf,size_t len,uint32_t type, +nftnl_expr_immediate_snprintf (struct nftnl_print_ctx *ctx,char *buf, +size_t len,uint32_t type,uint32_t flags,const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT : -return nftnl_expr_immediate_snprintf_default (buf, len, e, flags); +return nftnl_expr_immediate_snprintf_default (ctx, buf, len, e, flags);case NFTNL_OUTPUT_XML :case NFTNL_OUTPUT_JSON :default :
src/expr/limit.c +3 -2
@@ -194,8 +194,9 @@ static int nftnl_expr_limit_snprintf_default(char *buf, size_t len, }static int -nftnl_expr_limit_snprintf (char *buf,size_t len,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_limit_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t len, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT :
src/expr/log.c +3 -2
@@ -237,8 +237,9 @@ static int nftnl_expr_log_snprintf_default(char *buf, size_t size, }static int -nftnl_expr_log_snprintf (char *buf,size_t len,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_log_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t len, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT :
src/expr/lookup.c +6 -4
@@ -168,7 +168,8 @@ nftnl_expr_lookup_parse(struct nftnl_expr *e, struct nlattr *attr) }static int -nftnl_expr_lookup_snprintf_default (char *buf,size_t size, +nftnl_expr_lookup_snprintf_default (struct nftnl_print_ctx *ctx, +char *buf,size_t size,const struct nftnl_expr *e) {int remain = size, offset =0 , ret;
@@ -191,12 +192,13 @@ nftnl_expr_lookup_snprintf_default(char *buf, size_t size, }static int -nftnl_expr_lookup_snprintf (char *buf,size_t size,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_lookup_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t size, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT : -return nftnl_expr_lookup_snprintf_default (buf, size, e); +return nftnl_expr_lookup_snprintf_default (ctx, buf, size, e);case NFTNL_OUTPUT_XML :case NFTNL_OUTPUT_JSON :default :
src/expr/masq.c +2 -1
@@ -151,7 +151,8 @@ static int nftnl_expr_masq_snprintf_default(char *buf, size_t len,return offset; } -static int nftnl_expr_masq_snprintf (char *buf,size_t len,uint32_t type, +static int nftnl_expr_masq_snprintf (struct nftnl_print_ctx *ctx,char *buf, +size_t len,uint32_t type,uint32_t flags,const struct nftnl_expr *e) {switch (type) {
src/expr/match.c +3 -2
@@ -165,8 +165,9 @@ static int nftnl_expr_match_parse(struct nftnl_expr *e, struct nlattr *attr) }static int -nftnl_expr_match_snprintf (char *buf,size_t len,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_match_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t len, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {struct nftnl_expr_match *match =nftnl_expr_data (e);
src/expr/meta.c +8 -5
@@ -192,16 +192,18 @@ static inline int str2meta_key(const char *str) }static int -nftnl_expr_meta_snprintf_default (char *buf,size_t len, -const struct nftnl_expr *e) +nftnl_expr_meta_snprintf_default (struct nftnl_print_ctx *ctx,char *buf, +size_t len,const struct nftnl_expr *e) {struct nftnl_expr_meta *meta =nftnl_expr_data (e);if (e->flags & (1 <<NFTNL_EXPR_META_SREG )) { +nftnl_print_ctx_set (ctx, meta->sreg,NFTNL_BYTEORDER_HOST );return snprintf (buf, len,"set %s with reg %u " ,meta_key2str (meta->key), meta->sreg); }if (e->flags & (1 <<NFTNL_EXPR_META_DREG )) { +nftnl_print_ctx_set (ctx, meta->dreg,NFTNL_BYTEORDER_HOST );return snprintf (buf, len,"load %s => reg %u " ,meta_key2str (meta->key), meta->dreg); }
@@ -209,12 +211,13 @@ nftnl_expr_meta_snprintf_default(char *buf, size_t len, }static int -nftnl_expr_meta_snprintf (char *buf,size_t len,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_meta_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t len, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT : -return nftnl_expr_meta_snprintf_default (buf, len, e); +return nftnl_expr_meta_snprintf_default (ctx, buf, len, e);case NFTNL_OUTPUT_XML :case NFTNL_OUTPUT_JSON :default :
src/expr/nat.c +3 -2
@@ -257,8 +257,9 @@ nftnl_expr_nat_snprintf_default(char *buf, size_t size, }static int -nftnl_expr_nat_snprintf (char *buf,size_t size,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_nat_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t size, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT :
src/expr/numgen.c +3 -2
@@ -173,8 +173,9 @@ nftnl_expr_ng_snprintf_default(char *buf, size_t size, }static int -nftnl_expr_ng_snprintf (char *buf,size_t len,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_ng_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t len, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT :
src/expr/objref.c +3 -2
@@ -195,8 +195,9 @@ static void nftnl_expr_objref_free(const struct nftnl_expr *e)xfree (objref->set.name); } -static int nftnl_expr_objref_snprintf (char *buf,size_t len,uint32_t type, -uint32_t flags, +static int nftnl_expr_objref_snprintf (struct nftnl_print_ctx *ctx, +char *buf,size_t len, +uint32_t type,uint32_t flags,const struct nftnl_expr *e) {switch (type) {
src/expr/osf.c +6 -4
@@ -124,7 +124,8 @@ nftnl_expr_osf_parse(struct nftnl_expr *e, struct nlattr *attr)return 0 ; } -static int nftnl_expr_osf_snprintf_default (char *buf,size_t size, +static int nftnl_expr_osf_snprintf_default (struct nftnl_print_ctx *ctx, +char *buf,size_t size,const struct nftnl_expr *e) {struct nftnl_expr_osf *osf =nftnl_expr_data (e);
@@ -139,12 +140,13 @@ static int nftnl_expr_osf_snprintf_default(char *buf, size_t size, }static int -nftnl_expr_osf_snprintf (char *buf,size_t len,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_osf_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t len, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT : -return nftnl_expr_osf_snprintf_default (buf, len, e); +return nftnl_expr_osf_snprintf_default (ctx, buf, len, e);case NFTNL_OUTPUT_XML :case NFTNL_OUTPUT_JSON :default :
src/expr/payload.c +3 -2
@@ -232,8 +232,9 @@ static inline int nftnl_str2base(const char *base) }static int -nftnl_expr_payload_snprintf (char *buf,size_t len,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_payload_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t len, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {struct nftnl_expr_payload *payload =nftnl_expr_data (e);
src/expr/queue.c +6 -4
@@ -143,7 +143,8 @@ nftnl_expr_queue_parse(struct nftnl_expr *e, struct nlattr *attr)return 0 ; } -static int nftnl_expr_queue_snprintf_default (char *buf,size_t len, +static int nftnl_expr_queue_snprintf_default (struct nftnl_print_ctx *ctx, +char *buf,size_t len,const struct nftnl_expr *e) {struct nftnl_expr_queue *queue =nftnl_expr_data (e);
@@ -185,12 +186,13 @@ static int nftnl_expr_queue_snprintf_default(char *buf, size_t len, }static int -nftnl_expr_queue_snprintf (char *buf,size_t len,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_queue_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t len, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT : -return nftnl_expr_queue_snprintf_default (buf, len, e); +return nftnl_expr_queue_snprintf_default (ctx, buf, len, e);case NFTNL_OUTPUT_XML :case NFTNL_OUTPUT_JSON :default :
src/expr/quota.c +4 -3
@@ -138,9 +138,10 @@ static int nftnl_expr_quota_snprintf_default(char *buf, size_t len, quota->bytes, quota->consumed, quota->flags); } -static int nftnl_expr_quota_snprintf (char *buf,size_t len,uint32_t type, -uint32_t flags, -const struct nftnl_expr *e) +static int nftnl_expr_quota_snprintf (struct nftnl_print_ctx *ctx, +char *buf,size_t len,uint32_t type, +uint32_t flags, +const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT :
src/expr/range.c +17 -8
@@ -184,33 +184,42 @@ static inline int nftnl_str2range(const char *op) } } -static int nftnl_expr_range_snprintf_default (char *buf,size_t size, -const struct nftnl_expr *e) +static int nftnl_expr_range_snprintf_default (struct nftnl_print_ctx *ctx, +char *buf,size_t size, +const struct nftnl_expr *e) {struct nftnl_expr_range *range =nftnl_expr_data (e);int remain = size, offset =0 , ret; +enum nftnl_byteorder byteorder; ret =snprintf (buf, remain,"%s reg %u " ,range2str (range->op), range->sreg);SNPRINTF_BUFFER_SIZE (ret, remain, offset); - ret =nftnl_data_reg_snprintf (buf + offset, remain, &range->data_from, -NFTNL_OUTPUT_DEFAULT ,0 ,DATA_VALUE ); + byteorder =nftnl_print_ctx_get (ctx, range->sreg); + + ret =nftnl_data_reg_snprintf (buf + offset, remain, + &range->data_from, +NFTNL_OUTPUT_DEFAULT ,0 ,DATA_VALUE , + byteorder);SNPRINTF_BUFFER_SIZE (ret, remain, offset); - ret =nftnl_data_reg_snprintf (buf + offset, remain, &range->data_to, -NFTNL_OUTPUT_DEFAULT ,0 ,DATA_VALUE ); + ret =nftnl_data_reg_snprintf (buf + offset, remain, + &range->data_to, +NFTNL_OUTPUT_DEFAULT ,0 ,DATA_VALUE , + byteorder);SNPRINTF_BUFFER_SIZE (ret, remain, offset);return offset; } -static int nftnl_expr_range_snprintf (char *buf,size_t size,uint32_t type, +static int nftnl_expr_range_snprintf (struct nftnl_print_ctx *ctx, +char *buf,size_t size,uint32_t type,uint32_t flags,const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT : -return nftnl_expr_range_snprintf_default (buf, size, e); +return nftnl_expr_range_snprintf_default (ctx, buf, size, e);case NFTNL_OUTPUT_XML :case NFTNL_OUTPUT_JSON :default :
src/expr/redir.c +6 -4
@@ -131,7 +131,8 @@ nftnl_expr_redir_parse(struct nftnl_expr *e, struct nlattr *attr)return 0 ; } -static int nftnl_expr_redir_snprintf_default (char *buf,size_t len, +static int nftnl_expr_redir_snprintf_default (struct nftnl_print_ctx *ctx, +char *buf,size_t len,const struct nftnl_expr *e) {int ret, remain = len, offset =0 ;
@@ -159,12 +160,13 @@ static int nftnl_expr_redir_snprintf_default(char *buf, size_t len, }static int -nftnl_expr_redir_snprintf (char *buf,size_t len,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_redir_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t len, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT : -return nftnl_expr_redir_snprintf_default (buf, len, e); +return nftnl_expr_redir_snprintf_default (ctx, buf, len, e);case NFTNL_OUTPUT_XML :case NFTNL_OUTPUT_JSON :default :
src/expr/reject.c +3 -2
@@ -126,8 +126,9 @@ static int nftnl_expr_reject_snprintf_default(char *buf, size_t len, }static int -nftnl_expr_reject_snprintf (char *buf,size_t len,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_reject_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t len, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT :
src/expr/rt.c +6 -4
@@ -142,7 +142,8 @@ static inline int str2rt_key(const char *str) }static int -nftnl_expr_rt_snprintf_default (char *buf,size_t len, +nftnl_expr_rt_snprintf_default (struct nftnl_print_ctx *ctx, +char *buf,size_t len,const struct nftnl_expr *e) {struct nftnl_expr_rt *rt =nftnl_expr_data (e);
@@ -155,12 +156,13 @@ nftnl_expr_rt_snprintf_default(char *buf, size_t len, }static int -nftnl_expr_rt_snprintf (char *buf,size_t len,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_rt_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t len, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT : -return nftnl_expr_rt_snprintf_default (buf, len, e); +return nftnl_expr_rt_snprintf_default (ctx, buf, len, e);case NFTNL_OUTPUT_XML :case NFTNL_OUTPUT_JSON :default :
src/expr/socket.c +7 -5
@@ -140,8 +140,9 @@ static inline int str2socket_key(const char *str) }static int -nftnl_expr_socket_snprintf_default (char *buf,size_t len, -const struct nftnl_expr *e) +nftnl_expr_socket_snprintf_default (struct nftnl_print_ctx *ctx, +char *buf,size_t len, +const struct nftnl_expr *e) {struct nftnl_expr_socket *socket =nftnl_expr_data (e);
@@ -153,12 +154,13 @@ nftnl_expr_socket_snprintf_default(char *buf, size_t len, }static int -nftnl_expr_socket_snprintf (char *buf,size_t len,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_socket_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t len, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT : -return nftnl_expr_socket_snprintf_default (buf, len, e); +return nftnl_expr_socket_snprintf_default (ctx, buf, len, e);case NFTNL_OUTPUT_XML :case NFTNL_OUTPUT_JSON :default :
src/expr/synproxy.c +3 -2
@@ -144,8 +144,9 @@ static int nftnl_expr_synproxy_snprintf_default(char *buf, size_t size, }static int -nftnl_expr_synproxy_snprintf (char *buf,size_t len,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_synproxy_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t len, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT :
src/expr/target.c +3 -2
@@ -165,8 +165,9 @@ static int nftnl_expr_target_parse(struct nftnl_expr *e, struct nlattr *attr) }static int -nftnl_expr_target_snprintf (char *buf,size_t len,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_target_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t len, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {struct nftnl_expr_target *target =nftnl_expr_data (e);
src/expr/tproxy.c +3 -2
@@ -163,8 +163,9 @@ nftnl_expr_tproxy_snprintf_default(char *buf, size_t size, }static int -nftnl_expr_tproxy_snprintf (char *buf,size_t size,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_tproxy_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t size, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT :
src/expr/tunnel.c +7 -5
@@ -138,8 +138,9 @@ static inline int str2tunnel_key(const char *str) }static int -nftnl_expr_tunnel_snprintf_default (char *buf,size_t len, -const struct nftnl_expr *e) +nftnl_expr_tunnel_snprintf_default (struct nftnl_print_ctx *ctx, +char *buf,size_t len, +const struct nftnl_expr *e) {struct nftnl_expr_tunnel *tunnel =nftnl_expr_data (e);
@@ -151,12 +152,13 @@ nftnl_expr_tunnel_snprintf_default(char *buf, size_t len, }static int -nftnl_expr_tunnel_snprintf (char *buf,size_t len,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_tunnel_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t len, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT : -return nftnl_expr_tunnel_snprintf_default (buf, len, e); +return nftnl_expr_tunnel_snprintf_default (ctx, buf, len, e);case NFTNL_OUTPUT_XML :case NFTNL_OUTPUT_JSON :default :
src/expr/xfrm.c +7 -5
@@ -200,8 +200,9 @@ static int str2xfmrdir(const char *s)#endif static int -nftnl_expr_xfrm_snprintf_default (char *buf,size_t size, -const struct nftnl_expr *e) +nftnl_expr_xfrm_snprintf_default (struct nftnl_print_ctx *ctx, +char *buf,size_t size, +const struct nftnl_expr *e) {struct nftnl_expr_xfrm *x =nftnl_expr_data (e);int ret, remain = size, offset =0 ;
@@ -217,12 +218,13 @@ nftnl_expr_xfrm_snprintf_default(char *buf, size_t size, }static int -nftnl_expr_xfrm_snprintf (char *buf,size_t len,uint32_t type, -uint32_t flags,const struct nftnl_expr *e) +nftnl_expr_xfrm_snprintf (struct nftnl_print_ctx *ctx,char *buf,size_t len, +uint32_t type,uint32_t flags, +const struct nftnl_expr *e) {switch (type) {case NFTNL_OUTPUT_DEFAULT : -return nftnl_expr_xfrm_snprintf_default (buf, len, e); +return nftnl_expr_xfrm_snprintf_default (ctx, buf, len, e);case NFTNL_OUTPUT_XML :case NFTNL_OUTPUT_JSON :default :
src/rule.c +30 -8
@@ -545,7 +545,26 @@ int nftnl_rule_parse_file(struct nftnl_rule *r, enum nftnl_parse_type type,return nftnl_rule_do_parse (r, type, fp, err,NFTNL_PARSE_FILE ); } -static int nftnl_rule_snprintf_default (char *buf,size_t size, +void nftnl_print_ctx_set (struct nftnl_print_ctx *ctx,uint32_t reg, +enum nftnl_byteorder byteorder) +{ +if (reg >NFT_REG32_15 ) +return ; + + ctx->byteorder[reg] = byteorder; +} + +enum nftnl_byteorder nftnl_print_ctx_get (struct nftnl_print_ctx *ctx, +uint32_t reg) +{ +if (reg >NFT_REG32_15 ) +return NFTNL_BYTEORDER_HOST ; + +return ctx->byteorder[reg]; +} + +static int nftnl_rule_snprintf_default (struct nftnl_print_ctx *ctx, +char *buf,size_t size,const struct nftnl_rule *r,uint32_t type,uint32_t flags) {
@@ -598,8 +617,8 @@ static int nftnl_rule_snprintf_default(char *buf, size_t size, ret =snprintf (buf + offset, remain," [ %s " , expr->ops->name);SNPRINTF_BUFFER_SIZE (ret, remain, offset); - ret =nftnl_expr_snprintf (buf + offset, remain, expr, - type, flags); + ret =__nftnl_expr_snprintf (ctx, buf + offset, remain, expr, + type, flags);SNPRINTF_BUFFER_SIZE (ret, remain, offset); ret =snprintf (buf + offset, remain,"]\n" );
@@ -626,7 +645,8 @@ static int nftnl_rule_snprintf_default(char *buf, size_t size,return offset; } -static int nftnl_rule_cmd_snprintf (char *buf,size_t size, +static int nftnl_rule_cmd_snprintf (struct nftnl_print_ctx *ctx, +char *buf,size_t size,const struct nftnl_rule *r,uint32_t cmd,uint32_t type,uint32_t flags) {
@@ -637,8 +657,8 @@ static int nftnl_rule_cmd_snprintf(char *buf, size_t size,switch (type) {case NFTNL_OUTPUT_DEFAULT : - ret =nftnl_rule_snprintf_default (buf + offset, remain, r, type, - inner_flags); + ret =nftnl_rule_snprintf_default (ctx, buf + offset, remain, + r, type, inner_flags);SNPRINTF_BUFFER_SIZE (ret, remain, offset);break ;case NFTNL_OUTPUT_JSON :
@@ -654,11 +674,13 @@ EXPORT_SYMBOL(nftnl_rule_snprintf);int nftnl_rule_snprintf (char *buf,size_t size,const struct nftnl_rule *r,uint32_t type,uint32_t flags) { +struct nftnl_print_ctx ctx = {}; +if (size) buf[0 ] ='\0' ; -return nftnl_rule_cmd_snprintf (buf, size, r,nftnl_flag2cmd (flags), type, - flags); +return nftnl_rule_cmd_snprintf (&ctx, buf, size, r, +nftnl_flag2cmd (flags), type, flags); } static int nftnl_rule_do_snprintf(char *buf, size_t size, const void *r,