Skip to contentSkip to conversation

netfilter: merge nf_log_proto modules

PATCH In review Florian Westphal 3 participants 11 messages Mar 25, 2021 – Mar 30, 2021

Subsystems (3)
lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

cover netfilter: merge nf_log_proto modules

Netfilter has multiple log modules:
nf_log_arp
nf_log_bridge
nf_log_ipv4
nf_log_ipv6
nf_log_netdev
nfnetlink_log
nf_log_common

With the exception of nfnetlink_log (packet is sent to userspace for dissection/logging) all of them log to the kernel ringbuffer.

This series merges all modules except nfnetlink_log into a single module, nf_log_syslog.

After the series, only two log modules remain:
nfnetlink_log and nf_log_syslog. The latter provides the same functionality as the old per-af log modules.

Last patch allows to move log backend module load
to nft_log to avoid a deadlock that can occur when request_module() is called with the nft transaction mutex held.

Florian Westphal (8):
netfilter: nf_log_ipv4: rename to nf_log_syslog
netfilter: nf_log_arp: merge with nf_log_syslog
netfilter: nf_log_ipv6: merge with nf_log_syslog
netfilter: nf_log_netdev: merge with nf_log_syslog
netfilter: nf_log_bridge: merge with nf_log_syslog
netfilter: nf_log_common: merge with nf_log_syslog
netfilter: nf_log: add module softdeps
netfilter: nft_log: perform module load from nf_tables

 include/net/netfilter/nf_log.h       |   25 -
 include/net/netfilter/nf_tables.h    |    5 +
 net/bridge/netfilter/Kconfig         |    4 -
 net/bridge/netfilter/Makefile        |    3 -
 net/bridge/netfilter/nf_log_bridge.c |   79 --
 net/ipv4/netfilter/Kconfig           |   10 +-
 net/ipv4/netfilter/Makefile          |    4 -
 net/ipv4/netfilter/nf_log_arp.c      |  172 ----
 net/ipv4/netfilter/nf_log_ipv4.c     |  395 ----------
 net/ipv6/netfilter/Kconfig           |    5 +-
 net/ipv6/netfilter/Makefile          |    3 -
 net/ipv6/netfilter/nf_log_ipv6.c     |  427 ----------
 net/netfilter/Kconfig                |   20 +-
 net/netfilter/Makefile               |    6 +-
 net/netfilter/nf_log.c               |   10 -
 net/netfilter/nf_log_common.c        |  224 ------
 net/netfilter/nf_log_netdev.c        |   78 --
 net/netfilter/nf_log_syslog.c        | 1089 ++++++++++++++++++++++++++
 net/netfilter/nf_tables_api.c        |    5 +-
 net/netfilter/nft_log.c              |   20 +-
 net/netfilter/xt_LOG.c               |    1 +
 net/netfilter/xt_NFLOG.c             |    1 +
 net/netfilter/xt_TRACE.c             |    1 +
 23 files changed, 1144 insertions(+), 1443 deletions(-)
 delete mode 100644 net/bridge/netfilter/nf_log_bridge.c
 delete mode 100644 net/ipv4/netfilter/nf_log_arp.c
 delete mode 100644 net/ipv4/netfilter/nf_log_ipv4.c
 delete mode 100644 net/ipv6/netfilter/nf_log_ipv6.c
 delete mode 100644 net/netfilter/nf_log_common.c
 delete mode 100644 net/netfilter/nf_log_netdev.c
 create mode 100644 net/netfilter/nf_log_syslog.c
Signature · 1 line
2.26.3
author maintainer
#1 lore raw

PATCH 1/8 netfilter: nf_log_ipv4: rename to nf_log_syslog

Netfilter has multiple log modules:
nf_log_arp
nf_log_bridge
nf_log_ipv4
nf_log_ipv6
nf_log_netdev
nfnetlink_log
nf_log_common

With the exception of nfnetlink_log (packet is sent to userspace for dissection/logging), all of them log to the kernel ringbuffer.

This is the first part of a series to merge all modules except nfnetlink_log into a single module: nf_log_syslog.

This allows to reduce code. After the series, only two log modules remain:
nfnetlink_log and nf_log_syslog. The latter provides the same functionality as the old per-af log modules.

This renames nf_log_ipv4 to nf_log_syslog.

