]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Multicast support for IPv6 | |
1ab1457c | 3 | * Linux INET6 implementation |
1da177e4 LT |
4 | * |
5 | * Authors: | |
1ab1457c | 6 | * Pedro Roque <roque@di.fc.ul.pt> |
1da177e4 | 7 | * |
1ab1457c | 8 | * Based on linux/ipv4/igmp.c and linux/ipv4/ip_sockglue.c |
1da177e4 LT |
9 | * |
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. | |
14 | */ | |
15 | ||
16 | /* Changes: | |
17 | * | |
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>: | |
26 | * - MLDv2 support | |
27 | */ | |
28 | ||
1da177e4 LT |
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> | |
38 | #include <linux/in.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> | |
5a0e3ad6 | 46 | #include <linux/slab.h> |
9d4a0314 | 47 | #include <linux/pkt_sched.h> |
6e7cb837 | 48 | #include <net/mld.h> |
1da177e4 LT |
49 | |
50 | #include <linux/netfilter.h> | |
51 | #include <linux/netfilter_ipv6.h> | |
52 | ||
457c4cbc | 53 | #include <net/net_namespace.h> |
1da177e4 LT |
54 | #include <net/sock.h> |
55 | #include <net/snmp.h> | |
56 | ||
57 | #include <net/ipv6.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> | |
1ed8516f | 63 | #include <net/inet_common.h> |
1da177e4 LT |
64 | |
65 | #include <net/ip6_checksum.h> | |
66 | ||
67 | /* Set to 3 to get tracing... */ | |
68 | #define MCAST_DEBUG 2 | |
69 | ||
70 | #if MCAST_DEBUG >= 3 | |
71 | #define MDBG(x) printk x | |
72 | #else | |
73 | #define MDBG(x) | |
74 | #endif | |
75 | ||
6e7cb837 YH |
76 | /* Ensure that we have struct in6_addr aligned on 32bit word. */ |
77 | static void *__mld2_query_bugs[] __attribute__((__unused__)) = { | |
78 | BUILD_BUG_ON_NULL(offsetof(struct mld2_query, mld2q_srcs) % 4), | |
79 | BUILD_BUG_ON_NULL(offsetof(struct mld2_report, mld2r_grec) % 4), | |
80 | BUILD_BUG_ON_NULL(offsetof(struct mld2_grec, grec_mca) % 4) | |
1da177e4 LT |
81 | }; |
82 | ||
83 | static struct in6_addr mld2_all_mcr = MLD2_ALL_MCR_INIT; | |
84 | ||
85 | /* Big mc list lock for all the sockets */ | |
456b61bc | 86 | static DEFINE_SPINLOCK(ipv6_sk_mc_lock); |
1da177e4 | 87 | |
1da177e4 LT |
88 | static void igmp6_join_group(struct ifmcaddr6 *ma); |
89 | static void igmp6_leave_group(struct ifmcaddr6 *ma); | |
90 | static void igmp6_timer_handler(unsigned long data); | |
91 | ||
92 | static void mld_gq_timer_expire(unsigned long data); | |
93 | static void mld_ifc_timer_expire(unsigned long data); | |
94 | static void mld_ifc_event(struct inet6_dev *idev); | |
95 | static void mld_add_delrec(struct inet6_dev *idev, struct ifmcaddr6 *pmc); | |
b71d1d42 | 96 | static void mld_del_delrec(struct inet6_dev *idev, const struct in6_addr *addr); |
1da177e4 | 97 | static void mld_clear_delrec(struct inet6_dev *idev); |
6c567b78 | 98 | static bool mld_in_v1_mode(const struct inet6_dev *idev); |
1da177e4 LT |
99 | static int sf_setstate(struct ifmcaddr6 *pmc); |
100 | static void sf_markstate(struct ifmcaddr6 *pmc); | |
101 | static void ip6_mc_clear_src(struct ifmcaddr6 *pmc); | |
b71d1d42 ED |
102 | static int ip6_mc_del_src(struct inet6_dev *idev, const struct in6_addr *pmca, |
103 | int sfmode, int sfcount, const struct in6_addr *psfsrc, | |
1da177e4 | 104 | int delta); |
b71d1d42 ED |
105 | static int ip6_mc_add_src(struct inet6_dev *idev, const struct in6_addr *pmca, |
106 | int sfmode, int sfcount, const struct in6_addr *psfsrc, | |
1da177e4 LT |
107 | int delta); |
108 | static int ip6_mc_leave_src(struct sock *sk, struct ipv6_mc_socklist *iml, | |
109 | struct inet6_dev *idev); | |
110 | ||
1da177e4 | 111 | #define MLD_QRV_DEFAULT 2 |
89225d1c DB |
112 | /* RFC3810, 9.2. Query Interval */ |
113 | #define MLD_QI_DEFAULT (125 * HZ) | |
114 | /* RFC3810, 9.3. Query Response Interval */ | |
115 | #define MLD_QRI_DEFAULT (10 * HZ) | |
1da177e4 | 116 | |
9fd07841 DB |
117 | /* RFC3810, 8.1 Query Version Distinctions */ |
118 | #define MLD_V1_QUERY_LEN 24 | |
119 | #define MLD_V2_QUERY_LEN_MIN 28 | |
120 | ||
6f4353d8 | 121 | #define IPV6_MLD_MAX_MSF 64 |
1da177e4 | 122 | |
ab32ea5d | 123 | int sysctl_mld_max_msf __read_mostly = IPV6_MLD_MAX_MSF; |
1da177e4 LT |
124 | |
125 | /* | |
126 | * socket join on multicast group | |
127 | */ | |
128 | ||
456b61bc ED |
129 | #define for_each_pmc_rcu(np, pmc) \ |
130 | for (pmc = rcu_dereference(np->ipv6_mc_list); \ | |
131 | pmc != NULL; \ | |
132 | pmc = rcu_dereference(pmc->next)) | |
133 | ||
fc4eba58 HFS |
134 | static int unsolicited_report_interval(struct inet6_dev *idev) |
135 | { | |
136 | int iv; | |
137 | ||
6c567b78 | 138 | if (mld_in_v1_mode(idev)) |
fc4eba58 HFS |
139 | iv = idev->cnf.mldv1_unsolicited_report_interval; |
140 | else | |
141 | iv = idev->cnf.mldv2_unsolicited_report_interval; | |
142 | ||
143 | return iv > 0 ? iv : 1; | |
144 | } | |
145 | ||
9acd9f3a | 146 | int ipv6_sock_mc_join(struct sock *sk, int ifindex, const struct in6_addr *addr) |
1da177e4 LT |
147 | { |
148 | struct net_device *dev = NULL; | |
149 | struct ipv6_mc_socklist *mc_lst; | |
150 | struct ipv6_pinfo *np = inet6_sk(sk); | |
3b1e0a65 | 151 | struct net *net = sock_net(sk); |
1da177e4 LT |
152 | int err; |
153 | ||
154 | if (!ipv6_addr_is_multicast(addr)) | |
155 | return -EINVAL; | |
156 | ||
456b61bc ED |
157 | rcu_read_lock(); |
158 | for_each_pmc_rcu(np, mc_lst) { | |
c9e3e8b6 DS |
159 | if ((ifindex == 0 || mc_lst->ifindex == ifindex) && |
160 | ipv6_addr_equal(&mc_lst->addr, addr)) { | |
456b61bc | 161 | rcu_read_unlock(); |
c9e3e8b6 DS |
162 | return -EADDRINUSE; |
163 | } | |
164 | } | |
456b61bc | 165 | rcu_read_unlock(); |
c9e3e8b6 | 166 | |
1da177e4 LT |
167 | mc_lst = sock_kmalloc(sk, sizeof(struct ipv6_mc_socklist), GFP_KERNEL); |
168 | ||
169 | if (mc_lst == NULL) | |
170 | return -ENOMEM; | |
171 | ||
172 | mc_lst->next = NULL; | |
4e3fd7a0 | 173 | mc_lst->addr = *addr; |
1da177e4 | 174 | |
96b52e61 | 175 | rcu_read_lock(); |
1da177e4 LT |
176 | if (ifindex == 0) { |
177 | struct rt6_info *rt; | |
b8ad0cbc | 178 | rt = rt6_lookup(net, addr, NULL, 0, 0); |
1da177e4 | 179 | if (rt) { |
d1918542 | 180 | dev = rt->dst.dev; |
94e187c0 | 181 | ip6_rt_put(rt); |
1da177e4 LT |
182 | } |
183 | } else | |
96b52e61 | 184 | dev = dev_get_by_index_rcu(net, ifindex); |
1da177e4 LT |
185 | |
186 | if (dev == NULL) { | |
96b52e61 | 187 | rcu_read_unlock(); |
1da177e4 LT |
188 | sock_kfree_s(sk, mc_lst, sizeof(*mc_lst)); |
189 | return -ENODEV; | |
190 | } | |
191 | ||
192 | mc_lst->ifindex = dev->ifindex; | |
193 | mc_lst->sfmode = MCAST_EXCLUDE; | |
196433c5 | 194 | rwlock_init(&mc_lst->sflock); |
1da177e4 LT |
195 | mc_lst->sflist = NULL; |
196 | ||
197 | /* | |
198 | * now add/increase the group membership on the device | |
199 | */ | |
200 | ||
201 | err = ipv6_dev_mc_inc(dev, addr); | |
202 | ||
203 | if (err) { | |
96b52e61 | 204 | rcu_read_unlock(); |
1da177e4 | 205 | sock_kfree_s(sk, mc_lst, sizeof(*mc_lst)); |
1da177e4 LT |
206 | return err; |
207 | } | |
208 | ||
456b61bc | 209 | spin_lock(&ipv6_sk_mc_lock); |
1da177e4 | 210 | mc_lst->next = np->ipv6_mc_list; |
456b61bc ED |
211 | rcu_assign_pointer(np->ipv6_mc_list, mc_lst); |
212 | spin_unlock(&ipv6_sk_mc_lock); | |
1da177e4 | 213 | |
96b52e61 | 214 | rcu_read_unlock(); |
1da177e4 LT |
215 | |
216 | return 0; | |
217 | } | |
218 | ||
219 | /* | |
220 | * socket leave on multicast group | |
221 | */ | |
9acd9f3a | 222 | int ipv6_sock_mc_drop(struct sock *sk, int ifindex, const struct in6_addr *addr) |
1da177e4 LT |
223 | { |
224 | struct ipv6_pinfo *np = inet6_sk(sk); | |
456b61bc ED |
225 | struct ipv6_mc_socklist *mc_lst; |
226 | struct ipv6_mc_socklist __rcu **lnk; | |
3b1e0a65 | 227 | struct net *net = sock_net(sk); |
1da177e4 | 228 | |
a858d64b LW |
229 | if (!ipv6_addr_is_multicast(addr)) |
230 | return -EINVAL; | |
231 | ||
456b61bc ED |
232 | spin_lock(&ipv6_sk_mc_lock); |
233 | for (lnk = &np->ipv6_mc_list; | |
234 | (mc_lst = rcu_dereference_protected(*lnk, | |
235 | lockdep_is_held(&ipv6_sk_mc_lock))) !=NULL ; | |
236 | lnk = &mc_lst->next) { | |
1da177e4 LT |
237 | if ((ifindex == 0 || mc_lst->ifindex == ifindex) && |
238 | ipv6_addr_equal(&mc_lst->addr, addr)) { | |
239 | struct net_device *dev; | |
240 | ||
241 | *lnk = mc_lst->next; | |
456b61bc | 242 | spin_unlock(&ipv6_sk_mc_lock); |
1da177e4 | 243 | |
96b52e61 ED |
244 | rcu_read_lock(); |
245 | dev = dev_get_by_index_rcu(net, mc_lst->ifindex); | |
b8ad0cbc | 246 | if (dev != NULL) { |
96b52e61 | 247 | struct inet6_dev *idev = __in6_dev_get(dev); |
1da177e4 | 248 | |
acd6e00b | 249 | (void) ip6_mc_leave_src(sk, mc_lst, idev); |
96b52e61 | 250 | if (idev) |
1da177e4 | 251 | __ipv6_dev_mc_dec(idev, &mc_lst->addr); |
acd6e00b DS |
252 | } else |
253 | (void) ip6_mc_leave_src(sk, mc_lst, NULL); | |
96b52e61 | 254 | rcu_read_unlock(); |
456b61bc | 255 | atomic_sub(sizeof(*mc_lst), &sk->sk_omem_alloc); |
e3cbf28f | 256 | kfree_rcu(mc_lst, rcu); |
1da177e4 LT |
257 | return 0; |
258 | } | |
259 | } | |
456b61bc | 260 | spin_unlock(&ipv6_sk_mc_lock); |
1da177e4 | 261 | |
9951f036 | 262 | return -EADDRNOTAVAIL; |
1da177e4 LT |
263 | } |
264 | ||
96b52e61 ED |
265 | /* called with rcu_read_lock() */ |
266 | static struct inet6_dev *ip6_mc_find_dev_rcu(struct net *net, | |
b71d1d42 | 267 | const struct in6_addr *group, |
96b52e61 | 268 | int ifindex) |
1da177e4 LT |
269 | { |
270 | struct net_device *dev = NULL; | |
271 | struct inet6_dev *idev = NULL; | |
272 | ||
273 | if (ifindex == 0) { | |
96b52e61 | 274 | struct rt6_info *rt = rt6_lookup(net, group, NULL, 0, 0); |
1da177e4 | 275 | |
1da177e4 | 276 | if (rt) { |
d1918542 | 277 | dev = rt->dst.dev; |
94e187c0 | 278 | ip6_rt_put(rt); |
1da177e4 LT |
279 | } |
280 | } else | |
96b52e61 | 281 | dev = dev_get_by_index_rcu(net, ifindex); |
1da177e4 LT |
282 | |
283 | if (!dev) | |
96b52e61 ED |
284 | return NULL; |
285 | idev = __in6_dev_get(dev); | |
448eb71f | 286 | if (!idev) |
8a22c99a | 287 | return NULL; |
1da177e4 | 288 | read_lock_bh(&idev->lock); |
96b52e61 ED |
289 | if (idev->dead) { |
290 | read_unlock_bh(&idev->lock); | |
291 | return NULL; | |
292 | } | |
1da177e4 LT |
293 | return idev; |
294 | } | |
295 | ||
296 | void ipv6_sock_mc_close(struct sock *sk) | |
297 | { | |
298 | struct ipv6_pinfo *np = inet6_sk(sk); | |
299 | struct ipv6_mc_socklist *mc_lst; | |
3b1e0a65 | 300 | struct net *net = sock_net(sk); |
1da177e4 | 301 | |
0e1efe9d ED |
302 | if (!rcu_access_pointer(np->ipv6_mc_list)) |
303 | return; | |
304 | ||
456b61bc ED |
305 | spin_lock(&ipv6_sk_mc_lock); |
306 | while ((mc_lst = rcu_dereference_protected(np->ipv6_mc_list, | |
307 | lockdep_is_held(&ipv6_sk_mc_lock))) != NULL) { | |
1da177e4 LT |
308 | struct net_device *dev; |
309 | ||
310 | np->ipv6_mc_list = mc_lst->next; | |
456b61bc | 311 | spin_unlock(&ipv6_sk_mc_lock); |
1da177e4 | 312 | |
96b52e61 ED |
313 | rcu_read_lock(); |
314 | dev = dev_get_by_index_rcu(net, mc_lst->ifindex); | |
1da177e4 | 315 | if (dev) { |
96b52e61 | 316 | struct inet6_dev *idev = __in6_dev_get(dev); |
1da177e4 | 317 | |
acd6e00b | 318 | (void) ip6_mc_leave_src(sk, mc_lst, idev); |
96b52e61 | 319 | if (idev) |
1da177e4 | 320 | __ipv6_dev_mc_dec(idev, &mc_lst->addr); |
acd6e00b DS |
321 | } else |
322 | (void) ip6_mc_leave_src(sk, mc_lst, NULL); | |
96b52e61 | 323 | rcu_read_unlock(); |
1da177e4 | 324 | |
456b61bc | 325 | atomic_sub(sizeof(*mc_lst), &sk->sk_omem_alloc); |
e3cbf28f | 326 | kfree_rcu(mc_lst, rcu); |
456b61bc ED |
327 | |
328 | spin_lock(&ipv6_sk_mc_lock); | |
1da177e4 | 329 | } |
456b61bc | 330 | spin_unlock(&ipv6_sk_mc_lock); |
1da177e4 LT |
331 | } |
332 | ||
333 | int ip6_mc_source(int add, int omode, struct sock *sk, | |
334 | struct group_source_req *pgsr) | |
335 | { | |
336 | struct in6_addr *source, *group; | |
337 | struct ipv6_mc_socklist *pmc; | |
1da177e4 LT |
338 | struct inet6_dev *idev; |
339 | struct ipv6_pinfo *inet6 = inet6_sk(sk); | |
340 | struct ip6_sf_socklist *psl; | |
3b1e0a65 | 341 | struct net *net = sock_net(sk); |
1da177e4 | 342 | int i, j, rv; |
c9e3e8b6 | 343 | int leavegroup = 0; |
5ab4a6c8 | 344 | int pmclocked = 0; |
1da177e4 LT |
345 | int err; |
346 | ||
1da177e4 LT |
347 | source = &((struct sockaddr_in6 *)&pgsr->gsr_source)->sin6_addr; |
348 | group = &((struct sockaddr_in6 *)&pgsr->gsr_group)->sin6_addr; | |
349 | ||
350 | if (!ipv6_addr_is_multicast(group)) | |
351 | return -EINVAL; | |
352 | ||
96b52e61 ED |
353 | rcu_read_lock(); |
354 | idev = ip6_mc_find_dev_rcu(net, group, pgsr->gsr_interface); | |
355 | if (!idev) { | |
356 | rcu_read_unlock(); | |
1da177e4 | 357 | return -ENODEV; |
96b52e61 | 358 | } |
1da177e4 LT |
359 | |
360 | err = -EADDRNOTAVAIL; | |
361 | ||
456b61bc | 362 | for_each_pmc_rcu(inet6, pmc) { |
1da177e4 LT |
363 | if (pgsr->gsr_interface && pmc->ifindex != pgsr->gsr_interface) |
364 | continue; | |
365 | if (ipv6_addr_equal(&pmc->addr, group)) | |
366 | break; | |
367 | } | |
917f2f10 DS |
368 | if (!pmc) { /* must have a prior join */ |
369 | err = -EINVAL; | |
1da177e4 | 370 | goto done; |
917f2f10 | 371 | } |
1da177e4 LT |
372 | /* if a source filter was set, must be the same mode as before */ |
373 | if (pmc->sflist) { | |
917f2f10 DS |
374 | if (pmc->sfmode != omode) { |
375 | err = -EINVAL; | |
1da177e4 | 376 | goto done; |
917f2f10 | 377 | } |
1da177e4 LT |
378 | } else if (pmc->sfmode != omode) { |
379 | /* allow mode switches for empty-set filters */ | |
380 | ip6_mc_add_src(idev, group, omode, 0, NULL, 0); | |
381 | ip6_mc_del_src(idev, group, pmc->sfmode, 0, NULL, 0); | |
382 | pmc->sfmode = omode; | |
383 | } | |
384 | ||
96b52e61 | 385 | write_lock(&pmc->sflock); |
5ab4a6c8 DS |
386 | pmclocked = 1; |
387 | ||
1da177e4 LT |
388 | psl = pmc->sflist; |
389 | if (!add) { | |
390 | if (!psl) | |
917f2f10 | 391 | goto done; /* err = -EADDRNOTAVAIL */ |
1da177e4 LT |
392 | rv = !0; |
393 | for (i=0; i<psl->sl_count; i++) { | |
07c2fecc | 394 | rv = !ipv6_addr_equal(&psl->sl_addr[i], source); |
1da177e4 LT |
395 | if (rv == 0) |
396 | break; | |
397 | } | |
398 | if (rv) /* source not found */ | |
917f2f10 | 399 | goto done; /* err = -EADDRNOTAVAIL */ |
1da177e4 | 400 | |
c9e3e8b6 DS |
401 | /* special case - (INCLUDE, empty) == LEAVE_GROUP */ |
402 | if (psl->sl_count == 1 && omode == MCAST_INCLUDE) { | |
403 | leavegroup = 1; | |
404 | goto done; | |
405 | } | |
406 | ||
1da177e4 LT |
407 | /* update the interface filter */ |
408 | ip6_mc_del_src(idev, group, omode, 1, source, 1); | |
409 | ||
410 | for (j=i+1; j<psl->sl_count; j++) | |
411 | psl->sl_addr[j-1] = psl->sl_addr[j]; | |
412 | psl->sl_count--; | |
413 | err = 0; | |
414 | goto done; | |
415 | } | |
416 | /* else, add a new source to the filter */ | |
417 | ||
418 | if (psl && psl->sl_count >= sysctl_mld_max_msf) { | |
419 | err = -ENOBUFS; | |
420 | goto done; | |
421 | } | |
422 | if (!psl || psl->sl_count == psl->sl_max) { | |
423 | struct ip6_sf_socklist *newpsl; | |
424 | int count = IP6_SFBLOCK; | |
425 | ||
426 | if (psl) | |
427 | count += psl->sl_max; | |
8b3a7005 | 428 | newpsl = sock_kmalloc(sk, IP6_SFLSIZE(count), GFP_ATOMIC); |
1da177e4 LT |
429 | if (!newpsl) { |
430 | err = -ENOBUFS; | |
431 | goto done; | |
432 | } | |
433 | newpsl->sl_max = count; | |
434 | newpsl->sl_count = count - IP6_SFBLOCK; | |
435 | if (psl) { | |
436 | for (i=0; i<psl->sl_count; i++) | |
437 | newpsl->sl_addr[i] = psl->sl_addr[i]; | |
438 | sock_kfree_s(sk, psl, IP6_SFLSIZE(psl->sl_max)); | |
439 | } | |
440 | pmc->sflist = psl = newpsl; | |
441 | } | |
442 | rv = 1; /* > 0 for insert logic below if sl_count is 0 */ | |
443 | for (i=0; i<psl->sl_count; i++) { | |
07c2fecc | 444 | rv = !ipv6_addr_equal(&psl->sl_addr[i], source); |
56db1c5f JS |
445 | if (rv == 0) /* There is an error in the address. */ |
446 | goto done; | |
1da177e4 | 447 | } |
1da177e4 LT |
448 | for (j=psl->sl_count-1; j>=i; j--) |
449 | psl->sl_addr[j+1] = psl->sl_addr[j]; | |
450 | psl->sl_addr[i] = *source; | |
451 | psl->sl_count++; | |
452 | err = 0; | |
453 | /* update the interface list */ | |
454 | ip6_mc_add_src(idev, group, omode, 1, source, 1); | |
455 | done: | |
5ab4a6c8 | 456 | if (pmclocked) |
96b52e61 | 457 | write_unlock(&pmc->sflock); |
1da177e4 | 458 | read_unlock_bh(&idev->lock); |
96b52e61 | 459 | rcu_read_unlock(); |
c9e3e8b6 DS |
460 | if (leavegroup) |
461 | return ipv6_sock_mc_drop(sk, pgsr->gsr_interface, group); | |
1da177e4 LT |
462 | return err; |
463 | } | |
464 | ||
465 | int ip6_mc_msfilter(struct sock *sk, struct group_filter *gsf) | |
466 | { | |
b71d1d42 | 467 | const struct in6_addr *group; |
1da177e4 | 468 | struct ipv6_mc_socklist *pmc; |
1da177e4 LT |
469 | struct inet6_dev *idev; |
470 | struct ipv6_pinfo *inet6 = inet6_sk(sk); | |
471 | struct ip6_sf_socklist *newpsl, *psl; | |
3b1e0a65 | 472 | struct net *net = sock_net(sk); |
9951f036 | 473 | int leavegroup = 0; |
1da177e4 LT |
474 | int i, err; |
475 | ||
476 | group = &((struct sockaddr_in6 *)&gsf->gf_group)->sin6_addr; | |
477 | ||
478 | if (!ipv6_addr_is_multicast(group)) | |
479 | return -EINVAL; | |
480 | if (gsf->gf_fmode != MCAST_INCLUDE && | |
481 | gsf->gf_fmode != MCAST_EXCLUDE) | |
482 | return -EINVAL; | |
483 | ||
96b52e61 ED |
484 | rcu_read_lock(); |
485 | idev = ip6_mc_find_dev_rcu(net, group, gsf->gf_interface); | |
1da177e4 | 486 | |
96b52e61 ED |
487 | if (!idev) { |
488 | rcu_read_unlock(); | |
1da177e4 | 489 | return -ENODEV; |
96b52e61 | 490 | } |
1da177e4 | 491 | |
9c05989b | 492 | err = 0; |
5ab4a6c8 | 493 | |
9951f036 DS |
494 | if (gsf->gf_fmode == MCAST_INCLUDE && gsf->gf_numsrc == 0) { |
495 | leavegroup = 1; | |
496 | goto done; | |
497 | } | |
498 | ||
456b61bc | 499 | for_each_pmc_rcu(inet6, pmc) { |
1da177e4 LT |
500 | if (pmc->ifindex != gsf->gf_interface) |
501 | continue; | |
502 | if (ipv6_addr_equal(&pmc->addr, group)) | |
503 | break; | |
504 | } | |
917f2f10 DS |
505 | if (!pmc) { /* must have a prior join */ |
506 | err = -EINVAL; | |
1da177e4 | 507 | goto done; |
917f2f10 | 508 | } |
1da177e4 | 509 | if (gsf->gf_numsrc) { |
8b3a7005 KK |
510 | newpsl = sock_kmalloc(sk, IP6_SFLSIZE(gsf->gf_numsrc), |
511 | GFP_ATOMIC); | |
1da177e4 LT |
512 | if (!newpsl) { |
513 | err = -ENOBUFS; | |
514 | goto done; | |
515 | } | |
516 | newpsl->sl_max = newpsl->sl_count = gsf->gf_numsrc; | |
517 | for (i=0; i<newpsl->sl_count; ++i) { | |
518 | struct sockaddr_in6 *psin6; | |
519 | ||
520 | psin6 = (struct sockaddr_in6 *)&gsf->gf_slist[i]; | |
521 | newpsl->sl_addr[i] = psin6->sin6_addr; | |
522 | } | |
523 | err = ip6_mc_add_src(idev, group, gsf->gf_fmode, | |
524 | newpsl->sl_count, newpsl->sl_addr, 0); | |
525 | if (err) { | |
526 | sock_kfree_s(sk, newpsl, IP6_SFLSIZE(newpsl->sl_max)); | |
527 | goto done; | |
528 | } | |
8713dbf0 | 529 | } else { |
1da177e4 | 530 | newpsl = NULL; |
8713dbf0 YZ |
531 | (void) ip6_mc_add_src(idev, group, gsf->gf_fmode, 0, NULL, 0); |
532 | } | |
5ab4a6c8 | 533 | |
96b52e61 | 534 | write_lock(&pmc->sflock); |
1da177e4 LT |
535 | psl = pmc->sflist; |
536 | if (psl) { | |
537 | (void) ip6_mc_del_src(idev, group, pmc->sfmode, | |
538 | psl->sl_count, psl->sl_addr, 0); | |
539 | sock_kfree_s(sk, psl, IP6_SFLSIZE(psl->sl_max)); | |
540 | } else | |
541 | (void) ip6_mc_del_src(idev, group, pmc->sfmode, 0, NULL, 0); | |
542 | pmc->sflist = newpsl; | |
543 | pmc->sfmode = gsf->gf_fmode; | |
96b52e61 | 544 | write_unlock(&pmc->sflock); |
917f2f10 | 545 | err = 0; |
1da177e4 LT |
546 | done: |
547 | read_unlock_bh(&idev->lock); | |
96b52e61 | 548 | rcu_read_unlock(); |
9951f036 DS |
549 | if (leavegroup) |
550 | err = ipv6_sock_mc_drop(sk, gsf->gf_interface, group); | |
1da177e4 LT |
551 | return err; |
552 | } | |
553 | ||
554 | int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf, | |
555 | struct group_filter __user *optval, int __user *optlen) | |
556 | { | |
557 | int err, i, count, copycount; | |
b71d1d42 | 558 | const struct in6_addr *group; |
1da177e4 LT |
559 | struct ipv6_mc_socklist *pmc; |
560 | struct inet6_dev *idev; | |
1da177e4 LT |
561 | struct ipv6_pinfo *inet6 = inet6_sk(sk); |
562 | struct ip6_sf_socklist *psl; | |
3b1e0a65 | 563 | struct net *net = sock_net(sk); |
1da177e4 LT |
564 | |
565 | group = &((struct sockaddr_in6 *)&gsf->gf_group)->sin6_addr; | |
566 | ||
567 | if (!ipv6_addr_is_multicast(group)) | |
568 | return -EINVAL; | |
569 | ||
96b52e61 ED |
570 | rcu_read_lock(); |
571 | idev = ip6_mc_find_dev_rcu(net, group, gsf->gf_interface); | |
1da177e4 | 572 | |
96b52e61 ED |
573 | if (!idev) { |
574 | rcu_read_unlock(); | |
1da177e4 | 575 | return -ENODEV; |
96b52e61 | 576 | } |
1da177e4 LT |
577 | |
578 | err = -EADDRNOTAVAIL; | |
5ab4a6c8 DS |
579 | /* |
580 | * changes to the ipv6_mc_list require the socket lock and | |
581 | * a read lock on ip6_sk_mc_lock. We have the socket lock, | |
582 | * so reading the list is safe. | |
583 | */ | |
1da177e4 | 584 | |
456b61bc | 585 | for_each_pmc_rcu(inet6, pmc) { |
1da177e4 LT |
586 | if (pmc->ifindex != gsf->gf_interface) |
587 | continue; | |
588 | if (ipv6_addr_equal(group, &pmc->addr)) | |
589 | break; | |
590 | } | |
591 | if (!pmc) /* must have a prior join */ | |
592 | goto done; | |
593 | gsf->gf_fmode = pmc->sfmode; | |
594 | psl = pmc->sflist; | |
595 | count = psl ? psl->sl_count : 0; | |
596 | read_unlock_bh(&idev->lock); | |
96b52e61 | 597 | rcu_read_unlock(); |
1da177e4 LT |
598 | |
599 | copycount = count < gsf->gf_numsrc ? count : gsf->gf_numsrc; | |
600 | gsf->gf_numsrc = count; | |
601 | if (put_user(GROUP_FILTER_SIZE(copycount), optlen) || | |
602 | copy_to_user(optval, gsf, GROUP_FILTER_SIZE(0))) { | |
603 | return -EFAULT; | |
604 | } | |
5ab4a6c8 DS |
605 | /* changes to psl require the socket lock, a read lock on |
606 | * on ipv6_sk_mc_lock and a write lock on pmc->sflock. We | |
607 | * have the socket lock, so reading here is safe. | |
608 | */ | |
1da177e4 LT |
609 | for (i=0; i<copycount; i++) { |
610 | struct sockaddr_in6 *psin6; | |
611 | struct sockaddr_storage ss; | |
612 | ||
613 | psin6 = (struct sockaddr_in6 *)&ss; | |
614 | memset(&ss, 0, sizeof(ss)); | |
615 | psin6->sin6_family = AF_INET6; | |
616 | psin6->sin6_addr = psl->sl_addr[i]; | |
1ab1457c | 617 | if (copy_to_user(&optval->gf_slist[i], &ss, sizeof(ss))) |
1da177e4 LT |
618 | return -EFAULT; |
619 | } | |
620 | return 0; | |
621 | done: | |
622 | read_unlock_bh(&idev->lock); | |
96b52e61 | 623 | rcu_read_unlock(); |
1da177e4 LT |
624 | return err; |
625 | } | |
626 | ||
a50feda5 ED |
627 | bool inet6_mc_check(struct sock *sk, const struct in6_addr *mc_addr, |
628 | const struct in6_addr *src_addr) | |
1da177e4 LT |
629 | { |
630 | struct ipv6_pinfo *np = inet6_sk(sk); | |
631 | struct ipv6_mc_socklist *mc; | |
632 | struct ip6_sf_socklist *psl; | |
a50feda5 | 633 | bool rv = true; |
1da177e4 | 634 | |
456b61bc ED |
635 | rcu_read_lock(); |
636 | for_each_pmc_rcu(np, mc) { | |
1da177e4 LT |
637 | if (ipv6_addr_equal(&mc->addr, mc_addr)) |
638 | break; | |
639 | } | |
640 | if (!mc) { | |
456b61bc | 641 | rcu_read_unlock(); |
a50feda5 | 642 | return true; |
1da177e4 | 643 | } |
5ab4a6c8 | 644 | read_lock(&mc->sflock); |
1da177e4 LT |
645 | psl = mc->sflist; |
646 | if (!psl) { | |
647 | rv = mc->sfmode == MCAST_EXCLUDE; | |
648 | } else { | |
649 | int i; | |
650 | ||
651 | for (i=0; i<psl->sl_count; i++) { | |
652 | if (ipv6_addr_equal(&psl->sl_addr[i], src_addr)) | |
653 | break; | |
654 | } | |
655 | if (mc->sfmode == MCAST_INCLUDE && i >= psl->sl_count) | |
a50feda5 | 656 | rv = false; |
1da177e4 | 657 | if (mc->sfmode == MCAST_EXCLUDE && i < psl->sl_count) |
a50feda5 | 658 | rv = false; |
1da177e4 | 659 | } |
5ab4a6c8 | 660 | read_unlock(&mc->sflock); |
456b61bc | 661 | rcu_read_unlock(); |
1da177e4 LT |
662 | |
663 | return rv; | |
664 | } | |
665 | ||
666 | static void ma_put(struct ifmcaddr6 *mc) | |
667 | { | |
668 | if (atomic_dec_and_test(&mc->mca_refcnt)) { | |
669 | in6_dev_put(mc->idev); | |
670 | kfree(mc); | |
671 | } | |
672 | } | |
673 | ||
674 | static void igmp6_group_added(struct ifmcaddr6 *mc) | |
675 | { | |
676 | struct net_device *dev = mc->idev->dev; | |
677 | char buf[MAX_ADDR_LEN]; | |
678 | ||
ec16ef22 YH |
679 | if (IPV6_ADDR_MC_SCOPE(&mc->mca_addr) < |
680 | IPV6_ADDR_SCOPE_LINKLOCAL) | |
681 | return; | |
682 | ||
1da177e4 LT |
683 | spin_lock_bh(&mc->mca_lock); |
684 | if (!(mc->mca_flags&MAF_LOADED)) { | |
685 | mc->mca_flags |= MAF_LOADED; | |
686 | if (ndisc_mc_map(&mc->mca_addr, buf, dev, 0) == 0) | |
22bedad3 | 687 | dev_mc_add(dev, buf); |
1da177e4 LT |
688 | } |
689 | spin_unlock_bh(&mc->mca_lock); | |
690 | ||
691 | if (!(dev->flags & IFF_UP) || (mc->mca_flags & MAF_NOREPORT)) | |
692 | return; | |
693 | ||
6c567b78 | 694 | if (mld_in_v1_mode(mc->idev)) { |
1da177e4 LT |
695 | igmp6_join_group(mc); |
696 | return; | |
697 | } | |
698 | /* else v2 */ | |
699 | ||
700 | mc->mca_crcount = mc->idev->mc_qrv; | |
701 | mld_ifc_event(mc->idev); | |
702 | } | |
703 | ||
704 | static void igmp6_group_dropped(struct ifmcaddr6 *mc) | |
705 | { | |
706 | struct net_device *dev = mc->idev->dev; | |
707 | char buf[MAX_ADDR_LEN]; | |
708 | ||
ec16ef22 YH |
709 | if (IPV6_ADDR_MC_SCOPE(&mc->mca_addr) < |
710 | IPV6_ADDR_SCOPE_LINKLOCAL) | |
711 | return; | |
712 | ||
1da177e4 LT |
713 | spin_lock_bh(&mc->mca_lock); |
714 | if (mc->mca_flags&MAF_LOADED) { | |
715 | mc->mca_flags &= ~MAF_LOADED; | |
716 | if (ndisc_mc_map(&mc->mca_addr, buf, dev, 0) == 0) | |
22bedad3 | 717 | dev_mc_del(dev, buf); |
1da177e4 LT |
718 | } |
719 | ||
720 | if (mc->mca_flags & MAF_NOREPORT) | |
721 | goto done; | |
722 | spin_unlock_bh(&mc->mca_lock); | |
723 | ||
724 | if (!mc->idev->dead) | |
725 | igmp6_leave_group(mc); | |
726 | ||
727 | spin_lock_bh(&mc->mca_lock); | |
728 | if (del_timer(&mc->mca_timer)) | |
729 | atomic_dec(&mc->mca_refcnt); | |
730 | done: | |
731 | ip6_mc_clear_src(mc); | |
732 | spin_unlock_bh(&mc->mca_lock); | |
733 | } | |
734 | ||
735 | /* | |
736 | * deleted ifmcaddr6 manipulation | |
737 | */ | |
738 | static void mld_add_delrec(struct inet6_dev *idev, struct ifmcaddr6 *im) | |
739 | { | |
740 | struct ifmcaddr6 *pmc; | |
741 | ||
742 | /* this is an "ifmcaddr6" for convenience; only the fields below | |
743 | * are actually used. In particular, the refcnt and users are not | |
744 | * used for management of the delete list. Using the same structure | |
745 | * for deleted items allows change reports to use common code with | |
746 | * non-deleted or query-response MCA's. | |
747 | */ | |
0c600eda | 748 | pmc = kzalloc(sizeof(*pmc), GFP_ATOMIC); |
1da177e4 LT |
749 | if (!pmc) |
750 | return; | |
0c600eda | 751 | |
1da177e4 LT |
752 | spin_lock_bh(&im->mca_lock); |
753 | spin_lock_init(&pmc->mca_lock); | |
754 | pmc->idev = im->idev; | |
755 | in6_dev_hold(idev); | |
756 | pmc->mca_addr = im->mca_addr; | |
757 | pmc->mca_crcount = idev->mc_qrv; | |
758 | pmc->mca_sfmode = im->mca_sfmode; | |
759 | if (pmc->mca_sfmode == MCAST_INCLUDE) { | |
760 | struct ip6_sf_list *psf; | |
761 | ||
762 | pmc->mca_tomb = im->mca_tomb; | |
763 | pmc->mca_sources = im->mca_sources; | |
764 | im->mca_tomb = im->mca_sources = NULL; | |
765 | for (psf=pmc->mca_sources; psf; psf=psf->sf_next) | |
766 | psf->sf_crcount = pmc->mca_crcount; | |
767 | } | |
768 | spin_unlock_bh(&im->mca_lock); | |
769 | ||
6457d26b | 770 | spin_lock_bh(&idev->mc_lock); |
1da177e4 LT |
771 | pmc->next = idev->mc_tomb; |
772 | idev->mc_tomb = pmc; | |
6457d26b | 773 | spin_unlock_bh(&idev->mc_lock); |
1da177e4 LT |
774 | } |
775 | ||
b71d1d42 | 776 | static void mld_del_delrec(struct inet6_dev *idev, const struct in6_addr *pmca) |
1da177e4 LT |
777 | { |
778 | struct ifmcaddr6 *pmc, *pmc_prev; | |
779 | struct ip6_sf_list *psf, *psf_next; | |
780 | ||
6457d26b | 781 | spin_lock_bh(&idev->mc_lock); |
1da177e4 LT |
782 | pmc_prev = NULL; |
783 | for (pmc=idev->mc_tomb; pmc; pmc=pmc->next) { | |
784 | if (ipv6_addr_equal(&pmc->mca_addr, pmca)) | |
785 | break; | |
786 | pmc_prev = pmc; | |
787 | } | |
788 | if (pmc) { | |
789 | if (pmc_prev) | |
790 | pmc_prev->next = pmc->next; | |
791 | else | |
792 | idev->mc_tomb = pmc->next; | |
793 | } | |
6457d26b SH |
794 | spin_unlock_bh(&idev->mc_lock); |
795 | ||
1da177e4 LT |
796 | if (pmc) { |
797 | for (psf=pmc->mca_tomb; psf; psf=psf_next) { | |
798 | psf_next = psf->sf_next; | |
799 | kfree(psf); | |
800 | } | |
801 | in6_dev_put(pmc->idev); | |
802 | kfree(pmc); | |
803 | } | |
804 | } | |
805 | ||
806 | static void mld_clear_delrec(struct inet6_dev *idev) | |
807 | { | |
808 | struct ifmcaddr6 *pmc, *nextpmc; | |
809 | ||
6457d26b | 810 | spin_lock_bh(&idev->mc_lock); |
1da177e4 LT |
811 | pmc = idev->mc_tomb; |
812 | idev->mc_tomb = NULL; | |
6457d26b | 813 | spin_unlock_bh(&idev->mc_lock); |
1da177e4 LT |
814 | |
815 | for (; pmc; pmc = nextpmc) { | |
816 | nextpmc = pmc->next; | |
817 | ip6_mc_clear_src(pmc); | |
818 | in6_dev_put(pmc->idev); | |
819 | kfree(pmc); | |
820 | } | |
821 | ||
822 | /* clear dead sources, too */ | |
823 | read_lock_bh(&idev->lock); | |
824 | for (pmc=idev->mc_list; pmc; pmc=pmc->next) { | |
825 | struct ip6_sf_list *psf, *psf_next; | |
826 | ||
827 | spin_lock_bh(&pmc->mca_lock); | |
828 | psf = pmc->mca_tomb; | |
829 | pmc->mca_tomb = NULL; | |
830 | spin_unlock_bh(&pmc->mca_lock); | |
831 | for (; psf; psf=psf_next) { | |
832 | psf_next = psf->sf_next; | |
833 | kfree(psf); | |
834 | } | |
835 | } | |
836 | read_unlock_bh(&idev->lock); | |
837 | } | |
838 | ||
839 | ||
840 | /* | |
841 | * device multicast group inc (add if not found) | |
842 | */ | |
9acd9f3a | 843 | int ipv6_dev_mc_inc(struct net_device *dev, const struct in6_addr *addr) |
1da177e4 LT |
844 | { |
845 | struct ifmcaddr6 *mc; | |
846 | struct inet6_dev *idev; | |
847 | ||
96b52e61 | 848 | /* we need to take a reference on idev */ |
1da177e4 LT |
849 | idev = in6_dev_get(dev); |
850 | ||
851 | if (idev == NULL) | |
852 | return -EINVAL; | |
853 | ||
854 | write_lock_bh(&idev->lock); | |
855 | if (idev->dead) { | |
856 | write_unlock_bh(&idev->lock); | |
857 | in6_dev_put(idev); | |
858 | return -ENODEV; | |
859 | } | |
860 | ||
861 | for (mc = idev->mc_list; mc; mc = mc->next) { | |
862 | if (ipv6_addr_equal(&mc->mca_addr, addr)) { | |
863 | mc->mca_users++; | |
864 | write_unlock_bh(&idev->lock); | |
865 | ip6_mc_add_src(idev, &mc->mca_addr, MCAST_EXCLUDE, 0, | |
866 | NULL, 0); | |
867 | in6_dev_put(idev); | |
868 | return 0; | |
869 | } | |
870 | } | |
871 | ||
872 | /* | |
873 | * not found: create a new one. | |
874 | */ | |
875 | ||
0c600eda | 876 | mc = kzalloc(sizeof(struct ifmcaddr6), GFP_ATOMIC); |
1da177e4 LT |
877 | |
878 | if (mc == NULL) { | |
879 | write_unlock_bh(&idev->lock); | |
880 | in6_dev_put(idev); | |
881 | return -ENOMEM; | |
882 | } | |
883 | ||
b24b8a24 | 884 | setup_timer(&mc->mca_timer, igmp6_timer_handler, (unsigned long)mc); |
1da177e4 | 885 | |
4e3fd7a0 | 886 | mc->mca_addr = *addr; |
96b52e61 | 887 | mc->idev = idev; /* (reference taken) */ |
1da177e4 LT |
888 | mc->mca_users = 1; |
889 | /* mca_stamp should be updated upon changes */ | |
890 | mc->mca_cstamp = mc->mca_tstamp = jiffies; | |
891 | atomic_set(&mc->mca_refcnt, 2); | |
892 | spin_lock_init(&mc->mca_lock); | |
893 | ||
894 | /* initial mode is (EX, empty) */ | |
895 | mc->mca_sfmode = MCAST_EXCLUDE; | |
896 | mc->mca_sfcount[MCAST_EXCLUDE] = 1; | |
897 | ||
898 | if (ipv6_addr_is_ll_all_nodes(&mc->mca_addr) || | |
899 | IPV6_ADDR_MC_SCOPE(&mc->mca_addr) < IPV6_ADDR_SCOPE_LINKLOCAL) | |
900 | mc->mca_flags |= MAF_NOREPORT; | |
901 | ||
902 | mc->next = idev->mc_list; | |
903 | idev->mc_list = mc; | |
904 | write_unlock_bh(&idev->lock); | |
905 | ||
906 | mld_del_delrec(idev, &mc->mca_addr); | |
907 | igmp6_group_added(mc); | |
908 | ma_put(mc); | |
909 | return 0; | |
910 | } | |
911 | ||
912 | /* | |
913 | * device multicast group del | |
914 | */ | |
9acd9f3a | 915 | int __ipv6_dev_mc_dec(struct inet6_dev *idev, const struct in6_addr *addr) |
1da177e4 LT |
916 | { |
917 | struct ifmcaddr6 *ma, **map; | |
918 | ||
919 | write_lock_bh(&idev->lock); | |
920 | for (map = &idev->mc_list; (ma=*map) != NULL; map = &ma->next) { | |
921 | if (ipv6_addr_equal(&ma->mca_addr, addr)) { | |
922 | if (--ma->mca_users == 0) { | |
923 | *map = ma->next; | |
924 | write_unlock_bh(&idev->lock); | |
925 | ||
926 | igmp6_group_dropped(ma); | |
927 | ||
928 | ma_put(ma); | |
929 | return 0; | |
930 | } | |
931 | write_unlock_bh(&idev->lock); | |
932 | return 0; | |
933 | } | |
934 | } | |
935 | write_unlock_bh(&idev->lock); | |
936 | ||
937 | return -ENOENT; | |
938 | } | |
939 | ||
9acd9f3a | 940 | int ipv6_dev_mc_dec(struct net_device *dev, const struct in6_addr *addr) |
1da177e4 | 941 | { |
96b52e61 | 942 | struct inet6_dev *idev; |
1da177e4 LT |
943 | int err; |
944 | ||
96b52e61 | 945 | rcu_read_lock(); |
1da177e4 | 946 | |
96b52e61 ED |
947 | idev = __in6_dev_get(dev); |
948 | if (!idev) | |
949 | err = -ENODEV; | |
950 | else | |
951 | err = __ipv6_dev_mc_dec(idev, addr); | |
1da177e4 | 952 | |
96b52e61 | 953 | rcu_read_unlock(); |
1da177e4 LT |
954 | return err; |
955 | } | |
956 | ||
1da177e4 LT |
957 | /* |
958 | * check if the interface/address pair is valid | |
959 | */ | |
a50feda5 ED |
960 | bool ipv6_chk_mcast_addr(struct net_device *dev, const struct in6_addr *group, |
961 | const struct in6_addr *src_addr) | |
1da177e4 LT |
962 | { |
963 | struct inet6_dev *idev; | |
964 | struct ifmcaddr6 *mc; | |
a50feda5 | 965 | bool rv = false; |
1da177e4 | 966 | |
96b52e61 ED |
967 | rcu_read_lock(); |
968 | idev = __in6_dev_get(dev); | |
1da177e4 LT |
969 | if (idev) { |
970 | read_lock_bh(&idev->lock); | |
971 | for (mc = idev->mc_list; mc; mc=mc->next) { | |
972 | if (ipv6_addr_equal(&mc->mca_addr, group)) | |
973 | break; | |
974 | } | |
975 | if (mc) { | |
976 | if (src_addr && !ipv6_addr_any(src_addr)) { | |
977 | struct ip6_sf_list *psf; | |
978 | ||
979 | spin_lock_bh(&mc->mca_lock); | |
980 | for (psf=mc->mca_sources;psf;psf=psf->sf_next) { | |
981 | if (ipv6_addr_equal(&psf->sf_addr, src_addr)) | |
982 | break; | |
983 | } | |
984 | if (psf) | |
985 | rv = psf->sf_count[MCAST_INCLUDE] || | |
986 | psf->sf_count[MCAST_EXCLUDE] != | |
987 | mc->mca_sfcount[MCAST_EXCLUDE]; | |
988 | else | |
989 | rv = mc->mca_sfcount[MCAST_EXCLUDE] !=0; | |
990 | spin_unlock_bh(&mc->mca_lock); | |
991 | } else | |
a50feda5 | 992 | rv = true; /* don't filter unspecified source */ |
1da177e4 LT |
993 | } |
994 | read_unlock_bh(&idev->lock); | |
1da177e4 | 995 | } |
96b52e61 | 996 | rcu_read_unlock(); |
1da177e4 LT |
997 | return rv; |
998 | } | |
999 | ||
1000 | static void mld_gq_start_timer(struct inet6_dev *idev) | |
1001 | { | |
c2cef4e8 | 1002 | unsigned long tv = net_random() % idev->mc_maxdelay; |
1da177e4 LT |
1003 | |
1004 | idev->mc_gq_running = 1; | |
1005 | if (!mod_timer(&idev->mc_gq_timer, jiffies+tv+2)) | |
1006 | in6_dev_hold(idev); | |
1007 | } | |
1008 | ||
c2cef4e8 | 1009 | static void mld_ifc_start_timer(struct inet6_dev *idev, unsigned long delay) |
1da177e4 | 1010 | { |
c2cef4e8 | 1011 | unsigned long tv = net_random() % delay; |
1da177e4 LT |
1012 | |
1013 | if (!mod_timer(&idev->mc_ifc_timer, jiffies+tv+2)) | |
1014 | in6_dev_hold(idev); | |
1015 | } | |
1016 | ||
c2cef4e8 | 1017 | static void mld_dad_start_timer(struct inet6_dev *idev, unsigned long delay) |
b173ee48 | 1018 | { |
c2cef4e8 | 1019 | unsigned long tv = net_random() % delay; |
b173ee48 HFS |
1020 | |
1021 | if (!mod_timer(&idev->mc_dad_timer, jiffies+tv+2)) | |
1022 | in6_dev_hold(idev); | |
1023 | } | |
1024 | ||
1da177e4 LT |
1025 | /* |
1026 | * IGMP handling (alias multicast ICMPv6 messages) | |
1027 | */ | |
1028 | ||
1029 | static void igmp6_group_queried(struct ifmcaddr6 *ma, unsigned long resptime) | |
1030 | { | |
1031 | unsigned long delay = resptime; | |
1032 | ||
1033 | /* Do not start timer for these addresses */ | |
1034 | if (ipv6_addr_is_ll_all_nodes(&ma->mca_addr) || | |
1035 | IPV6_ADDR_MC_SCOPE(&ma->mca_addr) < IPV6_ADDR_SCOPE_LINKLOCAL) | |
1036 | return; | |
1037 | ||
1038 | if (del_timer(&ma->mca_timer)) { | |
1039 | atomic_dec(&ma->mca_refcnt); | |
1040 | delay = ma->mca_timer.expires - jiffies; | |
1041 | } | |
1042 | ||
cc7f7ab7 DB |
1043 | if (delay >= resptime) |
1044 | delay = net_random() % resptime; | |
1045 | ||
1da177e4 LT |
1046 | ma->mca_timer.expires = jiffies + delay; |
1047 | if (!mod_timer(&ma->mca_timer, jiffies + delay)) | |
1048 | atomic_inc(&ma->mca_refcnt); | |
1049 | ma->mca_flags |= MAF_TIMER_RUNNING; | |
1050 | } | |
1051 | ||
5ab4a6c8 | 1052 | /* mark EXCLUDE-mode sources */ |
a50feda5 ED |
1053 | static bool mld_xmarksources(struct ifmcaddr6 *pmc, int nsrcs, |
1054 | const struct in6_addr *srcs) | |
1da177e4 LT |
1055 | { |
1056 | struct ip6_sf_list *psf; | |
1057 | int i, scount; | |
1058 | ||
1059 | scount = 0; | |
1060 | for (psf=pmc->mca_sources; psf; psf=psf->sf_next) { | |
1061 | if (scount == nsrcs) | |
1062 | break; | |
5ab4a6c8 DS |
1063 | for (i=0; i<nsrcs; i++) { |
1064 | /* skip inactive filters */ | |
e05c4ad3 | 1065 | if (psf->sf_count[MCAST_INCLUDE] || |
5ab4a6c8 DS |
1066 | pmc->mca_sfcount[MCAST_EXCLUDE] != |
1067 | psf->sf_count[MCAST_EXCLUDE]) | |
ce713ee5 | 1068 | break; |
5ab4a6c8 DS |
1069 | if (ipv6_addr_equal(&srcs[i], &psf->sf_addr)) { |
1070 | scount++; | |
1071 | break; | |
1072 | } | |
1073 | } | |
1074 | } | |
1075 | pmc->mca_flags &= ~MAF_GSQUERY; | |
1076 | if (scount == nsrcs) /* all sources excluded */ | |
a50feda5 ED |
1077 | return false; |
1078 | return true; | |
5ab4a6c8 DS |
1079 | } |
1080 | ||
a50feda5 ED |
1081 | static bool mld_marksources(struct ifmcaddr6 *pmc, int nsrcs, |
1082 | const struct in6_addr *srcs) | |
5ab4a6c8 DS |
1083 | { |
1084 | struct ip6_sf_list *psf; | |
1085 | int i, scount; | |
1086 | ||
1087 | if (pmc->mca_sfmode == MCAST_EXCLUDE) | |
1088 | return mld_xmarksources(pmc, nsrcs, srcs); | |
1089 | ||
1090 | /* mark INCLUDE-mode sources */ | |
1091 | ||
1092 | scount = 0; | |
1093 | for (psf=pmc->mca_sources; psf; psf=psf->sf_next) { | |
1094 | if (scount == nsrcs) | |
1095 | break; | |
1096 | for (i=0; i<nsrcs; i++) { | |
1da177e4 LT |
1097 | if (ipv6_addr_equal(&srcs[i], &psf->sf_addr)) { |
1098 | psf->sf_gsresp = 1; | |
1099 | scount++; | |
1100 | break; | |
1101 | } | |
5ab4a6c8 DS |
1102 | } |
1103 | } | |
1104 | if (!scount) { | |
1105 | pmc->mca_flags &= ~MAF_GSQUERY; | |
a50feda5 | 1106 | return false; |
1da177e4 | 1107 | } |
5ab4a6c8 | 1108 | pmc->mca_flags |= MAF_GSQUERY; |
a50feda5 | 1109 | return true; |
1da177e4 LT |
1110 | } |
1111 | ||
58c0ecfd DB |
1112 | static int mld_force_mld_version(const struct inet6_dev *idev) |
1113 | { | |
1114 | /* Normally, both are 0 here. If enforcement to a particular is | |
1115 | * being used, individual device enforcement will have a lower | |
1116 | * precedence over 'all' device (.../conf/all/force_mld_version). | |
1117 | */ | |
1118 | ||
1119 | if (dev_net(idev->dev)->ipv6.devconf_all->force_mld_version != 0) | |
1120 | return dev_net(idev->dev)->ipv6.devconf_all->force_mld_version; | |
1121 | else | |
1122 | return idev->cnf.force_mld_version; | |
1123 | } | |
1124 | ||
1125 | static bool mld_in_v2_mode_only(const struct inet6_dev *idev) | |
1126 | { | |
1127 | return mld_force_mld_version(idev) == 2; | |
1128 | } | |
1129 | ||
1130 | static bool mld_in_v1_mode_only(const struct inet6_dev *idev) | |
1131 | { | |
1132 | return mld_force_mld_version(idev) == 1; | |
1133 | } | |
1134 | ||
6c567b78 DB |
1135 | static bool mld_in_v1_mode(const struct inet6_dev *idev) |
1136 | { | |
58c0ecfd DB |
1137 | if (mld_in_v2_mode_only(idev)) |
1138 | return false; | |
1139 | if (mld_in_v1_mode_only(idev)) | |
6c567b78 DB |
1140 | return true; |
1141 | if (idev->mc_v1_seen && time_before(jiffies, idev->mc_v1_seen)) | |
1142 | return true; | |
1143 | ||
1144 | return false; | |
1145 | } | |
1146 | ||
89225d1c DB |
1147 | static void mld_set_v1_mode(struct inet6_dev *idev) |
1148 | { | |
1149 | /* RFC3810, relevant sections: | |
1150 | * - 9.1. Robustness Variable | |
1151 | * - 9.2. Query Interval | |
1152 | * - 9.3. Query Response Interval | |
1153 | * - 9.12. Older Version Querier Present Timeout | |
1154 | */ | |
1155 | unsigned long switchback; | |
1156 | ||
1157 | switchback = (idev->mc_qrv * idev->mc_qi) + idev->mc_qri; | |
1158 | ||
1159 | idev->mc_v1_seen = jiffies + switchback; | |
1160 | } | |
1161 | ||
1162 | static void mld_update_qrv(struct inet6_dev *idev, | |
1163 | const struct mld2_query *mlh2) | |
1164 | { | |
1165 | /* RFC3810, relevant sections: | |
1166 | * - 5.1.8. QRV (Querier's Robustness Variable) | |
1167 | * - 9.1. Robustness Variable | |
1168 | */ | |
1169 | ||
1170 | /* The value of the Robustness Variable MUST NOT be zero, | |
1171 | * and SHOULD NOT be one. Catch this here if we ever run | |
1172 | * into such a case in future. | |
1173 | */ | |
1174 | WARN_ON(idev->mc_qrv == 0); | |
1175 | ||
1176 | if (mlh2->mld2q_qrv > 0) | |
1177 | idev->mc_qrv = mlh2->mld2q_qrv; | |
1178 | ||
1179 | if (unlikely(idev->mc_qrv < 2)) { | |
1180 | net_warn_ratelimited("IPv6: MLD: clamping QRV from %u to %u!\n", | |
1181 | idev->mc_qrv, MLD_QRV_DEFAULT); | |
1182 | idev->mc_qrv = MLD_QRV_DEFAULT; | |
1183 | } | |
1184 | } | |
1185 | ||
1186 | static void mld_update_qi(struct inet6_dev *idev, | |
1187 | const struct mld2_query *mlh2) | |
1188 | { | |
1189 | /* RFC3810, relevant sections: | |
1190 | * - 5.1.9. QQIC (Querier's Query Interval Code) | |
1191 | * - 9.2. Query Interval | |
1192 | * - 9.12. Older Version Querier Present Timeout | |
1193 | * (the [Query Interval] in the last Query received) | |
1194 | */ | |
1195 | unsigned long mc_qqi; | |
1196 | ||
1197 | if (mlh2->mld2q_qqic < 128) { | |
1198 | mc_qqi = mlh2->mld2q_qqic; | |
1199 | } else { | |
1200 | unsigned long mc_man, mc_exp; | |
1201 | ||
1202 | mc_exp = MLDV2_QQIC_EXP(mlh2->mld2q_qqic); | |
1203 | mc_man = MLDV2_QQIC_MAN(mlh2->mld2q_qqic); | |
1204 | ||
1205 | mc_qqi = (mc_man | 0x10) << (mc_exp + 3); | |
1206 | } | |
1207 | ||
1208 | idev->mc_qi = mc_qqi * HZ; | |
1209 | } | |
1210 | ||
1211 | static void mld_update_qri(struct inet6_dev *idev, | |
1212 | const struct mld2_query *mlh2) | |
1213 | { | |
1214 | /* RFC3810, relevant sections: | |
1215 | * - 5.1.3. Maximum Response Code | |
1216 | * - 9.3. Query Response Interval | |
1217 | */ | |
e3f5b170 | 1218 | idev->mc_qri = msecs_to_jiffies(mldv2_mrc(mlh2)); |
89225d1c DB |
1219 | } |
1220 | ||
2b7c121f DB |
1221 | static int mld_process_v1(struct inet6_dev *idev, struct mld_msg *mld, |
1222 | unsigned long *max_delay) | |
1223 | { | |
1224 | unsigned long mldv1_md; | |
1225 | ||
1226 | /* Ignore v1 queries */ | |
1227 | if (mld_in_v2_mode_only(idev)) | |
1228 | return -EINVAL; | |
1229 | ||
1230 | /* MLDv1 router present */ | |
1231 | mldv1_md = ntohs(mld->mld_maxdelay); | |
1232 | *max_delay = max(msecs_to_jiffies(mldv1_md), 1UL); | |
1233 | ||
1234 | mld_set_v1_mode(idev); | |
1235 | ||
1236 | /* cancel MLDv2 report timer */ | |
1237 | idev->mc_gq_running = 0; | |
1238 | if (del_timer(&idev->mc_gq_timer)) | |
1239 | __in6_dev_put(idev); | |
1240 | ||
1241 | /* cancel the interface change timer */ | |
1242 | idev->mc_ifc_count = 0; | |
1243 | if (del_timer(&idev->mc_ifc_timer)) | |
1244 | __in6_dev_put(idev); | |
1245 | ||
1246 | /* clear deleted report items */ | |
1247 | mld_clear_delrec(idev); | |
1248 | ||
1249 | return 0; | |
1250 | } | |
1251 | ||
1252 | static int mld_process_v2(struct inet6_dev *idev, struct mld2_query *mld, | |
1253 | unsigned long *max_delay) | |
1254 | { | |
1255 | /* hosts need to stay in MLDv1 mode, discard MLDv2 queries */ | |
1256 | if (mld_in_v1_mode(idev)) | |
1257 | return -EINVAL; | |
1258 | ||
1259 | *max_delay = max(msecs_to_jiffies(mldv2_mrc(mld)), 1UL); | |
1260 | ||
1261 | mld_update_qrv(idev, mld); | |
1262 | mld_update_qi(idev, mld); | |
1263 | mld_update_qri(idev, mld); | |
1264 | ||
1265 | idev->mc_maxdelay = *max_delay; | |
1266 | ||
1267 | return 0; | |
1268 | } | |
1269 | ||
96b52e61 | 1270 | /* called with rcu_read_lock() */ |
1da177e4 LT |
1271 | int igmp6_event_query(struct sk_buff *skb) |
1272 | { | |
97300b5f | 1273 | struct mld2_query *mlh2 = NULL; |
1da177e4 | 1274 | struct ifmcaddr6 *ma; |
b71d1d42 | 1275 | const struct in6_addr *group; |
1da177e4 LT |
1276 | unsigned long max_delay; |
1277 | struct inet6_dev *idev; | |
6e7cb837 | 1278 | struct mld_msg *mld; |
1da177e4 LT |
1279 | int group_type; |
1280 | int mark = 0; | |
2b7c121f | 1281 | int len, err; |
1da177e4 LT |
1282 | |
1283 | if (!pskb_may_pull(skb, sizeof(struct in6_addr))) | |
1284 | return -EINVAL; | |
1285 | ||
1286 | /* compute payload length excluding extension headers */ | |
0660e03f | 1287 | len = ntohs(ipv6_hdr(skb)->payload_len) + sizeof(struct ipv6hdr); |
cfe1fc77 | 1288 | len -= skb_network_header_len(skb); |
1da177e4 LT |
1289 | |
1290 | /* Drop queries with not link local source */ | |
0660e03f | 1291 | if (!(ipv6_addr_type(&ipv6_hdr(skb)->saddr) & IPV6_ADDR_LINKLOCAL)) |
1da177e4 LT |
1292 | return -EINVAL; |
1293 | ||
96b52e61 | 1294 | idev = __in6_dev_get(skb->dev); |
1da177e4 LT |
1295 | if (idev == NULL) |
1296 | return 0; | |
1297 | ||
6e7cb837 YH |
1298 | mld = (struct mld_msg *)icmp6_hdr(skb); |
1299 | group = &mld->mld_mca; | |
1da177e4 LT |
1300 | group_type = ipv6_addr_type(group); |
1301 | ||
1302 | if (group_type != IPV6_ADDR_ANY && | |
96b52e61 | 1303 | !(group_type&IPV6_ADDR_MULTICAST)) |
1da177e4 | 1304 | return -EINVAL; |
1da177e4 | 1305 | |
9fd07841 | 1306 | if (len == MLD_V1_QUERY_LEN) { |
2b7c121f DB |
1307 | err = mld_process_v1(idev, mld, &max_delay); |
1308 | if (err < 0) | |
1309 | return err; | |
9fd07841 | 1310 | } else if (len >= MLD_V2_QUERY_LEN_MIN) { |
1ab1457c | 1311 | int srcs_offset = sizeof(struct mld2_query) - |
97300b5f | 1312 | sizeof(struct icmp6hdr); |
89225d1c | 1313 | |
96b52e61 | 1314 | if (!pskb_may_pull(skb, srcs_offset)) |
97300b5f | 1315 | return -EINVAL; |
96b52e61 | 1316 | |
9c70220b | 1317 | mlh2 = (struct mld2_query *)skb_transport_header(skb); |
84698963 | 1318 | |
2b7c121f DB |
1319 | err = mld_process_v2(idev, mlh2, &max_delay); |
1320 | if (err < 0) | |
1321 | return err; | |
89225d1c | 1322 | |
1da177e4 | 1323 | if (group_type == IPV6_ADDR_ANY) { /* general query */ |
96b52e61 | 1324 | if (mlh2->mld2q_nsrcs) |
1da177e4 | 1325 | return -EINVAL; /* no sources allowed */ |
96b52e61 | 1326 | |
1da177e4 | 1327 | mld_gq_start_timer(idev); |
1da177e4 LT |
1328 | return 0; |
1329 | } | |
1330 | /* mark sources to include, if group & source-specific */ | |
6e7cb837 | 1331 | if (mlh2->mld2q_nsrcs != 0) { |
1ab1457c | 1332 | if (!pskb_may_pull(skb, srcs_offset + |
96b52e61 | 1333 | ntohs(mlh2->mld2q_nsrcs) * sizeof(struct in6_addr))) |
97300b5f | 1334 | return -EINVAL; |
96b52e61 | 1335 | |
9c70220b | 1336 | mlh2 = (struct mld2_query *)skb_transport_header(skb); |
97300b5f YZ |
1337 | mark = 1; |
1338 | } | |
96b52e61 | 1339 | } else |
1da177e4 | 1340 | return -EINVAL; |
1da177e4 LT |
1341 | |
1342 | read_lock_bh(&idev->lock); | |
1343 | if (group_type == IPV6_ADDR_ANY) { | |
1344 | for (ma = idev->mc_list; ma; ma=ma->next) { | |
1345 | spin_lock_bh(&ma->mca_lock); | |
1346 | igmp6_group_queried(ma, max_delay); | |
1347 | spin_unlock_bh(&ma->mca_lock); | |
1348 | } | |
1349 | } else { | |
1350 | for (ma = idev->mc_list; ma; ma=ma->next) { | |
7add2a43 | 1351 | if (!ipv6_addr_equal(group, &ma->mca_addr)) |
1da177e4 LT |
1352 | continue; |
1353 | spin_lock_bh(&ma->mca_lock); | |
1354 | if (ma->mca_flags & MAF_TIMER_RUNNING) { | |
1355 | /* gsquery <- gsquery && mark */ | |
1356 | if (!mark) | |
1357 | ma->mca_flags &= ~MAF_GSQUERY; | |
1358 | } else { | |
1359 | /* gsquery <- mark */ | |
1360 | if (mark) | |
1361 | ma->mca_flags |= MAF_GSQUERY; | |
1362 | else | |
1363 | ma->mca_flags &= ~MAF_GSQUERY; | |
1364 | } | |
5ab4a6c8 | 1365 | if (!(ma->mca_flags & MAF_GSQUERY) || |
6e7cb837 | 1366 | mld_marksources(ma, ntohs(mlh2->mld2q_nsrcs), mlh2->mld2q_srcs)) |
5ab4a6c8 | 1367 | igmp6_group_queried(ma, max_delay); |
1da177e4 | 1368 | spin_unlock_bh(&ma->mca_lock); |
7add2a43 | 1369 | break; |
1da177e4 LT |
1370 | } |
1371 | } | |
1372 | read_unlock_bh(&idev->lock); | |
1da177e4 LT |
1373 | |
1374 | return 0; | |
1375 | } | |
1376 | ||
96b52e61 | 1377 | /* called with rcu_read_lock() */ |
1da177e4 LT |
1378 | int igmp6_event_report(struct sk_buff *skb) |
1379 | { | |
1380 | struct ifmcaddr6 *ma; | |
1da177e4 | 1381 | struct inet6_dev *idev; |
6e7cb837 | 1382 | struct mld_msg *mld; |
1da177e4 LT |
1383 | int addr_type; |
1384 | ||
1385 | /* Our own report looped back. Ignore it. */ | |
1386 | if (skb->pkt_type == PACKET_LOOPBACK) | |
1387 | return 0; | |
1388 | ||
24c69275 DS |
1389 | /* send our report if the MC router may not have heard this report */ |
1390 | if (skb->pkt_type != PACKET_MULTICAST && | |
1391 | skb->pkt_type != PACKET_BROADCAST) | |
1392 | return 0; | |
1393 | ||
6e7cb837 | 1394 | if (!pskb_may_pull(skb, sizeof(*mld) - sizeof(struct icmp6hdr))) |
1da177e4 LT |
1395 | return -EINVAL; |
1396 | ||
6e7cb837 | 1397 | mld = (struct mld_msg *)icmp6_hdr(skb); |
1da177e4 LT |
1398 | |
1399 | /* Drop reports with not link local source */ | |
0660e03f | 1400 | addr_type = ipv6_addr_type(&ipv6_hdr(skb)->saddr); |
1ab1457c | 1401 | if (addr_type != IPV6_ADDR_ANY && |
1da177e4 LT |
1402 | !(addr_type&IPV6_ADDR_LINKLOCAL)) |
1403 | return -EINVAL; | |
1404 | ||
96b52e61 | 1405 | idev = __in6_dev_get(skb->dev); |
1da177e4 LT |
1406 | if (idev == NULL) |
1407 | return -ENODEV; | |
1408 | ||
1409 | /* | |
1410 | * Cancel the timer for this group | |
1411 | */ | |
1412 | ||
1413 | read_lock_bh(&idev->lock); | |
1414 | for (ma = idev->mc_list; ma; ma=ma->next) { | |
6e7cb837 | 1415 | if (ipv6_addr_equal(&ma->mca_addr, &mld->mld_mca)) { |
1da177e4 LT |
1416 | spin_lock(&ma->mca_lock); |
1417 | if (del_timer(&ma->mca_timer)) | |
1418 | atomic_dec(&ma->mca_refcnt); | |
1419 | ma->mca_flags &= ~(MAF_LAST_REPORTER|MAF_TIMER_RUNNING); | |
1420 | spin_unlock(&ma->mca_lock); | |
1421 | break; | |
1422 | } | |
1423 | } | |
1424 | read_unlock_bh(&idev->lock); | |
1da177e4 LT |
1425 | return 0; |
1426 | } | |
1427 | ||
a50feda5 ED |
1428 | static bool is_in(struct ifmcaddr6 *pmc, struct ip6_sf_list *psf, int type, |
1429 | int gdeleted, int sdeleted) | |
1da177e4 LT |
1430 | { |
1431 | switch (type) { | |
1432 | case MLD2_MODE_IS_INCLUDE: | |
1433 | case MLD2_MODE_IS_EXCLUDE: | |
1434 | if (gdeleted || sdeleted) | |
a50feda5 | 1435 | return false; |
5ab4a6c8 DS |
1436 | if (!((pmc->mca_flags & MAF_GSQUERY) && !psf->sf_gsresp)) { |
1437 | if (pmc->mca_sfmode == MCAST_INCLUDE) | |
a50feda5 | 1438 | return true; |
5ab4a6c8 DS |
1439 | /* don't include if this source is excluded |
1440 | * in all filters | |
1441 | */ | |
1442 | if (psf->sf_count[MCAST_INCLUDE]) | |
7add2a43 | 1443 | return type == MLD2_MODE_IS_INCLUDE; |
5ab4a6c8 DS |
1444 | return pmc->mca_sfcount[MCAST_EXCLUDE] == |
1445 | psf->sf_count[MCAST_EXCLUDE]; | |
1446 | } | |
a50feda5 | 1447 | return false; |
1da177e4 LT |
1448 | case MLD2_CHANGE_TO_INCLUDE: |
1449 | if (gdeleted || sdeleted) | |
a50feda5 | 1450 | return false; |
1da177e4 LT |
1451 | return psf->sf_count[MCAST_INCLUDE] != 0; |
1452 | case MLD2_CHANGE_TO_EXCLUDE: | |
1453 | if (gdeleted || sdeleted) | |
a50feda5 | 1454 | return false; |
1da177e4 LT |
1455 | if (pmc->mca_sfcount[MCAST_EXCLUDE] == 0 || |
1456 | psf->sf_count[MCAST_INCLUDE]) | |
a50feda5 | 1457 | return false; |
1da177e4 LT |
1458 | return pmc->mca_sfcount[MCAST_EXCLUDE] == |
1459 | psf->sf_count[MCAST_EXCLUDE]; | |
1460 | case MLD2_ALLOW_NEW_SOURCES: | |
1461 | if (gdeleted || !psf->sf_crcount) | |
a50feda5 | 1462 | return false; |
1da177e4 LT |
1463 | return (pmc->mca_sfmode == MCAST_INCLUDE) ^ sdeleted; |
1464 | case MLD2_BLOCK_OLD_SOURCES: | |
1465 | if (pmc->mca_sfmode == MCAST_INCLUDE) | |
1466 | return gdeleted || (psf->sf_crcount && sdeleted); | |
1467 | return psf->sf_crcount && !gdeleted && !sdeleted; | |
1468 | } | |
a50feda5 | 1469 | return false; |
1da177e4 LT |
1470 | } |
1471 | ||
1472 | static int | |
1473 | mld_scount(struct ifmcaddr6 *pmc, int type, int gdeleted, int sdeleted) | |
1474 | { | |
1475 | struct ip6_sf_list *psf; | |
1476 | int scount = 0; | |
1477 | ||
1478 | for (psf=pmc->mca_sources; psf; psf=psf->sf_next) { | |
1479 | if (!is_in(pmc, psf, type, gdeleted, sdeleted)) | |
1480 | continue; | |
1481 | scount++; | |
1482 | } | |
1483 | return scount; | |
1484 | } | |
1485 | ||
2576f17d YH |
1486 | static void ip6_mc_hdr(struct sock *sk, struct sk_buff *skb, |
1487 | struct net_device *dev, | |
1488 | const struct in6_addr *saddr, | |
1489 | const struct in6_addr *daddr, | |
1490 | int proto, int len) | |
1491 | { | |
1492 | struct ipv6hdr *hdr; | |
1493 | ||
1494 | skb->protocol = htons(ETH_P_IPV6); | |
1495 | skb->dev = dev; | |
1496 | ||
1497 | skb_reset_network_header(skb); | |
1498 | skb_put(skb, sizeof(struct ipv6hdr)); | |
1499 | hdr = ipv6_hdr(skb); | |
1500 | ||
1501 | ip6_flow_hdr(hdr, 0, 0); | |
1502 | ||
1503 | hdr->payload_len = htons(len); | |
1504 | hdr->nexthdr = proto; | |
1505 | hdr->hop_limit = inet6_sk(sk)->hop_limit; | |
1506 | ||
1507 | hdr->saddr = *saddr; | |
1508 | hdr->daddr = *daddr; | |
1509 | } | |
1510 | ||
8965779d | 1511 | static struct sk_buff *mld_newpack(struct inet6_dev *idev, int size) |
1da177e4 | 1512 | { |
8965779d | 1513 | struct net_device *dev = idev->dev; |
c346dca1 | 1514 | struct net *net = dev_net(dev); |
b8ad0cbc | 1515 | struct sock *sk = net->ipv6.igmp_sk; |
1da177e4 LT |
1516 | struct sk_buff *skb; |
1517 | struct mld2_report *pmr; | |
1518 | struct in6_addr addr_buf; | |
d7aabf22 | 1519 | const struct in6_addr *saddr; |
a7ae1992 HX |
1520 | int hlen = LL_RESERVED_SPACE(dev); |
1521 | int tlen = dev->needed_tailroom; | |
1da177e4 LT |
1522 | int err; |
1523 | u8 ra[8] = { IPPROTO_ICMPV6, 0, | |
1524 | IPV6_TLV_ROUTERALERT, 2, 0, 0, | |
1525 | IPV6_TLV_PADN, 0 }; | |
1526 | ||
1527 | /* we assume size > sizeof(ra) here */ | |
a7ae1992 | 1528 | size += hlen + tlen; |
72e09ad1 ED |
1529 | /* limit our allocations to order-0 page */ |
1530 | size = min_t(int, size, SKB_MAX_ORDER(0, 0)); | |
1531 | skb = sock_alloc_send_skb(sk, size, 1, &err); | |
1da177e4 | 1532 | |
cfcabdcc | 1533 | if (!skb) |
1da177e4 LT |
1534 | return NULL; |
1535 | ||
9d4a0314 | 1536 | skb->priority = TC_PRIO_CONTROL; |
a7ae1992 | 1537 | skb_reserve(skb, hlen); |
1da177e4 | 1538 | |
8965779d | 1539 | if (__ipv6_get_lladdr(idev, &addr_buf, IFA_F_TENTATIVE)) { |
1da177e4 | 1540 | /* <draft-ietf-magma-mld-source-05.txt>: |
1ab1457c | 1541 | * use unspecified address as the source address |
1da177e4 LT |
1542 | * when a valid link-local address is not available. |
1543 | */ | |
d7aabf22 YH |
1544 | saddr = &in6addr_any; |
1545 | } else | |
1546 | saddr = &addr_buf; | |
1da177e4 | 1547 | |
2576f17d | 1548 | ip6_mc_hdr(sk, skb, dev, saddr, &mld2_all_mcr, NEXTHDR_HOP, 0); |
1da177e4 LT |
1549 | |
1550 | memcpy(skb_put(skb, sizeof(ra)), ra, sizeof(ra)); | |
1551 | ||
27a884dc | 1552 | skb_set_transport_header(skb, skb_tail_pointer(skb) - skb->data); |
d10ba34b ACM |
1553 | skb_put(skb, sizeof(*pmr)); |
1554 | pmr = (struct mld2_report *)skb_transport_header(skb); | |
6e7cb837 YH |
1555 | pmr->mld2r_type = ICMPV6_MLD2_REPORT; |
1556 | pmr->mld2r_resv1 = 0; | |
1557 | pmr->mld2r_cksum = 0; | |
1558 | pmr->mld2r_resv2 = 0; | |
1559 | pmr->mld2r_ngrec = 0; | |
1da177e4 LT |
1560 | return skb; |
1561 | } | |
1562 | ||
1563 | static void mld_sendpack(struct sk_buff *skb) | |
1564 | { | |
0660e03f | 1565 | struct ipv6hdr *pip6 = ipv6_hdr(skb); |
9c70220b ACM |
1566 | struct mld2_report *pmr = |
1567 | (struct mld2_report *)skb_transport_header(skb); | |
1da177e4 | 1568 | int payload_len, mldlen; |
96b52e61 | 1569 | struct inet6_dev *idev; |
c346dca1 | 1570 | struct net *net = dev_net(skb->dev); |
1da177e4 | 1571 | int err; |
4c9483b2 | 1572 | struct flowi6 fl6; |
adf30907 | 1573 | struct dst_entry *dst; |
1da177e4 | 1574 | |
96b52e61 ED |
1575 | rcu_read_lock(); |
1576 | idev = __in6_dev_get(skb->dev); | |
edf391ff NH |
1577 | IP6_UPD_PO_STATS(net, idev, IPSTATS_MIB_OUT, skb->len); |
1578 | ||
29a3cad5 SH |
1579 | payload_len = (skb_tail_pointer(skb) - skb_network_header(skb)) - |
1580 | sizeof(*pip6); | |
1581 | mldlen = skb_tail_pointer(skb) - skb_transport_header(skb); | |
1da177e4 LT |
1582 | pip6->payload_len = htons(payload_len); |
1583 | ||
6e7cb837 YH |
1584 | pmr->mld2r_cksum = csum_ipv6_magic(&pip6->saddr, &pip6->daddr, mldlen, |
1585 | IPPROTO_ICMPV6, | |
1586 | csum_partial(skb_transport_header(skb), | |
1587 | mldlen, 0)); | |
41927178 | 1588 | |
4c9483b2 | 1589 | icmpv6_flow_init(net->ipv6.igmp_sk, &fl6, ICMPV6_MLD2_REPORT, |
41927178 YH |
1590 | &ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr, |
1591 | skb->dev->ifindex); | |
12fd84f4 | 1592 | dst = icmp6_dst_alloc(skb->dev, &fl6); |
41927178 | 1593 | |
452edd59 DM |
1594 | err = 0; |
1595 | if (IS_ERR(dst)) { | |
1596 | err = PTR_ERR(dst); | |
1597 | dst = NULL; | |
1598 | } | |
adf30907 | 1599 | skb_dst_set(skb, dst); |
41927178 YH |
1600 | if (err) |
1601 | goto err_out; | |
1602 | ||
edf391ff NH |
1603 | payload_len = skb->len; |
1604 | ||
b2e0b385 | 1605 | err = NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT, skb, NULL, skb->dev, |
41927178 YH |
1606 | dst_output); |
1607 | out: | |
1da177e4 | 1608 | if (!err) { |
5a57d4c7 | 1609 | ICMP6MSGOUT_INC_STATS_BH(net, idev, ICMPV6_MLD2_REPORT); |
e41b5368 | 1610 | ICMP6_INC_STATS_BH(net, idev, ICMP6_MIB_OUTMSGS); |
edf391ff | 1611 | IP6_UPD_PO_STATS_BH(net, idev, IPSTATS_MIB_OUTMCAST, payload_len); |
1da177e4 | 1612 | } else |
483a47d2 | 1613 | IP6_INC_STATS_BH(net, idev, IPSTATS_MIB_OUTDISCARDS); |
1da177e4 | 1614 | |
96b52e61 | 1615 | rcu_read_unlock(); |
41927178 YH |
1616 | return; |
1617 | ||
1618 | err_out: | |
1619 | kfree_skb(skb); | |
1620 | goto out; | |
1da177e4 LT |
1621 | } |
1622 | ||
1623 | static int grec_size(struct ifmcaddr6 *pmc, int type, int gdel, int sdel) | |
1624 | { | |
fab10fe3 | 1625 | return sizeof(struct mld2_grec) + 16 * mld_scount(pmc,type,gdel,sdel); |
1da177e4 LT |
1626 | } |
1627 | ||
1628 | static struct sk_buff *add_grhead(struct sk_buff *skb, struct ifmcaddr6 *pmc, | |
1629 | int type, struct mld2_grec **ppgr) | |
1630 | { | |
1631 | struct net_device *dev = pmc->idev->dev; | |
1632 | struct mld2_report *pmr; | |
1633 | struct mld2_grec *pgr; | |
1634 | ||
1635 | if (!skb) | |
8965779d | 1636 | skb = mld_newpack(pmc->idev, dev->mtu); |
1da177e4 LT |
1637 | if (!skb) |
1638 | return NULL; | |
1639 | pgr = (struct mld2_grec *)skb_put(skb, sizeof(struct mld2_grec)); | |
1640 | pgr->grec_type = type; | |
1641 | pgr->grec_auxwords = 0; | |
1642 | pgr->grec_nsrcs = 0; | |
1643 | pgr->grec_mca = pmc->mca_addr; /* structure copy */ | |
9c70220b | 1644 | pmr = (struct mld2_report *)skb_transport_header(skb); |
6e7cb837 | 1645 | pmr->mld2r_ngrec = htons(ntohs(pmr->mld2r_ngrec)+1); |
1da177e4 LT |
1646 | *ppgr = pgr; |
1647 | return skb; | |
1648 | } | |
1649 | ||
1650 | #define AVAILABLE(skb) ((skb) ? ((skb)->dev ? (skb)->dev->mtu - (skb)->len : \ | |
1651 | skb_tailroom(skb)) : 0) | |
1652 | ||
1653 | static struct sk_buff *add_grec(struct sk_buff *skb, struct ifmcaddr6 *pmc, | |
1654 | int type, int gdeleted, int sdeleted) | |
1655 | { | |
8965779d AW |
1656 | struct inet6_dev *idev = pmc->idev; |
1657 | struct net_device *dev = idev->dev; | |
1da177e4 LT |
1658 | struct mld2_report *pmr; |
1659 | struct mld2_grec *pgr = NULL; | |
1660 | struct ip6_sf_list *psf, *psf_next, *psf_prev, **psf_list; | |
5ab4a6c8 | 1661 | int scount, stotal, first, isquery, truncate; |
1da177e4 LT |
1662 | |
1663 | if (pmc->mca_flags & MAF_NOREPORT) | |
1664 | return skb; | |
1665 | ||
1666 | isquery = type == MLD2_MODE_IS_INCLUDE || | |
1667 | type == MLD2_MODE_IS_EXCLUDE; | |
1668 | truncate = type == MLD2_MODE_IS_EXCLUDE || | |
1669 | type == MLD2_CHANGE_TO_EXCLUDE; | |
1670 | ||
5ab4a6c8 DS |
1671 | stotal = scount = 0; |
1672 | ||
1da177e4 LT |
1673 | psf_list = sdeleted ? &pmc->mca_tomb : &pmc->mca_sources; |
1674 | ||
5ab4a6c8 DS |
1675 | if (!*psf_list) |
1676 | goto empty_source; | |
1677 | ||
9c70220b | 1678 | pmr = skb ? (struct mld2_report *)skb_transport_header(skb) : NULL; |
1da177e4 LT |
1679 | |
1680 | /* EX and TO_EX get a fresh packet, if needed */ | |
1681 | if (truncate) { | |
6e7cb837 | 1682 | if (pmr && pmr->mld2r_ngrec && |
1da177e4 LT |
1683 | AVAILABLE(skb) < grec_size(pmc, type, gdeleted, sdeleted)) { |
1684 | if (skb) | |
1685 | mld_sendpack(skb); | |
8965779d | 1686 | skb = mld_newpack(idev, dev->mtu); |
1da177e4 LT |
1687 | } |
1688 | } | |
1689 | first = 1; | |
1da177e4 LT |
1690 | psf_prev = NULL; |
1691 | for (psf=*psf_list; psf; psf=psf_next) { | |
1692 | struct in6_addr *psrc; | |
1693 | ||
1694 | psf_next = psf->sf_next; | |
1695 | ||
1696 | if (!is_in(pmc, psf, type, gdeleted, sdeleted)) { | |
1697 | psf_prev = psf; | |
1698 | continue; | |
1699 | } | |
1700 | ||
1701 | /* clear marks on query responses */ | |
1702 | if (isquery) | |
1703 | psf->sf_gsresp = 0; | |
1704 | ||
1705 | if (AVAILABLE(skb) < sizeof(*psrc) + | |
1706 | first*sizeof(struct mld2_grec)) { | |
1707 | if (truncate && !first) | |
1708 | break; /* truncate these */ | |
1709 | if (pgr) | |
1710 | pgr->grec_nsrcs = htons(scount); | |
1711 | if (skb) | |
1712 | mld_sendpack(skb); | |
8965779d | 1713 | skb = mld_newpack(idev, dev->mtu); |
1da177e4 LT |
1714 | first = 1; |
1715 | scount = 0; | |
1716 | } | |
1717 | if (first) { | |
1718 | skb = add_grhead(skb, pmc, type, &pgr); | |
1719 | first = 0; | |
1720 | } | |
cc63f70b AD |
1721 | if (!skb) |
1722 | return NULL; | |
1da177e4 LT |
1723 | psrc = (struct in6_addr *)skb_put(skb, sizeof(*psrc)); |
1724 | *psrc = psf->sf_addr; | |
5ab4a6c8 | 1725 | scount++; stotal++; |
1da177e4 LT |
1726 | if ((type == MLD2_ALLOW_NEW_SOURCES || |
1727 | type == MLD2_BLOCK_OLD_SOURCES) && psf->sf_crcount) { | |
1728 | psf->sf_crcount--; | |
1729 | if ((sdeleted || gdeleted) && psf->sf_crcount == 0) { | |
1730 | if (psf_prev) | |
1731 | psf_prev->sf_next = psf->sf_next; | |
1732 | else | |
1733 | *psf_list = psf->sf_next; | |
1734 | kfree(psf); | |
1735 | continue; | |
1736 | } | |
1737 | } | |
1738 | psf_prev = psf; | |
1739 | } | |
5ab4a6c8 DS |
1740 | |
1741 | empty_source: | |
1742 | if (!stotal) { | |
1743 | if (type == MLD2_ALLOW_NEW_SOURCES || | |
1744 | type == MLD2_BLOCK_OLD_SOURCES) | |
1745 | return skb; | |
1746 | if (pmc->mca_crcount || isquery) { | |
1747 | /* make sure we have room for group header */ | |
1748 | if (skb && AVAILABLE(skb) < sizeof(struct mld2_grec)) { | |
1749 | mld_sendpack(skb); | |
1750 | skb = NULL; /* add_grhead will get a new one */ | |
1751 | } | |
1752 | skb = add_grhead(skb, pmc, type, &pgr); | |
1753 | } | |
1754 | } | |
1da177e4 LT |
1755 | if (pgr) |
1756 | pgr->grec_nsrcs = htons(scount); | |
1757 | ||
1758 | if (isquery) | |
1759 | pmc->mca_flags &= ~MAF_GSQUERY; /* clear query state */ | |
1760 | return skb; | |
1761 | } | |
1762 | ||
1763 | static void mld_send_report(struct inet6_dev *idev, struct ifmcaddr6 *pmc) | |
1764 | { | |
1765 | struct sk_buff *skb = NULL; | |
1766 | int type; | |
1767 | ||
8965779d | 1768 | read_lock_bh(&idev->lock); |
1da177e4 | 1769 | if (!pmc) { |
1da177e4 LT |
1770 | for (pmc=idev->mc_list; pmc; pmc=pmc->next) { |
1771 | if (pmc->mca_flags & MAF_NOREPORT) | |
1772 | continue; | |
1773 | spin_lock_bh(&pmc->mca_lock); | |
1774 | if (pmc->mca_sfcount[MCAST_EXCLUDE]) | |
1775 | type = MLD2_MODE_IS_EXCLUDE; | |
1776 | else | |
1777 | type = MLD2_MODE_IS_INCLUDE; | |
1778 | skb = add_grec(skb, pmc, type, 0, 0); | |
1779 | spin_unlock_bh(&pmc->mca_lock); | |
1780 | } | |
1da177e4 LT |
1781 | } else { |
1782 | spin_lock_bh(&pmc->mca_lock); | |
1783 | if (pmc->mca_sfcount[MCAST_EXCLUDE]) | |
1784 | type = MLD2_MODE_IS_EXCLUDE; | |
1785 | else | |
1786 | type = MLD2_MODE_IS_INCLUDE; | |
1787 | skb = add_grec(skb, pmc, type, 0, 0); | |
1788 | spin_unlock_bh(&pmc->mca_lock); | |
1789 | } | |
8965779d | 1790 | read_unlock_bh(&idev->lock); |
1da177e4 LT |
1791 | if (skb) |
1792 | mld_sendpack(skb); | |
1793 | } | |
1794 | ||
1795 | /* | |
1796 | * remove zero-count source records from a source filter list | |
1797 | */ | |
1798 | static void mld_clear_zeros(struct ip6_sf_list **ppsf) | |
1799 | { | |
1800 | struct ip6_sf_list *psf_prev, *psf_next, *psf; | |
1801 | ||
1802 | psf_prev = NULL; | |
1803 | for (psf=*ppsf; psf; psf = psf_next) { | |
1804 | psf_next = psf->sf_next; | |
1805 | if (psf->sf_crcount == 0) { | |
1806 | if (psf_prev) | |
1807 | psf_prev->sf_next = psf->sf_next; | |
1808 | else | |
1809 | *ppsf = psf->sf_next; | |
1810 | kfree(psf); | |
1811 | } else | |
1812 | psf_prev = psf; | |
1813 | } | |
1814 | } | |
1815 | ||
1816 | static void mld_send_cr(struct inet6_dev *idev) | |
1817 | { | |
1818 | struct ifmcaddr6 *pmc, *pmc_prev, *pmc_next; | |
1819 | struct sk_buff *skb = NULL; | |
1820 | int type, dtype; | |
1821 | ||
1822 | read_lock_bh(&idev->lock); | |
6457d26b | 1823 | spin_lock(&idev->mc_lock); |
1da177e4 LT |
1824 | |
1825 | /* deleted MCA's */ | |
1826 | pmc_prev = NULL; | |
1827 | for (pmc=idev->mc_tomb; pmc; pmc=pmc_next) { | |
1828 | pmc_next = pmc->next; | |
1829 | if (pmc->mca_sfmode == MCAST_INCLUDE) { | |
1830 | type = MLD2_BLOCK_OLD_SOURCES; | |
1831 | dtype = MLD2_BLOCK_OLD_SOURCES; | |
1832 | skb = add_grec(skb, pmc, type, 1, 0); | |
1833 | skb = add_grec(skb, pmc, dtype, 1, 1); | |
1834 | } | |
1835 | if (pmc->mca_crcount) { | |
1da177e4 LT |
1836 | if (pmc->mca_sfmode == MCAST_EXCLUDE) { |
1837 | type = MLD2_CHANGE_TO_INCLUDE; | |
1838 | skb = add_grec(skb, pmc, type, 1, 0); | |
1839 | } | |
5ab4a6c8 | 1840 | pmc->mca_crcount--; |
1da177e4 LT |
1841 | if (pmc->mca_crcount == 0) { |
1842 | mld_clear_zeros(&pmc->mca_tomb); | |
1843 | mld_clear_zeros(&pmc->mca_sources); | |
1844 | } | |
1845 | } | |
1846 | if (pmc->mca_crcount == 0 && !pmc->mca_tomb && | |
1847 | !pmc->mca_sources) { | |
1848 | if (pmc_prev) | |
1849 | pmc_prev->next = pmc_next; | |
1850 | else | |
1851 | idev->mc_tomb = pmc_next; | |
1852 | in6_dev_put(pmc->idev); | |
1853 | kfree(pmc); | |
1854 | } else | |
1855 | pmc_prev = pmc; | |
1856 | } | |
6457d26b | 1857 | spin_unlock(&idev->mc_lock); |
1da177e4 LT |
1858 | |
1859 | /* change recs */ | |
1860 | for (pmc=idev->mc_list; pmc; pmc=pmc->next) { | |
1861 | spin_lock_bh(&pmc->mca_lock); | |
1862 | if (pmc->mca_sfcount[MCAST_EXCLUDE]) { | |
1863 | type = MLD2_BLOCK_OLD_SOURCES; | |
1864 | dtype = MLD2_ALLOW_NEW_SOURCES; | |
1865 | } else { | |
1866 | type = MLD2_ALLOW_NEW_SOURCES; | |
1867 | dtype = MLD2_BLOCK_OLD_SOURCES; | |
1868 | } | |
1869 | skb = add_grec(skb, pmc, type, 0, 0); | |
1870 | skb = add_grec(skb, pmc, dtype, 0, 1); /* deleted sources */ | |
1871 | ||
1872 | /* filter mode changes */ | |
1873 | if (pmc->mca_crcount) { | |
1da177e4 LT |
1874 | if (pmc->mca_sfmode == MCAST_EXCLUDE) |
1875 | type = MLD2_CHANGE_TO_EXCLUDE; | |
1876 | else | |
1877 | type = MLD2_CHANGE_TO_INCLUDE; | |
1878 | skb = add_grec(skb, pmc, type, 0, 0); | |
5ab4a6c8 | 1879 | pmc->mca_crcount--; |
1da177e4 LT |
1880 | } |
1881 | spin_unlock_bh(&pmc->mca_lock); | |
1882 | } | |
1883 | read_unlock_bh(&idev->lock); | |
1884 | if (!skb) | |
1885 | return; | |
1886 | (void) mld_sendpack(skb); | |
1887 | } | |
1888 | ||
1889 | static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type) | |
1890 | { | |
c346dca1 | 1891 | struct net *net = dev_net(dev); |
b8ad0cbc | 1892 | struct sock *sk = net->ipv6.igmp_sk; |
1da177e4 | 1893 | struct inet6_dev *idev; |
1ab1457c | 1894 | struct sk_buff *skb; |
6e7cb837 | 1895 | struct mld_msg *hdr; |
d7aabf22 | 1896 | const struct in6_addr *snd_addr, *saddr; |
1da177e4 | 1897 | struct in6_addr addr_buf; |
a7ae1992 HX |
1898 | int hlen = LL_RESERVED_SPACE(dev); |
1899 | int tlen = dev->needed_tailroom; | |
1da177e4 LT |
1900 | int err, len, payload_len, full_len; |
1901 | u8 ra[8] = { IPPROTO_ICMPV6, 0, | |
1902 | IPV6_TLV_ROUTERALERT, 2, 0, 0, | |
1903 | IPV6_TLV_PADN, 0 }; | |
4c9483b2 | 1904 | struct flowi6 fl6; |
adf30907 | 1905 | struct dst_entry *dst; |
1da177e4 | 1906 | |
f3ee4010 YH |
1907 | if (type == ICMPV6_MGM_REDUCTION) |
1908 | snd_addr = &in6addr_linklocal_allrouters; | |
1909 | else | |
1910 | snd_addr = addr; | |
1da177e4 LT |
1911 | |
1912 | len = sizeof(struct icmp6hdr) + sizeof(struct in6_addr); | |
1913 | payload_len = len + sizeof(ra); | |
1914 | full_len = sizeof(struct ipv6hdr) + payload_len; | |
1915 | ||
edf391ff NH |
1916 | rcu_read_lock(); |
1917 | IP6_UPD_PO_STATS(net, __in6_dev_get(dev), | |
1918 | IPSTATS_MIB_OUT, full_len); | |
1919 | rcu_read_unlock(); | |
1920 | ||
a7ae1992 | 1921 | skb = sock_alloc_send_skb(sk, hlen + tlen + full_len, 1, &err); |
1da177e4 LT |
1922 | |
1923 | if (skb == NULL) { | |
a11d206d | 1924 | rcu_read_lock(); |
3bd653c8 | 1925 | IP6_INC_STATS(net, __in6_dev_get(dev), |
a11d206d YH |
1926 | IPSTATS_MIB_OUTDISCARDS); |
1927 | rcu_read_unlock(); | |
1da177e4 LT |
1928 | return; |
1929 | } | |
9d4a0314 | 1930 | skb->priority = TC_PRIO_CONTROL; |
a7ae1992 | 1931 | skb_reserve(skb, hlen); |
1da177e4 | 1932 | |
95c385b4 | 1933 | if (ipv6_get_lladdr(dev, &addr_buf, IFA_F_TENTATIVE)) { |
1da177e4 | 1934 | /* <draft-ietf-magma-mld-source-05.txt>: |
1ab1457c | 1935 | * use unspecified address as the source address |
1da177e4 LT |
1936 | * when a valid link-local address is not available. |
1937 | */ | |
d7aabf22 YH |
1938 | saddr = &in6addr_any; |
1939 | } else | |
1940 | saddr = &addr_buf; | |
1da177e4 | 1941 | |
2576f17d | 1942 | ip6_mc_hdr(sk, skb, dev, saddr, snd_addr, NEXTHDR_HOP, payload_len); |
1da177e4 LT |
1943 | |
1944 | memcpy(skb_put(skb, sizeof(ra)), ra, sizeof(ra)); | |
1945 | ||
6e7cb837 YH |
1946 | hdr = (struct mld_msg *) skb_put(skb, sizeof(struct mld_msg)); |
1947 | memset(hdr, 0, sizeof(struct mld_msg)); | |
1948 | hdr->mld_type = type; | |
4e3fd7a0 | 1949 | hdr->mld_mca = *addr; |
1da177e4 | 1950 | |
6e7cb837 YH |
1951 | hdr->mld_cksum = csum_ipv6_magic(saddr, snd_addr, len, |
1952 | IPPROTO_ICMPV6, | |
1953 | csum_partial(hdr, len, 0)); | |
1da177e4 | 1954 | |
96b52e61 ED |
1955 | rcu_read_lock(); |
1956 | idev = __in6_dev_get(skb->dev); | |
1da177e4 | 1957 | |
4c9483b2 | 1958 | icmpv6_flow_init(sk, &fl6, type, |
41927178 YH |
1959 | &ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr, |
1960 | skb->dev->ifindex); | |
12fd84f4 | 1961 | dst = icmp6_dst_alloc(skb->dev, &fl6); |
452edd59 DM |
1962 | if (IS_ERR(dst)) { |
1963 | err = PTR_ERR(dst); | |
41927178 | 1964 | goto err_out; |
452edd59 | 1965 | } |
41927178 | 1966 | |
adf30907 | 1967 | skb_dst_set(skb, dst); |
b2e0b385 | 1968 | err = NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT, skb, NULL, skb->dev, |
41927178 YH |
1969 | dst_output); |
1970 | out: | |
1da177e4 | 1971 | if (!err) { |
5c5d244b | 1972 | ICMP6MSGOUT_INC_STATS(net, idev, type); |
a862f6a6 | 1973 | ICMP6_INC_STATS(net, idev, ICMP6_MIB_OUTMSGS); |
edf391ff | 1974 | IP6_UPD_PO_STATS(net, idev, IPSTATS_MIB_OUTMCAST, full_len); |
1da177e4 | 1975 | } else |
3bd653c8 | 1976 | IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTDISCARDS); |
1da177e4 | 1977 | |
96b52e61 | 1978 | rcu_read_unlock(); |
1da177e4 | 1979 | return; |
41927178 YH |
1980 | |
1981 | err_out: | |
1982 | kfree_skb(skb); | |
1983 | goto out; | |
1da177e4 LT |
1984 | } |
1985 | ||
b173ee48 HFS |
1986 | static void mld_resend_report(struct inet6_dev *idev) |
1987 | { | |
6c567b78 | 1988 | if (mld_in_v1_mode(idev)) { |
b173ee48 HFS |
1989 | struct ifmcaddr6 *mcaddr; |
1990 | read_lock_bh(&idev->lock); | |
1991 | for (mcaddr = idev->mc_list; mcaddr; mcaddr = mcaddr->next) { | |
1992 | if (!(mcaddr->mca_flags & MAF_NOREPORT)) | |
1993 | igmp6_send(&mcaddr->mca_addr, idev->dev, | |
1994 | ICMPV6_MGM_REPORT); | |
1995 | } | |
1996 | read_unlock_bh(&idev->lock); | |
1997 | } else { | |
1998 | mld_send_report(idev, NULL); | |
1999 | } | |
2000 | } | |
2001 | ||
2002 | void ipv6_mc_dad_complete(struct inet6_dev *idev) | |
2003 | { | |
2004 | idev->mc_dad_count = idev->mc_qrv; | |
2005 | if (idev->mc_dad_count) { | |
2006 | mld_resend_report(idev); | |
2007 | idev->mc_dad_count--; | |
2008 | if (idev->mc_dad_count) | |
2009 | mld_dad_start_timer(idev, idev->mc_maxdelay); | |
2010 | } | |
2011 | } | |
2012 | ||
2013 | static void mld_dad_timer_expire(unsigned long data) | |
2014 | { | |
2015 | struct inet6_dev *idev = (struct inet6_dev *)data; | |
2016 | ||
2017 | mld_resend_report(idev); | |
2018 | if (idev->mc_dad_count) { | |
2019 | idev->mc_dad_count--; | |
2020 | if (idev->mc_dad_count) | |
2021 | mld_dad_start_timer(idev, idev->mc_maxdelay); | |
2022 | } | |
2023 | __in6_dev_put(idev); | |
2024 | } | |
2025 | ||
1da177e4 | 2026 | static int ip6_mc_del1_src(struct ifmcaddr6 *pmc, int sfmode, |
b71d1d42 | 2027 | const struct in6_addr *psfsrc) |
1da177e4 LT |
2028 | { |
2029 | struct ip6_sf_list *psf, *psf_prev; | |
2030 | int rv = 0; | |
2031 | ||
2032 | psf_prev = NULL; | |
2033 | for (psf=pmc->mca_sources; psf; psf=psf->sf_next) { | |
2034 | if (ipv6_addr_equal(&psf->sf_addr, psfsrc)) | |
2035 | break; | |
2036 | psf_prev = psf; | |
2037 | } | |
2038 | if (!psf || psf->sf_count[sfmode] == 0) { | |
2039 | /* source filter not found, or count wrong => bug */ | |
2040 | return -ESRCH; | |
2041 | } | |
2042 | psf->sf_count[sfmode]--; | |
2043 | if (!psf->sf_count[MCAST_INCLUDE] && !psf->sf_count[MCAST_EXCLUDE]) { | |
2044 | struct inet6_dev *idev = pmc->idev; | |
2045 | ||
2046 | /* no more filters for this source */ | |
2047 | if (psf_prev) | |
2048 | psf_prev->sf_next = psf->sf_next; | |
2049 | else | |
2050 | pmc->mca_sources = psf->sf_next; | |
2051 | if (psf->sf_oldin && !(pmc->mca_flags & MAF_NOREPORT) && | |
6c567b78 | 2052 | !mld_in_v1_mode(idev)) { |
1da177e4 LT |
2053 | psf->sf_crcount = idev->mc_qrv; |
2054 | psf->sf_next = pmc->mca_tomb; | |
2055 | pmc->mca_tomb = psf; | |
2056 | rv = 1; | |
2057 | } else | |
2058 | kfree(psf); | |
2059 | } | |
2060 | return rv; | |
2061 | } | |
2062 | ||
b71d1d42 ED |
2063 | static int ip6_mc_del_src(struct inet6_dev *idev, const struct in6_addr *pmca, |
2064 | int sfmode, int sfcount, const struct in6_addr *psfsrc, | |
1da177e4 LT |
2065 | int delta) |
2066 | { | |
2067 | struct ifmcaddr6 *pmc; | |
2068 | int changerec = 0; | |
2069 | int i, err; | |
2070 | ||
2071 | if (!idev) | |
2072 | return -ENODEV; | |
2073 | read_lock_bh(&idev->lock); | |
2074 | for (pmc=idev->mc_list; pmc; pmc=pmc->next) { | |
2075 | if (ipv6_addr_equal(pmca, &pmc->mca_addr)) | |
2076 | break; | |
2077 | } | |
2078 | if (!pmc) { | |
2079 | /* MCA not found?? bug */ | |
2080 | read_unlock_bh(&idev->lock); | |
2081 | return -ESRCH; | |
2082 | } | |
2083 | spin_lock_bh(&pmc->mca_lock); | |
2084 | sf_markstate(pmc); | |
2085 | if (!delta) { | |
2086 | if (!pmc->mca_sfcount[sfmode]) { | |
2087 | spin_unlock_bh(&pmc->mca_lock); | |
2088 | read_unlock_bh(&idev->lock); | |
2089 | return -EINVAL; | |
2090 | } | |
2091 | pmc->mca_sfcount[sfmode]--; | |
2092 | } | |
2093 | err = 0; | |
2094 | for (i=0; i<sfcount; i++) { | |
2095 | int rv = ip6_mc_del1_src(pmc, sfmode, &psfsrc[i]); | |
2096 | ||
2097 | changerec |= rv > 0; | |
2098 | if (!err && rv < 0) | |
2099 | err = rv; | |
2100 | } | |
2101 | if (pmc->mca_sfmode == MCAST_EXCLUDE && | |
2102 | pmc->mca_sfcount[MCAST_EXCLUDE] == 0 && | |
2103 | pmc->mca_sfcount[MCAST_INCLUDE]) { | |
2104 | struct ip6_sf_list *psf; | |
2105 | ||
2106 | /* filter mode change */ | |
2107 | pmc->mca_sfmode = MCAST_INCLUDE; | |
2108 | pmc->mca_crcount = idev->mc_qrv; | |
2109 | idev->mc_ifc_count = pmc->mca_crcount; | |
2110 | for (psf=pmc->mca_sources; psf; psf = psf->sf_next) | |
2111 | psf->sf_crcount = 0; | |
2112 | mld_ifc_event(pmc->idev); | |
2113 | } else if (sf_setstate(pmc) || changerec) | |
2114 | mld_ifc_event(pmc->idev); | |
2115 | spin_unlock_bh(&pmc->mca_lock); | |
2116 | read_unlock_bh(&idev->lock); | |
2117 | return err; | |
2118 | } | |
2119 | ||
2120 | /* | |
2121 | * Add multicast single-source filter to the interface list | |
2122 | */ | |
2123 | static int ip6_mc_add1_src(struct ifmcaddr6 *pmc, int sfmode, | |
99d2f47a | 2124 | const struct in6_addr *psfsrc) |
1da177e4 LT |
2125 | { |
2126 | struct ip6_sf_list *psf, *psf_prev; | |
2127 | ||
2128 | psf_prev = NULL; | |
2129 | for (psf=pmc->mca_sources; psf; psf=psf->sf_next) { | |
2130 | if (ipv6_addr_equal(&psf->sf_addr, psfsrc)) | |
2131 | break; | |
2132 | psf_prev = psf; | |
2133 | } | |
2134 | if (!psf) { | |
0c600eda | 2135 | psf = kzalloc(sizeof(*psf), GFP_ATOMIC); |
1da177e4 LT |
2136 | if (!psf) |
2137 | return -ENOBUFS; | |
0c600eda | 2138 | |
1da177e4 LT |
2139 | psf->sf_addr = *psfsrc; |
2140 | if (psf_prev) { | |
2141 | psf_prev->sf_next = psf; | |
2142 | } else | |
2143 | pmc->mca_sources = psf; | |
2144 | } | |
2145 | psf->sf_count[sfmode]++; | |
2146 | return 0; | |
2147 | } | |
2148 | ||
2149 | static void sf_markstate(struct ifmcaddr6 *pmc) | |
2150 | { | |
2151 | struct ip6_sf_list *psf; | |
2152 | int mca_xcount = pmc->mca_sfcount[MCAST_EXCLUDE]; | |
2153 | ||
2154 | for (psf=pmc->mca_sources; psf; psf=psf->sf_next) | |
2155 | if (pmc->mca_sfcount[MCAST_EXCLUDE]) { | |
2156 | psf->sf_oldin = mca_xcount == | |
2157 | psf->sf_count[MCAST_EXCLUDE] && | |
2158 | !psf->sf_count[MCAST_INCLUDE]; | |
2159 | } else | |
2160 | psf->sf_oldin = psf->sf_count[MCAST_INCLUDE] != 0; | |
2161 | } | |
2162 | ||
2163 | static int sf_setstate(struct ifmcaddr6 *pmc) | |
2164 | { | |
7add2a43 | 2165 | struct ip6_sf_list *psf, *dpsf; |
1da177e4 LT |
2166 | int mca_xcount = pmc->mca_sfcount[MCAST_EXCLUDE]; |
2167 | int qrv = pmc->idev->mc_qrv; | |
2168 | int new_in, rv; | |
2169 | ||
2170 | rv = 0; | |
2171 | for (psf=pmc->mca_sources; psf; psf=psf->sf_next) { | |
2172 | if (pmc->mca_sfcount[MCAST_EXCLUDE]) { | |
2173 | new_in = mca_xcount == psf->sf_count[MCAST_EXCLUDE] && | |
2174 | !psf->sf_count[MCAST_INCLUDE]; | |
2175 | } else | |
2176 | new_in = psf->sf_count[MCAST_INCLUDE] != 0; | |
7add2a43 DS |
2177 | if (new_in) { |
2178 | if (!psf->sf_oldin) { | |
e80e28b6 | 2179 | struct ip6_sf_list *prev = NULL; |
7add2a43 DS |
2180 | |
2181 | for (dpsf=pmc->mca_tomb; dpsf; | |
2182 | dpsf=dpsf->sf_next) { | |
2183 | if (ipv6_addr_equal(&dpsf->sf_addr, | |
2184 | &psf->sf_addr)) | |
2185 | break; | |
2186 | prev = dpsf; | |
2187 | } | |
2188 | if (dpsf) { | |
2189 | if (prev) | |
2190 | prev->sf_next = dpsf->sf_next; | |
2191 | else | |
2192 | pmc->mca_tomb = dpsf->sf_next; | |
2193 | kfree(dpsf); | |
2194 | } | |
2195 | psf->sf_crcount = qrv; | |
2196 | rv++; | |
2197 | } | |
2198 | } else if (psf->sf_oldin) { | |
2199 | psf->sf_crcount = 0; | |
2200 | /* | |
2201 | * add or update "delete" records if an active filter | |
2202 | * is now inactive | |
2203 | */ | |
2204 | for (dpsf=pmc->mca_tomb; dpsf; dpsf=dpsf->sf_next) | |
2205 | if (ipv6_addr_equal(&dpsf->sf_addr, | |
2206 | &psf->sf_addr)) | |
2207 | break; | |
2208 | if (!dpsf) { | |
5d55354f | 2209 | dpsf = kmalloc(sizeof(*dpsf), GFP_ATOMIC); |
7add2a43 DS |
2210 | if (!dpsf) |
2211 | continue; | |
2212 | *dpsf = *psf; | |
2213 | /* pmc->mca_lock held by callers */ | |
2214 | dpsf->sf_next = pmc->mca_tomb; | |
2215 | pmc->mca_tomb = dpsf; | |
2216 | } | |
2217 | dpsf->sf_crcount = qrv; | |
1da177e4 LT |
2218 | rv++; |
2219 | } | |
2220 | } | |
2221 | return rv; | |
2222 | } | |
2223 | ||
2224 | /* | |
2225 | * Add multicast source filter list to the interface list | |
2226 | */ | |
b71d1d42 ED |
2227 | static int ip6_mc_add_src(struct inet6_dev *idev, const struct in6_addr *pmca, |
2228 | int sfmode, int sfcount, const struct in6_addr *psfsrc, | |
1da177e4 LT |
2229 | int delta) |
2230 | { | |
2231 | struct ifmcaddr6 *pmc; | |
2232 | int isexclude; | |
2233 | int i, err; | |
2234 | ||
2235 | if (!idev) | |
2236 | return -ENODEV; | |
2237 | read_lock_bh(&idev->lock); | |
2238 | for (pmc=idev->mc_list; pmc; pmc=pmc->next) { | |
2239 | if (ipv6_addr_equal(pmca, &pmc->mca_addr)) | |
2240 | break; | |
2241 | } | |
2242 | if (!pmc) { | |
2243 | /* MCA not found?? bug */ | |
2244 | read_unlock_bh(&idev->lock); | |
2245 | return -ESRCH; | |
2246 | } | |
2247 | spin_lock_bh(&pmc->mca_lock); | |
2248 | ||
2249 | sf_markstate(pmc); | |
2250 | isexclude = pmc->mca_sfmode == MCAST_EXCLUDE; | |
2251 | if (!delta) | |
2252 | pmc->mca_sfcount[sfmode]++; | |
2253 | err = 0; | |
2254 | for (i=0; i<sfcount; i++) { | |
99d2f47a | 2255 | err = ip6_mc_add1_src(pmc, sfmode, &psfsrc[i]); |
1da177e4 LT |
2256 | if (err) |
2257 | break; | |
2258 | } | |
2259 | if (err) { | |
2260 | int j; | |
2261 | ||
2262 | if (!delta) | |
2263 | pmc->mca_sfcount[sfmode]--; | |
2264 | for (j=0; j<i; j++) | |
78d50217 | 2265 | ip6_mc_del1_src(pmc, sfmode, &psfsrc[j]); |
1da177e4 | 2266 | } else if (isexclude != (pmc->mca_sfcount[MCAST_EXCLUDE] != 0)) { |
1da177e4 LT |
2267 | struct ip6_sf_list *psf; |
2268 | ||
2269 | /* filter mode change */ | |
2270 | if (pmc->mca_sfcount[MCAST_EXCLUDE]) | |
2271 | pmc->mca_sfmode = MCAST_EXCLUDE; | |
2272 | else if (pmc->mca_sfcount[MCAST_INCLUDE]) | |
2273 | pmc->mca_sfmode = MCAST_INCLUDE; | |
2274 | /* else no filters; keep old mode for reports */ | |
2275 | ||
2276 | pmc->mca_crcount = idev->mc_qrv; | |
2277 | idev->mc_ifc_count = pmc->mca_crcount; | |
2278 | for (psf=pmc->mca_sources; psf; psf = psf->sf_next) | |
2279 | psf->sf_crcount = 0; | |
2280 | mld_ifc_event(idev); | |
2281 | } else if (sf_setstate(pmc)) | |
2282 | mld_ifc_event(idev); | |
2283 | spin_unlock_bh(&pmc->mca_lock); | |
2284 | read_unlock_bh(&idev->lock); | |
2285 | return err; | |
2286 | } | |
2287 | ||
2288 | static void ip6_mc_clear_src(struct ifmcaddr6 *pmc) | |
2289 | { | |
2290 | struct ip6_sf_list *psf, *nextpsf; | |
2291 | ||
2292 | for (psf=pmc->mca_tomb; psf; psf=nextpsf) { | |
2293 | nextpsf = psf->sf_next; | |
2294 | kfree(psf); | |
2295 | } | |
2296 | pmc->mca_tomb = NULL; | |
2297 | for (psf=pmc->mca_sources; psf; psf=nextpsf) { | |
2298 | nextpsf = psf->sf_next; | |
2299 | kfree(psf); | |
2300 | } | |
2301 | pmc->mca_sources = NULL; | |
2302 | pmc->mca_sfmode = MCAST_EXCLUDE; | |
de9daad9 | 2303 | pmc->mca_sfcount[MCAST_INCLUDE] = 0; |
1da177e4 LT |
2304 | pmc->mca_sfcount[MCAST_EXCLUDE] = 1; |
2305 | } | |
2306 | ||
2307 | ||
2308 | static void igmp6_join_group(struct ifmcaddr6 *ma) | |
2309 | { | |
2310 | unsigned long delay; | |
2311 | ||
2312 | if (ma->mca_flags & MAF_NOREPORT) | |
2313 | return; | |
2314 | ||
2315 | igmp6_send(&ma->mca_addr, ma->idev->dev, ICMPV6_MGM_REPORT); | |
2316 | ||
fc4eba58 | 2317 | delay = net_random() % unsolicited_report_interval(ma->idev); |
1da177e4 LT |
2318 | |
2319 | spin_lock_bh(&ma->mca_lock); | |
2320 | if (del_timer(&ma->mca_timer)) { | |
2321 | atomic_dec(&ma->mca_refcnt); | |
2322 | delay = ma->mca_timer.expires - jiffies; | |
2323 | } | |
2324 | ||
2325 | if (!mod_timer(&ma->mca_timer, jiffies + delay)) | |
2326 | atomic_inc(&ma->mca_refcnt); | |
2327 | ma->mca_flags |= MAF_TIMER_RUNNING | MAF_LAST_REPORTER; | |
2328 | spin_unlock_bh(&ma->mca_lock); | |
2329 | } | |
2330 | ||
2331 | static int ip6_mc_leave_src(struct sock *sk, struct ipv6_mc_socklist *iml, | |
2332 | struct inet6_dev *idev) | |
2333 | { | |
2334 | int err; | |
2335 | ||
5ab4a6c8 DS |
2336 | /* callers have the socket lock and a write lock on ipv6_sk_mc_lock, |
2337 | * so no other readers or writers of iml or its sflist | |
2338 | */ | |
cfcabdcc | 2339 | if (!iml->sflist) { |
1da177e4 LT |
2340 | /* any-source empty exclude case */ |
2341 | return ip6_mc_del_src(idev, &iml->addr, iml->sfmode, 0, NULL, 0); | |
2342 | } | |
2343 | err = ip6_mc_del_src(idev, &iml->addr, iml->sfmode, | |
2344 | iml->sflist->sl_count, iml->sflist->sl_addr, 0); | |
2345 | sock_kfree_s(sk, iml->sflist, IP6_SFLSIZE(iml->sflist->sl_max)); | |
2346 | iml->sflist = NULL; | |
2347 | return err; | |
2348 | } | |
2349 | ||
2350 | static void igmp6_leave_group(struct ifmcaddr6 *ma) | |
2351 | { | |
6c567b78 | 2352 | if (mld_in_v1_mode(ma->idev)) { |
1da177e4 LT |
2353 | if (ma->mca_flags & MAF_LAST_REPORTER) |
2354 | igmp6_send(&ma->mca_addr, ma->idev->dev, | |
2355 | ICMPV6_MGM_REDUCTION); | |
2356 | } else { | |
2357 | mld_add_delrec(ma->idev, ma); | |
2358 | mld_ifc_event(ma->idev); | |
2359 | } | |
2360 | } | |
2361 | ||
2362 | static void mld_gq_timer_expire(unsigned long data) | |
2363 | { | |
2364 | struct inet6_dev *idev = (struct inet6_dev *)data; | |
2365 | ||
2366 | idev->mc_gq_running = 0; | |
2367 | mld_send_report(idev, NULL); | |
2368 | __in6_dev_put(idev); | |
2369 | } | |
2370 | ||
2371 | static void mld_ifc_timer_expire(unsigned long data) | |
2372 | { | |
2373 | struct inet6_dev *idev = (struct inet6_dev *)data; | |
2374 | ||
2375 | mld_send_cr(idev); | |
2376 | if (idev->mc_ifc_count) { | |
2377 | idev->mc_ifc_count--; | |
2378 | if (idev->mc_ifc_count) | |
2379 | mld_ifc_start_timer(idev, idev->mc_maxdelay); | |
2380 | } | |
2381 | __in6_dev_put(idev); | |
2382 | } | |
2383 | ||
2384 | static void mld_ifc_event(struct inet6_dev *idev) | |
2385 | { | |
6c567b78 | 2386 | if (mld_in_v1_mode(idev)) |
1da177e4 LT |
2387 | return; |
2388 | idev->mc_ifc_count = idev->mc_qrv; | |
2389 | mld_ifc_start_timer(idev, 1); | |
2390 | } | |
2391 | ||
2392 | ||
2393 | static void igmp6_timer_handler(unsigned long data) | |
2394 | { | |
2395 | struct ifmcaddr6 *ma = (struct ifmcaddr6 *) data; | |
2396 | ||
6c567b78 | 2397 | if (mld_in_v1_mode(ma->idev)) |
1da177e4 LT |
2398 | igmp6_send(&ma->mca_addr, ma->idev->dev, ICMPV6_MGM_REPORT); |
2399 | else | |
2400 | mld_send_report(ma->idev, ma); | |
2401 | ||
2402 | spin_lock(&ma->mca_lock); | |
2403 | ma->mca_flags |= MAF_LAST_REPORTER; | |
2404 | ma->mca_flags &= ~MAF_TIMER_RUNNING; | |
2405 | spin_unlock(&ma->mca_lock); | |
2406 | ma_put(ma); | |
2407 | } | |
2408 | ||
75c78500 MS |
2409 | /* Device changing type */ |
2410 | ||
2411 | void ipv6_mc_unmap(struct inet6_dev *idev) | |
2412 | { | |
2413 | struct ifmcaddr6 *i; | |
2414 | ||
2415 | /* Install multicast list, except for all-nodes (already installed) */ | |
2416 | ||
2417 | read_lock_bh(&idev->lock); | |
2418 | for (i = idev->mc_list; i; i = i->next) | |
2419 | igmp6_group_dropped(i); | |
2420 | read_unlock_bh(&idev->lock); | |
2421 | } | |
2422 | ||
2423 | void ipv6_mc_remap(struct inet6_dev *idev) | |
2424 | { | |
2425 | ipv6_mc_up(idev); | |
2426 | } | |
2427 | ||
1da177e4 LT |
2428 | /* Device going down */ |
2429 | ||
2430 | void ipv6_mc_down(struct inet6_dev *idev) | |
2431 | { | |
2432 | struct ifmcaddr6 *i; | |
2433 | ||
2434 | /* Withdraw multicast list */ | |
2435 | ||
2436 | read_lock_bh(&idev->lock); | |
2437 | idev->mc_ifc_count = 0; | |
2438 | if (del_timer(&idev->mc_ifc_timer)) | |
2439 | __in6_dev_put(idev); | |
2440 | idev->mc_gq_running = 0; | |
2441 | if (del_timer(&idev->mc_gq_timer)) | |
2442 | __in6_dev_put(idev); | |
b173ee48 HFS |
2443 | if (del_timer(&idev->mc_dad_timer)) |
2444 | __in6_dev_put(idev); | |
1da177e4 LT |
2445 | |
2446 | for (i = idev->mc_list; i; i=i->next) | |
2447 | igmp6_group_dropped(i); | |
2448 | read_unlock_bh(&idev->lock); | |
2449 | ||
2450 | mld_clear_delrec(idev); | |
2451 | } | |
2452 | ||
2453 | ||
2454 | /* Device going up */ | |
2455 | ||
2456 | void ipv6_mc_up(struct inet6_dev *idev) | |
2457 | { | |
2458 | struct ifmcaddr6 *i; | |
2459 | ||
2460 | /* Install multicast list, except for all-nodes (already installed) */ | |
2461 | ||
2462 | read_lock_bh(&idev->lock); | |
2463 | for (i = idev->mc_list; i; i=i->next) | |
2464 | igmp6_group_added(i); | |
2465 | read_unlock_bh(&idev->lock); | |
2466 | } | |
2467 | ||
2468 | /* IPv6 device initialization. */ | |
2469 | ||
2470 | void ipv6_mc_init_dev(struct inet6_dev *idev) | |
2471 | { | |
1da177e4 | 2472 | write_lock_bh(&idev->lock); |
6457d26b | 2473 | spin_lock_init(&idev->mc_lock); |
1da177e4 | 2474 | idev->mc_gq_running = 0; |
b24b8a24 PE |
2475 | setup_timer(&idev->mc_gq_timer, mld_gq_timer_expire, |
2476 | (unsigned long)idev); | |
1da177e4 LT |
2477 | idev->mc_tomb = NULL; |
2478 | idev->mc_ifc_count = 0; | |
b24b8a24 PE |
2479 | setup_timer(&idev->mc_ifc_timer, mld_ifc_timer_expire, |
2480 | (unsigned long)idev); | |
b173ee48 HFS |
2481 | setup_timer(&idev->mc_dad_timer, mld_dad_timer_expire, |
2482 | (unsigned long)idev); | |
89225d1c | 2483 | |
1da177e4 | 2484 | idev->mc_qrv = MLD_QRV_DEFAULT; |
89225d1c DB |
2485 | idev->mc_qi = MLD_QI_DEFAULT; |
2486 | idev->mc_qri = MLD_QRI_DEFAULT; | |
2487 | ||
fc4eba58 | 2488 | idev->mc_maxdelay = unsolicited_report_interval(idev); |
1da177e4 LT |
2489 | idev->mc_v1_seen = 0; |
2490 | write_unlock_bh(&idev->lock); | |
1da177e4 LT |
2491 | } |
2492 | ||
2493 | /* | |
2494 | * Device is about to be destroyed: clean up. | |
2495 | */ | |
2496 | ||
2497 | void ipv6_mc_destroy_dev(struct inet6_dev *idev) | |
2498 | { | |
2499 | struct ifmcaddr6 *i; | |
1da177e4 LT |
2500 | |
2501 | /* Deactivate timers */ | |
2502 | ipv6_mc_down(idev); | |
2503 | ||
2504 | /* Delete all-nodes address. */ | |
1da177e4 LT |
2505 | /* We cannot call ipv6_dev_mc_dec() directly, our caller in |
2506 | * addrconf.c has NULL'd out dev->ip6_ptr so in6_dev_get() will | |
2507 | * fail. | |
2508 | */ | |
f3ee4010 | 2509 | __ipv6_dev_mc_dec(idev, &in6addr_linklocal_allnodes); |
1da177e4 | 2510 | |
f3ee4010 YH |
2511 | if (idev->cnf.forwarding) |
2512 | __ipv6_dev_mc_dec(idev, &in6addr_linklocal_allrouters); | |
1da177e4 LT |
2513 | |
2514 | write_lock_bh(&idev->lock); | |
2515 | while ((i = idev->mc_list) != NULL) { | |
2516 | idev->mc_list = i->next; | |
2517 | write_unlock_bh(&idev->lock); | |
2518 | ||
2519 | igmp6_group_dropped(i); | |
2520 | ma_put(i); | |
2521 | ||
2522 | write_lock_bh(&idev->lock); | |
2523 | } | |
2524 | write_unlock_bh(&idev->lock); | |
2525 | } | |
2526 | ||
2527 | #ifdef CONFIG_PROC_FS | |
2528 | struct igmp6_mc_iter_state { | |
b8ad0cbc | 2529 | struct seq_net_private p; |
1da177e4 LT |
2530 | struct net_device *dev; |
2531 | struct inet6_dev *idev; | |
2532 | }; | |
2533 | ||
2534 | #define igmp6_mc_seq_private(seq) ((struct igmp6_mc_iter_state *)(seq)->private) | |
2535 | ||
2536 | static inline struct ifmcaddr6 *igmp6_mc_get_first(struct seq_file *seq) | |
2537 | { | |
2538 | struct ifmcaddr6 *im = NULL; | |
2539 | struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq); | |
1218854a | 2540 | struct net *net = seq_file_net(seq); |
1da177e4 | 2541 | |
7562f876 | 2542 | state->idev = NULL; |
ce81b76a | 2543 | for_each_netdev_rcu(net, state->dev) { |
1da177e4 | 2544 | struct inet6_dev *idev; |
ce81b76a | 2545 | idev = __in6_dev_get(state->dev); |
1da177e4 LT |
2546 | if (!idev) |
2547 | continue; | |
2548 | read_lock_bh(&idev->lock); | |
2549 | im = idev->mc_list; | |
2550 | if (im) { | |
2551 | state->idev = idev; | |
2552 | break; | |
2553 | } | |
2554 | read_unlock_bh(&idev->lock); | |
1da177e4 LT |
2555 | } |
2556 | return im; | |
2557 | } | |
2558 | ||
2559 | static struct ifmcaddr6 *igmp6_mc_get_next(struct seq_file *seq, struct ifmcaddr6 *im) | |
2560 | { | |
2561 | struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq); | |
2562 | ||
2563 | im = im->next; | |
2564 | while (!im) { | |
ce81b76a | 2565 | if (likely(state->idev != NULL)) |
1da177e4 | 2566 | read_unlock_bh(&state->idev->lock); |
ce81b76a ED |
2567 | |
2568 | state->dev = next_net_device_rcu(state->dev); | |
1da177e4 LT |
2569 | if (!state->dev) { |
2570 | state->idev = NULL; | |
2571 | break; | |
2572 | } | |
ce81b76a | 2573 | state->idev = __in6_dev_get(state->dev); |
1da177e4 LT |
2574 | if (!state->idev) |
2575 | continue; | |
2576 | read_lock_bh(&state->idev->lock); | |
2577 | im = state->idev->mc_list; | |
2578 | } | |
2579 | return im; | |
2580 | } | |
2581 | ||
2582 | static struct ifmcaddr6 *igmp6_mc_get_idx(struct seq_file *seq, loff_t pos) | |
2583 | { | |
2584 | struct ifmcaddr6 *im = igmp6_mc_get_first(seq); | |
2585 | if (im) | |
2586 | while (pos && (im = igmp6_mc_get_next(seq, im)) != NULL) | |
2587 | --pos; | |
2588 | return pos ? NULL : im; | |
2589 | } | |
2590 | ||
2591 | static void *igmp6_mc_seq_start(struct seq_file *seq, loff_t *pos) | |
ce81b76a | 2592 | __acquires(RCU) |
1da177e4 | 2593 | { |
ce81b76a | 2594 | rcu_read_lock(); |
1da177e4 LT |
2595 | return igmp6_mc_get_idx(seq, *pos); |
2596 | } | |
2597 | ||
2598 | static void *igmp6_mc_seq_next(struct seq_file *seq, void *v, loff_t *pos) | |
2599 | { | |
ce81b76a ED |
2600 | struct ifmcaddr6 *im = igmp6_mc_get_next(seq, v); |
2601 | ||
1da177e4 LT |
2602 | ++*pos; |
2603 | return im; | |
2604 | } | |
2605 | ||
2606 | static void igmp6_mc_seq_stop(struct seq_file *seq, void *v) | |
ce81b76a | 2607 | __releases(RCU) |
1da177e4 LT |
2608 | { |
2609 | struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq); | |
ce81b76a | 2610 | |
1da177e4 LT |
2611 | if (likely(state->idev != NULL)) { |
2612 | read_unlock_bh(&state->idev->lock); | |
1da177e4 LT |
2613 | state->idev = NULL; |
2614 | } | |
2615 | state->dev = NULL; | |
ce81b76a | 2616 | rcu_read_unlock(); |
1da177e4 LT |
2617 | } |
2618 | ||
2619 | static int igmp6_mc_seq_show(struct seq_file *seq, void *v) | |
2620 | { | |
2621 | struct ifmcaddr6 *im = (struct ifmcaddr6 *)v; | |
2622 | struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq); | |
2623 | ||
2624 | seq_printf(seq, | |
4b7a4274 | 2625 | "%-4d %-15s %pi6 %5d %08X %ld\n", |
1da177e4 | 2626 | state->dev->ifindex, state->dev->name, |
b071195d | 2627 | &im->mca_addr, |
1da177e4 LT |
2628 | im->mca_users, im->mca_flags, |
2629 | (im->mca_flags&MAF_TIMER_RUNNING) ? | |
2630 | jiffies_to_clock_t(im->mca_timer.expires-jiffies) : 0); | |
2631 | return 0; | |
2632 | } | |
2633 | ||
56b3d975 | 2634 | static const struct seq_operations igmp6_mc_seq_ops = { |
1da177e4 LT |
2635 | .start = igmp6_mc_seq_start, |
2636 | .next = igmp6_mc_seq_next, | |
2637 | .stop = igmp6_mc_seq_stop, | |
2638 | .show = igmp6_mc_seq_show, | |
2639 | }; | |
2640 | ||
2641 | static int igmp6_mc_seq_open(struct inode *inode, struct file *file) | |
2642 | { | |
b8ad0cbc DL |
2643 | return seq_open_net(inode, file, &igmp6_mc_seq_ops, |
2644 | sizeof(struct igmp6_mc_iter_state)); | |
1da177e4 LT |
2645 | } |
2646 | ||
9a32144e | 2647 | static const struct file_operations igmp6_mc_seq_fops = { |
1da177e4 LT |
2648 | .owner = THIS_MODULE, |
2649 | .open = igmp6_mc_seq_open, | |
2650 | .read = seq_read, | |
2651 | .llseek = seq_lseek, | |
b8ad0cbc | 2652 | .release = seq_release_net, |
1da177e4 LT |
2653 | }; |
2654 | ||
2655 | struct igmp6_mcf_iter_state { | |
b8ad0cbc | 2656 | struct seq_net_private p; |
1da177e4 LT |
2657 | struct net_device *dev; |
2658 | struct inet6_dev *idev; | |
2659 | struct ifmcaddr6 *im; | |
2660 | }; | |
2661 | ||
2662 | #define igmp6_mcf_seq_private(seq) ((struct igmp6_mcf_iter_state *)(seq)->private) | |
2663 | ||
2664 | static inline struct ip6_sf_list *igmp6_mcf_get_first(struct seq_file *seq) | |
2665 | { | |
2666 | struct ip6_sf_list *psf = NULL; | |
2667 | struct ifmcaddr6 *im = NULL; | |
2668 | struct igmp6_mcf_iter_state *state = igmp6_mcf_seq_private(seq); | |
1218854a | 2669 | struct net *net = seq_file_net(seq); |
1da177e4 | 2670 | |
7562f876 PE |
2671 | state->idev = NULL; |
2672 | state->im = NULL; | |
ce81b76a | 2673 | for_each_netdev_rcu(net, state->dev) { |
1da177e4 | 2674 | struct inet6_dev *idev; |
ce81b76a | 2675 | idev = __in6_dev_get(state->dev); |
1da177e4 LT |
2676 | if (unlikely(idev == NULL)) |
2677 | continue; | |
2678 | read_lock_bh(&idev->lock); | |
2679 | im = idev->mc_list; | |
2680 | if (likely(im != NULL)) { | |
2681 | spin_lock_bh(&im->mca_lock); | |
2682 | psf = im->mca_sources; | |
2683 | if (likely(psf != NULL)) { | |
2684 | state->im = im; | |
2685 | state->idev = idev; | |
2686 | break; | |
2687 | } | |
2688 | spin_unlock_bh(&im->mca_lock); | |
2689 | } | |
2690 | read_unlock_bh(&idev->lock); | |
1da177e4 LT |
2691 | } |
2692 | return psf; | |
2693 | } | |
2694 | ||
2695 | static struct ip6_sf_list *igmp6_mcf_get_next(struct seq_file *seq, struct ip6_sf_list *psf) | |
2696 | { | |
2697 | struct igmp6_mcf_iter_state *state = igmp6_mcf_seq_private(seq); | |
2698 | ||
2699 | psf = psf->sf_next; | |
2700 | while (!psf) { | |
2701 | spin_unlock_bh(&state->im->mca_lock); | |
2702 | state->im = state->im->next; | |
2703 | while (!state->im) { | |
ce81b76a | 2704 | if (likely(state->idev != NULL)) |
1da177e4 | 2705 | read_unlock_bh(&state->idev->lock); |
ce81b76a ED |
2706 | |
2707 | state->dev = next_net_device_rcu(state->dev); | |
1da177e4 LT |
2708 | if (!state->dev) { |
2709 | state->idev = NULL; | |
2710 | goto out; | |
2711 | } | |
ce81b76a | 2712 | state->idev = __in6_dev_get(state->dev); |
1da177e4 LT |
2713 | if (!state->idev) |
2714 | continue; | |
2715 | read_lock_bh(&state->idev->lock); | |
2716 | state->im = state->idev->mc_list; | |
2717 | } | |
2718 | if (!state->im) | |
2719 | break; | |
2720 | spin_lock_bh(&state->im->mca_lock); | |
2721 | psf = state->im->mca_sources; | |
2722 | } | |
2723 | out: | |
2724 | return psf; | |
2725 | } | |
2726 | ||
2727 | static struct ip6_sf_list *igmp6_mcf_get_idx(struct seq_file *seq, loff_t pos) | |
2728 | { | |
2729 | struct ip6_sf_list *psf = igmp6_mcf_get_first(seq); | |
2730 | if (psf) | |
2731 | while (pos && (psf = igmp6_mcf_get_next(seq, psf)) != NULL) | |
2732 | --pos; | |
2733 | return pos ? NULL : psf; | |
2734 | } | |
2735 | ||
2736 | static void *igmp6_mcf_seq_start(struct seq_file *seq, loff_t *pos) | |
ce81b76a | 2737 | __acquires(RCU) |
1da177e4 | 2738 | { |
ce81b76a | 2739 | rcu_read_lock(); |
1da177e4 LT |
2740 | return *pos ? igmp6_mcf_get_idx(seq, *pos - 1) : SEQ_START_TOKEN; |
2741 | } | |
2742 | ||
2743 | static void *igmp6_mcf_seq_next(struct seq_file *seq, void *v, loff_t *pos) | |
2744 | { | |
2745 | struct ip6_sf_list *psf; | |
2746 | if (v == SEQ_START_TOKEN) | |
2747 | psf = igmp6_mcf_get_first(seq); | |
2748 | else | |
2749 | psf = igmp6_mcf_get_next(seq, v); | |
2750 | ++*pos; | |
2751 | return psf; | |
2752 | } | |
2753 | ||
2754 | static void igmp6_mcf_seq_stop(struct seq_file *seq, void *v) | |
ce81b76a | 2755 | __releases(RCU) |
1da177e4 LT |
2756 | { |
2757 | struct igmp6_mcf_iter_state *state = igmp6_mcf_seq_private(seq); | |
2758 | if (likely(state->im != NULL)) { | |
2759 | spin_unlock_bh(&state->im->mca_lock); | |
2760 | state->im = NULL; | |
2761 | } | |
2762 | if (likely(state->idev != NULL)) { | |
2763 | read_unlock_bh(&state->idev->lock); | |
1da177e4 LT |
2764 | state->idev = NULL; |
2765 | } | |
2766 | state->dev = NULL; | |
ce81b76a | 2767 | rcu_read_unlock(); |
1da177e4 LT |
2768 | } |
2769 | ||
2770 | static int igmp6_mcf_seq_show(struct seq_file *seq, void *v) | |
2771 | { | |
2772 | struct ip6_sf_list *psf = (struct ip6_sf_list *)v; | |
2773 | struct igmp6_mcf_iter_state *state = igmp6_mcf_seq_private(seq); | |
2774 | ||
2775 | if (v == SEQ_START_TOKEN) { | |
1ab1457c | 2776 | seq_printf(seq, |
1da177e4 | 2777 | "%3s %6s " |
9343e79a | 2778 | "%32s %32s %6s %6s\n", "Idx", |
1da177e4 LT |
2779 | "Device", "Multicast Address", |
2780 | "Source Address", "INC", "EXC"); | |
2781 | } else { | |
2782 | seq_printf(seq, | |
4b7a4274 | 2783 | "%3d %6.6s %pi6 %pi6 %6lu %6lu\n", |
1da177e4 | 2784 | state->dev->ifindex, state->dev->name, |
b071195d HH |
2785 | &state->im->mca_addr, |
2786 | &psf->sf_addr, | |
1da177e4 LT |
2787 | psf->sf_count[MCAST_INCLUDE], |
2788 | psf->sf_count[MCAST_EXCLUDE]); | |
2789 | } | |
2790 | return 0; | |
2791 | } | |
2792 | ||
56b3d975 | 2793 | static const struct seq_operations igmp6_mcf_seq_ops = { |
1da177e4 LT |
2794 | .start = igmp6_mcf_seq_start, |
2795 | .next = igmp6_mcf_seq_next, | |
2796 | .stop = igmp6_mcf_seq_stop, | |
2797 | .show = igmp6_mcf_seq_show, | |
2798 | }; | |
2799 | ||
2800 | static int igmp6_mcf_seq_open(struct inode *inode, struct file *file) | |
2801 | { | |
b8ad0cbc DL |
2802 | return seq_open_net(inode, file, &igmp6_mcf_seq_ops, |
2803 | sizeof(struct igmp6_mcf_iter_state)); | |
1da177e4 LT |
2804 | } |
2805 | ||
9a32144e | 2806 | static const struct file_operations igmp6_mcf_seq_fops = { |
1da177e4 LT |
2807 | .owner = THIS_MODULE, |
2808 | .open = igmp6_mcf_seq_open, | |
2809 | .read = seq_read, | |
2810 | .llseek = seq_lseek, | |
b8ad0cbc | 2811 | .release = seq_release_net, |
1da177e4 | 2812 | }; |
ea82edf7 | 2813 | |
2c8c1e72 | 2814 | static int __net_init igmp6_proc_init(struct net *net) |
ea82edf7 DL |
2815 | { |
2816 | int err; | |
2817 | ||
2818 | err = -ENOMEM; | |
d4beaa66 | 2819 | if (!proc_create("igmp6", S_IRUGO, net->proc_net, &igmp6_mc_seq_fops)) |
ea82edf7 | 2820 | goto out; |
d4beaa66 G |
2821 | if (!proc_create("mcfilter6", S_IRUGO, net->proc_net, |
2822 | &igmp6_mcf_seq_fops)) | |
ea82edf7 DL |
2823 | goto out_proc_net_igmp6; |
2824 | ||
2825 | err = 0; | |
2826 | out: | |
2827 | return err; | |
2828 | ||
2829 | out_proc_net_igmp6: | |
ece31ffd | 2830 | remove_proc_entry("igmp6", net->proc_net); |
ea82edf7 DL |
2831 | goto out; |
2832 | } | |
2833 | ||
2c8c1e72 | 2834 | static void __net_exit igmp6_proc_exit(struct net *net) |
ea82edf7 | 2835 | { |
ece31ffd G |
2836 | remove_proc_entry("mcfilter6", net->proc_net); |
2837 | remove_proc_entry("igmp6", net->proc_net); | |
ea82edf7 DL |
2838 | } |
2839 | #else | |
2c8c1e72 | 2840 | static inline int igmp6_proc_init(struct net *net) |
ea82edf7 DL |
2841 | { |
2842 | return 0; | |
2843 | } | |
2c8c1e72 | 2844 | static inline void igmp6_proc_exit(struct net *net) |
ea82edf7 | 2845 | { |
ea82edf7 | 2846 | } |
1da177e4 LT |
2847 | #endif |
2848 | ||
2c8c1e72 | 2849 | static int __net_init igmp6_net_init(struct net *net) |
1da177e4 | 2850 | { |
1da177e4 LT |
2851 | int err; |
2852 | ||
1ed8516f DL |
2853 | err = inet_ctl_sock_create(&net->ipv6.igmp_sk, PF_INET6, |
2854 | SOCK_RAW, IPPROTO_ICMPV6, net); | |
1da177e4 | 2855 | if (err < 0) { |
f3213831 | 2856 | pr_err("Failed to initialize the IGMP6 control socket (err %d)\n", |
1da177e4 | 2857 | err); |
b8ad0cbc | 2858 | goto out; |
1da177e4 LT |
2859 | } |
2860 | ||
1ed8516f | 2861 | inet6_sk(net->ipv6.igmp_sk)->hop_limit = 1; |
1da177e4 | 2862 | |
ea82edf7 DL |
2863 | err = igmp6_proc_init(net); |
2864 | if (err) | |
b8ad0cbc | 2865 | goto out_sock_create; |
b8ad0cbc DL |
2866 | out: |
2867 | return err; | |
2868 | ||
2869 | out_sock_create: | |
1ed8516f | 2870 | inet_ctl_sock_destroy(net->ipv6.igmp_sk); |
b8ad0cbc | 2871 | goto out; |
1da177e4 LT |
2872 | } |
2873 | ||
2c8c1e72 | 2874 | static void __net_exit igmp6_net_exit(struct net *net) |
1da177e4 | 2875 | { |
1ed8516f | 2876 | inet_ctl_sock_destroy(net->ipv6.igmp_sk); |
ea82edf7 | 2877 | igmp6_proc_exit(net); |
1da177e4 | 2878 | } |
b8ad0cbc DL |
2879 | |
2880 | static struct pernet_operations igmp6_net_ops = { | |
2881 | .init = igmp6_net_init, | |
2882 | .exit = igmp6_net_exit, | |
2883 | }; | |
2884 | ||
2885 | int __init igmp6_init(void) | |
2886 | { | |
2887 | return register_pernet_subsys(&igmp6_net_ops); | |
2888 | } | |
2889 | ||
2890 | void igmp6_cleanup(void) | |
2891 | { | |
2892 | unregister_pernet_subsys(&igmp6_net_ops); | |
2893 | } |