diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2020-03-20 13:40:57 +0100 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2020-03-20 13:46:56 +0100 |
commit | ff9286876571c1a7a2c75323a7e8a853af6884ea (patch) | |
tree | 2e4f6137e9ee9d2cc1365ce36edf22d4581c9c71 | |
parent | c76d36a1a2805c49bf5c9ceeedb0d86f6c06e1eb (diff) |
expr: masq: revisit _snprintf()
Print combination of registers and flags.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r-- | src/expr/masq.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/expr/masq.c b/src/expr/masq.c index f6f3ceb..622ba28 100644 --- a/src/expr/masq.c +++ b/src/expr/masq.c @@ -135,16 +135,20 @@ static int nftnl_expr_masq_snprintf_default(char *buf, size_t len, const struct nftnl_expr *e) { struct nftnl_expr_masq *masq = nftnl_expr_data(e); + int remain = len, offset = 0, ret = 0; - if (e->flags & (1 << NFTNL_EXPR_MASQ_FLAGS)) - return snprintf(buf, len, "flags 0x%x ", masq->flags); if (e->flags & (1 << NFTNL_EXPR_MASQ_REG_PROTO_MIN)) { - return snprintf(buf, len, - "proto_min reg %u proto_max reg %u ", - masq->sreg_proto_min, masq->sreg_proto_max); + ret = snprintf(buf, remain, + "proto_min reg %u proto_max reg %u ", + masq->sreg_proto_min, masq->sreg_proto_max); + SNPRINTF_BUFFER_SIZE(ret, remain, offset); + } + if (e->flags & (1 << NFTNL_EXPR_MASQ_FLAGS)) { + ret = snprintf(buf + offset, remain, "flags 0x%x ", masq->flags); + SNPRINTF_BUFFER_SIZE(ret, remain, offset); } - return 0; + return offset; } static int nftnl_expr_masq_snprintf(char *buf, size_t len, uint32_t type, |