|
|
ea9c6b |
From 0b886ea23e8473e692bdf20ecf4985f44408a132 Mon Sep 17 00:00:00 2001
|
|
|
ea9c6b |
From: Florian Westphal <fw@strlen.de>
|
|
|
ea9c6b |
Date: Sat, 12 Dec 2020 16:15:32 +0100
|
|
|
ea9c6b |
Subject: [PATCH] xtables-monitor: fix rule printing
|
|
|
ea9c6b |
|
|
|
ea9c6b |
trace_print_rule does a rule dump. This prints unrelated rules
|
|
|
ea9c6b |
in the same chain. Instead the function should only request the
|
|
|
ea9c6b |
specific handle.
|
|
|
ea9c6b |
|
|
|
ea9c6b |
Furthermore, flush output buffer afterwards so this plays nice when
|
|
|
ea9c6b |
output isn't a terminal.
|
|
|
ea9c6b |
|
|
|
ea9c6b |
Signed-off-by: Florian Westphal <fw@strlen.de>
|
|
|
ea9c6b |
(cherry picked from commit 07af4da52ab3002c9cb510863b4eb7aaca4fb43b)
|
|
|
ea9c6b |
Signed-off-by: Phil Sutter <psutter@redhat.com>
|
|
|
ea9c6b |
---
|
|
|
ea9c6b |
iptables/xtables-monitor.c | 32 +++++++++++++++-----------------
|
|
|
ea9c6b |
1 file changed, 15 insertions(+), 17 deletions(-)
|
|
|
ea9c6b |
|
|
|
ea9c6b |
diff --git a/iptables/xtables-monitor.c b/iptables/xtables-monitor.c
|
|
|
ea9c6b |
index 92962a2a95f48..43b9064c3d30e 100644
|
|
|
ea9c6b |
--- a/iptables/xtables-monitor.c
|
|
|
ea9c6b |
+++ b/iptables/xtables-monitor.c
|
|
|
ea9c6b |
@@ -227,12 +227,12 @@ static void trace_print_rule(const struct nftnl_trace *nlt, struct cb_arg *args)
|
|
|
ea9c6b |
exit(EXIT_FAILURE);
|
|
|
ea9c6b |
}
|
|
|
ea9c6b |
|
|
|
ea9c6b |
- nlh = nftnl_chain_nlmsg_build_hdr(buf, NFT_MSG_GETRULE, family, NLM_F_DUMP, 0);
|
|
|
ea9c6b |
+ nlh = nftnl_chain_nlmsg_build_hdr(buf, NFT_MSG_GETRULE, family, 0, 0);
|
|
|
ea9c6b |
|
|
|
ea9c6b |
nftnl_rule_set_u32(r, NFTNL_RULE_FAMILY, family);
|
|
|
ea9c6b |
nftnl_rule_set_str(r, NFTNL_RULE_CHAIN, chain);
|
|
|
ea9c6b |
nftnl_rule_set_str(r, NFTNL_RULE_TABLE, table);
|
|
|
ea9c6b |
- nftnl_rule_set_u64(r, NFTNL_RULE_POSITION, handle);
|
|
|
ea9c6b |
+ nftnl_rule_set_u64(r, NFTNL_RULE_HANDLE, handle);
|
|
|
ea9c6b |
nftnl_rule_nlmsg_build_payload(nlh, r);
|
|
|
ea9c6b |
nftnl_rule_free(r);
|
|
|
ea9c6b |
|
|
|
ea9c6b |
@@ -248,24 +248,21 @@ static void trace_print_rule(const struct nftnl_trace *nlt, struct cb_arg *args)
|
|
|
ea9c6b |
}
|
|
|
ea9c6b |
|
|
|
ea9c6b |
portid = mnl_socket_get_portid(nl);
|
|
|
ea9c6b |
- if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
|
|
|
ea9c6b |
- perror("mnl_socket_send");
|
|
|
ea9c6b |
- exit(EXIT_FAILURE);
|
|
|
ea9c6b |
- }
|
|
|
ea9c6b |
+ if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
|
|
|
ea9c6b |
+ perror("mnl_socket_send");
|
|
|
ea9c6b |
+ exit(EXIT_FAILURE);
|
|
|
ea9c6b |
+ }
|
|
|
ea9c6b |
|
|
|
ea9c6b |
ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
|
|
|
ea9c6b |
- while (ret > 0) {
|
|
|
ea9c6b |
+ if (ret > 0) {
|
|
|
ea9c6b |
args->is_event = false;
|
|
|
ea9c6b |
- ret = mnl_cb_run(buf, ret, 0, portid, rule_cb, args);
|
|
|
ea9c6b |
- if (ret <= 0)
|
|
|
ea9c6b |
- break;
|
|
|
ea9c6b |
- ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
|
|
|
ea9c6b |
- }
|
|
|
ea9c6b |
- if (ret == -1) {
|
|
|
ea9c6b |
- perror("error");
|
|
|
ea9c6b |
- exit(EXIT_FAILURE);
|
|
|
ea9c6b |
- }
|
|
|
ea9c6b |
- mnl_socket_close(nl);
|
|
|
ea9c6b |
+ ret = mnl_cb_run(buf, ret, 0, portid, rule_cb, args);
|
|
|
ea9c6b |
+ }
|
|
|
ea9c6b |
+ if (ret == -1) {
|
|
|
ea9c6b |
+ perror("error");
|
|
|
ea9c6b |
+ exit(EXIT_FAILURE);
|
|
|
ea9c6b |
+ }
|
|
|
ea9c6b |
+ mnl_socket_close(nl);
|
|
|
ea9c6b |
}
|
|
|
ea9c6b |
|
|
|
ea9c6b |
static void trace_print_packet(const struct nftnl_trace *nlt, struct cb_arg *args)
|
|
|
ea9c6b |
@@ -531,6 +528,7 @@ static int trace_cb(const struct nlmsghdr *nlh, struct cb_arg *arg)
|
|
|
ea9c6b |
err_free:
|
|
|
ea9c6b |
nftnl_trace_free(nlt);
|
|
|
ea9c6b |
err:
|
|
|
ea9c6b |
+ fflush(stdout);
|
|
|
ea9c6b |
return MNL_CB_OK;
|
|
|
ea9c6b |
}
|
|
|
ea9c6b |
|
|
|
ea9c6b |
--
|
|
|
ea9c6b |
2.31.1
|
|
|
ea9c6b |
|