diff options
author | Thomas Haller <thaller@redhat.com> | 2023-08-25 13:36:30 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2023-08-25 14:59:19 +0200 |
commit | b4add075c1283151d0514cf0052f9184e9e073df (patch) | |
tree | 7798c59dbe1ec7b982f7adcd4a6357aa436b20d3 /include | |
parent | 19231d4c896571fea397d43568c4b3562969c7e2 (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>
Diffstat (limited to 'include')
-rw-r--r-- | include/Makefile.am | 3 | ||||
-rw-r--r-- | include/cli.h | 1 | ||||
-rw-r--r-- | include/gmputil.h | 2 | ||||
-rw-r--r-- | include/nft.h | 9 | ||||
-rw-r--r-- | include/utils.h | 1 |
5 files changed, 11 insertions, 5 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; |