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));
1304 if (dev->hard_header) {
1305 unsigned char ha[MAX_ADDR_LEN];
1307 ndisc_mc_map(&mld2_all_mcr, ha, dev, 1);
1308 if (dev->hard_header(skb, dev, ETH_P_IPV6,ha,NULL,size) < 0) {
1314 if (ipv6_get_lladdr(dev, &addr_buf)) {
1315 /* <draft-ietf-magma-mld-source-05.txt>:
1316 * use unspecified address as the source address
1317 * when a valid link-local address is not available.
1319 memset(&addr_buf, 0, sizeof(addr_buf));
1322 ip6_nd_hdr(sk, skb, dev, &addr_buf, &mld2_all_mcr, NEXTHDR_HOP, 0);
1324 memcpy(skb_put(skb, sizeof(ra)), ra, sizeof(ra));
1326 pmr =(struct mld2_report *)skb_put(skb, sizeof(*pmr));
1327 skb->h.raw = (unsigned char *)pmr;
1328 pmr->type = ICMPV6_MLD2_REPORT;
1336 static void mld_sendpack(struct sk_buff *skb)
1338 struct ipv6hdr *pip6 = skb->nh.ipv6h;
1339 struct mld2_report *pmr = (struct mld2_report *)skb->h.raw;
1340 int payload_len, mldlen;
1341 struct inet6_dev *idev = in6_dev_get(skb->dev);
1344 IP6_INC_STATS(IPSTATS_MIB_OUTREQUESTS);
1345 payload_len = skb->tail - (unsigned char *)skb->nh.ipv6h -
1346 sizeof(struct ipv6hdr);
1347 mldlen = skb->tail - skb->h.raw;
1348 pip6->payload_len = htons(payload_len);
1350 pmr->csum = csum_ipv6_magic(&pip6->saddr, &pip6->daddr, mldlen,
1351 IPPROTO_ICMPV6, csum_partial(skb->h.raw, mldlen, 0));
1352 err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, skb->dev,
1355 ICMP6_INC_STATS(idev,ICMP6_MIB_OUTMSGS);
1356 IP6_INC_STATS(IPSTATS_MIB_OUTMCASTPKTS);
1358 IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
1360 if (likely(idev != NULL))
1364 static int grec_size(struct ifmcaddr6 *pmc, int type, int gdel, int sdel)
1366 return sizeof(struct mld2_grec) + 4*mld_scount(pmc,type,gdel,sdel);
1369 static struct sk_buff *add_grhead(struct sk_buff *skb, struct ifmcaddr6 *pmc,
1370 int type, struct mld2_grec **ppgr)
1372 struct net_device *dev = pmc->idev->dev;
1373 struct mld2_report *pmr;
1374 struct mld2_grec *pgr;
1377 skb = mld_newpack(dev, dev->mtu);
1380 pgr = (struct mld2_grec *)skb_put(skb, sizeof(struct mld2_grec));
1381 pgr->grec_type = type;
1382 pgr->grec_auxwords = 0;
1383 pgr->grec_nsrcs = 0;
1384 pgr->grec_mca = pmc->mca_addr; /* structure copy */
1385 pmr = (struct mld2_report *)skb->h.raw;
1386 pmr->ngrec = htons(ntohs(pmr->ngrec)+1);
1391 #define AVAILABLE(skb) ((skb) ? ((skb)->dev ? (skb)->dev->mtu - (skb)->len : \
1392 skb_tailroom(skb)) : 0)
1394 static struct sk_buff *add_grec(struct sk_buff *skb, struct ifmcaddr6 *pmc,
1395 int type, int gdeleted, int sdeleted)
1397 struct net_device *dev = pmc->idev->dev;
1398 struct mld2_report *pmr;
1399 struct mld2_grec *pgr = NULL;
1400 struct ip6_sf_list *psf, *psf_next, *psf_prev, **psf_list;
1401 int scount, first, isquery, truncate;
1403 if (pmc->mca_flags & MAF_NOREPORT)
1406 isquery = type == MLD2_MODE_IS_INCLUDE ||
1407 type == MLD2_MODE_IS_EXCLUDE;
1408 truncate = type == MLD2_MODE_IS_EXCLUDE ||
1409 type == MLD2_CHANGE_TO_EXCLUDE;
1411 psf_list = sdeleted ? &pmc->mca_tomb : &pmc->mca_sources;
1414 if (type == MLD2_ALLOW_NEW_SOURCES ||
1415 type == MLD2_BLOCK_OLD_SOURCES)
1417 if (pmc->mca_crcount || isquery) {
1418 /* make sure we have room for group header and at
1421 if (skb && AVAILABLE(skb) < sizeof(struct mld2_grec)+
1422 sizeof(struct in6_addr)) {
1424 skb = NULL; /* add_grhead will get a new one */
1426 skb = add_grhead(skb, pmc, type, &pgr);
1430 pmr = skb ? (struct mld2_report *)skb->h.raw : NULL;
1432 /* EX and TO_EX get a fresh packet, if needed */
1434 if (pmr && pmr->ngrec &&
1435 AVAILABLE(skb) < grec_size(pmc, type, gdeleted, sdeleted)) {
1438 skb = mld_newpack(dev, dev->mtu);
1444 for (psf=*psf_list; psf; psf=psf_next) {
1445 struct in6_addr *psrc;
1447 psf_next = psf->sf_next;
1449 if (!is_in(pmc, psf, type, gdeleted, sdeleted)) {
1454 /* clear marks on query responses */
1458 if (AVAILABLE(skb) < sizeof(*psrc) +
1459 first*sizeof(struct mld2_grec)) {
1460 if (truncate && !first)
1461 break; /* truncate these */
1463 pgr->grec_nsrcs = htons(scount);
1466 skb = mld_newpack(dev, dev->mtu);
1471 skb = add_grhead(skb, pmc, type, &pgr);
1474 psrc = (struct in6_addr *)skb_put(skb, sizeof(*psrc));
1475 *psrc = psf->sf_addr;
1477 if ((type == MLD2_ALLOW_NEW_SOURCES ||
1478 type == MLD2_BLOCK_OLD_SOURCES) && psf->sf_crcount) {
1480 if ((sdeleted || gdeleted) && psf->sf_crcount == 0) {
1482 psf_prev->sf_next = psf->sf_next;
1484 *psf_list = psf->sf_next;
1492 pgr->grec_nsrcs = htons(scount);
1495 pmc->mca_flags &= ~MAF_GSQUERY; /* clear query state */
1499 static void mld_send_report(struct inet6_dev *idev, struct ifmcaddr6 *pmc)
1501 struct sk_buff *skb = NULL;
1505 read_lock_bh(&idev->lock);
1506 for (pmc=idev->mc_list; pmc; pmc=pmc->next) {
1507 if (pmc->mca_flags & MAF_NOREPORT)
1509 spin_lock_bh(&pmc->mca_lock);
1510 if (pmc->mca_sfcount[MCAST_EXCLUDE])
1511 type = MLD2_MODE_IS_EXCLUDE;
1513 type = MLD2_MODE_IS_INCLUDE;
1514 skb = add_grec(skb, pmc, type, 0, 0);
1515 spin_unlock_bh(&pmc->mca_lock);
1517 read_unlock_bh(&idev->lock);
1519 spin_lock_bh(&pmc->mca_lock);
1520 if (pmc->mca_sfcount[MCAST_EXCLUDE])
1521 type = MLD2_MODE_IS_EXCLUDE;
1523 type = MLD2_MODE_IS_INCLUDE;
1524 skb = add_grec(skb, pmc, type, 0, 0);
1525 spin_unlock_bh(&pmc->mca_lock);
1532 * remove zero-count source records from a source filter list
1534 static void mld_clear_zeros(struct ip6_sf_list **ppsf)
1536 struct ip6_sf_list *psf_prev, *psf_next, *psf;
1539 for (psf=*ppsf; psf; psf = psf_next) {
1540 psf_next = psf->sf_next;
1541 if (psf->sf_crcount == 0) {
1543 psf_prev->sf_next = psf->sf_next;
1545 *ppsf = psf->sf_next;
1552 static void mld_send_cr(struct inet6_dev *idev)
1554 struct ifmcaddr6 *pmc, *pmc_prev, *pmc_next;
1555 struct sk_buff *skb = NULL;
1558 read_lock_bh(&idev->lock);
1559 write_lock_bh(&idev->mc_lock);
1563 for (pmc=idev->mc_tomb; pmc; pmc=pmc_next) {
1564 pmc_next = pmc->next;
1565 if (pmc->mca_sfmode == MCAST_INCLUDE) {
1566 type = MLD2_BLOCK_OLD_SOURCES;
1567 dtype = MLD2_BLOCK_OLD_SOURCES;
1568 skb = add_grec(skb, pmc, type, 1, 0);
1569 skb = add_grec(skb, pmc, dtype, 1, 1);
1571 if (pmc->mca_crcount) {
1573 if (pmc->mca_sfmode == MCAST_EXCLUDE) {
1574 type = MLD2_CHANGE_TO_INCLUDE;
1575 skb = add_grec(skb, pmc, type, 1, 0);
1577 if (pmc->mca_crcount == 0) {
1578 mld_clear_zeros(&pmc->mca_tomb);
1579 mld_clear_zeros(&pmc->mca_sources);
1582 if (pmc->mca_crcount == 0 && !pmc->mca_tomb &&
1583 !pmc->mca_sources) {
1585 pmc_prev->next = pmc_next;
1587 idev->mc_tomb = pmc_next;
1588 in6_dev_put(pmc->idev);
1593 write_unlock_bh(&idev->mc_lock);
1596 for (pmc=idev->mc_list; pmc; pmc=pmc->next) {
1597 spin_lock_bh(&pmc->mca_lock);
1598 if (pmc->mca_sfcount[MCAST_EXCLUDE]) {
1599 type = MLD2_BLOCK_OLD_SOURCES;
1600 dtype = MLD2_ALLOW_NEW_SOURCES;
1602 type = MLD2_ALLOW_NEW_SOURCES;
1603 dtype = MLD2_BLOCK_OLD_SOURCES;
1605 skb = add_grec(skb, pmc, type, 0, 0);
1606 skb = add_grec(skb, pmc, dtype, 0, 1); /* deleted sources */
1608 /* filter mode changes */
1609 if (pmc->mca_crcount) {
1611 if (pmc->mca_sfmode == MCAST_EXCLUDE)
1612 type = MLD2_CHANGE_TO_EXCLUDE;
1614 type = MLD2_CHANGE_TO_INCLUDE;
1615 skb = add_grec(skb, pmc, type, 0, 0);
1617 spin_unlock_bh(&pmc->mca_lock);
1619 read_unlock_bh(&idev->lock);
1622 (void) mld_sendpack(skb);
1625 static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type)
1627 struct sock *sk = igmp6_socket->sk;
1628 struct inet6_dev *idev;
1629 struct sk_buff *skb;
1630 struct icmp6hdr *hdr;
1631 struct in6_addr *snd_addr;
1632 struct in6_addr *addrp;
1633 struct in6_addr addr_buf;
1634 struct in6_addr all_routers;
1635 int err, len, payload_len, full_len;
1636 u8 ra[8] = { IPPROTO_ICMPV6, 0,
1637 IPV6_TLV_ROUTERALERT, 2, 0, 0,
1640 IP6_INC_STATS(IPSTATS_MIB_OUTREQUESTS);
1642 if (type == ICMPV6_MGM_REDUCTION) {
1643 snd_addr = &all_routers;
1644 ipv6_addr_all_routers(&all_routers);
1647 len = sizeof(struct icmp6hdr) + sizeof(struct in6_addr);
1648 payload_len = len + sizeof(ra);
1649 full_len = sizeof(struct ipv6hdr) + payload_len;
1651 skb = sock_alloc_send_skb(sk, LL_RESERVED_SPACE(dev) + full_len, 1, &err);
1654 IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
1658 skb_reserve(skb, LL_RESERVED_SPACE(dev));
1659 if (dev->hard_header) {
1660 unsigned char ha[MAX_ADDR_LEN];
1661 ndisc_mc_map(snd_addr, ha, dev, 1);
1662 if (dev->hard_header(skb, dev, ETH_P_IPV6, ha, NULL, full_len) < 0)
1666 if (ipv6_get_lladdr(dev, &addr_buf)) {
1667 /* <draft-ietf-magma-mld-source-05.txt>:
1668 * use unspecified address as the source address
1669 * when a valid link-local address is not available.
1671 memset(&addr_buf, 0, sizeof(addr_buf));
1674 ip6_nd_hdr(sk, skb, dev, &addr_buf, snd_addr, NEXTHDR_HOP, payload_len);
1676 memcpy(skb_put(skb, sizeof(ra)), ra, sizeof(ra));
1678 hdr = (struct icmp6hdr *) skb_put(skb, sizeof(struct icmp6hdr));
1679 memset(hdr, 0, sizeof(struct icmp6hdr));
1680 hdr->icmp6_type = type;
1682 addrp = (struct in6_addr *) skb_put(skb, sizeof(struct in6_addr));
1683 ipv6_addr_copy(addrp, addr);
1685 hdr->icmp6_cksum = csum_ipv6_magic(&addr_buf, snd_addr, len,
1687 csum_partial((__u8 *) hdr, len, 0));
1689 idev = in6_dev_get(skb->dev);
1691 err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, skb->dev,
1694 if (type == ICMPV6_MGM_REDUCTION)
1695 ICMP6_INC_STATS(idev, ICMP6_MIB_OUTGROUPMEMBREDUCTIONS);
1697 ICMP6_INC_STATS(idev, ICMP6_MIB_OUTGROUPMEMBRESPONSES);
1698 ICMP6_INC_STATS(idev, ICMP6_MIB_OUTMSGS);
1699 IP6_INC_STATS(IPSTATS_MIB_OUTMCASTPKTS);
1701 IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
1703 if (likely(idev != NULL))
1708 IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
1712 static int ip6_mc_del1_src(struct ifmcaddr6 *pmc, int sfmode,
1713 struct in6_addr *psfsrc)
1715 struct ip6_sf_list *psf, *psf_prev;
1719 for (psf=pmc->mca_sources; psf; psf=psf->sf_next) {
1720 if (ipv6_addr_equal(&psf->sf_addr, psfsrc))
1724 if (!psf || psf->sf_count[sfmode] == 0) {
1725 /* source filter not found, or count wrong => bug */
1728 psf->sf_count[sfmode]--;
1729 if (!psf->sf_count[MCAST_INCLUDE] && !psf->sf_count[MCAST_EXCLUDE]) {
1730 struct inet6_dev *idev = pmc->idev;
1732 /* no more filters for this source */
1734 psf_prev->sf_next = psf->sf_next;
1736 pmc->mca_sources = psf->sf_next;
1737 if (psf->sf_oldin && !(pmc->mca_flags & MAF_NOREPORT) &&
1738 !MLD_V1_SEEN(idev)) {
1739 psf->sf_crcount = idev->mc_qrv;
1740 psf->sf_next = pmc->mca_tomb;
1741 pmc->mca_tomb = psf;
1749 static int ip6_mc_del_src(struct inet6_dev *idev, struct in6_addr *pmca,
1750 int sfmode, int sfcount, struct in6_addr *psfsrc,
1753 struct ifmcaddr6 *pmc;
1759 read_lock_bh(&idev->lock);
1760 for (pmc=idev->mc_list; pmc; pmc=pmc->next) {
1761 if (ipv6_addr_equal(pmca, &pmc->mca_addr))
1765 /* MCA not found?? bug */
1766 read_unlock_bh(&idev->lock);
1769 spin_lock_bh(&pmc->mca_lock);
1772 if (!pmc->mca_sfcount[sfmode]) {
1773 spin_unlock_bh(&pmc->mca_lock);
1774 read_unlock_bh(&idev->lock);
1777 pmc->mca_sfcount[sfmode]--;
1780 for (i=0; i<sfcount; i++) {
1781 int rv = ip6_mc_del1_src(pmc, sfmode, &psfsrc[i]);
1783 changerec |= rv > 0;
1787 if (pmc->mca_sfmode == MCAST_EXCLUDE &&
1788 pmc->mca_sfcount[MCAST_EXCLUDE] == 0 &&
1789 pmc->mca_sfcount[MCAST_INCLUDE]) {
1790 struct ip6_sf_list *psf;
1792 /* filter mode change */
1793 pmc->mca_sfmode = MCAST_INCLUDE;
1794 pmc->mca_crcount = idev->mc_qrv;
1795 idev->mc_ifc_count = pmc->mca_crcount;
1796 for (psf=pmc->mca_sources; psf; psf = psf->sf_next)
1797 psf->sf_crcount = 0;
1798 mld_ifc_event(pmc->idev);
1799 } else if (sf_setstate(pmc) || changerec)
1800 mld_ifc_event(pmc->idev);
1801 spin_unlock_bh(&pmc->mca_lock);
1802 read_unlock_bh(&idev->lock);
1807 * Add multicast single-source filter to the interface list
1809 static int ip6_mc_add1_src(struct ifmcaddr6 *pmc, int sfmode,
1810 struct in6_addr *psfsrc, int delta)
1812 struct ip6_sf_list *psf, *psf_prev;
1815 for (psf=pmc->mca_sources; psf; psf=psf->sf_next) {
1816 if (ipv6_addr_equal(&psf->sf_addr, psfsrc))
1821 psf = (struct ip6_sf_list *)kmalloc(sizeof(*psf), GFP_ATOMIC);
1824 memset(psf, 0, sizeof(*psf));
1825 psf->sf_addr = *psfsrc;
1827 psf_prev->sf_next = psf;
1829 pmc->mca_sources = psf;
1831 psf->sf_count[sfmode]++;
1835 static void sf_markstate(struct ifmcaddr6 *pmc)
1837 struct ip6_sf_list *psf;
1838 int mca_xcount = pmc->mca_sfcount[MCAST_EXCLUDE];
1840 for (psf=pmc->mca_sources; psf; psf=psf->sf_next)
1841 if (pmc->mca_sfcount[MCAST_EXCLUDE]) {
1842 psf->sf_oldin = mca_xcount ==
1843 psf->sf_count[MCAST_EXCLUDE] &&
1844 !psf->sf_count[MCAST_INCLUDE];
1846 psf->sf_oldin = psf->sf_count[MCAST_INCLUDE] != 0;
1849 static int sf_setstate(struct ifmcaddr6 *pmc)
1851 struct ip6_sf_list *psf;
1852 int mca_xcount = pmc->mca_sfcount[MCAST_EXCLUDE];
1853 int qrv = pmc->idev->mc_qrv;
1857 for (psf=pmc->mca_sources; psf; psf=psf->sf_next) {
1858 if (pmc->mca_sfcount[MCAST_EXCLUDE]) {
1859 new_in = mca_xcount == psf->sf_count[MCAST_EXCLUDE] &&
1860 !psf->sf_count[MCAST_INCLUDE];
1862 new_in = psf->sf_count[MCAST_INCLUDE] != 0;
1863 if (new_in != psf->sf_oldin) {
1864 psf->sf_crcount = qrv;
1872 * Add multicast source filter list to the interface list
1874 static int ip6_mc_add_src(struct inet6_dev *idev, struct in6_addr *pmca,
1875 int sfmode, int sfcount, struct in6_addr *psfsrc,
1878 struct ifmcaddr6 *pmc;
1884 read_lock_bh(&idev->lock);
1885 for (pmc=idev->mc_list; pmc; pmc=pmc->next) {
1886 if (ipv6_addr_equal(pmca, &pmc->mca_addr))
1890 /* MCA not found?? bug */
1891 read_unlock_bh(&idev->lock);
1894 spin_lock_bh(&pmc->mca_lock);
1897 isexclude = pmc->mca_sfmode == MCAST_EXCLUDE;
1899 pmc->mca_sfcount[sfmode]++;
1901 for (i=0; i<sfcount; i++) {
1902 err = ip6_mc_add1_src(pmc, sfmode, &psfsrc[i], delta);
1910 pmc->mca_sfcount[sfmode]--;
1912 (void) ip6_mc_del1_src(pmc, sfmode, &psfsrc[i]);
1913 } else if (isexclude != (pmc->mca_sfcount[MCAST_EXCLUDE] != 0)) {
1914 struct inet6_dev *idev = pmc->idev;
1915 struct ip6_sf_list *psf;
1917 /* filter mode change */
1918 if (pmc->mca_sfcount[MCAST_EXCLUDE])
1919 pmc->mca_sfmode = MCAST_EXCLUDE;
1920 else if (pmc->mca_sfcount[MCAST_INCLUDE])
1921 pmc->mca_sfmode = MCAST_INCLUDE;
1922 /* else no filters; keep old mode for reports */
1924 pmc->mca_crcount = idev->mc_qrv;
1925 idev->mc_ifc_count = pmc->mca_crcount;
1926 for (psf=pmc->mca_sources; psf; psf = psf->sf_next)
1927 psf->sf_crcount = 0;
1928 mld_ifc_event(idev);
1929 } else if (sf_setstate(pmc))
1930 mld_ifc_event(idev);
1931 spin_unlock_bh(&pmc->mca_lock);
1932 read_unlock_bh(&idev->lock);
1936 static void ip6_mc_clear_src(struct ifmcaddr6 *pmc)
1938 struct ip6_sf_list *psf, *nextpsf;
1940 for (psf=pmc->mca_tomb; psf; psf=nextpsf) {
1941 nextpsf = psf->sf_next;
1944 pmc->mca_tomb = NULL;
1945 for (psf=pmc->mca_sources; psf; psf=nextpsf) {
1946 nextpsf = psf->sf_next;
1949 pmc->mca_sources = NULL;
1950 pmc->mca_sfmode = MCAST_EXCLUDE;
1951 pmc->mca_sfcount[MCAST_EXCLUDE] = 0;
1952 pmc->mca_sfcount[MCAST_EXCLUDE] = 1;
1956 static void igmp6_join_group(struct ifmcaddr6 *ma)
1958 unsigned long delay;
1960 if (ma->mca_flags & MAF_NOREPORT)
1963 igmp6_send(&ma->mca_addr, ma->idev->dev, ICMPV6_MGM_REPORT);
1965 delay = net_random() % IGMP6_UNSOLICITED_IVAL;
1967 spin_lock_bh(&ma->mca_lock);
1968 if (del_timer(&ma->mca_timer)) {
1969 atomic_dec(&ma->mca_refcnt);
1970 delay = ma->mca_timer.expires - jiffies;
1973 if (!mod_timer(&ma->mca_timer, jiffies + delay))
1974 atomic_inc(&ma->mca_refcnt);
1975 ma->mca_flags |= MAF_TIMER_RUNNING | MAF_LAST_REPORTER;
1976 spin_unlock_bh(&ma->mca_lock);
1979 static int ip6_mc_leave_src(struct sock *sk, struct ipv6_mc_socklist *iml,
1980 struct inet6_dev *idev)
1984 if (iml->sflist == 0) {
1985 /* any-source empty exclude case */
1986 return ip6_mc_del_src(idev, &iml->addr, iml->sfmode, 0, NULL, 0);
1988 err = ip6_mc_del_src(idev, &iml->addr, iml->sfmode,
1989 iml->sflist->sl_count, iml->sflist->sl_addr, 0);
1990 sock_kfree_s(sk, iml->sflist, IP6_SFLSIZE(iml->sflist->sl_max));
1995 static void igmp6_leave_group(struct ifmcaddr6 *ma)
1997 if (MLD_V1_SEEN(ma->idev)) {
1998 if (ma->mca_flags & MAF_LAST_REPORTER)
1999 igmp6_send(&ma->mca_addr, ma->idev->dev,
2000 ICMPV6_MGM_REDUCTION);
2002 mld_add_delrec(ma->idev, ma);
2003 mld_ifc_event(ma->idev);
2007 static void mld_gq_timer_expire(unsigned long data)
2009 struct inet6_dev *idev = (struct inet6_dev *)data;
2011 idev->mc_gq_running = 0;
2012 mld_send_report(idev, NULL);
2013 __in6_dev_put(idev);
2016 static void mld_ifc_timer_expire(unsigned long data)
2018 struct inet6_dev *idev = (struct inet6_dev *)data;
2021 if (idev->mc_ifc_count) {
2022 idev->mc_ifc_count--;
2023 if (idev->mc_ifc_count)
2024 mld_ifc_start_timer(idev, idev->mc_maxdelay);
2026 __in6_dev_put(idev);
2029 static void mld_ifc_event(struct inet6_dev *idev)
2031 if (MLD_V1_SEEN(idev))
2033 idev->mc_ifc_count = idev->mc_qrv;
2034 mld_ifc_start_timer(idev, 1);
2038 static void igmp6_timer_handler(unsigned long data)
2040 struct ifmcaddr6 *ma = (struct ifmcaddr6 *) data;
2042 if (MLD_V1_SEEN(ma->idev))
2043 igmp6_send(&ma->mca_addr, ma->idev->dev, ICMPV6_MGM_REPORT);
2045 mld_send_report(ma->idev, ma);
2047 spin_lock(&ma->mca_lock);
2048 ma->mca_flags |= MAF_LAST_REPORTER;
2049 ma->mca_flags &= ~MAF_TIMER_RUNNING;
2050 spin_unlock(&ma->mca_lock);
2054 /* Device going down */
2056 void ipv6_mc_down(struct inet6_dev *idev)
2058 struct ifmcaddr6 *i;
2060 /* Withdraw multicast list */
2062 read_lock_bh(&idev->lock);
2063 idev->mc_ifc_count = 0;
2064 if (del_timer(&idev->mc_ifc_timer))
2065 __in6_dev_put(idev);
2066 idev->mc_gq_running = 0;
2067 if (del_timer(&idev->mc_gq_timer))
2068 __in6_dev_put(idev);
2070 for (i = idev->mc_list; i; i=i->next)
2071 igmp6_group_dropped(i);
2072 read_unlock_bh(&idev->lock);
2074 mld_clear_delrec(idev);
2078 /* Device going up */
2080 void ipv6_mc_up(struct inet6_dev *idev)
2082 struct ifmcaddr6 *i;
2084 /* Install multicast list, except for all-nodes (already installed) */
2086 read_lock_bh(&idev->lock);
2087 for (i = idev->mc_list; i; i=i->next)
2088 igmp6_group_added(i);
2089 read_unlock_bh(&idev->lock);
2092 /* IPv6 device initialization. */
2094 void ipv6_mc_init_dev(struct inet6_dev *idev)
2096 struct in6_addr maddr;
2098 write_lock_bh(&idev->lock);
2099 rwlock_init(&idev->mc_lock);
2100 idev->mc_gq_running = 0;
2101 init_timer(&idev->mc_gq_timer);
2102 idev->mc_gq_timer.data = (unsigned long) idev;
2103 idev->mc_gq_timer.function = &mld_gq_timer_expire;
2104 idev->mc_tomb = NULL;
2105 idev->mc_ifc_count = 0;
2106 init_timer(&idev->mc_ifc_timer);
2107 idev->mc_ifc_timer.data = (unsigned long) idev;
2108 idev->mc_ifc_timer.function = &mld_ifc_timer_expire;
2109 idev->mc_qrv = MLD_QRV_DEFAULT;
2110 idev->mc_maxdelay = IGMP6_UNSOLICITED_IVAL;
2111 idev->mc_v1_seen = 0;
2112 write_unlock_bh(&idev->lock);
2114 /* Add all-nodes address. */
2115 ipv6_addr_all_nodes(&maddr);
2116 ipv6_dev_mc_inc(idev->dev, &maddr);
2120 * Device is about to be destroyed: clean up.
2123 void ipv6_mc_destroy_dev(struct inet6_dev *idev)
2125 struct ifmcaddr6 *i;
2126 struct in6_addr maddr;
2128 /* Deactivate timers */
2131 /* Delete all-nodes address. */
2132 ipv6_addr_all_nodes(&maddr);
2134 /* We cannot call ipv6_dev_mc_dec() directly, our caller in
2135 * addrconf.c has NULL'd out dev->ip6_ptr so in6_dev_get() will
2138 __ipv6_dev_mc_dec(idev, &maddr);
2140 if (idev->cnf.forwarding) {
2141 ipv6_addr_all_routers(&maddr);
2142 __ipv6_dev_mc_dec(idev, &maddr);
2145 write_lock_bh(&idev->lock);
2146 while ((i = idev->mc_list) != NULL) {
2147 idev->mc_list = i->next;
2148 write_unlock_bh(&idev->lock);
2150 igmp6_group_dropped(i);
2153 write_lock_bh(&idev->lock);
2155 write_unlock_bh(&idev->lock);
2158 #ifdef CONFIG_PROC_FS
2159 struct igmp6_mc_iter_state {
2160 struct net_device *dev;
2161 struct inet6_dev *idev;
2164 #define igmp6_mc_seq_private(seq) ((struct igmp6_mc_iter_state *)(seq)->private)
2166 static inline struct ifmcaddr6 *igmp6_mc_get_first(struct seq_file *seq)
2168 struct ifmcaddr6 *im = NULL;
2169 struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq);
2171 for (state->dev = dev_base, state->idev = NULL;
2173 state->dev = state->dev->next) {
2174 struct inet6_dev *idev;
2175 idev = in6_dev_get(state->dev);
2178 read_lock_bh(&idev->lock);
2184 read_unlock_bh(&idev->lock);
2190 static struct ifmcaddr6 *igmp6_mc_get_next(struct seq_file *seq, struct ifmcaddr6 *im)
2192 struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq);
2196 if (likely(state->idev != NULL)) {
2197 read_unlock_bh(&state->idev->lock);
2198 in6_dev_put(state->idev);
2200 state->dev = state->dev->next;
2205 state->idev = in6_dev_get(state->dev);
2208 read_lock_bh(&state->idev->lock);
2209 im = state->idev->mc_list;
2214 static struct ifmcaddr6 *igmp6_mc_get_idx(struct seq_file *seq, loff_t pos)
2216 struct ifmcaddr6 *im = igmp6_mc_get_first(seq);
2218 while (pos && (im = igmp6_mc_get_next(seq, im)) != NULL)
2220 return pos ? NULL : im;
2223 static void *igmp6_mc_seq_start(struct seq_file *seq, loff_t *pos)
2225 read_lock(&dev_base_lock);
2226 return igmp6_mc_get_idx(seq, *pos);
2229 static void *igmp6_mc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2231 struct ifmcaddr6 *im;
2232 im = igmp6_mc_get_next(seq, v);
2237 static void igmp6_mc_seq_stop(struct seq_file *seq, void *v)
2239 struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq);
2240 if (likely(state->idev != NULL)) {
2241 read_unlock_bh(&state->idev->lock);
2242 in6_dev_put(state->idev);
2246 read_unlock(&dev_base_lock);
2249 static int igmp6_mc_seq_show(struct seq_file *seq, void *v)
2251 struct ifmcaddr6 *im = (struct ifmcaddr6 *)v;
2252 struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq);
2255 "%-4d %-15s %04x%04x%04x%04x%04x%04x%04x%04x %5d %08X %ld\n",
2256 state->dev->ifindex, state->dev->name,
2258 im->mca_users, im->mca_flags,
2259 (im->mca_flags&MAF_TIMER_RUNNING) ?
2260 jiffies_to_clock_t(im->mca_timer.expires-jiffies) : 0);
2264 static struct seq_operations igmp6_mc_seq_ops = {
2265 .start = igmp6_mc_seq_start,
2266 .next = igmp6_mc_seq_next,
2267 .stop = igmp6_mc_seq_stop,
2268 .show = igmp6_mc_seq_show,
2271 static int igmp6_mc_seq_open(struct inode *inode, struct file *file)
2273 struct seq_file *seq;
2275 struct igmp6_mc_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL);
2280 rc = seq_open(file, &igmp6_mc_seq_ops);
2284 seq = file->private_data;
2286 memset(s, 0, sizeof(*s));
2294 static struct file_operations igmp6_mc_seq_fops = {
2295 .owner = THIS_MODULE,
2296 .open = igmp6_mc_seq_open,
2298 .llseek = seq_lseek,
2299 .release = seq_release_private,
2302 struct igmp6_mcf_iter_state {
2303 struct net_device *dev;
2304 struct inet6_dev *idev;
2305 struct ifmcaddr6 *im;
2308 #define igmp6_mcf_seq_private(seq) ((struct igmp6_mcf_iter_state *)(seq)->private)
2310 static inline struct ip6_sf_list *igmp6_mcf_get_first(struct seq_file *seq)
2312 struct ip6_sf_list *psf = NULL;
2313 struct ifmcaddr6 *im = NULL;
2314 struct igmp6_mcf_iter_state *state = igmp6_mcf_seq_private(seq);
2316 for (state->dev = dev_base, state->idev = NULL, state->im = NULL;
2318 state->dev = state->dev->next) {
2319 struct inet6_dev *idev;
2320 idev = in6_dev_get(state->dev);
2321 if (unlikely(idev == NULL))
2323 read_lock_bh(&idev->lock);
2325 if (likely(im != NULL)) {
2326 spin_lock_bh(&im->mca_lock);
2327 psf = im->mca_sources;
2328 if (likely(psf != NULL)) {
2333 spin_unlock_bh(&im->mca_lock);
2335 read_unlock_bh(&idev->lock);
2341 static struct ip6_sf_list *igmp6_mcf_get_next(struct seq_file *seq, struct ip6_sf_list *psf)
2343 struct igmp6_mcf_iter_state *state = igmp6_mcf_seq_private(seq);
2347 spin_unlock_bh(&state->im->mca_lock);
2348 state->im = state->im->next;
2349 while (!state->im) {
2350 if (likely(state->idev != NULL)) {
2351 read_unlock_bh(&state->idev->lock);
2352 in6_dev_put(state->idev);
2354 state->dev = state->dev->next;
2359 state->idev = in6_dev_get(state->dev);
2362 read_lock_bh(&state->idev->lock);
2363 state->im = state->idev->mc_list;
2367 spin_lock_bh(&state->im->mca_lock);
2368 psf = state->im->mca_sources;
2374 static struct ip6_sf_list *igmp6_mcf_get_idx(struct seq_file *seq, loff_t pos)
2376 struct ip6_sf_list *psf = igmp6_mcf_get_first(seq);
2378 while (pos && (psf = igmp6_mcf_get_next(seq, psf)) != NULL)
2380 return pos ? NULL : psf;
2383 static void *igmp6_mcf_seq_start(struct seq_file *seq, loff_t *pos)
2385 read_lock(&dev_base_lock);
2386 return *pos ? igmp6_mcf_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
2389 static void *igmp6_mcf_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2391 struct ip6_sf_list *psf;
2392 if (v == SEQ_START_TOKEN)
2393 psf = igmp6_mcf_get_first(seq);
2395 psf = igmp6_mcf_get_next(seq, v);
2400 static void igmp6_mcf_seq_stop(struct seq_file *seq, void *v)
2402 struct igmp6_mcf_iter_state *state = igmp6_mcf_seq_private(seq);
2403 if (likely(state->im != NULL)) {
2404 spin_unlock_bh(&state->im->mca_lock);
2407 if (likely(state->idev != NULL)) {
2408 read_unlock_bh(&state->idev->lock);
2409 in6_dev_put(state->idev);
2413 read_unlock(&dev_base_lock);
2416 static int igmp6_mcf_seq_show(struct seq_file *seq, void *v)
2418 struct ip6_sf_list *psf = (struct ip6_sf_list *)v;
2419 struct igmp6_mcf_iter_state *state = igmp6_mcf_seq_private(seq);
2421 if (v == SEQ_START_TOKEN) {
2424 "%32s %32s %6s %6s\n", "Idx",
2425 "Device", "Multicast Address",
2426 "Source Address", "INC", "EXC");
2430 "%04x%04x%04x%04x%04x%04x%04x%04x "
2431 "%04x%04x%04x%04x%04x%04x%04x%04x "
2433 state->dev->ifindex, state->dev->name,
2434 NIP6(state->im->mca_addr),
2436 psf->sf_count[MCAST_INCLUDE],
2437 psf->sf_count[MCAST_EXCLUDE]);
2442 static struct seq_operations igmp6_mcf_seq_ops = {
2443 .start = igmp6_mcf_seq_start,
2444 .next = igmp6_mcf_seq_next,
2445 .stop = igmp6_mcf_seq_stop,
2446 .show = igmp6_mcf_seq_show,
2449 static int igmp6_mcf_seq_open(struct inode *inode, struct file *file)
2451 struct seq_file *seq;
2453 struct igmp6_mcf_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL);
2458 rc = seq_open(file, &igmp6_mcf_seq_ops);
2462 seq = file->private_data;
2464 memset(s, 0, sizeof(*s));
2472 static struct file_operations igmp6_mcf_seq_fops = {
2473 .owner = THIS_MODULE,
2474 .open = igmp6_mcf_seq_open,
2476 .llseek = seq_lseek,
2477 .release = seq_release_private,
2481 int __init igmp6_init(struct net_proto_family *ops)
2483 struct ipv6_pinfo *np;
2487 err = sock_create_kern(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6, &igmp6_socket);
2490 "Failed to initialize the IGMP6 control socket (err %d).\n",
2492 igmp6_socket = NULL; /* For safety. */
2496 sk = igmp6_socket->sk;
2497 sk->sk_allocation = GFP_ATOMIC;
2498 sk->sk_prot->unhash(sk);
2503 #ifdef CONFIG_PROC_FS
2504 proc_net_fops_create("igmp6", S_IRUGO, &igmp6_mc_seq_fops);
2505 proc_net_fops_create("mcfilter6", S_IRUGO, &igmp6_mcf_seq_fops);
2511 void igmp6_cleanup(void)
2513 sock_release(igmp6_socket);
2514 igmp6_socket = NULL; /* for safety */
2516 #ifdef CONFIG_PROC_FS
2517 proc_net_remove("mcfilter6");
2518 proc_net_remove("igmp6");