]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
chain: Don't print unset policy value in netlink debug
authorPhil Sutter <phil@nwl.cc>
Thu, 7 Sep 2017 17:41:27 +0000 (19:41 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 8 Sep 2017 12:57:49 +0000 (14:57 +0200)
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>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/chain.c

index 29860c509a1807a573099632921e8e4355e4cae5..e5b9fe3755dab7df055a0641e3ffe9ef7f958419 100644 (file)
@@ -795,16 +795,24 @@ 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);
 
                if (c->flags & (1 << NFTNL_CHAIN_DEV)) {
-                       ret = snprintf(buf+offset, len, " dev %s ", c->dev);
+                       ret = snprintf(buf + offset, len, " dev %s ", c->dev);
                        SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
                }
        }