kernel: optimize out remaining netfilter hooks in the bridging code if bridge filtering is disabled

SVN-Revision: 30954
This commit is contained in:
Felix Fietkau 2012-03-16 09:21:59 +00:00
parent b957208807
commit dd0f928b14
2 changed files with 161 additions and 69 deletions

View file

@ -14,7 +14,7 @@
if (vlan_tx_tag_present(skb)) if (vlan_tx_tag_present(skb))
--- a/net/bridge/br_private.h --- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h +++ b/net/bridge/br_private.h
@@ -491,10 +491,12 @@ static inline bool br_multicast_is_route @@ -491,12 +491,25 @@ static inline bool br_multicast_is_route
extern int br_netfilter_init(void); extern int br_netfilter_init(void);
extern void br_netfilter_fini(void); extern void br_netfilter_fini(void);
extern void br_netfilter_rtable_init(struct net_bridge *); extern void br_netfilter_rtable_init(struct net_bridge *);
@ -26,13 +26,6 @@
+#define br_netfilter_run_hooks() false +#define br_netfilter_run_hooks() false
#endif #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 +static inline int
+BR_HOOK(uint8_t pf, unsigned int hook, struct sk_buff *skb, +BR_HOOK(uint8_t pf, unsigned int hook, struct sk_buff *skb,
+ struct net_device *in, struct net_device *out, + struct net_device *in, struct net_device *out,
@ -44,10 +37,12 @@
+ return NF_HOOK(pf, hook, skb, in, out, okfn); + return NF_HOOK(pf, hook, skb, in, out, okfn);
+} +}
+ +
static int br_pass_frame_up(struct sk_buff *skb) /* br_stp.c */
{ extern void br_log_state(const struct net_bridge_port *p);
struct net_device *indev, *brdev = BR_INPUT_SKB_CB(skb)->brdev; extern struct net_bridge_port *br_get_port(struct net_bridge *br,
@@ -40,7 +51,7 @@ static int br_pass_frame_up(struct sk_bu --- a/net/bridge/br_input.c
+++ b/net/bridge/br_input.c
@@ -40,7 +40,7 @@ static int br_pass_frame_up(struct sk_bu
indev = skb->dev; indev = skb->dev;
skb->dev = brdev; skb->dev = brdev;
@ -56,7 +51,7 @@
netif_receive_skb); netif_receive_skb);
} }
@@ -199,7 +210,7 @@ rx_handler_result_t br_handle_frame(stru @@ -199,7 +199,7 @@ rx_handler_result_t br_handle_frame(stru
} }
/* Deliver packet to local host only */ /* Deliver packet to local host only */
@ -65,7 +60,7 @@
NULL, br_handle_local_finish)) { NULL, br_handle_local_finish)) {
return RX_HANDLER_CONSUMED; /* consumed by filter */ return RX_HANDLER_CONSUMED; /* consumed by filter */
} else { } else {
@@ -224,7 +235,7 @@ forward: @@ -224,7 +224,7 @@ forward:
if (!compare_ether_addr(p->br->dev->dev_addr, dest)) if (!compare_ether_addr(p->br->dev->dev_addr, dest))
skb->pkt_type = PACKET_HOST; skb->pkt_type = PACKET_HOST;
@ -74,3 +69,54 @@
br_handle_frame_finish); br_handle_frame_finish);
break; break;
default: default:
--- a/net/bridge/br_forward.c
+++ b/net/bridge/br_forward.c
@@ -55,7 +55,7 @@ int br_dev_queue_push_xmit(struct sk_buf
int br_forward_finish(struct sk_buff *skb)
{
- return NF_HOOK(NFPROTO_BRIDGE, NF_BR_POST_ROUTING, skb, NULL, skb->dev,
+ return BR_HOOK(NFPROTO_BRIDGE, NF_BR_POST_ROUTING, skb, NULL, skb->dev,
br_dev_queue_push_xmit);
}
@@ -74,7 +74,7 @@ static void __br_deliver(const struct ne
return;
}
- NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
+ BR_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
br_forward_finish);
}
@@ -91,7 +91,7 @@ static void __br_forward(const struct ne
skb->dev = to->dev;
skb_forward_csum(skb);
- NF_HOOK(NFPROTO_BRIDGE, NF_BR_FORWARD, skb, indev, skb->dev,
+ BR_HOOK(NFPROTO_BRIDGE, NF_BR_FORWARD, skb, indev, skb->dev,
br_forward_finish);
}
--- a/net/bridge/br_multicast.c
+++ b/net/bridge/br_multicast.c
@@ -824,7 +824,7 @@ static void __br_multicast_send_query(st
if (port) {
__skb_push(skb, sizeof(struct ethhdr));
skb->dev = port->dev;
- NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
+ BR_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
dev_queue_xmit);
} else
netif_rx(skb);
--- a/net/bridge/br_stp_bpdu.c
+++ b/net/bridge/br_stp_bpdu.c
@@ -52,7 +52,7 @@ static void br_send_bpdu(struct net_brid
skb_reset_mac_header(skb);
- NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
+ BR_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
dev_queue_xmit);
}

