summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-08-25 13:36:30 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2023-08-25 14:59:19 +0200
commitb4add075c1283151d0514cf0052f9184e9e073df (patch)
tree7798c59dbe1ec7b982f7adcd4a6357aa436b20d3
parent19231d4c896571fea397d43568c4b3562969c7e2 (diff)
src: add <nft.h> header and include it as first
<config.h> is generated by the configure script. As it contains our feature detection, it want to use it everywhere. Likewise, in some of our sources, we define _GNU_SOURCE. This defines the C variant we want to use. Such a define need to come before anything else, and it would be confusing if different source files adhere to a different C variant. It would be good to use autoconf's AC_USE_SYSTEM_EXTENSIONS, in which case we would also need to ensure that <config.h> is always included as first. Instead of going through all source files and include <config.h> as first, add a new header "include/nft.h", which is supposed to be included in all our sources (and as first). This will also allow us later to prepare some common base, like include <stdbool.h> everywhere. We aim that headers are self-contained, so that they can be included in any order. Which, by the way, already didn't work because some headers define _GNU_SOURCE, which would only work if the header gets included as first. <nft.h> is however an exception to the rule: everything we compile shall rely on having <nft.h> header included as first. This applies to source files (which explicitly include <nft.h>) and to internal header files (which are only compiled indirectly, by being included from a source file). Note that <config.h> has no include guards, which is at least ugly to include multiple times. It doesn't cause problems in practice, because it only contains defines and the compiler doesn't warn about redefining a macro with the same value. Still, <nft.h> also ensures to include <config.h> exactly once. Signed-off-by: Thomas Haller <thaller@redhat.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--include/Makefile.am3
-rw-r--r--include/cli.h1
-rw-r--r--include/gmputil.h2
-rw-r--r--include/nft.h9
-rw-r--r--include/utils.h1
-rw-r--r--src/cache.c2
-rw-r--r--src/cli.c3
-rw-r--r--src/cmd.c2
-rw-r--r--src/ct.c2
-rw-r--r--src/datatype.c2
-rw-r--r--src/dccpopt.c2
-rw-r--r--src/erec.c4
-rw-r--r--src/evaluate.c2
-rw-r--r--src/expression.c2
-rw-r--r--src/exthdr.c2
-rw-r--r--src/fib.c2
-rw-r--r--src/gmputil.c2
-rw-r--r--src/hash.c2
-rw-r--r--src/iface.c2
-rw-r--r--src/intervals.c2
-rw-r--r--src/ipopt.c2
-rw-r--r--src/json.c3
-rw-r--r--src/libnftables.c3
-rw-r--r--src/main.c2
-rw-r--r--src/mergesort.c2
-rw-r--r--src/meta.c2
-rw-r--r--src/mini-gmp.c2
-rw-r--r--src/misspell.c2
-rw-r--r--src/mnl.c2
-rw-r--r--src/monitor.c2
-rw-r--r--src/netlink.c2
-rw-r--r--src/netlink_delinearize.c2
-rw-r--r--src/netlink_linearize.c2
-rw-r--r--src/nfnl_osf.c2
-rw-r--r--src/nftutils.c2
-rw-r--r--src/numgen.c2
-rw-r--r--src/optimize.c3
-rw-r--r--src/osf.c2
-rw-r--r--src/owner.c2
-rw-r--r--src/parser_json.c3
-rw-r--r--src/payload.c2
-rw-r--r--src/print.c2
-rw-r--r--src/proto.c2
-rw-r--r--src/rt.c2
-rw-r--r--src/rule.c2
-rw-r--r--src/scanner.l2
-rw-r--r--src/sctp_chunk.c2
-rw-r--r--src/segtree.c2
-rw-r--r--src/socket.c2
-rw-r--r--src/statement.c2
-rw-r--r--src/tcpopt.c2
-rw-r--r--src/utils.c2
-rw-r--r--src/xfrm.c2
-rw-r--r--src/xt.c2
54 files changed, 108 insertions, 13 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
index 1d20f404..162807b0 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -1,11 +1,12 @@
SUBDIRS = linux \
nftables
-noinst_HEADERS = cli.h \
+noinst_HEADERS = cli.h \
cache.h \
cmd.h \
datatype.h \
dccpopt.h \
+ nft.h \
expression.h \
fib.h \
hash.h \
diff --git a/include/cli.h b/include/cli.h
index c854948e..f0a0d47a 100644
--- a/include/cli.h
+++ b/include/cli.h
@@ -2,7 +2,6 @@
#define _NFT_CLI_H_
#include <nftables/libnftables.h>
-#include <config.h>
#if defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDIT) || defined(HAVE_LIBLINENOISE)
extern int cli_init(struct nft_ctx *nft);
diff --git a/include/gmputil.h b/include/gmputil.h
index 0cb85a7d..c524aced 100644
--- a/include/gmputil.h
+++ b/include/gmputil.h
@@ -1,8 +1,6 @@
#ifndef NFTABLES_GMPUTIL_H
#define NFTABLES_GMPUTIL_H
-#include <config.h>
-
#ifdef HAVE_LIBGMP
#include <gmp.h>
#else
diff --git a/include/nft.h b/include/nft.h
new file mode 100644
index 00000000..4e66f8e6
--- /dev/null
+++ b/include/nft.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef NFTABLES_NFT_H
+#define NFTABLES_NFT_H
+
+#define _GNU_SOURCE
+
+#include <config.h>
+
+#endif /* NFTABLES_NFT_H */
diff --git a/include/utils.h b/include/utils.h
index d5073e06..6764f921 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -11,7 +11,6 @@
#include <list.h>
#include <gmputil.h>
-#include "config.h"
#ifdef HAVE_VISIBILITY_HIDDEN
# define __visible __attribute__((visibility("default")))
# define EXPORT_SYMBOL(x) typeof(x) (x) __visible;
diff --git a/src/cache.c b/src/cache.c
index db9a9a75..3fe6bb40 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -6,6 +6,8 @@
* later) as published by the Free Software Foundation.
*/
+#include <nft.h>
+
#include <expression.h>
#include <statement.h>
#include <rule.h>
diff --git a/src/cli.c b/src/cli.c
index 5f7e01ff..bfae90e6 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -12,7 +12,8 @@
* Development of this code funded by Astaro AG (http://www.astaro.com/)
*/
-#include <config.h>
+#include <nft.h>
+
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
diff --git a/src/cmd.c b/src/cmd.c
index 98216d54..98859674 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -6,6 +6,8 @@
* later) as published by the Free Software Foundation.
*/
+#include <nft.h>
+
#include <erec.h>
#include <mnl.h>
#include <cmd.h>
diff --git a/src/ct.c b/src/ct.c
index 64327561..ca35087a 100644
--- a/src/ct.c
+++ b/src/ct.c
@@ -10,6 +10,8 @@
* Development of this code funded by Astaro AG (http://www.astaro.com/)
*/
+#include <nft.h>
+
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
diff --git a/src/datatype.c b/src/datatype.c
index 64396db8..dd6a5fbf 100644
--- a/src/datatype.c
+++ b/src/datatype.c
@@ -8,6 +8,8 @@
* Development of this code funded by Astaro AG (http://www.astaro.com/)
*/
+#include <nft.h>
+
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
diff --git a/src/dccpopt.c b/src/dccpopt.c
index 3a2eb952..d713d903 100644
--- a/src/dccpopt.c
+++ b/src/dccpopt.c
@@ -1,3 +1,5 @@
+#include <nft.h>
+
#include <stddef.h>
#include <stdint.h>
diff --git a/src/erec.c b/src/erec.c
index aebb8632..d26dee60 100644
--- a/src/erec.c
+++ b/src/erec.c
@@ -8,8 +8,8 @@
* Development of this code funded by Astaro AG (http://www.astaro.com/)
*/
-#define _GNU_SOURCE
-#include <config.h>
+#include <nft.h>
+
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
diff --git a/src/evaluate.c b/src/evaluate.c
index 2b158aee..69a12351 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -8,6 +8,8 @@
* Development of this code funded by Astaro AG (http://www.astaro.com/)
*/
+#include <nft.h>
+
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
diff --git a/src/expression.c b/src/expression.c
index 34902c84..8ef00891 100644
--- a/src/expression.c
+++ b/src/expression.c
@@ -8,6 +8,8 @@
* Development of this code funded by Astaro AG (http://www.astaro.com/)
*/
+#include <nft.h>
+
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
diff --git a/src/exthdr.c b/src/exthdr.c
index 0358005b..dd8c7581 100644
--- a/src/exthdr.c
+++ b/src/exthdr.c
@@ -10,6 +10,8 @@
* Development of this code funded by Astaro AG (http://www.astaro.com/)
*/
+#include <nft.h>
+
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
diff --git a/src/fib.c b/src/fib.c
index 98c57868..b977fe28 100644
--- a/src/fib.c
+++ b/src/fib.c
@@ -8,6 +8,8 @@
* later) as published by the Free Software Foundation.
*/
+#include <nft.h>
+
#include <nftables.h>
#include <erec.h>
#include <expression.h>
diff --git a/src/gmputil.c b/src/gmputil.c
index b356460f..9cda1853 100644
--- a/src/gmputil.c
+++ b/src/gmputil.c
@@ -8,6 +8,8 @@
* Development of this code funded by Astaro AG (http://www.astaro.com/)
*/
+#include <nft.h>
+
#include <stddef.h>
#include <stdlib.h>
#include <stdarg.h>
diff --git a/src/hash.c b/src/hash.c
index a3fd0872..1c8c00aa 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -8,6 +8,8 @@
* later) as published by the Free Software Foundation.
*/
+#include <nft.h>
+
#include <nftables.h>
#include <expression.h>
#include <datatype.h>
diff --git a/src/iface.c b/src/iface.c
index 3647778c..ec7f5c7f 100644
--- a/src/iface.c
+++ b/src/iface.c
@@ -6,6 +6,8 @@
* later) as published by the Free Software Foundation.
*/
+#include <nft.h>
+
#include <stdio.h>
#include <stdlib.h>
#include <net/if.h>
diff --git a/src/intervals.c b/src/intervals.c
index d79c52c5..85de0199 100644
--- a/src/intervals.c
+++ b/src/intervals.c
@@ -6,6 +6,8 @@
* later) as published by the Free Software Foundation.
*/
+#include <nft.h>
+
#include <nftables.h>
#include <expression.h>
#include <intervals.h>
diff --git a/src/ipopt.c b/src/ipopt.c
index 67e904ff..3ba67b01 100644
--- a/src/ipopt.c
+++ b/src/ipopt.c
@@ -1,3 +1,5 @@
+#include <nft.h>
+
#include <stdint.h>
#include <netinet/in.h>
diff --git a/src/json.c b/src/json.c
index 31dd1856..446575c2 100644
--- a/src/json.c
+++ b/src/json.c
@@ -6,7 +6,8 @@
* later) as published by the Free Software Foundation.
*/
-#define _GNU_SOURCE
+#include <nft.h>
+
#include <stdio.h>
#include <string.h>
diff --git a/src/libnftables.c b/src/libnftables.c
index 69ea9d41..9c802ec9 100644
--- a/src/libnftables.c
+++ b/src/libnftables.c
@@ -5,6 +5,9 @@
* it under the terms of the GNU General Public License version 2 (or any
* later) as published by the Free Software Foundation.
*/
+
+#include <nft.h>
+
#include <nftables/libnftables.h>
#include <erec.h>
#include <mnl.h>
diff --git a/src/main.c b/src/main.c
index 40dc60c2..260338d3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -8,6 +8,8 @@
* Development of this code funded by Astaro AG (http://www.astaro.com/)
*/
+#include <nft.h>
+
#include <stdlib.h>
#include <stddef.h>
#include <unistd.h>
diff --git a/src/mergesort.c b/src/mergesort.c
index a3a9d605..9315093b 100644
--- a/src/mergesort.c
+++ b/src/mergesort.c
@@ -6,6 +6,8 @@
* later) as published by the Free Software Foundation.
*/
+#include <nft.h>
+
#include <stdint.h>
#include <expression.h>
#include <gmputil.h>
diff --git a/src/meta.c b/src/meta.c
index 8508b11e..fcb872e6 100644
--- a/src/meta.c
+++ b/src/meta.c
@@ -10,7 +10,7 @@
* Development of this code funded by Astaro AG (http://www.astaro.com/)
*/
-#define _GNU_SOURCE
+#include <nft.h>
#include <errno.h>
#include <limits.h>
diff --git a/src/mini-gmp.c b/src/mini-gmp.c
index 04bed3f5..6217f745 100644
--- a/src/mini-gmp.c
+++ b/src/mini-gmp.c
@@ -41,6 +41,8 @@ see https://www.gnu.org/licenses/. */
mpn/generic/sbpi1_div_qr.c, mpn/generic/sub_n.c,
mpn/generic/submul_1.c. */
+#include <nft.h>
+
#include <assert.h>
#include <ctype.h>
#include <limits.h>
diff --git a/src/misspell.c b/src/misspell.c
index 8992c75e..18da4386 100644
--- a/src/misspell.c
+++ b/src/misspell.c
@@ -6,6 +6,8 @@
* later) as published by the Free Software Foundation.
*/
+#include <nft.h>
+
#include <stdlib.h>
#include <string.h>
#include <limits.h>
diff --git a/src/mnl.c b/src/mnl.c
index 9406fc48..d583177d 100644
--- a/src/mnl.c
+++ b/src/mnl.c
@@ -8,6 +8,8 @@
* Development of this code funded by Astaro AG (http://www.astaro.com/)
*/
+#include <nft.h>
+
#include <libmnl/libmnl.h>
#include <libnftnl/common.h>
#include <libnftnl/ruleset.h>
diff --git a/src/monitor.c b/src/monitor.c
index 3a189691..0554089b 100644
--- a/src/monitor.c
+++ b/src/monitor.c
@@ -6,6 +6,8 @@
* later) as published by the Free Software Foundation.
*/
+#include <nft.h>
+
#include <string.h>
#include <fcntl.h>
#include <errno.h>
diff --git a/src/netlink.c b/src/netlink.c
index ed61cd89..e1904a99 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -9,6 +9,8 @@
* Development of this code funded by Astaro AG (http://www.astaro.com/)
*/
+#include <nft.h>
+
#include <string.h>
#include <errno.h>
#include <libmnl/libmnl.h>
diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c
index 125b6c68..dfa816cf 100644
--- a/src/netlink_delinearize.c
+++ b/src/netlink_delinearize.c
@@ -9,6 +9,8 @@
* Development of this code funded by Astaro AG (http://www.astaro.com/)
*/
+#include <nft.h>
+
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
diff --git a/src/netlink_linearize.c b/src/netlink_linearize.c
index f5b2d6bb..53a318aa 100644
--- a/src/netlink_linearize.c
+++ b/src/netlink_linearize.c
@@ -9,6 +9,8 @@
* Development of this code funded by Astaro AG (http://www.astaro.com/)
*/
+#include <nft.h>
+
#include <linux/netfilter/nf_tables.h>
#include <linux/netfilter/nf_log.h>
diff --git a/src/nfnl_osf.c b/src/nfnl_osf.c
index 08e978de..48e83ea8 100644
--- a/src/nfnl_osf.c
+++ b/src/nfnl_osf.c
@@ -19,6 +19,8 @@
* Based on iptables/utils/nfnl_osf.c.
*/
+#include <nft.h>
+
#include <sys/time.h>
#include <ctype.h>
diff --git a/src/nftutils.c b/src/nftutils.c
index 13f879dd..14cb1fcf 100644
--- a/src/nftutils.c
+++ b/src/nftutils.c
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
-#include <config.h>
+#include <nft.h>
#include "nftutils.h"
diff --git a/src/numgen.c b/src/numgen.c
index 256514d1..3029fa58 100644
--- a/src/numgen.c
+++ b/src/numgen.c
@@ -8,6 +8,8 @@
* later) as published by the Free Software Foundation.
*/
+#include <nft.h>
+
#include <nftables.h>
#include <expression.h>
#include <datatype.h>
diff --git a/src/optimize.c b/src/optimize.c
index 7ca57ce7..0b99b672 100644
--- a/src/optimize.c
+++ b/src/optimize.c
@@ -11,7 +11,8 @@
* programme.
*/
-#define _GNU_SOURCE
+#include <nft.h>
+
#include <string.h>
#include <errno.h>
#include <inttypes.h>
diff --git a/src/osf.c b/src/osf.c
index c611b542..6f5ed9bc 100644
--- a/src/osf.c
+++ b/src/osf.c
@@ -6,6 +6,8 @@
* later) as published by the Free Software Foundation.
*/
+#include <nft.h>
+
#include <nftables.h>
#include <expression.h>
#include <utils.h>
diff --git a/src/owner.c b/src/owner.c
index c34b0c15..be1756a6 100644
--- a/src/owner.c
+++ b/src/owner.c
@@ -6,6 +6,8 @@
* later) as published by the Free Software Foundation.
*/
+#include <nft.h>
+
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
diff --git a/src/parser_json.c b/src/parser_json.c
index 92cffee9..323d15bb 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -6,7 +6,8 @@
* later) as published by the Free Software Foundation.
*/
-#define _GNU_SOURCE
+#include <nft.h>
+
#include <errno.h>
#include <stdint.h> /* needed by gmputil.h */
#include <string.h>
diff --git a/src/payload.c b/src/payload.c
index 7862745b..9fdbf499 100644
--- a/src/payload.c
+++ b/src/payload.c
@@ -10,6 +10,8 @@
* Development of this code funded by Astaro AG (http://www.astaro.com/)
*/
+#include <nft.h>
+
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
diff --git a/src/print.c b/src/print.c
index 4896e13c..8aefa961 100644
--- a/src/print.c
+++ b/src/print.c
@@ -6,6 +6,8 @@
* later) as published by the Free Software Foundation.
*/
+#include <nft.h>
+
#include <stdarg.h>
#include <nftables.h>
#include <utils.h>
diff --git a/src/proto.c b/src/proto.c
index edf99e84..eb9c3ea1 100644
--- a/src/proto.c
+++ b/src/proto.c
@@ -9,6 +9,8 @@
*
*/
+#include <nft.h>
+
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
diff --git a/src/rt.c b/src/rt.c
index d7aa5edd..33820d4c 100644
--- a/src/rt.c
+++ b/src/rt.c
@@ -8,6 +8,8 @@
* published by the Free Software Foundation.
*/
+#include <nft.h>
+
#include <errno.h>
#include <stddef.h>
#include <stdlib.h>
diff --git a/src/rule.c b/src/rule.c
index b59fcd3a..f2c4768e 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -8,6 +8,8 @@
* Development of this code funded by Astaro AG (http://www.astaro.com/)
*/
+#include <nft.h>
+
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
diff --git a/src/scanner.l b/src/scanner.l
index c903b8c3..1aae1ecb 100644
--- a/src/scanner.l
+++ b/src/scanner.l
@@ -10,6 +10,8 @@
%{
+#include <nft.h>
+
#include <limits.h>
#include <glob.h>
#include <netinet/in.h>
diff --git a/src/sctp_chunk.c b/src/sctp_chunk.c
index 6e73e72f..1cd5e20a 100644
--- a/src/sctp_chunk.c
+++ b/src/sctp_chunk.c
@@ -6,6 +6,8 @@
* later) as published by the Free Software Foundation.
*/
+#include <nft.h>
+
#include <exthdr.h>
#include <sctp_chunk.h>
diff --git a/src/segtree.c b/src/segtree.c
index 0e3d111f..a265a0b3 100644
--- a/src/segtree.c
+++ b/src/segtree.c
@@ -8,6 +8,8 @@
* Development of this code funded by Astaro AG (http://www.astaro.com/)
*/
+#include <nft.h>
+
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
diff --git a/src/socket.c b/src/socket.c
index 356557b4..8a149e63 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -8,6 +8,8 @@
* later) as published by the Free Software Foundation.
*/
+#include <nft.h>
+
#include <nftables.h>
#include <expression.h>
#include <socket.h>
diff --git a/src/statement.c b/src/statement.c
index 9ca7e208..e6ea43d0 100644
--- a/src/statement.c
+++ b/src/statement.c
@@ -8,6 +8,8 @@
* Development of this code funded by Astaro AG (http://www.astaro.com/)
*/
+#include <nft.h>
+
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
diff --git a/src/tcpopt.c b/src/tcpopt.c
index c3e07d78..5dd760a5 100644
--- a/src/tcpopt.c
+++ b/src/tcpopt.c
@@ -1,3 +1,5 @@
+#include <nft.h>
+
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
diff --git a/src/utils.c b/src/utils.c
index a5815018..d2841f34 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -8,6 +8,8 @@
* Development of this code funded by Astaro AG (http://www.astaro.com/)
*/
+#include <nft.h>
+
#include <stddef.h>
#include <stdlib.h>
#include <stdarg.h>
diff --git a/src/xfrm.c b/src/xfrm.c
index b27821a9..041c0ce7 100644
--- a/src/xfrm.c
+++ b/src/xfrm.c
@@ -8,6 +8,8 @@
* later) as published by the Free Software Foundation.
*/
+#include <nft.h>
+
#include <nftables.h>
#include <erec.h>
#include <expression.h>
diff --git a/src/xt.c b/src/xt.c
index b17aafd5..df7140b4 100644
--- a/src/xt.c
+++ b/src/xt.c
@@ -7,6 +7,8 @@
* later) as published by the Free Software Foundation.
*/
+#include <nft.h>
+
#include <stdlib.h>
#include <time.h>
#include <string.h>