2 * Multicast support for IPv6
3 * Linux INET6 implementation
6 * Pedro Roque <roque@di.fc.ul.pt>
8 * Based on linux/ipv4/igmp.c and linux/ipv4/ip_sockglue.c
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
18 * yoshfuji : fix format of router-alert option
19 * YOSHIFUJI Hideaki @USAGI:
20 * Fixed source address for MLD message based on
21 * <draft-ietf-magma-mld-source-05.txt>.
22 * YOSHIFUJI Hideaki @USAGI:
23 * - Ignore Queries for invalid addresses.
24 * - MLD for link-local addresses.
25 * David L Stevens <dlstevens@us.ibm.com>:
29 #include <linux/module.h>
30 #include <linux/errno.h>
31 #include <linux/types.h>
32 #include <linux/string.h>
33 #include <linux/socket.h>
34 #include <linux/sockios.h>
35 #include <linux/jiffies.h>
36 #include <linux/times.h>
37 #include <linux/net.h>
39 #include <linux/in6.h>
40 #include <linux/netdevice.h>
41 #include <linux/if_arp.h>
42 #include <linux/route.h>
43 #include <linux/init.h>
44 #include <linux/proc_fs.h>
45 #include <linux/seq_file.h>
46 #include <linux/slab.h>
47 #include <linux/pkt_sched.h>
50 #include <linux/netfilter.h>
51 #include <linux/netfilter_ipv6.h>
53 #include <net/net_namespace.h>
58 #include <net/protocol.h>
59 #include <net/if_inet6.h>
60 #include <net/ndisc.h>
61 #include <net/addrconf.h>
62 #include <net/ip6_route.h>
63 #include <net/inet_common.h>
65 #include <net/ip6_checksum.h>
67 /* Ensure that we have struct in6_addr aligned on 32bit word. */
68 static void *__mld2_query_bugs
[] __attribute__((__unused__
)) = {
69 BUILD_BUG_ON_NULL(offsetof(struct mld2_query
, mld2q_srcs
) % 4),
70 BUILD_BUG_ON_NULL(offsetof(struct mld2_report
, mld2r_grec
) % 4),
71 BUILD_BUG_ON_NULL(offsetof(struct mld2_grec
, grec_mca
) % 4)
74 static struct in6_addr mld2_all_mcr
= MLD2_ALL_MCR_INIT
;
76 static void igmp6_join_group(struct ifmcaddr6
*ma
);
77 static void igmp6_leave_group(struct ifmcaddr6
*ma
);
78 static void igmp6_timer_handler(struct timer_list
*t
);
80 static void mld_gq_timer_expire(struct timer_list
*t
);
81 static void mld_ifc_timer_expire(struct timer_list
*t
);
82 static void mld_ifc_event(struct inet6_dev
*idev
);
83 static void mld_add_delrec(struct inet6_dev
*idev
, struct ifmcaddr6
*pmc
);
84 static void mld_del_delrec(struct inet6_dev
*idev
, struct ifmcaddr6
*pmc
);
85 static void mld_clear_delrec(struct inet6_dev
*idev
);
86 static bool mld_in_v1_mode(const struct inet6_dev
*idev
);
87 static int sf_setstate(struct ifmcaddr6
*pmc
);
88 static void sf_markstate(struct ifmcaddr6
*pmc
);
89 static void ip6_mc_clear_src(struct ifmcaddr6
*pmc
);
90 static int ip6_mc_del_src(struct inet6_dev
*idev
, const struct in6_addr
*pmca
,
91 int sfmode
, int sfcount
, const struct in6_addr
*psfsrc
,
93 static int ip6_mc_add_src(struct inet6_dev
*idev
, const struct in6_addr
*pmca
,
94 int sfmode
, int sfcount
, const struct in6_addr
*psfsrc
,
96 static int ip6_mc_leave_src(struct sock
*sk
, struct ipv6_mc_socklist
*iml
,
97 struct inet6_dev
*idev
);
99 #define MLD_QRV_DEFAULT 2
100 /* RFC3810, 9.2. Query Interval */
101 #define MLD_QI_DEFAULT (125 * HZ)
102 /* RFC3810, 9.3. Query Response Interval */
103 #define MLD_QRI_DEFAULT (10 * HZ)
105 /* RFC3810, 8.1 Query Version Distinctions */
106 #define MLD_V1_QUERY_LEN 24
107 #define MLD_V2_QUERY_LEN_MIN 28
109 #define IPV6_MLD_MAX_MSF 64
111 int sysctl_mld_max_msf __read_mostly
= IPV6_MLD_MAX_MSF
;
112 int sysctl_mld_qrv __read_mostly
= MLD_QRV_DEFAULT
;
115 * socket join on multicast group
118 #define for_each_pmc_rcu(np, pmc) \
119 for (pmc = rcu_dereference(np->ipv6_mc_list); \
121 pmc = rcu_dereference(pmc->next))
123 static int unsolicited_report_interval(struct inet6_dev
*idev
)
127 if (mld_in_v1_mode(idev
))
128 iv
= idev
->cnf
.mldv1_unsolicited_report_interval
;
130 iv
= idev
->cnf
.mldv2_unsolicited_report_interval
;
132 return iv
> 0 ? iv
: 1;
135 int ipv6_sock_mc_join(struct sock
*sk
, int ifindex
, const struct in6_addr
*addr
)
137 struct net_device
*dev
= NULL
;
138 struct ipv6_mc_socklist
*mc_lst
;
139 struct ipv6_pinfo
*np
= inet6_sk(sk
);
140 struct net
*net
= sock_net(sk
);
145 if (!ipv6_addr_is_multicast(addr
))
149 for_each_pmc_rcu(np
, mc_lst
) {
150 if ((ifindex
== 0 || mc_lst
->ifindex
== ifindex
) &&
151 ipv6_addr_equal(&mc_lst
->addr
, addr
)) {
158 mc_lst
= sock_kmalloc(sk
, sizeof(struct ipv6_mc_socklist
), GFP_KERNEL
);
164 mc_lst
->addr
= *addr
;
168 rt
= rt6_lookup(net
, addr
, NULL
, 0, 0);
174 dev
= __dev_get_by_index(net
, ifindex
);
177 sock_kfree_s(sk
, mc_lst
, sizeof(*mc_lst
));
181 mc_lst
->ifindex
= dev
->ifindex
;
182 mc_lst
->sfmode
= MCAST_EXCLUDE
;
183 rwlock_init(&mc_lst
->sflock
);
184 mc_lst
->sflist
= NULL
;
187 * now add/increase the group membership on the device
190 err
= ipv6_dev_mc_inc(dev
, addr
);
193 sock_kfree_s(sk
, mc_lst
, sizeof(*mc_lst
));
197 mc_lst
->next
= np
->ipv6_mc_list
;
198 rcu_assign_pointer(np
->ipv6_mc_list
, mc_lst
);
202 EXPORT_SYMBOL(ipv6_sock_mc_join
);
205 * socket leave on multicast group
207 int ipv6_sock_mc_drop(struct sock
*sk
, int ifindex
, const struct in6_addr
*addr
)
209 struct ipv6_pinfo
*np
= inet6_sk(sk
);
210 struct ipv6_mc_socklist
*mc_lst
;
211 struct ipv6_mc_socklist __rcu
**lnk
;
212 struct net
*net
= sock_net(sk
);
216 if (!ipv6_addr_is_multicast(addr
))
219 for (lnk
= &np
->ipv6_mc_list
;
220 (mc_lst
= rtnl_dereference(*lnk
)) != NULL
;
221 lnk
= &mc_lst
->next
) {
222 if ((ifindex
== 0 || mc_lst
->ifindex
== ifindex
) &&
223 ipv6_addr_equal(&mc_lst
->addr
, addr
)) {
224 struct net_device
*dev
;
228 dev
= __dev_get_by_index(net
, mc_lst
->ifindex
);
230 struct inet6_dev
*idev
= __in6_dev_get(dev
);
232 (void) ip6_mc_leave_src(sk
, mc_lst
, idev
);
234 __ipv6_dev_mc_dec(idev
, &mc_lst
->addr
);
236 (void) ip6_mc_leave_src(sk
, mc_lst
, NULL
);
238 atomic_sub(sizeof(*mc_lst
), &sk
->sk_omem_alloc
);
239 kfree_rcu(mc_lst
, rcu
);
244 return -EADDRNOTAVAIL
;
246 EXPORT_SYMBOL(ipv6_sock_mc_drop
);
248 /* called with rcu_read_lock() */
249 static struct inet6_dev
*ip6_mc_find_dev_rcu(struct net
*net
,
250 const struct in6_addr
*group
,
253 struct net_device
*dev
= NULL
;
254 struct inet6_dev
*idev
= NULL
;
257 struct rt6_info
*rt
= rt6_lookup(net
, group
, NULL
, 0, 0);
264 dev
= dev_get_by_index_rcu(net
, ifindex
);
268 idev
= __in6_dev_get(dev
);
271 read_lock_bh(&idev
->lock
);
273 read_unlock_bh(&idev
->lock
);
279 void __ipv6_sock_mc_close(struct sock
*sk
)
281 struct ipv6_pinfo
*np
= inet6_sk(sk
);
282 struct ipv6_mc_socklist
*mc_lst
;
283 struct net
*net
= sock_net(sk
);
287 while ((mc_lst
= rtnl_dereference(np
->ipv6_mc_list
)) != NULL
) {
288 struct net_device
*dev
;
290 np
->ipv6_mc_list
= mc_lst
->next
;
292 dev
= __dev_get_by_index(net
, mc_lst
->ifindex
);
294 struct inet6_dev
*idev
= __in6_dev_get(dev
);
296 (void) ip6_mc_leave_src(sk
, mc_lst
, idev
);
298 __ipv6_dev_mc_dec(idev
, &mc_lst
->addr
);
300 (void) ip6_mc_leave_src(sk
, mc_lst
, NULL
);
302 atomic_sub(sizeof(*mc_lst
), &sk
->sk_omem_alloc
);
303 kfree_rcu(mc_lst
, rcu
);
307 void ipv6_sock_mc_close(struct sock
*sk
)
309 struct ipv6_pinfo
*np
= inet6_sk(sk
);
311 if (!rcu_access_pointer(np
->ipv6_mc_list
))
314 __ipv6_sock_mc_close(sk
);
318 int ip6_mc_source(int add
, int omode
, struct sock
*sk
,
319 struct group_source_req
*pgsr
)
321 struct in6_addr
*source
, *group
;
322 struct ipv6_mc_socklist
*pmc
;
323 struct inet6_dev
*idev
;
324 struct ipv6_pinfo
*inet6
= inet6_sk(sk
);
325 struct ip6_sf_socklist
*psl
;
326 struct net
*net
= sock_net(sk
);
332 source
= &((struct sockaddr_in6
*)&pgsr
->gsr_source
)->sin6_addr
;
333 group
= &((struct sockaddr_in6
*)&pgsr
->gsr_group
)->sin6_addr
;
335 if (!ipv6_addr_is_multicast(group
))
339 idev
= ip6_mc_find_dev_rcu(net
, group
, pgsr
->gsr_interface
);
345 err
= -EADDRNOTAVAIL
;
347 for_each_pmc_rcu(inet6
, pmc
) {
348 if (pgsr
->gsr_interface
&& pmc
->ifindex
!= pgsr
->gsr_interface
)
350 if (ipv6_addr_equal(&pmc
->addr
, group
))
353 if (!pmc
) { /* must have a prior join */
357 /* if a source filter was set, must be the same mode as before */
359 if (pmc
->sfmode
!= omode
) {
363 } else if (pmc
->sfmode
!= omode
) {
364 /* allow mode switches for empty-set filters */
365 ip6_mc_add_src(idev
, group
, omode
, 0, NULL
, 0);
366 ip6_mc_del_src(idev
, group
, pmc
->sfmode
, 0, NULL
, 0);
370 write_lock(&pmc
->sflock
);
376 goto done
; /* err = -EADDRNOTAVAIL */
378 for (i
= 0; i
< psl
->sl_count
; i
++) {
379 rv
= !ipv6_addr_equal(&psl
->sl_addr
[i
], source
);
383 if (rv
) /* source not found */
384 goto done
; /* err = -EADDRNOTAVAIL */
386 /* special case - (INCLUDE, empty) == LEAVE_GROUP */
387 if (psl
->sl_count
== 1 && omode
== MCAST_INCLUDE
) {
392 /* update the interface filter */
393 ip6_mc_del_src(idev
, group
, omode
, 1, source
, 1);
395 for (j
= i
+1; j
< psl
->sl_count
; j
++)
396 psl
->sl_addr
[j
-1] = psl
->sl_addr
[j
];
401 /* else, add a new source to the filter */
403 if (psl
&& psl
->sl_count
>= sysctl_mld_max_msf
) {
407 if (!psl
|| psl
->sl_count
== psl
->sl_max
) {
408 struct ip6_sf_socklist
*newpsl
;
409 int count
= IP6_SFBLOCK
;
412 count
+= psl
->sl_max
;
413 newpsl
= sock_kmalloc(sk
, IP6_SFLSIZE(count
), GFP_ATOMIC
);
418 newpsl
->sl_max
= count
;
419 newpsl
->sl_count
= count
- IP6_SFBLOCK
;
421 for (i
= 0; i
< psl
->sl_count
; i
++)
422 newpsl
->sl_addr
[i
] = psl
->sl_addr
[i
];
423 sock_kfree_s(sk
, psl
, IP6_SFLSIZE(psl
->sl_max
));
425 pmc
->sflist
= psl
= newpsl
;
427 rv
= 1; /* > 0 for insert logic below if sl_count is 0 */
428 for (i
= 0; i
< psl
->sl_count
; i
++) {
429 rv
= !ipv6_addr_equal(&psl
->sl_addr
[i
], source
);
430 if (rv
== 0) /* There is an error in the address. */
433 for (j
= psl
->sl_count
-1; j
>= i
; j
--)
434 psl
->sl_addr
[j
+1] = psl
->sl_addr
[j
];
435 psl
->sl_addr
[i
] = *source
;
438 /* update the interface list */
439 ip6_mc_add_src(idev
, group
, omode
, 1, source
, 1);
442 write_unlock(&pmc
->sflock
);
443 read_unlock_bh(&idev
->lock
);
446 err
= ipv6_sock_mc_drop(sk
, pgsr
->gsr_interface
, group
);
450 int ip6_mc_msfilter(struct sock
*sk
, struct group_filter
*gsf
)
452 const struct in6_addr
*group
;
453 struct ipv6_mc_socklist
*pmc
;
454 struct inet6_dev
*idev
;
455 struct ipv6_pinfo
*inet6
= inet6_sk(sk
);
456 struct ip6_sf_socklist
*newpsl
, *psl
;
457 struct net
*net
= sock_net(sk
);
461 group
= &((struct sockaddr_in6
*)&gsf
->gf_group
)->sin6_addr
;
463 if (!ipv6_addr_is_multicast(group
))
465 if (gsf
->gf_fmode
!= MCAST_INCLUDE
&&
466 gsf
->gf_fmode
!= MCAST_EXCLUDE
)
470 idev
= ip6_mc_find_dev_rcu(net
, group
, gsf
->gf_interface
);
479 if (gsf
->gf_fmode
== MCAST_INCLUDE
&& gsf
->gf_numsrc
== 0) {
484 for_each_pmc_rcu(inet6
, pmc
) {
485 if (pmc
->ifindex
!= gsf
->gf_interface
)
487 if (ipv6_addr_equal(&pmc
->addr
, group
))
490 if (!pmc
) { /* must have a prior join */
494 if (gsf
->gf_numsrc
) {
495 newpsl
= sock_kmalloc(sk
, IP6_SFLSIZE(gsf
->gf_numsrc
),
501 newpsl
->sl_max
= newpsl
->sl_count
= gsf
->gf_numsrc
;
502 for (i
= 0; i
< newpsl
->sl_count
; ++i
) {
503 struct sockaddr_in6
*psin6
;
505 psin6
= (struct sockaddr_in6
*)&gsf
->gf_slist
[i
];
506 newpsl
->sl_addr
[i
] = psin6
->sin6_addr
;
508 err
= ip6_mc_add_src(idev
, group
, gsf
->gf_fmode
,
509 newpsl
->sl_count
, newpsl
->sl_addr
, 0);
511 sock_kfree_s(sk
, newpsl
, IP6_SFLSIZE(newpsl
->sl_max
));
516 (void) ip6_mc_add_src(idev
, group
, gsf
->gf_fmode
, 0, NULL
, 0);
519 write_lock(&pmc
->sflock
);
522 (void) ip6_mc_del_src(idev
, group
, pmc
->sfmode
,
523 psl
->sl_count
, psl
->sl_addr
, 0);
524 sock_kfree_s(sk
, psl
, IP6_SFLSIZE(psl
->sl_max
));
526 (void) ip6_mc_del_src(idev
, group
, pmc
->sfmode
, 0, NULL
, 0);
527 pmc
->sflist
= newpsl
;
528 pmc
->sfmode
= gsf
->gf_fmode
;
529 write_unlock(&pmc
->sflock
);
532 read_unlock_bh(&idev
->lock
);
535 err
= ipv6_sock_mc_drop(sk
, gsf
->gf_interface
, group
);
539 int ip6_mc_msfget(struct sock
*sk
, struct group_filter
*gsf
,
540 struct group_filter __user
*optval
, int __user
*optlen
)
542 int err
, i
, count
, copycount
;
543 const struct in6_addr
*group
;
544 struct ipv6_mc_socklist
*pmc
;
545 struct inet6_dev
*idev
;
546 struct ipv6_pinfo
*inet6
= inet6_sk(sk
);
547 struct ip6_sf_socklist
*psl
;
548 struct net
*net
= sock_net(sk
);
550 group
= &((struct sockaddr_in6
*)&gsf
->gf_group
)->sin6_addr
;
552 if (!ipv6_addr_is_multicast(group
))
556 idev
= ip6_mc_find_dev_rcu(net
, group
, gsf
->gf_interface
);
563 err
= -EADDRNOTAVAIL
;
564 /* changes to the ipv6_mc_list require the socket lock and
565 * rtnl lock. We have the socket lock and rcu read lock,
566 * so reading the list is safe.
569 for_each_pmc_rcu(inet6
, pmc
) {
570 if (pmc
->ifindex
!= gsf
->gf_interface
)
572 if (ipv6_addr_equal(group
, &pmc
->addr
))
575 if (!pmc
) /* must have a prior join */
577 gsf
->gf_fmode
= pmc
->sfmode
;
579 count
= psl
? psl
->sl_count
: 0;
580 read_unlock_bh(&idev
->lock
);
583 copycount
= count
< gsf
->gf_numsrc
? count
: gsf
->gf_numsrc
;
584 gsf
->gf_numsrc
= count
;
585 if (put_user(GROUP_FILTER_SIZE(copycount
), optlen
) ||
586 copy_to_user(optval
, gsf
, GROUP_FILTER_SIZE(0))) {
589 /* changes to psl require the socket lock, and a write lock
590 * on pmc->sflock. We have the socket lock so reading here is safe.
592 for (i
= 0; i
< copycount
; i
++) {
593 struct sockaddr_in6
*psin6
;
594 struct sockaddr_storage ss
;
596 psin6
= (struct sockaddr_in6
*)&ss
;
597 memset(&ss
, 0, sizeof(ss
));
598 psin6
->sin6_family
= AF_INET6
;
599 psin6
->sin6_addr
= psl
->sl_addr
[i
];
600 if (copy_to_user(&optval
->gf_slist
[i
], &ss
, sizeof(ss
)))
605 read_unlock_bh(&idev
->lock
);
610 bool inet6_mc_check(struct sock
*sk
, const struct in6_addr
*mc_addr
,
611 const struct in6_addr
*src_addr
)
613 struct ipv6_pinfo
*np
= inet6_sk(sk
);
614 struct ipv6_mc_socklist
*mc
;
615 struct ip6_sf_socklist
*psl
;
619 for_each_pmc_rcu(np
, mc
) {
620 if (ipv6_addr_equal(&mc
->addr
, mc_addr
))
627 read_lock(&mc
->sflock
);
630 rv
= mc
->sfmode
== MCAST_EXCLUDE
;
634 for (i
= 0; i
< psl
->sl_count
; i
++) {
635 if (ipv6_addr_equal(&psl
->sl_addr
[i
], src_addr
))
638 if (mc
->sfmode
== MCAST_INCLUDE
&& i
>= psl
->sl_count
)
640 if (mc
->sfmode
== MCAST_EXCLUDE
&& i
< psl
->sl_count
)
643 read_unlock(&mc
->sflock
);
649 static void igmp6_group_added(struct ifmcaddr6
*mc
)
651 struct net_device
*dev
= mc
->idev
->dev
;
652 char buf
[MAX_ADDR_LEN
];
654 if (IPV6_ADDR_MC_SCOPE(&mc
->mca_addr
) <
655 IPV6_ADDR_SCOPE_LINKLOCAL
)
658 spin_lock_bh(&mc
->mca_lock
);
659 if (!(mc
->mca_flags
&MAF_LOADED
)) {
660 mc
->mca_flags
|= MAF_LOADED
;
661 if (ndisc_mc_map(&mc
->mca_addr
, buf
, dev
, 0) == 0)
662 dev_mc_add(dev
, buf
);
664 spin_unlock_bh(&mc
->mca_lock
);
666 if (!(dev
->flags
& IFF_UP
) || (mc
->mca_flags
& MAF_NOREPORT
))
669 if (mld_in_v1_mode(mc
->idev
)) {
670 igmp6_join_group(mc
);
675 mc
->mca_crcount
= mc
->idev
->mc_qrv
;
676 mld_ifc_event(mc
->idev
);
679 static void igmp6_group_dropped(struct ifmcaddr6
*mc
)
681 struct net_device
*dev
= mc
->idev
->dev
;
682 char buf
[MAX_ADDR_LEN
];
684 if (IPV6_ADDR_MC_SCOPE(&mc
->mca_addr
) <
685 IPV6_ADDR_SCOPE_LINKLOCAL
)
688 spin_lock_bh(&mc
->mca_lock
);
689 if (mc
->mca_flags
&MAF_LOADED
) {
690 mc
->mca_flags
&= ~MAF_LOADED
;
691 if (ndisc_mc_map(&mc
->mca_addr
, buf
, dev
, 0) == 0)
692 dev_mc_del(dev
, buf
);
695 spin_unlock_bh(&mc
->mca_lock
);
696 if (mc
->mca_flags
& MAF_NOREPORT
)
700 igmp6_leave_group(mc
);
702 spin_lock_bh(&mc
->mca_lock
);
703 if (del_timer(&mc
->mca_timer
))
704 refcount_dec(&mc
->mca_refcnt
);
705 spin_unlock_bh(&mc
->mca_lock
);
709 * deleted ifmcaddr6 manipulation
711 static void mld_add_delrec(struct inet6_dev
*idev
, struct ifmcaddr6
*im
)
713 struct ifmcaddr6
*pmc
;
715 /* this is an "ifmcaddr6" for convenience; only the fields below
716 * are actually used. In particular, the refcnt and users are not
717 * used for management of the delete list. Using the same structure
718 * for deleted items allows change reports to use common code with
719 * non-deleted or query-response MCA's.
721 pmc
= kzalloc(sizeof(*pmc
), GFP_ATOMIC
);
725 spin_lock_bh(&im
->mca_lock
);
726 spin_lock_init(&pmc
->mca_lock
);
727 pmc
->idev
= im
->idev
;
729 pmc
->mca_addr
= im
->mca_addr
;
730 pmc
->mca_crcount
= idev
->mc_qrv
;
731 pmc
->mca_sfmode
= im
->mca_sfmode
;
732 if (pmc
->mca_sfmode
== MCAST_INCLUDE
) {
733 struct ip6_sf_list
*psf
;
735 pmc
->mca_tomb
= im
->mca_tomb
;
736 pmc
->mca_sources
= im
->mca_sources
;
737 im
->mca_tomb
= im
->mca_sources
= NULL
;
738 for (psf
= pmc
->mca_sources
; psf
; psf
= psf
->sf_next
)
739 psf
->sf_crcount
= pmc
->mca_crcount
;
741 spin_unlock_bh(&im
->mca_lock
);
743 spin_lock_bh(&idev
->mc_lock
);
744 pmc
->next
= idev
->mc_tomb
;
746 spin_unlock_bh(&idev
->mc_lock
);
749 static void mld_del_delrec(struct inet6_dev
*idev
, struct ifmcaddr6
*im
)
751 struct ifmcaddr6
*pmc
, *pmc_prev
;
752 struct ip6_sf_list
*psf
;
753 struct in6_addr
*pmca
= &im
->mca_addr
;
755 spin_lock_bh(&idev
->mc_lock
);
757 for (pmc
= idev
->mc_tomb
; pmc
; pmc
= pmc
->next
) {
758 if (ipv6_addr_equal(&pmc
->mca_addr
, pmca
))
764 pmc_prev
->next
= pmc
->next
;
766 idev
->mc_tomb
= pmc
->next
;
768 spin_unlock_bh(&idev
->mc_lock
);
770 spin_lock_bh(&im
->mca_lock
);
772 im
->idev
= pmc
->idev
;
773 im
->mca_crcount
= idev
->mc_qrv
;
774 if (im
->mca_sfmode
== MCAST_INCLUDE
) {
775 im
->mca_tomb
= pmc
->mca_tomb
;
776 im
->mca_sources
= pmc
->mca_sources
;
777 for (psf
= im
->mca_sources
; psf
; psf
= psf
->sf_next
)
778 psf
->sf_crcount
= im
->mca_crcount
;
780 in6_dev_put(pmc
->idev
);
783 spin_unlock_bh(&im
->mca_lock
);
786 static void mld_clear_delrec(struct inet6_dev
*idev
)
788 struct ifmcaddr6
*pmc
, *nextpmc
;
790 spin_lock_bh(&idev
->mc_lock
);
792 idev
->mc_tomb
= NULL
;
793 spin_unlock_bh(&idev
->mc_lock
);
795 for (; pmc
; pmc
= nextpmc
) {
797 ip6_mc_clear_src(pmc
);
798 in6_dev_put(pmc
->idev
);
802 /* clear dead sources, too */
803 read_lock_bh(&idev
->lock
);
804 for (pmc
= idev
->mc_list
; pmc
; pmc
= pmc
->next
) {
805 struct ip6_sf_list
*psf
, *psf_next
;
807 spin_lock_bh(&pmc
->mca_lock
);
809 pmc
->mca_tomb
= NULL
;
810 spin_unlock_bh(&pmc
->mca_lock
);
811 for (; psf
; psf
= psf_next
) {
812 psf_next
= psf
->sf_next
;
816 read_unlock_bh(&idev
->lock
);
819 static void mca_get(struct ifmcaddr6
*mc
)
821 refcount_inc(&mc
->mca_refcnt
);
824 static void ma_put(struct ifmcaddr6
*mc
)
826 if (refcount_dec_and_test(&mc
->mca_refcnt
)) {
827 in6_dev_put(mc
->idev
);
832 static struct ifmcaddr6
*mca_alloc(struct inet6_dev
*idev
,
833 const struct in6_addr
*addr
)
835 struct ifmcaddr6
*mc
;
837 mc
= kzalloc(sizeof(*mc
), GFP_ATOMIC
);
841 timer_setup(&mc
->mca_timer
, igmp6_timer_handler
, 0);
843 mc
->mca_addr
= *addr
;
844 mc
->idev
= idev
; /* reference taken by caller */
846 /* mca_stamp should be updated upon changes */
847 mc
->mca_cstamp
= mc
->mca_tstamp
= jiffies
;
848 refcount_set(&mc
->mca_refcnt
, 1);
849 spin_lock_init(&mc
->mca_lock
);
851 /* initial mode is (EX, empty) */
852 mc
->mca_sfmode
= MCAST_EXCLUDE
;
853 mc
->mca_sfcount
[MCAST_EXCLUDE
] = 1;
855 if (ipv6_addr_is_ll_all_nodes(&mc
->mca_addr
) ||
856 IPV6_ADDR_MC_SCOPE(&mc
->mca_addr
) < IPV6_ADDR_SCOPE_LINKLOCAL
)
857 mc
->mca_flags
|= MAF_NOREPORT
;
863 * device multicast group inc (add if not found)
865 int ipv6_dev_mc_inc(struct net_device
*dev
, const struct in6_addr
*addr
)
867 struct ifmcaddr6
*mc
;
868 struct inet6_dev
*idev
;
872 /* we need to take a reference on idev */
873 idev
= in6_dev_get(dev
);
878 write_lock_bh(&idev
->lock
);
880 write_unlock_bh(&idev
->lock
);
885 for (mc
= idev
->mc_list
; mc
; mc
= mc
->next
) {
886 if (ipv6_addr_equal(&mc
->mca_addr
, addr
)) {
888 write_unlock_bh(&idev
->lock
);
889 ip6_mc_add_src(idev
, &mc
->mca_addr
, MCAST_EXCLUDE
, 0,
896 mc
= mca_alloc(idev
, addr
);
898 write_unlock_bh(&idev
->lock
);
903 mc
->next
= idev
->mc_list
;
906 /* Hold this for the code below before we unlock,
907 * it is already exposed via idev->mc_list.
910 write_unlock_bh(&idev
->lock
);
912 mld_del_delrec(idev
, mc
);
913 igmp6_group_added(mc
);
919 * device multicast group del
921 int __ipv6_dev_mc_dec(struct inet6_dev
*idev
, const struct in6_addr
*addr
)
923 struct ifmcaddr6
*ma
, **map
;
927 write_lock_bh(&idev
->lock
);
928 for (map
= &idev
->mc_list
; (ma
= *map
) != NULL
; map
= &ma
->next
) {
929 if (ipv6_addr_equal(&ma
->mca_addr
, addr
)) {
930 if (--ma
->mca_users
== 0) {
932 write_unlock_bh(&idev
->lock
);
934 igmp6_group_dropped(ma
);
935 ip6_mc_clear_src(ma
);
940 write_unlock_bh(&idev
->lock
);
944 write_unlock_bh(&idev
->lock
);
949 int ipv6_dev_mc_dec(struct net_device
*dev
, const struct in6_addr
*addr
)
951 struct inet6_dev
*idev
;
956 idev
= __in6_dev_get(dev
);
960 err
= __ipv6_dev_mc_dec(idev
, addr
);
966 * check if the interface/address pair is valid
968 bool ipv6_chk_mcast_addr(struct net_device
*dev
, const struct in6_addr
*group
,
969 const struct in6_addr
*src_addr
)
971 struct inet6_dev
*idev
;
972 struct ifmcaddr6
*mc
;
976 idev
= __in6_dev_get(dev
);
978 read_lock_bh(&idev
->lock
);
979 for (mc
= idev
->mc_list
; mc
; mc
= mc
->next
) {
980 if (ipv6_addr_equal(&mc
->mca_addr
, group
))
984 if (src_addr
&& !ipv6_addr_any(src_addr
)) {
985 struct ip6_sf_list
*psf
;
987 spin_lock_bh(&mc
->mca_lock
);
988 for (psf
= mc
->mca_sources
; psf
; psf
= psf
->sf_next
) {
989 if (ipv6_addr_equal(&psf
->sf_addr
, src_addr
))
993 rv
= psf
->sf_count
[MCAST_INCLUDE
] ||
994 psf
->sf_count
[MCAST_EXCLUDE
] !=
995 mc
->mca_sfcount
[MCAST_EXCLUDE
];
997 rv
= mc
->mca_sfcount
[MCAST_EXCLUDE
] != 0;
998 spin_unlock_bh(&mc
->mca_lock
);
1000 rv
= true; /* don't filter unspecified source */
1002 read_unlock_bh(&idev
->lock
);
1008 static void mld_gq_start_timer(struct inet6_dev
*idev
)
1010 unsigned long tv
= prandom_u32() % idev
->mc_maxdelay
;
1012 idev
->mc_gq_running
= 1;
1013 if (!mod_timer(&idev
->mc_gq_timer
, jiffies
+tv
+2))
1017 static void mld_gq_stop_timer(struct inet6_dev
*idev
)
1019 idev
->mc_gq_running
= 0;
1020 if (del_timer(&idev
->mc_gq_timer
))
1021 __in6_dev_put(idev
);
1024 static void mld_ifc_start_timer(struct inet6_dev
*idev
, unsigned long delay
)
1026 unsigned long tv
= prandom_u32() % delay
;
1028 if (!mod_timer(&idev
->mc_ifc_timer
, jiffies
+tv
+2))
1032 static void mld_ifc_stop_timer(struct inet6_dev
*idev
)
1034 idev
->mc_ifc_count
= 0;
1035 if (del_timer(&idev
->mc_ifc_timer
))
1036 __in6_dev_put(idev
);
1039 static void mld_dad_start_timer(struct inet6_dev
*idev
, unsigned long delay
)
1041 unsigned long tv
= prandom_u32() % delay
;
1043 if (!mod_timer(&idev
->mc_dad_timer
, jiffies
+tv
+2))
1047 static void mld_dad_stop_timer(struct inet6_dev
*idev
)
1049 if (del_timer(&idev
->mc_dad_timer
))
1050 __in6_dev_put(idev
);
1054 * IGMP handling (alias multicast ICMPv6 messages)
1057 static void igmp6_group_queried(struct ifmcaddr6
*ma
, unsigned long resptime
)
1059 unsigned long delay
= resptime
;
1061 /* Do not start timer for these addresses */
1062 if (ipv6_addr_is_ll_all_nodes(&ma
->mca_addr
) ||
1063 IPV6_ADDR_MC_SCOPE(&ma
->mca_addr
) < IPV6_ADDR_SCOPE_LINKLOCAL
)
1066 if (del_timer(&ma
->mca_timer
)) {
1067 refcount_dec(&ma
->mca_refcnt
);
1068 delay
= ma
->mca_timer
.expires
- jiffies
;
1071 if (delay
>= resptime
)
1072 delay
= prandom_u32() % resptime
;
1074 ma
->mca_timer
.expires
= jiffies
+ delay
;
1075 if (!mod_timer(&ma
->mca_timer
, jiffies
+ delay
))
1076 refcount_inc(&ma
->mca_refcnt
);
1077 ma
->mca_flags
|= MAF_TIMER_RUNNING
;
1080 /* mark EXCLUDE-mode sources */
1081 static bool mld_xmarksources(struct ifmcaddr6
*pmc
, int nsrcs
,
1082 const struct in6_addr
*srcs
)
1084 struct ip6_sf_list
*psf
;
1088 for (psf
= pmc
->mca_sources
; psf
; psf
= psf
->sf_next
) {
1089 if (scount
== nsrcs
)
1091 for (i
= 0; i
< nsrcs
; i
++) {
1092 /* skip inactive filters */
1093 if (psf
->sf_count
[MCAST_INCLUDE
] ||
1094 pmc
->mca_sfcount
[MCAST_EXCLUDE
] !=
1095 psf
->sf_count
[MCAST_EXCLUDE
])
1097 if (ipv6_addr_equal(&srcs
[i
], &psf
->sf_addr
)) {
1103 pmc
->mca_flags
&= ~MAF_GSQUERY
;
1104 if (scount
== nsrcs
) /* all sources excluded */
1109 static bool mld_marksources(struct ifmcaddr6
*pmc
, int nsrcs
,
1110 const struct in6_addr
*srcs
)
1112 struct ip6_sf_list
*psf
;
1115 if (pmc
->mca_sfmode
== MCAST_EXCLUDE
)
1116 return mld_xmarksources(pmc
, nsrcs
, srcs
);
1118 /* mark INCLUDE-mode sources */
1121 for (psf
= pmc
->mca_sources
; psf
; psf
= psf
->sf_next
) {
1122 if (scount
== nsrcs
)
1124 for (i
= 0; i
< nsrcs
; i
++) {
1125 if (ipv6_addr_equal(&srcs
[i
], &psf
->sf_addr
)) {
1133 pmc
->mca_flags
&= ~MAF_GSQUERY
;
1136 pmc
->mca_flags
|= MAF_GSQUERY
;
1140 static int mld_force_mld_version(const struct inet6_dev
*idev
)
1142 /* Normally, both are 0 here. If enforcement to a particular is
1143 * being used, individual device enforcement will have a lower
1144 * precedence over 'all' device (.../conf/all/force_mld_version).
1147 if (dev_net(idev
->dev
)->ipv6
.devconf_all
->force_mld_version
!= 0)
1148 return dev_net(idev
->dev
)->ipv6
.devconf_all
->force_mld_version
;
1150 return idev
->cnf
.force_mld_version
;
1153 static bool mld_in_v2_mode_only(const struct inet6_dev
*idev
)
1155 return mld_force_mld_version(idev
) == 2;
1158 static bool mld_in_v1_mode_only(const struct inet6_dev
*idev
)
1160 return mld_force_mld_version(idev
) == 1;
1163 static bool mld_in_v1_mode(const struct inet6_dev
*idev
)
1165 if (mld_in_v2_mode_only(idev
))
1167 if (mld_in_v1_mode_only(idev
))
1169 if (idev
->mc_v1_seen
&& time_before(jiffies
, idev
->mc_v1_seen
))
1175 static void mld_set_v1_mode(struct inet6_dev
*idev
)
1177 /* RFC3810, relevant sections:
1178 * - 9.1. Robustness Variable
1179 * - 9.2. Query Interval
1180 * - 9.3. Query Response Interval
1181 * - 9.12. Older Version Querier Present Timeout
1183 unsigned long switchback
;
1185 switchback
= (idev
->mc_qrv
* idev
->mc_qi
) + idev
->mc_qri
;
1187 idev
->mc_v1_seen
= jiffies
+ switchback
;
1190 static void mld_update_qrv(struct inet6_dev
*idev
,
1191 const struct mld2_query
*mlh2
)
1193 /* RFC3810, relevant sections:
1194 * - 5.1.8. QRV (Querier's Robustness Variable)
1195 * - 9.1. Robustness Variable
1198 /* The value of the Robustness Variable MUST NOT be zero,
1199 * and SHOULD NOT be one. Catch this here if we ever run
1200 * into such a case in future.
1202 const int min_qrv
= min(MLD_QRV_DEFAULT
, sysctl_mld_qrv
);
1203 WARN_ON(idev
->mc_qrv
== 0);
1205 if (mlh2
->mld2q_qrv
> 0)
1206 idev
->mc_qrv
= mlh2
->mld2q_qrv
;
1208 if (unlikely(idev
->mc_qrv
< min_qrv
)) {
1209 net_warn_ratelimited("IPv6: MLD: clamping QRV from %u to %u!\n",
1210 idev
->mc_qrv
, min_qrv
);
1211 idev
->mc_qrv
= min_qrv
;
1215 static void mld_update_qi(struct inet6_dev
*idev
,
1216 const struct mld2_query
*mlh2
)
1218 /* RFC3810, relevant sections:
1219 * - 5.1.9. QQIC (Querier's Query Interval Code)
1220 * - 9.2. Query Interval
1221 * - 9.12. Older Version Querier Present Timeout
1222 * (the [Query Interval] in the last Query received)
1224 unsigned long mc_qqi
;
1226 if (mlh2
->mld2q_qqic
< 128) {
1227 mc_qqi
= mlh2
->mld2q_qqic
;
1229 unsigned long mc_man
, mc_exp
;
1231 mc_exp
= MLDV2_QQIC_EXP(mlh2
->mld2q_qqic
);
1232 mc_man
= MLDV2_QQIC_MAN(mlh2
->mld2q_qqic
);
1234 mc_qqi
= (mc_man
| 0x10) << (mc_exp
+ 3);
1237 idev
->mc_qi
= mc_qqi
* HZ
;
1240 static void mld_update_qri(struct inet6_dev
*idev
,
1241 const struct mld2_query
*mlh2
)
1243 /* RFC3810, relevant sections:
1244 * - 5.1.3. Maximum Response Code
1245 * - 9.3. Query Response Interval
1247 idev
->mc_qri
= msecs_to_jiffies(mldv2_mrc(mlh2
));
1250 static int mld_process_v1(struct inet6_dev
*idev
, struct mld_msg
*mld
,
1251 unsigned long *max_delay
, bool v1_query
)
1253 unsigned long mldv1_md
;
1255 /* Ignore v1 queries */
1256 if (mld_in_v2_mode_only(idev
))
1259 mldv1_md
= ntohs(mld
->mld_maxdelay
);
1261 /* When in MLDv1 fallback and a MLDv2 router start-up being
1262 * unaware of current MLDv1 operation, the MRC == MRD mapping
1263 * only works when the exponential algorithm is not being
1264 * used (as MLDv1 is unaware of such things).
1266 * According to the RFC author, the MLDv2 implementations
1267 * he's aware of all use a MRC < 32768 on start up queries.
1269 * Thus, should we *ever* encounter something else larger
1270 * than that, just assume the maximum possible within our
1274 mldv1_md
= min(mldv1_md
, MLDV1_MRD_MAX_COMPAT
);
1276 *max_delay
= max(msecs_to_jiffies(mldv1_md
), 1UL);
1278 /* MLDv1 router present: we need to go into v1 mode *only*
1279 * when an MLDv1 query is received as per section 9.12. of
1280 * RFC3810! And we know from RFC2710 section 3.7 that MLDv1
1281 * queries MUST be of exactly 24 octets.
1284 mld_set_v1_mode(idev
);
1286 /* cancel MLDv2 report timer */
1287 mld_gq_stop_timer(idev
);
1288 /* cancel the interface change timer */
1289 mld_ifc_stop_timer(idev
);
1290 /* clear deleted report items */
1291 mld_clear_delrec(idev
);
1296 static int mld_process_v2(struct inet6_dev
*idev
, struct mld2_query
*mld
,
1297 unsigned long *max_delay
)
1299 *max_delay
= max(msecs_to_jiffies(mldv2_mrc(mld
)), 1UL);
1301 mld_update_qrv(idev
, mld
);
1302 mld_update_qi(idev
, mld
);
1303 mld_update_qri(idev
, mld
);
1305 idev
->mc_maxdelay
= *max_delay
;
1310 /* called with rcu_read_lock() */
1311 int igmp6_event_query(struct sk_buff
*skb
)
1313 struct mld2_query
*mlh2
= NULL
;
1314 struct ifmcaddr6
*ma
;
1315 const struct in6_addr
*group
;
1316 unsigned long max_delay
;
1317 struct inet6_dev
*idev
;
1318 struct mld_msg
*mld
;
1323 if (!pskb_may_pull(skb
, sizeof(struct in6_addr
)))
1326 /* compute payload length excluding extension headers */
1327 len
= ntohs(ipv6_hdr(skb
)->payload_len
) + sizeof(struct ipv6hdr
);
1328 len
-= skb_network_header_len(skb
);
1331 * Upon reception of an MLD message that contains a Query, the node
1332 * checks if the source address of the message is a valid link-local
1333 * address, if the Hop Limit is set to 1, and if the Router Alert
1334 * option is present in the Hop-By-Hop Options header of the IPv6
1335 * packet. If any of these checks fails, the packet is dropped.
1337 if (!(ipv6_addr_type(&ipv6_hdr(skb
)->saddr
) & IPV6_ADDR_LINKLOCAL
) ||
1338 ipv6_hdr(skb
)->hop_limit
!= 1 ||
1339 !(IP6CB(skb
)->flags
& IP6SKB_ROUTERALERT
) ||
1340 IP6CB(skb
)->ra
!= htons(IPV6_OPT_ROUTERALERT_MLD
))
1343 idev
= __in6_dev_get(skb
->dev
);
1347 mld
= (struct mld_msg
*)icmp6_hdr(skb
);
1348 group
= &mld
->mld_mca
;
1349 group_type
= ipv6_addr_type(group
);
1351 if (group_type
!= IPV6_ADDR_ANY
&&
1352 !(group_type
&IPV6_ADDR_MULTICAST
))
1355 if (len
< MLD_V1_QUERY_LEN
) {
1357 } else if (len
== MLD_V1_QUERY_LEN
|| mld_in_v1_mode(idev
)) {
1358 err
= mld_process_v1(idev
, mld
, &max_delay
,
1359 len
== MLD_V1_QUERY_LEN
);
1362 } else if (len
>= MLD_V2_QUERY_LEN_MIN
) {
1363 int srcs_offset
= sizeof(struct mld2_query
) -
1364 sizeof(struct icmp6hdr
);
1366 if (!pskb_may_pull(skb
, srcs_offset
))
1369 mlh2
= (struct mld2_query
*)skb_transport_header(skb
);
1371 err
= mld_process_v2(idev
, mlh2
, &max_delay
);
1375 if (group_type
== IPV6_ADDR_ANY
) { /* general query */
1376 if (mlh2
->mld2q_nsrcs
)
1377 return -EINVAL
; /* no sources allowed */
1379 mld_gq_start_timer(idev
);
1382 /* mark sources to include, if group & source-specific */
1383 if (mlh2
->mld2q_nsrcs
!= 0) {
1384 if (!pskb_may_pull(skb
, srcs_offset
+
1385 ntohs(mlh2
->mld2q_nsrcs
) * sizeof(struct in6_addr
)))
1388 mlh2
= (struct mld2_query
*)skb_transport_header(skb
);
1395 read_lock_bh(&idev
->lock
);
1396 if (group_type
== IPV6_ADDR_ANY
) {
1397 for (ma
= idev
->mc_list
; ma
; ma
= ma
->next
) {
1398 spin_lock_bh(&ma
->mca_lock
);
1399 igmp6_group_queried(ma
, max_delay
);
1400 spin_unlock_bh(&ma
->mca_lock
);
1403 for (ma
= idev
->mc_list
; ma
; ma
= ma
->next
) {
1404 if (!ipv6_addr_equal(group
, &ma
->mca_addr
))
1406 spin_lock_bh(&ma
->mca_lock
);
1407 if (ma
->mca_flags
& MAF_TIMER_RUNNING
) {
1408 /* gsquery <- gsquery && mark */
1410 ma
->mca_flags
&= ~MAF_GSQUERY
;
1412 /* gsquery <- mark */
1414 ma
->mca_flags
|= MAF_GSQUERY
;
1416 ma
->mca_flags
&= ~MAF_GSQUERY
;
1418 if (!(ma
->mca_flags
& MAF_GSQUERY
) ||
1419 mld_marksources(ma
, ntohs(mlh2
->mld2q_nsrcs
), mlh2
->mld2q_srcs
))
1420 igmp6_group_queried(ma
, max_delay
);
1421 spin_unlock_bh(&ma
->mca_lock
);
1425 read_unlock_bh(&idev
->lock
);
1430 /* called with rcu_read_lock() */
1431 int igmp6_event_report(struct sk_buff
*skb
)
1433 struct ifmcaddr6
*ma
;
1434 struct inet6_dev
*idev
;
1435 struct mld_msg
*mld
;
1438 /* Our own report looped back. Ignore it. */
1439 if (skb
->pkt_type
== PACKET_LOOPBACK
)
1442 /* send our report if the MC router may not have heard this report */
1443 if (skb
->pkt_type
!= PACKET_MULTICAST
&&
1444 skb
->pkt_type
!= PACKET_BROADCAST
)
1447 if (!pskb_may_pull(skb
, sizeof(*mld
) - sizeof(struct icmp6hdr
)))
1450 mld
= (struct mld_msg
*)icmp6_hdr(skb
);
1452 /* Drop reports with not link local source */
1453 addr_type
= ipv6_addr_type(&ipv6_hdr(skb
)->saddr
);
1454 if (addr_type
!= IPV6_ADDR_ANY
&&
1455 !(addr_type
&IPV6_ADDR_LINKLOCAL
))
1458 idev
= __in6_dev_get(skb
->dev
);
1463 * Cancel the timer for this group
1466 read_lock_bh(&idev
->lock
);
1467 for (ma
= idev
->mc_list
; ma
; ma
= ma
->next
) {
1468 if (ipv6_addr_equal(&ma
->mca_addr
, &mld
->mld_mca
)) {
1469 spin_lock(&ma
->mca_lock
);
1470 if (del_timer(&ma
->mca_timer
))
1471 refcount_dec(&ma
->mca_refcnt
);
1472 ma
->mca_flags
&= ~(MAF_LAST_REPORTER
|MAF_TIMER_RUNNING
);
1473 spin_unlock(&ma
->mca_lock
);
1477 read_unlock_bh(&idev
->lock
);
1481 static bool is_in(struct ifmcaddr6
*pmc
, struct ip6_sf_list
*psf
, int type
,
1482 int gdeleted
, int sdeleted
)
1485 case MLD2_MODE_IS_INCLUDE
:
1486 case MLD2_MODE_IS_EXCLUDE
:
1487 if (gdeleted
|| sdeleted
)
1489 if (!((pmc
->mca_flags
& MAF_GSQUERY
) && !psf
->sf_gsresp
)) {
1490 if (pmc
->mca_sfmode
== MCAST_INCLUDE
)
1492 /* don't include if this source is excluded
1495 if (psf
->sf_count
[MCAST_INCLUDE
])
1496 return type
== MLD2_MODE_IS_INCLUDE
;
1497 return pmc
->mca_sfcount
[MCAST_EXCLUDE
] ==
1498 psf
->sf_count
[MCAST_EXCLUDE
];
1501 case MLD2_CHANGE_TO_INCLUDE
:
1502 if (gdeleted
|| sdeleted
)
1504 return psf
->sf_count
[MCAST_INCLUDE
] != 0;
1505 case MLD2_CHANGE_TO_EXCLUDE
:
1506 if (gdeleted
|| sdeleted
)
1508 if (pmc
->mca_sfcount
[MCAST_EXCLUDE
] == 0 ||
1509 psf
->sf_count
[MCAST_INCLUDE
])
1511 return pmc
->mca_sfcount
[MCAST_EXCLUDE
] ==
1512 psf
->sf_count
[MCAST_EXCLUDE
];
1513 case MLD2_ALLOW_NEW_SOURCES
:
1514 if (gdeleted
|| !psf
->sf_crcount
)
1516 return (pmc
->mca_sfmode
== MCAST_INCLUDE
) ^ sdeleted
;
1517 case MLD2_BLOCK_OLD_SOURCES
:
1518 if (pmc
->mca_sfmode
== MCAST_INCLUDE
)
1519 return gdeleted
|| (psf
->sf_crcount
&& sdeleted
);
1520 return psf
->sf_crcount
&& !gdeleted
&& !sdeleted
;
1526 mld_scount(struct ifmcaddr6
*pmc
, int type
, int gdeleted
, int sdeleted
)
1528 struct ip6_sf_list
*psf
;
1531 for (psf
= pmc
->mca_sources
; psf
; psf
= psf
->sf_next
) {
1532 if (!is_in(pmc
, psf
, type
, gdeleted
, sdeleted
))
1539 static void ip6_mc_hdr(struct sock
*sk
, struct sk_buff
*skb
,
1540 struct net_device
*dev
,
1541 const struct in6_addr
*saddr
,
1542 const struct in6_addr
*daddr
,
1545 struct ipv6hdr
*hdr
;
1547 skb
->protocol
= htons(ETH_P_IPV6
);
1550 skb_reset_network_header(skb
);
1551 skb_put(skb
, sizeof(struct ipv6hdr
));
1552 hdr
= ipv6_hdr(skb
);
1554 ip6_flow_hdr(hdr
, 0, 0);
1556 hdr
->payload_len
= htons(len
);
1557 hdr
->nexthdr
= proto
;
1558 hdr
->hop_limit
= inet6_sk(sk
)->hop_limit
;
1560 hdr
->saddr
= *saddr
;
1561 hdr
->daddr
= *daddr
;
1564 static struct sk_buff
*mld_newpack(struct inet6_dev
*idev
, unsigned int mtu
)
1566 struct net_device
*dev
= idev
->dev
;
1567 struct net
*net
= dev_net(dev
);
1568 struct sock
*sk
= net
->ipv6
.igmp_sk
;
1569 struct sk_buff
*skb
;
1570 struct mld2_report
*pmr
;
1571 struct in6_addr addr_buf
;
1572 const struct in6_addr
*saddr
;
1573 int hlen
= LL_RESERVED_SPACE(dev
);
1574 int tlen
= dev
->needed_tailroom
;
1575 unsigned int size
= mtu
+ hlen
+ tlen
;
1577 u8 ra
[8] = { IPPROTO_ICMPV6
, 0,
1578 IPV6_TLV_ROUTERALERT
, 2, 0, 0,
1581 /* we assume size > sizeof(ra) here */
1582 /* limit our allocations to order-0 page */
1583 size
= min_t(int, size
, SKB_MAX_ORDER(0, 0));
1584 skb
= sock_alloc_send_skb(sk
, size
, 1, &err
);
1589 skb
->priority
= TC_PRIO_CONTROL
;
1590 skb_reserve(skb
, hlen
);
1591 skb_tailroom_reserve(skb
, mtu
, tlen
);
1593 if (__ipv6_get_lladdr(idev
, &addr_buf
, IFA_F_TENTATIVE
)) {
1594 /* <draft-ietf-magma-mld-source-05.txt>:
1595 * use unspecified address as the source address
1596 * when a valid link-local address is not available.
1598 saddr
= &in6addr_any
;
1602 ip6_mc_hdr(sk
, skb
, dev
, saddr
, &mld2_all_mcr
, NEXTHDR_HOP
, 0);
1604 skb_put_data(skb
, ra
, sizeof(ra
));
1606 skb_set_transport_header(skb
, skb_tail_pointer(skb
) - skb
->data
);
1607 skb_put(skb
, sizeof(*pmr
));
1608 pmr
= (struct mld2_report
*)skb_transport_header(skb
);
1609 pmr
->mld2r_type
= ICMPV6_MLD2_REPORT
;
1610 pmr
->mld2r_resv1
= 0;
1611 pmr
->mld2r_cksum
= 0;
1612 pmr
->mld2r_resv2
= 0;
1613 pmr
->mld2r_ngrec
= 0;
1617 static void mld_sendpack(struct sk_buff
*skb
)
1619 struct ipv6hdr
*pip6
= ipv6_hdr(skb
);
1620 struct mld2_report
*pmr
=
1621 (struct mld2_report
*)skb_transport_header(skb
);
1622 int payload_len
, mldlen
;
1623 struct inet6_dev
*idev
;
1624 struct net
*net
= dev_net(skb
->dev
);
1627 struct dst_entry
*dst
;
1630 idev
= __in6_dev_get(skb
->dev
);
1631 IP6_UPD_PO_STATS(net
, idev
, IPSTATS_MIB_OUT
, skb
->len
);
1633 payload_len
= (skb_tail_pointer(skb
) - skb_network_header(skb
)) -
1635 mldlen
= skb_tail_pointer(skb
) - skb_transport_header(skb
);
1636 pip6
->payload_len
= htons(payload_len
);
1638 pmr
->mld2r_cksum
= csum_ipv6_magic(&pip6
->saddr
, &pip6
->daddr
, mldlen
,
1640 csum_partial(skb_transport_header(skb
),
1643 icmpv6_flow_init(net
->ipv6
.igmp_sk
, &fl6
, ICMPV6_MLD2_REPORT
,
1644 &ipv6_hdr(skb
)->saddr
, &ipv6_hdr(skb
)->daddr
,
1646 dst
= icmp6_dst_alloc(skb
->dev
, &fl6
);
1653 skb_dst_set(skb
, dst
);
1657 payload_len
= skb
->len
;
1659 err
= NF_HOOK(NFPROTO_IPV6
, NF_INET_LOCAL_OUT
,
1660 net
, net
->ipv6
.igmp_sk
, skb
, NULL
, skb
->dev
,
1664 ICMP6MSGOUT_INC_STATS(net
, idev
, ICMPV6_MLD2_REPORT
);
1665 ICMP6_INC_STATS(net
, idev
, ICMP6_MIB_OUTMSGS
);
1667 IP6_INC_STATS(net
, idev
, IPSTATS_MIB_OUTDISCARDS
);
1678 static int grec_size(struct ifmcaddr6
*pmc
, int type
, int gdel
, int sdel
)
1680 return sizeof(struct mld2_grec
) + 16 * mld_scount(pmc
,type
,gdel
,sdel
);
1683 static struct sk_buff
*add_grhead(struct sk_buff
*skb
, struct ifmcaddr6
*pmc
,
1684 int type
, struct mld2_grec
**ppgr
, unsigned int mtu
)
1686 struct mld2_report
*pmr
;
1687 struct mld2_grec
*pgr
;
1690 skb
= mld_newpack(pmc
->idev
, mtu
);
1694 pgr
= skb_put(skb
, sizeof(struct mld2_grec
));
1695 pgr
->grec_type
= type
;
1696 pgr
->grec_auxwords
= 0;
1697 pgr
->grec_nsrcs
= 0;
1698 pgr
->grec_mca
= pmc
->mca_addr
; /* structure copy */
1699 pmr
= (struct mld2_report
*)skb_transport_header(skb
);
1700 pmr
->mld2r_ngrec
= htons(ntohs(pmr
->mld2r_ngrec
)+1);
1705 #define AVAILABLE(skb) ((skb) ? skb_availroom(skb) : 0)
1707 static struct sk_buff
*add_grec(struct sk_buff
*skb
, struct ifmcaddr6
*pmc
,
1708 int type
, int gdeleted
, int sdeleted
, int crsend
)
1710 struct inet6_dev
*idev
= pmc
->idev
;
1711 struct net_device
*dev
= idev
->dev
;
1712 struct mld2_report
*pmr
;
1713 struct mld2_grec
*pgr
= NULL
;
1714 struct ip6_sf_list
*psf
, *psf_next
, *psf_prev
, **psf_list
;
1715 int scount
, stotal
, first
, isquery
, truncate
;
1718 if (pmc
->mca_flags
& MAF_NOREPORT
)
1721 mtu
= READ_ONCE(dev
->mtu
);
1722 if (mtu
< IPV6_MIN_MTU
)
1725 isquery
= type
== MLD2_MODE_IS_INCLUDE
||
1726 type
== MLD2_MODE_IS_EXCLUDE
;
1727 truncate
= type
== MLD2_MODE_IS_EXCLUDE
||
1728 type
== MLD2_CHANGE_TO_EXCLUDE
;
1730 stotal
= scount
= 0;
1732 psf_list
= sdeleted
? &pmc
->mca_tomb
: &pmc
->mca_sources
;
1737 pmr
= skb
? (struct mld2_report
*)skb_transport_header(skb
) : NULL
;
1739 /* EX and TO_EX get a fresh packet, if needed */
1741 if (pmr
&& pmr
->mld2r_ngrec
&&
1742 AVAILABLE(skb
) < grec_size(pmc
, type
, gdeleted
, sdeleted
)) {
1745 skb
= mld_newpack(idev
, mtu
);
1750 for (psf
= *psf_list
; psf
; psf
= psf_next
) {
1751 struct in6_addr
*psrc
;
1753 psf_next
= psf
->sf_next
;
1755 if (!is_in(pmc
, psf
, type
, gdeleted
, sdeleted
)) {
1760 /* Based on RFC3810 6.1. Should not send source-list change
1761 * records when there is a filter mode change.
1763 if (((gdeleted
&& pmc
->mca_sfmode
== MCAST_EXCLUDE
) ||
1764 (!gdeleted
&& pmc
->mca_crcount
)) &&
1765 (type
== MLD2_ALLOW_NEW_SOURCES
||
1766 type
== MLD2_BLOCK_OLD_SOURCES
) && psf
->sf_crcount
)
1767 goto decrease_sf_crcount
;
1769 /* clear marks on query responses */
1773 if (AVAILABLE(skb
) < sizeof(*psrc
) +
1774 first
*sizeof(struct mld2_grec
)) {
1775 if (truncate
&& !first
)
1776 break; /* truncate these */
1778 pgr
->grec_nsrcs
= htons(scount
);
1781 skb
= mld_newpack(idev
, mtu
);
1786 skb
= add_grhead(skb
, pmc
, type
, &pgr
, mtu
);
1791 psrc
= skb_put(skb
, sizeof(*psrc
));
1792 *psrc
= psf
->sf_addr
;
1794 if ((type
== MLD2_ALLOW_NEW_SOURCES
||
1795 type
== MLD2_BLOCK_OLD_SOURCES
) && psf
->sf_crcount
) {
1796 decrease_sf_crcount
:
1798 if ((sdeleted
|| gdeleted
) && psf
->sf_crcount
== 0) {
1800 psf_prev
->sf_next
= psf
->sf_next
;
1802 *psf_list
= psf
->sf_next
;
1812 if (type
== MLD2_ALLOW_NEW_SOURCES
||
1813 type
== MLD2_BLOCK_OLD_SOURCES
)
1815 if (pmc
->mca_crcount
|| isquery
|| crsend
) {
1816 /* make sure we have room for group header */
1817 if (skb
&& AVAILABLE(skb
) < sizeof(struct mld2_grec
)) {
1819 skb
= NULL
; /* add_grhead will get a new one */
1821 skb
= add_grhead(skb
, pmc
, type
, &pgr
, mtu
);
1825 pgr
->grec_nsrcs
= htons(scount
);
1828 pmc
->mca_flags
&= ~MAF_GSQUERY
; /* clear query state */
1832 static void mld_send_report(struct inet6_dev
*idev
, struct ifmcaddr6
*pmc
)
1834 struct sk_buff
*skb
= NULL
;
1837 read_lock_bh(&idev
->lock
);
1839 for (pmc
= idev
->mc_list
; pmc
; pmc
= pmc
->next
) {
1840 if (pmc
->mca_flags
& MAF_NOREPORT
)
1842 spin_lock_bh(&pmc
->mca_lock
);
1843 if (pmc
->mca_sfcount
[MCAST_EXCLUDE
])
1844 type
= MLD2_MODE_IS_EXCLUDE
;
1846 type
= MLD2_MODE_IS_INCLUDE
;
1847 skb
= add_grec(skb
, pmc
, type
, 0, 0, 0);
1848 spin_unlock_bh(&pmc
->mca_lock
);
1851 spin_lock_bh(&pmc
->mca_lock
);
1852 if (pmc
->mca_sfcount
[MCAST_EXCLUDE
])
1853 type
= MLD2_MODE_IS_EXCLUDE
;
1855 type
= MLD2_MODE_IS_INCLUDE
;
1856 skb
= add_grec(skb
, pmc
, type
, 0, 0, 0);
1857 spin_unlock_bh(&pmc
->mca_lock
);
1859 read_unlock_bh(&idev
->lock
);
1865 * remove zero-count source records from a source filter list
1867 static void mld_clear_zeros(struct ip6_sf_list
**ppsf
)
1869 struct ip6_sf_list
*psf_prev
, *psf_next
, *psf
;
1872 for (psf
= *ppsf
; psf
; psf
= psf_next
) {
1873 psf_next
= psf
->sf_next
;
1874 if (psf
->sf_crcount
== 0) {
1876 psf_prev
->sf_next
= psf
->sf_next
;
1878 *ppsf
= psf
->sf_next
;
1885 static void mld_send_cr(struct inet6_dev
*idev
)
1887 struct ifmcaddr6
*pmc
, *pmc_prev
, *pmc_next
;
1888 struct sk_buff
*skb
= NULL
;
1891 read_lock_bh(&idev
->lock
);
1892 spin_lock(&idev
->mc_lock
);
1896 for (pmc
= idev
->mc_tomb
; pmc
; pmc
= pmc_next
) {
1897 pmc_next
= pmc
->next
;
1898 if (pmc
->mca_sfmode
== MCAST_INCLUDE
) {
1899 type
= MLD2_BLOCK_OLD_SOURCES
;
1900 dtype
= MLD2_BLOCK_OLD_SOURCES
;
1901 skb
= add_grec(skb
, pmc
, type
, 1, 0, 0);
1902 skb
= add_grec(skb
, pmc
, dtype
, 1, 1, 0);
1904 if (pmc
->mca_crcount
) {
1905 if (pmc
->mca_sfmode
== MCAST_EXCLUDE
) {
1906 type
= MLD2_CHANGE_TO_INCLUDE
;
1907 skb
= add_grec(skb
, pmc
, type
, 1, 0, 0);
1910 if (pmc
->mca_crcount
== 0) {
1911 mld_clear_zeros(&pmc
->mca_tomb
);
1912 mld_clear_zeros(&pmc
->mca_sources
);
1915 if (pmc
->mca_crcount
== 0 && !pmc
->mca_tomb
&&
1916 !pmc
->mca_sources
) {
1918 pmc_prev
->next
= pmc_next
;
1920 idev
->mc_tomb
= pmc_next
;
1921 in6_dev_put(pmc
->idev
);
1926 spin_unlock(&idev
->mc_lock
);
1929 for (pmc
= idev
->mc_list
; pmc
; pmc
= pmc
->next
) {
1930 spin_lock_bh(&pmc
->mca_lock
);
1931 if (pmc
->mca_sfcount
[MCAST_EXCLUDE
]) {
1932 type
= MLD2_BLOCK_OLD_SOURCES
;
1933 dtype
= MLD2_ALLOW_NEW_SOURCES
;
1935 type
= MLD2_ALLOW_NEW_SOURCES
;
1936 dtype
= MLD2_BLOCK_OLD_SOURCES
;
1938 skb
= add_grec(skb
, pmc
, type
, 0, 0, 0);
1939 skb
= add_grec(skb
, pmc
, dtype
, 0, 1, 0); /* deleted sources */
1941 /* filter mode changes */
1942 if (pmc
->mca_crcount
) {
1943 if (pmc
->mca_sfmode
== MCAST_EXCLUDE
)
1944 type
= MLD2_CHANGE_TO_EXCLUDE
;
1946 type
= MLD2_CHANGE_TO_INCLUDE
;
1947 skb
= add_grec(skb
, pmc
, type
, 0, 0, 0);
1950 spin_unlock_bh(&pmc
->mca_lock
);
1952 read_unlock_bh(&idev
->lock
);
1955 (void) mld_sendpack(skb
);
1958 static void igmp6_send(struct in6_addr
*addr
, struct net_device
*dev
, int type
)
1960 struct net
*net
= dev_net(dev
);
1961 struct sock
*sk
= net
->ipv6
.igmp_sk
;
1962 struct inet6_dev
*idev
;
1963 struct sk_buff
*skb
;
1964 struct mld_msg
*hdr
;
1965 const struct in6_addr
*snd_addr
, *saddr
;
1966 struct in6_addr addr_buf
;
1967 int hlen
= LL_RESERVED_SPACE(dev
);
1968 int tlen
= dev
->needed_tailroom
;
1969 int err
, len
, payload_len
, full_len
;
1970 u8 ra
[8] = { IPPROTO_ICMPV6
, 0,
1971 IPV6_TLV_ROUTERALERT
, 2, 0, 0,
1974 struct dst_entry
*dst
;
1976 if (type
== ICMPV6_MGM_REDUCTION
)
1977 snd_addr
= &in6addr_linklocal_allrouters
;
1981 len
= sizeof(struct icmp6hdr
) + sizeof(struct in6_addr
);
1982 payload_len
= len
+ sizeof(ra
);
1983 full_len
= sizeof(struct ipv6hdr
) + payload_len
;
1986 IP6_UPD_PO_STATS(net
, __in6_dev_get(dev
),
1987 IPSTATS_MIB_OUT
, full_len
);
1990 skb
= sock_alloc_send_skb(sk
, hlen
+ tlen
+ full_len
, 1, &err
);
1994 IP6_INC_STATS(net
, __in6_dev_get(dev
),
1995 IPSTATS_MIB_OUTDISCARDS
);
1999 skb
->priority
= TC_PRIO_CONTROL
;
2000 skb_reserve(skb
, hlen
);
2002 if (ipv6_get_lladdr(dev
, &addr_buf
, IFA_F_TENTATIVE
)) {
2003 /* <draft-ietf-magma-mld-source-05.txt>:
2004 * use unspecified address as the source address
2005 * when a valid link-local address is not available.
2007 saddr
= &in6addr_any
;
2011 ip6_mc_hdr(sk
, skb
, dev
, saddr
, snd_addr
, NEXTHDR_HOP
, payload_len
);
2013 skb_put_data(skb
, ra
, sizeof(ra
));
2015 hdr
= skb_put_zero(skb
, sizeof(struct mld_msg
));
2016 hdr
->mld_type
= type
;
2017 hdr
->mld_mca
= *addr
;
2019 hdr
->mld_cksum
= csum_ipv6_magic(saddr
, snd_addr
, len
,
2021 csum_partial(hdr
, len
, 0));
2024 idev
= __in6_dev_get(skb
->dev
);
2026 icmpv6_flow_init(sk
, &fl6
, type
,
2027 &ipv6_hdr(skb
)->saddr
, &ipv6_hdr(skb
)->daddr
,
2029 dst
= icmp6_dst_alloc(skb
->dev
, &fl6
);
2035 skb_dst_set(skb
, dst
);
2036 err
= NF_HOOK(NFPROTO_IPV6
, NF_INET_LOCAL_OUT
,
2037 net
, sk
, skb
, NULL
, skb
->dev
,
2041 ICMP6MSGOUT_INC_STATS(net
, idev
, type
);
2042 ICMP6_INC_STATS(net
, idev
, ICMP6_MIB_OUTMSGS
);
2044 IP6_INC_STATS(net
, idev
, IPSTATS_MIB_OUTDISCARDS
);
2054 static void mld_send_initial_cr(struct inet6_dev
*idev
)
2056 struct sk_buff
*skb
;
2057 struct ifmcaddr6
*pmc
;
2060 if (mld_in_v1_mode(idev
))
2064 read_lock_bh(&idev
->lock
);
2065 for (pmc
= idev
->mc_list
; pmc
; pmc
= pmc
->next
) {
2066 spin_lock_bh(&pmc
->mca_lock
);
2067 if (pmc
->mca_sfcount
[MCAST_EXCLUDE
])
2068 type
= MLD2_CHANGE_TO_EXCLUDE
;
2070 type
= MLD2_CHANGE_TO_INCLUDE
;
2071 skb
= add_grec(skb
, pmc
, type
, 0, 0, 1);
2072 spin_unlock_bh(&pmc
->mca_lock
);
2074 read_unlock_bh(&idev
->lock
);
2079 void ipv6_mc_dad_complete(struct inet6_dev
*idev
)
2081 idev
->mc_dad_count
= idev
->mc_qrv
;
2082 if (idev
->mc_dad_count
) {
2083 mld_send_initial_cr(idev
);
2084 idev
->mc_dad_count
--;
2085 if (idev
->mc_dad_count
)
2086 mld_dad_start_timer(idev
, idev
->mc_maxdelay
);
2090 static void mld_dad_timer_expire(struct timer_list
*t
)
2092 struct inet6_dev
*idev
= from_timer(idev
, t
, mc_dad_timer
);
2094 mld_send_initial_cr(idev
);
2095 if (idev
->mc_dad_count
) {
2096 idev
->mc_dad_count
--;
2097 if (idev
->mc_dad_count
)
2098 mld_dad_start_timer(idev
, idev
->mc_maxdelay
);
2103 static int ip6_mc_del1_src(struct ifmcaddr6
*pmc
, int sfmode
,
2104 const struct in6_addr
*psfsrc
)
2106 struct ip6_sf_list
*psf
, *psf_prev
;
2110 for (psf
= pmc
->mca_sources
; psf
; psf
= psf
->sf_next
) {
2111 if (ipv6_addr_equal(&psf
->sf_addr
, psfsrc
))
2115 if (!psf
|| psf
->sf_count
[sfmode
] == 0) {
2116 /* source filter not found, or count wrong => bug */
2119 psf
->sf_count
[sfmode
]--;
2120 if (!psf
->sf_count
[MCAST_INCLUDE
] && !psf
->sf_count
[MCAST_EXCLUDE
]) {
2121 struct inet6_dev
*idev
= pmc
->idev
;
2123 /* no more filters for this source */
2125 psf_prev
->sf_next
= psf
->sf_next
;
2127 pmc
->mca_sources
= psf
->sf_next
;
2128 if (psf
->sf_oldin
&& !(pmc
->mca_flags
& MAF_NOREPORT
) &&
2129 !mld_in_v1_mode(idev
)) {
2130 psf
->sf_crcount
= idev
->mc_qrv
;
2131 psf
->sf_next
= pmc
->mca_tomb
;
2132 pmc
->mca_tomb
= psf
;
2140 static int ip6_mc_del_src(struct inet6_dev
*idev
, const struct in6_addr
*pmca
,
2141 int sfmode
, int sfcount
, const struct in6_addr
*psfsrc
,
2144 struct ifmcaddr6
*pmc
;
2150 read_lock_bh(&idev
->lock
);
2151 for (pmc
= idev
->mc_list
; pmc
; pmc
= pmc
->next
) {
2152 if (ipv6_addr_equal(pmca
, &pmc
->mca_addr
))
2156 /* MCA not found?? bug */
2157 read_unlock_bh(&idev
->lock
);
2160 spin_lock_bh(&pmc
->mca_lock
);
2163 if (!pmc
->mca_sfcount
[sfmode
]) {
2164 spin_unlock_bh(&pmc
->mca_lock
);
2165 read_unlock_bh(&idev
->lock
);
2168 pmc
->mca_sfcount
[sfmode
]--;
2171 for (i
= 0; i
< sfcount
; i
++) {
2172 int rv
= ip6_mc_del1_src(pmc
, sfmode
, &psfsrc
[i
]);
2174 changerec
|= rv
> 0;
2178 if (pmc
->mca_sfmode
== MCAST_EXCLUDE
&&
2179 pmc
->mca_sfcount
[MCAST_EXCLUDE
] == 0 &&
2180 pmc
->mca_sfcount
[MCAST_INCLUDE
]) {
2181 struct ip6_sf_list
*psf
;
2183 /* filter mode change */
2184 pmc
->mca_sfmode
= MCAST_INCLUDE
;
2185 pmc
->mca_crcount
= idev
->mc_qrv
;
2186 idev
->mc_ifc_count
= pmc
->mca_crcount
;
2187 for (psf
= pmc
->mca_sources
; psf
; psf
= psf
->sf_next
)
2188 psf
->sf_crcount
= 0;
2189 mld_ifc_event(pmc
->idev
);
2190 } else if (sf_setstate(pmc
) || changerec
)
2191 mld_ifc_event(pmc
->idev
);
2192 spin_unlock_bh(&pmc
->mca_lock
);
2193 read_unlock_bh(&idev
->lock
);
2198 * Add multicast single-source filter to the interface list
2200 static int ip6_mc_add1_src(struct ifmcaddr6
*pmc
, int sfmode
,
2201 const struct in6_addr
*psfsrc
)
2203 struct ip6_sf_list
*psf
, *psf_prev
;
2206 for (psf
= pmc
->mca_sources
; psf
; psf
= psf
->sf_next
) {
2207 if (ipv6_addr_equal(&psf
->sf_addr
, psfsrc
))
2212 psf
= kzalloc(sizeof(*psf
), GFP_ATOMIC
);
2216 psf
->sf_addr
= *psfsrc
;
2218 psf_prev
->sf_next
= psf
;
2220 pmc
->mca_sources
= psf
;
2222 psf
->sf_count
[sfmode
]++;
2226 static void sf_markstate(struct ifmcaddr6
*pmc
)
2228 struct ip6_sf_list
*psf
;
2229 int mca_xcount
= pmc
->mca_sfcount
[MCAST_EXCLUDE
];
2231 for (psf
= pmc
->mca_sources
; psf
; psf
= psf
->sf_next
)
2232 if (pmc
->mca_sfcount
[MCAST_EXCLUDE
]) {
2233 psf
->sf_oldin
= mca_xcount
==
2234 psf
->sf_count
[MCAST_EXCLUDE
] &&
2235 !psf
->sf_count
[MCAST_INCLUDE
];
2237 psf
->sf_oldin
= psf
->sf_count
[MCAST_INCLUDE
] != 0;
2240 static int sf_setstate(struct ifmcaddr6
*pmc
)
2242 struct ip6_sf_list
*psf
, *dpsf
;
2243 int mca_xcount
= pmc
->mca_sfcount
[MCAST_EXCLUDE
];
2244 int qrv
= pmc
->idev
->mc_qrv
;
2248 for (psf
= pmc
->mca_sources
; psf
; psf
= psf
->sf_next
) {
2249 if (pmc
->mca_sfcount
[MCAST_EXCLUDE
]) {
2250 new_in
= mca_xcount
== psf
->sf_count
[MCAST_EXCLUDE
] &&
2251 !psf
->sf_count
[MCAST_INCLUDE
];
2253 new_in
= psf
->sf_count
[MCAST_INCLUDE
] != 0;
2255 if (!psf
->sf_oldin
) {
2256 struct ip6_sf_list
*prev
= NULL
;
2258 for (dpsf
= pmc
->mca_tomb
; dpsf
;
2259 dpsf
= dpsf
->sf_next
) {
2260 if (ipv6_addr_equal(&dpsf
->sf_addr
,
2267 prev
->sf_next
= dpsf
->sf_next
;
2269 pmc
->mca_tomb
= dpsf
->sf_next
;
2272 psf
->sf_crcount
= qrv
;
2275 } else if (psf
->sf_oldin
) {
2276 psf
->sf_crcount
= 0;
2278 * add or update "delete" records if an active filter
2281 for (dpsf
= pmc
->mca_tomb
; dpsf
; dpsf
= dpsf
->sf_next
)
2282 if (ipv6_addr_equal(&dpsf
->sf_addr
,
2286 dpsf
= kmalloc(sizeof(*dpsf
), GFP_ATOMIC
);
2290 /* pmc->mca_lock held by callers */
2291 dpsf
->sf_next
= pmc
->mca_tomb
;
2292 pmc
->mca_tomb
= dpsf
;
2294 dpsf
->sf_crcount
= qrv
;
2302 * Add multicast source filter list to the interface list
2304 static int ip6_mc_add_src(struct inet6_dev
*idev
, const struct in6_addr
*pmca
,
2305 int sfmode
, int sfcount
, const struct in6_addr
*psfsrc
,
2308 struct ifmcaddr6
*pmc
;
2314 read_lock_bh(&idev
->lock
);
2315 for (pmc
= idev
->mc_list
; pmc
; pmc
= pmc
->next
) {
2316 if (ipv6_addr_equal(pmca
, &pmc
->mca_addr
))
2320 /* MCA not found?? bug */
2321 read_unlock_bh(&idev
->lock
);
2324 spin_lock_bh(&pmc
->mca_lock
);
2327 isexclude
= pmc
->mca_sfmode
== MCAST_EXCLUDE
;
2329 pmc
->mca_sfcount
[sfmode
]++;
2331 for (i
= 0; i
< sfcount
; i
++) {
2332 err
= ip6_mc_add1_src(pmc
, sfmode
, &psfsrc
[i
]);
2340 pmc
->mca_sfcount
[sfmode
]--;
2341 for (j
= 0; j
< i
; j
++)
2342 ip6_mc_del1_src(pmc
, sfmode
, &psfsrc
[j
]);
2343 } else if (isexclude
!= (pmc
->mca_sfcount
[MCAST_EXCLUDE
] != 0)) {
2344 struct ip6_sf_list
*psf
;
2346 /* filter mode change */
2347 if (pmc
->mca_sfcount
[MCAST_EXCLUDE
])
2348 pmc
->mca_sfmode
= MCAST_EXCLUDE
;
2349 else if (pmc
->mca_sfcount
[MCAST_INCLUDE
])
2350 pmc
->mca_sfmode
= MCAST_INCLUDE
;
2351 /* else no filters; keep old mode for reports */
2353 pmc
->mca_crcount
= idev
->mc_qrv
;
2354 idev
->mc_ifc_count
= pmc
->mca_crcount
;
2355 for (psf
= pmc
->mca_sources
; psf
; psf
= psf
->sf_next
)
2356 psf
->sf_crcount
= 0;
2357 mld_ifc_event(idev
);
2358 } else if (sf_setstate(pmc
))
2359 mld_ifc_event(idev
);
2360 spin_unlock_bh(&pmc
->mca_lock
);
2361 read_unlock_bh(&idev
->lock
);
2365 static void ip6_mc_clear_src(struct ifmcaddr6
*pmc
)
2367 struct ip6_sf_list
*psf
, *nextpsf
;
2369 for (psf
= pmc
->mca_tomb
; psf
; psf
= nextpsf
) {
2370 nextpsf
= psf
->sf_next
;
2373 pmc
->mca_tomb
= NULL
;
2374 for (psf
= pmc
->mca_sources
; psf
; psf
= nextpsf
) {
2375 nextpsf
= psf
->sf_next
;
2378 pmc
->mca_sources
= NULL
;
2379 pmc
->mca_sfmode
= MCAST_EXCLUDE
;
2380 pmc
->mca_sfcount
[MCAST_INCLUDE
] = 0;
2381 pmc
->mca_sfcount
[MCAST_EXCLUDE
] = 1;
2385 static void igmp6_join_group(struct ifmcaddr6
*ma
)
2387 unsigned long delay
;
2389 if (ma
->mca_flags
& MAF_NOREPORT
)
2392 igmp6_send(&ma
->mca_addr
, ma
->idev
->dev
, ICMPV6_MGM_REPORT
);
2394 delay
= prandom_u32() % unsolicited_report_interval(ma
->idev
);
2396 spin_lock_bh(&ma
->mca_lock
);
2397 if (del_timer(&ma
->mca_timer
)) {
2398 refcount_dec(&ma
->mca_refcnt
);
2399 delay
= ma
->mca_timer
.expires
- jiffies
;
2402 if (!mod_timer(&ma
->mca_timer
, jiffies
+ delay
))
2403 refcount_inc(&ma
->mca_refcnt
);
2404 ma
->mca_flags
|= MAF_TIMER_RUNNING
| MAF_LAST_REPORTER
;
2405 spin_unlock_bh(&ma
->mca_lock
);
2408 static int ip6_mc_leave_src(struct sock
*sk
, struct ipv6_mc_socklist
*iml
,
2409 struct inet6_dev
*idev
)
2413 /* callers have the socket lock and rtnl lock
2414 * so no other readers or writers of iml or its sflist
2417 /* any-source empty exclude case */
2418 return ip6_mc_del_src(idev
, &iml
->addr
, iml
->sfmode
, 0, NULL
, 0);
2420 err
= ip6_mc_del_src(idev
, &iml
->addr
, iml
->sfmode
,
2421 iml
->sflist
->sl_count
, iml
->sflist
->sl_addr
, 0);
2422 sock_kfree_s(sk
, iml
->sflist
, IP6_SFLSIZE(iml
->sflist
->sl_max
));
2427 static void igmp6_leave_group(struct ifmcaddr6
*ma
)
2429 if (mld_in_v1_mode(ma
->idev
)) {
2430 if (ma
->mca_flags
& MAF_LAST_REPORTER
)
2431 igmp6_send(&ma
->mca_addr
, ma
->idev
->dev
,
2432 ICMPV6_MGM_REDUCTION
);
2434 mld_add_delrec(ma
->idev
, ma
);
2435 mld_ifc_event(ma
->idev
);
2439 static void mld_gq_timer_expire(struct timer_list
*t
)
2441 struct inet6_dev
*idev
= from_timer(idev
, t
, mc_gq_timer
);
2443 idev
->mc_gq_running
= 0;
2444 mld_send_report(idev
, NULL
);
2448 static void mld_ifc_timer_expire(struct timer_list
*t
)
2450 struct inet6_dev
*idev
= from_timer(idev
, t
, mc_ifc_timer
);
2453 if (idev
->mc_ifc_count
) {
2454 idev
->mc_ifc_count
--;
2455 if (idev
->mc_ifc_count
)
2456 mld_ifc_start_timer(idev
, idev
->mc_maxdelay
);
2461 static void mld_ifc_event(struct inet6_dev
*idev
)
2463 if (mld_in_v1_mode(idev
))
2465 idev
->mc_ifc_count
= idev
->mc_qrv
;
2466 mld_ifc_start_timer(idev
, 1);
2469 static void igmp6_timer_handler(struct timer_list
*t
)
2471 struct ifmcaddr6
*ma
= from_timer(ma
, t
, mca_timer
);
2473 if (mld_in_v1_mode(ma
->idev
))
2474 igmp6_send(&ma
->mca_addr
, ma
->idev
->dev
, ICMPV6_MGM_REPORT
);
2476 mld_send_report(ma
->idev
, ma
);
2478 spin_lock(&ma
->mca_lock
);
2479 ma
->mca_flags
|= MAF_LAST_REPORTER
;
2480 ma
->mca_flags
&= ~MAF_TIMER_RUNNING
;
2481 spin_unlock(&ma
->mca_lock
);
2485 /* Device changing type */
2487 void ipv6_mc_unmap(struct inet6_dev
*idev
)
2489 struct ifmcaddr6
*i
;
2491 /* Install multicast list, except for all-nodes (already installed) */
2493 read_lock_bh(&idev
->lock
);
2494 for (i
= idev
->mc_list
; i
; i
= i
->next
)
2495 igmp6_group_dropped(i
);
2496 read_unlock_bh(&idev
->lock
);
2499 void ipv6_mc_remap(struct inet6_dev
*idev
)
2504 /* Device going down */
2506 void ipv6_mc_down(struct inet6_dev
*idev
)
2508 struct ifmcaddr6
*i
;
2510 /* Withdraw multicast list */
2512 read_lock_bh(&idev
->lock
);
2514 for (i
= idev
->mc_list
; i
; i
= i
->next
)
2515 igmp6_group_dropped(i
);
2517 /* Should stop timer after group drop. or we will
2518 * start timer again in mld_ifc_event()
2520 mld_ifc_stop_timer(idev
);
2521 mld_gq_stop_timer(idev
);
2522 mld_dad_stop_timer(idev
);
2523 read_unlock_bh(&idev
->lock
);
2526 static void ipv6_mc_reset(struct inet6_dev
*idev
)
2528 idev
->mc_qrv
= sysctl_mld_qrv
;
2529 idev
->mc_qi
= MLD_QI_DEFAULT
;
2530 idev
->mc_qri
= MLD_QRI_DEFAULT
;
2531 idev
->mc_v1_seen
= 0;
2532 idev
->mc_maxdelay
= unsolicited_report_interval(idev
);
2535 /* Device going up */
2537 void ipv6_mc_up(struct inet6_dev
*idev
)
2539 struct ifmcaddr6
*i
;
2541 /* Install multicast list, except for all-nodes (already installed) */
2543 read_lock_bh(&idev
->lock
);
2544 ipv6_mc_reset(idev
);
2545 for (i
= idev
->mc_list
; i
; i
= i
->next
) {
2546 mld_del_delrec(idev
, i
);
2547 igmp6_group_added(i
);
2549 read_unlock_bh(&idev
->lock
);
2552 /* IPv6 device initialization. */
2554 void ipv6_mc_init_dev(struct inet6_dev
*idev
)
2556 write_lock_bh(&idev
->lock
);
2557 spin_lock_init(&idev
->mc_lock
);
2558 idev
->mc_gq_running
= 0;
2559 timer_setup(&idev
->mc_gq_timer
, mld_gq_timer_expire
, 0);
2560 idev
->mc_tomb
= NULL
;
2561 idev
->mc_ifc_count
= 0;
2562 timer_setup(&idev
->mc_ifc_timer
, mld_ifc_timer_expire
, 0);
2563 timer_setup(&idev
->mc_dad_timer
, mld_dad_timer_expire
, 0);
2564 ipv6_mc_reset(idev
);
2565 write_unlock_bh(&idev
->lock
);
2569 * Device is about to be destroyed: clean up.
2572 void ipv6_mc_destroy_dev(struct inet6_dev
*idev
)
2574 struct ifmcaddr6
*i
;
2576 /* Deactivate timers */
2578 mld_clear_delrec(idev
);
2580 /* Delete all-nodes address. */
2581 /* We cannot call ipv6_dev_mc_dec() directly, our caller in
2582 * addrconf.c has NULL'd out dev->ip6_ptr so in6_dev_get() will
2585 __ipv6_dev_mc_dec(idev
, &in6addr_linklocal_allnodes
);
2587 if (idev
->cnf
.forwarding
)
2588 __ipv6_dev_mc_dec(idev
, &in6addr_linklocal_allrouters
);
2590 write_lock_bh(&idev
->lock
);
2591 while ((i
= idev
->mc_list
) != NULL
) {
2592 idev
->mc_list
= i
->next
;
2594 write_unlock_bh(&idev
->lock
);
2596 write_lock_bh(&idev
->lock
);
2598 write_unlock_bh(&idev
->lock
);
2601 static void ipv6_mc_rejoin_groups(struct inet6_dev
*idev
)
2603 struct ifmcaddr6
*pmc
;
2607 if (mld_in_v1_mode(idev
)) {
2608 read_lock_bh(&idev
->lock
);
2609 for (pmc
= idev
->mc_list
; pmc
; pmc
= pmc
->next
)
2610 igmp6_join_group(pmc
);
2611 read_unlock_bh(&idev
->lock
);
2613 mld_send_report(idev
, NULL
);
2616 static int ipv6_mc_netdev_event(struct notifier_block
*this,
2617 unsigned long event
,
2620 struct net_device
*dev
= netdev_notifier_info_to_dev(ptr
);
2621 struct inet6_dev
*idev
= __in6_dev_get(dev
);
2624 case NETDEV_RESEND_IGMP
:
2626 ipv6_mc_rejoin_groups(idev
);
2635 static struct notifier_block igmp6_netdev_notifier
= {
2636 .notifier_call
= ipv6_mc_netdev_event
,
2639 #ifdef CONFIG_PROC_FS
2640 struct igmp6_mc_iter_state
{
2641 struct seq_net_private p
;
2642 struct net_device
*dev
;
2643 struct inet6_dev
*idev
;
2646 #define igmp6_mc_seq_private(seq) ((struct igmp6_mc_iter_state *)(seq)->private)
2648 static inline struct ifmcaddr6
*igmp6_mc_get_first(struct seq_file
*seq
)
2650 struct ifmcaddr6
*im
= NULL
;
2651 struct igmp6_mc_iter_state
*state
= igmp6_mc_seq_private(seq
);
2652 struct net
*net
= seq_file_net(seq
);
2655 for_each_netdev_rcu(net
, state
->dev
) {
2656 struct inet6_dev
*idev
;
2657 idev
= __in6_dev_get(state
->dev
);
2660 read_lock_bh(&idev
->lock
);
2666 read_unlock_bh(&idev
->lock
);
2671 static struct ifmcaddr6
*igmp6_mc_get_next(struct seq_file
*seq
, struct ifmcaddr6
*im
)
2673 struct igmp6_mc_iter_state
*state
= igmp6_mc_seq_private(seq
);
2677 if (likely(state
->idev
))
2678 read_unlock_bh(&state
->idev
->lock
);
2680 state
->dev
= next_net_device_rcu(state
->dev
);
2685 state
->idev
= __in6_dev_get(state
->dev
);
2688 read_lock_bh(&state
->idev
->lock
);
2689 im
= state
->idev
->mc_list
;
2694 static struct ifmcaddr6
*igmp6_mc_get_idx(struct seq_file
*seq
, loff_t pos
)
2696 struct ifmcaddr6
*im
= igmp6_mc_get_first(seq
);
2698 while (pos
&& (im
= igmp6_mc_get_next(seq
, im
)) != NULL
)
2700 return pos
? NULL
: im
;
2703 static void *igmp6_mc_seq_start(struct seq_file
*seq
, loff_t
*pos
)
2707 return igmp6_mc_get_idx(seq
, *pos
);
2710 static void *igmp6_mc_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
2712 struct ifmcaddr6
*im
= igmp6_mc_get_next(seq
, v
);
2718 static void igmp6_mc_seq_stop(struct seq_file
*seq
, void *v
)
2721 struct igmp6_mc_iter_state
*state
= igmp6_mc_seq_private(seq
);
2723 if (likely(state
->idev
)) {
2724 read_unlock_bh(&state
->idev
->lock
);
2731 static int igmp6_mc_seq_show(struct seq_file
*seq
, void *v
)
2733 struct ifmcaddr6
*im
= (struct ifmcaddr6
*)v
;
2734 struct igmp6_mc_iter_state
*state
= igmp6_mc_seq_private(seq
);
2737 "%-4d %-15s %pi6 %5d %08X %ld\n",
2738 state
->dev
->ifindex
, state
->dev
->name
,
2740 im
->mca_users
, im
->mca_flags
,
2741 (im
->mca_flags
&MAF_TIMER_RUNNING
) ?
2742 jiffies_to_clock_t(im
->mca_timer
.expires
-jiffies
) : 0);
2746 static const struct seq_operations igmp6_mc_seq_ops
= {
2747 .start
= igmp6_mc_seq_start
,
2748 .next
= igmp6_mc_seq_next
,
2749 .stop
= igmp6_mc_seq_stop
,
2750 .show
= igmp6_mc_seq_show
,
2753 static int igmp6_mc_seq_open(struct inode
*inode
, struct file
*file
)
2755 return seq_open_net(inode
, file
, &igmp6_mc_seq_ops
,
2756 sizeof(struct igmp6_mc_iter_state
));
2759 static const struct file_operations igmp6_mc_seq_fops
= {
2760 .owner
= THIS_MODULE
,
2761 .open
= igmp6_mc_seq_open
,
2763 .llseek
= seq_lseek
,
2764 .release
= seq_release_net
,
2767 struct igmp6_mcf_iter_state
{
2768 struct seq_net_private p
;
2769 struct net_device
*dev
;
2770 struct inet6_dev
*idev
;
2771 struct ifmcaddr6
*im
;
2774 #define igmp6_mcf_seq_private(seq) ((struct igmp6_mcf_iter_state *)(seq)->private)
2776 static inline struct ip6_sf_list
*igmp6_mcf_get_first(struct seq_file
*seq
)
2778 struct ip6_sf_list
*psf
= NULL
;
2779 struct ifmcaddr6
*im
= NULL
;
2780 struct igmp6_mcf_iter_state
*state
= igmp6_mcf_seq_private(seq
);
2781 struct net
*net
= seq_file_net(seq
);
2785 for_each_netdev_rcu(net
, state
->dev
) {
2786 struct inet6_dev
*idev
;
2787 idev
= __in6_dev_get(state
->dev
);
2788 if (unlikely(idev
== NULL
))
2790 read_lock_bh(&idev
->lock
);
2793 spin_lock_bh(&im
->mca_lock
);
2794 psf
= im
->mca_sources
;
2800 spin_unlock_bh(&im
->mca_lock
);
2802 read_unlock_bh(&idev
->lock
);
2807 static struct ip6_sf_list
*igmp6_mcf_get_next(struct seq_file
*seq
, struct ip6_sf_list
*psf
)
2809 struct igmp6_mcf_iter_state
*state
= igmp6_mcf_seq_private(seq
);
2813 spin_unlock_bh(&state
->im
->mca_lock
);
2814 state
->im
= state
->im
->next
;
2815 while (!state
->im
) {
2816 if (likely(state
->idev
))
2817 read_unlock_bh(&state
->idev
->lock
);
2819 state
->dev
= next_net_device_rcu(state
->dev
);
2824 state
->idev
= __in6_dev_get(state
->dev
);
2827 read_lock_bh(&state
->idev
->lock
);
2828 state
->im
= state
->idev
->mc_list
;
2832 spin_lock_bh(&state
->im
->mca_lock
);
2833 psf
= state
->im
->mca_sources
;
2839 static struct ip6_sf_list
*igmp6_mcf_get_idx(struct seq_file
*seq
, loff_t pos
)
2841 struct ip6_sf_list
*psf
= igmp6_mcf_get_first(seq
);
2843 while (pos
&& (psf
= igmp6_mcf_get_next(seq
, psf
)) != NULL
)
2845 return pos
? NULL
: psf
;
2848 static void *igmp6_mcf_seq_start(struct seq_file
*seq
, loff_t
*pos
)
2852 return *pos
? igmp6_mcf_get_idx(seq
, *pos
- 1) : SEQ_START_TOKEN
;
2855 static void *igmp6_mcf_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
2857 struct ip6_sf_list
*psf
;
2858 if (v
== SEQ_START_TOKEN
)
2859 psf
= igmp6_mcf_get_first(seq
);
2861 psf
= igmp6_mcf_get_next(seq
, v
);
2866 static void igmp6_mcf_seq_stop(struct seq_file
*seq
, void *v
)
2869 struct igmp6_mcf_iter_state
*state
= igmp6_mcf_seq_private(seq
);
2870 if (likely(state
->im
)) {
2871 spin_unlock_bh(&state
->im
->mca_lock
);
2874 if (likely(state
->idev
)) {
2875 read_unlock_bh(&state
->idev
->lock
);
2882 static int igmp6_mcf_seq_show(struct seq_file
*seq
, void *v
)
2884 struct ip6_sf_list
*psf
= (struct ip6_sf_list
*)v
;
2885 struct igmp6_mcf_iter_state
*state
= igmp6_mcf_seq_private(seq
);
2887 if (v
== SEQ_START_TOKEN
) {
2888 seq_puts(seq
, "Idx Device Multicast Address Source Address INC EXC\n");
2891 "%3d %6.6s %pi6 %pi6 %6lu %6lu\n",
2892 state
->dev
->ifindex
, state
->dev
->name
,
2893 &state
->im
->mca_addr
,
2895 psf
->sf_count
[MCAST_INCLUDE
],
2896 psf
->sf_count
[MCAST_EXCLUDE
]);
2901 static const struct seq_operations igmp6_mcf_seq_ops
= {
2902 .start
= igmp6_mcf_seq_start
,
2903 .next
= igmp6_mcf_seq_next
,
2904 .stop
= igmp6_mcf_seq_stop
,
2905 .show
= igmp6_mcf_seq_show
,
2908 static int igmp6_mcf_seq_open(struct inode
*inode
, struct file
*file
)
2910 return seq_open_net(inode
, file
, &igmp6_mcf_seq_ops
,
2911 sizeof(struct igmp6_mcf_iter_state
));
2914 static const struct file_operations igmp6_mcf_seq_fops
= {
2915 .owner
= THIS_MODULE
,
2916 .open
= igmp6_mcf_seq_open
,
2918 .llseek
= seq_lseek
,
2919 .release
= seq_release_net
,
2922 static int __net_init
igmp6_proc_init(struct net
*net
)
2927 if (!proc_create("igmp6", S_IRUGO
, net
->proc_net
, &igmp6_mc_seq_fops
))
2929 if (!proc_create("mcfilter6", S_IRUGO
, net
->proc_net
,
2930 &igmp6_mcf_seq_fops
))
2931 goto out_proc_net_igmp6
;
2938 remove_proc_entry("igmp6", net
->proc_net
);
2942 static void __net_exit
igmp6_proc_exit(struct net
*net
)
2944 remove_proc_entry("mcfilter6", net
->proc_net
);
2945 remove_proc_entry("igmp6", net
->proc_net
);
2948 static inline int igmp6_proc_init(struct net
*net
)
2952 static inline void igmp6_proc_exit(struct net
*net
)
2957 static int __net_init
igmp6_net_init(struct net
*net
)
2961 err
= inet_ctl_sock_create(&net
->ipv6
.igmp_sk
, PF_INET6
,
2962 SOCK_RAW
, IPPROTO_ICMPV6
, net
);
2964 pr_err("Failed to initialize the IGMP6 control socket (err %d)\n",
2969 inet6_sk(net
->ipv6
.igmp_sk
)->hop_limit
= 1;
2971 err
= inet_ctl_sock_create(&net
->ipv6
.mc_autojoin_sk
, PF_INET6
,
2972 SOCK_RAW
, IPPROTO_ICMPV6
, net
);
2974 pr_err("Failed to initialize the IGMP6 autojoin socket (err %d)\n",
2976 goto out_sock_create
;
2979 err
= igmp6_proc_init(net
);
2981 goto out_sock_create_autojoin
;
2985 out_sock_create_autojoin
:
2986 inet_ctl_sock_destroy(net
->ipv6
.mc_autojoin_sk
);
2988 inet_ctl_sock_destroy(net
->ipv6
.igmp_sk
);
2993 static void __net_exit
igmp6_net_exit(struct net
*net
)
2995 inet_ctl_sock_destroy(net
->ipv6
.igmp_sk
);
2996 inet_ctl_sock_destroy(net
->ipv6
.mc_autojoin_sk
);
2997 igmp6_proc_exit(net
);
3000 static struct pernet_operations igmp6_net_ops
= {
3001 .init
= igmp6_net_init
,
3002 .exit
= igmp6_net_exit
,
3005 int __init
igmp6_init(void)
3007 return register_pernet_subsys(&igmp6_net_ops
);
3010 int __init
igmp6_late_init(void)
3012 return register_netdevice_notifier(&igmp6_netdev_notifier
);
3015 void igmp6_cleanup(void)
3017 unregister_pernet_subsys(&igmp6_net_ops
);
3020 void igmp6_late_cleanup(void)
3022 unregister_netdevice_notifier(&igmp6_netdev_notifier
);