diff options
Diffstat (limited to 'net/bridge/br_multicast.c')
-rw-r--r-- | net/bridge/br_multicast.c | 619 |
1 files changed, 563 insertions, 56 deletions
diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c index 81bfdfe14ce5..38d1fbde5fb8 100644 --- a/net/bridge/br_multicast.c +++ b/net/bridge/br_multicast.c | |||
@@ -24,51 +24,138 @@ | |||
24 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
25 | #include <linux/timer.h> | 25 | #include <linux/timer.h> |
26 | #include <net/ip.h> | 26 | #include <net/ip.h> |
27 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
28 | #include <net/ipv6.h> | ||
29 | #include <net/mld.h> | ||
30 | #include <net/addrconf.h> | ||
31 | #endif | ||
27 | 32 | ||
28 | #include "br_private.h" | 33 | #include "br_private.h" |
29 | 34 | ||
30 | static inline int br_ip_hash(struct net_bridge_mdb_htable *mdb, __be32 ip) | 35 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
36 | static inline int ipv6_is_local_multicast(const struct in6_addr *addr) | ||
37 | { | ||
38 | if (ipv6_addr_is_multicast(addr) && | ||
39 | IPV6_ADDR_MC_SCOPE(addr) <= IPV6_ADDR_SCOPE_LINKLOCAL) | ||
40 | return 1; | ||
41 | return 0; | ||
42 | } | ||
43 | #endif | ||
44 | |||
45 | static inline int br_ip_equal(const struct br_ip *a, const struct br_ip *b) | ||
46 | { | ||
47 | if (a->proto != b->proto) | ||
48 | return 0; | ||
49 | switch (a->proto) { | ||
50 | case htons(ETH_P_IP): | ||
51 | return a->u.ip4 == b->u.ip4; | ||
52 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
53 | case htons(ETH_P_IPV6): | ||
54 | return ipv6_addr_equal(&a->u.ip6, &b->u.ip6); | ||
55 | #endif | ||
56 | } | ||
57 | return 0; | ||
58 | } | ||
59 | |||
60 | static inline int __br_ip4_hash(struct net_bridge_mdb_htable *mdb, __be32 ip) | ||
31 | { | 61 | { |
32 | return jhash_1word(mdb->secret, (__force u32)ip) & (mdb->max - 1); | 62 | return jhash_1word(mdb->secret, (__force u32)ip) & (mdb->max - 1); |
33 | } | 63 | } |
34 | 64 | ||
65 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
66 | static inline int __br_ip6_hash(struct net_bridge_mdb_htable *mdb, | ||
67 | const struct in6_addr *ip) | ||
68 | { | ||
69 | return jhash2((__force u32 *)ip->s6_addr32, 4, mdb->secret) & (mdb->max - 1); | ||
70 | } | ||
71 | #endif | ||
72 | |||
73 | static inline int br_ip_hash(struct net_bridge_mdb_htable *mdb, | ||
74 | struct br_ip *ip) | ||
75 | { | ||
76 | switch (ip->proto) { | ||
77 | case htons(ETH_P_IP): | ||
78 | return __br_ip4_hash(mdb, ip->u.ip4); | ||
79 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
80 | case htons(ETH_P_IPV6): | ||
81 | return __br_ip6_hash(mdb, &ip->u.ip6); | ||
82 | #endif | ||
83 | } | ||
84 | return 0; | ||
85 | } | ||
86 | |||
35 | static struct net_bridge_mdb_entry *__br_mdb_ip_get( | 87 | static struct net_bridge_mdb_entry *__br_mdb_ip_get( |
36 | struct net_bridge_mdb_htable *mdb, __be32 dst, int hash) | 88 | struct net_bridge_mdb_htable *mdb, struct br_ip *dst, int hash) |
37 | { | 89 | { |
38 | struct net_bridge_mdb_entry *mp; | 90 | struct net_bridge_mdb_entry *mp; |
39 | struct hlist_node *p; | 91 | struct hlist_node *p; |
40 | 92 | ||
41 | hlist_for_each_entry_rcu(mp, p, &mdb->mhash[hash], hlist[mdb->ver]) { | 93 | hlist_for_each_entry_rcu(mp, p, &mdb->mhash[hash], hlist[mdb->ver]) { |
42 | if (dst == mp->addr) | 94 | if (br_ip_equal(&mp->addr, dst)) |
43 | return mp; | 95 | return mp; |
44 | } | 96 | } |
45 | 97 | ||
46 | return NULL; | 98 | return NULL; |
47 | } | 99 | } |
48 | 100 | ||
49 | static struct net_bridge_mdb_entry *br_mdb_ip_get( | 101 | static struct net_bridge_mdb_entry *br_mdb_ip4_get( |
50 | struct net_bridge_mdb_htable *mdb, __be32 dst) | 102 | struct net_bridge_mdb_htable *mdb, __be32 dst) |
51 | { | 103 | { |
52 | if (!mdb) | 104 | struct br_ip br_dst; |
53 | return NULL; | 105 | |
106 | br_dst.u.ip4 = dst; | ||
107 | br_dst.proto = htons(ETH_P_IP); | ||
108 | |||
109 | return __br_mdb_ip_get(mdb, &br_dst, __br_ip4_hash(mdb, dst)); | ||
110 | } | ||
111 | |||
112 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
113 | static struct net_bridge_mdb_entry *br_mdb_ip6_get( | ||
114 | struct net_bridge_mdb_htable *mdb, const struct in6_addr *dst) | ||
115 | { | ||
116 | struct br_ip br_dst; | ||
117 | |||
118 | ipv6_addr_copy(&br_dst.u.ip6, dst); | ||
119 | br_dst.proto = htons(ETH_P_IPV6); | ||
54 | 120 | ||
121 | return __br_mdb_ip_get(mdb, &br_dst, __br_ip6_hash(mdb, dst)); | ||
122 | } | ||
123 | #endif | ||
124 | |||
125 | static struct net_bridge_mdb_entry *br_mdb_ip_get( | ||
126 | struct net_bridge_mdb_htable *mdb, struct br_ip *dst) | ||
127 | { | ||
55 | return __br_mdb_ip_get(mdb, dst, br_ip_hash(mdb, dst)); | 128 | return __br_mdb_ip_get(mdb, dst, br_ip_hash(mdb, dst)); |
56 | } | 129 | } |
57 | 130 | ||
58 | struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br, | 131 | struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br, |
59 | struct sk_buff *skb) | 132 | struct sk_buff *skb) |
60 | { | 133 | { |
61 | if (br->multicast_disabled) | 134 | struct net_bridge_mdb_htable *mdb = br->mdb; |
135 | struct br_ip ip; | ||
136 | |||
137 | if (!mdb || br->multicast_disabled) | ||
62 | return NULL; | 138 | return NULL; |
63 | 139 | ||
140 | if (BR_INPUT_SKB_CB(skb)->igmp) | ||
141 | return NULL; | ||
142 | |||
143 | ip.proto = skb->protocol; | ||
144 | |||
64 | switch (skb->protocol) { | 145 | switch (skb->protocol) { |
65 | case htons(ETH_P_IP): | 146 | case htons(ETH_P_IP): |
66 | if (BR_INPUT_SKB_CB(skb)->igmp) | 147 | ip.u.ip4 = ip_hdr(skb)->daddr; |
67 | break; | 148 | break; |
68 | return br_mdb_ip_get(br->mdb, ip_hdr(skb)->daddr); | 149 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
150 | case htons(ETH_P_IPV6): | ||
151 | ipv6_addr_copy(&ip.u.ip6, &ipv6_hdr(skb)->daddr); | ||
152 | break; | ||
153 | #endif | ||
154 | default: | ||
155 | return NULL; | ||
69 | } | 156 | } |
70 | 157 | ||
71 | return NULL; | 158 | return br_mdb_ip_get(mdb, &ip); |
72 | } | 159 | } |
73 | 160 | ||
74 | static void br_mdb_free(struct rcu_head *head) | 161 | static void br_mdb_free(struct rcu_head *head) |
@@ -95,7 +182,7 @@ static int br_mdb_copy(struct net_bridge_mdb_htable *new, | |||
95 | for (i = 0; i < old->max; i++) | 182 | for (i = 0; i < old->max; i++) |
96 | hlist_for_each_entry(mp, p, &old->mhash[i], hlist[old->ver]) | 183 | hlist_for_each_entry(mp, p, &old->mhash[i], hlist[old->ver]) |
97 | hlist_add_head(&mp->hlist[new->ver], | 184 | hlist_add_head(&mp->hlist[new->ver], |
98 | &new->mhash[br_ip_hash(new, mp->addr)]); | 185 | &new->mhash[br_ip_hash(new, &mp->addr)]); |
99 | 186 | ||
100 | if (!elasticity) | 187 | if (!elasticity) |
101 | return 0; | 188 | return 0; |
@@ -163,7 +250,7 @@ static void br_multicast_del_pg(struct net_bridge *br, | |||
163 | struct net_bridge_port_group *p; | 250 | struct net_bridge_port_group *p; |
164 | struct net_bridge_port_group **pp; | 251 | struct net_bridge_port_group **pp; |
165 | 252 | ||
166 | mp = br_mdb_ip_get(mdb, pg->addr); | 253 | mp = br_mdb_ip_get(mdb, &pg->addr); |
167 | if (WARN_ON(!mp)) | 254 | if (WARN_ON(!mp)) |
168 | return; | 255 | return; |
169 | 256 | ||
@@ -249,8 +336,8 @@ out: | |||
249 | return 0; | 336 | return 0; |
250 | } | 337 | } |
251 | 338 | ||
252 | static struct sk_buff *br_multicast_alloc_query(struct net_bridge *br, | 339 | static struct sk_buff *br_ip4_multicast_alloc_query(struct net_bridge *br, |
253 | __be32 group) | 340 | __be32 group) |
254 | { | 341 | { |
255 | struct sk_buff *skb; | 342 | struct sk_buff *skb; |
256 | struct igmphdr *ih; | 343 | struct igmphdr *ih; |
@@ -314,12 +401,104 @@ out: | |||
314 | return skb; | 401 | return skb; |
315 | } | 402 | } |
316 | 403 | ||
404 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
405 | static struct sk_buff *br_ip6_multicast_alloc_query(struct net_bridge *br, | ||
406 | struct in6_addr *group) | ||
407 | { | ||
408 | struct sk_buff *skb; | ||
409 | struct ipv6hdr *ip6h; | ||
410 | struct mld_msg *mldq; | ||
411 | struct ethhdr *eth; | ||
412 | u8 *hopopt; | ||
413 | unsigned long interval; | ||
414 | |||
415 | skb = netdev_alloc_skb_ip_align(br->dev, sizeof(*eth) + sizeof(*ip6h) + | ||
416 | 8 + sizeof(*mldq)); | ||
417 | if (!skb) | ||
418 | goto out; | ||
419 | |||
420 | skb->protocol = htons(ETH_P_IPV6); | ||
421 | |||
422 | /* Ethernet header */ | ||
423 | skb_reset_mac_header(skb); | ||
424 | eth = eth_hdr(skb); | ||
425 | |||
426 | memcpy(eth->h_source, br->dev->dev_addr, 6); | ||
427 | ipv6_eth_mc_map(group, eth->h_dest); | ||
428 | eth->h_proto = htons(ETH_P_IPV6); | ||
429 | skb_put(skb, sizeof(*eth)); | ||
430 | |||
431 | /* IPv6 header + HbH option */ | ||
432 | skb_set_network_header(skb, skb->len); | ||
433 | ip6h = ipv6_hdr(skb); | ||
434 | |||
435 | *(__force __be32 *)ip6h = htonl(0x60000000); | ||
436 | ip6h->payload_len = 8 + sizeof(*mldq); | ||
437 | ip6h->nexthdr = IPPROTO_HOPOPTS; | ||
438 | ip6h->hop_limit = 1; | ||
439 | ipv6_addr_set(&ip6h->saddr, 0, 0, 0, 0); | ||
440 | ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1)); | ||
441 | |||
442 | hopopt = (u8 *)(ip6h + 1); | ||
443 | hopopt[0] = IPPROTO_ICMPV6; /* next hdr */ | ||
444 | hopopt[1] = 0; /* length of HbH */ | ||
445 | hopopt[2] = IPV6_TLV_ROUTERALERT; /* Router Alert */ | ||
446 | hopopt[3] = 2; /* Length of RA Option */ | ||
447 | hopopt[4] = 0; /* Type = 0x0000 (MLD) */ | ||
448 | hopopt[5] = 0; | ||
449 | hopopt[6] = IPV6_TLV_PAD0; /* Pad0 */ | ||
450 | hopopt[7] = IPV6_TLV_PAD0; /* Pad0 */ | ||
451 | |||
452 | skb_put(skb, sizeof(*ip6h) + 8); | ||
453 | |||
454 | /* ICMPv6 */ | ||
455 | skb_set_transport_header(skb, skb->len); | ||
456 | mldq = (struct mld_msg *) icmp6_hdr(skb); | ||
457 | |||
458 | interval = ipv6_addr_any(group) ? br->multicast_last_member_interval : | ||
459 | br->multicast_query_response_interval; | ||
460 | |||
461 | mldq->mld_type = ICMPV6_MGM_QUERY; | ||
462 | mldq->mld_code = 0; | ||
463 | mldq->mld_cksum = 0; | ||
464 | mldq->mld_maxdelay = htons((u16)jiffies_to_msecs(interval)); | ||
465 | mldq->mld_reserved = 0; | ||
466 | ipv6_addr_copy(&mldq->mld_mca, group); | ||
467 | |||
468 | /* checksum */ | ||
469 | mldq->mld_cksum = csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr, | ||
470 | sizeof(*mldq), IPPROTO_ICMPV6, | ||
471 | csum_partial(mldq, | ||
472 | sizeof(*mldq), 0)); | ||
473 | skb_put(skb, sizeof(*mldq)); | ||
474 | |||
475 | __skb_pull(skb, sizeof(*eth)); | ||
476 | |||
477 | out: | ||
478 | return skb; | ||
479 | } | ||
480 | #endif | ||
481 | |||
482 | static struct sk_buff *br_multicast_alloc_query(struct net_bridge *br, | ||
483 | struct br_ip *addr) | ||
484 | { | ||
485 | switch (addr->proto) { | ||
486 | case htons(ETH_P_IP): | ||
487 | return br_ip4_multicast_alloc_query(br, addr->u.ip4); | ||
488 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
489 | case htons(ETH_P_IPV6): | ||
490 | return br_ip6_multicast_alloc_query(br, &addr->u.ip6); | ||
491 | #endif | ||
492 | } | ||
493 | return NULL; | ||
494 | } | ||
495 | |||
317 | static void br_multicast_send_group_query(struct net_bridge_mdb_entry *mp) | 496 | static void br_multicast_send_group_query(struct net_bridge_mdb_entry *mp) |
318 | { | 497 | { |
319 | struct net_bridge *br = mp->br; | 498 | struct net_bridge *br = mp->br; |
320 | struct sk_buff *skb; | 499 | struct sk_buff *skb; |
321 | 500 | ||
322 | skb = br_multicast_alloc_query(br, mp->addr); | 501 | skb = br_multicast_alloc_query(br, &mp->addr); |
323 | if (!skb) | 502 | if (!skb) |
324 | goto timer; | 503 | goto timer; |
325 | 504 | ||
@@ -353,7 +532,7 @@ static void br_multicast_send_port_group_query(struct net_bridge_port_group *pg) | |||
353 | struct net_bridge *br = port->br; | 532 | struct net_bridge *br = port->br; |
354 | struct sk_buff *skb; | 533 | struct sk_buff *skb; |
355 | 534 | ||
356 | skb = br_multicast_alloc_query(br, pg->addr); | 535 | skb = br_multicast_alloc_query(br, &pg->addr); |
357 | if (!skb) | 536 | if (!skb) |
358 | goto timer; | 537 | goto timer; |
359 | 538 | ||
@@ -383,8 +562,8 @@ out: | |||
383 | } | 562 | } |
384 | 563 | ||
385 | static struct net_bridge_mdb_entry *br_multicast_get_group( | 564 | static struct net_bridge_mdb_entry *br_multicast_get_group( |
386 | struct net_bridge *br, struct net_bridge_port *port, __be32 group, | 565 | struct net_bridge *br, struct net_bridge_port *port, |
387 | int hash) | 566 | struct br_ip *group, int hash) |
388 | { | 567 | { |
389 | struct net_bridge_mdb_htable *mdb = br->mdb; | 568 | struct net_bridge_mdb_htable *mdb = br->mdb; |
390 | struct net_bridge_mdb_entry *mp; | 569 | struct net_bridge_mdb_entry *mp; |
@@ -396,9 +575,8 @@ static struct net_bridge_mdb_entry *br_multicast_get_group( | |||
396 | 575 | ||
397 | hlist_for_each_entry(mp, p, &mdb->mhash[hash], hlist[mdb->ver]) { | 576 | hlist_for_each_entry(mp, p, &mdb->mhash[hash], hlist[mdb->ver]) { |
398 | count++; | 577 | count++; |
399 | if (unlikely(group == mp->addr)) { | 578 | if (unlikely(br_ip_equal(group, &mp->addr))) |
400 | return mp; | 579 | return mp; |
401 | } | ||
402 | } | 580 | } |
403 | 581 | ||
404 | elasticity = 0; | 582 | elasticity = 0; |
@@ -463,7 +641,8 @@ err: | |||
463 | } | 641 | } |
464 | 642 | ||
465 | static struct net_bridge_mdb_entry *br_multicast_new_group( | 643 | static struct net_bridge_mdb_entry *br_multicast_new_group( |
466 | struct net_bridge *br, struct net_bridge_port *port, __be32 group) | 644 | struct net_bridge *br, struct net_bridge_port *port, |
645 | struct br_ip *group) | ||
467 | { | 646 | { |
468 | struct net_bridge_mdb_htable *mdb = br->mdb; | 647 | struct net_bridge_mdb_htable *mdb = br->mdb; |
469 | struct net_bridge_mdb_entry *mp; | 648 | struct net_bridge_mdb_entry *mp; |
@@ -496,7 +675,7 @@ rehash: | |||
496 | goto out; | 675 | goto out; |
497 | 676 | ||
498 | mp->br = br; | 677 | mp->br = br; |
499 | mp->addr = group; | 678 | mp->addr = *group; |
500 | setup_timer(&mp->timer, br_multicast_group_expired, | 679 | setup_timer(&mp->timer, br_multicast_group_expired, |
501 | (unsigned long)mp); | 680 | (unsigned long)mp); |
502 | setup_timer(&mp->query_timer, br_multicast_group_query_expired, | 681 | setup_timer(&mp->query_timer, br_multicast_group_query_expired, |
@@ -510,7 +689,8 @@ out: | |||
510 | } | 689 | } |
511 | 690 | ||
512 | static int br_multicast_add_group(struct net_bridge *br, | 691 | static int br_multicast_add_group(struct net_bridge *br, |
513 | struct net_bridge_port *port, __be32 group) | 692 | struct net_bridge_port *port, |
693 | struct br_ip *group) | ||
514 | { | 694 | { |
515 | struct net_bridge_mdb_entry *mp; | 695 | struct net_bridge_mdb_entry *mp; |
516 | struct net_bridge_port_group *p; | 696 | struct net_bridge_port_group *p; |
@@ -518,9 +698,6 @@ static int br_multicast_add_group(struct net_bridge *br, | |||
518 | unsigned long now = jiffies; | 698 | unsigned long now = jiffies; |
519 | int err; | 699 | int err; |
520 | 700 | ||
521 | if (ipv4_is_local_multicast(group)) | ||
522 | return 0; | ||
523 | |||
524 | spin_lock(&br->multicast_lock); | 701 | spin_lock(&br->multicast_lock); |
525 | if (!netif_running(br->dev) || | 702 | if (!netif_running(br->dev) || |
526 | (port && port->state == BR_STATE_DISABLED)) | 703 | (port && port->state == BR_STATE_DISABLED)) |
@@ -549,7 +726,7 @@ static int br_multicast_add_group(struct net_bridge *br, | |||
549 | if (unlikely(!p)) | 726 | if (unlikely(!p)) |
550 | goto err; | 727 | goto err; |
551 | 728 | ||
552 | p->addr = group; | 729 | p->addr = *group; |
553 | p->port = port; | 730 | p->port = port; |
554 | p->next = *pp; | 731 | p->next = *pp; |
555 | hlist_add_head(&p->mglist, &port->mglist); | 732 | hlist_add_head(&p->mglist, &port->mglist); |
@@ -570,6 +747,38 @@ err: | |||
570 | return err; | 747 | return err; |
571 | } | 748 | } |
572 | 749 | ||
750 | static int br_ip4_multicast_add_group(struct net_bridge *br, | ||
751 | struct net_bridge_port *port, | ||
752 | __be32 group) | ||
753 | { | ||
754 | struct br_ip br_group; | ||
755 | |||
756 | if (ipv4_is_local_multicast(group)) | ||
757 | return 0; | ||
758 | |||
759 | br_group.u.ip4 = group; | ||
760 | br_group.proto = htons(ETH_P_IP); | ||
761 | |||
762 | return br_multicast_add_group(br, port, &br_group); | ||
763 | } | ||
764 | |||
765 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
766 | static int br_ip6_multicast_add_group(struct net_bridge *br, | ||
767 | struct net_bridge_port *port, | ||
768 | const struct in6_addr *group) | ||
769 | { | ||
770 | struct br_ip br_group; | ||
771 | |||
772 | if (ipv6_is_local_multicast(group)) | ||
773 | return 0; | ||
774 | |||
775 | ipv6_addr_copy(&br_group.u.ip6, group); | ||
776 | br_group.proto = htons(ETH_P_IP); | ||
777 | |||
778 | return br_multicast_add_group(br, port, &br_group); | ||
779 | } | ||
780 | #endif | ||
781 | |||
573 | static void br_multicast_router_expired(unsigned long data) | 782 | static void br_multicast_router_expired(unsigned long data) |
574 | { | 783 | { |
575 | struct net_bridge_port *port = (void *)data; | 784 | struct net_bridge_port *port = (void *)data; |
@@ -591,19 +800,15 @@ static void br_multicast_local_router_expired(unsigned long data) | |||
591 | { | 800 | { |
592 | } | 801 | } |
593 | 802 | ||
594 | static void br_multicast_send_query(struct net_bridge *br, | 803 | static void __br_multicast_send_query(struct net_bridge *br, |
595 | struct net_bridge_port *port, u32 sent) | 804 | struct net_bridge_port *port, |
805 | struct br_ip *ip) | ||
596 | { | 806 | { |
597 | unsigned long time; | ||
598 | struct sk_buff *skb; | 807 | struct sk_buff *skb; |
599 | 808 | ||
600 | if (!netif_running(br->dev) || br->multicast_disabled || | 809 | skb = br_multicast_alloc_query(br, ip); |
601 | timer_pending(&br->multicast_querier_timer)) | ||
602 | return; | ||
603 | |||
604 | skb = br_multicast_alloc_query(br, 0); | ||
605 | if (!skb) | 810 | if (!skb) |
606 | goto timer; | 811 | return; |
607 | 812 | ||
608 | if (port) { | 813 | if (port) { |
609 | __skb_push(skb, sizeof(struct ethhdr)); | 814 | __skb_push(skb, sizeof(struct ethhdr)); |
@@ -612,8 +817,28 @@ static void br_multicast_send_query(struct net_bridge *br, | |||
612 | dev_queue_xmit); | 817 | dev_queue_xmit); |
613 | } else | 818 | } else |
614 | netif_rx(skb); | 819 | netif_rx(skb); |
820 | } | ||
821 | |||
822 | static void br_multicast_send_query(struct net_bridge *br, | ||
823 | struct net_bridge_port *port, u32 sent) | ||
824 | { | ||
825 | unsigned long time; | ||
826 | struct br_ip br_group; | ||
827 | |||
828 | if (!netif_running(br->dev) || br->multicast_disabled || | ||
829 | timer_pending(&br->multicast_querier_timer)) | ||
830 | return; | ||
831 | |||
832 | memset(&br_group.u, 0, sizeof(br_group.u)); | ||
833 | |||
834 | br_group.proto = htons(ETH_P_IP); | ||
835 | __br_multicast_send_query(br, port, &br_group); | ||
836 | |||
837 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
838 | br_group.proto = htons(ETH_P_IPV6); | ||
839 | __br_multicast_send_query(br, port, &br_group); | ||
840 | #endif | ||
615 | 841 | ||
616 | timer: | ||
617 | time = jiffies; | 842 | time = jiffies; |
618 | time += sent < br->multicast_startup_query_count ? | 843 | time += sent < br->multicast_startup_query_count ? |
619 | br->multicast_startup_query_interval : | 844 | br->multicast_startup_query_interval : |
@@ -698,9 +923,9 @@ void br_multicast_disable_port(struct net_bridge_port *port) | |||
698 | spin_unlock(&br->multicast_lock); | 923 | spin_unlock(&br->multicast_lock); |
699 | } | 924 | } |
700 | 925 | ||
701 | static int br_multicast_igmp3_report(struct net_bridge *br, | 926 | static int br_ip4_multicast_igmp3_report(struct net_bridge *br, |
702 | struct net_bridge_port *port, | 927 | struct net_bridge_port *port, |
703 | struct sk_buff *skb) | 928 | struct sk_buff *skb) |
704 | { | 929 | { |
705 | struct igmpv3_report *ih; | 930 | struct igmpv3_report *ih; |
706 | struct igmpv3_grec *grec; | 931 | struct igmpv3_grec *grec; |
@@ -745,7 +970,7 @@ static int br_multicast_igmp3_report(struct net_bridge *br, | |||
745 | continue; | 970 | continue; |
746 | } | 971 | } |
747 | 972 | ||
748 | err = br_multicast_add_group(br, port, group); | 973 | err = br_ip4_multicast_add_group(br, port, group); |
749 | if (err) | 974 | if (err) |
750 | break; | 975 | break; |
751 | } | 976 | } |
@@ -753,6 +978,66 @@ static int br_multicast_igmp3_report(struct net_bridge *br, | |||
753 | return err; | 978 | return err; |
754 | } | 979 | } |
755 | 980 | ||
981 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
982 | static int br_ip6_multicast_mld2_report(struct net_bridge *br, | ||
983 | struct net_bridge_port *port, | ||
984 | struct sk_buff *skb) | ||
985 | { | ||
986 | struct icmp6hdr *icmp6h; | ||
987 | struct mld2_grec *grec; | ||
988 | int i; | ||
989 | int len; | ||
990 | int num; | ||
991 | int err = 0; | ||
992 | |||
993 | if (!pskb_may_pull(skb, sizeof(*icmp6h))) | ||
994 | return -EINVAL; | ||
995 | |||
996 | icmp6h = icmp6_hdr(skb); | ||
997 | num = ntohs(icmp6h->icmp6_dataun.un_data16[1]); | ||
998 | len = sizeof(*icmp6h); | ||
999 | |||
1000 | for (i = 0; i < num; i++) { | ||
1001 | __be16 *nsrcs, _nsrcs; | ||
1002 | |||
1003 | nsrcs = skb_header_pointer(skb, | ||
1004 | len + offsetof(struct mld2_grec, | ||
1005 | grec_mca), | ||
1006 | sizeof(_nsrcs), &_nsrcs); | ||
1007 | if (!nsrcs) | ||
1008 | return -EINVAL; | ||
1009 | |||
1010 | if (!pskb_may_pull(skb, | ||
1011 | len + sizeof(*grec) + | ||
1012 | sizeof(struct in6_addr) * (*nsrcs))) | ||
1013 | return -EINVAL; | ||
1014 | |||
1015 | grec = (struct mld2_grec *)(skb->data + len); | ||
1016 | len += sizeof(*grec) + sizeof(struct in6_addr) * (*nsrcs); | ||
1017 | |||
1018 | /* We treat these as MLDv1 reports for now. */ | ||
1019 | switch (grec->grec_type) { | ||
1020 | case MLD2_MODE_IS_INCLUDE: | ||
1021 | case MLD2_MODE_IS_EXCLUDE: | ||
1022 | case MLD2_CHANGE_TO_INCLUDE: | ||
1023 | case MLD2_CHANGE_TO_EXCLUDE: | ||
1024 | case MLD2_ALLOW_NEW_SOURCES: | ||
1025 | case MLD2_BLOCK_OLD_SOURCES: | ||
1026 | break; | ||
1027 | |||
1028 | default: | ||
1029 | continue; | ||
1030 | } | ||
1031 | |||
1032 | err = br_ip6_multicast_add_group(br, port, &grec->grec_mca); | ||
1033 | if (!err) | ||
1034 | break; | ||
1035 | } | ||
1036 | |||
1037 | return err; | ||
1038 | } | ||
1039 | #endif | ||
1040 | |||
756 | static void br_multicast_add_router(struct net_bridge *br, | 1041 | static void br_multicast_add_router(struct net_bridge *br, |
757 | struct net_bridge_port *port) | 1042 | struct net_bridge_port *port) |
758 | { | 1043 | { |
@@ -800,7 +1085,7 @@ timer: | |||
800 | 1085 | ||
801 | static void br_multicast_query_received(struct net_bridge *br, | 1086 | static void br_multicast_query_received(struct net_bridge *br, |
802 | struct net_bridge_port *port, | 1087 | struct net_bridge_port *port, |
803 | __be32 saddr) | 1088 | int saddr) |
804 | { | 1089 | { |
805 | if (saddr) | 1090 | if (saddr) |
806 | mod_timer(&br->multicast_querier_timer, | 1091 | mod_timer(&br->multicast_querier_timer, |
@@ -811,9 +1096,9 @@ static void br_multicast_query_received(struct net_bridge *br, | |||
811 | br_multicast_mark_router(br, port); | 1096 | br_multicast_mark_router(br, port); |
812 | } | 1097 | } |
813 | 1098 | ||
814 | static int br_multicast_query(struct net_bridge *br, | 1099 | static int br_ip4_multicast_query(struct net_bridge *br, |
815 | struct net_bridge_port *port, | 1100 | struct net_bridge_port *port, |
816 | struct sk_buff *skb) | 1101 | struct sk_buff *skb) |
817 | { | 1102 | { |
818 | struct iphdr *iph = ip_hdr(skb); | 1103 | struct iphdr *iph = ip_hdr(skb); |
819 | struct igmphdr *ih = igmp_hdr(skb); | 1104 | struct igmphdr *ih = igmp_hdr(skb); |
@@ -831,7 +1116,7 @@ static int br_multicast_query(struct net_bridge *br, | |||
831 | (port && port->state == BR_STATE_DISABLED)) | 1116 | (port && port->state == BR_STATE_DISABLED)) |
832 | goto out; | 1117 | goto out; |
833 | 1118 | ||
834 | br_multicast_query_received(br, port, iph->saddr); | 1119 | br_multicast_query_received(br, port, !!iph->saddr); |
835 | 1120 | ||
836 | group = ih->group; | 1121 | group = ih->group; |
837 | 1122 | ||
@@ -859,7 +1144,7 @@ static int br_multicast_query(struct net_bridge *br, | |||
859 | if (!group) | 1144 | if (!group) |
860 | goto out; | 1145 | goto out; |
861 | 1146 | ||
862 | mp = br_mdb_ip_get(br->mdb, group); | 1147 | mp = br_mdb_ip4_get(br->mdb, group); |
863 | if (!mp) | 1148 | if (!mp) |
864 | goto out; | 1149 | goto out; |
865 | 1150 | ||
@@ -883,9 +1168,78 @@ out: | |||
883 | return err; | 1168 | return err; |
884 | } | 1169 | } |
885 | 1170 | ||
1171 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
1172 | static int br_ip6_multicast_query(struct net_bridge *br, | ||
1173 | struct net_bridge_port *port, | ||
1174 | struct sk_buff *skb) | ||
1175 | { | ||
1176 | struct ipv6hdr *ip6h = ipv6_hdr(skb); | ||
1177 | struct mld_msg *mld = (struct mld_msg *) icmp6_hdr(skb); | ||
1178 | struct net_bridge_mdb_entry *mp; | ||
1179 | struct mld2_query *mld2q; | ||
1180 | struct net_bridge_port_group *p, **pp; | ||
1181 | unsigned long max_delay; | ||
1182 | unsigned long now = jiffies; | ||
1183 | struct in6_addr *group = NULL; | ||
1184 | int err = 0; | ||
1185 | |||
1186 | spin_lock(&br->multicast_lock); | ||
1187 | if (!netif_running(br->dev) || | ||
1188 | (port && port->state == BR_STATE_DISABLED)) | ||
1189 | goto out; | ||
1190 | |||
1191 | br_multicast_query_received(br, port, !ipv6_addr_any(&ip6h->saddr)); | ||
1192 | |||
1193 | if (skb->len == sizeof(*mld)) { | ||
1194 | if (!pskb_may_pull(skb, sizeof(*mld))) { | ||
1195 | err = -EINVAL; | ||
1196 | goto out; | ||
1197 | } | ||
1198 | mld = (struct mld_msg *) icmp6_hdr(skb); | ||
1199 | max_delay = msecs_to_jiffies(htons(mld->mld_maxdelay)); | ||
1200 | if (max_delay) | ||
1201 | group = &mld->mld_mca; | ||
1202 | } else if (skb->len >= sizeof(*mld2q)) { | ||
1203 | if (!pskb_may_pull(skb, sizeof(*mld2q))) { | ||
1204 | err = -EINVAL; | ||
1205 | goto out; | ||
1206 | } | ||
1207 | mld2q = (struct mld2_query *)icmp6_hdr(skb); | ||
1208 | if (!mld2q->mld2q_nsrcs) | ||
1209 | group = &mld2q->mld2q_mca; | ||
1210 | max_delay = mld2q->mld2q_mrc ? MLDV2_MRC(mld2q->mld2q_mrc) : 1; | ||
1211 | } | ||
1212 | |||
1213 | if (!group) | ||
1214 | goto out; | ||
1215 | |||
1216 | mp = br_mdb_ip6_get(br->mdb, group); | ||
1217 | if (!mp) | ||
1218 | goto out; | ||
1219 | |||
1220 | max_delay *= br->multicast_last_member_count; | ||
1221 | if (!hlist_unhashed(&mp->mglist) && | ||
1222 | (timer_pending(&mp->timer) ? | ||
1223 | time_after(mp->timer.expires, now + max_delay) : | ||
1224 | try_to_del_timer_sync(&mp->timer) >= 0)) | ||
1225 | mod_timer(&mp->timer, now + max_delay); | ||
1226 | |||
1227 | for (pp = &mp->ports; (p = *pp); pp = &p->next) { | ||
1228 | if (timer_pending(&p->timer) ? | ||
1229 | time_after(p->timer.expires, now + max_delay) : | ||
1230 | try_to_del_timer_sync(&p->timer) >= 0) | ||
1231 | mod_timer(&mp->timer, now + max_delay); | ||
1232 | } | ||
1233 | |||
1234 | out: | ||
1235 | spin_unlock(&br->multicast_lock); | ||
1236 | return err; | ||
1237 | } | ||
1238 | #endif | ||
1239 | |||
886 | static void br_multicast_leave_group(struct net_bridge *br, | 1240 | static void br_multicast_leave_group(struct net_bridge *br, |
887 | struct net_bridge_port *port, | 1241 | struct net_bridge_port *port, |
888 | __be32 group) | 1242 | struct br_ip *group) |
889 | { | 1243 | { |
890 | struct net_bridge_mdb_htable *mdb; | 1244 | struct net_bridge_mdb_htable *mdb; |
891 | struct net_bridge_mdb_entry *mp; | 1245 | struct net_bridge_mdb_entry *mp; |
@@ -893,9 +1247,6 @@ static void br_multicast_leave_group(struct net_bridge *br, | |||
893 | unsigned long now; | 1247 | unsigned long now; |
894 | unsigned long time; | 1248 | unsigned long time; |
895 | 1249 | ||
896 | if (ipv4_is_local_multicast(group)) | ||
897 | return; | ||
898 | |||
899 | spin_lock(&br->multicast_lock); | 1250 | spin_lock(&br->multicast_lock); |
900 | if (!netif_running(br->dev) || | 1251 | if (!netif_running(br->dev) || |
901 | (port && port->state == BR_STATE_DISABLED) || | 1252 | (port && port->state == BR_STATE_DISABLED) || |
@@ -946,6 +1297,38 @@ out: | |||
946 | spin_unlock(&br->multicast_lock); | 1297 | spin_unlock(&br->multicast_lock); |
947 | } | 1298 | } |
948 | 1299 | ||
1300 | static void br_ip4_multicast_leave_group(struct net_bridge *br, | ||
1301 | struct net_bridge_port *port, | ||
1302 | __be32 group) | ||
1303 | { | ||
1304 | struct br_ip br_group; | ||
1305 | |||
1306 | if (ipv4_is_local_multicast(group)) | ||
1307 | return; | ||
1308 | |||
1309 | br_group.u.ip4 = group; | ||
1310 | br_group.proto = htons(ETH_P_IP); | ||
1311 | |||
1312 | br_multicast_leave_group(br, port, &br_group); | ||
1313 | } | ||
1314 | |||
1315 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
1316 | static void br_ip6_multicast_leave_group(struct net_bridge *br, | ||
1317 | struct net_bridge_port *port, | ||
1318 | const struct in6_addr *group) | ||
1319 | { | ||
1320 | struct br_ip br_group; | ||
1321 | |||
1322 | if (ipv6_is_local_multicast(group)) | ||
1323 | return; | ||
1324 | |||
1325 | ipv6_addr_copy(&br_group.u.ip6, group); | ||
1326 | br_group.proto = htons(ETH_P_IPV6); | ||
1327 | |||
1328 | br_multicast_leave_group(br, port, &br_group); | ||
1329 | } | ||
1330 | #endif | ||
1331 | |||
949 | static int br_multicast_ipv4_rcv(struct net_bridge *br, | 1332 | static int br_multicast_ipv4_rcv(struct net_bridge *br, |
950 | struct net_bridge_port *port, | 1333 | struct net_bridge_port *port, |
951 | struct sk_buff *skb) | 1334 | struct sk_buff *skb) |
@@ -1023,16 +1406,16 @@ static int br_multicast_ipv4_rcv(struct net_bridge *br, | |||
1023 | case IGMP_HOST_MEMBERSHIP_REPORT: | 1406 | case IGMP_HOST_MEMBERSHIP_REPORT: |
1024 | case IGMPV2_HOST_MEMBERSHIP_REPORT: | 1407 | case IGMPV2_HOST_MEMBERSHIP_REPORT: |
1025 | BR_INPUT_SKB_CB(skb2)->mrouters_only = 1; | 1408 | BR_INPUT_SKB_CB(skb2)->mrouters_only = 1; |
1026 | err = br_multicast_add_group(br, port, ih->group); | 1409 | err = br_ip4_multicast_add_group(br, port, ih->group); |
1027 | break; | 1410 | break; |
1028 | case IGMPV3_HOST_MEMBERSHIP_REPORT: | 1411 | case IGMPV3_HOST_MEMBERSHIP_REPORT: |
1029 | err = br_multicast_igmp3_report(br, port, skb2); | 1412 | err = br_ip4_multicast_igmp3_report(br, port, skb2); |
1030 | break; | 1413 | break; |
1031 | case IGMP_HOST_MEMBERSHIP_QUERY: | 1414 | case IGMP_HOST_MEMBERSHIP_QUERY: |
1032 | err = br_multicast_query(br, port, skb2); | 1415 | err = br_ip4_multicast_query(br, port, skb2); |
1033 | break; | 1416 | break; |
1034 | case IGMP_HOST_LEAVE_MESSAGE: | 1417 | case IGMP_HOST_LEAVE_MESSAGE: |
1035 | br_multicast_leave_group(br, port, ih->group); | 1418 | br_ip4_multicast_leave_group(br, port, ih->group); |
1036 | break; | 1419 | break; |
1037 | } | 1420 | } |
1038 | 1421 | ||
@@ -1044,6 +1427,126 @@ err_out: | |||
1044 | return err; | 1427 | return err; |
1045 | } | 1428 | } |
1046 | 1429 | ||
1430 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
1431 | static int br_multicast_ipv6_rcv(struct net_bridge *br, | ||
1432 | struct net_bridge_port *port, | ||
1433 | struct sk_buff *skb) | ||
1434 | { | ||
1435 | struct sk_buff *skb2 = skb; | ||
1436 | struct ipv6hdr *ip6h; | ||
1437 | struct icmp6hdr *icmp6h; | ||
1438 | u8 nexthdr; | ||
1439 | unsigned len; | ||
1440 | unsigned offset; | ||
1441 | int err; | ||
1442 | |||
1443 | BR_INPUT_SKB_CB(skb)->igmp = 0; | ||
1444 | BR_INPUT_SKB_CB(skb)->mrouters_only = 0; | ||
1445 | |||
1446 | if (!pskb_may_pull(skb, sizeof(*ip6h))) | ||
1447 | return -EINVAL; | ||
1448 | |||
1449 | ip6h = ipv6_hdr(skb); | ||
1450 | |||
1451 | /* | ||
1452 | * We're interested in MLD messages only. | ||
1453 | * - Version is 6 | ||
1454 | * - MLD has always Router Alert hop-by-hop option | ||
1455 | * - But we do not support jumbrograms. | ||
1456 | */ | ||
1457 | if (ip6h->version != 6 || | ||
1458 | ip6h->nexthdr != IPPROTO_HOPOPTS || | ||
1459 | ip6h->payload_len == 0) | ||
1460 | return 0; | ||
1461 | |||
1462 | len = ntohs(ip6h->payload_len); | ||
1463 | if (skb->len < len) | ||
1464 | return -EINVAL; | ||
1465 | |||
1466 | nexthdr = ip6h->nexthdr; | ||
1467 | offset = ipv6_skip_exthdr(skb, sizeof(*ip6h), &nexthdr); | ||
1468 | |||
1469 | if (offset < 0 || nexthdr != IPPROTO_ICMPV6) | ||
1470 | return 0; | ||
1471 | |||
1472 | /* Okay, we found ICMPv6 header */ | ||
1473 | skb2 = skb_clone(skb, GFP_ATOMIC); | ||
1474 | if (!skb2) | ||
1475 | return -ENOMEM; | ||
1476 | |||
1477 | len -= offset - skb_network_offset(skb2); | ||
1478 | |||
1479 | __skb_pull(skb2, offset); | ||
1480 | skb_reset_transport_header(skb2); | ||
1481 | |||
1482 | err = -EINVAL; | ||
1483 | if (!pskb_may_pull(skb2, sizeof(*icmp6h))) | ||
1484 | goto out; | ||
1485 | |||
1486 | icmp6h = icmp6_hdr(skb2); | ||
1487 | |||
1488 | switch (icmp6h->icmp6_type) { | ||
1489 | case ICMPV6_MGM_QUERY: | ||
1490 | case ICMPV6_MGM_REPORT: | ||
1491 | case ICMPV6_MGM_REDUCTION: | ||
1492 | case ICMPV6_MLD2_REPORT: | ||
1493 | break; | ||
1494 | default: | ||
1495 | err = 0; | ||
1496 | goto out; | ||
1497 | } | ||
1498 | |||
1499 | /* Okay, we found MLD message. Check further. */ | ||
1500 | if (skb2->len > len) { | ||
1501 | err = pskb_trim_rcsum(skb2, len); | ||
1502 | if (err) | ||
1503 | goto out; | ||
1504 | } | ||
1505 | |||
1506 | switch (skb2->ip_summed) { | ||
1507 | case CHECKSUM_COMPLETE: | ||
1508 | if (!csum_fold(skb2->csum)) | ||
1509 | break; | ||
1510 | /*FALLTHROUGH*/ | ||
1511 | case CHECKSUM_NONE: | ||
1512 | skb2->csum = 0; | ||
1513 | if (skb_checksum_complete(skb2)) | ||
1514 | goto out; | ||
1515 | } | ||
1516 | |||
1517 | err = 0; | ||
1518 | |||
1519 | BR_INPUT_SKB_CB(skb)->igmp = 1; | ||
1520 | |||
1521 | switch (icmp6h->icmp6_type) { | ||
1522 | case ICMPV6_MGM_REPORT: | ||
1523 | { | ||
1524 | struct mld_msg *mld = (struct mld_msg *)icmp6h; | ||
1525 | BR_INPUT_SKB_CB(skb2)->mrouters_only = 1; | ||
1526 | err = br_ip6_multicast_add_group(br, port, &mld->mld_mca); | ||
1527 | break; | ||
1528 | } | ||
1529 | case ICMPV6_MLD2_REPORT: | ||
1530 | err = br_ip6_multicast_mld2_report(br, port, skb2); | ||
1531 | break; | ||
1532 | case ICMPV6_MGM_QUERY: | ||
1533 | err = br_ip6_multicast_query(br, port, skb2); | ||
1534 | break; | ||
1535 | case ICMPV6_MGM_REDUCTION: | ||
1536 | { | ||
1537 | struct mld_msg *mld = (struct mld_msg *)icmp6h; | ||
1538 | br_ip6_multicast_leave_group(br, port, &mld->mld_mca); | ||
1539 | } | ||
1540 | } | ||
1541 | |||
1542 | out: | ||
1543 | __skb_push(skb2, offset); | ||
1544 | if (skb2 != skb) | ||
1545 | kfree_skb(skb2); | ||
1546 | return err; | ||
1547 | } | ||
1548 | #endif | ||
1549 | |||
1047 | int br_multicast_rcv(struct net_bridge *br, struct net_bridge_port *port, | 1550 | int br_multicast_rcv(struct net_bridge *br, struct net_bridge_port *port, |
1048 | struct sk_buff *skb) | 1551 | struct sk_buff *skb) |
1049 | { | 1552 | { |
@@ -1053,6 +1556,10 @@ int br_multicast_rcv(struct net_bridge *br, struct net_bridge_port *port, | |||
1053 | switch (skb->protocol) { | 1556 | switch (skb->protocol) { |
1054 | case htons(ETH_P_IP): | 1557 | case htons(ETH_P_IP): |
1055 | return br_multicast_ipv4_rcv(br, port, skb); | 1558 | return br_multicast_ipv4_rcv(br, port, skb); |
1559 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
1560 | case htons(ETH_P_IPV6): | ||
1561 | return br_multicast_ipv6_rcv(br, port, skb); | ||
1562 | #endif | ||
1056 | } | 1563 | } |
1057 | 1564 | ||
1058 | return 0; | 1565 | return 0; |