Skip to contentSkip to conversation

use of pkg-config in libnetfilter_*, conntrack, and ulogd2

RFC PATCH In review KOVACS Krisztian 3 participants 4 messages Mar 19, 2006 – Jul 20, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 use of pkg-config in libnetfilter_*, conntrack, and ulogd2

Hi,

This weekend I've spent a significant amount of time configuring and
compiling the whole libnetfilter_* universe and the conntrack and ulogd2 tools. My initial plan was to install everything under /opt/netfilter, however, the out-of-the-box configure.in files provided with these modules do not make this particularly easy.

So after spending some time trying all kinds of mantras and magical
runes to get autoconfuse do what I intended to do, I came to the conclusion that all this would be much simpler if we used the PKG_CHECK_* macros in configure.in. The necessary pkgconfig .pc files are generated and installed anyway, so why not?

Of course this means that to compile these modules one will need
pkg-config, but personally I don't consider this a problem. The additional benefit of this method would be that the only thing to take care of is that of setting a correct PKG_CONFIG_PATH, all the include paths and libraries are then found magically.

Patches for libnetfilter_{conntrack,cthelper,log,queue}, conntrack and
ulogd2 attached.

Signature · 1 line
 KOVACS Krisztian
configure.in +9 -2
Index: libnetfilter_conntrack/configure.in
===================================================================
@@ -18,9 +18,12 @@
 *) AC_MSG_ERROR([Linux only, dude!]);;
 esac
 
-AC_CHECK_LIB(nfnetlink, nfnl_subsys_open, AC_MSG_RESULT(found), AC_MSG_ERROR([libnfnetlink 0.0.16 or later needed]))
-AC_CHECK_HEADER([libnfnetlink/linux_nfnetlink.h], [AC_MSG_RESULT([found])], [AC_MSG_ERROR([libnfnetlink 0.0.16 or later needed])])
+dnl Dependencies
+LIBNFNETLINK_REQUIRED=0.0.16
 
+PKG_CHECK_MODULES(LIBNFNETLINK, libnfnetlink >= $LIBNFNETLINK_REQUIRED,,
+	AC_MSG_ERROR(Cannot find libnfnetlink >= $LIBNFNETLINK_REQUIRED))
+
 AC_CHECK_HEADERS(arpa/inet.h)
 dnl Check for inet_ntop
 AC_CHECK_FUNCS(inet_ntop)
@@ -61,7 +64,11 @@
 	CFLAGS="$CFLAGS -DLIBNETFILTER_CONNTRACK_DIR=$MODULE_DIR"
 fi
 
+CFLAGS="$CFLAGS $LIBNFNETLINK_CFLAGS"
+LIBNFCONNTRACK_LIBS="$LIBNFNETLINK_LIBS"
 
+AC_SUBST(LIBNFCONNTRACK_LIBS)
+
 dnl Output the makefile
 AC_OUTPUT(Makefile src/Makefile include/Makefile utils/Makefile include/libnetfilter_conntrack/Makefile l3extensions/Makefile extensions/Makefile libnetfilter_conntrack.pc)
 
src/Makefile.am +2 -2
Index: libnetfilter_conntrack/src/Makefile.am
===================================================================
@@ -4,8 +4,8 @@
 
 #EXTRA_DIST = $(man_MANS) acinclude.m4
 
-AM_CFLAGS=-fPIC -Wall
-LIBS=
+AM_CFLAGS = -fPIC -Wall
+LIBS = @LIBNFCONNTRACK_LIBS@
 
 lib_LTLIBRARIES = libnetfilter_conntrack.la 
 
Makefile.am +0 -1
Index: libnetfilter_conntrack/Makefile.am
===================================================================
@@ -3,7 +3,6 @@
 AUTOMAKE_OPTIONS = foreign dist-bzip2 1.6
 
 SUBDIRS	= include src l3extensions extensions utils
