diff mbox series

[libnftnl] chain: Don't print unset policy value in netlink debug

Message ID 20170907174127.1909-1-phil@nwl.cc
State Accepted
Delegated to: Pablo Neira
Headers show
Series [libnftnl] chain: Don't print unset policy value in netlink debug | expand

Commit Message

Phil Sutter Sept. 7, 2017, 5:41 p.m. UTC
The policy field was printed unconditionally, but if it wasn't set the
default value 0 was printed as 'policy drop' which is not correct.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 src/chain.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Comments

Pablo Neira Ayuso Sept. 8, 2017, 12:58 p.m. UTC | #1
On Thu, Sep 07, 2017 at 07:41:27PM +0200, Phil Sutter wrote:
> The policy field was printed unconditionally, but if it wasn't set the
> default value 0 was printed as 'policy drop' which is not correct.

Applied, thanks Phil.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox series

Patch

diff --git a/src/chain.c b/src/chain.c
index 29860c509a180..3190a775a0005 100644
--- a/src/chain.c
+++ b/src/chain.c
@@ -795,11 +795,19 @@  static int nftnl_chain_snprintf_default(char *buf, size_t size,
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	if (c->flags & (1 << NFTNL_CHAIN_HOOKNUM)) {
-		ret = snprintf(buf+offset, len,
-			       " type %s hook %s prio %d policy %s "
-			       "packets %"PRIu64" bytes %"PRIu64"",
+		ret = snprintf(buf+offset, len, " type %s hook %s prio %d",
 			       c->type, nftnl_hooknum2str(c->family, c->hooknum),
-			       c->prio, nftnl_verdict2str(c->policy),
+			       c->prio);
+		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
+
+		if (c->flags & (1 << NFTNL_CHAIN_POLICY)) {
+			ret = snprintf(buf+offset, len, " policy %s",
+				       nftnl_verdict2str(c->policy));
+			SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
+		}
+
+		ret = snprintf(buf+offset, len,
+			       " packets %"PRIu64" bytes %"PRIu64"",
 			       c->packets, c->bytes);
 		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);