Skip to contentSkip to conversation

Fix netlink debug output on Big Endian

PATCH Superseded Phil Sutter 3 participants 53 messages Oct 23, 2025 – Oct 30, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

cover Fix netlink debug output on Big Endian

Make use of recent changes to libnftnl and make tests/py testsuite pass on Big Endian systems.

Patches 1-7 fix existing code, are valid without the remaining ones but required for the target at hand.

Patches 8-12 are a mixture of fixes and preparation for the remaining ones.

Patches 13-15 change the defined byteorder for all string-based expressions to BYTEORDER_BIG_ENDIAN. This avoids special casing when communicating data reg byteorder to libnftnl as they should be printed left to right, just like with Big Endian values.

Patches 16-21 contain the required changes correcting netlink debug output.

Patches 22 and 23 change how concatenations are linearized before comparison for set element sorting. Aside from unifying results between Little and Big Endian, sorting order now seems "correct" to a human reader.

Patches 24 and 25 Introduce a tool to refresh stored payload records in py test suite and record the tool's results.

Patch 26 adds expr_print_debug() macro easing "printf debugging" around expression use.

Patches 27 and 28 finally fix for BUG() messages missing a terminating newline at times.

Phil Sutter (28):
datatype: Fix boolean type on Big Endian
optimize: Fix verdict expression comparison
tests: py: any/tcpopt.t.json: Fix JSON equivalent
tests: py: any/ct.t.json.output: Drop leftover entry
tests: py: inet/osf.t: Fix element ordering in JSON equivalents
tests: py: Fix for using wrong payload path
tests: py: Implement payload_record()
tests: py: Do not rely upon '[end]' marker
netlink: No need to reference array when passing as pointer
datatype: Increase symbolic constant printer robustness
tests: py: ip6/vmap.t: Drop double whitespace in rule
netlink: Zero nft_data_linearize objects when populating Define string-based data types as Big Endian
segtree: No byteorder conversion for string prefix len calculation Fix byteorder conversion of concatenated value expressions and ranges
expression: Set range expression 'len' field
segtree: Export complete data before editing
segtree: Drop problematic constant expr len adjustment
netlink: Introduce struct nft_data_linearize::byteorder
netlink: Introduce struct nft_data_linearize::sizes
netlink: Make use of nftnl_{expr,set_elem}_set_imm()
mergesort: Linearize concatentations in network byte order
tests: Adjust JSON records to improved element sorting
tests: py: tools: Add regen_payloads.sh
tests: py: Update payload records
utils: Introduce expr_print_debug()
utils: Cover for missing newline after BUG() messages
Drop no longer needed newline in BUG() messages

 include/netlink.h                             |   2 +
 include/utils.h                               |  11 +-
 src/ct.c                                      |   2 +-
 src/datatype.c                                |  28 +-
 src/erec.c                                    |   2 +-
 src/evaluate.c                                |  65 +--
 src/expression.c                              |   7 +-
 src/fib.c                                     |   7 +-
 src/intervals.c                               |  23 +-
 src/json.c                                    |   6 +-
 src/mergesort.c                               |   6 +-
 src/meta.c                                    |  16 +-
 src/mnl.c                                     |  10 +-
 src/netlink.c                                 |  84 +++-
 src/netlink_delinearize.c                     |  25 +-
 src/netlink_linearize.c                       |  62 +--
 src/optimize.c                                |  13 +-
 src/osf.c                                     |   3 +-
 src/parser_bison.y                            |  10 +-
 src/parser_json.c                             |   4 +-
 src/rule.c                                    |  20 +-
 src/segtree.c                                 |  25 +-
 src/statement.c                               |   2 +-
 tests/py/any/ct.t.json.output                 |  51 +-
 tests/py/any/ct.t.payload                     |  89 ++--
 tests/py/any/meta.t.json.output               |  54 ---
 tests/py/any/meta.t.payload                   | 232 ++++-----
 tests/py/any/meta.t.payload.bridge            |  10 +-
 tests/py/any/queue.t.json.output              |   4 +-
 tests/py/any/queue.t.payload                  |   2 +-
 tests/py/any/rawpayload.t.payload             |  64 +--
 tests/py/any/rt.t.payload                     |   5 +-
 tests/py/any/tcpopt.t.json                    |  24 +-
 tests/py/any/tcpopt.t.json.output             |   1 -
 tests/py/any/tcpopt.t.payload                 |  88 ++--
 tests/py/arp/arp.t.payload                    |  99 ++--
 tests/py/arp/arp.t.payload.netdev             | 189 ++++----
 tests/py/bridge/ether.t.payload               |  43 +-
 tests/py/bridge/icmpX.t.payload               |  25 +-
 tests/py/bridge/meta.t.payload                |  20 +-
 tests/py/bridge/redirect.t.payload            |   2 +-
 tests/py/bridge/reject.t.payload              |  43 +-
 tests/py/bridge/vlan.t.payload                | 262 +++++------
 tests/py/bridge/vlan.t.payload.netdev         | 316 ++++++-------
 tests/py/inet/ah.t.payload                    |  89 ++--
 tests/py/inet/comp.t.payload                  |  53 ++-
 tests/py/inet/ct.t.payload                    |  14 +-
 tests/py/inet/dccp.t.payload                  |  53 ++-
 tests/py/inet/dnat.t.payload                  |  47 +-
 tests/py/inet/esp.t.payload                   |  45 +-
 tests/py/inet/ether-ip.t.payload              |  22 +-
 tests/py/inet/ether-ip.t.payload.netdev       |  23 +-
 tests/py/inet/ether.t.payload                 |  37 +-
 tests/py/inet/ether.t.payload.bridge          |  29 +-
 tests/py/inet/ether.t.payload.ip              |  37 +-
 tests/py/inet/fib.t.payload                   |  12 +-
 tests/py/inet/geneve.t.payload                |  83 ++--
 tests/py/inet/gre.t.payload                   |  53 ++-
 tests/py/inet/gretap.t.payload                |  59 ++-
 tests/py/inet/icmp.t.payload                  |  37 +-
 tests/py/inet/icmpX.t.payload                 |  32 +-
 tests/py/inet/ip.t.payload                    |   4 +-
 tests/py/inet/ip.t.payload.bridge             |   4 +-
 tests/py/inet/ip.t.payload.inet               |   7 +-
 tests/py/inet/ip.t.payload.netdev             |   7 +-
 tests/py/inet/ip_tcp.t.payload                |  36 +-
 tests/py/inet/ip_tcp.t.payload.bridge         |  35 +-
 tests/py/inet/ip_tcp.t.payload.netdev         |  37 +-
 tests/py/inet/ipsec.t.payload                 |  11 +-
 tests/py/inet/map.t.payload                   |  11 +-
 tests/py/inet/map.t.payload.ip                |   7 +-
 tests/py/inet/map.t.payload.netdev            |  11 +-
 tests/py/inet/meta.t.payload                  |  83 ++--
 tests/py/inet/osf.t.json                      |  12 +-
 tests/py/inet/osf.t.json.output               | 107 +++++
 tests/py/inet/osf.t.payload                   |  16 +-
 tests/py/inet/payloadmerge.t.payload          |  43 +-
 tests/py/inet/reject.t.payload.inet           |  43 +-
 tests/py/inet/rt.t.payload                    |   7 +-
 tests/py/inet/sctp.t.payload                  | 159 ++++---
 tests/py/inet/sets.t.payload.bridge           |  15 +-
 tests/py/inet/sets.t.payload.inet             |  14 +-
 tests/py/inet/sets.t.payload.netdev           |  14 +-
 tests/py/inet/snat.t.payload                  |  30 +-
 tests/py/inet/socket.t.payload                |   8 +-
 tests/py/inet/tcp.t.payload                   | 360 +++++++-------
 tests/py/inet/tproxy.t.payload                |  45 +-
 tests/py/inet/udp.t.payload                   | 112 ++---
 tests/py/inet/udplite.t.payload               |  81 ++--
 tests/py/inet/vmap.t.payload                  |  13 +-
 tests/py/inet/vmap.t.payload.netdev           |  13 +-
 tests/py/inet/vxlan.t.payload                 |  83 ++--
 tests/py/ip/ct.t.payload                      |  46 +-
 tests/py/ip/dnat.t.payload.ip                 | 117 +++--
 tests/py/ip/dup.t.payload                     |   7 +-
 tests/py/ip/ether.t.payload                   |  37 +-
 tests/py/ip/hash.t.payload                    |   2 +-
 tests/py/ip/icmp.t.payload.ip                 | 312 ++++++-------
 tests/py/ip/igmp.t.payload                    |  61 ++-
 tests/py/ip/ip.t.payload                      | 246 +++++-----
 tests/py/ip/ip.t.payload.bridge               | 440 +++++++++---------
 tests/py/ip/ip.t.payload.inet                 | 440 +++++++++---------
 tests/py/ip/ip.t.payload.netdev               | 434 ++++++++---------
 tests/py/ip/ip_tcp.t.payload                  |   9 +-
 tests/py/ip/masquerade.t.payload              |  71 ++-
 tests/py/ip/meta.t.payload                    |  32 +-
 tests/py/ip/numgen.t.payload                  |   4 +-
 tests/py/ip/objects.t.payload                 |  26 +-
 tests/py/ip/redirect.t.payload                | 121 +++--
 tests/py/ip/reject.t.payload                  |   3 +-
 tests/py/ip/rt.t.payload                      |   3 +-
 tests/py/ip/sets.t.payload.inet               |  38 +-
 tests/py/ip/sets.t.payload.ip                 |  12 +-
 tests/py/ip/sets.t.payload.netdev             |  38 +-
 tests/py/ip/snat.t.payload                    |  74 +--
 tests/py/ip/tcp.t.payload                     |  11 +-
 tests/py/ip/tproxy.t.payload                  |  29 +-
 tests/py/ip6/ct.t.payload                     |  12 +-
 tests/py/ip6/dnat.t.payload.ip6               |  38 +-
 tests/py/ip6/dst.t.payload.inet               |  60 +--
 tests/py/ip6/dst.t.payload.ip6                |  30 +-
 tests/py/ip6/dup.t.payload                    |   7 +-
 tests/py/ip6/ether.t.payload                  |  36 +-
 tests/py/ip6/exthdr.t.payload.ip6             |  25 +-
 tests/py/ip6/frag.t.payload.inet              | 131 +++---
 tests/py/ip6/frag.t.payload.ip6               |  75 ++-
 tests/py/ip6/frag.t.payload.netdev            | 131 +++---
 tests/py/ip6/hbh.t.payload.inet               |  65 ++-
 tests/py/ip6/hbh.t.payload.ip6                |  33 +-
 tests/py/ip6/icmpv6.t.payload.ip6             | 322 ++++++-------
 tests/py/ip6/ip6.t.payload.inet               | 359 +++++++-------
 tests/py/ip6/ip6.t.payload.ip6                | 191 ++++----
 tests/py/ip6/map.t.payload                    |   5 +-
 tests/py/ip6/masquerade.t.payload.ip6         |  71 ++-
 tests/py/ip6/meta.t.payload                   |  36 +-
 tests/py/ip6/mh.t.payload.inet                | 132 +++---
 tests/py/ip6/mh.t.payload.ip6                 |  66 +--
 tests/py/ip6/redirect.t.payload.ip6           | 105 +++--
 tests/py/ip6/reject.t.payload.ip6             |   3 +-
 tests/py/ip6/rt.t.payload.inet                | 121 +++--
 tests/py/ip6/rt.t.payload.ip6                 |  61 ++-
 tests/py/ip6/rt0.t.payload                    |   3 +-
 tests/py/ip6/sets.t.payload.inet              |  18 +-
 tests/py/ip6/sets.t.payload.ip6               |   4 +-
 tests/py/ip6/sets.t.payload.netdev            |  18 +-
 tests/py/ip6/snat.t.payload.ip6               |  23 +-
 tests/py/ip6/srh.t.payload                    |  23 +-
 tests/py/ip6/tproxy.t.payload                 |  29 +-
 tests/py/ip6/vmap.t                           |   2 +-
 tests/py/ip6/vmap.t.json                      |   2 +-
 tests/py/ip6/vmap.t.payload.inet              | 171 ++++---
 tests/py/ip6/vmap.t.payload.ip6               |  87 ++--
 tests/py/ip6/vmap.t.payload.netdev            | 171 ++++---
 tests/py/netdev/dup.t.payload                 |   3 +-
 tests/py/netdev/fwd.t.payload                 |   5 +-
 tests/py/netdev/reject.t.payload              |  41 +-
 tests/py/netdev/tunnel.t.payload              |   5 +-
 tests/py/nft-test.py                          | 138 +++---
 tests/py/tools/regen_payloads.sh              |  74 +++
 .../testcases/maps/dumps/0012map_0.json-nft   |  20 +-
 .../shell/testcases/maps/dumps/0012map_0.nft  |   8 +-
 .../maps/dumps/named_ct_objects.json-nft      |  12 +-
 .../testcases/maps/dumps/named_ct_objects.nft |   6 +-
 .../maps/dumps/typeof_integer_0.json-nft      |  12 +-
 .../testcases/maps/dumps/typeof_integer_0.nft |   4 +-
 .../dumps/0012different_defines_0.json-nft    |   8 +-
 .../nft-f/dumps/0012different_defines_0.nft   |   2 +-
 .../dumps/merge_nat_inet.json-nft             |  12 +-
 .../optimizations/dumps/merge_nat_inet.nft    |   2 +-
 .../optimizations/dumps/merge_reject.json-nft |  16 +-
 .../optimizations/dumps/merge_reject.nft      |   4 +-
 .../dumps/merge_stmts_concat.json-nft         |  42 +-
 .../dumps/merge_stmts_concat.nft              |   8 +-
 .../dumps/merge_stmts_concat_vmap.json-nft    |   4 +-
 .../dumps/merge_stmts_concat_vmap.nft         |   2 +-
 .../sets/dumps/0029named_ifname_dtype_0.nft   |   4 +-
 .../0037_set_with_inet_service_0.json-nft     |  12 +-
 .../dumps/0037_set_with_inet_service_0.nft    |   8 +-
 .../sets/dumps/sets_with_ifnames.json-nft     |   4 +-
 .../sets/dumps/sets_with_ifnames.nft          |   2 +-
 .../testcases/sets/dumps/typeof_sets_0.nft    |   4 +-
 tests/shell/testcases/sets/typeof_sets_0      |   4 +-
 182 files changed, 5023 insertions(+), 4931 deletions(-)
 create mode 100644 tests/py/inet/osf.t.json.output
 create mode 100755 tests/py/tools/regen_payloads.sh
Signature · 1 line
2.51.0
author reviewer
#1 lore raw

PATCH 1/28 datatype: Fix boolean type on Big Endian

Pass a reference to a variable with correct size when creating the expression, otherwise mpz_import_data() will read only the always zero upper byte on Big Endian hosts.

Fixes afb6a8e66a111 ("datatype: clamp boolean value to 0 and 1")
---
 src/datatype.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/datatype.c +1 -1
index f347010f4a1af..7104ae8119ec6 100644
@@ -1559,7 +1559,7 @@ static struct error_record *boolean_type_parse(struct parse_ctx *ctx,
 					       struct expr **res)
 {
 	struct error_record *erec;
-	int num;
+	uint8_t num;
 
 	erec = integer_type_parse(ctx, sym, res);
 	if (erec)
Signature · 1 line
2.51.0
author reviewer
#2 lore raw

PATCH 2/28 optimize: Fix verdict expression comparison

In reply to Phil Sutter

In verdict expression, 'chain' points at a constant expression of verdict_type, not a symbol expression. Therefore 'chain->identifier' points eight bytes (on 64bit systems) into the mpz_t 'value' holding the chain name. This matches the '_mp_d' data pointer, so works by accident.

Fix this by copying what verdict_jump_chain_print() does and export chain names before comparing.

Fixes fb298877ece27 ("src: add ruleset optimization infrastructure")
---
 src/optimize.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
src/optimize.c +8 -3
index cdd6913a306dd..ffc06480d4ee5 100644
@@ -341,13 +341,18 @@ static bool __stmt_type_eq(const struct stmt *stmt_a, const struct stmt *stmt_b,
 
 static bool expr_verdict_eq(const struct expr *expr_a, const struct expr *expr_b)
 {
+	char chain_a[NFT_CHAIN_MAXNAMELEN];
+	char chain_b[NFT_CHAIN_MAXNAMELEN];
+
 	if (expr_a->verdict != expr_b->verdict)
 		return false;
 	if (expr_a->chain && expr_b->chain) {
-		if (expr_a->chain->etype != expr_b->chain->etype)
+		if (expr_a->chain->etype != EXPR_VALUE ||
+		    expr_a->chain->etype != expr_b->chain->etype)
 			return false;
-		if (expr_a->chain->etype == EXPR_VALUE &&
-		    strcmp(expr_a->chain->identifier, expr_b->chain->identifier))
+		expr_chain_export(expr_a->chain, chain_a);
+		expr_chain_export(expr_b->chain, chain_b);
+		if (strcmp(chain_a, chain_b))
 			return false;
 	} else if (expr_a->chain || expr_b->chain) {
 		return false;
Signature · 1 line
2.51.0
author reviewer
#3 lore raw

PATCH 3/28 tests: py: any/tcpopt.t.json: Fix JSON equivalent

In reply to Phil Sutter

Set element ordering differed from the rule in standard syntax.

Fixes d199cca92f9eb ("expression: expr_build_udata_recurse should recurse")
---
 tests/py/any/tcpopt.t.json        | 24 +++++-----
 tests/py/any/tcpopt.t.json.output | 76 +++++++++++++++++++++++++++++++
 2 files changed, 88 insertions(+), 12 deletions(-)
tests/py/any/tcpopt.t.json +12 -12
index e712a5e0ed56f..65fa1de50eea0 100644
@@ -622,20 +622,20 @@
                     },
                     {
                         "concat": [
-                            "remove-addr",
-                            300
+                            "mp-join",
+                            100
                         ]
                     },
                     {
                         "concat": [
-                            "mp-fastclose",
-                            600
+                            "add-addr",
+                            200
                         ]
                     },
                     {
                         "concat": [
-                            "mp-join",
-                            100
+                            "remove-addr",
+                            300
                         ]
                     },
                     {
@@ -646,20 +646,20 @@
                     },
                     {
                         "concat": [
-                            "mp-tcprst",
-                            700
+                            "mp-fail",
+                            500
                         ]
                     },
                     {
                         "concat": [
-                            "add-addr",
-                            200
+                            "mp-fastclose",
+                            600
                         ]
                     },
                     {
                         "concat": [
-                            "mp-fail",
-                            500
+                            "mp-tcprst",
+                            700
                         ]
                     }
                 ]
tests/py/any/tcpopt.t.json.output +76 -0

79 lines not on this page · raw message

Signature · 1 line
2.51.0
author reviewer
#4 lore raw

PATCH 4/28 tests: py: any/ct.t.json.output: Drop leftover entry

In reply to Phil Sutter

The rule with single element anonymous set was replaced, drop this leftover.

Fixes 27f6a4c68b4fd ("tests: replace single element sets")
---
 tests/py/any/ct.t.json.output | 33 ---------------------------------
 1 file changed, 33 deletions(-)
tests/py/any/ct.t.json.output +0 -33
index 70ade7e38987a..82634c2da6720 100644
@@ -471,39 +471,6 @@
     }
 ]
 
-# ct state . ct mark { new . 0x12345678}
-[
-    {
-        "match": {
-            "left": {
-                "concat": [
-                    {
-                        "ct": {
-                            "key": "state"
-                        }
-                    },
-                    {
-                        "ct": {
-                            "key": "mark"
-                        }
-                    }
-                ]
-            },
-            "op": "==",
-            "right": {
-                "set": [
-                    {
-                        "concat": [
-                            "new",
-                            305419896
-                        ]
-                    }
-                ]
-            }
-        }
-    }
-]
-
 # ct state . ct mark { new . 0x12345678, new . 0x34127856, established . 0x12785634}
 [
     {
Signature · 1 line
2.51.0
author reviewer
#5 lore raw

PATCH 5/28 tests: py: inet/osf.t: Fix element ordering in JSON equivalents

In reply to Phil Sutter

The original rules order set elements differently. Stick to that and add entries to inet/osf.t.json.output to cover for nftables reordering entries.

Fixes 92029c1282958 ("src: osf: add json support")
---
 tests/py/inet/osf.t.json        | 12 ++++----
 tests/py/inet/osf.t.json.output | 53 +++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+), 6 deletions(-)
 create mode 100644 tests/py/inet/osf.t.json.output
tests/py/inet/osf.t.json +6 -6
index cedb7f67bd52f..b1bf747265f81 100644
@@ -73,8 +73,8 @@
             "op": "==",
             "right": {
                 "set": [
-                    "MacOs",
-                    "Windows"
+                    "Windows",
+                    "MacOs"
                 ]
             }
         }
