netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH libnftnl 1/2] expr: masq: revisit _snprintf()
@ 2020-03-20 12:47 Pablo Neira Ayuso
  2020-03-20 12:47 ` [PATCH libnftnl 2/2] expr: nat: snprint flags in hexadecimal Pablo Neira Ayuso
  0 siblings, 1 reply; 2+ messages in thread
From: Pablo Neira Ayuso @ 2020-03-20 12:47 UTC (permalink / raw)
  To: netfilter-devel

Print combination of registers and flags.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 src/expr/masq.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/expr/masq.c b/src/expr/masq.c
index f6f3ceb6e8da..622ba282ff16 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,
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH libnftnl 2/2] expr: nat: snprint flags in hexadecimal
  2020-03-20 12:47 [PATCH libnftnl 1/2] expr: masq: revisit _snprintf() Pablo Neira Ayuso
@ 2020-03-20 12:47 ` Pablo Neira Ayuso
  0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2020-03-20 12:47 UTC (permalink / raw)
  To: netfilter-devel

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 src/expr/nat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/expr/nat.c b/src/expr/nat.c
index 6b7d50ea801a..408521626d89 100644
--- a/src/expr/nat.c
+++ b/src/expr/nat.c
@@ -249,7 +249,7 @@ nftnl_expr_nat_snprintf_default(char *buf, size_t size,
 	}
 
 	if (e->flags & (1 << NFTNL_EXPR_NAT_FLAGS)) {
-		ret = snprintf(buf + offset, remain, "flags %u", nat->flags);
+		ret = snprintf(buf + offset, remain, "flags 0x%x ", nat->flags);
 		SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 	}
 
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-03-20 12:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-20 12:47 [PATCH libnftnl 1/2] expr: masq: revisit _snprintf() Pablo Neira Ayuso
2020-03-20 12:47 ` [PATCH libnftnl 2/2] expr: nat: snprint flags in hexadecimal Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).