ulogd2 patches
cover ulogd2 patches
Hi guys
This patchset is against ulogd2 subversion repository.
The actual code in subversion did not work for me with the following stack:
stack=log1:NFLOG,base1:BASE,ifi2:IFINDEX,print1:PRINTPKT,emu1:SYSLOG stack=log2:ULOG,base2:BASE,print1:PRINTPKT,emu2:SYSLOG
The patch set fixes some problems after which ulogd2 works for me with this plugin stack.
Patch #4 is a workaround of the following problem, of which i am not quite sure is really no problem of ulogd2, but i think so:
After every successful received packet coming from the ULOG netlink, namely in the next iteration of ipulog_read() in ulog_read_cb(), ipulog_read() returns -1 and thus logs an error.
This happens because the recvfrom() within ipulog_netlink_recvfrom() fails with EAGAIN, which in reality should'nt, since the select() should only return when packets are present.
I think it is probably this kernel bug:
http://bugzilla.kernel.org/show_bug.cgi?id=5498
I'm not sure if it is really that bug, but i think so, because libipulog had virtually no changes between ulogd1 and ulogd2 and ulogd1 does not have this problem. The only thing which changed is that the netlink socket is now O_NONBLOCK, which IMHO indicates that it must be that kernel bug.
Probably it is already solved with newer kernel versions. I tested on 2.6.22.15
BTW: finally managed to set up quilt correctly, so these patches should now be inline :)
kind regards,
Peter
--
PATCH 1/5 openlog() to syslog for global ulogd log messages
When [global]'s logfile is syslog, ulogd should log it's own mesasages (not the firewall log lines) to syslog, which it does'nt because openlog() is missing. This patch adds openlog()
--- src/ulogd.c | 1 + 1 file changed, 1 insertion(+)
src/ulogd.c +1 -0
@@ -738,6 +738,7 @@if (!strcmp (name,"stdout" )) { logfile = stdout; }else if (!strcmp (name,"syslog" )) { +openlog ("ulogd" ,LOG_PID ,LOG_DAEMON ); logfile = &syslog_dummy; }else { logfile =fopen (ulogd_logfile,"a" );
--
PATCH 2/5 Dont ntohs() mac_len of ULOG, since it is not in network byte order
In reply to Peter WarasinStores mac_len correctly, since within ULOG structire it is not stored in network byte order.
--- input/packet/ulogd_inppkt_ULOG.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
input/packet/ulogd_inppkt_ULOG.c +1 -1
@@ -167,7 +167,7 @@if (pkt->mac_len) { ret[ULOG_KEY_RAW_MAC ].u.value.ptr = pkt->mac; ret[ULOG_KEY_RAW_MAC ].flags |=ULOGD_RETF_VALID ; - ret[ULOG_KEY_RAW_MAC_LEN ].u.value.ui16 =ntohs (pkt->mac_len); + ret[ULOG_KEY_RAW_MAC_LEN ].u.value.ui16 = pkt->mac_len; ret[ULOG_KEY_RAW_MAC_LEN ].flags |=ULOGD_RETF_VALID ; }
--
PATCH 3/5 Logs also ipulog_strerror() and strerror() within ULOG plugin
In reply to Peter WarasinThis patch logs also the string representations ipulog:_strerror() and strerror() when an error occurred during receivement of packets within the ULOG plugin
--- input/packet/ulogd_inppkt_ULOG.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
input/packet/ulogd_inppkt_ULOG.c +5 -2
@@ -227,8 +227,11 @@if (len <=0 ) {/* this is not supposed to happen */ ulogd_log (ULOGD_ERROR ,"ipulog_read = %d! " -"ipulog_errno = %d, errno = %d\n" , - len, ipulog_errno, errno); +"ipulog_errno = %d (%s), " +"errno = %d (%s)\n" , + len, ipulog_errno, +ipulog_strerror (ipulog_errno), + errno,strerror (errno));break ; } while ((upkt = ipulog_get_packet(u->libulog_h,
--
PATCH 4/5 Workaround of recvfrom() EAGAIN bug
In reply to Peter WarasinThis is a workaround which prevents ulogd from logging each time when recvfrom() returns error because of EAGAIN. Since the netlink socket is now O_NONBLOCK, we probably run into the following bug:
http://bugzilla.kernel.org/show_bug.cgi?id=5498
which causes recvfrom() get an error when select() had a good return, whenever select() receives a packet with a bad checksum.
ipulog_read() always has this problem once after every successful ipulog_read().
--- input/packet/ulogd_inppkt_ULOG.c | 2 ++ 1 file changed, 2 insertions(+)
input/packet/ulogd_inppkt_ULOG.c +2 -0
@@ -225,6 +225,8 @@while ((len =ipulog_read (u->libulog_h, u->libulog_buf, upi->config_kset->ces[0 ].u.value,1 ))) {if (len <=0 ) { +if (errno ==EAGAIN ) +break ;/* this is not supposed to happen */ ulogd_log (ULOGD_ERROR ,"ipulog_read = %d! " "ipulog_errno = %d (%s), "
--
PATCH 5/5 stores the converted syslog parameters set within config file
In reply to Peter WarasinThis patch stores the converted values from the configuration file into the syslog instance structure.
Otherwise configuration parameters are senseless and only the default values will be used.
--- output/ulogd_output_SYSLOG.c | 4 ++++ 1 file changed, 4 insertions(+)
output/ulogd_output_SYSLOG.c +4 -0
@@ -87,6 +87,7 @@ {int syslog_facility, syslog_level;char *facility, *level; +struct syslog_instance *li = (struct syslog_instance *) &pi->private;/* FIXME: error handling */ config_parse_file (pi->id, pi->config_kset);
@@ -144,6 +145,9 @@return -EINVAL ; } + li->syslog_level = syslog_level; + li->syslog_facility = syslog_facility; +return 0 ; }
--
Patrick McHardy
AppliedRe: [PATCH 1/5] openlog() to syslog for global ulogd log messages
In reply to Peter WarasinQuoted 5 lines · Peter Warasin
When [global]'s logfile is syslog, ulogd should log it's own mesasages (not the firewall log lines) to syslog, which it does'nt because
openlog()is missing. This patch addsopenlog()Signed-off-by Peter Warasin <[email protected]>
Applied, but I changed the spaces used for intending to tabs.
Patrick McHardy
AppliedRe: [PATCH 2/5] Dont ntohs() mac_len of ULOG, since it is not in network byte order
In reply to Peter WarasinQuoted 4 lines · Peter Warasin
Stores
mac_lencorrectly, since within ULOG structire it is not stored in network byte order.Signed-off-by Peter Warasin <[email protected]>
Applied, thanks Peter.
Patrick McHardy
AppliedRe: [PATCH 3/5] Logs also ipulog_strerror() and strerror() within ULOG plugin
In reply to Peter WarasinQuoted 5 lines · Peter Warasin
This patch logs also the string representations ipulog:_strerror() and
strerror()when an error occurred during receivement of packets within the ULOG pluginSigned-off-by Peter Warasin <[email protected]>
Applied, thanks.
Patrick McHardy
AppliedRe: [PATCH 4/5] Workaround of recvfrom() EAGAIN bug
In reply to Peter WarasinQuoted 5 lines · Peter Warasin
This is a workaround which prevents ulogd from logging each time when
recvfrom()returns error because of EAGAIN. Since the netlink socket is nowO_NONBLOCK, we probably run into the following bug:
...
This is not a workaround, but correct handling of EAGAIN on a non-blocking socket. This happens because we loop until there is no more data in the receive-queue.
Applied, thanks.
Patrick McHardy
AppliedRe: [PATCH 5/5] stores the converted syslog parameters set within config file
In reply to Peter WarasinQuoted 6 lines · Peter Warasin
This patch stores the converted values from the configuration file into the syslog instance structure.
Otherwise configuration parameters are senseless and only the default values will be used.Signed-off-by Peter Warasin <[email protected]>
Applied, thanks.