diff options
author | YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> | 2010-04-22 12:54:22 -0400 |
---|---|---|
committer | YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> | 2010-04-23 00:35:56 -0400 |
commit | 08b202b6726459626c73ecfa08fcdc8c3efc76c2 (patch) | |
tree | 1d4c3ac1584cf445beb6de2e2fd6f22ee64d23ae /net/bridge | |
parent | 8ef2a9a59854994bace13b5c4f7edc2c8d4d124e (diff) |
bridge br_multicast: IPv6 MLD support.
Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Diffstat (limited to 'net/bridge')
-rw-r--r-- | net/bridge/Kconfig | 6 | ||||
-rw-r--r-- | net/bridge/br_multicast.c | 424 | ||||
-rw-r--r-- | net/bridge/br_private.h | 3 |
3 files changed, 429 insertions, 4 deletions
diff --git a/net/bridge/Kconfig b/net/bridge/Kconfig index d115d5cea5b6..9190ae462cb4 100644 --- a/net/bridge/Kconfig +++ b/net/bridge/Kconfig | |||
@@ -33,14 +33,14 @@ config BRIDGE | |||
33 | If unsure, say N. | 33 | If unsure, say N. |
34 | 34 | ||
35 | config BRIDGE_IGMP_SNOOPING | 35 | config BRIDGE_IGMP_SNOOPING |
36 | bool "IGMP snooping" | 36 | bool "IGMP/MLD snooping" |
37 | depends on BRIDGE | 37 | depends on BRIDGE |
38 | depends on INET | 38 | depends on INET |
39 | default y | 39 | default y |
40 | ---help--- | 40 | ---help--- |
41 | If you say Y here, then the Ethernet bridge will be able selectively | 41 | If you say Y here, then the Ethernet bridge will be able selectively |
42 | forward multicast traffic based on IGMP traffic received from each | 42 | forward multicast traffic based on IGMP/MLD traffic received from |
43 | port. | 43 | each port. |
44 | 44 | ||
45 | Say N to exclude this support and reduce the binary size. | 45 | Say N to exclude this support and reduce the binary size. |
46 | 46 | ||
diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c index 64a3e4f74348..38d1fbde5fb8 100644 --- a/net/bridge/br_multicast.c +++ b/net/bridge/br_multicast.c | |||
@@ -24,9 +24,24 @@ | |||
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 | ||
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 | |||
30 | static inline int br_ip_equal(const struct br_ip *a, const struct br_ip *b) | 45 | static inline int br_ip_equal(const struct br_ip *a, const struct br_ip *b) |
31 | { | 46 | { |
32 | if (a->proto != b->proto) | 47 | if (a->proto != b->proto) |
@@ -34,6 +49,10 @@ static inline int br_ip_equal(const struct br_ip *a, const struct br_ip *b) | |||
34 | switch (a->proto) { | 49 | switch (a->proto) { |
35 | case htons(ETH_P_IP): | 50 | case htons(ETH_P_IP): |
36 | return a->u.ip4 == b->u.ip4; | 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 | ||
37 | } | 56 | } |
38 | return 0; | 57 | return 0; |
39 | } | 58 | } |
@@ -43,12 +62,24 @@ static inline int __br_ip4_hash(struct net_bridge_mdb_htable *mdb, __be32 ip) | |||
43 | return jhash_1word(mdb->secret, (__force u32)ip) & (mdb->max - 1); | 62 | return jhash_1word(mdb->secret, (__force u32)ip) & (mdb->max - 1); |
44 | } | 63 | } |
45 | 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 | |||
46 | static inline int br_ip_hash(struct net_bridge_mdb_htable *mdb, | 73 | static inline int br_ip_hash(struct net_bridge_mdb_htable *mdb, |
47 | struct br_ip *ip) | 74 | struct br_ip *ip) |
48 | { | 75 | { |
49 | switch (ip->proto) { | 76 | switch (ip->proto) { |
50 | case htons(ETH_P_IP): | 77 | case htons(ETH_P_IP): |
51 | return __br_ip4_hash(mdb, ip->u.ip4); | 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 | ||
52 | } | 83 | } |
53 | return 0; | 84 | return 0; |
54 | } | 85 | } |
@@ -78,6 +109,19 @@ static struct net_bridge_mdb_entry *br_mdb_ip4_get( | |||
78 | return __br_mdb_ip_get(mdb, &br_dst, __br_ip4_hash(mdb, dst)); | 109 | return __br_mdb_ip_get(mdb, &br_dst, __br_ip4_hash(mdb, dst)); |
79 | } | 110 | } |
80 | 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); | ||
120 | |||
121 | return __br_mdb_ip_get(mdb, &br_dst, __br_ip6_hash(mdb, dst)); | ||
122 | } | ||
123 | #endif | ||
124 | |||
81 | static struct net_bridge_mdb_entry *br_mdb_ip_get( | 125 | static struct net_bridge_mdb_entry *br_mdb_ip_get( |
82 | struct net_bridge_mdb_htable *mdb, struct br_ip *dst) | 126 | struct net_bridge_mdb_htable *mdb, struct br_ip *dst) |
83 | { | 127 | { |
@@ -102,6 +146,11 @@ struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br, | |||
102 | case htons(ETH_P_IP): | 146 | case htons(ETH_P_IP): |
103 | ip.u.ip4 = ip_hdr(skb)->daddr; | 147 | ip.u.ip4 = ip_hdr(skb)->daddr; |
104 | break; | 148 | break; |
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 | ||
105 | default: | 154 | default: |
106 | return NULL; | 155 | return NULL; |
107 | } | 156 | } |
@@ -352,12 +401,94 @@ out: | |||
352 | return skb; | 401 | return skb; |
353 | } | 402 | } |
354 | 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 | |||
355 | static struct sk_buff *br_multicast_alloc_query(struct net_bridge *br, | 482 | static struct sk_buff *br_multicast_alloc_query(struct net_bridge *br, |
356 | struct br_ip *addr) | 483 | struct br_ip *addr) |
357 | { | 484 | { |
358 | switch (addr->proto) { | 485 | switch (addr->proto) { |
359 | case htons(ETH_P_IP): | 486 | case htons(ETH_P_IP): |
360 | return br_ip4_multicast_alloc_query(br, addr->u.ip4); | 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 | ||
361 | } | 492 | } |
362 | return NULL; | 493 | return NULL; |
363 | } | 494 | } |
@@ -631,6 +762,23 @@ static int br_ip4_multicast_add_group(struct net_bridge *br, | |||
631 | return br_multicast_add_group(br, port, &br_group); | 762 | return br_multicast_add_group(br, port, &br_group); |
632 | } | 763 | } |
633 | 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 | |||
634 | static void br_multicast_router_expired(unsigned long data) | 782 | static void br_multicast_router_expired(unsigned long data) |
635 | { | 783 | { |
636 | struct net_bridge_port *port = (void *)data; | 784 | struct net_bridge_port *port = (void *)data; |
@@ -681,10 +829,15 @@ static void br_multicast_send_query(struct net_bridge *br, | |||
681 | timer_pending(&br->multicast_querier_timer)) | 829 | timer_pending(&br->multicast_querier_timer)) |
682 | return; | 830 | return; |
683 | 831 | ||
684 | br_group.u.ip4 = 0; | 832 | memset(&br_group.u, 0, sizeof(br_group.u)); |
833 | |||
685 | br_group.proto = htons(ETH_P_IP); | 834 | br_group.proto = htons(ETH_P_IP); |
835 | __br_multicast_send_query(br, port, &br_group); | ||
686 | 836 | ||
837 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
838 | br_group.proto = htons(ETH_P_IPV6); | ||
687 | __br_multicast_send_query(br, port, &br_group); | 839 | __br_multicast_send_query(br, port, &br_group); |
840 | #endif | ||
688 | 841 | ||
689 | time = jiffies; | 842 | time = jiffies; |
690 | time += sent < br->multicast_startup_query_count ? | 843 | time += sent < br->multicast_startup_query_count ? |
@@ -825,6 +978,66 @@ static int br_ip4_multicast_igmp3_report(struct net_bridge *br, | |||
825 | return err; | 978 | return err; |
826 | } | 979 | } |
827 | 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 | |||
828 | static void br_multicast_add_router(struct net_bridge *br, | 1041 | static void br_multicast_add_router(struct net_bridge *br, |
829 | struct net_bridge_port *port) | 1042 | struct net_bridge_port *port) |
830 | { | 1043 | { |
@@ -955,6 +1168,75 @@ out: | |||
955 | return err; | 1168 | return err; |
956 | } | 1169 | } |
957 | 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 | |||
958 | static void br_multicast_leave_group(struct net_bridge *br, | 1240 | static void br_multicast_leave_group(struct net_bridge *br, |
959 | struct net_bridge_port *port, | 1241 | struct net_bridge_port *port, |
960 | struct br_ip *group) | 1242 | struct br_ip *group) |
@@ -1030,6 +1312,22 @@ static void br_ip4_multicast_leave_group(struct net_bridge *br, | |||
1030 | br_multicast_leave_group(br, port, &br_group); | 1312 | br_multicast_leave_group(br, port, &br_group); |
1031 | } | 1313 | } |
1032 | 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 | ||
1033 | 1331 | ||
1034 | static int br_multicast_ipv4_rcv(struct net_bridge *br, | 1332 | static int br_multicast_ipv4_rcv(struct net_bridge *br, |
1035 | struct net_bridge_port *port, | 1333 | struct net_bridge_port *port, |
@@ -1129,6 +1427,126 @@ err_out: | |||
1129 | return err; | 1427 | return err; |
1130 | } | 1428 | } |
1131 | 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 | |||
1132 | 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, |
1133 | struct sk_buff *skb) | 1551 | struct sk_buff *skb) |
1134 | { | 1552 | { |
@@ -1138,6 +1556,10 @@ int br_multicast_rcv(struct net_bridge *br, struct net_bridge_port *port, | |||
1138 | switch (skb->protocol) { | 1556 | switch (skb->protocol) { |
1139 | case htons(ETH_P_IP): | 1557 | case htons(ETH_P_IP): |
1140 | 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 | ||
1141 | } | 1563 | } |
1142 | 1564 | ||
1143 | return 0; | 1565 | return 0; |
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 45d11e49fbbb..018499ebe19d 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h | |||
@@ -49,6 +49,9 @@ struct br_ip | |||
49 | { | 49 | { |
50 | union { | 50 | union { |
51 | __be32 ip4; | 51 | __be32 ip4; |
52 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
53 | struct in6_addr ip6; | ||
54 | #endif | ||
52 | } u; | 55 | } u; |
53 | __be16 proto; | 56 | __be16 proto; |
54 | }; | 57 | }; |