@@ -114,13 +114,13 @@
                 "map": {
                     "data": {
                         "set": [
-                            [
-                                "MacOs",
-                                2
-                            ],
                             [
                                 "Windows",
                                 1
+                            ],
+                            [
+                                "MacOs",
+                                2
                             ]
                         ]
                     },
tests/py/inet/osf.t.json.output new file +53 -0

53 lines not on this page · raw message

Signature · 1 line
2.51.0
author reviewer
#6 lore raw

PATCH 6/28 tests: py: Fix for using wrong payload path

In reply to Phil Sutter

If one family has a per-family payload record, following families used it by accident for a .got file when they actually should use the generic name.

---
 tests/py/nft-test.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
tests/py/nft-test.py +4 -3
index 35b29fc90870b..019c828f957a5 100755
@@ -817,9 +817,10 @@ def set_delete_elements(set_element, set_name, table, filename=None,
     for table in table_list:
         if rule[1].strip() == "ok":
             table_payload_expected = None
+            table_payload_path = payload_path
             try:
                 payload_log = open("%s.payload.%s" % (filename_path, table.family))
-                payload_path = payload_log.name
+                table_payload_path = payload_log.name
                 table_payload_expected = payload_find_expected(payload_log, rule[0])
             except:
                 if not payload_log:
@@ -868,14 +869,14 @@ def set_delete_elements(set_element, set_name, table, filename=None,
                 error += 1
 
                 try:
-                    gotf = open("%s.got" % payload_path)
+                    gotf = open("%s.got" % table_payload_path)
                     gotf_payload_expected = payload_find_expected(gotf, rule[0])
                     gotf.close()
                 except:
                     gotf_payload_expected = None
                 payload_log.seek(0, 0)
                 if not payload_check(gotf_payload_expected, payload_log, cmd):
-                    gotf = open("%s.got" % payload_path, 'a')
+                    gotf = open("%s.got" % table_payload_path, 'a')
                     payload_log.seek(0, 0)
                     gotf.write("# %s\n" % rule[0])
                     while True:
Signature · 1 line
2.51.0
author reviewer
#7 lore raw

PATCH 7/28 tests: py: Implement payload_record()

In reply to Phil Sutter

This is a helper function to store payload records (and JSON equivalents) in .got files. The code it replaces missed to insert a newline before the new entry and also did not check for existing records in all spots.

---
 tests/py/nft-test.py | 117 ++++++++++++++++++++++++++-----------------
 1 file changed, 71 insertions(+), 46 deletions(-)
tests/py/nft-test.py +71 -46
index 019c828f957a5..dc074d4c3872a 100755
@@ -16,6 +16,7 @@
 from __future__ import print_function
 import sys
 import os
+import io
 import argparse
 import signal
 import json
@@ -741,6 +742,66 @@ def set_delete_elements(set_element, set_name, table, filename=None,
     return i > 0
 
 
+def payload_record(path, rule, payload, desc="payload"):
+    '''
+    Record payload for @rule in file at @path
+
+    - @payload may be a file handle, a string or an array of strings
+    - Avoid duplicate entries by searching for a match first
+    - Separate entries by a single empty line, so check for trailing newlines
+      before writing
+    - @return False if already existing, True otherwise
+    '''
+    try:
+        with open(path, 'r') as f:
+            lines = f.readlines()
+    except:
+        lines = []
+
+    plines = []
+    if isinstance(payload, io.TextIOWrapper):
+        payload.seek(0, 0)
+        while True:
+            line = payload.readline()
+            if line.startswith("family "):
+                continue
+            if line == "":
+                break
+            plines.append(line)
+    elif isinstance(payload, str):
+        plines = [l + "\n" for l in payload.split("\n")]
+    elif isinstance(payload, list):
+        plines = payload
+    else:
+        raise Exception
+
+    found = False
+    for i in range(len(lines)):
+        if lines[i] == rule + "\n":
+            found = True
+            for pline in plines:
+                i += 1
+                if lines[i] != pline:
+                    found = False
+                    break
+            if found:
+                return False
+
+    try:
+        with open(path, 'a') as f:
+            if len(lines) > 0 and lines[-1] != "\n":
+                f.write("\n")
+            f.write("# %s\n" % rule)
+            f.writelines(plines)
+    except:
+        warnfmt = "Failed to write %s for rule %s"
+    else:
+        warnfmt = "Wrote %s for rule %s"
+
+    print_warning(warnfmt % (desc, rule[0]), os.path.basename(path), 1)
+    return True
+
+
 def json_dump_normalize(json_string, human_readable = False):
     json_obj = json.loads(json_string)
 
@@ -867,28 +928,8 @@ def set_delete_elements(set_element, set_name, table, filename=None,
             if state == "ok" and not payload_check(table_payload_expected,
                                                    payload_log, cmd):
                 error += 1
-
-                try:
-                    gotf = open("%s.got" % table_payload_path)
-                    gotf_payload_expected = payload_find_expected(gotf, rule[0])
-                    gotf.close()
-                except:
-                    gotf_payload_expected = None
-                payload_log.seek(0, 0)
-                if not payload_check(gotf_payload_expected, payload_log, cmd):
-                    gotf = open("%s.got" % table_payload_path, 'a')
-                    payload_log.seek(0, 0)
-                    gotf.write("# %s\n" % rule[0])
-                    while True:
-                        line = payload_log.readline()
-                        if line.startswith("family "):
-                            continue
-                        if line == "":
-                            break
-                        gotf.write(line)
-                    gotf.close()
-                    print_warning("Wrote payload for rule %s" % rule[0],
-                                  gotf.name, 1)
+                payload_record("%s.got" % table_payload_path,
+                               rule[0], payload_log)
 
             # Check for matching ruleset listing
             numeric_proto_old = nftables.set_numeric_proto_output(True)
@@ -979,13 +1020,9 @@ def set_delete_elements(set_element, set_name, table, filename=None,
                         json_output = item["rule"]
                         break
                 json_input = json.dumps(json_output["expr"], sort_keys = True)
-
-                gotf = open("%s.json.got" % filename_path, 'a')
-                jdump = json_dump_normalize(json_input, True)
-                gotf.write("# %s\n%s\n\n" % (rule[0], jdump))
-                gotf.close()
-                print_warning("Wrote JSON equivalent for rule %s" % rule[0],
-                              gotf.name, 1)
+                payload_record("%s.json.got" % filename_path, rule[0],
+                               json_dump_normalize(json_input, True),
+                               "JSON equivalent")
 
             table_flush(table, filename, lineno)
             payload_log = tempfile.TemporaryFile(mode="w+")
@@ -1013,17 +1050,8 @@ def set_delete_elements(set_element, set_name, table, filename=None,
             # Check for matching payload
             if not payload_check(table_payload_expected, payload_log, cmd):
                 error += 1
-                gotf = open("%s.json.payload.got" % filename_path, 'a')
-                payload_log.seek(0, 0)
-                gotf.write("# %s\n" % rule[0])
-                while True:
-                    line = payload_log.readline()
-                    if line == "":
-                        break
-                    gotf.write(line)
-                gotf.close()
-                print_warning("Wrote JSON payload for rule %s" % rule[0],
-                              gotf.name, 1)
+                payload_record("%s.json.payload.got" % filename_path,
+                               rule[0], payload_log, "JSON payload")
 
             # Check for matching ruleset listing
             numeric_proto_old = nftables.set_numeric_proto_output(True)
@@ -1049,12 +1077,9 @@ def set_delete_elements(set_element, set_name, table, filename=None,
                 print_differences_warning(filename, lineno,
                                           json_input, json_output, cmd)
                 error += 1
-                gotf = open("%s.json.output.got" % filename_path, 'a')
-                jdump = json_dump_normalize(json_output, True)
-                gotf.write("# %s\n%s\n\n" % (rule[0], jdump))
-                gotf.close()
-                print_warning("Wrote JSON output for rule %s" % rule[0],
-                              gotf.name, 1)
+                payload_record("%s.json.output.got" % filename_path, rule[0],
+                               json_dump_normalize(json_output, True),
+                               "JSON output")
                 # prevent further warnings and .got file updates
                 json_expected = json_output
             elif json_expected and json_output != json_expected:
Signature · 1 line
2.51.0
author reviewer
#8 lore raw

PATCH 8/28 tests: py: Do not rely upon '[end]' marker

In reply to Phil Sutter

Set element lines reliably start with whitespace followed by the word "element" and are separated by the same pattern. Use it instead of '[end]' (or anything enclosed in brackets).

While at it, recognize payload lines as starting with ' [ ' and avoid searching for the closing bracket.

---
 tests/py/nft-test.py | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
tests/py/nft-test.py +9 -9
index dc074d4c3872a..ff2412acc21e9 100755
@@ -686,7 +686,7 @@ def set_delete_elements(set_element, set_name, table, filename=None,
 def payload_check_elems_to_set(elems):
     newset = set()
 
-    for n, line in enumerate(elems.split('[end]')):
+    for n, line in enumerate(elems.split("element")):
         e = line.strip()
         if e in newset:
             print_error("duplicate", e, n)
@@ -698,17 +698,17 @@ def set_delete_elements(set_element, set_name, table, filename=None,
 
 
 def payload_check_set_elems(want, got):
-    if want.find('element') < 0 or want.find('[end]') < 0:
-        return 0
-
-    if got.find('element') < 0 or got.find('[end]') < 0:
-        return 0
+    if not want.strip().startswith("element") or \
+       not got.strip().startswith("element"):
+        return False
 
     set_want = payload_check_elems_to_set(want)
     set_got = payload_check_elems_to_set(got)
 
     return set_want == set_got
 
+def payload_line_relevant(line):
+    return line.startswith('  [ ') or line.strip().startswith("element")
 
 def payload_check(payload_buffer, file, cmd):
     file.seek(0, 0)
@@ -719,11 +719,11 @@ def set_delete_elements(set_element, set_name, table, filename=None,
 
     for lineno, want_line in enumerate(payload_buffer):
         # skip irreleant parts, such as "ip test-ipv4 output"
-        if want_line.find("[") < 0 or want_line.find("]") < 0:
-             continue
+        if not payload_line_relevant(want_line):
+            continue
 
         line = file.readline()
-        while line.find("[") < 0 or line.find("]") < 0 or (line.startswith("family ") and line.find(" [nf_tables]") > 0):
+        while not payload_line_relevant(line):
             line = file.readline()
             if line == "":
                 break
Signature · 1 line
2.51.0
author reviewer
#9 lore raw

PATCH 9/28 netlink: No need to reference array when passing as pointer

In reply to Phil Sutter

Struct nft_data_linearize::value is an array, drop the reference operator.

---
 src/netlink.c           | 6 +++---
 src/netlink_linearize.c | 8 ++++----
 2 files changed, 7 insertions(+), 7 deletions(-)
src/netlink.c +3 -3
index 5511d9888e5bd..7882381ebd389 100644
@@ -139,17 +139,17 @@ struct nftnl_set_elem *alloc_nftnl_setelem(const struct expr *set,
 			netlink_gen_key(key, &nld);
 			key->flags &= ~EXPR_F_INTERVAL;
 
-			nftnl_set_elem_set(nlse, NFTNL_SET_ELEM_KEY, &nld.value, nld.len);
+			nftnl_set_elem_set(nlse, NFTNL_SET_ELEM_KEY, nld.value, nld.len);
 
 			key->flags |= EXPR_F_INTERVAL_END;
 			netlink_gen_key(key, &nld);
 			key->flags &= ~EXPR_F_INTERVAL_END;
 
 			nftnl_set_elem_set(nlse, NFTNL_SET_ELEM_KEY_END,
-					   &nld.value, nld.len);
+					   nld.value, nld.len);
 		} else {
 			netlink_gen_key(key, &nld);
-			nftnl_set_elem_set(nlse, NFTNL_SET_ELEM_KEY, &nld.value, nld.len);
+			nftnl_set_elem_set(nlse, NFTNL_SET_ELEM_KEY, nld.value, nld.len);
 		}
 		break;
 	}
src/netlink_linearize.c +4 -4
index d01cadf84faf0..43cfbfa75f3d2 100644
@@ -482,8 +482,8 @@ static struct expr *netlink_gen_prefix(struct netlink_linearize_ctx *ctx,
 	netlink_put_register(nle, NFTNL_EXPR_BITWISE_SREG, sreg);
 	netlink_put_register(nle, NFTNL_EXPR_BITWISE_DREG, sreg);
 	nftnl_expr_set_u32(nle, NFTNL_EXPR_BITWISE_LEN, nld.len);
-	nftnl_expr_set(nle, NFTNL_EXPR_BITWISE_MASK, &nld.value, nld.len);
-	nftnl_expr_set(nle, NFTNL_EXPR_BITWISE_XOR, &zero.value, zero.len);
+	nftnl_expr_set(nle, NFTNL_EXPR_BITWISE_MASK, nld.value, nld.len);
+	nftnl_expr_set(nle, NFTNL_EXPR_BITWISE_XOR, zero.value, zero.len);
 	nft_rule_add_expr(ctx, nle, &expr->location);
 
 	return expr->right->prefix;
@@ -558,8 +558,8 @@ static void netlink_gen_flagcmp(struct netlink_linearize_ctx *ctx,
 		netlink_put_register(nle, NFTNL_EXPR_BITWISE_SREG, sreg);
 		netlink_put_register(nle, NFTNL_EXPR_BITWISE_DREG, sreg);
 		nftnl_expr_set_u32(nle, NFTNL_EXPR_BITWISE_LEN, len);
-		nftnl_expr_set(nle, NFTNL_EXPR_BITWISE_MASK, &nld2.value, nld2.len);
-		nftnl_expr_set(nle, NFTNL_EXPR_BITWISE_XOR, &nld.value, nld.len);
+		nftnl_expr_set(nle, NFTNL_EXPR_BITWISE_MASK, nld2.value, nld2.len);
+		nftnl_expr_set(nle, NFTNL_EXPR_BITWISE_XOR, nld.value, nld.len);
 		nft_rule_add_expr(ctx, nle, &expr->location);
 
 		nle = alloc_nft_expr("cmp");
Signature · 1 line
2.51.0
author reviewer
#10 lore raw

PATCH 10/28 datatype: Increase symbolic constant printer robustness

In reply to Phil Sutter

Do not segfault if passed symbol table is NULL.

---
 src/datatype.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
src/datatype.c +9 -5
index 7104ae8119ec6..55cd0267055bd 100644
@@ -254,15 +254,19 @@ void symbolic_constant_print(const struct symbol_table *tbl,
 	mpz_export_data(constant_data_ptr(val, expr->len), expr->value,
 			expr->byteorder, len);
 
+	if (nft_output_numeric_symbol(octx) || !tbl)
+		goto basetype_print;
+
 	for (s = tbl->symbols; s->identifier != NULL; s++) {
 		if (val == s->value)
 			break;
 	}
-
-	if (s->identifier == NULL || nft_output_numeric_symbol(octx))
-		return expr_basetype(expr)->print(expr, octx);
-
-	nft_print(octx, quotes ? "\"%s\"" : "%s", s->identifier);
+	if (s->identifier) {
+		nft_print(octx, quotes ? "\"%s\"" : "%s", s->identifier);
+		return;
+	}
+basetype_print:
+	expr_basetype(expr)->print(expr, octx);
 }
 
 static void switch_byteorder(void *data, unsigned int len)
Signature · 1 line
2.51.0
#11 lore raw

Re: [nft PATCH 10/28] datatype: Increase symbolic constant printer robustness

Quoted 1 line · Phil Sutter

Do not segfault if passed symbol table is NULL.

Is this a fix, or a cleanup?

Quoted 38 lines
---
 src/datatype.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
src/datatype.c +9 -5
index 7104ae8119ec6..55cd0267055bd 100644
@@ -254,15 +254,19 @@ void symbolic_constant_print(const struct symbol_table *tbl,
 	mpz_export_data(constant_data_ptr(val, expr->len), expr->value,
 			expr->byteorder, len);
 
+	if (nft_output_numeric_symbol(octx) || !tbl)
+		goto basetype_print;
+
 	for (s = tbl->symbols; s->identifier != NULL; s++) {
 		if (val == s->value)
 			break;
 	}
-
-	if (s->identifier == NULL || nft_output_numeric_symbol(octx))
-		return expr_basetype(expr)->print(expr, octx);
-
-	nft_print(octx, quotes ? "\"%s\"" : "%s", s->identifier);
+	if (s->identifier) {
+		nft_print(octx, quotes ? "\"%s\"" : "%s", s->identifier);
+		return;
+	}
+basetype_print:
+	expr_basetype(expr)->print(expr, octx);
 }
 
 static void switch_byteorder(void *data, unsigned int len)
Signature · 1 line
2.51.0
author reviewer
#12 lore raw

Re: [nft PATCH 10/28] datatype: Increase symbolic constant printer robustness

Quoted 4 lines · Pablo Neira Ayuso
Quoted 1 line · Phil Sutter

Do not segfault if passed symbol table is NULL.

Is this a fix, or a cleanup?

It is a fix but for a case which normally doesn't happen. It is triggered by the macro in patch 26 due to the ad-hoc struct output_ctx definition not populating the symbol tables.

Cheers, Phil

#13 lore raw

Re: [nft PATCH 10/28] datatype: Increase symbolic constant printer robustness

Quoted 9 lines · Phil Sutter
Quoted 4 lines · Pablo Neira Ayuso
Quoted 1 line · Phil Sutter

Do not segfault if passed symbol table is NULL.

Is this a fix, or a cleanup?

It is a fix but for a case which normally doesn't happen. It is triggered by the macro in patch 26 due to the ad-hoc struct output_ctx definition not populating the symbol tables.

For the debug thing that is unused? ie. #define expr_print_debug(expr)

This cannot ever happen in the code:

src/datatype.c: return symbolic_constant_print(octx->tbl.mark, expr, true, octx);
src/meta.c:     return symbolic_constant_print(&pkttype_type_tbl, expr, false, octx);
src/meta.c:     return symbolic_constant_print(octx->tbl.devgroup, expr, true, octx);
src/meta.c:     return symbolic_constant_print(&day_type_tbl, expr, true, octx);
src/proto.c:    return symbolic_constant_print(&ethertype_tbl, expr, false, octx);
src/rt.c:       return symbolic_constant_print(octx->tbl.realm, expr, true, octx);

And here:

void datatype_print(const struct expr *expr, struct output_ctx *octx) {
...

                if (dtype->sym_tbl != NULL)
                        return symbolic_constant_print(dtype->sym_tbl, expr,
                                                       false, octx);

Sorry but this is all sufficiently complex to add misleading hints.

If you need to extend anything, then please have a look at extending --debug to expose more information that you need.

Sorry, I do not see this is an improvement.

author reviewer
#14 lore raw

Re: [nft PATCH 10/28] datatype: Increase symbolic constant printer robustness

Quoted 5 lines · Pablo Neira Ayuso
Quoted 4 lines · Phil Sutter
Quoted 3 lines · Pablo Neira Ayuso
Quoted 1 line · Phil Sutter

Do not segfault if passed symbol table is NULL.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Is this a fix, or a cleanup?

It is a fix but for a case which normally doesn't happen. It is triggered by the macro in patch 26 due to the ad-hoc struct output_ctx definition not populating the symbol tables.

For the debug thing that is unused? ie. #define expr_print_debug(expr)

Yes, exactly. It basically does:

| {
| 	struct output_ctx octx = { .output_fp = stdout };
| 
| 	expr_print(expr, &octx);
| }

Depending on type of 'expr', this may then call
symbolic_constant_print(NULL, ...).

Quoted 18 lines

This cannot ever happen in the code:

src/datatype.c: return symbolic_constant_print(octx->tbl.mark, expr, true, octx);
src/meta.c:     return symbolic_constant_print(&pkttype_type_tbl, expr, false, octx);
src/meta.c:     return symbolic_constant_print(octx->tbl.devgroup, expr, true, octx);
src/meta.c:     return symbolic_constant_print(&day_type_tbl, expr, true, octx);
src/proto.c:    return symbolic_constant_print(&ethertype_tbl, expr, false, octx);
src/rt.c:       return symbolic_constant_print(octx->tbl.realm, expr, true, octx);

And here:

void datatype_print(const struct expr *expr, struct output_ctx *octx) {
...

                if (dtype->sym_tbl != NULL)
                        return symbolic_constant_print(dtype->sym_tbl, expr,
                                                       false, octx);
Quoted 6 lines

Sorry but this is all sufficiently complex to add misleading hints.

If you need to extend anything, then please have a look at extending --debug to expose more information that you need.

Sorry, I do not see this is an improvement.

OK, no problem. I can just drop patch 26 and this one from the series.

Cheers, Phil

#15 lore raw

Re: [nft PATCH 10/28] datatype: Increase symbolic constant printer robustness

Quoted 43 lines · Phil Sutter
Quoted 5 lines · Pablo Neira Ayuso
Quoted 4 lines · Phil Sutter
Quoted 3 lines · Pablo Neira Ayuso
Quoted 1 line · Phil Sutter

Do not segfault if passed symbol table is NULL.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Is this a fix, or a cleanup?

It is a fix but for a case which normally doesn't happen. It is triggered by the macro in patch 26 due to the ad-hoc struct output_ctx definition not populating the symbol tables.

For the debug thing that is unused? ie. #define expr_print_debug(expr)

Yes, exactly. It basically does:

| {
| 	struct output_ctx octx = { .output_fp = stdout };
| 
| 	expr_print(expr, &octx);
| }

Depending on type of 'expr', this may then call
symbolic_constant_print(NULL, ...).

Quoted 18 lines

This cannot ever happen in the code:

src/datatype.c: return symbolic_constant_print(octx->tbl.mark, expr, true, octx);
src/meta.c:     return symbolic_constant_print(&pkttype_type_tbl, expr, false, octx);
src/meta.c:     return symbolic_constant_print(octx->tbl.devgroup, expr, true, octx);
src/meta.c:     return symbolic_constant_print(&day_type_tbl, expr, true, octx);
src/proto.c:    return symbolic_constant_print(&ethertype_tbl, expr, false, octx);
src/rt.c:       return symbolic_constant_print(octx->tbl.realm, expr, true, octx);

And here:

void datatype_print(const struct expr *expr, struct output_ctx *octx) {
...

                if (dtype->sym_tbl != NULL)
                        return symbolic_constant_print(dtype->sym_tbl, expr,
                                                       false, octx);
Quoted 8 lines
Quoted 6 lines

Sorry but this is all sufficiently complex to add misleading hints.

If you need to extend anything, then please have a look at extending --debug to expose more information that you need.

Sorry, I do not see this is an improvement.

OK, no problem. I can just drop patch 26 and this one from the series.

I inclined to think that this is scaffolding that has helped you to develop this series, but I am not sure expr_print_debug() will be of use for me in the future.

author reviewer
#16 lore raw

PATCH 11/28 tests: py: ip6/vmap.t: Drop double whitespace in rule

In reply to Phil Sutter

Just a harmless typo.

---
 tests/py/ip6/vmap.t                | 2 +-
 tests/py/ip6/vmap.t.json           | 2 +-
 tests/py/ip6/vmap.t.payload.inet   | 2 +-
 tests/py/ip6/vmap.t.payload.ip6    | 2 +-
 tests/py/ip6/vmap.t.payload.netdev | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)
tests/py/ip6/vmap.t +1 -1
index 2d54b8226e426..bfaa0c3bfca80 100644
@@ -32,7 +32,7 @@ ip6 saddr vmap { 1234::1234:1234:1234:1234 : accept};ok
 ip6 saddr vmap { 1234:1234::1234:1234:1234 : accept};ok
 ip6 saddr vmap { 1234:1234:1234::1234:1234 : accept};ok
 ip6 saddr vmap { 1234:1234:1234:1234::1234 : accept};ok
-ip6 saddr vmap { 1234:1234:1234:1234:1234::  : accept};ok
+ip6 saddr vmap { 1234:1234:1234:1234:1234:: : accept};ok
 ip6 saddr vmap { ::1234:1234:1234:1234 : accept};ok
 ip6 saddr vmap { 1234::1234:1234:1234 : accept};ok
 ip6 saddr vmap { 1234:1234::1234:1234 : accept};ok
tests/py/ip6/vmap.t.json +1 -1
index 1b867ff076928..2ba071cf1140f 100644
@@ -526,7 +526,7 @@
     }
 ]
 
-# ip6 saddr vmap { 1234:1234:1234:1234:1234::  : accept}
+# ip6 saddr vmap { 1234:1234:1234:1234:1234:: : accept}
 [
     {
         "vmap": {
tests/py/ip6/vmap.t.payload.inet +1 -1
index 931cc6bd75a77..26bca5e26f279 100644
@@ -218,7 +218,7 @@ inet test-inet input
   [ payload load 16b @ network header + 8 => reg 1 ]
   [ lookup reg 1 set __map%d dreg 0 ]
 
-# ip6 saddr vmap { 1234:1234:1234:1234:1234::  : accept}
+# ip6 saddr vmap { 1234:1234:1234:1234:1234:: : accept}
 __map%d test-inet b
 __map%d test-inet 0
 	element 34123412 34123412 00003412 00000000  : accept 0 [end]
tests/py/ip6/vmap.t.payload.ip6 +1 -1
index 6e077b27a5f09..2aaa0e48f4b10 100644
@@ -174,7 +174,7 @@ ip6 test-ip6 input
   [ payload load 16b @ network header + 8 => reg 1 ]
   [ lookup reg 1 set __map%d dreg 0 ]
 
-# ip6 saddr vmap { 1234:1234:1234:1234:1234::  : accept}
+# ip6 saddr vmap { 1234:1234:1234:1234:1234:: : accept}
 __map%d test-ip6 b
 __map%d test-ip6 0
 	element 34123412 34123412 00003412 00000000  : accept 0 [end]
tests/py/ip6/vmap.t.payload.netdev +1 -1
index 45f2c0b01e9c8..4d81309b9e6eb 100644
@@ -218,7 +218,7 @@ netdev test-netdev ingress
   [ payload load 16b @ network header + 8 => reg 1 ]
   [ lookup reg 1 set __map%d dreg 0 ]
 
-# ip6 saddr vmap { 1234:1234:1234:1234:1234::  : accept}
+# ip6 saddr vmap { 1234:1234:1234:1234:1234:: : accept}
 __map%d test-netdev b
 __map%d test-netdev 0
 	element 34123412 34123412 00003412 00000000  : accept 0 [end]
Signature · 1 line
2.51.0
author reviewer
#17 lore raw

PATCH 12/28 netlink: Zero nft_data_linearize objects when populating

In reply to Phil Sutter

Callers of netlink_gen_{key,data}() pass an uninitialized auto-variable, avoid misinterpreting garbage in fields "left blank".

---
 src/netlink.c | 4 ++++
 1 file changed, 4 insertions(+)
src/netlink.c +4 -0
index 7882381ebd389..3258f9ab9056e 100644
@@ -563,6 +563,8 @@ static void netlink_gen_prefix(const struct expr *expr,
 static void netlink_gen_key(const struct expr *expr,
 			    struct nft_data_linearize *data)
 {
+	memset(data, 0, sizeof(*data));
+
 	switch (expr->etype) {
 	case EXPR_VALUE:
 		return netlink_gen_constant_data(expr, data);
@@ -580,6 +582,8 @@ static void netlink_gen_key(const struct expr *expr,
 static void __netlink_gen_data(const struct expr *expr,
 			       struct nft_data_linearize *data, bool expand)
 {
+	memset(data, 0, sizeof(*data));
+
 	switch (expr->etype) {
 	case EXPR_VALUE:
 		return netlink_gen_constant_data(expr, data);
Signature · 1 line
2.51.0
#18 lore raw

Re: [nft PATCH 12/28] netlink: Zero nft_data_linearize objects when populating

Quoted 2 lines · Phil Sutter

Callers of netlink_gen_{key,data}() pass an uninitialized auto-variable, avoid misinterpreting garbage in fields "left blank".

Is this a safety improvement or fixing something you have observed?

Quoted 31 lines
---
 src/netlink.c | 4 ++++
 1 file changed, 4 insertions(+)
src/netlink.c +4 -0
index 7882381ebd389..3258f9ab9056e 100644
@@ -563,6 +563,8 @@ static void netlink_gen_prefix(const struct expr *expr,
 static void netlink_gen_key(const struct expr *expr,
 			    struct nft_data_linearize *data)
 {
+	memset(data, 0, sizeof(*data));
+
 	switch (expr->etype) {
 	case EXPR_VALUE:
 		return netlink_gen_constant_data(expr, data);
@@ -580,6 +582,8 @@ static void netlink_gen_key(const struct expr *expr,
 static void __netlink_gen_data(const struct expr *expr,
 			       struct nft_data_linearize *data, bool expand)
 {
+	memset(data, 0, sizeof(*data));
+
 	switch (expr->etype) {
 	case EXPR_VALUE:
 		return netlink_gen_constant_data(expr, data);
Signature · 1 line
2.51.0
author reviewer
#19 lore raw

Re: [nft PATCH 12/28] netlink: Zero nft_data_linearize objects when populating

Quoted 5 lines · Pablo Neira Ayuso
Quoted 2 lines · Phil Sutter

Callers of netlink_gen_{key,data}() pass an uninitialized auto-variable, avoid misinterpreting garbage in fields "left blank".

Is this a safety improvement or fixing something you have observed?

Patches 19 and 20 add fields to struct nft_data_linearize ('byteorder' and 'sizes'). Having these memset() calls in place allows for setting (bits in) these fields only if needed, default value becomes zero when it was random before.

One could avoid it by making sure the new fields 'byteorder' and 'sizes' are fully initialized by called functions. Are you concerned about the performance impact?

Cheers, Phil

#20 lore raw

Re: [nft PATCH 12/28] netlink: Zero nft_data_linearize objects when populating

Quoted 7 lines · Phil Sutter
Quoted 5 lines · Pablo Neira Ayuso
Quoted 2 lines · Phil Sutter

Callers of netlink_gen_{key,data}() pass an uninitialized auto-variable, avoid misinterpreting garbage in fields "left blank".

Is this a safety improvement or fixing something you have observed?

Quoted 8 lines

Patches 19 and 20 add fields to struct nft_data_linearize ('byteorder' and 'sizes'). Having these memset() calls in place allows for setting (bits in) these fields only if needed, default value becomes zero when it was random before.

One could avoid it by making sure the new fields 'byteorder' and 'sizes' are fully initialized by called functions. Are you concerned about the performance impact?

No, I just was expecting you clarify in the commit message that this is just extra-safety initialization that is not fixing anything, otherwise it is not obvious what the intention with this is.

But it is too late to discuss this now.

author reviewer
#21 lore raw

Re: [nft PATCH 12/28] netlink: Zero nft_data_linearize objects when populating

Quoted 13 lines · Pablo Neira Ayuso
Quoted 12 lines · Phil Sutter
Quoted 5 lines · Pablo Neira Ayuso
Quoted 2 lines · Phil Sutter

Callers of netlink_gen_{key,data}() pass an uninitialized auto-variable, avoid misinterpreting garbage in fields "left blank".

Is this a safety improvement or fixing something you have observed?

Patches 19 and 20 add fields to struct nft_data_linearize ('byteorder' and 'sizes'). Having these memset() calls in place allows for setting (bits in) these fields only if needed, default value becomes zero when it was random before.

Quoted 7 lines
Quoted 3 lines

One could avoid it by making sure the new fields 'byteorder' and 'sizes' are fully initialized by called functions. Are you concerned about the performance impact?

No, I just was expecting you clarify in the commit message that this is just extra-safety initialization that is not fixing anything, otherwise it is not obvious what the intention with this is.

It is needed because later patches add fields to that struct which are not always written to. In order to not break the code temporarily, I chose to add the memset() before adding these fields. If this is too confusing, I can fold this patch into patch 19 which introduces the first new field.

Quoted 1 line

But it is too late to discuss this now.

Seems so, yes.

Cheers, Phil

author reviewer
#22 lore raw

PATCH 13/28 Define string-based data types as Big Endian

In reply to Phil Sutter

Doesn't quite matter internally, but libnftnl should not attempt to convert strings from host byte order when printing.

Fib expression byte order changes with NFT_FIB_RESULT_OIFNAME to Big Endian.

---
 src/ct.c                  |  2 +-
 src/datatype.c            | 10 +++++-----
 src/evaluate.c            | 18 +++++++++---------
 src/fib.c                 |  5 +++--
 src/intervals.c           |  5 -----
 src/json.c                |  2 +-
 src/meta.c                | 16 ++++++++--------
 src/mnl.c                 |  2 +-
 src/netlink.c             | 12 +++++-------
 src/netlink_delinearize.c | 14 +++++++-------
 src/osf.c                 |  3 +--
 src/parser_bison.y        | 10 +++++-----
 src/parser_json.c         |  4 ++--
 src/segtree.c             | 10 +++++-----
 14 files changed, 53 insertions(+), 60 deletions(-)
src/ct.c +1 -1
index 4edbc0fc2997f..e9333c79dfd42 100644
@@ -273,7 +273,7 @@ const struct ct_template ct_templates[__NFT_CT_MAX] = {
 					      BYTEORDER_HOST_ENDIAN,
 					      4 * BITS_PER_BYTE),
 	[NFT_CT_HELPER]		= CT_TEMPLATE("helper",	    &string_type,
-					      BYTEORDER_HOST_ENDIAN,
+					      BYTEORDER_BIG_ENDIAN,
 					      NF_CT_HELPER_NAME_LEN * BITS_PER_BYTE),
 	[NFT_CT_L3PROTOCOL]	= CT_TEMPLATE("l3proto",    &nfproto_type,
 					      BYTEORDER_HOST_ENDIAN,
src/datatype.c +5 -5
index 55cd0267055bd..2ee7e7d5e9cf6 100644
@@ -324,7 +324,7 @@ void expr_chain_export(const struct expr *e, char *chain_name)
 		BUG("verdict expression length %u is too large (%u bits max)",
 		    e->len, NFT_CHAIN_MAXNAMELEN * BITS_PER_BYTE);
 
-	mpz_export_data(chain_name, e->value, BYTEORDER_HOST_ENDIAN, len);
+	mpz_export_data(chain_name, e->value, BYTEORDER_BIG_ENDIAN, len);
 }
 
 static void verdict_jump_chain_print(const char *what, const struct expr *e,
@@ -532,7 +532,7 @@ static void string_type_print(const struct expr *expr, struct output_ctx *octx)
 	unsigned int len = div_round_up(expr->len, BITS_PER_BYTE);
 	char data[len+1];
 
-	mpz_export_data(data, expr->value, BYTEORDER_HOST_ENDIAN, len);
+	mpz_export_data(data, expr->value, BYTEORDER_BIG_ENDIAN, len);
 	data[len] = '\0';
 	nft_print(octx, "\"%s\"", data);
 }
@@ -542,7 +542,7 @@ static struct error_record *string_type_parse(struct parse_ctx *ctx,
 	      				      struct expr **res)
 {
 	*res = constant_expr_alloc(&sym->location, &string_type,
-				   BYTEORDER_HOST_ENDIAN,
+				   BYTEORDER_BIG_ENDIAN,
 				   (strlen(sym->identifier) + 1) * BITS_PER_BYTE,
 				   sym->identifier);
 	return NULL;
@@ -552,7 +552,7 @@ const struct datatype string_type = {
 	.type		= TYPE_STRING,
 	.name		= "string",
 	.desc		= "string",
-	.byteorder	= BYTEORDER_HOST_ENDIAN,
+	.byteorder	= BYTEORDER_BIG_ENDIAN,
 	.print		= string_type_print,
 	.json		= string_type_json,
 	.parse		= string_type_parse,
@@ -1609,7 +1609,7 @@ static struct error_record *priority_type_parse(struct parse_ctx *ctx,
 	} else {
 		erec_destroy(erec);
 		*res = constant_expr_alloc(&sym->location, &string_type,
-					   BYTEORDER_HOST_ENDIAN,
+					   BYTEORDER_BIG_ENDIAN,
 					   strlen(sym->identifier) * BITS_PER_BYTE,
 					   sym->identifier);
 	}
src/evaluate.c +9 -9
index a5cc418191989..be366140c12f2 100644
@@ -376,7 +376,7 @@ static int expr_evaluate_string(struct eval_ctx *ctx, struct expr **exprp)
 	}
 
 	memset(data + len, 0, data_len - len);
-	mpz_export_data(data, expr->value, BYTEORDER_HOST_ENDIAN, len);
+	mpz_export_data(data, expr->value, BYTEORDER_BIG_ENDIAN, len);
 
 	if (strlen(data) == 0)
 		return expr_error(ctx->msgs, expr,
@@ -388,7 +388,7 @@ static int expr_evaluate_string(struct eval_ctx *ctx, struct expr **exprp)
 		 * expression length to avoid problems on big endian.
 		 */
 		value = constant_expr_alloc(&expr->location, ctx->ectx.dtype,
-					    BYTEORDER_HOST_ENDIAN,
+					    BYTEORDER_BIG_ENDIAN,
 					    expr->len, data);
 		expr_free(expr);
 		*exprp = value;
@@ -406,7 +406,7 @@ static int expr_evaluate_string(struct eval_ctx *ctx, struct expr **exprp)
 		xstrunescape(data, unescaped_str);
 
 		value = constant_expr_alloc(&expr->location, ctx->ectx.dtype,
-					    BYTEORDER_HOST_ENDIAN,
+					    BYTEORDER_BIG_ENDIAN,
 					    expr->len, unescaped_str);
 		expr_free(expr);
 		*exprp = value;
@@ -415,14 +415,14 @@ static int expr_evaluate_string(struct eval_ctx *ctx, struct expr **exprp)
 
 	data[datalen] = 0;
 	value = constant_expr_alloc(&expr->location, ctx->ectx.dtype,
-				    BYTEORDER_HOST_ENDIAN,
+				    BYTEORDER_BIG_ENDIAN,
 				    expr->len, data);
 
 	prefix = prefix_expr_alloc(&expr->location, value,
 				   datalen * BITS_PER_BYTE);
 	datatype_set(prefix, ctx->ectx.dtype);
 	prefix->flags |= EXPR_F_CONSTANT;
-	prefix->byteorder = BYTEORDER_HOST_ENDIAN;
+	prefix->byteorder = BYTEORDER_BIG_ENDIAN;
 	prefix->len = expr->len;
 
 	expr_free(expr);
@@ -3120,7 +3120,7 @@ static int verdict_validate_chain(struct eval_ctx *ctx,
 				  "chain name length 0 not allowed");
 
 	memset(buf, 0, sizeof(buf));
-	mpz_export_data(buf, chain->value, BYTEORDER_HOST_ENDIAN, len);
+	mpz_export_data(buf, chain->value, BYTEORDER_BIG_ENDIAN, len);
 
 	if (strnlen(buf, sizeof(buf)) < sizeof(buf))
 		return 0;
@@ -5010,7 +5010,7 @@ static int stmt_evaluate_objref(struct eval_ctx *ctx, struct stmt *stmt)
 
 	if (stmt_evaluate_arg(ctx, stmt,
 			      &string_type, NFT_OBJ_MAXNAMELEN * BITS_PER_BYTE,
-			      BYTEORDER_HOST_ENDIAN, &stmt->objref.expr) < 0)
+			      BYTEORDER_BIG_ENDIAN, &stmt->objref.expr) < 0)
 		return -1;
 
 	if (!expr_is_constant(stmt->objref.expr))
@@ -5336,7 +5336,7 @@ static int set_evaluate(struct eval_ctx *ctx, struct set *set)
 	} else if (set_is_objmap(set->flags)) {
 		assert(set->data == NULL);
 		set->data = constant_expr_alloc(&netlink_location, &string_type,
-						BYTEORDER_HOST_ENDIAN,
+						BYTEORDER_BIG_ENDIAN,
 						NFT_OBJ_MAXNAMELEN * BITS_PER_BYTE,
 						NULL);
 
@@ -5414,7 +5414,7 @@ static bool evaluate_priority(struct eval_ctx *ctx, struct prio_spec *prio,
 	if (prio->expr->dtype->type == TYPE_INTEGER)
 		return true;
 
-	mpz_export_data(prio_str, prio->expr->value, BYTEORDER_HOST_ENDIAN,
+	mpz_export_data(prio_str, prio->expr->value, BYTEORDER_BIG_ENDIAN,
 			NFT_NAME_MAXLEN);
 	loc = prio->expr->location;
 
src/fib.c +3 -2
index 4db7cd2bbc9c3..571277ddf434a 100644
@@ -179,6 +179,7 @@ const struct expr_ops fib_expr_ops = {
 struct expr *fib_expr_alloc(const struct location *loc,
 			    unsigned int flags, unsigned int result)
 {
+	enum byteorder bo = BYTEORDER_HOST_ENDIAN;
 	const struct datatype *type;
 	unsigned int len = 4 * BITS_PER_BYTE;
 	struct expr *expr;
@@ -190,6 +191,7 @@ struct expr *fib_expr_alloc(const struct location *loc,
 	case NFT_FIB_RESULT_OIFNAME:
 		type = &ifname_type;
 		len = IFNAMSIZ * BITS_PER_BYTE;
+		bo = BYTEORDER_BIG_ENDIAN;
 		break;
 	case NFT_FIB_RESULT_ADDRTYPE:
 		type = &fib_addr_type;
@@ -203,8 +205,7 @@ struct expr *fib_expr_alloc(const struct location *loc,
 		len = BITS_PER_BYTE;
 	}
 
-	expr = expr_alloc(loc, EXPR_FIB, type,
-			  BYTEORDER_HOST_ENDIAN, len);
+	expr = expr_alloc(loc, EXPR_FIB, type, bo, len);
 
 	expr->fib.result = result;
 	expr->fib.flags	= flags;
src/intervals.c +0 -5
index a63c58ac96066..438957c52d391 100644
@@ -42,8 +42,6 @@ static void setelem_expr_to_range(struct expr *expr)
 
 		mpz_init(rop);
 		mpz_bitmask(rop, expr->key->len - expr->key->prefix_len);
-		if (expr_basetype(expr)->type == TYPE_STRING)
-			mpz_switch_byteorder(expr->key->prefix->value, expr->len / BITS_PER_BYTE);
 
 		mpz_ior(rop, rop, expr->key->prefix->value);
 		key = constant_range_expr_alloc(&expr->location,
@@ -57,9 +55,6 @@ static void setelem_expr_to_range(struct expr *expr)
 		expr->key = key;
 		break;
 	case EXPR_VALUE:
-		if (expr_basetype(expr)->type == TYPE_STRING)
-			mpz_switch_byteorder(expr->key->value, expr->len / BITS_PER_BYTE);
-
 		key = constant_range_expr_alloc(&expr->location,
 						expr->key->dtype,
 						expr->key->byteorder,
src/json.c +1 -1
index 0afce5415f541..46d8a73333374 100644
@@ -1220,7 +1220,7 @@ json_t *string_type_json(const struct expr *expr, struct output_ctx *octx)
 	unsigned int len = div_round_up(expr->len, BITS_PER_BYTE);
 	char data[len+1];
 
-	mpz_export_data(data, expr->value, BYTEORDER_HOST_ENDIAN, len);
+	mpz_export_data(data, expr->value, BYTEORDER_BIG_ENDIAN, len);
 	data[len] = '\0';
 
 	return json_string(data);
src/meta.c +8 -8
index c36486029cca8..4eccb2cadf3b0 100644
@@ -370,7 +370,7 @@ const struct datatype ifname_type = {
 	.type		= TYPE_IFNAME,
 	.name		= "ifname",
 	.desc		= "network interface name",
-	.byteorder	= BYTEORDER_HOST_ENDIAN,
+	.byteorder	= BYTEORDER_BIG_ENDIAN,
 	.size		= IFNAMSIZ * BITS_PER_BYTE,
 	.basetype	= &string_type,
 };
@@ -630,14 +630,14 @@ const struct meta_template meta_templates[] = {
 						4 * 8, BYTEORDER_HOST_ENDIAN),
 	[NFT_META_IIFNAME]	= META_TEMPLATE("iifname",   &ifname_type,
 						IFNAMSIZ * BITS_PER_BYTE,
-						BYTEORDER_HOST_ENDIAN),
+						BYTEORDER_BIG_ENDIAN),
 	[NFT_META_IIFTYPE]	= META_TEMPLATE("iiftype",   &arphrd_type,
 						2 * 8, BYTEORDER_HOST_ENDIAN),
 	[NFT_META_OIF]		= META_TEMPLATE("oif",	     &ifindex_type,
 						4 * 8, BYTEORDER_HOST_ENDIAN),
 	[NFT_META_OIFNAME]	= META_TEMPLATE("oifname",   &ifname_type,
 						IFNAMSIZ * BITS_PER_BYTE,
-						BYTEORDER_HOST_ENDIAN),
+						BYTEORDER_BIG_ENDIAN),
 	[NFT_META_OIFTYPE]	= META_TEMPLATE("oiftype",   &arphrd_type,
 						2 * 8, BYTEORDER_HOST_ENDIAN),
 	[NFT_META_SKUID]	= META_TEMPLATE("skuid",     &uid_type,
@@ -650,10 +650,10 @@ const struct meta_template meta_templates[] = {
 						4 * 8, BYTEORDER_HOST_ENDIAN),
 	[NFT_META_BRI_IIFNAME]	= META_TEMPLATE("ibrname",  &ifname_type,
 						IFNAMSIZ * BITS_PER_BYTE,
-						BYTEORDER_HOST_ENDIAN),
+						BYTEORDER_BIG_ENDIAN),
 	[NFT_META_BRI_OIFNAME]	= META_TEMPLATE("obrname",  &ifname_type,
 						IFNAMSIZ * BITS_PER_BYTE,
-						BYTEORDER_HOST_ENDIAN),
+						BYTEORDER_BIG_ENDIAN),
 	[NFT_META_PKTTYPE]	= META_TEMPLATE("pkttype",   &pkttype_type,
 						BITS_PER_BYTE,
 						BYTEORDER_HOST_ENDIAN),
@@ -676,10 +676,10 @@ const struct meta_template meta_templates[] = {
 						BITS_PER_BYTE, BYTEORDER_HOST_ENDIAN),
 	[NFT_META_IIFKIND]	= META_TEMPLATE("iifkind",   &ifname_type,
 						IFNAMSIZ * BITS_PER_BYTE,
-						BYTEORDER_HOST_ENDIAN),
+						BYTEORDER_BIG_ENDIAN),
 	[NFT_META_OIFKIND]	= META_TEMPLATE("oifkind",   &ifname_type,
 						IFNAMSIZ * BITS_PER_BYTE,
-						BYTEORDER_HOST_ENDIAN),
+						BYTEORDER_BIG_ENDIAN),
 	[NFT_META_BRI_IIFPVID]	= META_TEMPLATE("ibrpvid",   &integer_type,
 						2 * BITS_PER_BYTE,
 						BYTEORDER_HOST_ENDIAN),
@@ -702,7 +702,7 @@ const struct meta_template meta_templates[] = {
 						BYTEORDER_HOST_ENDIAN),
 	[NFT_META_SDIFNAME]	= META_TEMPLATE("sdifname", &ifname_type,
 						IFNAMSIZ * BITS_PER_BYTE,
-						BYTEORDER_HOST_ENDIAN),
+						BYTEORDER_BIG_ENDIAN),
 	[NFT_META_BRI_BROUTE]	= META_TEMPLATE("broute",   &integer_type,
 						1    , BYTEORDER_HOST_ENDIAN),
 	[NFT_META_BRI_IIFHWADDR] = META_TEMPLATE("ibrhwaddr", &etheraddr_type,
src/mnl.c +1 -1
index ab4a7dbc8d252..6e32fc3467ce9 100644
@@ -748,7 +748,7 @@ static void nft_dev_add(struct nft_dev *dev_array, const struct expr *expr, int
 	if (ifname_len > sizeof(ifname))
 		BUG("Interface length %u exceeds limit\n", ifname_len);
 
-	mpz_export_data(ifname, expr->value, BYTEORDER_HOST_ENDIAN, ifname_len);
+	mpz_export_data(ifname, expr->value, BYTEORDER_BIG_ENDIAN, ifname_len);
 
 	if (strnlen(ifname, IFNAMSIZ) >= IFNAMSIZ)
 		BUG("Interface length %zu exceeds limit, no NUL byte\n", strnlen(ifname, IFNAMSIZ));
src/netlink.c +5 -7
index 3258f9ab9056e..2a6caa9c76565 100644
@@ -487,7 +487,7 @@ static void netlink_gen_chain(const struct expr *expr,
 	memset(chain, 0, sizeof(chain));
 
 	mpz_export_data(chain, expr->chain->value,
-			BYTEORDER_HOST_ENDIAN, len);
+			BYTEORDER_BIG_ENDIAN, len);
 	snprintf(data->chain, NFT_CHAIN_MAXNAMELEN, "%s", chain);
 }
 
@@ -623,7 +623,7 @@ static struct expr *netlink_alloc_verdict(const struct location *loc,
 	case NFT_JUMP:
 	case NFT_GOTO:
 		chain = constant_expr_alloc(loc, &string_type,
-					    BYTEORDER_HOST_ENDIAN,
+					    BYTEORDER_BIG_ENDIAN,
 					    strlen(nld->chain) * BITS_PER_BYTE,
 					    nld->chain);
 		break;
@@ -1376,9 +1376,8 @@ static struct expr *concat_elem_expr(const struct set *set, struct expr *key,
 		expr->byteorder = subtype->byteorder;
 	}
 
-	if (expr_basetype(expr)->type == TYPE_STRING ||
-	    (!(set->flags & NFT_SET_INTERVAL) &&
-	     expr->byteorder == BYTEORDER_HOST_ENDIAN))
+	if (!(set->flags & NFT_SET_INTERVAL) &&
+	    expr->byteorder == BYTEORDER_HOST_ENDIAN)
 		mpz_switch_byteorder(expr->value, expr->len / BITS_PER_BYTE);
 
 	if (expr->dtype->basetype != NULL &&
@@ -1623,8 +1622,7 @@ int netlink_delinearize_setelem(struct netlink_ctx *ctx,
 
 		data = netlink_alloc_value(&netlink_location, &nld);
 		data->dtype = &string_type;
-		data->byteorder = BYTEORDER_HOST_ENDIAN;
-		mpz_switch_byteorder(data->value, data->len / BITS_PER_BYTE);
+		data->byteorder = BYTEORDER_BIG_ENDIAN;
 		expr = mapping_expr_alloc(&netlink_location, expr, data);
 	}
 out:
src/netlink_delinearize.c +7 -7
index 990edc824ad9e..54be0682b0899 100644
@@ -1876,7 +1876,7 @@ static void netlink_parse_objref(struct netlink_parse_ctx *ctx,
 					   &nld.len);
 		expr = netlink_alloc_value(&netlink_location, &nld);
 		datatype_set(expr, &string_type);
-		expr->byteorder = BYTEORDER_HOST_ENDIAN;
+		expr->byteorder = BYTEORDER_BIG_ENDIAN;
 	} else if (nftnl_expr_is_set(nle, NFTNL_EXPR_OBJREF_SET_SREG)) {
 		struct expr *left, *right;
 		enum nft_registers sreg;
@@ -1905,7 +1905,7 @@ static void netlink_parse_objref(struct netlink_parse_ctx *ctx,
 
 		right = set_ref_expr_alloc(loc, set);
 		expr = map_expr_alloc(loc, left, right);
-		expr_set_type(expr, &string_type, BYTEORDER_HOST_ENDIAN);
+		expr_set_type(expr, &string_type, BYTEORDER_BIG_ENDIAN);
 		type = set->objtype;
 	} else {
 		netlink_error(ctx, loc, "unknown objref expression type %u",
@@ -2752,12 +2752,12 @@ static struct expr *string_wildcard_expr_alloc(struct location *loc,
 	char data[len + 2];
 	int pos;
 
-	mpz_export_data(data, expr->value, BYTEORDER_HOST_ENDIAN, len);
+	mpz_export_data(data, expr->value, BYTEORDER_BIG_ENDIAN, len);
 	pos = div_round_up(expr_mask_to_prefix(mask), BITS_PER_BYTE);
 	data[pos] = '*';
 	data[pos + 1] = '\0';
 
-	return constant_expr_alloc(loc, expr->dtype, BYTEORDER_HOST_ENDIAN,
+	return constant_expr_alloc(loc, expr->dtype, BYTEORDER_BIG_ENDIAN,
 				   expr->len + BITS_PER_BYTE, data);
 }
 
@@ -2770,7 +2770,7 @@ static bool __expr_postprocess_string(struct expr **exprp)
 	unsigned int len = div_round_up(expr->len, BITS_PER_BYTE);
 	char data[len + 1];
 
-	mpz_export_data(data, expr->value, BYTEORDER_HOST_ENDIAN, len);
+	mpz_export_data(data, expr->value, BYTEORDER_BIG_ENDIAN, len);
 
 	if (data[len - 1] != '\0')
 		return false;
@@ -2781,7 +2781,7 @@ static bool __expr_postprocess_string(struct expr **exprp)
 		data[len]	= '*';
 		data[len + 1]	= '\0';
 		expr = constant_expr_alloc(&expr->location, expr->dtype,
-					   BYTEORDER_HOST_ENDIAN,
+					   BYTEORDER_BIG_ENDIAN,
 					   (len + 2) * BITS_PER_BYTE, data);
 		expr_free(*exprp);
 		*exprp = expr;
@@ -2799,7 +2799,7 @@ static struct expr *expr_postprocess_string(struct expr *expr)
 		return expr;
 
 	mask = constant_expr_alloc(&expr->location, &integer_type,
-				   BYTEORDER_HOST_ENDIAN,
+				   BYTEORDER_BIG_ENDIAN,
 				   expr->len + BITS_PER_BYTE, NULL);
 	mpz_clear(mask->value);
 	mpz_init_bitmask(mask->value, expr->len);
src/osf.c +1 -2
index a8f80b2bbaacb..2ff8490ae1790 100644
@@ -75,8 +75,7 @@ struct expr *osf_expr_alloc(const struct location *loc, const uint8_t ttl,
 	const struct datatype *type = &string_type;
 	struct expr *expr;
 
-	expr = expr_alloc(loc, EXPR_OSF, type,
-			  BYTEORDER_HOST_ENDIAN, len);
+	expr = expr_alloc(loc, EXPR_OSF, type, BYTEORDER_BIG_ENDIAN, len);
 	expr->osf.ttl = ttl;
 	expr->osf.flags = flags;
 
src/parser_bison.y +5 -5
index 3c21c7584d01f..8e34b86a0f400 100644
@@ -176,7 +176,7 @@ static struct expr *ifname_expr_alloc(const struct location *location,
 		return NULL;
 	}
 
-	expr = constant_expr_alloc(location, &ifname_type, BYTEORDER_HOST_ENDIAN,
+	expr = constant_expr_alloc(location, &ifname_type, BYTEORDER_BIG_ENDIAN,
 				   length * BITS_PER_BYTE, name);
 
 	free_const(name);
@@ -2800,7 +2800,7 @@ extended_prio_spec	:	int_num
 				struct prio_spec spec = {0};
 
 				spec.expr = constant_expr_alloc(&@$, &string_type,
-								BYTEORDER_HOST_ENDIAN,
+								BYTEORDER_BIG_ENDIAN,
 								strlen($1) * BITS_PER_BYTE,
 								$1);
 				free_const($1);
@@ -2813,7 +2813,7 @@ extended_prio_spec	:	int_num
 				char str[NFT_NAME_MAXLEN];
 				snprintf(str, sizeof(str), "%s + %" PRIu64, $1, $3);
 				spec.expr = constant_expr_alloc(&@$, &string_type,
-								BYTEORDER_HOST_ENDIAN,
+								BYTEORDER_BIG_ENDIAN,
 								strlen(str) * BITS_PER_BYTE,
 								str);
 				free_const($1);
@@ -2826,7 +2826,7 @@ extended_prio_spec	:	int_num
 
 				snprintf(str, sizeof(str), "%s - %" PRIu64, $1, $3);
 				spec.expr = constant_expr_alloc(&@$, &string_type,
-								BYTEORDER_HOST_ENDIAN,
+								BYTEORDER_BIG_ENDIAN,
 								strlen(str) * BITS_PER_BYTE,
 								str);
 				free_const($1);
@@ -5471,7 +5471,7 @@ chain_expr		:	variable_expr
 			|	identifier
 			{
 				$$ = constant_expr_alloc(&@$, &string_type,
-							 BYTEORDER_HOST_ENDIAN,
+							 BYTEORDER_BIG_ENDIAN,
 							 strlen($1) * BITS_PER_BYTE,
 							 $1);
 				free_const($1);
src/parser_json.c +2 -2
index e78262505d243..a7d6a0f5997c1 100644
@@ -1412,7 +1412,7 @@ static struct expr *json_alloc_chain_expr(const char *chain)
 	if (!chain)
 		return NULL;
 
-	return constant_expr_alloc(int_loc, &string_type, BYTEORDER_HOST_ENDIAN,
+	return constant_expr_alloc(int_loc, &string_type, BYTEORDER_BIG_ENDIAN,
 				   strlen(chain) * BITS_PER_BYTE, chain);
 }
 
@@ -3020,7 +3020,7 @@ static struct expr *ifname_expr_alloc(struct json_ctx *ctx,
 		return NULL;
 	}
 
-	return constant_expr_alloc(int_loc, &ifname_type, BYTEORDER_HOST_ENDIAN,
+	return constant_expr_alloc(int_loc, &ifname_type, BYTEORDER_BIG_ENDIAN,
 				   length * BITS_PER_BYTE, name);
 }
 
src/segtree.c +5 -5
index 88207a3987b8f..b9c35dcb297ce 100644
@@ -33,7 +33,7 @@ static enum byteorder get_key_byteorder(const struct expr *e)
 		 */
 		return BYTEORDER_BIG_ENDIAN;
 	case TYPE_STRING:
-		return BYTEORDER_HOST_ENDIAN;
+		return BYTEORDER_BIG_ENDIAN;
 	default:
 		break;
 	}
@@ -201,7 +201,7 @@ static struct expr *expr_to_set_elem(struct expr *e)
 	data[str_len] = '*';
 
 	expr = constant_expr_alloc(&e->location, e->dtype,
-				   BYTEORDER_HOST_ENDIAN,
+				   BYTEORDER_BIG_ENDIAN,
 				   (str_len + 1) * BITS_PER_BYTE, data);
 
 	return __expr_to_set_elem(e, expr);
@@ -412,11 +412,11 @@ void concat_range_aggregate(struct expr *set)
 				unsigned int str_len = prefix_len / BITS_PER_BYTE;
 				char data[str_len + 2];
 
-				mpz_export_data(data, r1->value, BYTEORDER_HOST_ENDIAN, str_len);
+				mpz_export_data(data, r1->value, BYTEORDER_BIG_ENDIAN, str_len);
 				data[str_len] = '*';
 
 				tmp = constant_expr_alloc(&r1->location, r1->dtype,
-							  BYTEORDER_HOST_ENDIAN,
+							  BYTEORDER_BIG_ENDIAN,
 							  (str_len + 1) * BITS_PER_BYTE, data);
 				tmp->len = r2->len;
 				list_replace(&r2->list, &tmp->list);
@@ -495,7 +495,7 @@ static struct expr *interval_to_string(struct expr *low, struct expr *i, const m
 	data[str_len] = '*';
 
 	expr = constant_expr_alloc(&low->location, low->dtype,
-				   BYTEORDER_HOST_ENDIAN,
+				   BYTEORDER_BIG_ENDIAN,
 				   len * BITS_PER_BYTE, data);
 
 	return __expr_to_set_elem(low, expr);
Signature · 1 line
2.51.0
#23 lore raw

Re: [nft PATCH 13/28] Define string-based data types as Big Endian

Quoted 29 lines · Phil Sutter

Doesn't quite matter internally, but libnftnl should not attempt to convert strings from host byte order when printing.

Fib expression byte order changes with NFT_FIB_RESULT_OIFNAME to Big Endian.

---
 src/ct.c                  |  2 +-
 src/datatype.c            | 10 +++++-----
 src/evaluate.c            | 18 +++++++++---------
 src/fib.c                 |  5 +++--
 src/intervals.c           |  5 -----
 src/json.c                |  2 +-
 src/meta.c                | 16 ++++++++--------
 src/mnl.c                 |  2 +-
 src/netlink.c             | 12 +++++-------
 src/netlink_delinearize.c | 14 +++++++-------
 src/osf.c                 |  3 +--
 src/parser_bison.y        | 10 +++++-----
 src/parser_json.c         |  4 ++--
 src/segtree.c             | 10 +++++-----
 14 files changed, 53 insertions(+), 60 deletions(-)
src/ct.c +0 -0
index 4edbc0fc2997f..e9333c79dfd42 100644

src/ct.c const struct ct_template ct_templates[__NFT_CT_MAX] = { · line 276

Quoted 5 lines
src/ct.c +1 -1
@@ -273,7 +273,7 @@ const struct ct_template ct_templates[__NFT_CT_MAX] = {
 					      BYTEORDER_HOST_ENDIAN,
 					      4 * BITS_PER_BYTE),
 	[NFT_CT_HELPER]		= CT_TEMPLATE("helper",	    &string_type,
-					      BYTEORDER_HOST_ENDIAN,
+					      BYTEORDER_BIG_ENDIAN,

No, this is not big endian, this is confusing.

author reviewer
#24 lore raw

Re: [nft PATCH 13/28] Define string-based data types as Big Endian

Quoted 25 lines · Pablo Neira Ayuso
Quoted 24 lines · Phil Sutter

Doesn't quite matter internally, but libnftnl should not attempt to convert strings from host byte order when printing.

Fib expression byte order changes with NFT_FIB_RESULT_OIFNAME to Big Endian.

---
 src/ct.c                  |  2 +-
 src/datatype.c            | 10 +++++-----
 src/evaluate.c            | 18 +++++++++---------
 src/fib.c                 |  5 +++--
 src/intervals.c           |  5 -----
 src/json.c                |  2 +-
 src/meta.c                | 16 ++++++++--------
 src/mnl.c                 |  2 +-
 src/netlink.c             | 12 +++++-------
 src/netlink_delinearize.c | 14 +++++++-------
 src/osf.c                 |  3 +--
 src/parser_bison.y        | 10 +++++-----
 src/parser_json.c         |  4 ++--
 src/segtree.c             | 10 +++++-----
 14 files changed, 53 insertions(+), 60 deletions(-)
Quoted 12 lines

src/ct.c const struct ct_template ct_templates[__NFT_CT_MAX] = { · line 276

Quoted 10 lines
src/ct.c +1 -1
index 4edbc0fc2997f..e9333c79dfd42 100644
@@ -273,7 +273,7 @@ const struct ct_template ct_templates[__NFT_CT_MAX] = {
 					      BYTEORDER_HOST_ENDIAN,
 					      4 * BITS_PER_BYTE),
 	[NFT_CT_HELPER]		= CT_TEMPLATE("helper",	    &string_type,
-					      BYTEORDER_HOST_ENDIAN,
+					      BYTEORDER_BIG_ENDIAN,

No, this is not big endian, this is confusing.

I agree, it is confusing. Maybe we could use BYTEORDER_INVALID for it? No idea if that would work or not, though. Since string values are always in the same ordering despite host's byteorder, BYTEORDER_HOST_ENDIAN is certainly not correct, either.

Cheers, Phil

author reviewer
#25 lore raw

PATCH 14/28 segtree: No byteorder conversion for string prefix len calculation

In reply to Phil Sutter

Not needed anymore since strings are defined as Big Endian.

---
 src/segtree.c | 9 ---------
 1 file changed, 9 deletions(-)
src/segtree.c +0 -9
index b9c35dcb297ce..5a334efc8bebb 100644
@@ -387,8 +387,6 @@ void concat_range_aggregate(struct expr *set)
 			if (expr_basetype(r1)->type == TYPE_STRING &&
 			    expr_basetype(r2)->type == TYPE_STRING) {
 				string_type = true;
-				mpz_switch_byteorder(r1->value, r1->len / BITS_PER_BYTE);
-				mpz_switch_byteorder(r2->value, r2->len / BITS_PER_BYTE);
 			}
 
 			mpz_sub(range, r2->value, r1->value);
@@ -401,10 +399,6 @@ void concat_range_aggregate(struct expr *set)
 			 */
 			prefix_len = range_mask_len(r1->value, r2->value,
 						    r1->len);
-			if (string_type) {
-				mpz_switch_byteorder(r1->value, r1->len / BITS_PER_BYTE);
-				mpz_switch_byteorder(r2->value, r2->len / BITS_PER_BYTE);
-			}
 
 			if (prefix_len >= 0 &&
 			    (prefix_len % BITS_PER_BYTE) == 0 &&
@@ -535,9 +529,6 @@ add_interval(struct expr *set, struct expr *low, struct expr *i)
 	mpz_and(p, expr_value(low)->value, range);
 
 	if (!mpz_cmp_ui(range, 0)) {
-		if (expr_basetype(low)->type == TYPE_STRING)
-			mpz_switch_byteorder(expr_value(low)->value,
-					     expr_value(low)->len / BITS_PER_BYTE);
 		low->flags |= EXPR_F_KERNEL;
 		expr = expr_get(low);
 	} else if (range_is_prefix(range) && !mpz_cmp_ui(p, 0)) {
Signature · 1 line
2.51.0
author reviewer
#26 lore raw

PATCH 15/28 Fix byteorder conversion of concatenated value expressions and ranges

In reply to Phil Sutter

A problem with the existing code was that struct expr::byteorder was not updated despite the call to mpz_switch_byteorder(). Doing so leads to an extra byteorder swap during data linearization though, so in order to have byteorder swapped *and* the field value set correctly, simply update the latter and rely upon the implicitly happening conversion.

---
 src/intervals.c | 10 +++-------
 src/netlink.c   |  5 ++---
 2 files changed, 5 insertions(+), 10 deletions(-)
src/intervals.c +3 -7
index 438957c52d391..6a917b7b79c3f 100644
@@ -793,11 +793,8 @@ int setelem_to_interval(const struct set *set, struct expr *elem,
 	}
 
 	low = constant_expr_alloc(&key->location, set->key->dtype,
-				  set->key->byteorder, set->key->len, NULL);
-
+				  BYTEORDER_BIG_ENDIAN, set->key->len, NULL);
 	mpz_set(low->value, key->range.low);
-	if (set->key->byteorder == BYTEORDER_HOST_ENDIAN)
-		mpz_switch_byteorder(low->value, set->key->len / BITS_PER_BYTE);
 
 	low = set_elem_expr_alloc(&key->location, low);
 	set_elem_expr_copy(low, interval_expr_key(elem));
@@ -819,12 +816,11 @@ int setelem_to_interval(const struct set *set, struct expr *elem,
 	}
 
 	high = constant_expr_alloc(&key->location, set->key->dtype,
-				   set->key->byteorder, set->key->len,
+				   BYTEORDER_BIG_ENDIAN, set->key->len,
 				   NULL);
 	mpz_set(high->value, key->range.high);
 	mpz_add_ui(high->value, high->value, 1);
-	if (set->key->byteorder == BYTEORDER_HOST_ENDIAN)
-		mpz_switch_byteorder(high->value, set->key->len / BITS_PER_BYTE);
+	high->byteorder = BYTEORDER_BIG_ENDIAN;
 
 	high = set_elem_expr_alloc(&key->location, high);
 
src/netlink.c +2 -3
index 2a6caa9c76565..3228747a74af8 100644
@@ -323,9 +323,8 @@ static int __netlink_gen_concat_key(uint32_t flags, const struct expr *i,
 			break;
 
 		expr = (struct expr *)i;
-		if (expr_basetype(expr)->type == TYPE_INTEGER &&
-		    expr->byteorder == BYTEORDER_HOST_ENDIAN)
-			byteorder_switch_expr_value(value, expr);
+		if (expr_basetype(expr)->type == TYPE_INTEGER)
+			expr->byteorder = BYTEORDER_BIG_ENDIAN;
 		break;
 	default:
 		BUG("invalid expression type '%s' in set", expr_ops(i)->name);
Signature · 1 line
2.51.0
author reviewer
#27 lore raw

PATCH 16/28 expression: Set range expression 'len' field

In reply to Phil Sutter

The length value is needed for netlink debug output of concatenated ranges. Set it to one of the inner elements' lengths (which should be identical).

Since the inner element length may not be set initially, set it in eval phase again. This covers at least all cases in tests/py.

Without this, netlink_gen_concat_key() et al. would have to inspect element types and extract lengths accordingly, this is much easier.

---
 src/evaluate.c   | 1 +
 src/expression.c | 1 +
 2 files changed, 2 insertions(+)
src/evaluate.c +1 -0
index be366140c12f2..cee500312bc6d 100644
@@ -1337,6 +1337,7 @@ static int expr_evaluate_range(struct eval_ctx *ctx, struct expr **exprp)
 
 	datatype_set(range, left->dtype);
 	range->flags |= EXPR_F_CONSTANT;
+	range->len = left->len;
 	return 0;
 }
 
src/expression.c +1 -0
index 019c263f187b8..de63196b60a6a 100644
@@ -1013,6 +1013,7 @@ struct expr *range_expr_alloc(const struct location *loc,
 			  BYTEORDER_INVALID, 0);
 	expr->left  = left;
 	expr->right = right;
+	expr->len = left->len;
 	return expr;
 }
 
Signature · 1 line
2.51.0
author reviewer
#28 lore raw

PATCH 17/28 segtree: Export complete data before editing

In reply to Phil Sutter

With Big Endian export, this did odd things: Content in 'data' appeared at the end of the buffer, so given the parameters mpz_export_data() actually overstepped boundaries.

Fix it by exporting the full data (just like string_type_print() does) into a large enough buffer, then create the constant expression from the significant part.

Initialize 'data' to zero just to be on the safe side, this is actually not needed.

---
 src/segtree.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
src/segtree.c +3 -2
index 5a334efc8bebb..ab107493ea97b 100644
@@ -403,10 +403,11 @@ void concat_range_aggregate(struct expr *set)
 			if (prefix_len >= 0 &&
 			    (prefix_len % BITS_PER_BYTE) == 0 &&
 			    string_type) {
+				unsigned int r1len = div_round_up(r1->len, BITS_PER_BYTE);
 				unsigned int str_len = prefix_len / BITS_PER_BYTE;
-				char data[str_len + 2];
+				char data[r1len + 1] = {};
 
-				mpz_export_data(data, r1->value, BYTEORDER_BIG_ENDIAN, str_len);
+				mpz_export_data(data, r1->value, BYTEORDER_BIG_ENDIAN, r1len);
 				data[str_len] = '*';
 
 				tmp = constant_expr_alloc(&r1->location, r1->dtype,
Signature · 1 line
2.51.0
author reviewer
#29 lore raw

PATCH 18/28 segtree: Drop problematic constant expr len adjustment

In reply to Phil Sutter

Changing a string-based expression's length will break listing on Big Endian hosts as the exported data is padded "on the wrong end".

Since not adjusting the length seems not to cause any problems, just drop it instead of trying to fix it.

---
 src/segtree.c | 1 -
 1 file changed, 1 deletion(-)
src/segtree.c +0 -1
index ab107493ea97b..7d4c50f499ef7 100644
@@ -413,7 +413,6 @@ void concat_range_aggregate(struct expr *set)
 				tmp = constant_expr_alloc(&r1->location, r1->dtype,
 							  BYTEORDER_BIG_ENDIAN,
 							  (str_len + 1) * BITS_PER_BYTE, data);
-				tmp->len = r2->len;
 				list_replace(&r2->list, &tmp->list);
 				r2_next = tmp->list.next;
 				expr_free(r2);
Signature · 1 line
2.51.0
author reviewer
#30 lore raw

PATCH 19/28 netlink: Introduce struct nft_data_linearize::byteorder

In reply to Phil Sutter

Bits in this field indicate data is in host byte order and thus may need conversion when being printed "byte by byte" in libnftnl.

With regular immediate values, this field's value may be treated as boolean (zero or not). Concatenations may contain components in different byteorder, so with them each bit (at pos N) indicates whether a component (at index N) is in host byte order. A follow-up patch collecting components' lengths will complete this.

---
 include/netlink.h |  1 +
 src/netlink.c     | 28 ++++++++++++++++++++++++----
 2 files changed, 25 insertions(+), 4 deletions(-)
include/netlink.h +1 -0
index 2737d5708b295..a762cb485784f 100644
@@ -106,6 +106,7 @@ struct nft_data_linearize {
 	char		chain[NFT_CHAIN_MAXNAMELEN];
 	uint32_t	chain_id;
 	int		verdict;
+	uint32_t	byteorder;
 };
 
 struct nft_data_delinearize {
src/netlink.c +24 -4
index 3228747a74af8..2a4315c691059 100644
@@ -248,6 +248,7 @@ void netlink_gen_raw_data(const mpz_t value, enum byteorder byteorder,
 	assert(len > 0);
 	mpz_export_data(data->value, value, byteorder, len);
 	data->len = len;
+	data->byteorder = byteorder == BYTEORDER_HOST_ENDIAN ? UINT32_MAX : 0;
 }
 
 static int netlink_export_pad(unsigned char *data, const mpz_t v,
@@ -353,14 +354,19 @@ static void netlink_gen_concat_key(const struct expr *expr,
 	unsigned char data[NFT_MAX_EXPR_LEN_BYTES];
 	unsigned int offset = 0;
 	const struct expr *i;
+	int n = 0;
 
 	if (len > sizeof(data))
 		BUG("Value export of %u bytes would overflow", len);
 
 	memset(data, 0, sizeof(data));
 
-	list_for_each_entry(i, &expr_concat(expr)->expressions, list)
+	list_for_each_entry(i, &expr_concat(expr)->expressions, list) {
 		offset += __netlink_gen_concat_key(expr->flags, i, data + offset);
+		if (i->byteorder == BYTEORDER_HOST_ENDIAN)
+			nld->byteorder |= 1 << n;
+		n++;
+	}
 
 	nft_data_memcpy(nld, data, len);
 }
@@ -417,17 +423,26 @@ static void __netlink_gen_concat_expand(const struct expr *expr,
 	unsigned char data[NFT_MAX_EXPR_LEN_BYTES];
 	unsigned int offset = 0;
 	const struct expr *i;
+	int n = 0;
 
 	if (len > sizeof(data))
 		BUG("Value export of %u bytes would overflow", len);
 
 	memset(data, 0, sizeof(data));
 
-	list_for_each_entry(i, &expr_concat(expr)->expressions, list)
+	list_for_each_entry(i, &expr_concat(expr)->expressions, list) {
 		offset += __netlink_gen_concat_data(false, i, data + offset);
+		if (i->byteorder == BYTEORDER_HOST_ENDIAN)
+			nld->byteorder |= 1 << n;
+		n++;
+	}
 
-	list_for_each_entry(i, &expr_concat(expr)->expressions, list)
+	list_for_each_entry(i, &expr_concat(expr)->expressions, list) {
 		offset += __netlink_gen_concat_data(true, i, data + offset);
+		if (i->byteorder == BYTEORDER_HOST_ENDIAN)
+			nld->byteorder |= 1 << n;
+		n++;
+	}
 
 	nft_data_memcpy(nld, data, len);
 }
@@ -439,14 +454,19 @@ static void __netlink_gen_concat(const struct expr *expr,
 	unsigned char data[NFT_MAX_EXPR_LEN_BYTES];
 	unsigned int offset = 0;
 	const struct expr *i;
+	int n = 0;
 
 	if (len > sizeof(data))
 		BUG("Value export of %u bytes would overflow", len);
 
 	memset(data, 0, sizeof(data));
 
-	list_for_each_entry(i, &expr_concat(expr)->expressions, list)
+	list_for_each_entry(i, &expr_concat(expr)->expressions, list) {
 		offset += __netlink_gen_concat_data(expr->flags, i, data + offset);
+		if (i->byteorder == BYTEORDER_HOST_ENDIAN)
+			nld->byteorder |= 1 << n;
+		n++;
+	}
 
 	nft_data_memcpy(nld, data, len);
 }
Signature · 1 line
2.51.0
author reviewer
#31 lore raw

PATCH 20/28 netlink: Introduce struct nft_data_linearize::sizes

In reply to Phil Sutter

This array holds each concat component's actual length in bytes. It is crucial because component data is padded to match register lengths and if libnftnl has to print data "in reverse" (to print Little Endian values byte-by-byte), it will print extra leading zeroes with odd data lengths and thus indicate number of printed bytes does no longer correctly reflect actual data length.

---
 include/netlink.h |  1 +
 src/netlink.c     | 14 ++++++++++----
 2 files changed, 11 insertions(+), 4 deletions(-)
include/netlink.h +1 -0
index a762cb485784f..aa25094dc7c1d 100644
@@ -107,6 +107,7 @@ struct nft_data_linearize {
 	uint32_t	chain_id;
 	int		verdict;
 	uint32_t	byteorder;
+	uint8_t		sizes[NFT_REG32_COUNT];
 };
 
 struct nft_data_delinearize {
src/netlink.c +10 -4
index 2a4315c691059..9d6cc31e40fb5 100644
@@ -365,7 +365,7 @@ static void netlink_gen_concat_key(const struct expr *expr,
 		offset += __netlink_gen_concat_key(expr->flags, i, data + offset);
 		if (i->byteorder == BYTEORDER_HOST_ENDIAN)
 			nld->byteorder |= 1 << n;
-		n++;
+		nld->sizes[n++] = div_round_up(i->len, BITS_PER_BYTE);
 	}
 
 	nft_data_memcpy(nld, data, len);
@@ -434,14 +434,14 @@ static void __netlink_gen_concat_expand(const struct expr *expr,
 		offset += __netlink_gen_concat_data(false, i, data + offset);
 		if (i->byteorder == BYTEORDER_HOST_ENDIAN)
 			nld->byteorder |= 1 << n;
-		n++;
+		nld->sizes[n++] = div_round_up(i->len, BITS_PER_BYTE);
 	}
 
 	list_for_each_entry(i, &expr_concat(expr)->expressions, list) {
 		offset += __netlink_gen_concat_data(true, i, data + offset);
 		if (i->byteorder == BYTEORDER_HOST_ENDIAN)
 			nld->byteorder |= 1 << n;
-		n++;
+		nld->sizes[n++] = div_round_up(i->len, BITS_PER_BYTE);
 	}
 
 	nft_data_memcpy(nld, data, len);
@@ -465,7 +465,7 @@ static void __netlink_gen_concat(const struct expr *expr,
 		offset += __netlink_gen_concat_data(expr->flags, i, data + offset);
 		if (i->byteorder == BYTEORDER_HOST_ENDIAN)
 			nld->byteorder |= 1 << n;
-		n++;
+		nld->sizes[n++] = div_round_up(i->len, BITS_PER_BYTE);
 	}
 
 	nft_data_memcpy(nld, data, len);
@@ -541,6 +541,8 @@ static void netlink_gen_range(const struct expr *expr,
 	offset = netlink_export_pad(data, expr->left->value, expr->left);
 	netlink_export_pad(data + offset, expr->right->value, expr->right);
 	nft_data_memcpy(nld, data, len);
+	nld->sizes[0] = div_round_up(expr->left->len, BITS_PER_BYTE);
+	nld->sizes[1] = div_round_up(expr->right->len, BITS_PER_BYTE);
 }
 
 static void netlink_gen_range_value(const struct expr *expr,
@@ -557,6 +559,8 @@ static void netlink_gen_range_value(const struct expr *expr,
 	offset = netlink_export_pad(data, expr->range.low, expr);
 	netlink_export_pad(data + offset, expr->range.high, expr);
 	nft_data_memcpy(nld, data, len);
+	nld->sizes[0] = div_round_up(expr->len, BITS_PER_BYTE);
+	nld->sizes[1] = nld->sizes[0];
 }
 
 static void netlink_gen_prefix(const struct expr *expr,
@@ -577,6 +581,8 @@ static void netlink_gen_prefix(const struct expr *expr,
 	mpz_clear(v);
 
 	nft_data_memcpy(nld, data, len);
+	nld->sizes[0] = div_round_up(expr->prefix->len, BITS_PER_BYTE);
+	nld->sizes[1] = nld->sizes[0];
 }
 
 static void netlink_gen_key(const struct expr *expr,
Signature · 1 line
2.51.0
#32 lore raw

Re: [nft PATCH 20/28] netlink: Introduce struct nft_data_linearize::sizes

Quoted 6 lines · Phil Sutter

This array holds each concat component's actual length in bytes. It is crucial because component data is padded to match register lengths and if libnftnl has to print data "in reverse" (to print Little Endian values byte-by-byte), it will print extra leading zeroes with odd data lengths and thus indicate number of printed bytes does no longer correctly reflect actual data length.

What patch is the first client for this new field?

Quoted 87 lines
---
 include/netlink.h |  1 +
 src/netlink.c     | 14 ++++++++++----
 2 files changed, 11 insertions(+), 4 deletions(-)
include/netlink.h +1 -0
index a762cb485784f..aa25094dc7c1d 100644
@@ -107,6 +107,7 @@ struct nft_data_linearize {
 	uint32_t	chain_id;
 	int		verdict;
 	uint32_t	byteorder;
+	uint8_t		sizes[NFT_REG32_COUNT];
 };
 
 struct nft_data_delinearize {
src/netlink.c +10 -4
index 2a4315c691059..9d6cc31e40fb5 100644
@@ -365,7 +365,7 @@ static void netlink_gen_concat_key(const struct expr *expr,
 		offset += __netlink_gen_concat_key(expr->flags, i, data + offset);
 		if (i->byteorder == BYTEORDER_HOST_ENDIAN)
 			nld->byteorder |= 1 << n;
-		n++;
+		nld->sizes[n++] = div_round_up(i->len, BITS_PER_BYTE);
 	}
 
 	nft_data_memcpy(nld, data, len);
@@ -434,14 +434,14 @@ static void __netlink_gen_concat_expand(const struct expr *expr,
 		offset += __netlink_gen_concat_data(false, i, data + offset);
 		if (i->byteorder == BYTEORDER_HOST_ENDIAN)
 			nld->byteorder |= 1 << n;
-		n++;
+		nld->sizes[n++] = div_round_up(i->len, BITS_PER_BYTE);
 	}
 
 	list_for_each_entry(i, &expr_concat(expr)->expressions, list) {
 		offset += __netlink_gen_concat_data(true, i, data + offset);
 		if (i->byteorder == BYTEORDER_HOST_ENDIAN)
 			nld->byteorder |= 1 << n;
-		n++;
+		nld->sizes[n++] = div_round_up(i->len, BITS_PER_BYTE);
 	}
 
 	nft_data_memcpy(nld, data, len);
@@ -465,7 +465,7 @@ static void __netlink_gen_concat(const struct expr *expr,
 		offset += __netlink_gen_concat_data(expr->flags, i, data + offset);
 		if (i->byteorder == BYTEORDER_HOST_ENDIAN)
 			nld->byteorder |= 1 << n;
-		n++;
+		nld->sizes[n++] = div_round_up(i->len, BITS_PER_BYTE);
 	}
 
 	nft_data_memcpy(nld, data, len);
@@ -541,6 +541,8 @@ static void netlink_gen_range(const struct expr *expr,
 	offset = netlink_export_pad(data, expr->left->value, expr->left);
 	netlink_export_pad(data + offset, expr->right->value, expr->right);
 	nft_data_memcpy(nld, data, len);
+	nld->sizes[0] = div_round_up(expr->left->len, BITS_PER_BYTE);
+	nld->sizes[1] = div_round_up(expr->right->len, BITS_PER_BYTE);
 }
 
 static void netlink_gen_range_value(const struct expr *expr,
@@ -557,6 +559,8 @@ static void netlink_gen_range_value(const struct expr *expr,
 	offset = netlink_export_pad(data, expr->range.low, expr);
 	netlink_export_pad(data + offset, expr->range.high, expr);
 	nft_data_memcpy(nld, data, len);
+	nld->sizes[0] = div_round_up(expr->len, BITS_PER_BYTE);
+	nld->sizes[1] = nld->sizes[0];
 }
 
 static void netlink_gen_prefix(const struct expr *expr,
@@ -577,6 +581,8 @@ static void netlink_gen_prefix(const struct expr *expr,
 	mpz_clear(v);
 
 	nft_data_memcpy(nld, data, len);
+	nld->sizes[0] = div_round_up(expr->prefix->len, BITS_PER_BYTE);
+	nld->sizes[1] = nld->sizes[0];
 }
 
 static void netlink_gen_key(const struct expr *expr,
Signature · 1 line
2.51.0
author reviewer
#33 lore raw

Re: [nft PATCH 20/28] netlink: Introduce struct nft_data_linearize::sizes

Quoted 9 lines · Pablo Neira Ayuso
Quoted 6 lines · Phil Sutter

This array holds each concat component's actual length in bytes. It is crucial because component data is padded to match register lengths and if libnftnl has to print data "in reverse" (to print Little Endian values byte-by-byte), it will print extra leading zeroes with odd data lengths and thus indicate number of printed bytes does no longer correctly reflect actual data length.

What patch is the first client for this new field?

The next one, patch 21. It changes nftables to call the new _set_imm() libnftnl functions which accept byteorder and sizes as parameters.

Cheers, Phil

author reviewer
#34 lore raw

PATCH 21/28 netlink: Make use of nftnl_{expr,set_elem}_set_imm()

In reply to Phil Sutter

Pass the previously collected byteorder (and sizes) to libnftnl for improved netlink debug output.

---
 src/netlink.c           | 18 ++++++++++++------
 src/netlink_linearize.c | 34 ++++++++++++++++++++++------------
 2 files changed, 34 insertions(+), 18 deletions(-)
src/netlink.c +12 -6
index 9d6cc31e40fb5..68228bdc5c99a 100644
@@ -139,17 +139,22 @@ struct nftnl_set_elem *alloc_nftnl_setelem(const struct expr *set,
 			netlink_gen_key(key, &nld);
 			key->flags &= ~EXPR_F_INTERVAL;
 
-			nftnl_set_elem_set(nlse, NFTNL_SET_ELEM_KEY, nld.value, nld.len);
+			nftnl_set_elem_set_imm(nlse, NFTNL_SET_ELEM_KEY,
+					       nld.value, nld.len,
+					       nld.byteorder, nld.sizes);
 
 			key->flags |= EXPR_F_INTERVAL_END;
 			netlink_gen_key(key, &nld);
 			key->flags &= ~EXPR_F_INTERVAL_END;
 
-			nftnl_set_elem_set(nlse, NFTNL_SET_ELEM_KEY_END,
-					   nld.value, nld.len);
+			nftnl_set_elem_set_imm(nlse, NFTNL_SET_ELEM_KEY_END,
+					       nld.value, nld.len,
+					       nld.byteorder, nld.sizes);
 		} else {
 			netlink_gen_key(key, &nld);
-			nftnl_set_elem_set(nlse, NFTNL_SET_ELEM_KEY, nld.value, nld.len);
+			nftnl_set_elem_set_imm(nlse, NFTNL_SET_ELEM_KEY,
+					       nld.value, nld.len,
+					       nld.byteorder, nld.sizes);
 		}
 		break;
 	}
@@ -217,8 +222,9 @@ struct nftnl_set_elem *alloc_nftnl_setelem(const struct expr *set,
 		case EXPR_RANGE:
 		case EXPR_RANGE_VALUE:
 		case EXPR_PREFIX:
-			nftnl_set_elem_set(nlse, NFTNL_SET_ELEM_DATA,
-					   nld.value, nld.len);
+			nftnl_set_elem_set_imm(nlse, NFTNL_SET_ELEM_DATA,
+					       nld.value, nld.len,
+					       nld.byteorder, nld.sizes);
 			break;
 		default:
 			BUG("unexpected set element expression\n");
src/netlink_linearize.c +22 -12
index 43cfbfa75f3d2..36a539bf96283 100644
@@ -482,8 +482,10 @@ static struct expr *netlink_gen_prefix(struct netlink_linearize_ctx *ctx,
 	netlink_put_register(nle, NFTNL_EXPR_BITWISE_SREG, sreg);
 	netlink_put_register(nle, NFTNL_EXPR_BITWISE_DREG, sreg);
 	nftnl_expr_set_u32(nle, NFTNL_EXPR_BITWISE_LEN, nld.len);
-	nftnl_expr_set(nle, NFTNL_EXPR_BITWISE_MASK, nld.value, nld.len);
-	nftnl_expr_set(nle, NFTNL_EXPR_BITWISE_XOR, zero.value, zero.len);
+	nftnl_expr_set_imm(nle, NFTNL_EXPR_BITWISE_MASK,
+			   nld.value, nld.len, nld.byteorder);
+	nftnl_expr_set_imm(nle, NFTNL_EXPR_BITWISE_XOR,
+			   zero.value, zero.len, zero.byteorder);
 	nft_rule_add_expr(ctx, nle, &expr->location);
 
 	return expr->right->prefix;
@@ -551,15 +553,18 @@ static void netlink_gen_flagcmp(struct netlink_linearize_ctx *ctx,
 		nle = alloc_nft_expr("cmp");
 		netlink_put_register(nle, NFTNL_EXPR_CMP_SREG, sreg);
 		nftnl_expr_set_u32(nle, NFTNL_EXPR_CMP_OP, NFT_CMP_EQ);
-		nftnl_expr_set(nle, NFTNL_EXPR_CMP_DATA, nld2.value, nld2.len);
+		nftnl_expr_set_imm(nle, NFTNL_EXPR_CMP_DATA,
+				   nld2.value, nld2.len, nld2.byteorder);
 		nft_rule_add_expr(ctx, nle, &expr->location);
 	} else {
 		nle = alloc_nft_expr("bitwise");
 		netlink_put_register(nle, NFTNL_EXPR_BITWISE_SREG, sreg);
 		netlink_put_register(nle, NFTNL_EXPR_BITWISE_DREG, sreg);
 		nftnl_expr_set_u32(nle, NFTNL_EXPR_BITWISE_LEN, len);
-		nftnl_expr_set(nle, NFTNL_EXPR_BITWISE_MASK, nld2.value, nld2.len);
-		nftnl_expr_set(nle, NFTNL_EXPR_BITWISE_XOR, nld.value, nld.len);
+		nftnl_expr_set_imm(nle, NFTNL_EXPR_BITWISE_MASK,
+				   nld2.value, nld2.len, nld2.byteorder);
+		nftnl_expr_set_imm(nle, NFTNL_EXPR_BITWISE_XOR,
+				   nld.value, nld.len, nld.byteorder);
 		nft_rule_add_expr(ctx, nle, &expr->location);
 
 		nle = alloc_nft_expr("cmp");
@@ -569,7 +574,8 @@ static void netlink_gen_flagcmp(struct netlink_linearize_ctx *ctx,
 		else
 			nftnl_expr_set_u32(nle, NFTNL_EXPR_CMP_OP, NFT_CMP_NEQ);
 
-		nftnl_expr_set(nle, NFTNL_EXPR_CMP_DATA, nld.value, nld.len);
+		nftnl_expr_set_imm(nle, NFTNL_EXPR_CMP_DATA,
+				   nld.value, nld.len, nld.byteorder);
 		nft_rule_add_expr(ctx, nle, &expr->location);
 	}
 
@@ -645,7 +651,8 @@ static void netlink_gen_relational(struct netlink_linearize_ctx *ctx,
 	nftnl_expr_set_u32(nle, NFTNL_EXPR_CMP_OP,
 			   netlink_gen_cmp_op(expr->op));
 	netlink_gen_data(right, &nld);
-	nftnl_expr_set(nle, NFTNL_EXPR_CMP_DATA, nld.value, len);
+	nftnl_expr_set_imm(nle, NFTNL_EXPR_CMP_DATA,
+			   nld.value, len, nld.byteorder);
 	release_register(ctx, expr->left);
 
 	nft_rule_add_expr(ctx, nle, &expr->location);
@@ -681,8 +688,8 @@ static void netlink_gen_bitwise_shift(struct netlink_linearize_ctx *ctx,
 	netlink_gen_raw_data(expr->right->value, expr->right->byteorder,
 			     sizeof(uint32_t), &nld);
 
-	nftnl_expr_set(nle, NFTNL_EXPR_BITWISE_DATA, nld.value,
-		       nld.len);
+	nftnl_expr_set_imm(nle, NFTNL_EXPR_BITWISE_DATA,
+			   nld.value, nld.len, nld.byteorder);
 
 	nft_rule_add_expr(ctx, nle, &expr->location);
 }
@@ -747,9 +754,11 @@ static void netlink_gen_bitwise_mask_xor(struct netlink_linearize_ctx *ctx,
 	nftnl_expr_set_u32(nle, NFTNL_EXPR_BITWISE_LEN, len);
 
 	netlink_gen_raw_data(mask, expr->byteorder, len, &nld);
-	nftnl_expr_set(nle, NFTNL_EXPR_BITWISE_MASK, nld.value, nld.len);
+	nftnl_expr_set_imm(nle, NFTNL_EXPR_BITWISE_MASK,
+			   nld.value, nld.len, nld.byteorder);
 	netlink_gen_raw_data(xor, expr->byteorder, len, &nld);
-	nftnl_expr_set(nle, NFTNL_EXPR_BITWISE_XOR, nld.value, nld.len);
+	nftnl_expr_set_imm(nle, NFTNL_EXPR_BITWISE_XOR,
+			   nld.value, nld.len, nld.byteorder);
 
 	mpz_clear(tmp);
 	mpz_clear(val);
@@ -871,7 +880,8 @@ static void netlink_gen_immediate(struct netlink_linearize_ctx *ctx,
 	netlink_gen_data(expr, &nld);
 	switch (expr->etype) {
 	case EXPR_VALUE:
-		nftnl_expr_set(nle, NFTNL_EXPR_IMM_DATA, nld.value, nld.len);
+		nftnl_expr_set_imm(nle, NFTNL_EXPR_IMM_DATA,
+				   nld.value, nld.len, nld.byteorder);
 		break;
 	case EXPR_VERDICT:
 		if (expr->chain) {
Signature · 1 line
2.51.0
author reviewer
#35 lore raw

PATCH 22/28 mergesort: Linearize concatentations in network byte order

In reply to Phil Sutter

Results are more stable this way.

---
 src/mergesort.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/mergesort.c +2 -2
index bd1c21877b21d..95037e5be8608 100644
@@ -20,11 +20,11 @@ static void concat_expr_msort_value(const struct expr *expr, mpz_t value)
 
 	list_for_each_entry(i, &expr_concat(expr)->expressions, list) {
 		ilen = div_round_up(i->len, BITS_PER_BYTE);
-		mpz_export_data(data + len, i->value, i->byteorder, ilen);
+		mpz_export_data(data + len, i->value, BYTEORDER_BIG_ENDIAN, ilen);
 		len += ilen;
 	}
 
-	mpz_import_data(value, data, BYTEORDER_HOST_ENDIAN, len);
+	mpz_import_data(value, data, BYTEORDER_BIG_ENDIAN, len);
 }
 
 static mpz_srcptr expr_msort_value(const struct expr *expr, mpz_t value)
Signature · 1 line
2.51.0
#36 lore raw

Re: [nft PATCH 22/28] mergesort: Linearize concatentations in network byte order

Quoted 1 line · Phil Sutter

Results are more stable this way.

Why? Sorry, but maybe this series is oversplit? It is a bit complicate to follow the rationale where all this small patches are taking us.

I find that a single patch with a oneliner explaination.

Question: Does tests/shell and tests/py work if I stop at any random patch in this series?

Quoted 26 lines
---
 src/mergesort.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/mergesort.c +2 -2
index bd1c21877b21d..95037e5be8608 100644
@@ -20,11 +20,11 @@ static void concat_expr_msort_value(const struct expr *expr, mpz_t value)
 
 	list_for_each_entry(i, &expr_concat(expr)->expressions, list) {
 		ilen = div_round_up(i->len, BITS_PER_BYTE);
-		mpz_export_data(data + len, i->value, i->byteorder, ilen);
+		mpz_export_data(data + len, i->value, BYTEORDER_BIG_ENDIAN, ilen);
 		len += ilen;
 	}
 
-	mpz_import_data(value, data, BYTEORDER_HOST_ENDIAN, len);
+	mpz_import_data(value, data, BYTEORDER_BIG_ENDIAN, len);
 }
 
 static mpz_srcptr expr_msort_value(const struct expr *expr, mpz_t value)
Signature · 1 line
2.51.0
author reviewer
#37 lore raw

Re: [nft PATCH 22/28] mergesort: Linearize concatentations in network byte order

Quoted 5 lines · Pablo Neira Ayuso
Quoted 1 line · Phil Sutter

Results are more stable this way.

Why? Sorry, but maybe this series is oversplit? It is a bit complicate to follow the rationale where all this small patches are taking us.

TBH, I don't fully understand how all this works internally given that GMP has its own way of organizing data.

Quoted 1 line

I find that a single patch with a oneliner explaination.

This change is quite unrelated to others, so folding it into another patch might have hidden it. I get your point about reviewing 28 patches, but there is a summary in the cover letter guiding through the series.

The effects of this patch show in patch 23 which updates the test cases. I can't tell for sure I didn't cause a big mess wrt. defined byteorder of strings and dropped/changed byteorder conversions but the resulting element ordering looks right to me.

Quoted 2 lines

Question: Does tests/shell and tests/py work if I stop at any random patch in this series?

Certainly not! I would have to mix code changes and test case updates to keep test suites passing after each patch. If you like to see what each patch changes, I can provide a series which does this. I guessed it would be easier to review if code changes were separate from "noise".

Also maybe worth mentioning explicitly: This series (and the related libnftnl one) does not intend to contain functional changes and merely change how libnftnl prints data, apart from two things:

* Set element ordering is changed by this patch

Since nft-test.py explicitly ignores changes in element ordering I consider this negligible.

* libnftnl stores u32 userdata values in Big Endian

Assuming that the kernel ignores userdata and user space stores/retrieves it using libnftnl, this should not have a practical effect (apart from userdata becoming stable).

Cheers, Phil

author reviewer
#38 lore raw

PATCH 23/28 tests: Adjust JSON records to improved element sorting

In reply to Phil Sutter

Contrary to with standard syntax, nft-test.py does not cover for deviating set element ordering when comparing JSON output with records. Sorting sets in JSON output is tedious due to potential nesting - the simple algorithm searching for curly braces and checking each element is present on both sides won't do here.

Also the above would not cover for shell test suite anyway, so just update the records.

---
 tests/py/any/ct.t.json.output                 | 20 ++---
 tests/py/any/meta.t.json.output               | 54 -------------
 tests/py/any/queue.t.json.output              |  4 +-
 tests/py/any/tcpopt.t.json.output             | 77 -------------------
 tests/py/inet/osf.t.json.output               | 54 +++++++++++++
 .../testcases/maps/dumps/0012map_0.json-nft   | 20 ++---
 .../shell/testcases/maps/dumps/0012map_0.nft  |  8 +-
 .../maps/dumps/named_ct_objects.json-nft      | 12 +--
 .../testcases/maps/dumps/named_ct_objects.nft |  6 +-
 .../maps/dumps/typeof_integer_0.json-nft      | 12 +--
 .../testcases/maps/dumps/typeof_integer_0.nft |  4 +-
 .../dumps/0012different_defines_0.json-nft    |  8 +-
 .../nft-f/dumps/0012different_defines_0.nft   |  2 +-
 .../dumps/merge_nat_inet.json-nft             | 12 +--
 .../optimizations/dumps/merge_nat_inet.nft    |  2 +-
 .../optimizations/dumps/merge_reject.json-nft | 16 ++--
 .../optimizations/dumps/merge_reject.nft      |  4 +-
 .../dumps/merge_stmts_concat.json-nft         | 42 +++++-----
 .../dumps/merge_stmts_concat.nft              |  8 +-
 .../dumps/merge_stmts_concat_vmap.json-nft    |  4 +-
 .../dumps/merge_stmts_concat_vmap.nft         |  2 +-
 .../sets/dumps/0029named_ifname_dtype_0.nft   |  4 +-
 .../0037_set_with_inet_service_0.json-nft     | 12 +--
 .../dumps/0037_set_with_inet_service_0.nft    |  8 +-
 .../sets/dumps/sets_with_ifnames.json-nft     |  4 +-
 .../sets/dumps/sets_with_ifnames.nft          |  2 +-
 .../testcases/sets/dumps/typeof_sets_0.nft    |  4 +-
 tests/shell/testcases/sets/typeof_sets_0      |  4 +-
 28 files changed, 166 insertions(+), 243 deletions(-)
tests/py/any/ct.t.json.output +10 -10
index 82634c2da6720..3f7959301354a 100644
@@ -494,14 +494,14 @@
                 "set": [
                     {
                         "concat": [
-                            "new",
-                            305419896
+                            "established",
+                            309876276
                         ]
                     },
                     {
                         "concat": [
-                            "established",
-                            309876276
+                            "new",
+                            305419896
                         ]
                     },
                     {
@@ -578,23 +578,23 @@
                     [
                         {
                             "concat": [
-                                "new",
-                                305419896
+                                "established",
+                                2271560481
                             ]
                         },
                         {
-                            "drop": null
+                            "accept": null
                         }
                     ],
                     [
                         {
                             "concat": [
-                                "established",
-                                2271560481
+                                "new",
+                                305419896
                             ]
                         },
                         {
-                            "accept": null
+                            "drop": null
                         }
                     ]
                 ]
tests/py/any/meta.t.json.output +0 -54

60 lines not on this page · raw message

tests/py/any/queue.t.json.output +2 -2
index ea3722383f113..90670cc938866 100644
@@ -104,11 +104,11 @@
                                 0
                             ],
                             [
-                                "ppp0",
+                                "eth1",
                                 2
                             ],
                             [
-                                "eth1",
+                                "ppp0",
                                 2
                             ]
                         ]
tests/py/any/tcpopt.t.json.output +0 -77

80 lines not on this page · raw message

tests/py/inet/osf.t.json.output +54 -0

63 lines not on this page · raw message

tests/shell/testcases/maps/dumps/0012map_0.json-nft +10 -10
index 2892e11d71f54..6c885703ffd6b 100644
@@ -32,21 +32,21 @@
         "map": "verdict",
         "elem": [
           [
-            "lo",
+            "eth0",
             {
-              "accept": null
+              "drop": null
             }
           ],
           [
-            "eth0",
+            "eth1",
             {
               "drop": null
             }
           ],
           [
-            "eth1",
+            "lo",
             {
-              "drop": null
+              "accept": null
             }
           ]
         ]
@@ -69,21 +69,21 @@
               "data": {
                 "set": [
                   [
-                    "lo",
+                    "eth0",
                     {
-                      "accept": null
+                      "drop": null
                     }
                   ],
                   [
-                    "eth0",
+                    "eth1",
                     {
                       "drop": null
                     }
                   ],
                   [
-                    "eth1",
+                    "lo",
                     {
-                      "drop": null
+                      "accept": null
                     }
                   ]
                 ]
tests/shell/testcases/maps/dumps/0012map_0.nft +4 -4
index e734fc1c70b93..0df329a550518 100644
@@ -1,12 +1,12 @@
 table ip x {
 	map z {
 		type ifname : verdict
-		elements = { "lo" : accept,
-			     "eth0" : drop,
-			     "eth1" : drop }
+		elements = { "eth0" : drop,
+			     "eth1" : drop,
+			     "lo" : accept }
 	}
 
 	chain y {
-		iifname vmap { "lo" : accept, "eth0" : drop, "eth1" : drop }
+		iifname vmap { "eth0" : drop, "eth1" : drop, "lo" : accept }
 	}
 }
tests/shell/testcases/maps/dumps/named_ct_objects.json-nft +6 -6
index c0f270e372b24..21ab05653a6d3 100644
@@ -195,8 +195,8 @@
         },
         "handle": 0,
         "elem": [
-          "sip",
-          "ftp"
+          "ftp",
+          "sip"
         ]
       }
     },
@@ -318,8 +318,8 @@
                     [
                       {
                         "concat": [
-                          "feed::17",
-                          512
+                          "dead::beef",
+                          123
                         ]
                       },
                       "exp2"
@@ -327,8 +327,8 @@
                     [
                       {
                         "concat": [
-                          "dead::beef",
-                          123
+                          "feed::17",
+                          512
                         ]
                       },
                       "exp2"
tests/shell/testcases/maps/dumps/named_ct_objects.nft +3 -3
index 59f18932b28ad..18b52eb16a052 100644
@@ -50,15 +50,15 @@ table inet t {
 
 	set helpname {
 		typeof ct helper
-		elements = { "sip",
-			     "ftp" }
+		elements = { "ftp",
+			     "sip" }
 	}
 
 	chain y {
 		ct expectation set ip saddr map @exp
 		ct expectation set ip6 saddr map { dead::beef : "exp2" }
 		ct expectation set ip6 daddr map { dead::beef : "exp2", feed::17 : "exp2" }
-		ct expectation set ip6 daddr . tcp dport map { feed::17 . 512 : "exp2", dead::beef . 123 : "exp2" }
+		ct expectation set ip6 daddr . tcp dport map { dead::beef . 123 : "exp2", feed::17 . 512 : "exp2" }
 		ct helper set ip6 saddr map { 1c3::c01d : "myftp", dead::beef : "myftp" }
 		ct helper set ip6 saddr map @helpobj
 		ct timeout set ip daddr map @timeoutmap
tests/shell/testcases/maps/dumps/typeof_integer_0.json-nft +6 -6
index 1df729b40a74f..65474c9e2a1b1 100644
@@ -117,23 +117,23 @@
           [
             {
               "concat": [
-                30,
-                30
+                20,
+                36
               ]
             },
             {
-              "drop": null
+              "accept": null
             }
           ],
           [
             {
               "concat": [
-                20,
-                36
+                30,
+                30
               ]
             },
             {
-              "accept": null
+              "drop": null
             }
           ]
         ]
tests/shell/testcases/maps/dumps/typeof_integer_0.nft +2 -2
index 19c24febffcc5..7bd7daaad7610 100644
@@ -8,8 +8,8 @@ table inet t {
 
 	map m2 {
 		typeof udp length . @ih,32,32 : verdict
-		elements = { 30 . 0x1e : drop,
-			     20 . 0x24 : accept }
+		elements = { 20 . 0x24 : accept,
+			     30 . 0x1e : drop }
 	}
 
 	chain c {
tests/shell/testcases/nft-f/dumps/0012different_defines_0.json-nft +4 -4
index 0e7ea228501b4..e266bf4c8a698 100644
@@ -361,14 +361,14 @@
                 "set": [
                   {
                     "concat": [
-                      "fe0::2",
-                      "tcp"
+                      "fe0::1",
+                      "udp"
                     ]
                   },
                   {
                     "concat": [
-                      "fe0::1",
-                      "udp"
+                      "fe0::2",
+                      "tcp"
                     ]
                   }
                 ]
tests/shell/testcases/nft-f/dumps/0012different_defines_0.nft +1 -1
index 4734b2fd8bd13..a6e16e7dd0336 100644
@@ -8,7 +8,7 @@ table inet t {
 		ip6 daddr fe0::1 ip6 saddr fe0::2
 		ip saddr vmap { 10.0.0.0 : drop, 10.0.0.2 : accept }
 		ip6 daddr vmap { fe0::1 : drop, fe0::2 : accept }
-		ip6 saddr . ip6 nexthdr { fe0::2 . tcp, fe0::1 . udp }
+		ip6 saddr . ip6 nexthdr { fe0::1 . udp, fe0::2 . tcp }
 		ip daddr . iif vmap { 10.0.0.0 . "lo" : accept }
 		tcp dport 100-222
 		udp dport vmap { 100-222 : accept }
tests/shell/testcases/optimizations/dumps/merge_nat_inet.json-nft +6 -6
index 99930f112ec69..7df802e6bd90b 100644
@@ -93,14 +93,14 @@
                         {
                           "concat": [
                             "enp2s0",
-                            "72.2.3.70",
-                            80
+                            "72.2.3.66",
+                            443
                           ]
                         },
                         {
                           "concat": [
                             "10.1.1.52",
-                            80
+                            443
                           ]
                         }
                       ],
@@ -123,14 +123,14 @@
                         {
                           "concat": [
                             "enp2s0",
-                            "72.2.3.66",
-                            443
+                            "72.2.3.70",
+                            80
                           ]
                         },
                         {
                           "concat": [
                             "10.1.1.52",
-                            443
+                            80
                           ]
                         }
                       ]
tests/shell/testcases/optimizations/dumps/merge_nat_inet.nft +1 -1
index a1a1135482b95..1e08d5a5a1229 100644
@@ -1,7 +1,7 @@
 table inet nat {
 	chain prerouting {
 		oif "lo" accept
-		dnat ip to iifname . ip daddr . tcp dport map { "enp2s0" . 72.2.3.70 . 80 : 10.1.1.52 . 80, "enp2s0" . 72.2.3.66 . 53122 : 10.1.1.10 . 22, "enp2s0" . 72.2.3.66 . 443 : 10.1.1.52 . 443 }
+		dnat ip to iifname . ip daddr . tcp dport map { "enp2s0" . 72.2.3.66 . 443 : 10.1.1.52 . 443, "enp2s0" . 72.2.3.66 . 53122 : 10.1.1.10 . 22, "enp2s0" . 72.2.3.70 . 80 : 10.1.1.52 . 80 }
 	}
 
 	chain postrouting {
tests/shell/testcases/optimizations/dumps/merge_reject.json-nft +8 -8
index 46ed0677d203e..8f468e019657c 100644
@@ -101,15 +101,15 @@
                   {
                     "concat": [
                       "tcp",
-                      "172.30.238.117",
-                      8080
+                      "172.30.33.71",
+                      3306
                     ]
                   },
                   {
                     "concat": [
                       "tcp",
-                      "172.30.33.71",
-                      3306
+                      "172.30.238.117",
+                      8080
                     ]
                   },
                   {
@@ -234,15 +234,15 @@
                   {
                     "concat": [
                       "tcp",
-                      "aaaa::3",
-                      8080
+                      "aaaa::2",
+                      3306
                     ]
                   },
                   {
                     "concat": [
                       "tcp",
-                      "aaaa::2",
-                      3306
+                      "aaaa::3",
+                      8080
                     ]
                   },
                   {
tests/shell/testcases/optimizations/dumps/merge_reject.nft +2 -2
index c29ad6d5648b6..1727d024866d7 100644
@@ -1,13 +1,13 @@
 table ip x {
 	chain y {
 		ip daddr 172.30.33.70 tcp dport 3306 counter packets 0 bytes 0 drop
-		meta l4proto . ip daddr . tcp dport { tcp . 172.30.238.117 . 8080, tcp . 172.30.33.71 . 3306, tcp . 172.30.254.251 . 3306 } counter packets 0 bytes 0 reject
+		meta l4proto . ip daddr . tcp dport { tcp . 172.30.33.71 . 3306, tcp . 172.30.238.117 . 8080, tcp . 172.30.254.251 . 3306 } counter packets 0 bytes 0 reject
 		ip daddr 172.30.254.252 tcp dport 3306 counter packets 0 bytes 0 reject with tcp reset
 	}
 }
 table ip6 x {
 	chain y {
-		meta l4proto . ip6 daddr . tcp dport { tcp . aaaa::3 . 8080, tcp . aaaa::2 . 3306, tcp . aaaa::4 . 3306 } counter packets 0 bytes 0 reject
+		meta l4proto . ip6 daddr . tcp dport { tcp . aaaa::2 . 3306, tcp . aaaa::3 . 8080, tcp . aaaa::4 . 3306 } counter packets 0 bytes 0 reject
 		ip6 daddr aaaa::5 tcp dport 3306 counter packets 0 bytes 0 reject with tcp reset
 	}
 }
tests/shell/testcases/optimizations/dumps/merge_stmts_concat.json-nft +21 -21

104 lines not on this page · raw message

tests/shell/testcases/optimizations/dumps/merge_stmts_concat.nft +4 -4
index d00ac417ca759..6150258512061 100644
@@ -2,18 +2,18 @@ table ip x {
 	chain y {
 		iifname . ip saddr . ip daddr { "eth1" . 1.1.1.1 . 2.2.2.3, "eth1" . 1.1.1.2 . 2.2.2.4, "eth1" . 1.1.1.2 . 2.2.3.0/24, "eth1" . 1.1.1.2 . 2.2.4.0-2.2.4.10, "eth2" . 1.1.1.3 . 2.2.2.5 } accept
 		ip protocol . th dport { tcp . 22, udp . 67 }
-		udp dport . ct state { 137 . new, 138 . new, 137 . untracked, 138 . untracked } accept
+		udp dport . ct state { 137 . new, 137 . untracked, 138 . new, 138 . untracked } accept
 	}
 
 	chain c1 {
-		udp dport . iifname { 51820 . "foo", 514 . "bar", 67 . "bar" } accept
+		udp dport . iifname { 67 . "bar", 514 . "bar", 51820 . "foo" } accept
 	}
 
 	chain c2 {
-		udp dport . iifname { 100 . "foo", 51820 . "foo", 514 . "bar", 67 . "bar" } accept
+		udp dport . iifname { 67 . "bar", 100 . "foo", 514 . "bar", 51820 . "foo" } accept
 	}
 
 	chain c3 {
-		udp dport . iifname { 100 . "foo", 51820 . "foo", 514 . "bar", 67 . "bar", 100 . "test", 51820 . "test" } accept
+		udp dport . iifname { 67 . "bar", 100 . "foo", 100 . "test", 514 . "bar", 51820 . "foo", 51820 . "test" } accept
 	}
 }
tests/shell/testcases/optimizations/dumps/merge_stmts_concat_vmap.json-nft +2 -2
index 5dfa40a821ebe..5259e5647cf08 100644
@@ -60,7 +60,7 @@
                     {
                       "concat": [
                         "broadcast",
-                        547
+                        67
                       ]
                     },
                     {
@@ -71,7 +71,7 @@
                     {
                       "concat": [
                         "broadcast",
-                        67
+                        547
                       ]
                     },
                     {
tests/shell/testcases/optimizations/dumps/merge_stmts_concat_vmap.nft +1 -1
index 780aa09adbe65..81abb99464e0a 100644
@@ -1,6 +1,6 @@
 table ip x {
 	chain x {
-		meta pkttype . udp dport vmap { broadcast . 547 : accept, broadcast . 67 : accept, multicast . 1900 : drop }
+		meta pkttype . udp dport vmap { broadcast . 67 : accept, broadcast . 547 : accept, multicast . 1900 : drop }
 	}
 
 	chain y {
tests/shell/testcases/sets/dumps/0029named_ifname_dtype_0.nft +2 -2
index 6f9832a96188f..e75d8a960e7d0 100644
@@ -12,8 +12,8 @@ table inet t {
 		type inet_service . ifname
 		elements = { 22 . "eth0",
 			     80 . "eth0",
-			     81 . "eth0",
-			     80 . "eth1" }
+			     80 . "eth1",
+			     81 . "eth0" }
 	}
 
 	set nv {
tests/shell/testcases/sets/dumps/0037_set_with_inet_service_0.json-nft +6 -6
index 1c3b559d48d43..cf1c1cc9d479e 100644
@@ -40,16 +40,16 @@
         "elem": [
           {
             "concat": [
-              "192.168.0.113",
+              "192.168.0.12",
               "tcp",
-              22
+              53
             ]
           },
           {
             "concat": [
               "192.168.0.12",
               "tcp",
-              53
+              80
             ]
           },
           {
@@ -61,16 +61,16 @@
           },
           {
             "concat": [
-              "192.168.0.12",
+              "192.168.0.13",
               "tcp",
               80
             ]
           },
           {
             "concat": [
-              "192.168.0.13",
+              "192.168.0.113",
               "tcp",
-              80
+              22
             ]
           }
         ]
tests/shell/testcases/sets/dumps/0037_set_with_inet_service_0.nft +4 -4
index 68b1f7bec4d84..0e85f7c20eba0 100644
@@ -1,11 +1,11 @@
 table inet filter {
 	set myset {
 		type ipv4_addr . inet_proto . inet_service
-		elements = { 192.168.0.113 . tcp . 22,
-			     192.168.0.12 . tcp . 53,
-			     192.168.0.12 . udp . 53,
+		elements = { 192.168.0.12 . tcp . 53,
 			     192.168.0.12 . tcp . 80,
-			     192.168.0.13 . tcp . 80 }
+			     192.168.0.12 . udp . 53,
+			     192.168.0.13 . tcp . 80,
+			     192.168.0.113 . tcp . 22 }
 	}
 
 	chain forward {
tests/shell/testcases/sets/dumps/sets_with_ifnames.json-nft +2 -2
index ac4284293c32a..7b4849e0530d3 100644
@@ -260,8 +260,8 @@
               },
               "right": {
                 "set": [
-                  "eth0",
-                  "abcdef0"
+                  "abcdef0",
+                  "eth0"
                 ]
               }
             }
tests/shell/testcases/sets/dumps/sets_with_ifnames.nft +1 -1
index 77a8baf58cef2..8abca03a080ec 100644
@@ -39,7 +39,7 @@ table inet testifsets {
 	chain v4icmp {
 		iifname @simple counter packets 0 bytes 0
 		iifname @simple_wild counter packets 0 bytes 0
-		iifname { "eth0", "abcdef0" } counter packets 0 bytes 0
+		iifname { "abcdef0", "eth0" } counter packets 0 bytes 0
 		iifname { "abcdef*", "eth0" } counter packets 0 bytes 0
 		iifname vmap @map_wild
 	}
tests/shell/testcases/sets/dumps/typeof_sets_0.nft +2 -2
index 34aaab601cda3..1ceddfc4cded7 100644
@@ -67,8 +67,8 @@ table inet t {
 
 	set s14 {
 		typeof tcp option mptcp subtype . ip daddr
-		elements = { remove-addr . 10.1.1.1,
-			     mp-join . 10.1.1.2 }
+		elements = { mp-join . 10.1.1.2,
+			     remove-addr . 10.1.1.1 }
 	}
 
 	chain c1 {
tests/shell/testcases/sets/typeof_sets_0 +2 -2
index 28e39b4d2cb30..8850e9acea698 100755
@@ -223,8 +223,8 @@ $INPUT_VERSION_SET
 
 	set s14 {
 		typeof tcp option mptcp subtype . ip daddr
-		elements = { remove-addr . 10.1.1.1,
-			     mp-join . 10.1.1.2 }
+		elements = { mp-join . 10.1.1.2,
+			     remove-addr . 10.1.1.1 }
 	}
 $INPUT_OSF_CHAIN
 	chain c2 {
Signature · 1 line
2.51.0
author reviewer
#39 lore raw

PATCH 24/28 tests: py: tools: Add regen_payloads.sh

In reply to Phil Sutter

Use this script to recreate all payload records.

---
 tests/py/tools/regen_payloads.sh | 74 ++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100755 tests/py/tools/regen_payloads.sh
tests/py/tools/regen_payloads.sh new file +74 -0
new file mode 100755
index 0000000000000..9fcbc2c0912a5
@@ -0,0 +1,74 @@
+#!/bin/bash
+
+# update payload records in an automated fashion, trying to reduce diff sizes
+
+
+# scan payloadfile and print record for cmd (if found)
+find_payload() { # (payloadfile, cmd)
+	local found=false
+
+	readarray -t pl <"$1"
+	for l in "${pl[@]}"; do
+		if [[ "$l" == "# "* ]]; then
+			$found && return
+			[[ "$l" == "$2" ]] && found=true
+		fi
+		$found && echo "$l"
+	done
+	$found || echo "Warning: Command '$2' not found in '$1'" >&2
+}
+
+cd $(dirname $0)/../
+
+# make sure no stray output files get in the way
+rm -f */*.got */*.gotgot
+
+# store payload records for later
+# clear payload files to force regenerating (but leave them in place)
+for pl in */*.payload*; do
+	[[ $pl == *.bak ]] && continue # ignore leftover .bak files
+	cp "$pl" "${pl}.bak"
+	echo >"$pl"
+done
+
+# run the testsuite to create .got files
+# pass -f to keep going despite missing payloads
+./nft-test.py -f
+
+# restore old payload records
+for plbak in */*.bak; do
+	mv "$plbak" "${plbak%.bak}"
+done
+
+# sort created got files to match order in old payload records
+for g in ${@:-*/*.payload*.got}; do
+	pl=${g%.got}
+
+	[[ -f $g ]] || continue
+	[[ -f $pl ]] || continue
+
+	readarray -t ploads <"$g"
+	readarray -t cmds <<< $(grep '^# ' $pl)
+	for cmd in "${cmds[@]}"; do
+		found=false
+		for l in "${ploads[@]}"; do
+			if [[ "$l" == "# "* ]]; then
+				$found && break
+				[[ "$l" == "$cmd" ]] && found=true
+			fi
+			$found && [[ "$l" != "" ]] && echo "$l"
+		done
+		if ! $found; then
+			echo "Warning: Command '$cmd' not found in '$g'" >&2
+		else
+			echo ""
+		fi
+	done | head -n -1 >${g}got
+
+	mv "${g}got" "${g}"
+done
+
+# overwrite old payload records with new ones
+for got in */*.payload*.got; do
+	mv "${got}" "${got%.got}"
+done
Signature · 1 line
2.51.0
author reviewer
#40 lore raw

PATCH 25/28 tests: py: Update payload records

In reply to Phil Sutter

This is the bulk change.

---
 tests/py/any/ct.t.payload               |  89 +++--
 tests/py/any/meta.t.payload             | 232 ++++++-------
 tests/py/any/meta.t.payload.bridge      |  10 +-
 tests/py/any/queue.t.payload            |   2 +-
 tests/py/any/rawpayload.t.payload       |  64 ++--
 tests/py/any/rt.t.payload               |   5 +-
 tests/py/any/tcpopt.t.payload           |  88 ++---
 tests/py/arp/arp.t.payload              |  99 +++---
 tests/py/arp/arp.t.payload.netdev       | 189 +++++-----
 tests/py/bridge/ether.t.payload         |  43 ++-
 tests/py/bridge/icmpX.t.payload         |  25 +-
 tests/py/bridge/meta.t.payload          |  20 +-
 tests/py/bridge/redirect.t.payload      |   2 +-
 tests/py/bridge/reject.t.payload        |  43 ++-
 tests/py/bridge/vlan.t.payload          | 262 +++++++-------
 tests/py/bridge/vlan.t.payload.netdev   | 316 ++++++++---------
 tests/py/inet/ah.t.payload              |  89 +++--
 tests/py/inet/comp.t.payload            |  53 ++-
 tests/py/inet/ct.t.payload              |  14 +-
 tests/py/inet/dccp.t.payload            |  53 ++-
 tests/py/inet/dnat.t.payload            |  47 ++-
 tests/py/inet/esp.t.payload             |  45 ++-
 tests/py/inet/ether-ip.t.payload        |  22 +-
 tests/py/inet/ether-ip.t.payload.netdev |  23 +-
 tests/py/inet/ether.t.payload           |  37 +-
 tests/py/inet/ether.t.payload.bridge    |  29 +-
 tests/py/inet/ether.t.payload.ip        |  37 +-
 tests/py/inet/fib.t.payload             |  12 +-
 tests/py/inet/geneve.t.payload          |  83 +++--
 tests/py/inet/gre.t.payload             |  53 ++-
 tests/py/inet/gretap.t.payload          |  59 ++--
 tests/py/inet/icmp.t.payload            |  37 +-
 tests/py/inet/icmpX.t.payload           |  32 +-
 tests/py/inet/ip.t.payload              |   4 +-
 tests/py/inet/ip.t.payload.bridge       |   4 +-
 tests/py/inet/ip.t.payload.inet         |   7 +-
 tests/py/inet/ip.t.payload.netdev       |   7 +-
 tests/py/inet/ip_tcp.t.payload          |  36 +-
 tests/py/inet/ip_tcp.t.payload.bridge   |  35 +-
 tests/py/inet/ip_tcp.t.payload.netdev   |  37 +-
 tests/py/inet/ipsec.t.payload           |  11 +-
 tests/py/inet/map.t.payload             |  11 +-
 tests/py/inet/map.t.payload.ip          |   7 +-
 tests/py/inet/map.t.payload.netdev      |  11 +-
 tests/py/inet/meta.t.payload            |  83 +++--
 tests/py/inet/osf.t.payload             |  16 +-
 tests/py/inet/payloadmerge.t.payload    |  43 ++-
 tests/py/inet/reject.t.payload.inet     |  43 ++-
 tests/py/inet/rt.t.payload              |   7 +-
 tests/py/inet/sctp.t.payload            | 159 +++++----
 tests/py/inet/sets.t.payload.bridge     |  15 +-
 tests/py/inet/sets.t.payload.inet       |  14 +-
 tests/py/inet/sets.t.payload.netdev     |  14 +-
 tests/py/inet/snat.t.payload            |  30 +-
 tests/py/inet/socket.t.payload          |   8 +-
 tests/py/inet/tcp.t.payload             | 360 +++++++++----------
 tests/py/inet/tproxy.t.payload          |  45 ++-
 tests/py/inet/udp.t.payload             | 112 +++---
 tests/py/inet/udplite.t.payload         |  81 +++--
 tests/py/inet/vmap.t.payload            |  13 +-
 tests/py/inet/vmap.t.payload.netdev     |  13 +-
 tests/py/inet/vxlan.t.payload           |  83 +++--
 tests/py/ip/ct.t.payload                |  46 +--
 tests/py/ip/dnat.t.payload.ip           | 117 ++++---
 tests/py/ip/dup.t.payload               |   7 +-
 tests/py/ip/ether.t.payload             |  37 +-
 tests/py/ip/hash.t.payload              |   2 +-
 tests/py/ip/icmp.t.payload.ip           | 312 ++++++++---------
 tests/py/ip/igmp.t.payload              |  61 ++--
 tests/py/ip/ip.t.payload                | 246 ++++++-------
 tests/py/ip/ip.t.payload.bridge         | 440 ++++++++++++------------
 tests/py/ip/ip.t.payload.inet           | 440 ++++++++++++------------
 tests/py/ip/ip.t.payload.netdev         | 434 +++++++++++------------
 tests/py/ip/ip_tcp.t.payload            |   9 +-
 tests/py/ip/masquerade.t.payload        |  71 ++--
 tests/py/ip/meta.t.payload              |  32 +-
 tests/py/ip/numgen.t.payload            |   4 +-
 tests/py/ip/objects.t.payload           |  26 +-
 tests/py/ip/redirect.t.payload          | 121 ++++---
 tests/py/ip/reject.t.payload            |   3 +-
 tests/py/ip/rt.t.payload                |   3 +-
 tests/py/ip/sets.t.payload.inet         |  38 +-
 tests/py/ip/sets.t.payload.ip           |  12 +-
 tests/py/ip/sets.t.payload.netdev       |  38 +-
 tests/py/ip/snat.t.payload              |  74 ++--
 tests/py/ip/tcp.t.payload               |  11 +-
 tests/py/ip/tproxy.t.payload            |  29 +-
 tests/py/ip6/ct.t.payload               |  12 +-
 tests/py/ip6/dnat.t.payload.ip6         |  38 +-
 tests/py/ip6/dst.t.payload.inet         |  60 ++--
 tests/py/ip6/dst.t.payload.ip6          |  30 +-
 tests/py/ip6/dup.t.payload              |   7 +-
 tests/py/ip6/ether.t.payload            |  36 +-
 tests/py/ip6/exthdr.t.payload.ip6       |  25 +-
 tests/py/ip6/frag.t.payload.inet        | 131 ++++---
 tests/py/ip6/frag.t.payload.ip6         |  75 ++--
 tests/py/ip6/frag.t.payload.netdev      | 131 ++++---
 tests/py/ip6/hbh.t.payload.inet         |  65 ++--
 tests/py/ip6/hbh.t.payload.ip6          |  33 +-
 tests/py/ip6/icmpv6.t.payload.ip6       | 322 ++++++++---------
 tests/py/ip6/ip6.t.payload.inet         | 359 ++++++++++---------
 tests/py/ip6/ip6.t.payload.ip6          | 191 +++++-----
 tests/py/ip6/map.t.payload              |   5 +-
 tests/py/ip6/masquerade.t.payload.ip6   |  71 ++--
 tests/py/ip6/meta.t.payload             |  36 +-
 tests/py/ip6/mh.t.payload.inet          | 132 +++----
 tests/py/ip6/mh.t.payload.ip6           |  66 ++--
 tests/py/ip6/redirect.t.payload.ip6     | 105 +++---
 tests/py/ip6/reject.t.payload.ip6       |   3 +-
 tests/py/ip6/rt.t.payload.inet          | 121 ++++---
 tests/py/ip6/rt.t.payload.ip6           |  61 ++--
 tests/py/ip6/rt0.t.payload              |   3 +-
 tests/py/ip6/sets.t.payload.inet        |  18 +-
 tests/py/ip6/sets.t.payload.ip6         |   4 +-
 tests/py/ip6/sets.t.payload.netdev      |  18 +-
 tests/py/ip6/snat.t.payload.ip6         |  23 +-
 tests/py/ip6/srh.t.payload              |  23 +-
 tests/py/ip6/tproxy.t.payload           |  29 +-
 tests/py/ip6/vmap.t.payload.inet        | 169 +++++----
 tests/py/ip6/vmap.t.payload.ip6         |  85 +++--
 tests/py/ip6/vmap.t.payload.netdev      | 169 +++++----
 tests/py/netdev/dup.t.payload           |   3 +-
 tests/py/netdev/fwd.t.payload           |   5 +-
 tests/py/netdev/reject.t.payload        |  41 ++-
 tests/py/netdev/tunnel.t.payload        |   5 +-
 125 files changed, 4385 insertions(+), 4461 deletions(-)
tests/py/any/ct.t.payload +44 -45
index 645041341ca86..ae4e0ec344876 100644
@@ -12,7 +12,7 @@ ip test-ip4 output
 # ct state {new,established, related, untracked}
 __set%d test-ip4 3
 __set%d test-ip4 0
-	element 00000008  : 0 [end]	element 00000002  : 0 [end]	element 00000004  : 0 [end]	element 00000040  : 0 [end]
+	element 00000008	element 00000002	element 00000004	element 00000040
 ip test-ip4 output
   [ ct load state => reg 1 ]
   [ lookup reg 1 set __set%d ]
@@ -20,7 +20,7 @@ ip test-ip4 output
 # ct state != {new,established, related, untracked}
 __set%d test-ip4 3
 __set%d test-ip4 0
-	element 00000008  : 0 [end]	element 00000002  : 0 [end]	element 00000004  : 0 [end]	element 00000040  : 0 [end]
+	element 00000008	element 00000002	element 00000004	element 00000040
 ip test-ip4 output
   [ ct load state => reg 1 ]
   [ lookup reg 1 set __set%d 0x1 ]
@@ -48,27 +48,27 @@ ip test-ip4 output
 # ct direction original
 ip test-ip4 output
   [ ct load direction => reg 1 ]
-  [ cmp eq reg 1 0x00000000 ]
+  [ cmp eq reg 1 0x00 ]
 
 # ct direction != original
 ip test-ip4 output
   [ ct load direction => reg 1 ]
-  [ cmp neq reg 1 0x00000000 ]
+  [ cmp neq reg 1 0x00 ]
 
 # ct direction reply
 ip test-ip4 output
   [ ct load direction => reg 1 ]
-  [ cmp eq reg 1 0x00000001 ]
+  [ cmp eq reg 1 0x01 ]
 
 # ct direction != reply
 ip test-ip4 output
   [ ct load direction => reg 1 ]
-  [ cmp neq reg 1 0x00000001 ]
+  [ cmp neq reg 1 0x01 ]
 
 # ct direction {reply, original}
 __set%d test-ip4 3
 __set%d test-ip4 0
-	element 00000001  : 0 [end]	element 00000000  : 0 [end]
+	element 01	element 00
 ip test-ip4 output
   [ ct load direction => reg 1 ]
   [ lookup reg 1 set __set%d ]
@@ -76,7 +76,7 @@ ip test-ip4 output
 # ct direction != {reply, original}
 __set%d test-ip4 3
 __set%d test-ip4 0
-	element 00000001  : 0 [end]	element 00000000  : 0 [end]
+	element 01	element 00
 ip test-ip4 output
   [ ct load direction => reg 1 ]
   [ lookup reg 1 set __set%d 0x1 ]
@@ -106,7 +106,7 @@ ip test-ip4 output
 # ct status {expected, seen-reply, assured, confirmed, dying}
 __set%d test-ip4 3
 __set%d test-ip4 0
-	element 00000001  : 0 [end]	element 00000002  : 0 [end]	element 00000004  : 0 [end]	element 00000008  : 0 [end]	element 00000200  : 0 [end]
+	element 00000001	element 00000002	element 00000004	element 00000008	element 00000200
 ip test-ip4 output
   [ ct load status => reg 1 ]
   [ lookup reg 1 set __set%d ]
@@ -114,7 +114,7 @@ ip test-ip4 output
 # ct status != {expected, seen-reply, assured, confirmed, dying}
 __set%d test-ip4 3
 __set%d test-ip4 0
-	element 00000001  : 0 [end]	element 00000002  : 0 [end]	element 00000004  : 0 [end]	element 00000008  : 0 [end]	element 00000200  : 0 [end]
+	element 00000001	element 00000002	element 00000004	element 00000008	element 00000200
 ip test-ip4 output
   [ ct load status => reg 1 ]
   [ lookup reg 1 set __set%d 0x1 ]
@@ -172,18 +172,18 @@ ip test-ip4 output
 ip test-ip4 output
   [ ct load mark => reg 1 ]
   [ byteorder reg 1 = hton(reg 1, 4, 4) ]
-  [ range eq reg 1 0x32000000 0x45000000 ]
+  [ range eq reg 1 0x00000032 0x00000045 ]
 
 # ct mark != 0x00000032-0x00000045
 ip test-ip4 output
   [ ct load mark => reg 1 ]
   [ byteorder reg 1 = hton(reg 1, 4, 4) ]
-  [ range neq reg 1 0x32000000 0x45000000 ]
+  [ range neq reg 1 0x00000032 0x00000045 ]
 
 # ct mark {0x32, 0x2222, 0x42de3}
 __set%d test-ip4 3
 __set%d test-ip4 0
-	element 00000032  : 0 [end]	element 00002222  : 0 [end]	element 00042de3  : 0 [end]
+	element 00000032	element 00002222	element 00042de3
 ip test-ip4 output
   [ ct load mark => reg 1 ]
   [ lookup reg 1 set __set%d ]
@@ -191,7 +191,7 @@ ip test-ip4 output
 # ct mark {0x32-0x2222, 0x4444-0x42de3}
 __set%d test-ip4 7
 __set%d test-ip4 0
-        element 00000000  : 1 [end]     element 32000000  : 0 [end]     element 23220000  : 1 [end]     element 44440000  : 0 [end]     element e42d0400  : 1 [end]
+	element 00000000 flags 1	element 00000032	element 00002223 flags 1	element 00004444	element 00042de4 flags 1
 ip test-ip4 output
   [ ct load mark => reg 1 ]
   [ byteorder reg 1 = hton(reg 1, 4, 4) ]
@@ -200,7 +200,7 @@ ip test-ip4 output
 # ct mark != {0x32, 0x2222, 0x42de3}
 __set%d test-ip4 3
 __set%d test-ip4 0
-	element 00000032  : 0 [end]	element 00002222  : 0 [end]	element 00042de3  : 0 [end]
+	element 00000032	element 00002222	element 00042de3
 ip test-ip4 output
   [ ct load mark => reg 1 ]
   [ lookup reg 1 set __set%d 0x1 ]
@@ -239,13 +239,13 @@ ip test-ip4 output
 ip test-ip4 output
   [ ct load expiration => reg 1 ]
   [ byteorder reg 1 = hton(reg 1, 4, 4) ]
-  [ range eq reg 1 0x60ea0000 0x80ee3600 ]
+  [ range eq reg 1 0x0000ea60 0x0036ee80 ]
 
 # ct expiration > 4d23h59m59s
 ip test-ip4 output
   [ ct load expiration => reg 1 ]
   [ byteorder reg 1 = hton(reg 1, 4, 4) ]
-  [ cmp gt reg 1 0x18c8bf19 ]
+  [ cmp gt reg 1 0x19bfc818 ]
 
 # ct expiration != 233
 ip test-ip4 output
@@ -256,18 +256,18 @@ ip test-ip4 output
 ip test-ip4 output
   [ ct load expiration => reg 1 ]
   [ byteorder reg 1 = hton(reg 1, 4, 4) ]
-  [ range eq reg 1 0xe8800000 0xc8af0000 ]
+  [ range eq reg 1 0x000080e8 0x0000afc8 ]
 
 # ct expiration != 33-45
 ip test-ip4 output
   [ ct load expiration => reg 1 ]
   [ byteorder reg 1 = hton(reg 1, 4, 4) ]
-  [ range neq reg 1 0xe8800000 0xc8af0000 ]
+  [ range neq reg 1 0x000080e8 0x0000afc8 ]
 
 # ct expiration {33, 55, 67, 88}
 __set%d test-ip4 3
 __set%d test-ip4 0
-	element 000080e8  : 0 [end]	element 0000d6d8  : 0 [end]	element 000105b8  : 0 [end]	element 000157c0  : 0 [end]
+	element 000080e8	element 0000d6d8	element 000105b8	element 000157c0
 ip test-ip4 output
   [ ct load expiration => reg 1 ]
   [ lookup reg 1 set __set%d ]
@@ -275,7 +275,7 @@ ip test-ip4 output
 # ct expiration != {33, 55, 67, 88}
 __set%d test-ip4 3
 __set%d test-ip4 0
-	element 000080e8  : 0 [end]	element 0000d6d8  : 0 [end]	element 000105b8  : 0 [end]	element 000157c0  : 0 [end]
+	element 000080e8	element 0000d6d8	element 000105b8	element 000157c0
 ip test-ip4 output
   [ ct load expiration => reg 1 ]
   [ lookup reg 1 set __set%d 0x1 ]
@@ -283,7 +283,7 @@ ip test-ip4 output
 # ct expiration {33-55, 66-88}
 __set%d test-ip4 7 size 5
 __set%d test-ip4 0
-	element 00000000  : 1 [end]	element e8800000  : 0 [end]	element d9d60000  : 1 [end]	element d0010100  : 0 [end]	element c1570100  : 1 [end]
+	element 00000000 flags 1	element 000080e8	element 0000d6d9 flags 1	element 000101d0	element 000157c1 flags 1
 ip test-ip4 output 
   [ ct load expiration => reg 1 ]
   [ byteorder reg 1 = hton(reg 1, 4, 4) ]
@@ -292,7 +292,7 @@ ip test-ip4 output
 # ct expiration != {33-55, 66-88}
 __set%d test-ip4 7 size 5
 __set%d test-ip4 0
-	element 00000000  : 1 [end]	element e8800000  : 0 [end]	element d9d60000  : 1 [end]	element d0010100  : 0 [end]	element c1570100  : 1 [end]
+	element 00000000 flags 1	element 000080e8	element 0000d6d9 flags 1	element 000101d0	element 000157c1 flags 1
 ip test-ip4 output 
   [ ct load expiration => reg 1 ]
   [ byteorder reg 1 = hton(reg 1, 4, 4) ]
@@ -301,12 +301,12 @@ ip test-ip4 output
 # ct helper "ftp"
 ip test-ip4 output
   [ ct load helper => reg 1 ]
-  [ cmp eq reg 1 0x00707466 0x00000000 0x00000000 0x00000000 ]
+  [ cmp eq reg 1 0x66747000 0x00000000 0x00000000 0x00000000 ]
 
 # ct state . ct mark { new . 0x12345678, new . 0x34127856, established . 0x12785634}
 __set%d test-ip4 3
 __set%d test-ip4 0
-	element 00000008 12345678  : 0 [end]	element 00000008 34127856  : 0 [end]	element 00000002 12785634  : 0 [end]
+	element 00000008 . 12345678	element 00000008 . 34127856	element 00000002 . 12785634
 ip test-ip4 output
   [ ct load state => reg 1 ]
   [ ct load mark => reg 9 ]
@@ -327,7 +327,7 @@ inet test-inet output
 # ct mark set mark map { 1 : 10, 2 : 20, 3 : 30 }
 __map%d test-ip4 b
 __map%d test-ip4 0
-        element 00000001  : 0000000a 0 [end]    element 00000002  : 00000014 0 [end]    element 00000003  : 0000001e 0 [end]
+	element 00000001 : 0000000a	element 00000002 : 00000014	element 00000003 : 0000001e
 ip test-ip4 output
   [ meta load mark => reg 1 ]
   [ lookup reg 1 set __map%d dreg 1 ]
@@ -346,31 +346,31 @@ ip
 ip test-ip4 output
   [ ct load bytes => reg 1 , dir original ]
   [ byteorder reg 1 = hton(reg 1, 8, 8) ]
-  [ cmp gt reg 1 0x00000000 0xa0860100 ]
+  [ cmp gt reg 1 0x00000000 0x000186a0 ]
 
 # ct reply packets < 100
 ip test-ip4 output
   [ ct load packets => reg 1 , dir reply ]
   [ byteorder reg 1 = hton(reg 1, 8, 8) ]
-  [ cmp lt reg 1 0x00000000 0x64000000 ]
+  [ cmp lt reg 1 0x00000000 0x00000064 ]
 
 # ct bytes > 100000
 ip test-ip4 output
   [ ct load bytes => reg 1 ]
   [ byteorder reg 1 = hton(reg 1, 8, 8) ]
-  [ cmp gt reg 1 0x00000000 0xa0860100 ]
+  [ cmp gt reg 1 0x00000000 0x000186a0 ]
 
 # ct avgpkt > 200
 ip test-ip4 output
   [ ct load avgpkt => reg 1 ]
   [ byteorder reg 1 = hton(reg 1, 8, 8) ]
-  [ cmp gt reg 1 0x00000000 0xc8000000 ]
+  [ cmp gt reg 1 0x00000000 0x000000c8 ]
 
 # ct original avgpkt < 500
 ip test-ip4 output
   [ ct load avgpkt => reg 1 , dir original ]
   [ byteorder reg 1 = hton(reg 1, 8, 8) ]
-  [ cmp lt reg 1 0x00000000 0xf4010000 ]
+  [ cmp lt reg 1 0x00000000 0x000001f4 ]
 
 # ct status expected,seen-reply,assured,confirmed,snat,dnat,dying
 ip test-ip4 output
@@ -423,53 +423,53 @@ ip test-ip4 output
 # ct label 127
 ip test-ip4 output
   [ ct load label => reg 1 ]
-  [ bitwise reg 1 = ( reg 1 & 0x00000000 0x00000000 0x00000000 0x80000000 ) ^ 0x00000000 0x00000000 0x00000000 0x00000000 ]
+  [ bitwise reg 1 = ( reg 1 & 0x80000000 0x00000000 0x00000000 0x00000000 ) ^ 0x00000000 0x00000000 0x00000000 0x00000000 ]
   [ cmp neq reg 1 0x00000000 0x00000000 0x00000000 0x00000000 ]
 
 # ct label set 127
 ip test-ip4 output
-  [ immediate reg 1 0x00000000 0x00000000 0x00000000 0x80000000 ]
+  [ immediate reg 1 0x80000000 0x00000000 0x00000000 0x00000000 ]
   [ ct set label with reg 1 ]
 
 # ct zone 0
 ip test-ip4 output
   [ ct load zone => reg 1 ]
-  [ cmp eq reg 1 0x00000000 ]
+  [ cmp eq reg 1 0x0000 ]
 
 # ct zone 23
 ip test-ip4 output
   [ ct load zone => reg 1 ]
-  [ cmp eq reg 1 0x00000017 ]
+  [ cmp eq reg 1 0x0017 ]
 
 # ct original zone 1
 ip test-ip4 output
   [ ct load zone => reg 1 , dir original ]
-  [ cmp eq reg 1 0x00000001 ]
+  [ cmp eq reg 1 0x0001 ]
 
 # ct reply zone 1
 ip test-ip4 output
   [ ct load zone => reg 1 , dir reply ]
-  [ cmp eq reg 1 0x00000001 ]
+  [ cmp eq reg 1 0x0001 ]
 
 # ct zone set 1
 ip test-ip4 output
-  [ immediate reg 1 0x00000001 ]
+  [ immediate reg 1 0x0001 ]
   [ ct set zone with reg 1 ]
 
 # ct original zone set 1
 ip test-ip4 output
-  [ immediate reg 1 0x00000001 ]
+  [ immediate reg 1 0x0001 ]
   [ ct set zone with reg 1 , dir original ]
 
 # ct reply zone set 1
 ip test-ip4 output
-  [ immediate reg 1 0x00000001 ]
+  [ immediate reg 1 0x0001 ]
   [ ct set zone with reg 1 , dir reply ]
 
 # ct zone set mark map { 1 : 1,  2 : 2 }
 __map%d test-ip4 b
 __map%d test-ip4 0
-        element 00000001  : 00000001 0 [end]    element 00000002  : 00000002 0 [end]
+	element 00000001 : 0001	element 00000002 : 0002
 ip test-ip4 output
   [ meta load mark => reg 1 ]
   [ lookup reg 1 set __map%d dreg 1 ]
@@ -482,7 +482,7 @@ ip test-ip4 output
 # ct direction . ct mark { original . 0x12345678, reply . 0x87654321}
 __set%d test-ip4 3 size 2
 __set%d test-ip4 0
-	element 00000000 12345678  : 0 [end]	element 00000001 87654321  : 0 [end]
+	element 00 . 12345678	element 01 . 87654321
 ip test-ip4 output 
   [ ct load direction => reg 1 ]
   [ ct load mark => reg 9 ]
@@ -491,7 +491,7 @@ ip test-ip4 output
 # ct state . ct mark vmap { new . 0x12345678 : drop, established . 0x87654321 : accept}
 __map%d test-ip4 b size 2
 __map%d test-ip4 0
-	element 00000008 12345678  : drop 0 [end]	element 00000002 87654321  : accept 0 [end]
+	element 00000008 . 12345678 : drop	element 00000002 . 87654321 : accept
 ip test-ip4 output 
   [ ct load state => reg 1 ]
   [ ct load mark => reg 9 ]
@@ -512,7 +512,7 @@ ip test-ip4 output
 # ct id 12345
 ip test-ip4 output
   [ ct load id => reg 1 ]
-  [ cmp eq reg 1 0x39300000 ]
+  [ cmp eq reg 1 0x00003039 ]
 
 # ct status ! dnat
 ip6
@@ -527,4 +527,3 @@ ip test-ip4 output
 # ct count over 3
 ip test-ip4 output
   [ connlimit count 3 flags 1 ]
-
tests/py/any/meta.t.payload +116 -116

831 lines not on this page · raw message

tests/py/any/meta.t.payload.bridge +5 -5
index 5997ccc7ba52b..b4e7ba374b4f0 100644
@@ -1,20 +1,20 @@
 # meta mark set vlan id map { 1 : 0x00000001, 4095 : 0x00004095 }
 __map%d test-bridge b size 2
 __map%d test-bridge 0
-	element 00000100  : 00000001 0 [end]	element 0000ff0f  : 00004095 0 [end]
+	element 0001 : 00000001	element 0fff : 00004095
 bridge test-bridge input
   [ payload load 2b @ link header + 12 => reg 1 ]
-  [ cmp eq reg 1 0x00000081 ]
+  [ cmp eq reg 1 0x8100 ]
   [ payload load 2b @ link header + 14 => reg 1 ]
-  [ bitwise reg 1 = ( reg 1 & 0x0000ff0f ) ^ 0x00000000 ]
+  [ bitwise reg 1 = ( reg 1 & 0x0fff ) ^ 0x0000 ]
   [ lookup reg 1 set __map%d dreg 1 ]
   [ meta set mark with reg 1 ]
 
 # meta mark set vlan id map @map1
 bridge test-bridge input
   [ payload load 2b @ link header + 12 => reg 1 ]
-  [ cmp eq reg 1 0x00000081 ]
+  [ cmp eq reg 1 0x8100 ]
   [ payload load 2b @ link header + 14 => reg 1 ]
-  [ bitwise reg 1 = ( reg 1 & 0x0000ff0f ) ^ 0x00000000 ]
+  [ bitwise reg 1 = ( reg 1 & 0x0fff ) ^ 0x0000 ]
   [ lookup reg 1 set map1 dreg 1 ]
   [ meta set mark with reg 1 ]
tests/py/any/queue.t.payload +1 -1
index 2f221930a1efc..b3b5dc051cdb2 100644
@@ -50,7 +50,7 @@ ip
 # queue flags bypass to oifname map { "eth0" : 0, "ppp0" : 2, "eth1" : 2 }
 __map%d test-ip4 b size 3
 __map%d test-ip4 0
-	element 30687465 00000000 00000000 00000000  : 00000000 0 [end]	element 30707070 00000000 00000000 00000000  : 00000002 0 [end]	element 31687465 00000000 00000000 00000000  : 00000002 0 [end]
+	element 65746830 00000000 00000000 00000000 : 0000	element 70707030 00000000 00000000 00000000 : 0002	element 65746831 00000000 00000000 00000000 : 0002
 ip
   [ meta load oifname => reg 1 ]
   [ lookup reg 1 set __map%d dreg 1 ]
tests/py/any/rawpayload.t.payload +32 -32

147 lines not on this page · raw message

tests/py/any/rt.t.payload +2 -3
index e1ecb2860ed08..a3d7a7ccec743 100644
@@ -6,10 +6,9 @@ ip test-ip4 input
 # rt ipsec exists
 ip test-ip4 input
   [ rt load ipsec => reg 1 ]
-  [ cmp eq reg 1 0x00000001 ]
+  [ cmp eq reg 1 0x01 ]
 
 # rt ipsec missing
 ip test-ip4 input
   [ rt load ipsec => reg 1 ]
-  [ cmp eq reg 1 0x00000000 ]
-
+  [ cmp eq reg 1 0x00 ]
tests/py/any/tcpopt.t.payload +44 -44

247 lines not on this page · raw message

tests/py/arp/arp.t.payload +49 -50

298 lines not on this page · raw message

tests/py/arp/arp.t.payload.netdev +94 -95

441 lines not on this page · raw message

tests/py/bridge/ether.t.payload +21 -22

81 lines not on this page · raw message

tests/py/bridge/icmpX.t.payload +12 -13
index f9ea7b60450af..d6634beadb26b 100644
@@ -1,36 +1,35 @@
 # ip protocol icmp icmp type echo-request
 bridge test-bridge input
   [ meta load protocol => reg 1 ]
-  [ cmp eq reg 1 0x00000008 ]
+  [ cmp eq reg 1 0x0800 ]
   [ payload load 1b @ network header + 9 => reg 1 ]
-  [ cmp eq reg 1 0x00000001 ]
+  [ cmp eq reg 1 0x01 ]
   [ payload load 1b @ transport header + 0 => reg 1 ]
-  [ cmp eq reg 1 0x00000008 ]
+  [ cmp eq reg 1 0x08 ]
 
 # icmp type echo-request
 bridge test-bridge input
   [ payload load 2b @ link header + 12 => reg 1 ]
-  [ cmp eq reg 1 0x00000008 ]
+  [ cmp eq reg 1 0x0800 ]
   [ meta load l4proto => reg 1 ]
-  [ cmp eq reg 1 0x00000001 ]
+  [ cmp eq reg 1 0x01 ]
   [ payload load 1b @ transport header + 0 => reg 1 ]
-  [ cmp eq reg 1 0x00000008 ]
+  [ cmp eq reg 1 0x08 ]
 
 # ip6 nexthdr icmpv6 icmpv6 type echo-request
 bridge test-bridge input
   [ meta load protocol => reg 1 ]
-  [ cmp eq reg 1 0x0000dd86 ]
+  [ cmp eq reg 1 0x86dd ]
   [ payload load 1b @ network header + 6 => reg 1 ]
-  [ cmp eq reg 1 0x0000003a ]
+  [ cmp eq reg 1 0x3a ]
   [ payload load 1b @ transport header + 0 => reg 1 ]
-  [ cmp eq reg 1 0x00000080 ]
+  [ cmp eq reg 1 0x80 ]
 
 # icmpv6 type echo-request
 bridge test-bridge input
   [ payload load 2b @ link header + 12 => reg 1 ]
-  [ cmp eq reg 1 0x0000dd86 ]
+  [ cmp eq reg 1 0x86dd ]
   [ meta load l4proto => reg 1 ]
-  [ cmp eq reg 1 0x0000003a ]
+  [ cmp eq reg 1 0x3a ]
   [ payload load 1b @ transport header + 0 => reg 1 ]
-  [ cmp eq reg 1 0x00000080 ]
-
+  [ cmp eq reg 1 0x80 ]
tests/py/bridge/meta.t.payload +10 -10
index 0a39842aedf3e..bbbf7968ed6ca 100644
@@ -1,37 +1,37 @@
 # meta obrname "br0"
 bridge test-bridge input
   [ meta load bri_oifname => reg 1 ]
-  [ cmp eq reg 1 0x00307262 0x00000000 0x00000000 0x00000000 ]
+  [ cmp eq reg 1 0x62723000 0x00000000 0x00000000 0x00000000 ]
 
 # meta ibrname "br0"
 bridge test-bridge input
   [ meta load bri_iifname => reg 1 ]
-  [ cmp eq reg 1 0x00307262 0x00000000 0x00000000 0x00000000 ]
+  [ cmp eq reg 1 0x62723000 0x00000000 0x00000000 0x00000000 ]
 
 # meta ibrvproto vlan
 bridge test-bridge input
   [ meta load bri_iifvproto => reg 1 ]
-  [ cmp eq reg 1 0x00000081 ]
+  [ cmp eq reg 1 0x8100 ]
 
 # meta ibrpvid 100
 bridge test-bridge input
   [ meta load bri_iifpvid => reg 1 ]
-  [ cmp eq reg 1 0x00000064 ]
+  [ cmp eq reg 1 0x0064 ]
 
 # meta protocol ip udp dport 67
 bridge test-bridge input
   [ meta load protocol => reg 1 ]
-  [ cmp eq reg 1 0x00000008 ]
+  [ cmp eq reg 1 0x0800 ]
   [ meta load l4proto => reg 1 ]
-  [ cmp eq reg 1 0x00000011 ]
+  [ cmp eq reg 1 0x11 ]
   [ payload load 2b @ transport header + 2 => reg 1 ]
-  [ cmp eq reg 1 0x00004300 ]
+  [ cmp eq reg 1 0x0043 ]
 
 # meta protocol ip6 udp dport 67
 bridge test-bridge input
   [ meta load protocol => reg 1 ]
-  [ cmp eq reg 1 0x0000dd86 ]
+  [ cmp eq reg 1 0x86dd ]
   [ meta load l4proto => reg 1 ]
-  [ cmp eq reg 1 0x00000011 ]
+  [ cmp eq reg 1 0x11 ]
   [ payload load 2b @ transport header + 2 => reg 1 ]
-  [ cmp eq reg 1 0x00004300 ]
+  [ cmp eq reg 1 0x0043 ]
tests/py/bridge/redirect.t.payload +1 -1
index 1fcfa5f1b04ff..a0afec94171fa 100644
@@ -1,4 +1,4 @@
 # meta broute set 1
 bridge test-bridge prerouting
-  [ immediate reg 1 0x00000001 ]
+  [ immediate reg 1 0x01 ]
   [ meta set broute with reg 1 ]
tests/py/bridge/reject.t.payload +21 -22

142 lines not on this page · raw message

tests/py/bridge/vlan.t.payload +131 -131

350 lines not on this page · raw message

tests/py/bridge/vlan.t.payload.netdev +158 -158

316 lines not on this page · raw message

tests/py/inet/ah.t.payload +44 -45

89 lines not on this page · raw message

tests/py/inet/comp.t.payload +26 -27

53 lines not on this page · raw message

tests/py/inet/ct.t.payload +7 -7
index 216dad2bb531c..4e9d5f04a6a2c 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/dccp.t.payload +26 -27

53 lines not on this page · raw message

tests/py/inet/dnat.t.payload +23 -24

47 lines not on this page · raw message

tests/py/inet/esp.t.payload +22 -23

45 lines not on this page · raw message

tests/py/inet/ether-ip.t.payload +11 -11
index 62e37a597b967..912a19b857dfd 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/ether-ip.t.payload.netdev +11 -12
index b0fa6d84b31b1..aca7a4b72ab7f 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/ether.t.payload +18 -19
index 8b74a7815d8ec..e0a36d43745b6 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/ether.t.payload.bridge +14 -15
index 0128d5f02b978..d5d4f5c0d49f7 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/ether.t.payload.ip +18 -19
index 7c91f412c33ee..5a4fb00808b15 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/fib.t.payload +6 -6
index 02d92b57a4776..612e5ba827a64 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/geneve.t.payload +41 -42

83 lines not on this page · raw message

tests/py/inet/gre.t.payload +26 -27

53 lines not on this page · raw message

tests/py/inet/gretap.t.payload +29 -30

59 lines not on this page · raw message

tests/py/inet/icmp.t.payload +18 -19
index f98cfc39abed4..4db6b6fe2326e 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/icmpX.t.payload +16 -16
index 9a761eef632ed..61b857b52737a 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/ip.t.payload +2 -2
index 589a5cd35a806..6ed1967d29ae3 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/ip.t.payload.bridge +2 -2
index 57dbc9eb42e77..3e7421c8152d3 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/ip.t.payload.inet +3 -4
index 8df41defea0a1..f566c98814c5b 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/ip.t.payload.netdev +3 -4
index 95be9194f2fed..e3799893f7428 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/ip_tcp.t.payload +18 -18
index 1e16f8522849b..cf68b98a1468f 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/ip_tcp.t.payload.bridge +17 -18
index 0344cd66668cc..121052d901137 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/ip_tcp.t.payload.netdev +18 -19
index 915a78706d598..bef0d6f575a98 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/ipsec.t.payload +5 -6
index f8ecd9d1cc1f3..2e012db1f6436 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/map.t.payload +5 -6
index 50344ada9161a..f9ab4ef6d9125 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/map.t.payload.ip +3 -4
index 3e45667573394..33c03e49d17f9 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/map.t.payload.netdev +5 -6
index 2e60f09d752d6..af1cfeb72a630 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/meta.t.payload +41 -42

83 lines not on this page · raw message

tests/py/inet/osf.t.payload +8 -8
index 6ddab9763b649..65d0a2e01a8d6 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/payloadmerge.t.payload +21 -22

43 lines not on this page · raw message

tests/py/inet/reject.t.payload.inet +21 -22

43 lines not on this page · raw message

tests/py/inet/rt.t.payload +3 -4
index 84dea12caad5d..3d65fef625a45 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/sctp.t.payload +79 -80

159 lines not on this page · raw message

tests/py/inet/sets.t.payload.bridge +7 -8
index 3dd9d57bc0ce8..c5be4cae0f730 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/sets.t.payload.inet +7 -7
index 53c6b1821af7c..8c903b35aa49c 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/sets.t.payload.netdev +7 -7
index e31aeb9274e66..376600152cc38 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/snat.t.payload +15 -15
index 50519c6b6bb6f..3399d33ece150 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/socket.t.payload +4 -4
index e66ccbf70aeaf..c3520db81833c 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/tcp.t.payload +180 -180

360 lines not on this page · raw message

tests/py/inet/tproxy.t.payload +22 -23

45 lines not on this page · raw message

tests/py/inet/udp.t.payload +56 -56

112 lines not on this page · raw message

tests/py/inet/udplite.t.payload +40 -41

81 lines not on this page · raw message

tests/py/inet/vmap.t.payload +6 -7
index 29ec846deb2ee..c905f80eb2cf9 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/vmap.t.payload.netdev +6 -7
index 3f51bb33054a2..881550df2883f 100644

Lines of this file are not shown. View the raw message.

tests/py/inet/vxlan.t.payload +41 -42

83 lines not on this page · raw message

tests/py/ip/ct.t.payload +23 -23

46 lines not on this page · raw message

tests/py/ip/dnat.t.payload.ip +58 -59

117 lines not on this page · raw message

tests/py/ip/dup.t.payload +3 -4
index 347dc07ad0be2..4e1c90702fa7e 100644

Lines of this file are not shown. View the raw message.

tests/py/ip/ether.t.payload +18 -19
index bd7c8f1506329..7d134894f1196 100644

Lines of this file are not shown. View the raw message.

tests/py/ip/hash.t.payload +1 -1
index fefe492d8cbef..f7241250628a3 100644

Lines of this file are not shown. View the raw message.

tests/py/ip/icmp.t.payload.ip +156 -156

312 lines not on this page · raw message

tests/py/ip/igmp.t.payload +30 -31

61 lines not on this page · raw message

tests/py/ip/ip.t.payload +123 -123

246 lines not on this page · raw message

tests/py/ip/ip.t.payload.bridge +220 -220

440 lines not on this page · raw message

tests/py/ip/ip.t.payload.inet +220 -220

440 lines not on this page · raw message

tests/py/ip/ip.t.payload.netdev +217 -217

434 lines not on this page · raw message

tests/py/ip/ip_tcp.t.payload +4 -5
index f6f640d43865b..cefbcafb392ce 100644

Lines of this file are not shown. View the raw message.

tests/py/ip/masquerade.t.payload +35 -36

71 lines not on this page · raw message

tests/py/ip/meta.t.payload +16 -16
index 880ac5d6c707a..bfdac5b3e4349 100644

Lines of this file are not shown. View the raw message.

tests/py/ip/numgen.t.payload +2 -2
index b4eadf857d13d..f405790e8f0de 100644

Lines of this file are not shown. View the raw message.

tests/py/ip/objects.t.payload +13 -13
index 3da4b28512b6f..b0b71818d5483 100644

Lines of this file are not shown. View the raw message.

tests/py/ip/redirect.t.payload +60 -61

121 lines not on this page · raw message

tests/py/ip/reject.t.payload +1 -2
index 5829065a154f6..c5419d096cf37 100644

Lines of this file are not shown. View the raw message.

tests/py/ip/rt.t.payload +1 -2
index 93eef4a77bb72..97c0ad30f2449 100644

Lines of this file are not shown. View the raw message.

tests/py/ip/sets.t.payload.inet +19 -19
index cc04b43d64bff..de8182e00c014 100644

Lines of this file are not shown. View the raw message.

tests/py/ip/sets.t.payload.ip +6 -6
index f9ee1f98203bf..957133707c62a 100644

Lines of this file are not shown. View the raw message.

tests/py/ip/sets.t.payload.netdev +19 -19
index 3d0dc79acfd91..66e20fa980221 100644

Lines of this file are not shown. View the raw message.

tests/py/ip/snat.t.payload +37 -37

74 lines not on this page · raw message

tests/py/ip/tcp.t.payload +5 -6
index 58956d984b1b7..cb464b17d0e8a 100644

Lines of this file are not shown. View the raw message.

tests/py/ip/tproxy.t.payload +14 -15
index dfe830ec37152..2f2ff0e2f5bec 100644

Lines of this file are not shown. View the raw message.

tests/py/ip6/ct.t.payload +6 -6
index a7a56d4be80bf..35f64e646f1cd 100644

Lines of this file are not shown. View the raw message.

tests/py/ip6/dnat.t.payload.ip6 +19 -19
index fe6e0422f074b..26f0f603b531c 100644

Lines of this file are not shown. View the raw message.

tests/py/ip6/dst.t.payload.inet +30 -30

60 lines not on this page · raw message

tests/py/ip6/dst.t.payload.ip6 +15 -15
index ac1fc8b39a2b7..f4fc9aed36671 100644

Lines of this file are not shown. View the raw message.

tests/py/ip6/dup.t.payload +3 -4
index c441d4be981bf..55bb3747d9608 100644

Lines of this file are not shown. View the raw message.

tests/py/ip6/ether.t.payload +18 -18
index 592b4ea0e0bcc..b26ad647a19c2 100644

Lines of this file are not shown. View the raw message.

tests/py/ip6/exthdr.t.payload.ip6 +12 -13
index be10d61ef6ccc..230a51375c797 100644

Lines of this file are not shown. View the raw message.

tests/py/ip6/frag.t.payload.inet +65 -66

131 lines not on this page · raw message

tests/py/ip6/frag.t.payload.ip6 +37 -38

75 lines not on this page · raw message

tests/py/ip6/frag.t.payload.netdev +65 -66

131 lines not on this page · raw message

tests/py/ip6/hbh.t.payload.inet +32 -33

65 lines not on this page · raw message

tests/py/ip6/hbh.t.payload.ip6 +16 -17
index a6bc7ae65475d..96c3ee2443f5e 100644

Lines of this file are not shown. View the raw message.

tests/py/ip6/icmpv6.t.payload.ip6 +161 -161

322 lines not on this page · raw message

tests/py/ip6/ip6.t.payload.inet +179 -180

359 lines not on this page · raw message

tests/py/ip6/ip6.t.payload.ip6 +95 -96

191 lines not on this page · raw message

tests/py/ip6/map.t.payload +2 -3
index 8e900c18c5e3d..ea39a81e83ff0 100644

Lines of this file are not shown. View the raw message.

tests/py/ip6/masquerade.t.payload.ip6 +35 -36

71 lines not on this page · raw message

tests/py/ip6/meta.t.payload +18 -18
index 6a37f1dee7edf..c36707421ba01 100644

Lines of this file are not shown. View the raw message.

tests/py/ip6/mh.t.payload.inet +66 -66

132 lines not on this page · raw message

tests/py/ip6/mh.t.payload.ip6 +33 -33

66 lines not on this page · raw message

tests/py/ip6/redirect.t.payload.ip6 +52 -53

105 lines not on this page · raw message

tests/py/ip6/reject.t.payload.ip6 +1 -2
index 3d4321b098c20..6b1282693a9a9 100644

Lines of this file are not shown. View the raw message.

tests/py/ip6/rt.t.payload.inet +60 -61

121 lines not on this page · raw message

tests/py/ip6/rt.t.payload.ip6 +30 -31

61 lines not on this page · raw message

tests/py/ip6/rt0.t.payload +1 -2
index 464b7f212fc5c..7b4d6d7b48e96 100644

Lines of this file are not shown. View the raw message.

tests/py/ip6/sets.t.payload.inet +9 -9
index 2dbb818a8aa1b..f694209f23b5b 100644

Lines of this file are not shown. View the raw message.

tests/py/ip6/sets.t.payload.ip6 +2 -2
index 7234b989a57db..8b7379a252fdc 100644

Lines of this file are not shown. View the raw message.

tests/py/ip6/sets.t.payload.netdev +9 -9
index 2ad0f434b3dc2..2441a44c8ca01 100644

Lines of this file are not shown. View the raw message.

tests/py/ip6/snat.t.payload.ip6 +11 -12
index 96a9ba0a3111d..01abb1ca3e677 100644

Lines of this file are not shown. View the raw message.

tests/py/ip6/srh.t.payload +11 -12
index 364940a95ee63..5c3031f3bdd23 100644

Lines of this file are not shown. View the raw message.

tests/py/ip6/tproxy.t.payload +14 -15
index 9f28e80b4142c..109b697ff9ff3 100644

Lines of this file are not shown. View the raw message.

tests/py/ip6/vmap.t.payload.inet +84 -85

169 lines not on this page · raw message

tests/py/ip6/vmap.t.payload.ip6 +42 -43

85 lines not on this page · raw message

tests/py/ip6/vmap.t.payload.netdev +84 -85

169 lines not on this page · raw message

tests/py/netdev/dup.t.payload +1 -2
index 51ff782c0525f..971dd1bbf5c5d 100644

Lines of this file are not shown. View the raw message.

tests/py/netdev/fwd.t.payload +2 -3
index f03077a60e2d1..3453c38f1a5f8 100644

Lines of this file are not shown. View the raw message.

tests/py/netdev/reject.t.payload +20 -21

41 lines not on this page · raw message

tests/py/netdev/tunnel.t.payload +2 -3
index 9148d0e5b6cb0..8692c92c5e5c0 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.51.0

Part of the diff is not shown here. View the raw message.

author reviewer
#41 lore raw

PATCH 26/28 utils: Introduce expr_print_debug()

In reply to Phil Sutter

A simple function to call in random places when debugging expression-related code.

---
 include/utils.h | 9 +++++++++
 1 file changed, 9 insertions(+)
include/utils.h +9 -0
index e18fabec56ba3..0db0cf20e493c 100644
@@ -26,6 +26,15 @@
 #define pr_gmp_debug(fmt, arg...) ({ if (false) {}; 0; })
 #endif
 
+#define expr_print_debug(expr)					\
+{								\
+	struct output_ctx octx = { .output_fp = stdout };	\
+	printf("%s:%d: ", __FILE__, __LINE__);			\
+	printf("'" #expr "' type %s: ", expr_name(expr));	\
+	expr_print((expr), &octx);				\
+	printf("\n");						\
+}
+
 #define __fmtstring(x, y)	__attribute__((format(printf, x, y)))
 #if 0
 #define __gmp_fmtstring(x, y)	__fmtstring(x, y)
Signature · 1 line
2.51.0
#43 lore raw

Re: [nft PATCH 26/28] utils: Introduce expr_print_debug()

In reply to Phil Sutter
Quoted 14 lines · Phil Sutter

A simple function to call in random places when debugging expression-related code.

---
 include/utils.h | 9 +++++++++
 1 file changed, 9 insertions(+)
include/utils.h +0 -0
index e18fabec56ba3..0db0cf20e493c 100644
@@ -26,6 +26,15 @@
 #define pr_gmp_debug(fmt, arg...) ({ if (false) {}; 0; })

include/utils.h line 36

Quoted 10 lines
include/utils.h +8 -0
 #endif
 
+#define expr_print_debug(expr)					\
+{								\
+	struct output_ctx octx = { .output_fp = stdout };	\
+	printf("%s:%d: ", __FILE__, __LINE__);			\
+	printf("'" #expr "' type %s: ", expr_name(expr));	\
+	expr_print((expr), &octx);				\
+	printf("\n");						\
+}

Where is the first user of this? Better add and add users to improve tracking when looking at git annotate?

Quoted 7 lines
include/utils.h +1 -0
+
 #define __fmtstring(x, y)	__attribute__((format(printf, x, y)))
 #if 0
 #define __gmp_fmtstring(x, y)	__fmtstring(x, y)
Signature · 1 line
2.51.0
author reviewer
#44 lore raw

Re: [nft PATCH 26/28] utils: Introduce expr_print_debug()

Hi Pablo,

Quoted 17 lines · Pablo Neira Ayuso
Quoted 16 lines · Phil Sutter

A simple function to call in random places when debugging expression-related code.

---
 include/utils.h | 9 +++++++++
 1 file changed, 9 insertions(+)
include/utils.h +0 -0
index e18fabec56ba3..0db0cf20e493c 100644
@@ -26,6 +26,15 @@
 #define pr_gmp_debug(fmt, arg...) ({ if (false) {}; 0; })
 #endif
 
Quoted 11 lines

include/utils.h line 36

Quoted 8 lines
include/utils.h +8 -0
+#define expr_print_debug(expr)					\
+{								\
+	struct output_ctx octx = { .output_fp = stdout };	\
+	printf("%s:%d: ", __FILE__, __LINE__);			\
+	printf("'" #expr "' type %s: ", expr_name(expr));	\
+	expr_print((expr), &octx);				\
+	printf("\n");						\
+}

Where is the first user of this? Better add and add users to improve tracking when looking at git annotate?

There are no users. This macro's sole purpose is for printf-debugging, to call temporarily in random spots when trying to figure what's going on.
It came in handy when I debugged bugs in the byteorder fixup code since often I wondered what kind of 'struct expr *' there was at a given spot and what it contained.
It's just an extra, I can drop it from this series if you think it's not worth keeping it in the code/history.

Cheers, Phil

author reviewer
#45 lore raw

PATCH 27/28 utils: Cover for missing newline after BUG() messages

In reply to Phil Sutter

Relieve callers from having to suffix their messages with a newline escape sequence, have the macro append it to the format string instead.

This is mostly a fix for (the many) calls to BUG() without a newline suffix but causes an extra new line in (equally many) others. Fixing them is subject to followup patch.

---
 include/utils.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/utils.h +1 -1
index 0db0cf20e493c..f47e7eb8d8093 100644
@@ -45,7 +45,7 @@
 #define __must_check		__attribute__((warn_unused_result))
 #define __noreturn		__attribute__((__noreturn__))
 
-#define BUG(fmt, arg...)	({ fprintf(stderr, "BUG: " fmt, ##arg); assert(0); abort(); })
+#define BUG(fmt, arg...)	({ fprintf(stderr, "BUG: " fmt "\n", ##arg); assert(0); abort(); })
 
 #define BUILD_BUG_ON(condition)	((void)sizeof(char[1 - 2*!!(condition)]))
 #define BUILD_BUG_ON_ZERO(e)	(sizeof(char[1 - 2 * !!(e)]) - 1)
Signature · 1 line
2.51.0
maintainer
#46 lore raw

Re: [nft PATCH 27/28] utils: Cover for missing newline after BUG() messages

Quoted 6 lines · Phil Sutter

Relieve callers from having to suffix their messages with a newline escape sequence, have the macro append it to the format string instead.

This is mostly a fix for (the many) calls to BUG() without a newline suffix but causes an extra new line in (equally many) others. Fixing them is subject to followup patch.

Would you mind rebaseing this patch and the next one? No need to resend, just push these two out.

author reviewer
#47 lore raw

Re: [nft PATCH 27/28] utils: Cover for missing newline after BUG() messages

Quoted 10 lines · Florian Westphal
Quoted 6 lines · Phil Sutter

Relieve callers from having to suffix their messages with a newline escape sequence, have the macro append it to the format string instead.

This is mostly a fix for (the many) calls to BUG() without a newline suffix but causes an extra new line in (equally many) others. Fixing them is subject to followup patch.

Would you mind rebaseing this patch and the next one? No need to resend, just push these two out.

ACK, will do!

Thanks, Phil

author reviewer
#48 lore raw

PATCH 28/28 Drop no longer needed newline in BUG() messages

In reply to Phil Sutter

Since BUG() now appends a newline itself, drop it from calls where present.

---
 src/datatype.c            |  2 +-
 src/erec.c                |  2 +-
 src/evaluate.c            | 46 +++++++++++++++++++--------------------
 src/expression.c          |  6 ++---
 src/fib.c                 |  2 +-
 src/intervals.c           |  8 +++----
 src/json.c                |  4 ++--
 src/mergesort.c           |  2 +-
 src/mnl.c                 |  8 +++----
 src/netlink.c             | 11 +++++-----
 src/netlink_delinearize.c | 11 +++++-----
 src/netlink_linearize.c   | 28 ++++++++++++------------
 src/optimize.c            |  2 +-
 src/rule.c                | 20 ++++++++---------
 src/segtree.c             |  2 +-
 src/statement.c           |  2 +-
 16 files changed, 79 insertions(+), 77 deletions(-)
src/datatype.c +1 -1
index 2ee7e7d5e9cf6..eee9ab9d19296 100644
@@ -119,7 +119,7 @@ void datatype_print(const struct expr *expr, struct output_ctx *octx)
 						       false, octx);
 	} while ((dtype = dtype->basetype));
 
-	BUG("datatype %s has no print method or symbol table\n",
+	BUG("datatype %s has no print method or symbol table",
 	    expr->dtype->name);
 }
 
src/erec.c +1 -1
index fe66abbe3ac29..8f480a80a0d0c 100644
@@ -156,7 +156,7 @@ void erec_print(struct output_ctx *octx, const struct error_record *erec,
 	case INDESC_NETLINK:
 		break;
 	default:
-		BUG("invalid input descriptor type %u\n", indesc->type);
+		BUG("invalid input descriptor type %u", indesc->type);
 	}
 
 	f = octx->error_fp;
src/evaluate.c +23 -23

182 lines not on this page · raw message

src/expression.c +3 -3
index de63196b60a6a..0dc59ab04b16c 100644
@@ -1770,7 +1770,7 @@ void range_expr_value_low(mpz_t rop, const struct expr *expr)
 	case EXPR_SET_ELEM:
 		return range_expr_value_low(rop, expr->key);
 	default:
-		BUG("invalid range expression type %s\n", expr_name(expr));
+		BUG("invalid range expression type %s", expr_name(expr));
 	}
 }
 
@@ -1797,7 +1797,7 @@ void range_expr_value_high(mpz_t rop, const struct expr *expr)
 	case EXPR_SET_ELEM:
 		return range_expr_value_high(rop, expr->key);
 	default:
-		BUG("invalid range expression type %s\n", expr_name(expr));
+		BUG("invalid range expression type %s", expr_name(expr));
 	}
 }
 
@@ -1848,7 +1848,7 @@ const struct expr_ops *expr_ops(const struct expr *e)
 
 	ops = __expr_ops_by_type(e->etype);
 	if (!ops)
-		BUG("Unknown expression type %d\n", e->etype);
+		BUG("Unknown expression type %d", e->etype);
 
 	return ops;
 }
src/fib.c +1 -1
index 571277ddf434a..c8ac8a8357e5d 100644
@@ -197,7 +197,7 @@ struct expr *fib_expr_alloc(const struct location *loc,
 		type = &fib_addr_type;
 		break;
 	default:
-		BUG("Unknown result %d\n", result);
+		BUG("Unknown result %d", result);
 	}
 
 	if (flags & NFTA_FIB_F_PRESENT) {
src/intervals.c +4 -4
index 6a917b7b79c3f..7f3d2252fcadc 100644
@@ -65,7 +65,7 @@ static void setelem_expr_to_range(struct expr *expr)
 		expr->key = key;
 		break;
 	default:
-		BUG("unhandled key type %s\n", expr_name(expr->key));
+		BUG("unhandled key type %s", expr_name(expr->key));
 	}
 }
 
@@ -221,7 +221,7 @@ static struct expr *interval_expr_key(struct expr *i)
 		elem = i;
 		break;
 	default:
-		BUG("unhandled expression type %d\n", i->etype);
+		BUG("unhandled expression type %d", i->etype);
 		return NULL;
 	}
 
@@ -751,7 +751,7 @@ static struct expr *setelem_key(struct expr *expr)
 		key = expr->key;
 		break;
 	default:
-		BUG("unhandled expression type %d\n", expr->etype);
+		BUG("unhandled expression type %d", expr->etype);
 		return NULL;
 	}
 
@@ -775,7 +775,7 @@ int setelem_to_interval(const struct set *set, struct expr *elem,
 	}
 
 	if (key->etype != EXPR_RANGE_VALUE)
-		BUG("key must be RANGE_VALUE, not %s\n", expr_name(key));
+		BUG("key must be RANGE_VALUE, not %s", expr_name(key));
 
 	assert(!next_key || next_key->etype == EXPR_RANGE_VALUE);
 
src/json.c +2 -2
index 46d8a73333374..e3688249f806a 100644
@@ -1117,7 +1117,7 @@ static json_t *datatype_json(const struct expr *expr, struct output_ctx *octx)
 		}
 	} while ((dtype = dtype->basetype));
 
-	BUG("datatype %s has no print method or symbol table\n",
+	BUG("datatype %s has no print method or symbol table",
 	    expr->dtype->name);
 }
 
@@ -2149,7 +2149,7 @@ int do_command_list_json(struct netlink_ctx *ctx, struct cmd *cmd)
 		errno = EOPNOTSUPP;
 		return -1;
 	case CMD_OBJ_INVALID:
-		BUG("invalid command object type %u\n", cmd->obj);
+		BUG("invalid command object type %u", cmd->obj);
 		break;
 	}
 
src/mergesort.c +1 -1
index 95037e5be8608..9984e272df580 100644
@@ -48,7 +48,7 @@ static mpz_srcptr expr_msort_value(const struct expr *expr, mpz_t value)
 		mpz_bitmask(value, expr->len);
 		break;
 	default:
-		BUG("Unknown expression %s\n", expr_name(expr));
+		BUG("Unknown expression %s", expr_name(expr));
 	}
 	return value;
 }
src/mnl.c +4 -4
index 6e32fc3467ce9..a2e555d4a8bf4 100644
@@ -740,18 +740,18 @@ static void nft_dev_add(struct nft_dev *dev_array, const struct expr *expr, int
 	char ifname[IFNAMSIZ];
 
 	if (expr->etype != EXPR_VALUE)
-		BUG("Must be a value, not %s\n", expr_name(expr));
+		BUG("Must be a value, not %s", expr_name(expr));
 
 	ifname_len = div_round_up(expr->len, BITS_PER_BYTE);
 	memset(ifname, 0, sizeof(ifname));
 
 	if (ifname_len > sizeof(ifname))
-		BUG("Interface length %u exceeds limit\n", ifname_len);
+		BUG("Interface length %u exceeds limit", ifname_len);
 
 	mpz_export_data(ifname, expr->value, BYTEORDER_BIG_ENDIAN, ifname_len);
 
 	if (strnlen(ifname, IFNAMSIZ) >= IFNAMSIZ)
-		BUG("Interface length %zu exceeds limit, no NUL byte\n", strnlen(ifname, IFNAMSIZ));
+		BUG("Interface length %zu exceeds limit, no NUL byte", strnlen(ifname, IFNAMSIZ));
 
 	dev_array[i].ifname = xstrdup(ifname);
 	dev_array[i].location = &expr->location;
@@ -1734,7 +1734,7 @@ int mnl_nft_obj_add(struct netlink_ctx *ctx, struct cmd *cmd,
 		obj_tunnel_add_opts(nlo, &obj->tunnel);
 		break;
 	default:
-		BUG("Unknown type %d\n", obj->type);
+		BUG("Unknown type %d", obj->type);
 		break;
 	}
 	netlink_dump_obj(nlo, ctx);
src/netlink.c +6 -5
index 68228bdc5c99a..5be7feb17d84a 100644
@@ -125,7 +125,7 @@ struct nftnl_set_elem *alloc_nftnl_setelem(const struct expr *set,
 		elem = expr;
 	}
 	if (elem->etype != EXPR_SET_ELEM)
-		BUG("Unexpected expression type: got %d\n", elem->etype);
+		BUG("Unexpected expression type: got %d", elem->etype);
 
 	key = elem->key;
 
@@ -227,7 +227,7 @@ struct nftnl_set_elem *alloc_nftnl_setelem(const struct expr *set,
 					       nld.byteorder, nld.sizes);
 			break;
 		default:
-			BUG("unexpected set element expression\n");
+			BUG("unexpected set element expression");
 			break;
 		}
 	}
@@ -347,7 +347,8 @@ static void nft_data_memcpy(struct nft_data_linearize *nld,
 			    const void *src, unsigned int len)
 {
 	if (len > sizeof(nld->value))
-		BUG("nld buffer overflow: want to copy %u, max %u\n", len, (unsigned int)sizeof(nld->value));
+		BUG("nld buffer overflow: want to copy %u, max %u",
+		    len, (unsigned int)sizeof(nld->value));
 
 	memcpy(nld->value, src, len);
 	nld->len = len;
@@ -606,7 +607,7 @@ static void netlink_gen_key(const struct expr *expr,
 	case EXPR_PREFIX:
 		return netlink_gen_prefix(expr, data);
 	default:
-		BUG("invalid data expression type %s\n", expr_name(expr));
+		BUG("invalid data expression type %s", expr_name(expr));
 	}
 }
 
@@ -629,7 +630,7 @@ static void __netlink_gen_data(const struct expr *expr,
 	case EXPR_PREFIX:
 		return netlink_gen_prefix(expr, data);
 	default:
-		BUG("invalid data expression type %s\n", expr_name(expr));
+		BUG("invalid data expression type %s", expr_name(expr));
 	}
 }
 
src/netlink_delinearize.c +6 -5
index 54be0682b0899..3f79463c25f76 100644
@@ -2474,7 +2474,7 @@ static void binop_adjust_one(const struct expr *binop, struct expr *value,
 		value->len = left->len;
 		break;
 	default:
-		BUG("unknown expression type %s\n", expr_name(left));
+		BUG("unknown expression type %s", expr_name(left));
 		break;
 	}
 }
@@ -2505,7 +2505,8 @@ static void binop_adjust(const struct expr *binop, struct expr *right,
 				binop_adjust(binop, i->key->key, shift);
 				break;
 			default:
-				BUG("unknown expression type %s\n", expr_name(i->key));
+				BUG("unknown expression type %s",
+				    expr_name(i->key));
 			}
 		}
 		break;
@@ -2514,7 +2515,7 @@ static void binop_adjust(const struct expr *binop, struct expr *right,
 		binop_adjust_one(binop, right->right, shift);
 		break;
 	default:
-		BUG("unknown expression type %s\n", expr_name(right));
+		BUG("unknown expression type %s", expr_name(right));
 		break;
 	}
 }
@@ -2645,7 +2646,7 @@ static void relational_binop_postprocess(struct rule_pp_ctx *ctx,
 			expr->op = OP_NEG;
 			break;
 		default:
-			BUG("unknown operation type %d\n", expr->op);
+			BUG("unknown operation type %d", expr->op);
 		}
 		expr_free(binop);
 	} else if (datatype_prefix_notation(binop->left->dtype) &&
@@ -3051,7 +3052,7 @@ static void expr_postprocess(struct rule_pp_ctx *ctx, struct expr **exprp)
 		ct_expr_update_type(&dl->pctx, expr);
 		break;
 	default:
-		BUG("unknown expression type %s\n", expr_name(expr));
+		BUG("unknown expression type %s", expr_name(expr));
 	}
 }
 
src/netlink_linearize.c +14 -14
index 36a539bf96283..ac0eaff9a23ca 100644
@@ -76,7 +76,7 @@ static enum nft_registers __get_register(struct netlink_linearize_ctx *ctx,
 
 	n = netlink_register_space(size);
 	if (ctx->reg_low + n > NFT_REG_1 + NFT_REG32_15 - NFT_REG32_00 + 1)
-		BUG("register reg_low %u invalid\n", ctx->reg_low);
+		BUG("register reg_low %u invalid", ctx->reg_low);
 
 	reg = ctx->reg_low;
 	ctx->reg_low += n;
@@ -90,7 +90,7 @@ static void __release_register(struct netlink_linearize_ctx *ctx,
 
 	n = netlink_register_space(size);
 	if (ctx->reg_low < NFT_REG_1 + n)
-		BUG("register reg_low %u invalid\n", ctx->reg_low);
+		BUG("register reg_low %u invalid", ctx->reg_low);
 
 	ctx->reg_low -= n;
 }
@@ -457,7 +457,7 @@ static enum nft_cmp_ops netlink_gen_cmp_op(enum ops op)
 	case OP_GTE:
 		return NFT_CMP_GTE;
 	default:
-		BUG("invalid comparison operation %u\n", op);
+		BUG("invalid comparison operation %u", op);
 	}
 }
 
@@ -521,7 +521,7 @@ static void netlink_gen_range(struct netlink_linearize_ctx *ctx,
 		nft_rule_add_expr(ctx, nle, &expr->location);
 		break;
 	default:
-		BUG("invalid range operation %u\n", expr->op);
+		BUG("invalid range operation %u", expr->op);
 
 	}
 
@@ -606,7 +606,7 @@ static void netlink_gen_relational(struct netlink_linearize_ctx *ctx,
 	case OP_NEG:
 		break;
 	default:
-		BUG("invalid relational operation %u\n", expr->op);
+		BUG("invalid relational operation %u", expr->op);
 	}
 
 	switch (expr->right->etype) {
@@ -741,7 +741,7 @@ static void netlink_gen_bitwise_mask_xor(struct netlink_linearize_ctx *ctx,
 			combine_binop(mask, xor, tmp, val);
 			break;
 		default:
-			BUG("invalid binary operation %u\n", i->op);
+			BUG("invalid binary operation %u", i->op);
 		}
 	}
 
@@ -789,7 +789,7 @@ static void netlink_gen_bitwise_bool(struct netlink_linearize_ctx *ctx,
 		nftnl_expr_set_u32(nle, NFTNL_EXPR_BITWISE_OP, NFT_BITWISE_OR);
 		break;
 	default:
-		BUG("invalid binary operation %u\n", expr->op);
+		BUG("invalid binary operation %u", expr->op);
 	}
 
 	netlink_gen_expr(ctx, expr->left, dreg);
@@ -833,7 +833,7 @@ static enum nft_byteorder_ops netlink_gen_unary_op(enum ops op)
 	case OP_NTOH:
 		return NFT_BYTEORDER_NTOH;
 	default:
-		BUG("invalid unary operation %u\n", op);
+		BUG("invalid unary operation %u", op);
 	}
 }
 
@@ -961,7 +961,7 @@ static void netlink_gen_expr(struct netlink_linearize_ctx *ctx,
 	case EXPR_XFRM:
 		return netlink_gen_xfrm(ctx, expr, dreg);
 	default:
-		BUG("unknown expression type %s\n", expr_name(expr));
+		BUG("unknown expression type %s", expr_name(expr));
 	}
 }
 
@@ -994,7 +994,7 @@ static void netlink_gen_objref_stmt(struct netlink_linearize_ctx *ctx,
 				   stmt->objref.type);
 		break;
 	default:
-		BUG("unsupported expression %u\n", expr->etype);
+		BUG("unsupported expression %u", expr->etype);
 	}
 	nft_rule_add_expr(ctx, nle, &expr->location);
 }
@@ -1082,7 +1082,7 @@ struct nftnl_expr *netlink_gen_stmt_stateful(const struct stmt *stmt)
 	case STMT_LAST:
 		return netlink_gen_last_stmt(stmt);
 	default:
-		BUG("unknown stateful statement type %d\n", stmt->type);
+		BUG("unknown stateful statement type %d", stmt->type);
 	}
 }
 
@@ -1241,7 +1241,7 @@ static unsigned int nat_addrlen(uint8_t family)
 	case NFPROTO_IPV6: return 128;
 	}
 
-	BUG("invalid nat family %u\n", family);
+	BUG("invalid nat family %u", family);
 	return 0;
 }
 
@@ -1284,7 +1284,7 @@ static void netlink_gen_nat_stmt(struct netlink_linearize_ctx *ctx,
 		nftnl_reg_pmax = NFTNL_EXPR_REDIR_REG_PROTO_MAX;
 		break;
 	default:
-		BUG("unknown nat type %d\n", stmt->nat.type);
+		BUG("unknown nat type %d", stmt->nat.type);
 		break;
 	}
 
@@ -1772,7 +1772,7 @@ static void netlink_gen_stmt(struct netlink_linearize_ctx *ctx,
 	case STMT_OPTSTRIP:
 		return netlink_gen_optstrip_stmt(ctx, stmt);
 	default:
-		BUG("unknown statement type %d\n", stmt->type);
+		BUG("unknown statement type %d", stmt->type);
 	}
 }
 
src/optimize.c +1 -1
index ffc06480d4ee5..17084a84d4655 100644
@@ -1181,7 +1181,7 @@ static void rule_optimize_print(struct output_ctx *octx,
 	case INDESC_NETLINK:
 		break;
 	default:
-		BUG("invalid input descriptor type %u\n", indesc->type);
+		BUG("invalid input descriptor type %u", indesc->type);
 	}
 
 	print_location(octx->error_fp, indesc, loc);
src/rule.c +10 -10
index d0a62a3ee002d..14184a70675b7 100644
@@ -1450,7 +1450,7 @@ void cmd_free(struct cmd *cmd)
 			flowtable_free(cmd->flowtable);
 			break;
 		default:
-			BUG("invalid command object type %u\n", cmd->obj);
+			BUG("invalid command object type %u", cmd->obj);
 		}
 	}
 	free(cmd->attr);
@@ -1549,7 +1549,7 @@ static int do_command_add(struct netlink_ctx *ctx, struct cmd *cmd, bool excl)
 	case CMD_OBJ_FLOWTABLE:
 		return mnl_nft_flowtable_add(ctx, cmd, flags);
 	default:
-		BUG("invalid command object type %u\n", cmd->obj);
+		BUG("invalid command object type %u", cmd->obj);
 	}
 	return 0;
 }
@@ -1560,7 +1560,7 @@ static int do_command_replace(struct netlink_ctx *ctx, struct cmd *cmd)
 	case CMD_OBJ_RULE:
 		return mnl_nft_rule_replace(ctx, cmd);
 	default:
-		BUG("invalid command object type %u\n", cmd->obj);
+		BUG("invalid command object type %u", cmd->obj);
 	}
 	return 0;
 }
@@ -1576,7 +1576,7 @@ static int do_command_insert(struct netlink_ctx *ctx, struct cmd *cmd)
 	case CMD_OBJ_RULE:
 		return mnl_nft_rule_add(ctx, cmd, flags);
 	default:
-		BUG("invalid command object type %u\n", cmd->obj);
+		BUG("invalid command object type %u", cmd->obj);
 	}
 	return 0;
 }
@@ -1630,7 +1630,7 @@ static int do_command_delete(struct netlink_ctx *ctx, struct cmd *cmd)
 	case CMD_OBJ_FLOWTABLE:
 		return mnl_nft_flowtable_del(ctx, cmd);
 	default:
-		BUG("invalid command object type %u\n", cmd->obj);
+		BUG("invalid command object type %u", cmd->obj);
 	}
 }
 
@@ -2654,7 +2654,7 @@ static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd)
 		break;
 	}
 
-	BUG("invalid command object type %u\n", cmd->obj);
+	BUG("invalid command object type %u", cmd->obj);
 	return 0;
 }
 
@@ -2694,7 +2694,7 @@ static int do_command_get(struct netlink_ctx *ctx, struct cmd *cmd)
 	case CMD_OBJ_ELEMENTS:
 		return do_get_setelems(ctx, cmd, false);
 	default:
-		BUG("invalid command object type %u\n", cmd->obj);
+		BUG("invalid command object type %u", cmd->obj);
 	}
 
 	return 0;
@@ -2725,7 +2725,7 @@ static int do_command_flush(struct netlink_ctx *ctx, struct cmd *cmd)
 	case CMD_OBJ_RULESET:
 		return mnl_nft_table_del(ctx, cmd);
 	default:
-		BUG("invalid command object type %u\n", cmd->obj);
+		BUG("invalid command object type %u", cmd->obj);
 	}
 	return 0;
 }
@@ -2743,7 +2743,7 @@ static int do_command_rename(struct netlink_ctx *ctx, struct cmd *cmd)
 
 		return mnl_nft_chain_rename(ctx, cmd, chain);
 	default:
-		BUG("invalid command object type %u\n", cmd->obj);
+		BUG("invalid command object type %u", cmd->obj);
 	}
 	return 0;
 }
@@ -2830,7 +2830,7 @@ int do_command(struct netlink_ctx *ctx, struct cmd *cmd)
 	case CMD_DESCRIBE:
 		return do_command_describe(ctx, cmd, &ctx->nft->output);
 	default:
-		BUG("invalid command object type %u\n", cmd->obj);
+		BUG("invalid command object type %u", cmd->obj);
 	}
 }
 
src/segtree.c +1 -1
index 7d4c50f499ef7..3758193efe3fc 100644
@@ -120,7 +120,7 @@ static struct expr *expr_value(struct expr *expr)
 	case EXPR_VALUE:
 		return expr;
 	default:
-		BUG("invalid expression type %s\n", expr_name(expr));
+		BUG("invalid expression type %s", expr_name(expr));
 	}
 }
 
src/statement.c +1 -1
index 20241f6867a31..d0993ddeac3b3 100644
@@ -1138,7 +1138,7 @@ const struct stmt_ops *stmt_ops(const struct stmt *stmt)
 
 	ops = __stmt_ops_by_type(stmt->type);
 	if (!ops)
-		BUG("Unknown statement type %d\n", stmt->type);
+		BUG("Unknown statement type %d", stmt->type);
 
 	return ops;
 }
Signature · 1 line
2.51.0
#49 lore raw

Re: [nft PATCH 28/28] Drop no longer needed newline in BUG() messages

Quoted 2 lines · Phil Sutter

Since BUG() now appends a newline itself, drop it from calls where present.

I really think 27/28 and 28/28 belong to the same patch.

Quoted 776 lines
---
 src/datatype.c            |  2 +-
 src/erec.c                |  2 +-
 src/evaluate.c            | 46 +++++++++++++++++++--------------------
 src/expression.c          |  6 ++---
 src/fib.c                 |  2 +-
 src/intervals.c           |  8 +++----
 src/json.c                |  4 ++--
 src/mergesort.c           |  2 +-
 src/mnl.c                 |  8 +++----
 src/netlink.c             | 11 +++++-----
 src/netlink_delinearize.c | 11 +++++-----
 src/netlink_linearize.c   | 28 ++++++++++++------------
 src/optimize.c            |  2 +-
 src/rule.c                | 20 ++++++++---------
 src/segtree.c             |  2 +-
 src/statement.c           |  2 +-
 16 files changed, 79 insertions(+), 77 deletions(-)
src/datatype.c +1 -1
index 2ee7e7d5e9cf6..eee9ab9d19296 100644
@@ -119,7 +119,7 @@ void datatype_print(const struct expr *expr, struct output_ctx *octx)
 						       false, octx);
 	} while ((dtype = dtype->basetype));
 
-	BUG("datatype %s has no print method or symbol table\n",
+	BUG("datatype %s has no print method or symbol table",
 	    expr->dtype->name);
 }
 
src/erec.c +1 -1
index fe66abbe3ac29..8f480a80a0d0c 100644
@@ -156,7 +156,7 @@ void erec_print(struct output_ctx *octx, const struct error_record *erec,
 	case INDESC_NETLINK:
 		break;
 	default:
-		BUG("invalid input descriptor type %u\n", indesc->type);
+		BUG("invalid input descriptor type %u", indesc->type);
 	}
 
 	f = octx->error_fp;
src/evaluate.c +23 -23
index cee500312bc6d..7dc59a00097a8 100644
@@ -172,7 +172,7 @@ static enum ops byteorder_conversion_op(struct expr *expr,
 	default:
 		break;
 	}
-	BUG("invalid byte order conversion %u => %u\n",
+	BUG("invalid byte order conversion %u => %u",
 	    expr->byteorder, byteorder);
 }
 
@@ -587,7 +587,7 @@ static int expr_evaluate_bits(struct eval_ctx *ctx, struct expr **exprp)
 					  &extra_len);
 		break;
 	default:
-		BUG("Unknown expression %s\n", expr_name(expr));
+		BUG("Unknown expression %s", expr_name(expr));
 	}
 
 	masklen = len + shift;
@@ -1366,7 +1366,7 @@ static int expr_evaluate_unary(struct eval_ctx *ctx, struct expr **expr)
 		byteorder = BYTEORDER_HOST_ENDIAN;
 		break;
 	default:
-		BUG("invalid unary operation %u\n", unary->op);
+		BUG("invalid unary operation %u", unary->op);
 	}
 
 	__datatype_set(unary, datatype_clone(arg->dtype));
@@ -1417,7 +1417,7 @@ static int constant_binop_simplify(struct eval_ctx *ctx, struct expr **expr)
 		mpz_rshift_ui(val, mpz_get_uint32(right->value));
 		break;
 	default:
-		BUG("invalid binary operation %u\n", op->op);
+		BUG("invalid binary operation %u", op->op);
 	}
 
 	new = constant_expr_alloc(&op->location, op->dtype, op->byteorder,
@@ -1606,7 +1606,7 @@ static int expr_evaluate_binop(struct eval_ctx *ctx, struct expr **expr)
 		ret = expr_evaluate_bitwise(ctx, expr);
 		break;
 	default:
-		BUG("invalid binary operation %u\n", op->op);
+		BUG("invalid binary operation %u", op->op);
 	}
 
 
@@ -2044,7 +2044,7 @@ static int interval_set_eval(struct eval_ctx *ctx, struct set *set,
 	case CMD_RESET:
 		break;
 	default:
-		BUG("unhandled op %d\n", ctx->cmd->op);
+		BUG("unhandled op %d", ctx->cmd->op);
 		break;
 	}
 
@@ -2269,7 +2269,7 @@ static int expr_evaluate_map(struct eval_ctx *ctx, struct expr **expr)
 			return -1;
 
 		if (ectx.len && mappings->set->data->len != ectx.len)
-			BUG("%d vs %d\n", mappings->set->data->len, ectx.len);
+			BUG("%d vs %d", mappings->set->data->len, ectx.len);
 
 		map->mappings = mappings;
 
@@ -2634,7 +2634,7 @@ static int binop_transfer_one(struct eval_ctx *ctx,
 					    *right, expr_get(left->right));
 		break;
 	default:
-		BUG("invalid binary operation %u\n", left->op);
+		BUG("invalid binary operation %u", left->op);
 	}
 
 	return expr_evaluate(ctx, right);
@@ -2956,7 +2956,7 @@ static int expr_evaluate_relational(struct eval_ctx *ctx, struct expr **expr)
 						 "Use concatenations with sets and maps, not singleton values");
 			break;
 		default:
-			BUG("invalid expression type %s\n", expr_name(right));
+			BUG("invalid expression type %s", expr_name(right));
 		}
 		break;
 	case OP_LT:
@@ -2987,7 +2987,7 @@ static int expr_evaluate_relational(struct eval_ctx *ctx, struct expr **expr)
 			return -1;
 		break;
 	default:
-		BUG("invalid relational operation %u\n", rel->op);
+		BUG("invalid relational operation %u", rel->op);
 	}
 
 	if (binop_transfer(ctx, expr) < 0)
@@ -3223,7 +3223,7 @@ static int expr_evaluate(struct eval_ctx *ctx, struct expr **expr)
 	case EXPR_RANGE_SYMBOL:
 		return expr_evaluate_symbol_range(ctx, expr);
 	default:
-		BUG("unknown expression type %s\n", expr_name(*expr));
+		BUG("unknown expression type %s", expr_name(*expr));
 	}
 }
 
@@ -3384,7 +3384,7 @@ static int stmt_evaluate_verdict(struct eval_ctx *ctx, struct stmt *stmt)
 	case EXPR_MAP:
 		break;
 	default:
-		BUG("invalid verdict expression %s\n", expr_name(stmt->expr));
+		BUG("invalid verdict expression %s", expr_name(stmt->expr));
 	}
 	return 0;
 }
@@ -5085,7 +5085,7 @@ int stmt_evaluate(struct eval_ctx *ctx, struct stmt *stmt)
 	case STMT_OPTSTRIP:
 		return stmt_evaluate_optstrip(ctx, stmt);
 	default:
-		BUG("unknown statement type %d\n", stmt->type);
+		BUG("unknown statement type %d", stmt->type);
 	}
 }
 
@@ -5476,7 +5476,7 @@ static struct expr *expr_set_to_list(struct eval_ctx *ctx, struct expr *dev_expr
 			expr = key;
 			break;
 		default:
-			BUG("invalid expression type %s\n", expr_name(expr));
+			BUG("invalid expression type %s", expr_name(expr));
 			break;
 		}
 
@@ -5528,7 +5528,7 @@ static bool evaluate_device_expr(struct eval_ctx *ctx, struct expr **dev_expr)
 		case EXPR_VALUE:
 			break;
 		default:
-			BUG("invalid expression type %s\n", expr_name(expr));
+			BUG("invalid expression type %s", expr_name(expr));
 			break;
 		}
 
@@ -5968,7 +5968,7 @@ static int cmd_evaluate_add(struct eval_ctx *ctx, struct cmd *cmd)
 		handle_merge(&cmd->object->handle, &cmd->handle);
 		return obj_evaluate(ctx, cmd->object);
 	default:
-		BUG("invalid command object type %u\n", cmd->obj);
+		BUG("invalid command object type %u", cmd->obj);
 	}
 }
 
