af793ee83033eb62726facc3f6c4c2521d0d026a
[openwrt/svn-archive/archive.git] / target / linux / generic / patches-3.3 / 644-bridge_optimize_netfilter_hooks.patch
1 --- a/net/bridge/br_input.c
2 +++ b/net/bridge/br_input.c
3 @@ -40,7 +40,7 @@ static int br_pass_frame_up(struct sk_bu
4 indev = skb->dev;
5 skb->dev = brdev;
6
7 - return NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, skb, indev, NULL,
8 + return BR_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, skb, indev, NULL,
9 netif_receive_skb);
10 }
11
12 @@ -194,7 +194,7 @@ rx_handler_result_t br_handle_frame(stru
13 }
14
15 /* Deliver packet to local host only */
16 - if (NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, skb, skb->dev,
17 + if (BR_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, skb, skb->dev,
18 NULL, br_handle_local_finish)) {
19 return RX_HANDLER_CONSUMED; /* consumed by filter */
20 } else {
21 @@ -219,7 +219,7 @@ forward:
22 if (!compare_ether_addr(p->br->dev->dev_addr, dest))
23 skb->pkt_type = PACKET_HOST;
24
25 - NF_HOOK(NFPROTO_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
26 + BR_HOOK(NFPROTO_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
27 br_handle_frame_finish);
28 break;
29 default:
30 --- a/net/bridge/br_netfilter.c
31 +++ b/net/bridge/br_netfilter.c
32 @@ -71,6 +71,11 @@ static int brnf_filter_pppoe_tagged __re
33 #define IS_ARP(skb) \
34 (!vlan_tx_tag_present(skb) && skb->protocol == htons(ETH_P_ARP))
35
36 +bool br_netfilter_run_hooks(void)
37 +{
38 + return brnf_call_iptables | brnf_call_ip6tables | brnf_call_arptables;
39 +}
40 +
41 static inline __be16 vlan_proto(const struct sk_buff *skb)
42 {
43 if (vlan_tx_tag_present(skb))
44 --- a/net/bridge/br_private.h
45 +++ b/net/bridge/br_private.h
46 @@ -492,12 +492,25 @@ static inline bool br_multicast_is_route
47 extern int br_netfilter_init(void);
48 extern void br_netfilter_fini(void);
49 extern void br_netfilter_rtable_init(struct net_bridge *);
50 +extern bool br_netfilter_run_hooks(void);
51 #else
52 #define br_netfilter_init() (0)
53 #define br_netfilter_fini() do { } while(0)
54 #define br_netfilter_rtable_init(x)
55 +#define br_netfilter_run_hooks() false
56 #endif
57
58 +static inline int
59 +BR_HOOK(uint8_t pf, unsigned int hook, struct sk_buff *skb,
60 + struct net_device *in, struct net_device *out,
61 + int (*okfn)(struct sk_buff *))
62 +{
63 + if (!br_netfilter_run_hooks())
64 + return okfn(skb);
65 +
66 + return NF_HOOK(pf, hook, skb, in, out, okfn);
67 +}
68 +
69 /* br_stp.c */
70 extern void br_log_state(const struct net_bridge_port *p);
71 extern struct net_bridge_port *br_get_port(struct net_bridge *br,
72 --- a/net/bridge/br_forward.c
73 +++ b/net/bridge/br_forward.c
74 @@ -55,7 +55,7 @@ int br_dev_queue_push_xmit(struct sk_buf
75
76 int br_forward_finish(struct sk_buff *skb)
77 {
78 - return NF_HOOK(NFPROTO_BRIDGE, NF_BR_POST_ROUTING, skb, NULL, skb->dev,
79 + return BR_HOOK(NFPROTO_BRIDGE, NF_BR_POST_ROUTING, skb, NULL, skb->dev,
80 br_dev_queue_push_xmit);
81
82 }
83 @@ -74,7 +74,7 @@ static void __br_deliver(const struct ne
84 return;
85 }
86
87 - NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
88 + BR_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
89 br_forward_finish);
90 }
91
92 @@ -91,7 +91,7 @@ static void __br_forward(const struct ne
93 skb->dev = to->dev;
94 skb_forward_csum(skb);
95
96 - NF_HOOK(NFPROTO_BRIDGE, NF_BR_FORWARD, skb, indev, skb->dev,
97 + BR_HOOK(NFPROTO_BRIDGE, NF_BR_FORWARD, skb, indev, skb->dev,
98 br_forward_finish);
99 }
100
101 --- a/net/bridge/br_multicast.c
102 +++ b/net/bridge/br_multicast.c
103 @@ -827,7 +827,7 @@ static void __br_multicast_send_query(st
104 if (port) {
105 __skb_push(skb, sizeof(struct ethhdr));
106 skb->dev = port->dev;
107 - NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
108 + BR_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
109 dev_queue_xmit);
110 } else
111 netif_rx(skb);
112 --- a/net/bridge/br_stp_bpdu.c
113 +++ b/net/bridge/br_stp_bpdu.c
114 @@ -52,7 +52,7 @@ static void br_send_bpdu(struct net_brid
115
116 skb_reset_mac_header(skb);
117
118 - NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
119 + BR_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
120 dev_queue_xmit);
121 }
122