modularize br_netfilter
Subsystems (3)
Pablo Neira Ayuso
maintainercover modularize br_netfilter
Hi,
I'm posting this series to take over the discussion on br_netfilter that Florian triggered with his initial patch.
At this moment, I see two possibilities:
1) Add glue code to make br_netfilter look like it is still available from the bridge core and spot a warning to announce deprecation in two years or so.
2) Modularize br_netfilter so users can control if this feature is enabled/disabled through modprobe/rmmod.
Regarding 1), Patrick suggested that users may overlook the warning message and things will break after that time.
On top of that I'm not sure anymore it is worth the effort to work on 1), given that the design problems and limitations of br_netfilter. We cannot obviously get rid of br_netfilter, but we can fence it and let users easily undo the damage by including 'modprobe br_netfilter' in their scripts if they really need it.
Let me know, thanks.
Pablo Neira Ayuso (2):
netfilter: bridge: nf_bridge_copy_header as static inline in header
netfilter: move br_netfilter out of the bridge core
include/linux/netfilter_bridge.h | 50 +++++++++++--- include/linux/skbuff.h | 12 ++-- include/net/neighbour.h | 2 +- include/net/netfilter/ipv4/nf_reject.h | 2 +- include/net/netfilter/ipv6/nf_reject.h | 2 +- net/Kconfig | 2 +- net/bridge/Makefile | 5 +- net/bridge/br.c | 14 ++-- net/bridge/br_device.c | 4 +- net/bridge/br_forward.c | 2 + net/bridge/br_input.c | 1 + net/bridge/br_netfilter.c | 116 +++++--------------------------- net/bridge/br_netlink.c | 2 +- net/bridge/br_nf_core.c | 96 ++++++++++++++++++++++++++ net/bridge/br_private.h | 12 ++-- net/bridge/br_sysfs_br.c | 4 +- 16 files changed, 186 insertions(+), 140 deletions(-) create mode 100644 net/bridge/br_nf_core.c
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 1/1 netfilter: move br_netfilter out of the bridge core
Jesper reported that br_netfilter always registers the hooks since this is part of the bridge core. This harms performance for people that don't need this.
This patch modularizes br_netfilter so it can be rmmod'ed, thus, the hooks can be unregistered. I think the bridge netfilter should have been a separated module since the beginning, Patrick agreed on that.
Note that this is breaking compatibility for users that expect that bridge netfilter is going to be available after explicitly 'modprobe bridge' or via automatic load through brctl.
However, the damage can be easily undone by modprobing br_netfilter. The bridge core also spots a message to provide a clue to people that didn't notice that this has been deprecated.
On top of that, the plan is that nftables will not rely on this software layer, but integrate the connection tracking into the bridge layer to enable stateful filtering and NAT, which is was bridge netfilter users seem to require.
This patch still keeps the fake_dst_ops in the bridge core, since this is required by when the bridge port is initialized. So we can safely modprobe/rmmod br_netfilter anytime.
--- include/linux/netfilter_bridge.h | 2 +- include/linux/skbuff.h | 12 ++-- include/net/neighbour.h | 2 +- include/net/netfilter/ipv4/nf_reject.h | 2 +- include/net/netfilter/ipv6/nf_reject.h | 2 +- net/Kconfig | 7 ++- net/bridge/Makefile | 5 +- net/bridge/br.c | 14 +++-- net/bridge/br_device.c | 4 +- net/bridge/br_forward.c | 2 + net/bridge/br_input.c | 1 + net/bridge/br_netfilter.c | 88 ++++++----------------------- net/bridge/br_netlink.c | 2 +- net/bridge/br_nf_core.c | 96 ++++++++++++++++++++++++++++++++ net/bridge/br_private.h | 12 ++-- net/bridge/br_sysfs_br.c | 4 +- 16 files changed, 151 insertions(+), 104 deletions(-) create mode 100644 net/bridge/br_nf_core.c
include/linux/netfilter_bridge.h +1 -1
@@ -15,7 +15,7 @@ enum nf_br_hook_priorities { NF_BR_PRI_LAST = INT_MAX, }; -#ifdef CONFIG_BRIDGE_NETFILTER +#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER )#define BRNF_PKT_TYPE 0x01#define BRNF_BRIDGED_DNAT 0x02
include/linux/skbuff.h +6 -6
@@ -156,7 +156,7 @@ struct nf_conntrack { };#endif -#ifdef CONFIG_BRIDGE_NETFILTER +#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER ) struct nf_bridge_info { atomic_t use; unsigned int mask;
@@ -560,7 +560,7 @@ struct sk_buff {#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE )struct nf_conntrack *nfct;#endif -#ifdef CONFIG_BRIDGE_NETFILTER +#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER )struct nf_bridge_info *nf_bridge;#endif
@@ -2977,7 +2977,7 @@ static inline void nf_conntrack_get(struct nf_conntrack *nfct)atomic_inc (&nfct->use); }#endif -#ifdef CONFIG_BRIDGE_NETFILTER +#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER )static inline void nf_bridge_put (struct nf_bridge_info *nf_bridge) {if (nf_bridge &&atomic_dec_and_test (&nf_bridge->use))
@@ -2995,7 +2995,7 @@ static inline void nf_reset(struct sk_buff *skb)nf_conntrack_put (skb->nfct); skb->nfct =NULL ;#endif -#ifdef CONFIG_BRIDGE_NETFILTER +#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER )nf_bridge_put (skb->nf_bridge); skb->nf_bridge =NULL ;#endif
@@ -3016,7 +3016,7 @@ static inline void __nf_copy(struct sk_buff *dst, const struct sk_buff *src)nf_conntrack_get (src->nfct); dst->nfctinfo = src->nfctinfo;#endif -#ifdef CONFIG_BRIDGE_NETFILTER +#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER ) dst->nf_bridge = src->nf_bridge;nf_bridge_get (src->nf_bridge);#endif
@@ -3030,7 +3030,7 @@ static inline void nf_copy(struct sk_buff *dst, const struct sk_buff *src)#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE )nf_conntrack_put (dst->nfct);#endif -#ifdef CONFIG_BRIDGE_NETFILTER +#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER )nf_bridge_put (dst->nf_bridge);#endif __nf_copy (dst, src);
include/net/neighbour.h +1 -1
@@ -373,7 +373,7 @@ static inline int neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)return 0 ; } -#ifdef CONFIG_BRIDGE_NETFILTER +#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER )static inline int neigh_hh_bridge (struct hh_cache *hh,struct sk_buff *skb) {unsigned int seq, hh_alen;
include/net/netfilter/ipv4/nf_reject.h +1 -1
@@ -98,7 +98,7 @@ static void nf_send_reset(struct sk_buff *oldskb, int hook)nf_ct_attach (nskb, oldskb); -#ifdef CONFIG_BRIDGE_NETFILTER +#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER )/* If we use ip_local_out for bridged traffic, the MAC source on * the RST will be ours, instead of the destination's. This confuses * some routers/firewalls, and they drop the packet. So we need to
include/net/netfilter/ipv6/nf_reject.h +1 -1
@@ -147,7 +147,7 @@ static void nf_send_reset6(struct net *net, struct sk_buff *oldskb, int hook)nf_ct_attach (nskb, oldskb); -#ifdef CONFIG_BRIDGE_NETFILTER +#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER )/* If we use ip6_local_out for bridged traffic, the MAC source on * the RST will be ours, instead of the destination's. This confuses * some routers/firewalls, and they drop the packet. So we need to
net/Kconfig +4 -3
@@ -176,10 +176,11 @@ config NETFILTER_ADVANCED If unsure, say Y. config BRIDGE_NETFILTER - bool "Bridged IP/ARP packets filtering" - depends on BRIDGE && NETFILTER && INET + tristate "Bridged IP/ARP packets filtering" + depends on (BRIDGE || BRIDGE=n) + depends on NETFILTER && INET depends on NETFILTER_ADVANCED - default y + default m ---help--- Enabling this option will let arptables resp. iptables see bridged ARP resp. IP traffic. If you want a bridging firewall, you probably
net/bridge/Makefile +3 -2
@@ -6,11 +6,12 @@ obj-$(CONFIG_BRIDGE) += bridge.o bridge-y := br.o br_device.o br_fdb.o br_forward.o br_if.o br_input.o \ br_ioctl.o br_stp.o br_stp_bpdu.o \ - br_stp_if.o br_stp_timer.o br_netlink.o + br_stp_if.o br_stp_timer.o br_netlink.o \ + br_nf_core.o bridge-$(CONFIG_SYSFS) += br_sysfs_if.o br_sysfs_br.o -bridge-$(CONFIG_BRIDGE_NETFILTER) += br_netfilter.o +obj-$(CONFIG_BRIDGE_NETFILTER) += br_netfilter.o bridge-$(CONFIG_BRIDGE_IGMP_SNOOPING) += br_multicast.o br_mdb.o
net/bridge/br.c +8 -6
@@ -161,7 +161,7 @@ static int __init br_init(void)if (err) goto err_out1; - err =br_netfilter_init (); + err =br_nf_core_init ();if (err) goto err_out2;
@@ -179,11 +179,16 @@ static int __init br_init(void) br_fdb_test_addr_hook = br_fdb_test_addr;#endif +pr_info ("bridge: automatic filtering via arp/ip/ip6tables has been " +"deprecated. Update your scripts to load br_netfilter if you " +"need this.\n" ); +return 0 ; + err_out4:unregister_netdevice_notifier (&br_device_notifier); err_out3: -br_netfilter_fini (); +br_nf_core_fini (); err_out2:unregister_pernet_subsys (&br_net_ops); err_out1:
@@ -196,20 +201,17 @@ err_out: static void __exit br_deinit(void) {stp_proto_unregister (&br_stp_proto); -br_netlink_fini ();unregister_netdevice_notifier (&br_device_notifier);brioctl_set (NULL ); -unregister_pernet_subsys (&br_net_ops);rcu_barrier ();/* Wait for completion of call_rcu()'s */ -br_netfilter_fini (); +br_nf_core_fini ();#if IS_ENABLED (CONFIG_ATM_LANE ) br_fdb_test_addr_hook =NULL ;#endif -br_fdb_fini (); }
net/bridge/br_device.c +2 -2
@@ -36,7 +36,7 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)u16 vid =0 ;rcu_read_lock (); -#ifdef CONFIG_BRIDGE_NETFILTER +#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER )if (skb->nf_bridge && (skb->nf_bridge->mask &BRNF_BRIDGED_DNAT )) {br_nf_pre_routing_finish_bridge_slow (skb);rcu_read_unlock ();
@@ -167,7 +167,7 @@ static int br_change_mtu(struct net_device *dev, int new_mtu) dev->mtu = new_mtu; -#ifdef CONFIG_BRIDGE_NETFILTER +#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER )/* remember the MTU in the rtable for PMTU */ dst_metric_set (&br->fake_rtable.dst,RTAX_MTU , new_mtu);#endif
net/bridge/br_forward.c +2 -0
@@ -49,6 +49,7 @@ int br_dev_queue_push_xmit(struct sk_buff *skb)return 0 ; } +EXPORT_SYMBOL_GPL (br_dev_queue_push_xmit);int br_forward_finish (struct sk_buff *skb) {
@@ -56,6 +57,7 @@ int br_forward_finish(struct sk_buff *skb) br_dev_queue_push_xmit); } +EXPORT_SYMBOL_GPL (br_forward_finish);static void __br_deliver (const struct net_bridge_port *to,struct sk_buff *skb) {
net/bridge/br_input.c +1 -0
@@ -140,6 +140,7 @@ drop:kfree_skb (skb); goto out; } +EXPORT_SYMBOL_GPL (br_handle_frame_finish);/* note: already called with rcu_read_lock */ static int br_handle_local_finish (struct sk_buff *skb)
net/bridge/br_netfilter.c +16 -72
120 lines not on this page · raw message
net/bridge/br_netlink.c +1 -1
@@ -602,7 +602,7 @@ out_af:return err; } -void __exit br_netlink_fini(void) +void br_netlink_fini (void ) {br_mdb_uninit ();rtnl_af_unregister (&br_af_ops);
net/bridge/br_nf_core.c new file +96 -0
96 lines not on this page · raw message
net/bridge/br_private.h +6 -6
@@ -221,7 +221,7 @@ struct net_bridgestruct pcpu_sw_netstats __percpu *stats;spinlock_t hash_lock;struct hlist_head hash[BR_HASH_SIZE ]; -#ifdef CONFIG_BRIDGE_NETFILTER +#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER )struct rtable fake_rtable;bool nf_call_iptables;bool nf_call_ip6tables;
@@ -751,13 +751,13 @@ static inline int br_vlan_enabled(struct net_bridge *br)#endif /* br_netfilter.c */ -#ifdef CONFIG_BRIDGE_NETFILTER -int br_netfilter_init (void ); -void br_netfilter_fini (void ); +#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER ) +int br_nf_core_init (void ); +void br_nf_core_fini (void );void br_netfilter_rtable_init (struct net_bridge *);#else -#define br_netfilter_init () (0) -#define br_netfilter_fini () do { } while (0) +static inline int br_nf_core_init (void ) {return 0 ; } +static inline void br_nf_core_fini (void ) {}#define br_netfilter_rtable_init (x)#endif
net/bridge/br_sysfs_br.c +2 -2
@@ -629,7 +629,7 @@ static ssize_t multicast_startup_query_interval_store( }static DEVICE_ATTR_RW (multicast_startup_query_interval);#endif -#ifdef CONFIG_BRIDGE_NETFILTER +#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER )static ssize_t nf_call_iptables_show (struct device *d,struct device_attribute *attr,char *buf) {
@@ -763,7 +763,7 @@ static struct attribute *bridge_attrs[] = { &dev_attr_multicast_query_response_interval.attr, &dev_attr_multicast_startup_query_interval.attr, #endif -#ifdef CONFIG_BRIDGE_NETFILTER +#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) &dev_attr_nf_call_iptables.attr, &dev_attr_nf_call_ip6tables.attr, &dev_attr_nf_call_arptables.attr,
Signature · 1 line
1.7.10.4
Re: [PATCH nf-next] netfilter: move br_netfilter out of the bridge core
Quoted 21 lines · Pablo Neira Ayuso
Jesper reported that
br_netfilteralways registers the hooks since this is part of the bridge core. This harms performance for people that don't need this.This patch modularizes
br_netfilterso it can be rmmod'ed, thus, the hooks can be unregistered. I think the bridge netfilter should have been a separated module since the beginning, Patrick agreed on that.Note that this is breaking compatibility for users that expect that bridge netfilter is going to be available after explicitly 'modprobe bridge' or via automatic load through brctl.
However, the damage can be easily undone by modprobing
br_netfilter. The bridge core also spots a message to provide a clue to people that didn't notice that this has been deprecated.On top of that, the plan is that nftables will not rely on this software layer, but integrate the connection tracking into the bridge layer to enable stateful filtering and NAT, which is was bridge netfilter users seem to require.
Quoted 5 lines
This patch still keeps the
fake_dst_opsin the bridge core, since this is required by when the bridge port is initialized. So we can safely modprobe/rmmodbr_netfilteranytime.Signed-off-by Pablo Neira Ayuso <[email protected]>
Thanks Pablo.
Pablo Neira Ayuso
maintainerPATCH 1/2 netfilter: bridge: nf_bridge_copy_header as static inline in header
In reply to Pablo Neira AyusoMove nf_bridge_copy_header() as static inline in netfilter_bridge.h header file. This patch prepares the modularization of the br_netfilter code.
--- include/linux/netfilter_bridge.h | 48 ++++++++++++++++++++++++++++++-------- net/bridge/br_netfilter.c | 28 ---------------------- 2 files changed, 38 insertions(+), 38 deletions(-)
include/linux/netfilter_bridge.h +38 -10
@@ -24,16 +24,6 @@ enum nf_br_hook_priorities {#define BRNF_8021Q 0x10#define BRNF_PPPoE 0x20 -/* Only used in br_forward.c */ -int nf_bridge_copy_header (struct sk_buff *skb); -static inline int nf_bridge_maybe_copy_header (struct sk_buff *skb) -{ -if (skb->nf_bridge && - skb->nf_bridge->mask & (BRNF_BRIDGED |BRNF_BRIDGED_DNAT )) -return nf_bridge_copy_header (skb); -return 0 ; -} -static inline unsigned int nf_bridge_encap_header_len (const struct sk_buff *skb) {switch (skb->protocol) {
@@ -46,6 +36,44 @@ static inline unsigned int nf_bridge_encap_header_len(const struct sk_buff *skb) } } +static inline void nf_bridge_update_protocol (struct sk_buff *skb) +{ +if (skb->nf_bridge->mask &BRNF_8021Q ) + skb->protocol =htons (ETH_P_8021Q ); +else if (skb->nf_bridge->mask & BRNF_PPPoE) + skb->protocol =htons (ETH_P_PPP_SES ); +} + +/* Fill in the header for fragmented IP packets handled by +* the IPv4 connection tracking code. +* +* Only used in br_forward.c +*/ +static inline int nf_bridge_copy_header (struct sk_buff *skb) +{ +int err; +unsigned int header_size; + +nf_bridge_update_protocol (skb); + header_size =ETH_HLEN +nf_bridge_encap_header_len (skb); + err =skb_cow_head (skb, header_size); +if (err) +return err; + +skb_copy_to_linear_data_offset (skb, -header_size, + skb->nf_bridge->data, header_size); +__skb_push (skb,nf_bridge_encap_header_len (skb)); +return 0 ; +} + +static inline int nf_bridge_maybe_copy_header (struct sk_buff *skb) +{ +if (skb->nf_bridge && + skb->nf_bridge->mask & (BRNF_BRIDGED |BRNF_BRIDGED_DNAT )) +return nf_bridge_copy_header (skb); +return 0 ; +} +static inline unsigned int nf_bridge_mtu_reduction (const struct sk_buff *skb) {if (unlikely (skb->nf_bridge->mask & BRNF_PPPoE))
net/bridge/br_netfilter.c +0 -28
@@ -245,14 +245,6 @@ static inline void nf_bridge_save_header(struct sk_buff *skb) skb->nf_bridge->data, header_size); } -static inline void nf_bridge_update_protocol (struct sk_buff *skb) -{ -if (skb->nf_bridge->mask &BRNF_8021Q ) - skb->protocol =htons (ETH_P_8021Q ); -else if (skb->nf_bridge->mask & BRNF_PPPoE) - skb->protocol =htons (ETH_P_PPP_SES ); -} -/* When handing a packet over to the IP layer * check whether we have a skb that is in the * expected format
@@ -320,26 +312,6 @@ drop:return -1 ; } -/* Fill in the header for fragmented IP packets handled by -* the IPv4 connection tracking code. -*/ -int nf_bridge_copy_header (struct sk_buff *skb) -{ -int err; -unsigned int header_size; - -nf_bridge_update_protocol (skb); - header_size =ETH_HLEN +nf_bridge_encap_header_len (skb); - err =skb_cow_head (skb, header_size); -if (err) -return err; - -skb_copy_to_linear_data_offset (skb, -header_size, - skb->nf_bridge->data, header_size); -__skb_push (skb,nf_bridge_encap_header_len (skb)); -return 0 ; -} -/* PF_BRIDGE/PRE_ROUTING *********************************************/ /* Undo the changes made for ip6tables PREROUTING and continue the * bridge PRE_ROUTING hook. */
Signature · 1 line
1.7.10.4