@@ -6139,7 +6139,7 @@ static int cmd_evaluate_delete(struct eval_ctx *ctx, struct cmd *cmd)
 		obj_del_cache(ctx, cmd, NFT_OBJECT_TUNNEL);
 		return 0;
 	default:
-		BUG("invalid command object type %u\n", cmd->obj);
+		BUG("invalid command object type %u", cmd->obj);
 	}
 }
 
@@ -6149,7 +6149,7 @@ static int cmd_evaluate_get(struct eval_ctx *ctx, struct cmd *cmd)
 	case CMD_OBJ_ELEMENTS:
 		return setelem_evaluate(ctx, cmd);
 	default:
-		BUG("invalid command object type %u\n", cmd->obj);
+		BUG("invalid command object type %u", cmd->obj);
 	}
 }
 
@@ -6304,7 +6304,7 @@ static int cmd_evaluate_list(struct eval_ctx *ctx, struct cmd *cmd)
 		}
 		return 0;
 	default:
-		BUG("invalid command object type %u\n", cmd->obj);
+		BUG("invalid command object type %u", cmd->obj);
 	}
 }
 
@@ -6333,7 +6333,7 @@ static int cmd_evaluate_reset(struct eval_ctx *ctx, struct cmd *cmd)
 	case CMD_OBJ_MAP:
 		return cmd_evaluate_list(ctx, cmd);
 	default:
