Skip to contentSkip to conversation

libnfnetlink dependency elimination

RFC PATCH New Duncan Roe 1 participant 2 messages Dec 31, 2023 netfilter

lore
Share & tools
lore

Duncan Roe

author
#0 lore raw

cover libnfnetlink dependency elimination

Hi Pablo (and everybody else),

This patch replaces most of the libnfnetlink calls with libmnl calls in libnetfilter_queue.
Please comment on all aspects of this patch that you think could be improved.

Do you agree the libmnl is the right place for nfnl_build_nfa_iovec and nfnl_sendiov replacement functions?

This patch does not include an updated main page - I'm still working on that.

Cheers ... Duncan.

Duncan Roe (1):
utils/nfqnl_test runs without libnfnetlink

 Make_global.am                                |   2 +-
 configure.ac                                  |   1 -
 doxygen/doxygen.cfg.in                        |   1 +
 .../libnetfilter_queue/libnetfilter_queue.h   |  12 +-
 libnetfilter_queue.pc.in                      |   1 -
 src/Makefile.am                               |   2 +-
 src/libnetfilter_queue.c                      | 453 ++++++++++--------
 utils/Makefile.am                             |   2 +-
 8 files changed, 271 insertions(+), 203 deletions(-)
Signature · 1 line
2.35.8
author
#1 lore raw

RFC PATCH 1/1 utils/nfqnl_test runs without libnfnetlink

The build of utils/nfqnl_test has to ignore unresolved symbols because some libnfnetlink functions used by libnetfilter_queue are still to be converted. Specifically, these are:

nlif_index2name
nfnl_build_nfa_iovec
nfnl_sendiov

Of these, nfnl_build_nfa_iovec and nfnl_sendiov replacements belong in libmnl.

nfq_get_indev_name() has code snippets documenting these libnfnetlink functions:

nlif_open
nlif_catch
nlif_fd
nlif_query

libnetfilter_queue will have to provide these.

--------------------------------

Summary of changes (sort-of cleaned up git log):

Convert nfq_fd()
Also update build of utils/nfqnl_test to ignore unresolved symbols and document nfq_nfnlh().

Rename element id of struct nfq_q_handle to queue_num This leaves id as always referring to packet id. queue_num is also used in other sources.

Remove libnfnetlink from the build
Programs using nfnl-api functions must build with -lnfnetlink. Programs using mnl-api functions no longer show libnfnetlink in ldd.

Incorporate nfnl_rcvbufsiz()

Remove struct nfnl_subsys_handle *nfnlssh from struct nfq_handle

Convert nfq_close()

Convert non-data verdict functions
Updated:
include/libnetfilter_queue/libnetfilter_queue.h:
- Fix name in 1st line
- Change name of guardian #define to the conventional one
- Flag line to be removed (when we can) src/libnetfilter_queue.c:
- include libmnl.h
- Use real Linux headers
- __set_verdict() uses mnl_socket_sendto() if no packed data

Convert more message parsing functioms
Functions now using libmnl exclusively: nfq_get_msg_packet_hdr(), nfq_get_nfmark(), nfq_get_timestamp(), nfq_get_indev(), nfq_get_physindev(), nfq_get_outdev(), nfq_get_physoutdev(), nfqnl_msg_packet_hw(), nfq_get_uid() & nfq_get_gid().

About to convert / redo all nfq_get_ functions
Functions now using libmnl exclusively: nfq_handle_packet(), nfq_get_secctx() & nfq_get_payload().
The opaque struct nfq_data is now an array of struct nlattr instead of struct nfattr.
The difference is: nlattr starts at 0 while nfattr starts at 1.

Delete nfq_open_nfnl() and __nfq_rcv_pkt()
nfq_open_nfnl was the last user of static __nfq_rcv_pkt and was slated for removal so delete both of them.

Convert nfq_set_queue_flags() & nfq_set_queue_maxlen() to use libmnl

Introduce a static function to check response from using NLM_F_ACK Code uses nfq_query() where it previously used nfnl_query(). nfq_query() takes 2 extra args being a buffer / buffer size pair which the caller can also use for sending.
(nfq_query() used to call nfnl_catch() which declared that buffer). THIS FUNCTION WILL BE REPLACED by nfq_socket_sendto() if it ever makes it out of patchwork.

Convert nfq_set_mode(), nfq_bind_pf() & nfq_unbind_pf() to use libmnl Also remove nfq_errno (incomplete project, never documented). Main change is to static function __build_send_cfg_msg().

Convert nfq_open() to use libmnl

---
 Make_global.am                                |   2 +-
 configure.ac                                  |   1 -
 doxygen/doxygen.cfg.in                        |   1 +
 .../libnetfilter_queue/libnetfilter_queue.h   |  12 +-
 libnetfilter_queue.pc.in                      |   1 -
 src/Makefile.am                               |   2 +-
 src/libnetfilter_queue.c                      | 453 ++++++++++--------
 utils/Makefile.am                             |   2 +-
 8 files changed, 271 insertions(+), 203 deletions(-)