---
 net/ipv4/netfilter/Kconfig                    |   5 +-
 net/ipv4/netfilter/Makefile                   |   1 -
 net/netfilter/Kconfig                         |  14 +-
 net/netfilter/Makefile                        |   1 +
 .../nf_log_syslog.c}                          | 120 +++++++++---------
 5 files changed, 76 insertions(+), 65 deletions(-)
 rename net/{ipv4/netfilter/nf_log_ipv4.c => netfilter/nf_log_syslog.c} (78%)
net/ipv4/netfilter/Kconfig +4 -1
index a2f4f894be2b..aadb98e43fb1 100644
@@ -81,7 +81,10 @@ config NF_LOG_ARP
 config NF_LOG_IPV4
 	tristate "IPv4 packet logging"
 	default m if NETFILTER_ADVANCED=n
-	select NF_LOG_COMMON
+	select NF_LOG_SYSLOG
+	help
+	This is a backwards-compat option for the user's convenience
+	(e.g. when running oldconfig). It selects CONFIG_NF_LOG_SYSLOG.
 
 config NF_REJECT_IPV4
 	tristate "IPv4 packet rejection"
net/ipv4/netfilter/Makefile +0 -1
index 7c497c78105f..abd133048b42 100644
@@ -11,7 +11,6 @@ obj-$(CONFIG_NF_TPROXY_IPV4) += nf_tproxy_ipv4.o
 
 # logging
 obj-$(CONFIG_NF_LOG_ARP) += nf_log_arp.o
-obj-$(CONFIG_NF_LOG_IPV4) += nf_log_ipv4.o
 
 # reject
 obj-$(CONFIG_NF_REJECT_IPV4) += nf_reject_ipv4.o
net/netfilter/Kconfig +13 -1
index 1a92063c73a4..d5c047190eb9 100644
@@ -78,6 +78,18 @@ config NF_LOG_NETDEV
 	tristate "Netdev packet logging"
 	select NF_LOG_COMMON
 
+config NF_LOG_SYSLOG
+	tristate "Syslog packet logging"
+	default m if NETFILTER_ADVANCED=n
+	select NF_LOG_COMMON
+	help
+	  This option enable support for packet logging via syslog.
+	  It supports IPv4 and common transport protocols such as TCP and UDP.
+	  This is a simpler but less flexible logging method compared to
+	  CONFIG_NETFILTER_NETLINK_LOG.
+	  If both are enabled the backend to use can be configured at run-time
+	  by means of per-address-family sysctl tunables.
+
 if NF_CONNTRACK
 config NETFILTER_CONNCOUNT
 	tristate
@@ -923,7 +935,7 @@ config NETFILTER_XT_TARGET_LED
 config NETFILTER_XT_TARGET_LOG
 	tristate "LOG target support"
 	select NF_LOG_COMMON
-	select NF_LOG_IPV4
+	select NF_LOG_SYSLOG
 	select NF_LOG_IPV6 if IP6_NF_IPTABLES
 	default m if NETFILTER_ADVANCED=n
 	help
net/netfilter/Makefile +1 -0
index 33da7bf1b68e..59642d9ab7a5 100644
@@ -50,6 +50,7 @@ nf_nat-y	:= nf_nat_core.o nf_nat_proto.o nf_nat_helper.o
 
 # generic transport layer logging
 obj-$(CONFIG_NF_LOG_COMMON) += nf_log_common.o
+obj-$(CONFIG_NF_LOG_SYSLOG) += nf_log_syslog.o
 
 # packet logging for netdev family
 obj-$(CONFIG_NF_LOG_NETDEV) += nf_log_netdev.o
net/netfilter/nf_log_syslog.c renamed from net/ipv4/netfilter/nf_log_ipv4.c +58 -62

265 lines not on this page · raw message

Signature · 1 line
2.26.3
author maintainer
#2 lore raw

PATCH 2/8 netfilter: nf_log_arp: merge with nf_log_syslog

In reply to Florian Westphal

similar to previous change: nf_log_syslog now covers ARP logging as well, the old nf_log_arp module is removed.

---
 net/ipv4/netfilter/Kconfig      |   5 +-
 net/ipv4/netfilter/Makefile     |   3 -
 net/ipv4/netfilter/nf_log_arp.c | 172 --------------------------------
 net/netfilter/nf_log_syslog.c   | 113 ++++++++++++++++++++-
 4 files changed, 115 insertions(+), 178 deletions(-)
 delete mode 100644 net/ipv4/netfilter/nf_log_arp.c
