Skip to contentSkip to conversation

netfilter: logging: factorize logging code to allow reutilization

PATCH Superseded Arturo Borrero Gonzalez 2 participants 4 messages Jun 2, 2014

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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.

---
 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
new file mode 100644
index 0000000..82a4965
@@ -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
new file mode 100644
index 0000000..697a9fd
@@ -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
index 99eac12..93b887e 100644
@@ -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
index 9d9756c..f67f066 100644
@@ -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
index a26ce03..e09f364 100644
@@ -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
index 90b8240..d2f4b29 100644
@@ -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
index 4bff1f2..4101334 100644
@@ -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
index 70d3dd6..4a5ffc6 100644
@@ -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
index e9410d1..4133172 100644
@@ -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
index bffdad7..d19e961 100644
@@ -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

#1 lore raw

PATCH 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.

Some new symbols are added to Kconfig: NFT_LOG_IPV4, NFT_LOG_IPV6 and NFT_LOG_INET.

---
 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         |   67 ++++++++++++++++++++++++++++
 net/ipv6/netfilter/Kconfig                |    5 ++
 net/ipv6/netfilter/Makefile               |    1 
 net/ipv6/netfilter/nft_log_ipv6.c         |   67 ++++++++++++++++++++++++++++
 net/netfilter/Kconfig                     |    5 ++
 net/netfilter/Makefile                    |    1 
 net/netfilter/nft_log.c                   |   65 ++++-----------------------
 net/netfilter/nft_log_inet.c              |   70 +++++++++++++++++++++++++++++
 13 files changed, 264 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
new file mode 100644
index 0000000..031eabb
@@ -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
new file mode 100644
index 0000000..8ed9cd7
@@ -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
new file mode 100644
index 0000000..818c289
@@ -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
index e09f364..db32b73 100644
@@ -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
index d2f4b29..1f153e5 100644
@@ -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 +67 -0

67 lines not on this page · raw message

net/ipv6/netfilter/Kconfig +5 -0
index 4101334..4ee6aa3 100644
@@ -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
index 4a5ffc6..047126d 100644
@@ -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 +67 -0

67 lines not on this page · raw message

net/netfilter/Kconfig +5 -0
index 4133172..701f39d 100644
@@ -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
index d19e961..5ac6480 100644
@@ -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 +70 -0

70 lines not on this page · raw message

#2 lore raw

Re: [nf_tables PATCH 2/2] netfilter: nf_tables: split nft_log in AF-specific modules

Quoted 158 lines · Arturo Borrero Gonzalez

This patch split the nft_log module in AF-specific modules. For NFPROTO_INET, it does nothing but dispatch to the AF-specific modules.

Some new symbols are added to Kconfig: NFT_LOG_IPV4, NFT_LOG_IPV6 and NFT_LOG_INET.

---
 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         |   67 ++++++++++++++++++++++++++++
 net/ipv6/netfilter/Kconfig                |    5 ++
 net/ipv6/netfilter/Makefile               |    1
 net/ipv6/netfilter/nft_log_ipv6.c         |   67 ++++++++++++++++++++++++++++
 net/netfilter/Kconfig                     |    5 ++
 net/netfilter/Makefile                    |    1
 net/netfilter/nft_log.c                   |   65 ++++-----------------------
 net/netfilter/nft_log_inet.c              |   70 +++++++++++++++++++++++++++++
 13 files changed, 264 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