-		BUG("invalid command object type %u\n", cmd->obj);
+		BUG("invalid command object type %u", cmd->obj);
 	}
 }
 
@@ -6413,7 +6413,7 @@ static int cmd_evaluate_flush(struct eval_ctx *ctx, struct cmd *cmd)
 
 		return 0;
 	default:
-		BUG("invalid command object type %u\n", cmd->obj);
+		BUG("invalid command object type %u", cmd->obj);
 	}
 	return 0;
 }
@@ -6435,7 +6435,7 @@ static int cmd_evaluate_rename(struct eval_ctx *ctx, struct cmd *cmd)
 
 		break;
 	default:
-		BUG("invalid command object type %u\n", cmd->obj);
+		BUG("invalid command object type %u", cmd->obj);
 	}
 	return 0;
 }
@@ -6625,5 +6625,5 @@ int cmd_evaluate(struct eval_ctx *ctx, struct cmd *cmd)
 		break;
 	};
 
-	BUG("invalid command operation %u\n", cmd->op);
+	BUG("invalid command operation %u", cmd->op);
 }
src/expression.c +3 -3
index de63196b60a6a..0dc59ab04b16c 100644
@@ -1770,7 +1770,7 @@ void range_expr_value_low(mpz_t rop, const struct expr *expr)
 	case EXPR_SET_ELEM:
 		return range_expr_value_low(rop, expr->key);
 	default:
