summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2013-11-24 21:01:49 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2013-11-24 21:08:21 +0100
commitd7955867a79e8aed8058a2a69953c6005bb9ef5a (patch)
treea649d38b5a7337e609531ee481b792aa55d8b5b2 /src
parent16f85ed04049501bf5ac932a5ae44627d76ef747 (diff)
src: consolidate netlink build header function
Add new function nft_nlmsg_build_hdr which consolidates all existing functions to build headers per object. They basically look the same. This patch still provides aliases for consistency in the naming approach. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/chain.c21
-rw-r--r--src/common.c36
-rw-r--r--src/libnftables.map7
-rw-r--r--src/rule.c21
-rw-r--r--src/set.c21
-rw-r--r--src/set_elem.c21
-rw-r--r--src/table.c21
8 files changed, 39 insertions, 110 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 48d5d2d..83ab658 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,6 +5,7 @@ libnftables_la_LIBADD = ${LIBMNL_LIBS} ${LIBXML_LIBS} ${LIBJSON_LIBS}
libnftables_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libnftables.map \
-version-info $(LIBVERSION)
libnftables_la_SOURCES = utils.c \
+ common.c \
table.c \
chain.c \
rule.c \
diff --git a/src/chain.c b/src/chain.c
index 0145d32..a0004b5 100644
--- a/src/chain.c
+++ b/src/chain.c
@@ -285,27 +285,6 @@ uint8_t nft_chain_attr_get_u8(struct nft_chain *c, uint16_t attr)
}
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)
-{
- struct nlmsghdr *nlh;
- struct nfgenmsg *nfh;
-
- nlh = mnl_nlmsg_put_header(buf);
- nlh->nlmsg_type = (NFNL_SUBSYS_NFTABLES << 8) | cmd;
- nlh->nlmsg_flags = NLM_F_REQUEST | type;
- nlh->nlmsg_seq = seq;
-
- nfh = mnl_nlmsg_put_extra_header(nlh, sizeof(struct nfgenmsg));
- nfh->nfgen_family = family;
- nfh->version = NFNETLINK_V0;
- nfh->res_id = 0;
-
- return nlh;
-}
-EXPORT_SYMBOL(nft_chain_nlmsg_build_hdr);
-
void nft_chain_nlmsg_build_payload(struct nlmsghdr *nlh, const struct nft_chain *c)
{
if (c->flags & (1 << NFT_CHAIN_ATTR_TABLE))
diff --git a/src/common.c b/src/common.c
new file mode 100644
index 0000000..f03e730
--- /dev/null
+++ b/src/common.c
@@ -0,0 +1,36 @@
+/*
+ * (C) 2012-2013 by Pablo Neira Ayuso <pablo@netfilter.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <linux/netlink.h>
+#include <linux/netfilter/nfnetlink.h>
+
+#include <libmnl/libmnl.h>
+#include <libnftables/common.h>
+
+#include "internal.h"
+
+struct nlmsghdr *nft_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family,
+ uint16_t type, uint32_t seq)
+{
+ struct nlmsghdr *nlh;
+ struct nfgenmsg *nfh;
+
+ nlh = mnl_nlmsg_put_header(buf);
+ nlh->nlmsg_type = (NFNL_SUBSYS_NFTABLES << 8) | cmd;
+ nlh->nlmsg_flags = NLM_F_REQUEST | type;
+ nlh->nlmsg_seq = seq;
+
+ nfh = mnl_nlmsg_put_extra_header(nlh, sizeof(struct nfgenmsg));
+ nfh->nfgen_family = family;
+ nfh->version = NFNETLINK_V0;
+ nfh->res_id = 0;
+
+ return nlh;
+}
+EXPORT_SYMBOL(nft_nlmsg_build_hdr);
diff --git a/src/libnftables.map b/src/libnftables.map
index 3bdfeda..7dc9aee 100644
--- a/src/libnftables.map
+++ b/src/libnftables.map
@@ -15,7 +15,6 @@ global:
nft_table_parse;
nft_table_snprintf;
nft_table_fprintf;
- nft_table_nlmsg_build_hdr;
nft_table_nlmsg_build_payload;
nft_table_nlmsg_parse;
nft_table_list_alloc;
@@ -48,7 +47,6 @@ global:
nft_chain_parse;
nft_chain_snprintf;
nft_chain_fprintf;
- nft_chain_nlmsg_build_hdr;
nft_chain_nlmsg_build_payload;
nft_chain_nlmsg_parse;
nft_chain_list_alloc;
@@ -78,7 +76,6 @@ global:
nft_rule_parse;
nft_rule_snprintf;
nft_rule_fprintf;
- nft_rule_nlmsg_build_hdr;
nft_rule_nlmsg_build_payload;
nft_rule_nlmsg_parse;
nft_rule_add_expr;
@@ -128,7 +125,6 @@ global:
nft_set_attr_get;
nft_set_attr_get_str;
nft_set_attr_get_u32;
- nft_set_nlmsg_build_hdr;
nft_set_nlmsg_build_payload;
nft_set_nlmsg_parse;
nft_set_parse;
@@ -160,7 +156,6 @@ global:
nft_set_elem_attr_get;
nft_set_elem_attr_get_str;
nft_set_elem_attr_get_u32;
- nft_set_elem_nlmsg_build_hdr;
nft_set_elem_nlmsg_build_payload;
nft_set_elem_nlmsg_parse;
nft_set_elem_parse;
@@ -187,5 +182,7 @@ global:
nft_ruleset_snprintf;
nft_ruleset_fprintf;
+ nft_nlmsg_build_hdr;
+
local: *;
};
diff --git a/src/rule.c b/src/rule.c
index 4f70dab..280350a 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -220,27 +220,6 @@ uint8_t nft_rule_attr_get_u8(const struct nft_rule *r, uint16_t attr)
}
EXPORT_SYMBOL(nft_rule_attr_get_u8);
-struct nlmsghdr *
-nft_rule_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family,
- uint16_t type, uint32_t seq)
-{
- struct nlmsghdr *nlh;
- struct nfgenmsg *nfh;
-
- nlh = mnl_nlmsg_put_header(buf);
- nlh->nlmsg_type = (NFNL_SUBSYS_NFTABLES << 8) | cmd;
- nlh->nlmsg_flags = NLM_F_REQUEST | type;
- nlh->nlmsg_seq = seq;
-
- nfh = mnl_nlmsg_put_extra_header(nlh, sizeof(struct nfgenmsg));
- nfh->nfgen_family = family;
- nfh->version = NFNETLINK_V0;
- nfh->res_id = 0;
-
- return nlh;
-}
-EXPORT_SYMBOL(nft_rule_nlmsg_build_hdr);
-
void nft_rule_nlmsg_build_payload(struct nlmsghdr *nlh, struct nft_rule *r)
{
struct nft_rule_expr *expr;
diff --git a/src/set.c b/src/set.c
index ba39c43..c5204cc 100644
--- a/src/set.c
+++ b/src/set.c
@@ -188,27 +188,6 @@ uint32_t nft_set_attr_get_u32(struct nft_set *s, uint16_t attr)
}
EXPORT_SYMBOL(nft_set_attr_get_u32);
-struct nlmsghdr *
-nft_set_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family,
- uint16_t type, uint32_t seq)
-{
- struct nlmsghdr *nlh;
- struct nfgenmsg *nfh;
-
- nlh = mnl_nlmsg_put_header(buf);
- nlh->nlmsg_type = (NFNL_SUBSYS_NFTABLES << 8) | cmd;
- nlh->nlmsg_flags = NLM_F_REQUEST | type;
- nlh->nlmsg_seq = seq;
-
- nfh = mnl_nlmsg_put_extra_header(nlh, sizeof(struct nfgenmsg));
- nfh->nfgen_family = family;
- nfh->version = NFNETLINK_V0;
- nfh->res_id = 0;
-
- return nlh;
-}
-EXPORT_SYMBOL(nft_set_nlmsg_build_hdr);
-
void nft_set_nlmsg_build_payload(struct nlmsghdr *nlh, struct nft_set *s)
{
if (s->flags & (1 << NFT_SET_ATTR_TABLE))
diff --git a/src/set_elem.c b/src/set_elem.c
index 297328f..fce9c1d 100644
--- a/src/set_elem.c
+++ b/src/set_elem.c
@@ -158,27 +158,6 @@ uint32_t nft_set_elem_attr_get_u32(struct nft_set_elem *s, uint16_t attr)
}
EXPORT_SYMBOL(nft_set_elem_attr_get_u32);
-struct nlmsghdr *
-nft_set_elem_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family,
- uint16_t type, uint32_t seq)
-{
- struct nlmsghdr *nlh;
- struct nfgenmsg *nfh;
-
- nlh = mnl_nlmsg_put_header(buf);
- nlh->nlmsg_type = (NFNL_SUBSYS_NFTABLES << 8) | cmd;
- nlh->nlmsg_flags = NLM_F_REQUEST | type;
- nlh->nlmsg_seq = seq;
-
- nfh = mnl_nlmsg_put_extra_header(nlh, sizeof(struct nfgenmsg));
- nfh->nfgen_family = family;
- nfh->version = NFNETLINK_V0;
- nfh->res_id = 0;
-
- return nlh;
-}
-EXPORT_SYMBOL(nft_set_elem_nlmsg_build_hdr);
-
void nft_set_elem_nlmsg_build_payload(struct nlmsghdr *nlh,
struct nft_set_elem *e)
{
diff --git a/src/table.c b/src/table.c
index cf24cae..9e20768 100644
--- a/src/table.c
+++ b/src/table.c
@@ -152,27 +152,6 @@ const char *nft_table_attr_get_str(struct nft_table *t, uint16_t attr)
}
EXPORT_SYMBOL(nft_table_attr_get_str);
-struct nlmsghdr *
-nft_table_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family,
- uint16_t type, uint32_t seq)
-{
- struct nlmsghdr *nlh;
- struct nfgenmsg *nfh;
-
- nlh = mnl_nlmsg_put_header(buf);
- nlh->nlmsg_type = (NFNL_SUBSYS_NFTABLES << 8) | cmd;
- nlh->nlmsg_flags = NLM_F_REQUEST | type;
- nlh->nlmsg_seq = seq;
-
- nfh = mnl_nlmsg_put_extra_header(nlh, sizeof(struct nfgenmsg));
- nfh->nfgen_family = family;
- nfh->version = NFNETLINK_V0;
- nfh->res_id = 0;
-
- return nlh;
-}
-EXPORT_SYMBOL(nft_table_nlmsg_build_hdr);
-
void nft_table_nlmsg_build_payload(struct nlmsghdr *nlh, const struct nft_table *t)
{
if (t->flags & (1 << NFT_TABLE_ATTR_NAME))