From: Ana Rey <anarey@gmail.com>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH] include: table: chain: added set and get for u8 values in chain and table.
Date: Tue, 19 Nov 2013 13:01:56 +0100 [thread overview]
Message-ID: <1384862516-3518-1-git-send-email-anarey@gmail.com> (raw)
I need it to allocate and show some values for chain and table.
I missed it doing the tests of libnftables.
---
include/libnftables/chain.h | 2 ++
include/libnftables/table.h | 2 ++
src/chain.c | 13 +++++++++++++
src/libnftables.map | 4 ++++
src/table.c | 13 +++++++++++++
5 files changed, 34 insertions(+)
diff --git a/include/libnftables/chain.h b/include/libnftables/chain.h
index 28f837f..a642b83 100644
--- a/include/libnftables/chain.h
+++ b/include/libnftables/chain.h
@@ -35,6 +35,7 @@ enum {
bool nft_chain_attr_is_set(const struct nft_chain *c, uint16_t attr);
void nft_chain_attr_unset(struct nft_chain *c, uint16_t attr);
void nft_chain_attr_set(struct nft_chain *t, uint16_t attr, const void *data);
+void nft_chain_attr_set_u8(struct nft_chain *t, uint16_t attr, uint8_t data);
void nft_chain_attr_set_u32(struct nft_chain *t, uint16_t attr, uint32_t data);
void nft_chain_attr_set_s32(struct nft_chain *t, uint16_t attr, int32_t data);
void nft_chain_attr_set_u64(struct nft_chain *t, uint16_t attr, uint64_t data);
@@ -42,6 +43,7 @@ void nft_chain_attr_set_str(struct nft_chain *t, uint16_t attr, const char *str)
const void *nft_chain_attr_get(struct nft_chain *c, uint16_t attr);
const char *nft_chain_attr_get_str(struct nft_chain *c, uint16_t attr);
+uint8_t nft_chain_attr_get_u8(struct nft_chain *c, uint16_t attr);
uint32_t nft_chain_attr_get_u32(struct nft_chain *c, uint16_t attr);
int32_t nft_chain_attr_get_s32(struct nft_chain *c, uint16_t attr);
uint64_t nft_chain_attr_get_u64(struct nft_chain *c, uint16_t attr);
diff --git a/include/libnftables/table.h b/include/libnftables/table.h
index 63a737e..9b0d866 100644
--- a/include/libnftables/table.h
+++ b/include/libnftables/table.h
@@ -28,8 +28,10 @@ void nft_table_attr_unset(struct nft_table *t, uint16_t attr);
void nft_table_attr_set(struct nft_table *t, uint16_t attr, const void *data);
const void *nft_table_attr_get(struct nft_table *t, uint16_t attr);
+void nft_table_attr_set_u8(struct nft_table *t, uint16_t attr, uint8_t data);
void nft_table_attr_set_u32(struct nft_table *t, uint16_t attr, uint32_t data);
void nft_table_attr_set_str(struct nft_table *t, uint16_t attr, const char *str);
+uint8_t nft_table_attr_get_u8(struct nft_table *t, uint16_t attr);
uint32_t nft_table_attr_get_u32(struct nft_table *t, uint16_t attr);
const char *nft_table_attr_get_str(struct nft_table *t, uint16_t attr);
diff --git a/src/chain.c b/src/chain.c
index a58999d..0145d32 100644
--- a/src/chain.c
+++ b/src/chain.c
@@ -206,6 +206,12 @@ void nft_chain_attr_set_u64(struct nft_chain *c, uint16_t attr, uint64_t data)
}
EXPORT_SYMBOL(nft_chain_attr_set_u64);
+void nft_chain_attr_set_u8(struct nft_chain *c, uint16_t attr, uint8_t data)
+{
+ nft_chain_attr_set(c, attr, &data);
+}
+EXPORT_SYMBOL(nft_chain_attr_set_u8);
+
void nft_chain_attr_set_str(struct nft_chain *c, uint16_t attr, const char *str)
{
nft_chain_attr_set(c, attr, str);
@@ -272,6 +278,13 @@ uint64_t nft_chain_attr_get_u64(struct nft_chain *c, uint16_t attr)
}
EXPORT_SYMBOL(nft_chain_attr_get_u64);
+uint8_t nft_chain_attr_get_u8(struct nft_chain *c, uint16_t attr)
+{
+ const uint8_t *val = nft_chain_attr_get(c, attr);
+ return val ? *val : 0;
+}
+EXPORT_SYMBOL(nft_chain_attr_get_u8);
+
struct nlmsghdr *
nft_chain_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family,
uint16_t type, uint32_t seq)
diff --git a/src/libnftables.map b/src/libnftables.map
index aa47714..3bdfeda 100644
--- a/src/libnftables.map
+++ b/src/libnftables.map
@@ -6,8 +6,10 @@ global:
nft_table_attr_unset;
nft_table_attr_set;
nft_table_attr_get;
+ nft_table_attr_set_u8;
nft_table_attr_set_u32;
nft_table_attr_set_str;
+ nft_table_attr_get_u8;
nft_table_attr_get_u32;
nft_table_attr_get_str;
nft_table_parse;
@@ -32,11 +34,13 @@ global:
nft_chain_attr_is_set;
nft_chain_attr_unset;
nft_chain_attr_set;
+ nft_chain_attr_set_u8;
nft_chain_attr_set_u32;
nft_chain_attr_set_s32;
nft_chain_attr_set_u64;
nft_chain_attr_set_str;
nft_chain_attr_get;
+ nft_chain_attr_get_u8;
nft_chain_attr_get_u32;
nft_chain_attr_get_s32;
nft_chain_attr_get_u64;
diff --git a/src/table.c b/src/table.c
index fe37f90..cf24cae 100644
--- a/src/table.c
+++ b/src/table.c
@@ -103,6 +103,12 @@ void nft_table_attr_set_u32(struct nft_table *t, uint16_t attr, uint32_t val)
}
EXPORT_SYMBOL(nft_table_attr_set_u32);
+void nft_table_attr_set_u8(struct nft_table *t, uint16_t attr, uint8_t val)
+{
+ nft_table_attr_set(t, attr, &val);
+}
+EXPORT_SYMBOL(nft_table_attr_set_u8);
+
void nft_table_attr_set_str(struct nft_table *t, uint16_t attr, const char *str)
{
nft_table_attr_set(t, attr, str);
@@ -133,6 +139,13 @@ uint32_t nft_table_attr_get_u32(struct nft_table *t, uint16_t attr)
}
EXPORT_SYMBOL(nft_table_attr_get_u32);
+uint8_t nft_table_attr_get_u8(struct nft_table *t, uint16_t attr)
+{
+ const void *ret = nft_table_attr_get(t, attr);
+ return ret == NULL ? 0 : *((uint8_t *)ret);
+}
+EXPORT_SYMBOL(nft_table_attr_get_u8);
+
const char *nft_table_attr_get_str(struct nft_table *t, uint16_t attr)
{
return nft_table_attr_get(t, attr);
--
1.8.4.rc3
next reply other threads:[~2013-11-19 12:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-19 12:01 Ana Rey [this message]
2013-11-20 22:57 ` [PATCH] include: table: chain: added set and get for u8 values in chain and table Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1384862516-3518-1-git-send-email-anarey@gmail.com \
--to=anarey@gmail.com \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).