@@ -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)
@@ -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;
@@ -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;
}
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(+)