summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2020-02-18 14:09:23 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2020-02-19 18:26:42 +0100
commitec3622b075300727d8349d7db0b116a41981b703 (patch)
tree22e99ed7807af81d5091eaf888def5ef70606999
parent629ee38dca48651bc8c0eedf2f3a0066a6c0aa5b (diff)
src: add nftnl_*_{get,set}_array()
The original intention in eb58f53372e7 ("src: add flowtable support") was to introduce this helper function. Add helper to set and to get array of strings. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Acked-by: Phil Sutter <phil@nwl.cc>
-rw-r--r--include/libnftnl/chain.h2
-rw-r--r--include/libnftnl/flowtable.h4
-rw-r--r--src/chain.c18
-rw-r--r--src/flowtable.c18
-rw-r--r--src/libnftnl.map4
5 files changed, 44 insertions, 2 deletions
diff --git a/include/libnftnl/chain.h b/include/libnftnl/chain.h
index 33d04e1..2eb22cc 100644
--- a/include/libnftnl/chain.h
+++ b/include/libnftnl/chain.h
@@ -46,6 +46,7 @@ void nftnl_chain_set_u32(struct nftnl_chain *t, uint16_t attr, uint32_t data);
void nftnl_chain_set_s32(struct nftnl_chain *t, uint16_t attr, int32_t data);
void nftnl_chain_set_u64(struct nftnl_chain *t, uint16_t attr, uint64_t data);
int nftnl_chain_set_str(struct nftnl_chain *t, uint16_t attr, const char *str);
+int nftnl_chain_set_array(struct nftnl_chain *t, uint16_t attr, const char **data);
const void *nftnl_chain_get(const struct nftnl_chain *c, uint16_t attr);
const void *nftnl_chain_get_data(const struct nftnl_chain *c, uint16_t attr,
@@ -55,6 +56,7 @@ uint8_t nftnl_chain_get_u8(const struct nftnl_chain *c, uint16_t attr);
uint32_t nftnl_chain_get_u32(const struct nftnl_chain *c, uint16_t attr);
int32_t nftnl_chain_get_s32(const struct nftnl_chain *c, uint16_t attr);
uint64_t nftnl_chain_get_u64(const struct nftnl_chain *c, uint16_t attr);
+const char *const *nftnl_chain_get_array(const struct nftnl_chain *c, uint16_t attr);
void nftnl_chain_rule_add(struct nftnl_rule *rule, struct nftnl_chain *c);
void nftnl_chain_rule_del(struct nftnl_rule *rule);
diff --git a/include/libnftnl/flowtable.h b/include/libnftnl/flowtable.h
index bdff114..168f833 100644
--- a/include/libnftnl/flowtable.h
+++ b/include/libnftnl/flowtable.h
@@ -41,7 +41,7 @@ void nftnl_flowtable_set_u32(struct nftnl_flowtable *t, uint16_t attr, uint32_t
void nftnl_flowtable_set_s32(struct nftnl_flowtable *t, uint16_t attr, int32_t data);
void nftnl_flowtable_set_u64(struct nftnl_flowtable *t, uint16_t attr, uint64_t data);
int nftnl_flowtable_set_str(struct nftnl_flowtable *t, uint16_t attr, const char *str);
-void nftnl_flowtable_set_array(struct nftnl_flowtable *t, uint16_t attr, const char **data);
+int nftnl_flowtable_set_array(struct nftnl_flowtable *t, uint16_t attr, const char **data);
const void *nftnl_flowtable_get(const struct nftnl_flowtable *c, uint16_t attr);
const void *nftnl_flowtable_get_data(const struct nftnl_flowtable *c, uint16_t attr,
@@ -50,7 +50,7 @@ const char *nftnl_flowtable_get_str(const struct nftnl_flowtable *c, uint16_t at
uint32_t nftnl_flowtable_get_u32(const struct nftnl_flowtable *c, uint16_t attr);
int32_t nftnl_flowtable_get_s32(const struct nftnl_flowtable *c, uint16_t attr);
uint64_t nftnl_flowtable_get_u64(const struct nftnl_flowtable *c, uint16_t attr);
-const char **nftnl_flowtable_get_array(const struct nftnl_flowtable *t, uint16_t attr);
+const char *const *nftnl_flowtable_get_array(const struct nftnl_flowtable *t, uint16_t attr);
struct nlmsghdr;
diff --git a/src/chain.c b/src/chain.c
index 94a9e43..c43ba22 100644
--- a/src/chain.c
+++ b/src/chain.c
@@ -319,6 +319,13 @@ int nftnl_chain_set_str(struct nftnl_chain *c, uint16_t attr, const char *str)
return nftnl_chain_set_data(c, attr, str, strlen(str) + 1);
}
+EXPORT_SYMBOL(nftnl_chain_set_array);
+int nftnl_chain_set_array(struct nftnl_chain *c, uint16_t attr,
+ const char **data)
+{
+ return nftnl_chain_set_data(c, attr, data, 0);
+}
+
EXPORT_SYMBOL(nftnl_chain_get_data);
const void *nftnl_chain_get_data(const struct nftnl_chain *c, uint16_t attr,
uint32_t *data_len)
@@ -427,6 +434,17 @@ uint8_t nftnl_chain_get_u8(const struct nftnl_chain *c, uint16_t attr)
return val ? *val : 0;
}
+EXPORT_SYMBOL(nftnl_chain_get_array);
+const char *const *nftnl_chain_get_array(const struct nftnl_chain *c, uint16_t attr)
+{
+ uint32_t data_len;
+ const char * const *val = nftnl_chain_get_data(c, attr, &data_len);
+
+ nftnl_assert(val, attr, attr == NFTNL_CHAIN_DEVICES);
+
+ return val;
+}
+
EXPORT_SYMBOL(nftnl_chain_nlmsg_build_payload);
void nftnl_chain_nlmsg_build_payload(struct nlmsghdr *nlh, const struct nftnl_chain *c)
{
diff --git a/src/flowtable.c b/src/flowtable.c
index 635322d..19e2882 100644
--- a/src/flowtable.c
+++ b/src/flowtable.c
@@ -206,6 +206,13 @@ void nftnl_flowtable_set_u64(struct nftnl_flowtable *c, uint16_t attr, uint64_t
nftnl_flowtable_set_data(c, attr, &data, sizeof(uint64_t));
}
+EXPORT_SYMBOL(nftnl_flowtable_set_array);
+int nftnl_flowtable_set_array(struct nftnl_flowtable *c, uint16_t attr,
+ const char **data)
+{
+ return nftnl_flowtable_set_data(c, attr, data, 0);
+}
+
EXPORT_SYMBOL(nftnl_flowtable_get_data);
const void *nftnl_flowtable_get_data(const struct nftnl_flowtable *c,
uint16_t attr, uint32_t *data_len)
@@ -291,6 +298,17 @@ int32_t nftnl_flowtable_get_s32(const struct nftnl_flowtable *c, uint16_t attr)
return val ? *val : 0;
}
+EXPORT_SYMBOL(nftnl_flowtable_get_array);
+const char *const *nftnl_flowtable_get_array(const struct nftnl_flowtable *c, uint16_t attr)
+{
+ uint32_t data_len;
+ const char * const *val = nftnl_flowtable_get_data(c, attr, &data_len);
+
+ nftnl_assert(val, attr, attr == NFTNL_FLOWTABLE_DEVICES);
+
+ return val;
+}
+
EXPORT_SYMBOL(nftnl_flowtable_nlmsg_build_payload);
void nftnl_flowtable_nlmsg_build_payload(struct nlmsghdr *nlh,
const struct nftnl_flowtable *c)
diff --git a/src/libnftnl.map b/src/libnftnl.map
index 5ba8d99..f62640f 100644
--- a/src/libnftnl.map
+++ b/src/libnftnl.map
@@ -363,4 +363,8 @@ LIBNFTNL_13 {
LIBNFTNL_14 {
nftnl_udata_nest_start;
nftnl_udata_nest_end;
+ nftnl_chain_set_array;
+ nftnl_chain_get_array;
+ nftnl_flowtable_set_array;
+ nftnl_flowtable_get_array;
} LIBNFTNL_13;