-LINKOPTS = -lnfnetlink
 
 man_MANS = #nfnetlink_conntrack.3 nfnetlink_conntrack.7
 
configure.in +10 -2
Index: libnetfilter_queue/configure.in
===================================================================
@@ -17,8 +17,16 @@
 *) AC_MSG_ERROR([Linux only, dude!]);;
 esac
 
-AC_CHECK_LIB(nfnetlink, nfnl_subsys_open, AC_MSG_RESULT(found), AC_MSG_ERROR([libnfnetlink 0.0.16 or later needed]))
-AC_CHECK_HEADER([libnfnetlink/linux_nfnetlink.h], [AC_MSG_RESULT([found])], [AC_MSG_ERROR([libnfnetlink 0.0.16 or later needed])])
+dnl Dependencies
+LIBNFNETLINK_REQUIRED=0.0.16
+ 
+PKG_CHECK_MODULES(LIBNFNETLINK, libnfnetlink >= $LIBNFNETLINK_REQUIRED,,
+	AC_MSG_ERROR(Cannot find libnfnetlink >= $LIBNFNETLINK_REQUIRED))
+ 
+CFLAGS="$CFLAGS $LIBNFNETLINK_CFLAGS"
+LIBNFQUEUE_LIBS="$LIBNFNETLINK_LIBS"
+ 
+AC_SUBST(LIBNFQUEUE_LIBS)
 
 dnl Output the makefiles
 AC_OUTPUT(Makefile include/Makefile include/libnetfilter_queue/Makefile src/Makefile utils/Makefile libnetfilter_queue.pc)
src/Makefile.am +2 -2
Index: libnetfilter_queue/src/Makefile.am
===================================================================
@@ -3,8 +3,8 @@
 LIBVERSION=2:0:1
 
 INCLUDES = $(all_includes) -I$(top_srcdir)/include -I${KERNELDIR}
-AM_CFLAGS=-fPIC -Wall
-LIBS=
+AM_CFLAGS = -fPIC -Wall
+LIBS = @LIBNFQUEUE_LIBS@
 
 lib_LTLIBRARIES = libnetfilter_queue.la libnetfilter_queue_libipq.la
 
configure.in +11 -26
Index: conntrack/configure.in
===================================================================
@@ -3,7 +3,6 @@
 AC_CANONICAL_SYSTEM
 
 AM_INIT_AUTOMAKE(conntrack, 1.00beta2)
-#AM_CONFIG_HEADER(config.h)
 
 AC_PROG_CC
 AM_PROG_LIBTOOL
@@ -15,14 +14,14 @@
 *) AC_MSG_ERROR([Linux only, dude!]);;
 esac
 
-# Checks for libraries.
-# FIXME: Replace `main' with a function in `-lc':
-dnl AC_CHECK_LIB([c], [main])
-# FIXME: Replace `main' with a function in `-ldl':
+dnl Dependencies
+LIBNFCONNTRACK_REQUIRED=0.0.31
+ 
+AC_CHECK_LIB(dl, dlopen)
 
-AC_CHECK_LIB([dl], [dlopen])
-AC_CHECK_LIB([netfilter_conntrack], [nfct_dump_conntrack_table] ,,,[-lnetfilter_conntrack])
-
+PKG_CHECK_MODULES(LIBNFCONNTRACK, libnetfilter_conntrack >= $LIBNFCONNTRACK_REQUIRED,,
+	AC_MSG_ERROR(Cannot find libnetfilter_conntrack >= $LIBNFCONNTRACK_REQUIRED))
+ 
 AC_CHECK_HEADERS(arpa/inet.h)
 dnl check for inet_pton
 AC_CHECK_FUNCS(inet_pton)
@@ -56,19 +55,6 @@
   ], AC_MSG_RESULT(no), AC_MSG_RESULT(no))
 fi
 
