kernel: refresh patches
[openwrt/staging/chunkeey.git] / target / linux / generic / patches-3.14 / 645-bridge_multicast_to_unicast.patch
1 --- a/net/bridge/br_multicast.c
2 +++ b/net/bridge/br_multicast.c
3 @@ -634,7 +634,8 @@ struct net_bridge_port_group *br_multica
4 struct net_bridge_port *port,
5 struct br_ip *group,
6 struct net_bridge_port_group __rcu *next,
7 - unsigned char state)
8 + unsigned char state,
9 + const unsigned char *src)
10 {
11 struct net_bridge_port_group *p;
12
13 @@ -649,12 +650,33 @@ struct net_bridge_port_group *br_multica
14 hlist_add_head(&p->mglist, &port->mglist);
15 setup_timer(&p->timer, br_multicast_port_group_expired,
16 (unsigned long)p);
17 + if ((port->flags & BR_MULTICAST_TO_UCAST) && src) {
18 + memcpy(p->eth_addr, src, ETH_ALEN);
19 + p->unicast = true;
20 + }
21 return p;
22 }
23
24 +static bool br_port_group_equal(struct net_bridge_port_group *p,
25 + struct net_bridge_port *port,
26 + const unsigned char *src)
27 +{
28 + if (p->port != port)
29 + return false;
30 +
31 + if (!p->unicast)
32 + return true;
33 +
34 + if (!src)
35 + return false;
36 +
37 + return ether_addr_equal(src, p->eth_addr);
38 +}
39 +
40 static int br_multicast_add_group(struct net_bridge *br,
41 struct net_bridge_port *port,
42 - struct br_ip *group)
43 + struct br_ip *group,
44 + const unsigned char *src)
45 {
46 struct net_bridge_mdb_entry *mp;
47 struct net_bridge_port_group *p;
48 @@ -681,13 +703,13 @@ static int br_multicast_add_group(struct
49 for (pp = &mp->ports;
50 (p = mlock_dereference(*pp, br)) != NULL;
51 pp = &p->next) {
52 - if (p->port == port)
53 + if (br_port_group_equal(p, port, src))
54 goto found;
55 if ((unsigned long)p->port < (unsigned long)port)
56 break;
57 }
58
59 - p = br_multicast_new_port_group(port, group, *pp, MDB_TEMPORARY);
60 + p = br_multicast_new_port_group(port, group, *pp, MDB_TEMPORARY, src);
61 if (unlikely(!p))
62 goto err;
63 rcu_assign_pointer(*pp, p);
64 @@ -706,7 +728,7 @@ err:
65 static int br_ip4_multicast_add_group(struct net_bridge *br,
66 struct net_bridge_port *port,
67 __be32 group,
68 - __u16 vid)
69 + __u16 vid, const unsigned char *src)
70 {
71 struct br_ip br_group;
72
73 @@ -717,14 +739,14 @@ static int br_ip4_multicast_add_group(st
74 br_group.proto = htons(ETH_P_IP);
75 br_group.vid = vid;
76
77 - return br_multicast_add_group(br, port, &br_group);
78 + return br_multicast_add_group(br, port, &br_group, src);
79 }
80
81 #if IS_ENABLED(CONFIG_IPV6)
82 static int br_ip6_multicast_add_group(struct net_bridge *br,
83 struct net_bridge_port *port,
84 const struct in6_addr *group,
85 - __u16 vid)
86 + __u16 vid, const unsigned char *src)
87 {
88 struct br_ip br_group;
89
90 @@ -735,7 +757,7 @@ static int br_ip6_multicast_add_group(st
91 br_group.proto = htons(ETH_P_IPV6);
92 br_group.vid = vid;
93
94 - return br_multicast_add_group(br, port, &br_group);
95 + return br_multicast_add_group(br, port, &br_group, src);
96 }
97 #endif
98
99 @@ -950,6 +972,7 @@ static int br_ip4_multicast_igmp3_report
100 struct sk_buff *skb,
101 u16 vid)
102 {
103 + const unsigned char *src = eth_hdr(skb)->h_source;
104 struct igmpv3_report *ih;
105 struct igmpv3_grec *grec;
106 int i;
107 @@ -993,7 +1016,7 @@ static int br_ip4_multicast_igmp3_report
108 continue;
109 }
110
111 - err = br_ip4_multicast_add_group(br, port, group, vid);
112 + err = br_ip4_multicast_add_group(br, port, group, vid, src);
113 if (err)
114 break;
115 }
116 @@ -1007,6 +1030,7 @@ static int br_ip6_multicast_mld2_report(
117 struct sk_buff *skb,
118 u16 vid)
119 {
120 + const unsigned char *src = eth_hdr(skb)->h_source;
121 struct icmp6hdr *icmp6h;
122 struct mld2_grec *grec;
123 int i;
124 @@ -1055,7 +1079,7 @@ static int br_ip6_multicast_mld2_report(
125 }
126
127 err = br_ip6_multicast_add_group(br, port, &grec->grec_mca,
128 - vid);
129 + vid, src);
130 if (!err)
131 break;
132 }
133 @@ -1319,7 +1343,8 @@ static void br_multicast_leave_group(str
134 struct net_bridge_port *port,
135 struct br_ip *group,
136 struct bridge_mcast_querier *querier,
137 - struct bridge_mcast_query *query)
138 + struct bridge_mcast_query *query,
139 + const unsigned char *src)
140 {
141 struct net_bridge_mdb_htable *mdb;
142 struct net_bridge_mdb_entry *mp;
143 @@ -1369,7 +1394,7 @@ static void br_multicast_leave_group(str
144 for (pp = &mp->ports;
145 (p = mlock_dereference(*pp, br)) != NULL;
146 pp = &p->next) {
147 - if (p->port != port)
148 + if (!br_port_group_equal(p, port, src))
149 continue;
150
151 rcu_assign_pointer(*pp, p->next);
152 @@ -1403,7 +1428,7 @@ static void br_multicast_leave_group(str
153 for (p = mlock_dereference(mp->ports, br);
154 p != NULL;
155 p = mlock_dereference(p->next, br)) {
156 - if (p->port != port)
157 + if (!br_port_group_equal(p, port, src))
158 continue;
159
160 if (!hlist_unhashed(&p->mglist) &&
161 @@ -1421,8 +1446,8 @@ out:
162
163 static void br_ip4_multicast_leave_group(struct net_bridge *br,
164 struct net_bridge_port *port,
165 - __be32 group,
166 - __u16 vid)
167 + __be32 group, __u16 vid,
168 + const unsigned char *src)
169 {
170 struct br_ip br_group;
171 struct bridge_mcast_query *query = port ? &port->ip4_query :
172 @@ -1435,14 +1460,15 @@ static void br_ip4_multicast_leave_group
173 br_group.proto = htons(ETH_P_IP);
174 br_group.vid = vid;
175
176 - br_multicast_leave_group(br, port, &br_group, &br->ip4_querier, query);
177 + br_multicast_leave_group(br, port, &br_group, &br->ip4_querier, query,
178 + src);
179 }
180
181 #if IS_ENABLED(CONFIG_IPV6)
182 static void br_ip6_multicast_leave_group(struct net_bridge *br,
183 struct net_bridge_port *port,
184 const struct in6_addr *group,
185 - __u16 vid)
186 + __u16 vid, const unsigned char *src)
187 {
188 struct br_ip br_group;
189 struct bridge_mcast_query *query = port ? &port->ip6_query :
190 @@ -1456,7 +1482,8 @@ static void br_ip6_multicast_leave_group
191 br_group.proto = htons(ETH_P_IPV6);
192 br_group.vid = vid;
193
194 - br_multicast_leave_group(br, port, &br_group, &br->ip6_querier, query);
195 + br_multicast_leave_group(br, port, &br_group, &br->ip6_querier, query,
196 + src);
197 }
198 #endif
199
200 @@ -1465,6 +1492,7 @@ static int br_multicast_ipv4_rcv(struct
201 struct sk_buff *skb,
202 u16 vid)
203 {
204 + const unsigned char *src = eth_hdr(skb)->h_source;
205 struct sk_buff *skb2 = skb;
206 const struct iphdr *iph;
207 struct igmphdr *ih;
208 @@ -1538,7 +1566,7 @@ static int br_multicast_ipv4_rcv(struct
209 case IGMP_HOST_MEMBERSHIP_REPORT:
210 case IGMPV2_HOST_MEMBERSHIP_REPORT:
211 BR_INPUT_SKB_CB(skb)->mrouters_only = 1;
212 - err = br_ip4_multicast_add_group(br, port, ih->group, vid);
213 + err = br_ip4_multicast_add_group(br, port, ih->group, vid, src);
214 break;
215 case IGMPV3_HOST_MEMBERSHIP_REPORT:
216 err = br_ip4_multicast_igmp3_report(br, port, skb2, vid);
217 @@ -1547,7 +1575,7 @@ static int br_multicast_ipv4_rcv(struct
218 err = br_ip4_multicast_query(br, port, skb2, vid);
219 break;
220 case IGMP_HOST_LEAVE_MESSAGE:
221 - br_ip4_multicast_leave_group(br, port, ih->group, vid);
222 + br_ip4_multicast_leave_group(br, port, ih->group, vid, src);
223 break;
224 }
225
226 @@ -1565,6 +1593,7 @@ static int br_multicast_ipv6_rcv(struct
227 struct sk_buff *skb,
228 u16 vid)
229 {
230 + const unsigned char *src = eth_hdr(skb)->h_source;
231 struct sk_buff *skb2;
232 const struct ipv6hdr *ip6h;
233 u8 icmp6_type;
234 @@ -1674,7 +1703,8 @@ static int br_multicast_ipv6_rcv(struct
235 }
236 mld = (struct mld_msg *)skb_transport_header(skb2);
237 BR_INPUT_SKB_CB(skb)->mrouters_only = 1;
238 - err = br_ip6_multicast_add_group(br, port, &mld->mld_mca, vid);
239 + err = br_ip6_multicast_add_group(br, port, &mld->mld_mca, vid,
240 + src);
241 break;
242 }
243 case ICMPV6_MLD2_REPORT:
244 @@ -1691,7 +1721,7 @@ static int br_multicast_ipv6_rcv(struct
245 goto out;
246 }
247 mld = (struct mld_msg *)skb_transport_header(skb2);
248 - br_ip6_multicast_leave_group(br, port, &mld->mld_mca, vid);
249 + br_ip6_multicast_leave_group(br, port, &mld->mld_mca, vid, src);
250 }
251 }
252
253 --- a/net/bridge/br_private.h
254 +++ b/net/bridge/br_private.h
255 @@ -116,6 +116,9 @@ struct net_bridge_port_group {
256 struct timer_list timer;
257 struct br_ip addr;
258 unsigned char state;
259 +
260 + unsigned char eth_addr[ETH_ALEN];
261 + bool unicast;
262 };
263
264 struct net_bridge_mdb_entry
265 @@ -175,6 +178,7 @@ struct net_bridge_port
266 #define BR_LEARNING 0x00000020
267 #define BR_FLOOD 0x00000040
268 #define BR_ISOLATE_MODE 0x00000080
269 +#define BR_MULTICAST_TO_UCAST 0x00000100
270
271 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
272 struct bridge_mcast_query ip4_query;
273 @@ -471,7 +475,8 @@ void br_multicast_free_pg(struct rcu_hea
274 struct net_bridge_port_group *
275 br_multicast_new_port_group(struct net_bridge_port *port, struct br_ip *group,
276 struct net_bridge_port_group __rcu *next,
277 - unsigned char state);
278 + unsigned char state,
279 + const unsigned char *src);
280 void br_mdb_init(void);
281 void br_mdb_uninit(void);
282 void br_mdb_notify(struct net_device *dev, struct net_bridge_port *port,
283 --- a/net/bridge/br_mdb.c
284 +++ b/net/bridge/br_mdb.c
285 @@ -342,7 +342,7 @@ static int br_mdb_add_group(struct net_b
286 break;
287 }
288
289 - p = br_multicast_new_port_group(port, group, *pp, state);
290 + p = br_multicast_new_port_group(port, group, *pp, state, NULL);
291 if (unlikely(!p))
292 return -ENOMEM;
293 rcu_assign_pointer(*pp, p);
294 --- a/net/bridge/br_forward.c
295 +++ b/net/bridge/br_forward.c
296 @@ -170,6 +170,29 @@ out:
297 return p;
298 }
299
300 +static struct net_bridge_port *maybe_deliver_addr(
301 + struct net_bridge_port *prev, struct net_bridge_port *p,
302 + struct sk_buff *skb, const unsigned char *addr,
303 + void (*__packet_hook)(const struct net_bridge_port *p,
304 + struct sk_buff *skb))
305 +{
306 + struct net_device *dev = BR_INPUT_SKB_CB(skb)->brdev;
307 +
308 + if (!should_deliver(p, skb))
309 + return prev;
310 +
311 + skb = skb_copy(skb, GFP_ATOMIC);
312 + if (!skb) {
313 + dev->stats.tx_dropped++;
314 + return prev;
315 + }
316 +
317 + memcpy(eth_hdr(skb)->h_dest, addr, ETH_ALEN);
318 + __packet_hook(p, skb);
319 +
320 + return prev;
321 +}
322 +
323 /* called under bridge lock */
324 static void br_flood(struct net_bridge *br, struct sk_buff *skb,
325 struct sk_buff *skb0,
326 @@ -234,6 +257,7 @@ static void br_multicast_flood(struct ne
327 struct net_bridge_port *prev = NULL;
328 struct net_bridge_port_group *p;
329 struct hlist_node *rp;
330 + const unsigned char *addr;
331
332 rp = rcu_dereference(hlist_first_rcu(&br->router_list));
333 p = mdst ? rcu_dereference(mdst->ports) : NULL;
334 @@ -244,10 +268,19 @@ static void br_multicast_flood(struct ne
335 rport = rp ? hlist_entry(rp, struct net_bridge_port, rlist) :
336 NULL;
337
338 - port = (unsigned long)lport > (unsigned long)rport ?
339 - lport : rport;
340 -
341 - prev = maybe_deliver(prev, port, skb, __packet_hook);
342 + if ((unsigned long)lport > (unsigned long)rport) {
343 + port = lport;
344 + addr = p->unicast ? p->eth_addr : NULL;
345 + } else {
346 + port = rport;
347 + addr = NULL;
348 + }
349 +
350 + if (addr)
351 + prev = maybe_deliver_addr(prev, port, skb, addr,
352 + __packet_hook);
353 + else
354 + prev = maybe_deliver(prev, port, skb, __packet_hook);
355 if (IS_ERR(prev))
356 goto out;
357
358 --- a/net/bridge/br_sysfs_if.c
359 +++ b/net/bridge/br_sysfs_if.c
360 @@ -192,6 +192,7 @@ static BRPORT_ATTR(multicast_router, S_I
361 store_multicast_router);
362
363 BRPORT_ATTR_FLAG(multicast_fast_leave, BR_MULTICAST_FAST_LEAVE);
364 +BRPORT_ATTR_FLAG(multicast_to_unicast, BR_MULTICAST_TO_UCAST);
365 #endif
366
367 static const struct brport_attribute *brport_attrs[] = {
368 @@ -218,6 +219,7 @@ static const struct brport_attribute *br
369 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
370 &brport_attr_multicast_router,
371 &brport_attr_multicast_fast_leave,
372 + &brport_attr_multicast_to_unicast,
373 #endif
374 &brport_attr_isolate_mode,
375 NULL