Netfilter packet logging updates
Subsystems (3)
Pablo Neira Ayuso
maintainercover Netfilter packet logging updates
Hi!
The following patch series contain updates for the Netfilter packet logging infrastructure that aim to finish the nft_log support by providing isolated modules that implement the family packet logger for IPv4, IPv6, ARP and bridged packets.
The result is somewhat similar to what we already have in the conntrack and NAT subsystems, ie. per-family modularized code. The output format aims to be consistent for all families, so nf_tables will solve the inconsistencies between the ebtables and ip{6}tables plain text logging formats. The bridge logger also doesn't replicate the IPv4, IPv6 and ARP code to log packets anymore.
These are the patches:
1) Kill the ulog targets, both ebt_ulog and ipt_ULOG. It's been a long time since we're providing the nfnetlink_log infrastructure.
2) Use an array of loggers, one per type. Basically, we can have the plain text packet logger and the netlink packet logging infrastructure. Now that the old ulog targets are gone, we don't need to keep the list of overlapping loggers anymore. This change prepares the follow up patch to consolidate nf_log_packet() interface.
3) Move Eric Dumazet's log buffering used by xt_LOG to the nf_log core so it can be used from other packet loggers, such as the new ARP packet logger.
4) Move the family specific code from xt_LOG to nf_log_ipv4.c, nf_log_ipv6.c and nf_log_common.c. This allows us to register one logger per family which can be used both from nft_log and xt_LOG.
5) Use the struct nf_loginfo parameter as the explict logger to be used through nf_log_packet(). Thus, the nf_log_packet() routes the packet to the corresponding family and type logger. If not specified, it still uses the default logger.
6) Add the ARP packet logger, which is indirectly used by nft_log through nf_log_packet().
7) Add the bridged packet logger. The ebt_log output has been left in place not to break backward compatibility. The ebt_log is not the default logger anymore, we should also reject new patches that use nf_log_packet() from the ebtables code.
8) Add the inet packet logger for the special inet chain.
9) Complete the nft_log support by allowing to specify the type of logging through the NFTA_LOG_SYSLOG and NFTA_LOG_GROUP attributes, which allows you to select plain kernel logging through the ringbuffer and the nfnetlink_log infrastructure.
Please, let me know if you have any comment. Thanks.
Pablo Neira Ayuso (9):
netfilter: kill ulog targets
netfilter: nf_log: use an array of loggers instead of list
netfilter: nf_log: move log buffering to core logging
netfilter: log: split family specific code to nf_log_{ip,ip6,common}.c files
netfilter: log: nf_log_packet() as real unified interface
netfilter: add generic ARP packet logger
netfilter: bridge: add generic packet logger
netfilter: add generic inet packet logger
netfilter: nft_log: complete logging support
include/net/netfilter/nf_log.h | 42 +- include/net/netfilter/xt_log.h | 54 -- include/uapi/linux/netfilter/nf_tables.h | 4 + include/uapi/linux/netfilter_bridge/Kbuild | 1 - include/uapi/linux/netfilter_bridge/ebt_ulog.h | 38 - include/uapi/linux/netfilter_ipv4/Kbuild | 1 - include/uapi/linux/netfilter_ipv4/ipt_ULOG.h | 49 -- net/bridge/netfilter/Kconfig | 19 +- net/bridge/netfilter/Makefile | 3 + net/bridge/netfilter/ebt_log.c | 47 +- net/bridge/netfilter/ebt_ulog.c | 393 ----------- net/bridge/netfilter/nf_log_bridge.c | 96 +++ net/ipv4/netfilter/Kconfig | 23 +- net/ipv4/netfilter/Makefile | 4 + net/ipv4/netfilter/ipt_ULOG.c | 498 ------------- net/ipv4/netfilter/nf_log_arp.c | 149 ++++ net/ipv4/netfilter/nf_log_ipv4.c | 385 +++++++++++ net/ipv6/netfilter/Kconfig | 5 + net/ipv6/netfilter/Makefile | 3 + net/ipv6/netfilter/nf_log_ipv6.c | 417 +++++++++++ net/netfilter/Kconfig | 10 + net/netfilter/Makefile | 4 + net/netfilter/nf_log.c | 144 +++- net/netfilter/nf_log_common.c | 187 +++++ net/netfilter/nf_log_inet.c | 78 +++ net/netfilter/nfnetlink_log.c | 4 + net/netfilter/nft_log.c | 81 ++- net/netfilter/xt_LOG.c | 884 +----------------------- 28 files changed, 1597 insertions(+), 2026 deletions(-) delete mode 100644 include/net/netfilter/xt_log.h delete mode 100644 include/uapi/linux/netfilter_bridge/ebt_ulog.h delete mode 100644 include/uapi/linux/netfilter_ipv4/ipt_ULOG.h delete mode 100644 net/bridge/netfilter/ebt_ulog.c create mode 100644 net/bridge/netfilter/nf_log_bridge.c delete mode 100644 net/ipv4/netfilter/ipt_ULOG.c create mode 100644 net/ipv4/netfilter/nf_log_arp.c create mode 100644 net/ipv4/netfilter/nf_log_ipv4.c create mode 100644 net/ipv6/netfilter/nf_log_ipv6.c create mode 100644 net/netfilter/nf_log_common.c create mode 100644 net/netfilter/nf_log_inet.c
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 1/9 netfilter: kill ulog targets
This has been marked as deprecated for quite some time and the NFLOG target replacement has been also available since 2006.
--- include/uapi/linux/netfilter_bridge/Kbuild | 1 - include/uapi/linux/netfilter_bridge/ebt_ulog.h | 38 -- include/uapi/linux/netfilter_ipv4/Kbuild | 1 - include/uapi/linux/netfilter_ipv4/ipt_ULOG.h | 49 --- net/bridge/netfilter/Kconfig | 16 - net/bridge/netfilter/ebt_ulog.c | 393 ------------------- net/ipv4/netfilter/Kconfig | 19 - net/ipv4/netfilter/ipt_ULOG.c | 498 ------------------------ 8 files changed, 1015 deletions(-) delete mode 100644 include/uapi/linux/netfilter_bridge/ebt_ulog.h delete mode 100644 include/uapi/linux/netfilter_ipv4/ipt_ULOG.h delete mode 100644 net/bridge/netfilter/ebt_ulog.c delete mode 100644 net/ipv4/netfilter/ipt_ULOG.c
include/uapi/linux/netfilter_bridge/Kbuild +0 -1
@@ -14,6 +14,5 @@ header-y += ebt_nflog.h header-y += ebt_pkttype.h header-y += ebt_redirect.h header-y += ebt_stp.h -header-y += ebt_ulog.h header-y += ebt_vlan.h header-y += ebtables.h
include/uapi/linux/netfilter_bridge/ebt_ulog.h deleted +0 -38
@@ -1,38 +0,0 @@ -#ifndef _EBT_ULOG_H -#define _EBT_ULOG_H - -#include <linux/types.h> - -#define EBT_ULOG_DEFAULT_NLGROUP 0 -#define EBT_ULOG_DEFAULT_QTHRESHOLD 1 -#define EBT_ULOG_MAXNLGROUPS 32/* hardcoded netlink max */ -#define EBT_ULOG_PREFIX_LEN 32 -#define EBT_ULOG_MAX_QLEN 50 -#define EBT_ULOG_WATCHER "ulog" -#define EBT_ULOG_VERSION 1 - -struct ebt_ulog_info { -__u32 nlgroup; -unsigned int cprange; -unsigned int qthreshold; -char prefix[EBT_ULOG_PREFIX_LEN ]; -}; - -typedef struct ebt_ulog_packet_msg { -int version; -char indev[IFNAMSIZ ]; -char outdev[IFNAMSIZ ]; -char physindev[IFNAMSIZ ]; -char physoutdev[IFNAMSIZ ]; -char prefix[EBT_ULOG_PREFIX_LEN ]; -struct timeval stamp; -unsigned long mark; -unsigned int hook; -size_t data_len; -/* The complete packet, including Ethernet header and perhaps -* the VLAN header is appended */ -unsigned char data[0 ] __attribute__ - ((aligned (__alignof__(struct ebt_ulog_info )))); -}ebt_ulog_packet_msg_t ; - -#endif /* _EBT_ULOG_H */
include/uapi/linux/netfilter_ipv4/Kbuild +0 -1
@@ -5,7 +5,6 @@ header-y += ipt_ECN.h header-y += ipt_LOG.h header-y += ipt_REJECT.h header-y += ipt_TTL.h -header-y += ipt_ULOG.h header-y += ipt_ah.h header-y += ipt_ecn.h header-y += ipt_ttl.h
include/uapi/linux/netfilter_ipv4/ipt_ULOG.h deleted +0 -49
49 lines not on this page · raw message
net/bridge/netfilter/Kconfig +0 -16
@@ -202,22 +202,6 @@ config BRIDGE_EBT_LOG To compile it as a module, choose M here. If unsure, say N. -config BRIDGE_EBT_ULOG - tristate "ebt: ulog support (OBSOLETE)" - help - This option enables the old bridge-specific "ebt_ulog" implementation - which has been obsoleted by the new "nfnetlink_log" code (see - CONFIG_NETFILTER_NETLINK_LOG). - - This option adds the ulog watcher, that you can use in any rule - in any ebtables table. The packet is passed to a userspace - logging daemon using netlink multicast sockets. This differs - from the log watcher in the sense that the complete packet is - sent to userspace instead of a descriptive text and that - netlink multicast sockets are used instead of the syslog. - - To compile it as a module, choose M here. If unsure, say N. - config BRIDGE_EBT_NFLOG tristate "ebt: nflog support" help
net/bridge/netfilter/ebt_ulog.c deleted +0 -393
393 lines not on this page · raw message
net/ipv4/netfilter/Kconfig +0 -19
@@ -159,25 +159,6 @@ config IP_NF_TARGET_SYNPROXY To compile it as a module, choose M here. If unsure, say N. -config IP_NF_TARGET_ULOG - tristate "ULOG target support (obsolete)" - default m if NETFILTER_ADVANCED=n - ---help--- - - This option enables the old IPv4-only "ipt_ULOG" implementation - which has been obsoleted by the new "nfnetlink_log" code (see - CONFIG_NETFILTER_NETLINK_LOG). - - This option adds a `ULOG' target, which allows you to create rules in - any iptables table. The packet is passed to a userspace logging - daemon using netlink multicast sockets; unlike the LOG target - which can only be viewed through syslog. - - The appropriate userspace logging daemon (ulogd) may be obtained from - <http://www.netfilter.org/projects/ulogd/index.html> - - To compile it as a module, choose M here. If unsure, say N. - # NAT + specific targets: nf_conntrack config NF_NAT_IPV4 tristate "IPv4 NAT"
net/ipv4/netfilter/ipt_ULOG.c deleted +0 -498
498 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 2/9 netfilter: nf_log: use an array of loggers instead of list
In reply to Pablo Neira AyusoNow that legacy ulog targets are not available anymore in the tree, we can have up to two possible loggers:
1) The plain text logging via kernel logging ring.
2) The nfnetlink_log infrastructure which delivers log messages to userspace.
This patch replaces the list of loggers by an array of two pointers per family for each possible logger and it also introduces a new field to the nf_logger structure which indicates the position in the logger array (based on the logger type). This prepares a follow up patch that consolidates the nf_log_packet() interface by allowing to specify the logger as parameter.
--- include/net/netfilter/nf_log.h | 15 +++++++++------ net/bridge/netfilter/ebt_log.c | 1 + net/netfilter/nf_log.c | 39 +++++++++++++++++++-------------------- net/netfilter/nfnetlink_log.c | 1 + net/netfilter/xt_LOG.c | 2 ++ 5 files changed, 32 insertions(+), 26 deletions(-)
include/net/netfilter/nf_log.h +9 -6
@@ -12,8 +12,11 @@#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 +enum nf_log_type { +NF_LOG_TYPE_LOG =0 , +NF_LOG_TYPE_ULOG , +NF_LOG_TYPE_MAX +};struct nf_loginfo {u_int8_t type;
@@ -40,10 +43,10 @@ typedef void nf_logfn(struct net *net, const char *prefix);struct nf_logger { -struct module *me; -nf_logfn *logfn; -char *name; -struct list_head list[NFPROTO_NUMPROTO ]; +char *name; +enum nf_log_type type; +nf_logfn *logfn; +struct module *me; };/* Function to register/unregister log function. */
net/bridge/netfilter/ebt_log.c +1 -0
@@ -207,6 +207,7 @@ static struct xt_target ebt_log_tg_reg __read_mostly = {static struct nf_logger ebt_log_logger__read_mostly = { .name ="ebt_log" , + .type =NF_LOG_TYPE_LOG , .logfn = &ebt_log_packet, .me =THIS_MODULE , };
net/netfilter/nf_log.c +19 -20
@@ -16,16 +16,19 @@#define NF_LOG_PREFIXLEN 128#define NFLOGGER_NAME_LEN 64 -static struct list_head nf_loggers_l[NFPROTO_NUMPROTO ]__read_mostly ; +static struct nf_logger *loggers[NFPROTO_NUMPROTO ][NF_LOG_TYPE_MAX ]__read_mostly ;static DEFINE_MUTEX (nf_log_mutex);static struct nf_logger *__find_logger (int pf,const char *str_logger) { -struct nf_logger *t; +int i; -list_for_each_entry (t, &nf_loggers_l[pf], list[pf]) { -if (!strnicmp (str_logger, t->name,strlen (t->name))) -return t; +for (i =0 ; i <NF_LOG_TYPE_MAX ; i++) { +if (loggers[pf][i] ==NULL ) +continue ; +if (!strnicmp (str_logger, loggers[pf][i]->name, +strlen (loggers[pf][i]->name))) +return loggers[pf][i]; }return NULL ;
@@ -73,17 +76,14 @@ int nf_log_register(u_int8_t pf, struct nf_logger *logger)if (pf >=ARRAY_SIZE (init_net.nf.nf_loggers))return -EINVAL ; -for (i =0 ; i <ARRAY_SIZE (logger->list); i++) -INIT_LIST_HEAD (&logger->list[i]); -mutex_lock (&nf_log_mutex);if (pf ==NFPROTO_UNSPEC ) {for (i =NFPROTO_UNSPEC ; i <NFPROTO_NUMPROTO ; i++) -list_add_tail (&(logger->list[i]), &(nf_loggers_l[i])); + loggers[i][logger->type] = logger; }else {/* register at end of list to honor first register win */ -list_add_tail (&logger->list[pf], &nf_loggers_l[pf]); + loggers[pf][logger->type] = logger; }mutex_unlock (&nf_log_mutex);
@@ -98,7 +98,7 @@ void nf_log_unregister(struct nf_logger *logger)mutex_lock (&nf_log_mutex);for (i =0 ; i <NFPROTO_NUMPROTO ; i++) -list_del (&logger->list[i]); + loggers[i][logger->type] =NULL ;mutex_unlock (&nf_log_mutex); }EXPORT_SYMBOL (nf_log_unregister);
@@ -188,8 +188,7 @@ static int seq_show(struct seq_file *s, void *v) {loff_t *pos = v;const struct nf_logger *logger; -struct nf_logger *t; -int ret; +int i, ret;struct net *net =seq_file_net (s); logger = rcu_dereference_protected(net->nf.nf_loggers[*pos],
@@ -203,11 +202,14 @@ static int seq_show(struct seq_file *s, void *v)if (ret <0 )return ret; -list_for_each_entry (t, &nf_loggers_l[*pos], list[*pos]) { - ret =seq_printf (s,"%s" , t->name); +for (i =0 ; i <NF_LOG_TYPE_MAX ; i++) { +if (loggers[*pos][i] ==NULL ) +continue ; + + ret =seq_printf (s,"%s" , loggers[*pos][i]->name);if (ret <0 )return ret; -if (&t->list[*pos] != nf_loggers_l[*pos].prev) { +if (i ==0 && loggers[*pos][i +1 ]) { ret =seq_printf (s,"," );if (ret <0 )return ret;
@@ -389,14 +391,11 @@ static struct pernet_operations nf_log_net_ops = {int __init netfilter_log_init (void ) { -int i, ret; +int ret; ret =register_pernet_subsys (&nf_log_net_ops);if (ret <0 )return ret; -for (i =NFPROTO_UNSPEC ; i <NFPROTO_NUMPROTO ; i++) -INIT_LIST_HEAD (&(nf_loggers_l[i])); -return 0 ; }
net/netfilter/nfnetlink_log.c +1 -0
@@ -773,6 +773,7 @@ nfulnl_recv_unsupp(struct sock *ctnl, struct sk_buff *skb,static struct nf_logger nfulnl_logger__read_mostly = { .name ="nfnetlink_log" , + .type =NF_LOG_TYPE_ULOG , .logfn = &nfulnl_log_packet, .me =THIS_MODULE , };
net/netfilter/xt_LOG.c +2 -0
@@ -896,6 +896,7 @@ static struct xt_target log_tg_regs[] __read_mostly = {static struct nf_logger ipt_log_logger__read_mostly = { .name ="ipt_LOG" , + .type =NF_LOG_TYPE_LOG , .logfn = &ipt_log_packet, .me =THIS_MODULE , };
@@ -903,6 +904,7 @@ static struct nf_logger ipt_log_logger __read_mostly = {#if IS_ENABLED (CONFIG_IP6_NF_IPTABLES )static struct nf_logger ip6t_log_logger__read_mostly = { .name ="ip6t_LOG" , + .type =NF_LOG_TYPE_LOG , .logfn = &ip6t_log_packet, .me =THIS_MODULE , };
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 3/9 netfilter: nf_log: move log buffering to core logging
In reply to Pablo Neira AyusoThis patch moves Eric Dumazet's log buffer implementation from the xt_log.h header file to the core net/netfilter/nf_log.c. This also includes the renaming of the structure and functions to avoid possible undesired namespace clashes.
This change allows us to use it from the arp and bridge packet logging implementation in follow up patches.
--- include/net/netfilter/nf_log.h | 6 + include/net/netfilter/xt_log.h | 54 ------- net/netfilter/nf_log.c | 57 ++++++++ net/netfilter/xt_LOG.c | 301 ++++++++++++++++++++-------------------- 4 files changed, 217 insertions(+), 201 deletions(-) delete mode 100644 include/net/netfilter/xt_log.h
include/net/netfilter/nf_log.h +6 -0
@@ -72,4 +72,10 @@ void nf_log_packet(struct net *net,const struct nf_loginfo *li, const char *fmt, ...); +struct nf_log_buf ; + +struct nf_log_buf *nf_log_buf_open (void ); +__printf(2, 3) int nf_log_buf_add(struct nf_log_buf *m, const char *f, ...); +void nf_log_buf_close (struct nf_log_buf *m); +#endif /* _NF_LOG_H */
include/net/netfilter/xt_log.h deleted +0 -54
54 lines not on this page · raw message
net/netfilter/nf_log.c +57 -0
63 lines not on this page · raw message
net/netfilter/xt_LOG.c +154 -147
769 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 4/9 netfilter: log: split family specific code to nf_log_{ip,ip6,common}.c files
In reply to Pablo Neira AyusoThe plain text logging is currently embedded into the xt_LOG target. In order to be able to use the plain text logging from nft_log, as a first step, this patch moves the family specific code to the following files and Kconfig symbols:
1) net/ipv4/netfilter/nf_log_ip.c: CONFIG_NF_LOG_IPV4
2) net/ipv6/netfilter/nf_log_ip6.c: CONFIG_NF_LOG_IPV6
3) net/netfilter/nf_log_common.c: CONFIG_NF_LOG_COMMON
These new modules will be required by xt_LOG and nft_log. This patch is based on original patch from Arturo Borrero Gonzalez.
--- include/net/netfilter/nf_log.h | 28 ++ net/ipv4/netfilter/Kconfig | 5 + net/ipv4/netfilter/Makefile | 3 + net/ipv4/netfilter/nf_log_ipv4.c | 385 +++++++++++++++++ net/ipv6/netfilter/Kconfig | 5 + net/ipv6/netfilter/Makefile | 3 + net/ipv6/netfilter/nf_log_ipv6.c | 417 ++++++++++++++++++ net/netfilter/Kconfig | 6 + net/netfilter/Makefile | 3 + net/netfilter/nf_log_common.c | 187 ++++++++ net/netfilter/xt_LOG.c | 879 +------------------------------------- 11 files changed, 1047 insertions(+), 874 deletions(-) create mode 100644 net/ipv4/netfilter/nf_log_ipv4.c create mode 100644 net/ipv6/netfilter/nf_log_ipv6.c create mode 100644 net/netfilter/nf_log_common.c
include/net/netfilter/nf_log.h +28 -0
@@ -78,4 +78,32 @@ struct nf_log_buf *nf_log_buf_open(void); __printf(2, 3) int nf_log_buf_add(struct nf_log_buf *m, const char *f, ...);void nf_log_buf_close (struct nf_log_buf *m); +void nf_log_ip_packet (struct net *net,u_int8_t pf, +unsigned int hooknum,const struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +const struct nf_loginfo *loginfo, +const char *prefix); + +void nf_log_ip6_packet (struct net *net,u_int8_t pf, +unsigned int hooknum,const struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +const struct nf_loginfo *loginfo, +const char *prefix); + +/* common logging functions */ +int nf_log_dump_udp_header (struct nf_log_buf *m,const struct sk_buff *skb, +u8 proto,int fragment,unsigned int offset); +int nf_log_dump_tcp_header (struct nf_log_buf *m,const struct sk_buff *skb, +u8 proto,int fragment,unsigned int offset, +unsigned int logflags); +void nf_log_dump_sk_uid_gid (struct nf_log_buf *m,struct sock *sk); +void nf_log_dump_packet_common (struct nf_log_buf *m,u_int8_t pf, +unsigned int hooknum,const struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +const struct nf_loginfo *loginfo, +const char *prefix); +#endif /* _NF_LOG_H */
net/ipv4/netfilter/Kconfig +5 -0
@@ -159,6 +159,11 @@ config IP_NF_TARGET_SYNPROXY To compile it as a module, choose M here. If unsure, say N. +config NF_LOG_IPV4 + tristate "IPv4 logging" + default m if NETFILTER_ADVANCED=n + select NF_LOG_COMMON + # NAT + specific targets: nf_conntrack config NF_NAT_IPV4 tristate "IPv4 NAT"
net/ipv4/netfilter/Makefile +3 -0
@@ -19,6 +19,9 @@ obj-$(CONFIG_NF_NAT_IPV4) += nf_nat_ipv4.o # defrag obj-$(CONFIG_NF_DEFRAG_IPV4) += nf_defrag_ipv4.o +# logging +obj-$(CONFIG_NF_LOG_IPV4) += nf_log_ipv4.o + # NAT helpers (nf_conntrack) obj-$(CONFIG_NF_NAT_H323) += nf_nat_h323.o obj-$(CONFIG_NF_NAT_PPTP) += nf_nat_pptp.o
net/ipv4/netfilter/nf_log_ipv4.c new file +385 -0
385 lines not on this page · raw message
net/ipv6/netfilter/Kconfig +5 -0
@@ -227,6 +227,11 @@ config IP6_NF_SECURITY If unsure, say N. +config NF_LOG_IPV6 + tristate "IPv6 logging" + depends on NETFILTER_ADVANCED + select NF_LOG_COMMON + config NF_NAT_IPV6 tristate "IPv6 NAT" depends on NF_CONNTRACK_IPV6
net/ipv6/netfilter/Makefile +3 -0
@@ -23,6 +23,9 @@ obj-$(CONFIG_NF_NAT_IPV6) += nf_nat_ipv6.o nf_defrag_ipv6-y := nf_defrag_ipv6_hooks.o nf_conntrack_reasm.o obj-$(CONFIG_NF_DEFRAG_IPV6) += nf_defrag_ipv6.o +# logging +obj-$(CONFIG_NF_LOG_IPV6) += nf_log_ipv6.o + # nf_tables obj-$(CONFIG_NF_TABLES_IPV6) += nf_tables_ipv6.o obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV6) += nft_chain_route_ipv6.o
net/ipv6/netfilter/nf_log_ipv6.c new file +417 -0
417 lines not on this page · raw message
net/netfilter/Kconfig +6 -0
@@ -359,6 +359,9 @@ config NETFILTER_NETLINK_QUEUE_CT If this option is enabled, NFQUEUE can include Connection Tracking information together with the packet is the enqueued via NFNETLINK. +config NF_LOG_COMMON + tristate + config NF_NAT tristate
@@ -744,6 +747,9 @@ config NETFILTER_XT_TARGET_LED config NETFILTER_XT_TARGET_LOG tristate "LOG target support" + select NF_LOG + select NF_LOG_IPV4 + select NF_LOG_IPV6 default m if NETFILTER_ADVANCED=n help This option adds a `LOG' target, which allows you to create rules in
net/netfilter/Makefile +3 -0
@@ -47,6 +47,9 @@ obj-$(CONFIG_NF_CONNTRACK_TFTP) += nf_conntrack_tftp.o nf_nat-y := nf_nat_core.o nf_nat_proto_unknown.o nf_nat_proto_common.o \ nf_nat_proto_udp.o nf_nat_proto_tcp.o nf_nat_helper.o +# generic transport layer logging +obj-$(CONFIG_NF_LOG_COMMON) += nf_log_common.o + obj-$(CONFIG_NF_NAT) += nf_nat.o # NAT protocols (nf_nat)
net/netfilter/nf_log_common.c new file +187 -0
187 lines not on this page · raw message
net/netfilter/xt_LOG.c +5 -874
905 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 5/9 netfilter: log: nf_log_packet() as real unified interface
In reply to Pablo Neira AyusoBefore this patch, the nf_loginfo parameter specified the logging configuration in case the specified default logger was loaded. This patch updates the semantics of the nf_loginfo parameter in nf_log_packet() which now indicates the logger that you explicitly want to use.
Thus, nf_log_packet() is exposed as an unified interface which internally routes the log message to the corresponding logger type by family.
The module dependencies are expressed by the new nf_logger_find_get() and nf_logger_put() functions which bump the logger module refcount. Thus, you can not remove logger modules that are used by rules anymore.
Another important effect of this change is that the family specific module is only loaded when required. Therefore, xt_LOG and nft_log will just trigger the autoload of the nf_log_{ip,ip6} modules according to the family.
--- include/net/netfilter/nf_log.h | 20 ++++++------------- net/ipv4/netfilter/nf_log_ipv4.c | 14 ++++++------- net/ipv6/netfilter/nf_log_ipv6.c | 14 ++++++------- net/netfilter/nf_log.c | 41 +++++++++++++++++++++++++++++++++++++- net/netfilter/nfnetlink_log.c | 3 +++ net/netfilter/xt_LOG.c | 22 ++++++++++---------- 6 files changed, 73 insertions(+), 41 deletions(-)
include/net/netfilter/nf_log.h +6 -14
@@ -61,6 +61,12 @@ int nf_log_bind_pf(struct net *net, u_int8_t pf, const struct nf_logger *logger);void nf_log_unbind_pf (struct net *net,u_int8_t pf); +int nf_logger_find_get (int pf,enum nf_log_type type); +void nf_logger_put (int pf,enum nf_log_type type); + +#define MODULE_ALIAS_NF_LOGGER (family, type) \ + MODULE_ALIAS("nf-logger-" __stringify(family) "-" __stringify(type)) +/* Calls the registered backend logging function */ __printf(8, 9) void nf_log_packet(struct net *net,
@@ -78,20 +84,6 @@ struct nf_log_buf *nf_log_buf_open(void); __printf(2, 3) int nf_log_buf_add(struct nf_log_buf *m, const char *f, ...);void nf_log_buf_close (struct nf_log_buf *m); -void nf_log_ip_packet (struct net *net,u_int8_t pf, -unsigned int hooknum,const struct sk_buff *skb, -const struct net_device *in, -const struct net_device *out, -const struct nf_loginfo *loginfo, -const char *prefix); - -void nf_log_ip6_packet (struct net *net,u_int8_t pf, -unsigned int hooknum,const struct sk_buff *skb, -const struct net_device *in, -const struct net_device *out, -const struct nf_loginfo *loginfo, -const char *prefix); -/* common logging functions */ int nf_log_dump_udp_header (struct nf_log_buf *m,const struct sk_buff *skb,u8 proto,int fragment,unsigned int offset);
net/ipv4/netfilter/nf_log_ipv4.c +7 -7
@@ -306,12 +306,12 @@ fallback:nf_log_buf_add (m," " ); } -void nf_log_ip_packet (struct net *net,u_int8_t pf, -unsigned int hooknum,const struct sk_buff *skb, -const struct net_device *in, -const struct net_device *out, -const struct nf_loginfo *loginfo, -const char *prefix) +static void nf_log_ip_packet (struct net *net,u_int8_t pf, +unsigned int hooknum,const struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +const struct nf_loginfo *loginfo, +const char *prefix) {struct nf_log_buf *m;
@@ -334,7 +334,6 @@ void nf_log_ip_packet(struct net *net, u_int8_t pf,nf_log_buf_close (m); } -EXPORT_SYMBOL_GPL (nf_log_ip_packet);static struct nf_logger nf_ip_logger__read_mostly = { .name ="nf_log_ipv4" ,
@@ -383,3 +382,4 @@ module_exit(nf_log_ipv4_exit);MODULE_AUTHOR ("Netfilter Core Team <[email protected]>" );MODULE_DESCRIPTION ("Netfilter IPv4 packet logging" );MODULE_LICENSE ("GPL" ); +MODULE_ALIAS_NF_LOGGER (AF_INET ,0 );
net/ipv6/netfilter/nf_log_ipv6.c +7 -7
@@ -338,12 +338,12 @@ fallback: } } -void nf_log_ip6_packet (struct net *net,u_int8_t pf, -unsigned int hooknum,const struct sk_buff *skb, -const struct net_device *in, -const struct net_device *out, -const struct nf_loginfo *loginfo, -const char *prefix) +static void nf_log_ip6_packet (struct net *net,u_int8_t pf, +unsigned int hooknum,const struct sk_buff *skb, +const struct net_device *in, +const struct net_device *out, +const struct nf_loginfo *loginfo, +const char *prefix) {struct nf_log_buf *m;
@@ -366,7 +366,6 @@ void nf_log_ip6_packet(struct net *net, u_int8_t pf,nf_log_buf_close (m); } -EXPORT_SYMBOL_GPL (nf_log_ip6_packet);static struct nf_logger nf_ip6_logger__read_mostly = { .name ="nf_log_ipv6" ,
@@ -415,3 +414,4 @@ module_exit(nf_log_ipv6_exit);MODULE_AUTHOR ("Netfilter Core Team <[email protected]>" );MODULE_DESCRIPTION ("Netfilter IPv4 packet logging" );MODULE_LICENSE ("GPL" ); +MODULE_ALIAS_NF_LOGGER (AF_INET6 ,0 );
net/netfilter/nf_log.c +40 -1
53 lines not on this page · raw message
net/netfilter/nfnetlink_log.c +3 -0
@@ -1106,6 +1106,9 @@ MODULE_DESCRIPTION("netfilter userspace logging");MODULE_AUTHOR ("Harald Welte <[email protected]>" );MODULE_LICENSE ("GPL" );MODULE_ALIAS_NFNL_SUBSYS (NFNL_SUBSYS_ULOG ); +MODULE_ALIAS_NF_LOGGER (AF_INET ,1 ); +MODULE_ALIAS_NF_LOGGER (AF_INET6 ,1 ); +MODULE_ALIAS_NF_LOGGER (AF_BRIDGE ,1 );module_init (nfnetlink_log_init);module_exit (nfnetlink_log_fini);
net/netfilter/xt_LOG.c +10 -12
@@ -39,17 +39,8 @@ log_tg(struct sk_buff *skb, const struct xt_action_param *par) li.u.log.level = loginfo->level; li.u.log.logflags = loginfo->logflags; -if (par->family ==NFPROTO_IPV4 ) -nf_log_ip_packet (net,NFPROTO_IPV4 , par->hooknum, skb, par->in, - par->out, &li, loginfo->prefix); -#if IS_ENABLED (CONFIG_IP6_NF_IPTABLES ) - else if (par->family == NFPROTO_IPV6) - nf_log_ip6_packet(net, NFPROTO_IPV6, par->hooknum, skb, par->in, - par->out, &li, loginfo->prefix); -#endif - else - WARN_ON_ONCE(1); - +nf_log_packet (net, par->family, par->hooknum, skb, par->in, par->out, + &li, loginfo->prefix);return XT_CONTINUE ; }
@@ -70,7 +61,12 @@ static int log_tg_check(const struct xt_tgchk_param *par)return -EINVAL ; } -return 0 ; +return nf_logger_find_get (par->family,NF_LOG_TYPE_LOG ); +} + +static void log_tg_destroy (const struct xt_tgdtor_param *par) +{ +nf_logger_put (par->family,NF_LOG_TYPE_LOG ); }static struct xt_target log_tg_regs[]__read_mostly = {
@@ -80,6 +76,7 @@ static struct xt_target log_tg_regs[] __read_mostly = { .target = log_tg, .targetsize = sizeof(struct xt_log_info), .checkentry = log_tg_check, + .destroy = log_tg_destroy, .me = THIS_MODULE, },#if IS_ENABLED (CONFIG_IP6_NF_IPTABLES )
@@ -89,6 +86,7 @@ static struct xt_target log_tg_regs[] __read_mostly = { .target = log_tg, .targetsize = sizeof(struct xt_log_info), .checkentry = log_tg_check, + .destroy = log_tg_destroy, .me = THIS_MODULE, },#endif
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 6/9 netfilter: add generic ARP packet logger
In reply to Pablo Neira AyusoThis adds the generic plain text packet loggger for ARP packets. It is based on the ebt_log code. Nevertheless, the output has been modified to make it consistent with the original xt_LOG output.
This is an example output:
IN=wlan0 OUT= ARP HTYPE=1 PTYPE=0x0800 OPCODE=2 MACSRC=00:ab:12:34:55:63 IPSRC=192.168.10.1 MACDST=80:09:12:70:4f:50 IPDST=192.168.10.150
This patch enables packet logging from ARP chains, eg.
nft add rule arp filter input log prefix "input: "
--- net/ipv4/netfilter/Kconfig | 5 ++ net/ipv4/netfilter/Makefile | 1 + net/ipv4/netfilter/nf_log_arp.c | 149 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 155 insertions(+) create mode 100644 net/ipv4/netfilter/nf_log_arp.c
net/ipv4/netfilter/Kconfig +5 -0
@@ -159,6 +159,11 @@ config IP_NF_TARGET_SYNPROXY To compile it as a module, choose M here. If unsure, say N. +config NF_LOG_ARP + tristate "ARP logging" + default m if NETFILTER_ADVANCED=n + select NF_LOG_INET + config NF_LOG_IPV4 tristate "IPv4 logging" default m if NETFILTER_ADVANCED=n
net/ipv4/netfilter/Makefile +1 -0
@@ -20,6 +20,7 @@ obj-$(CONFIG_NF_NAT_IPV4) += nf_nat_ipv4.o obj-$(CONFIG_NF_DEFRAG_IPV4) += nf_defrag_ipv4.o # logging +obj-$(CONFIG_NF_LOG_ARP) += nf_log_arp.o obj-$(CONFIG_NF_LOG_IPV4) += nf_log_ipv4.o # NAT helpers (nf_conntrack)
net/ipv4/netfilter/nf_log_arp.c new file +149 -0
149 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 7/9 netfilter: bridge: add generic packet logger
In reply to Pablo Neira AyusoThis adds the generic plain text packet loggger for bridged packets. It routes the logging message to the real protocol packet logger. I decided not to refactor the ebt_log code for two reasons:
1) The ebt_log output is not consistent with the IPv4 and IPv6 Netfilter packet loggers. The output is different for no good reason and it adds redundant code to handle packet logging.
2) To avoid breaking backward compatibility for applications outthere that are parsing the specific ebt_log output, the ebt_log output has been left as is. So only nftables will use the new consistent logging format for logged bridged packets.
More decisions coming in this patch:
1) This also removes ebt_log as default logger for bridged packets. Thus, nf_log_packet() routes packet to this new packet logger instead. This doesn't break backward compatibility since nf_log_packet() is not used to log packets in plain text format from anywhere in the ebtables/netfilter bridge code.
2) The new bridge packet logger also performs a lazy request to register the real IPv4, ARP and IPv6 netfilter packet loggers. If the real protocol logger is no available (not compiled or the module is not available in the system, not packet logging happens.
--- include/net/netfilter/nf_log.h | 1 + net/bridge/netfilter/Kconfig | 3 ++ net/bridge/netfilter/Makefile | 3 ++ net/bridge/netfilter/ebt_log.c | 48 ++--------------- net/bridge/netfilter/nf_log_bridge.c | 96 ++++++++++++++++++++++++++++++++++ net/netfilter/nf_log.c | 7 +++ 6 files changed, 115 insertions(+), 43 deletions(-) create mode 100644 net/bridge/netfilter/nf_log_bridge.c
include/net/netfilter/nf_log.h +1 -0
@@ -63,6 +63,7 @@ void nf_log_unbind_pf(struct net *net, u_int8_t pf);int nf_logger_find_get (int pf,enum nf_log_type type);void nf_logger_put (int pf,enum nf_log_type type); +void nf_logger_request_module (int pf,enum nf_log_type type);#define MODULE_ALIAS_NF_LOGGER (family, type) \ MODULE_ALIAS("nf-logger-" __stringify(family) "-" __stringify(type))
net/bridge/netfilter/Kconfig +3 -0
@@ -14,6 +14,9 @@ config NFT_BRIDGE_META help Add support for bridge dedicated meta key. +config NF_LOG_BRIDGE + tristate "Bridge packet logging" + endif # NF_TABLES_BRIDGE menuconfig BRIDGE_NF_EBTABLES
net/bridge/netfilter/Makefile +3 -0
@@ -5,6 +5,9 @@ obj-$(CONFIG_NF_TABLES_BRIDGE) += nf_tables_bridge.o obj-$(CONFIG_NFT_BRIDGE_META) += nft_meta_bridge.o +# packet logging +obj-$(CONFIG_NF_LOG_BRIDGE) += nf_log_bridge.o + obj-$(CONFIG_BRIDGE_NF_EBTABLES) += ebtables.o # tables
net/bridge/netfilter/ebt_log.c +5 -43
66 lines not on this page · raw message
net/bridge/netfilter/nf_log_bridge.c new file +96 -0
96 lines not on this page · raw message
net/netfilter/nf_log.c +7 -0
@@ -129,6 +129,13 @@ void nf_log_unbind_pf(struct net *net, u_int8_t pf) }EXPORT_SYMBOL (nf_log_unbind_pf); +void nf_logger_request_module (int pf,enum nf_log_type type) +{ +if (loggers[pf][type] ==NULL ) +request_module ("nf-logger-%u-%u" , pf, type); +} +EXPORT_SYMBOL_GPL (nf_logger_request_module); +int nf_logger_find_get (int pf,enum nf_log_type type) {struct nf_logger *logger;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 8/9 netfilter: add generic inet packet logger
In reply to Pablo Neira AyusoThis allows you to log packets from the special inet chains.
--- net/netfilter/Kconfig | 4 +++ net/netfilter/Makefile | 3 +- net/netfilter/nf_log_inet.c | 78 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 net/netfilter/nf_log_inet.c
net/netfilter/Kconfig +4 -0
@@ -362,6 +362,10 @@ config NETFILTER_NETLINK_QUEUE_CT config NF_LOG_COMMON tristate +config NF_LOG_INET + tristate "INET packet logging" + default m if NETFILTER_ADVANCED=n + config NF_NAT tristate
net/netfilter/Makefile +2 -1
@@ -47,7 +47,8 @@ obj-$(CONFIG_NF_CONNTRACK_TFTP) += nf_conntrack_tftp.o nf_nat-y := nf_nat_core.o nf_nat_proto_unknown.o nf_nat_proto_common.o \ nf_nat_proto_udp.o nf_nat_proto_tcp.o nf_nat_helper.o -# generic transport layer logging +# packet logging +obj-$(CONFIG_NF_LOG_INET) += nf_log_inet.o obj-$(CONFIG_NF_LOG_COMMON) += nf_log_common.o obj-$(CONFIG_NF_NAT) += nf_nat.o
net/netfilter/nf_log_inet.c new file +78 -0
78 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 9/9 netfilter: nft_log: complete logging support
In reply to Pablo Neira AyusoUse the unified nf_log_packet() interface that allows us explicit logger selection through the nf_loginfo structure.
If you specify the group attribute, this means you want to receive logging messages through nfnetlink_log. In that case, the snaplen and qthreshold attributes allows you to tune internal aspects of the netlink logging infrastructure.
On the other hand, if the level is specified, then the plain text format through the kernel logging ring is used instead, which is also used by default if neither group nor level are indicated.
--- include/uapi/linux/netfilter/nf_tables.h | 4 ++ net/netfilter/nft_log.c | 81 +++++++++++++++++++++++------- 2 files changed, 67 insertions(+), 18 deletions(-)
include/uapi/linux/netfilter/nf_tables.h +4 -0
@@ -697,6 +697,8 @@ enum nft_counter_attributes {* @NFTA_LOG_PREFIX: prefix to prepend to log messages (NLA_STRING) * @NFTA_LOG_SNAPLEN: length of payload to include in netlink message (NLA_U32) * @NFTA_LOG_QTHRESHOLD: queue threshold (NLA_U32) +* @NFTA_LOG_SYSLOG: syslog level (NLA_U32) +* @NFTA_LOG_FLAGS: logging flags (NLA_U32) */ enum nft_log_attributes {NFTA_LOG_UNSPEC ,
@@ -704,6 +706,8 @@ enum nft_log_attributes {NFTA_LOG_PREFIX ,NFTA_LOG_SNAPLEN ,NFTA_LOG_QTHRESHOLD , +NFTA_LOG_SYSLOG , +NFTA_LOG_FLAGS , __NFTA_LOG_MAX };#define NFTA_LOG_MAX (__NFTA_LOG_MAX - 1)
net/netfilter/nft_log.c +63 -18
121 lines not on this page · raw message
Signature · 1 line
1.7.10.4