net/ipv4/netfilter/Kconfig +4 -1
index aadb98e43fb1..63cb953bd019 100644
@@ -76,7 +76,10 @@ config NF_DUP_IPV4
 config NF_LOG_ARP
 	tristate "ARP packet logging"
 	default m if NETFILTER_ADVANCED=n
-	select NF_LOG_COMMON
+	select NF_LOG_SYSLOG
+	help
+	This is a backwards-compat option for the user's convenience
+	(e.g. when running oldconfig). It selects CONFIG_NF_LOG_SYSLOG.
 
 config NF_LOG_IPV4
 	tristate "IPv4 packet logging"
net/ipv4/netfilter/Makefile +0 -3
index abd133048b42..f38fb1368ddb 100644
@@ -9,9 +9,6 @@ obj-$(CONFIG_NF_DEFRAG_IPV4) += nf_defrag_ipv4.o
 obj-$(CONFIG_NF_SOCKET_IPV4) += nf_socket_ipv4.o
 obj-$(CONFIG_NF_TPROXY_IPV4) += nf_tproxy_ipv4.o
 
-# logging
-obj-$(CONFIG_NF_LOG_ARP) += nf_log_arp.o
-
 # reject
 obj-$(CONFIG_NF_REJECT_IPV4) += nf_reject_ipv4.o
 
net/ipv4/netfilter/nf_log_arp.c deleted +0 -172

172 lines not on this page · raw message

net/netfilter/nf_log_syslog.c +111 -2

149 lines not on this page · raw message

Signature · 1 line
2.26.3
author maintainer
#3 lore raw

PATCH 3/8 netfilter: nf_log_ipv6: merge with nf_log_syslog

In reply to Florian Westphal

This removes the nf_log_ipv6 module, the functionality is now provided by nf_log_syslog.

---
 net/ipv6/netfilter/Kconfig       |   5 +-
 net/ipv6/netfilter/Makefile      |   3 -
 net/ipv6/netfilter/nf_log_ipv6.c | 427 -------------------------------
 net/netfilter/nf_log_syslog.c    | 358 +++++++++++++++++++++++++-
 4 files changed, 360 insertions(+), 433 deletions(-)
 delete mode 100644 net/ipv6/netfilter/nf_log_ipv6.c
net/ipv6/netfilter/Kconfig +4 -1
index 262bb51a2d99..f22233e44ee9 100644
@@ -69,7 +69,10 @@ config NF_REJECT_IPV6
 config NF_LOG_IPV6
 	tristate "IPv6 packet logging"
 	default m if NETFILTER_ADVANCED=n
-	select NF_LOG_COMMON
+	select NF_LOG_SYSLOG
+	help
+	  This is a backwards-compat option for the user's convenience
+	  (e.g. when running oldconfig). It selects CONFIG_NF_LOG_SYSLOG.
 
 config IP6_NF_IPTABLES
 	tristate "IP6 tables support (required for filtering)"
net/ipv6/netfilter/Makefile +0 -3
index 731a74c60dca..b85383606df7 100644
@@ -18,9 +18,6 @@ obj-$(CONFIG_NF_DEFRAG_IPV6) += nf_defrag_ipv6.o
 obj-$(CONFIG_NF_SOCKET_IPV6) += nf_socket_ipv6.o
 obj-$(CONFIG_NF_TPROXY_IPV6) += nf_tproxy_ipv6.o
 
-# logging
-obj-$(CONFIG_NF_LOG_IPV6) += nf_log_ipv6.o
-
 # reject
 obj-$(CONFIG_NF_REJECT_IPV6) += nf_reject_ipv6.o
 
net/ipv6/netfilter/nf_log_ipv6.c deleted +0 -427

427 lines not on this page · raw message

net/netfilter/nf_log_syslog.c +356 -2

402 lines not on this page · raw message

Signature · 1 line
2.26.3
author maintainer
#4 lore raw

PATCH 4/8 netfilter: nf_log_netdev: merge with nf_log_syslog

In reply to Florian Westphal

Provide netdev family support from the nf_log_syslog module.