-# Checks for header files.
-dnl AC_HEADER_STDC
-dnl AC_CHECK_HEADERS([netinet/in.h stdlib.h])
-
-# Checks for typedefs, structures, and compiler characteristics.
-dnl AC_C_CONST
-dnl AC_C_INLINE
-
-# Checks for library functions.
-dnl AC_FUNC_MALLOC
-dnl AC_FUNC_VPRINTF
-dnl AC_CHECK_FUNCS([memset])
-
 dnl--------------------------------
 
 if test ! -z "$libdir"; then
@@ -78,10 +64,9 @@
 
 dnl--------------------------------
 
-dnl AC_CONFIG_FILES([Makefile
-dnl                  debug/Makefile
-dnl                  debug/src/Makefile
-dnl                  extensions/Makefile
-dnl                  src/Makefile])
+CFLAGS="$CFLAGS $LIBNFCONNTRACK_CFLAGS"
+CONNTRACK_LIBS="$LIBNFCONNTRACK_LIBS"
 
+AC_SUBST(CONNTRACK_LIBS)
+
 AC_OUTPUT(Makefile src/Makefile extensions/Makefile include/Makefile)
src/Makefile.am +2 -2
Index: conntrack/src/Makefile.am
===================================================================
@@ -1,7 +1,7 @@
 include $(top_srcdir)/Make_global.am
+LIBS = @CONNTRACK_LIBS@
 
 sbin_PROGRAMS = conntrack
 conntrack_SOURCES = conntrack.c
-
-conntrack_LDFLAGS = $(all_libraries) -rdynamic -lnetfilter_conntrack
+#conntrack_LDFLAGS = $(all_libraries) -rdynamic
  
autogen.sh +1 -1
Index: conntrack/autogen.sh
===================================================================
@@ -13,6 +13,6 @@
 
 run aclocal
 run libtoolize -f
-run autoheader
+#run autoheader
 run automake -a
 run autoconf
configure.in +13 -7
Index: ulogd2/configure.in
===================================================================
@@ -2,7 +2,7 @@
 AC_INIT
 
 AM_INIT_AUTOMAKE(ulogd, 2.0.0beta2)
-AM_CONFIG_HEADER(config.h)
+# AM_CONFIG_HEADER(config.h)
 
 dnl Checks for programs.
 AC_PROG_MAKE_SET
@@ -28,13 +28,14 @@
 AC_FUNC_VPRINTF
 AC_CHECK_FUNCS(socket strerror)
 
-AC_CHECK_HEADER([libnetfilter_log/linux_nfnetlink_log.h], [AC_MSG_RESULT([found])],
-		[AC_MSG_ERROR([libnetfilter_log Version 0.0.11 or later needed])])
+LIBNFCONNTRACK_REQUIRED=0.0.31
+LIBNFLOG_REQUIRED=0.0.11
+ 
+PKG_CHECK_MODULES(LIBNFCONNTRACK, libnetfilter_conntrack >= $LIBNFCONNTRACK_REQUIRED,,
+	AC_MSG_ERROR(Cannot find libnetfilter_conntrack >= $LIBNFCONNTRACK_REQUIRED))
+PKG_CHECK_MODULES(LIBNFLOG, libnetfilter_log >= $LIBNFLOG_REQUIRED,,
+	AC_MSG_ERROR(Cannot find libnetfilter_log >= $LIBNFLOG_REQUIRED))
 
-AC_CHECK_HEADER([libnetfilter_conntrack/libnetfilter_conntrack.h], [AC_MSG_RESULT([found])],
-		[AC_MSG_ERROR([libnetfilter_conntrack Version 0.0.11 or later needed])])
-
-
 CT_CHECK_POSTGRES_DB()
 AM_CONDITIONAL(HAVE_PGSQL, test "x$PQLIBPATH" != "x")
 
@@ -61,6 +62,11 @@
 dnl AM_CONDITIONAL(HAVE_MYSQL, test x$mysqldir != x)
 dnl AM_CONDITIONAL(HAVE_PGSQL, test x$pgsqldir != x)
 
