Blame SOURCES/0005-monitor-Make-trace-events-respect-output_fp.patch

ba04b3
From 696fd8bbb2c654a1d16849fef0f0ae362739def4 Mon Sep 17 00:00:00 2001
ba04b3
From: Phil Sutter <psutter@redhat.com>
ba04b3
Date: Wed, 20 Jun 2018 09:22:00 +0200
ba04b3
Subject: [PATCH] monitor: Make trace events respect output_fp
ba04b3
ba04b3
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1504157
ba04b3
Upstream Status: nftables commit 657472843e7a7
ba04b3
ba04b3
commit 657472843e7a7a4bc7f756356e6636b1f197b745
ba04b3
Author: Phil Sutter <phil@nwl.cc>
ba04b3
Date:   Wed Feb 28 16:04:27 2018 +0100
ba04b3
ba04b3
    monitor: Make trace events respect output_fp
ba04b3
ba04b3
    Seems like this was incompletely converted, part of the output went to
ba04b3
    output_fp already.
ba04b3
ba04b3
    Signed-off-by: Phil Sutter <phil@nwl.cc>
ba04b3
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
ba04b3
---
ba04b3
 src/netlink.c | 38 +++++++++++++++++++++-----------------
ba04b3
 1 file changed, 21 insertions(+), 17 deletions(-)
ba04b3
ba04b3
diff --git a/src/netlink.c b/src/netlink.c
ba04b3
index 5d6f5ce..d839ded 100644
ba04b3
--- a/src/netlink.c
ba04b3
+++ b/src/netlink.c
ba04b3
@@ -2587,14 +2587,18 @@ static void netlink_events_cache_update(struct netlink_mon_handler *monh,
ba04b3
 	}
ba04b3
 }
ba04b3
 
ba04b3
-static void trace_print_hdr(const struct nftnl_trace *nlt)
ba04b3
+static void trace_print_hdr(const struct nftnl_trace *nlt,
ba04b3
+			    struct output_ctx *octx)
ba04b3
 {
ba04b3
-	printf("trace id %08x ", nftnl_trace_get_u32(nlt, NFTNL_TRACE_ID));
ba04b3
-	printf("%s ", family2str(nftnl_trace_get_u32(nlt, NFTNL_TRACE_FAMILY)));
ba04b3
+	nft_print(octx, "trace id %08x %s ",
ba04b3
+		  nftnl_trace_get_u32(nlt, NFTNL_TRACE_ID),
ba04b3
+		  family2str(nftnl_trace_get_u32(nlt, NFTNL_TRACE_FAMILY)));
ba04b3
 	if (nftnl_trace_is_set(nlt, NFTNL_TRACE_TABLE))
ba04b3
-		printf("%s ", nftnl_trace_get_str(nlt, NFTNL_TRACE_TABLE));
ba04b3
+		nft_print(octx, "%s ",
ba04b3
+			  nftnl_trace_get_str(nlt, NFTNL_TRACE_TABLE));
ba04b3
 	if (nftnl_trace_is_set(nlt, NFTNL_TRACE_CHAIN))
ba04b3
-		printf("%s ", nftnl_trace_get_str(nlt, NFTNL_TRACE_CHAIN));
ba04b3
+		nft_print(octx, "%s ",
ba04b3
+			  nftnl_trace_get_str(nlt, NFTNL_TRACE_CHAIN));
ba04b3
 }
ba04b3
 
