All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH libnftnl 1/2] expr: masq: revisit _snprintf()
Date: Fri, 20 Mar 2020 13:47:23 +0100	[thread overview]
Message-ID: <20200320124724.407366-1-pablo@netfilter.org> (raw)

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


             reply	other threads:[~2020-03-20 12:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-20 12:47 Pablo Neira Ayuso [this message]
2020-03-20 12:47 ` [PATCH libnftnl 2/2] expr: nat: snprint flags in hexadecimal Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200320124724.407366-1-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.