Make_global.am +1 -1
index 91da5da..4d8a58e 100644
@@ -1,2 +1,2 @@
-AM_CPPFLAGS = -I${top_srcdir}/include ${LIBNFNETLINK_CFLAGS} ${LIBMNL_CFLAGS}
+AM_CPPFLAGS = -I${top_srcdir}/include ${LIBMNL_CFLAGS}
 AM_CFLAGS = -Wall ${GCC_FVISIBILITY_HIDDEN}
configure.ac +0 -1
index 7359fba..ba7b15f 100644
@@ -42,7 +42,6 @@ case "$host" in
 esac
 
 dnl Dependencies
-PKG_CHECK_MODULES([LIBNFNETLINK], [libnfnetlink >= 0.0.41])
 PKG_CHECK_MODULES([LIBMNL], [libmnl >= 1.0.3])
 
 AS_IF([test "$enable_man_pages" = no -a "$enable_html_doc" = no],
doxygen/doxygen.cfg.in +1 -0
index 97174ff..3e06bd8 100644
@@ -13,6 +13,7 @@ EXCLUDE_SYMBOLS        = EXPORT_SYMBOL \
                          nfq_handle \
                          nfq_data \
                          nfq_q_handle \
+                         nfnl_handle \
                          tcp_flag_word
 EXAMPLE_PATTERNS       =
 INPUT_FILTER           = "sed 's/EXPORT_SYMBOL//g'"
include/libnetfilter_queue/libnetfilter_queue.h +6 -6
index f7e68d8..8932847 100644
@@ -1,4 +1,4 @@
-/* libnfqnetlink.h: Header file for the Netfilter Queue library.
+/* libnetfilter_queue.h: Header file for the Netfilter Queue library.
  *
  * (C) 2005 by Harald Welte <[email protected]>
  *
@@ -10,11 +10,11 @@
  * of the GNU General Public License, incorporated herein by reference.
  */
 
-#ifndef __LIBCTNETLINK_H
-#define __LIBCTNETLINK_H
+#ifndef __LIBNETFILTER_QUEUE_H
+#define __LIBNETFILTER_QUEUE_H
 
 #include <sys/time.h>
-#include <libnfnetlink/libnfnetlink.h>
+#include <libnfnetlink/libnfnetlink.h> /* FIXME: Remove */
 
 #include <libnetfilter_queue/linux_nfnetlink_queue.h>
 
@@ -26,8 +26,6 @@ struct nfq_handle;
 struct nfq_q_handle;
 struct nfq_data;
 
-extern int nfq_errno;
-
 extern struct nfnl_handle *nfq_nfnlh(struct nfq_handle *h);
 extern int nfq_fd(struct nfq_handle *h);
 
@@ -35,6 +33,8 @@ typedef int  nfq_callback(struct nfq_q_handle *gh, struct nfgenmsg *nfmsg,
 		       struct nfq_data *nfad, void *data);
 
 
+extern unsigned int nfnl_rcvbufsiz(const struct nfnl_handle *h,
+				   unsigned int size);
 extern struct nfq_handle *nfq_open(void);
 extern struct nfq_handle *nfq_open_nfnl(struct nfnl_handle *nfnlh);
 extern int nfq_close(struct nfq_handle *h);
libnetfilter_queue.pc.in +0 -1
index 9c6c2c4..962c686 100644
@@ -12,5 +12,4 @@ Version: @VERSION@
 Requires: libnfnetlink
 Conflicts:
 Libs: -L${libdir} -lnetfilter_queue
-Libs.private: @LIBNFNETLINK_LIBS@
 Cflags: -I${includedir}
src/Makefile.am +1 -1
index 079853e..aa0c3a9 100644
@@ -38,4 +38,4 @@ libnetfilter_queue_la_SOURCES = libnetfilter_queue.c	\
 				extra/pktbuff.c		\
 				extra/udp.c
 
-libnetfilter_queue_la_LIBADD  = ${LIBNFNETLINK_LIBS} ${LIBMNL_LIBS}
+libnetfilter_queue_la_LIBADD  = ${LIBMNL_LIBS}
src/libnetfilter_queue.c +261 -192

760 lines not on this page · raw message

utils/Makefile.am +1 -1
index d3147e3..d0d3eb8 100644
@@ -4,6 +4,6 @@ check_PROGRAMS = nfqnl_test
 
 nfqnl_test_SOURCES = nfqnl_test.c
 nfqnl_test_LDADD = ../src/libnetfilter_queue.la
-nfqnl_test_LDFLAGS = -dynamic
+nfqnl_test_LDFLAGS = -dynamic -Wl,--unresolved-symbols=ignore-all
 
 
Signature · 1 line
2.35.8