clean up nf_log API
Subsystems (3)
RFC PATCH 1/1 clean up nf_log API
Hi!
After spending some more time with the nf_log API, I think it still needs some further cleanup.
The main point of nf_log was to get some unfied support for packet logging backends, independent of the ruleset. We currently have logging backend functionality tied to ipt_LOG, ipt_ULOG packet filter rules, which is inflexible and unsuitable for other entities within netfilter that want to log packets.
However, on thing that I missed during the nf_log implementation was the fact that it was no longer possible to have some rules using LOG, some others ULOG. With the introduction of nf_log, it was only possible to use only one logging mechanism at any given point in time.
Also, there was no fallback support. If you had configured nfnetlink_log as your backend and the admin decides to remove that module, nothing will be logged, even though other mechanisms might be available and present in the kernel.
Another problem was that neither the ULOG nor the LOG target supported all of the arguments/parameters that the nfnetlink_log backend needed. Therefore, it is practically impossible to exploit all the features with the current kernel.
Therefore, I now propose the following patchset, which
1) enhances 'struct nf_logger' with a list_head, usage counter a priority and pf field
2) cleans up the api. we now call nf_log_[un]register() once from every backend. registering doesn't mean that it's actually active. successive calls to nf_log_[un]bind_pf() will actually bind a given backend to the specified protocol family.
3) introduction of a new NFLOG target. Only that NFLOG target supports all the arguments that all our backends support.
4) Adds 'fallback' support. This means that during unbind or unregistration of a given backend, we check in the global list of logging backends and chose the one with the hightest priority that supports our protocol family.
4) modify ipt_LOG, ipt_ULOG, ip6t_LOG and nfnetlink_log to reflect the abovementioned changes.
I have implemented the NFLOG target as iptables target (not xtables) due to 'customer need'. However, once we decide that this patch should be merged, I'll provide an x_tables version.
There are some open questions:
a) we only search for 'fallback' backends during unregistration/unbind. Should we also do this during registration? Or whenever we receive a packet and don't have a backend? Early registration might become problematic, since we don't really know what the user wants...
b) reference counting. We could actually get_module / put_module the module that implements a specific backend rather than using our own use counter.
Comments welcome.
Signature · 5 lines
- Harald Welte <[email protected]> http://netfilter.org/ ============================================================================ "Fragmentation is like classful addressing -- an interesting early architectural error that shows how much experimentation was going on while IP was being designed." -- Paul Vixie
Hi,
I wrote a patch about 2 month ago, that does something similiar.
Maybe some of it is usefull. If you are interested I would venture to update the patch.
The patch uses only a modified version of the normal LOG target, but I wanted to change this to a NF_LOG target anyway.
Regards
Gregor
[PATCH][RFC] Unifiy logging in netfilter using nf_log, take #1
Although nf_log is meant as a general logging API for netfilter, not every module uses it. Furthermore modules can interfere with the logging of other modules. This patch (against net-2.6.17) tries to eliminate these problems.
* Everything uses nf_log.c as logging API (excpect the obsolete ULOG targets)
* Loggers in nf_log.c are stackable. More than one logger can be registered per PF
* nf_loginfo struct has been changed. Instead of the type field and the union there is a "backends" field now that contains a bitmask specifing which backends should process/log this packet.
* ipt_LOGc and ip6t_LOG.c have been splitted:
* xt_LOG.c now contains the targets. The targets
always use nf_log for logging. These should be the only logging targets. They take care of setting up nf_loginfo for logging to syslog and/or to other backends
* ip_log_syslog.c and ip6_log_syslog.c are new and contain the syslog log backends. When these modules are loaded, the syslog backend is registered with nf_log
* The backends (nfnetlink_log, ip_log_syslog, ip6_log_syslog, ebt_LOG) check the backends field of nf_loginfo to see if they should handle the packet
* The ULOG targets have been changed to be self-contained and independent from nf_log API. They are the _only_ modules that do not use nf_log
What the LOG targets for v4 and v6 can do from a userspace / iptables point of view:
* Log to syslog (allows you to specify the flags)
* Log to nfnetlink_log (allows you to specify the loggroup)
* Log to syslog and nfnetlink_log
===> One LOG target fits all.
Things TODO:
* ebt_log is always using the syslog backend. Furthermore the code there isn't split into the syslog logger and the target
* change userspace iptables, so it can utilize the new stuff. Patch will follow soon
* thoroughly test the patch
POTENTIAL PROBLEMS / ALTERNATIVE SOLUTION
* ipt_log_info and ip6t_log_info have been replaced by xt_log_info (which has changed in size). This means iptables must be recompiled and older iptables versions won't work with these changes.
If this is considered a problem the only solution I can think of, is not to change the old LOG targets and introduce a new, general purpose target, that can do what the LOG target in this patch can to.
=====================================================================
include/linux/netfilter.h +12 -15
@@ -123,22 +123,19 @@ extern struct list_head nf_hooks[NPROTO]#define NF_LOG_UID 0x08/* Log UID owning local socket */ #define NF_LOG_MASK 0x0f -#define NF_LOG_TYPE_LOG 0x01 -#define NF_LOG_TYPE_ULOG 0x02 +/* make sure not to change this without changing xt_LOG.h:NF_LOG_BACKEND_* */ +#define NF_LOG_BACKEND_SYSLOG 0x01 +#define NF_LOG_BACKEND_NFLOG 0x02 +#define NF_LOG_BACKEND_MASK (NF_LOG_BACKEND_SYSLOG|NF_LOG_BACKEND_NFLOG)struct nf_loginfo { -u_int8_t type; -union { -struct { -u_int32_t copy_len; -u_int16_t group; -u_int16_t qthreshold; - } ulog; -struct { -u_int8_t level; -u_int8_t logflags; - } log; - } u; +u_int8_t backends;/* ORed from NF_LOG_BACKEND* */ +/* nflog backend */ +u_int16_t group; +u_int16_t qthreshold; +/* SYSLOG backend */ +u_int8_t level; +u_int8_t logflags; }; typedef void nf_logfn(unsigned int pf,
@@ -157,7 +154,7 @@ struct nf_logger {/* Function to register/unregister log function. */ int nf_log_register (int pf,struct nf_logger *logger); -int nf_log_unregister_pf (int pf); +int nf_log_unregister_pf (int pf,struct nf_logger *logger);void nf_log_unregister_logger (struct nf_logger *logger);/* Calls the registered backend logging function */
include/linux/netfilter/xt_LOG.h new file +43 -0
43 lines not on this page · raw message
include/linux/netfilter_bridge/ebt_log.h +1 -1
@@ -4,7 +4,7 @@#define EBT_LOG_IP 0x01/* if the frame is made by ip, log the ip information */ #define EBT_LOG_ARP 0x02#define EBT_LOG_NFLOG 0x04 -#define EBT_LOG_MASK (EBT_LOG_IP | EBT_LOG_ARP) +#define EBT_LOG_MASK (EBT_LOG_IP | EBT_LOG_ARP | EBT_LOG_NFLOG)#define EBT_LOG_PREFIX_SIZE 30#define EBT_LOG_WATCHER "log"
net/bridge/netfilter/Makefile +1 -1
@@ -29,4 +29,4 @@ obj-$(CONFIG_BRIDGE_EBT_SNAT) += ebt_sna # watchers obj-$(CONFIG_BRIDGE_EBT_LOG) += ebt_log.o -obj-$(CONFIG_BRIDGE_EBT_LOG) += ebt_ulog.o +obj-$(CONFIG_BRIDGE_EBT_ULOG) += ebt_ulog.o
net/bridge/netfilter/ebt_log.c +13 -13
@@ -67,8 +67,13 @@ ebt_log_packet(unsigned int pf, unsigned {unsigned int bitmask; +if (!loginfo) +return ;/* FIXME: we should add a default_loginfo here */ +if (!(loginfo->backends &NF_LOG_BACKEND_SYSLOG )) +return ; +spin_lock_bh (&ebt_log_lock); -printk ("<%c>%s IN=%s OUT=%s MAC source = " ,'0' + loginfo->u.log.level, +printk ("<%c>%s IN=%s OUT=%s MAC source = " ,'0' + loginfo->level, prefix, in ? in->name :"" , out ? out->name :"" );print_MAC (eth_hdr (skb)->h_source);
@@ -77,10 +82,7 @@ ebt_log_packet(unsigned int pf, unsignedprintk ("proto = 0x%04x" ,ntohs (eth_hdr (skb)->h_proto)); -if (loginfo->type ==NF_LOG_TYPE_LOG ) - bitmask = loginfo->u.log.logflags; -else - bitmask =NF_LOG_MASK ; + bitmask = loginfo->logflags;if ((bitmask &EBT_LOG_IP ) &ð_hdr (skb)->h_proto ==htons (ETH_P_IP )){
@@ -162,16 +164,14 @@ static void ebt_log(const struct sk_buffstruct ebt_log_info *info = (struct ebt_log_info *)data;struct nf_loginfo li; - li.type =NF_LOG_TYPE_LOG ; - li.u.log.level = info->loglevel; - li.u.log.logflags = info->bitmask; + li.backends =NF_LOG_BACKEND_SYSLOG ;/* currently only syslog backend supported */ + li.level = info->loglevel; +/* XXX: info->bitmask is 32 bit, logflas only 8 +* Currently it's not a problem, since only 3 falgs are defined, but nevertheless */ + li.logflags = info->bitmask; -if (info->bitmask &EBT_LOG_NFLOG ) -nf_log_packet (PF_BRIDGE , hooknr, skb, in, out, &li, +nf_log_packet (PF_BRIDGE , hooknr, skb, in, out, &li, info->prefix); -else -ebt_log_packet (PF_BRIDGE , hooknr, skb, in, out, &li, - info->prefix); } static struct ebt_watcher log =
net/bridge/netfilter/ebt_ulog.c +0 -36
@@ -218,28 +218,6 @@ alloc_failure: goto unlock; } -/* this function is registered with the netfilter core */ -static void ebt_log_packet (unsigned int pf,unsigned int hooknum, -const struct sk_buff *skb,const struct net_device *in, -const struct net_device *out,const struct nf_loginfo *li, -const char *prefix) -{ -struct ebt_ulog_info loginfo; - -if (!li || li->type !=NF_LOG_TYPE_ULOG ) { - loginfo.nlgroup =EBT_ULOG_DEFAULT_NLGROUP ; - loginfo.cprange =0 ; - loginfo.qthreshold =EBT_ULOG_DEFAULT_QTHRESHOLD ; - loginfo.prefix[0 ] ='\0' ; - }else { - loginfo.nlgroup = li->u.ulog.group; - loginfo.cprange = li->u.ulog.copy_len; - loginfo.qthreshold = li->u.ulog.qthreshold; -strlcpy (loginfo.prefix, prefix,sizeof (loginfo.prefix)); - } - -ebt_ulog_packet (hooknum, skb, in, out, &loginfo, prefix); -} static void ebt_ulog(const struct sk_buff *skb, unsigned int hooknr, const struct net_device *in, const struct net_device *out,
@@ -275,12 +253,6 @@ static struct ebt_watcher ulog = { .me = THIS_MODULE, }; -static struct nf_logger ebt_ulog_logger = { - .name =EBT_ULOG_WATCHER , - .logfn = &ebt_log_packet, - .me =THIS_MODULE , -}; -static int __init init (void ) {int i, ret =0 ;
@@ -306,13 +278,6 @@ static int __init init(void)else if ((ret =ebt_register_watcher (&ulog)))sock_release (ebtulognl->sk_socket); -if (nf_log_register (PF_BRIDGE , &ebt_ulog_logger) <0 ) { -printk (KERN_WARNING "ebt_ulog: not logging via ulog " -"since somebody else already registered for PF_BRIDGE\n" ); -/* we cannot make module load fail here, since otherwise -* ebtables userspace would abort */ - } -return ret; }
@@ -321,7 +286,6 @@ static void __exit fini(void)ebt_ulog_buff_t *ub;int i; -nf_log_unregister_logger (&ebt_ulog_logger);ebt_unregister_watcher (&ulog);for (i =0 ; i <EBT_ULOG_MAXNLGROUPS ; i++) { ub = &ulog_buffers[i];
net/ipv4/netfilter/Kconfig +11 -9
@@ -313,6 +313,17 @@ config IP_NF_FILTER local output. See the man page for iptables(8). To compile it as a module, choose M here. If unsure, say N. + +config IP_NF_LOG_SYSLOG + tristate "Syslog backend for LOG target" + depends on IP_NF_IPTABLES + help + This option adds a log backend, which allows you to create rules in + any iptables table which records the packet header to the syslog. + See NF_XTABLES_TARGET_LOG + + To compile it as a module, choose M here. If unsure, say N. + config IP_NF_TARGET_REJECT tristate "REJECT target support"
@@ -324,15 +335,6 @@ config IP_NF_TARGET_REJECT To compile it as a module, choose M here. If unsure, say N. -config IP_NF_TARGET_LOG - tristate "LOG target support" - depends on IP_NF_IPTABLES - help - This option adds a `LOG' target, which allows you to create rules in - any iptables table which records the packet header to the syslog. - - To compile it as a module, choose M here. If unsure, say N. - config IP_NF_TARGET_ULOG tristate "ULOG target support (OBSOLETE)" depends on IP_NF_IPTABLES
net/ipv4/netfilter/Makefile +3 -1
@@ -45,6 +45,9 @@ obj-$(CONFIG_IP_NF_MANGLE) += iptable_ma obj-$(CONFIG_IP_NF_NAT) += iptable_nat.o obj-$(CONFIG_IP_NF_RAW) += iptable_raw.o +# Syslog backend support +obj-$(CONFIG_IP_NF_LOG_SYSLOG) += ip_log_syslog.o + # matches obj-$(CONFIG_IP_NF_MATCH_HASHLIMIT) += ipt_hashlimit.o obj-$(CONFIG_IP_NF_MATCH_IPRANGE) += ipt_iprange.o
@@ -68,7 +71,6 @@ obj-$(CONFIG_IP_NF_TARGET_REDIRECT) += i obj-$(CONFIG_IP_NF_TARGET_NETMAP) += ipt_NETMAP.o obj-$(CONFIG_IP_NF_TARGET_SAME) += ipt_SAME.o obj-$(CONFIG_IP_NF_NAT_SNMP_BASIC) += ip_nat_snmp_basic.o -obj-$(CONFIG_IP_NF_TARGET_LOG) += ipt_LOG.o obj-$(CONFIG_IP_NF_TARGET_ULOG) += ipt_ULOG.o obj-$(CONFIG_IP_NF_TARGET_TCPMSS) += ipt_TCPMSS.o obj-$(CONFIG_IP_NF_TARGET_CLUSTERIP) += ipt_CLUSTERIP.o
net/ipv4/netfilter/ip_log_syslog.c new file +437 -0
437 lines not on this page · raw message
net/ipv4/netfilter/ipt_ULOG.c +1 -35
@@ -15,6 +15,7 @@* 2002/10/30 fix uninitialized mac_len field - <Anders K. Pedersen> * 2004/10/25 fix erroneous calculation of 'len' parameter to NLMSG_PUT * resulting in bogus 'error during NLMSG_PUT' messages. +* 2006/03/04 make ULOG self-contained without interaction with nf_log * * (C) 1999-2001 Paul `Rusty' Russell * (C) 2002-2004 Netfilter Core Team <[email protected]>
@@ -313,31 +314,6 @@ static unsigned int ipt_ulog_target(strureturn IPT_CONTINUE ; } -static void ipt_logfn (unsigned int pf, -unsigned int hooknum, -const struct sk_buff *skb, -const struct net_device *in, -const struct net_device *out, -const struct nf_loginfo *li, -const char *prefix) -{ -struct ipt_ulog_info loginfo; - -if (!li || li->type !=NF_LOG_TYPE_ULOG ) { - loginfo.nl_group =ULOG_DEFAULT_NLGROUP ; - loginfo.copy_range =0 ; - loginfo.qthreshold =ULOG_DEFAULT_QTHRESHOLD ; - loginfo.prefix[0 ] ='\0' ; - }else { - loginfo.nl_group = li->u.ulog.group; - loginfo.copy_range = li->u.ulog.copy_len; - loginfo.qthreshold = li->u.ulog.qthreshold; -strlcpy (loginfo.prefix, prefix,sizeof (loginfo.prefix)); - } - -ipt_ulog_packet (hooknum, skb, in, out, &loginfo, prefix); -} - static int ipt_ulog_checkentry(const char *tablename, const void *e, const struct xt_target *target,
@@ -368,12 +344,6 @@ static struct ipt_target ipt_ulog_reg = .me = THIS_MODULE, }; -static struct nf_logger ipt_ulog_logger = { - .name ="ipt_ULOG" , - .logfn = ipt_logfn, - .me =THIS_MODULE , -}; -static int __init init (void ) {int i;
@@ -401,8 +371,6 @@ static int __init init(void)sock_release (nflognl->sk_socket);return -EINVAL ; } -if (nflog) -nf_log_register (PF_INET , &ipt_ulog_logger);return 0 ; }
@@ -414,8 +382,6 @@ static void __exit fini(void)DEBUGP ("ipt_ULOG: cleanup_module\n" ); -if (nflog) -nf_log_unregister_logger (&ipt_ulog_logger);ipt_unregister_target (&ipt_ulog_reg);sock_release (nflognl->sk_socket);
net/ipv6/netfilter/Kconfig +6 -4
@@ -144,15 +144,17 @@ config IP6_NF_FILTER To compile it as a module, choose M here. If unsure, say N. -config IP6_NF_TARGET_LOG - tristate "LOG target support" - depends on IP6_NF_FILTER +config IP6_NF_LOG_SYSLOG + tristate "Syslog backend for LOG target" + depends on IP_NF_IPTABLES help - This option adds a `LOG' target, which allows you to create rules in + This option adds a log backend, which allows you to create rules in any iptables table which records the packet header to the syslog. + See NF_XTABLES_TARGET_LOG To compile it as a module, choose M here. If unsure, say N. + config IP6_NF_TARGET_REJECT tristate "REJECT target support" depends on IP6_NF_FILTER
net/ipv6/netfilter/Makefile +1 -1
@@ -4,6 +4,7 @@ # Link order matters here. obj-$(CONFIG_IP6_NF_IPTABLES) += ip6_tables.o +obj-$(CONFIG_IP6_NF_LOG_SYSLOG) += ip6_log_syslog.o obj-$(CONFIG_IP6_NF_MATCH_RT) += ip6t_rt.o obj-$(CONFIG_IP6_NF_MATCH_OPTS) += ip6t_hbh.o ip6t_dst.o obj-$(CONFIG_IP6_NF_MATCH_IPV6HEADER) += ip6t_ipv6header.o
@@ -16,7 +17,6 @@ obj-$(CONFIG_IP6_NF_FILTER) += ip6table_ obj-$(CONFIG_IP6_NF_MANGLE) += ip6table_mangle.o obj-$(CONFIG_IP6_NF_TARGET_HL) += ip6t_HL.o obj-$(CONFIG_IP6_NF_QUEUE) += ip6_queue.o -obj-$(CONFIG_IP6_NF_TARGET_LOG) += ip6t_LOG.o obj-$(CONFIG_IP6_NF_RAW) += ip6table_raw.o obj-$(CONFIG_IP6_NF_MATCH_HL) += ip6t_hl.o obj-$(CONFIG_IP6_NF_TARGET_REJECT) += ip6t_REJECT.o
net/ipv6/netfilter/ip6_log_syslog.c new file +449 -0
449 lines not on this page · raw message
net/netfilter/Kconfig +11 -0
@@ -136,6 +136,17 @@ config NETFILTER_XT_TARGET_CONNMARK <file:Documentation/modules.txt>. The module will be called ipt_CONNMARK.o. If unsure, say `N'. +config NETFILTER_XT_TARGET_LOG + tristate '"LOG" target Support' + depends on NETFILTER_XTABLES + help + This option adds a `LOG' target, which allows you to create rules in + any iptables table which records the packet registered loggers like + NETFILTER_NETLINK_LOG, IP_NF_LOG_SYSLOG or IP6_NF_LOG_SYSLOG. + + To compile it as a module, choose M here. If unsure, say `N'. + + config NETFILTER_XT_TARGET_MARK tristate '"MARK" target support' depends on NETFILTER_XTABLES
net/netfilter/Makefile +1 -0
@@ -25,6 +25,7 @@ obj-$(CONFIG_NETFILTER_XTABLES) += x_tab # targets obj-$(CONFIG_NETFILTER_XT_TARGET_CLASSIFY) += xt_CLASSIFY.o obj-$(CONFIG_NETFILTER_XT_TARGET_CONNMARK) += xt_CONNMARK.o +obj-$(CONFIG_NETFILTER_XT_TARGET_LOG) += xt_LOG.o obj-$(CONFIG_NETFILTER_XT_TARGET_MARK) += xt_MARK.o obj-$(CONFIG_NETFILTER_XT_TARGET_NFQUEUE) += xt_NFQUEUE.o obj-$(CONFIG_NETFILTER_XT_TARGET_NOTRACK) += xt_NOTRACK.o
net/netfilter/nf_log.c +72 -30
179 lines not on this page · raw message
net/netfilter/nfnetlink_log.c +10 -8
@@ -574,6 +574,7 @@ nfattr_failure:#define RCV_SKB_FAIL (err) do { netlink_ack(skb, nlh, (err)); return; } while (0) +/* static struct nf_loginfo default_loginfo = { .type = NF_LOG_TYPE_ULOG, .u = {
@@ -584,6 +585,7 @@ static struct nf_loginfo default_loginfo}, }, }; +*/ /* log handler for internal netfilter logging api */ static void
@@ -601,17 +603,17 @@ nfulnl_log_packet(unsigned int pf,unsigned int qthreshold;unsigned int nlbufsiz; -if (li_user && li_user->type ==NF_LOG_TYPE_ULOG ) +if (li_user && (li_user->backends &NF_LOG_BACKEND_NFLOG )) li = li_user; -else - li = &default_loginfo; +else /* This packet is none of our buisness */ +return ; - inst =instance_lookup_get (li->u.ulog.group); + inst =instance_lookup_get (li->group);if (!inst) inst =instance_lookup_get (0 );if (!inst) {PRINTR ("nfnetlink_log: trying to log packet, " -"but no instance for group %u\n" , li->u.ulog.group); +"but no instance for group %u\n" , li->group);return ; }
@@ -644,8 +646,8 @@ nfulnl_log_packet(unsigned int pf, qthreshold = inst->qthreshold;/* per-rule qthreshold overrides per-instance */ -if (qthreshold > li->u.ulog.qthreshold) - qthreshold = li->u.ulog.qthreshold; +if (qthreshold > li->qthreshold) + qthreshold = li->qthreshold;switch (inst->copy_mode) {case NFULNL_COPY_META :
@@ -848,7 +850,7 @@ nfulnl_recv_config(struct sock *ctnl, stUDEBUG ("unregistering log handler for pf=%u\n" , pf);/* This is a bug and a feature. We cannot unregister * other handlers, like nfnetlink_inst can */ -nf_log_unregister_pf (pf); +nf_log_unregister_pf (pf, &nfulnl_logger);break ;default : ret = -EINVAL ;
net/netfilter/xt_LOG.c new file +136 -0
136 lines not on this page · raw message
Quoted 3 lines · Gregor Maier
Hi,
I wrote a patch about 2 month ago, that does something similiar.
mh, I must have missed that, sorry.
Quoted 2 lines
Maybe some of it is usefull. If you are interested I would venture to update the patch.
I think we should merge them in some way.
Quoted 2 lines
The patch uses only a modified version of the normal LOG target, but I wanted to change this to a
NF_LOGtarget anyway.
Ok, a new LOG target would be fine, yes.
I now actually like the idea that the old LOG target and old ULOG target just continue to do what the used to do.
Only NFLOG supersedes all of them, and allows to access the full flexibility of all backends.
Quoted 1 line
* Everything uses
nf_log.cas logging API (excpect the obsolete ULOG targets)
as indicated, maybe we should modify LOG back to the old syslog-only behaviour, too.
Quoted 2 lines
* Loggers in
nf_log.care stackable. More than one logger can be registered per PF
I don't like that idea, since it is overkill from my point of view. If somebody wants to log a packet twice, he can have multiple rules in the ruleset for doing so.
Quoted 3 lines
*
nf_loginfostruct has been changed. Instead of the type field and the union there is a "backends" field now that contains a bitmask specifing which backends should process/log this packet.
bitmask is only required if we go for multiple backends.
Quoted 8 lines
*
ipt_LOGcandip6t_LOG.chave been splitted:
*xt_LOG.cnow contains the targets. The targets always usenf_logfor logging. These should be the only logging targets. They take care of setting upnf_loginfofor logging to syslog and/or to other backends
*ip_log_syslog.candip6_log_syslog.care new and contain the syslog log backends. When these modules are loaded, the syslog backend is registered withnf_log
that makes sense to a certain degree. However, if we say that LOG should be just like in old times, and we have a new NFLOG target, then that change makes a little bit less sense. Still I like it because it's clean.
However, we need to make sure that module autoloading works, e.g. if somebody uses your xt_LOG (or the 'LOG as in old times' target), then the ip*_log_syslog.ko backend would have to be loaded on demand. Also, I'd prefer the names to indicate that they're netfilter related.
Quoted 4 lines
POTENTIAL PROBLEMS / ALTERNATIVE SOLUTION
*ipt_log_infoandip6t_log_infohave been replaced byxt_log_info(which has changed in size). This means iptables must be recompiled and older iptables versions won't work with these changes.
this is not acceptable.
I'll modify my patch and merge the changes of your patch that I like and produce a resulting patchset later today.
Thansk!
Signature · 5 lines
- Harald Welte <[email protected]> http://netfilter.org/ ============================================================================ "Fragmentation is like classful addressing -- an interesting early architectural error that shows how much experimentation was going on while IP was being designed." -- Paul Vixie
Quoted 2 lines · Harald Welte
I now actually like the idea that the old LOG target and old ULOG target just continue to do what the used to do.
I fully agree. I already changed the default behaviour back to just use their own logging functions, nf_log backends can be used by specifying an extra flag. This isn't supported by userspace so far, so we are free to rip it out again.
Quoted 7 lines · Patrick McHardy
Quoted 2 lines
I now actually like the idea that the old LOG target and old ULOG target just continue to do what the used to do.
I fully agree. I already changed the default behaviour back to just use their own logging functions,
nf_logbackends can be used by specifying an extra flag. This isn't supported by userspace so far, so we are free to rip it out again.
IMO this is the best solution too, since the current way is not very transparent to the user. Worse than that, ULOG even is stamped "deprecated" in kconfig of 2.6.15.y, so most people will just be able use the limited arguments of the LOG target.
Signature · 8 lines
Holger Eitzenberger <[email protected]> | Kernel Developer Astaro AG | www.astaro.com | Phone +49-721-25516-246 | Fax -200 Astaro Security Linux - PC Magazine Best of the Year 2004/2005 - CRN Best of the Year 2005 - SC Magazine "Best Buy" & 5 star rating - October 2005, Best of the Year 2005 - Internet Professionell "Empfehlung der Redaktion" - November 2005
Quoted 3 lines · Holger Eitzenberger
IMO this is the best solution too, since the current way is not very transparent to the user. Worse than that, ULOG even is stamped "deprecated" in kconfig of 2.6.15.y, so most people will just be able use the limited arguments of the LOG target.
JFTI: that deprecated has been removed in more current mainline kernels.
Signature · 5 lines
- Harald Welte <[email protected]> http://netfilter.org/ ============================================================================ "Fragmentation is like classful addressing -- an interesting early architectural error that shows how much experimentation was going on while IP was being designed." -- Paul Vixie
Quoted 28 lines · Harald Welte
Hi!
After spending some more time with the
nf_logAPI, I think it still needs some further cleanup.The main point of
nf_logwas to get some unfied support for packet logging backends, independent of the ruleset. We currently have logging backend functionality tied toipt_LOG,ipt_ULOGpacket filter rules, which is inflexible and unsuitable for other entities within netfilter that want to log packets.However, on thing that I missed during the
nf_logimplementation was the fact that it was no longer possible to have some rules using LOG, some others ULOG. With the introduction ofnf_log, it was only possible to use only one logging mechanism at any given point in time.Also, there was no fallback support. If you had configured
nfnetlink_logas your backend and the admin decides to remove that module, nothing will be logged, even though other mechanisms might be available and present in the kernel.Another problem was that neither the ULOG nor the LOG target supported all of the arguments/parameters that the
nfnetlink_logbackend needed. Therefore, it is practically impossible to exploit all the features with the current kernel.Therefore, I now propose the following patchset, which
Quoted 14 lines
1) enhances 'struct
nf_logger' with alist_head, usage counter a priority and pf field
2) cleans up the api. we now call nf_log_[un]register() once from every backend. registering doesn't mean that it's actually active. successive calls to nf_log_[un]bind_pf() will actually bind a given backend to the specified protocol family.
3) introduction of a new NFLOG target. Only that NFLOG target supports all the arguments that all our backends support.
4) Adds 'fallback' support. This means that during unbind or unregistration of a given backend, we check in the global list of logging backends and chose the one with the hightest priority that supports our protocol family.
4) modifyipt_LOG,ipt_ULOG,ip6t_LOGandnfnetlink_logto reflect the abovementioned changes.
That all sounds very reasonable. How is the priority of a backend determined?
Quoted 10 lines
I have implemented the NFLOG target as iptables target (not xtables) due to 'customer need'. However, once we decide that this patch should be merged, I'll provide an
x_tablesversion.There are some open questions:
a) we only search for 'fallback' backends during unregistration/unbind. Should we also do this during registration? Or whenever we receive a packet and don't have a backend? Early registration might become problematic, since we don't really know what the user wants...
I think after each change we should just search for the highest priority backend and use that.
Quoted 3 lines
b) reference counting. We could actually
get_module/put_modulethe module that implements a specific backend rather than using our own use counter.
I guess it depends on whether we want to block unloading while it is in use or do automatic fallback. I tend to prefer the later.
Quoted 2 lines · Patrick McHardy
That all sounds very reasonable. How is the priority of a backend determined?
statically. nfnetlink_log overrules ULOG, which overrules LOG.
We could make that configurable, but I think that's too much flexibility. If a user _wants_ a specific backend, he can chose it. if not, we'll fallback on something.
Quoted 7 lines
Quoted 4 lines
a) we only search for 'fallback' backends during unregistration/unbind. Should we also do this during registration? Or whenever we receive a packet and don't have a backend? Early registration might become problematic, since we don't really know what the user wants...
I think after each change we should just search for the highest priority backend and use that.
ok, that's what the code does now.
Quoted 6 lines
Quoted 3 lines
b) reference counting. We could actually
get_module/put_modulethe module that implements a specific backend rather than using our own use counter.I guess it depends on whether we want to block unloading while it is in use or do automatic fallback. I tend to prefer the later.
I agree, I prefer automatic fallback while giving the user the ability to unload. However, if people automatically unload 'unused' modules, then there might be a problem (however, for both ULOG and nfnetlink_log, userspace listeners would increment the refcount, I think).
Also, there is another unresolved problem: What if we actually have e.g. nfnetlink_log loaded, but it is unable to send a specific packet to userspace because there is no listener for this Address family or log
group? Should we then also fall back on some other backend?
At the moment we only fall back if a backend is unbound, but not if it e.g. returns an error code because it was unable to log a specific packet.
Signature · 5 lines
- Harald Welte <[email protected]> http://netfilter.org/ ============================================================================ "Fragmentation is like classful addressing -- an interesting early architectural error that shows how much experimentation was going on while IP was being designed." -- Paul Vixie
Quoted 7 lines · Harald Welte
Quoted 2 lines · Patrick McHardy
That all sounds very reasonable. How is the priority of a backend determined?
Quoted 5 lines
statically.
nfnetlink_logoverrules ULOG, which overrules LOG.We could make that configurable, but I think that's too much flexibility. If a user _wants_ a specific backend, he can chose it. if not, we'll fallback on something.
I'm not sure about this. I assume a user would choose the backend by specifying extra arguments to the NFLOG target, but that isn't possible for internal logging.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
b) reference counting. We could actually
get_module/put_modulethe module that implements a specific backend rather than using our own use counter.
Quoted 8 lines
Quoted 2 lines
I guess it depends on whether we want to block unloading while it is in use or do automatic fallback. I tend to prefer the later.
I agree, I prefer automatic fallback while giving the user the ability to unload. However, if people automatically unload 'unused' modules, then there might be a problem (however, for both ULOG and
nfnetlink_log, userspace listeners would increment the refcount, I think).
Do people still do that? I think distributions stopped the "rmmod -something" triggered by cron a long time ago. Anyway, netlink listeners will keep the module pinned.
Quoted 8 lines
Also, there is another unresolved problem: What if we actually have e.g.
nfnetlink_logloaded, but it is unable to send a specific packet to userspace because there is no listener for this Address family or log
group? Should we then also fall back on some other backend?At the moment we only fall back if a backend is unbound, but not if it e.g. returns an error code because it was unable to log a specific packet.
If the user explicitly specifies the backend we shouldn't fall back. Otherwise I'm not sure .. it probably makes sense as long as we don't permanently disable the higher priority backend.
BTW, I have a patch queued for 2.6.18 that makes the logging functions return a status. I guess your patch already includes that, shall I drop my patch?
Quoted 4 lines · Harald Welte
I agree, I prefer automatic fallback while giving the user the ability to unload. However, if people automatically unload 'unused' modules, then there might be a problem (however, for both ULOG and
nfnetlink_log, userspace listeners would increment the refcount, I think).
What constitutes in use? If a backend is in use whenever it is the highest priority backend, then blocking unloading would mean nfnetlink_log can never be unloaded. Letting the user choose the highest priority backend would solve that. In which case I think blocking unloading is desirable, we shouldn't unload the backend the user has chosen.
And I assume that log rules can also specify a backend? (eg the LOG and ULOG rules always will) That should probably block unloading too.
Quoted 4 lines
Also, there is another unresolved problem: What if we actually have e.g.
nfnetlink_logloaded, but it is unable to send a specific packet to userspace because there is no listener for this Address family or log
group? Should we then also fall back on some other backend?
Just doing a printk to notify of the error is enough? We probably should be doing a printk anyway if it is a backend the user has chosen explicitly.
Quoted 3 lines · Harald Welte
b) reference counting. We could actually
get_module/put_modulethe module that implements a specific backend rather than using our own use counter.
Yes, I saw this during nfnetlink_log evaluation. It is kind of confusing if the module refcount stays zero all the time.
/holger
Signature · 8 lines
Holger Eitzenberger <[email protected]> | Kernel Developer Astaro AG | www.astaro.com | Phone +49-721-25516-246 | Fax -200 Astaro Security Linux - PC Magazine Best of the Year 2004/2005 - CRN Best of the Year 2005 - SC Magazine "Best Buy" & 5 star rating - October 2005, Best of the Year 2005 - Internet Professionell "Empfehlung der Redaktion" - November 2005