Skip to contentSkip to conversation

Add Linenoise support to the CLI.

PATCH Applied Jeremy Sowden 4 participants 9 messages Sep 24, 2019 – Oct 16, 2019 netfilter

lore
Share & tools
lore
#0 lore raw

v2 cover Add Linenoise support to the CLI.

Sebastian Priebe [0] requested Linenoise support for the CLI as an alternative to Readline, so I thought I'd have a go at providing it. Linenoise is a minimal, zero-config, BSD licensed, Readline replacement used in Redis, MongoDB, and Android [1].

0 - https://lore.kernel.org/netfilter-devel/[email protected]/
1 - https://github.com/antirez/linenoise/

By default, the CLI continues to be build using Readline, but passing --with-cli=linenoise instead causes Linenoise to be used instead.

nft -v has been extended to display what CLI implementation was built and whether mini-gmp was used.

Changes since v1:

* dropped the linenoise source from the nftables tree and added an AC_CHECK_LIB check instead.

Changes since RFC:

* two tidy-up patches dropped because they have already been applied;
* source now added to include/ and src/;
* tests/build/run-tests.sh updated to test --with-cli=linenoise;
* nft -v extended.

Jeremy Sowden (2):
cli: add linenoise CLI implementation.
main: add more information to nft -v.

 configure.ac             | 17 ++++++++---
 include/cli.h            |  2 +-
 src/Makefile.am          |  3 ++
 src/cli.c                | 64 ++++++++++++++++++++++++++++++++++------
 src/main.c               | 28 ++++++++++++++++--
 tests/build/run-tests.sh |  4 +--
 6 files changed, 100 insertions(+), 18 deletions(-)
Signature · 1 line
2.23.0
#1 lore raw

PATCH v2 1/2 cli: add linenoise CLI implementation.

By default, continue to use libreadline, but if --with-cli=linenoise is passed to configure, build the linenoise implementation instead.

---
 configure.ac             | 17 ++++++++---
 include/cli.h            |  2 +-
 src/cli.c                | 64 ++++++++++++++++++++++++++++++++++------
 tests/build/run-tests.sh |  4 +--
 4 files changed, 71 insertions(+), 16 deletions(-)
configure.ac +13 -4
index 68f97f090535..73654b005cd2 100644
@@ -68,12 +68,21 @@ AC_CHECK_LIB([gmp],[__gmpz_init], , AC_MSG_ERROR([No suitable version of libgmp
 AM_CONDITIONAL([BUILD_MINIGMP], [test "x$with_mini_gmp" = xyes])
 
 AC_ARG_WITH([cli], [AS_HELP_STRING([--without-cli],
-            [disable interactive CLI (libreadline support)])],
-            [], [with_cli=yes])
-AS_IF([test "x$with_cli" != xno], [
+            [disable interactive CLI (libreadline or linenoise support)])],
+            [], [with_cli=readline])
+
+AS_IF([test "x$with_cli" = xreadline], [
 AC_CHECK_LIB([readline], [readline], ,
-	     AC_MSG_ERROR([No suitable version of libreadline found]))
+        AC_MSG_ERROR([No suitable version of libreadline found]))
 AC_DEFINE([HAVE_LIBREADLINE], [1], [])
+],
+      [test "x$with_cli" = xlinenoise], [
+AC_CHECK_LIB([linenoise], [linenoise], ,
+        AC_MSG_ERROR([No suitable version of linenoise found]))
+AC_DEFINE([HAVE_LIBLINENOISE], [1], [])
+],
+      [test "x$with_cli" != xno], [
+AC_MSG_ERROR([unexpected CLI value: $with_cli])
 ])
 AM_CONDITIONAL([BUILD_CLI], [test "x$with_cli" != xno])
 
include/cli.h +1 -1
index 023f004b8dab..d82517750abc 100644
@@ -4,7 +4,7 @@
 #include <nftables/libnftables.h>
 #include <config.h>
 
-#ifdef HAVE_LIBREADLINE
+#if defined(HAVE_LIBREADLINE) || defined(HAVE_LIBLINENOISE)
 extern int cli_init(struct nft_ctx *nft);
 #else
 static inline int cli_init(struct nft_ctx *nft)
src/cli.c +55 -9

101 lines not on this page · raw message

tests/build/run-tests.sh +2 -2
index b0560da61398..ccb62af3d8dd 100755
@@ -2,8 +2,8 @@
 
 log_file="`pwd`/tests.log"
 dir=../..
-argument=( --without-cli --enable-debug --with-mini-gmp --enable-man-doc
-	    --with-xtables --with-json)
+argument=( --without-cli --with-cli=linenoise --enable-debug --with-mini-gmp
+	   --enable-man-doc --with-xtables --with-json)
 ok=0
 failed=0
 
Signature · 1 line
2.23.0
maintainer Applied
#2 lore raw

Re: [PATCH nftables v2 1/2] cli: add linenoise CLI implementation.

Quoted 2 lines · Jeremy Sowden

By default, continue to use libreadline, but if --with-cli=linenoise is passed to configure, build the linenoise implementation instead.

Applied, thanks Jeremy.

#3 lore raw

Re: [PATCH nftables v2 1/2] cli: add linenoise CLI implementation.

Quoted 6 lines · Pablo Neira Ayuso
Quoted 3 lines · Jeremy Sowden

By default, continue to use libreadline, but if --with-cli=linenoise is passed to configure, build the linenoise implementation instead.

Applied, thanks Jeremy.

Thanks, Pablo. Don't know whether you change your mind about it, but there was a second patch with changes to nft -v that you suggested:

https://lore.kernel.org/netfilter-devel/[email protected]/

Need to find something else to do now. :) Will go and have a poke about in Bugzilla.

