1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Linux NET3: Internet Group Management Protocol [IGMP]
5 * This code implements the IGMP protocol as defined in RFC1112. There has
6 * been a further revision of this protocol since which is now supported.
8 * If you have trouble with this module be careful what gcc you have used,
9 * the older version didn't come out right using gcc 2.5.8, the newer one
10 * seems to fall out with gcc 2.6.2.
13 * Alan Cox <alan@lxorguk.ukuu.org.uk>
17 * Alan Cox : Added lots of __inline__ to optimise
18 * the memory usage of all the tiny little
20 * Alan Cox : Dumped the header building experiment.
21 * Alan Cox : Minor tweaks ready for multicast routing
22 * and extended IGMP protocol.
23 * Alan Cox : Removed a load of inline directives. Gcc 2.5.8
24 * writes utterly bogus code otherwise (sigh)
25 * fixed IGMP loopback to behave in the manner
26 * desired by mrouted, fixed the fact it has been
27 * broken since 1.3.6 and cleaned up a few minor
30 * Chih-Jen Chang : Tried to revise IGMP to Version 2
31 * Tsu-Sheng Tsao E-mail: chihjenc@scf.usc.edu and tsusheng@scf.usc.edu
32 * The enhancements are mainly based on Steve Deering's
33 * ipmulti-3.5 source code.
34 * Chih-Jen Chang : Added the igmp_get_mrouter_info and
35 * Tsu-Sheng Tsao igmp_set_mrouter_info to keep track of
36 * the mrouted version on that device.
37 * Chih-Jen Chang : Added the max_resp_time parameter to
38 * Tsu-Sheng Tsao igmp_heard_query(). Using this parameter
39 * to identify the multicast router version
40 * and do what the IGMP version 2 specified.
41 * Chih-Jen Chang : Added a timer to revert to IGMP V2 router
42 * Tsu-Sheng Tsao if the specified time expired.
43 * Alan Cox : Stop IGMP from 0.0.0.0 being accepted.
44 * Alan Cox : Use GFP_ATOMIC in the right places.
45 * Christian Daudt : igmp timer wasn't set for local group
46 * memberships but was being deleted,
47 * which caused a "del_timer() called
48 * from %p with timer not initialized\n"
50 * Christian Daudt : removed del_timer from
51 * igmp_timer_expire function (960205).
52 * Christian Daudt : igmp_heard_report now only calls
53 * igmp_timer_expire if tm->running is
55 * Malcolm Beattie : ttl comparison wrong in igmp_rcv made
56 * igmp_heard_query never trigger. Expiry
57 * miscalculation fixed in igmp_heard_query
58 * and random() made to return unsigned to
59 * prevent negative expiry times.
60 * Alexey Kuznetsov: Wrong group leaving behaviour, backport
61 * fix from pending 2.1.x patches.
62 * Alan Cox: Forget to enable FDDI support earlier.
63 * Alexey Kuznetsov: Fixed leaving groups on device down.
64 * Alexey Kuznetsov: Accordance to igmp-v2-06 draft.
65 * David L Stevens: IGMPv3 support, with help from
69 #include <linux/module.h>
70 #include <linux/slab.h>
71 #include <linux/uaccess.h>
72 #include <linux/types.h>
73 #include <linux/kernel.h>
74 #include <linux/jiffies.h>
75 #include <linux/string.h>
76 #include <linux/socket.h>
77 #include <linux/sockios.h>
79 #include <linux/inet.h>
80 #include <linux/netdevice.h>
81 #include <linux/skbuff.h>
82 #include <linux/inetdevice.h>
83 #include <linux/igmp.h>
84 #include <linux/if_arp.h>
85 #include <linux/rtnetlink.h>
86 #include <linux/times.h>
87 #include <linux/pkt_sched.h>
88 #include <linux/byteorder/generic.h>
90 #include <net/net_namespace.h>
93 #include <net/protocol.h>
94 #include <net/route.h>
96 #include <net/checksum.h>
97 #include <net/inet_common.h>
98 #include <linux/netfilter_ipv4.h>
99 #ifdef CONFIG_IP_MROUTE
100 #include <linux/mroute.h>
102 #ifdef CONFIG_PROC_FS
103 #include <linux/proc_fs.h>
104 #include <linux/seq_file.h>
107 #ifdef CONFIG_IP_MULTICAST
108 /* Parameter names and values are taken from igmp-v2-06 draft */
110 #define IGMP_QUERY_INTERVAL (125*HZ)
111 #define IGMP_QUERY_RESPONSE_INTERVAL (10*HZ)
113 #define IGMP_INITIAL_REPORT_DELAY (1)
115 /* IGMP_INITIAL_REPORT_DELAY is not from IGMP specs!
116 * IGMP specs require to report membership immediately after
117 * joining a group, but we delay the first report by a
118 * small interval. It seems more natural and still does not
119 * contradict to specs provided this delay is small enough.
122 #define IGMP_V1_SEEN(in_dev) \
123 (IPV4_DEVCONF_ALL(dev_net(in_dev->dev), FORCE_IGMP_VERSION) == 1 || \
124 IN_DEV_CONF_GET((in_dev), FORCE_IGMP_VERSION) == 1 || \
125 ((in_dev)->mr_v1_seen && \
126 time_before(jiffies, (in_dev)->mr_v1_seen)))
127 #define IGMP_V2_SEEN(in_dev) \
128 (IPV4_DEVCONF_ALL(dev_net(in_dev->dev), FORCE_IGMP_VERSION) == 2 || \
129 IN_DEV_CONF_GET((in_dev), FORCE_IGMP_VERSION) == 2 || \
130 ((in_dev)->mr_v2_seen && \
131 time_before(jiffies, (in_dev)->mr_v2_seen)))
133 static int unsolicited_report_interval(struct in_device
*in_dev
)
135 int interval_ms
, interval_jiffies
;
137 if (IGMP_V1_SEEN(in_dev
) || IGMP_V2_SEEN(in_dev
))
138 interval_ms
= IN_DEV_CONF_GET(
140 IGMPV2_UNSOLICITED_REPORT_INTERVAL
);
142 interval_ms
= IN_DEV_CONF_GET(
144 IGMPV3_UNSOLICITED_REPORT_INTERVAL
);
146 interval_jiffies
= msecs_to_jiffies(interval_ms
);
148 /* _timer functions can't handle a delay of 0 jiffies so ensure
149 * we always return a positive value.
151 if (interval_jiffies
<= 0)
152 interval_jiffies
= 1;
153 return interval_jiffies
;
156 static void igmpv3_add_delrec(struct in_device
*in_dev
, struct ip_mc_list
*im
,
158 static void igmpv3_del_delrec(struct in_device
*in_dev
, struct ip_mc_list
*im
);
159 static void igmpv3_clear_delrec(struct in_device
*in_dev
);
160 static int sf_setstate(struct ip_mc_list
*pmc
);
161 static void sf_markstate(struct ip_mc_list
*pmc
);
163 static void ip_mc_clear_src(struct ip_mc_list
*pmc
);
164 static int ip_mc_add_src(struct in_device
*in_dev
, __be32
*pmca
, int sfmode
,
165 int sfcount
, __be32
*psfsrc
, int delta
);
167 static void ip_ma_put(struct ip_mc_list
*im
)
169 if (refcount_dec_and_test(&im
->refcnt
)) {
170 in_dev_put(im
->interface
);
175 #define for_each_pmc_rcu(in_dev, pmc) \
176 for (pmc = rcu_dereference(in_dev->mc_list); \
178 pmc = rcu_dereference(pmc->next_rcu))
180 #define for_each_pmc_rtnl(in_dev, pmc) \
181 for (pmc = rtnl_dereference(in_dev->mc_list); \
183 pmc = rtnl_dereference(pmc->next_rcu))
185 static void ip_sf_list_clear_all(struct ip_sf_list
*psf
)
187 struct ip_sf_list
*next
;
196 #ifdef CONFIG_IP_MULTICAST
202 static void igmp_stop_timer(struct ip_mc_list
*im
)
204 spin_lock_bh(&im
->lock
);
205 if (del_timer(&im
->timer
))
206 refcount_dec(&im
->refcnt
);
209 im
->unsolicit_count
= 0;
210 spin_unlock_bh(&im
->lock
);
213 /* It must be called with locked im->lock */
214 static void igmp_start_timer(struct ip_mc_list
*im
, int max_delay
)
216 int tv
= prandom_u32() % max_delay
;
219 if (!mod_timer(&im
->timer
, jiffies
+tv
+2))
220 refcount_inc(&im
->refcnt
);
223 static void igmp_gq_start_timer(struct in_device
*in_dev
)
225 int tv
= prandom_u32() % in_dev
->mr_maxdelay
;
226 unsigned long exp
= jiffies
+ tv
+ 2;
228 if (in_dev
->mr_gq_running
&&
229 time_after_eq(exp
, (in_dev
->mr_gq_timer
).expires
))
232 in_dev
->mr_gq_running
= 1;
233 if (!mod_timer(&in_dev
->mr_gq_timer
, exp
))
237 static void igmp_ifc_start_timer(struct in_device
*in_dev
, int delay
)
239 int tv
= prandom_u32() % delay
;
241 if (!mod_timer(&in_dev
->mr_ifc_timer
, jiffies
+tv
+2))
245 static void igmp_mod_timer(struct ip_mc_list
*im
, int max_delay
)
247 spin_lock_bh(&im
->lock
);
248 im
->unsolicit_count
= 0;
249 if (del_timer(&im
->timer
)) {
250 if ((long)(im
->timer
.expires
-jiffies
) < max_delay
) {
251 add_timer(&im
->timer
);
253 spin_unlock_bh(&im
->lock
);
256 refcount_dec(&im
->refcnt
);
258 igmp_start_timer(im
, max_delay
);
259 spin_unlock_bh(&im
->lock
);
264 * Send an IGMP report.
267 #define IGMP_SIZE (sizeof(struct igmphdr)+sizeof(struct iphdr)+4)
270 static int is_in(struct ip_mc_list
*pmc
, struct ip_sf_list
*psf
, int type
,
271 int gdeleted
, int sdeleted
)
274 case IGMPV3_MODE_IS_INCLUDE
:
275 case IGMPV3_MODE_IS_EXCLUDE
:
276 if (gdeleted
|| sdeleted
)
278 if (!(pmc
->gsquery
&& !psf
->sf_gsresp
)) {
279 if (pmc
->sfmode
== MCAST_INCLUDE
)
281 /* don't include if this source is excluded
284 if (psf
->sf_count
[MCAST_INCLUDE
])
285 return type
== IGMPV3_MODE_IS_INCLUDE
;
286 return pmc
->sfcount
[MCAST_EXCLUDE
] ==
287 psf
->sf_count
[MCAST_EXCLUDE
];
290 case IGMPV3_CHANGE_TO_INCLUDE
:
291 if (gdeleted
|| sdeleted
)
293 return psf
->sf_count
[MCAST_INCLUDE
] != 0;
294 case IGMPV3_CHANGE_TO_EXCLUDE
:
295 if (gdeleted
|| sdeleted
)
297 if (pmc
->sfcount
[MCAST_EXCLUDE
] == 0 ||
298 psf
->sf_count
[MCAST_INCLUDE
])
300 return pmc
->sfcount
[MCAST_EXCLUDE
] ==
301 psf
->sf_count
[MCAST_EXCLUDE
];
302 case IGMPV3_ALLOW_NEW_SOURCES
:
303 if (gdeleted
|| !psf
->sf_crcount
)
305 return (pmc
->sfmode
== MCAST_INCLUDE
) ^ sdeleted
;
306 case IGMPV3_BLOCK_OLD_SOURCES
:
307 if (pmc
->sfmode
== MCAST_INCLUDE
)
308 return gdeleted
|| (psf
->sf_crcount
&& sdeleted
);
309 return psf
->sf_crcount
&& !gdeleted
&& !sdeleted
;
315 igmp_scount(struct ip_mc_list
*pmc
, int type
, int gdeleted
, int sdeleted
)
317 struct ip_sf_list
*psf
;
320 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
) {
321 if (!is_in(pmc
, psf
, type
, gdeleted
, sdeleted
))
328 /* source address selection per RFC 3376 section 4.2.13 */
329 static __be32
igmpv3_get_srcaddr(struct net_device
*dev
,
330 const struct flowi4
*fl4
)
332 struct in_device
*in_dev
= __in_dev_get_rcu(dev
);
333 const struct in_ifaddr
*ifa
;
336 return htonl(INADDR_ANY
);
338 in_dev_for_each_ifa_rcu(ifa
, in_dev
) {
339 if (fl4
->saddr
== ifa
->ifa_local
)
343 return htonl(INADDR_ANY
);
346 static struct sk_buff
*igmpv3_newpack(struct net_device
*dev
, unsigned int mtu
)
351 struct igmpv3_report
*pig
;
352 struct net
*net
= dev_net(dev
);
354 int hlen
= LL_RESERVED_SPACE(dev
);
355 int tlen
= dev
->needed_tailroom
;
356 unsigned int size
= mtu
;
359 skb
= alloc_skb(size
+ hlen
+ tlen
,
360 GFP_ATOMIC
| __GFP_NOWARN
);
367 skb
->priority
= TC_PRIO_CONTROL
;
369 rt
= ip_route_output_ports(net
, &fl4
, NULL
, IGMPV3_ALL_MCR
, 0,
371 IPPROTO_IGMP
, 0, dev
->ifindex
);
377 skb_dst_set(skb
, &rt
->dst
);
380 skb_reserve(skb
, hlen
);
381 skb_tailroom_reserve(skb
, mtu
, tlen
);
383 skb_reset_network_header(skb
);
385 skb_put(skb
, sizeof(struct iphdr
) + 4);
388 pip
->ihl
= (sizeof(struct iphdr
)+4)>>2;
390 pip
->frag_off
= htons(IP_DF
);
392 pip
->daddr
= fl4
.daddr
;
395 pip
->saddr
= igmpv3_get_srcaddr(dev
, &fl4
);
398 pip
->protocol
= IPPROTO_IGMP
;
399 pip
->tot_len
= 0; /* filled in later */
400 ip_select_ident(net
, skb
, NULL
);
401 ((u8
*)&pip
[1])[0] = IPOPT_RA
;
402 ((u8
*)&pip
[1])[1] = 4;
403 ((u8
*)&pip
[1])[2] = 0;
404 ((u8
*)&pip
[1])[3] = 0;
406 skb
->transport_header
= skb
->network_header
+ sizeof(struct iphdr
) + 4;
407 skb_put(skb
, sizeof(*pig
));
408 pig
= igmpv3_report_hdr(skb
);
409 pig
->type
= IGMPV3_HOST_MEMBERSHIP_REPORT
;
417 static int igmpv3_sendpack(struct sk_buff
*skb
)
419 struct igmphdr
*pig
= igmp_hdr(skb
);
420 const int igmplen
= skb_tail_pointer(skb
) - skb_transport_header(skb
);
422 pig
->csum
= ip_compute_csum(igmp_hdr(skb
), igmplen
);
424 return ip_local_out(dev_net(skb_dst(skb
)->dev
), skb
->sk
, skb
);
427 static int grec_size(struct ip_mc_list
*pmc
, int type
, int gdel
, int sdel
)
429 return sizeof(struct igmpv3_grec
) + 4*igmp_scount(pmc
, type
, gdel
, sdel
);
432 static struct sk_buff
*add_grhead(struct sk_buff
*skb
, struct ip_mc_list
*pmc
,
433 int type
, struct igmpv3_grec
**ppgr
, unsigned int mtu
)
435 struct net_device
*dev
= pmc
->interface
->dev
;
436 struct igmpv3_report
*pih
;
437 struct igmpv3_grec
*pgr
;
440 skb
= igmpv3_newpack(dev
, mtu
);
444 pgr
= skb_put(skb
, sizeof(struct igmpv3_grec
));
445 pgr
->grec_type
= type
;
446 pgr
->grec_auxwords
= 0;
448 pgr
->grec_mca
= pmc
->multiaddr
;
449 pih
= igmpv3_report_hdr(skb
);
450 pih
->ngrec
= htons(ntohs(pih
->ngrec
)+1);
455 #define AVAILABLE(skb) ((skb) ? skb_availroom(skb) : 0)
457 static struct sk_buff
*add_grec(struct sk_buff
*skb
, struct ip_mc_list
*pmc
,
458 int type
, int gdeleted
, int sdeleted
)
460 struct net_device
*dev
= pmc
->interface
->dev
;
461 struct net
*net
= dev_net(dev
);
462 struct igmpv3_report
*pih
;
463 struct igmpv3_grec
*pgr
= NULL
;
464 struct ip_sf_list
*psf
, *psf_next
, *psf_prev
, **psf_list
;
465 int scount
, stotal
, first
, isquery
, truncate
;
468 if (pmc
->multiaddr
== IGMP_ALL_HOSTS
)
470 if (ipv4_is_local_multicast(pmc
->multiaddr
) && !net
->ipv4
.sysctl_igmp_llm_reports
)
473 mtu
= READ_ONCE(dev
->mtu
);
474 if (mtu
< IPV4_MIN_MTU
)
477 isquery
= type
== IGMPV3_MODE_IS_INCLUDE
||
478 type
== IGMPV3_MODE_IS_EXCLUDE
;
479 truncate
= type
== IGMPV3_MODE_IS_EXCLUDE
||
480 type
== IGMPV3_CHANGE_TO_EXCLUDE
;
484 psf_list
= sdeleted
? &pmc
->tomb
: &pmc
->sources
;
489 pih
= skb
? igmpv3_report_hdr(skb
) : NULL
;
491 /* EX and TO_EX get a fresh packet, if needed */
493 if (pih
&& pih
->ngrec
&&
494 AVAILABLE(skb
) < grec_size(pmc
, type
, gdeleted
, sdeleted
)) {
496 igmpv3_sendpack(skb
);
497 skb
= igmpv3_newpack(dev
, mtu
);
502 for (psf
= *psf_list
; psf
; psf
= psf_next
) {
505 psf_next
= psf
->sf_next
;
507 if (!is_in(pmc
, psf
, type
, gdeleted
, sdeleted
)) {
512 /* Based on RFC3376 5.1. Should not send source-list change
513 * records when there is a filter mode change.
515 if (((gdeleted
&& pmc
->sfmode
== MCAST_EXCLUDE
) ||
516 (!gdeleted
&& pmc
->crcount
)) &&
517 (type
== IGMPV3_ALLOW_NEW_SOURCES
||
518 type
== IGMPV3_BLOCK_OLD_SOURCES
) && psf
->sf_crcount
)
519 goto decrease_sf_crcount
;
521 /* clear marks on query responses */
525 if (AVAILABLE(skb
) < sizeof(__be32
) +
526 first
*sizeof(struct igmpv3_grec
)) {
527 if (truncate
&& !first
)
528 break; /* truncate these */
530 pgr
->grec_nsrcs
= htons(scount
);
532 igmpv3_sendpack(skb
);
533 skb
= igmpv3_newpack(dev
, mtu
);
538 skb
= add_grhead(skb
, pmc
, type
, &pgr
, mtu
);
543 psrc
= skb_put(skb
, sizeof(__be32
));
544 *psrc
= psf
->sf_inaddr
;
546 if ((type
== IGMPV3_ALLOW_NEW_SOURCES
||
547 type
== IGMPV3_BLOCK_OLD_SOURCES
) && psf
->sf_crcount
) {
550 if ((sdeleted
|| gdeleted
) && psf
->sf_crcount
== 0) {
552 psf_prev
->sf_next
= psf
->sf_next
;
554 *psf_list
= psf
->sf_next
;
564 if (type
== IGMPV3_ALLOW_NEW_SOURCES
||
565 type
== IGMPV3_BLOCK_OLD_SOURCES
)
567 if (pmc
->crcount
|| isquery
) {
568 /* make sure we have room for group header */
569 if (skb
&& AVAILABLE(skb
) < sizeof(struct igmpv3_grec
)) {
570 igmpv3_sendpack(skb
);
571 skb
= NULL
; /* add_grhead will get a new one */
573 skb
= add_grhead(skb
, pmc
, type
, &pgr
, mtu
);
577 pgr
->grec_nsrcs
= htons(scount
);
580 pmc
->gsquery
= 0; /* clear query state on report */
584 static int igmpv3_send_report(struct in_device
*in_dev
, struct ip_mc_list
*pmc
)
586 struct sk_buff
*skb
= NULL
;
587 struct net
*net
= dev_net(in_dev
->dev
);
592 for_each_pmc_rcu(in_dev
, pmc
) {
593 if (pmc
->multiaddr
== IGMP_ALL_HOSTS
)
595 if (ipv4_is_local_multicast(pmc
->multiaddr
) &&
596 !net
->ipv4
.sysctl_igmp_llm_reports
)
598 spin_lock_bh(&pmc
->lock
);
599 if (pmc
->sfcount
[MCAST_EXCLUDE
])
600 type
= IGMPV3_MODE_IS_EXCLUDE
;
602 type
= IGMPV3_MODE_IS_INCLUDE
;
603 skb
= add_grec(skb
, pmc
, type
, 0, 0);
604 spin_unlock_bh(&pmc
->lock
);
608 spin_lock_bh(&pmc
->lock
);
609 if (pmc
->sfcount
[MCAST_EXCLUDE
])
610 type
= IGMPV3_MODE_IS_EXCLUDE
;
612 type
= IGMPV3_MODE_IS_INCLUDE
;
613 skb
= add_grec(skb
, pmc
, type
, 0, 0);
614 spin_unlock_bh(&pmc
->lock
);
618 return igmpv3_sendpack(skb
);
622 * remove zero-count source records from a source filter list
624 static void igmpv3_clear_zeros(struct ip_sf_list
**ppsf
)
626 struct ip_sf_list
*psf_prev
, *psf_next
, *psf
;
629 for (psf
= *ppsf
; psf
; psf
= psf_next
) {
630 psf_next
= psf
->sf_next
;
631 if (psf
->sf_crcount
== 0) {
633 psf_prev
->sf_next
= psf
->sf_next
;
635 *ppsf
= psf
->sf_next
;
642 static void kfree_pmc(struct ip_mc_list
*pmc
)
644 ip_sf_list_clear_all(pmc
->sources
);
645 ip_sf_list_clear_all(pmc
->tomb
);
649 static void igmpv3_send_cr(struct in_device
*in_dev
)
651 struct ip_mc_list
*pmc
, *pmc_prev
, *pmc_next
;
652 struct sk_buff
*skb
= NULL
;
656 spin_lock_bh(&in_dev
->mc_tomb_lock
);
660 for (pmc
= in_dev
->mc_tomb
; pmc
; pmc
= pmc_next
) {
661 pmc_next
= pmc
->next
;
662 if (pmc
->sfmode
== MCAST_INCLUDE
) {
663 type
= IGMPV3_BLOCK_OLD_SOURCES
;
664 dtype
= IGMPV3_BLOCK_OLD_SOURCES
;
665 skb
= add_grec(skb
, pmc
, type
, 1, 0);
666 skb
= add_grec(skb
, pmc
, dtype
, 1, 1);
669 if (pmc
->sfmode
== MCAST_EXCLUDE
) {
670 type
= IGMPV3_CHANGE_TO_INCLUDE
;
671 skb
= add_grec(skb
, pmc
, type
, 1, 0);
674 if (pmc
->crcount
== 0) {
675 igmpv3_clear_zeros(&pmc
->tomb
);
676 igmpv3_clear_zeros(&pmc
->sources
);
679 if (pmc
->crcount
== 0 && !pmc
->tomb
&& !pmc
->sources
) {
681 pmc_prev
->next
= pmc_next
;
683 in_dev
->mc_tomb
= pmc_next
;
684 in_dev_put(pmc
->interface
);
689 spin_unlock_bh(&in_dev
->mc_tomb_lock
);
692 for_each_pmc_rcu(in_dev
, pmc
) {
693 spin_lock_bh(&pmc
->lock
);
694 if (pmc
->sfcount
[MCAST_EXCLUDE
]) {
695 type
= IGMPV3_BLOCK_OLD_SOURCES
;
696 dtype
= IGMPV3_ALLOW_NEW_SOURCES
;
698 type
= IGMPV3_ALLOW_NEW_SOURCES
;
699 dtype
= IGMPV3_BLOCK_OLD_SOURCES
;
701 skb
= add_grec(skb
, pmc
, type
, 0, 0);
702 skb
= add_grec(skb
, pmc
, dtype
, 0, 1); /* deleted sources */
704 /* filter mode changes */
706 if (pmc
->sfmode
== MCAST_EXCLUDE
)
707 type
= IGMPV3_CHANGE_TO_EXCLUDE
;
709 type
= IGMPV3_CHANGE_TO_INCLUDE
;
710 skb
= add_grec(skb
, pmc
, type
, 0, 0);
713 spin_unlock_bh(&pmc
->lock
);
719 (void) igmpv3_sendpack(skb
);
722 static int igmp_send_report(struct in_device
*in_dev
, struct ip_mc_list
*pmc
,
729 struct net_device
*dev
= in_dev
->dev
;
730 struct net
*net
= dev_net(dev
);
731 __be32 group
= pmc
? pmc
->multiaddr
: 0;
736 if (type
== IGMPV3_HOST_MEMBERSHIP_REPORT
)
737 return igmpv3_send_report(in_dev
, pmc
);
739 if (ipv4_is_local_multicast(group
) && !net
->ipv4
.sysctl_igmp_llm_reports
)
742 if (type
== IGMP_HOST_LEAVE_MESSAGE
)
743 dst
= IGMP_ALL_ROUTER
;
747 rt
= ip_route_output_ports(net
, &fl4
, NULL
, dst
, 0,
749 IPPROTO_IGMP
, 0, dev
->ifindex
);
753 hlen
= LL_RESERVED_SPACE(dev
);
754 tlen
= dev
->needed_tailroom
;
755 skb
= alloc_skb(IGMP_SIZE
+ hlen
+ tlen
, GFP_ATOMIC
);
760 skb
->priority
= TC_PRIO_CONTROL
;
762 skb_dst_set(skb
, &rt
->dst
);
764 skb_reserve(skb
, hlen
);
766 skb_reset_network_header(skb
);
768 skb_put(skb
, sizeof(struct iphdr
) + 4);
771 iph
->ihl
= (sizeof(struct iphdr
)+4)>>2;
773 iph
->frag_off
= htons(IP_DF
);
776 iph
->saddr
= fl4
.saddr
;
777 iph
->protocol
= IPPROTO_IGMP
;
778 ip_select_ident(net
, skb
, NULL
);
779 ((u8
*)&iph
[1])[0] = IPOPT_RA
;
780 ((u8
*)&iph
[1])[1] = 4;
781 ((u8
*)&iph
[1])[2] = 0;
782 ((u8
*)&iph
[1])[3] = 0;
784 ih
= skb_put(skb
, sizeof(struct igmphdr
));
789 ih
->csum
= ip_compute_csum((void *)ih
, sizeof(struct igmphdr
));
791 return ip_local_out(net
, skb
->sk
, skb
);
794 static void igmp_gq_timer_expire(struct timer_list
*t
)
796 struct in_device
*in_dev
= from_timer(in_dev
, t
, mr_gq_timer
);
798 in_dev
->mr_gq_running
= 0;
799 igmpv3_send_report(in_dev
, NULL
);
803 static void igmp_ifc_timer_expire(struct timer_list
*t
)
805 struct in_device
*in_dev
= from_timer(in_dev
, t
, mr_ifc_timer
);
807 igmpv3_send_cr(in_dev
);
808 if (in_dev
->mr_ifc_count
) {
809 in_dev
->mr_ifc_count
--;
810 igmp_ifc_start_timer(in_dev
,
811 unsolicited_report_interval(in_dev
));
816 static void igmp_ifc_event(struct in_device
*in_dev
)
818 struct net
*net
= dev_net(in_dev
->dev
);
819 if (IGMP_V1_SEEN(in_dev
) || IGMP_V2_SEEN(in_dev
))
821 in_dev
->mr_ifc_count
= in_dev
->mr_qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
822 igmp_ifc_start_timer(in_dev
, 1);
826 static void igmp_timer_expire(struct timer_list
*t
)
828 struct ip_mc_list
*im
= from_timer(im
, t
, timer
);
829 struct in_device
*in_dev
= im
->interface
;
831 spin_lock(&im
->lock
);
834 if (im
->unsolicit_count
&& --im
->unsolicit_count
)
835 igmp_start_timer(im
, unsolicited_report_interval(in_dev
));
838 spin_unlock(&im
->lock
);
840 if (IGMP_V1_SEEN(in_dev
))
841 igmp_send_report(in_dev
, im
, IGMP_HOST_MEMBERSHIP_REPORT
);
842 else if (IGMP_V2_SEEN(in_dev
))
843 igmp_send_report(in_dev
, im
, IGMPV2_HOST_MEMBERSHIP_REPORT
);
845 igmp_send_report(in_dev
, im
, IGMPV3_HOST_MEMBERSHIP_REPORT
);
850 /* mark EXCLUDE-mode sources */
851 static int igmp_xmarksources(struct ip_mc_list
*pmc
, int nsrcs
, __be32
*srcs
)
853 struct ip_sf_list
*psf
;
857 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
) {
860 for (i
= 0; i
< nsrcs
; i
++) {
861 /* skip inactive filters */
862 if (psf
->sf_count
[MCAST_INCLUDE
] ||
863 pmc
->sfcount
[MCAST_EXCLUDE
] !=
864 psf
->sf_count
[MCAST_EXCLUDE
])
866 if (srcs
[i
] == psf
->sf_inaddr
) {
873 if (scount
== nsrcs
) /* all sources excluded */
878 static int igmp_marksources(struct ip_mc_list
*pmc
, int nsrcs
, __be32
*srcs
)
880 struct ip_sf_list
*psf
;
883 if (pmc
->sfmode
== MCAST_EXCLUDE
)
884 return igmp_xmarksources(pmc
, nsrcs
, srcs
);
886 /* mark INCLUDE-mode sources */
888 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
) {
891 for (i
= 0; i
< nsrcs
; i
++)
892 if (srcs
[i
] == psf
->sf_inaddr
) {
906 /* return true if packet was dropped */
907 static bool igmp_heard_report(struct in_device
*in_dev
, __be32 group
)
909 struct ip_mc_list
*im
;
910 struct net
*net
= dev_net(in_dev
->dev
);
912 /* Timers are only set for non-local groups */
914 if (group
== IGMP_ALL_HOSTS
)
916 if (ipv4_is_local_multicast(group
) && !net
->ipv4
.sysctl_igmp_llm_reports
)
920 for_each_pmc_rcu(in_dev
, im
) {
921 if (im
->multiaddr
== group
) {
930 /* return true if packet was dropped */
931 static bool igmp_heard_query(struct in_device
*in_dev
, struct sk_buff
*skb
,
934 struct igmphdr
*ih
= igmp_hdr(skb
);
935 struct igmpv3_query
*ih3
= igmpv3_query_hdr(skb
);
936 struct ip_mc_list
*im
;
937 __be32 group
= ih
->group
;
940 struct net
*net
= dev_net(in_dev
->dev
);
945 /* Alas, old v1 router presents here. */
947 max_delay
= IGMP_QUERY_RESPONSE_INTERVAL
;
948 in_dev
->mr_v1_seen
= jiffies
+
949 (in_dev
->mr_qrv
* in_dev
->mr_qi
) +
953 /* v2 router present */
954 max_delay
= ih
->code
*(HZ
/IGMP_TIMER_SCALE
);
955 in_dev
->mr_v2_seen
= jiffies
+
956 (in_dev
->mr_qrv
* in_dev
->mr_qi
) +
959 /* cancel the interface change timer */
960 in_dev
->mr_ifc_count
= 0;
961 if (del_timer(&in_dev
->mr_ifc_timer
))
962 __in_dev_put(in_dev
);
963 /* clear deleted report items */
964 igmpv3_clear_delrec(in_dev
);
965 } else if (len
< 12) {
966 return true; /* ignore bogus packet; freed by caller */
967 } else if (IGMP_V1_SEEN(in_dev
)) {
968 /* This is a v3 query with v1 queriers present */
969 max_delay
= IGMP_QUERY_RESPONSE_INTERVAL
;
971 } else if (IGMP_V2_SEEN(in_dev
)) {
972 /* this is a v3 query with v2 queriers present;
973 * Interpretation of the max_delay code is problematic here.
974 * A real v2 host would use ih_code directly, while v3 has a
975 * different encoding. We use the v3 encoding as more likely
976 * to be intended in a v3 query.
978 max_delay
= IGMPV3_MRC(ih3
->code
)*(HZ
/IGMP_TIMER_SCALE
);
980 max_delay
= 1; /* can't mod w/ 0 */
982 if (!pskb_may_pull(skb
, sizeof(struct igmpv3_query
)))
985 ih3
= igmpv3_query_hdr(skb
);
987 if (!pskb_may_pull(skb
, sizeof(struct igmpv3_query
)
988 + ntohs(ih3
->nsrcs
)*sizeof(__be32
)))
990 ih3
= igmpv3_query_hdr(skb
);
993 max_delay
= IGMPV3_MRC(ih3
->code
)*(HZ
/IGMP_TIMER_SCALE
);
995 max_delay
= 1; /* can't mod w/ 0 */
996 in_dev
->mr_maxdelay
= max_delay
;
998 /* RFC3376, 4.1.6. QRV and 4.1.7. QQIC, when the most recently
999 * received value was zero, use the default or statically
1002 in_dev
->mr_qrv
= ih3
->qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
1003 in_dev
->mr_qi
= IGMPV3_QQIC(ih3
->qqic
)*HZ
?: IGMP_QUERY_INTERVAL
;
1005 /* RFC3376, 8.3. Query Response Interval:
1006 * The number of seconds represented by the [Query Response
1007 * Interval] must be less than the [Query Interval].
1009 if (in_dev
->mr_qri
>= in_dev
->mr_qi
)
1010 in_dev
->mr_qri
= (in_dev
->mr_qi
/HZ
- 1)*HZ
;
1012 if (!group
) { /* general query */
1014 return true; /* no sources allowed */
1015 igmp_gq_start_timer(in_dev
);
1018 /* mark sources to include, if group & source-specific */
1019 mark
= ih3
->nsrcs
!= 0;
1023 * - Start the timers in all of our membership records
1024 * that the query applies to for the interface on
1025 * which the query arrived excl. those that belong
1026 * to a "local" group (224.0.0.X)
1027 * - For timers already running check if they need to
1029 * - Use the igmp->igmp_code field as the maximum
1033 for_each_pmc_rcu(in_dev
, im
) {
1036 if (group
&& group
!= im
->multiaddr
)
1038 if (im
->multiaddr
== IGMP_ALL_HOSTS
)
1040 if (ipv4_is_local_multicast(im
->multiaddr
) &&
1041 !net
->ipv4
.sysctl_igmp_llm_reports
)
1043 spin_lock_bh(&im
->lock
);
1045 im
->gsquery
= im
->gsquery
&& mark
;
1048 changed
= !im
->gsquery
||
1049 igmp_marksources(im
, ntohs(ih3
->nsrcs
), ih3
->srcs
);
1050 spin_unlock_bh(&im
->lock
);
1052 igmp_mod_timer(im
, max_delay
);
1058 /* called in rcu_read_lock() section */
1059 int igmp_rcv(struct sk_buff
*skb
)
1061 /* This basically follows the spec line by line -- see RFC1112 */
1063 struct net_device
*dev
= skb
->dev
;
1064 struct in_device
*in_dev
;
1066 bool dropped
= true;
1068 if (netif_is_l3_master(dev
)) {
1069 dev
= dev_get_by_index_rcu(dev_net(dev
), IPCB(skb
)->iif
);
1074 in_dev
= __in_dev_get_rcu(dev
);
1078 if (!pskb_may_pull(skb
, sizeof(struct igmphdr
)))
1081 if (skb_checksum_simple_validate(skb
))
1086 case IGMP_HOST_MEMBERSHIP_QUERY
:
1087 dropped
= igmp_heard_query(in_dev
, skb
, len
);
1089 case IGMP_HOST_MEMBERSHIP_REPORT
:
1090 case IGMPV2_HOST_MEMBERSHIP_REPORT
:
1091 /* Is it our report looped back? */
1092 if (rt_is_output_route(skb_rtable(skb
)))
1094 /* don't rely on MC router hearing unicast reports */
1095 if (skb
->pkt_type
== PACKET_MULTICAST
||
1096 skb
->pkt_type
== PACKET_BROADCAST
)
1097 dropped
= igmp_heard_report(in_dev
, ih
->group
);
1100 #ifdef CONFIG_IP_PIMSM_V1
1101 return pim_rcv_v1(skb
);
1103 case IGMPV3_HOST_MEMBERSHIP_REPORT
:
1106 case IGMP_HOST_LEAVE_MESSAGE
:
1108 case IGMP_MTRACE_RESP
:
1126 * Add a filter to a device
1129 static void ip_mc_filter_add(struct in_device
*in_dev
, __be32 addr
)
1131 char buf
[MAX_ADDR_LEN
];
1132 struct net_device
*dev
= in_dev
->dev
;
1134 /* Checking for IFF_MULTICAST here is WRONG-WRONG-WRONG.
1135 We will get multicast token leakage, when IFF_MULTICAST
1136 is changed. This check should be done in ndo_set_rx_mode
1137 routine. Something sort of:
1138 if (dev->mc_list && dev->flags&IFF_MULTICAST) { do it; }
1141 if (arp_mc_map(addr
, buf
, dev
, 0) == 0)
1142 dev_mc_add(dev
, buf
);
1146 * Remove a filter from a device
1149 static void ip_mc_filter_del(struct in_device
*in_dev
, __be32 addr
)
1151 char buf
[MAX_ADDR_LEN
];
1152 struct net_device
*dev
= in_dev
->dev
;
1154 if (arp_mc_map(addr
, buf
, dev
, 0) == 0)
1155 dev_mc_del(dev
, buf
);
1158 #ifdef CONFIG_IP_MULTICAST
1160 * deleted ip_mc_list manipulation
1162 static void igmpv3_add_delrec(struct in_device
*in_dev
, struct ip_mc_list
*im
,
1165 struct ip_mc_list
*pmc
;
1166 struct net
*net
= dev_net(in_dev
->dev
);
1168 /* this is an "ip_mc_list" for convenience; only the fields below
1169 * are actually used. In particular, the refcnt and users are not
1170 * used for management of the delete list. Using the same structure
1171 * for deleted items allows change reports to use common code with
1172 * non-deleted or query-response MCA's.
1174 pmc
= kzalloc(sizeof(*pmc
), gfp
);
1177 spin_lock_init(&pmc
->lock
);
1178 spin_lock_bh(&im
->lock
);
1179 pmc
->interface
= im
->interface
;
1180 in_dev_hold(in_dev
);
1181 pmc
->multiaddr
= im
->multiaddr
;
1182 pmc
->crcount
= in_dev
->mr_qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
1183 pmc
->sfmode
= im
->sfmode
;
1184 if (pmc
->sfmode
== MCAST_INCLUDE
) {
1185 struct ip_sf_list
*psf
;
1187 pmc
->tomb
= im
->tomb
;
1188 pmc
->sources
= im
->sources
;
1189 im
->tomb
= im
->sources
= NULL
;
1190 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
)
1191 psf
->sf_crcount
= pmc
->crcount
;
1193 spin_unlock_bh(&im
->lock
);
1195 spin_lock_bh(&in_dev
->mc_tomb_lock
);
1196 pmc
->next
= in_dev
->mc_tomb
;
1197 in_dev
->mc_tomb
= pmc
;
1198 spin_unlock_bh(&in_dev
->mc_tomb_lock
);
1202 * restore ip_mc_list deleted records
1204 static void igmpv3_del_delrec(struct in_device
*in_dev
, struct ip_mc_list
*im
)
1206 struct ip_mc_list
*pmc
, *pmc_prev
;
1207 struct ip_sf_list
*psf
;
1208 struct net
*net
= dev_net(in_dev
->dev
);
1209 __be32 multiaddr
= im
->multiaddr
;
1211 spin_lock_bh(&in_dev
->mc_tomb_lock
);
1213 for (pmc
= in_dev
->mc_tomb
; pmc
; pmc
= pmc
->next
) {
1214 if (pmc
->multiaddr
== multiaddr
)
1220 pmc_prev
->next
= pmc
->next
;
1222 in_dev
->mc_tomb
= pmc
->next
;
1224 spin_unlock_bh(&in_dev
->mc_tomb_lock
);
1226 spin_lock_bh(&im
->lock
);
1228 im
->interface
= pmc
->interface
;
1229 if (im
->sfmode
== MCAST_INCLUDE
) {
1230 swap(im
->tomb
, pmc
->tomb
);
1231 swap(im
->sources
, pmc
->sources
);
1232 for (psf
= im
->sources
; psf
; psf
= psf
->sf_next
)
1233 psf
->sf_crcount
= in_dev
->mr_qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
1235 im
->crcount
= in_dev
->mr_qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
1237 in_dev_put(pmc
->interface
);
1240 spin_unlock_bh(&im
->lock
);
1244 * flush ip_mc_list deleted records
1246 static void igmpv3_clear_delrec(struct in_device
*in_dev
)
1248 struct ip_mc_list
*pmc
, *nextpmc
;
1250 spin_lock_bh(&in_dev
->mc_tomb_lock
);
1251 pmc
= in_dev
->mc_tomb
;
1252 in_dev
->mc_tomb
= NULL
;
1253 spin_unlock_bh(&in_dev
->mc_tomb_lock
);
1255 for (; pmc
; pmc
= nextpmc
) {
1256 nextpmc
= pmc
->next
;
1257 ip_mc_clear_src(pmc
);
1258 in_dev_put(pmc
->interface
);
1261 /* clear dead sources, too */
1263 for_each_pmc_rcu(in_dev
, pmc
) {
1264 struct ip_sf_list
*psf
;
1266 spin_lock_bh(&pmc
->lock
);
1269 spin_unlock_bh(&pmc
->lock
);
1270 ip_sf_list_clear_all(psf
);
1276 static void __igmp_group_dropped(struct ip_mc_list
*im
, gfp_t gfp
)
1278 struct in_device
*in_dev
= im
->interface
;
1279 #ifdef CONFIG_IP_MULTICAST
1280 struct net
*net
= dev_net(in_dev
->dev
);
1286 ip_mc_filter_del(in_dev
, im
->multiaddr
);
1289 #ifdef CONFIG_IP_MULTICAST
1290 if (im
->multiaddr
== IGMP_ALL_HOSTS
)
1292 if (ipv4_is_local_multicast(im
->multiaddr
) && !net
->ipv4
.sysctl_igmp_llm_reports
)
1295 reporter
= im
->reporter
;
1296 igmp_stop_timer(im
);
1298 if (!in_dev
->dead
) {
1299 if (IGMP_V1_SEEN(in_dev
))
1301 if (IGMP_V2_SEEN(in_dev
)) {
1303 igmp_send_report(in_dev
, im
, IGMP_HOST_LEAVE_MESSAGE
);
1307 igmpv3_add_delrec(in_dev
, im
, gfp
);
1309 igmp_ifc_event(in_dev
);
1314 static void igmp_group_dropped(struct ip_mc_list
*im
)
1316 __igmp_group_dropped(im
, GFP_KERNEL
);
1319 static void igmp_group_added(struct ip_mc_list
*im
)
1321 struct in_device
*in_dev
= im
->interface
;
1322 #ifdef CONFIG_IP_MULTICAST
1323 struct net
*net
= dev_net(in_dev
->dev
);
1326 if (im
->loaded
== 0) {
1328 ip_mc_filter_add(in_dev
, im
->multiaddr
);
1331 #ifdef CONFIG_IP_MULTICAST
1332 if (im
->multiaddr
== IGMP_ALL_HOSTS
)
1334 if (ipv4_is_local_multicast(im
->multiaddr
) && !net
->ipv4
.sysctl_igmp_llm_reports
)
1340 im
->unsolicit_count
= net
->ipv4
.sysctl_igmp_qrv
;
1341 if (IGMP_V1_SEEN(in_dev
) || IGMP_V2_SEEN(in_dev
)) {
1342 spin_lock_bh(&im
->lock
);
1343 igmp_start_timer(im
, IGMP_INITIAL_REPORT_DELAY
);
1344 spin_unlock_bh(&im
->lock
);
1349 /* Based on RFC3376 5.1, for newly added INCLUDE SSM, we should
1350 * not send filter-mode change record as the mode should be from
1353 if (im
->sfmode
== MCAST_EXCLUDE
)
1354 im
->crcount
= in_dev
->mr_qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
1356 igmp_ifc_event(in_dev
);
1362 * Multicast list managers
1365 static u32
ip_mc_hash(const struct ip_mc_list
*im
)
1367 return hash_32((__force u32
)im
->multiaddr
, MC_HASH_SZ_LOG
);
1370 static void ip_mc_hash_add(struct in_device
*in_dev
,
1371 struct ip_mc_list
*im
)
1373 struct ip_mc_list __rcu
**mc_hash
;
1376 mc_hash
= rtnl_dereference(in_dev
->mc_hash
);
1378 hash
= ip_mc_hash(im
);
1379 im
->next_hash
= mc_hash
[hash
];
1380 rcu_assign_pointer(mc_hash
[hash
], im
);
1384 /* do not use a hash table for small number of items */
1385 if (in_dev
->mc_count
< 4)
1388 mc_hash
= kzalloc(sizeof(struct ip_mc_list
*) << MC_HASH_SZ_LOG
,
1393 for_each_pmc_rtnl(in_dev
, im
) {
1394 hash
= ip_mc_hash(im
);
1395 im
->next_hash
= mc_hash
[hash
];
1396 RCU_INIT_POINTER(mc_hash
[hash
], im
);
1399 rcu_assign_pointer(in_dev
->mc_hash
, mc_hash
);
1402 static void ip_mc_hash_remove(struct in_device
*in_dev
,
1403 struct ip_mc_list
*im
)
1405 struct ip_mc_list __rcu
**mc_hash
= rtnl_dereference(in_dev
->mc_hash
);
1406 struct ip_mc_list
*aux
;
1410 mc_hash
+= ip_mc_hash(im
);
1411 while ((aux
= rtnl_dereference(*mc_hash
)) != im
)
1412 mc_hash
= &aux
->next_hash
;
1413 *mc_hash
= im
->next_hash
;
1418 * A socket has joined a multicast group on device dev.
1420 static void ____ip_mc_inc_group(struct in_device
*in_dev
, __be32 addr
,
1421 unsigned int mode
, gfp_t gfp
)
1423 struct ip_mc_list
*im
;
1427 for_each_pmc_rtnl(in_dev
, im
) {
1428 if (im
->multiaddr
== addr
) {
1430 ip_mc_add_src(in_dev
, &addr
, mode
, 0, NULL
, 0);
1435 im
= kzalloc(sizeof(*im
), gfp
);
1440 im
->interface
= in_dev
;
1441 in_dev_hold(in_dev
);
1442 im
->multiaddr
= addr
;
1443 /* initial mode is (EX, empty) */
1445 im
->sfcount
[mode
] = 1;
1446 refcount_set(&im
->refcnt
, 1);
1447 spin_lock_init(&im
->lock
);
1448 #ifdef CONFIG_IP_MULTICAST
1449 timer_setup(&im
->timer
, igmp_timer_expire
, 0);
1452 im
->next_rcu
= in_dev
->mc_list
;
1454 rcu_assign_pointer(in_dev
->mc_list
, im
);
1456 ip_mc_hash_add(in_dev
, im
);
1458 #ifdef CONFIG_IP_MULTICAST
1459 igmpv3_del_delrec(in_dev
, im
);
1461 igmp_group_added(im
);
1463 ip_rt_multicast_event(in_dev
);
1468 void __ip_mc_inc_group(struct in_device
*in_dev
, __be32 addr
, gfp_t gfp
)
1470 ____ip_mc_inc_group(in_dev
, addr
, MCAST_EXCLUDE
, gfp
);
1472 EXPORT_SYMBOL(__ip_mc_inc_group
);
1474 void ip_mc_inc_group(struct in_device
*in_dev
, __be32 addr
)
1476 __ip_mc_inc_group(in_dev
, addr
, GFP_KERNEL
);
1478 EXPORT_SYMBOL(ip_mc_inc_group
);
1480 static int ip_mc_check_iphdr(struct sk_buff
*skb
)
1482 const struct iphdr
*iph
;
1484 unsigned int offset
= skb_network_offset(skb
) + sizeof(*iph
);
1486 if (!pskb_may_pull(skb
, offset
))
1491 if (iph
->version
!= 4 || ip_hdrlen(skb
) < sizeof(*iph
))
1494 offset
+= ip_hdrlen(skb
) - sizeof(*iph
);
1496 if (!pskb_may_pull(skb
, offset
))
1501 if (unlikely(ip_fast_csum((u8
*)iph
, iph
->ihl
)))
1504 len
= skb_network_offset(skb
) + ntohs(iph
->tot_len
);
1505 if (skb
->len
< len
|| len
< offset
)
1508 skb_set_transport_header(skb
, offset
);
1513 static int ip_mc_check_igmp_reportv3(struct sk_buff
*skb
)
1515 unsigned int len
= skb_transport_offset(skb
);
1517 len
+= sizeof(struct igmpv3_report
);
1519 return ip_mc_may_pull(skb
, len
) ? 0 : -EINVAL
;
1522 static int ip_mc_check_igmp_query(struct sk_buff
*skb
)
1524 unsigned int transport_len
= ip_transport_len(skb
);
1528 if (transport_len
!= sizeof(struct igmphdr
)) {
1530 if (transport_len
< sizeof(struct igmpv3_query
))
1533 len
= skb_transport_offset(skb
) + sizeof(struct igmpv3_query
);
1534 if (!ip_mc_may_pull(skb
, len
))
1538 /* RFC2236+RFC3376 (IGMPv2+IGMPv3) require the multicast link layer
1539 * all-systems destination addresses (224.0.0.1) for general queries
1541 if (!igmp_hdr(skb
)->group
&&
1542 ip_hdr(skb
)->daddr
!= htonl(INADDR_ALLHOSTS_GROUP
))
1548 static int ip_mc_check_igmp_msg(struct sk_buff
*skb
)
1550 switch (igmp_hdr(skb
)->type
) {
1551 case IGMP_HOST_LEAVE_MESSAGE
:
1552 case IGMP_HOST_MEMBERSHIP_REPORT
:
1553 case IGMPV2_HOST_MEMBERSHIP_REPORT
:
1555 case IGMPV3_HOST_MEMBERSHIP_REPORT
:
1556 return ip_mc_check_igmp_reportv3(skb
);
1557 case IGMP_HOST_MEMBERSHIP_QUERY
:
1558 return ip_mc_check_igmp_query(skb
);
1564 static __sum16
ip_mc_validate_checksum(struct sk_buff
*skb
)
1566 return skb_checksum_simple_validate(skb
);
1569 static int ip_mc_check_igmp_csum(struct sk_buff
*skb
)
1571 unsigned int len
= skb_transport_offset(skb
) + sizeof(struct igmphdr
);
1572 unsigned int transport_len
= ip_transport_len(skb
);
1573 struct sk_buff
*skb_chk
;
1575 if (!ip_mc_may_pull(skb
, len
))
1578 skb_chk
= skb_checksum_trimmed(skb
, transport_len
,
1579 ip_mc_validate_checksum
);
1590 * ip_mc_check_igmp - checks whether this is a sane IGMP packet
1591 * @skb: the skb to validate
1593 * Checks whether an IPv4 packet is a valid IGMP packet. If so sets
1594 * skb transport header accordingly and returns zero.
1596 * -EINVAL: A broken packet was detected, i.e. it violates some internet
1598 * -ENOMSG: IP header validation succeeded but it is not an IGMP packet.
1599 * -ENOMEM: A memory allocation failure happened.
1601 * Caller needs to set the skb network header and free any returned skb if it
1602 * differs from the provided skb.
1604 int ip_mc_check_igmp(struct sk_buff
*skb
)
1606 int ret
= ip_mc_check_iphdr(skb
);
1611 if (ip_hdr(skb
)->protocol
!= IPPROTO_IGMP
)
1614 ret
= ip_mc_check_igmp_csum(skb
);
1618 return ip_mc_check_igmp_msg(skb
);
1620 EXPORT_SYMBOL(ip_mc_check_igmp
);
1623 * Resend IGMP JOIN report; used by netdev notifier.
1625 static void ip_mc_rejoin_groups(struct in_device
*in_dev
)
1627 #ifdef CONFIG_IP_MULTICAST
1628 struct ip_mc_list
*im
;
1630 struct net
*net
= dev_net(in_dev
->dev
);
1634 for_each_pmc_rtnl(in_dev
, im
) {
1635 if (im
->multiaddr
== IGMP_ALL_HOSTS
)
1637 if (ipv4_is_local_multicast(im
->multiaddr
) &&
1638 !net
->ipv4
.sysctl_igmp_llm_reports
)
1641 /* a failover is happening and switches
1642 * must be notified immediately
1644 if (IGMP_V1_SEEN(in_dev
))
1645 type
= IGMP_HOST_MEMBERSHIP_REPORT
;
1646 else if (IGMP_V2_SEEN(in_dev
))
1647 type
= IGMPV2_HOST_MEMBERSHIP_REPORT
;
1649 type
= IGMPV3_HOST_MEMBERSHIP_REPORT
;
1650 igmp_send_report(in_dev
, im
, type
);
1656 * A socket has left a multicast group on device dev
1659 void __ip_mc_dec_group(struct in_device
*in_dev
, __be32 addr
, gfp_t gfp
)
1661 struct ip_mc_list
*i
;
1662 struct ip_mc_list __rcu
**ip
;
1666 for (ip
= &in_dev
->mc_list
;
1667 (i
= rtnl_dereference(*ip
)) != NULL
;
1668 ip
= &i
->next_rcu
) {
1669 if (i
->multiaddr
== addr
) {
1670 if (--i
->users
== 0) {
1671 ip_mc_hash_remove(in_dev
, i
);
1674 __igmp_group_dropped(i
, gfp
);
1678 ip_rt_multicast_event(in_dev
);
1687 EXPORT_SYMBOL(__ip_mc_dec_group
);
1689 /* Device changing type */
1691 void ip_mc_unmap(struct in_device
*in_dev
)
1693 struct ip_mc_list
*pmc
;
1697 for_each_pmc_rtnl(in_dev
, pmc
)
1698 igmp_group_dropped(pmc
);
1701 void ip_mc_remap(struct in_device
*in_dev
)
1703 struct ip_mc_list
*pmc
;
1707 for_each_pmc_rtnl(in_dev
, pmc
) {
1708 #ifdef CONFIG_IP_MULTICAST
1709 igmpv3_del_delrec(in_dev
, pmc
);
1711 igmp_group_added(pmc
);
1715 /* Device going down */
1717 void ip_mc_down(struct in_device
*in_dev
)
1719 struct ip_mc_list
*pmc
;
1723 for_each_pmc_rtnl(in_dev
, pmc
)
1724 igmp_group_dropped(pmc
);
1726 #ifdef CONFIG_IP_MULTICAST
1727 in_dev
->mr_ifc_count
= 0;
1728 if (del_timer(&in_dev
->mr_ifc_timer
))
1729 __in_dev_put(in_dev
);
1730 in_dev
->mr_gq_running
= 0;
1731 if (del_timer(&in_dev
->mr_gq_timer
))
1732 __in_dev_put(in_dev
);
1735 ip_mc_dec_group(in_dev
, IGMP_ALL_HOSTS
);
1738 #ifdef CONFIG_IP_MULTICAST
1739 static void ip_mc_reset(struct in_device
*in_dev
)
1741 struct net
*net
= dev_net(in_dev
->dev
);
1743 in_dev
->mr_qi
= IGMP_QUERY_INTERVAL
;
1744 in_dev
->mr_qri
= IGMP_QUERY_RESPONSE_INTERVAL
;
1745 in_dev
->mr_qrv
= net
->ipv4
.sysctl_igmp_qrv
;
1748 static void ip_mc_reset(struct in_device
*in_dev
)
1753 void ip_mc_init_dev(struct in_device
*in_dev
)
1757 #ifdef CONFIG_IP_MULTICAST
1758 timer_setup(&in_dev
->mr_gq_timer
, igmp_gq_timer_expire
, 0);
1759 timer_setup(&in_dev
->mr_ifc_timer
, igmp_ifc_timer_expire
, 0);
1761 ip_mc_reset(in_dev
);
1763 spin_lock_init(&in_dev
->mc_tomb_lock
);
1766 /* Device going up */
1768 void ip_mc_up(struct in_device
*in_dev
)
1770 struct ip_mc_list
*pmc
;
1774 ip_mc_reset(in_dev
);
1775 ip_mc_inc_group(in_dev
, IGMP_ALL_HOSTS
);
1777 for_each_pmc_rtnl(in_dev
, pmc
) {
1778 #ifdef CONFIG_IP_MULTICAST
1779 igmpv3_del_delrec(in_dev
, pmc
);
1781 igmp_group_added(pmc
);
1786 * Device is about to be destroyed: clean up.
1789 void ip_mc_destroy_dev(struct in_device
*in_dev
)
1791 struct ip_mc_list
*i
;
1795 /* Deactivate timers */
1797 #ifdef CONFIG_IP_MULTICAST
1798 igmpv3_clear_delrec(in_dev
);
1801 while ((i
= rtnl_dereference(in_dev
->mc_list
)) != NULL
) {
1802 in_dev
->mc_list
= i
->next_rcu
;
1808 /* RTNL is locked */
1809 static struct in_device
*ip_mc_find_dev(struct net
*net
, struct ip_mreqn
*imr
)
1811 struct net_device
*dev
= NULL
;
1812 struct in_device
*idev
= NULL
;
1814 if (imr
->imr_ifindex
) {
1815 idev
= inetdev_by_index(net
, imr
->imr_ifindex
);
1818 if (imr
->imr_address
.s_addr
) {
1819 dev
= __ip_dev_find(net
, imr
->imr_address
.s_addr
, false);
1825 struct rtable
*rt
= ip_route_output(net
,
1826 imr
->imr_multiaddr
.s_addr
,
1834 imr
->imr_ifindex
= dev
->ifindex
;
1835 idev
= __in_dev_get_rtnl(dev
);
1841 * Join a socket to a group
1844 static int ip_mc_del1_src(struct ip_mc_list
*pmc
, int sfmode
,
1847 struct ip_sf_list
*psf
, *psf_prev
;
1851 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
) {
1852 if (psf
->sf_inaddr
== *psfsrc
)
1856 if (!psf
|| psf
->sf_count
[sfmode
] == 0) {
1857 /* source filter not found, or count wrong => bug */
1860 psf
->sf_count
[sfmode
]--;
1861 if (psf
->sf_count
[sfmode
] == 0) {
1862 ip_rt_multicast_event(pmc
->interface
);
1864 if (!psf
->sf_count
[MCAST_INCLUDE
] && !psf
->sf_count
[MCAST_EXCLUDE
]) {
1865 #ifdef CONFIG_IP_MULTICAST
1866 struct in_device
*in_dev
= pmc
->interface
;
1867 struct net
*net
= dev_net(in_dev
->dev
);
1870 /* no more filters for this source */
1872 psf_prev
->sf_next
= psf
->sf_next
;
1874 pmc
->sources
= psf
->sf_next
;
1875 #ifdef CONFIG_IP_MULTICAST
1876 if (psf
->sf_oldin
&&
1877 !IGMP_V1_SEEN(in_dev
) && !IGMP_V2_SEEN(in_dev
)) {
1878 psf
->sf_crcount
= in_dev
->mr_qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
1879 psf
->sf_next
= pmc
->tomb
;
1889 #ifndef CONFIG_IP_MULTICAST
1890 #define igmp_ifc_event(x) do { } while (0)
1893 static int ip_mc_del_src(struct in_device
*in_dev
, __be32
*pmca
, int sfmode
,
1894 int sfcount
, __be32
*psfsrc
, int delta
)
1896 struct ip_mc_list
*pmc
;
1903 for_each_pmc_rcu(in_dev
, pmc
) {
1904 if (*pmca
== pmc
->multiaddr
)
1908 /* MCA not found?? bug */
1912 spin_lock_bh(&pmc
->lock
);
1914 #ifdef CONFIG_IP_MULTICAST
1919 if (!pmc
->sfcount
[sfmode
])
1921 pmc
->sfcount
[sfmode
]--;
1924 for (i
= 0; i
< sfcount
; i
++) {
1925 int rv
= ip_mc_del1_src(pmc
, sfmode
, &psfsrc
[i
]);
1927 changerec
|= rv
> 0;
1931 if (pmc
->sfmode
== MCAST_EXCLUDE
&&
1932 pmc
->sfcount
[MCAST_EXCLUDE
] == 0 &&
1933 pmc
->sfcount
[MCAST_INCLUDE
]) {
1934 #ifdef CONFIG_IP_MULTICAST
1935 struct ip_sf_list
*psf
;
1936 struct net
*net
= dev_net(in_dev
->dev
);
1939 /* filter mode change */
1940 pmc
->sfmode
= MCAST_INCLUDE
;
1941 #ifdef CONFIG_IP_MULTICAST
1942 pmc
->crcount
= in_dev
->mr_qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
1943 in_dev
->mr_ifc_count
= pmc
->crcount
;
1944 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
)
1945 psf
->sf_crcount
= 0;
1946 igmp_ifc_event(pmc
->interface
);
1947 } else if (sf_setstate(pmc
) || changerec
) {
1948 igmp_ifc_event(pmc
->interface
);
1952 spin_unlock_bh(&pmc
->lock
);
1957 * Add multicast single-source filter to the interface list
1959 static int ip_mc_add1_src(struct ip_mc_list
*pmc
, int sfmode
,
1962 struct ip_sf_list
*psf
, *psf_prev
;
1965 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
) {
1966 if (psf
->sf_inaddr
== *psfsrc
)
1971 psf
= kzalloc(sizeof(*psf
), GFP_ATOMIC
);
1974 psf
->sf_inaddr
= *psfsrc
;
1976 psf_prev
->sf_next
= psf
;
1980 psf
->sf_count
[sfmode
]++;
1981 if (psf
->sf_count
[sfmode
] == 1) {
1982 ip_rt_multicast_event(pmc
->interface
);
1987 #ifdef CONFIG_IP_MULTICAST
1988 static void sf_markstate(struct ip_mc_list
*pmc
)
1990 struct ip_sf_list
*psf
;
1991 int mca_xcount
= pmc
->sfcount
[MCAST_EXCLUDE
];
1993 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
)
1994 if (pmc
->sfcount
[MCAST_EXCLUDE
]) {
1995 psf
->sf_oldin
= mca_xcount
==
1996 psf
->sf_count
[MCAST_EXCLUDE
] &&
1997 !psf
->sf_count
[MCAST_INCLUDE
];
1999 psf
->sf_oldin
= psf
->sf_count
[MCAST_INCLUDE
] != 0;
2002 static int sf_setstate(struct ip_mc_list
*pmc
)
2004 struct ip_sf_list
*psf
, *dpsf
;
2005 int mca_xcount
= pmc
->sfcount
[MCAST_EXCLUDE
];
2006 int qrv
= pmc
->interface
->mr_qrv
;
2010 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
) {
2011 if (pmc
->sfcount
[MCAST_EXCLUDE
]) {
2012 new_in
= mca_xcount
== psf
->sf_count
[MCAST_EXCLUDE
] &&
2013 !psf
->sf_count
[MCAST_INCLUDE
];
2015 new_in
= psf
->sf_count
[MCAST_INCLUDE
] != 0;
2017 if (!psf
->sf_oldin
) {
2018 struct ip_sf_list
*prev
= NULL
;
2020 for (dpsf
= pmc
->tomb
; dpsf
; dpsf
= dpsf
->sf_next
) {
2021 if (dpsf
->sf_inaddr
== psf
->sf_inaddr
)
2027 prev
->sf_next
= dpsf
->sf_next
;
2029 pmc
->tomb
= dpsf
->sf_next
;
2032 psf
->sf_crcount
= qrv
;
2035 } else if (psf
->sf_oldin
) {
2037 psf
->sf_crcount
= 0;
2039 * add or update "delete" records if an active filter
2042 for (dpsf
= pmc
->tomb
; dpsf
; dpsf
= dpsf
->sf_next
)
2043 if (dpsf
->sf_inaddr
== psf
->sf_inaddr
)
2046 dpsf
= kmalloc(sizeof(*dpsf
), GFP_ATOMIC
);
2050 /* pmc->lock held by callers */
2051 dpsf
->sf_next
= pmc
->tomb
;
2054 dpsf
->sf_crcount
= qrv
;
2063 * Add multicast source filter list to the interface list
2065 static int ip_mc_add_src(struct in_device
*in_dev
, __be32
*pmca
, int sfmode
,
2066 int sfcount
, __be32
*psfsrc
, int delta
)
2068 struct ip_mc_list
*pmc
;
2075 for_each_pmc_rcu(in_dev
, pmc
) {
2076 if (*pmca
== pmc
->multiaddr
)
2080 /* MCA not found?? bug */
2084 spin_lock_bh(&pmc
->lock
);
2087 #ifdef CONFIG_IP_MULTICAST
2090 isexclude
= pmc
->sfmode
== MCAST_EXCLUDE
;
2092 pmc
->sfcount
[sfmode
]++;
2094 for (i
= 0; i
< sfcount
; i
++) {
2095 err
= ip_mc_add1_src(pmc
, sfmode
, &psfsrc
[i
]);
2103 pmc
->sfcount
[sfmode
]--;
2104 for (j
= 0; j
< i
; j
++)
2105 (void) ip_mc_del1_src(pmc
, sfmode
, &psfsrc
[j
]);
2106 } else if (isexclude
!= (pmc
->sfcount
[MCAST_EXCLUDE
] != 0)) {
2107 #ifdef CONFIG_IP_MULTICAST
2108 struct ip_sf_list
*psf
;
2109 struct net
*net
= dev_net(pmc
->interface
->dev
);
2110 in_dev
= pmc
->interface
;
2113 /* filter mode change */
2114 if (pmc
->sfcount
[MCAST_EXCLUDE
])
2115 pmc
->sfmode
= MCAST_EXCLUDE
;
2116 else if (pmc
->sfcount
[MCAST_INCLUDE
])
2117 pmc
->sfmode
= MCAST_INCLUDE
;
2118 #ifdef CONFIG_IP_MULTICAST
2119 /* else no filters; keep old mode for reports */
2121 pmc
->crcount
= in_dev
->mr_qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
2122 in_dev
->mr_ifc_count
= pmc
->crcount
;
2123 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
)
2124 psf
->sf_crcount
= 0;
2125 igmp_ifc_event(in_dev
);
2126 } else if (sf_setstate(pmc
)) {
2127 igmp_ifc_event(in_dev
);
2130 spin_unlock_bh(&pmc
->lock
);
2134 static void ip_mc_clear_src(struct ip_mc_list
*pmc
)
2136 struct ip_sf_list
*tomb
, *sources
;
2138 spin_lock_bh(&pmc
->lock
);
2141 sources
= pmc
->sources
;
2142 pmc
->sources
= NULL
;
2143 pmc
->sfmode
= MCAST_EXCLUDE
;
2144 pmc
->sfcount
[MCAST_INCLUDE
] = 0;
2145 pmc
->sfcount
[MCAST_EXCLUDE
] = 1;
2146 spin_unlock_bh(&pmc
->lock
);
2148 ip_sf_list_clear_all(tomb
);
2149 ip_sf_list_clear_all(sources
);
2152 /* Join a multicast group
2154 static int __ip_mc_join_group(struct sock
*sk
, struct ip_mreqn
*imr
,
2157 __be32 addr
= imr
->imr_multiaddr
.s_addr
;
2158 struct ip_mc_socklist
*iml
, *i
;
2159 struct in_device
*in_dev
;
2160 struct inet_sock
*inet
= inet_sk(sk
);
2161 struct net
*net
= sock_net(sk
);
2168 if (!ipv4_is_multicast(addr
))
2171 in_dev
= ip_mc_find_dev(net
, imr
);
2179 ifindex
= imr
->imr_ifindex
;
2180 for_each_pmc_rtnl(inet
, i
) {
2181 if (i
->multi
.imr_multiaddr
.s_addr
== addr
&&
2182 i
->multi
.imr_ifindex
== ifindex
)
2187 if (count
>= net
->ipv4
.sysctl_igmp_max_memberships
)
2189 iml
= sock_kmalloc(sk
, sizeof(*iml
), GFP_KERNEL
);
2193 memcpy(&iml
->multi
, imr
, sizeof(*imr
));
2194 iml
->next_rcu
= inet
->mc_list
;
2197 rcu_assign_pointer(inet
->mc_list
, iml
);
2198 ____ip_mc_inc_group(in_dev
, addr
, mode
, GFP_KERNEL
);
2204 /* Join ASM (Any-Source Multicast) group
2206 int ip_mc_join_group(struct sock
*sk
, struct ip_mreqn
*imr
)
2208 return __ip_mc_join_group(sk
, imr
, MCAST_EXCLUDE
);
2210 EXPORT_SYMBOL(ip_mc_join_group
);
2212 /* Join SSM (Source-Specific Multicast) group
2214 int ip_mc_join_group_ssm(struct sock
*sk
, struct ip_mreqn
*imr
,
2217 return __ip_mc_join_group(sk
, imr
, mode
);
2220 static int ip_mc_leave_src(struct sock
*sk
, struct ip_mc_socklist
*iml
,
2221 struct in_device
*in_dev
)
2223 struct ip_sf_socklist
*psf
= rtnl_dereference(iml
->sflist
);
2227 /* any-source empty exclude case */
2228 return ip_mc_del_src(in_dev
, &iml
->multi
.imr_multiaddr
.s_addr
,
2229 iml
->sfmode
, 0, NULL
, 0);
2231 err
= ip_mc_del_src(in_dev
, &iml
->multi
.imr_multiaddr
.s_addr
,
2232 iml
->sfmode
, psf
->sl_count
, psf
->sl_addr
, 0);
2233 RCU_INIT_POINTER(iml
->sflist
, NULL
);
2234 /* decrease mem now to avoid the memleak warning */
2235 atomic_sub(IP_SFLSIZE(psf
->sl_max
), &sk
->sk_omem_alloc
);
2236 kfree_rcu(psf
, rcu
);
2240 int ip_mc_leave_group(struct sock
*sk
, struct ip_mreqn
*imr
)
2242 struct inet_sock
*inet
= inet_sk(sk
);
2243 struct ip_mc_socklist
*iml
;
2244 struct ip_mc_socklist __rcu
**imlp
;
2245 struct in_device
*in_dev
;
2246 struct net
*net
= sock_net(sk
);
2247 __be32 group
= imr
->imr_multiaddr
.s_addr
;
2249 int ret
= -EADDRNOTAVAIL
;
2253 in_dev
= ip_mc_find_dev(net
, imr
);
2254 if (!imr
->imr_ifindex
&& !imr
->imr_address
.s_addr
&& !in_dev
) {
2258 ifindex
= imr
->imr_ifindex
;
2259 for (imlp
= &inet
->mc_list
;
2260 (iml
= rtnl_dereference(*imlp
)) != NULL
;
2261 imlp
= &iml
->next_rcu
) {
2262 if (iml
->multi
.imr_multiaddr
.s_addr
!= group
)
2265 if (iml
->multi
.imr_ifindex
!= ifindex
)
2267 } else if (imr
->imr_address
.s_addr
&& imr
->imr_address
.s_addr
!=
2268 iml
->multi
.imr_address
.s_addr
)
2271 (void) ip_mc_leave_src(sk
, iml
, in_dev
);
2273 *imlp
= iml
->next_rcu
;
2276 ip_mc_dec_group(in_dev
, group
);
2278 /* decrease mem now to avoid the memleak warning */
2279 atomic_sub(sizeof(*iml
), &sk
->sk_omem_alloc
);
2280 kfree_rcu(iml
, rcu
);
2286 EXPORT_SYMBOL(ip_mc_leave_group
);
2288 int ip_mc_source(int add
, int omode
, struct sock
*sk
, struct
2289 ip_mreq_source
*mreqs
, int ifindex
)
2292 struct ip_mreqn imr
;
2293 __be32 addr
= mreqs
->imr_multiaddr
;
2294 struct ip_mc_socklist
*pmc
;
2295 struct in_device
*in_dev
= NULL
;
2296 struct inet_sock
*inet
= inet_sk(sk
);
2297 struct ip_sf_socklist
*psl
;
2298 struct net
*net
= sock_net(sk
);
2302 if (!ipv4_is_multicast(addr
))
2307 imr
.imr_multiaddr
.s_addr
= mreqs
->imr_multiaddr
;
2308 imr
.imr_address
.s_addr
= mreqs
->imr_interface
;
2309 imr
.imr_ifindex
= ifindex
;
2310 in_dev
= ip_mc_find_dev(net
, &imr
);
2316 err
= -EADDRNOTAVAIL
;
2318 for_each_pmc_rtnl(inet
, pmc
) {
2319 if ((pmc
->multi
.imr_multiaddr
.s_addr
==
2320 imr
.imr_multiaddr
.s_addr
) &&
2321 (pmc
->multi
.imr_ifindex
== imr
.imr_ifindex
))
2324 if (!pmc
) { /* must have a prior join */
2328 /* if a source filter was set, must be the same mode as before */
2330 if (pmc
->sfmode
!= omode
) {
2334 } else if (pmc
->sfmode
!= omode
) {
2335 /* allow mode switches for empty-set filters */
2336 ip_mc_add_src(in_dev
, &mreqs
->imr_multiaddr
, omode
, 0, NULL
, 0);
2337 ip_mc_del_src(in_dev
, &mreqs
->imr_multiaddr
, pmc
->sfmode
, 0,
2339 pmc
->sfmode
= omode
;
2342 psl
= rtnl_dereference(pmc
->sflist
);
2345 goto done
; /* err = -EADDRNOTAVAIL */
2347 for (i
= 0; i
< psl
->sl_count
; i
++) {
2348 rv
= memcmp(&psl
->sl_addr
[i
], &mreqs
->imr_sourceaddr
,
2353 if (rv
) /* source not found */
2354 goto done
; /* err = -EADDRNOTAVAIL */
2356 /* special case - (INCLUDE, empty) == LEAVE_GROUP */
2357 if (psl
->sl_count
== 1 && omode
== MCAST_INCLUDE
) {
2362 /* update the interface filter */
2363 ip_mc_del_src(in_dev
, &mreqs
->imr_multiaddr
, omode
, 1,
2364 &mreqs
->imr_sourceaddr
, 1);
2366 for (j
= i
+1; j
< psl
->sl_count
; j
++)
2367 psl
->sl_addr
[j
-1] = psl
->sl_addr
[j
];
2372 /* else, add a new source to the filter */
2374 if (psl
&& psl
->sl_count
>= net
->ipv4
.sysctl_igmp_max_msf
) {
2378 if (!psl
|| psl
->sl_count
== psl
->sl_max
) {
2379 struct ip_sf_socklist
*newpsl
;
2380 int count
= IP_SFBLOCK
;
2383 count
+= psl
->sl_max
;
2384 newpsl
= sock_kmalloc(sk
, IP_SFLSIZE(count
), GFP_KERNEL
);
2389 newpsl
->sl_max
= count
;
2390 newpsl
->sl_count
= count
- IP_SFBLOCK
;
2392 for (i
= 0; i
< psl
->sl_count
; i
++)
2393 newpsl
->sl_addr
[i
] = psl
->sl_addr
[i
];
2394 /* decrease mem now to avoid the memleak warning */
2395 atomic_sub(IP_SFLSIZE(psl
->sl_max
), &sk
->sk_omem_alloc
);
2396 kfree_rcu(psl
, rcu
);
2398 rcu_assign_pointer(pmc
->sflist
, newpsl
);
2401 rv
= 1; /* > 0 for insert logic below if sl_count is 0 */
2402 for (i
= 0; i
< psl
->sl_count
; i
++) {
2403 rv
= memcmp(&psl
->sl_addr
[i
], &mreqs
->imr_sourceaddr
,
2408 if (rv
== 0) /* address already there is an error */
2410 for (j
= psl
->sl_count
-1; j
>= i
; j
--)
2411 psl
->sl_addr
[j
+1] = psl
->sl_addr
[j
];
2412 psl
->sl_addr
[i
] = mreqs
->imr_sourceaddr
;
2415 /* update the interface list */
2416 ip_mc_add_src(in_dev
, &mreqs
->imr_multiaddr
, omode
, 1,
2417 &mreqs
->imr_sourceaddr
, 1);
2420 err
= ip_mc_leave_group(sk
, &imr
);
2424 int ip_mc_msfilter(struct sock
*sk
, struct ip_msfilter
*msf
, int ifindex
)
2427 struct ip_mreqn imr
;
2428 __be32 addr
= msf
->imsf_multiaddr
;
2429 struct ip_mc_socklist
*pmc
;
2430 struct in_device
*in_dev
;
2431 struct inet_sock
*inet
= inet_sk(sk
);
2432 struct ip_sf_socklist
*newpsl
, *psl
;
2433 struct net
*net
= sock_net(sk
);
2436 if (!ipv4_is_multicast(addr
))
2438 if (msf
->imsf_fmode
!= MCAST_INCLUDE
&&
2439 msf
->imsf_fmode
!= MCAST_EXCLUDE
)
2444 imr
.imr_multiaddr
.s_addr
= msf
->imsf_multiaddr
;
2445 imr
.imr_address
.s_addr
= msf
->imsf_interface
;
2446 imr
.imr_ifindex
= ifindex
;
2447 in_dev
= ip_mc_find_dev(net
, &imr
);
2454 /* special case - (INCLUDE, empty) == LEAVE_GROUP */
2455 if (msf
->imsf_fmode
== MCAST_INCLUDE
&& msf
->imsf_numsrc
== 0) {
2460 for_each_pmc_rtnl(inet
, pmc
) {
2461 if (pmc
->multi
.imr_multiaddr
.s_addr
== msf
->imsf_multiaddr
&&
2462 pmc
->multi
.imr_ifindex
== imr
.imr_ifindex
)
2465 if (!pmc
) { /* must have a prior join */
2469 if (msf
->imsf_numsrc
) {
2470 newpsl
= sock_kmalloc(sk
, IP_SFLSIZE(msf
->imsf_numsrc
),
2476 newpsl
->sl_max
= newpsl
->sl_count
= msf
->imsf_numsrc
;
2477 memcpy(newpsl
->sl_addr
, msf
->imsf_slist
,
2478 msf
->imsf_numsrc
* sizeof(msf
->imsf_slist
[0]));
2479 err
= ip_mc_add_src(in_dev
, &msf
->imsf_multiaddr
,
2480 msf
->imsf_fmode
, newpsl
->sl_count
, newpsl
->sl_addr
, 0);
2482 sock_kfree_s(sk
, newpsl
, IP_SFLSIZE(newpsl
->sl_max
));
2487 (void) ip_mc_add_src(in_dev
, &msf
->imsf_multiaddr
,
2488 msf
->imsf_fmode
, 0, NULL
, 0);
2490 psl
= rtnl_dereference(pmc
->sflist
);
2492 (void) ip_mc_del_src(in_dev
, &msf
->imsf_multiaddr
, pmc
->sfmode
,
2493 psl
->sl_count
, psl
->sl_addr
, 0);
2494 /* decrease mem now to avoid the memleak warning */
2495 atomic_sub(IP_SFLSIZE(psl
->sl_max
), &sk
->sk_omem_alloc
);
2496 kfree_rcu(psl
, rcu
);
2498 (void) ip_mc_del_src(in_dev
, &msf
->imsf_multiaddr
, pmc
->sfmode
,
2500 rcu_assign_pointer(pmc
->sflist
, newpsl
);
2501 pmc
->sfmode
= msf
->imsf_fmode
;
2505 err
= ip_mc_leave_group(sk
, &imr
);
2509 int ip_mc_msfget(struct sock
*sk
, struct ip_msfilter
*msf
,
2510 struct ip_msfilter __user
*optval
, int __user
*optlen
)
2512 int err
, len
, count
, copycount
;
2513 struct ip_mreqn imr
;
2514 __be32 addr
= msf
->imsf_multiaddr
;
2515 struct ip_mc_socklist
*pmc
;
2516 struct in_device
*in_dev
;
2517 struct inet_sock
*inet
= inet_sk(sk
);
2518 struct ip_sf_socklist
*psl
;
2519 struct net
*net
= sock_net(sk
);
2523 if (!ipv4_is_multicast(addr
))
2526 imr
.imr_multiaddr
.s_addr
= msf
->imsf_multiaddr
;
2527 imr
.imr_address
.s_addr
= msf
->imsf_interface
;
2528 imr
.imr_ifindex
= 0;
2529 in_dev
= ip_mc_find_dev(net
, &imr
);
2535 err
= -EADDRNOTAVAIL
;
2537 for_each_pmc_rtnl(inet
, pmc
) {
2538 if (pmc
->multi
.imr_multiaddr
.s_addr
== msf
->imsf_multiaddr
&&
2539 pmc
->multi
.imr_ifindex
== imr
.imr_ifindex
)
2542 if (!pmc
) /* must have a prior join */
2544 msf
->imsf_fmode
= pmc
->sfmode
;
2545 psl
= rtnl_dereference(pmc
->sflist
);
2550 count
= psl
->sl_count
;
2552 copycount
= count
< msf
->imsf_numsrc
? count
: msf
->imsf_numsrc
;
2553 len
= copycount
* sizeof(psl
->sl_addr
[0]);
2554 msf
->imsf_numsrc
= count
;
2555 if (put_user(IP_MSFILTER_SIZE(copycount
), optlen
) ||
2556 copy_to_user(optval
, msf
, IP_MSFILTER_SIZE(0))) {
2560 copy_to_user(&optval
->imsf_slist
[0], psl
->sl_addr
, len
))
2567 int ip_mc_gsfget(struct sock
*sk
, struct group_filter
*gsf
,
2568 struct group_filter __user
*optval
, int __user
*optlen
)
2570 int err
, i
, count
, copycount
;
2571 struct sockaddr_in
*psin
;
2573 struct ip_mc_socklist
*pmc
;
2574 struct inet_sock
*inet
= inet_sk(sk
);
2575 struct ip_sf_socklist
*psl
;
2579 psin
= (struct sockaddr_in
*)&gsf
->gf_group
;
2580 if (psin
->sin_family
!= AF_INET
)
2582 addr
= psin
->sin_addr
.s_addr
;
2583 if (!ipv4_is_multicast(addr
))
2586 err
= -EADDRNOTAVAIL
;
2588 for_each_pmc_rtnl(inet
, pmc
) {
2589 if (pmc
->multi
.imr_multiaddr
.s_addr
== addr
&&
2590 pmc
->multi
.imr_ifindex
== gsf
->gf_interface
)
2593 if (!pmc
) /* must have a prior join */
2595 gsf
->gf_fmode
= pmc
->sfmode
;
2596 psl
= rtnl_dereference(pmc
->sflist
);
2597 count
= psl
? psl
->sl_count
: 0;
2598 copycount
= count
< gsf
->gf_numsrc
? count
: gsf
->gf_numsrc
;
2599 gsf
->gf_numsrc
= count
;
2600 if (put_user(GROUP_FILTER_SIZE(copycount
), optlen
) ||
2601 copy_to_user(optval
, gsf
, GROUP_FILTER_SIZE(0))) {
2604 for (i
= 0; i
< copycount
; i
++) {
2605 struct sockaddr_storage ss
;
2607 psin
= (struct sockaddr_in
*)&ss
;
2608 memset(&ss
, 0, sizeof(ss
));
2609 psin
->sin_family
= AF_INET
;
2610 psin
->sin_addr
.s_addr
= psl
->sl_addr
[i
];
2611 if (copy_to_user(&optval
->gf_slist
[i
], &ss
, sizeof(ss
)))
2620 * check if a multicast source filter allows delivery for a given <src,dst,intf>
2622 int ip_mc_sf_allow(struct sock
*sk
, __be32 loc_addr
, __be32 rmt_addr
,
2625 struct inet_sock
*inet
= inet_sk(sk
);
2626 struct ip_mc_socklist
*pmc
;
2627 struct ip_sf_socklist
*psl
;
2632 if (!ipv4_is_multicast(loc_addr
))
2636 for_each_pmc_rcu(inet
, pmc
) {
2637 if (pmc
->multi
.imr_multiaddr
.s_addr
== loc_addr
&&
2638 (pmc
->multi
.imr_ifindex
== dif
||
2639 (sdif
&& pmc
->multi
.imr_ifindex
== sdif
)))
2645 psl
= rcu_dereference(pmc
->sflist
);
2646 ret
= (pmc
->sfmode
== MCAST_EXCLUDE
);
2650 for (i
= 0; i
< psl
->sl_count
; i
++) {
2651 if (psl
->sl_addr
[i
] == rmt_addr
)
2655 if (pmc
->sfmode
== MCAST_INCLUDE
&& i
>= psl
->sl_count
)
2657 if (pmc
->sfmode
== MCAST_EXCLUDE
&& i
< psl
->sl_count
)
2667 * A socket is closing.
2670 void ip_mc_drop_socket(struct sock
*sk
)
2672 struct inet_sock
*inet
= inet_sk(sk
);
2673 struct ip_mc_socklist
*iml
;
2674 struct net
*net
= sock_net(sk
);
2680 while ((iml
= rtnl_dereference(inet
->mc_list
)) != NULL
) {
2681 struct in_device
*in_dev
;
2683 inet
->mc_list
= iml
->next_rcu
;
2684 in_dev
= inetdev_by_index(net
, iml
->multi
.imr_ifindex
);
2685 (void) ip_mc_leave_src(sk
, iml
, in_dev
);
2687 ip_mc_dec_group(in_dev
, iml
->multi
.imr_multiaddr
.s_addr
);
2688 /* decrease mem now to avoid the memleak warning */
2689 atomic_sub(sizeof(*iml
), &sk
->sk_omem_alloc
);
2690 kfree_rcu(iml
, rcu
);
2695 /* called with rcu_read_lock() */
2696 int ip_check_mc_rcu(struct in_device
*in_dev
, __be32 mc_addr
, __be32 src_addr
, u8 proto
)
2698 struct ip_mc_list
*im
;
2699 struct ip_mc_list __rcu
**mc_hash
;
2700 struct ip_sf_list
*psf
;
2703 mc_hash
= rcu_dereference(in_dev
->mc_hash
);
2705 u32 hash
= hash_32((__force u32
)mc_addr
, MC_HASH_SZ_LOG
);
2707 for (im
= rcu_dereference(mc_hash
[hash
]);
2709 im
= rcu_dereference(im
->next_hash
)) {
2710 if (im
->multiaddr
== mc_addr
)
2714 for_each_pmc_rcu(in_dev
, im
) {
2715 if (im
->multiaddr
== mc_addr
)
2719 if (im
&& proto
== IPPROTO_IGMP
) {
2723 for (psf
= im
->sources
; psf
; psf
= psf
->sf_next
) {
2724 if (psf
->sf_inaddr
== src_addr
)
2728 rv
= psf
->sf_count
[MCAST_INCLUDE
] ||
2729 psf
->sf_count
[MCAST_EXCLUDE
] !=
2730 im
->sfcount
[MCAST_EXCLUDE
];
2732 rv
= im
->sfcount
[MCAST_EXCLUDE
] != 0;
2734 rv
= 1; /* unspecified source; tentatively allow */
2739 #if defined(CONFIG_PROC_FS)
2740 struct igmp_mc_iter_state
{
2741 struct seq_net_private p
;
2742 struct net_device
*dev
;
2743 struct in_device
*in_dev
;
2746 #define igmp_mc_seq_private(seq) ((struct igmp_mc_iter_state *)(seq)->private)
2748 static inline struct ip_mc_list
*igmp_mc_get_first(struct seq_file
*seq
)
2750 struct net
*net
= seq_file_net(seq
);
2751 struct ip_mc_list
*im
= NULL
;
2752 struct igmp_mc_iter_state
*state
= igmp_mc_seq_private(seq
);
2754 state
->in_dev
= NULL
;
2755 for_each_netdev_rcu(net
, state
->dev
) {
2756 struct in_device
*in_dev
;
2758 in_dev
= __in_dev_get_rcu(state
->dev
);
2761 im
= rcu_dereference(in_dev
->mc_list
);
2763 state
->in_dev
= in_dev
;
2770 static struct ip_mc_list
*igmp_mc_get_next(struct seq_file
*seq
, struct ip_mc_list
*im
)
2772 struct igmp_mc_iter_state
*state
= igmp_mc_seq_private(seq
);
2774 im
= rcu_dereference(im
->next_rcu
);
2776 state
->dev
= next_net_device_rcu(state
->dev
);
2778 state
->in_dev
= NULL
;
2781 state
->in_dev
= __in_dev_get_rcu(state
->dev
);
2784 im
= rcu_dereference(state
->in_dev
->mc_list
);
2789 static struct ip_mc_list
*igmp_mc_get_idx(struct seq_file
*seq
, loff_t pos
)
2791 struct ip_mc_list
*im
= igmp_mc_get_first(seq
);
2793 while (pos
&& (im
= igmp_mc_get_next(seq
, im
)) != NULL
)
2795 return pos
? NULL
: im
;
2798 static void *igmp_mc_seq_start(struct seq_file
*seq
, loff_t
*pos
)
2802 return *pos
? igmp_mc_get_idx(seq
, *pos
- 1) : SEQ_START_TOKEN
;
2805 static void *igmp_mc_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
2807 struct ip_mc_list
*im
;
2808 if (v
== SEQ_START_TOKEN
)
2809 im
= igmp_mc_get_first(seq
);
2811 im
= igmp_mc_get_next(seq
, v
);
2816 static void igmp_mc_seq_stop(struct seq_file
*seq
, void *v
)
2819 struct igmp_mc_iter_state
*state
= igmp_mc_seq_private(seq
);
2821 state
->in_dev
= NULL
;
2826 static int igmp_mc_seq_show(struct seq_file
*seq
, void *v
)
2828 if (v
== SEQ_START_TOKEN
)
2830 "Idx\tDevice : Count Querier\tGroup Users Timer\tReporter\n");
2832 struct ip_mc_list
*im
= (struct ip_mc_list
*)v
;
2833 struct igmp_mc_iter_state
*state
= igmp_mc_seq_private(seq
);
2837 #ifdef CONFIG_IP_MULTICAST
2838 querier
= IGMP_V1_SEEN(state
->in_dev
) ? "V1" :
2839 IGMP_V2_SEEN(state
->in_dev
) ? "V2" :
2845 if (rcu_access_pointer(state
->in_dev
->mc_list
) == im
) {
2846 seq_printf(seq
, "%d\t%-10s: %5d %7s\n",
2847 state
->dev
->ifindex
, state
->dev
->name
, state
->in_dev
->mc_count
, querier
);
2850 delta
= im
->timer
.expires
- jiffies
;
2852 "\t\t\t\t%08X %5d %d:%08lX\t\t%d\n",
2853 im
->multiaddr
, im
->users
,
2855 im
->tm_running
? jiffies_delta_to_clock_t(delta
) : 0,
2861 static const struct seq_operations igmp_mc_seq_ops
= {
2862 .start
= igmp_mc_seq_start
,
2863 .next
= igmp_mc_seq_next
,
2864 .stop
= igmp_mc_seq_stop
,
2865 .show
= igmp_mc_seq_show
,
2868 struct igmp_mcf_iter_state
{
2869 struct seq_net_private p
;
2870 struct net_device
*dev
;
2871 struct in_device
*idev
;
2872 struct ip_mc_list
*im
;
2875 #define igmp_mcf_seq_private(seq) ((struct igmp_mcf_iter_state *)(seq)->private)
2877 static inline struct ip_sf_list
*igmp_mcf_get_first(struct seq_file
*seq
)
2879 struct net
*net
= seq_file_net(seq
);
2880 struct ip_sf_list
*psf
= NULL
;
2881 struct ip_mc_list
*im
= NULL
;
2882 struct igmp_mcf_iter_state
*state
= igmp_mcf_seq_private(seq
);
2886 for_each_netdev_rcu(net
, state
->dev
) {
2887 struct in_device
*idev
;
2888 idev
= __in_dev_get_rcu(state
->dev
);
2889 if (unlikely(!idev
))
2891 im
= rcu_dereference(idev
->mc_list
);
2893 spin_lock_bh(&im
->lock
);
2900 spin_unlock_bh(&im
->lock
);
2906 static struct ip_sf_list
*igmp_mcf_get_next(struct seq_file
*seq
, struct ip_sf_list
*psf
)
2908 struct igmp_mcf_iter_state
*state
= igmp_mcf_seq_private(seq
);
2912 spin_unlock_bh(&state
->im
->lock
);
2913 state
->im
= state
->im
->next
;
2914 while (!state
->im
) {
2915 state
->dev
= next_net_device_rcu(state
->dev
);
2920 state
->idev
= __in_dev_get_rcu(state
->dev
);
2923 state
->im
= rcu_dereference(state
->idev
->mc_list
);
2927 spin_lock_bh(&state
->im
->lock
);
2928 psf
= state
->im
->sources
;
2934 static struct ip_sf_list
*igmp_mcf_get_idx(struct seq_file
*seq
, loff_t pos
)
2936 struct ip_sf_list
*psf
= igmp_mcf_get_first(seq
);
2938 while (pos
&& (psf
= igmp_mcf_get_next(seq
, psf
)) != NULL
)
2940 return pos
? NULL
: psf
;
2943 static void *igmp_mcf_seq_start(struct seq_file
*seq
, loff_t
*pos
)
2947 return *pos
? igmp_mcf_get_idx(seq
, *pos
- 1) : SEQ_START_TOKEN
;
2950 static void *igmp_mcf_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
2952 struct ip_sf_list
*psf
;
2953 if (v
== SEQ_START_TOKEN
)
2954 psf
= igmp_mcf_get_first(seq
);
2956 psf
= igmp_mcf_get_next(seq
, v
);
2961 static void igmp_mcf_seq_stop(struct seq_file
*seq
, void *v
)
2964 struct igmp_mcf_iter_state
*state
= igmp_mcf_seq_private(seq
);
2965 if (likely(state
->im
)) {
2966 spin_unlock_bh(&state
->im
->lock
);
2974 static int igmp_mcf_seq_show(struct seq_file
*seq
, void *v
)
2976 struct ip_sf_list
*psf
= (struct ip_sf_list
*)v
;
2977 struct igmp_mcf_iter_state
*state
= igmp_mcf_seq_private(seq
);
2979 if (v
== SEQ_START_TOKEN
) {
2980 seq_puts(seq
, "Idx Device MCA SRC INC EXC\n");
2984 "0x%08x %6lu %6lu\n",
2985 state
->dev
->ifindex
, state
->dev
->name
,
2986 ntohl(state
->im
->multiaddr
),
2987 ntohl(psf
->sf_inaddr
),
2988 psf
->sf_count
[MCAST_INCLUDE
],
2989 psf
->sf_count
[MCAST_EXCLUDE
]);
2994 static const struct seq_operations igmp_mcf_seq_ops
= {
2995 .start
= igmp_mcf_seq_start
,
2996 .next
= igmp_mcf_seq_next
,
2997 .stop
= igmp_mcf_seq_stop
,
2998 .show
= igmp_mcf_seq_show
,
3001 static int __net_init
igmp_net_init(struct net
*net
)
3003 struct proc_dir_entry
*pde
;
3006 pde
= proc_create_net("igmp", 0444, net
->proc_net
, &igmp_mc_seq_ops
,
3007 sizeof(struct igmp_mc_iter_state
));
3010 pde
= proc_create_net("mcfilter", 0444, net
->proc_net
,
3011 &igmp_mcf_seq_ops
, sizeof(struct igmp_mcf_iter_state
));
3014 err
= inet_ctl_sock_create(&net
->ipv4
.mc_autojoin_sk
, AF_INET
,
3015 SOCK_DGRAM
, 0, net
);
3017 pr_err("Failed to initialize the IGMP autojoin socket (err %d)\n",
3025 remove_proc_entry("mcfilter", net
->proc_net
);
3027 remove_proc_entry("igmp", net
->proc_net
);
3032 static void __net_exit
igmp_net_exit(struct net
*net
)
3034 remove_proc_entry("mcfilter", net
->proc_net
);
3035 remove_proc_entry("igmp", net
->proc_net
);
3036 inet_ctl_sock_destroy(net
->ipv4
.mc_autojoin_sk
);
3039 static struct pernet_operations igmp_net_ops
= {
3040 .init
= igmp_net_init
,
3041 .exit
= igmp_net_exit
,
3045 static int igmp_netdev_event(struct notifier_block
*this,
3046 unsigned long event
, void *ptr
)
3048 struct net_device
*dev
= netdev_notifier_info_to_dev(ptr
);
3049 struct in_device
*in_dev
;
3052 case NETDEV_RESEND_IGMP
:
3053 in_dev
= __in_dev_get_rtnl(dev
);
3055 ip_mc_rejoin_groups(in_dev
);
3063 static struct notifier_block igmp_notifier
= {
3064 .notifier_call
= igmp_netdev_event
,
3067 int __init
igmp_mc_init(void)
3069 #if defined(CONFIG_PROC_FS)
3072 err
= register_pernet_subsys(&igmp_net_ops
);
3075 err
= register_netdevice_notifier(&igmp_notifier
);
3077 goto reg_notif_fail
;
3081 unregister_pernet_subsys(&igmp_net_ops
);
3084 return register_netdevice_notifier(&igmp_notifier
);