netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH libnftnl 1/3] common: get rid of nftnl_batch_build_hdr()
@ 2017-02-15 10:43 Pablo Neira Ayuso
  2017-02-15 10:43 ` [PATCH libnftnl 2/3] common: return nlmsghdr in nftnl_batch_{begin,end}() Pablo Neira Ayuso
  2017-02-15 10:43 ` [PATCH libnftnl 3/3] rule: add NFTA_RULE_ID attribute Pablo Neira Ayuso
  0 siblings, 2 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2017-02-15 10:43 UTC (permalink / raw)
  To: netfilter-devel

Add __nftnl_nlmsg_build_hdr() so nftnl_batch_build_hdr() and
nftnl_nlmsg_build_hdr() share the same code.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 include/libnftnl/common.h |  4 ++--
 src/common.c              | 41 ++++++++++++++++++-----------------------
 2 files changed, 20 insertions(+), 25 deletions(-)

diff --git a/include/libnftnl/common.h b/include/libnftnl/common.h
index b9c6ff3e2e54..f67f1866560f 100644
--- a/include/libnftnl/common.h
+++ b/include/libnftnl/common.h
@@ -41,8 +41,8 @@ enum nftnl_parse_type {
 
 struct nftnl_parse_err;
 
-struct nlmsghdr *nftnl_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family,
-				     uint16_t type, uint32_t seq);
+struct nlmsghdr *nftnl_nlmsg_build_hdr(char *buf, uint16_t type, uint16_t family,
+				       uint16_t flags, uint32_t seq);
 
 struct nftnl_parse_err *nftnl_parse_err_alloc(void);
 void nftnl_parse_err_free(struct nftnl_parse_err *);
diff --git a/src/common.c b/src/common.c
index 8b001fe8da97..0f23785e05d3 100644
--- a/src/common.c
+++ b/src/common.c
@@ -22,24 +22,33 @@
 #include <errno.h>
 #include "internal.h"
 
-struct nlmsghdr *nftnl_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family,
-				     uint16_t type, uint32_t seq)
+static struct nlmsghdr *__nftnl_nlmsg_build_hdr(char *buf, uint16_t type,
+						uint16_t family,
+						uint16_t flags, uint32_t seq,
+						uint16_t res_id)
 {
 	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_type = type;
+	nlh->nlmsg_flags = NLM_F_REQUEST | flags;
 	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;
+	nfh->res_id = res_id;
 
 	return nlh;
 }
+
+struct nlmsghdr *nftnl_nlmsg_build_hdr(char *buf, uint16_t type, uint16_t family,
+				       uint16_t flags, uint32_t seq)
+{
+	return __nftnl_nlmsg_build_hdr(buf, (NFNL_SUBSYS_NFTABLES << 8) | type,
+				       family, flags, seq, 0);
+}
 EXPORT_SYMBOL(nftnl_nlmsg_build_hdr);
 
 struct nftnl_parse_err *nftnl_parse_err_alloc(void)
@@ -156,31 +165,17 @@ int nftnl_cmd_footer_fprintf(FILE *fp, uint32_t cmd, uint32_t type,
 			   nftnl_cmd_footer_fprintf_cb);
 }
 
-static void nftnl_batch_build_hdr(char *buf, uint16_t type, uint32_t seq)
-{
-	struct nlmsghdr *nlh;
-	struct nfgenmsg *nfg;
-
-	nlh = mnl_nlmsg_put_header(buf);
-	nlh->nlmsg_type = type;
-	nlh->nlmsg_flags = NLM_F_REQUEST;
-	nlh->nlmsg_seq = seq;
-
-	nfg = mnl_nlmsg_put_extra_header(nlh, sizeof(*nfg));
-	nfg->nfgen_family = AF_UNSPEC;
-	nfg->version = NFNETLINK_V0;
-	nfg->res_id = NFNL_SUBSYS_NFTABLES;
-}
-
 void nftnl_batch_begin(char *buf, uint32_t seq)
 {
-	nftnl_batch_build_hdr(buf, NFNL_MSG_BATCH_BEGIN, seq);
+	__nftnl_nlmsg_build_hdr(buf, NFNL_MSG_BATCH_BEGIN, AF_UNSPEC, 0, seq,
+				NFNL_SUBSYS_NFTABLES);
 }
 EXPORT_SYMBOL(nftnl_batch_begin);
 
 void nftnl_batch_end(char *buf, uint32_t seq)
 {
-	nftnl_batch_build_hdr(buf, NFNL_MSG_BATCH_END, seq);
+	__nftnl_nlmsg_build_hdr(buf, NFNL_MSG_BATCH_END, AF_UNSPEC, 0, seq,
+				NFNL_SUBSYS_NFTABLES);
 }
 EXPORT_SYMBOL(nftnl_batch_end);
 
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-02-15 10:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-15 10:43 [PATCH libnftnl 1/3] common: get rid of nftnl_batch_build_hdr() Pablo Neira Ayuso
2017-02-15 10:43 ` [PATCH libnftnl 2/3] common: return nlmsghdr in nftnl_batch_{begin,end}() Pablo Neira Ayuso
2017-02-15 10:43 ` [PATCH libnftnl 3/3] rule: add NFTA_RULE_ID attribute Pablo Neira Ayuso

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).