J.

#4 lore raw

Re: [PATCH nftables v2 1/2] cli: add linenoise CLI implementation.

Quoted 8 lines · Jeremy Sowden
Quoted 6 lines · Pablo Neira Ayuso
Quoted 3 lines · Jeremy Sowden

By default, continue to use libreadline, but if --with-cli=linenoise is passed to configure, build the linenoise implementation instead.

Applied, thanks Jeremy.

Quoted 7 lines

Thanks, Pablo. Don't know whether you change your mind about it, but there was a second patch with changes to nft -v that you suggested:

https://lore.kernel.org/netfilter-devel/[email protected]/

Need to find something else to do now. :) Will go and have a poke about in Bugzilla.

This might be useful:

https://bugzilla.netfilter.org/show_bug.cgi?id=1374

#5 lore raw

Re: [PATCH nftables v2 1/2] cli: add linenoise CLI implementation.

Quoted 13 lines · Pablo Neira Ayuso
Quoted 12 lines · Jeremy Sowden
Quoted 6 lines · Pablo Neira Ayuso
Quoted 3 lines · Jeremy Sowden

By default, continue to use libreadline, but if --with-cli=linenoise is passed to configure, build the linenoise implementation instead.

Applied, thanks Jeremy.

Thanks, Pablo. Don't know whether you change your mind about it, but there was a second patch with changes to nft -v that you suggested:

Quoted 8 lines
Quoted 4 lines

https://lore.kernel.org/netfilter-devel/[email protected]/

Need to find something else to do now. :) Will go and have a poke about in Bugzilla.

This might be useful:

https://bugzilla.netfilter.org/show_bug.cgi?id=1374

Cheers. I'll pick that up.

J.

#6 lore raw

PATCH v2 2/2 main: add more information to `nft -v`.

In reply to Jeremy Sowden

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.2 (Scram)
      cli:          linenoise
      minigmp:      no
---
 src/Makefile.am |  3 +++
 src/main.c      | 28 ++++++++++++++++++++++++++--
 2 files changed, 29 insertions(+), 2 deletions(-)
src/Makefile.am +3 -0
index 740c21f2cac8..54aed5efb7bb 100644
@@ -13,6 +13,9 @@ endif
 if BUILD_XTABLES
 AM_CPPFLAGS += ${XTABLES_CFLAGS}
 endif
+if BUILD_MINIGMP
+AM_CPPFLAGS += -DHAVE_MINIGMP
+endif
 
 AM_CFLAGS = -Wall								\
 	    -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations	\