-		BUG("invalid range expression type %s\n", expr_name(expr));
+		BUG("invalid range expression type %s", expr_name(expr));
 	}
 }
 
@@ -1797,7 +1797,7 @@ void range_expr_value_high(mpz_t rop, const struct expr *expr)
 	case EXPR_SET_ELEM:
 		return range_expr_value_high(rop, expr->key);
 	default:
-		BUG("invalid range expression type %s\n", expr_name(expr));
+		BUG("invalid range expression type %s", expr_name(expr));
 	}
 }
 
@@ -1848,7 +1848,7 @@ const struct expr_ops *expr_ops(const struct expr *e)
 
 	ops = __expr_ops_by_type(e->etype);
 	if (!ops)
-		BUG("Unknown expression type %d\n", e->etype);
+		BUG("Unknown expression type %d", e->etype);
 
 	return ops;
 }
src/fib.c +1 -1
index 571277ddf434a..c8ac8a8357e5d 100644
@@ -197,7 +197,7 @@ struct expr *fib_expr_alloc(const struct location *loc,
 		type = &fib_addr_type;
 		break;
 	default:
-		BUG("Unknown result %d\n", result);
+		BUG("Unknown result %d", result);
 	}
 
 	if (flags & NFTA_FIB_F_PRESENT) {
src/intervals.c +4 -4
index 6a917b7b79c3f..7f3d2252fcadc 100644
@@ -65,7 +65,7 @@ static void setelem_expr_to_range(struct expr *expr)
 		expr->key = key;
 		break;
 	default:
-		BUG("unhandled key type %s\n", expr_name(expr->key));
+		BUG("unhandled key type %s", expr_name(expr->key));
 	}
 }
 