---
 net/netfilter/Kconfig         |  4 --
 net/netfilter/Makefile        |  3 --
 net/netfilter/nf_log_netdev.c | 78 -----------------------------------
 net/netfilter/nf_log_syslog.c | 36 ++++++++++++++++
 4 files changed, 36 insertions(+), 85 deletions(-)
 delete mode 100644 net/netfilter/nf_log_netdev.c
net/netfilter/Kconfig +0 -4
index d5c047190eb9..6aef981a8446 100644
@@ -74,10 +74,6 @@ config NF_CONNTRACK
 config NF_LOG_COMMON
 	tristate
 
-config NF_LOG_NETDEV
-	tristate "Netdev packet logging"
-	select NF_LOG_COMMON
-
 config NF_LOG_SYSLOG
 	tristate "Syslog packet logging"
 	default m if NETFILTER_ADVANCED=n
net/netfilter/Makefile +0 -3
index 59642d9ab7a5..429be36fe4c7 100644
@@ -52,9 +52,6 @@ nf_nat-y	:= nf_nat_core.o nf_nat_proto.o nf_nat_helper.o
 obj-$(CONFIG_NF_LOG_COMMON) += nf_log_common.o
 obj-$(CONFIG_NF_LOG_SYSLOG) += nf_log_syslog.o
 
-# packet logging for netdev family
-obj-$(CONFIG_NF_LOG_NETDEV) += nf_log_netdev.o
-
 obj-$(CONFIG_NF_NAT) += nf_nat.o
 nf_nat-$(CONFIG_NF_NAT_REDIRECT) += nf_nat_redirect.o
 nf_nat-$(CONFIG_NF_NAT_MASQUERADE) += nf_nat_masquerade.o
net/netfilter/nf_log_netdev.c deleted +0 -78

78 lines not on this page · raw message

net/netfilter/nf_log_syslog.c +36 -0
index 9ba71bc2ef84..617e0071c0c4 100644
@@ -768,6 +768,25 @@ static struct nf_logger nf_ip6_logger __read_mostly = {
 	.me		= THIS_MODULE,
 };
 