src/main.c +26 -2
index f77d8a820a02..3334141eab35 100644
@@ -154,6 +154,31 @@ static void show_help(const char *name)
 	name, DEFAULT_INCLUDE_PATH);
 }
 
+static void show_version(void)
+{
+	const char *cli, *minigmp;
+
+#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
+
+	printf("%s v%s (%s)\n"
+	       "  cli:		%s\n"
+	       "  minigmp:	%s\n",
+	       PACKAGE_NAME, PACKAGE_VERSION, RELEASE_NAME,
+	       cli, minigmp);
+}
+
 static const struct {
 	const char		*name;
 	enum nft_debug_level	level;
@@ -213,8 +238,7 @@ int main(int argc, char * const *argv)
 			show_help(argv[0]);
 			exit(EXIT_SUCCESS);
 		case OPT_VERSION:
-			printf("%s v%s (%s)\n",
-			       PACKAGE_NAME, PACKAGE_VERSION, RELEASE_NAME);
+			show_version();
 			exit(EXIT_SUCCESS);
 		case OPT_CHECK:
 			nft_ctx_set_dry_run(nft, true);
Signature · 1 line
2.23.0
reviewer Acked-by on the v2 series
#7 lore raw
In reply to Jeremy Sowden
Quoted 5 lines · Jeremy Sowden

Sebastian Priebe [0] requested Linenoise support for the CLI as an alternative to Readline, so I thought I'd have a go at providing it. Linenoise is a minimal, zero-config, BSD licensed, Readline replacement used in Redis, MongoDB, and Android [1].

Quoted 8 lines

0 - https://lore.kernel.org/netfilter-devel/[email protected]/
1 - https://github.com/antirez/linenoise/

By default, the CLI continues to be build using Readline, but passing --with-cli=linenoise instead causes Linenoise to be used instead.

nft -v has been extended to display what CLI implementation was built and whether mini-gmp was used.

Series:

#8 lore raw
In reply to Jeremy Sowden

Hello,
I'd really would appreciate if this gets pulled soon. Are there any objections?

Until now this series was acked-by Phil Sutter.

Greetings,
Sebastian

Quoted 47 lines

-----Ursprüngliche Nachricht-----
Von: Jeremy Sowden <[email protected]>
Gesendet: Dienstag, 24. September 2019 09:41
An: Pablo Neira Ayuso <[email protected]>
Cc: Netfilter Devel <[email protected]>; Priebe, Sebastian <[email protected]>
Betreff: [PATCH nftables v2 0/2] Add Linenoise support to the CLI.

Sebastian Priebe [0] requested Linenoise support for the CLI as an alternative to Readline, so I thought I'd have a go at providing it. Linenoise is a minimal, zero-config, BSD licensed, Readline replacement used in Redis, MongoDB, and Android [1].

0 - https://lore.kernel.org/netfilter-
devel/[email protected]/
1 - https://github.com/antirez/linenoise/

By default, the CLI continues to be build using Readline, but passing --with- cli=linenoise instead causes Linenoise to be used instead.

nft -v has been extended to display what CLI implementation was built and whether mini-gmp was used.

Changes since v1:

* dropped the linenoise source from the nftables tree and added an AC_CHECK_LIB check instead.

Changes since RFC:

* two tidy-up patches dropped because they have already been applied;
* source now added to include/ and src/;
* tests/build/run-tests.sh updated to test --with-cli=linenoise;
* nft -v extended.

Jeremy Sowden (2):
cli: add linenoise CLI implementation.
main: add more information to nft -v.

 configure.ac             | 17 ++++++++---
 include/cli.h            |  2 +-
 src/Makefile.am          |  3 ++
 src/cli.c                | 64 ++++++++++++++++++++++++++++++++++------
 src/main.c               | 28 ++++++++++++++++--
 tests/build/run-tests.sh |  4 +--
 6 files changed, 100 insertions(+), 18 deletions(-)
Quoted 3 lines

--
2.23.0

SII Technologies GmbH
Geschäftsführer: Robert Bauer
Sitz der Gesellschaft: 86167 Augsburg
Registergericht: Amtsgericht Augsburg HRB 31802