Skip to contentSkip to conversation

nft: trace: print packet unconditionally

PATCH In review Florian Westphal 1 participant 2 messages Dec 12, 2020 – Dec 14, 2020 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 nft: trace: print packet unconditionally

The kernel includes the packet dump once for each base hook. This means that in case a table contained no matching rule(s), the packet dump will be included in the base policy dump.

Simply move the packet dump request out of the switch statement so the debug output shows current packet even with no matched rule.

---
 src/netlink.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
src/netlink.c +4 -4
index 2ea2d4457664..8098b9746c95 100644
@@ -1880,12 +1880,12 @@ int netlink_events_trace_cb(const struct nlmsghdr *nlh, int type,
 	if (nftnl_trace_nlmsg_parse(nlh, nlt) < 0)
 		netlink_abi_error();
 
+	if (nftnl_trace_is_set(nlt, NFTNL_TRACE_LL_HEADER) ||
+	    nftnl_trace_is_set(nlt, NFTNL_TRACE_NETWORK_HEADER))
+		trace_print_packet(nlt, &monh->ctx->nft->output);
+
 	switch (nftnl_trace_get_u32(nlt, NFTNL_TRACE_TYPE)) {
 	case NFT_TRACETYPE_RULE:
-		if (nftnl_trace_is_set(nlt, NFTNL_TRACE_LL_HEADER) ||
-		    nftnl_trace_is_set(nlt, NFTNL_TRACE_NETWORK_HEADER))
-			trace_print_packet(nlt, &monh->ctx->nft->output);
-
 		if (nftnl_trace_is_set(nlt, NFTNL_TRACE_RULE_HANDLE))
 			trace_print_rule(nlt, &monh->ctx->nft->output,
 					 &monh->ctx->nft->cache);
Signature · 1 line
2.28.0
author maintainer
#1 lore raw
Quoted 6 lines · Florian Westphal

The kernel includes the packet dump once for each base hook. This means that in case a table contained no matching rule(s), the packet dump will be included in the base policy dump.

Simply move the packet dump request out of the switch statement so the debug output shows current packet even with no matched rule.

Pushed this series with the one change (PRIx64) suggested by Phil.