+static void nf_log_netdev_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)
+{
+	nf_log_l2packet(net, pf, skb->protocol, hooknum, skb, in, out,
+			loginfo, prefix);
+}
+
+static struct nf_logger nf_netdev_logger __read_mostly = {
+	.name		= "nf_log_netdev",
+	.type		= NF_LOG_TYPE_LOG,
+	.logfn		= nf_log_netdev_packet,
+	.me		= THIS_MODULE,
+};
+
 static int __net_init nf_log_syslog_net_init(struct net *net)
 {
 	int ret = nf_log_set(net, NFPROTO_IPV4, &nf_ip_logger);
@@ -782,7 +801,13 @@ static int __net_init nf_log_syslog_net_init(struct net *net)
 	ret = nf_log_set(net, NFPROTO_IPV6, &nf_ip6_logger);
 	if (ret)
 		goto err2;
+
+	ret = nf_log_set(net, NFPROTO_NETDEV, &nf_netdev_logger);
+	if (ret)
+		goto err3;
 	return 0;
+err3:
+	nf_log_unset(net, &nf_ip6_logger);
 err2:
 	nf_log_unset(net, &nf_arp_logger);
 err1:
@@ -794,6 +819,8 @@ static void __net_exit nf_log_syslog_net_exit(struct net *net)
 {
 	nf_log_unset(net, &nf_ip_logger);
 	nf_log_unset(net, &nf_arp_logger);
+	nf_log_unset(net, &nf_ip6_logger);
+	nf_log_unset(net, &nf_netdev_logger);
 }
 
 static struct pernet_operations nf_log_syslog_net_ops = {
@@ -821,7 +848,13 @@ static int __init nf_log_syslog_init(void)
 	if (ret < 0)
 		goto err3;
 
+	ret = nf_log_register(NFPROTO_NETDEV, &nf_netdev_logger);
+	if (ret < 0)
+		goto err4;
+
 	return 0;
+err4:
+	nf_log_unregister(&nf_ip6_logger);
 err3:
 	nf_log_unregister(&nf_arp_logger);
 err2:
@@ -838,6 +871,7 @@ static void __exit nf_log_syslog_exit(void)
 	nf_log_unregister(&nf_ip_logger);
 	nf_log_unregister(&nf_arp_logger);
 	nf_log_unregister(&nf_ip6_logger);
+	nf_log_unregister(&nf_netdev_logger);
 }
 
 module_init(nf_log_syslog_init);
@@ -849,6 +883,8 @@ MODULE_LICENSE("GPL");
 MODULE_ALIAS("nf_log_arp");
 MODULE_ALIAS("nf_log_ipv4");
 MODULE_ALIAS("nf_log_ipv6");
+MODULE_ALIAS("nf_log_netdev");
 MODULE_ALIAS_NF_LOGGER(AF_INET, 0);
 MODULE_ALIAS_NF_LOGGER(3, 0);
+MODULE_ALIAS_NF_LOGGER(5, 0); /* NFPROTO_NETDEV */
 MODULE_ALIAS_NF_LOGGER(AF_INET6, 0);
Signature · 1 line
2.26.3
author maintainer
#5 lore raw

PATCH 5/8 netfilter: nf_log_bridge: merge with nf_log_syslog

In reply to Florian Westphal

Provide bridge log support from nf_log_syslog.

After the merge there is no need to load the "real packet loggers", all of them now reside in the same module.

---
 include/net/netfilter/nf_log.h       |  1 -
 net/bridge/netfilter/Kconfig         |  4 --
 net/bridge/netfilter/Makefile        |  3 --
 net/bridge/netfilter/nf_log_bridge.c | 79 ----------------------------
 net/netfilter/nf_log.c               |  7 ---
 net/netfilter/nf_log_syslog.c        | 22 ++++++++
 6 files changed, 22 insertions(+), 94 deletions(-)
 delete mode 100644 net/bridge/netfilter/nf_log_bridge.c
include/net/netfilter/nf_log.h +0 -1
index 716db4a0fed8..a6b85068c294 100644
@@ -68,7 +68,6 @@ 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 +0 -4
index ac5372121e60..7f304a19ac1b 100644
@@ -23,10 +23,6 @@ config NFT_BRIDGE_REJECT
 	help
 	  Add support to reject packets.
 
-config NF_LOG_BRIDGE
-	tristate "Bridge packet logging"
-	select NF_LOG_COMMON
-
 endif # NF_TABLES_BRIDGE
 
 config NF_CONNTRACK_BRIDGE
net/bridge/netfilter/Makefile +0 -3
index 8e2c5759d964..1c9ce49ab651 100644
@@ -9,9 +9,6 @@ obj-$(CONFIG_NFT_BRIDGE_REJECT)  += nft_reject_bridge.o
 # connection tracking
 obj-$(CONFIG_NF_CONNTRACK_BRIDGE) += nf_conntrack_bridge.o
 
-# packet logging
-obj-$(CONFIG_NF_LOG_BRIDGE) += nf_log_bridge.o
-
 obj-$(CONFIG_BRIDGE_NF_EBTABLES) += ebtables.o
 
 # tables
net/bridge/netfilter/nf_log_bridge.c deleted +0 -79

79 lines not on this page · raw message

net/netfilter/nf_log.c +0 -7
index 6cb9f9474b05..eaa8181f5ef7 100644
@@ -151,13 +151,6 @@ 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;
net/netfilter/nf_log_syslog.c +22 -0
index 617e0071c0c4..eedbc53f29b7 100644
@@ -787,6 +787,13 @@ static struct nf_logger nf_netdev_logger __read_mostly = {
 	.me		= THIS_MODULE,
 };
 
+static struct nf_logger nf_bridge_logger __read_mostly = {
+	.name		= "nf_log_bridge",
+	.type		= NF_LOG_TYPE_LOG,
+	.logfn		= nf_log_netdev_packet,
+	.me		= THIS_MODULE,
+};
+
 static int __net_init nf_log_syslog_net_init(struct net *net)
 {
 	int ret = nf_log_set(net, NFPROTO_IPV4, &nf_ip_logger);
@@ -805,7 +812,13 @@ static int __net_init nf_log_syslog_net_init(struct net *net)
 	ret = nf_log_set(net, NFPROTO_NETDEV, &nf_netdev_logger);
 	if (ret)
 		goto err3;
+
+	ret = nf_log_set(net, NFPROTO_BRIDGE, &nf_bridge_logger);
+	if (ret)
+		goto err4;
 	return 0;
+err4:
+	nf_log_unset(net, &nf_netdev_logger);
 err3:
 	nf_log_unset(net, &nf_ip6_logger);
 err2:
@@ -852,7 +865,13 @@ static int __init nf_log_syslog_init(void)
 	if (ret < 0)
 		goto err4;
 
+	nf_log_register(NFPROTO_BRIDGE, &nf_bridge_logger);
+	if (ret < 0)
+		goto err5;
+
 	return 0;
+err5:
+	nf_log_unregister(&nf_netdev_logger);
 err4:
 	nf_log_unregister(&nf_ip6_logger);
 err3:
@@ -872,6 +891,7 @@ static void __exit nf_log_syslog_exit(void)
 	nf_log_unregister(&nf_arp_logger);
 	nf_log_unregister(&nf_ip6_logger);
 	nf_log_unregister(&nf_netdev_logger);
+	nf_log_unregister(&nf_bridge_logger);
 }
 
 module_init(nf_log_syslog_init);
@@ -881,9 +901,11 @@ MODULE_AUTHOR("Netfilter Core Team <[email protected]>");
 MODULE_DESCRIPTION("Netfilter syslog packet logging");
 MODULE_LICENSE("GPL");
 MODULE_ALIAS("nf_log_arp");
+MODULE_ALIAS("nf_log_bridge");
 MODULE_ALIAS("nf_log_ipv4");
 MODULE_ALIAS("nf_log_ipv6");
 MODULE_ALIAS("nf_log_netdev");
+MODULE_ALIAS_NF_LOGGER(AF_BRIDGE, 0);
 MODULE_ALIAS_NF_LOGGER(AF_INET, 0);
 MODULE_ALIAS_NF_LOGGER(3, 0);
 MODULE_ALIAS_NF_LOGGER(5, 0); /* NFPROTO_NETDEV */
Signature · 1 line
2.26.3
author maintainer
#6 lore raw

PATCH 6/8 netfilter: nf_log_common: merge with nf_log_syslog

In reply to Florian Westphal

Remove nf_log_common. Now that all per-af modules have been merged there is no longer a need to provide a helper module.

---
 include/net/netfilter/nf_log.h |  24 ----
 net/netfilter/Kconfig          |   8 +-
 net/netfilter/Makefile         |   2 -
 net/netfilter/nf_log_common.c  | 224 ---------------------------------
 net/netfilter/nf_log_syslog.c  | 181 +++++++++++++++++++++++++-
 5 files changed, 181 insertions(+), 258 deletions(-)
 delete mode 100644 net/netfilter/nf_log_common.c
include/net/netfilter/nf_log.h +0 -24
index a6b85068c294..e55eedc84ed7 100644
@@ -98,28 +98,4 @@ 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);
-
-/* 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 net *net, struct nf_log_buf *m,
-			    struct sock *sk);
-void nf_log_dump_vlan(struct nf_log_buf *m, const struct sk_buff *skb);
-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);
-void nf_log_l2packet(struct net *net, u_int8_t pf,
-		     __be16 protocol,
-		     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/netfilter/Kconfig +2 -6
index 6aef981a8446..fcd8682704c4 100644
@@ -71,16 +71,13 @@ config NF_CONNTRACK
 
 	  To compile it as a module, choose M here.  If unsure, say N.
 
-config NF_LOG_COMMON
-	tristate
-
 config NF_LOG_SYSLOG
 	tristate "Syslog packet logging"
 	default m if NETFILTER_ADVANCED=n
-	select NF_LOG_COMMON
 	help
 	  This option enable support for packet logging via syslog.
-	  It supports IPv4 and common transport protocols such as TCP and UDP.
+	  It supports IPv4, IPV6, ARP and common transport protocols such
+	  as TCP and UDP.
 	  This is a simpler but less flexible logging method compared to
 	  CONFIG_NETFILTER_NETLINK_LOG.
 	  If both are enabled the backend to use can be configured at run-time
@@ -930,7 +927,6 @@ config NETFILTER_XT_TARGET_LED
 
 config NETFILTER_XT_TARGET_LOG
 	tristate "LOG target support"
-	select NF_LOG_COMMON
 	select NF_LOG_SYSLOG
 	select NF_LOG_IPV6 if IP6_NF_IPTABLES
 	default m if NETFILTER_ADVANCED=n
net/netfilter/Makefile +0 -2
index 429be36fe4c7..e80e010354b1 100644
@@ -48,8 +48,6 @@ obj-$(CONFIG_NF_CONNTRACK_TFTP) += nf_conntrack_tftp.o
 
 nf_nat-y	:= nf_nat_core.o nf_nat_proto.o nf_nat_helper.o
 
-# generic transport layer logging
-obj-$(CONFIG_NF_LOG_COMMON) += nf_log_common.o
 obj-$(CONFIG_NF_LOG_SYSLOG) += nf_log_syslog.o
 
 obj-$(CONFIG_NF_NAT) += nf_nat.o
net/netfilter/nf_log_common.c deleted +0 -224

224 lines not on this page · raw message

net/netfilter/nf_log_syslog.c +179 -2

211 lines not on this page · raw message

Signature · 1 line
2.26.3
author maintainer
#7 lore raw

PATCH 7/8 netfilter: nf_log: add module softdeps

In reply to Florian Westphal

xt_LOG has no direct dependency on the syslog-based logger, it relies on the nf_log core to probe the requested backend.

Now that all syslog-based loggers reside in the same module, we can just add a soft dependency on nf_log_syslog and let modprobe take care of it.

---
 net/netfilter/xt_LOG.c   | 1 +
 net/netfilter/xt_NFLOG.c | 1 +
 net/netfilter/xt_TRACE.c | 1 +
 3 files changed, 3 insertions(+)
net/netfilter/xt_LOG.c +1 -0
index a1e79b517c01..2ff75f7637b0 100644
@@ -108,3 +108,4 @@ MODULE_AUTHOR("Jan Rekorajski <[email protected]>");
 MODULE_DESCRIPTION("Xtables: IPv4/IPv6 packet logging");
 MODULE_ALIAS("ipt_LOG");
 MODULE_ALIAS("ip6t_LOG");
+MODULE_SOFTDEP("pre: nf_log_syslog");
net/netfilter/xt_NFLOG.c +1 -0
index 6e83ce3000db..fb5793208059 100644
@@ -79,3 +79,4 @@ static void __exit nflog_tg_exit(void)
 
 module_init(nflog_tg_init);
 module_exit(nflog_tg_exit);
+MODULE_SOFTDEP("pre: nfnetlink_log");
net/netfilter/xt_TRACE.c +1 -0
index 349ab5609b1b..5582dce98cae 100644
@@ -52,3 +52,4 @@ static void __exit trace_tg_exit(void)
 
 module_init(trace_tg_init);
 module_exit(trace_tg_exit);
+MODULE_SOFTDEP("pre: nf_log_syslog");
Signature · 1 line
2.26.3
author maintainer
#8 lore raw

PATCH 8/8 netfilter: nft_log: perform module load from nf_tables

In reply to Florian Westphal

modprobe calls from the nf_logger_find_get() API causes deadlock in very special cases because they occur with the nf_tables transaction mutex held.

In the specific case of nf_log, deadlock is via:

 A nf_tables -> transaction mutex -> nft_log -> modprobe -> nf_log_syslog \
	    -> pernet_ops rwsem -> wait for C

B netlink event -> rtnl_mutex -> nf_tables transaction mutex -> wait for A C close() -> ip6mr_sk_done -> rtnl_mutex -> wait for B

Earlier patch added NFLOG/xt_LOG module softdeps to avoid the need to load the backend module during a transaction.

For nft_log we would have to add a softdep for both nfnetlink_log or nf_log_syslog, since we do not know in advance which of the two backends are going to be configured.

This defers the modprobe op until after the transaction mutex is released.

---
 include/net/netfilter/nf_tables.h |  5 +++++
 net/netfilter/nf_log.c            |  3 ---
 net/netfilter/nf_tables_api.c     |  5 +++--
 net/netfilter/nft_log.c           | 20 +++++++++++++++++++-
 4 files changed, 27 insertions(+), 6 deletions(-)
include/net/netfilter/nf_tables.h +5 -0
index 5aaced6bf13e..6f26a38d1766 100644
@@ -1559,4 +1559,9 @@ void nf_tables_trans_destroy_flush_work(void);
 int nf_msecs_to_jiffies64(const struct nlattr *nla, u64 *result);
 __be64 nf_jiffies64_to_msecs(u64 input);
 
+#ifdef CONFIG_MODULES
+__printf(2, 3) int nft_request_module(struct net *net, const char *fmt, ...);
+#else
+static inline int nft_request_module(struct net *net, const char *fmt, ...) { return -ENOENT; }
+#endif
 #endif /* _NET_NF_TABLES_H */
