netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: [libnftnl PATCH 4/7] data_reg: Support varying byteorder in concat data
Date: Wed, 24 Nov 2021 18:22:39 +0100	[thread overview]
Message-ID: <20211124172242.11402-5-phil@nwl.cc> (raw)
In-Reply-To: <20211124172242.11402-1-phil@nwl.cc>

Byteorder may be different in each field of reg->val array. Pass a 16bit
value where each bit indicates the field value at same offset is in
network byte order.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 src/expr/data_reg.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/expr/data_reg.c b/src/expr/data_reg.c
index 789958ea66c0d..289443b47f9d6 100644
--- a/src/expr/data_reg.c
+++ b/src/expr/data_reg.c
@@ -27,8 +27,7 @@
 static int
 nftnl_data_reg_value_snprintf_default(char *buf, size_t remain,
 				      const union nftnl_data_reg *reg,
-				      uint32_t flags,
-				      enum nftnl_byteorder byteorder)
+				      uint32_t flags, uint16_t byteorder_bits)
 {
 	const char *pfx = flags & DATA_F_NOPFX ? "" : "0x";
 	int offset = 0, ret, i;
@@ -37,7 +36,7 @@ nftnl_data_reg_value_snprintf_default(char *buf, size_t remain,
 
 
 	for (i = 0; i < div_round_up(reg->len, sizeof(uint32_t)); i++) {
-		if (byteorder == NFTNL_BYTEORDER_NETWORK)
+		if (byteorder_bits & (1 << i))
 			value = ntohl(reg->val[i]);
 		else
 			value = reg->val[i];
@@ -72,11 +71,13 @@ int nftnl_data_reg_snprintf(char *buf, size_t size,
 			    uint32_t flags, int reg_type,
 			    enum nftnl_byteorder byteorder)
 {
+	uint16_t byteorder_bits = byteorder == NFTNL_BYTEORDER_NETWORK ? -1 : 0;
+
 	switch(reg_type) {
 	case DATA_VALUE:
 		return nftnl_data_reg_value_snprintf_default(buf, size,
 							     reg, flags,
-							     byteorder);
+							     byteorder_bits);
 	case DATA_VERDICT:
 	case DATA_CHAIN:
 		return nftnl_data_reg_verdict_snprintf_def(buf, size,
-- 
2.33.0


  parent reply	other threads:[~2021-11-24 17:23 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-24 17:22 [libnftnl PATCH 0/7] Stabilize debug output on different endian systems Phil Sutter
2021-11-24 17:22 ` [libnftnl PATCH v2 1/7] src: add infrastructure to infer byteorder from keys Phil Sutter
2021-12-12 17:12   ` Jeremy Sowden
2021-11-24 17:22 ` [libnftnl PATCH 2/7] set: Introduce NFTNL_SET_DESC_BYTEORDER Phil Sutter
2021-11-24 17:22 ` [libnftnl PATCH 3/7] set: Introduce NFTNL_SET_DESC_CONCAT_DATA Phil Sutter
2021-11-30 13:46   ` Pablo Neira Ayuso
2021-11-30 17:45     ` Phil Sutter
2022-01-05 16:17       ` Pablo Neira Ayuso
2022-01-06 13:10         ` Phil Sutter
2022-01-20  0:08           ` Pablo Neira Ayuso
2021-11-24 17:22 ` Phil Sutter [this message]
2021-11-24 17:22 ` [libnftnl PATCH 5/7] data_reg: Respect each value's size Phil Sutter
2021-11-24 17:22 ` [libnftnl PATCH 6/7] include: Introduce and publish struct nftnl_set_desc Phil Sutter
2021-11-24 17:22 ` [libnftnl PATCH 7/7] set: Introduce nftnl_set_elem_snprintf_desc() Phil Sutter

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=20211124172242.11402-5-phil@nwl.cc \
    --to=phil@nwl.cc \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.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 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).