4388cda6efefa03baca8a96c97bd9b5b6bddb8e2
[openwrt/staging/thess.git] /
1 From: daniel <daniel@dd-wrt.com>
2 Date: Fri, 24 Jun 2016 12:35:18 +0200
3 Subject: [PATCH] Bridge: Fix ipv6 mc snooping if bridge has no ipv6 address
4
5 The bridge is falsly dropping ipv6 mulitcast packets if there is:
6 1. No ipv6 address assigned on the brigde.
7 2. No external mld querier present.
8 3. The internal querier enabled.
9
10 When the bridge fails to build mld queries, because it has no
11 ipv6 address, it slilently returns, but keeps the local querier enabled.
12 This specific case causes confusing packet loss.
13
14 Ipv6 multicast snooping can only work if:
15 a) An external querier is present
16 OR
17 b) The bridge has an ipv6 address an is capable of sending own queries
18
19 Otherwise it has to forward/flood the ipv6 multicast traffic,
20 because snooping cannot work.
21
22 This patch fixes the issue by adding a flag to the bridge struct that
23 indicates that there is currently no ipv6 address assinged to the bridge
24 and returns a false state for the local querier in
25 __br_multicast_querier_exists().
26
27 Special thanks to Linus Lüssing.
28
29 Fixes: d1d81d4c3dd8 ("bridge: check return value of ipv6_dev_get_saddr()")
30 Signed-off-by: Daniel Danzberger <daniel@dd-wrt.com>
31 Acked-by: Linus Lüssing <linus.luessing@c0d3.blue>
32 Signed-off-by: David S. Miller <davem@davemloft.net>
33 ---
34 net/bridge/br_multicast.c | 4 ++++
35 net/bridge/br_private.h | 23 +++++++++++++++++++----
36 2 files changed, 23 insertions(+), 4 deletions(-)
37
38 diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
39 index c8c2a8a..d063a10 100644
40 --- a/net/bridge/br_multicast.c
41 +++ b/net/bridge/br_multicast.c
42 @@ -465,8 +465,11 @@ static struct sk_buff *br_ip6_multicast_alloc_query(struct net_bridge *br,
43 if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
44 &ip6h->saddr)) {
45 kfree_skb(skb);
46 + br->has_ipv6_addr = 0;
47 return NULL;
48 }
49 +
50 + br->has_ipv6_addr = 1;
51 ipv6_eth_mc_map(&ip6h->daddr, eth->h_dest);
52
53 hopopt = (u8 *)(ip6h + 1);
54 @@ -1768,6 +1771,7 @@ void br_multicast_init(struct net_bridge *br)
55 br->ip6_other_query.delay_time = 0;
56 br->ip6_querier.port = NULL;
57 #endif
58 + br->has_ipv6_addr = 1;
59
60 spin_lock_init(&br->multicast_lock);
61 setup_timer(&br->multicast_router_timer,
62 diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
63 index e24abfd..3dd7e2c 100644
64 --- a/net/bridge/br_private.h
65 +++ b/net/bridge/br_private.h
66 @@ -303,6 +303,7 @@ struct net_bridge
67 u8 multicast_disabled:1;
68 u8 multicast_querier:1;
69 u8 multicast_query_use_ifaddr:1;
70 + u8 has_ipv6_addr:1;
71
72 u32 hash_elasticity;
73 u32 hash_max;
74 @@ -577,10 +578,22 @@ static inline bool br_multicast_is_router(struct net_bridge *br)
75
76 static inline bool
77 __br_multicast_querier_exists(struct net_bridge *br,
78 - struct bridge_mcast_other_query *querier)
79 + struct bridge_mcast_other_query *querier,
80 + const bool is_ipv6)
81 {
82 + bool own_querier_enabled;
83 +
84 + if (br->multicast_querier) {
85 + if (is_ipv6 && !br->has_ipv6_addr)
86 + own_querier_enabled = false;
87 + else
88 + own_querier_enabled = true;
89 + } else {
90 + own_querier_enabled = false;
91 + }
92 +
93 return time_is_before_jiffies(querier->delay_time) &&
94 - (br->multicast_querier || timer_pending(&querier->timer));
95 + (own_querier_enabled || timer_pending(&querier->timer));
96 }
97
98 static inline bool br_multicast_querier_exists(struct net_bridge *br,
99 @@ -588,10 +601,12 @@ static inline bool br_multicast_querier_exists(struct net_bridge *br,
100 {
101 switch (eth->h_proto) {
102 case (htons(ETH_P_IP)):
103 - return __br_multicast_querier_exists(br, &br->ip4_other_query);
104 + return __br_multicast_querier_exists(br,
105 + &br->ip4_other_query, false);
106 #if IS_ENABLED(CONFIG_IPV6)
107 case (htons(ETH_P_IPV6)):
108 - return __br_multicast_querier_exists(br, &br->ip6_other_query);
109 + return __br_multicast_querier_exists(br,
110 + &br->ip6_other_query, true);
111 #endif
112 default:
113 return false;