You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

128 lines
4.0 KiB

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