2 * Multicast support for IPv6
3 * Linux INET6 implementation
6 * Pedro Roque <roque@di.fc.ul.pt>
8 * $Id: mcast.c,v 1.40 2002/02/08 03:57:19 davem Exp $
10 * Based on linux/ipv4/igmp.c and linux/ipv4/ip_sockglue.c
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version.
20 * yoshfuji : fix format of router-alert option
21 * YOSHIFUJI Hideaki @USAGI:
22 * Fixed source address for MLD message based on
23 * <draft-ietf-magma-mld-source-05.txt>.
24 * YOSHIFUJI Hideaki @USAGI:
25 * - Ignore Queries for invalid addresses.
26 * - MLD for link-local addresses.
27 * David L Stevens <dlstevens@us.ibm.com>:
31 #include <linux/config.h>
32 #include <linux/module.h>
33 #include <linux/errno.h>
34 #include <linux/types.h>
35 #include <linux/string.h>
36 #include <linux/socket.h>
37 #include <linux/sockios.h>
38 #include <linux/jiffies.h>
39 #include <linux/times.h>
40 #include <linux/net.h>
42 #include <linux/in6.h>
43 #include <linux/netdevice.h>
44 #include <linux/if_arp.h>
45 #include <linux/route.h>
46 #include <linux/init.h>
47 #include <linux/proc_fs.h>
48 #include <linux/seq_file.h>
50 #include <linux/netfilter.h>
51 #include <linux/netfilter_ipv6.h>
57 #include <net/protocol.h>
58 #include <net/if_inet6.h>
59 #include <net/ndisc.h>
60 #include <net/addrconf.h>
61 #include <net/ip6_route.h>
63 #include <net/ip6_checksum.h>
65 /* Set to 3 to get tracing... */
69 #define MDBG(x) printk x
75 * These header formats should be in a separate include file, but icmpv6.h
76 * doesn't have in6_addr defined in all cases, there is no __u128, and no
77 * other files reference these.
82 /* Multicast Listener Discovery version 2 headers */
88 struct in6_addr grec_mca;
89 struct in6_addr grec_src[0];
98 struct mld2_grec grec[0];
108 #if defined(__LITTLE_ENDIAN_BITFIELD)
112 #elif defined(__BIG_ENDIAN_BITFIELD)
117 #error "Please fix <asm/byteorder.h>"
121 struct in6_addr srcs[0];
124 static struct in6_addr mld2_all_mcr = MLD2_ALL_MCR_INIT;
126 /* Big mc list lock for all the sockets */
127 static DEFINE_RWLOCK(ipv6_sk_mc_lock);
129 static struct socket *igmp6_socket;
131 int __ipv6_dev_mc_dec(struct inet6_dev *idev, struct in6_addr *addr);
133 static void igmp6_join_group(struct ifmcaddr6 *ma);
134 static void igmp6_leave_group(struct ifmcaddr6 *ma);
135 static void igmp6_timer_handler(unsigned long data);
137 static void mld_gq_timer_expire(unsigned long data);
138 static void mld_ifc_timer_expire(unsigned long data);
139 static void mld_ifc_event(struct inet6_dev *idev);
140 static void mld_add_delrec(struct inet6_dev *idev, struct ifmcaddr6 *pmc);
141 static void mld_del_delrec(struct inet6_dev *idev, struct in6_addr *addr);
142 static void mld_clear_delrec(struct inet6_dev *idev);
143 static int sf_setstate(struct ifmcaddr6 *pmc);
144 static void sf_markstate(struct ifmcaddr6 *pmc);
145 static void ip6_mc_clear_src(struct ifmcaddr6 *pmc);
146 static int ip6_mc_del_src(struct inet6_dev *idev, struct in6_addr *pmca,
147 int sfmode, int sfcount, struct in6_addr *psfsrc,
149 static int ip6_mc_add_src(struct inet6_dev *idev, struct in6_addr *pmca,
150 int sfmode, int sfcount, struct in6_addr *psfsrc,
152 static int ip6_mc_leave_src(struct sock *sk, struct ipv6_mc_socklist *iml,
153 struct inet6_dev *idev);
156 #define IGMP6_UNSOLICITED_IVAL (10*HZ)
157 #define MLD_QRV_DEFAULT 2
159 #define MLD_V1_SEEN(idev) (ipv6_devconf.force_mld_version == 1 || \
160 (idev)->cnf.force_mld_version == 1 || \
161 ((idev)->mc_v1_seen && \
162 time_before(jiffies, (idev)->mc_v1_seen)))
164 #define MLDV2_MASK(value, nb) ((nb)>=32 ? (value) : ((1<<(nb))-1) & (value))
165 #define MLDV2_EXP(thresh, nbmant, nbexp, value) \
166 ((value) < (thresh) ? (value) : \
167 ((MLDV2_MASK(value, nbmant) | (1<<(nbmant+nbexp))) << \
168 (MLDV2_MASK((value) >> (nbmant), nbexp) + (nbexp))))
170 #define MLDV2_QQIC(value) MLDV2_EXP(0x80, 4, 3, value)
171 #define MLDV2_MRC(value) MLDV2_EXP(0x8000, 12, 3, value)
173 #define IPV6_MLD_MAX_MSF 10
175 int sysctl_mld_max_msf = IPV6_MLD_MAX_MSF;
178 * socket join on multicast group
181 int ipv6_sock_mc_join(struct sock *sk, int ifindex, struct in6_addr *addr)
183 struct net_device *dev = NULL;
184 struct ipv6_mc_socklist *mc_lst;
185 struct ipv6_pinfo *np = inet6_sk(sk);
188 if (!ipv6_addr_is_multicast(addr))
191 read_lock_bh(&ipv6_sk_mc_lock);
192 for (mc_lst=np->ipv6_mc_list; mc_lst; mc_lst=mc_lst->next) {
193 if ((ifindex == 0 || mc_lst->ifindex == ifindex) &&
194 ipv6_addr_equal(&mc_lst->addr, addr)) {
195 read_unlock_bh(&ipv6_sk_mc_lock);
199 read_unlock_bh(&ipv6_sk_mc_lock);
201 mc_lst = sock_kmalloc(sk, sizeof(struct ipv6_mc_socklist), GFP_KERNEL);
207 ipv6_addr_copy(&mc_lst->addr, addr);
211 rt = rt6_lookup(addr, NULL, 0, 0);
215 dst_release(&rt->u.dst);
218 dev = dev_get_by_index(ifindex);
221 sock_kfree_s(sk, mc_lst, sizeof(*mc_lst));
225 mc_lst->ifindex = dev->ifindex;
226 mc_lst->sfmode = MCAST_EXCLUDE;
227 mc_lst->sflist = NULL;
230 * now add/increase the group membership on the device
233 err = ipv6_dev_mc_inc(dev, addr);
236 sock_kfree_s(sk, mc_lst, sizeof(*mc_lst));
241 write_lock_bh(&ipv6_sk_mc_lock);
242 mc_lst->next = np->ipv6_mc_list;
243 np->ipv6_mc_list = mc_lst;
244 write_unlock_bh(&ipv6_sk_mc_lock);
252 * socket leave on multicast group
254 int ipv6_sock_mc_drop(struct sock *sk, int ifindex, struct in6_addr *addr)
256 struct ipv6_pinfo *np = inet6_sk(sk);
257 struct ipv6_mc_socklist *mc_lst, **lnk;
259 write_lock_bh(&ipv6_sk_mc_lock);
260 for (lnk = &np->ipv6_mc_list; (mc_lst = *lnk) !=NULL ; lnk = &mc_lst->next) {
261 if ((ifindex == 0 || mc_lst->ifindex == ifindex) &&
262 ipv6_addr_equal(&mc_lst->addr, addr)) {
263 struct net_device *dev;
266 write_unlock_bh(&ipv6_sk_mc_lock);
268 if ((dev = dev_get_by_index(mc_lst->ifindex)) != NULL) {
269 struct inet6_dev *idev = in6_dev_get(dev);
272 (void) ip6_mc_leave_src(sk,mc_lst,idev);
273 __ipv6_dev_mc_dec(idev, &mc_lst->addr);
278 sock_kfree_s(sk, mc_lst, sizeof(*mc_lst));
282 write_unlock_bh(&ipv6_sk_mc_lock);
287 static struct inet6_dev *ip6_mc_find_dev(struct in6_addr *group, int ifindex)
289 struct net_device *dev = NULL;
290 struct inet6_dev *idev = NULL;
295 rt = rt6_lookup(group, NULL, 0, 0);
299 dst_release(&rt->u.dst);
302 dev = dev_get_by_index(ifindex);
306 idev = in6_dev_get(dev);
311 read_lock_bh(&idev->lock);
313 read_unlock_bh(&idev->lock);
321 void ipv6_sock_mc_close(struct sock *sk)
323 struct ipv6_pinfo *np = inet6_sk(sk);
324 struct ipv6_mc_socklist *mc_lst;
326 write_lock_bh(&ipv6_sk_mc_lock);
327 while ((mc_lst = np->ipv6_mc_list) != NULL) {
328 struct net_device *dev;
330 np->ipv6_mc_list = mc_lst->next;
331 write_unlock_bh(&ipv6_sk_mc_lock);
333 dev = dev_get_by_index(mc_lst->ifindex);
335 struct inet6_dev *idev = in6_dev_get(dev);
338 (void) ip6_mc_leave_src(sk, mc_lst, idev);
339 __ipv6_dev_mc_dec(idev, &mc_lst->addr);
345 sock_kfree_s(sk, mc_lst, sizeof(*mc_lst));
347 write_lock_bh(&ipv6_sk_mc_lock);
349 write_unlock_bh(&ipv6_sk_mc_lock);
352 int ip6_mc_source(int add, int omode, struct sock *sk,
353 struct group_source_req *pgsr)
355 struct in6_addr *source, *group;
356 struct ipv6_mc_socklist *pmc;
357 struct net_device *dev;
358 struct inet6_dev *idev;
359 struct ipv6_pinfo *inet6 = inet6_sk(sk);
360 struct ip6_sf_socklist *psl;
365 if (pgsr->gsr_group.ss_family != AF_INET6 ||
366 pgsr->gsr_source.ss_family != AF_INET6)
369 source = &((struct sockaddr_in6 *)&pgsr->gsr_source)->sin6_addr;
370 group = &((struct sockaddr_in6 *)&pgsr->gsr_group)->sin6_addr;
372 if (!ipv6_addr_is_multicast(group))
375 idev = ip6_mc_find_dev(group, pgsr->gsr_interface);
380 err = -EADDRNOTAVAIL;
382 read_lock_bh(&ipv6_sk_mc_lock);
383 for (pmc=inet6->ipv6_mc_list; pmc; pmc=pmc->next) {
384 if (pgsr->gsr_interface && pmc->ifindex != pgsr->gsr_interface)
386 if (ipv6_addr_equal(&pmc->addr, group))
389 if (!pmc) /* must have a prior join */
391 /* if a source filter was set, must be the same mode as before */
393 if (pmc->sfmode != omode)
395 } else if (pmc->sfmode != omode) {
396 /* allow mode switches for empty-set filters */
397 ip6_mc_add_src(idev, group, omode, 0, NULL, 0);
398 ip6_mc_del_src(idev, group, pmc->sfmode, 0, NULL, 0);
407 for (i=0; i<psl->sl_count; i++) {
408 rv = memcmp(&psl->sl_addr[i], source,
409 sizeof(struct in6_addr));
413 if (rv) /* source not found */
416 /* special case - (INCLUDE, empty) == LEAVE_GROUP */
417 if (psl->sl_count == 1 && omode == MCAST_INCLUDE) {
422 /* update the interface filter */
423 ip6_mc_del_src(idev, group, omode, 1, source, 1);
425 for (j=i+1; j<psl->sl_count; j++)
426 psl->sl_addr[j-1] = psl->sl_addr[j];
431 /* else, add a new source to the filter */
433 if (psl && psl->sl_count >= sysctl_mld_max_msf) {
437 if (!psl || psl->sl_count == psl->sl_max) {
438 struct ip6_sf_socklist *newpsl;
439 int count = IP6_SFBLOCK;
442 count += psl->sl_max;
443 newpsl = (struct ip6_sf_socklist *)sock_kmalloc(sk,
444 IP6_SFLSIZE(count), GFP_ATOMIC);
449 newpsl->sl_max = count;
450 newpsl->sl_count = count - IP6_SFBLOCK;
452 for (i=0; i<psl->sl_count; i++)
453 newpsl->sl_addr[i] = psl->sl_addr[i];
454 sock_kfree_s(sk, psl, IP6_SFLSIZE(psl->sl_max));
456 pmc->sflist = psl = newpsl;
458 rv = 1; /* > 0 for insert logic below if sl_count is 0 */
459 for (i=0; i<psl->sl_count; i++) {
460 rv = memcmp(&psl->sl_addr[i], source, sizeof(struct in6_addr));
464 if (rv == 0) /* address already there is an error */
466 for (j=psl->sl_count-1; j>=i; j--)
467 psl->sl_addr[j+1] = psl->sl_addr[j];
468 psl->sl_addr[i] = *source;
471 /* update the interface list */
472 ip6_mc_add_src(idev, group, omode, 1, source, 1);
474 read_unlock_bh(&ipv6_sk_mc_lock);
475 read_unlock_bh(&idev->lock);
479 return ipv6_sock_mc_drop(sk, pgsr->gsr_interface, group);
483 int ip6_mc_msfilter(struct sock *sk, struct group_filter *gsf)
485 struct in6_addr *group;
486 struct ipv6_mc_socklist *pmc;
487 struct net_device *dev;
488 struct inet6_dev *idev;
489 struct ipv6_pinfo *inet6 = inet6_sk(sk);
490 struct ip6_sf_socklist *newpsl, *psl;
493 group = &((struct sockaddr_in6 *)&gsf->gf_group)->sin6_addr;
495 if (!ipv6_addr_is_multicast(group))
497 if (gsf->gf_fmode != MCAST_INCLUDE &&
498 gsf->gf_fmode != MCAST_EXCLUDE)
501 idev = ip6_mc_find_dev(group, gsf->gf_interface);
506 err = -EADDRNOTAVAIL;
508 for (pmc=inet6->ipv6_mc_list; pmc; pmc=pmc->next) {
509 if (pmc->ifindex != gsf->gf_interface)
511 if (ipv6_addr_equal(&pmc->addr, group))
514 if (!pmc) /* must have a prior join */
516 if (gsf->gf_numsrc) {
517 newpsl = (struct ip6_sf_socklist *)sock_kmalloc(sk,
518 IP6_SFLSIZE(gsf->gf_numsrc), GFP_ATOMIC);
523 newpsl->sl_max = newpsl->sl_count = gsf->gf_numsrc;
524 for (i=0; i<newpsl->sl_count; ++i) {
525 struct sockaddr_in6 *psin6;
527 psin6 = (struct sockaddr_in6 *)&gsf->gf_slist[i];
528 newpsl->sl_addr[i] = psin6->sin6_addr;
530 err = ip6_mc_add_src(idev, group, gsf->gf_fmode,
531 newpsl->sl_count, newpsl->sl_addr, 0);
533 sock_kfree_s(sk, newpsl, IP6_SFLSIZE(newpsl->sl_max));
540 (void) ip6_mc_del_src(idev, group, pmc->sfmode,
541 psl->sl_count, psl->sl_addr, 0);
542 sock_kfree_s(sk, psl, IP6_SFLSIZE(psl->sl_max));
544 (void) ip6_mc_del_src(idev, group, pmc->sfmode, 0, NULL, 0);
545 pmc->sflist = newpsl;
546 pmc->sfmode = gsf->gf_fmode;
548 read_unlock_bh(&idev->lock);
554 int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf,
555 struct group_filter __user *optval, int __user *optlen)
557 int err, i, count, copycount;
558 struct in6_addr *group;
559 struct ipv6_mc_socklist *pmc;
560 struct inet6_dev *idev;
561 struct net_device *dev;
562 struct ipv6_pinfo *inet6 = inet6_sk(sk);
563 struct ip6_sf_socklist *psl;
565 group = &((struct sockaddr_in6 *)&gsf->gf_group)->sin6_addr;
567 if (!ipv6_addr_is_multicast(group))
570 idev = ip6_mc_find_dev(group, gsf->gf_interface);
577 err = -EADDRNOTAVAIL;
579 for (pmc=inet6->ipv6_mc_list; pmc; pmc=pmc->next) {
580 if (pmc->ifindex != gsf->gf_interface)
582 if (ipv6_addr_equal(group, &pmc->addr))
585 if (!pmc) /* must have a prior join */
587 gsf->gf_fmode = pmc->sfmode;
589 count = psl ? psl->sl_count : 0;
590 read_unlock_bh(&idev->lock);
594 copycount = count < gsf->gf_numsrc ? count : gsf->gf_numsrc;
595 gsf->gf_numsrc = count;
596 if (put_user(GROUP_FILTER_SIZE(copycount), optlen) ||
597 copy_to_user(optval, gsf, GROUP_FILTER_SIZE(0))) {
600 for (i=0; i<copycount; i++) {
601 struct sockaddr_in6 *psin6;
602 struct sockaddr_storage ss;
604 psin6 = (struct sockaddr_in6 *)&ss;
605 memset(&ss, 0, sizeof(ss));
606 psin6->sin6_family = AF_INET6;
607 psin6->sin6_addr = psl->sl_addr[i];
608 if (copy_to_user(&optval->gf_slist[i], &ss, sizeof(ss)))
613 read_unlock_bh(&idev->lock);
619 int inet6_mc_check(struct sock *sk, struct in6_addr *mc_addr,
620 struct in6_addr *src_addr)
622 struct ipv6_pinfo *np = inet6_sk(sk);
623 struct ipv6_mc_socklist *mc;
624 struct ip6_sf_socklist *psl;
627 read_lock(&ipv6_sk_mc_lock);
628 for (mc = np->ipv6_mc_list; mc; mc = mc->next) {
629 if (ipv6_addr_equal(&mc->addr, mc_addr))
633 read_unlock(&ipv6_sk_mc_lock);
638 rv = mc->sfmode == MCAST_EXCLUDE;
642 for (i=0; i<psl->sl_count; i++) {
643 if (ipv6_addr_equal(&psl->sl_addr[i], src_addr))
646 if (mc->sfmode == MCAST_INCLUDE && i >= psl->sl_count)
648 if (mc->sfmode == MCAST_EXCLUDE && i < psl->sl_count)
651 read_unlock(&ipv6_sk_mc_lock);
656 static void ma_put(struct ifmcaddr6 *mc)
658 if (atomic_dec_and_test(&mc->mca_refcnt)) {
659 in6_dev_put(mc->idev);
664 static void igmp6_group_added(struct ifmcaddr6 *mc)
666 struct net_device *dev = mc->idev->dev;
667 char buf[MAX_ADDR_LEN];
669 spin_lock_bh(&mc->mca_lock);
670 if (!(mc->mca_flags&MAF_LOADED)) {
671 mc->mca_flags |= MAF_LOADED;
672 if (ndisc_mc_map(&mc->mca_addr, buf, dev, 0) == 0)
673 dev_mc_add(dev, buf, dev->addr_len, 0);
675 spin_unlock_bh(&mc->mca_lock);
677 if (!(dev->flags & IFF_UP) || (mc->mca_flags & MAF_NOREPORT))
680 if (MLD_V1_SEEN(mc->idev)) {
681 igmp6_join_group(mc);
686 mc->mca_crcount = mc->idev->mc_qrv;
687 mld_ifc_event(mc->idev);
690 static void igmp6_group_dropped(struct ifmcaddr6 *mc)
692 struct net_device *dev = mc->idev->dev;
693 char buf[MAX_ADDR_LEN];
695 spin_lock_bh(&mc->mca_lock);
696 if (mc->mca_flags&MAF_LOADED) {
697 mc->mca_flags &= ~MAF_LOADED;
698 if (ndisc_mc_map(&mc->mca_addr, buf, dev, 0) == 0)
699 dev_mc_delete(dev, buf, dev->addr_len, 0);
702 if (mc->mca_flags & MAF_NOREPORT)
704 spin_unlock_bh(&mc->mca_lock);
707 igmp6_leave_group(mc);
709 spin_lock_bh(&mc->mca_lock);
710 if (del_timer(&mc->mca_timer))
711 atomic_dec(&mc->mca_refcnt);
713 ip6_mc_clear_src(mc);
714 spin_unlock_bh(&mc->mca_lock);
718 * deleted ifmcaddr6 manipulation
720 static void mld_add_delrec(struct inet6_dev *idev, struct ifmcaddr6 *im)
722 struct ifmcaddr6 *pmc;
724 /* this is an "ifmcaddr6" for convenience; only the fields below
725 * are actually used. In particular, the refcnt and users are not
726 * used for management of the delete list. Using the same structure
727 * for deleted items allows change reports to use common code with
728 * non-deleted or query-response MCA's.
730 pmc = (struct ifmcaddr6 *)kmalloc(sizeof(*pmc), GFP_ATOMIC);
733 memset(pmc, 0, sizeof(*pmc));
734 spin_lock_bh(&im->mca_lock);
735 spin_lock_init(&pmc->mca_lock);
736 pmc->idev = im->idev;
738 pmc->mca_addr = im->mca_addr;
739 pmc->mca_crcount = idev->mc_qrv;
740 pmc->mca_sfmode = im->mca_sfmode;
741 if (pmc->mca_sfmode == MCAST_INCLUDE) {
742 struct ip6_sf_list *psf;
744 pmc->mca_tomb = im->mca_tomb;
745 pmc->mca_sources = im->mca_sources;
746 im->mca_tomb = im->mca_sources = NULL;
747 for (psf=pmc->mca_sources; psf; psf=psf->sf_next)
748 psf->sf_crcount = pmc->mca_crcount;
750 spin_unlock_bh(&im->mca_lock);
752 write_lock_bh(&idev->mc_lock);
753 pmc->next = idev->mc_tomb;
755 write_unlock_bh(&idev->mc_lock);
758 static void mld_del_delrec(struct inet6_dev *idev, struct in6_addr *pmca)
760 struct ifmcaddr6 *pmc, *pmc_prev;
761 struct ip6_sf_list *psf, *psf_next;
763 write_lock_bh(&idev->mc_lock);
765 for (pmc=idev->mc_tomb; pmc; pmc=pmc->next) {
766 if (ipv6_addr_equal(&pmc->mca_addr, pmca))
772 pmc_prev->next = pmc->next;
774 idev->mc_tomb = pmc->next;
776 write_unlock_bh(&idev->mc_lock);
778 for (psf=pmc->mca_tomb; psf; psf=psf_next) {
779 psf_next = psf->sf_next;
782 in6_dev_put(pmc->idev);
787 static void mld_clear_delrec(struct inet6_dev *idev)
789 struct ifmcaddr6 *pmc, *nextpmc;
791 write_lock_bh(&idev->mc_lock);
793 idev->mc_tomb = NULL;
794 write_unlock_bh(&idev->mc_lock);
796 for (; pmc; pmc = nextpmc) {
798 ip6_mc_clear_src(pmc);
799 in6_dev_put(pmc->idev);
803 /* clear dead sources, too */
804 read_lock_bh(&idev->lock);
805 for (pmc=idev->mc_list; pmc; pmc=pmc->next) {
806 struct ip6_sf_list *psf, *psf_next;
808 spin_lock_bh(&pmc->mca_lock);
810 pmc->mca_tomb = NULL;
811 spin_unlock_bh(&pmc->mca_lock);
812 for (; psf; psf=psf_next) {
813 psf_next = psf->sf_next;
817 read_unlock_bh(&idev->lock);
822 * device multicast group inc (add if not found)
824 int ipv6_dev_mc_inc(struct net_device *dev, struct in6_addr *addr)
826 struct ifmcaddr6 *mc;
827 struct inet6_dev *idev;
829 idev = in6_dev_get(dev);
834 write_lock_bh(&idev->lock);
836 write_unlock_bh(&idev->lock);
841 for (mc = idev->mc_list; mc; mc = mc->next) {
842 if (ipv6_addr_equal(&mc->mca_addr, addr)) {
844 write_unlock_bh(&idev->lock);
845 ip6_mc_add_src(idev, &mc->mca_addr, MCAST_EXCLUDE, 0,
853 * not found: create a new one.
856 mc = kmalloc(sizeof(struct ifmcaddr6), GFP_ATOMIC);
859 write_unlock_bh(&idev->lock);
864 memset(mc, 0, sizeof(struct ifmcaddr6));
865 init_timer(&mc->mca_timer);
866 mc->mca_timer.function = igmp6_timer_handler;
867 mc->mca_timer.data = (unsigned long) mc;
869 ipv6_addr_copy(&mc->mca_addr, addr);
872 /* mca_stamp should be updated upon changes */
873 mc->mca_cstamp = mc->mca_tstamp = jiffies;
874 atomic_set(&mc->mca_refcnt, 2);
875 spin_lock_init(&mc->mca_lock);
877 /* initial mode is (EX, empty) */
878 mc->mca_sfmode = MCAST_EXCLUDE;
879 mc->mca_sfcount[MCAST_EXCLUDE] = 1;
881 if (ipv6_addr_is_ll_all_nodes(&mc->mca_addr) ||
882 IPV6_ADDR_MC_SCOPE(&mc->mca_addr) < IPV6_ADDR_SCOPE_LINKLOCAL)
883 mc->mca_flags |= MAF_NOREPORT;
885 mc->next = idev->mc_list;
887 write_unlock_bh(&idev->lock);
889 mld_del_delrec(idev, &mc->mca_addr);
890 igmp6_group_added(mc);
896 * device multicast group del
898 int __ipv6_dev_mc_dec(struct inet6_dev *idev, struct in6_addr *addr)
900 struct ifmcaddr6 *ma, **map;
902 write_lock_bh(&idev->lock);
903 for (map = &idev->mc_list; (ma=*map) != NULL; map = &ma->next) {
904 if (ipv6_addr_equal(&ma->mca_addr, addr)) {
905 if (--ma->mca_users == 0) {
907 write_unlock_bh(&idev->lock);
909 igmp6_group_dropped(ma);
914 write_unlock_bh(&idev->lock);
918 write_unlock_bh(&idev->lock);
923 int ipv6_dev_mc_dec(struct net_device *dev, struct in6_addr *addr)
925 struct inet6_dev *idev = in6_dev_get(dev);
931 err = __ipv6_dev_mc_dec(idev, addr);
939 * identify MLD packets for MLD filter exceptions
941 int ipv6_is_mld(struct sk_buff *skb, int nexthdr)
943 struct icmp6hdr *pic;
945 if (nexthdr != IPPROTO_ICMPV6)
948 if (!pskb_may_pull(skb, sizeof(struct icmp6hdr)))
951 pic = (struct icmp6hdr *)skb->h.raw;
953 switch (pic->icmp6_type) {
954 case ICMPV6_MGM_QUERY:
955 case ICMPV6_MGM_REPORT:
956 case ICMPV6_MGM_REDUCTION:
957 case ICMPV6_MLD2_REPORT:
966 * check if the interface/address pair is valid
968 int ipv6_chk_mcast_addr(struct net_device *dev, struct in6_addr *group,
969 struct in6_addr *src_addr)
971 struct inet6_dev *idev;
972 struct ifmcaddr6 *mc;
975 idev = in6_dev_get(dev);
977 read_lock_bh(&idev->lock);
978 for (mc = idev->mc_list; mc; mc=mc->next) {
979 if (ipv6_addr_equal(&mc->mca_addr, group))
983 if (src_addr && !ipv6_addr_any(src_addr)) {
984 struct ip6_sf_list *psf;
986 spin_lock_bh(&mc->mca_lock);
987 for (psf=mc->mca_sources;psf;psf=psf->sf_next) {
988 if (ipv6_addr_equal(&psf->sf_addr, src_addr))
992 rv = psf->sf_count[MCAST_INCLUDE] ||
993 psf->sf_count[MCAST_EXCLUDE] !=
994 mc->mca_sfcount[MCAST_EXCLUDE];
996 rv = mc->mca_sfcount[MCAST_EXCLUDE] !=0;
997 spin_unlock_bh(&mc->mca_lock);
999 rv = 1; /* don't filter unspecified source */
1001 read_unlock_bh(&idev->lock);
1007 static void mld_gq_start_timer(struct inet6_dev *idev)
1009 int tv = net_random() % idev->mc_maxdelay;
1011 idev->mc_gq_running = 1;
1012 if (!mod_timer(&idev->mc_gq_timer, jiffies+tv+2))
1016 static void mld_ifc_start_timer(struct inet6_dev *idev, int delay)
1018 int tv = net_random() % delay;
1020 if (!mod_timer(&idev->mc_ifc_timer, jiffies+tv+2))
1025 * IGMP handling (alias multicast ICMPv6 messages)
1028 static void igmp6_group_queried(struct ifmcaddr6 *ma, unsigned long resptime)
1030 unsigned long delay = resptime;
1032 /* Do not start timer for these addresses */
1033 if (ipv6_addr_is_ll_all_nodes(&ma->mca_addr) ||
1034 IPV6_ADDR_MC_SCOPE(&ma->mca_addr) < IPV6_ADDR_SCOPE_LINKLOCAL)
1037 if (del_timer(&ma->mca_timer)) {
1038 atomic_dec(&ma->mca_refcnt);
1039 delay = ma->mca_timer.expires - jiffies;
1042 if (delay >= resptime) {
1044 delay = net_random() % resptime;
1048 ma->mca_timer.expires = jiffies + delay;
1049 if (!mod_timer(&ma->mca_timer, jiffies + delay))
1050 atomic_inc(&ma->mca_refcnt);
1051 ma->mca_flags |= MAF_TIMER_RUNNING;
1054 static void mld_marksources(struct ifmcaddr6 *pmc, int nsrcs,
1055 struct in6_addr *srcs)
1057 struct ip6_sf_list *psf;
1061 for (psf=pmc->mca_sources; psf; psf=psf->sf_next) {
1062 if (scount == nsrcs)
1064 for (i=0; i<nsrcs; i++)
1065 if (ipv6_addr_equal(&srcs[i], &psf->sf_addr)) {
1073 int igmp6_event_query(struct sk_buff *skb)
1075 struct mld2_query *mlh2 = (struct mld2_query *) skb->h.raw;
1076 struct ifmcaddr6 *ma;
1077 struct in6_addr *group;
1078 unsigned long max_delay;
1079 struct inet6_dev *idev;
1080 struct icmp6hdr *hdr;
1085 if (!pskb_may_pull(skb, sizeof(struct in6_addr)))
1088 /* compute payload length excluding extension headers */
1089 len = ntohs(skb->nh.ipv6h->payload_len) + sizeof(struct ipv6hdr);
1090 len -= (char *)skb->h.raw - (char *)skb->nh.ipv6h;
1092 /* Drop queries with not link local source */
1093 if (!(ipv6_addr_type(&skb->nh.ipv6h->saddr)&IPV6_ADDR_LINKLOCAL))
1096 idev = in6_dev_get(skb->dev);
1101 hdr = (struct icmp6hdr *) skb->h.raw;
1102 group = (struct in6_addr *) (hdr + 1);
1103 group_type = ipv6_addr_type(group);
1105 if (group_type != IPV6_ADDR_ANY &&
1106 !(group_type&IPV6_ADDR_MULTICAST)) {
1113 /* MLDv1 router present */
1115 /* Translate milliseconds to jiffies */
1116 max_delay = (ntohs(hdr->icmp6_maxdelay)*HZ)/1000;
1118 switchback = (idev->mc_qrv + 1) * max_delay;
1119 idev->mc_v1_seen = jiffies + switchback;
1121 /* cancel the interface change timer */
1122 idev->mc_ifc_count = 0;
1123 if (del_timer(&idev->mc_ifc_timer))
1124 __in6_dev_put(idev);
1125 /* clear deleted report items */
1126 mld_clear_delrec(idev);
1127 } else if (len >= 28) {
1128 max_delay = (MLDV2_MRC(ntohs(mlh2->mrc))*HZ)/1000;
1131 idev->mc_maxdelay = max_delay;
1133 idev->mc_qrv = mlh2->qrv;
1134 if (group_type == IPV6_ADDR_ANY) { /* general query */
1137 return -EINVAL; /* no sources allowed */
1139 mld_gq_start_timer(idev);
1143 /* mark sources to include, if group & source-specific */
1144 mark = mlh2->nsrcs != 0;
1150 read_lock_bh(&idev->lock);
1151 if (group_type == IPV6_ADDR_ANY) {
1152 for (ma = idev->mc_list; ma; ma=ma->next) {
1153 spin_lock_bh(&ma->mca_lock);
1154 igmp6_group_queried(ma, max_delay);
1155 spin_unlock_bh(&ma->mca_lock);
1158 for (ma = idev->mc_list; ma; ma=ma->next) {
1159 if (group_type != IPV6_ADDR_ANY &&
1160 !ipv6_addr_equal(group, &ma->mca_addr))
1162 spin_lock_bh(&ma->mca_lock);
1163 if (ma->mca_flags & MAF_TIMER_RUNNING) {
1164 /* gsquery <- gsquery && mark */
1166 ma->mca_flags &= ~MAF_GSQUERY;
1168 /* gsquery <- mark */
1170 ma->mca_flags |= MAF_GSQUERY;
1172 ma->mca_flags &= ~MAF_GSQUERY;
1174 if (ma->mca_flags & MAF_GSQUERY)
1175 mld_marksources(ma, ntohs(mlh2->nsrcs),
1177 igmp6_group_queried(ma, max_delay);
1178 spin_unlock_bh(&ma->mca_lock);
1179 if (group_type != IPV6_ADDR_ANY)
1183 read_unlock_bh(&idev->lock);
1190 int igmp6_event_report(struct sk_buff *skb)
1192 struct ifmcaddr6 *ma;
1193 struct in6_addr *addrp;
1194 struct inet6_dev *idev;
1195 struct icmp6hdr *hdr;
1198 /* Our own report looped back. Ignore it. */
1199 if (skb->pkt_type == PACKET_LOOPBACK)
1202 if (!pskb_may_pull(skb, sizeof(struct in6_addr)))
1205 hdr = (struct icmp6hdr*) skb->h.raw;
1207 /* Drop reports with not link local source */
1208 addr_type = ipv6_addr_type(&skb->nh.ipv6h->saddr);
1209 if (addr_type != IPV6_ADDR_ANY &&
1210 !(addr_type&IPV6_ADDR_LINKLOCAL))
1213 addrp = (struct in6_addr *) (hdr + 1);
1215 idev = in6_dev_get(skb->dev);
1220 * Cancel the timer for this group
1223 read_lock_bh(&idev->lock);
1224 for (ma = idev->mc_list; ma; ma=ma->next) {
1225 if (ipv6_addr_equal(&ma->mca_addr, addrp)) {
1226 spin_lock(&ma->mca_lock);
1227 if (del_timer(&ma->mca_timer))
1228 atomic_dec(&ma->mca_refcnt);
1229 ma->mca_flags &= ~(MAF_LAST_REPORTER|MAF_TIMER_RUNNING);
1230 spin_unlock(&ma->mca_lock);
1234 read_unlock_bh(&idev->lock);
1239 static int is_in(struct ifmcaddr6 *pmc, struct ip6_sf_list *psf, int type,
1240 int gdeleted, int sdeleted)
1243 case MLD2_MODE_IS_INCLUDE:
1244 case MLD2_MODE_IS_EXCLUDE:
1245 if (gdeleted || sdeleted)
1247 return !((pmc->mca_flags & MAF_GSQUERY) && !psf->sf_gsresp);
1248 case MLD2_CHANGE_TO_INCLUDE:
1249 if (gdeleted || sdeleted)
1251 return psf->sf_count[MCAST_INCLUDE] != 0;
1252 case MLD2_CHANGE_TO_EXCLUDE:
1253 if (gdeleted || sdeleted)
1255 if (pmc->mca_sfcount[MCAST_EXCLUDE] == 0 ||
1256 psf->sf_count[MCAST_INCLUDE])
1258 return pmc->mca_sfcount[MCAST_EXCLUDE] ==
1259 psf->sf_count[MCAST_EXCLUDE];
1260 case MLD2_ALLOW_NEW_SOURCES:
1261 if (gdeleted || !psf->sf_crcount)
1263 return (pmc->mca_sfmode == MCAST_INCLUDE) ^ sdeleted;
1264 case MLD2_BLOCK_OLD_SOURCES:
1265 if (pmc->mca_sfmode == MCAST_INCLUDE)
1266 return gdeleted || (psf->sf_crcount && sdeleted);
1267 return psf->sf_crcount && !gdeleted && !sdeleted;
1273 mld_scount(struct ifmcaddr6 *pmc, int type, int gdeleted, int sdeleted)
1275 struct ip6_sf_list *psf;
1278 for (psf=pmc->mca_sources; psf; psf=psf->sf_next) {
1279 if (!is_in(pmc, psf, type, gdeleted, sdeleted))
1286 static struct sk_buff *mld_newpack(struct net_device *dev, int size)
1288 struct sock *sk = igmp6_socket->sk;
1289 struct sk_buff *skb;
1290 struct mld2_report *pmr;
1291 struct in6_addr addr_buf;
1293 u8 ra[8] = { IPPROTO_ICMPV6, 0,
1294 IPV6_TLV_ROUTERALERT, 2, 0, 0,
1297 /* we assume size > sizeof(ra) here */
1298 skb = sock_alloc_send_skb(sk, size + LL_RESERVED_SPACE(dev), 1, &err);
1303 skb_reserve(skb, LL_RESERVED_SPACE(dev));
1305 if (ipv6_get_lladdr(dev, &addr_buf)) {
1306 /* <draft-ietf-magma-mld-source-05.txt>:
1307 * use unspecified address as the source address
1308 * when a valid link-local address is not available.
1310 memset(&addr_buf, 0, sizeof(addr_buf));
1313 ip6_nd_hdr(sk, skb, dev, &addr_buf, &mld2_all_mcr, NEXTHDR_HOP, 0);
1315 memcpy(skb_put(skb, sizeof(ra)), ra, sizeof(ra));
1317 pmr =(struct mld2_report *)skb_put(skb, sizeof(*pmr));
1318 skb->h.raw = (unsigned char *)pmr;
1319 pmr->type = ICMPV6_MLD2_REPORT;
1327 static inline int mld_dev_queue_xmit2(struct sk_buff *skb)
1329 struct net_device *dev = skb->dev;
1331 if (dev->hard_header) {
1332 unsigned char ha[MAX_ADDR_LEN];
1335 ndisc_mc_map(&skb->nh.ipv6h->daddr, ha, dev, 1);
1336 err = dev->hard_header(skb, dev, ETH_P_IPV6, ha, NULL, skb->len);
1342 return dev_queue_xmit(skb);
1345 static inline int mld_dev_queue_xmit(struct sk_buff *skb)
1347 return NF_HOOK(PF_INET6, NF_IP6_POST_ROUTING, skb, NULL, skb->dev,
1348 mld_dev_queue_xmit2);
1351 static void mld_sendpack(struct sk_buff *skb)
1353 struct ipv6hdr *pip6 = skb->nh.ipv6h;
1354 struct mld2_report *pmr = (struct mld2_report *)skb->h.raw;
1355 int payload_len, mldlen;
1356 struct inet6_dev *idev = in6_dev_get(skb->dev);
1359 IP6_INC_STATS(IPSTATS_MIB_OUTREQUESTS);
1360 payload_len = skb->tail - (unsigned char *)skb->nh.ipv6h -
1361 sizeof(struct ipv6hdr);
1362 mldlen = skb->tail - skb->h.raw;
1363 pip6->payload_len = htons(payload_len);
1365 pmr->csum = csum_ipv6_magic(&pip6->saddr, &pip6->daddr, mldlen,
1366 IPPROTO_ICMPV6, csum_partial(skb->h.raw, mldlen, 0));
1367 err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, skb->dev,
1368 mld_dev_queue_xmit);
1370 ICMP6_INC_STATS(idev,ICMP6_MIB_OUTMSGS);
1371 IP6_INC_STATS(IPSTATS_MIB_OUTMCASTPKTS);
1373 IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
1375 if (likely(idev != NULL))
1379 static int grec_size(struct ifmcaddr6 *pmc, int type, int gdel, int sdel)
1381 return sizeof(struct mld2_grec) + 4*mld_scount(pmc,type,gdel,sdel);
1384 static struct sk_buff *add_grhead(struct sk_buff *skb, struct ifmcaddr6 *pmc,
1385 int type, struct mld2_grec **ppgr)
1387 struct net_device *dev = pmc->idev->dev;
1388 struct mld2_report *pmr;
1389 struct mld2_grec *pgr;
1392 skb = mld_newpack(dev, dev->mtu);
1395 pgr = (struct mld2_grec *)skb_put(skb, sizeof(struct mld2_grec));
1396 pgr->grec_type = type;
1397 pgr->grec_auxwords = 0;
1398 pgr->grec_nsrcs = 0;
1399 pgr->grec_mca = pmc->mca_addr; /* structure copy */
1400 pmr = (struct mld2_report *)skb->h.raw;
1401 pmr->ngrec = htons(ntohs(pmr->ngrec)+1);
1406 #define AVAILABLE(skb) ((skb) ? ((skb)->dev ? (skb)->dev->mtu - (skb)->len : \
1407 skb_tailroom(skb)) : 0)
1409 static struct sk_buff *add_grec(struct sk_buff *skb, struct ifmcaddr6 *pmc,
1410 int type, int gdeleted, int sdeleted)
1412 struct net_device *dev = pmc->idev->dev;
1413 struct mld2_report *pmr;
1414 struct mld2_grec *pgr = NULL;
1415 struct ip6_sf_list *psf, *psf_next, *psf_prev, **psf_list;
1416 int scount, first, isquery, truncate;
1418 if (pmc->mca_flags & MAF_NOREPORT)
1421 isquery = type == MLD2_MODE_IS_INCLUDE ||
1422 type == MLD2_MODE_IS_EXCLUDE;
1423 truncate = type == MLD2_MODE_IS_EXCLUDE ||
1424 type == MLD2_CHANGE_TO_EXCLUDE;
1426 psf_list = sdeleted ? &pmc->mca_tomb : &pmc->mca_sources;
1429 if (type == MLD2_ALLOW_NEW_SOURCES ||
1430 type == MLD2_BLOCK_OLD_SOURCES)
1432 if (pmc->mca_crcount || isquery) {
1433 /* make sure we have room for group header and at
1436 if (skb && AVAILABLE(skb) < sizeof(struct mld2_grec)+
1437 sizeof(struct in6_addr)) {
1439 skb = NULL; /* add_grhead will get a new one */
1441 skb = add_grhead(skb, pmc, type, &pgr);
1445 pmr = skb ? (struct mld2_report *)skb->h.raw : NULL;
1447 /* EX and TO_EX get a fresh packet, if needed */
1449 if (pmr && pmr->ngrec &&
1450 AVAILABLE(skb) < grec_size(pmc, type, gdeleted, sdeleted)) {
1453 skb = mld_newpack(dev, dev->mtu);
1459 for (psf=*psf_list; psf; psf=psf_next) {
1460 struct in6_addr *psrc;
1462 psf_next = psf->sf_next;
1464 if (!is_in(pmc, psf, type, gdeleted, sdeleted)) {
1469 /* clear marks on query responses */
1473 if (AVAILABLE(skb) < sizeof(*psrc) +
1474 first*sizeof(struct mld2_grec)) {
1475 if (truncate && !first)
1476 break; /* truncate these */
1478 pgr->grec_nsrcs = htons(scount);
1481 skb = mld_newpack(dev, dev->mtu);
1486 skb = add_grhead(skb, pmc, type, &pgr);
1489 psrc = (struct in6_addr *)skb_put(skb, sizeof(*psrc));
1490 *psrc = psf->sf_addr;
1492 if ((type == MLD2_ALLOW_NEW_SOURCES ||
1493 type == MLD2_BLOCK_OLD_SOURCES) && psf->sf_crcount) {
1495 if ((sdeleted || gdeleted) && psf->sf_crcount == 0) {
1497 psf_prev->sf_next = psf->sf_next;
1499 *psf_list = psf->sf_next;
1507 pgr->grec_nsrcs = htons(scount);
1510 pmc->mca_flags &= ~MAF_GSQUERY; /* clear query state */
1514 static void mld_send_report(struct inet6_dev *idev, struct ifmcaddr6 *pmc)
1516 struct sk_buff *skb = NULL;
1520 read_lock_bh(&idev->lock);
1521 for (pmc=idev->mc_list; pmc; pmc=pmc->next) {
1522 if (pmc->mca_flags & MAF_NOREPORT)
1524 spin_lock_bh(&pmc->mca_lock);
1525 if (pmc->mca_sfcount[MCAST_EXCLUDE])
1526 type = MLD2_MODE_IS_EXCLUDE;
1528 type = MLD2_MODE_IS_INCLUDE;
1529 skb = add_grec(skb, pmc, type, 0, 0);
1530 spin_unlock_bh(&pmc->mca_lock);
1532 read_unlock_bh(&idev->lock);
1534 spin_lock_bh(&pmc->mca_lock);
1535 if (pmc->mca_sfcount[MCAST_EXCLUDE])
1536 type = MLD2_MODE_IS_EXCLUDE;
1538 type = MLD2_MODE_IS_INCLUDE;
1539 skb = add_grec(skb, pmc, type, 0, 0);
1540 spin_unlock_bh(&pmc->mca_lock);
1547 * remove zero-count source records from a source filter list
1549 static void mld_clear_zeros(struct ip6_sf_list **ppsf)
1551 struct ip6_sf_list *psf_prev, *psf_next, *psf;
1554 for (psf=*ppsf; psf; psf = psf_next) {
1555 psf_next = psf->sf_next;
1556 if (psf->sf_crcount == 0) {
1558 psf_prev->sf_next = psf->sf_next;
1560 *ppsf = psf->sf_next;
1567 static void mld_send_cr(struct inet6_dev *idev)
1569 struct ifmcaddr6 *pmc, *pmc_prev, *pmc_next;
1570 struct sk_buff *skb = NULL;
1573 read_lock_bh(&idev->lock);
1574 write_lock_bh(&idev->mc_lock);
1578 for (pmc=idev->mc_tomb; pmc; pmc=pmc_next) {
1579 pmc_next = pmc->next;
1580 if (pmc->mca_sfmode == MCAST_INCLUDE) {
1581 type = MLD2_BLOCK_OLD_SOURCES;
1582 dtype = MLD2_BLOCK_OLD_SOURCES;
1583 skb = add_grec(skb, pmc, type, 1, 0);
1584 skb = add_grec(skb, pmc, dtype, 1, 1);
1586 if (pmc->mca_crcount) {
1588 if (pmc->mca_sfmode == MCAST_EXCLUDE) {
1589 type = MLD2_CHANGE_TO_INCLUDE;
1590 skb = add_grec(skb, pmc, type, 1, 0);
1592 if (pmc->mca_crcount == 0) {
1593 mld_clear_zeros(&pmc->mca_tomb);
1594 mld_clear_zeros(&pmc->mca_sources);
1597 if (pmc->mca_crcount == 0 && !pmc->mca_tomb &&
1598 !pmc->mca_sources) {
1600 pmc_prev->next = pmc_next;
1602 idev->mc_tomb = pmc_next;
1603 in6_dev_put(pmc->idev);
1608 write_unlock_bh(&idev->mc_lock);
1611 for (pmc=idev->mc_list; pmc; pmc=pmc->next) {
1612 spin_lock_bh(&pmc->mca_lock);
1613 if (pmc->mca_sfcount[MCAST_EXCLUDE]) {
1614 type = MLD2_BLOCK_OLD_SOURCES;
1615 dtype = MLD2_ALLOW_NEW_SOURCES;
1617 type = MLD2_ALLOW_NEW_SOURCES;
1618 dtype = MLD2_BLOCK_OLD_SOURCES;
1620 skb = add_grec(skb, pmc, type, 0, 0);
1621 skb = add_grec(skb, pmc, dtype, 0, 1); /* deleted sources */
1623 /* filter mode changes */
1624 if (pmc->mca_crcount) {
1626 if (pmc->mca_sfmode == MCAST_EXCLUDE)
1627 type = MLD2_CHANGE_TO_EXCLUDE;
1629 type = MLD2_CHANGE_TO_INCLUDE;
1630 skb = add_grec(skb, pmc, type, 0, 0);
1632 spin_unlock_bh(&pmc->mca_lock);
1634 read_unlock_bh(&idev->lock);
1637 (void) mld_sendpack(skb);
1640 static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type)
1642 struct sock *sk = igmp6_socket->sk;
1643 struct inet6_dev *idev;
1644 struct sk_buff *skb;
1645 struct icmp6hdr *hdr;
1646 struct in6_addr *snd_addr;
1647 struct in6_addr *addrp;
1648 struct in6_addr addr_buf;
1649 struct in6_addr all_routers;
1650 int err, len, payload_len, full_len;
1651 u8 ra[8] = { IPPROTO_ICMPV6, 0,
1652 IPV6_TLV_ROUTERALERT, 2, 0, 0,
1655 IP6_INC_STATS(IPSTATS_MIB_OUTREQUESTS);
1657 if (type == ICMPV6_MGM_REDUCTION) {
1658 snd_addr = &all_routers;
1659 ipv6_addr_all_routers(&all_routers);
1662 len = sizeof(struct icmp6hdr) + sizeof(struct in6_addr);
1663 payload_len = len + sizeof(ra);
1664 full_len = sizeof(struct ipv6hdr) + payload_len;
1666 skb = sock_alloc_send_skb(sk, LL_RESERVED_SPACE(dev) + full_len, 1, &err);
1669 IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
1673 skb_reserve(skb, LL_RESERVED_SPACE(dev));
1675 if (ipv6_get_lladdr(dev, &addr_buf)) {
1676 /* <draft-ietf-magma-mld-source-05.txt>:
1677 * use unspecified address as the source address
1678 * when a valid link-local address is not available.
1680 memset(&addr_buf, 0, sizeof(addr_buf));
1683 ip6_nd_hdr(sk, skb, dev, &addr_buf, snd_addr, NEXTHDR_HOP, payload_len);
1685 memcpy(skb_put(skb, sizeof(ra)), ra, sizeof(ra));
1687 hdr = (struct icmp6hdr *) skb_put(skb, sizeof(struct icmp6hdr));
1688 memset(hdr, 0, sizeof(struct icmp6hdr));
1689 hdr->icmp6_type = type;
1691 addrp = (struct in6_addr *) skb_put(skb, sizeof(struct in6_addr));
1692 ipv6_addr_copy(addrp, addr);
1694 hdr->icmp6_cksum = csum_ipv6_magic(&addr_buf, snd_addr, len,
1696 csum_partial((__u8 *) hdr, len, 0));
1698 idev = in6_dev_get(skb->dev);
1700 err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, skb->dev,
1701 mld_dev_queue_xmit);
1703 if (type == ICMPV6_MGM_REDUCTION)
1704 ICMP6_INC_STATS(idev, ICMP6_MIB_OUTGROUPMEMBREDUCTIONS);
1706 ICMP6_INC_STATS(idev, ICMP6_MIB_OUTGROUPMEMBRESPONSES);
1707 ICMP6_INC_STATS(idev, ICMP6_MIB_OUTMSGS);
1708 IP6_INC_STATS(IPSTATS_MIB_OUTMCASTPKTS);
1710 IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
1712 if (likely(idev != NULL))
1717 static int ip6_mc_del1_src(struct ifmcaddr6 *pmc, int sfmode,
1718 struct in6_addr *psfsrc)
1720 struct ip6_sf_list *psf, *psf_prev;
1724 for (psf=pmc->mca_sources; psf; psf=psf->sf_next) {
1725 if (ipv6_addr_equal(&psf->sf_addr, psfsrc))
1729 if (!psf || psf->sf_count[sfmode] == 0) {
1730 /* source filter not found, or count wrong => bug */
1733 psf->sf_count[sfmode]--;
1734 if (!psf->sf_count[MCAST_INCLUDE] && !psf->sf_count[MCAST_EXCLUDE]) {
1735 struct inet6_dev *idev = pmc->idev;
1737 /* no more filters for this source */
1739 psf_prev->sf_next = psf->sf_next;
1741 pmc->mca_sources = psf->sf_next;
1742 if (psf->sf_oldin && !(pmc->mca_flags & MAF_NOREPORT) &&
1743 !MLD_V1_SEEN(idev)) {
1744 psf->sf_crcount = idev->mc_qrv;
1745 psf->sf_next = pmc->mca_tomb;
1746 pmc->mca_tomb = psf;
1754 static int ip6_mc_del_src(struct inet6_dev *idev, struct in6_addr *pmca,
1755 int sfmode, int sfcount, struct in6_addr *psfsrc,
1758 struct ifmcaddr6 *pmc;
1764 read_lock_bh(&idev->lock);
1765 for (pmc=idev->mc_list; pmc; pmc=pmc->next) {
1766 if (ipv6_addr_equal(pmca, &pmc->mca_addr))
1770 /* MCA not found?? bug */
1771 read_unlock_bh(&idev->lock);
1774 spin_lock_bh(&pmc->mca_lock);
1777 if (!pmc->mca_sfcount[sfmode]) {
1778 spin_unlock_bh(&pmc->mca_lock);
1779 read_unlock_bh(&idev->lock);
1782 pmc->mca_sfcount[sfmode]--;
1785 for (i=0; i<sfcount; i++) {
1786 int rv = ip6_mc_del1_src(pmc, sfmode, &psfsrc[i]);
1788 changerec |= rv > 0;
1792 if (pmc->mca_sfmode == MCAST_EXCLUDE &&
1793 pmc->mca_sfcount[MCAST_EXCLUDE] == 0 &&
1794 pmc->mca_sfcount[MCAST_INCLUDE]) {
1795 struct ip6_sf_list *psf;
1797 /* filter mode change */
1798 pmc->mca_sfmode = MCAST_INCLUDE;
1799 pmc->mca_crcount = idev->mc_qrv;
1800 idev->mc_ifc_count = pmc->mca_crcount;
1801 for (psf=pmc->mca_sources; psf; psf = psf->sf_next)
1802 psf->sf_crcount = 0;
1803 mld_ifc_event(pmc->idev);
1804 } else if (sf_setstate(pmc) || changerec)
1805 mld_ifc_event(pmc->idev);
1806 spin_unlock_bh(&pmc->mca_lock);
1807 read_unlock_bh(&idev->lock);
1812 * Add multicast single-source filter to the interface list
1814 static int ip6_mc_add1_src(struct ifmcaddr6 *pmc, int sfmode,
1815 struct in6_addr *psfsrc, int delta)
1817 struct ip6_sf_list *psf, *psf_prev;
1820 for (psf=pmc->mca_sources; psf; psf=psf->sf_next) {
1821 if (ipv6_addr_equal(&psf->sf_addr, psfsrc))
1826 psf = (struct ip6_sf_list *)kmalloc(sizeof(*psf), GFP_ATOMIC);
1829 memset(psf, 0, sizeof(*psf));
1830 psf->sf_addr = *psfsrc;
1832 psf_prev->sf_next = psf;
1834 pmc->mca_sources = psf;
1836 psf->sf_count[sfmode]++;
1840 static void sf_markstate(struct ifmcaddr6 *pmc)
1842 struct ip6_sf_list *psf;
1843 int mca_xcount = pmc->mca_sfcount[MCAST_EXCLUDE];
1845 for (psf=pmc->mca_sources; psf; psf=psf->sf_next)
1846 if (pmc->mca_sfcount[MCAST_EXCLUDE]) {
1847 psf->sf_oldin = mca_xcount ==
1848 psf->sf_count[MCAST_EXCLUDE] &&
1849 !psf->sf_count[MCAST_INCLUDE];
1851 psf->sf_oldin = psf->sf_count[MCAST_INCLUDE] != 0;
1854 static int sf_setstate(struct ifmcaddr6 *pmc)
1856 struct ip6_sf_list *psf;
1857 int mca_xcount = pmc->mca_sfcount[MCAST_EXCLUDE];
1858 int qrv = pmc->idev->mc_qrv;
1862 for (psf=pmc->mca_sources; psf; psf=psf->sf_next) {
1863 if (pmc->mca_sfcount[MCAST_EXCLUDE]) {
1864 new_in = mca_xcount == psf->sf_count[MCAST_EXCLUDE] &&
1865 !psf->sf_count[MCAST_INCLUDE];
1867 new_in = psf->sf_count[MCAST_INCLUDE] != 0;
1868 if (new_in != psf->sf_oldin) {
1869 psf->sf_crcount = qrv;
1877 * Add multicast source filter list to the interface list
1879 static int ip6_mc_add_src(struct inet6_dev *idev, struct in6_addr *pmca,
1880 int sfmode, int sfcount, struct in6_addr *psfsrc,
1883 struct ifmcaddr6 *pmc;
1889 read_lock_bh(&idev->lock);
1890 for (pmc=idev->mc_list; pmc; pmc=pmc->next) {
1891 if (ipv6_addr_equal(pmca, &pmc->mca_addr))
1895 /* MCA not found?? bug */
1896 read_unlock_bh(&idev->lock);
1899 spin_lock_bh(&pmc->mca_lock);
1902 isexclude = pmc->mca_sfmode == MCAST_EXCLUDE;
1904 pmc->mca_sfcount[sfmode]++;
1906 for (i=0; i<sfcount; i++) {
1907 err = ip6_mc_add1_src(pmc, sfmode, &psfsrc[i], delta);
1915 pmc->mca_sfcount[sfmode]--;
1917 (void) ip6_mc_del1_src(pmc, sfmode, &psfsrc[i]);
1918 } else if (isexclude != (pmc->mca_sfcount[MCAST_EXCLUDE] != 0)) {
1919 struct inet6_dev *idev = pmc->idev;
1920 struct ip6_sf_list *psf;
1922 /* filter mode change */
1923 if (pmc->mca_sfcount[MCAST_EXCLUDE])
1924 pmc->mca_sfmode = MCAST_EXCLUDE;
1925 else if (pmc->mca_sfcount[MCAST_INCLUDE])
1926 pmc->mca_sfmode = MCAST_INCLUDE;
1927 /* else no filters; keep old mode for reports */
1929 pmc->mca_crcount = idev->mc_qrv;
1930 idev->mc_ifc_count = pmc->mca_crcount;
1931 for (psf=pmc->mca_sources; psf; psf = psf->sf_next)
1932 psf->sf_crcount = 0;
1933 mld_ifc_event(idev);
1934 } else if (sf_setstate(pmc))
1935 mld_ifc_event(idev);
1936 spin_unlock_bh(&pmc->mca_lock);
1937 read_unlock_bh(&idev->lock);
1941 static void ip6_mc_clear_src(struct ifmcaddr6 *pmc)
1943 struct ip6_sf_list *psf, *nextpsf;
1945 for (psf=pmc->mca_tomb; psf; psf=nextpsf) {
1946 nextpsf = psf->sf_next;
1949 pmc->mca_tomb = NULL;
1950 for (psf=pmc->mca_sources; psf; psf=nextpsf) {
1951 nextpsf = psf->sf_next;
1954 pmc->mca_sources = NULL;
1955 pmc->mca_sfmode = MCAST_EXCLUDE;
1956 pmc->mca_sfcount[MCAST_EXCLUDE] = 0;
1957 pmc->mca_sfcount[MCAST_EXCLUDE] = 1;
1961 static void igmp6_join_group(struct ifmcaddr6 *ma)
1963 unsigned long delay;
1965 if (ma->mca_flags & MAF_NOREPORT)
1968 igmp6_send(&ma->mca_addr, ma->idev->dev, ICMPV6_MGM_REPORT);
1970 delay = net_random() % IGMP6_UNSOLICITED_IVAL;
1972 spin_lock_bh(&ma->mca_lock);
1973 if (del_timer(&ma->mca_timer)) {
1974 atomic_dec(&ma->mca_refcnt);
1975 delay = ma->mca_timer.expires - jiffies;
1978 if (!mod_timer(&ma->mca_timer, jiffies + delay))
1979 atomic_inc(&ma->mca_refcnt);
1980 ma->mca_flags |= MAF_TIMER_RUNNING | MAF_LAST_REPORTER;
1981 spin_unlock_bh(&ma->mca_lock);
1984 static int ip6_mc_leave_src(struct sock *sk, struct ipv6_mc_socklist *iml,
1985 struct inet6_dev *idev)
1989 if (iml->sflist == 0) {
1990 /* any-source empty exclude case */
1991 return ip6_mc_del_src(idev, &iml->addr, iml->sfmode, 0, NULL, 0);
1993 err = ip6_mc_del_src(idev, &iml->addr, iml->sfmode,
1994 iml->sflist->sl_count, iml->sflist->sl_addr, 0);
1995 sock_kfree_s(sk, iml->sflist, IP6_SFLSIZE(iml->sflist->sl_max));
2000 static void igmp6_leave_group(struct ifmcaddr6 *ma)
2002 if (MLD_V1_SEEN(ma->idev)) {
2003 if (ma->mca_flags & MAF_LAST_REPORTER)
2004 igmp6_send(&ma->mca_addr, ma->idev->dev,
2005 ICMPV6_MGM_REDUCTION);
2007 mld_add_delrec(ma->idev, ma);
2008 mld_ifc_event(ma->idev);
2012 static void mld_gq_timer_expire(unsigned long data)
2014 struct inet6_dev *idev = (struct inet6_dev *)data;
2016 idev->mc_gq_running = 0;
2017 mld_send_report(idev, NULL);
2018 __in6_dev_put(idev);
2021 static void mld_ifc_timer_expire(unsigned long data)
2023 struct inet6_dev *idev = (struct inet6_dev *)data;
2026 if (idev->mc_ifc_count) {
2027 idev->mc_ifc_count--;
2028 if (idev->mc_ifc_count)
2029 mld_ifc_start_timer(idev, idev->mc_maxdelay);
2031 __in6_dev_put(idev);
2034 static void mld_ifc_event(struct inet6_dev *idev)
2036 if (MLD_V1_SEEN(idev))
2038 idev->mc_ifc_count = idev->mc_qrv;
2039 mld_ifc_start_timer(idev, 1);
2043 static void igmp6_timer_handler(unsigned long data)
2045 struct ifmcaddr6 *ma = (struct ifmcaddr6 *) data;
2047 if (MLD_V1_SEEN(ma->idev))
2048 igmp6_send(&ma->mca_addr, ma->idev->dev, ICMPV6_MGM_REPORT);
2050 mld_send_report(ma->idev, ma);
2052 spin_lock(&ma->mca_lock);
2053 ma->mca_flags |= MAF_LAST_REPORTER;
2054 ma->mca_flags &= ~MAF_TIMER_RUNNING;
2055 spin_unlock(&ma->mca_lock);
2059 /* Device going down */
2061 void ipv6_mc_down(struct inet6_dev *idev)
2063 struct ifmcaddr6 *i;
2065 /* Withdraw multicast list */
2067 read_lock_bh(&idev->lock);
2068 idev->mc_ifc_count = 0;
2069 if (del_timer(&idev->mc_ifc_timer))
2070 __in6_dev_put(idev);
2071 idev->mc_gq_running = 0;
2072 if (del_timer(&idev->mc_gq_timer))
2073 __in6_dev_put(idev);
2075 for (i = idev->mc_list; i; i=i->next)
2076 igmp6_group_dropped(i);
2077 read_unlock_bh(&idev->lock);
2079 mld_clear_delrec(idev);
2083 /* Device going up */
2085 void ipv6_mc_up(struct inet6_dev *idev)
2087 struct ifmcaddr6 *i;
2089 /* Install multicast list, except for all-nodes (already installed) */
2091 read_lock_bh(&idev->lock);
2092 for (i = idev->mc_list; i; i=i->next)
2093 igmp6_group_added(i);
2094 read_unlock_bh(&idev->lock);
2097 /* IPv6 device initialization. */
2099 void ipv6_mc_init_dev(struct inet6_dev *idev)
2101 struct in6_addr maddr;
2103 write_lock_bh(&idev->lock);
2104 rwlock_init(&idev->mc_lock);
2105 idev->mc_gq_running = 0;
2106 init_timer(&idev->mc_gq_timer);
2107 idev->mc_gq_timer.data = (unsigned long) idev;
2108 idev->mc_gq_timer.function = &mld_gq_timer_expire;
2109 idev->mc_tomb = NULL;
2110 idev->mc_ifc_count = 0;
2111 init_timer(&idev->mc_ifc_timer);
2112 idev->mc_ifc_timer.data = (unsigned long) idev;
2113 idev->mc_ifc_timer.function = &mld_ifc_timer_expire;
2114 idev->mc_qrv = MLD_QRV_DEFAULT;
2115 idev->mc_maxdelay = IGMP6_UNSOLICITED_IVAL;
2116 idev->mc_v1_seen = 0;
2117 write_unlock_bh(&idev->lock);
2119 /* Add all-nodes address. */
2120 ipv6_addr_all_nodes(&maddr);
2121 ipv6_dev_mc_inc(idev->dev, &maddr);
2125 * Device is about to be destroyed: clean up.
2128 void ipv6_mc_destroy_dev(struct inet6_dev *idev)
2130 struct ifmcaddr6 *i;
2131 struct in6_addr maddr;
2133 /* Deactivate timers */
2136 /* Delete all-nodes address. */
2137 ipv6_addr_all_nodes(&maddr);
2139 /* We cannot call ipv6_dev_mc_dec() directly, our caller in
2140 * addrconf.c has NULL'd out dev->ip6_ptr so in6_dev_get() will
2143 __ipv6_dev_mc_dec(idev, &maddr);
2145 if (idev->cnf.forwarding) {
2146 ipv6_addr_all_routers(&maddr);
2147 __ipv6_dev_mc_dec(idev, &maddr);
2150 write_lock_bh(&idev->lock);
2151 while ((i = idev->mc_list) != NULL) {
2152 idev->mc_list = i->next;
2153 write_unlock_bh(&idev->lock);
2155 igmp6_group_dropped(i);
2158 write_lock_bh(&idev->lock);
2160 write_unlock_bh(&idev->lock);
2163 #ifdef CONFIG_PROC_FS
2164 struct igmp6_mc_iter_state {
2165 struct net_device *dev;
2166 struct inet6_dev *idev;
2169 #define igmp6_mc_seq_private(seq) ((struct igmp6_mc_iter_state *)(seq)->private)
2171 static inline struct ifmcaddr6 *igmp6_mc_get_first(struct seq_file *seq)
2173 struct ifmcaddr6 *im = NULL;
2174 struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq);
2176 for (state->dev = dev_base, state->idev = NULL;
2178 state->dev = state->dev->next) {
2179 struct inet6_dev *idev;
2180 idev = in6_dev_get(state->dev);
2183 read_lock_bh(&idev->lock);
2189 read_unlock_bh(&idev->lock);
2195 static struct ifmcaddr6 *igmp6_mc_get_next(struct seq_file *seq, struct ifmcaddr6 *im)
2197 struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq);
2201 if (likely(state->idev != NULL)) {
2202 read_unlock_bh(&state->idev->lock);
2203 in6_dev_put(state->idev);
2205 state->dev = state->dev->next;
2210 state->idev = in6_dev_get(state->dev);
2213 read_lock_bh(&state->idev->lock);
2214 im = state->idev->mc_list;
2219 static struct ifmcaddr6 *igmp6_mc_get_idx(struct seq_file *seq, loff_t pos)
2221 struct ifmcaddr6 *im = igmp6_mc_get_first(seq);
2223 while (pos && (im = igmp6_mc_get_next(seq, im)) != NULL)
2225 return pos ? NULL : im;
2228 static void *igmp6_mc_seq_start(struct seq_file *seq, loff_t *pos)
2230 read_lock(&dev_base_lock);
2231 return igmp6_mc_get_idx(seq, *pos);
2234 static void *igmp6_mc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2236 struct ifmcaddr6 *im;
2237 im = igmp6_mc_get_next(seq, v);
2242 static void igmp6_mc_seq_stop(struct seq_file *seq, void *v)
2244 struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq);
2245 if (likely(state->idev != NULL)) {
2246 read_unlock_bh(&state->idev->lock);
2247 in6_dev_put(state->idev);
2251 read_unlock(&dev_base_lock);
2254 static int igmp6_mc_seq_show(struct seq_file *seq, void *v)
2256 struct ifmcaddr6 *im = (struct ifmcaddr6 *)v;
2257 struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq);
2260 "%-4d %-15s %04x%04x%04x%04x%04x%04x%04x%04x %5d %08X %ld\n",
2261 state->dev->ifindex, state->dev->name,
2263 im->mca_users, im->mca_flags,
2264 (im->mca_flags&MAF_TIMER_RUNNING) ?
2265 jiffies_to_clock_t(im->mca_timer.expires-jiffies) : 0);
2269 static struct seq_operations igmp6_mc_seq_ops = {
2270 .start = igmp6_mc_seq_start,
2271 .next = igmp6_mc_seq_next,
2272 .stop = igmp6_mc_seq_stop,
2273 .show = igmp6_mc_seq_show,
2276 static int igmp6_mc_seq_open(struct inode *inode, struct file *file)
2278 struct seq_file *seq;
2280 struct igmp6_mc_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL);
2285 rc = seq_open(file, &igmp6_mc_seq_ops);
2289 seq = file->private_data;
2291 memset(s, 0, sizeof(*s));
2299 static struct file_operations igmp6_mc_seq_fops = {
2300 .owner = THIS_MODULE,
2301 .open = igmp6_mc_seq_open,
2303 .llseek = seq_lseek,
2304 .release = seq_release_private,
2307 struct igmp6_mcf_iter_state {
2308 struct net_device *dev;
2309 struct inet6_dev *idev;
2310 struct ifmcaddr6 *im;
2313 #define igmp6_mcf_seq_private(seq) ((struct igmp6_mcf_iter_state *)(seq)->private)
2315 static inline struct ip6_sf_list *igmp6_mcf_get_first(struct seq_file *seq)
2317 struct ip6_sf_list *psf = NULL;
2318 struct ifmcaddr6 *im = NULL;
2319 struct igmp6_mcf_iter_state *state = igmp6_mcf_seq_private(seq);
2321 for (state->dev = dev_base, state->idev = NULL, state->im = NULL;
2323 state->dev = state->dev->next) {
2324 struct inet6_dev *idev;
2325 idev = in6_dev_get(state->dev);
2326 if (unlikely(idev == NULL))
2328 read_lock_bh(&idev->lock);
2330 if (likely(im != NULL)) {
2331 spin_lock_bh(&im->mca_lock);
2332 psf = im->mca_sources;
2333 if (likely(psf != NULL)) {
2338 spin_unlock_bh(&im->mca_lock);
2340 read_unlock_bh(&idev->lock);
2346 static struct ip6_sf_list *igmp6_mcf_get_next(struct seq_file *seq, struct ip6_sf_list *psf)
2348 struct igmp6_mcf_iter_state *state = igmp6_mcf_seq_private(seq);
2352 spin_unlock_bh(&state->im->mca_lock);
2353 state->im = state->im->next;
2354 while (!state->im) {
2355 if (likely(state->idev != NULL)) {
2356 read_unlock_bh(&state->idev->lock);
2357 in6_dev_put(state->idev);
2359 state->dev = state->dev->next;
2364 state->idev = in6_dev_get(state->dev);
2367 read_lock_bh(&state->idev->lock);
2368 state->im = state->idev->mc_list;
2372 spin_lock_bh(&state->im->mca_lock);
2373 psf = state->im->mca_sources;
2379 static struct ip6_sf_list *igmp6_mcf_get_idx(struct seq_file *seq, loff_t pos)
2381 struct ip6_sf_list *psf = igmp6_mcf_get_first(seq);
2383 while (pos && (psf = igmp6_mcf_get_next(seq, psf)) != NULL)
2385 return pos ? NULL : psf;
2388 static void *igmp6_mcf_seq_start(struct seq_file *seq, loff_t *pos)
2390 read_lock(&dev_base_lock);
2391 return *pos ? igmp6_mcf_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
2394 static void *igmp6_mcf_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2396 struct ip6_sf_list *psf;
2397 if (v == SEQ_START_TOKEN)
2398 psf = igmp6_mcf_get_first(seq);
2400 psf = igmp6_mcf_get_next(seq, v);
2405 static void igmp6_mcf_seq_stop(struct seq_file *seq, void *v)
2407 struct igmp6_mcf_iter_state *state = igmp6_mcf_seq_private(seq);
2408 if (likely(state->im != NULL)) {
2409 spin_unlock_bh(&state->im->mca_lock);
2412 if (likely(state->idev != NULL)) {
2413 read_unlock_bh(&state->idev->lock);
2414 in6_dev_put(state->idev);
2418 read_unlock(&dev_base_lock);
2421 static int igmp6_mcf_seq_show(struct seq_file *seq, void *v)
2423 struct ip6_sf_list *psf = (struct ip6_sf_list *)v;
2424 struct igmp6_mcf_iter_state *state = igmp6_mcf_seq_private(seq);
2426 if (v == SEQ_START_TOKEN) {
2429 "%32s %32s %6s %6s\n", "Idx",
2430 "Device", "Multicast Address",
2431 "Source Address", "INC", "EXC");
2435 "%04x%04x%04x%04x%04x%04x%04x%04x "
2436 "%04x%04x%04x%04x%04x%04x%04x%04x "
2438 state->dev->ifindex, state->dev->name,
2439 NIP6(state->im->mca_addr),
2441 psf->sf_count[MCAST_INCLUDE],
2442 psf->sf_count[MCAST_EXCLUDE]);
2447 static struct seq_operations igmp6_mcf_seq_ops = {
2448 .start = igmp6_mcf_seq_start,
2449 .next = igmp6_mcf_seq_next,
2450 .stop = igmp6_mcf_seq_stop,
2451 .show = igmp6_mcf_seq_show,
2454 static int igmp6_mcf_seq_open(struct inode *inode, struct file *file)
2456 struct seq_file *seq;
2458 struct igmp6_mcf_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL);
2463 rc = seq_open(file, &igmp6_mcf_seq_ops);
2467 seq = file->private_data;
2469 memset(s, 0, sizeof(*s));
2477 static struct file_operations igmp6_mcf_seq_fops = {
2478 .owner = THIS_MODULE,
2479 .open = igmp6_mcf_seq_open,
2481 .llseek = seq_lseek,
2482 .release = seq_release_private,
2486 int __init igmp6_init(struct net_proto_family *ops)
2488 struct ipv6_pinfo *np;
2492 err = sock_create_kern(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6, &igmp6_socket);
2495 "Failed to initialize the IGMP6 control socket (err %d).\n",
2497 igmp6_socket = NULL; /* For safety. */
2501 sk = igmp6_socket->sk;
2502 sk->sk_allocation = GFP_ATOMIC;
2503 sk->sk_prot->unhash(sk);
2508 #ifdef CONFIG_PROC_FS
2509 proc_net_fops_create("igmp6", S_IRUGO, &igmp6_mc_seq_fops);
2510 proc_net_fops_create("mcfilter6", S_IRUGO, &igmp6_mcf_seq_fops);
2516 void igmp6_cleanup(void)
2518 sock_release(igmp6_socket);
2519 igmp6_socket = NULL; /* for safety */
2521 #ifdef CONFIG_PROC_FS
2522 proc_net_remove("mcfilter6");
2523 proc_net_remove("igmp6");