This patch extends userdata to store a unsigned 64-bit cookie value. Signed-off-by: Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx> --- include/libnftnl/udata.h | 6 ++++++ src/libnftnl.map | 5 +++++ src/udata.c | 17 +++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/include/libnftnl/udata.h b/include/libnftnl/udata.h index 661493b48618..2c846978f5c3 100644 --- a/include/libnftnl/udata.h +++ b/include/libnftnl/udata.h @@ -12,6 +12,7 @@ extern "C" { enum nftnl_udata_rule_types { NFTNL_UDATA_RULE_COMMENT, NFTNL_UDATA_RULE_EBTABLES_POLICY, + NFTNL_UDATA_RULE_COOKIE, __NFTNL_UDATA_RULE_MAX }; #define NFTNL_UDATA_RULE_MAX (__NFTNL_UDATA_RULE_MAX - 1) @@ -26,6 +27,7 @@ enum nftnl_udata_set_types { NFTNL_UDATA_SET_DATA_TYPEOF, NFTNL_UDATA_SET_EXPR, NFTNL_UDATA_SET_DATA_INTERVAL, + NFTNL_UDATA_SET_COOKIE, __NFTNL_UDATA_SET_MAX }; #define NFTNL_UDATA_SET_MAX (__NFTNL_UDATA_SET_MAX - 1) @@ -40,6 +42,7 @@ enum { enum nftnl_udata_set_elem_types { NFTNL_UDATA_SET_ELEM_COMMENT, NFTNL_UDATA_SET_ELEM_FLAGS, + NFTNL_UDATA_SET_ELEM_COOKIE, __NFTNL_UDATA_SET_ELEM_MAX }; #define NFTNL_UDATA_SET_ELEM_MAX (__NFTNL_UDATA_SET_ELEM_MAX - 1) @@ -74,6 +77,8 @@ bool nftnl_udata_put(struct nftnl_udata_buf *buf, uint8_t type, uint32_t len, const void *value); bool nftnl_udata_put_u32(struct nftnl_udata_buf *buf, uint8_t type, uint32_t data); +bool nftnl_udata_put_u64(struct nftnl_udata_buf *buf, uint8_t type, + uint64_t data); bool nftnl_udata_put_strz(struct nftnl_udata_buf *buf, uint8_t type, const char *strz); @@ -87,6 +92,7 @@ uint8_t nftnl_udata_type(const struct nftnl_udata *attr); uint8_t nftnl_udata_len(const struct nftnl_udata *attr); void *nftnl_udata_get(const struct nftnl_udata *attr); uint32_t nftnl_udata_get_u32(const struct nftnl_udata *attr); +uint64_t nftnl_udata_get_u64(const struct nftnl_udata *attr); /* iterator */ struct nftnl_udata *nftnl_udata_next(const struct nftnl_udata *attr); diff --git a/src/libnftnl.map b/src/libnftnl.map index f62640f83e6b..cbb5f0ae54c5 100644 --- a/src/libnftnl.map +++ b/src/libnftnl.map @@ -368,3 +368,8 @@ LIBNFTNL_14 { nftnl_flowtable_set_array; nftnl_flowtable_get_array; } LIBNFTNL_13; + +LIBNFTNL_15 { + nftnl_udata_get_u64; + nftnl_udata_put_u64; +} LIBNFTNL_14; diff --git a/src/udata.c b/src/udata.c index 0cc3520ccede..a257663089e1 100644 --- a/src/udata.c +++ b/src/udata.c @@ -101,6 +101,13 @@ bool nftnl_udata_put_u32(struct nftnl_udata_buf *buf, uint8_t type, return nftnl_udata_put(buf, type, sizeof(data), &data); } +EXPORT_SYMBOL(nftnl_udata_put_u64); +bool nftnl_udata_put_u64(struct nftnl_udata_buf *buf, uint8_t type, + uint64_t data) +{ + return nftnl_udata_put(buf, type, sizeof(data), &data); +} + EXPORT_SYMBOL(nftnl_udata_type); uint8_t nftnl_udata_type(const struct nftnl_udata *attr) { @@ -129,6 +136,16 @@ uint32_t nftnl_udata_get_u32(const struct nftnl_udata *attr) return data; } +EXPORT_SYMBOL(nftnl_udata_get_u64); +uint64_t nftnl_udata_get_u64(const struct nftnl_udata *attr) +{ + uint64_t data; + + memcpy(&data, attr->value, sizeof(data)); + + return data; +} + EXPORT_SYMBOL(nftnl_udata_next); struct nftnl_udata *nftnl_udata_next(const struct nftnl_udata *attr) { -- 2.20.1