+CFLAGS="$CFLAGS $LIBNFCONNTRACK_CFLAGS $LIBNFLOG_CFLAGS"
+
+AC_SUBST(LIBNFCONNTRACK_LIBS)
+AC_SUBST(LIBNFLOG_LIBS)
+
 AC_OUTPUT(doc/Makefile \
 	  include/Makefile include/ulogd/Makefile include/libipulog/Makefile \
 	  libipulog/Makefile \
input/flow/Makefile.am +3 -2
Index: ulogd2/input/flow/Makefile.am
===================================================================
@@ -1,11 +1,12 @@
 
 INCLUDES = $(all_includes) -I$(top_srcdir)/include
-AM_CFLAGS=-fPIC -Wall
+AM_CFLAGS = -fPIC -Wall
+LIBS = @LIBNFCONNTRACK_LIBS@
 
 pkglib_LTLIBRARIES = ulogd_inpflow_NFCT.la # ulogd_inpflow_IPFIX.la
 
 ulogd_inpflow_NFCT_la_SOURCES = ulogd_inpflow_NFCT.c
-ulogd_inpflow_NFCT_la_LDFLAGS = -module -lnetfilter_conntrack
+ulogd_inpflow_NFCT_la_LDFLAGS = -module
 
 #ulogd_inpflow_IPFIX_la_SOURCES = ulogd_inpflow_IPFIX.c
 #ulogd_inpflow_IPFIX_la_LDFLAGS = -module
input/packet/Makefile.am +3 -3
Index: ulogd2/input/packet/Makefile.am
===================================================================
@@ -1,12 +1,12 @@
 
 INCLUDES = $(all_includes) -I$(top_srcdir)/include
-AM_CFLAGS=-fPIC -Wall
-LIBS=
+AM_CFLAGS = -fPIC -Wall
+LIBS = @LIBNFLOG_LIBS@
 
 pkglib_LTLIBRARIES = ulogd_inppkt_NFLOG.la ulogd_inppkt_ULOG.la
 
 ulogd_inppkt_NFLOG_la_SOURCES = ulogd_inppkt_NFLOG.c
-ulogd_inppkt_NFLOG_la_LDFLAGS = -module -lnetfilter_log
+ulogd_inppkt_NFLOG_la_LDFLAGS = -module
 
 ulogd_inppkt_ULOG_la_SOURCES = ulogd_inppkt_ULOG.c
 ulogd_inppkt_ULOG_la_LDFLAGS = -module
include/Makefile.am +1 -1
Index: libnetfilter_cthelper/include/Makefile.am
===================================================================
@@ -1,4 +1,4 @@
 
 SUBDIRS = libnetfilter_cthelper
 
-nodist_HEADERS = linux_list.h
+# nodist_HEADERS = linux_list.h
configure.in +15 -7
Index: libnetfilter_cthelper/configure.in
===================================================================
@@ -18,15 +18,23 @@
 *) AC_MSG_ERROR([Linux only, dude!]);;
 esac
 
-AC_CHECK_LIB(nfnetlink, nfnl_subsys_open, AC_MSG_RESULT(found), AC_MSG_ERROR([libnfnetlink 0.0.16 or later needed]))
-AC_CHECK_HEADER([libnfnetlink/linux_nfnetlink.h], [AC_MSG_RESULT([found])], [AC_MSG_ERROR([libnfnetlink 0.0.16 or later needed])])
+dnl Dependencies
+LIBNFNETLINK_REQUIRED=0.0.16
+LIBNFCONNTRACK_REQUIRED=0.0.31
+LIBNFQUEUE_REQUIRED=0.0.12
+ 
+PKG_CHECK_MODULES(LIBNFNETLINK, libnfnetlink >= $LIBNFNETLINK_REQUIRED,,
+	AC_MSG_ERROR(Cannot find libnfnetlink >= $LIBNFNETLINK_REQUIRED))
+PKG_CHECK_MODULES(LIBNFCONNTRACK, libnetfilter_conntrack >= $LIBNFCONNTRACK_REQUIRED,,
+	AC_MSG_ERROR(Cannot find libnetfilter_conntrack >= $LIBNFCONNTRACK_REQUIRED))
+PKG_CHECK_MODULES(LIBNFQUEUE, libnetfilter_queue >= $LIBNFQUEUE_REQUIRED,,
+	AC_MSG_ERROR(Cannot find libnetfilter_queue >= $LIBNFQUEUE_REQUIRED))
 
