]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
expr/{masq,nat}: Don't print unused regs
authorPhil Sutter <phil@nwl.cc>
Sat, 19 Dec 2020 01:01:23 +0000 (02:01 +0100)
committerPhil Sutter <phil@nwl.cc>
Tue, 9 Mar 2021 13:23:13 +0000 (14:23 +0100)
No point in printing the unset register value (which is zero then).

Fixes: af0c182670837 ("expr: masq: Add support for port selection")
Signed-off-by: Phil Sutter <phil@nwl.cc>
src/expr/masq.c
src/expr/nat.c

index 622ba282ff1602e42d8d69dbdf98fd2f6edb114f..ea66fecdf2a7283ec70113d4b9f1b499a6575206 100644 (file)
@@ -138,9 +138,13 @@ static int nftnl_expr_masq_snprintf_default(char *buf, size_t len,
        int remain = len, offset = 0, ret = 0;
 
        if (e->flags & (1 << NFTNL_EXPR_MASQ_REG_PROTO_MIN)) {
-               ret = snprintf(buf, remain,
-                              "proto_min reg %u proto_max reg %u ",
-                              masq->sreg_proto_min, masq->sreg_proto_max);
+               ret = snprintf(buf + offset, remain, "proto_min reg %u ",
+                              masq->sreg_proto_min);
+               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
+       }
+       if (e->flags & (1 << NFTNL_EXPR_MASQ_REG_PROTO_MAX)) {
+               ret = snprintf(buf + offset, remain, "proto_max reg %u ",
+                              masq->sreg_proto_max);
                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
        }
        if (e->flags & (1 << NFTNL_EXPR_MASQ_FLAGS)) {
index 408521626d89266a94c1496c2d30b5b8f74d3007..91a1ae6c99a4331d10ffa37ec37964571d962c8d 100644 (file)
@@ -236,15 +236,25 @@ nftnl_expr_nat_snprintf_default(char *buf, size_t size,
 
        if (e->flags & (1 << NFTNL_EXPR_NAT_REG_ADDR_MIN)) {
                ret = snprintf(buf + offset, remain,
-                              "addr_min reg %u addr_max reg %u ",
-                              nat->sreg_addr_min, nat->sreg_addr_max);
+                              "addr_min reg %u ", nat->sreg_addr_min);
+               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
+       }
+
+       if (e->flags & (1 << NFTNL_EXPR_NAT_REG_ADDR_MAX)) {
+               ret = snprintf(buf + offset, remain,
+                              "addr_max reg %u ", nat->sreg_addr_max);
                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
        }
 
        if (e->flags & (1 << NFTNL_EXPR_NAT_REG_PROTO_MIN)) {
                ret = snprintf(buf + offset, remain,
-                              "proto_min reg %u proto_max reg %u ",
-                              nat->sreg_proto_min, nat->sreg_proto_max);
+                              "proto_min reg %u ", nat->sreg_proto_min);
+               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
+       }
+
+       if (e->flags & (1 << NFTNL_EXPR_NAT_REG_PROTO_MAX)) {
+               ret = snprintf(buf + offset, remain,
+                              "proto_max reg %u ", nat->sreg_proto_max);
                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
        }