summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornbd <nbd@3c298f89-4303-0410-b956-a3cf2f4a3e73>2012-03-13 10:06:45 +0000
committernbd <nbd@3c298f89-4303-0410-b956-a3cf2f4a3e73>2012-03-13 10:06:45 +0000
commitbaf14aebfcb583991d51e44eaec31ecb92b60f0d (patch)
treeeccb8639dbaddd16bee4c4f17fa4f119fde34a26
parent4a8df0b66129c74d15b4ff99eb5b5b2b40aff56d (diff)
kernel: bypass all netfilter hooks if the sysctls for that functionality have been disabled - eliminates the overhead of enabling CONFIG_BRIDGE_NETFILTER in the kernel config
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@30917 3c298f89-4303-0410-b956-a3cf2f4a3e73
-rw-r--r--target/linux/generic/patches-3.2/644-bridge_optimize_netfilter_hooks.patch76
-rw-r--r--target/linux/generic/patches-3.3/644-bridge_optimize_netfilter_hooks.patch76
2 files changed, 152 insertions, 0 deletions
diff --git a/target/linux/generic/patches-3.2/644-bridge_optimize_netfilter_hooks.patch b/target/linux/generic/patches-3.2/644-bridge_optimize_netfilter_hooks.patch
new file mode 100644
index 000000000..835d18dca
--- /dev/null
+++ b/target/linux/generic/patches-3.2/644-bridge_optimize_netfilter_hooks.patch
@@ -0,0 +1,76 @@
+--- a/net/bridge/br_netfilter.c
++++ b/net/bridge/br_netfilter.c
+@@ -62,6 +62,11 @@ static int brnf_filter_pppoe_tagged __re
+ #define brnf_filter_pppoe_tagged 0
+ #endif
+
++bool br_netfilter_run_hooks(void)
++{
++ return brnf_call_iptables | brnf_call_ip6tables | brnf_call_arptables;
++}
++
+ static inline __be16 vlan_proto(const struct sk_buff *skb)
+ {
+ if (vlan_tx_tag_present(skb))
+--- a/net/bridge/br_private.h
++++ b/net/bridge/br_private.h
+@@ -491,10 +491,12 @@ static inline bool br_multicast_is_route
+ extern int br_netfilter_init(void);
+ extern void br_netfilter_fini(void);
+ extern void br_netfilter_rtable_init(struct net_bridge *);
++extern bool br_netfilter_run_hooks(void);
+ #else
+ #define br_netfilter_init() (0)
+ #define br_netfilter_fini() do { } while(0)
+ #define br_netfilter_rtable_init(x)
++#define br_netfilter_run_hooks() false
+ #endif
+
+ /* br_stp.c */
+--- a/net/bridge/br_input.c
++++ b/net/bridge/br_input.c
+@@ -26,6 +26,17 @@ const u8 br_group_address[ETH_ALEN] = {
+ br_should_route_hook_t __rcu *br_should_route_hook __read_mostly;
+ EXPORT_SYMBOL(br_should_route_hook);
+
++static inline int
++BR_HOOK(uint8_t pf, unsigned int hook, struct sk_buff *skb,
++ struct net_device *in, struct net_device *out,
++ int (*okfn)(struct sk_buff *))
++{
++ if (!br_netfilter_run_hooks())
++ return okfn(skb);
++
++ return NF_HOOK(pf, hook, skb, in, out, okfn);
++}
++
+ static int br_pass_frame_up(struct sk_buff *skb)
+ {
+ struct net_device *indev, *brdev = BR_INPUT_SKB_CB(skb)->brdev;
+@@ -40,7 +51,7 @@ static int br_pass_frame_up(struct sk_bu
+ indev = skb->dev;
+ skb->dev = brdev;
+
+- return NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, skb, indev, NULL,
++ return BR_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, skb, indev, NULL,
+ netif_receive_skb);
+ }
+
+@@ -199,7 +210,7 @@ rx_handler_result_t br_handle_frame(stru
+ }
+
+ /* Deliver packet to local host only */
+- if (NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, skb, skb->dev,
++ if (BR_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, skb, skb->dev,
+ NULL, br_handle_local_finish)) {
+ return RX_HANDLER_CONSUMED; /* consumed by filter */
+ } else {
+@@ -224,7 +235,7 @@ forward:
+ if (!compare_ether_addr(p->br->dev->dev_addr, dest))
+ skb->pkt_type = PACKET_HOST;
+
+- NF_HOOK(NFPROTO_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
++ BR_HOOK(NFPROTO_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
+ br_handle_frame_finish);
+ break;
+ default:
diff --git a/target/linux/generic/patches-3.3/644-bridge_optimize_netfilter_hooks.patch b/target/linux/generic/patches-3.3/644-bridge_optimize_netfilter_hooks.patch
new file mode 100644
index 000000000..c2c38271d
--- /dev/null
+++ b/target/linux/generic/patches-3.3/644-bridge_optimize_netfilter_hooks.patch
@@ -0,0 +1,76 @@
+--- a/net/bridge/br_input.c
++++ b/net/bridge/br_input.c
+@@ -26,6 +26,17 @@ const u8 br_group_address[ETH_ALEN] = {
+ br_should_route_hook_t __rcu *br_should_route_hook __read_mostly;
+ EXPORT_SYMBOL(br_should_route_hook);
+
++static inline int
++BR_HOOK(uint8_t pf, unsigned int hook, struct sk_buff *skb,
++ struct net_device *in, struct net_device *out,
++ int (*okfn)(struct sk_buff *))
++{
++ if (!br_netfilter_run_hooks())
++ return okfn(skb);
++
++ return NF_HOOK(pf, hook, skb, in, out, okfn);
++}
++
+ static int br_pass_frame_up(struct sk_buff *skb)
+ {
+ struct net_device *indev, *brdev = BR_INPUT_SKB_CB(skb)->brdev;
+@@ -40,7 +51,7 @@ static int br_pass_frame_up(struct sk_bu
+ indev = skb->dev;
+ skb->dev = brdev;
+
+- return NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, skb, indev, NULL,
++ return BR_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, skb, indev, NULL,
+ netif_receive_skb);
+ }
+
+@@ -194,7 +205,7 @@ rx_handler_result_t br_handle_frame(stru
+ }
+
+ /* Deliver packet to local host only */
+- if (NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, skb, skb->dev,
++ if (BR_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, skb, skb->dev,
+ NULL, br_handle_local_finish)) {
+ return RX_HANDLER_CONSUMED; /* consumed by filter */
+ } else {
+@@ -219,7 +230,7 @@ forward:
+ if (!compare_ether_addr(p->br->dev->dev_addr, dest))
+ skb->pkt_type = PACKET_HOST;
+
+- NF_HOOK(NFPROTO_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
++ BR_HOOK(NFPROTO_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
+ br_handle_frame_finish);
+ break;
+ default:
+--- a/net/bridge/br_netfilter.c
++++ b/net/bridge/br_netfilter.c
+@@ -62,6 +62,11 @@ static int brnf_filter_pppoe_tagged __re
+ #define brnf_filter_pppoe_tagged 0
+ #endif
+
++bool br_netfilter_run_hooks(void)
++{
++ return brnf_call_iptables | brnf_call_ip6tables | brnf_call_arptables;
++}
++
+ static inline __be16 vlan_proto(const struct sk_buff *skb)
+ {
+ if (vlan_tx_tag_present(skb))
+--- a/net/bridge/br_private.h
++++ b/net/bridge/br_private.h
+@@ -492,10 +492,12 @@ static inline bool br_multicast_is_route
+ extern int br_netfilter_init(void);
+ extern void br_netfilter_fini(void);
+ extern void br_netfilter_rtable_init(struct net_bridge *);
++extern bool br_netfilter_run_hooks(void);
+ #else
+ #define br_netfilter_init() (0)
+ #define br_netfilter_fini() do { } while(0)
+ #define br_netfilter_rtable_init(x)
++#define br_netfilter_run_hooks() false
+ #endif
+
+ /* br_stp.c */