]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
src: consolidate netlink build header function
authorPablo Neira Ayuso <pablo@netfilter.org>
Sun, 24 Nov 2013 20:01:49 +0000 (21:01 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Sun, 24 Nov 2013 20:08:21 +0000 (21:08 +0100)
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>
13 files changed:
include/libnftables/chain.h
include/libnftables/common.h
include/libnftables/rule.h
include/libnftables/set.h
include/libnftables/table.h
src/Makefile.am
src/chain.c
src/common.c [new file with mode: 0644]
src/libnftables.map
src/rule.c
src/set.c
src/set_elem.c
src/table.c

index fff47d347fcf44ee9c4c5a7faa50d0260cdc5f03..8b4eab9c19b7dd412cc917a39a9012aa1b800ff5 100644 (file)
@@ -55,7 +55,7 @@ int nft_chain_parse(struct nft_chain *c, enum nft_parse_type type, const char *d
 int nft_chain_snprintf(char *buf, size_t size, struct nft_chain *t, uint32_t type, uint32_t flags);
 int nft_chain_fprintf(FILE *fp, struct nft_chain *c, uint32_t type, uint32_t flags);
 
-struct nlmsghdr *nft_chain_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family, uint16_t type, uint32_t seq);
+#define nft_chain_nlmsg_build_hdr      nft_nlmsg_build_hdr
 int nft_chain_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_chain *t);
 
 struct nft_chain_list;
index 2283d725678f79323655f74daa6b5a7715935171..9cd92b287c15c42c23bc9fc37e6c2b6cc990003f 100644 (file)
@@ -13,4 +13,8 @@ enum nft_parse_type {
        NFT_PARSE_JSON,
        NFT_PARSE_MAX,
 };
+
+struct nlmsghdr *nft_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family,
+                                    uint16_t type, uint32_t seq);
+
 #endif
index d1d75e1260adc27f3bc2f9247b9e5be11856ca3a..86dbc17cb3ff45c121f9370c89792bec3fb80e04 100644 (file)
@@ -51,7 +51,7 @@ int nft_rule_parse(struct nft_rule *r, enum nft_parse_type type, const char *dat
 int nft_rule_snprintf(char *buf, size_t size, struct nft_rule *t, uint32_t type, uint32_t flags);
 int nft_rule_fprintf(FILE *fp, struct nft_rule *r, uint32_t type, uint32_t flags);
 
-struct nlmsghdr *nft_rule_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family, uint16_t type, uint32_t seq);
+#define nft_rule_nlmsg_build_hdr       nft_nlmsg_build_hdr
 int nft_rule_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_rule *t);
 
 int nft_rule_expr_foreach(struct nft_rule *r,
index d91bd424042ad6d94d67d32f4a9985b847841a39..13ac8576e987ca3a079ff40ae1bc7156507b9e2e 100644 (file)
@@ -36,7 +36,7 @@ uint32_t nft_set_attr_get_u32(struct nft_set *s, uint16_t attr);
 
 struct nlmsghdr;
 
-struct nlmsghdr *nft_set_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family, uint16_t type, uint32_t seq);
+#define nft_set_nlmsg_build_hdr        nft_nlmsg_build_hdr
 void nft_set_nlmsg_build_payload(struct nlmsghdr *nlh, struct nft_set *s);
 int nft_set_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_set *s);
 int nft_set_elems_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_set *s);
@@ -92,7 +92,7 @@ uint32_t nft_set_elem_attr_get_u32(struct nft_set_elem *s, uint16_t attr);
 
 bool nft_set_elem_attr_is_set(const struct nft_set_elem *s, uint16_t attr);
 
-struct nlmsghdr *nft_set_elem_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family, uint16_t type, uint32_t seq);
+#define nft_set_elem_nlmsg_build_hdr   nft_nlmsg_build_hdr
 void nft_set_elems_nlmsg_build_payload(struct nlmsghdr *nlh, struct nft_set *s);
 void nft_set_elem_nlmsg_build_payload(struct nlmsghdr *nlh, struct nft_set_elem *e);
 
index 87481e42a1003419b17ff4fdff185acb5cc884a0..be60da91fbeacfccd2afb3743c47b753219ec59d 100644 (file)
@@ -43,7 +43,7 @@ int nft_table_parse(struct nft_table *t, enum nft_parse_type type, const char *d
 int nft_table_snprintf(char *buf, size_t size, struct nft_table *t, uint32_t type, uint32_t flags);
 int nft_table_fprintf(FILE *fp, struct nft_table *t, uint32_t type, uint32_t flags);
 
-struct nlmsghdr *nft_table_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family, uint16_t type, uint32_t seq);
+#define nft_table_nlmsg_build_hdr      nft_nlmsg_build_hdr
 int nft_table_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_table *t);
 
 struct nft_table_list;
index 48d5d2db71408d0233fa45349cd406b07e95a822..83ab6584d0b824e604555c6b51c88ea0841405c2 100644 (file)
@@ -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                 \
index 0145d323f60bcfdf8500f75cf019104d3714ccf9..a0004b5e5b368997aa947ed61a52357362529de8 100644 (file)
@@ -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 (file)
index 0000000..f03e730
--- /dev/null
@@ -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);
index 3bdfeda6be4d3f74e95abf7f8f839f0983a4ddb4..7dc9aee15f11ae5109edd05e174e1cfe9014e2b0 100644 (file)
@@ -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: *;
 };
index 4f70dabb2c5bdc596cb585ff4b5ad24d4a22f06b..280350a31fffba45bb7e9b3eadf89cce93879e03 100644 (file)
@@ -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;
index ba39c43b4e523c20c63d27f1e68593c488399c91..c5204cc6be972b97015c4a9b9600b752cacf9f9b 100644 (file)
--- 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))
index 297328f9dc1f3a5f72206f21af50940950ac6703..fce9c1d9ccd5a5c7ac400a20456bca4a5c754c0f 100644 (file)
@@ -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)
 {
index cf24cae343e0c3230687f41e190b8fb61961df93..9e20768325eb40d8961167da7d2f4bde2ee69763 100644 (file)
@@ -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))