@@ -221,7 +221,7 @@ static struct expr *interval_expr_key(struct expr *i)
 		elem = i;
 		break;
 	default:
-		BUG("unhandled expression type %d\n", i->etype);
+		BUG("unhandled expression type %d", i->etype);
 		return NULL;
 	}
 
@@ -751,7 +751,7 @@ static struct expr *setelem_key(struct expr *expr)
 		key = expr->key;
 		break;
 	default:
-		BUG("unhandled expression type %d\n", expr->etype);
+		BUG("unhandled expression type %d", expr->etype);
 		return NULL;
 	}
 
@@ -775,7 +775,7 @@ int setelem_to_interval(const struct set *set, struct expr *elem,
 	}
 
 	if (key->etype != EXPR_RANGE_VALUE)
-		BUG("key must be RANGE_VALUE, not %s\n", expr_name(key));
+		BUG("key must be RANGE_VALUE, not %s", expr_name(key));
 
 	assert(!next_key || next_key->etype == EXPR_RANGE_VALUE);
 
src/json.c +2 -2
index 46d8a73333374..e3688249f806a 100644
@@ -1117,7 +1117,7 @@ static json_t *datatype_json(const struct expr *expr, struct output_ctx *octx)
 		}
 	} while ((dtype = dtype->basetype));
 