ba04b3
 static void trace_print_expr(const struct nftnl_trace *nlt, unsigned int attr,
ba04b3
@@ -2611,7 +2615,7 @@ static void trace_print_expr(const struct nftnl_trace *nlt, unsigned int attr,
ba04b3
 	rel  = relational_expr_alloc(&netlink_location, OP_EQ, lhs, rhs);
ba04b3
 
ba04b3
 	expr_print(rel, octx);
ba04b3
-	printf(" ");
ba04b3
+	nft_print(octx, " ");
ba04b3
 	expr_free(rel);
ba04b3
 }
ba04b3
 
ba04b3
@@ -2661,12 +2665,12 @@ static void trace_print_rule(const struct nftnl_trace *nlt,
ba04b3
 	if (!rule)
ba04b3
 		return;
ba04b3
 
ba04b3
-	trace_print_hdr(nlt);
ba04b3
-	printf("rule ");
ba04b3
+	trace_print_hdr(nlt, octx);
ba04b3
+	nft_print(octx, "rule ");
ba04b3
 	rule_print(rule, octx);
ba04b3
-	printf(" (");
ba04b3
+	nft_print(octx, " (");
ba04b3
 	trace_print_verdict(nlt, octx);
ba04b3
-	printf(")\n");
ba04b3
+	nft_print(octx, ")\n");
ba04b3
 }
ba04b3
 
ba04b3
 static void trace_gen_stmts(struct list_head *stmts,
ba04b3
@@ -2775,9 +2779,9 @@ static void trace_print_packet(const struct nftnl_trace *nlt,
ba04b3
 	uint32_t nfproto;
ba04b3
 	struct stmt *stmt, *next;
ba04b3
 
ba04b3
-	trace_print_hdr(nlt);
ba04b3
+	trace_print_hdr(nlt, octx);
ba04b3
 
ba04b3
-	printf("packet: ");
ba04b3
+	nft_print(octx, "packet: ");
ba04b3
 	if (nftnl_trace_is_set(nlt, NFTNL_TRACE_IIF))
ba04b3
 		trace_print_expr(nlt, NFTNL_TRACE_IIF,
ba04b3
 				 meta_expr_alloc(&netlink_location,
ba04b3
@@ -2813,10 +2817,10 @@ static void trace_print_packet(const struct nftnl_trace *nlt,
ba04b3
 
ba04b3
 	list_for_each_entry_safe(stmt, next, &stmts, list) {
ba04b3
 		stmt_print(stmt, octx);
ba04b3
-		printf(" ");
ba04b3
+		nft_print(octx, " ");
ba04b3
 		stmt_free(stmt);
ba04b3
 	}
ba04b3
-	printf("\n");
ba04b3
+	nft_print(octx, "\n");
ba04b3
 }
ba04b3
 
ba04b3
 static int netlink_events_trace_cb(const struct nlmsghdr *nlh, int type,
ba04b3
@@ -2844,11 +2848,11 @@ static int netlink_events_trace_cb(const struct nlmsghdr *nlh, int type,
ba04b3
 		break;
ba04b3
 	case NFT_TRACETYPE_POLICY:
ba04b3
 	case NFT_TRACETYPE_RETURN:
ba04b3
-		trace_print_hdr(nlt);
ba04b3
+		trace_print_hdr(nlt, monh->ctx->octx);
ba04b3
 
ba04b3
 		if (nftnl_trace_is_set(nlt, NFTNL_TRACE_VERDICT)) {
ba04b3
 			trace_print_verdict(nlt, monh->ctx->octx);
ba04b3
-			printf(" ");
ba04b3
+			nft_mon_print(monh, " ");
ba04b3
 		}
ba04b3
 
ba04b3
 		if (nftnl_trace_is_set(nlt, NFTNL_TRACE_MARK))
ba04b3
@@ -2856,7 +2860,7 @@ static int netlink_events_trace_cb(const struct nlmsghdr *nlh, int type,
ba04b3
 					 meta_expr_alloc(&netlink_location,
ba04b3
 							 NFT_META_MARK),
ba04b3
 					 monh->ctx->octx);
ba04b3
-		printf("\n");
ba04b3
+		nft_mon_print(monh, "\n");
ba04b3
 		break;
ba04b3
 	}
ba04b3
 
ba04b3
-- 
ba04b3
1.8.3.1
ba04b3