net/netfilter/nf_log.c +0 -3
index eaa8181f5ef7..edee7fa944c1 100644
@@ -170,9 +170,6 @@ int nf_logger_find_get(int pf, enum nf_log_type type)
 		return 0;
 	}
 
-	if (rcu_access_pointer(loggers[pf][type]) == NULL)
-		request_module("nf-logger-%u-%u", pf, type);
-
 	rcu_read_lock();
 	logger = rcu_dereference(loggers[pf][type]);
 	if (logger == NULL)
net/netfilter/nf_tables_api.c +3 -2
index f57f1a6ba96f..0569aaecec04 100644
@@ -586,8 +586,8 @@ struct nft_module_request {
 };
 
 #ifdef CONFIG_MODULES
-static __printf(2, 3) int nft_request_module(struct net *net, const char *fmt,
-					     ...)
+__printf(2, 3) int nft_request_module(struct net *net, const char *fmt,
+				      ...)
 {
 	char module_name[MODULE_NAME_LEN];
 	struct nft_module_request *req;
@@ -620,6 +620,7 @@ static __printf(2, 3) int nft_request_module(struct net *net, const char *fmt,
 
 	return -EAGAIN;
 }
+EXPORT_SYMBOL_GPL(nft_request_module);
 #endif
 
 static void lockdep_nfnl_nft_mutex_not_held(void)
net/netfilter/nft_log.c +19 -1
index a06a46b039c5..54f6c2035e84 100644
@@ -128,6 +128,20 @@ static const struct nla_policy nft_log_policy[NFTA_LOG_MAX + 1] = {
 	[NFTA_LOG_FLAGS]	= { .type = NLA_U32 },
 };
 
+static int nft_log_modprobe(struct net *net, enum nf_log_type t)
+{
+	switch (t) {
+	case NF_LOG_TYPE_LOG:
+		return nft_request_module(net, "%s", "nf_log_syslog");
+	case NF_LOG_TYPE_ULOG:
+		return nft_request_module(net, "%s", "nfnetlink_log");
+	case NF_LOG_TYPE_MAX:
+		break;
+	}
+
+	return -ENOENT;
+}
+
 static int nft_log_init(const struct nft_ctx *ctx,
 			const struct nft_expr *expr,
 			const struct nlattr * const tb[])
@@ -197,8 +211,12 @@ static int nft_log_init(const struct nft_ctx *ctx,
 		return 0;
 
 	err = nf_logger_find_get(ctx->family, li->type);
-	if (err < 0)
+	if (err < 0) {
+		if (nft_log_modprobe(ctx->net, li->type) == -EAGAIN)
+			err = -EAGAIN;
+
 		goto err1;
+	}
 
 	return 0;
 
Signature · 1 line
2.26.3
reviewer Tested-by on the v1 series
#9 lore raw
In reply to Florian Westphal

Hi,

On Thu, Mar 25, 2021 at 06:25:04PM +0100, Florian Westphal wrote:
[...]

Quoted 3 lines

Last patch allows to move log backend module load
to nft_log to avoid a deadlock that can occur when request_module() is called with the nft transaction mutex held.

With this series applied, my reproducer doesn't lock up anymore. In addition to that, neither iptables nor nftables testsuites seem unhappy with the change. Hence:

Thanks a lot,

Phil

#10 lore raw
In reply to Florian Westphal
Quoted 15 lines · Florian Westphal

Netfilter has multiple log modules:
nf_log_arp
nf_log_bridge
nf_log_ipv4
nf_log_ipv6
nf_log_netdev
nfnetlink_log
nf_log_common

With the exception of nfnetlink_log (packet is sent to userspace for dissection/logging) all of them log to the kernel ringbuffer.

This series merges all modules except nfnetlink_log into a single module, nf_log_syslog.

Quoted 7 lines

After the series, only two log modules remain:
nfnetlink_log and nf_log_syslog. The latter provides the same functionality as the old per-af log modules.

Last patch allows to move log backend module load
to nft_log to avoid a deadlock that can occur when request_module() is called with the nft transaction mutex held.

Series applied to nf-next, thanks.