-	BUG("datatype %s has no print method or symbol table\n",
+	BUG("datatype %s has no print method or symbol table",
 	    expr->dtype->name);
 }
 
@@ -2149,7 +2149,7 @@ int do_command_list_json(struct netlink_ctx *ctx, struct cmd *cmd)
 		errno = EOPNOTSUPP;
 		return -1;
 	case CMD_OBJ_INVALID:
-		BUG("invalid command object type %u\n", cmd->obj);
+		BUG("invalid command object type %u", cmd->obj);
 		break;
 	}
 
src/mergesort.c +1 -1
index 95037e5be8608..9984e272df580 100644
@@ -48,7 +48,7 @@ static mpz_srcptr expr_msort_value(const struct expr *expr, mpz_t value)
 		mpz_bitmask(value, expr->len);
 		break;
 	default:
-		BUG("Unknown expression %s\n", expr_name(expr));
+		BUG("Unknown expression %s", expr_name(expr));
 	}
 	return value;
 }
src/mnl.c +4 -4
index 6e32fc3467ce9..a2e555d4a8bf4 100644
@@ -740,18 +740,18 @@ static void nft_dev_add(struct nft_dev *dev_array, const struct expr *expr, int
 	char ifname[IFNAMSIZ];
 
 	if (expr->etype != EXPR_VALUE)
-		BUG("Must be a value, not %s\n", expr_name(expr));
+		BUG("Must be a value, not %s", expr_name(expr));
 
 	ifname_len = div_round_up(expr->len, BITS_PER_BYTE);
 	memset(ifname, 0, sizeof(ifname));
 
 	if (ifname_len > sizeof(ifname))
-		BUG("Interface length %u exceeds limit\n", ifname_len);
+		BUG("Interface length %u exceeds limit", ifname_len);
 
 	mpz_export_data(ifname, expr->value, BYTEORDER_BIG_ENDIAN, ifname_len);
 
 	if (strnlen(ifname, IFNAMSIZ) >= IFNAMSIZ)
-		BUG("Interface length %zu exceeds limit, no NUL byte\n", strnlen(ifname, IFNAMSIZ));
+		BUG("Interface length %zu exceeds limit, no NUL byte", strnlen(ifname, IFNAMSIZ));
 
 	dev_array[i].ifname = xstrdup(ifname);
 	dev_array[i].location = &expr->location;
@@ -1734,7 +1734,7 @@ int mnl_nft_obj_add(struct netlink_ctx *ctx, struct cmd *cmd,
 		obj_tunnel_add_opts(nlo, &obj->tunnel);
 		break;
 	default:
-		BUG("Unknown type %d\n", obj->type);
+		BUG("Unknown type %d", obj->type);
 		break;
 	}
 	netlink_dump_obj(nlo, ctx);
src/netlink.c +6 -5
index 68228bdc5c99a..5be7feb17d84a 100644
@@ -125,7 +125,7 @@ struct nftnl_set_elem *alloc_nftnl_setelem(const struct expr *set,
 		elem = expr;
 	}
 	if (elem->etype != EXPR_SET_ELEM)
-		BUG("Unexpected expression type: got %d\n", elem->etype);
+		BUG("Unexpected expression type: got %d", elem->etype);
 
 	key = elem->key;
 
@@ -227,7 +227,7 @@ struct nftnl_set_elem *alloc_nftnl_setelem(const struct expr *set,
 					       nld.byteorder, nld.sizes);
 			break;
 		default:
-			BUG("unexpected set element expression\n");
+			BUG("unexpected set element expression");
 			break;
 		}
 	}
