]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
main: add more information to `nft -V`.
authorJeremy Sowden <jeremy@azazel.net>
Tue, 3 Mar 2020 23:15:30 +0000 (00:15 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 5 Mar 2020 11:39:50 +0000 (12:39 +0100)
In addition to the package-version and release-name, output the CLI
implementation (if any) and whether mini-gmp was used, e.g.:

    $ ./src/nft -V
    nftables v0.9.3 (Topsy)
      cli:          linenoise
      json:         yes
      minigmp:      no
      libxtables:   yes

[pablo@netfilter.org: add json and libxtables, use -V ]

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/Makefile.am
src/main.c

index 9142ab4484f233bcf32aeadfd3e6cf4e778660b0..3041a933bc0671a9dd83ee482bc46128e6198985 100644 (file)
@@ -13,6 +13,15 @@ endif
 if BUILD_XTABLES
 AM_CPPFLAGS += ${XTABLES_CFLAGS}
 endif
+if BUILD_MINIGMP
+AM_CPPFLAGS += -DHAVE_MINIGMP
+endif
+if BUILD_JSON
+AM_CPPFLAGS += -DHAVE_JSON
+endif
+if BUILD_XTABLES
+AM_CPPFLAGS += -DHAVE_XTABLES
+endif
 
 AM_CFLAGS = -Wall                                                              \
            -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations     \
index 6ab1b89f4dd57747096d66c3ed70a2064b23312d..fefa3186a4c117c03c9f8a7c17c46fdfc9e414b6 100644 (file)
@@ -27,6 +27,7 @@ static struct nft_ctx *nft;
 enum opt_vals {
        OPT_HELP                = 'h',
        OPT_VERSION             = 'v',
+       OPT_VERSION_LONG        = 'V',
        OPT_CHECK               = 'c',
        OPT_FILE                = 'f',
        OPT_INTERACTIVE         = 'i',
@@ -46,7 +47,7 @@ enum opt_vals {
        OPT_TERSE               = 't',
        OPT_INVALID             = '?',
 };
-#define OPTSTRING      "+hvd:cf:iI:jvnsNaeSupypTt"
+#define OPTSTRING      "+hvVd:cf:iI:jvnsNaeSupypTt"
 
 static const struct option options[] = {
        {
@@ -141,6 +142,7 @@ static void show_help(const char *name)
 "Options:\n"
 "  -h, --help                  Show this help\n"
 "  -v, --version                       Show version information\n"
+"  -V                          Show extended version information\n"
 "\n"
 "  -c, --check                 Check commands validity without actually applying the changes.\n"
 "  -f, --file <filename>               Read input from <filename>\n"
@@ -164,6 +166,45 @@ static void show_help(const char *name)
        name, DEFAULT_INCLUDE_PATH);
 }
 
+static void show_version(void)
+{
+       const char *cli, *minigmp, *json, *xt;
+
+#if defined(HAVE_LIBREADLINE)
+       cli = "readline";
+#elif defined(HAVE_LIBLINENOISE)
+       cli = "linenoise";
+#else
+       cli = "no";
+#endif
+
+#if defined(HAVE_MINIGMP)
+       minigmp = "yes";
+#else
+       minigmp = "no";
+#endif
+
+#if defined(HAVE_JSON)
+       json = "yes";
+#else
+       json = "no";
+#endif
+
+#if defined(HAVE_XTABLES)
+       xt = "yes";
+#else
+       xt = "no";
+#endif
+
+       printf("%s v%s (%s)\n"
+              "  cli:          %s\n"
+              "  json:         %s\n"
+              "  minigmp:      %s\n"
+              "  libxtables:   %s\n",
+              PACKAGE_NAME, PACKAGE_VERSION, RELEASE_NAME,
+              cli, minigmp, json, xt);
+}
+
 static const struct {
        const char              *name;
        enum nft_debug_level    level;
@@ -272,6 +313,9 @@ int main(int argc, char * const *argv)
                        printf("%s v%s (%s)\n",
                               PACKAGE_NAME, PACKAGE_VERSION, RELEASE_NAME);
                        exit(EXIT_SUCCESS);
+               case OPT_VERSION_LONG:
+                       show_version();
+                       exit(EXIT_SUCCESS);
                case OPT_CHECK:
                        nft_ctx_set_dry_run(nft, true);
                        break;