Netfilter updates for net-next
Subsystems (5)
Pablo Neira Ayuso
maintainercover Netfilter updates for net-next
Hi,
The following batch contains Netfilter/IPVS updates for your net-next tree:
1) Simplify log infrastructure modularity: Merge ipv4, ipv6, bridge, netdev and ARP families to nf_log_syslog.c. Add module softdeps. This fixes a rare deadlock condition that might occur when log module autoload is required. From Florian Westphal.
2) Moves part of netfilter related pernet data from struct net to net_generic() infrastructure. All of these users can be modules, so if they are not loaded there is no need to waste space. Size reduction is 7 cachelines on x86_64, also from Florian.
2) Update nftables audit support to report events once per table, to get it aligned with iptables. From Richard Guy Briggs.
3) Check for stale routes from the flowtable garbage collector path. This is fixing IPv6 which breaks due missing check for the dst_cookie.
4) Add a nfnl_fill_hdr() function to simplify netlink + nfnetlink headers setup.
5) Remove documentation on several statified functions.
6) Remove printk on netns creation for the FTP IPVS tracker, from Florian Westphal.
7) Remove unnecessary nf_tables_destroy_list_lock spinlock initialization, from Yang Yingliang.
7) Remove a duplicated forward declaration in ipset, from Wan Jiabing.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
Thanks!
----------------------------------------------------------------
The following changes since commit cda1893e9f7c1d78e391dbb6ef1798cd32354113:
net: mhi: remove pointless conditional before kfree_skb() (2021-03-30 13:47:28 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git HEAD
for you to fetch changes up to db3685b4046f8b629bbf73caa33751ce567ea8ff:
net: remove obsolete members from struct net (2021-04-06 00:34:53 +0200)
----------------------------------------------------------------
Dan Carpenter (1):
netfilter: nftables: fix a warning message in nf_tables_commit_audit_collect()
Florian Westphal (20):
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
netfilter: ipvs: do not printk on netns creation
netfilter: nfnetlink: add and use nfnetlink_broadcast
netfilter: nfnetlink: use net_generic infra
netfilter: cttimeout: use net_generic infra
netfilter: nf_defrag_ipv6: use net_generic infra
netfilter: nf_defrag_ipv4: use net_generic infra
netfilter: ebtables: use net_generic infra
netfilter: nf_tables: use net_generic infra for transaction data
netfilter: x_tables: move known table lists to net_generic infra
netfilter: conntrack: move sysctl pointer to net_generic infra
netfilter: conntrack: move ecache dwork to net_generic infra
net: remove obsolete members from struct net
Pablo Neira Ayuso (4):
netfilter: flowtable: dst_check() from garbage collector path
netfilter: nftables: add helper function to set the base sequence number
netfilter: add helper function to set up the nfnetlink header and use it
netfilter: nftables: remove documentation on static functions
Richard Guy Briggs (1):
audit: log nftables configuration change events once per table
Wan Jiabing (1):
netfilter: ipset: Remove duplicate declaration
Yang Yingliang (1):
netfilter: nftables: remove unnecessary spin_lock_init()
include/linux/netfilter/ipset/ip_set.h | 2 - include/linux/netfilter/nfnetlink.h | 29 + include/net/net_namespace.h | 9 - include/net/netfilter/ipv6/nf_defrag_ipv6.h | 6 + include/net/netfilter/nf_conntrack.h | 7 + include/net/netfilter/nf_conntrack_ecache.h | 33 +- include/net/netfilter/nf_flow_table.h | 5 +- include/net/netfilter/nf_log.h | 25 - include/net/netfilter/nf_tables.h | 16 + include/net/netns/conntrack.h | 4 - include/net/netns/netfilter.h | 6 - include/net/netns/nftables.h | 7 - include/net/netns/x_tables.h | 1 - net/bridge/netfilter/Kconfig | 4 - net/bridge/netfilter/Makefile | 3 - net/bridge/netfilter/ebtables.c | 39 +- net/bridge/netfilter/nf_log_bridge.c | 79 -- net/ipv4/netfilter/Kconfig | 10 +- net/ipv4/netfilter/Makefile | 4 - net/ipv4/netfilter/nf_defrag_ipv4.c | 20 +- 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_conntrack_reasm.c | 68 +- net/ipv6/netfilter/nf_defrag_ipv6_hooks.c | 15 +- net/ipv6/netfilter/nf_log_ipv6.c | 427 ----------- net/netfilter/Kconfig | 20 +- net/netfilter/Makefile | 6 +- net/netfilter/ipset/ip_set_core.c | 17 +- net/netfilter/ipvs/ip_vs_ftp.c | 2 - net/netfilter/nf_conntrack_core.c | 7 +- net/netfilter/nf_conntrack_ecache.c | 31 +- net/netfilter/nf_conntrack_netlink.c | 77 +- net/netfilter/nf_conntrack_standalone.c | 10 +- net/netfilter/nf_flow_table_core.c | 37 +- net/netfilter/nf_flow_table_ip.c | 22 +- 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 | 632 ++++++++-------- net/netfilter/nf_tables_offload.c | 30 +- net/netfilter/nf_tables_trace.c | 9 +- net/netfilter/nfnetlink.c | 67 +- net/netfilter/nfnetlink_acct.c | 14 +- net/netfilter/nfnetlink_cthelper.c | 11 +- net/netfilter/nfnetlink_cttimeout.c | 63 +- net/netfilter/nfnetlink_log.c | 11 +- net/netfilter/nfnetlink_queue.c | 12 +- net/netfilter/nft_chain_filter.c | 11 +- net/netfilter/nft_compat.c | 11 +- net/netfilter/nft_dynset.c | 6 +- net/netfilter/nft_log.c | 20 +- net/netfilter/x_tables.c | 46 +- net/netfilter/xt_LOG.c | 1 + net/netfilter/xt_NFLOG.c | 1 + net/netfilter/xt_TRACE.c | 1 + 58 files changed, 1910 insertions(+), 2060 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
Pablo Neira Ayuso
maintainerPATCH 1/28 netfilter: nf_log_ipv4: rename to nf_log_syslog
From: Florian Westphal <[email protected]>
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/ipv4/netfilter/nf_log_ipv4.c | 395 ------------------------------- net/netfilter/Kconfig | 14 +- net/netfilter/Makefile | 1 + net/netfilter/nf_log_syslog.c | 391 ++++++++++++++++++++++++++++++ 6 files changed, 409 insertions(+), 398 deletions(-) delete mode 100644 net/ipv4/netfilter/nf_log_ipv4.c create mode 100644 net/netfilter/nf_log_syslog.c
net/ipv4/netfilter/Kconfig +4 -1
@@ -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
@@ -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/ipv4/netfilter/nf_log_ipv4.c deleted +0 -395
395 lines not on this page · raw message
net/netfilter/Kconfig +13 -1
@@ -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
@@ -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 new file +391 -0
391 lines not on this page · raw message
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 2/28 netfilter: nf_log_arp: merge with nf_log_syslog
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
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
@@ -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
@@ -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.30.2
Pablo Neira Ayuso
maintainerPATCH 3/28 netfilter: nf_log_ipv6: merge with nf_log_syslog
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
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
@@ -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
@@ -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.30.2
Pablo Neira Ayuso
maintainerPATCH 4/28 netfilter: nf_log_netdev: merge with nf_log_syslog
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
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
@@ -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
@@ -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
@@ -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.30.2
Pablo Neira Ayuso
maintainerPATCH 5/28 netfilter: nf_log_bridge: merge with nf_log_syslog
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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; + ret =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.30.2
Pablo Neira Ayuso
maintainerPATCH 7/28 netfilter: nf_log: add module softdeps
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
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
@@ -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
@@ -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
@@ -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.30.2
Pablo Neira Ayuso
maintainerPATCH 6/28 netfilter: nf_log_common: merge with nf_log_syslog
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
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
@@ -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
@@ -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
@@ -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.30.2
Pablo Neira Ayuso
maintainerPATCH 12/28 netfilter: nftables: remove unnecessary spin_lock_init()
In reply to Pablo Neira AyusoFrom: Yang Yingliang <[email protected]>
The spinlock nf_tables_destroy_list_lock is initialized statically. It is unnecessary to initialize by spin_lock_init().
--- net/netfilter/nf_tables_api.c | 1 - 1 file changed, 1 deletion(-)
net/netfilter/nf_tables_api.c +0 -1
@@ -9214,7 +9214,6 @@ static int __init nf_tables_module_init(void) {int err; -spin_lock_init (&nf_tables_destroy_list_lock); err =register_pernet_subsys (&nf_tables_net_ops);if (err <0 )return err;
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 8/28 netfilter: nft_log: perform module load from nf_tables
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
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
@@ -1562,4 +1562,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
@@ -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
@@ -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
@@ -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.30.2
Pablo Neira Ayuso
maintainerPATCH 10/28 netfilter: ipset: Remove duplicate declaration
In reply to Pablo Neira AyusoFrom: Wan Jiabing <[email protected]>
struct ip_set is declared twice. One is declared at 79th line, so remove the duplicate.
--- include/linux/netfilter/ipset/ip_set.h | 2 -- 1 file changed, 2 deletions(-)
include/linux/netfilter/ipset/ip_set.h +0 -2
@@ -124,8 +124,6 @@ struct ip_set_ext {bool target; }; -struct ip_set ; -#define ext_timeout (e, s) \ ((unsigned long *)(((void *)(e)) + (s)->offset[IPSET_EXT_ID_TIMEOUT]))#define ext_counter (e, s) \
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 9/28 audit: log nftables configuration change events once per table
In reply to Pablo Neira AyusoFrom: Richard Guy Briggs <[email protected]>
Reduce logging of nftables events to a level similar to iptables. Restore the table field to list the table, adding the generation.
Indicate the op as the most significant operation in the event.
A couple of sample events:
type=PROCTITLE msg=audit(2021-03-18 09:30:49.801:143) : proctitle=/usr/bin/python3 -s /usr/sbin/firewalld --nofork --nopid
type=SYSCALL msg=audit(2021-03-18 09:30:49.801:143) : arch=x86_64 syscall=sendmsg success=yes exit=172 a0=0x6 a1=0x7ffdcfcbe650 a2=0x0 a3=0x7ffdcfcbd52c items=0 ppid=1 pid=367 auid=unset uid=root gid=root euid=root suid=root fsuid=root egid=roo t sgid=root fsgid=root tty=(none) ses=unset comm=firewalld exe=/usr/bin/python3.9 subj=system_u:system_r:firewalld_t:s0 key=(null)
type=NETFILTER_CFG msg=audit(2021-03-18 09:30:49.801:143) : table=firewalld:2 family=ipv6 entries=1 op=nft_register_table pid=367 subj=system_u:system_r:firewalld_t:s0 comm=firewalld
type=NETFILTER_CFG msg=audit(2021-03-18 09:30:49.801:143) : table=firewalld:2 family=ipv4 entries=1 op=nft_register_table pid=367 subj=system_u:system_r:firewalld_t:s0 comm=firewalld
type=NETFILTER_CFG msg=audit(2021-03-18 09:30:49.801:143) : table=firewalld:2 family=inet entries=1 op=nft_register_table pid=367 subj=system_u:system_r:firewalld_t:s0 comm=firewalld
type=PROCTITLE msg=audit(2021-03-18 09:30:49.839:144) : proctitle=/usr/bin/python3 -s /usr/sbin/firewalld --nofork --nopid
type=SYSCALL msg=audit(2021-03-18 09:30:49.839:144) : arch=x86_64 syscall=sendmsg success=yes exit=22792 a0=0x6 a1=0x7ffdcfcbe650 a2=0x0 a3=0x7ffdcfcbd52c items=0 ppid=1 pid=367 auid=unset uid=root gid=root euid=root suid=root fsuid=root egid=r oot sgid=root fsgid=root tty=(none) ses=unset comm=firewalld exe=/usr/bin/python3.9 subj=system_u:system_r:firewalld_t:s0 key=(null)
type=NETFILTER_CFG msg=audit(2021-03-18 09:30:49.839:144) : table=firewalld:3 family=ipv6 entries=30 op=nft_register_chain pid=367 subj=system_u:system_r:firewalld_t:s0 comm=firewalld
type=NETFILTER_CFG msg=audit(2021-03-18 09:30:49.839:144) : table=firewalld:3 family=ipv4 entries=30 op=nft_register_chain pid=367 subj=system_u:system_r:firewalld_t:s0 comm=firewalld
type=NETFILTER_CFG msg=audit(2021-03-18 09:30:49.839:144) : table=firewalld:3 family=inet entries=165 op=nft_register_chain pid=367 subj=system_u:system_r:firewalld_t:s0 comm=firewalld
The issue was originally documented in
https://github.com/linux-audit/audit-kernel/issues/124
--- net/netfilter/nf_tables_api.c | 186 +++++++++++++++++++--------------- 1 file changed, 103 insertions(+), 83 deletions(-)
net/netfilter/nf_tables_api.c +103 -83
@@ -66,6 +66,41 @@ static const struct rhashtable_params nft_objname_ht_params = { .automatic_shrinking = true, }; +struct nft_audit_data { +struct nft_table *table; +int entries; +int op; +struct list_head list; +}; + +static const u8 nft2audit_op[NFT_MSG_MAX ] = {// enum nf_tables_msg_types + [NFT_MSG_NEWTABLE ] =AUDIT_NFT_OP_TABLE_REGISTER , + [NFT_MSG_GETTABLE ] =AUDIT_NFT_OP_INVALID , + [NFT_MSG_DELTABLE ] =AUDIT_NFT_OP_TABLE_UNREGISTER , + [NFT_MSG_NEWCHAIN ] =AUDIT_NFT_OP_CHAIN_REGISTER , + [NFT_MSG_GETCHAIN ] =AUDIT_NFT_OP_INVALID , + [NFT_MSG_DELCHAIN ] =AUDIT_NFT_OP_CHAIN_UNREGISTER , + [NFT_MSG_NEWRULE ] =AUDIT_NFT_OP_RULE_REGISTER , + [NFT_MSG_GETRULE ] =AUDIT_NFT_OP_INVALID , + [NFT_MSG_DELRULE ] =AUDIT_NFT_OP_RULE_UNREGISTER , + [NFT_MSG_NEWSET ] =AUDIT_NFT_OP_SET_REGISTER , + [NFT_MSG_GETSET ] =AUDIT_NFT_OP_INVALID , + [NFT_MSG_DELSET ] =AUDIT_NFT_OP_SET_UNREGISTER , + [NFT_MSG_NEWSETELEM ] =AUDIT_NFT_OP_SETELEM_REGISTER , + [NFT_MSG_GETSETELEM ] =AUDIT_NFT_OP_INVALID , + [NFT_MSG_DELSETELEM ] =AUDIT_NFT_OP_SETELEM_UNREGISTER , + [NFT_MSG_NEWGEN ] =AUDIT_NFT_OP_GEN_REGISTER , + [NFT_MSG_GETGEN ] =AUDIT_NFT_OP_INVALID , + [NFT_MSG_TRACE ] =AUDIT_NFT_OP_INVALID , + [NFT_MSG_NEWOBJ ] =AUDIT_NFT_OP_OBJ_REGISTER , + [NFT_MSG_GETOBJ ] =AUDIT_NFT_OP_INVALID , + [NFT_MSG_DELOBJ ] =AUDIT_NFT_OP_OBJ_UNREGISTER , + [NFT_MSG_GETOBJ_RESET ] =AUDIT_NFT_OP_OBJ_RESET , + [NFT_MSG_NEWFLOWTABLE ] =AUDIT_NFT_OP_FLOWTABLE_REGISTER , + [NFT_MSG_GETFLOWTABLE ] =AUDIT_NFT_OP_INVALID , + [NFT_MSG_DELFLOWTABLE ] =AUDIT_NFT_OP_FLOWTABLE_UNREGISTER , +}; +static void nft_validate_state_update (struct net *net,u8 new_validate_state) {switch (net->nft.validate_state) {
@@ -718,17 +753,6 @@ static void nf_tables_table_notify(const struct nft_ctx *ctx, int event) {struct sk_buff *skb;int err; -char *buf =kasprintf (GFP_KERNEL ,"%s:%llu;?:0" , - ctx->table->name, ctx->table->handle); - -audit_log_nfcfg (buf, - ctx->family, - ctx->table->use, - event ==NFT_MSG_NEWTABLE ? -AUDIT_NFT_OP_TABLE_REGISTER : -AUDIT_NFT_OP_TABLE_UNREGISTER , -GFP_KERNEL ); -kfree (buf);if (!ctx->report && !nfnetlink_has_listeners (ctx->net,NFNLGRP_NFTABLES ))
@@ -1502,18 +1526,6 @@ static void nf_tables_chain_notify(const struct nft_ctx *ctx, int event) {struct sk_buff *skb;int err; -char *buf =kasprintf (GFP_KERNEL ,"%s:%llu;%s:%llu" , - ctx->table->name, ctx->table->handle, - ctx->chain->name, ctx->chain->handle); - -audit_log_nfcfg (buf, - ctx->family, - ctx->chain->use, - event ==NFT_MSG_NEWCHAIN ? -AUDIT_NFT_OP_CHAIN_REGISTER : -AUDIT_NFT_OP_CHAIN_UNREGISTER , -GFP_KERNEL ); -kfree (buf);if (!ctx->report && !nfnetlink_has_listeners (ctx->net,NFNLGRP_NFTABLES ))
@@ -2866,18 +2878,6 @@ static void nf_tables_rule_notify(const struct nft_ctx *ctx, {struct sk_buff *skb;int err; -char *buf =kasprintf (GFP_KERNEL ,"%s:%llu;%s:%llu" , - ctx->table->name, ctx->table->handle, - ctx->chain->name, ctx->chain->handle); - -audit_log_nfcfg (buf, - ctx->family, - rule->handle, - event ==NFT_MSG_NEWRULE ? -AUDIT_NFT_OP_RULE_REGISTER : -AUDIT_NFT_OP_RULE_UNREGISTER , -GFP_KERNEL ); -kfree (buf);if (!ctx->report && !nfnetlink_has_listeners (ctx->net,NFNLGRP_NFTABLES ))
@@ -3912,18 +3912,6 @@ static void nf_tables_set_notify(const struct nft_ctx *ctx,struct sk_buff *skb;u32 portid = ctx->portid;int err; -char *buf =kasprintf (gfp_flags,"%s:%llu;%s:%llu" , - ctx->table->name, ctx->table->handle, - set->name, set->handle); - -audit_log_nfcfg (buf, - ctx->family, - set->field_count, - event ==NFT_MSG_NEWSET ? -AUDIT_NFT_OP_SET_REGISTER : -AUDIT_NFT_OP_SET_UNREGISTER , - gfp_flags); -kfree (buf);if (!ctx->report && !nfnetlink_has_listeners (ctx->net,NFNLGRP_NFTABLES ))
@@ -5108,18 +5096,6 @@ static void nf_tables_setelem_notify(const struct nft_ctx *ctx,u32 portid = ctx->portid;struct sk_buff *skb;int err; -char *buf =kasprintf (GFP_KERNEL ,"%s:%llu;%s:%llu" , - ctx->table->name, ctx->table->handle, - set->name, set->handle); - -audit_log_nfcfg (buf, - ctx->family, - set->handle, - event ==NFT_MSG_NEWSETELEM ? -AUDIT_NFT_OP_SETELEM_REGISTER : -AUDIT_NFT_OP_SETELEM_UNREGISTER , -GFP_KERNEL ); -kfree (buf);if (!ctx->report && !nfnetlink_has_listeners (net,NFNLGRP_NFTABLES ))return ;
@@ -6321,12 +6297,11 @@ static int nf_tables_dump_obj(struct sk_buff *skb, struct netlink_callback *cb) filter->type != NFT_OBJECT_UNSPEC && obj->ops->type->type != filter->type) goto cont; -if (reset) {char *buf =kasprintf (GFP_ATOMIC , -"%s:%llu;?:0" , +"%s:%u" , table->name, - table->handle); + net->nft.base_seq); audit_log_nfcfg(buf, family,
@@ -6447,8 +6422,8 @@ static int nf_tables_getobj(struct net *net, struct sock *nlsk, reset = true;if (reset) { -char *buf =kasprintf (GFP_ATOMIC ,"%s:%llu;?:0" , - table->name, table->handle); +char *buf =kasprintf (GFP_ATOMIC ,"%s:%u" , + table->name, net->nft.base_seq); audit_log_nfcfg(buf, family,
@@ -6536,15 +6511,15 @@ void nft_obj_notify(struct net *net, const struct nft_table *table, {struct sk_buff *skb;int err; -char *buf =kasprintf (gfp,"%s:%llu;?:0" , - table->name, table->handle); +char *buf =kasprintf (gfp,"%s:%u" , + table->name, net->nft.base_seq);audit_log_nfcfg (buf, family, obj->handle, event ==NFT_MSG_NEWOBJ ? -AUDIT_NFT_OP_OBJ_REGISTER : -AUDIT_NFT_OP_OBJ_UNREGISTER , +AUDIT_NFT_OP_OBJ_REGISTER : +AUDIT_NFT_OP_OBJ_UNREGISTER , gfp);kfree (buf);
@@ -7362,18 +7337,6 @@ static void nf_tables_flowtable_notify(struct nft_ctx *ctx, {struct sk_buff *skb;int err; -char *buf =kasprintf (GFP_KERNEL ,"%s:%llu;%s:%llu" , - flowtable->table->name, flowtable->table->handle, - flowtable->name, flowtable->handle); - -audit_log_nfcfg (buf, - ctx->family, - flowtable->hooknum, - event ==NFT_MSG_NEWFLOWTABLE ? -AUDIT_NFT_OP_FLOWTABLE_REGISTER : -AUDIT_NFT_OP_FLOWTABLE_UNREGISTER , -GFP_KERNEL ); -kfree (buf);if (!ctx->report && !nfnetlink_has_listeners (ctx->net,NFNLGRP_NFTABLES ))
@@ -7494,9 +7457,6 @@ static void nf_tables_gen_notify(struct net *net, struct sk_buff *skb,struct sk_buff *skb2;int err; -audit_log_nfcfg ("?:0;?:0" ,0 , net->nft.base_seq, -AUDIT_NFT_OP_GEN_REGISTER ,GFP_KERNEL ); -if (!nlmsg_report (nlh) && !nfnetlink_has_listeners (net,NFNLGRP_NFTABLES ))return ;
@@ -8035,12 +7995,64 @@ static void nft_commit_notify(struct net *net, u32 portid)WARN_ON_ONCE (!list_empty (&net->nft.notify_list)); } +static int nf_tables_commit_audit_alloc (struct list_head *adl, +struct nft_table *table) +{ +struct nft_audit_data *adp; + +list_for_each_entry (adp, adl, list) { +if (adp->table == table) +return 0 ; + } + adp =kzalloc (sizeof (*adp),GFP_KERNEL ); +if (!adp) +return -ENOMEM ; + adp->table = table; +list_add (&adp->list, adl); +return 0 ; +} + +static void nf_tables_commit_audit_collect (struct list_head *adl, +struct nft_table *table,u32 op) +{ +struct nft_audit_data *adp; + +list_for_each_entry (adp, adl, list) { +if (adp->table == table) + goto found; + } +WARN_ONCE ("table=%s not expected in commit list" , table->name); +return ; +found: + adp->entries++; +if (!adp->op || adp->op > op) + adp->op = op; +} + +#define AUNFTABLENAMELEN (NFT_TABLE_MAXNAMELEN + 22) + +static void nf_tables_commit_audit_log (struct list_head *adl,u32 generation) +{ +struct nft_audit_data *adp, *adn; +char aubuf[AUNFTABLENAMELEN ]; + +list_for_each_entry_safe (adp, adn, adl, list) { +snprintf (aubuf,AUNFTABLENAMELEN ,"%s:%u" , adp->table->name, + generation); +audit_log_nfcfg (aubuf, adp->table->family, adp->entries, + nft2audit_op[adp->op],GFP_KERNEL ); +list_del (&adp->list); +kfree (adp); + } +} +static int nf_tables_commit (struct net *net,struct sk_buff *skb) {struct nft_trans *trans, *next;struct nft_trans_elem *te;struct nft_chain *chain;struct nft_table *table; +LIST_HEAD (adl);int err;if (list_empty (&net->nft.commit_list)) {
@@ -8060,6 +8072,11 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)list_for_each_entry_safe (trans, next, &net->nft.commit_list, list) {int ret; + ret =nf_tables_commit_audit_alloc (&adl, trans->ctx.table); +if (ret) { +nf_tables_commit_chain_prepare_cancel (net); +return ret; + }if (trans->msg_type ==NFT_MSG_NEWRULE || trans->msg_type ==NFT_MSG_DELRULE ) { chain = trans->ctx.chain;
@@ -8088,6 +8105,8 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb) net->nft.gencursor =nft_gencursor_next (net);list_for_each_entry_safe (trans, next, &net->nft.commit_list, list) { +nf_tables_commit_audit_collect (&adl, trans->ctx.table, + trans->msg_type);switch (trans->msg_type) {case NFT_MSG_NEWTABLE :if (nft_trans_table_update (trans)) {
@@ -8240,6 +8259,7 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)nft_commit_notify (net,NETLINK_CB (skb).portid);nf_tables_gen_notify (net, skb,NFT_MSG_NEWGEN ); +nf_tables_commit_audit_log (&adl, net->nft.base_seq);nf_tables_commit_release (net);return 0 ;
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 13/28 netfilter: nftables: add helper function to set the base sequence number
In reply to Pablo Neira AyusoThis patch adds a helper function to calculate the base sequence number field that is stored in the nfnetlink header. Use the helper function whenever possible.
--- net/netfilter/nf_tables_api.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
net/netfilter/nf_tables_api.c +14 -9
@@ -688,6 +688,11 @@ nf_tables_chain_type_lookup(struct net *net, const struct nlattr *nla,return ERR_PTR (-ENOENT ); } +static __be16 nft_base_seq (const struct net *net) +{ +return htons (net->nft.base_seq &0xffff ); +} +static const struct nla_policy nft_table_policy[NFTA_TABLE_MAX +1 ] = { [NFTA_TABLE_NAME ] = { .type =NLA_STRING , .len =NFT_TABLE_MAXNAMELEN -1 },
@@ -712,7 +717,7 @@ static int nf_tables_fill_table_info(struct sk_buff *skb, struct net *net, nfmsg =nlmsg_data (nlh); nfmsg->nfgen_family = family; nfmsg->version =NFNETLINK_V0 ; - nfmsg->res_id =htons (net->nft.base_seq &0xffff ); + nfmsg->res_id =nft_base_seq (net); if (nla_put_string(skb, NFTA_TABLE_NAME, table->name) || nla_put_be32(skb, NFTA_TABLE_FLAGS, htonl(table->flags)) ||
@@ -1473,7 +1478,7 @@ static int nf_tables_fill_chain_info(struct sk_buff *skb, struct net *net, nfmsg =nlmsg_data (nlh); nfmsg->nfgen_family = family; nfmsg->version =NFNETLINK_V0 ; - nfmsg->res_id =htons (net->nft.base_seq &0xffff ); + nfmsg->res_id =nft_base_seq (net);if (nla_put_string (skb,NFTA_CHAIN_TABLE , table->name)) goto nla_put_failure;
@@ -2832,7 +2837,7 @@ static int nf_tables_fill_rule_info(struct sk_buff *skb, struct net *net, nfmsg =nlmsg_data (nlh); nfmsg->nfgen_family = family; nfmsg->version =NFNETLINK_V0 ; - nfmsg->res_id =htons (net->nft.base_seq &0xffff ); + nfmsg->res_id =nft_base_seq (net);if (nla_put_string (skb,NFTA_RULE_TABLE , table->name)) goto nla_put_failure;
@@ -3820,7 +3825,7 @@ static int nf_tables_fill_set(struct sk_buff *skb, const struct nft_ctx *ctx, nfmsg =nlmsg_data (nlh); nfmsg->nfgen_family = ctx->family; nfmsg->version =NFNETLINK_V0 ; - nfmsg->res_id =htons (ctx->net->nft.base_seq &0xffff ); + nfmsg->res_id =nft_base_seq (ctx->net);if (nla_put_string (skb,NFTA_SET_TABLE , ctx->table->name)) goto nla_put_failure;
@@ -4831,7 +4836,7 @@ static int nf_tables_dump_set(struct sk_buff *skb, struct netlink_callback *cb) nfmsg =nlmsg_data (nlh); nfmsg->nfgen_family = table->family; nfmsg->version =NFNETLINK_V0 ; - nfmsg->res_id =htons (net->nft.base_seq &0xffff ); + nfmsg->res_id =nft_base_seq (net);if (nla_put_string (skb,NFTA_SET_ELEM_LIST_TABLE , table->name)) goto nla_put_failure;
@@ -4903,7 +4908,7 @@ static int nf_tables_fill_setelem_info(struct sk_buff *skb, nfmsg =nlmsg_data (nlh); nfmsg->nfgen_family = ctx->family; nfmsg->version =NFNETLINK_V0 ; - nfmsg->res_id =htons (ctx->net->nft.base_seq &0xffff ); + nfmsg->res_id =nft_base_seq (ctx->net);if (nla_put_string (skb,NFTA_SET_TABLE , ctx->table->name)) goto nla_put_failure;
@@ -6233,7 +6238,7 @@ static int nf_tables_fill_obj_info(struct sk_buff *skb, struct net *net, nfmsg =nlmsg_data (nlh); nfmsg->nfgen_family = family; nfmsg->version =NFNETLINK_V0 ; - nfmsg->res_id =htons (net->nft.base_seq &0xffff ); + nfmsg->res_id =nft_base_seq (net); if (nla_put_string(skb, NFTA_OBJ_TABLE, table->name) || nla_put_string(skb, NFTA_OBJ_NAME, obj->key.name) ||
@@ -7146,7 +7151,7 @@ static int nf_tables_fill_flowtable_info(struct sk_buff *skb, struct net *net, nfmsg =nlmsg_data (nlh); nfmsg->nfgen_family = family; nfmsg->version =NFNETLINK_V0 ; - nfmsg->res_id =htons (net->nft.base_seq &0xffff ); + nfmsg->res_id =nft_base_seq (net); if (nla_put_string(skb, NFTA_FLOWTABLE_TABLE, flowtable->table->name) || nla_put_string(skb, NFTA_FLOWTABLE_NAME, flowtable->name) ||
@@ -7391,7 +7396,7 @@ static int nf_tables_fill_gen_info(struct sk_buff *skb, struct net *net, nfmsg =nlmsg_data (nlh); nfmsg->nfgen_family =AF_UNSPEC ; nfmsg->version =NFNETLINK_V0 ; - nfmsg->res_id =htons (net->nft.base_seq &0xffff ); + nfmsg->res_id =nft_base_seq (net); if (nla_put_be32(skb, NFTA_GEN_ID, htonl(net->nft.base_seq)) || nla_put_be32(skb, NFTA_GEN_PROC_PID, htonl(task_pid_nr(current))) ||
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 16/28 netfilter: nftables: fix a warning message in nf_tables_commit_audit_collect()
In reply to Pablo Neira AyusoFrom: Dan Carpenter <[email protected]>
The first argument of a WARN_ONCE() is a condition. This WARN_ONCE() will only print the table name, and is potentially problematic if the table name has a %s in it.
--- net/netfilter/nf_tables_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +1 -1
@@ -7978,7 +7978,7 @@ static void nf_tables_commit_audit_collect(struct list_head *adl,if (adp->table == table) goto found; } -WARN_ONCE ("table=%s not expected in commit list" , table->name); +WARN_ONCE (1 ,"table=%s not expected in commit list" , table->name);return ; found: adp->entries++;
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 20/28 netfilter: cttimeout: use net_generic infra
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
reduce size of struct net and make this self-contained. The member in struct net is kept to minimize changes to struct net layout, it will be removed in a separate patch.
--- net/netfilter/nfnetlink_cttimeout.c | 41 ++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 9 deletions(-)
net/netfilter/nfnetlink_cttimeout.c +32 -9
@@ -20,6 +20,7 @@#include <linux/netfilter.h> #include <net/netlink.h> +#include <net/netns/generic.h> #include <net/sock.h> #include <net/netfilter/nf_conntrack.h> #include <net/netfilter/nf_conntrack_core.h>
@@ -30,6 +31,12 @@#include <linux/netfilter/nfnetlink.h> #include <linux/netfilter/nfnetlink_cttimeout.h> +static unsigned int nfct_timeout_id__read_mostly ; + +struct nfct_timeout_pernet { +struct list_head nfct_timeout_list; +}; +MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Pablo Neira Ayuso <[email protected]>" );MODULE_DESCRIPTION ("cttimeout: Extended Netfilter Connection Tracking timeout tuning" );
@@ -42,6 +49,11 @@ static const struct nla_policy cttimeout_nla_policy[CTA_TIMEOUT_MAX+1] = { [CTA_TIMEOUT_DATA] = { .type = NLA_NESTED }, }; +static struct nfct_timeout_pernet *nfct_timeout_pernet (struct net *net) +{ +return net_generic (net, nfct_timeout_id); +} + static int ctnl_timeout_parse_policy(void *timeout, const struct nf_conntrack_l4proto *l4proto,
@@ -77,6 +89,7 @@ static int cttimeout_new_timeout(struct net *net, struct sock *ctnl,const struct nlattr *const cda[], struct netlink_ext_ack *extack) { + struct nfct_timeout_pernet *pernet = nfct_timeout_pernet(net);__u16 l3num;__u8 l4num;const struct nf_conntrack_l4proto *l4proto;
@@ -94,7 +107,7 @@ static int cttimeout_new_timeout(struct net *net, struct sock *ctnl, l3num =ntohs (nla_get_be16 (cda[CTA_TIMEOUT_L3PROTO ])); l4num =nla_get_u8 (cda[CTA_TIMEOUT_L4PROTO ]); -list_for_each_entry (timeout, &net->nfct_timeout_list, head) { +list_for_each_entry (timeout, &pernet->nfct_timeout_list, head) {if (strncmp (timeout->name, name,CTNL_TIMEOUT_NAME_MAX ) !=0 )continue ;
@@ -146,7 +159,7 @@ static int cttimeout_new_timeout(struct net *net, struct sock *ctnl, timeout->timeout.l3num = l3num; timeout->timeout.l4proto = l4proto;refcount_set (&timeout->refcnt,1 ); -list_add_tail_rcu (&timeout->head, &net->nfct_timeout_list); +list_add_tail_rcu (&timeout->head, &pernet->nfct_timeout_list);return 0 ; err:
@@ -201,6 +214,7 @@ ctnl_timeout_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type,static int ctnl_timeout_dump (struct sk_buff *skb,struct netlink_callback *cb) { +struct nfct_timeout_pernet *pernet;struct net *net =sock_net (skb->sk);struct ctnl_timeout *cur, *last;
@@ -212,7 +226,8 @@ ctnl_timeout_dump(struct sk_buff *skb, struct netlink_callback *cb) cb->args[1 ] =0 ;rcu_read_lock (); -list_for_each_entry_rcu (cur, &net->nfct_timeout_list, head) { + pernet =nfct_timeout_pernet (net); +list_for_each_entry_rcu (cur, &pernet->nfct_timeout_list, head) {if (last) {if (cur != last)continue ;
@@ -239,6 +254,7 @@ static int cttimeout_get_timeout(struct net *net, struct sock *ctnl,const struct nlattr *const cda[], struct netlink_ext_ack *extack) { + struct nfct_timeout_pernet *pernet = nfct_timeout_pernet(net);int ret = -ENOENT ;char *name;struct ctnl_timeout *cur;
@@ -254,7 +270,7 @@ static int cttimeout_get_timeout(struct net *net, struct sock *ctnl,return -EINVAL ; name =nla_data (cda[CTA_TIMEOUT_NAME ]); -list_for_each_entry (cur, &net->nfct_timeout_list, head) { +list_for_each_entry (cur, &pernet->nfct_timeout_list, head) {struct sk_buff *skb2;if (strncmp (cur->name, name,CTNL_TIMEOUT_NAME_MAX ) !=0 )
@@ -310,12 +326,13 @@ static int cttimeout_del_timeout(struct net *net, struct sock *ctnl,const struct nlattr *const cda[], struct netlink_ext_ack *extack) { + struct nfct_timeout_pernet *pernet = nfct_timeout_pernet(net);struct ctnl_timeout *cur, *tmp;int ret = -ENOENT ;char *name;if (!cda[CTA_TIMEOUT_NAME ]) { -list_for_each_entry_safe (cur, tmp, &net->nfct_timeout_list, +list_for_each_entry_safe (cur, tmp, &pernet->nfct_timeout_list, head)ctnl_timeout_try_del (net, cur);
@@ -323,7 +340,7 @@ static int cttimeout_del_timeout(struct net *net, struct sock *ctnl, } name =nla_data (cda[CTA_TIMEOUT_NAME ]); -list_for_each_entry (cur, &net->nfct_timeout_list, head) { +list_for_each_entry (cur, &pernet->nfct_timeout_list, head) {if (strncmp (cur->name, name,CTNL_TIMEOUT_NAME_MAX ) !=0 )continue ;
@@ -503,9 +520,10 @@ static int cttimeout_default_get(struct net *net, struct sock *ctnl,static struct nf_ct_timeout *ctnl_timeout_find_get (struct net *net,const char *name) { +struct nfct_timeout_pernet *pernet =nfct_timeout_pernet (net);struct ctnl_timeout *timeout, *matching =NULL ; -list_for_each_entry_rcu (timeout, &net->nfct_timeout_list, head) { +list_for_each_entry_rcu (timeout, &pernet->nfct_timeout_list, head) {if (strncmp (timeout->name, name,CTNL_TIMEOUT_NAME_MAX ) !=0 )continue ;
@@ -563,19 +581,22 @@ MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_CTNETLINK_TIMEOUT);static int __net_init cttimeout_net_init (struct net *net) { -INIT_LIST_HEAD (&net->nfct_timeout_list); +struct nfct_timeout_pernet *pernet =nfct_timeout_pernet (net); + +INIT_LIST_HEAD (&pernet->nfct_timeout_list);return 0 ; } static void __net_exit cttimeout_net_exit(struct net *net) { +struct nfct_timeout_pernet *pernet =nfct_timeout_pernet (net);struct ctnl_timeout *cur, *tmp;nf_ct_unconfirmed_destroy (net);nf_ct_untimeout (net,NULL ); -list_for_each_entry_safe (cur, tmp, &net->nfct_timeout_list, head) { +list_for_each_entry_safe (cur, tmp, &pernet->nfct_timeout_list, head) {list_del_rcu (&cur->head);if (refcount_dec_and_test (&cur->refcnt))
@@ -586,6 +607,8 @@ static void __net_exit cttimeout_net_exit(struct net *net)static struct pernet_operations cttimeout_ops = { .init = cttimeout_net_init, .exit = cttimeout_net_exit, + .id = &nfct_timeout_id, + .size =sizeof (struct nfct_timeout_pernet ), };static int __init cttimeout_init (void )
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 22/28 netfilter: nf_defrag_ipv4: use net_generic infra
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
This allows followup patch to remove the defrag_ipv4 member from struct net. It also allows to auto-remove the hooks later on by adding a _disable() function. This will be done later in a follow patch series.
--- net/ipv4/netfilter/nf_defrag_ipv4.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
net/ipv4/netfilter/nf_defrag_ipv4.c +15 -5
@@ -20,8 +20,13 @@#endif #include <net/netfilter/nf_conntrack_zones.h> +static unsigned int defrag4_pernet_id__read_mostly ;static DEFINE_MUTEX (defrag4_mutex); +struct defrag4_pernet { +unsigned int users; +}; +static int nf_ct_ipv4_gather_frags (struct net *net,struct sk_buff *skb,u_int32_t user) {
@@ -106,15 +111,19 @@ static const struct nf_hook_ops ipv4_defrag_ops[] = { static void __net_exit defrag4_net_exit(struct net *net) { -if (net->nf.defrag_ipv4) { +struct defrag4_pernet *nf_defrag =net_generic (net, defrag4_pernet_id); + +if (nf_defrag->users) {nf_unregister_net_hooks (net, ipv4_defrag_ops,ARRAY_SIZE (ipv4_defrag_ops)); - net->nf.defrag_ipv4 = false; + nf_defrag->users =0 ; } }static struct pernet_operations defrag4_net_ops = { .exit = defrag4_net_exit, + .id = &defrag4_pernet_id, + .size =sizeof (struct defrag4_pernet ), };static int __init nf_defrag_init (void )
@@ -129,21 +138,22 @@ static void __exit nf_defrag_fini(void)int nf_defrag_ipv4_enable (struct net *net) { +struct defrag4_pernet *nf_defrag =net_generic (net, defrag4_pernet_id);int err =0 ;might_sleep (); -if (net->nf.defrag_ipv4) +if (nf_defrag->users)return 0 ;mutex_lock (&defrag4_mutex); -if (net->nf.defrag_ipv4) +if (nf_defrag->users) goto out_unlock; err =nf_register_net_hooks (net, ipv4_defrag_ops,ARRAY_SIZE (ipv4_defrag_ops));if (err ==0 ) - net->nf.defrag_ipv4 = true; + nf_defrag->users =1 ; out_unlock:mutex_unlock (&defrag4_mutex);
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 18/28 netfilter: nfnetlink: add and use nfnetlink_broadcast
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
This removes the only reference of net->nfnl outside of the nfnetlink module. This allows to move net->nfnl to net_generic infra.
--- include/linux/netfilter/nfnetlink.h | 2 ++ net/netfilter/nfnetlink.c | 7 +++++++ net/netfilter/nfnetlink_acct.c | 3 +-- 3 files changed, 10 insertions(+), 2 deletions(-)
include/linux/netfilter/nfnetlink.h +2 -0
@@ -51,6 +51,8 @@ int nfnetlink_send(struct sk_buff *skb, struct net *net, u32 portid, unsigned int group, int echo, gfp_t flags);int nfnetlink_set_err (struct net *net,u32 portid,u32 group,int error);int nfnetlink_unicast (struct sk_buff *skb,struct net *net,u32 portid); +void nfnetlink_broadcast (struct net *net,struct sk_buff *skb,__u32 portid, +__u32 group,gfp_t allocation);static inline u16 nfnl_msg_type (u8 subsys,u8 msg_type) {
net/netfilter/nfnetlink.c +7 -0
@@ -178,6 +178,13 @@ int nfnetlink_unicast(struct sk_buff *skb, struct net *net, u32 portid) }EXPORT_SYMBOL_GPL (nfnetlink_unicast); +void nfnetlink_broadcast (struct net *net,struct sk_buff *skb,__u32 portid, +__u32 group,gfp_t allocation) +{ +netlink_broadcast (net->nfnl, skb, portid, group, allocation); +} +EXPORT_SYMBOL_GPL (nfnetlink_broadcast); +/* Process one complete nfnetlink message. */ static int nfnetlink_rcv_msg (struct sk_buff *skb,struct nlmsghdr *nlh,struct netlink_ext_ack *extack)
net/netfilter/nfnetlink_acct.c +1 -2
@@ -469,8 +469,7 @@ static void nfnl_overquota_report(struct net *net, struct nf_acct *nfacct)kfree_skb (skb);return ; } -netlink_broadcast (net->nfnl, skb,0 ,NFNLGRP_ACCT_QUOTA , -GFP_ATOMIC ); +nfnetlink_broadcast (net, skb,0 ,NFNLGRP_ACCT_QUOTA ,GFP_ATOMIC ); }int nfnl_acct_overquota (struct net *net,struct nf_acct *nfacct)
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 17/28 netfilter: nftables: remove documentation on static functions
In reply to Pablo Neira AyusoSince 4f16d25c68ec ("netfilter: nftables: add nft_parse_register_load() and use it") and 345023b0db31 ("netfilter: nftables: add nft_parse_register_store() and use it"), the following functions are not exported symbols anymore:
- nft_parse_register()
- nft_validate_register_load()
- nft_validate_register_store()
--- net/netfilter/nf_tables_api.c | 32 -------------------------------- 1 file changed, 32 deletions(-)
net/netfilter/nf_tables_api.c +0 -32
@@ -8615,15 +8615,6 @@ int nft_parse_u32_check(const struct nlattr *attr, int max, u32 *dest) }EXPORT_SYMBOL_GPL (nft_parse_u32_check); -/** -* nft_parse_register - parse a register value from a netlink attribute -* -* @attr: netlink attribute -* -* Parse and translate a register value from a netlink attribute. -* Registers used to be 128 bit wide, these register numbers will be -* mapped to the corresponding 32 bit register numbers. -*/ static unsigned int nft_parse_register (const struct nlattr *attr) {unsigned int reg;
@@ -8659,15 +8650,6 @@ int nft_dump_register(struct sk_buff *skb, unsigned int attr, unsigned int reg) }EXPORT_SYMBOL_GPL (nft_dump_register); -/** -* nft_validate_register_load - validate a load from a register -* -* @reg: the register number -* @len: the length of the data -* -* Validate that the input register is one of the general purpose -* registers and that the length of the load is within the bounds. -*/ static int nft_validate_register_load (enum nft_registers reg,unsigned int len) {if (reg <NFT_REG_1 *NFT_REG_SIZE /NFT_REG32_SIZE )
@@ -8695,20 +8677,6 @@ int nft_parse_register_load(const struct nlattr *attr, u8 *sreg, u32 len) }EXPORT_SYMBOL_GPL (nft_parse_register_load); -/** -* nft_validate_register_store - validate an expressions' register store -* -* @ctx: context of the expression performing the load -* @reg: the destination register number -* @data: the data to load -* @type: the data type -* @len: the length of the data -* -* Validate that a data load uses the appropriate data type for -* the destination register and the length is within the bounds. -* A value of NULL for the data means that its runtime gathered -* data. -*/ static int nft_validate_register_store(const struct nft_ctx *ctx, enum nft_registers reg, const struct nft_data *data,
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 14/28 netfilter: add helper function to set up the nfnetlink header and use it
In reply to Pablo Neira AyusoThis patch adds a helper function to set up the netlink and nfnetlink headers. Update existing codebase to use it.
--- include/linux/netfilter/nfnetlink.h | 27 +++++++ net/netfilter/ipset/ip_set_core.c | 17 +---- net/netfilter/nf_conntrack_netlink.c | 77 ++++++-------------- net/netfilter/nf_tables_api.c | 102 +++++++-------------------- net/netfilter/nf_tables_trace.c | 9 +-- net/netfilter/nfnetlink_acct.c | 11 +-- net/netfilter/nfnetlink_cthelper.c | 11 +-- net/netfilter/nfnetlink_cttimeout.c | 22 ++---- net/netfilter/nfnetlink_log.c | 11 +-- net/netfilter/nfnetlink_queue.c | 12 ++-- net/netfilter/nft_compat.c | 11 +-- 11 files changed, 102 insertions(+), 208 deletions(-)
include/linux/netfilter/nfnetlink.h +27 -0
@@ -57,6 +57,33 @@ static inline u16 nfnl_msg_type(u8 subsys, u8 msg_type)return subsys <<8 | msg_type; } +static inline void nfnl_fill_hdr (struct nlmsghdr *nlh,u8 family,u8 version, +__be16 res_id) +{ +struct nfgenmsg *nfmsg; + + nfmsg =nlmsg_data (nlh); + nfmsg->nfgen_family = family; + nfmsg->version = version; + nfmsg->res_id = res_id; +} + +static inline struct nlmsghdr *nfnl_msg_put (struct sk_buff *skb,u32 portid, +u32 seq,int type,int flags, +u8 family,u8 version, +__be16 res_id) +{ +struct nlmsghdr *nlh; + + nlh =nlmsg_put (skb, portid, seq, type,sizeof (struct nfgenmsg ), flags); +if (!nlh) +return NULL ; + +nfnl_fill_hdr (nlh, family, version, res_id); + +return nlh; +} +void nfnl_lock (__u8 subsys_id);void nfnl_unlock (__u8 subsys_id);#ifdef CONFIG_PROVE_LOCKING
net/netfilter/ipset/ip_set_core.c +3 -14
@@ -963,20 +963,9 @@ static struct nlmsghdr * start_msg(struct sk_buff *skb, u32 portid, u32 seq, unsigned int flags, enum ipset_cmd cmd) { - struct nlmsghdr *nlh; -struct nfgenmsg *nfmsg; - - nlh =nlmsg_put (skb, portid, seq,nfnl_msg_type (NFNL_SUBSYS_IPSET , cmd), -sizeof (*nfmsg), flags); -if (!nlh) -return NULL ; - - nfmsg =nlmsg_data (nlh); - nfmsg->nfgen_family =NFPROTO_IPV4 ; - nfmsg->version =NFNETLINK_V0 ; - nfmsg->res_id =0 ; - -return nlh; + return nfnl_msg_put(skb, portid, seq, + nfnl_msg_type(NFNL_SUBSYS_IPSET ,cmd ), flags, + NFPROTO_IPV4, NFNETLINK_V0, 0); }/* Create a set */
net/netfilter/nf_conntrack_netlink.c +21 -56
166 lines not on this page · raw message
net/netfilter/nf_tables_api.c +27 -75
209 lines not on this page · raw message
net/netfilter/nf_tables_trace.c +2 -7
@@ -183,7 +183,6 @@ static bool nft_trace_have_verdict_chain(struct nft_traceinfo *info)void nft_trace_notify (struct nft_traceinfo *info) {const struct nft_pktinfo *pkt = info->pkt; -struct nfgenmsg *nfmsg;struct nlmsghdr *nlh;struct sk_buff *skb;unsigned int size;
@@ -219,15 +218,11 @@ void nft_trace_notify(struct nft_traceinfo *info)return ; event =nfnl_msg_type (NFNL_SUBSYS_NFTABLES ,NFT_MSG_TRACE ); - nlh =nlmsg_put (skb,0 ,0 , event,sizeof (struct nfgenmsg ),0 ); + nlh =nfnl_msg_put (skb,0 ,0 , event,0 , info->basechain->type->family, +NFNETLINK_V0 ,0 );if (!nlh) goto nla_put_failure; - nfmsg =nlmsg_data (nlh); - nfmsg->nfgen_family = info->basechain->type->family; - nfmsg->version =NFNETLINK_V0 ; - nfmsg->res_id =0 ; -if (nla_put_be32 (skb,NFTA_TRACE_NFPROTO ,htonl (nft_pf (pkt)))) goto nla_put_failure;
net/netfilter/nfnetlink_acct.c +3 -8
@@ -145,21 +145,16 @@ nfnl_acct_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type, int event, struct nf_acct *acct) { struct nlmsghdr *nlh; -struct nfgenmsg *nfmsg;unsigned int flags = portid ?NLM_F_MULTI :0 ;u64 pkts, bytes;u32 old_flags; event =nfnl_msg_type (NFNL_SUBSYS_ACCT , event); - nlh =nlmsg_put (skb, portid, seq, event,sizeof (*nfmsg), flags); -if (nlh ==NULL ) + nlh =nfnl_msg_put (skb, portid, seq, event, flags,AF_UNSPEC , +NFNETLINK_V0 ,0 ); +if (!nlh) goto nlmsg_failure; - nfmsg =nlmsg_data (nlh); - nfmsg->nfgen_family =AF_UNSPEC ; - nfmsg->version =NFNETLINK_V0 ; - nfmsg->res_id =0 ; -if (nla_put_string (skb,NFACCT_NAME , acct->name)) goto nla_put_failure;
net/netfilter/nfnetlink_cthelper.c +3 -8
@@ -526,20 +526,15 @@ nfnl_cthelper_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type, int event, struct nf_conntrack_helper *helper) { struct nlmsghdr *nlh; -struct nfgenmsg *nfmsg;unsigned int flags = portid ?NLM_F_MULTI :0 ;int status; event =nfnl_msg_type (NFNL_SUBSYS_CTHELPER , event); - nlh =nlmsg_put (skb, portid, seq, event,sizeof (*nfmsg), flags); -if (nlh ==NULL ) + nlh =nfnl_msg_put (skb, portid, seq, event, flags,AF_UNSPEC , +NFNETLINK_V0 ,0 ); +if (!nlh) goto nlmsg_failure; - nfmsg =nlmsg_data (nlh); - nfmsg->nfgen_family =AF_UNSPEC ; - nfmsg->version =NFNETLINK_V0 ; - nfmsg->res_id =0 ; -if (nla_put_string (skb,NFCTH_NAME , helper->name)) goto nla_put_failure;
net/netfilter/nfnetlink_cttimeout.c +6 -16
@@ -160,22 +160,17 @@ ctnl_timeout_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type, int event, struct ctnl_timeout *timeout) { struct nlmsghdr *nlh; -struct nfgenmsg *nfmsg;unsigned int flags = portid ?NLM_F_MULTI :0 ;const struct nf_conntrack_l4proto *l4proto = timeout->timeout.l4proto;struct nlattr *nest_parms;int ret; event =nfnl_msg_type (NFNL_SUBSYS_CTNETLINK_TIMEOUT , event); - nlh =nlmsg_put (skb, portid, seq, event,sizeof (*nfmsg), flags); -if (nlh ==NULL ) + nlh =nfnl_msg_put (skb, portid, seq, event, flags,AF_UNSPEC , +NFNETLINK_V0 ,0 ); +if (!nlh) goto nlmsg_failure; - nfmsg =nlmsg_data (nlh); - nfmsg->nfgen_family =AF_UNSPEC ; - nfmsg->version =NFNETLINK_V0 ; - nfmsg->res_id =0 ; - if (nla_put_string(skb, CTA_TIMEOUT_NAME, timeout->name) || nla_put_be16(skb, CTA_TIMEOUT_L3PROTO, htons(timeout->timeout.l3num)) ||
@@ -382,21 +377,16 @@ cttimeout_default_fill_info(struct net *net, struct sk_buff *skb, u32 portid, const unsigned int *timeouts) {struct nlmsghdr *nlh; -struct nfgenmsg *nfmsg;unsigned int flags = portid ?NLM_F_MULTI :0 ;struct nlattr *nest_parms;int ret; event =nfnl_msg_type (NFNL_SUBSYS_CTNETLINK_TIMEOUT , event); - nlh =nlmsg_put (skb, portid, seq, event,sizeof (*nfmsg), flags); -if (nlh ==NULL ) + nlh =nfnl_msg_put (skb, portid, seq, event, flags,AF_UNSPEC , +NFNETLINK_V0 ,0 ); +if (!nlh) goto nlmsg_failure; - nfmsg =nlmsg_data (nlh); - nfmsg->nfgen_family =AF_UNSPEC ; - nfmsg->version =NFNETLINK_V0 ; - nfmsg->res_id =0 ; -if (nla_put_be16 (skb,CTA_TIMEOUT_L3PROTO ,htons (l3num)) ||nla_put_u8 (skb,CTA_TIMEOUT_L4PROTO , l4proto->l4proto)) goto nla_put_failure;
net/netfilter/nfnetlink_log.c +3 -8
@@ -456,20 +456,15 @@ __build_packet_message(struct nfnl_log_net *log, {struct nfulnl_msg_packet_hdr pmsg;struct nlmsghdr *nlh; -struct nfgenmsg *nfmsg;sk_buff_data_t old_tail = inst->skb->tail;struct sock *sk;const unsigned char *hwhdrp; - nlh =nlmsg_put (inst->skb,0 ,0 , -nfnl_msg_type (NFNL_SUBSYS_ULOG ,NFULNL_MSG_PACKET ), -sizeof (struct nfgenmsg ),0 ); + nlh =nfnl_msg_put (inst->skb,0 ,0 , +nfnl_msg_type (NFNL_SUBSYS_ULOG ,NFULNL_MSG_PACKET ), +0 , pf,NFNETLINK_V0 ,htons (inst->group_num));if (!nlh)return -1 ; - nfmsg =nlmsg_data (nlh); - nfmsg->nfgen_family = pf; - nfmsg->version =NFNETLINK_V0 ; - nfmsg->res_id =htons (inst->group_num);memset (&pmsg,0 ,sizeof (pmsg)); pmsg.hw_protocol = skb->protocol;
net/netfilter/nfnetlink_queue.c +4 -8
@@ -383,7 +383,6 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,struct nlattr *nla;struct nfqnl_msg_packet_hdr *pmsg;struct nlmsghdr *nlh; -struct nfgenmsg *nfmsg;struct sk_buff *entskb = entry->skb;struct net_device *indev;struct net_device *outdev;
@@ -471,18 +470,15 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, goto nlmsg_failure; } - nlh =nlmsg_put (skb,0 ,0 , -nfnl_msg_type (NFNL_SUBSYS_QUEUE ,NFQNL_MSG_PACKET ), -sizeof (struct nfgenmsg ),0 ); + nlh =nfnl_msg_put (skb,0 ,0 , +nfnl_msg_type (NFNL_SUBSYS_QUEUE ,NFQNL_MSG_PACKET ), +0 , entry->state.pf,NFNETLINK_V0 , +htons (queue->queue_num));if (!nlh) {skb_tx_error (entskb);kfree_skb (skb); goto nlmsg_failure; } - nfmsg =nlmsg_data (nlh); - nfmsg->nfgen_family = entry->state.pf; - nfmsg->version =NFNETLINK_V0 ; - nfmsg->res_id =htons (queue->queue_num); nla =__nla_reserve (skb,NFQA_PACKET_HDR ,sizeof (*pmsg)); pmsg =nla_data (nla);
net/netfilter/nft_compat.c +3 -8
@@ -591,19 +591,14 @@ nfnl_compat_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type, int rev, int target) {struct nlmsghdr *nlh; -struct nfgenmsg *nfmsg;unsigned int flags = portid ?NLM_F_MULTI :0 ; event =nfnl_msg_type (NFNL_SUBSYS_NFT_COMPAT , event); - nlh =nlmsg_put (skb, portid, seq, event,sizeof (*nfmsg), flags); -if (nlh ==NULL ) + nlh =nfnl_msg_put (skb, portid, seq, event, flags, family, +NFNETLINK_V0 ,0 ); +if (!nlh) goto nlmsg_failure; - nfmsg =nlmsg_data (nlh); - nfmsg->nfgen_family = family; - nfmsg->version =NFNETLINK_V0 ; - nfmsg->res_id =0 ; -if (nla_put_string (skb,NFTA_COMPAT_NAME , name) ||nla_put_be32 (skb,NFTA_COMPAT_REV ,htonl (rev)) ||nla_put_be32 (skb,NFTA_COMPAT_TYPE ,htonl (target)))
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 11/28 netfilter: flowtable: dst_check() from garbage collector path
In reply to Pablo Neira AyusoMove dst_check() to the garbage collector path. Stale routes trigger the flow entry teardown state which makes affected flows go back to the classic forwarding path to re-evaluate flow offloading.
IPv6 requires the dst cookie to work, store it in the flow_tuple, otherwise dst_check() always fails.
--- include/net/netfilter/nf_flow_table.h | 5 +++- net/netfilter/nf_flow_table_core.c | 37 ++++++++++++++++++++++++++- net/netfilter/nf_flow_table_ip.c | 22 +++------------- 3 files changed, 44 insertions(+), 20 deletions(-)
include/net/netfilter/nf_flow_table.h +4 -1
@@ -129,7 +129,10 @@ struct flow_offload_tuple { in_vlan_ingress:2 ;u16 mtu;union { -struct dst_entry *dst_cache; +struct { +struct dst_entry *dst_cache; +u32 dst_cookie; + };struct {u32 ifidx;u32 hw_ifidx;
net/netfilter/nf_flow_table_core.c +36 -1
@@ -74,6 +74,18 @@ struct flow_offload *flow_offload_alloc(struct nf_conn *ct) }EXPORT_SYMBOL_GPL (flow_offload_alloc); +static u32 flow_offload_dst_cookie (struct flow_offload_tuple *flow_tuple) +{ +const struct rt6_info *rt; + +if (flow_tuple->l3proto ==NFPROTO_IPV6 ) { + rt = (const struct rt6_info *)flow_tuple->dst_cache; +return rt6_get_cookie (rt); + } + +return 0 ; +} +static int flow_offload_fill_route (struct flow_offload *flow,const struct nf_flow_route *route,enum flow_offload_tuple_dir dir)
@@ -116,6 +128,7 @@ static int flow_offload_fill_route(struct flow_offload *flow,return -1 ; flow_tuple->dst_cache = dst; + flow_tuple->dst_cookie =flow_offload_dst_cookie (flow_tuple);break ; } flow_tuple->xmit_type = route->tuple[dir].xmit_type;
@@ -390,11 +403,33 @@ nf_flow_table_iterate(struct nf_flowtable *flow_table,return err; } +static bool flow_offload_stale_dst (struct flow_offload_tuple *tuple) +{ +struct dst_entry *dst; + +if (tuple->xmit_type ==FLOW_OFFLOAD_XMIT_NEIGH || + tuple->xmit_type ==FLOW_OFFLOAD_XMIT_XFRM ) { + dst = tuple->dst_cache; +if (!dst_check (dst, tuple->dst_cookie)) +return true; + } + +return false; +} + +static bool nf_flow_has_stale_dst (struct flow_offload *flow) +{ +return flow_offload_stale_dst (&flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL ].tuple) || +flow_offload_stale_dst (&flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY ].tuple); +} +static void nf_flow_offload_gc_step (struct flow_offload *flow,void *data) {struct nf_flowtable *flow_table = data; -if (nf_flow_has_expired (flow) ||nf_ct_is_dying (flow->ct)) +if (nf_flow_has_expired (flow) || +nf_ct_is_dying (flow->ct) || +nf_flow_has_stale_dst (flow))set_bit (NF_FLOW_TEARDOWN , &flow->flags);if (test_bit (NF_FLOW_TEARDOWN , &flow->flags)) {
net/netfilter/nf_flow_table_ip.c +4 -18
@@ -364,15 +364,6 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,if (nf_flow_state_check (flow, iph->protocol, skb, thoff))return NF_ACCEPT ; -if (tuplehash->tuple.xmit_type ==FLOW_OFFLOAD_XMIT_NEIGH || - tuplehash->tuple.xmit_type ==FLOW_OFFLOAD_XMIT_XFRM ) { - rt = (struct rtable *)tuplehash->tuple.dst_cache; -if (!dst_check (&rt->dst,0 )) { -flow_offload_teardown (flow); -return NF_ACCEPT ; - } - } -if (skb_try_make_writable (skb, thoff + hdrsize))return NF_DROP ;
@@ -391,6 +382,7 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,nf_ct_acct_update (flow->ct, tuplehash->tuple.dir, skb->len);if (unlikely (tuplehash->tuple.xmit_type ==FLOW_OFFLOAD_XMIT_XFRM )) { + rt = (struct rtable *)tuplehash->tuple.dst_cache;memset (skb->cb,0 ,sizeof (struct inet_skb_parm ));IPCB (skb)->iif = skb->dev->ifindex;IPCB (skb)->flags =IPSKB_FORWARDED ;
@@ -399,6 +391,7 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,switch (tuplehash->tuple.xmit_type) {case FLOW_OFFLOAD_XMIT_NEIGH : + rt = (struct rtable *)tuplehash->tuple.dst_cache; outdev = rt->dst.dev; skb->dev = outdev; nexthop =rt_nexthop (rt, flow->tuplehash[!dir].tuple.src_v4.s_addr);
@@ -607,15 +600,6 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,if (nf_flow_state_check (flow, ip6h->nexthdr, skb, thoff))return NF_ACCEPT ; -if (tuplehash->tuple.xmit_type ==FLOW_OFFLOAD_XMIT_NEIGH || - tuplehash->tuple.xmit_type ==FLOW_OFFLOAD_XMIT_XFRM ) { - rt = (struct rt6_info *)tuplehash->tuple.dst_cache; -if (!dst_check (&rt->dst,0 )) { -flow_offload_teardown (flow); -return NF_ACCEPT ; - } - } -if (skb_try_make_writable (skb, thoff + hdrsize))return NF_DROP ;
@@ -633,6 +617,7 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,nf_ct_acct_update (flow->ct, tuplehash->tuple.dir, skb->len);if (unlikely (tuplehash->tuple.xmit_type ==FLOW_OFFLOAD_XMIT_XFRM )) { + rt = (struct rt6_info *)tuplehash->tuple.dst_cache;memset (skb->cb,0 ,sizeof (struct inet6_skb_parm ));IP6CB (skb)->iif = skb->dev->ifindex;IP6CB (skb)->flags =IP6SKB_FORWARDED ;
@@ -641,6 +626,7 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,switch (tuplehash->tuple.xmit_type) {case FLOW_OFFLOAD_XMIT_NEIGH : + rt = (struct rt6_info *)tuplehash->tuple.dst_cache; outdev = rt->dst.dev; skb->dev = outdev; nexthop =rt6_nexthop (rt, &flow->tuplehash[!dir].tuple.src_v6);
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 15/28 netfilter: ipvs: do not printk on netns creation
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
This causes dmesg spew during normal operation, so remove this.
--- net/netfilter/ipvs/ip_vs_ftp.c | 2 -- 1 file changed, 2 deletions(-)
net/netfilter/ipvs/ip_vs_ftp.c +0 -2
@@ -591,8 +591,6 @@ static int __net_init __ip_vs_ftp_init(struct net *net) ret =register_ip_vs_app_inc (ipvs, app, app->protocol, ports[i]);if (ret) goto err_unreg; -pr_info ("%s: loaded support on port[%d] = %u\n" , - app->name, i, ports[i]); }return 0 ;
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 23/28 netfilter: ebtables: use net_generic infra
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
ebtables currently uses net->xt.tables[BRIDGE], but upcoming patch will move net->xt.tables away from struct net.
To avoid exposing x_tables internals to ebtables, use a private list instead.
--- net/bridge/netfilter/ebtables.c | 39 ++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-)
net/bridge/netfilter/ebtables.c +34 -5
@@ -24,6 +24,7 @@#include <linux/cpumask.h> #include <linux/audit.h> #include <net/sock.h> +#include <net/netns/generic.h> /* needed for logical [in,out]-dev filtering */ #include "../br_private.h"
@@ -39,8 +40,11 @@#define COUNTER_BASE (c, n, cpu) ((struct ebt_counter *)(((char *)c) + \ COUNTER_OFFSET(n) * cpu)) +struct ebt_pernet { +struct list_head tables; +}; - +static unsigned int ebt_pernet_id__read_mostly ;static DEFINE_MUTEX (ebt_mutex);#ifdef CONFIG_COMPAT
@@ -336,7 +340,9 @@ static inline struct ebt_table * find_table_lock(struct net *net, const char *name, int *error, struct mutex *mutex) { - return find_inlist_lock(&net->xt.tables[NFPROTO_BRIDGE], name, + struct ebt_pernet *ebt_net = net_generic(net, ebt_pernet_id); + +return find_inlist_lock (&ebt_net->tables, name,"ebtable_" , error, mutex); }
@@ -1136,6 +1142,7 @@ static void __ebt_unregister_table(struct net *net, struct ebt_table *table)int ebt_register_table (struct net *net,const struct ebt_table *input_table,const struct nf_hook_ops *ops,struct ebt_table **res) { +struct ebt_pernet *ebt_net =net_generic (net, ebt_pernet_id);struct ebt_table_info *newinfo;struct ebt_table *t, *table;struct ebt_replace_kernel *repl;
@@ -1194,7 +1201,7 @@ int ebt_register_table(struct net *net, const struct ebt_table *input_table, table->private = newinfo;rwlock_init (&table->lock);mutex_lock (&ebt_mutex); -list_for_each_entry (t, &net->xt.tables[NFPROTO_BRIDGE ], list) { +list_for_each_entry (t, &ebt_net->tables, list) {if (strcmp (t->name, table->name) ==0 ) { ret = -EEXIST ; goto free_unlock;
@@ -1206,7 +1213,7 @@ int ebt_register_table(struct net *net, const struct ebt_table *input_table, ret = -ENOENT ; goto free_unlock; } -list_add (&table->list, &net->xt.tables[NFPROTO_BRIDGE ]); +list_add (&table->list, &ebt_net->tables);mutex_unlock (&ebt_mutex);WRITE_ONCE (*res, table);
@@ -2412,6 +2419,20 @@ static struct nf_sockopt_ops ebt_sockopts = { .owner = THIS_MODULE, }; +static int __net_init ebt_pernet_init (struct net *net) +{ +struct ebt_pernet *ebt_net =net_generic (net, ebt_pernet_id); + +INIT_LIST_HEAD (&ebt_net->tables); +return 0 ; +} + +static struct pernet_operations ebt_net_ops = { + .init = ebt_pernet_init, + .id = &ebt_pernet_id, + .size =sizeof (struct ebt_pernet ), +}; +static int __init ebtables_init (void ) {int ret;
@@ -2425,13 +2446,21 @@ static int __init ebtables_init(void)return ret; } + ret =register_pernet_subsys (&ebt_net_ops); +if (ret <0 ) { +nf_unregister_sockopt (&ebt_sockopts); +xt_unregister_target (&ebt_standard_target); +return ret; + } +return 0 ; } -static void __exit ebtables_fini(void) +static void ebtables_fini (void ) {nf_unregister_sockopt (&ebt_sockopts);xt_unregister_target (&ebt_standard_target); +unregister_pernet_subsys (&ebt_net_ops); }EXPORT_SYMBOL (ebt_register_table);
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 19/28 netfilter: nfnetlink: use net_generic infra
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
No need to place it in struct net, nfnetlink is a module and usage doesn't occur in fastpath.
Also remove rcu usage:
Not a single reader of net->nfnl uses rcu accessors.
When exit_batch callbacks are executed the net namespace is already dead so no calls to these functions are possible anymore (else we'd get NULL deref crash too).
If the module is removed, then modules that call any of those functions have been removed too so no calls to nfnl functions are possible either.
The nfnl and nfl_stash pointers in struct net are no longer used, they will be removed in a followup patch to minimize changes to struct net (causes rebuild for entire network stack).
--- net/netfilter/nfnetlink.c | 62 +++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 18 deletions(-)
net/netfilter/nfnetlink.c +44 -18
@@ -28,6 +28,7 @@#include <linux/sched/signal.h> #include <net/netlink.h> +#include <net/netns/generic.h> #include <linux/netfilter/nfnetlink.h> MODULE_LICENSE ("GPL" );
@@ -41,6 +42,12 @@ MODULE_DESCRIPTION("Netfilter messages via netlink socket");#define NFNL_MAX_ATTR_COUNT 32 +static unsigned int nfnetlink_pernet_id__read_mostly ; + +struct nfnl_net { +struct sock *nfnl; +}; + static struct { struct mutex mutex; const struct nfnetlink_subsystem __rcu *subsys;
@@ -75,6 +82,11 @@ static const int nfnl_group2type[NFNLGRP_MAX+1] = { [NFNLGRP_NFTRACE] = NFNL_SUBSYS_NFTABLES, }; +static struct nfnl_net *nfnl_pernet (struct net *net) +{ +return net_generic (net, nfnetlink_pernet_id); +} +void nfnl_lock (__u8 subsys_id) {mutex_lock (&table[subsys_id].mutex);
@@ -149,28 +161,35 @@ nfnetlink_find_client(u16 type, const struct nfnetlink_subsystem *ss)int nfnetlink_has_listeners (struct net *net,unsigned int group) { -return netlink_has_listeners (net->nfnl, group); +struct nfnl_net *nfnlnet =nfnl_pernet (net); + +return netlink_has_listeners (nfnlnet->nfnl, group); }EXPORT_SYMBOL_GPL (nfnetlink_has_listeners);int nfnetlink_send (struct sk_buff *skb,struct net *net,u32 portid,unsigned int group,int echo,gfp_t flags) { -return nlmsg_notify (net->nfnl, skb, portid, group, echo, flags); +struct nfnl_net *nfnlnet =nfnl_pernet (net); + +return nlmsg_notify (nfnlnet->nfnl, skb, portid, group, echo, flags); }EXPORT_SYMBOL_GPL (nfnetlink_send);int nfnetlink_set_err (struct net *net,u32 portid,u32 group,int error) { -return netlink_set_err (net->nfnl, portid, group, error); +struct nfnl_net *nfnlnet =nfnl_pernet (net); + +return netlink_set_err (nfnlnet->nfnl, portid, group, error); }EXPORT_SYMBOL_GPL (nfnetlink_set_err);int nfnetlink_unicast (struct sk_buff *skb,struct net *net,u32 portid) { +struct nfnl_net *nfnlnet =nfnl_pernet (net);int err; - err =nlmsg_unicast (net->nfnl, skb, portid); + err =nlmsg_unicast (nfnlnet->nfnl, skb, portid);if (err == -EAGAIN ) err = -ENOBUFS ;
@@ -181,7 +200,9 @@ EXPORT_SYMBOL_GPL(nfnetlink_unicast);void nfnetlink_broadcast (struct net *net,struct sk_buff *skb,__u32 portid,__u32 group,gfp_t allocation) { -netlink_broadcast (net->nfnl, skb, portid, group, allocation); +struct nfnl_net *nfnlnet =nfnl_pernet (net); + +netlink_broadcast (nfnlnet->nfnl, skb, portid, group, allocation); }EXPORT_SYMBOL_GPL (nfnetlink_broadcast);
@@ -201,6 +222,7 @@ static int nfnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, type = nlh->nlmsg_type; replay:rcu_read_lock (); + ss =nfnetlink_get_subsys (type);if (!ss) {#ifdef CONFIG_MODULES
@@ -224,6 +246,7 @@ static int nfnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, {int min_len =nlmsg_total_size (sizeof (struct nfgenmsg )); +struct nfnl_net *nfnlnet =nfnl_pernet (net);u8 cb_id =NFNL_MSG_TYPE (nlh->nlmsg_type);struct nlattr *cda[NFNL_MAX_ATTR_COUNT +1 ];struct nlattr *attr = (void *)nlh + min_len;
@@ -245,7 +268,7 @@ static int nfnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, }if (nc->call_rcu) { - err = nc->call_rcu (net, net->nfnl, skb, nlh, + err = nc->call_rcu (net, nfnlnet->nfnl, skb, nlh, (const struct nlattr **)cda, extack);rcu_read_unlock ();
@@ -256,7 +279,7 @@ static int nfnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, nfnetlink_find_client(type, ss) != nc) err = -EAGAIN ; else if (nc->call) - err = nc->call (net, net->nfnl, skb, nlh, + err = nc->call (net, nfnlnet->nfnl, skb, nlh, (const struct nlattr **)cda, extack); else
@@ -460,7 +483,9 @@ static void nfnetlink_rcv_batch(struct sk_buff *skb, struct nlmsghdr *nlh, goto ack;if (nc->call_batch) { - err = nc->call_batch (net, net->nfnl, skb, nlh, +struct nfnl_net *nfnlnet =nfnl_pernet (net); + + err = nc->call_batch (net, nfnlnet->nfnl, skb, nlh, (const struct nlattr **)cda, &extack); }
@@ -629,7 +654,7 @@ static int nfnetlink_bind(struct net *net, int group)static int __net_init nfnetlink_net_init (struct net *net) { -struct sock *nfnl; +struct nfnl_net *nfnlnet =nfnl_pernet (net);struct netlink_kernel_cfg cfg = { .groups =NFNLGRP_MAX , .input = nfnetlink_rcv,
@@ -638,28 +663,29 @@ static int __net_init nfnetlink_net_init(struct net *net)#endif }; - nfnl =netlink_kernel_create (net,NETLINK_NETFILTER , &cfg); -if (!nfnl) + nfnlnet->nfnl =netlink_kernel_create (net,NETLINK_NETFILTER , &cfg); +if (!nfnlnet->nfnl)return -ENOMEM ; - net->nfnl_stash = nfnl; -rcu_assign_pointer (net->nfnl, nfnl);return 0 ; } static void __net_exit nfnetlink_net_exit_batch(struct list_head *net_exit_list) { +struct nfnl_net *nfnlnet;struct net *net; -list_for_each_entry (net, net_exit_list, exit_list) -RCU_INIT_POINTER (net->nfnl,NULL ); -synchronize_net (); -list_for_each_entry (net, net_exit_list, exit_list) -netlink_kernel_release (net->nfnl_stash); +list_for_each_entry (net, net_exit_list, exit_list) { + nfnlnet =nfnl_pernet (net); + +netlink_kernel_release (nfnlnet->nfnl); + } }static struct pernet_operations nfnetlink_net_ops = { .init = nfnetlink_net_init, .exit_batch = nfnetlink_net_exit_batch, + .id = &nfnetlink_pernet_id, + .size =sizeof (struct nfnl_net ), };static int __init nfnetlink_init (void )
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 24/28 netfilter: nf_tables: use net_generic infra for transaction data
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
This moves all nf_tables pernet data from struct net to a net_generic extension, with the exception of the gencursor.
The latter is used in the data path and also outside of the nf_tables core. All others are only used from the configuration plane.
--- include/net/netfilter/nf_tables.h | 11 ++ net/netfilter/nf_tables_api.c | 313 +++++++++++++++++++----------- net/netfilter/nf_tables_offload.c | 30 +-- net/netfilter/nft_chain_filter.c | 11 +- net/netfilter/nft_dynset.c | 6 +- 5 files changed, 243 insertions(+), 128 deletions(-)
include/net/netfilter/nf_tables.h +11 -0
@@ -1567,4 +1567,15 @@ __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 + +struct nftables_pernet { +struct list_head tables; +struct list_head commit_list; +struct list_head module_list; +struct list_head notify_list; +struct mutex commit_mutex; +unsigned int base_seq; +u8 validate_state; +}; +#endif /* _NET_NF_TABLES_H */
net/netfilter/nf_tables_api.c +200 -113
1,041 lines not on this page · raw message
net/netfilter/nf_tables_offload.c +19 -11
@@ -7,6 +7,8 @@#include <net/netfilter/nf_tables_offload.h> #include <net/pkt_cls.h> +extern unsigned int nf_tables_net_id; +static struct nft_flow_rule *nft_flow_rule_alloc (int num_actions) {struct nft_flow_rule *flow;
@@ -307,16 +309,18 @@ static void nft_indr_block_cleanup(struct flow_block_cb *block_cb)struct nft_base_chain *basechain = block_cb->indr.data;struct net_device *dev = block_cb->indr.dev;struct netlink_ext_ack extack = {}; +struct nftables_pernet *nft_net;struct net *net =dev_net (dev);struct flow_block_offload bo;nft_flow_block_offload_init (&bo,dev_net (dev),FLOW_BLOCK_UNBIND , basechain, &extack); -mutex_lock (&net->nft.commit_mutex); + nft_net =net_generic (net, nf_tables_net_id); +mutex_lock (&nft_net->commit_mutex);list_del (&block_cb->driver_list);list_move (&block_cb->list, &bo.cb_list);nft_flow_offload_unbind (&bo, basechain); -mutex_unlock (&net->nft.commit_mutex); +mutex_unlock (&nft_net->commit_mutex); } static int nft_indr_block_offload_cmd(struct nft_base_chain *basechain,
@@ -412,9 +416,10 @@ static int nft_flow_offload_chain(struct nft_chain *chain, u8 *ppolicy,static void nft_flow_rule_offload_abort (struct net *net,struct nft_trans *trans) { +struct nftables_pernet *nft_net =net_generic (net, nf_tables_net_id);int err =0 ; -list_for_each_entry_continue_reverse (trans, &net->nft.commit_list, list) { +list_for_each_entry_continue_reverse (trans, &nft_net->commit_list, list) {if (trans->ctx.family !=NFPROTO_NETDEV )continue ;
@@ -460,11 +465,12 @@ static void nft_flow_rule_offload_abort(struct net *net,int nft_flow_rule_offload_commit (struct net *net) { +struct nftables_pernet *nft_net =net_generic (net, nf_tables_net_id);struct nft_trans *trans;int err =0 ;u8 policy; -list_for_each_entry (trans, &net->nft.commit_list, list) { +list_for_each_entry (trans, &nft_net->commit_list, list) {if (trans->ctx.family !=NFPROTO_NETDEV )continue ;
@@ -516,7 +522,7 @@ int nft_flow_rule_offload_commit(struct net *net) } } -list_for_each_entry (trans, &net->nft.commit_list, list) { +list_for_each_entry (trans, &nft_net->commit_list, list) {if (trans->ctx.family !=NFPROTO_NETDEV )continue ;
@@ -536,15 +542,15 @@ int nft_flow_rule_offload_commit(struct net *net)return err; } -static struct nft_chain *__nft_offload_get_chain (struct net_device *dev) +static struct nft_chain *__nft_offload_get_chain (const struct nftables_pernet *nft_net, +struct net_device *dev) {struct nft_base_chain *basechain; -struct net *net =dev_net (dev);struct nft_hook *hook, *found;const struct nft_table *table;struct nft_chain *chain; -list_for_each_entry (table, &net->nft.tables, list) { +list_for_each_entry (table, &nft_net->tables, list) {if (table->family !=NFPROTO_NETDEV )continue ;
@@ -576,19 +582,21 @@ static int nft_offload_netdev_event(struct notifier_block *this, unsigned long event, void *ptr) { struct net_device *dev = netdev_notifier_info_to_dev(ptr); +struct nftables_pernet *nft_net;struct net *net =dev_net (dev);struct nft_chain *chain;if (event !=NETDEV_UNREGISTER )return NOTIFY_DONE ; -mutex_lock (&net->nft.commit_mutex); - chain =__nft_offload_get_chain (dev); + nft_net =net_generic (net, nf_tables_net_id); +mutex_lock (&nft_net->commit_mutex); + chain =__nft_offload_get_chain (nft_net, dev);if (chain)nft_flow_block_chain (nft_base_chain (chain), dev,FLOW_BLOCK_UNBIND ); -mutex_unlock (&net->nft.commit_mutex); +mutex_unlock (&nft_net->commit_mutex);return NOTIFY_DONE ; }
net/netfilter/nft_chain_filter.c +8 -3
@@ -2,6 +2,7 @@#include <linux/kernel.h> #include <linux/netdevice.h> #include <net/net_namespace.h> +#include <net/netns/generic.h> #include <net/netfilter/nf_tables.h> #include <linux/netfilter_ipv4.h> #include <linux/netfilter_ipv6.h>
@@ -10,6 +11,8 @@#include <net/netfilter/nf_tables_ipv4.h> #include <net/netfilter/nf_tables_ipv6.h> +extern unsigned int nf_tables_net_id; +#ifdef CONFIG_NF_TABLES_IPV4 static unsigned int nft_do_chain_ipv4(void *priv, struct sk_buff *skb,
@@ -355,6 +358,7 @@ static int nf_tables_netdev_event(struct notifier_block *this, unsigned long event, void *ptr) { struct net_device *dev = netdev_notifier_info_to_dev(ptr); +struct nftables_pernet *nft_net;struct nft_table *table;struct nft_chain *chain, *nr; struct nft_ctx ctx = {
@@ -365,8 +369,9 @@ static int nf_tables_netdev_event(struct notifier_block *this, event != NETDEV_CHANGENAME)return NOTIFY_DONE ; -mutex_lock (&ctx.net->nft.commit_mutex); -list_for_each_entry (table, &ctx.net->nft.tables, list) { + nft_net =net_generic (ctx.net, nf_tables_net_id); +mutex_lock (&nft_net->commit_mutex); +list_for_each_entry (table, &nft_net->tables, list) {if (table->family !=NFPROTO_NETDEV )continue ;
@@ -380,7 +385,7 @@ static int nf_tables_netdev_event(struct notifier_block *this,nft_netdev_event (event, dev, &ctx); } } -mutex_unlock (&ctx.net->nft.commit_mutex); +mutex_unlock (&nft_net->commit_mutex);return NOTIFY_DONE ; }
net/netfilter/nft_dynset.c +5 -1
@@ -11,6 +11,9 @@#include <linux/netfilter/nf_tables.h> #include <net/netfilter/nf_tables.h> #include <net/netfilter/nf_tables_core.h> +#include <net/netns/generic.h> + +extern unsigned int nf_tables_net_id;struct nft_dynset {struct nft_set *set;
@@ -161,13 +164,14 @@ static int nft_dynset_init(const struct nft_ctx *ctx,const struct nft_expr *expr, const struct nlattr * const tb[]) { + struct nftables_pernet *nft_net = net_generic(ctx->net, nf_tables_net_id);struct nft_dynset *priv =nft_expr_priv (expr);u8 genmask =nft_genmask_next (ctx->net);struct nft_set *set;u64 timeout;int err, i; -lockdep_assert_held (&ctx->net->nft.commit_mutex); +lockdep_assert_held (&nft_net->commit_mutex); if (tb[NFTA_DYNSET_SET_NAME] == NULL || tb[NFTA_DYNSET_OP] == NULL ||
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 21/28 netfilter: nf_defrag_ipv6: use net_generic infra
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
This allows followup patch to remove these members from struct net.
--- include/net/netfilter/ipv6/nf_defrag_ipv6.h | 6 ++ net/ipv6/netfilter/nf_conntrack_reasm.c | 68 +++++++++++---------- net/ipv6/netfilter/nf_defrag_ipv6_hooks.c | 15 +++-- 3 files changed, 52 insertions(+), 37 deletions(-)
include/net/netfilter/ipv6/nf_defrag_ipv6.h +6 -0
@@ -13,4 +13,10 @@ int nf_ct_frag6_gather(struct net *net, struct sk_buff *skb, u32 user);struct inet_frags_ctl ; +struct nft_ct_frag6_pernet { +struct ctl_table_header *nf_frag_frags_hdr; +struct fqdir *fqdir; +unsigned int users; +}; +#endif /* _NF_DEFRAG_IPV6_H */
net/ipv6/netfilter/nf_conntrack_reasm.c +36 -32
159 lines not on this page · raw message
net/ipv6/netfilter/nf_defrag_ipv6_hooks.c +10 -5
@@ -25,6 +25,8 @@#include <net/netfilter/nf_conntrack_zones.h> #include <net/netfilter/ipv6/nf_defrag_ipv6.h> +extern unsigned int nf_frag_pernet_id; +static DEFINE_MUTEX (defrag6_mutex); static enum ip6_defrag_users nf_ct6_defrag_user(unsigned int hooknum,
@@ -89,10 +91,12 @@ static const struct nf_hook_ops ipv6_defrag_ops[] = { static void __net_exit defrag6_net_exit(struct net *net) { -if (net->nf.defrag_ipv6) { +struct nft_ct_frag6_pernet *nf_frag =net_generic (net, nf_frag_pernet_id); + +if (nf_frag->users) {nf_unregister_net_hooks (net, ipv6_defrag_ops,ARRAY_SIZE (ipv6_defrag_ops)); - net->nf.defrag_ipv6 = false; + nf_frag->users =0 ; } }
@@ -130,21 +134,22 @@ static void __exit nf_defrag_fini(void)int nf_defrag_ipv6_enable (struct net *net) { +struct nft_ct_frag6_pernet *nf_frag =net_generic (net, nf_frag_pernet_id);int err =0 ;might_sleep (); -if (net->nf.defrag_ipv6) +if (nf_frag->users)return 0 ;mutex_lock (&defrag6_mutex); -if (net->nf.defrag_ipv6) +if (nf_frag->users) goto out_unlock; err =nf_register_net_hooks (net, ipv6_defrag_ops,ARRAY_SIZE (ipv6_defrag_ops));if (err ==0 ) - net->nf.defrag_ipv6 = true; + nf_frag->users =1 ; out_unlock:mutex_unlock (&defrag6_mutex);
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 25/28 netfilter: x_tables: move known table lists to net_generic infra
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Will reduce struct net size by 208 bytes.
--- net/netfilter/x_tables.c | 46 ++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 13 deletions(-)
net/netfilter/x_tables.c +33 -13
@@ -24,6 +24,7 @@#include <linux/audit.h> #include <linux/user_namespace.h> #include <net/net_namespace.h> +#include <net/netns/generic.h> #include <linux/netfilter/x_tables.h> #include <linux/netfilter_arp.h>
@@ -38,6 +39,10 @@ MODULE_DESCRIPTION("{ip,ip6,arp,eb}_tables backend module");#define XT_PCPU_BLOCK_SIZE 4096#define XT_MAX_TABLE_SIZE (512 * 1024 * 1024) +struct xt_pernet { +struct list_head tables[NFPROTO_NUMPROTO ]; +}; +struct compat_delta {unsigned int offset;/* offset in kernel */ int delta;/* delta in 32bit user land */
@@ -55,7 +60,8 @@ struct xt_af {#endif }; -static struct xt_af *xt; +static unsigned int xt_pernet_id__read_mostly ; +static struct xt_af *xt__read_mostly ;static const char *const xt_prefix[NFPROTO_NUMPROTO ] = { [NFPROTO_UNSPEC ] ="x" ,
@@ -1203,10 +1209,11 @@ EXPORT_SYMBOL(xt_free_table_info);struct xt_table *xt_find_table_lock (struct net *net,u_int8_t af,const char *name) { +struct xt_pernet *xt_net =net_generic (net, xt_pernet_id);struct xt_table *t, *found =NULL ;mutex_lock (&xt[af].mutex); -list_for_each_entry (t, &net->xt.tables[af], list) +list_for_each_entry (t, &xt_net->tables[af], list)if (strcmp (t->name, name) ==0 &&try_module_get (t->me))return t;
@@ -1214,7 +1221,8 @@ struct xt_table *xt_find_table_lock(struct net *net, u_int8_t af, goto out;/* Table doesn't exist in this netns, re-try init */ -list_for_each_entry (t, &init_net.xt.tables[af], list) { + xt_net =net_generic (&init_net, xt_pernet_id); +list_for_each_entry (t, &xt_net->tables[af], list) {int err;if (strcmp (t->name, name))
@@ -1237,8 +1245,9 @@ struct xt_table *xt_find_table_lock(struct net *net, u_int8_t af,if (!found) goto out; + xt_net =net_generic (net, xt_pernet_id);/* and once again: */ -list_for_each_entry (t, &net->xt.tables[af], list) +list_for_each_entry (t, &xt_net->tables[af], list)if (strcmp (t->name, name) ==0 )return t;
@@ -1423,9 +1432,10 @@ struct xt_table *xt_register_table(struct net *net,struct xt_table_info *bootstrap, struct xt_table_info *newinfo) { - int ret; + struct xt_pernet *xt_net = net_generic(net, xt_pernet_id);struct xt_table_info *private;struct xt_table *t, *table; +int ret;/* Don't add one object to multiple lists. */ table =kmemdup (input_table,sizeof (struct xt_table ),GFP_KERNEL );
@@ -1436,7 +1446,7 @@ struct xt_table *xt_register_table(struct net *net,mutex_lock (&xt[table->af].mutex);/* Don't autoload: we'd eat our tail... */ -list_for_each_entry (t, &net->xt.tables[table->af], list) { +list_for_each_entry (t, &xt_net->tables[table->af], list) {if (strcmp (t->name, table->name) ==0 ) { ret = -EEXIST ; goto unlock;
@@ -1455,7 +1465,7 @@ struct xt_table *xt_register_table(struct net *net,/* save number of initial entries */ private->initial_entries = private->number; -list_add (&table->list, &net->xt.tables[table->af]); +list_add (&table->list, &xt_net->tables[table->af]);mutex_unlock (&xt[table->af].mutex);return table;
@@ -1486,19 +1496,25 @@ EXPORT_SYMBOL_GPL(xt_unregister_table);#ifdef CONFIG_PROC_FS static void *xt_table_seq_start (struct seq_file *seq,loff_t *pos) { +u8 af = (unsigned long )PDE_DATA (file_inode (seq->file));struct net *net =seq_file_net (seq); -u_int8_t af = (unsigned long )PDE_DATA (file_inode (seq->file)); +struct xt_pernet *xt_net; + + xt_net =net_generic (net, xt_pernet_id);mutex_lock (&xt[af].mutex); -return seq_list_start (&net->xt.tables[af], *pos); +return seq_list_start (&xt_net->tables[af], *pos); }static void *xt_table_seq_next (struct seq_file *seq,void *v,loff_t *pos) { +u8 af = (unsigned long )PDE_DATA (file_inode (seq->file));struct net *net =seq_file_net (seq); -u_int8_t af = (unsigned long )PDE_DATA (file_inode (seq->file)); +struct xt_pernet *xt_net; + + xt_net =net_generic (net, xt_pernet_id); -return seq_list_next (v, &net->xt.tables[af], pos); +return seq_list_next (v, &xt_net->tables[af], pos); }static void xt_table_seq_stop (struct seq_file *seq,void *v)
@@ -1864,24 +1880,28 @@ EXPORT_SYMBOL_GPL(xt_percpu_counter_free);static int __net_init xt_net_init (struct net *net) { +struct xt_pernet *xt_net =net_generic (net, xt_pernet_id);int i;for (i =0 ; i <NFPROTO_NUMPROTO ; i++) -INIT_LIST_HEAD (&net->xt.tables[i]); +INIT_LIST_HEAD (&xt_net->tables[i]);return 0 ; } static void __net_exit xt_net_exit(struct net *net) { +struct xt_pernet *xt_net =net_generic (net, xt_pernet_id);int i;for (i =0 ; i <NFPROTO_NUMPROTO ; i++) -WARN_ON_ONCE (!list_empty (&net->xt.tables[i])); +WARN_ON_ONCE (!list_empty (&xt_net->tables[i])); }static struct pernet_operations xt_net_ops = { .init = xt_net_init, .exit = xt_net_exit, + .id = &xt_pernet_id, + .size =sizeof (struct xt_pernet ), };static int __init xt_init (void )
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 26/28 netfilter: conntrack: move sysctl pointer to net_generic infra
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
No need to keep this in struct net, place it in the net_generic data. The sysctl pointer is removed from struct net in a followup patch.
--- include/net/netfilter/nf_conntrack.h | 3 +++ net/netfilter/nf_conntrack_standalone.c | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-)
include/net/netfilter/nf_conntrack.h +3 -0
@@ -47,6 +47,9 @@ struct nf_conntrack_net {unsigned int users4;unsigned int users6;unsigned int users_bridge; +#ifdef CONFIG_SYSCTL +struct ctl_table_header *sysctl_header; +#endif };#include <linux/types.h>
net/netfilter/nf_conntrack_standalone.c +6 -4
@@ -1027,6 +1027,7 @@ static void nf_conntrack_standalone_init_gre_sysctl(struct net *net,static int nf_conntrack_standalone_init_sysctl (struct net *net) { +struct nf_conntrack_net *cnet =net_generic (net, nf_conntrack_net_id);struct nf_udp_net *un =nf_udp_pernet (net);struct ctl_table *table;
@@ -1072,8 +1073,8 @@ static int nf_conntrack_standalone_init_sysctl(struct net *net) table[NF_SYSCTL_CT_BUCKETS ].mode =0444 ; } - net->ct.sysctl_header =register_net_sysctl (net,"net/netfilter" , table); -if (!net->ct.sysctl_header) + cnet->sysctl_header =register_net_sysctl (net,"net/netfilter" , table); +if (!cnet->sysctl_header) goto out_unregister_netfilter;return 0 ;
@@ -1085,10 +1086,11 @@ static int nf_conntrack_standalone_init_sysctl(struct net *net)static void nf_conntrack_standalone_fini_sysctl (struct net *net) { +struct nf_conntrack_net *cnet =net_generic (net, nf_conntrack_net_id);struct ctl_table *table; - table = net->ct.sysctl_header->ctl_table_arg; -unregister_net_sysctl_table (net->ct.sysctl_header); + table = cnet->sysctl_header->ctl_table_arg; +unregister_net_sysctl_table (cnet->sysctl_header);kfree (table); }#else
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 27/28 netfilter: conntrack: move ecache dwork to net_generic infra
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
dwork struct is large (>128 byte) and not needed when conntrack module is not loaded.
Place it in net_generic data instead. The struct net dwork member is now obsolete and will be removed in a followup patch.
--- include/net/netfilter/nf_conntrack.h | 4 +++ include/net/netfilter/nf_conntrack_ecache.h | 33 ++++++++------------- net/netfilter/nf_conntrack_core.c | 7 +++-- net/netfilter/nf_conntrack_ecache.c | 31 +++++++++++++++---- 4 files changed, 47 insertions(+), 28 deletions(-)
include/net/netfilter/nf_conntrack.h +4 -0
@@ -50,6 +50,10 @@ struct nf_conntrack_net {#ifdef CONFIG_SYSCTL struct ctl_table_header *sysctl_header;#endif +#ifdef CONFIG_NF_CONNTRACK_EVENTS +struct delayed_work ecache_dwork; +struct netns_ct *ct_net; +#endif };#include <linux/types.h>
include/net/netfilter/nf_conntrack_ecache.h +12 -21
@@ -171,12 +171,18 @@ void nf_ct_expect_event_report(enum ip_conntrack_expect_events event,struct nf_conntrack_expect *exp, u32 portid, int report); +void nf_conntrack_ecache_work (struct net *net,enum nf_ct_ecache_state state); +void nf_conntrack_ecache_pernet_init (struct net *net);void nf_conntrack_ecache_pernet_fini (struct net *net);int nf_conntrack_ecache_init (void );void nf_conntrack_ecache_fini (void ); +static inline bool nf_conntrack_ecache_dwork_pending (const struct net *net) +{ +return net->ct.ecache_dwork_pending; +}#else /* CONFIG_NF_CONNTRACK_EVENTS */ static inline void nf_ct_expect_event_report(enum ip_conntrack_expect_events e,
@@ -186,6 +192,11 @@ static inline void nf_ct_expect_event_report(enum ip_conntrack_expect_events e, { } +static inline void nf_conntrack_ecache_work (struct net *net, +enum nf_ct_ecache_state s) +{ +} +static inline void nf_conntrack_ecache_pernet_init (struct net *net) { }
@@ -203,26 +214,6 @@ static inline void nf_conntrack_ecache_fini(void) { } +static inline bool nf_conntrack_ecache_dwork_pending (const struct net *net) {return false; }#endif /* CONFIG_NF_CONNTRACK_EVENTS */ - -static inline void nf_conntrack_ecache_delayed_work (struct net *net) -{ -#ifdef CONFIG_NF_CONNTRACK_EVENTS -if (!delayed_work_pending (&net->ct.ecache_dwork)) { -schedule_delayed_work (&net->ct.ecache_dwork,HZ ); - net->ct.ecache_dwork_pending = true; - } -#endif -} - -static inline void nf_conntrack_ecache_work (struct net *net) -{ -#ifdef CONFIG_NF_CONNTRACK_EVENTS -if (net->ct.ecache_dwork_pending) { - net->ct.ecache_dwork_pending = false; -mod_delayed_work (system_wq, &net->ct.ecache_dwork,0 ); - } -#endif -} -#endif /*_NF_CONNTRACK_ECACHE_H*/
net/netfilter/nf_conntrack_core.c +5 -2
@@ -656,6 +656,7 @@ static void nf_ct_delete_from_lists(struct nf_conn *ct)bool nf_ct_delete (struct nf_conn *ct,u32 portid,int report) {struct nf_conn_tstamp *tstamp; +struct net *net;if (test_and_set_bit (IPS_DYING_BIT , &ct->status))return false;
@@ -670,11 +671,13 @@ bool nf_ct_delete(struct nf_conn *ct, u32 portid, int report)* be done by event cache worker on redelivery. */ nf_ct_delete_from_lists (ct); -nf_conntrack_ecache_delayed_work (nf_ct_net (ct)); +nf_conntrack_ecache_work (nf_ct_net (ct),NFCT_ECACHE_DESTROY_FAIL );return false; } -nf_conntrack_ecache_work (nf_ct_net (ct)); + net =nf_ct_net (ct); +if (nf_conntrack_ecache_dwork_pending (net)) +nf_conntrack_ecache_work (net,NFCT_ECACHE_DESTROY_SENT );nf_ct_delete_from_lists (ct);nf_ct_put (ct);return true;
net/netfilter/nf_conntrack_ecache.c +26 -5
@@ -27,6 +27,8 @@#include <net/netfilter/nf_conntrack_ecache.h> #include <net/netfilter/nf_conntrack_extend.h> +extern unsigned int nf_conntrack_net_id; +static DEFINE_MUTEX (nf_ct_ecache_mutex);#define ECACHE_RETRY_WAIT (HZ/10)
@@ -96,8 +98,8 @@ static enum retry_state ecache_work_evict_list(struct ct_pcpu *pcpu)static void ecache_work (struct work_struct *work) { -struct netns_ct *ctnet = - container_of(work, struct netns_ct, ecache_dwork.work); + struct nf_conntrack_net *cnet = container_of(work, struct nf_conntrack_net, ecache_dwork.work); +struct netns_ct *ctnet = cnet->ct_net;int cpu, delay =-1 ;struct ct_pcpu *pcpu;
@@ -127,7 +129,7 @@ static void ecache_work(struct work_struct *work) ctnet->ecache_dwork_pending = delay >0 ;if (delay >=0 ) -schedule_delayed_work (&ctnet->ecache_dwork, delay); +schedule_delayed_work (&cnet->ecache_dwork, delay); } int nf_conntrack_eventmask_report(unsigned int eventmask, struct nf_conn *ct,
@@ -344,6 +346,20 @@ void nf_ct_expect_unregister_notifier(struct net *net, }EXPORT_SYMBOL_GPL (nf_ct_expect_unregister_notifier); +void nf_conntrack_ecache_work (struct net *net,enum nf_ct_ecache_state state) +{ +struct nf_conntrack_net *cnet =net_generic (net, nf_conntrack_net_id); + +if (state ==NFCT_ECACHE_DESTROY_FAIL && + !delayed_work_pending (&cnet->ecache_dwork)) { +schedule_delayed_work (&cnet->ecache_dwork,HZ ); + net->ct.ecache_dwork_pending = true; + }else if (state ==NFCT_ECACHE_DESTROY_SENT ) { + net->ct.ecache_dwork_pending = false; +mod_delayed_work (system_wq, &cnet->ecache_dwork,0 ); + } +} +#define NF_CT_EVENTS_DEFAULT 1static int nf_ct_events__read_mostly =NF_CT_EVENTS_DEFAULT ;
@@ -355,13 +371,18 @@ static const struct nf_ct_ext_type event_extend = {void nf_conntrack_ecache_pernet_init (struct net *net) { +struct nf_conntrack_net *cnet =net_generic (net, nf_conntrack_net_id); + net->ct.sysctl_events = nf_ct_events; -INIT_DELAYED_WORK (&net->ct.ecache_dwork, ecache_work); + cnet->ct_net = &net->ct; +INIT_DELAYED_WORK (&cnet->ecache_dwork, ecache_work); }void nf_conntrack_ecache_pernet_fini (struct net *net) { -cancel_delayed_work_sync (&net->ct.ecache_dwork); +struct nf_conntrack_net *cnet =net_generic (net, nf_conntrack_net_id); + +cancel_delayed_work_sync (&cnet->ecache_dwork); }int nf_conntrack_ecache_init (void )
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 28/28 net: remove obsolete members from struct net
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
all have been moved to generic_net infra. On x86_64, this reduces struct net size from 70 to 63 cache lines (4480 to 4032 byte).
--- include/net/net_namespace.h | 9 --------- include/net/netns/conntrack.h | 4 ---- include/net/netns/netfilter.h | 6 ------ include/net/netns/nftables.h | 7 ------- include/net/netns/x_tables.h | 1 - 5 files changed, 27 deletions(-)
include/net/net_namespace.h +0 -9
@@ -142,15 +142,6 @@ struct net {#if defined(CONFIG_NF_TABLES ) || defined(CONFIG_NF_TABLES_MODULE )struct netns_nftables nft;#endif -#if IS_ENABLED (CONFIG_NF_DEFRAG_IPV6 ) -struct netns_nf_frag nf_frag; -struct ctl_table_header *nf_frag_frags_hdr; -#endif -struct sock *nfnl; -struct sock *nfnl_stash; -#if IS_ENABLED (CONFIG_NF_CT_NETLINK_TIMEOUT ) -struct list_head nfct_timeout_list; -#endif #endif #ifdef CONFIG_WEXT_CORE struct sk_buff_head wext_nlevents;
include/net/netns/conntrack.h +0 -4
@@ -96,13 +96,9 @@ struct netns_ct {atomic_t count;unsigned int expect_count;#ifdef CONFIG_NF_CONNTRACK_EVENTS -struct delayed_work ecache_dwork;bool ecache_dwork_pending;#endif bool auto_assign_helper_warned; -#ifdef CONFIG_SYSCTL -struct ctl_table_header *sysctl_header; -#endif unsigned int sysctl_log_invalid;/* Log invalid packets */ int sysctl_events;int sysctl_acct;
include/net/netns/netfilter.h +0 -6
@@ -28,11 +28,5 @@ struct netns_nf {#if IS_ENABLED (CONFIG_DECNET )struct nf_hook_entries __rcu *hooks_decnet[NF_DN_NUMHOOKS ]; #endif -#if IS_ENABLED (CONFIG_NF_DEFRAG_IPV4 ) -bool defrag_ipv4; -#endif -#if IS_ENABLED (CONFIG_NF_DEFRAG_IPV6 ) -bool defrag_ipv6; -#endif };#endif
include/net/netns/nftables.h +0 -7
@@ -5,14 +5,7 @@#include <linux/list.h> struct netns_nftables { -struct list_head tables; -struct list_head commit_list; -struct list_head module_list; -struct list_head notify_list; -struct mutex commit_mutex; -unsigned int base_seq;u8 gencursor; -u8 validate_state; };#endif
include/net/netns/x_tables.h +0 -1
@@ -8,7 +8,6 @@struct ebt_table ;struct netns_xt { -struct list_head tables[NFPROTO_NUMPROTO ];bool notrack_deprecated_warning;bool clusterip_deprecated_warning; #if defined(CONFIG_BRIDGE_NF_EBTABLES) || \
Signature · 1 line
2.30.2