Blame SOURCES/0017-src-trace-fix-policy-printing.patch

34625f
From 244a83f9e0809177f07fb7b7474f84a126cf827f Mon Sep 17 00:00:00 2001
34625f
From: Florian Westphal <fw@strlen.de>
34625f
Date: Wed, 20 Jun 2018 23:06:04 +0200
34625f
Subject: [PATCH] src: trace: fix policy printing
34625f
34625f
policy type is erronously handled via verdict, this is wrong.
34625f
It is a different event type and needs to be handled as such.
34625f
34625f
before:
34625f
trace id 42b54e71 inet filter input packet: iif "lo" ip saddr 127.0.0.1 ..
34625f
trace id 42b54e71 inet filter input rule ip protocol icmp nftrace set 1 (verdict continue)
34625f
trace id 42b54e71 inet filter input verdict continue
34625f
trace id 42b54e71 inet filter input
34625f
34625f
after:
34625f
trace id 9f40c5c7 inet filter input packet: iif "lo" ip saddr 127.0.0.1 ..
34625f
trace id 9f40c5c7 inet filter input rule ip protocol icmp nftrace set 1 (verdict continue)
34625f
trace id 9f40c5c7 inet filter input verdict continue
34625f
trace id 9f40c5c7 inet filter input policy drop
34625f
34625f
Reported-by: vtol@gmx.net
34625f
Signed-off-by: Florian Westphal <fw@strlen.de>
34625f
(cherry picked from commit 78ba4ffdeacc9b31f7396d72c98907e861024653)
34625f
Signed-off-by: Phil Sutter <psutter@redhat.com>
34625f
---
34625f
 src/netlink.c | 31 ++++++++++++++++++++++++++++++-
34625f
 1 file changed, 30 insertions(+), 1 deletion(-)
34625f
34625f
diff --git a/src/netlink.c b/src/netlink.c
34625f
index ca5e9b4a0f8a6..4fd3f2dfefced 100644
34625f
--- a/src/netlink.c
34625f
+++ b/src/netlink.c
34625f
@@ -1705,7 +1705,22 @@ static void trace_print_verdict(const struct nftnl_trace *nlt,
34625f
 		chain = xstrdup(nftnl_trace_get_str(nlt, NFTNL_TRACE_JUMP_TARGET));
34625f
 	expr = verdict_expr_alloc(&netlink_location, verdict, chain);
34625f
 
34625f
-	printf("verdict ");
34625f
+	nft_print(octx, "verdict ");
34625f
+	expr_print(expr, octx);
34625f
+	expr_free(expr);
34625f
+}
34625f
+
34625f
+static void trace_print_policy(const struct nftnl_trace *nlt,
34625f
+			       struct output_ctx *octx)
34625f
+{
34625f
+	unsigned int policy;
34625f
+	struct expr *expr;
34625f
+
34625f
+	policy = nftnl_trace_get_u32(nlt, NFTNL_TRACE_POLICY);
34625f
+
34625f
+	expr = verdict_expr_alloc(&netlink_location, policy, NULL);
34625f
+
34625f
+	nft_print(octx, "policy ");
34625f
 	expr_print(expr, octx);
34625f
 	expr_free(expr);
34625f
 }
34625f
@@ -1921,6 +1936,20 @@ int netlink_events_trace_cb(const struct nlmsghdr *nlh, int type,
34625f
 			trace_print_rule(nlt, monh->ctx->octx, monh->cache);
34625f
 		break;
34625f
 	case NFT_TRACETYPE_POLICY:
34625f
+		trace_print_hdr(nlt, monh->ctx->octx);
34625f
+
34625f
+		if (nftnl_trace_is_set(nlt, NFTNL_TRACE_POLICY)) {
34625f
+			trace_print_policy(nlt, monh->ctx->octx);
34625f
+			nft_mon_print(monh, " ");
34625f
+		}
34625f
+
34625f
+		if (nftnl_trace_is_set(nlt, NFTNL_TRACE_MARK))
34625f
+			trace_print_expr(nlt, NFTNL_TRACE_MARK,
34625f
+					 meta_expr_alloc(&netlink_location,
34625f
+							 NFT_META_MARK),
34625f
+					 monh->ctx->octx);
34625f
+		nft_mon_print(monh, "\n");
34625f
+		break;
34625f
 	case NFT_TRACETYPE_RETURN:
34625f
 		trace_print_hdr(nlt, monh->ctx->octx);
34625f
 
34625f
-- 
34625f
2.19.0
34625f