new file mode 100644
index 0000000..031eabb
@@ -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
new file mode 100644
index 0000000..8ed9cd7
@@ -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
new file mode 100644
index 0000000..818c289
@@ -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
index e09f364..db32b73 100644
@@ -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
index d2f4b29..1f153e5 100644
@@ -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 +45 -0
new file mode 100644
index 0000000..3b797a3
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2008-2009 Patrick McHardy <[email protected]>
+ * Copyright (c) 2014 Arturo Borrero Gonzalez <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/netlink.h>
+#include <linux/netfilter.h>
+#include <linux/netfilter/nf_tables.h>
+#include <net/netfilter/nf_tables.h>
+#include <net/netfilter/ipv4/nf_log_ipv4.h>
+#include <linux/netdevice.h>
+#include <net/netfilter/nft_log.h>
+
+void nft_log_ipv4_eval(const struct nft_expr *expr,
+		       struct nft_data data[NFT_REG_MAX + 1],
+		       const struct nft_pktinfo *pkt)
+{
+	const struct nft_log *priv = nft_expr_priv(expr);
+	struct net *net = dev_net(pkt->in ? pkt->in : pkt->out);
+
+	nf_log_ip_packet(net, pkt->ops->pf, pkt->ops->hooknum, pkt->skb,
+			 pkt->in, pkt->out, &priv->loginfo, priv->prefix);
+}
+EXPORT_SYMBOL_GPL(nft_log_ipv4_eval);
+
+static struct nft_expr_type nft_log_ipv4_type;
+static const struct nft_expr_ops nft_log_ipv4_ops = {
+	.type		= &nft_log_ipv4_type,
+	.size		= NFT_EXPR_SIZE(sizeof(struct nft_log)),
+	.eval		= nft_log_ipv4_eval,
+	.init		= nft_log_init,
+	.destroy	= nft_log_destroy,
+	.dump		= nft_log_dump,
+};
+
+static struct nft_expr_type nft_log_ipv4_type __read_mostly = {
+	.family		= NFPROTO_IPV4,
+	.name		= "log",

net/ipv4/netfilter/nft_log_ipv4.c line 55

Quoted 10 lines
net/ipv4/netfilter/nft_log_ipv4.c new file +10 -0
+	.ops		= &nft_log_ipv4_ops,
+	.policy		= nft_log_policy,
+	.maxattr	= NFTA_LOG_MAX,
+	.owner		= THIS_MODULE,
+};
+
+static int __init nft_log_ipv4_module_init(void)
+{
+	return nft_register_expr(&nft_log_ipv4_type);
+}

I think there's some important code missing here:

        nf_log_set(net, NFPROTO_IPV4, &ipt_log_logger);

Otherwise, we still need to modprobe ipt_LOG to enable logging after a rule that uses the 'log' expression is added.

And this patchset is all about that ;-)

#3 lore raw

Re: [nf_tables PATCH 2/2] netfilter: nf_tables: split nft_log in AF-specific modules

In reply to Arturo Borrero Gonzalez
Quoted 26 lines · Arturo Borrero Gonzalez
net/netfilter/nft_log_inet.c new file +20 -0
new file mode 100644
index 0000000..b982df8
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2008-2009 Patrick McHardy <[email protected]>
+ * Copyright (c) 2014 Arturo Borrero Gonzalez <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/netlink.h>
+#include <linux/netfilter.h>
+#include <linux/netfilter/nf_tables.h>
+#include <net/netfilter/nf_tables.h>
+#include <net/netfilter/nf_log.h>
+#include <linux/netdevice.h>
+#include <net/netfilter/nft_log.h>

net/netfilter/nft_log_inet.c line 30

Quoted 10 lines
net/netfilter/nft_log_inet.c new file +10 -0
+#include <net/netfilter/ipv4/nft_log_ipv4.h>
+#include <net/netfilter/ipv6/nft_log_ipv6.h>
+
+static void nft_log_inet_eval(const struct nft_expr *expr,
+			      struct nft_data data[NFT_REG_MAX + 1],
+			      const struct nft_pktinfo *pkt)
+{
+	switch (pkt->ops->pf) {
+	case NFPROTO_IPV4:
+		nft_log_ipv4_eval(expr, data, pkt);

missing break here. Otherwise, it falls back on the IPv6 code too.

net/netfilter/nft_log_inet.c line 32

Quoted 2 lines
net/netfilter/nft_log_inet.c new file +2 -0
+	case NFPROTO_IPV6:
+		nft_log_ipv6_eval(expr, data, pkt);

Not really needed, but my suggestion is to add it here as well for consistency.