From 5048736e76e553b54b445dee488a6316468bce73 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Sat, 19 Dec 2020 02:01:23 +0100 Subject: expr/{masq,nat}: Don't print unused regs 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 --- src/expr/masq.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/expr/masq.c') diff --git a/src/expr/masq.c b/src/expr/masq.c index 622ba28..ea66fec 100644 --- a/src/expr/masq.c +++ b/src/expr/masq.c @@ -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)) { -- cgit v1.2.3