-AC_CHECK_LIB(netfilter_conntrack, nfct_open_nfnl, AC_MSG_RESULT(found), AC_MSG_ERROR([libnetfilter_conntrack 0.0.31 or later needed]))
-AC_CHECK_HEADER([libnetfilter_conntrack/libnetfilter_conntrack.h], [AC_MSG_RESULT([found])], [AC_MSG_ERROR([libnetfilter_conntrack 0.0.31 or later needed])])
+CFLAGS="$CFLAGS $LIBNFNETLINK_CFLAGS $LIBNFCONNTRACK_CFLAGS $LIBNFQUEUE_CFLAGS"
+LIBNFCTHELPER_LIBS="$LIBNFNETLINK_LIBS $LIBNFCONNTRACK_LIBS $LIBNFQUEUE_LIBS"
 
-AC_CHECK_LIB(netfilter_queue, nfq_open_nfnl, AC_MSG_RESULT(found), AC_MSG_ERROR([libnetfilter_queue 0.0.12 or later needed]))
-AC_CHECK_HEADER([libnetfilter_queue/libnetfilter_queue.h], [AC_MSG_RESULT([found])], [AC_MSG_ERROR([libnetfilter_queue 0.0.12 or later needed])])
+dnl Output the makefile
+AC_SUBST(LIBNFCTHELPER_LIBS)
 
-dnl Output the makefile
 AC_OUTPUT(Makefile src/Makefile include/Makefile utils/Makefile include/libnetfilter_cthelper/Makefile libnetfilter_cthelper.pc)
 
src/Makefile.am +2 -2
Index: libnetfilter_cthelper/src/Makefile.am
===================================================================
@@ -3,8 +3,8 @@
 LIBVERSION=0:0:0
 
 INCLUDES = $(all_includes) -I$(top_srcdir)/include -I${KERNELDIR}
-AM_CFLAGS=-fPIC -Wall
-LIBS=
+AM_CFLAGS = -fPIC -Wall
+LIBS = @LIBNFCTHELPER_LIBS@
 
 lib_LTLIBRARIES = libnetfilter_cthelper.la
 
configure.in +10 -2
Index: libnetfilter_log/configure.in
===================================================================
@@ -18,9 +18,17 @@
 *) AC_MSG_ERROR([Linux only, dude!]);;
 esac
 
-AC_CHECK_LIB(nfnetlink, nfnl_subsys_open, AC_MSG_RESULT(found), AC_MSG_ERROR([libnfnetlink 0.0.16 or later needed]))
-AC_CHECK_HEADER([libnfnetlink/linux_nfnetlink.h], [AC_MSG_RESULT([found])], [AC_MSG_ERROR([libnfnetlink 0.0.16 or later needed])])
+dnl Dependencies
+LIBNFNETLINK_REQUIRED=0.0.16
+ 
+PKG_CHECK_MODULES(LIBNFNETLINK, libnfnetlink >= $LIBNFNETLINK_REQUIRED,,
+	AC_MSG_ERROR(Cannot find libnfnetlink >= $LIBNFNETLINK_REQUIRED))
 
+CFLAGS="$CFLAGS $LIBNFNETLINK_CFLAGS"
+LIBNFLOG_LIBS="$LIBNFNETLINK_LIBS"
+ 
+AC_SUBST(LIBNFLOG_LIBS)
+
 dnl Output the makefile
 AC_OUTPUT(Makefile src/Makefile include/Makefile include/libnetfilter_log/Makefile utils/Makefile libnetfilter_log.pc)
 
