netfilter: logging: factorize logging code to allow reutilization
Subsystems (2)
PATCH v2 1/2 netfilter: logging: factorize logging code to allow reutilization
We need this code to be reusable outside the xt_LOG context, by the nf_tables subsystem.
While at it, split up into AF specifc parts. The resulting two main functions to do the packet logging are: nf_log_ip_packet() nf_log_ip6_packet().
Also, this patch introduces some new Kconfig symbols: IP_NF_LOG, IP6_NF_LOG and NET_NF_LOG.
---
v2: no changes, resending as part of the series.
include/net/netfilter/ipv4/nf_log_ipv4.h | 19 + include/net/netfilter/ipv6/nf_log_ipv6.h | 19 + include/net/netfilter/nf_log.h | 16 + include/net/netfilter/xt_log.h | 6 net/ipv4/netfilter/Kconfig | 7 net/ipv4/netfilter/Makefile | 3 net/ipv4/netfilter/nf_log_ipv4.c | 338 ++++++++++++ net/ipv6/netfilter/Kconfig | 8 net/ipv6/netfilter/Makefile | 4 net/ipv6/netfilter/nf_log_ipv6.c | 365 +++++++++++++ net/netfilter/Kconfig | 10 net/netfilter/Makefile | 3 net/netfilter/nf_log_inet.c | 172 ++++++ net/netfilter/xt_LOG.c | 814 ------------------------------ 14 files changed, 975 insertions(+), 809 deletions(-) create mode 100644 include/net/netfilter/ipv4/nf_log_ipv4.h create mode 100644 include/net/netfilter/ipv6/nf_log_ipv6.h 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_inet.c
include/net/netfilter/ipv4/nf_log_ipv4.h new file +19 -0
@@ -0,0 +1,19 @@ +#ifndef _NF_LOG_IPV4_H_ +#define _NF_LOG_IPV4_H_ + +#include <linux/skbuff.h> + +#include <linux/netfilter.h> +#include <net/netfilter/nf_log.h> + +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); + + +#endif /* _NF_LOG_IPV4_H_ */
include/net/netfilter/ipv6/nf_log_ipv6.h new file +19 -0
@@ -0,0 +1,19 @@ +#ifndef _NF_LOG_IPV6_H_ +#define _NF_LOG_IPV6_H_ + +#include <linux/skbuff.h> + +#include <linux/netfilter.h> +#include <net/netfilter/nf_log.h> + +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); + +#endif /* _NF_LOG_IPV6_H_ */ +
include/net/netfilter/nf_log.h +16 -0
@@ -2,6 +2,8 @@#define _NF_LOG_H#include <linux/netfilter.h> +#include <linux/skbuff.h> +#include <net/netfilter/xt_log.h> /* those NF_LOG_* defines and struct nf_loginfo are legacy definitios that will * disappear once iptables is replaced with pkttables. Please DO NOT use them
@@ -69,4 +71,18 @@ void nf_log_packet(struct net *net,const struct nf_loginfo *li, const char *fmt, ...); +/* common logging functions */ +int nf_log_dump_udp_header (struct sbuff *m,const struct sk_buff *skb, +u8 proto,int fragment,unsigned int offset); +int nf_log_dump_tcp_header (struct sbuff *m,const struct sk_buff *skb, +u8 proto,int fragment,unsigned int offset, +unsigned int logflags); +void nf_log_dump_sk_uid_gid (struct sbuff *m,struct sock *sk); +void nf_log_dump_packet_common (struct sbuff *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 */
include/net/netfilter/xt_log.h +3 -3
@@ -6,7 +6,7 @@ struct sbuff { };static struct sbuff emergency, *emergency_ptr = &emergency; -static __printf(2, 3) int sb_add(struct sbuff *m, const char *f, ...) +static inline __printf(2, 3) int sb_add(struct sbuff *m, const char *f, ...) { va_list args;int len;
@@ -25,7 +25,7 @@ static __printf(2, 3) int sb_add(struct sbuff *m, const char *f, ...)return -1 ; } -static struct sbuff *sb_open (void ) +static inline struct sbuff *sb_open (void ) {struct sbuff *m =kmalloc (sizeof (*m),GFP_ATOMIC );
@@ -39,7 +39,7 @@ static struct sbuff *sb_open(void)return m; } -static void sb_close (struct sbuff *m) +static inline void sb_close (struct sbuff *m) { m->buf[m->count] =0 ;printk ("%s\n" , m->buf);
net/ipv4/netfilter/Kconfig +7 -0
@@ -84,6 +84,13 @@ config IP_NF_IPTABLES To compile it as a module, choose M here. If unsure, say N. +config IP_NF_LOG + tristate "Netfilter logging support" + default n + help + This option enables the logging infraestructure for the Netfilter + system. + if IP_NF_IPTABLES # The matches.
net/ipv4/netfilter/Makefile +3 -0
@@ -61,3 +61,6 @@ obj-$(CONFIG_IP_NF_ARP_MANGLE) += arpt_mangle.o # just filtering instance of ARP tables for now obj-$(CONFIG_IP_NF_ARPFILTER) += arptable_filter.o + +# IPv4 specific logging +obj-$(CONFIG_IP_NF_LOG) += nf_log_ipv4.o
net/ipv4/netfilter/nf_log_ipv4.c new file +338 -0
338 lines not on this page · raw message
net/ipv6/netfilter/Kconfig +8 -0
@@ -68,6 +68,14 @@ config IP6_NF_IPTABLES To compile it as a module, choose M here. If unsure, say N. +config IP6_NF_LOG + tristate "IPv6 Netfilter logging support" + default n + help + This option enables the logging infraestructure for the Netfilter + system in IPv6. + + if IP6_NF_IPTABLES # The simple matches.
net/ipv6/netfilter/Makefile +4 -0
@@ -44,3 +44,7 @@ obj-$(CONFIG_IP6_NF_TARGET_MASQUERADE) += ip6t_MASQUERADE.o obj-$(CONFIG_IP6_NF_TARGET_NPT) += ip6t_NPT.o obj-$(CONFIG_IP6_NF_TARGET_REJECT) += ip6t_REJECT.o obj-$(CONFIG_IP6_NF_TARGET_SYNPROXY) += ip6t_SYNPROXY.o + +# IPv6 specific logging +obj-$(CONFIG_IP6_NF_LOG) += nf_log_ipv6.o +
net/ipv6/netfilter/nf_log_ipv6.c new file +365 -0
365 lines not on this page · raw message
net/netfilter/Kconfig +10 -0
@@ -32,6 +32,13 @@ config NETFILTER_NETLINK_LOG and is also scheduled to replace the old syslog-based ipt_LOG and ip6t_LOG modules. +config NET_NF_LOG + tristate "Netfilter family-agnostic logging support" + default n + help + This option enables the logging infraestructure for the Netfilter + system for address family agnostic protocols. + config NF_CONNTRACK tristate "Netfilter connection tracking support" default m if NETFILTER_ADVANCED=n
@@ -744,6 +751,9 @@ config NETFILTER_XT_TARGET_LED config NETFILTER_XT_TARGET_LOG tristate "LOG target support" + select IP_NF_LOG + select IP6_NF_LOG + select NET_NF_LOG 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
@@ -64,6 +64,9 @@ obj-$(CONFIG_NF_NAT_TFTP) += nf_nat_tftp.o # SYNPROXY obj-$(CONFIG_NETFILTER_SYNPROXY) += nf_synproxy_core.o +# Common log +obj-$(CONFIG_NET_NF_LOG) += nf_log_inet.o + # nf_tables nf_tables-objs += nf_tables_core.o nf_tables_api.o nf_tables-objs += nft_immediate.o nft_cmp.o nft_lookup.o
net/netfilter/nf_log_inet.c new file +172 -0
172 lines not on this page · raw message
net/netfilter/xt_LOG.c +8 -806
840 lines not on this page · raw message
PATCH v2 2/2 netfilter: nf_tables: split nft_log in AF-specific modules
This patch split the nft_log module in AF-specific modules. For NFPROTO_INET, it does nothing but dispatch to the AF-specific modules.
The main benefit of this patch is that we can now use nft_log from userspace without being force to modprobe ipt_LOG, which was an annoying bug.
Some new symbols are added to Kconfig: NFT_LOG_IPV4, NFT_LOG_IPV6 and NFT_LOG_INET.
---
v2: actually solve the nft_log issue regarding the need to load ipt_LOG.
include/net/netfilter/ipv4/nft_log_ipv4.h | 8 ++ include/net/netfilter/ipv6/nft_log_ipv6.h | 8 ++ include/net/netfilter/nft_log.h | 16 ++++ net/ipv4/netfilter/Kconfig | 5 + net/ipv4/netfilter/Makefile | 1 net/ipv4/netfilter/nft_log_ipv4.c | 95 ++++++++++++++++++++++++ net/ipv6/netfilter/Kconfig | 5 + net/ipv6/netfilter/Makefile | 1 net/ipv6/netfilter/nft_log_ipv6.c | 95 ++++++++++++++++++++++++ net/netfilter/Kconfig | 5 + net/netfilter/Makefile | 1 net/netfilter/nft_log.c | 65 +++------------- net/netfilter/nft_log_inet.c | 116 +++++++++++++++++++++++++++++ 13 files changed, 366 insertions(+), 55 deletions(-) create mode 100644 include/net/netfilter/ipv4/nft_log_ipv4.h create mode 100644 include/net/netfilter/ipv6/nft_log_ipv6.h create mode 100644 include/net/netfilter/nft_log.h create mode 100644 net/ipv4/netfilter/nft_log_ipv4.c create mode 100644 net/ipv6/netfilter/nft_log_ipv6.c create mode 100644 net/netfilter/nft_log_inet.c
include/net/netfilter/ipv4/nft_log_ipv4.h new file +8 -0
@@ -0,0 +1,8 @@ +#ifndef _NFT_LOG_IPV4_H_ +#define _NFT_LOG_IPV4_H_ + +void nft_log_ipv4_eval (const struct nft_expr *expr, +struct nft_data data[NFT_REG_MAX +1 ], +const struct nft_pktinfo *pkt); + +#endif /* _NFT_LOG_IPV4_H_ */
include/net/netfilter/ipv6/nft_log_ipv6.h new file +8 -0
@@ -0,0 +1,8 @@ +#ifndef _NFT_LOG_IPV6_H_ +#define _NFT_LOG_IPV6_H_ + +void nft_log_ipv6_eval (const struct nft_expr *expr, +struct nft_data data[NFT_REG_MAX +1 ], +const struct nft_pktinfo *pkt); + +#endif /* _NFT_LOG_IPV6_H_ */
include/net/netfilter/nft_log.h new file +16 -0
@@ -0,0 +1,16 @@ +#ifndef _NFT_LOG_H_ +#define _NFT_LOG_H_ + +struct nft_log { +struct nf_loginfo loginfo; +char *prefix; +}; + +extern const struct nla_policy nft_log_policy[]; + +int nft_log_init (const struct nft_ctx *ctx,const struct nft_expr *expr, +const struct nlattr *const tb[]); +void nft_log_destroy (const struct nft_ctx *ctx,const struct nft_expr *expr); +int nft_log_dump (struct sk_buff *skb,const struct nft_expr *expr); + +#endif /* _NFT_LOG_H_ */
net/ipv4/netfilter/Kconfig +5 -0
@@ -66,6 +66,11 @@ config NFT_REJECT_IPV4 default NFT_REJECT tristate +config NFT_LOG_IPV4 + depends on NF_TABLES_IPV4 + default NFT_LOG + tristate + config NF_TABLES_ARP depends on NF_TABLES tristate "ARP nf_tables support"
net/ipv4/netfilter/Makefile +1 -0
@@ -31,6 +31,7 @@ obj-$(CONFIG_NF_TABLES_IPV4) += nf_tables_ipv4.o obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV4) += nft_chain_route_ipv4.o obj-$(CONFIG_NFT_CHAIN_NAT_IPV4) += nft_chain_nat_ipv4.o obj-$(CONFIG_NFT_REJECT_IPV4) += nft_reject_ipv4.o +obj-$(CONFIG_NFT_LOG_IPV4) += nft_log_ipv4.o obj-$(CONFIG_NF_TABLES_ARP) += nf_tables_arp.o # generic IP tables
net/ipv4/netfilter/nft_log_ipv4.c new file +95 -0
95 lines not on this page · raw message
net/ipv6/netfilter/Kconfig +5 -0
@@ -55,6 +55,11 @@ config NFT_REJECT_IPV6 default NFT_REJECT tristate +config NFT_LOG_IPV6 + depends on NF_TABLES_IPV6 + default NFT_LOG + tristate + config IP6_NF_IPTABLES tristate "IP6 tables support (required for filtering)" depends on INET && IPV6
net/ipv6/netfilter/Makefile +1 -0
@@ -28,6 +28,7 @@ obj-$(CONFIG_NF_TABLES_IPV6) += nf_tables_ipv6.o obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV6) += nft_chain_route_ipv6.o obj-$(CONFIG_NFT_CHAIN_NAT_IPV6) += nft_chain_nat_ipv6.o obj-$(CONFIG_NFT_REJECT_IPV6) += nft_reject_ipv6.o +obj-$(CONFIG_NFT_LOG_IPV6) += nft_log_ipv6.o # matches obj-$(CONFIG_IP6_NF_MATCH_AH) += ip6t_ah.o
net/ipv6/netfilter/nft_log_ipv6.c new file +95 -0
95 lines not on this page · raw message
net/netfilter/Kconfig +5 -0
@@ -532,6 +532,11 @@ config NFT_REJECT_INET default NFT_REJECT tristate +config NFT_LOG_INET + depends on NF_TABLES_INET + default NFT_LOG + tristate + config NFT_COMPAT depends on NF_TABLES depends on NETFILTER_XTABLES
net/netfilter/Makefile +1 -0
@@ -87,6 +87,7 @@ obj-$(CONFIG_NFT_RBTREE) += nft_rbtree.o obj-$(CONFIG_NFT_HASH) += nft_hash.o obj-$(CONFIG_NFT_COUNTER) += nft_counter.o obj-$(CONFIG_NFT_LOG) += nft_log.o +obj-$(CONFIG_NFT_LOG_INET) += nft_log_inet.o # generic X tables obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o
net/netfilter/nft_log.c +10 -55
100 lines not on this page · raw message
net/netfilter/nft_log_inet.c new file +116 -0
116 lines not on this page · raw message