libnfnetlink and iface conversion to string
Status from this message: Applied. Merci Eric.
Get series with b4
b4 am 1169162676.8926.14.camel@localhostVersions newest first
Patches in v1 Applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/2 | libnfnetlink, iface conversion to stringMakefile.am iftable.c libnfnetlink/ +1 more | +48 | 10 replies | |
| 2/2 | libnetfilter_queue and iface conversion to stringlibnetfilter_queue.c libnetfilter_queue/ | +30 | 3 replies | |
| 2/2 | libnetfilter_queue, iface conversion to stringlibnetfilter_queue.c libnetfilter_queue/ | +30 | 3 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [Patch 0/2] libnfnetlink and iface conversion to string
Hi,
Quoted 8 lines · Harald Welte
Quoted 1 line · Eric Leblond
Hi,
I have committed that code to svn:
http://svn.netfilter.org/cgi-bin/viewcvs.cgi/trunk/libnfnetlink/src/rtnl.candiftable.cHowever, I never found the time to integrate them intl libnfnetlink, so they remained dead code for the last 16 months :(
Here's an attempt to add iface name resolution to libnfnetlink. It works and it is not too difficult to use.
Quoted 5 lines
Quoted 2 lines
In fact, if we omit the thread approach which is somehow intrusive, I don't see a way to do this via a simple call to added functions.
It isn't all that difficult to keep a in-memory list of name-ifindex mappings. You once dump at startup, and then listen to events...
This can be translated like that :
1. get netlink_fd with nlif_table_init()
2. use nlif_treat_msg(netlink_fd) to parse initial message
3. put netlink_fd in a select, and call nlif_treat_msg(netlink_fd) when data arrives
4. cleanup with nlif_table_fini(void) when feature is not needed any more
I join the patch for NuFW as code example.
To follow :
* Patch for libnfnetlink
* Patch for libnetfilter_queue
BR,
Signature · 2 lines
Eric Leblond <[email protected]> INL
nufw/packetsrv.c +15 -0
@@ -18,6 +18,8 @@#include "nufw.h" +#include "iface.h" +/** \file packetsrv.c * \brief Packet server thread *
@@ -159,6 +161,7 @@return 1 ; } +/** * Open a netlink connection and returns file descriptor */
@@ -335,6 +338,7 @@unsigned char buffer[BUFSIZ ];struct timeval tv;int fd; +int if_fd;int rv;int select_result;fd_set wk_set;
@@ -345,6 +349,12 @@exit (EXIT_FAILURE ); } + if_fd =iface_table_open (); + +if (if_fd <0 ) { +exit (EXIT_FAILURE ); + } +log_area_printf (DEBUG_AREA_MAIN ,DEBUG_LEVEL_WARNING ,"[+] Packet server started" );
@@ -360,6 +370,7 @@/* wait new event on socket */ FD_ZERO (&wk_set);FD_SET (fd,&wk_set); +FD_SET (if_fd,&wk_set); select_result =select (fd+1 ,&wk_set,NULL ,NULL ,&tv);if (select_result ==-1 ) {
@@ -380,6 +391,10 @@continue ; } +if (FD_ISSET (if_fd,&wk_set)){ +iface_treat_message (if_fd); +continue ; + }/* read one packet */ rv =recv (fd, buffer,sizeof (buffer),0 );if (rv <0 )
nufw/iface.c +20 -0
@@ -42,4 +42,24 @@ return 1; } +int iface_table_open () +{ +int iftable_fd; +/* opening ifname resolution handle */ + iftable_fd =nlif_table_init (); +if (iftable_fd <=0 ) { +log_area_printf (DEBUG_AREA_MAIN ,DEBUG_LEVEL_CRITICAL , +"[!] Error during nlif_table_init()" ); +return -1 ; + } +/* treat initial rtnetlink message */ +nlif_treat_msg (iftable_fd); + +return iftable_fd; +} + +int iface_treat_message (int fd) +{ +return nlif_treat_msg (fd); +}#endif
nufw/Makefile.am +2 -2
@@ -4,8 +4,8 @@ sbin_PROGRAMS = nufw # nufw -nufw_SOURCES = authsrv.c common.c main.c packetsrv.c proto.h structure.h\ - tls.c audit.c conntrack.c log.c iface.c +nufw_SOURCES = authsrv.c common.c main.c iface.c packetsrv.c proto.h structure.h\ + tls.c audit.c conntrack.c log.c if HAVE_IPQ nufw_LDADD = -lipq -lpthread -lgnutls endif
ChangeLog +3 -0
@@ -1,6 +1,9 @@ 2.1.2 - log_mysql: add option to log by default in SQL database with IPV4 schema + - libnuclient: add nu_get_home_dir function which is not + dependant of HOME environment variable + - nufw: fix compilation in ipq mode (workaround ipq.h problem) 2.1.1 (2007/01/03) - suppress ldap authentication code - add support for log prefix