diff mbox series

[libnftnl,2/7] set: Introduce NFTNL_SET_DESC_BYTEORDER

Message ID 20211124172242.11402-3-phil@nwl.cc
State Changes Requested
Delegated to: Pablo Neira
Headers show
Series Stabilize debug output on different endian systems | expand

Commit Message

Phil Sutter Nov. 24, 2021, 5:22 p.m. UTC
This attribute allows to specify byteorder of data stored in this set's
elements.

In general, elements make use of up to three nftnl_data_reg unions: one
for the key, one for the data (with maps) and one for key_end (with
concatenated ranges). Byteorder of key and key_end is always identical.

To represent byteorder of a data_reg, 16bits are needed: each marking
whether the field at same position in 'val' array is network or host
byteorder. So for storing elements' data byteorder, a single 32bit
variable is sufficient.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 include/libnftnl/set.h | 1 +
 include/set.h          | 1 +
 src/set.c              | 8 ++++++++
 3 files changed, 10 insertions(+)
diff mbox series

Patch

diff --git a/include/libnftnl/set.h b/include/libnftnl/set.h
index e2e5795aa9b40..1ffb6c415260d 100644
--- a/include/libnftnl/set.h
+++ b/include/libnftnl/set.h
@@ -32,6 +32,7 @@  enum nftnl_set_attr {
 	NFTNL_SET_DESC_CONCAT,
 	NFTNL_SET_EXPR,
 	NFTNL_SET_EXPRESSIONS,
+	NFTNL_SET_DESC_BYTEORDER,
 	__NFTNL_SET_MAX
 };
 #define NFTNL_SET_MAX (__NFTNL_SET_MAX - 1)
diff --git a/include/set.h b/include/set.h
index 55018b6b9ba95..816bd24faf651 100644
--- a/include/set.h
+++ b/include/set.h
@@ -25,6 +25,7 @@  struct nftnl_set {
 	enum nft_set_policies	policy;
 	struct {
 		uint32_t	size;
+		uint32_t	byteorder;
 		uint8_t		field_len[NFT_REG32_COUNT];
 		uint8_t		field_count;
 	} desc;
diff --git a/src/set.c b/src/set.c
index c46f8277ff687..651eaf5503dee 100644
--- a/src/set.c
+++ b/src/set.c
@@ -99,6 +99,7 @@  void nftnl_set_unset(struct nftnl_set *s, uint16_t attr)
 	case NFTNL_SET_DESC_CONCAT:
 	case NFTNL_SET_TIMEOUT:
 	case NFTNL_SET_GC_INTERVAL:
+	case NFTNL_SET_DESC_BYTEORDER:
 		break;
 	case NFTNL_SET_USERDATA:
 		xfree(s->user.data);
@@ -128,6 +129,7 @@  static uint32_t nftnl_set_validate[NFTNL_SET_MAX + 1] = {
 	[NFTNL_SET_DESC_SIZE]	= sizeof(uint32_t),
 	[NFTNL_SET_TIMEOUT]		= sizeof(uint64_t),
 	[NFTNL_SET_GC_INTERVAL]	= sizeof(uint32_t),
+	[NFTNL_SET_DESC_BYTEORDER]	= sizeof(uint32_t),
 };
 
 EXPORT_SYMBOL(nftnl_set_set_data);
@@ -216,6 +218,9 @@  int nftnl_set_set_data(struct nftnl_set *s, uint16_t attr, const void *data,
 		expr = (void *)data;
 		list_add(&expr->head, &s->expr_list);
 		break;
+	case NFTNL_SET_DESC_BYTEORDER:
+		s->desc.byteorder = *(uint32_t *)data;
+		break;
 	}
 	s->flags |= (1 << attr);
 	return 0;
@@ -310,6 +315,9 @@  const void *nftnl_set_get_data(const struct nftnl_set *s, uint16_t attr,
 		list_for_each_entry(expr, &s->expr_list, head)
 			break;
 		return expr;
+	case NFTNL_SET_DESC_BYTEORDER:
+		*data_len = sizeof(uint32_t);
+		return &s->desc.byteorder;
 	}
 	return NULL;
 }