Skip to content

Commit a386f99

Browse files
Eric Dumazetdavem330
authored andcommitted
bridge: add proper RCU annotation to should_route_hook
Add br_should_route_hook_t typedef, this is the only way we can get a clean RCU implementation for function pointer. Move route_hook to location where it is used. Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: Stephen Hemminger <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e805168 commit a386f99

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

include/linux/if_bridge.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ struct __fdb_entry {
102102
#include <linux/netdevice.h>
103103

104104
extern void brioctl_set(int (*ioctl_hook)(struct net *, unsigned int, void __user *));
105-
extern int (*br_should_route_hook)(struct sk_buff *skb);
105+
106+
typedef int (*br_should_route_hook_t)(struct sk_buff *skb);
107+
extern br_should_route_hook_t __rcu *br_should_route_hook;
106108

107109
#endif
108110

net/bridge/br.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
#include "br_private.h"
2424

25-
int (*br_should_route_hook)(struct sk_buff *skb);
26-
2725
static const struct stp_proto br_stp_proto = {
2826
.rcv = br_stp_rcv,
2927
};
@@ -102,8 +100,6 @@ static void __exit br_deinit(void)
102100
br_fdb_fini();
103101
}
104102

105-
EXPORT_SYMBOL(br_should_route_hook);
106-
107103
module_init(br_init)
108104
module_exit(br_deinit)
109105
MODULE_LICENSE("GPL");

net/bridge/br_input.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
/* Bridge group multicast address 802.1d (pg 51). */
2222
const u8 br_group_address[ETH_ALEN] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 };
2323

24+
/* Hook for brouter */
25+
br_should_route_hook_t __rcu *br_should_route_hook __read_mostly;
26+
EXPORT_SYMBOL(br_should_route_hook);
27+
2428
static int br_pass_frame_up(struct sk_buff *skb)
2529
{
2630
struct net_device *indev, *brdev = BR_INPUT_SKB_CB(skb)->brdev;
@@ -139,7 +143,7 @@ struct sk_buff *br_handle_frame(struct sk_buff *skb)
139143
{
140144
struct net_bridge_port *p;
141145
const unsigned char *dest = eth_hdr(skb)->h_dest;
142-
int (*rhook)(struct sk_buff *skb);
146+
br_should_route_hook_t *rhook;
143147

144148
if (unlikely(skb->pkt_type == PACKET_LOOPBACK))
145149
return skb;
@@ -173,8 +177,8 @@ struct sk_buff *br_handle_frame(struct sk_buff *skb)
173177
switch (p->state) {
174178
case BR_STATE_FORWARDING:
175179
rhook = rcu_dereference(br_should_route_hook);
176-
if (rhook != NULL) {
177-
if (rhook(skb))
180+
if (rhook) {
181+
if ((*rhook)(skb))
178182
return skb;
179183
dest = eth_hdr(skb)->h_dest;
180184
}

net/bridge/netfilter/ebtable_broute.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ static int __init ebtable_broute_init(void)
8787
if (ret < 0)
8888
return ret;
8989
/* see br_input.c */
90-
rcu_assign_pointer(br_should_route_hook, ebt_broute);
90+
rcu_assign_pointer(br_should_route_hook,
91+
(br_should_route_hook_t *)ebt_broute);
9192
return 0;
9293
}
9394

0 commit comments

Comments
 (0)