0efa2967121dba51d31847645ba9eab952e132c9
[openwrt/openwrt.git] / target / linux / generic / patches-4.0 / 644-bridge_optimize_netfilter_hooks.patch
1 --- a/net/bridge/br_forward.c
2 +++ b/net/bridge/br_forward.c
3 @@ -53,7 +53,7 @@ EXPORT_SYMBOL_GPL(br_dev_queue_push_xmit
4
5 int br_forward_finish(struct sk_buff *skb)
6 {
7 - return NF_HOOK(NFPROTO_BRIDGE, NF_BR_POST_ROUTING, skb, NULL, skb->dev,
8 + return BR_HOOK(NFPROTO_BRIDGE, NF_BR_POST_ROUTING, skb, NULL, skb->dev,
9 br_dev_queue_push_xmit);
10
11 }
12 @@ -77,7 +77,7 @@ static void __br_deliver(const struct ne
13 return;
14 }
15
16 - NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
17 + BR_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
18 br_forward_finish);
19 }
20
21 @@ -98,7 +98,7 @@ static void __br_forward(const struct ne
22 skb->dev = to->dev;
23 skb_forward_csum(skb);
24
25 - NF_HOOK(NFPROTO_BRIDGE, NF_BR_FORWARD, skb, indev, skb->dev,
26 + BR_HOOK(NFPROTO_BRIDGE, NF_BR_FORWARD, skb, indev, skb->dev,
27 br_forward_finish);
28 }
29
30 --- a/net/bridge/br_input.c
31 +++ b/net/bridge/br_input.c
32 @@ -55,7 +55,7 @@ static int br_pass_frame_up(struct sk_bu
33 if (!skb)
34 return NET_RX_DROP;
35
36 - return NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, skb, indev, NULL,
37 + return BR_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, skb, indev, NULL,
38 netif_receive_skb);
39 }
40
41 @@ -280,7 +280,7 @@ rx_handler_result_t br_handle_frame(stru
42 }
43
44 /* Deliver packet to local host only */
45 - if (NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, skb, skb->dev,
46 + if (BR_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, skb, skb->dev,
47 NULL, br_handle_local_finish)) {
48 return RX_HANDLER_CONSUMED; /* consumed by filter */
49 } else {
50 @@ -295,7 +295,7 @@ forward:
51 if (ether_addr_equal(p->br->dev->dev_addr, dest))
52 skb->pkt_type = PACKET_HOST;
53
54 - if (NF_HOOK(NFPROTO_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
55 + if (BR_HOOK(NFPROTO_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
56 br_handle_local_finish))
57 break;
58
59 @@ -317,7 +317,7 @@ forward:
60 if (ether_addr_equal(p->br->dev->dev_addr, dest))
61 skb->pkt_type = PACKET_HOST;
62
63 - NF_HOOK(NFPROTO_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
64 + BR_HOOK(NFPROTO_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
65 br_handle_frame_finish);
66 break;
67 default:
68 --- a/net/bridge/br_multicast.c
69 +++ b/net/bridge/br_multicast.c
70 @@ -814,7 +814,7 @@ static void __br_multicast_send_query(st
71
72 if (port) {
73 skb->dev = port->dev;
74 - NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
75 + BR_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
76 br_dev_queue_push_xmit);
77 } else {
78 br_multicast_select_own_querier(br, ip, skb);
79 --- a/net/bridge/br_netfilter.c
80 +++ b/net/bridge/br_netfilter.c
81 @@ -74,6 +74,15 @@ static int brnf_pass_vlan_indev __read_m
82 #define IS_ARP(skb) \
83 (!skb_vlan_tag_present(skb) && skb->protocol == htons(ETH_P_ARP))
84
85 +int brnf_call_ebtables __read_mostly = 0;
86 +EXPORT_SYMBOL_GPL(brnf_call_ebtables);
87 +
88 +bool br_netfilter_run_hooks(void)
89 +{
90 + return brnf_call_iptables | brnf_call_ip6tables | brnf_call_arptables |
91 + brnf_call_ebtables;
92 +}
93 +
94 static inline __be16 vlan_proto(const struct sk_buff *skb)
95 {
96 if (skb_vlan_tag_present(skb))
97 --- a/net/bridge/br_private.h
98 +++ b/net/bridge/br_private.h
99 @@ -773,6 +773,24 @@ static inline void br_nf_core_fini(void)
100 #define br_netfilter_rtable_init(x)
101 #endif
102
103 +#if IS_BUILTIN(CONFIG_BRIDGE_NETFILTER)
104 +extern int brnf_call_ebtables;
105 +bool br_netfilter_run_hooks(void);
106 +#else
107 +#define br_netfilter_run_hooks() false
108 +#endif
109 +
110 +static inline int
111 +BR_HOOK(uint8_t pf, unsigned int hook, struct sk_buff *skb,
112 + struct net_device *in, struct net_device *out,
113 + int (*okfn)(struct sk_buff *))
114 +{
115 + if (!br_netfilter_run_hooks())
116 + return okfn(skb);
117 +
118 + return NF_HOOK(pf, hook, skb, in, out, okfn);
119 +}
120 +
121 /* br_stp.c */
122 void br_log_state(const struct net_bridge_port *p);
123 void br_set_state(struct net_bridge_port *p, unsigned int state);
124 --- a/net/bridge/br_stp_bpdu.c
125 +++ b/net/bridge/br_stp_bpdu.c
126 @@ -54,7 +54,7 @@ static void br_send_bpdu(struct net_brid
127
128 skb_reset_mac_header(skb);
129
130 - NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
131 + BR_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
132 dev_queue_xmit);
133 }
134
135 --- a/net/bridge/netfilter/ebtables.c
136 +++ b/net/bridge/netfilter/ebtables.c
137 @@ -2414,11 +2414,19 @@ static int __init ebtables_init(void)
138 }
139
140 printk(KERN_INFO "Ebtables v2.0 registered\n");
141 +
142 +#if IS_BUILTIN(CONFIG_BRIDGE_NETFILTER)
143 + brnf_call_ebtables = 1;
144 +#endif
145 +
146 return 0;
147 }
148
149 static void __exit ebtables_fini(void)
150 {
151 +#if IS_BUILTIN(CONFIG_BRIDGE_NETFILTER)
152 + brnf_call_ebtables = 0;
153 +#endif
154 nf_unregister_sockopt(&ebt_sockopts);
155 xt_unregister_target(&ebt_standard_target);
156 printk(KERN_INFO "Ebtables v2.0 unregistered\n");
157 --- a/net/Kconfig
158 +++ b/net/Kconfig
159 @@ -177,11 +177,11 @@ config NETFILTER_ADVANCED
160 If unsure, say Y.
161
162 config BRIDGE_NETFILTER
163 - tristate "Bridged IP/ARP packets filtering"
164 + bool "Bridged IP/ARP packets filtering"
165 depends on BRIDGE
166 depends on NETFILTER && INET
167 depends on NETFILTER_ADVANCED
168 - default m
169 + default y
170 ---help---
171 Enabling this option will let arptables resp. iptables see bridged
172 ARP resp. IP traffic. If you want a bridging firewall, you probably