src/Makefile.am +2 -2
Index: libnetfilter_log/src/Makefile.am
===================================================================
@@ -3,8 +3,8 @@
 LIBVERSION=2:0:1
 
 INCLUDES = $(all_includes) -I$(top_srcdir)/include
-AM_CFLAGS=-fPIC -Wall
-LIBS=
+AM_CFLAGS = -fPIC -Wall
+LIBS = @LIBNFLOG_LIBS@
 
 lib_LTLIBRARIES = libnetfilter_log.la libnetfilter_log_libipulog.la
 
#1 lore raw

Hi Krisztian,

Quoted 8 lines · KOVACS Krisztian

This weekend I've spent a significant amount of time configuring and
compiling the whole libnetfilter_* universe and the conntrack and ulogd2 tools. My initial plan was to install everything under /opt/netfilter, however, the out-of-the-box configure.in files provided with these modules do not make this particularly easy.

So after spending some time trying all kinds of mantras and magical
runes to get autoconfuse do what I intended to do, I came to the conclusion that all this would be much simpler if we used the PKG_CHECK_* macros in configure.in. The necessary pkgconfig .pc files are generated and installed anyway, so why not?

Of course this means that to compile these modules one will need
pkg-config, but personally I don't consider this a problem. The additional benefit of this method would be that the only thing to take care of is that of setting a correct PKG_CONFIG_PATH, all the include paths and libraries are then found magically.

I like it, AFAIK pkg-config is always in most distros, so this new requirement shouldn't be a problem. Moreover, this provides us a way to easily maintain the library version dependencies. Since this also affects other libraries, I'll wait for Harald's ACK before commiting this to conntrack and libnetfilter_conntrack.

cheers,

--
Pablo

#2 lore raw

Hi,

Quoted 18 lines · Pablo Neira Ayuso
Quoted 12 lines

This weekend I've spent a significant amount of time configuring and
compiling the whole libnetfilter_* universe and the conntrack and ulogd2 tools. My initial plan was to install everything under /opt/netfilter, however, the out-of-the-box configure.in files provided with these modules do not make this particularly easy.

So after spending some time trying all kinds of mantras and magical
runes to get autoconfuse do what I intended to do, I came to the conclusion that all this would be much simpler if we used the PKG_CHECK_* macros in configure.in. The necessary pkgconfig .pc files are generated and installed anyway, so why not?

Quoted 5 lines

Of course this means that to compile these modules one will need
pkg-config, but personally I don't consider this a problem. The additional benefit of this method would be that the only thing to take care of is that of setting a correct PKG_CONFIG_PATH, all the include paths and libraries are then found magically.

Quoted 5 lines

I like it, AFAIK pkg-config is always in most distros, so this new requirement shouldn't be a problem. Moreover, this provides us a way to easily maintain the library version dependencies. Since this also affects other libraries, I'll wait for Harald's ACK before commiting this to conntrack and libnetfilter_conntrack.

Is there any chance of getting these patches applied? Compiling all the
necessary libraries from an SVN checkout is still a daunting task for me, especially because of the nfnetlink dependency.

The original email and patches are here:

http://marc.theaimsgroup.com/?l=netfilter-devel&m=114280711926066&w=2

Signature · 1 line
KOVACS Krisztian
#3 lore raw
Quoted 8 lines · KOVACS Krisztian

Is there any chance of getting these patches applied? Compiling all the
necessary libraries from an SVN checkout is still a daunting task for me, especially because of the nfnetlink dependency.

The original email and patches are here:

http://marc.theaimsgroup.com/?l=netfilter-devel&m=114280711926066&w=2

I'm fine with this. Objections anyone? Otherwise please resend the patches and I'll apply them.