]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: add <nft.h> header and include it as first
authorThomas Haller <thaller@redhat.com>
Fri, 25 Aug 2023 11:36:30 +0000 (13:36 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 25 Aug 2023 12:59:19 +0000 (14:59 +0200)
<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>
54 files changed:
include/Makefile.am
include/cli.h
include/gmputil.h
include/nft.h [new file with mode: 0644]
include/utils.h
src/cache.c
src/cli.c
src/cmd.c
src/ct.c
src/datatype.c
src/dccpopt.c
src/erec.c
src/evaluate.c
src/expression.c
src/exthdr.c
src/fib.c
src/gmputil.c
src/hash.c
src/iface.c
src/intervals.c
src/ipopt.c
src/json.c
src/libnftables.c
src/main.c
src/mergesort.c
src/meta.c
src/mini-gmp.c
src/misspell.c
src/mnl.c
src/monitor.c
src/netlink.c
src/netlink_delinearize.c
src/netlink_linearize.c
src/nfnl_osf.c
src/nftutils.c
src/numgen.c
src/optimize.c
src/osf.c
src/owner.c
src/parser_json.c
src/payload.c
src/print.c
src/proto.c
src/rt.c
src/rule.c
src/scanner.l
src/sctp_chunk.c
src/segtree.c
src/socket.c
src/statement.c
src/tcpopt.c
src/utils.c
src/xfrm.c
src/xt.c

index 1d20f404dbfe3080cc31e8321f0335751142562b..162807b03900db1ad7ba793d805aea7efe275eb8 100644 (file)
@@ -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          \
index c854948e4a16d617016b060ce35e2b220f2b5e37..f0a0d47a645f79e30a6090f3793190f08b4c582d 100644 (file)
@@ -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);
index 0cb85a7d07930f541772f289a656365e011b1e42..c524aced16acf120b38c4b4d5c95e813e27e0086 100644 (file)
@@ -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 (file)
index 0000000..4e66f8e
--- /dev/null
@@ -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 */
index d5073e061033c642acf98f25db5236e2fde91fb6..6764f9219ada1abddb0218df1ff8be725cb0bf0f 100644 (file)
@@ -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;
index db9a9a75074a9a2c297d21238a024faf7b23e77e..3fe6bb4077960c094048bfeea428a68be9f284f9 100644 (file)
@@ -6,6 +6,8 @@
  * later) as published by the Free Software Foundation.
  */
 
+#include <nft.h>
+
 #include <expression.h>
 #include <statement.h>
 #include <rule.h>
index 5f7e01ff963149b40a8c89f4f7471f50cca1c31c..bfae90e67554dfc95fca357f1aec9b87ace94fca 100644 (file)
--- 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>
index 98216d54e78d67fd78e9c8ceb81c735e3fd76619..98859674d24b933471a0be7201536ec27bb87dd5 100644 (file)
--- 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>
index 64327561d08920490c1972edc5a346f8eca5f586..ca35087ad7b7583f0de51025abc726413ad31a15 100644 (file)
--- 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>
index 64396db82a7e52e027f3c9a9d61048361e73d2f2..dd6a5fbf5df8037c36b1d526ed27f9520ef050d6 100644 (file)
@@ -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>
index 3a2eb9524a20722eb8c500c72e89d5b2b65a3df1..d713d9034c9202274e8165209acd3149a79d2b32 100644 (file)
@@ -1,3 +1,5 @@
+#include <nft.h>
+
 #include <stddef.h>
 #include <stdint.h>
 
index aebb8632583a11f937ee7cee60036d3fc433f58a..d26dee602e8a4c6809419624fdebacc3f53780e5 100644 (file)
@@ -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>
index 2b158aee720bd7726f932b32a404b887237bee85..69a123511be8ccd5e13021b6fca6401a28ce2162 100644 (file)
@@ -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>
index 34902c842d16e960b22716a1ca939e36028f7f81..8ef008910da59a7caa1744cbd60223c2de386b2f 100644 (file)
@@ -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>
index 0358005b1b89440d8f13821a4ae43e39892bc658..dd8c758153145ef18280bb865ee49c05765a5500 100644 (file)
@@ -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>
index 98c5786891f71cff5aaea81aa5f2e9deeb4422df..b977fe28e8034cba90def89c5fc7cfb5641a781a 100644 (file)
--- 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>
index b356460fa739ca48ac421e0a4c4c35061d6e24ad..9cda18534d0add982bf22e0d24ea6173c5925336 100644 (file)
@@ -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>
index a3fd0872c3b9606417836bde1daf218e4476f47c..1c8c00aa149110378f9f9a60ac1578bb0bbe0769 100644 (file)
@@ -8,6 +8,8 @@
  * later) as published by the Free Software Foundation.
  */
 
