summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2017-03-06 14:27:24 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2017-03-06 18:27:10 +0100
commit17b1c5dda5658ebf9df08cfa8b5c384286448a9b (patch)
tree1d9729dda99d2be8b06319fe2086f840bffc1414
parent1ebd1e974e95ea90389064265523840968f50859 (diff)
udata: add nftnl_udata_put_u32() and nftnl_udata_get_u32()
Add new helper function to put and to fetch tlv that comes with u32 payload. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--include/libnftnl/udata.h3
-rw-r--r--src/libnftnl.map2
-rw-r--r--src/udata.c15
3 files changed, 20 insertions, 0 deletions
diff --git a/include/libnftnl/udata.h b/include/libnftnl/udata.h
index d36cef7..e6f80f9 100644
--- a/include/libnftnl/udata.h
+++ b/include/libnftnl/udata.h
@@ -24,6 +24,8 @@ struct nftnl_udata *nftnl_udata_end(const struct nftnl_udata_buf *buf);
/* putters */
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_strz(struct nftnl_udata_buf *buf, uint8_t type,
const char *strz);
@@ -31,6 +33,7 @@ bool nftnl_udata_put_strz(struct nftnl_udata_buf *buf, uint8_t type,
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);
/* iterator */
struct nftnl_udata *nftnl_udata_next(const struct nftnl_udata *attr);
diff --git a/src/libnftnl.map b/src/libnftnl.map
index 4282367..4c08210 100644
--- a/src/libnftnl.map
+++ b/src/libnftnl.map
@@ -261,9 +261,11 @@ global:
nftnl_udata_end;
nftnl_udata_put;
nftnl_udata_put_strz;
+ nftnl_udata_put_u32;
nftnl_udata_type;
nftnl_udata_len;
nftnl_udata_get;
+ nftnl_udata_get_u32;
nftnl_udata_next;
nftnl_udata_parse;
diff --git a/src/udata.c b/src/udata.c
index 60c2f34..d679dd0 100644
--- a/src/udata.c
+++ b/src/udata.c
@@ -94,6 +94,13 @@ bool nftnl_udata_put_strz(struct nftnl_udata_buf *buf, uint8_t type,
}
EXPORT_SYMBOL(nftnl_udata_put_strz);
+bool nftnl_udata_put_u32(struct nftnl_udata_buf *buf, uint8_t type,
+ uint32_t data)
+{
+ return nftnl_udata_put(buf, type, sizeof(data), &data);
+}
+EXPORT_SYMBOL(nftnl_udata_put_u32);
+
uint8_t nftnl_udata_type(const struct nftnl_udata *attr)
{
return attr->type;
@@ -112,6 +119,14 @@ void *nftnl_udata_get(const struct nftnl_udata *attr)
}
EXPORT_SYMBOL(nftnl_udata_get);
+uint32_t nftnl_udata_get_u32(const struct nftnl_udata *attr)
+{
+ uint32_t *data = (uint32_t *)attr->value;
+
+ return *data;
+}
+EXPORT_SYMBOL(nftnl_udata_get_u32);
+
struct nftnl_udata *nftnl_udata_next(const struct nftnl_udata *attr)
{
return (struct nftnl_udata *)&attr->value[attr->len];