Skip to contentSkip to conversation

libnftables: Split code into frontend and library

PATCH In review Phil Sutter 2 participants 4 messages Nov 14, 2017 – Nov 16, 2017

Subsystems (2)
lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/1 libnftables: Split code into frontend and library

This finally creates the libnftables shared object.

For some reason, this causes two compiler warnings to appear:

| parser_bison.y: In function 'nft_parse':
| parser_bison.y:131:3: warning: implicit declaration of function 'nft_set_debug' [-Wimplicit-function-declaration]
|    nft_set_debug(1, scanner);
|    ^~~~~~~~~~~~~
| parser_bison.c:64:25: warning: implicit declaration of function 'nft_lex' [-Wimplicit-function-declaration]
|  #define yylex           nft_lex
|                          ^
| parser_bison.c:4745:16: note: in expansion of macro 'yylex'
|        yychar = yylex (&yylval, &yylloc, scanner);

So this patch contains a workaround, namely declaring both functions in src/parser_bison.y. During linking the objects are found, so this is rather a matter of cosmetics.

---
 .gitignore         |  3 +++
 Makefile.am        |  3 +++
 configure.ac       |  4 ++++
 libnftables.pc.in  | 15 +++++++++++++++
 src/.gitignore     |  1 +
 src/Makefile.am    | 24 +++++++++++++++---------
 src/parser_bison.y |  4 ++++
 7 files changed, 45 insertions(+), 9 deletions(-)
 create mode 100644 libnftables.pc.in
.gitignore +3 -0
index 009f7d005afa1..64af328e0abf9 100644
@@ -1,5 +1,6 @@
 # Dependency and object files
 .*.d
+*.lo
 *.o
 
 # Generated by autoconf/configure/automake
@@ -8,6 +9,7 @@ Makefile
 Makefile.in
 src/Makefile.in
 src/.deps/
+src/.libs/
 stamp-h1
 config.h
 config.h.in
@@ -17,6 +19,7 @@ config.status
 configure
 autom4te.cache
 build-aux/
+libnftables.pc
 libtool
 missing
 depcomp
Makefile.am +3 -0
index 10aa40f14127f..9af25ded836b8 100644
@@ -6,3 +6,6 @@ SUBDIRS = 	src	\
 		files
 
 EXTRA_DIST =	tests
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = libnftables.pc
configure.ac +4 -0
index 099a4a5e81ec6..a97d9e73270dc 100644
@@ -56,6 +56,9 @@ then
         exit 1
 fi
 
+AM_PROG_AR
+AM_PROG_LIBTOOL
+
 AC_CHECK_PROG(DOCBOOK2X_MAN, [docbook2x-man], [docbook2x-man], [no])
 AC_CHECK_PROG(DOCBOOK2MAN, [docbook2man], [docbook2man], [no])
 AC_CHECK_PROG(DB2X_DOCBOOK2MAN, [db2x_docbook2man], [db2x_docbook2man], [no])