+#include <nft.h>
+
 #include <nftables.h>
 #include <expression.h>
 #include <datatype.h>
index 3647778c1f0d7d1db025c47d3fb48e24923cf4a8..ec7f5c7f4cd9579c68319767ea3a5b9b21c18140 100644 (file)
@@ -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>
index d79c52c58710a77a53a920648ef2d1c6fb0ba26d..85de0199c373a88858bc48b0f259847ef2f0e1a5 100644 (file)
@@ -6,6 +6,8 @@
  * later) as published by the Free Software Foundation.
  */
 
+#include <nft.h>
+
 #include <nftables.h>
 #include <expression.h>
 #include <intervals.h>
index 67e904ff3d88f5c882fa4fc6f1922861031991ad..3ba67b011166f3d3bf209fa63bf06446d727d865 100644 (file)
@@ -1,3 +1,5 @@
+#include <nft.h>
+
 #include <stdint.h>
 
 #include <netinet/in.h>
index 31dd185666b141a6322ac9e74c44aebb52779d56..446575c2afc047dc3196f8b7fb65be17fd649f2d 100644 (file)
@@ -6,7 +6,8 @@
  * later) as published by the Free Software Foundation.
  */
 
-#define _GNU_SOURCE
+#include <nft.h>
+
 #include <stdio.h>
 #include <string.h>
 
index 69ea9d4135b703a2ab4378fd71adf8c177648de0..9c802ec95f27adad5de2bad7b3dd8b16c7f308f7 100644 (file)
@@ -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>
index 40dc60c2258cc5d1cf4445d81d79a27d61212181..260338d320ab2ee1976f73543256fcdff9acd341 100644 (file)
@@ -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>
index a3a9d6050ccb0758297c3d868bd5adb83e8f3bba..9315093b3359931d1b1747e8a24587e52a4d7e6d 100644 (file)
@@ -6,6 +6,8 @@
  * later) as published by the Free Software Foundation.
  */
 
+#include <nft.h>
+
 #include <stdint.h>
 #include <expression.h>
 #include <gmputil.h>
index 8508b11e70cea418a14be3c664b58692c18fa962..fcb872e669df64a51f40d40fd6c33c3c3ee184c1 100644 (file)
@@ -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>
index 04bed3f51ddbcce15d2ee1765fc5e3bc1b5b2fb1..6217f745465172431f9ffdd93d5713411be1b980 100644 (file)
@@ -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>
index 8992c75e7bc1aa748c02248fa009eaf7c087b1d2..18da4386ea5b62e5189cde9113b6d747618587d5 100644 (file)
@@ -6,6 +6,8 @@
  * later) as published by the Free Software Foundation.
  */
 
+#include <nft.h>
+
 #include <stdlib.h>
 #include <string.h>
 #include <limits.h>
index 9406fc4821236be9e907ce4009da8033a179b830..d583177d5490a1219c99f81a8357cece905fd431 100644 (file)
--- 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>
index 3a1896917923f6c0c9b1b46adc08c975356b0d7d..0554089b74ac64d48fd882fc26834c1711a835e6 100644 (file)
@@ -6,6 +6,8 @@
  * later) as published by the Free Software Foundation.
  */
 
+#include <nft.h>
+
 #include <string.h>
 #include <fcntl.h>
 #include <errno.h>
index ed61cd896511a0c193d42d62face596bfd544290..e1904a99d3baaa7d0778965f05c0944ad2682c06 100644 (file)
@@ -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>
index 125b6c685f803dfce6cfb7690adb7a43eb302249..dfa816cfdfb6b3b6d945ab6924e0f581942c9714 100644 (file)
@@ -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>
index f5b2d6bb6cea178fe4a81bdf1b339b49e63702ba..53a318aa2e6210e5bd606faeeb95506ad6acc12b 100644 (file)
@@ -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>
 
index 08e978de2f67f9ec4f130a350983d499f1086f8c..48e83ea8a5497bc4aa83c32bd25b2d3cbaf76b25 100644 (file)
@@ -19,6 +19,8 @@
  * Based on iptables/utils/nfnl_osf.c.
  */
 
+#include <nft.h>
+
 #include <sys/time.h>
 
 #include <ctype.h>
index 13f879ddc5c75cd3431efe2fbea47db8cdb7f058..14cb1fcf07de99a9f823695bd436290df19f8c2c 100644 (file)
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
 
-#include <config.h>
+#include <nft.h>
 
 #include "nftutils.h"
 
index 256514d146717b0c97292b4ef9dadfe26f487781..3029fa58cc493540cf22f5f1c5bfa1b209fd4472 100644 (file)
@@ -8,6 +8,8 @@
  * later) as published by the Free Software Foundation.
  */
 
