Skip to contentSkip to conversation

include: fix possible clash in ifdef namespace

PATCH New Pablo Neira Ayuso 1 participant 2 messages Nov 24, 2013 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/2 include: fix possible clash in ifdef namespace

Use _LIBNFTABLES_ prefix to avoid possible clash with headers that are defined in other libraries that may be used by third party applications.

---
 include/libnftables/chain.h   |    6 +++---
 include/libnftables/common.h  |    4 ++--
 include/libnftables/expr.h    |    6 +++---
 include/libnftables/rule.h    |    6 +++---
 include/libnftables/ruleset.h |    6 +++---
 include/libnftables/set.h     |    6 +++---
 include/libnftables/table.h   |    6 +++---
 7 files changed, 20 insertions(+), 20 deletions(-)
include/libnftables/chain.h +3 -3
index 7dee88a..fff47d3 100644
@@ -1,5 +1,5 @@
-#ifndef _CHAIN_H_
-#define _CHAIN_H_
+#ifndef _LIBNFTABLES_CHAIN_H_
+#define _LIBNFTABLES_CHAIN_H_
 
 #include <stdio.h>
 #include <stdint.h>
@@ -79,4 +79,4 @@ void nft_chain_list_iter_destroy(struct nft_chain_list_iter *iter);
 } /* extern "C" */
 #endif
 
-#endif /* _CHAIN_H_ */
+#endif /* _LIBNFTABLES_CHAIN_H_ */
include/libnftables/common.h +2 -2
index d19a84b..2283d72 100644
@@ -1,5 +1,5 @@
-#ifndef _COMMON_H_
-#define _COMMON_H_
+#ifndef _LIBNFTABLES_COMMON_H_
+#define _LIBNFTABLES_COMMON_H_
 
 enum nft_output_type {
 	NFT_OUTPUT_DEFAULT	= 0,
include/libnftables/expr.h +3 -3
index 81e224c..54de186 100644
@@ -1,5 +1,5 @@
-#ifndef _RULE_EXPR_H_
-#define _RULE_EXPR_H_
+#ifndef _LIBNFTABLES_RULE_EXPR_H_
+#define _LIBNFTABLES_RULE_EXPR_H_
 
 #include <stdint.h>
 #include <stdbool.h>
@@ -147,4 +147,4 @@ enum {
 } /* extern "C" */
 #endif
 
-#endif
+#endif /* _LIBNFTABLES_RULE_EXPR_H_ */
include/libnftables/rule.h +3 -3
index 4957a2a..d1d75e1 100644
@@ -1,5 +1,5 @@
-#ifndef _RULE_H_
-#define _RULE_H_
+#ifndef _LIBNFTABLES_RULE_H_
+#define _LIBNFTABLES_RULE_H_
 
 #include <stdio.h>
 #include <stdint.h>
@@ -85,4 +85,4 @@ void nft_rule_list_iter_destroy(struct nft_rule_list_iter *iter);
 } /* extern "C" */
 #endif
 
-#endif /* _RULE_H_ */
+#endif /* _LIBNFTABLES_RULE_H_ */
include/libnftables/ruleset.h +3 -3
index 71ef3b1..1ec3059 100644
@@ -1,5 +1,5 @@
-#ifndef _RULESET_H_
-#define _RULESET_H_
+#ifndef _LIBNFTABLES_RULESET_H_
+#define _LIBNFTABLES_RULESET_H_
 
 #include <stdio.h>
 
@@ -38,4 +38,4 @@ int nft_ruleset_fprintf(FILE *fp, const struct nft_ruleset *rs, uint32_t type, u
 } /* extern "C" */
 #endif
 
-#endif /* _RULESET_H_ */
+#endif /* _LIBNFTABLES_RULESET_H_ */
include/libnftables/set.h +3 -3
index d378049..d91bd42 100644
@@ -1,5 +1,5 @@
-#ifndef _NFT_SET_H_
-#define _NFT_SET_H_
+#ifndef _LIBNFTABLES_SET_H_
+#define _LIBNFTABLES_SET_H_
 
 #include <stdio.h>
 #include <stdint.h>
@@ -110,4 +110,4 @@ struct nft_set_elem *nft_set_elems_iter_cur(struct nft_set_elems_iter *iter);
 struct nft_set_elem *nft_set_elems_iter_next(struct nft_set_elems_iter *iter);
 void nft_set_elems_iter_destroy(struct nft_set_elems_iter *iter);
 
-#endif
+#endif /* _LIBNFTABLES_SET_H_ */
include/libnftables/table.h +3 -3
index 9228cec..87481e4 100644
@@ -1,5 +1,5 @@
-#ifndef _TABLE_H_
-#define _TABLE_H_
+#ifndef _LIBNFTABLES_TABLE_H_
+#define _LIBNFTABLES_TABLE_H_
 
 #include <stdio.h>
 #include <stdint.h>
@@ -67,4 +67,4 @@ void nft_table_list_iter_destroy(struct nft_table_list_iter *iter);
 } /* extern "C" */
 #endif
 
-#endif /* _TABLE_H_ */
+#endif /* _LIBNFTABLES_TABLE_H_ */
Signature · 1 line
1.7.10.4
author maintainer
#1 lore raw

PATCH 2/2 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.

---
 include/libnftables/chain.h  |    2 +-
 include/libnftables/common.h |    4 ++++
 include/libnftables/rule.h   |    2 +-
 include/libnftables/set.h    |    4 ++--
 include/libnftables/table.h  |    2 +-
 src/Makefile.am              |    1 +
 src/chain.c                  |   21 ---------------------
 src/common.c                 |   36 ++++++++++++++++++++++++++++++++++++
 src/libnftables.map          |    7 ++-----
 src/rule.c                   |   21 ---------------------
 src/set.c                    |   21 ---------------------
 src/set_elem.c               |   21 ---------------------
 src/table.c                  |   21 ---------------------
 13 files changed, 48 insertions(+), 115 deletions(-)
 create mode 100644 src/common.c
include/libnftables/chain.h +1 -1
index fff47d3..8b4eab9 100644
@@ -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;
include/libnftables/common.h +4 -0
index 2283d72..9cd92b2 100644
@@ -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
include/libnftables/rule.h +1 -1
index d1d75e1..86dbc17 100644
@@ -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,
include/libnftables/set.h +2 -2
index d91bd42..13ac857 100644
@@ -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);
 
include/libnftables/table.h +1 -1
index 87481e4..be60da9 100644
@@ -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;
src/Makefile.am +1 -0
index 48d5d2d..83ab658 100644
@@ -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			\
src/chain.c +0 -21
index 0145d32..a0004b5 100644
@@ -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))
src/common.c new file +36 -0
new file mode 100644
index 0000000..f03e730
@@ -0,0 +1,36 @@
+/*
+ * (C) 2012-2013 by Pablo Neira Ayuso <[email protected]>
+ *
+ * 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);
src/libnftables.map +2 -5
index 3bdfeda..7dc9aee 100644
@@ -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: *;
 };
src/rule.c +0 -21
index 4f70dab..280350a 100644
@@ -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;
src/set.c +0 -21
index ba39c43..c5204cc 100644
@@ -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))
src/set_elem.c +0 -21
index 297328f..fce9c1d 100644
@@ -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)
 {
src/table.c +0 -21
index cf24cae..9e20768 100644
@@ -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))
Signature · 1 line
1.7.10.4