@@ -138,6 +141,7 @@ AC_CHECK_FUNCS([memmove memset strchr strdup strerror strtoull])
 
 AC_CONFIG_FILES([					\
 		Makefile				\
+		libnftables.pc				\
 		src/Makefile				\
 		include/Makefile			\
 		include/nftables/Makefile		\
libnftables.pc.in new file +15 -0
new file mode 100644
index 0000000000000..6431d48cf6f2c
@@ -0,0 +1,15 @@
+# libnftables pkg-config file
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libnftables
+Description: Netfilter nf_tables user library
+URL: http://netfilter.org/projects/nftables/
+Version: @VERSION@
+Requires:
+Conflicts:
+Libs: -L${libdir} -lnftables
+Cflags: -I${includedir}
src/.gitignore +1 -0
index 23e6ae030f107..36d6acd1e4d01 100644
@@ -1,3 +1,4 @@
+libnftables.la
 parser.c
 parser.h
 scanner.c
src/Makefile.am +15 -9
index 4d613a731dfb9..9f7a4bfbb90a4 100644
@@ -27,7 +27,9 @@ parser_bison.o scanner.o: AM_CFLAGS += -Wno-missing-prototypes -Wno-missing-decl
 
 BUILT_SOURCES = parser_bison.h
 
-nft_SOURCES =	main.c				\
+lib_LTLIBRARIES = libnftables.la
+
+libnftables_la_SOURCES =			\
 		rule.c				\
 		statement.c			\
 		datatype.c			\
@@ -59,19 +61,23 @@ nft_SOURCES =	main.c				\
 		parser_bison.y			\
 		libnftables.c
 
-if BUILD_CLI
-nft_SOURCES +=	cli.c
-endif
-
 if BUILD_MINIGMP
 mini-gmp.o: AM_CFLAGS += -Wno-sign-compare
 
-nft_SOURCES +=	mini-gmp.c
+libnftables_la_SOURCES += mini-gmp.c
 endif
 
-nft_LDADD	= ${LIBMNL_LIBS} ${LIBNFTNL_LIBS}
+libnftables_la_LIBADD = ${LIBMNL_LIBS} ${LIBNFTNL_LIBS}
 
 if BUILD_XTABLES
-nft_SOURCES +=	xt.c
-nft_LDADD   +=  ${XTABLES_LIBS}
+libnftables_la_SOURCES += xt.c
+libnftables_la_LIBADD += ${XTABLES_LIBS}
 endif
+
+nft_SOURCES = main.c
+
+if BUILD_CLI
+nft_SOURCES += cli.c
+endif
+
+nft_LDADD = libnftables.la
src/parser_bison.y +4 -0
index 2c59fa784585a..c64c3979eb041 100644
@@ -105,6 +105,10 @@ static void location_update(struct location *loc, struct location *rhs, int n)
 
 #define symbol_value(loc, str) \
 	symbol_expr_alloc(loc, SYMBOL_VALUE, current_scope(state), str)
+
+/* Declare those here to avoid compiler warnings */
+void nft_set_debug(int, void *);
+int nft_lex(void *, void *, void *);
 %}
 
 /* Declaration section */
Signature · 1 line
2.13.1
#1 lore raw
Quoted 14 lines · Phil Sutter

This finally creates the libnftables shared object.

For some reason, this causes two compiler warnings to appear:

| parser_bison.y: In function 'nft_parse':
| parser_bison.y:131:3: warning: implicit declaration of function 'nft_set_debug' [-Wimplicit-function-declaration]
|    nft_set_debug(1, scanner);
|    ^~~~~~~~~~~~~
| parser_bison.c:64:25: warning: implicit declaration of function 'nft_lex' [-Wimplicit-function-declaration]
|  #define yylex           nft_lex
|                          ^
| parser_bison.c:4745:16: note: in expansion of macro 'yylex'
|        yychar = yylex (&yylval, &yylloc, scanner);
Quoted 3 lines

So this patch contains a workaround, namely declaring both functions in src/parser_bison.y. During linking the objects are found, so this is rather a matter of cosmetics.

Also applied, thanks Phil.

Upfront warning: I will not consider this API stable until we make the 0.9 release, so we have a bit more time to make API changes.

#2 lore raw
Quoted 15 lines · Pablo Neira Ayuso
Quoted 14 lines · Phil Sutter

This finally creates the libnftables shared object.

For some reason, this causes two compiler warnings to appear:

| parser_bison.y: In function 'nft_parse':
| parser_bison.y:131:3: warning: implicit declaration of function 'nft_set_debug' [-Wimplicit-function-declaration]
|    nft_set_debug(1, scanner);
|    ^~~~~~~~~~~~~
| parser_bison.c:64:25: warning: implicit declaration of function 'nft_lex' [-Wimplicit-function-declaration]
|  #define yylex           nft_lex
|                          ^
| parser_bison.c:4745:16: note: in expansion of macro 'yylex'
|        yychar = yylex (&yylval, &yylloc, scanner);
Quoted 5 lines
Quoted 3 lines

So this patch contains a workaround, namely declaring both functions in src/parser_bison.y. During linking the objects are found, so this is rather a matter of cosmetics.

Also applied, thanks Phil.

This message is popping up here:

CCLD libnftables.la
ar: u' modifier ignored since D' is the default (see `U')

author reviewer
#3 lore raw
Quoted 20 lines · Pablo Neira Ayuso
Quoted 19 lines · Pablo Neira Ayuso
Quoted 17 lines · Phil Sutter

This finally creates the libnftables shared object.

For some reason, this causes two compiler warnings to appear:

| parser_bison.y: In function 'nft_parse':
| parser_bison.y:131:3: warning: implicit declaration of function 'nft_set_debug' [-Wimplicit-function-declaration]
|    nft_set_debug(1, scanner);
|    ^~~~~~~~~~~~~
| parser_bison.c:64:25: warning: implicit declaration of function 'nft_lex' [-Wimplicit-function-declaration]
|  #define yylex           nft_lex
|                          ^
| parser_bison.c:4745:16: note: in expansion of macro 'yylex'
|        yychar = yylex (&yylval, &yylloc, scanner);

So this patch contains a workaround, namely declaring both functions in src/parser_bison.y. During linking the objects are found, so this is rather a matter of cosmetics.

Quoted 6 lines
Quoted 1 line

Also applied, thanks Phil.

This message is popping up here:

CCLD libnftables.la
ar: u' modifier ignored since D' is the default (see `U')

Looks like an automake bug on your system? (Googling turned this up:
https://bugzilla.redhat.com/show_bug.cgi?id=1155273). I don't see the warning on my machine at least.

Cheers, Phil

Quoted 1 line