+#include <nft.h>
+
 #include <nftables.h>
 #include <expression.h>
 #include <datatype.h>
index 7ca57ce73873eb4496f4db650c305fa2a022f208..0b99b6726115b5baea76221b8801c01e1158aa5e 100644 (file)
@@ -11,7 +11,8 @@
  * programme.
  */
 
-#define _GNU_SOURCE
+#include <nft.h>
+
 #include <string.h>
 #include <errno.h>
 #include <inttypes.h>
index c611b542206d1549962aa42ef2d9877d72a05599..6f5ed9bc895a15c587aa9720afef2fddc9a7423d 100644 (file)
--- 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>
index c34b0c1501fa20b4c661d053aac41c544f4136bd..be1756a68c75ad83fecd1289989ff3c945680c4b 100644 (file)
@@ -6,6 +6,8 @@
  * later) as published by the Free Software Foundation.
  */
 
+#include <nft.h>
+
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
index 92cffee905e304e827ef85894f0578c072e57a7c..323d15bb5b7117e87b4809834b5f8759385766b1 100644 (file)
@@ -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>
index 7862745b2035bba363dafd6e4a205f936125ff7a..9fdbf4997c4e994223503a6360d3ba85a8b34611 100644 (file)
@@ -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>
index 4896e13c2ca55a4ffff665f31d8196735bcc083b..8aefa961fb24c69925997a5031562d0d2a23d4b6 100644 (file)
@@ -6,6 +6,8 @@
  * later) as published by the Free Software Foundation.
  */
 
+#include <nft.h>
+
 #include <stdarg.h>
 #include <nftables.h>
 #include <utils.h>
index edf99e840c0cc6bd973b51a5140c74b4d907525c..eb9c3ea18e682e4fa935e7ecb3cf3b8849a8ab44 100644 (file)
@@ -9,6 +9,8 @@
  *
  */
 
+#include <nft.h>
+
 #include <stddef.h>
 #include <stdlib.h>
 #include <stdint.h>
index d7aa5edd93a3c6312da31a94826f8533e5e1f8ff..33820d4c871934291f248c28dca4a4c482164836 100644 (file)
--- 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>
index b59fcd3a9fa8d9f6c6b8e2a282cc42d714fc0f3d..f2c4768e01ab30999306c51a22b2e950652097ba 100644 (file)
@@ -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>
index c903b8c3e02d9b190eebc503cef302049d4f09e0..1aae1ecb09ef03c32b92ecbf878d84d1bc92482c 100644 (file)
@@ -10,6 +10,8 @@
 
 %{
 
+#include <nft.h>
+
 #include <limits.h>
 #include <glob.h>
 #include <netinet/in.h>
index 6e73e72f8308b810c7106547466c5241c633407f..1cd5e20abf78e638414f8fa69a0d695b13f196c2 100644 (file)
@@ -6,6 +6,8 @@
  * later) as published by the Free Software Foundation.
  */
 
+#include <nft.h>
+
 #include <exthdr.h>
 #include <sctp_chunk.h>
 
index 0e3d111fb7aba4a91a2a1af99e4ce5e3ecd4cf28..a265a0b30d64ce420823640396d473e5e52cc365 100644 (file)
@@ -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>
index 356557b4dbed982e92c39f9354d5f7248aa31e11..8a149e63dd73244e18748f3a325b125430a5e0e5 100644 (file)
@@ -8,6 +8,8 @@
  * later) as published by the Free Software Foundation.
  */
 
+#include <nft.h>
+
 #include <nftables.h>
 #include <expression.h>
 #include <socket.h>
index 9ca7e208cf795268369dbb7524af8c6e1abc0867..e6ea43d0a4d11fdd66a3730dff869574640c104b 100644 (file)
@@ -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>
index c3e07d7889ab4724934d026aad9220d2a7d16f42..5dd760a51aabfe62e12037edb648445c302118fa 100644 (file)
@@ -1,3 +1,5 @@
+#include <nft.h>
+
 #include <stddef.h>
 #include <stdlib.h>
 #include <stdio.h>
index a5815018c775c17c055aee40fbf50d1ace9e0b81..d2841f3469b593ab19419ccc2d72f407f8a92b53 100644 (file)
@@ -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>
index b27821a922f58a6641af11ae837db23cbd7b9b92..041c0ce7ac6d9904edcb3775a0fbf5fc2172ebd9 100644 (file)
@@ -8,6 +8,8 @@
  * later) as published by the Free Software Foundation.
  */
 
+#include <nft.h>
+
 #include <nftables.h>
 #include <erec.h>
 #include <expression.h>
index b17aafd5653828e037adc6538162f5b81a5acb14..df7140b4fa977cd66e5a2a02bd3f5fef0c6873ef 100644 (file)
--- 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>