@@ -347,7 +347,8 @@ static void nft_data_memcpy(struct nft_data_linearize *nld,
 			    const void *src, unsigned int len)
 {
 	if (len > sizeof(nld->value))
-		BUG("nld buffer overflow: want to copy %u, max %u\n", len, (unsigned int)sizeof(nld->value));
+		BUG("nld buffer overflow: want to copy %u, max %u",
+		    len, (unsigned int)sizeof(nld->value));
 
 	memcpy(nld->value, src, len);
 	nld->len = len;
@@ -606,7 +607,7 @@ static void netlink_gen_key(const struct expr *expr,
 	case EXPR_PREFIX:
 		return netlink_gen_prefix(expr, data);
 	default:
-		BUG("invalid data expression type %s\n", expr_name(expr));
+		BUG("invalid data expression type %s", expr_name(expr));
 	}
 }
 
@@ -629,7 +630,7 @@ static void __netlink_gen_data(const struct expr *expr,
 	case EXPR_PREFIX:
 		return netlink_gen_prefix(expr, data);
 	default:
-		BUG("invalid data expression type %s\n", expr_name(expr));
+		BUG("invalid data expression type %s", expr_name(expr));
 	}
 }
 
src/netlink_delinearize.c +6 -5
index 54be0682b0899..3f79463c25f76 100644
@@ -2474,7 +2474,7 @@ static void binop_adjust_one(const struct expr *binop, struct expr *value,
 		value->len = left->len;
 		break;
 	default:
-		BUG("unknown expression type %s\n", expr_name(left));
+		BUG("unknown expression type %s", expr_name(left));
 		break;
 	}
 }
@@ -2505,7 +2505,8 @@ static void binop_adjust(const struct expr *binop, struct expr *right,
 				binop_adjust(binop, i->key->key, shift);
 				break;
 			default:
-				BUG("unknown expression type %s\n", expr_name(i->key));
+				BUG("unknown expression type %s",
+				    expr_name(i->key));
 			}
 		}
 		break;
@@ -2514,7 +2515,7 @@ static void binop_adjust(const struct expr *binop, struct expr *right,
 		binop_adjust_one(binop, right->right, shift);
 		break;
 	default:
-		BUG("unknown expression type %s\n", expr_name(right));
+		BUG("unknown expression type %s", expr_name(right));
 		break;
 	}
 }
@@ -2645,7 +2646,7 @@ static void relational_binop_postprocess(struct rule_pp_ctx *ctx,
 			expr->op = OP_NEG;
 			break;
 		default:
-			BUG("unknown operation type %d\n", expr->op);
+			BUG("unknown operation type %d", expr->op);
 		}
 		expr_free(binop);
 	} else if (datatype_prefix_notation(binop->left->dtype) &&
@@ -3051,7 +3052,7 @@ static void expr_postprocess(struct rule_pp_ctx *ctx, struct expr **exprp)
 		ct_expr_update_type(&dl->pctx, expr);
 		break;
 	default:
-		BUG("unknown expression type %s\n", expr_name(expr));
+		BUG("unknown expression type %s", expr_name(expr));
 	}
 }
 
src/netlink_linearize.c +14 -14
index 36a539bf96283..ac0eaff9a23ca 100644
@@ -76,7 +76,7 @@ static enum nft_registers __get_register(struct netlink_linearize_ctx *ctx,
 
 	n = netlink_register_space(size);
 	if (ctx->reg_low + n > NFT_REG_1 + NFT_REG32_15 - NFT_REG32_00 + 1)
-		BUG("register reg_low %u invalid\n", ctx->reg_low);
+		BUG("register reg_low %u invalid", ctx->reg_low);
 
 	reg = ctx->reg_low;
 	ctx->reg_low += n;
@@ -90,7 +90,7 @@ static void __release_register(struct netlink_linearize_ctx *ctx,
 
 	n = netlink_register_space(size);
 	if (ctx->reg_low < NFT_REG_1 + n)
-		BUG("register reg_low %u invalid\n", ctx->reg_low);
+		BUG("register reg_low %u invalid", ctx->reg_low);
 
 	ctx->reg_low -= n;
 }
@@ -457,7 +457,7 @@ static enum nft_cmp_ops netlink_gen_cmp_op(enum ops op)
 	case OP_GTE:
 		return NFT_CMP_GTE;
 	default:
-		BUG("invalid comparison operation %u\n", op);
+		BUG("invalid comparison operation %u", op);
 	}
 }
 
@@ -521,7 +521,7 @@ static void netlink_gen_range(struct netlink_linearize_ctx *ctx,
 		nft_rule_add_expr(ctx, nle, &expr->location);
 		break;
 	default:
-		BUG("invalid range operation %u\n", expr->op);
+		BUG("invalid range operation %u", expr->op);
 
 	}
 
@@ -606,7 +606,7 @@ static void netlink_gen_relational(struct netlink_linearize_ctx *ctx,
 	case OP_NEG:
 		break;
 	default:
-		BUG("invalid relational operation %u\n", expr->op);
+		BUG("invalid relational operation %u", expr->op);
 	}
 
 	switch (expr->right->etype) {
@@ -741,7 +741,7 @@ static void netlink_gen_bitwise_mask_xor(struct netlink_linearize_ctx *ctx,
 			combine_binop(mask, xor, tmp, val);
 			break;
 		default:
-			BUG("invalid binary operation %u\n", i->op);
+			BUG("invalid binary operation %u", i->op);
 		}
 	}
 
@@ -789,7 +789,7 @@ static void netlink_gen_bitwise_bool(struct netlink_linearize_ctx *ctx,
 		nftnl_expr_set_u32(nle, NFTNL_EXPR_BITWISE_OP, NFT_BITWISE_OR);
 		break;
 	default:
-		BUG("invalid binary operation %u\n", expr->op);
+		BUG("invalid binary operation %u", expr->op);
 	}
 
 	netlink_gen_expr(ctx, expr->left, dreg);
@@ -833,7 +833,7 @@ static enum nft_byteorder_ops netlink_gen_unary_op(enum ops op)
 	case OP_NTOH:
 		return NFT_BYTEORDER_NTOH;
 	default:
-		BUG("invalid unary operation %u\n", op);
+		BUG("invalid unary operation %u", op);
 	}
 }
 
@@ -961,7 +961,7 @@ static void netlink_gen_expr(struct netlink_linearize_ctx *ctx,
 	case EXPR_XFRM:
 		return netlink_gen_xfrm(ctx, expr, dreg);
 	default:
-		BUG("unknown expression type %s\n", expr_name(expr));
+		BUG("unknown expression type %s", expr_name(expr));
 	}
 }
 
@@ -994,7 +994,7 @@ static void netlink_gen_objref_stmt(struct netlink_linearize_ctx *ctx,
 				   stmt->objref.type);
 		break;
 	default:
-		BUG("unsupported expression %u\n", expr->etype);
+		BUG("unsupported expression %u", expr->etype);
 	}
 	nft_rule_add_expr(ctx, nle, &expr->location);
 }
@@ -1082,7 +1082,7 @@ struct nftnl_expr *netlink_gen_stmt_stateful(const struct stmt *stmt)
 	case STMT_LAST:
 		return netlink_gen_last_stmt(stmt);
 	default:
-		BUG("unknown stateful statement type %d\n", stmt->type);
+		BUG("unknown stateful statement type %d", stmt->type);
 	}
 }
 
@@ -1241,7 +1241,7 @@ static unsigned int nat_addrlen(uint8_t family)
 	case NFPROTO_IPV6: return 128;
 	}
 
-	BUG("invalid nat family %u\n", family);
+	BUG("invalid nat family %u", family);
 	return 0;
 }
 
@@ -1284,7 +1284,7 @@ static void netlink_gen_nat_stmt(struct netlink_linearize_ctx *ctx,
 		nftnl_reg_pmax = NFTNL_EXPR_REDIR_REG_PROTO_MAX;
 		break;
 	default:
-		BUG("unknown nat type %d\n", stmt->nat.type);
+		BUG("unknown nat type %d", stmt->nat.type);
 		break;
 	}
 
@@ -1772,7 +1772,7 @@ static void netlink_gen_stmt(struct netlink_linearize_ctx *ctx,
 	case STMT_OPTSTRIP:
 		return netlink_gen_optstrip_stmt(ctx, stmt);
 	default:
-		BUG("unknown statement type %d\n", stmt->type);
+		BUG("unknown statement type %d", stmt->type);
 	}
 }
 
src/optimize.c +1 -1
index ffc06480d4ee5..17084a84d4655 100644
@@ -1181,7 +1181,7 @@ static void rule_optimize_print(struct output_ctx *octx,
 	case INDESC_NETLINK:
 		break;
 	default:
-		BUG("invalid input descriptor type %u\n", indesc->type);
+		BUG("invalid input descriptor type %u", indesc->type);
 	}
 
 	print_location(octx->error_fp, indesc, loc);
src/rule.c +10 -10
index d0a62a3ee002d..14184a70675b7 100644
@@ -1450,7 +1450,7 @@ void cmd_free(struct cmd *cmd)
 			flowtable_free(cmd->flowtable);
 			break;
 		default:
-			BUG("invalid command object type %u\n", cmd->obj);
+			BUG("invalid command object type %u", cmd->obj);
 		}
 	}
 	free(cmd->attr);
@@ -1549,7 +1549,7 @@ static int do_command_add(struct netlink_ctx *ctx, struct cmd *cmd, bool excl)
 	case CMD_OBJ_FLOWTABLE:
 		return mnl_nft_flowtable_add(ctx, cmd, flags);
 	default:
-		BUG("invalid command object type %u\n", cmd->obj);
+		BUG("invalid command object type %u", cmd->obj);
 	}
 	return 0;
 }
@@ -1560,7 +1560,7 @@ static int do_command_replace(struct netlink_ctx *ctx, struct cmd *cmd)
 	case CMD_OBJ_RULE:
 		return mnl_nft_rule_replace(ctx, cmd);
 	default:
-		BUG("invalid command object type %u\n", cmd->obj);
+		BUG("invalid command object type %u", cmd->obj);
 	}
 	return 0;
 }
@@ -1576,7 +1576,7 @@ static int do_command_insert(struct netlink_ctx *ctx, struct cmd *cmd)
 	case CMD_OBJ_RULE:
 		return mnl_nft_rule_add(ctx, cmd, flags);
 	default:
-		BUG("invalid command object type %u\n", cmd->obj);
+		BUG("invalid command object type %u", cmd->obj);
 	}
 	return 0;
 }
@@ -1630,7 +1630,7 @@ static int do_command_delete(struct netlink_ctx *ctx, struct cmd *cmd)
 	case CMD_OBJ_FLOWTABLE:
 		return mnl_nft_flowtable_del(ctx, cmd);
 	default:
-		BUG("invalid command object type %u\n", cmd->obj);
+		BUG("invalid command object type %u", cmd->obj);
 	}
 }
 
@@ -2654,7 +2654,7 @@ static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd)
 		break;
 	}
 
-	BUG("invalid command object type %u\n", cmd->obj);
+	BUG("invalid command object type %u", cmd->obj);
 	return 0;
 }
 
@@ -2694,7 +2694,7 @@ static int do_command_get(struct netlink_ctx *ctx, struct cmd *cmd)
 	case CMD_OBJ_ELEMENTS:
 		return do_get_setelems(ctx, cmd, false);
 	default:
-		BUG("invalid command object type %u\n", cmd->obj);
+		BUG("invalid command object type %u", cmd->obj);
 	}
 
 	return 0;
@@ -2725,7 +2725,7 @@ static int do_command_flush(struct netlink_ctx *ctx, struct cmd *cmd)
 	case CMD_OBJ_RULESET:
 		return mnl_nft_table_del(ctx, cmd);
 	default:
-		BUG("invalid command object type %u\n", cmd->obj);
+		BUG("invalid command object type %u", cmd->obj);
 	}
 	return 0;
 }
@@ -2743,7 +2743,7 @@ static int do_command_rename(struct netlink_ctx *ctx, struct cmd *cmd)
 
 		return mnl_nft_chain_rename(ctx, cmd, chain);
 	default:
-		BUG("invalid command object type %u\n", cmd->obj);
+		BUG("invalid command object type %u", cmd->obj);
 	}
 	return 0;
 }
@@ -2830,7 +2830,7 @@ int do_command(struct netlink_ctx *ctx, struct cmd *cmd)
 	case CMD_DESCRIBE:
 		return do_command_describe(ctx, cmd, &ctx->nft->output);
 	default:
-		BUG("invalid command object type %u\n", cmd->obj);
+		BUG("invalid command object type %u", cmd->obj);
 	}
 }
 
src/segtree.c +1 -1
index 7d4c50f499ef7..3758193efe3fc 100644
@@ -120,7 +120,7 @@ static struct expr *expr_value(struct expr *expr)
 	case EXPR_VALUE:
 		return expr;
 	default:
-		BUG("invalid expression type %s\n", expr_name(expr));
+		BUG("invalid expression type %s", expr_name(expr));
 	}
 }
 
src/statement.c +1 -1
index 20241f6867a31..d0993ddeac3b3 100644
@@ -1138,7 +1138,7 @@ const struct stmt_ops *stmt_ops(const struct stmt *stmt)
 
 	ops = __stmt_ops_by_type(stmt->type);
 	if (!ops)
-		BUG("Unknown statement type %d\n", stmt->type);
+		BUG("Unknown statement type %d", stmt->type);
 
 	return ops;
 }
Signature · 1 line
2.51.0
author reviewer
#50 lore raw

Re: [nft PATCH 28/28] Drop no longer needed newline in BUG() messages

Quoted 5 lines · Pablo Neira Ayuso
Quoted 2 lines · Phil Sutter

Since BUG() now appends a newline itself, drop it from calls where present.

I really think 27/28 and 28/28 belong to the same patch.

I'll fold them before pushing out as Florian suggested, OK?

Cheers, Phil

maintainer
#51 lore raw
In reply to Phil Sutter
Quoted 5 lines · Phil Sutter

Make use of recent changes to libnftnl and make tests/py testsuite pass on Big Endian systems.

Patches 1-7 fix existing code, are valid without the remaining ones but required for the target at hand.

Please push those out, thanks.

Quoted 2 lines

Patches 8-12 are a mixture of fixes and preparation for the remaining ones.

I think they are fine too, so just flush them out.

I'll go over the rest tomorrow.

author reviewer
#52 lore raw
Quoted 7 lines · Florian Westphal
Quoted 5 lines · Phil Sutter

Make use of recent changes to libnftnl and make tests/py testsuite pass on Big Endian systems.

Patches 1-7 fix existing code, are valid without the remaining ones but required for the target at hand.

Quoted 8 lines

Please push those out, thanks.

Quoted 2 lines

Patches 8-12 are a mixture of fixes and preparation for the remaining ones.

I think they are fine too, so just flush them out.

I'll go over the rest tomorrow.

Cool, thanks for the quick review!