View file

@ -1,8 +1,59 @@
--- a/net/bridge/br_input.c --- a/net/bridge/br_input.c
+++ b/net/bridge/br_input.c +++ b/net/bridge/br_input.c
@@ -26,6 +26,17 @@ const u8 br_group_address[ETH_ALEN] = { @@ -40,7 +40,7 @@ static int br_pass_frame_up(struct sk_bu
br_should_route_hook_t __rcu *br_should_route_hook __read_mostly; indev = skb->dev;
EXPORT_SYMBOL(br_should_route_hook); 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 +194,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 +219,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
@@ -71,6 +71,11 @@ static int brnf_filter_pppoe_tagged __re
#define IS_ARP(skb) \
(!vlan_tx_tag_present(skb) && skb->protocol == htons(ETH_P_ARP))
+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,12 +492,25 @@ 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
+static inline int +static inline int
+BR_HOOK(uint8_t pf, unsigned int hook, struct sk_buff *skb, +BR_HOOK(uint8_t pf, unsigned int hook, struct sk_buff *skb,
@ -15,62 +66,57 @@
+ return NF_HOOK(pf, hook, skb, in, out, okfn); + return NF_HOOK(pf, hook, skb, in, out, okfn);
+} +}
+ +
static int br_pass_frame_up(struct sk_buff *skb) /* br_stp.c */
{ extern void br_log_state(const struct net_bridge_port *p);
struct net_device *indev, *brdev = BR_INPUT_SKB_CB(skb)->brdev; extern struct net_bridge_port *br_get_port(struct net_bridge *br,
@@ -40,7 +51,7 @@ static int br_pass_frame_up(struct sk_bu --- a/net/bridge/br_forward.c
indev = skb->dev; +++ b/net/bridge/br_forward.c
skb->dev = brdev; @@ -55,7 +55,7 @@ int br_dev_queue_push_xmit(struct sk_buf
- return NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, skb, indev, NULL, int br_forward_finish(struct sk_buff *skb)
+ return BR_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, skb, indev, NULL, {
netif_receive_skb); - return NF_HOOK(NFPROTO_BRIDGE, NF_BR_POST_ROUTING, skb, NULL, skb->dev,
+ return BR_HOOK(NFPROTO_BRIDGE, NF_BR_POST_ROUTING, skb, NULL, skb->dev,
br_dev_queue_push_xmit);
}
@@ -74,7 +74,7 @@ static void __br_deliver(const struct ne
return;
}
- NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
+ BR_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
br_forward_finish);
} }
@@ -194,7 +205,7 @@ rx_handler_result_t br_handle_frame(stru @@ -91,7 +91,7 @@ static void __br_forward(const struct ne
} skb->dev = to->dev;
skb_forward_csum(skb);
/* Deliver packet to local host only */ - NF_HOOK(NFPROTO_BRIDGE, NF_BR_FORWARD, skb, indev, skb->dev,
- if (NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, skb, skb->dev, + BR_HOOK(NFPROTO_BRIDGE, NF_BR_FORWARD, skb, indev, skb->dev,
+ if (BR_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, skb, skb->dev, br_forward_finish);
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, --- a/net/bridge/br_multicast.c
+ BR_HOOK(NFPROTO_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL, +++ b/net/bridge/br_multicast.c
br_handle_frame_finish); @@ -827,7 +827,7 @@ static void __br_multicast_send_query(st
break; if (port) {
default: __skb_push(skb, sizeof(struct ethhdr));
--- a/net/bridge/br_netfilter.c skb->dev = port->dev;
+++ b/net/bridge/br_netfilter.c - NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
@@ -62,6 +62,11 @@ static int brnf_filter_pppoe_tagged __re + BR_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
#define brnf_filter_pppoe_tagged 0 dev_queue_xmit);
#endif } else
netif_rx(skb);
--- a/net/bridge/br_stp_bpdu.c
+++ b/net/bridge/br_stp_bpdu.c
@@ -52,7 +52,7 @@ static void br_send_bpdu(struct net_brid
+bool br_netfilter_run_hooks(void) skb_reset_mac_header(skb);
+{
+ return brnf_call_iptables | brnf_call_ip6tables | brnf_call_arptables; - NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
+} + BR_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
+ dev_queue_xmit);
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 */