Blame SOURCES/0045-xtables-monitor-fix-rule-printing.patch

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