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 struct in6_addr mld2_all_mcr = MLD2_ALL_MCR_INIT;
126 /* Big mc list lock for all the sockets */
127 static rwlock_t ipv6_sk_mc_lock = RW_LOCK_UNLOCKED;
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 int ip6_mc_del_src(struct inet6_dev *idev, struct in6_addr *pmca, int sfmode,
147 int sfcount, struct in6_addr *psfsrc, int delta);
148 int ip6_mc_add_src(struct inet6_dev *idev, struct in6_addr *pmca, int sfmode,
149 int sfcount, struct in6_addr *psfsrc, int delta);
150 int ip6_mc_leave_src(struct sock *sk, struct ipv6_mc_socklist *iml,
151 struct inet6_dev *idev);
154 #define IGMP6_UNSOLICITED_IVAL (10*HZ)
155 #define MLD_QRV_DEFAULT 2
157 #define MLD_V1_SEEN(idev) (ipv6_devconf.force_mld_version == 1 || \
158 (idev)->cnf.force_mld_version == 1 || \
159 ((idev)->mc_v1_seen && \
160 time_before(jiffies, (idev)->mc_v1_seen)))
162 #define MLDV2_MASK(value, nb) ((nb)>=32 ? (value) : ((1<<(nb))-1) & (value))
163 #define MLDV2_EXP(thresh, nbmant, nbexp, value) \
164 ((value) < (thresh) ? (value) : \
165 ((MLDV2_MASK(value, nbmant) | (1<<(nbmant+nbexp))) << \
166 (MLDV2_MASK((value) >> (nbmant), nbexp) + (nbexp))))
168 #define MLDV2_QQIC(value) MLDV2_EXP(0x80, 4, 3, value)
169 #define MLDV2_MRC(value) MLDV2_EXP(0x8000, 12, 3, value)
171 #define IPV6_MLD_MAX_MSF 10
173 int sysctl_mld_max_msf = IPV6_MLD_MAX_MSF;
176 * socket join on multicast group
179 int ipv6_sock_mc_join(struct sock *sk, int ifindex, struct in6_addr *addr)
181 struct net_device *dev = NULL;
182 struct ipv6_mc_socklist *mc_lst;
183 struct ipv6_pinfo *np = inet6_sk(sk);
186 if (!ipv6_addr_is_multicast(addr))
189 mc_lst = sock_kmalloc(sk, sizeof(struct ipv6_mc_socklist), GFP_KERNEL);
195 ipv6_addr_copy(&mc_lst->addr, addr);
199 rt = rt6_lookup(addr, NULL, 0, 0);
203 dst_release(&rt->u.dst);
206 dev = dev_get_by_index(ifindex);
209 sock_kfree_s(sk, mc_lst, sizeof(*mc_lst));
213 mc_lst->ifindex = dev->ifindex;
214 mc_lst->sfmode = MCAST_EXCLUDE;
215 mc_lst->sflist = NULL;
218 * now add/increase the group membership on the device
221 err = ipv6_dev_mc_inc(dev, addr);
224 sock_kfree_s(sk, mc_lst, sizeof(*mc_lst));
229 write_lock_bh(&ipv6_sk_mc_lock);
230 mc_lst->next = np->ipv6_mc_list;
231 np->ipv6_mc_list = mc_lst;
232 write_unlock_bh(&ipv6_sk_mc_lock);
240 * socket leave on multicast group
242 int ipv6_sock_mc_drop(struct sock *sk, int ifindex, struct in6_addr *addr)
244 struct ipv6_pinfo *np = inet6_sk(sk);
245 struct ipv6_mc_socklist *mc_lst, **lnk;
247 write_lock_bh(&ipv6_sk_mc_lock);
248 for (lnk = &np->ipv6_mc_list; (mc_lst = *lnk) !=NULL ; lnk = &mc_lst->next) {
249 if ((ifindex == 0 || mc_lst->ifindex == ifindex) &&
250 ipv6_addr_cmp(&mc_lst->addr, addr) == 0) {
251 struct net_device *dev;
254 write_unlock_bh(&ipv6_sk_mc_lock);
256 if ((dev = dev_get_by_index(mc_lst->ifindex)) != NULL) {
257 struct inet6_dev *idev = in6_dev_get(dev);
260 (void) ip6_mc_leave_src(sk,mc_lst,idev);
261 __ipv6_dev_mc_dec(idev, &mc_lst->addr);
266 sock_kfree_s(sk, mc_lst, sizeof(*mc_lst));
270 write_unlock_bh(&ipv6_sk_mc_lock);
275 struct inet6_dev *ip6_mc_find_dev(struct in6_addr *group, int ifindex)
277 struct net_device *dev = NULL;
278 struct inet6_dev *idev = NULL;
283 rt = rt6_lookup(group, NULL, 0, 0);
287 dst_release(&rt->u.dst);
290 dev = dev_get_by_index(ifindex);
294 idev = in6_dev_get(dev);
299 read_lock_bh(&idev->lock);
301 read_unlock_bh(&idev->lock);
309 void ipv6_sock_mc_close(struct sock *sk)
311 struct ipv6_pinfo *np = inet6_sk(sk);
312 struct ipv6_mc_socklist *mc_lst;
314 write_lock_bh(&ipv6_sk_mc_lock);
315 while ((mc_lst = np->ipv6_mc_list) != NULL) {
316 struct net_device *dev;
318 np->ipv6_mc_list = mc_lst->next;
319 write_unlock_bh(&ipv6_sk_mc_lock);
321 dev = dev_get_by_index(mc_lst->ifindex);
323 struct inet6_dev *idev = in6_dev_get(dev);
326 (void) ip6_mc_leave_src(sk, mc_lst, idev);
327 __ipv6_dev_mc_dec(idev, &mc_lst->addr);
333 sock_kfree_s(sk, mc_lst, sizeof(*mc_lst));
335 write_lock_bh(&ipv6_sk_mc_lock);
337 write_unlock_bh(&ipv6_sk_mc_lock);
340 int ip6_mc_source(int add, int omode, struct sock *sk,
341 struct group_source_req *pgsr)
343 struct in6_addr *source, *group;
344 struct ipv6_mc_socklist *pmc;
345 struct net_device *dev;
346 struct inet6_dev *idev;
347 struct ipv6_pinfo *inet6 = inet6_sk(sk);
348 struct ip6_sf_socklist *psl;
352 if (pgsr->gsr_group.ss_family != AF_INET6 ||
353 pgsr->gsr_source.ss_family != AF_INET6)
356 source = &((struct sockaddr_in6 *)&pgsr->gsr_source)->sin6_addr;
357 group = &((struct sockaddr_in6 *)&pgsr->gsr_group)->sin6_addr;
359 if (!ipv6_addr_is_multicast(group))
362 idev = ip6_mc_find_dev(group, pgsr->gsr_interface);
367 err = -EADDRNOTAVAIL;
369 for (pmc=inet6->ipv6_mc_list; pmc; pmc=pmc->next) {
370 if (pgsr->gsr_interface && pmc->ifindex != pgsr->gsr_interface)
372 if (ipv6_addr_cmp(&pmc->addr, group) == 0)
375 if (!pmc) /* must have a prior join */
377 /* if a source filter was set, must be the same mode as before */
379 if (pmc->sfmode != omode)
381 } else if (pmc->sfmode != omode) {
382 /* allow mode switches for empty-set filters */
383 ip6_mc_add_src(idev, group, omode, 0, NULL, 0);
384 ip6_mc_del_src(idev, group, pmc->sfmode, 0, NULL, 0);
393 for (i=0; i<psl->sl_count; i++) {
394 rv = memcmp(&psl->sl_addr, group,
395 sizeof(struct in6_addr));
399 if (!rv) /* source not found */
402 /* update the interface filter */
403 ip6_mc_del_src(idev, group, omode, 1, source, 1);
405 for (j=i+1; j<psl->sl_count; j++)
406 psl->sl_addr[j-1] = psl->sl_addr[j];
411 /* else, add a new source to the filter */
413 if (psl && psl->sl_count >= sysctl_mld_max_msf) {
417 if (!psl || psl->sl_count == psl->sl_max) {
418 struct ip6_sf_socklist *newpsl;
419 int count = IP6_SFBLOCK;
422 count += psl->sl_max;
423 newpsl = (struct ip6_sf_socklist *)sock_kmalloc(sk,
424 IP6_SFLSIZE(count), GFP_ATOMIC);
429 newpsl->sl_max = count;
430 newpsl->sl_count = count - IP6_SFBLOCK;
432 for (i=0; i<psl->sl_count; i++)
433 newpsl->sl_addr[i] = psl->sl_addr[i];
434 sock_kfree_s(sk, psl, IP6_SFLSIZE(psl->sl_max));
436 pmc->sflist = psl = newpsl;
438 rv = 1; /* > 0 for insert logic below if sl_count is 0 */
439 for (i=0; i<psl->sl_count; i++) {
440 rv = memcmp(&psl->sl_addr, group, sizeof(struct in6_addr));
444 if (rv == 0) /* address already there is an error */
446 for (j=psl->sl_count-1; j>=i; j--)
447 psl->sl_addr[j+1] = psl->sl_addr[j];
448 psl->sl_addr[i] = *source;
451 /* update the interface list */
452 ip6_mc_add_src(idev, group, omode, 1, source, 1);
454 read_unlock_bh(&idev->lock);
460 int ip6_mc_msfilter(struct sock *sk, struct group_filter *gsf)
462 struct in6_addr *group;
463 struct ipv6_mc_socklist *pmc;
464 struct net_device *dev;
465 struct inet6_dev *idev;
466 struct ipv6_pinfo *inet6 = inet6_sk(sk);
467 struct ip6_sf_socklist *newpsl, *psl;
470 group = &((struct sockaddr_in6 *)&gsf->gf_group)->sin6_addr;
472 if (!ipv6_addr_is_multicast(group))
474 if (gsf->gf_fmode != MCAST_INCLUDE &&
475 gsf->gf_fmode != MCAST_EXCLUDE)
478 idev = ip6_mc_find_dev(group, gsf->gf_interface);
483 err = -EADDRNOTAVAIL;
485 for (pmc=inet6->ipv6_mc_list; pmc; pmc=pmc->next) {
486 if (pmc->ifindex != gsf->gf_interface)
488 if (ipv6_addr_cmp(&pmc->addr, group) == 0)
491 if (!pmc) /* must have a prior join */
493 if (gsf->gf_numsrc) {
494 newpsl = (struct ip6_sf_socklist *)sock_kmalloc(sk,
495 IP6_SFLSIZE(gsf->gf_numsrc), GFP_ATOMIC);
500 newpsl->sl_max = newpsl->sl_count = gsf->gf_numsrc;
501 for (i=0; i<newpsl->sl_count; ++i) {
502 struct sockaddr_in6 *psin6;
504 psin6 = (struct sockaddr_in6 *)&gsf->gf_slist[i];
505 newpsl->sl_addr[i] = psin6->sin6_addr;
507 err = ip6_mc_add_src(idev, group, gsf->gf_fmode,
508 newpsl->sl_count, newpsl->sl_addr, 0);
510 sock_kfree_s(sk, newpsl, IP6_SFLSIZE(newpsl->sl_max));
517 (void) ip6_mc_del_src(idev, group, pmc->sfmode,
518 psl->sl_count, psl->sl_addr, 0);
519 sock_kfree_s(sk, psl, IP6_SFLSIZE(psl->sl_max));
521 (void) ip6_mc_del_src(idev, group, pmc->sfmode, 0, NULL, 0);
522 pmc->sflist = newpsl;
523 pmc->sfmode = gsf->gf_fmode;
525 read_unlock_bh(&idev->lock);
531 int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf,
532 struct group_filter __user *optval, int __user *optlen)
534 int err, i, count, copycount;
535 struct in6_addr *group;
536 struct ipv6_mc_socklist *pmc;
537 struct inet6_dev *idev;
538 struct net_device *dev;
539 struct ipv6_pinfo *inet6 = inet6_sk(sk);
540 struct ip6_sf_socklist *psl;
542 group = &((struct sockaddr_in6 *)&gsf->gf_group)->sin6_addr;
544 if (!ipv6_addr_is_multicast(group))
547 idev = ip6_mc_find_dev(group, gsf->gf_interface);
554 err = -EADDRNOTAVAIL;
556 for (pmc=inet6->ipv6_mc_list; pmc; pmc=pmc->next) {
557 if (pmc->ifindex != gsf->gf_interface)
559 if (ipv6_addr_cmp(group, &pmc->addr) == 0)
562 if (!pmc) /* must have a prior join */
564 gsf->gf_fmode = pmc->sfmode;
566 count = psl ? psl->sl_count : 0;
567 read_unlock_bh(&idev->lock);
571 copycount = count < gsf->gf_numsrc ? count : gsf->gf_numsrc;
572 gsf->gf_numsrc = count;
573 if (put_user(GROUP_FILTER_SIZE(copycount), optlen) ||
574 copy_to_user(optval, gsf, GROUP_FILTER_SIZE(0))) {
577 for (i=0; i<copycount; i++) {
578 struct sockaddr_in6 *psin6;
579 struct sockaddr_storage ss;
581 psin6 = (struct sockaddr_in6 *)&ss;
582 memset(&ss, 0, sizeof(ss));
583 psin6->sin6_family = AF_INET6;
584 psin6->sin6_addr = psl->sl_addr[i];
585 if (copy_to_user(&optval->gf_slist[i], &ss, sizeof(ss)))
590 read_unlock_bh(&idev->lock);
596 int inet6_mc_check(struct sock *sk, struct in6_addr *mc_addr,
597 struct in6_addr *src_addr)
599 struct ipv6_pinfo *np = inet6_sk(sk);
600 struct ipv6_mc_socklist *mc;
601 struct ip6_sf_socklist *psl;
604 read_lock(&ipv6_sk_mc_lock);
605 for (mc = np->ipv6_mc_list; mc; mc = mc->next) {
606 if (ipv6_addr_cmp(&mc->addr, mc_addr) == 0)
610 read_unlock(&ipv6_sk_mc_lock);
615 rv = mc->sfmode == MCAST_EXCLUDE;
619 for (i=0; i<psl->sl_count; i++) {
620 if (ipv6_addr_cmp(&psl->sl_addr[i], src_addr) == 0)
623 if (mc->sfmode == MCAST_INCLUDE && i >= psl->sl_count)
625 if (mc->sfmode == MCAST_EXCLUDE && i < psl->sl_count)
628 read_unlock(&ipv6_sk_mc_lock);
633 static void ma_put(struct ifmcaddr6 *mc)
635 if (atomic_dec_and_test(&mc->mca_refcnt)) {
636 in6_dev_put(mc->idev);
641 static void igmp6_group_added(struct ifmcaddr6 *mc)
643 struct net_device *dev = mc->idev->dev;
644 char buf[MAX_ADDR_LEN];
646 spin_lock_bh(&mc->mca_lock);
647 if (!(mc->mca_flags&MAF_LOADED)) {
648 mc->mca_flags |= MAF_LOADED;
649 if (ndisc_mc_map(&mc->mca_addr, buf, dev, 0) == 0)
650 dev_mc_add(dev, buf, dev->addr_len, 0);
652 spin_unlock_bh(&mc->mca_lock);
654 if (!(dev->flags & IFF_UP) || (mc->mca_flags & MAF_NOREPORT))
657 if (MLD_V1_SEEN(mc->idev)) {
658 igmp6_join_group(mc);
663 mc->mca_crcount = mc->idev->mc_qrv;
664 mld_ifc_event(mc->idev);
667 static void igmp6_group_dropped(struct ifmcaddr6 *mc)
669 struct net_device *dev = mc->idev->dev;
670 char buf[MAX_ADDR_LEN];
672 spin_lock_bh(&mc->mca_lock);
673 if (mc->mca_flags&MAF_LOADED) {
674 mc->mca_flags &= ~MAF_LOADED;
675 if (ndisc_mc_map(&mc->mca_addr, buf, dev, 0) == 0)
676 dev_mc_delete(dev, buf, dev->addr_len, 0);
679 if (mc->mca_flags & MAF_NOREPORT)
681 spin_unlock_bh(&mc->mca_lock);
684 igmp6_leave_group(mc);
686 spin_lock_bh(&mc->mca_lock);
687 if (del_timer(&mc->mca_timer))
688 atomic_dec(&mc->mca_refcnt);
690 ip6_mc_clear_src(mc);
691 spin_unlock_bh(&mc->mca_lock);
695 * deleted ifmcaddr6 manipulation
697 static void mld_add_delrec(struct inet6_dev *idev, struct ifmcaddr6 *im)
699 struct ifmcaddr6 *pmc;
701 /* this is an "ifmcaddr6" for convenience; only the fields below
702 * are actually used. In particular, the refcnt and users are not
703 * used for management of the delete list. Using the same structure
704 * for deleted items allows change reports to use common code with
705 * non-deleted or query-response MCA's.
707 pmc = (struct ifmcaddr6 *)kmalloc(sizeof(*pmc), GFP_ATOMIC);
710 memset(pmc, 0, sizeof(*pmc));
711 spin_lock_bh(&im->mca_lock);
712 pmc->mca_lock = SPIN_LOCK_UNLOCKED;
713 pmc->idev = im->idev;
715 pmc->mca_addr = im->mca_addr;
716 pmc->mca_crcount = idev->mc_qrv;
717 pmc->mca_sfmode = im->mca_sfmode;
718 if (pmc->mca_sfmode == MCAST_INCLUDE) {
719 struct ip6_sf_list *psf;
721 pmc->mca_tomb = im->mca_tomb;
722 pmc->mca_sources = im->mca_sources;
723 im->mca_tomb = im->mca_sources = NULL;
724 for (psf=pmc->mca_sources; psf; psf=psf->sf_next)
725 psf->sf_crcount = pmc->mca_crcount;
727 spin_unlock_bh(&im->mca_lock);
729 write_lock_bh(&idev->mc_lock);
730 pmc->next = idev->mc_tomb;
732 write_unlock_bh(&idev->mc_lock);
735 static void mld_del_delrec(struct inet6_dev *idev, struct in6_addr *pmca)
737 struct ifmcaddr6 *pmc, *pmc_prev;
738 struct ip6_sf_list *psf, *psf_next;
740 write_lock_bh(&idev->mc_lock);
742 for (pmc=idev->mc_tomb; pmc; pmc=pmc->next) {
743 if (ipv6_addr_cmp(&pmc->mca_addr, pmca) == 0)
749 pmc_prev->next = pmc->next;
751 idev->mc_tomb = pmc->next;
753 write_unlock_bh(&idev->mc_lock);
755 for (psf=pmc->mca_tomb; psf; psf=psf_next) {
756 psf_next = psf->sf_next;
759 in6_dev_put(pmc->idev);
764 static void mld_clear_delrec(struct inet6_dev *idev)
766 struct ifmcaddr6 *pmc, *nextpmc;
768 write_lock_bh(&idev->mc_lock);
770 idev->mc_tomb = NULL;
771 write_unlock_bh(&idev->mc_lock);
773 for (; pmc; pmc = nextpmc) {
775 ip6_mc_clear_src(pmc);
776 in6_dev_put(pmc->idev);
780 /* clear dead sources, too */
781 read_lock_bh(&idev->lock);
782 for (pmc=idev->mc_list; pmc; pmc=pmc->next) {
783 struct ip6_sf_list *psf, *psf_next;
785 spin_lock_bh(&pmc->mca_lock);
787 pmc->mca_tomb = NULL;
788 spin_unlock_bh(&pmc->mca_lock);
789 for (; psf; psf=psf_next) {
790 psf_next = psf->sf_next;
794 read_unlock_bh(&idev->lock);
799 * device multicast group inc (add if not found)
801 int ipv6_dev_mc_inc(struct net_device *dev, struct in6_addr *addr)
803 struct ifmcaddr6 *mc;
804 struct inet6_dev *idev;
806 idev = in6_dev_get(dev);
811 write_lock_bh(&idev->lock);
813 write_unlock_bh(&idev->lock);
818 for (mc = idev->mc_list; mc; mc = mc->next) {
819 if (ipv6_addr_cmp(&mc->mca_addr, addr) == 0) {
821 write_unlock_bh(&idev->lock);
822 ip6_mc_add_src(idev, &mc->mca_addr, MCAST_EXCLUDE, 0,
830 * not found: create a new one.
833 mc = kmalloc(sizeof(struct ifmcaddr6), GFP_ATOMIC);
836 write_unlock_bh(&idev->lock);
841 memset(mc, 0, sizeof(struct ifmcaddr6));
842 init_timer(&mc->mca_timer);
843 mc->mca_timer.function = igmp6_timer_handler;
844 mc->mca_timer.data = (unsigned long) mc;
846 ipv6_addr_copy(&mc->mca_addr, addr);
849 /* mca_stamp should be updated upon changes */
850 mc->mca_cstamp = mc->mca_tstamp = jiffies;
851 atomic_set(&mc->mca_refcnt, 2);
852 mc->mca_lock = SPIN_LOCK_UNLOCKED;
854 /* initial mode is (EX, empty) */
855 mc->mca_sfmode = MCAST_EXCLUDE;
856 mc->mca_sfcount[MCAST_EXCLUDE] = 1;
858 if (ipv6_addr_is_ll_all_nodes(&mc->mca_addr) ||
859 IPV6_ADDR_MC_SCOPE(&mc->mca_addr) < IPV6_ADDR_SCOPE_LINKLOCAL)
860 mc->mca_flags |= MAF_NOREPORT;
862 mc->next = idev->mc_list;
864 write_unlock_bh(&idev->lock);
866 mld_del_delrec(idev, &mc->mca_addr);
867 igmp6_group_added(mc);
873 * device multicast group del
875 int __ipv6_dev_mc_dec(struct inet6_dev *idev, struct in6_addr *addr)
877 struct ifmcaddr6 *ma, **map;
879 write_lock_bh(&idev->lock);
880 for (map = &idev->mc_list; (ma=*map) != NULL; map = &ma->next) {
881 if (ipv6_addr_cmp(&ma->mca_addr, addr) == 0) {
882 if (--ma->mca_users == 0) {
884 write_unlock_bh(&idev->lock);
886 igmp6_group_dropped(ma);
891 write_unlock_bh(&idev->lock);
895 write_unlock_bh(&idev->lock);
900 int ipv6_dev_mc_dec(struct net_device *dev, struct in6_addr *addr)
902 struct inet6_dev *idev = in6_dev_get(dev);
908 err = __ipv6_dev_mc_dec(idev, addr);
916 * identify MLD packets for MLD filter exceptions
918 int ipv6_is_mld(struct sk_buff *skb, int nexthdr)
920 struct icmp6hdr *pic;
922 if (nexthdr != IPPROTO_ICMPV6)
925 if (!pskb_may_pull(skb, sizeof(struct icmp6hdr)))
928 pic = (struct icmp6hdr *)skb->h.raw;
930 switch (pic->icmp6_type) {
931 case ICMPV6_MGM_QUERY:
932 case ICMPV6_MGM_REPORT:
933 case ICMPV6_MGM_REDUCTION:
934 case ICMPV6_MLD2_REPORT:
943 * check if the interface/address pair is valid
945 int ipv6_chk_mcast_addr(struct net_device *dev, struct in6_addr *group,
946 struct in6_addr *src_addr)
948 struct inet6_dev *idev;
949 struct ifmcaddr6 *mc;
952 idev = in6_dev_get(dev);
954 read_lock_bh(&idev->lock);
955 for (mc = idev->mc_list; mc; mc=mc->next) {
956 if (ipv6_addr_cmp(&mc->mca_addr, group) == 0)
960 if (src_addr && !ipv6_addr_any(src_addr)) {
961 struct ip6_sf_list *psf;
963 spin_lock_bh(&mc->mca_lock);
964 for (psf=mc->mca_sources;psf;psf=psf->sf_next) {
965 if (ipv6_addr_cmp(&psf->sf_addr,
970 rv = psf->sf_count[MCAST_INCLUDE] ||
971 psf->sf_count[MCAST_EXCLUDE] !=
972 mc->mca_sfcount[MCAST_EXCLUDE];
974 rv = mc->mca_sfcount[MCAST_EXCLUDE] !=0;
975 spin_unlock_bh(&mc->mca_lock);
977 rv = 1; /* don't filter unspecified source */
979 read_unlock_bh(&idev->lock);
985 static void mld_gq_start_timer(struct inet6_dev *idev)
987 int tv = net_random() % idev->mc_maxdelay;
989 idev->mc_gq_running = 1;
990 if (!mod_timer(&idev->mc_gq_timer, jiffies+tv+2))
994 static void mld_ifc_start_timer(struct inet6_dev *idev, int delay)
996 int tv = net_random() % delay;
998 if (!mod_timer(&idev->mc_ifc_timer, jiffies+tv+2))
1003 * IGMP handling (alias multicast ICMPv6 messages)
1006 static void igmp6_group_queried(struct ifmcaddr6 *ma, unsigned long resptime)
1008 unsigned long delay = resptime;
1010 /* Do not start timer for these addresses */
1011 if (ipv6_addr_is_ll_all_nodes(&ma->mca_addr) ||
1012 IPV6_ADDR_MC_SCOPE(&ma->mca_addr) < IPV6_ADDR_SCOPE_LINKLOCAL)
1015 if (del_timer(&ma->mca_timer)) {
1016 atomic_dec(&ma->mca_refcnt);
1017 delay = ma->mca_timer.expires - jiffies;
1020 if (delay >= resptime) {
1022 delay = net_random() % resptime;
1026 ma->mca_timer.expires = jiffies + delay;
1027 if (!mod_timer(&ma->mca_timer, jiffies + delay))
1028 atomic_inc(&ma->mca_refcnt);
1029 ma->mca_flags |= MAF_TIMER_RUNNING;
1032 static void mld_marksources(struct ifmcaddr6 *pmc, int nsrcs,
1033 struct in6_addr *srcs)
1035 struct ip6_sf_list *psf;
1039 for (psf=pmc->mca_sources; psf; psf=psf->sf_next) {
1040 if (scount == nsrcs)
1042 for (i=0; i<nsrcs; i++)
1043 if (ipv6_addr_cmp(&srcs[i], &psf->sf_addr) == 0) {
1051 int igmp6_event_query(struct sk_buff *skb)
1053 struct mld2_query *mlh2 = (struct mld2_query *) skb->h.raw;
1054 struct ifmcaddr6 *ma;
1055 struct in6_addr *group;
1056 unsigned long max_delay;
1057 struct inet6_dev *idev;
1058 struct icmp6hdr *hdr;
1063 if (!pskb_may_pull(skb, sizeof(struct in6_addr)))
1066 /* compute payload length excluding extension headers */
1067 len = ntohs(skb->nh.ipv6h->payload_len) + sizeof(struct ipv6hdr);
1068 len -= (char *)skb->h.raw - (char *)skb->nh.ipv6h;
1070 /* Drop queries with not link local source */
1071 if (!(ipv6_addr_type(&skb->nh.ipv6h->saddr)&IPV6_ADDR_LINKLOCAL))
1074 idev = in6_dev_get(skb->dev);
1079 hdr = (struct icmp6hdr *) skb->h.raw;
1080 group = (struct in6_addr *) (hdr + 1);
1081 group_type = ipv6_addr_type(group);
1083 if (group_type != IPV6_ADDR_ANY &&
1084 !(group_type&IPV6_ADDR_MULTICAST)) {
1091 /* MLDv1 router present */
1093 /* Translate milliseconds to jiffies */
1094 max_delay = (ntohs(hdr->icmp6_maxdelay)*HZ)/1000;
1096 switchback = (idev->mc_qrv + 1) * max_delay;
1097 idev->mc_v1_seen = jiffies + switchback;
1099 /* cancel the interface change timer */
1100 idev->mc_ifc_count = 0;
1101 if (del_timer(&idev->mc_ifc_timer))
1102 __in6_dev_put(idev);
1103 /* clear deleted report items */
1104 mld_clear_delrec(idev);
1105 } else if (len >= 28) {
1106 max_delay = (MLDV2_MRC(ntohs(mlh2->mrc))*HZ)/1000;
1109 idev->mc_maxdelay = max_delay;
1111 idev->mc_qrv = mlh2->qrv;
1112 if (group_type == IPV6_ADDR_ANY) { /* general query */
1115 return -EINVAL; /* no sources allowed */
1117 mld_gq_start_timer(idev);
1121 /* mark sources to include, if group & source-specific */
1122 mark = mlh2->nsrcs != 0;
1128 read_lock_bh(&idev->lock);
1129 if (group_type == IPV6_ADDR_ANY) {
1130 for (ma = idev->mc_list; ma; ma=ma->next) {
1131 spin_lock_bh(&ma->mca_lock);
1132 igmp6_group_queried(ma, max_delay);
1133 spin_unlock_bh(&ma->mca_lock);
1136 for (ma = idev->mc_list; ma; ma=ma->next) {
1137 if (group_type != IPV6_ADDR_ANY &&
1138 ipv6_addr_cmp(group, &ma->mca_addr) != 0)
1140 spin_lock_bh(&ma->mca_lock);
1141 if (ma->mca_flags & MAF_TIMER_RUNNING) {
1142 /* gsquery <- gsquery && mark */
1144 ma->mca_flags &= ~MAF_GSQUERY;
1146 /* gsquery <- mark */
1148 ma->mca_flags |= MAF_GSQUERY;
1150 ma->mca_flags &= ~MAF_GSQUERY;
1152 if (ma->mca_flags & MAF_GSQUERY)
1153 mld_marksources(ma, ntohs(mlh2->nsrcs),
1155 igmp6_group_queried(ma, max_delay);
1156 spin_unlock_bh(&ma->mca_lock);
1157 if (group_type != IPV6_ADDR_ANY)
1161 read_unlock_bh(&idev->lock);
1168 int igmp6_event_report(struct sk_buff *skb)
1170 struct ifmcaddr6 *ma;
1171 struct in6_addr *addrp;
1172 struct inet6_dev *idev;
1173 struct icmp6hdr *hdr;
1176 /* Our own report looped back. Ignore it. */
1177 if (skb->pkt_type == PACKET_LOOPBACK)
1180 if (!pskb_may_pull(skb, sizeof(struct in6_addr)))
1183 hdr = (struct icmp6hdr*) skb->h.raw;
1185 /* Drop reports with not link local source */
1186 addr_type = ipv6_addr_type(&skb->nh.ipv6h->saddr);
1187 if (addr_type != IPV6_ADDR_ANY &&
1188 !(addr_type&IPV6_ADDR_LINKLOCAL))
1191 addrp = (struct in6_addr *) (hdr + 1);
1193 idev = in6_dev_get(skb->dev);
1198 * Cancel the timer for this group
1201 read_lock_bh(&idev->lock);
1202 for (ma = idev->mc_list; ma; ma=ma->next) {
1203 if (ipv6_addr_cmp(&ma->mca_addr, addrp) == 0) {
1204 spin_lock(&ma->mca_lock);
1205 if (del_timer(&ma->mca_timer))
1206 atomic_dec(&ma->mca_refcnt);
1207 ma->mca_flags &= ~(MAF_LAST_REPORTER|MAF_TIMER_RUNNING);
1208 spin_unlock(&ma->mca_lock);
1212 read_unlock_bh(&idev->lock);
1217 static int is_in(struct ifmcaddr6 *pmc, struct ip6_sf_list *psf, int type,
1218 int gdeleted, int sdeleted)
1221 case MLD2_MODE_IS_INCLUDE:
1222 case MLD2_MODE_IS_EXCLUDE:
1223 if (gdeleted || sdeleted)
1225 return !((pmc->mca_flags & MAF_GSQUERY) && !psf->sf_gsresp);
1226 case MLD2_CHANGE_TO_INCLUDE:
1227 if (gdeleted || sdeleted)
1229 return psf->sf_count[MCAST_INCLUDE] != 0;
1230 case MLD2_CHANGE_TO_EXCLUDE:
1231 if (gdeleted || sdeleted)
1233 if (pmc->mca_sfcount[MCAST_EXCLUDE] == 0 ||
1234 psf->sf_count[MCAST_INCLUDE])
1236 return pmc->mca_sfcount[MCAST_EXCLUDE] ==
1237 psf->sf_count[MCAST_EXCLUDE];
1238 case MLD2_ALLOW_NEW_SOURCES:
1239 if (gdeleted || !psf->sf_crcount)
1241 return (pmc->mca_sfmode == MCAST_INCLUDE) ^ sdeleted;
1242 case MLD2_BLOCK_OLD_SOURCES:
1243 if (pmc->mca_sfmode == MCAST_INCLUDE)
1244 return gdeleted || (psf->sf_crcount && sdeleted);
1245 return psf->sf_crcount && !gdeleted && !sdeleted;
1251 mld_scount(struct ifmcaddr6 *pmc, int type, int gdeleted, int sdeleted)
1253 struct ip6_sf_list *psf;
1256 for (psf=pmc->mca_sources; psf; psf=psf->sf_next) {
1257 if (!is_in(pmc, psf, type, gdeleted, sdeleted))
1264 static struct sk_buff *mld_newpack(struct net_device *dev, int size)
1266 struct sock *sk = igmp6_socket->sk;
1267 struct sk_buff *skb;
1268 struct mld2_report *pmr;
1269 struct in6_addr addr_buf;
1271 u8 ra[8] = { IPPROTO_ICMPV6, 0,
1272 IPV6_TLV_ROUTERALERT, 2, 0, 0,
1275 /* we assume size > sizeof(ra) here */
1276 skb = sock_alloc_send_skb(sk, size + LL_RESERVED_SPACE(dev), 1, &err);
1281 skb_reserve(skb, LL_RESERVED_SPACE(dev));
1282 if (dev->hard_header) {
1283 unsigned char ha[MAX_ADDR_LEN];
1285 ndisc_mc_map(&mld2_all_mcr, ha, dev, 1);
1286 if (dev->hard_header(skb, dev, ETH_P_IPV6,ha,NULL,size) < 0) {
1292 if (ipv6_get_lladdr(dev, &addr_buf)) {
1293 /* <draft-ietf-magma-mld-source-05.txt>:
1294 * use unspecified address as the source address
1295 * when a valid link-local address is not available.
1297 memset(&addr_buf, 0, sizeof(addr_buf));
1300 ip6_nd_hdr(sk, skb, dev, &addr_buf, &mld2_all_mcr, NEXTHDR_HOP, 0);
1302 memcpy(skb_put(skb, sizeof(ra)), ra, sizeof(ra));
1304 pmr =(struct mld2_report *)skb_put(skb, sizeof(*pmr));
1305 skb->h.raw = (unsigned char *)pmr;
1306 pmr->type = ICMPV6_MLD2_REPORT;
1314 static void mld_sendpack(struct sk_buff *skb)
1316 struct ipv6hdr *pip6 = skb->nh.ipv6h;
1317 struct mld2_report *pmr = (struct mld2_report *)skb->h.raw;
1318 int payload_len, mldlen;
1319 struct inet6_dev *idev = in6_dev_get(skb->dev);
1322 IP6_INC_STATS(IPSTATS_MIB_OUTREQUESTS);
1323 payload_len = skb->tail - (unsigned char *)skb->nh.ipv6h -
1324 sizeof(struct ipv6hdr);
1325 mldlen = skb->tail - skb->h.raw;
1326 pip6->payload_len = htons(payload_len);
1328 pmr->csum = csum_ipv6_magic(&pip6->saddr, &pip6->daddr, mldlen,
1329 IPPROTO_ICMPV6, csum_partial(skb->h.raw, mldlen, 0));
1330 err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, skb->dev,
1333 ICMP6_INC_STATS(idev,ICMP6_MIB_OUTMSGS);
1334 IP6_INC_STATS(IPSTATS_MIB_OUTMCASTPKTS);
1336 IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
1338 if (likely(idev != NULL))
1342 static int grec_size(struct ifmcaddr6 *pmc, int type, int gdel, int sdel)
1344 return sizeof(struct mld2_grec) + 4*mld_scount(pmc,type,gdel,sdel);
1347 static struct sk_buff *add_grhead(struct sk_buff *skb, struct ifmcaddr6 *pmc,
1348 int type, struct mld2_grec **ppgr)
1350 struct net_device *dev = pmc->idev->dev;
1351 struct mld2_report *pmr;
1352 struct mld2_grec *pgr;
1355 skb = mld_newpack(dev, dev->mtu);
1358 pgr = (struct mld2_grec *)skb_put(skb, sizeof(struct mld2_grec));
1359 pgr->grec_type = type;
1360 pgr->grec_auxwords = 0;
1361 pgr->grec_nsrcs = 0;
1362 pgr->grec_mca = pmc->mca_addr; /* structure copy */
1363 pmr = (struct mld2_report *)skb->h.raw;
1364 pmr->ngrec = htons(ntohs(pmr->ngrec)+1);
1369 #define AVAILABLE(skb) ((skb) ? ((skb)->dev ? (skb)->dev->mtu - (skb)->len : \
1370 skb_tailroom(skb)) : 0)
1372 static struct sk_buff *add_grec(struct sk_buff *skb, struct ifmcaddr6 *pmc,
1373 int type, int gdeleted, int sdeleted)
1375 struct net_device *dev = pmc->idev->dev;
1376 struct mld2_report *pmr;
1377 struct mld2_grec *pgr = NULL;
1378 struct ip6_sf_list *psf, *psf_next, *psf_prev, **psf_list;
1379 int scount, first, isquery, truncate;
1381 if (pmc->mca_flags & MAF_NOREPORT)
1384 isquery = type == MLD2_MODE_IS_INCLUDE ||
1385 type == MLD2_MODE_IS_EXCLUDE;
1386 truncate = type == MLD2_MODE_IS_EXCLUDE ||
1387 type == MLD2_CHANGE_TO_EXCLUDE;
1389 psf_list = sdeleted ? &pmc->mca_tomb : &pmc->mca_sources;
1392 if (type == MLD2_ALLOW_NEW_SOURCES ||
1393 type == MLD2_BLOCK_OLD_SOURCES)
1395 if (pmc->mca_crcount || isquery) {
1396 /* make sure we have room for group header and at
1399 if (skb && AVAILABLE(skb) < sizeof(struct mld2_grec)+
1400 sizeof(struct in6_addr)) {
1402 skb = NULL; /* add_grhead will get a new one */
1404 skb = add_grhead(skb, pmc, type, &pgr);
1408 pmr = skb ? (struct mld2_report *)skb->h.raw : NULL;
1410 /* EX and TO_EX get a fresh packet, if needed */
1412 if (pmr && pmr->ngrec &&
1413 AVAILABLE(skb) < grec_size(pmc, type, gdeleted, sdeleted)) {
1416 skb = mld_newpack(dev, dev->mtu);
1422 for (psf=*psf_list; psf; psf=psf_next) {
1423 struct in6_addr *psrc;
1425 psf_next = psf->sf_next;
1427 if (!is_in(pmc, psf, type, gdeleted, sdeleted)) {
1432 /* clear marks on query responses */
1436 if (AVAILABLE(skb) < sizeof(*psrc) +
1437 first*sizeof(struct mld2_grec)) {
1438 if (truncate && !first)
1439 break; /* truncate these */
1441 pgr->grec_nsrcs = htons(scount);
1444 skb = mld_newpack(dev, dev->mtu);
1449 skb = add_grhead(skb, pmc, type, &pgr);
1452 psrc = (struct in6_addr *)skb_put(skb, sizeof(*psrc));
1453 *psrc = psf->sf_addr;
1455 if ((type == MLD2_ALLOW_NEW_SOURCES ||
1456 type == MLD2_BLOCK_OLD_SOURCES) && psf->sf_crcount) {
1458 if ((sdeleted || gdeleted) && psf->sf_crcount == 0) {
1460 psf_prev->sf_next = psf->sf_next;
1462 *psf_list = psf->sf_next;
1470 pgr->grec_nsrcs = htons(scount);
1473 pmc->mca_flags &= ~MAF_GSQUERY; /* clear query state */
1477 static void mld_send_report(struct inet6_dev *idev, struct ifmcaddr6 *pmc)
1479 struct sk_buff *skb = NULL;
1483 read_lock_bh(&idev->lock);
1484 for (pmc=idev->mc_list; pmc; pmc=pmc->next) {
1485 if (pmc->mca_flags & MAF_NOREPORT)
1487 spin_lock_bh(&pmc->mca_lock);
1488 if (pmc->mca_sfcount[MCAST_EXCLUDE])
1489 type = MLD2_MODE_IS_EXCLUDE;
1491 type = MLD2_MODE_IS_INCLUDE;
1492 skb = add_grec(skb, pmc, type, 0, 0);
1493 spin_unlock_bh(&pmc->mca_lock);
1495 read_unlock_bh(&idev->lock);
1497 spin_lock_bh(&pmc->mca_lock);
1498 if (pmc->mca_sfcount[MCAST_EXCLUDE])
1499 type = MLD2_MODE_IS_EXCLUDE;
1501 type = MLD2_MODE_IS_INCLUDE;
1502 skb = add_grec(skb, pmc, type, 0, 0);
1503 spin_unlock_bh(&pmc->mca_lock);
1510 * remove zero-count source records from a source filter list
1512 static void mld_clear_zeros(struct ip6_sf_list **ppsf)
1514 struct ip6_sf_list *psf_prev, *psf_next, *psf;
1517 for (psf=*ppsf; psf; psf = psf_next) {
1518 psf_next = psf->sf_next;
1519 if (psf->sf_crcount == 0) {
1521 psf_prev->sf_next = psf->sf_next;
1523 *ppsf = psf->sf_next;
1530 static void mld_send_cr(struct inet6_dev *idev)
1532 struct ifmcaddr6 *pmc, *pmc_prev, *pmc_next;
1533 struct sk_buff *skb = NULL;
1536 read_lock_bh(&idev->lock);
1537 write_lock_bh(&idev->mc_lock);
1541 for (pmc=idev->mc_tomb; pmc; pmc=pmc_next) {
1542 pmc_next = pmc->next;
1543 if (pmc->mca_sfmode == MCAST_INCLUDE) {
1544 type = MLD2_BLOCK_OLD_SOURCES;
1545 dtype = MLD2_BLOCK_OLD_SOURCES;
1546 skb = add_grec(skb, pmc, type, 1, 0);
1547 skb = add_grec(skb, pmc, dtype, 1, 1);
1549 if (pmc->mca_crcount) {
1551 if (pmc->mca_sfmode == MCAST_EXCLUDE) {
1552 type = MLD2_CHANGE_TO_INCLUDE;
1553 skb = add_grec(skb, pmc, type, 1, 0);
1555 if (pmc->mca_crcount == 0) {
1556 mld_clear_zeros(&pmc->mca_tomb);
1557 mld_clear_zeros(&pmc->mca_sources);
1560 if (pmc->mca_crcount == 0 && !pmc->mca_tomb &&
1561 !pmc->mca_sources) {
1563 pmc_prev->next = pmc_next;
1565 idev->mc_tomb = pmc_next;
1566 in6_dev_put(pmc->idev);
1571 write_unlock_bh(&idev->mc_lock);
1574 for (pmc=idev->mc_list; pmc; pmc=pmc->next) {
1575 spin_lock_bh(&pmc->mca_lock);
1576 if (pmc->mca_sfcount[MCAST_EXCLUDE]) {
1577 type = MLD2_BLOCK_OLD_SOURCES;
1578 dtype = MLD2_ALLOW_NEW_SOURCES;
1580 type = MLD2_ALLOW_NEW_SOURCES;
1581 dtype = MLD2_BLOCK_OLD_SOURCES;
1583 skb = add_grec(skb, pmc, type, 0, 0);
1584 skb = add_grec(skb, pmc, dtype, 0, 1); /* deleted sources */
1586 /* filter mode changes */
1587 if (pmc->mca_crcount) {
1589 if (pmc->mca_sfmode == MCAST_EXCLUDE)
1590 type = MLD2_CHANGE_TO_EXCLUDE;
1592 type = MLD2_CHANGE_TO_INCLUDE;
1593 skb = add_grec(skb, pmc, type, 0, 0);
1595 spin_unlock_bh(&pmc->mca_lock);
1597 read_unlock_bh(&idev->lock);
1600 (void) mld_sendpack(skb);
1603 static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type)
1605 struct sock *sk = igmp6_socket->sk;
1606 struct inet6_dev *idev;
1607 struct sk_buff *skb;
1608 struct icmp6hdr *hdr;
1609 struct in6_addr *snd_addr;
1610 struct in6_addr *addrp;
1611 struct in6_addr addr_buf;
1612 struct in6_addr all_routers;
1613 int err, len, payload_len, full_len;
1614 u8 ra[8] = { IPPROTO_ICMPV6, 0,
1615 IPV6_TLV_ROUTERALERT, 2, 0, 0,
1618 IP6_INC_STATS(IPSTATS_MIB_OUTREQUESTS);
1620 if (type == ICMPV6_MGM_REDUCTION) {
1621 snd_addr = &all_routers;
1622 ipv6_addr_all_routers(&all_routers);
1625 len = sizeof(struct icmp6hdr) + sizeof(struct in6_addr);
1626 payload_len = len + sizeof(ra);
1627 full_len = sizeof(struct ipv6hdr) + payload_len;
1629 skb = sock_alloc_send_skb(sk, LL_RESERVED_SPACE(dev) + full_len, 1, &err);
1632 IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
1636 skb_reserve(skb, LL_RESERVED_SPACE(dev));
1637 if (dev->hard_header) {
1638 unsigned char ha[MAX_ADDR_LEN];
1639 ndisc_mc_map(snd_addr, ha, dev, 1);
1640 if (dev->hard_header(skb, dev, ETH_P_IPV6, ha, NULL, full_len) < 0)
1644 if (ipv6_get_lladdr(dev, &addr_buf)) {
1645 /* <draft-ietf-magma-mld-source-05.txt>:
1646 * use unspecified address as the source address
1647 * when a valid link-local address is not available.
1649 memset(&addr_buf, 0, sizeof(addr_buf));
1652 ip6_nd_hdr(sk, skb, dev, &addr_buf, snd_addr, NEXTHDR_HOP, payload_len);
1654 memcpy(skb_put(skb, sizeof(ra)), ra, sizeof(ra));
1656 hdr = (struct icmp6hdr *) skb_put(skb, sizeof(struct icmp6hdr));
1657 memset(hdr, 0, sizeof(struct icmp6hdr));
1658 hdr->icmp6_type = type;
1660 addrp = (struct in6_addr *) skb_put(skb, sizeof(struct in6_addr));
1661 ipv6_addr_copy(addrp, addr);
1663 hdr->icmp6_cksum = csum_ipv6_magic(&addr_buf, snd_addr, len,
1665 csum_partial((__u8 *) hdr, len, 0));
1667 idev = in6_dev_get(skb->dev);
1669 err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, skb->dev,
1672 if (type == ICMPV6_MGM_REDUCTION)
1673 ICMP6_INC_STATS(idev, ICMP6_MIB_OUTGROUPMEMBREDUCTIONS);
1675 ICMP6_INC_STATS(idev, ICMP6_MIB_OUTGROUPMEMBRESPONSES);
1676 ICMP6_INC_STATS(idev, ICMP6_MIB_OUTMSGS);
1677 IP6_INC_STATS(IPSTATS_MIB_OUTMCASTPKTS);
1679 IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
1681 if (likely(idev != NULL))
1686 IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
1690 static int ip6_mc_del1_src(struct ifmcaddr6 *pmc, int sfmode,
1691 struct in6_addr *psfsrc)
1693 struct ip6_sf_list *psf, *psf_prev;
1697 for (psf=pmc->mca_sources; psf; psf=psf->sf_next) {
1698 if (ipv6_addr_cmp(&psf->sf_addr, psfsrc) == 0)
1702 if (!psf || psf->sf_count[sfmode] == 0) {
1703 /* source filter not found, or count wrong => bug */
1706 psf->sf_count[sfmode]--;
1707 if (!psf->sf_count[MCAST_INCLUDE] && !psf->sf_count[MCAST_EXCLUDE]) {
1708 struct inet6_dev *idev = pmc->idev;
1710 /* no more filters for this source */
1712 psf_prev->sf_next = psf->sf_next;
1714 pmc->mca_sources = psf->sf_next;
1715 if (psf->sf_oldin && !(pmc->mca_flags & MAF_NOREPORT) &&
1716 !MLD_V1_SEEN(idev)) {
1717 psf->sf_crcount = idev->mc_qrv;
1718 psf->sf_next = pmc->mca_tomb;
1719 pmc->mca_tomb = psf;
1727 int ip6_mc_del_src(struct inet6_dev *idev, struct in6_addr *pmca, int sfmode,
1728 int sfcount, struct in6_addr *psfsrc, int delta)
1730 struct ifmcaddr6 *pmc;
1736 read_lock_bh(&idev->lock);
1737 for (pmc=idev->mc_list; pmc; pmc=pmc->next) {
1738 if (ipv6_addr_cmp(pmca, &pmc->mca_addr) == 0)
1742 /* MCA not found?? bug */
1743 read_unlock_bh(&idev->lock);
1746 spin_lock_bh(&pmc->mca_lock);
1749 if (!pmc->mca_sfcount[sfmode]) {
1750 spin_unlock_bh(&pmc->mca_lock);
1751 read_unlock_bh(&idev->lock);
1754 pmc->mca_sfcount[sfmode]--;
1757 for (i=0; i<sfcount; i++) {
1758 int rv = ip6_mc_del1_src(pmc, sfmode, &psfsrc[i]);
1760 changerec |= rv > 0;
1764 if (pmc->mca_sfmode == MCAST_EXCLUDE &&
1765 pmc->mca_sfcount[MCAST_EXCLUDE] == 0 &&
1766 pmc->mca_sfcount[MCAST_INCLUDE]) {
1767 struct ip6_sf_list *psf;
1769 /* filter mode change */
1770 pmc->mca_sfmode = MCAST_INCLUDE;
1771 pmc->mca_crcount = idev->mc_qrv;
1772 idev->mc_ifc_count = pmc->mca_crcount;
1773 for (psf=pmc->mca_sources; psf; psf = psf->sf_next)
1774 psf->sf_crcount = 0;
1775 mld_ifc_event(pmc->idev);
1776 } else if (sf_setstate(pmc) || changerec)
1777 mld_ifc_event(pmc->idev);
1778 spin_unlock_bh(&pmc->mca_lock);
1779 read_unlock_bh(&idev->lock);
1784 * Add multicast single-source filter to the interface list
1786 static int ip6_mc_add1_src(struct ifmcaddr6 *pmc, int sfmode,
1787 struct in6_addr *psfsrc, int delta)
1789 struct ip6_sf_list *psf, *psf_prev;
1792 for (psf=pmc->mca_sources; psf; psf=psf->sf_next) {
1793 if (ipv6_addr_cmp(&psf->sf_addr, psfsrc) == 0)
1798 psf = (struct ip6_sf_list *)kmalloc(sizeof(*psf), GFP_ATOMIC);
1801 memset(psf, 0, sizeof(*psf));
1802 psf->sf_addr = *psfsrc;
1804 psf_prev->sf_next = psf;
1806 pmc->mca_sources = psf;
1808 psf->sf_count[sfmode]++;
1812 static void sf_markstate(struct ifmcaddr6 *pmc)
1814 struct ip6_sf_list *psf;
1815 int mca_xcount = pmc->mca_sfcount[MCAST_EXCLUDE];
1817 for (psf=pmc->mca_sources; psf; psf=psf->sf_next)
1818 if (pmc->mca_sfcount[MCAST_EXCLUDE]) {
1819 psf->sf_oldin = mca_xcount ==
1820 psf->sf_count[MCAST_EXCLUDE] &&
1821 !psf->sf_count[MCAST_INCLUDE];
1823 psf->sf_oldin = psf->sf_count[MCAST_INCLUDE] != 0;
1826 static int sf_setstate(struct ifmcaddr6 *pmc)
1828 struct ip6_sf_list *psf;
1829 int mca_xcount = pmc->mca_sfcount[MCAST_EXCLUDE];
1830 int qrv = pmc->idev->mc_qrv;
1834 for (psf=pmc->mca_sources; psf; psf=psf->sf_next) {
1835 if (pmc->mca_sfcount[MCAST_EXCLUDE]) {
1836 new_in = mca_xcount == psf->sf_count[MCAST_EXCLUDE] &&
1837 !psf->sf_count[MCAST_INCLUDE];
1839 new_in = psf->sf_count[MCAST_INCLUDE] != 0;
1840 if (new_in != psf->sf_oldin) {
1841 psf->sf_crcount = qrv;
1849 * Add multicast source filter list to the interface list
1851 int ip6_mc_add_src(struct inet6_dev *idev, struct in6_addr *pmca, int sfmode,
1852 int sfcount, struct in6_addr *psfsrc, int delta)
1854 struct ifmcaddr6 *pmc;
1860 read_lock_bh(&idev->lock);
1861 for (pmc=idev->mc_list; pmc; pmc=pmc->next) {
1862 if (ipv6_addr_cmp(pmca, &pmc->mca_addr) == 0)
1866 /* MCA not found?? bug */
1867 read_unlock_bh(&idev->lock);
1870 spin_lock_bh(&pmc->mca_lock);
1873 isexclude = pmc->mca_sfmode == MCAST_EXCLUDE;
1875 pmc->mca_sfcount[sfmode]++;
1877 for (i=0; i<sfcount; i++) {
1878 err = ip6_mc_add1_src(pmc, sfmode, &psfsrc[i], delta);
1885 pmc->mca_sfcount[sfmode]--;
1887 (void) ip6_mc_del1_src(pmc, sfmode, &psfsrc[i]);
1888 } else if (isexclude != (pmc->mca_sfcount[MCAST_EXCLUDE] != 0)) {
1889 struct inet6_dev *idev = pmc->idev;
1890 struct ip6_sf_list *psf;
1892 /* filter mode change */
1893 if (pmc->mca_sfcount[MCAST_EXCLUDE])
1894 pmc->mca_sfmode = MCAST_EXCLUDE;
1895 else if (pmc->mca_sfcount[MCAST_INCLUDE])
1896 pmc->mca_sfmode = MCAST_INCLUDE;
1897 /* else no filters; keep old mode for reports */
1899 pmc->mca_crcount = idev->mc_qrv;
1900 idev->mc_ifc_count = pmc->mca_crcount;
1901 for (psf=pmc->mca_sources; psf; psf = psf->sf_next)
1902 psf->sf_crcount = 0;
1903 mld_ifc_event(idev);
1904 } else if (sf_setstate(pmc))
1905 mld_ifc_event(idev);
1906 spin_unlock_bh(&pmc->mca_lock);
1907 read_unlock_bh(&idev->lock);
1911 static void ip6_mc_clear_src(struct ifmcaddr6 *pmc)
1913 struct ip6_sf_list *psf, *nextpsf;
1915 for (psf=pmc->mca_tomb; psf; psf=nextpsf) {
1916 nextpsf = psf->sf_next;
1919 pmc->mca_tomb = NULL;
1920 for (psf=pmc->mca_sources; psf; psf=nextpsf) {
1921 nextpsf = psf->sf_next;
1924 pmc->mca_sources = NULL;
1925 pmc->mca_sfmode = MCAST_EXCLUDE;
1926 pmc->mca_sfcount[MCAST_EXCLUDE] = 0;
1927 pmc->mca_sfcount[MCAST_EXCLUDE] = 1;
1931 static void igmp6_join_group(struct ifmcaddr6 *ma)
1933 unsigned long delay;
1935 if (ma->mca_flags & MAF_NOREPORT)
1938 igmp6_send(&ma->mca_addr, ma->idev->dev, ICMPV6_MGM_REPORT);
1940 delay = net_random() % IGMP6_UNSOLICITED_IVAL;
1942 spin_lock_bh(&ma->mca_lock);
1943 if (del_timer(&ma->mca_timer)) {
1944 atomic_dec(&ma->mca_refcnt);
1945 delay = ma->mca_timer.expires - jiffies;
1948 if (!mod_timer(&ma->mca_timer, jiffies + delay))
1949 atomic_inc(&ma->mca_refcnt);
1950 ma->mca_flags |= MAF_TIMER_RUNNING | MAF_LAST_REPORTER;
1951 spin_unlock_bh(&ma->mca_lock);
1954 int ip6_mc_leave_src(struct sock *sk, struct ipv6_mc_socklist *iml,
1955 struct inet6_dev *idev)
1959 if (iml->sflist == 0) {
1960 /* any-source empty exclude case */
1961 return ip6_mc_del_src(idev, &iml->addr, iml->sfmode, 0, NULL, 0);
1963 err = ip6_mc_del_src(idev, &iml->addr, iml->sfmode,
1964 iml->sflist->sl_count, iml->sflist->sl_addr, 0);
1965 sock_kfree_s(sk, iml->sflist, IP6_SFLSIZE(iml->sflist->sl_max));
1970 static void igmp6_leave_group(struct ifmcaddr6 *ma)
1972 if (MLD_V1_SEEN(ma->idev)) {
1973 if (ma->mca_flags & MAF_LAST_REPORTER)
1974 igmp6_send(&ma->mca_addr, ma->idev->dev,
1975 ICMPV6_MGM_REDUCTION);
1977 mld_add_delrec(ma->idev, ma);
1978 mld_ifc_event(ma->idev);
1982 static void mld_gq_timer_expire(unsigned long data)
1984 struct inet6_dev *idev = (struct inet6_dev *)data;
1986 idev->mc_gq_running = 0;
1987 mld_send_report(idev, NULL);
1988 __in6_dev_put(idev);
1991 static void mld_ifc_timer_expire(unsigned long data)
1993 struct inet6_dev *idev = (struct inet6_dev *)data;
1996 if (idev->mc_ifc_count) {
1997 idev->mc_ifc_count--;
1998 if (idev->mc_ifc_count)
1999 mld_ifc_start_timer(idev, idev->mc_maxdelay);
2001 __in6_dev_put(idev);
2004 static void mld_ifc_event(struct inet6_dev *idev)
2006 if (MLD_V1_SEEN(idev))
2008 idev->mc_ifc_count = idev->mc_qrv;
2009 mld_ifc_start_timer(idev, 1);
2013 static void igmp6_timer_handler(unsigned long data)
2015 struct ifmcaddr6 *ma = (struct ifmcaddr6 *) data;
2017 if (MLD_V1_SEEN(ma->idev))
2018 igmp6_send(&ma->mca_addr, ma->idev->dev, ICMPV6_MGM_REPORT);
2020 mld_send_report(ma->idev, ma);
2022 spin_lock(&ma->mca_lock);
2023 ma->mca_flags |= MAF_LAST_REPORTER;
2024 ma->mca_flags &= ~MAF_TIMER_RUNNING;
2025 spin_unlock(&ma->mca_lock);
2029 /* Device going down */
2031 void ipv6_mc_down(struct inet6_dev *idev)
2033 struct ifmcaddr6 *i;
2035 /* Withdraw multicast list */
2037 read_lock_bh(&idev->lock);
2038 idev->mc_ifc_count = 0;
2039 if (del_timer(&idev->mc_ifc_timer))
2040 __in6_dev_put(idev);
2041 idev->mc_gq_running = 0;
2042 if (del_timer(&idev->mc_gq_timer))
2043 __in6_dev_put(idev);
2045 for (i = idev->mc_list; i; i=i->next)
2046 igmp6_group_dropped(i);
2047 read_unlock_bh(&idev->lock);
2049 mld_clear_delrec(idev);
2053 /* Device going up */
2055 void ipv6_mc_up(struct inet6_dev *idev)
2057 struct ifmcaddr6 *i;
2059 /* Install multicast list, except for all-nodes (already installed) */
2061 read_lock_bh(&idev->lock);
2062 for (i = idev->mc_list; i; i=i->next)
2063 igmp6_group_added(i);
2064 read_unlock_bh(&idev->lock);
2067 /* IPv6 device initialization. */
2069 void ipv6_mc_init_dev(struct inet6_dev *idev)
2071 struct in6_addr maddr;
2073 write_lock_bh(&idev->lock);
2074 idev->mc_lock = RW_LOCK_UNLOCKED;
2075 idev->mc_gq_running = 0;
2076 init_timer(&idev->mc_gq_timer);
2077 idev->mc_gq_timer.data = (unsigned long) idev;
2078 idev->mc_gq_timer.function = &mld_gq_timer_expire;
2079 idev->mc_tomb = NULL;
2080 idev->mc_ifc_count = 0;
2081 init_timer(&idev->mc_ifc_timer);
2082 idev->mc_ifc_timer.data = (unsigned long) idev;
2083 idev->mc_ifc_timer.function = &mld_ifc_timer_expire;
2084 idev->mc_qrv = MLD_QRV_DEFAULT;
2085 idev->mc_maxdelay = IGMP6_UNSOLICITED_IVAL;
2086 idev->mc_v1_seen = 0;
2087 write_unlock_bh(&idev->lock);
2089 /* Add all-nodes address. */
2090 ipv6_addr_all_nodes(&maddr);
2091 ipv6_dev_mc_inc(idev->dev, &maddr);
2095 * Device is about to be destroyed: clean up.
2098 void ipv6_mc_destroy_dev(struct inet6_dev *idev)
2100 struct ifmcaddr6 *i;
2101 struct in6_addr maddr;
2103 /* Deactivate timers */
2106 /* Delete all-nodes address. */
2107 ipv6_addr_all_nodes(&maddr);
2109 /* We cannot call ipv6_dev_mc_dec() directly, our caller in
2110 * addrconf.c has NULL'd out dev->ip6_ptr so in6_dev_get() will
2113 __ipv6_dev_mc_dec(idev, &maddr);
2115 if (idev->cnf.forwarding) {
2116 ipv6_addr_all_routers(&maddr);
2117 __ipv6_dev_mc_dec(idev, &maddr);
2120 write_lock_bh(&idev->lock);
2121 while ((i = idev->mc_list) != NULL) {
2122 idev->mc_list = i->next;
2123 write_unlock_bh(&idev->lock);
2125 igmp6_group_dropped(i);
2128 write_lock_bh(&idev->lock);
2130 write_unlock_bh(&idev->lock);
2133 #ifdef CONFIG_PROC_FS
2134 struct igmp6_mc_iter_state {
2135 struct net_device *dev;
2136 struct inet6_dev *idev;
2139 #define igmp6_mc_seq_private(seq) ((struct igmp6_mc_iter_state *)(seq)->private)
2141 static inline struct ifmcaddr6 *igmp6_mc_get_first(struct seq_file *seq)
2143 struct ifmcaddr6 *im = NULL;
2144 struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq);
2146 for (state->dev = dev_base, state->idev = NULL;
2148 state->dev = state->dev->next) {
2149 struct inet6_dev *idev;
2150 idev = in6_dev_get(state->dev);
2153 read_lock_bh(&idev->lock);
2159 read_unlock_bh(&idev->lock);
2165 static struct ifmcaddr6 *igmp6_mc_get_next(struct seq_file *seq, struct ifmcaddr6 *im)
2167 struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq);
2171 if (likely(state->idev != NULL)) {
2172 read_unlock_bh(&state->idev->lock);
2173 in6_dev_put(state->idev);
2175 state->dev = state->dev->next;
2180 state->idev = in6_dev_get(state->dev);
2183 read_lock_bh(&state->idev->lock);
2184 im = state->idev->mc_list;
2189 static struct ifmcaddr6 *igmp6_mc_get_idx(struct seq_file *seq, loff_t pos)
2191 struct ifmcaddr6 *im = igmp6_mc_get_first(seq);
2193 while (pos && (im = igmp6_mc_get_next(seq, im)) != NULL)
2195 return pos ? NULL : im;
2198 static void *igmp6_mc_seq_start(struct seq_file *seq, loff_t *pos)
2200 read_lock(&dev_base_lock);
2201 return igmp6_mc_get_idx(seq, *pos);
2204 static void *igmp6_mc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2206 struct ifmcaddr6 *im;
2207 im = igmp6_mc_get_next(seq, v);
2212 static void igmp6_mc_seq_stop(struct seq_file *seq, void *v)
2214 struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq);
2215 if (likely(state->idev != NULL)) {
2216 read_unlock_bh(&state->idev->lock);
2217 in6_dev_put(state->idev);
2221 read_unlock(&dev_base_lock);
2224 static int igmp6_mc_seq_show(struct seq_file *seq, void *v)
2226 struct ifmcaddr6 *im = (struct ifmcaddr6 *)v;
2227 struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq);
2230 "%-4d %-15s %04x%04x%04x%04x%04x%04x%04x%04x %5d %08X %ld\n",
2231 state->dev->ifindex, state->dev->name,
2233 im->mca_users, im->mca_flags,
2234 (im->mca_flags&MAF_TIMER_RUNNING) ?
2235 jiffies_to_clock_t(im->mca_timer.expires-jiffies) : 0);
2239 static struct seq_operations igmp6_mc_seq_ops = {
2240 .start = igmp6_mc_seq_start,
2241 .next = igmp6_mc_seq_next,
2242 .stop = igmp6_mc_seq_stop,
2243 .show = igmp6_mc_seq_show,
2246 static int igmp6_mc_seq_open(struct inode *inode, struct file *file)
2248 struct seq_file *seq;
2250 struct igmp6_mc_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL);
2255 rc = seq_open(file, &igmp6_mc_seq_ops);
2259 seq = file->private_data;
2261 memset(s, 0, sizeof(*s));
2269 static struct file_operations igmp6_mc_seq_fops = {
2270 .owner = THIS_MODULE,
2271 .open = igmp6_mc_seq_open,
2273 .llseek = seq_lseek,
2274 .release = seq_release_private,
2277 struct igmp6_mcf_iter_state {
2278 struct net_device *dev;
2279 struct inet6_dev *idev;
2280 struct ifmcaddr6 *im;
2283 #define igmp6_mcf_seq_private(seq) ((struct igmp6_mcf_iter_state *)(seq)->private)
2285 static inline struct ip6_sf_list *igmp6_mcf_get_first(struct seq_file *seq)
2287 struct ip6_sf_list *psf = NULL;
2288 struct ifmcaddr6 *im = NULL;
2289 struct igmp6_mcf_iter_state *state = igmp6_mcf_seq_private(seq);
2291 for (state->dev = dev_base, state->idev = NULL, state->im = NULL;
2293 state->dev = state->dev->next) {
2294 struct inet6_dev *idev;
2295 idev = in6_dev_get(state->dev);
2296 if (unlikely(idev == NULL))
2298 read_lock_bh(&idev->lock);
2300 if (likely(im != NULL)) {
2301 spin_lock_bh(&im->mca_lock);
2302 psf = im->mca_sources;
2303 if (likely(psf != NULL)) {
2308 spin_unlock_bh(&im->mca_lock);
2310 read_unlock_bh(&idev->lock);
2316 static struct ip6_sf_list *igmp6_mcf_get_next(struct seq_file *seq, struct ip6_sf_list *psf)
2318 struct igmp6_mcf_iter_state *state = igmp6_mcf_seq_private(seq);
2322 spin_unlock_bh(&state->im->mca_lock);
2323 state->im = state->im->next;
2324 while (!state->im) {
2325 if (likely(state->idev != NULL)) {
2326 read_unlock_bh(&state->idev->lock);
2327 in6_dev_put(state->idev);
2329 state->dev = state->dev->next;
2334 state->idev = in6_dev_get(state->dev);
2337 read_lock_bh(&state->idev->lock);
2338 state->im = state->idev->mc_list;
2342 spin_lock_bh(&state->im->mca_lock);
2343 psf = state->im->mca_sources;
2349 static struct ip6_sf_list *igmp6_mcf_get_idx(struct seq_file *seq, loff_t pos)
2351 struct ip6_sf_list *psf = igmp6_mcf_get_first(seq);
2353 while (pos && (psf = igmp6_mcf_get_next(seq, psf)) != NULL)
2355 return pos ? NULL : psf;
2358 static void *igmp6_mcf_seq_start(struct seq_file *seq, loff_t *pos)
2360 read_lock(&dev_base_lock);
2361 return *pos ? igmp6_mcf_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
2364 static void *igmp6_mcf_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2366 struct ip6_sf_list *psf;
2367 if (v == SEQ_START_TOKEN)
2368 psf = igmp6_mcf_get_first(seq);
2370 psf = igmp6_mcf_get_next(seq, v);
2375 static void igmp6_mcf_seq_stop(struct seq_file *seq, void *v)
2377 struct igmp6_mcf_iter_state *state = igmp6_mcf_seq_private(seq);
2378 if (likely(state->im != NULL)) {
2379 spin_unlock_bh(&state->im->mca_lock);
2382 if (likely(state->idev != NULL)) {
2383 read_unlock_bh(&state->idev->lock);
2384 in6_dev_put(state->idev);
2388 read_unlock(&dev_base_lock);
2391 static int igmp6_mcf_seq_show(struct seq_file *seq, void *v)
2393 struct ip6_sf_list *psf = (struct ip6_sf_list *)v;
2394 struct igmp6_mcf_iter_state *state = igmp6_mcf_seq_private(seq);
2396 if (v == SEQ_START_TOKEN) {
2399 "%32s %32s %6s %6s\n", "Idx",
2400 "Device", "Multicast Address",
2401 "Source Address", "INC", "EXC");
2405 "%04x%04x%04x%04x%04x%04x%04x%04x "
2406 "%04x%04x%04x%04x%04x%04x%04x%04x "
2408 state->dev->ifindex, state->dev->name,
2409 NIP6(state->im->mca_addr),
2411 psf->sf_count[MCAST_INCLUDE],
2412 psf->sf_count[MCAST_EXCLUDE]);
2417 static struct seq_operations igmp6_mcf_seq_ops = {
2418 .start = igmp6_mcf_seq_start,
2419 .next = igmp6_mcf_seq_next,
2420 .stop = igmp6_mcf_seq_stop,
2421 .show = igmp6_mcf_seq_show,
2424 static int igmp6_mcf_seq_open(struct inode *inode, struct file *file)
2426 struct seq_file *seq;
2428 struct igmp6_mcf_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL);
2433 rc = seq_open(file, &igmp6_mcf_seq_ops);
2437 seq = file->private_data;
2439 memset(s, 0, sizeof(*s));
2447 static struct file_operations igmp6_mcf_seq_fops = {
2448 .owner = THIS_MODULE,
2449 .open = igmp6_mcf_seq_open,
2451 .llseek = seq_lseek,
2452 .release = seq_release_private,
2456 int __init igmp6_init(struct net_proto_family *ops)
2458 struct ipv6_pinfo *np;
2462 err = sock_create_kern(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6, &igmp6_socket);
2465 "Failed to initialize the IGMP6 control socket (err %d).\n",
2467 igmp6_socket = NULL; /* For safety. */
2471 sk = igmp6_socket->sk;
2472 sk->sk_allocation = GFP_ATOMIC;
2473 sk->sk_prot->unhash(sk);
2478 #ifdef CONFIG_PROC_FS
2479 proc_net_fops_create("igmp6", S_IRUGO, &igmp6_mc_seq_fops);
2480 proc_net_fops_create("mcfilter6", S_IRUGO, &igmp6_mcf_seq_fops);
2486 void igmp6_cleanup(void)
2488 sock_release(igmp6_socket);
2489 igmp6_socket = NULL; /* for safety */
2491 #ifdef CONFIG_PROC_FS
2492 proc_net_remove("mcfilter6");
2493 proc_net_remove("igmp6");