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_V2_UNSOLICITED_REPORT_INTERVAL (10*HZ)
111 #define IGMP_V3_UNSOLICITED_REPORT_INTERVAL (1*HZ)
112 #define IGMP_QUERY_INTERVAL (125*HZ)
113 #define IGMP_QUERY_RESPONSE_INTERVAL (10*HZ)
115 #define IGMP_INITIAL_REPORT_DELAY (1)
117 /* IGMP_INITIAL_REPORT_DELAY is not from IGMP specs!
118 * IGMP specs require to report membership immediately after
119 * joining a group, but we delay the first report by a
120 * small interval. It seems more natural and still does not
121 * contradict to specs provided this delay is small enough.
124 #define IGMP_V1_SEEN(in_dev) \
125 (IPV4_DEVCONF_ALL(dev_net(in_dev->dev), FORCE_IGMP_VERSION) == 1 || \
126 IN_DEV_CONF_GET((in_dev), FORCE_IGMP_VERSION) == 1 || \
127 ((in_dev)->mr_v1_seen && \
128 time_before(jiffies, (in_dev)->mr_v1_seen)))
129 #define IGMP_V2_SEEN(in_dev) \
130 (IPV4_DEVCONF_ALL(dev_net(in_dev->dev), FORCE_IGMP_VERSION) == 2 || \
131 IN_DEV_CONF_GET((in_dev), FORCE_IGMP_VERSION) == 2 || \
132 ((in_dev)->mr_v2_seen && \
133 time_before(jiffies, (in_dev)->mr_v2_seen)))
135 static int unsolicited_report_interval(struct in_device
*in_dev
)
137 int interval_ms
, interval_jiffies
;
139 if (IGMP_V1_SEEN(in_dev
) || IGMP_V2_SEEN(in_dev
))
140 interval_ms
= IN_DEV_CONF_GET(
142 IGMPV2_UNSOLICITED_REPORT_INTERVAL
);
144 interval_ms
= IN_DEV_CONF_GET(
146 IGMPV3_UNSOLICITED_REPORT_INTERVAL
);
148 interval_jiffies
= msecs_to_jiffies(interval_ms
);
150 /* _timer functions can't handle a delay of 0 jiffies so ensure
151 * we always return a positive value.
153 if (interval_jiffies
<= 0)
154 interval_jiffies
= 1;
155 return interval_jiffies
;
158 static void igmpv3_add_delrec(struct in_device
*in_dev
, struct ip_mc_list
*im
,
160 static void igmpv3_del_delrec(struct in_device
*in_dev
, struct ip_mc_list
*im
);
161 static void igmpv3_clear_delrec(struct in_device
*in_dev
);
162 static int sf_setstate(struct ip_mc_list
*pmc
);
163 static void sf_markstate(struct ip_mc_list
*pmc
);
165 static void ip_mc_clear_src(struct ip_mc_list
*pmc
);
166 static int ip_mc_add_src(struct in_device
*in_dev
, __be32
*pmca
, int sfmode
,
167 int sfcount
, __be32
*psfsrc
, int delta
);
169 static void ip_ma_put(struct ip_mc_list
*im
)
171 if (refcount_dec_and_test(&im
->refcnt
)) {
172 in_dev_put(im
->interface
);
177 #define for_each_pmc_rcu(in_dev, pmc) \
178 for (pmc = rcu_dereference(in_dev->mc_list); \
180 pmc = rcu_dereference(pmc->next_rcu))
182 #define for_each_pmc_rtnl(in_dev, pmc) \
183 for (pmc = rtnl_dereference(in_dev->mc_list); \
185 pmc = rtnl_dereference(pmc->next_rcu))
187 static void ip_sf_list_clear_all(struct ip_sf_list
*psf
)
189 struct ip_sf_list
*next
;
198 #ifdef CONFIG_IP_MULTICAST
204 static void igmp_stop_timer(struct ip_mc_list
*im
)
206 spin_lock_bh(&im
->lock
);
207 if (del_timer(&im
->timer
))
208 refcount_dec(&im
->refcnt
);
211 im
->unsolicit_count
= 0;
212 spin_unlock_bh(&im
->lock
);
215 /* It must be called with locked im->lock */
216 static void igmp_start_timer(struct ip_mc_list
*im
, int max_delay
)
218 int tv
= prandom_u32() % max_delay
;
221 if (!mod_timer(&im
->timer
, jiffies
+tv
+2))
222 refcount_inc(&im
->refcnt
);
225 static void igmp_gq_start_timer(struct in_device
*in_dev
)
227 int tv
= prandom_u32() % in_dev
->mr_maxdelay
;
228 unsigned long exp
= jiffies
+ tv
+ 2;
230 if (in_dev
->mr_gq_running
&&
231 time_after_eq(exp
, (in_dev
->mr_gq_timer
).expires
))
234 in_dev
->mr_gq_running
= 1;
235 if (!mod_timer(&in_dev
->mr_gq_timer
, exp
))
239 static void igmp_ifc_start_timer(struct in_device
*in_dev
, int delay
)
241 int tv
= prandom_u32() % delay
;
243 if (!mod_timer(&in_dev
->mr_ifc_timer
, jiffies
+tv
+2))
247 static void igmp_mod_timer(struct ip_mc_list
*im
, int max_delay
)
249 spin_lock_bh(&im
->lock
);
250 im
->unsolicit_count
= 0;
251 if (del_timer(&im
->timer
)) {
252 if ((long)(im
->timer
.expires
-jiffies
) < max_delay
) {
253 add_timer(&im
->timer
);
255 spin_unlock_bh(&im
->lock
);
258 refcount_dec(&im
->refcnt
);
260 igmp_start_timer(im
, max_delay
);
261 spin_unlock_bh(&im
->lock
);
266 * Send an IGMP report.
269 #define IGMP_SIZE (sizeof(struct igmphdr)+sizeof(struct iphdr)+4)
272 static int is_in(struct ip_mc_list
*pmc
, struct ip_sf_list
*psf
, int type
,
273 int gdeleted
, int sdeleted
)
276 case IGMPV3_MODE_IS_INCLUDE
:
277 case IGMPV3_MODE_IS_EXCLUDE
:
278 if (gdeleted
|| sdeleted
)
280 if (!(pmc
->gsquery
&& !psf
->sf_gsresp
)) {
281 if (pmc
->sfmode
== MCAST_INCLUDE
)
283 /* don't include if this source is excluded
286 if (psf
->sf_count
[MCAST_INCLUDE
])
287 return type
== IGMPV3_MODE_IS_INCLUDE
;
288 return pmc
->sfcount
[MCAST_EXCLUDE
] ==
289 psf
->sf_count
[MCAST_EXCLUDE
];
292 case IGMPV3_CHANGE_TO_INCLUDE
:
293 if (gdeleted
|| sdeleted
)
295 return psf
->sf_count
[MCAST_INCLUDE
] != 0;
296 case IGMPV3_CHANGE_TO_EXCLUDE
:
297 if (gdeleted
|| sdeleted
)
299 if (pmc
->sfcount
[MCAST_EXCLUDE
] == 0 ||
300 psf
->sf_count
[MCAST_INCLUDE
])
302 return pmc
->sfcount
[MCAST_EXCLUDE
] ==
303 psf
->sf_count
[MCAST_EXCLUDE
];
304 case IGMPV3_ALLOW_NEW_SOURCES
:
305 if (gdeleted
|| !psf
->sf_crcount
)
307 return (pmc
->sfmode
== MCAST_INCLUDE
) ^ sdeleted
;
308 case IGMPV3_BLOCK_OLD_SOURCES
:
309 if (pmc
->sfmode
== MCAST_INCLUDE
)
310 return gdeleted
|| (psf
->sf_crcount
&& sdeleted
);
311 return psf
->sf_crcount
&& !gdeleted
&& !sdeleted
;
317 igmp_scount(struct ip_mc_list
*pmc
, int type
, int gdeleted
, int sdeleted
)
319 struct ip_sf_list
*psf
;
322 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
) {
323 if (!is_in(pmc
, psf
, type
, gdeleted
, sdeleted
))
330 /* source address selection per RFC 3376 section 4.2.13 */
331 static __be32
igmpv3_get_srcaddr(struct net_device
*dev
,
332 const struct flowi4
*fl4
)
334 struct in_device
*in_dev
= __in_dev_get_rcu(dev
);
337 return htonl(INADDR_ANY
);
340 if (fl4
->saddr
== ifa
->ifa_local
)
342 } endfor_ifa(in_dev
);
344 return htonl(INADDR_ANY
);
347 static struct sk_buff
*igmpv3_newpack(struct net_device
*dev
, unsigned int mtu
)
352 struct igmpv3_report
*pig
;
353 struct net
*net
= dev_net(dev
);
355 int hlen
= LL_RESERVED_SPACE(dev
);
356 int tlen
= dev
->needed_tailroom
;
357 unsigned int size
= mtu
;
360 skb
= alloc_skb(size
+ hlen
+ tlen
,
361 GFP_ATOMIC
| __GFP_NOWARN
);
368 skb
->priority
= TC_PRIO_CONTROL
;
370 rt
= ip_route_output_ports(net
, &fl4
, NULL
, IGMPV3_ALL_MCR
, 0,
372 IPPROTO_IGMP
, 0, dev
->ifindex
);
378 skb_dst_set(skb
, &rt
->dst
);
381 skb_reserve(skb
, hlen
);
382 skb_tailroom_reserve(skb
, mtu
, tlen
);
384 skb_reset_network_header(skb
);
386 skb_put(skb
, sizeof(struct iphdr
) + 4);
389 pip
->ihl
= (sizeof(struct iphdr
)+4)>>2;
391 pip
->frag_off
= htons(IP_DF
);
393 pip
->daddr
= fl4
.daddr
;
396 pip
->saddr
= igmpv3_get_srcaddr(dev
, &fl4
);
399 pip
->protocol
= IPPROTO_IGMP
;
400 pip
->tot_len
= 0; /* filled in later */
401 ip_select_ident(net
, skb
, NULL
);
402 ((u8
*)&pip
[1])[0] = IPOPT_RA
;
403 ((u8
*)&pip
[1])[1] = 4;
404 ((u8
*)&pip
[1])[2] = 0;
405 ((u8
*)&pip
[1])[3] = 0;
407 skb
->transport_header
= skb
->network_header
+ sizeof(struct iphdr
) + 4;
408 skb_put(skb
, sizeof(*pig
));
409 pig
= igmpv3_report_hdr(skb
);
410 pig
->type
= IGMPV3_HOST_MEMBERSHIP_REPORT
;
418 static int igmpv3_sendpack(struct sk_buff
*skb
)
420 struct igmphdr
*pig
= igmp_hdr(skb
);
421 const int igmplen
= skb_tail_pointer(skb
) - skb_transport_header(skb
);
423 pig
->csum
= ip_compute_csum(igmp_hdr(skb
), igmplen
);
425 return ip_local_out(dev_net(skb_dst(skb
)->dev
), skb
->sk
, skb
);
428 static int grec_size(struct ip_mc_list
*pmc
, int type
, int gdel
, int sdel
)
430 return sizeof(struct igmpv3_grec
) + 4*igmp_scount(pmc
, type
, gdel
, sdel
);
433 static struct sk_buff
*add_grhead(struct sk_buff
*skb
, struct ip_mc_list
*pmc
,
434 int type
, struct igmpv3_grec
**ppgr
, unsigned int mtu
)
436 struct net_device
*dev
= pmc
->interface
->dev
;
437 struct igmpv3_report
*pih
;
438 struct igmpv3_grec
*pgr
;
441 skb
= igmpv3_newpack(dev
, mtu
);
445 pgr
= skb_put(skb
, sizeof(struct igmpv3_grec
));
446 pgr
->grec_type
= type
;
447 pgr
->grec_auxwords
= 0;
449 pgr
->grec_mca
= pmc
->multiaddr
;
450 pih
= igmpv3_report_hdr(skb
);
451 pih
->ngrec
= htons(ntohs(pih
->ngrec
)+1);
456 #define AVAILABLE(skb) ((skb) ? skb_availroom(skb) : 0)
458 static struct sk_buff
*add_grec(struct sk_buff
*skb
, struct ip_mc_list
*pmc
,
459 int type
, int gdeleted
, int sdeleted
)
461 struct net_device
*dev
= pmc
->interface
->dev
;
462 struct net
*net
= dev_net(dev
);
463 struct igmpv3_report
*pih
;
464 struct igmpv3_grec
*pgr
= NULL
;
465 struct ip_sf_list
*psf
, *psf_next
, *psf_prev
, **psf_list
;
466 int scount
, stotal
, first
, isquery
, truncate
;
469 if (pmc
->multiaddr
== IGMP_ALL_HOSTS
)
471 if (ipv4_is_local_multicast(pmc
->multiaddr
) && !net
->ipv4
.sysctl_igmp_llm_reports
)
474 mtu
= READ_ONCE(dev
->mtu
);
475 if (mtu
< IPV4_MIN_MTU
)
478 isquery
= type
== IGMPV3_MODE_IS_INCLUDE
||
479 type
== IGMPV3_MODE_IS_EXCLUDE
;
480 truncate
= type
== IGMPV3_MODE_IS_EXCLUDE
||
481 type
== IGMPV3_CHANGE_TO_EXCLUDE
;
485 psf_list
= sdeleted
? &pmc
->tomb
: &pmc
->sources
;
490 pih
= skb
? igmpv3_report_hdr(skb
) : NULL
;
492 /* EX and TO_EX get a fresh packet, if needed */
494 if (pih
&& pih
->ngrec
&&
495 AVAILABLE(skb
) < grec_size(pmc
, type
, gdeleted
, sdeleted
)) {
497 igmpv3_sendpack(skb
);
498 skb
= igmpv3_newpack(dev
, mtu
);
503 for (psf
= *psf_list
; psf
; psf
= psf_next
) {
506 psf_next
= psf
->sf_next
;
508 if (!is_in(pmc
, psf
, type
, gdeleted
, sdeleted
)) {
513 /* Based on RFC3376 5.1. Should not send source-list change
514 * records when there is a filter mode change.
516 if (((gdeleted
&& pmc
->sfmode
== MCAST_EXCLUDE
) ||
517 (!gdeleted
&& pmc
->crcount
)) &&
518 (type
== IGMPV3_ALLOW_NEW_SOURCES
||
519 type
== IGMPV3_BLOCK_OLD_SOURCES
) && psf
->sf_crcount
)
520 goto decrease_sf_crcount
;
522 /* clear marks on query responses */
526 if (AVAILABLE(skb
) < sizeof(__be32
) +
527 first
*sizeof(struct igmpv3_grec
)) {
528 if (truncate
&& !first
)
529 break; /* truncate these */
531 pgr
->grec_nsrcs
= htons(scount
);
533 igmpv3_sendpack(skb
);
534 skb
= igmpv3_newpack(dev
, mtu
);
539 skb
= add_grhead(skb
, pmc
, type
, &pgr
, mtu
);
544 psrc
= skb_put(skb
, sizeof(__be32
));
545 *psrc
= psf
->sf_inaddr
;
547 if ((type
== IGMPV3_ALLOW_NEW_SOURCES
||
548 type
== IGMPV3_BLOCK_OLD_SOURCES
) && psf
->sf_crcount
) {
551 if ((sdeleted
|| gdeleted
) && psf
->sf_crcount
== 0) {
553 psf_prev
->sf_next
= psf
->sf_next
;
555 *psf_list
= psf
->sf_next
;
565 if (type
== IGMPV3_ALLOW_NEW_SOURCES
||
566 type
== IGMPV3_BLOCK_OLD_SOURCES
)
568 if (pmc
->crcount
|| isquery
) {
569 /* make sure we have room for group header */
570 if (skb
&& AVAILABLE(skb
) < sizeof(struct igmpv3_grec
)) {
571 igmpv3_sendpack(skb
);
572 skb
= NULL
; /* add_grhead will get a new one */
574 skb
= add_grhead(skb
, pmc
, type
, &pgr
, mtu
);
578 pgr
->grec_nsrcs
= htons(scount
);
581 pmc
->gsquery
= 0; /* clear query state on report */
585 static int igmpv3_send_report(struct in_device
*in_dev
, struct ip_mc_list
*pmc
)
587 struct sk_buff
*skb
= NULL
;
588 struct net
*net
= dev_net(in_dev
->dev
);
593 for_each_pmc_rcu(in_dev
, pmc
) {
594 if (pmc
->multiaddr
== IGMP_ALL_HOSTS
)
596 if (ipv4_is_local_multicast(pmc
->multiaddr
) &&
597 !net
->ipv4
.sysctl_igmp_llm_reports
)
599 spin_lock_bh(&pmc
->lock
);
600 if (pmc
->sfcount
[MCAST_EXCLUDE
])
601 type
= IGMPV3_MODE_IS_EXCLUDE
;
603 type
= IGMPV3_MODE_IS_INCLUDE
;
604 skb
= add_grec(skb
, pmc
, type
, 0, 0);
605 spin_unlock_bh(&pmc
->lock
);
609 spin_lock_bh(&pmc
->lock
);
610 if (pmc
->sfcount
[MCAST_EXCLUDE
])
611 type
= IGMPV3_MODE_IS_EXCLUDE
;
613 type
= IGMPV3_MODE_IS_INCLUDE
;
614 skb
= add_grec(skb
, pmc
, type
, 0, 0);
615 spin_unlock_bh(&pmc
->lock
);
619 return igmpv3_sendpack(skb
);
623 * remove zero-count source records from a source filter list
625 static void igmpv3_clear_zeros(struct ip_sf_list
**ppsf
)
627 struct ip_sf_list
*psf_prev
, *psf_next
, *psf
;
630 for (psf
= *ppsf
; psf
; psf
= psf_next
) {
631 psf_next
= psf
->sf_next
;
632 if (psf
->sf_crcount
== 0) {
634 psf_prev
->sf_next
= psf
->sf_next
;
636 *ppsf
= psf
->sf_next
;
643 static void kfree_pmc(struct ip_mc_list
*pmc
)
645 ip_sf_list_clear_all(pmc
->sources
);
646 ip_sf_list_clear_all(pmc
->tomb
);
650 static void igmpv3_send_cr(struct in_device
*in_dev
)
652 struct ip_mc_list
*pmc
, *pmc_prev
, *pmc_next
;
653 struct sk_buff
*skb
= NULL
;
657 spin_lock_bh(&in_dev
->mc_tomb_lock
);
661 for (pmc
= in_dev
->mc_tomb
; pmc
; pmc
= pmc_next
) {
662 pmc_next
= pmc
->next
;
663 if (pmc
->sfmode
== MCAST_INCLUDE
) {
664 type
= IGMPV3_BLOCK_OLD_SOURCES
;
665 dtype
= IGMPV3_BLOCK_OLD_SOURCES
;
666 skb
= add_grec(skb
, pmc
, type
, 1, 0);
667 skb
= add_grec(skb
, pmc
, dtype
, 1, 1);
670 if (pmc
->sfmode
== MCAST_EXCLUDE
) {
671 type
= IGMPV3_CHANGE_TO_INCLUDE
;
672 skb
= add_grec(skb
, pmc
, type
, 1, 0);
675 if (pmc
->crcount
== 0) {
676 igmpv3_clear_zeros(&pmc
->tomb
);
677 igmpv3_clear_zeros(&pmc
->sources
);
680 if (pmc
->crcount
== 0 && !pmc
->tomb
&& !pmc
->sources
) {
682 pmc_prev
->next
= pmc_next
;
684 in_dev
->mc_tomb
= pmc_next
;
685 in_dev_put(pmc
->interface
);
690 spin_unlock_bh(&in_dev
->mc_tomb_lock
);
693 for_each_pmc_rcu(in_dev
, pmc
) {
694 spin_lock_bh(&pmc
->lock
);
695 if (pmc
->sfcount
[MCAST_EXCLUDE
]) {
696 type
= IGMPV3_BLOCK_OLD_SOURCES
;
697 dtype
= IGMPV3_ALLOW_NEW_SOURCES
;
699 type
= IGMPV3_ALLOW_NEW_SOURCES
;
700 dtype
= IGMPV3_BLOCK_OLD_SOURCES
;
702 skb
= add_grec(skb
, pmc
, type
, 0, 0);
703 skb
= add_grec(skb
, pmc
, dtype
, 0, 1); /* deleted sources */
705 /* filter mode changes */
707 if (pmc
->sfmode
== MCAST_EXCLUDE
)
708 type
= IGMPV3_CHANGE_TO_EXCLUDE
;
710 type
= IGMPV3_CHANGE_TO_INCLUDE
;
711 skb
= add_grec(skb
, pmc
, type
, 0, 0);
714 spin_unlock_bh(&pmc
->lock
);
720 (void) igmpv3_sendpack(skb
);
723 static int igmp_send_report(struct in_device
*in_dev
, struct ip_mc_list
*pmc
,
730 struct net_device
*dev
= in_dev
->dev
;
731 struct net
*net
= dev_net(dev
);
732 __be32 group
= pmc
? pmc
->multiaddr
: 0;
737 if (type
== IGMPV3_HOST_MEMBERSHIP_REPORT
)
738 return igmpv3_send_report(in_dev
, pmc
);
740 if (ipv4_is_local_multicast(group
) && !net
->ipv4
.sysctl_igmp_llm_reports
)
743 if (type
== IGMP_HOST_LEAVE_MESSAGE
)
744 dst
= IGMP_ALL_ROUTER
;
748 rt
= ip_route_output_ports(net
, &fl4
, NULL
, dst
, 0,
750 IPPROTO_IGMP
, 0, dev
->ifindex
);
754 hlen
= LL_RESERVED_SPACE(dev
);
755 tlen
= dev
->needed_tailroom
;
756 skb
= alloc_skb(IGMP_SIZE
+ hlen
+ tlen
, GFP_ATOMIC
);
761 skb
->priority
= TC_PRIO_CONTROL
;
763 skb_dst_set(skb
, &rt
->dst
);
765 skb_reserve(skb
, hlen
);
767 skb_reset_network_header(skb
);
769 skb_put(skb
, sizeof(struct iphdr
) + 4);
772 iph
->ihl
= (sizeof(struct iphdr
)+4)>>2;
774 iph
->frag_off
= htons(IP_DF
);
777 iph
->saddr
= fl4
.saddr
;
778 iph
->protocol
= IPPROTO_IGMP
;
779 ip_select_ident(net
, skb
, NULL
);
780 ((u8
*)&iph
[1])[0] = IPOPT_RA
;
781 ((u8
*)&iph
[1])[1] = 4;
782 ((u8
*)&iph
[1])[2] = 0;
783 ((u8
*)&iph
[1])[3] = 0;
785 ih
= skb_put(skb
, sizeof(struct igmphdr
));
790 ih
->csum
= ip_compute_csum((void *)ih
, sizeof(struct igmphdr
));
792 return ip_local_out(net
, skb
->sk
, skb
);
795 static void igmp_gq_timer_expire(struct timer_list
*t
)
797 struct in_device
*in_dev
= from_timer(in_dev
, t
, mr_gq_timer
);
799 in_dev
->mr_gq_running
= 0;
800 igmpv3_send_report(in_dev
, NULL
);
804 static void igmp_ifc_timer_expire(struct timer_list
*t
)
806 struct in_device
*in_dev
= from_timer(in_dev
, t
, mr_ifc_timer
);
808 igmpv3_send_cr(in_dev
);
809 if (in_dev
->mr_ifc_count
) {
810 in_dev
->mr_ifc_count
--;
811 igmp_ifc_start_timer(in_dev
,
812 unsolicited_report_interval(in_dev
));
817 static void igmp_ifc_event(struct in_device
*in_dev
)
819 struct net
*net
= dev_net(in_dev
->dev
);
820 if (IGMP_V1_SEEN(in_dev
) || IGMP_V2_SEEN(in_dev
))
822 in_dev
->mr_ifc_count
= in_dev
->mr_qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
823 igmp_ifc_start_timer(in_dev
, 1);
827 static void igmp_timer_expire(struct timer_list
*t
)
829 struct ip_mc_list
*im
= from_timer(im
, t
, timer
);
830 struct in_device
*in_dev
= im
->interface
;
832 spin_lock(&im
->lock
);
835 if (im
->unsolicit_count
&& --im
->unsolicit_count
)
836 igmp_start_timer(im
, unsolicited_report_interval(in_dev
));
839 spin_unlock(&im
->lock
);
841 if (IGMP_V1_SEEN(in_dev
))
842 igmp_send_report(in_dev
, im
, IGMP_HOST_MEMBERSHIP_REPORT
);
843 else if (IGMP_V2_SEEN(in_dev
))
844 igmp_send_report(in_dev
, im
, IGMPV2_HOST_MEMBERSHIP_REPORT
);
846 igmp_send_report(in_dev
, im
, IGMPV3_HOST_MEMBERSHIP_REPORT
);
851 /* mark EXCLUDE-mode sources */
852 static int igmp_xmarksources(struct ip_mc_list
*pmc
, int nsrcs
, __be32
*srcs
)
854 struct ip_sf_list
*psf
;
858 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
) {
861 for (i
= 0; i
< nsrcs
; i
++) {
862 /* skip inactive filters */
863 if (psf
->sf_count
[MCAST_INCLUDE
] ||
864 pmc
->sfcount
[MCAST_EXCLUDE
] !=
865 psf
->sf_count
[MCAST_EXCLUDE
])
867 if (srcs
[i
] == psf
->sf_inaddr
) {
874 if (scount
== nsrcs
) /* all sources excluded */
879 static int igmp_marksources(struct ip_mc_list
*pmc
, int nsrcs
, __be32
*srcs
)
881 struct ip_sf_list
*psf
;
884 if (pmc
->sfmode
== MCAST_EXCLUDE
)
885 return igmp_xmarksources(pmc
, nsrcs
, srcs
);
887 /* mark INCLUDE-mode sources */
889 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
) {
892 for (i
= 0; i
< nsrcs
; i
++)
893 if (srcs
[i
] == psf
->sf_inaddr
) {
907 /* return true if packet was dropped */
908 static bool igmp_heard_report(struct in_device
*in_dev
, __be32 group
)
910 struct ip_mc_list
*im
;
911 struct net
*net
= dev_net(in_dev
->dev
);
913 /* Timers are only set for non-local groups */
915 if (group
== IGMP_ALL_HOSTS
)
917 if (ipv4_is_local_multicast(group
) && !net
->ipv4
.sysctl_igmp_llm_reports
)
921 for_each_pmc_rcu(in_dev
, im
) {
922 if (im
->multiaddr
== group
) {
931 /* return true if packet was dropped */
932 static bool igmp_heard_query(struct in_device
*in_dev
, struct sk_buff
*skb
,
935 struct igmphdr
*ih
= igmp_hdr(skb
);
936 struct igmpv3_query
*ih3
= igmpv3_query_hdr(skb
);
937 struct ip_mc_list
*im
;
938 __be32 group
= ih
->group
;
941 struct net
*net
= dev_net(in_dev
->dev
);
946 /* Alas, old v1 router presents here. */
948 max_delay
= IGMP_QUERY_RESPONSE_INTERVAL
;
949 in_dev
->mr_v1_seen
= jiffies
+
950 (in_dev
->mr_qrv
* in_dev
->mr_qi
) +
954 /* v2 router present */
955 max_delay
= ih
->code
*(HZ
/IGMP_TIMER_SCALE
);
956 in_dev
->mr_v2_seen
= jiffies
+
957 (in_dev
->mr_qrv
* in_dev
->mr_qi
) +
960 /* cancel the interface change timer */
961 in_dev
->mr_ifc_count
= 0;
962 if (del_timer(&in_dev
->mr_ifc_timer
))
963 __in_dev_put(in_dev
);
964 /* clear deleted report items */
965 igmpv3_clear_delrec(in_dev
);
966 } else if (len
< 12) {
967 return true; /* ignore bogus packet; freed by caller */
968 } else if (IGMP_V1_SEEN(in_dev
)) {
969 /* This is a v3 query with v1 queriers present */
970 max_delay
= IGMP_QUERY_RESPONSE_INTERVAL
;
972 } else if (IGMP_V2_SEEN(in_dev
)) {
973 /* this is a v3 query with v2 queriers present;
974 * Interpretation of the max_delay code is problematic here.
975 * A real v2 host would use ih_code directly, while v3 has a
976 * different encoding. We use the v3 encoding as more likely
977 * to be intended in a v3 query.
979 max_delay
= IGMPV3_MRC(ih3
->code
)*(HZ
/IGMP_TIMER_SCALE
);
981 max_delay
= 1; /* can't mod w/ 0 */
983 if (!pskb_may_pull(skb
, sizeof(struct igmpv3_query
)))
986 ih3
= igmpv3_query_hdr(skb
);
988 if (!pskb_may_pull(skb
, sizeof(struct igmpv3_query
)
989 + ntohs(ih3
->nsrcs
)*sizeof(__be32
)))
991 ih3
= igmpv3_query_hdr(skb
);
994 max_delay
= IGMPV3_MRC(ih3
->code
)*(HZ
/IGMP_TIMER_SCALE
);
996 max_delay
= 1; /* can't mod w/ 0 */
997 in_dev
->mr_maxdelay
= max_delay
;
999 /* RFC3376, 4.1.6. QRV and 4.1.7. QQIC, when the most recently
1000 * received value was zero, use the default or statically
1003 in_dev
->mr_qrv
= ih3
->qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
1004 in_dev
->mr_qi
= IGMPV3_QQIC(ih3
->qqic
)*HZ
?: IGMP_QUERY_INTERVAL
;
1006 /* RFC3376, 8.3. Query Response Interval:
1007 * The number of seconds represented by the [Query Response
1008 * Interval] must be less than the [Query Interval].
1010 if (in_dev
->mr_qri
>= in_dev
->mr_qi
)
1011 in_dev
->mr_qri
= (in_dev
->mr_qi
/HZ
- 1)*HZ
;
1013 if (!group
) { /* general query */
1015 return true; /* no sources allowed */
1016 igmp_gq_start_timer(in_dev
);
1019 /* mark sources to include, if group & source-specific */
1020 mark
= ih3
->nsrcs
!= 0;
1024 * - Start the timers in all of our membership records
1025 * that the query applies to for the interface on
1026 * which the query arrived excl. those that belong
1027 * to a "local" group (224.0.0.X)
1028 * - For timers already running check if they need to
1030 * - Use the igmp->igmp_code field as the maximum
1034 for_each_pmc_rcu(in_dev
, im
) {
1037 if (group
&& group
!= im
->multiaddr
)
1039 if (im
->multiaddr
== IGMP_ALL_HOSTS
)
1041 if (ipv4_is_local_multicast(im
->multiaddr
) &&
1042 !net
->ipv4
.sysctl_igmp_llm_reports
)
1044 spin_lock_bh(&im
->lock
);
1046 im
->gsquery
= im
->gsquery
&& mark
;
1049 changed
= !im
->gsquery
||
1050 igmp_marksources(im
, ntohs(ih3
->nsrcs
), ih3
->srcs
);
1051 spin_unlock_bh(&im
->lock
);
1053 igmp_mod_timer(im
, max_delay
);
1059 /* called in rcu_read_lock() section */
1060 int igmp_rcv(struct sk_buff
*skb
)
1062 /* This basically follows the spec line by line -- see RFC1112 */
1064 struct net_device
*dev
= skb
->dev
;
1065 struct in_device
*in_dev
;
1067 bool dropped
= true;
1069 if (netif_is_l3_master(dev
)) {
1070 dev
= dev_get_by_index_rcu(dev_net(dev
), IPCB(skb
)->iif
);
1075 in_dev
= __in_dev_get_rcu(dev
);
1079 if (!pskb_may_pull(skb
, sizeof(struct igmphdr
)))
1082 if (skb_checksum_simple_validate(skb
))
1087 case IGMP_HOST_MEMBERSHIP_QUERY
:
1088 dropped
= igmp_heard_query(in_dev
, skb
, len
);
1090 case IGMP_HOST_MEMBERSHIP_REPORT
:
1091 case IGMPV2_HOST_MEMBERSHIP_REPORT
:
1092 /* Is it our report looped back? */
1093 if (rt_is_output_route(skb_rtable(skb
)))
1095 /* don't rely on MC router hearing unicast reports */
1096 if (skb
->pkt_type
== PACKET_MULTICAST
||
1097 skb
->pkt_type
== PACKET_BROADCAST
)
1098 dropped
= igmp_heard_report(in_dev
, ih
->group
);
1101 #ifdef CONFIG_IP_PIMSM_V1
1102 return pim_rcv_v1(skb
);
1104 case IGMPV3_HOST_MEMBERSHIP_REPORT
:
1107 case IGMP_HOST_LEAVE_MESSAGE
:
1109 case IGMP_MTRACE_RESP
:
1127 * Add a filter to a device
1130 static void ip_mc_filter_add(struct in_device
*in_dev
, __be32 addr
)
1132 char buf
[MAX_ADDR_LEN
];
1133 struct net_device
*dev
= in_dev
->dev
;
1135 /* Checking for IFF_MULTICAST here is WRONG-WRONG-WRONG.
1136 We will get multicast token leakage, when IFF_MULTICAST
1137 is changed. This check should be done in ndo_set_rx_mode
1138 routine. Something sort of:
1139 if (dev->mc_list && dev->flags&IFF_MULTICAST) { do it; }
1142 if (arp_mc_map(addr
, buf
, dev
, 0) == 0)
1143 dev_mc_add(dev
, buf
);
1147 * Remove a filter from a device
1150 static void ip_mc_filter_del(struct in_device
*in_dev
, __be32 addr
)
1152 char buf
[MAX_ADDR_LEN
];
1153 struct net_device
*dev
= in_dev
->dev
;
1155 if (arp_mc_map(addr
, buf
, dev
, 0) == 0)
1156 dev_mc_del(dev
, buf
);
1159 #ifdef CONFIG_IP_MULTICAST
1161 * deleted ip_mc_list manipulation
1163 static void igmpv3_add_delrec(struct in_device
*in_dev
, struct ip_mc_list
*im
,
1166 struct ip_mc_list
*pmc
;
1167 struct net
*net
= dev_net(in_dev
->dev
);
1169 /* this is an "ip_mc_list" for convenience; only the fields below
1170 * are actually used. In particular, the refcnt and users are not
1171 * used for management of the delete list. Using the same structure
1172 * for deleted items allows change reports to use common code with
1173 * non-deleted or query-response MCA's.
1175 pmc
= kzalloc(sizeof(*pmc
), gfp
);
1178 spin_lock_init(&pmc
->lock
);
1179 spin_lock_bh(&im
->lock
);
1180 pmc
->interface
= im
->interface
;
1181 in_dev_hold(in_dev
);
1182 pmc
->multiaddr
= im
->multiaddr
;
1183 pmc
->crcount
= in_dev
->mr_qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
1184 pmc
->sfmode
= im
->sfmode
;
1185 if (pmc
->sfmode
== MCAST_INCLUDE
) {
1186 struct ip_sf_list
*psf
;
1188 pmc
->tomb
= im
->tomb
;
1189 pmc
->sources
= im
->sources
;
1190 im
->tomb
= im
->sources
= NULL
;
1191 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
)
1192 psf
->sf_crcount
= pmc
->crcount
;
1194 spin_unlock_bh(&im
->lock
);
1196 spin_lock_bh(&in_dev
->mc_tomb_lock
);
1197 pmc
->next
= in_dev
->mc_tomb
;
1198 in_dev
->mc_tomb
= pmc
;
1199 spin_unlock_bh(&in_dev
->mc_tomb_lock
);
1203 * restore ip_mc_list deleted records
1205 static void igmpv3_del_delrec(struct in_device
*in_dev
, struct ip_mc_list
*im
)
1207 struct ip_mc_list
*pmc
, *pmc_prev
;
1208 struct ip_sf_list
*psf
;
1209 struct net
*net
= dev_net(in_dev
->dev
);
1210 __be32 multiaddr
= im
->multiaddr
;
1212 spin_lock_bh(&in_dev
->mc_tomb_lock
);
1214 for (pmc
= in_dev
->mc_tomb
; pmc
; pmc
= pmc
->next
) {
1215 if (pmc
->multiaddr
== multiaddr
)
1221 pmc_prev
->next
= pmc
->next
;
1223 in_dev
->mc_tomb
= pmc
->next
;
1225 spin_unlock_bh(&in_dev
->mc_tomb_lock
);
1227 spin_lock_bh(&im
->lock
);
1229 im
->interface
= pmc
->interface
;
1230 if (im
->sfmode
== MCAST_INCLUDE
) {
1231 im
->tomb
= pmc
->tomb
;
1234 im
->sources
= pmc
->sources
;
1235 pmc
->sources
= NULL
;
1237 for (psf
= im
->sources
; psf
; psf
= psf
->sf_next
)
1238 psf
->sf_crcount
= in_dev
->mr_qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
1240 im
->crcount
= in_dev
->mr_qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
1242 in_dev_put(pmc
->interface
);
1245 spin_unlock_bh(&im
->lock
);
1249 * flush ip_mc_list deleted records
1251 static void igmpv3_clear_delrec(struct in_device
*in_dev
)
1253 struct ip_mc_list
*pmc
, *nextpmc
;
1255 spin_lock_bh(&in_dev
->mc_tomb_lock
);
1256 pmc
= in_dev
->mc_tomb
;
1257 in_dev
->mc_tomb
= NULL
;
1258 spin_unlock_bh(&in_dev
->mc_tomb_lock
);
1260 for (; pmc
; pmc
= nextpmc
) {
1261 nextpmc
= pmc
->next
;
1262 ip_mc_clear_src(pmc
);
1263 in_dev_put(pmc
->interface
);
1266 /* clear dead sources, too */
1268 for_each_pmc_rcu(in_dev
, pmc
) {
1269 struct ip_sf_list
*psf
;
1271 spin_lock_bh(&pmc
->lock
);
1274 spin_unlock_bh(&pmc
->lock
);
1275 ip_sf_list_clear_all(psf
);
1281 static void __igmp_group_dropped(struct ip_mc_list
*im
, gfp_t gfp
)
1283 struct in_device
*in_dev
= im
->interface
;
1284 #ifdef CONFIG_IP_MULTICAST
1285 struct net
*net
= dev_net(in_dev
->dev
);
1291 ip_mc_filter_del(in_dev
, im
->multiaddr
);
1294 #ifdef CONFIG_IP_MULTICAST
1295 if (im
->multiaddr
== IGMP_ALL_HOSTS
)
1297 if (ipv4_is_local_multicast(im
->multiaddr
) && !net
->ipv4
.sysctl_igmp_llm_reports
)
1300 reporter
= im
->reporter
;
1301 igmp_stop_timer(im
);
1303 if (!in_dev
->dead
) {
1304 if (IGMP_V1_SEEN(in_dev
))
1306 if (IGMP_V2_SEEN(in_dev
)) {
1308 igmp_send_report(in_dev
, im
, IGMP_HOST_LEAVE_MESSAGE
);
1312 igmpv3_add_delrec(in_dev
, im
, gfp
);
1314 igmp_ifc_event(in_dev
);
1319 static void igmp_group_dropped(struct ip_mc_list
*im
)
1321 __igmp_group_dropped(im
, GFP_KERNEL
);
1324 static void igmp_group_added(struct ip_mc_list
*im
)
1326 struct in_device
*in_dev
= im
->interface
;
1327 #ifdef CONFIG_IP_MULTICAST
1328 struct net
*net
= dev_net(in_dev
->dev
);
1331 if (im
->loaded
== 0) {
1333 ip_mc_filter_add(in_dev
, im
->multiaddr
);
1336 #ifdef CONFIG_IP_MULTICAST
1337 if (im
->multiaddr
== IGMP_ALL_HOSTS
)
1339 if (ipv4_is_local_multicast(im
->multiaddr
) && !net
->ipv4
.sysctl_igmp_llm_reports
)
1345 im
->unsolicit_count
= net
->ipv4
.sysctl_igmp_qrv
;
1346 if (IGMP_V1_SEEN(in_dev
) || IGMP_V2_SEEN(in_dev
)) {
1347 spin_lock_bh(&im
->lock
);
1348 igmp_start_timer(im
, IGMP_INITIAL_REPORT_DELAY
);
1349 spin_unlock_bh(&im
->lock
);
1354 /* Based on RFC3376 5.1, for newly added INCLUDE SSM, we should
1355 * not send filter-mode change record as the mode should be from
1358 if (im
->sfmode
== MCAST_EXCLUDE
)
1359 im
->crcount
= in_dev
->mr_qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
1361 igmp_ifc_event(in_dev
);
1367 * Multicast list managers
1370 static u32
ip_mc_hash(const struct ip_mc_list
*im
)
1372 return hash_32((__force u32
)im
->multiaddr
, MC_HASH_SZ_LOG
);
1375 static void ip_mc_hash_add(struct in_device
*in_dev
,
1376 struct ip_mc_list
*im
)
1378 struct ip_mc_list __rcu
**mc_hash
;
1381 mc_hash
= rtnl_dereference(in_dev
->mc_hash
);
1383 hash
= ip_mc_hash(im
);
1384 im
->next_hash
= mc_hash
[hash
];
1385 rcu_assign_pointer(mc_hash
[hash
], im
);
1389 /* do not use a hash table for small number of items */
1390 if (in_dev
->mc_count
< 4)
1393 mc_hash
= kzalloc(sizeof(struct ip_mc_list
*) << MC_HASH_SZ_LOG
,
1398 for_each_pmc_rtnl(in_dev
, im
) {
1399 hash
= ip_mc_hash(im
);
1400 im
->next_hash
= mc_hash
[hash
];
1401 RCU_INIT_POINTER(mc_hash
[hash
], im
);
1404 rcu_assign_pointer(in_dev
->mc_hash
, mc_hash
);
1407 static void ip_mc_hash_remove(struct in_device
*in_dev
,
1408 struct ip_mc_list
*im
)
1410 struct ip_mc_list __rcu
**mc_hash
= rtnl_dereference(in_dev
->mc_hash
);
1411 struct ip_mc_list
*aux
;
1415 mc_hash
+= ip_mc_hash(im
);
1416 while ((aux
= rtnl_dereference(*mc_hash
)) != im
)
1417 mc_hash
= &aux
->next_hash
;
1418 *mc_hash
= im
->next_hash
;
1423 * A socket has joined a multicast group on device dev.
1425 static void ____ip_mc_inc_group(struct in_device
*in_dev
, __be32 addr
,
1426 unsigned int mode
, gfp_t gfp
)
1428 struct ip_mc_list
*im
;
1432 for_each_pmc_rtnl(in_dev
, im
) {
1433 if (im
->multiaddr
== addr
) {
1435 ip_mc_add_src(in_dev
, &addr
, mode
, 0, NULL
, 0);
1440 im
= kzalloc(sizeof(*im
), gfp
);
1445 im
->interface
= in_dev
;
1446 in_dev_hold(in_dev
);
1447 im
->multiaddr
= addr
;
1448 /* initial mode is (EX, empty) */
1450 im
->sfcount
[mode
] = 1;
1451 refcount_set(&im
->refcnt
, 1);
1452 spin_lock_init(&im
->lock
);
1453 #ifdef CONFIG_IP_MULTICAST
1454 timer_setup(&im
->timer
, igmp_timer_expire
, 0);
1457 im
->next_rcu
= in_dev
->mc_list
;
1459 rcu_assign_pointer(in_dev
->mc_list
, im
);
1461 ip_mc_hash_add(in_dev
, im
);
1463 #ifdef CONFIG_IP_MULTICAST
1464 igmpv3_del_delrec(in_dev
, im
);
1466 igmp_group_added(im
);
1468 ip_rt_multicast_event(in_dev
);
1473 void __ip_mc_inc_group(struct in_device
*in_dev
, __be32 addr
, gfp_t gfp
)
1475 ____ip_mc_inc_group(in_dev
, addr
, MCAST_EXCLUDE
, gfp
);
1477 EXPORT_SYMBOL(__ip_mc_inc_group
);
1479 void ip_mc_inc_group(struct in_device
*in_dev
, __be32 addr
)
1481 __ip_mc_inc_group(in_dev
, addr
, MCAST_EXCLUDE
);
1483 EXPORT_SYMBOL(ip_mc_inc_group
);
1485 static int ip_mc_check_iphdr(struct sk_buff
*skb
)
1487 const struct iphdr
*iph
;
1489 unsigned int offset
= skb_network_offset(skb
) + sizeof(*iph
);
1491 if (!pskb_may_pull(skb
, offset
))
1496 if (iph
->version
!= 4 || ip_hdrlen(skb
) < sizeof(*iph
))
1499 offset
+= ip_hdrlen(skb
) - sizeof(*iph
);
1501 if (!pskb_may_pull(skb
, offset
))
1506 if (unlikely(ip_fast_csum((u8
*)iph
, iph
->ihl
)))
1509 len
= skb_network_offset(skb
) + ntohs(iph
->tot_len
);
1510 if (skb
->len
< len
|| len
< offset
)
1513 skb_set_transport_header(skb
, offset
);
1518 static int ip_mc_check_igmp_reportv3(struct sk_buff
*skb
)
1520 unsigned int len
= skb_transport_offset(skb
);
1522 len
+= sizeof(struct igmpv3_report
);
1524 return ip_mc_may_pull(skb
, len
) ? 0 : -EINVAL
;
1527 static int ip_mc_check_igmp_query(struct sk_buff
*skb
)
1529 unsigned int transport_len
= ip_transport_len(skb
);
1533 if (transport_len
!= sizeof(struct igmphdr
)) {
1535 if (transport_len
< sizeof(struct igmpv3_query
))
1538 len
= skb_transport_offset(skb
) + sizeof(struct igmpv3_query
);
1539 if (!ip_mc_may_pull(skb
, len
))
1543 /* RFC2236+RFC3376 (IGMPv2+IGMPv3) require the multicast link layer
1544 * all-systems destination addresses (224.0.0.1) for general queries
1546 if (!igmp_hdr(skb
)->group
&&
1547 ip_hdr(skb
)->daddr
!= htonl(INADDR_ALLHOSTS_GROUP
))
1553 static int ip_mc_check_igmp_msg(struct sk_buff
*skb
)
1555 switch (igmp_hdr(skb
)->type
) {
1556 case IGMP_HOST_LEAVE_MESSAGE
:
1557 case IGMP_HOST_MEMBERSHIP_REPORT
:
1558 case IGMPV2_HOST_MEMBERSHIP_REPORT
:
1560 case IGMPV3_HOST_MEMBERSHIP_REPORT
:
1561 return ip_mc_check_igmp_reportv3(skb
);
1562 case IGMP_HOST_MEMBERSHIP_QUERY
:
1563 return ip_mc_check_igmp_query(skb
);
1569 static inline __sum16
ip_mc_validate_checksum(struct sk_buff
*skb
)
1571 return skb_checksum_simple_validate(skb
);
1574 static int ip_mc_check_igmp_csum(struct sk_buff
*skb
)
1576 unsigned int len
= skb_transport_offset(skb
) + sizeof(struct igmphdr
);
1577 unsigned int transport_len
= ip_transport_len(skb
);
1578 struct sk_buff
*skb_chk
;
1580 if (!ip_mc_may_pull(skb
, len
))
1583 skb_chk
= skb_checksum_trimmed(skb
, transport_len
,
1584 ip_mc_validate_checksum
);
1595 * ip_mc_check_igmp - checks whether this is a sane IGMP packet
1596 * @skb: the skb to validate
1598 * Checks whether an IPv4 packet is a valid IGMP packet. If so sets
1599 * skb transport header accordingly and returns zero.
1601 * -EINVAL: A broken packet was detected, i.e. it violates some internet
1603 * -ENOMSG: IP header validation succeeded but it is not an IGMP packet.
1604 * -ENOMEM: A memory allocation failure happened.
1606 * Caller needs to set the skb network header and free any returned skb if it
1607 * differs from the provided skb.
1609 int ip_mc_check_igmp(struct sk_buff
*skb
)
1611 int ret
= ip_mc_check_iphdr(skb
);
1616 if (ip_hdr(skb
)->protocol
!= IPPROTO_IGMP
)
1619 ret
= ip_mc_check_igmp_csum(skb
);
1623 return ip_mc_check_igmp_msg(skb
);
1625 EXPORT_SYMBOL(ip_mc_check_igmp
);
1628 * Resend IGMP JOIN report; used by netdev notifier.
1630 static void ip_mc_rejoin_groups(struct in_device
*in_dev
)
1632 #ifdef CONFIG_IP_MULTICAST
1633 struct ip_mc_list
*im
;
1635 struct net
*net
= dev_net(in_dev
->dev
);
1639 for_each_pmc_rtnl(in_dev
, im
) {
1640 if (im
->multiaddr
== IGMP_ALL_HOSTS
)
1642 if (ipv4_is_local_multicast(im
->multiaddr
) &&
1643 !net
->ipv4
.sysctl_igmp_llm_reports
)
1646 /* a failover is happening and switches
1647 * must be notified immediately
1649 if (IGMP_V1_SEEN(in_dev
))
1650 type
= IGMP_HOST_MEMBERSHIP_REPORT
;
1651 else if (IGMP_V2_SEEN(in_dev
))
1652 type
= IGMPV2_HOST_MEMBERSHIP_REPORT
;
1654 type
= IGMPV3_HOST_MEMBERSHIP_REPORT
;
1655 igmp_send_report(in_dev
, im
, type
);
1661 * A socket has left a multicast group on device dev
1664 void __ip_mc_dec_group(struct in_device
*in_dev
, __be32 addr
, gfp_t gfp
)
1666 struct ip_mc_list
*i
;
1667 struct ip_mc_list __rcu
**ip
;
1671 for (ip
= &in_dev
->mc_list
;
1672 (i
= rtnl_dereference(*ip
)) != NULL
;
1673 ip
= &i
->next_rcu
) {
1674 if (i
->multiaddr
== addr
) {
1675 if (--i
->users
== 0) {
1676 ip_mc_hash_remove(in_dev
, i
);
1679 __igmp_group_dropped(i
, gfp
);
1683 ip_rt_multicast_event(in_dev
);
1692 EXPORT_SYMBOL(__ip_mc_dec_group
);
1694 /* Device changing type */
1696 void ip_mc_unmap(struct in_device
*in_dev
)
1698 struct ip_mc_list
*pmc
;
1702 for_each_pmc_rtnl(in_dev
, pmc
)
1703 igmp_group_dropped(pmc
);
1706 void ip_mc_remap(struct in_device
*in_dev
)
1708 struct ip_mc_list
*pmc
;
1712 for_each_pmc_rtnl(in_dev
, pmc
) {
1713 #ifdef CONFIG_IP_MULTICAST
1714 igmpv3_del_delrec(in_dev
, pmc
);
1716 igmp_group_added(pmc
);
1720 /* Device going down */
1722 void ip_mc_down(struct in_device
*in_dev
)
1724 struct ip_mc_list
*pmc
;
1728 for_each_pmc_rtnl(in_dev
, pmc
)
1729 igmp_group_dropped(pmc
);
1731 #ifdef CONFIG_IP_MULTICAST
1732 in_dev
->mr_ifc_count
= 0;
1733 if (del_timer(&in_dev
->mr_ifc_timer
))
1734 __in_dev_put(in_dev
);
1735 in_dev
->mr_gq_running
= 0;
1736 if (del_timer(&in_dev
->mr_gq_timer
))
1737 __in_dev_put(in_dev
);
1740 ip_mc_dec_group(in_dev
, IGMP_ALL_HOSTS
);
1743 #ifdef CONFIG_IP_MULTICAST
1744 static void ip_mc_reset(struct in_device
*in_dev
)
1746 struct net
*net
= dev_net(in_dev
->dev
);
1748 in_dev
->mr_qi
= IGMP_QUERY_INTERVAL
;
1749 in_dev
->mr_qri
= IGMP_QUERY_RESPONSE_INTERVAL
;
1750 in_dev
->mr_qrv
= net
->ipv4
.sysctl_igmp_qrv
;
1753 static void ip_mc_reset(struct in_device
*in_dev
)
1758 void ip_mc_init_dev(struct in_device
*in_dev
)
1762 #ifdef CONFIG_IP_MULTICAST
1763 timer_setup(&in_dev
->mr_gq_timer
, igmp_gq_timer_expire
, 0);
1764 timer_setup(&in_dev
->mr_ifc_timer
, igmp_ifc_timer_expire
, 0);
1766 ip_mc_reset(in_dev
);
1768 spin_lock_init(&in_dev
->mc_tomb_lock
);
1771 /* Device going up */
1773 void ip_mc_up(struct in_device
*in_dev
)
1775 struct ip_mc_list
*pmc
;
1779 ip_mc_reset(in_dev
);
1780 ip_mc_inc_group(in_dev
, IGMP_ALL_HOSTS
);
1782 for_each_pmc_rtnl(in_dev
, pmc
) {
1783 #ifdef CONFIG_IP_MULTICAST
1784 igmpv3_del_delrec(in_dev
, pmc
);
1786 igmp_group_added(pmc
);
1791 * Device is about to be destroyed: clean up.
1794 void ip_mc_destroy_dev(struct in_device
*in_dev
)
1796 struct ip_mc_list
*i
;
1800 /* Deactivate timers */
1802 #ifdef CONFIG_IP_MULTICAST
1803 igmpv3_clear_delrec(in_dev
);
1806 while ((i
= rtnl_dereference(in_dev
->mc_list
)) != NULL
) {
1807 in_dev
->mc_list
= i
->next_rcu
;
1813 /* RTNL is locked */
1814 static struct in_device
*ip_mc_find_dev(struct net
*net
, struct ip_mreqn
*imr
)
1816 struct net_device
*dev
= NULL
;
1817 struct in_device
*idev
= NULL
;
1819 if (imr
->imr_ifindex
) {
1820 idev
= inetdev_by_index(net
, imr
->imr_ifindex
);
1823 if (imr
->imr_address
.s_addr
) {
1824 dev
= __ip_dev_find(net
, imr
->imr_address
.s_addr
, false);
1830 struct rtable
*rt
= ip_route_output(net
,
1831 imr
->imr_multiaddr
.s_addr
,
1839 imr
->imr_ifindex
= dev
->ifindex
;
1840 idev
= __in_dev_get_rtnl(dev
);
1846 * Join a socket to a group
1849 static int ip_mc_del1_src(struct ip_mc_list
*pmc
, int sfmode
,
1852 struct ip_sf_list
*psf
, *psf_prev
;
1856 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
) {
1857 if (psf
->sf_inaddr
== *psfsrc
)
1861 if (!psf
|| psf
->sf_count
[sfmode
] == 0) {
1862 /* source filter not found, or count wrong => bug */
1865 psf
->sf_count
[sfmode
]--;
1866 if (psf
->sf_count
[sfmode
] == 0) {
1867 ip_rt_multicast_event(pmc
->interface
);
1869 if (!psf
->sf_count
[MCAST_INCLUDE
] && !psf
->sf_count
[MCAST_EXCLUDE
]) {
1870 #ifdef CONFIG_IP_MULTICAST
1871 struct in_device
*in_dev
= pmc
->interface
;
1872 struct net
*net
= dev_net(in_dev
->dev
);
1875 /* no more filters for this source */
1877 psf_prev
->sf_next
= psf
->sf_next
;
1879 pmc
->sources
= psf
->sf_next
;
1880 #ifdef CONFIG_IP_MULTICAST
1881 if (psf
->sf_oldin
&&
1882 !IGMP_V1_SEEN(in_dev
) && !IGMP_V2_SEEN(in_dev
)) {
1883 psf
->sf_crcount
= in_dev
->mr_qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
1884 psf
->sf_next
= pmc
->tomb
;
1894 #ifndef CONFIG_IP_MULTICAST
1895 #define igmp_ifc_event(x) do { } while (0)
1898 static int ip_mc_del_src(struct in_device
*in_dev
, __be32
*pmca
, int sfmode
,
1899 int sfcount
, __be32
*psfsrc
, int delta
)
1901 struct ip_mc_list
*pmc
;
1908 for_each_pmc_rcu(in_dev
, pmc
) {
1909 if (*pmca
== pmc
->multiaddr
)
1913 /* MCA not found?? bug */
1917 spin_lock_bh(&pmc
->lock
);
1919 #ifdef CONFIG_IP_MULTICAST
1924 if (!pmc
->sfcount
[sfmode
])
1926 pmc
->sfcount
[sfmode
]--;
1929 for (i
= 0; i
< sfcount
; i
++) {
1930 int rv
= ip_mc_del1_src(pmc
, sfmode
, &psfsrc
[i
]);
1932 changerec
|= rv
> 0;
1936 if (pmc
->sfmode
== MCAST_EXCLUDE
&&
1937 pmc
->sfcount
[MCAST_EXCLUDE
] == 0 &&
1938 pmc
->sfcount
[MCAST_INCLUDE
]) {
1939 #ifdef CONFIG_IP_MULTICAST
1940 struct ip_sf_list
*psf
;
1941 struct net
*net
= dev_net(in_dev
->dev
);
1944 /* filter mode change */
1945 pmc
->sfmode
= MCAST_INCLUDE
;
1946 #ifdef CONFIG_IP_MULTICAST
1947 pmc
->crcount
= in_dev
->mr_qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
1948 in_dev
->mr_ifc_count
= pmc
->crcount
;
1949 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
)
1950 psf
->sf_crcount
= 0;
1951 igmp_ifc_event(pmc
->interface
);
1952 } else if (sf_setstate(pmc
) || changerec
) {
1953 igmp_ifc_event(pmc
->interface
);
1957 spin_unlock_bh(&pmc
->lock
);
1962 * Add multicast single-source filter to the interface list
1964 static int ip_mc_add1_src(struct ip_mc_list
*pmc
, int sfmode
,
1967 struct ip_sf_list
*psf
, *psf_prev
;
1970 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
) {
1971 if (psf
->sf_inaddr
== *psfsrc
)
1976 psf
= kzalloc(sizeof(*psf
), GFP_ATOMIC
);
1979 psf
->sf_inaddr
= *psfsrc
;
1981 psf_prev
->sf_next
= psf
;
1985 psf
->sf_count
[sfmode
]++;
1986 if (psf
->sf_count
[sfmode
] == 1) {
1987 ip_rt_multicast_event(pmc
->interface
);
1992 #ifdef CONFIG_IP_MULTICAST
1993 static void sf_markstate(struct ip_mc_list
*pmc
)
1995 struct ip_sf_list
*psf
;
1996 int mca_xcount
= pmc
->sfcount
[MCAST_EXCLUDE
];
1998 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
)
1999 if (pmc
->sfcount
[MCAST_EXCLUDE
]) {
2000 psf
->sf_oldin
= mca_xcount
==
2001 psf
->sf_count
[MCAST_EXCLUDE
] &&
2002 !psf
->sf_count
[MCAST_INCLUDE
];
2004 psf
->sf_oldin
= psf
->sf_count
[MCAST_INCLUDE
] != 0;
2007 static int sf_setstate(struct ip_mc_list
*pmc
)
2009 struct ip_sf_list
*psf
, *dpsf
;
2010 int mca_xcount
= pmc
->sfcount
[MCAST_EXCLUDE
];
2011 int qrv
= pmc
->interface
->mr_qrv
;
2015 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
) {
2016 if (pmc
->sfcount
[MCAST_EXCLUDE
]) {
2017 new_in
= mca_xcount
== psf
->sf_count
[MCAST_EXCLUDE
] &&
2018 !psf
->sf_count
[MCAST_INCLUDE
];
2020 new_in
= psf
->sf_count
[MCAST_INCLUDE
] != 0;
2022 if (!psf
->sf_oldin
) {
2023 struct ip_sf_list
*prev
= NULL
;
2025 for (dpsf
= pmc
->tomb
; dpsf
; dpsf
= dpsf
->sf_next
) {
2026 if (dpsf
->sf_inaddr
== psf
->sf_inaddr
)
2032 prev
->sf_next
= dpsf
->sf_next
;
2034 pmc
->tomb
= dpsf
->sf_next
;
2037 psf
->sf_crcount
= qrv
;
2040 } else if (psf
->sf_oldin
) {
2042 psf
->sf_crcount
= 0;
2044 * add or update "delete" records if an active filter
2047 for (dpsf
= pmc
->tomb
; dpsf
; dpsf
= dpsf
->sf_next
)
2048 if (dpsf
->sf_inaddr
== psf
->sf_inaddr
)
2051 dpsf
= kmalloc(sizeof(*dpsf
), GFP_ATOMIC
);
2055 /* pmc->lock held by callers */
2056 dpsf
->sf_next
= pmc
->tomb
;
2059 dpsf
->sf_crcount
= qrv
;
2068 * Add multicast source filter list to the interface list
2070 static int ip_mc_add_src(struct in_device
*in_dev
, __be32
*pmca
, int sfmode
,
2071 int sfcount
, __be32
*psfsrc
, int delta
)
2073 struct ip_mc_list
*pmc
;
2080 for_each_pmc_rcu(in_dev
, pmc
) {
2081 if (*pmca
== pmc
->multiaddr
)
2085 /* MCA not found?? bug */
2089 spin_lock_bh(&pmc
->lock
);
2092 #ifdef CONFIG_IP_MULTICAST
2095 isexclude
= pmc
->sfmode
== MCAST_EXCLUDE
;
2097 pmc
->sfcount
[sfmode
]++;
2099 for (i
= 0; i
< sfcount
; i
++) {
2100 err
= ip_mc_add1_src(pmc
, sfmode
, &psfsrc
[i
]);
2108 pmc
->sfcount
[sfmode
]--;
2109 for (j
= 0; j
< i
; j
++)
2110 (void) ip_mc_del1_src(pmc
, sfmode
, &psfsrc
[j
]);
2111 } else if (isexclude
!= (pmc
->sfcount
[MCAST_EXCLUDE
] != 0)) {
2112 #ifdef CONFIG_IP_MULTICAST
2113 struct ip_sf_list
*psf
;
2114 struct net
*net
= dev_net(pmc
->interface
->dev
);
2115 in_dev
= pmc
->interface
;
2118 /* filter mode change */
2119 if (pmc
->sfcount
[MCAST_EXCLUDE
])
2120 pmc
->sfmode
= MCAST_EXCLUDE
;
2121 else if (pmc
->sfcount
[MCAST_INCLUDE
])
2122 pmc
->sfmode
= MCAST_INCLUDE
;
2123 #ifdef CONFIG_IP_MULTICAST
2124 /* else no filters; keep old mode for reports */
2126 pmc
->crcount
= in_dev
->mr_qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
2127 in_dev
->mr_ifc_count
= pmc
->crcount
;
2128 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
)
2129 psf
->sf_crcount
= 0;
2130 igmp_ifc_event(in_dev
);
2131 } else if (sf_setstate(pmc
)) {
2132 igmp_ifc_event(in_dev
);
2135 spin_unlock_bh(&pmc
->lock
);
2139 static void ip_mc_clear_src(struct ip_mc_list
*pmc
)
2141 struct ip_sf_list
*tomb
, *sources
;
2143 spin_lock_bh(&pmc
->lock
);
2146 sources
= pmc
->sources
;
2147 pmc
->sources
= NULL
;
2148 pmc
->sfmode
= MCAST_EXCLUDE
;
2149 pmc
->sfcount
[MCAST_INCLUDE
] = 0;
2150 pmc
->sfcount
[MCAST_EXCLUDE
] = 1;
2151 spin_unlock_bh(&pmc
->lock
);
2153 ip_sf_list_clear_all(tomb
);
2154 ip_sf_list_clear_all(sources
);
2157 /* Join a multicast group
2159 static int __ip_mc_join_group(struct sock
*sk
, struct ip_mreqn
*imr
,
2162 __be32 addr
= imr
->imr_multiaddr
.s_addr
;
2163 struct ip_mc_socklist
*iml
, *i
;
2164 struct in_device
*in_dev
;
2165 struct inet_sock
*inet
= inet_sk(sk
);
2166 struct net
*net
= sock_net(sk
);
2173 if (!ipv4_is_multicast(addr
))
2176 in_dev
= ip_mc_find_dev(net
, imr
);
2184 ifindex
= imr
->imr_ifindex
;
2185 for_each_pmc_rtnl(inet
, i
) {
2186 if (i
->multi
.imr_multiaddr
.s_addr
== addr
&&
2187 i
->multi
.imr_ifindex
== ifindex
)
2192 if (count
>= net
->ipv4
.sysctl_igmp_max_memberships
)
2194 iml
= sock_kmalloc(sk
, sizeof(*iml
), GFP_KERNEL
);
2198 memcpy(&iml
->multi
, imr
, sizeof(*imr
));
2199 iml
->next_rcu
= inet
->mc_list
;
2202 rcu_assign_pointer(inet
->mc_list
, iml
);
2203 __ip_mc_inc_group(in_dev
, addr
, mode
);
2209 /* Join ASM (Any-Source Multicast) group
2211 int ip_mc_join_group(struct sock
*sk
, struct ip_mreqn
*imr
)
2213 return __ip_mc_join_group(sk
, imr
, MCAST_EXCLUDE
);
2215 EXPORT_SYMBOL(ip_mc_join_group
);
2217 /* Join SSM (Source-Specific Multicast) group
2219 int ip_mc_join_group_ssm(struct sock
*sk
, struct ip_mreqn
*imr
,
2222 return __ip_mc_join_group(sk
, imr
, mode
);
2225 static int ip_mc_leave_src(struct sock
*sk
, struct ip_mc_socklist
*iml
,
2226 struct in_device
*in_dev
)
2228 struct ip_sf_socklist
*psf
= rtnl_dereference(iml
->sflist
);
2232 /* any-source empty exclude case */
2233 return ip_mc_del_src(in_dev
, &iml
->multi
.imr_multiaddr
.s_addr
,
2234 iml
->sfmode
, 0, NULL
, 0);
2236 err
= ip_mc_del_src(in_dev
, &iml
->multi
.imr_multiaddr
.s_addr
,
2237 iml
->sfmode
, psf
->sl_count
, psf
->sl_addr
, 0);
2238 RCU_INIT_POINTER(iml
->sflist
, NULL
);
2239 /* decrease mem now to avoid the memleak warning */
2240 atomic_sub(IP_SFLSIZE(psf
->sl_max
), &sk
->sk_omem_alloc
);
2241 kfree_rcu(psf
, rcu
);
2245 int ip_mc_leave_group(struct sock
*sk
, struct ip_mreqn
*imr
)
2247 struct inet_sock
*inet
= inet_sk(sk
);
2248 struct ip_mc_socklist
*iml
;
2249 struct ip_mc_socklist __rcu
**imlp
;
2250 struct in_device
*in_dev
;
2251 struct net
*net
= sock_net(sk
);
2252 __be32 group
= imr
->imr_multiaddr
.s_addr
;
2254 int ret
= -EADDRNOTAVAIL
;
2258 in_dev
= ip_mc_find_dev(net
, imr
);
2259 if (!imr
->imr_ifindex
&& !imr
->imr_address
.s_addr
&& !in_dev
) {
2263 ifindex
= imr
->imr_ifindex
;
2264 for (imlp
= &inet
->mc_list
;
2265 (iml
= rtnl_dereference(*imlp
)) != NULL
;
2266 imlp
= &iml
->next_rcu
) {
2267 if (iml
->multi
.imr_multiaddr
.s_addr
!= group
)
2270 if (iml
->multi
.imr_ifindex
!= ifindex
)
2272 } else if (imr
->imr_address
.s_addr
&& imr
->imr_address
.s_addr
!=
2273 iml
->multi
.imr_address
.s_addr
)
2276 (void) ip_mc_leave_src(sk
, iml
, in_dev
);
2278 *imlp
= iml
->next_rcu
;
2281 ip_mc_dec_group(in_dev
, group
);
2283 /* decrease mem now to avoid the memleak warning */
2284 atomic_sub(sizeof(*iml
), &sk
->sk_omem_alloc
);
2285 kfree_rcu(iml
, rcu
);
2291 EXPORT_SYMBOL(ip_mc_leave_group
);
2293 int ip_mc_source(int add
, int omode
, struct sock
*sk
, struct
2294 ip_mreq_source
*mreqs
, int ifindex
)
2297 struct ip_mreqn imr
;
2298 __be32 addr
= mreqs
->imr_multiaddr
;
2299 struct ip_mc_socklist
*pmc
;
2300 struct in_device
*in_dev
= NULL
;
2301 struct inet_sock
*inet
= inet_sk(sk
);
2302 struct ip_sf_socklist
*psl
;
2303 struct net
*net
= sock_net(sk
);
2307 if (!ipv4_is_multicast(addr
))
2312 imr
.imr_multiaddr
.s_addr
= mreqs
->imr_multiaddr
;
2313 imr
.imr_address
.s_addr
= mreqs
->imr_interface
;
2314 imr
.imr_ifindex
= ifindex
;
2315 in_dev
= ip_mc_find_dev(net
, &imr
);
2321 err
= -EADDRNOTAVAIL
;
2323 for_each_pmc_rtnl(inet
, pmc
) {
2324 if ((pmc
->multi
.imr_multiaddr
.s_addr
==
2325 imr
.imr_multiaddr
.s_addr
) &&
2326 (pmc
->multi
.imr_ifindex
== imr
.imr_ifindex
))
2329 if (!pmc
) { /* must have a prior join */
2333 /* if a source filter was set, must be the same mode as before */
2335 if (pmc
->sfmode
!= omode
) {
2339 } else if (pmc
->sfmode
!= omode
) {
2340 /* allow mode switches for empty-set filters */
2341 ip_mc_add_src(in_dev
, &mreqs
->imr_multiaddr
, omode
, 0, NULL
, 0);
2342 ip_mc_del_src(in_dev
, &mreqs
->imr_multiaddr
, pmc
->sfmode
, 0,
2344 pmc
->sfmode
= omode
;
2347 psl
= rtnl_dereference(pmc
->sflist
);
2350 goto done
; /* err = -EADDRNOTAVAIL */
2352 for (i
= 0; i
< psl
->sl_count
; i
++) {
2353 rv
= memcmp(&psl
->sl_addr
[i
], &mreqs
->imr_sourceaddr
,
2358 if (rv
) /* source not found */
2359 goto done
; /* err = -EADDRNOTAVAIL */
2361 /* special case - (INCLUDE, empty) == LEAVE_GROUP */
2362 if (psl
->sl_count
== 1 && omode
== MCAST_INCLUDE
) {
2367 /* update the interface filter */
2368 ip_mc_del_src(in_dev
, &mreqs
->imr_multiaddr
, omode
, 1,
2369 &mreqs
->imr_sourceaddr
, 1);
2371 for (j
= i
+1; j
< psl
->sl_count
; j
++)
2372 psl
->sl_addr
[j
-1] = psl
->sl_addr
[j
];
2377 /* else, add a new source to the filter */
2379 if (psl
&& psl
->sl_count
>= net
->ipv4
.sysctl_igmp_max_msf
) {
2383 if (!psl
|| psl
->sl_count
== psl
->sl_max
) {
2384 struct ip_sf_socklist
*newpsl
;
2385 int count
= IP_SFBLOCK
;
2388 count
+= psl
->sl_max
;
2389 newpsl
= sock_kmalloc(sk
, IP_SFLSIZE(count
), GFP_KERNEL
);
2394 newpsl
->sl_max
= count
;
2395 newpsl
->sl_count
= count
- IP_SFBLOCK
;
2397 for (i
= 0; i
< psl
->sl_count
; i
++)
2398 newpsl
->sl_addr
[i
] = psl
->sl_addr
[i
];
2399 /* decrease mem now to avoid the memleak warning */
2400 atomic_sub(IP_SFLSIZE(psl
->sl_max
), &sk
->sk_omem_alloc
);
2401 kfree_rcu(psl
, rcu
);
2403 rcu_assign_pointer(pmc
->sflist
, newpsl
);
2406 rv
= 1; /* > 0 for insert logic below if sl_count is 0 */
2407 for (i
= 0; i
< psl
->sl_count
; i
++) {
2408 rv
= memcmp(&psl
->sl_addr
[i
], &mreqs
->imr_sourceaddr
,
2413 if (rv
== 0) /* address already there is an error */
2415 for (j
= psl
->sl_count
-1; j
>= i
; j
--)
2416 psl
->sl_addr
[j
+1] = psl
->sl_addr
[j
];
2417 psl
->sl_addr
[i
] = mreqs
->imr_sourceaddr
;
2420 /* update the interface list */
2421 ip_mc_add_src(in_dev
, &mreqs
->imr_multiaddr
, omode
, 1,
2422 &mreqs
->imr_sourceaddr
, 1);
2425 err
= ip_mc_leave_group(sk
, &imr
);
2429 int ip_mc_msfilter(struct sock
*sk
, struct ip_msfilter
*msf
, int ifindex
)
2432 struct ip_mreqn imr
;
2433 __be32 addr
= msf
->imsf_multiaddr
;
2434 struct ip_mc_socklist
*pmc
;
2435 struct in_device
*in_dev
;
2436 struct inet_sock
*inet
= inet_sk(sk
);
2437 struct ip_sf_socklist
*newpsl
, *psl
;
2438 struct net
*net
= sock_net(sk
);
2441 if (!ipv4_is_multicast(addr
))
2443 if (msf
->imsf_fmode
!= MCAST_INCLUDE
&&
2444 msf
->imsf_fmode
!= MCAST_EXCLUDE
)
2449 imr
.imr_multiaddr
.s_addr
= msf
->imsf_multiaddr
;
2450 imr
.imr_address
.s_addr
= msf
->imsf_interface
;
2451 imr
.imr_ifindex
= ifindex
;
2452 in_dev
= ip_mc_find_dev(net
, &imr
);
2459 /* special case - (INCLUDE, empty) == LEAVE_GROUP */
2460 if (msf
->imsf_fmode
== MCAST_INCLUDE
&& msf
->imsf_numsrc
== 0) {
2465 for_each_pmc_rtnl(inet
, pmc
) {
2466 if (pmc
->multi
.imr_multiaddr
.s_addr
== msf
->imsf_multiaddr
&&
2467 pmc
->multi
.imr_ifindex
== imr
.imr_ifindex
)
2470 if (!pmc
) { /* must have a prior join */
2474 if (msf
->imsf_numsrc
) {
2475 newpsl
= sock_kmalloc(sk
, IP_SFLSIZE(msf
->imsf_numsrc
),
2481 newpsl
->sl_max
= newpsl
->sl_count
= msf
->imsf_numsrc
;
2482 memcpy(newpsl
->sl_addr
, msf
->imsf_slist
,
2483 msf
->imsf_numsrc
* sizeof(msf
->imsf_slist
[0]));
2484 err
= ip_mc_add_src(in_dev
, &msf
->imsf_multiaddr
,
2485 msf
->imsf_fmode
, newpsl
->sl_count
, newpsl
->sl_addr
, 0);
2487 sock_kfree_s(sk
, newpsl
, IP_SFLSIZE(newpsl
->sl_max
));
2492 (void) ip_mc_add_src(in_dev
, &msf
->imsf_multiaddr
,
2493 msf
->imsf_fmode
, 0, NULL
, 0);
2495 psl
= rtnl_dereference(pmc
->sflist
);
2497 (void) ip_mc_del_src(in_dev
, &msf
->imsf_multiaddr
, pmc
->sfmode
,
2498 psl
->sl_count
, psl
->sl_addr
, 0);
2499 /* decrease mem now to avoid the memleak warning */
2500 atomic_sub(IP_SFLSIZE(psl
->sl_max
), &sk
->sk_omem_alloc
);
2501 kfree_rcu(psl
, rcu
);
2503 (void) ip_mc_del_src(in_dev
, &msf
->imsf_multiaddr
, pmc
->sfmode
,
2505 rcu_assign_pointer(pmc
->sflist
, newpsl
);
2506 pmc
->sfmode
= msf
->imsf_fmode
;
2510 err
= ip_mc_leave_group(sk
, &imr
);
2514 int ip_mc_msfget(struct sock
*sk
, struct ip_msfilter
*msf
,
2515 struct ip_msfilter __user
*optval
, int __user
*optlen
)
2517 int err
, len
, count
, copycount
;
2518 struct ip_mreqn imr
;
2519 __be32 addr
= msf
->imsf_multiaddr
;
2520 struct ip_mc_socklist
*pmc
;
2521 struct in_device
*in_dev
;
2522 struct inet_sock
*inet
= inet_sk(sk
);
2523 struct ip_sf_socklist
*psl
;
2524 struct net
*net
= sock_net(sk
);
2528 if (!ipv4_is_multicast(addr
))
2531 imr
.imr_multiaddr
.s_addr
= msf
->imsf_multiaddr
;
2532 imr
.imr_address
.s_addr
= msf
->imsf_interface
;
2533 imr
.imr_ifindex
= 0;
2534 in_dev
= ip_mc_find_dev(net
, &imr
);
2540 err
= -EADDRNOTAVAIL
;
2542 for_each_pmc_rtnl(inet
, pmc
) {
2543 if (pmc
->multi
.imr_multiaddr
.s_addr
== msf
->imsf_multiaddr
&&
2544 pmc
->multi
.imr_ifindex
== imr
.imr_ifindex
)
2547 if (!pmc
) /* must have a prior join */
2549 msf
->imsf_fmode
= pmc
->sfmode
;
2550 psl
= rtnl_dereference(pmc
->sflist
);
2555 count
= psl
->sl_count
;
2557 copycount
= count
< msf
->imsf_numsrc
? count
: msf
->imsf_numsrc
;
2558 len
= copycount
* sizeof(psl
->sl_addr
[0]);
2559 msf
->imsf_numsrc
= count
;
2560 if (put_user(IP_MSFILTER_SIZE(copycount
), optlen
) ||
2561 copy_to_user(optval
, msf
, IP_MSFILTER_SIZE(0))) {
2565 copy_to_user(&optval
->imsf_slist
[0], psl
->sl_addr
, len
))
2572 int ip_mc_gsfget(struct sock
*sk
, struct group_filter
*gsf
,
2573 struct group_filter __user
*optval
, int __user
*optlen
)
2575 int err
, i
, count
, copycount
;
2576 struct sockaddr_in
*psin
;
2578 struct ip_mc_socklist
*pmc
;
2579 struct inet_sock
*inet
= inet_sk(sk
);
2580 struct ip_sf_socklist
*psl
;
2584 psin
= (struct sockaddr_in
*)&gsf
->gf_group
;
2585 if (psin
->sin_family
!= AF_INET
)
2587 addr
= psin
->sin_addr
.s_addr
;
2588 if (!ipv4_is_multicast(addr
))
2591 err
= -EADDRNOTAVAIL
;
2593 for_each_pmc_rtnl(inet
, pmc
) {
2594 if (pmc
->multi
.imr_multiaddr
.s_addr
== addr
&&
2595 pmc
->multi
.imr_ifindex
== gsf
->gf_interface
)
2598 if (!pmc
) /* must have a prior join */
2600 gsf
->gf_fmode
= pmc
->sfmode
;
2601 psl
= rtnl_dereference(pmc
->sflist
);
2602 count
= psl
? psl
->sl_count
: 0;
2603 copycount
= count
< gsf
->gf_numsrc
? count
: gsf
->gf_numsrc
;
2604 gsf
->gf_numsrc
= count
;
2605 if (put_user(GROUP_FILTER_SIZE(copycount
), optlen
) ||
2606 copy_to_user(optval
, gsf
, GROUP_FILTER_SIZE(0))) {
2609 for (i
= 0; i
< copycount
; i
++) {
2610 struct sockaddr_storage ss
;
2612 psin
= (struct sockaddr_in
*)&ss
;
2613 memset(&ss
, 0, sizeof(ss
));
2614 psin
->sin_family
= AF_INET
;
2615 psin
->sin_addr
.s_addr
= psl
->sl_addr
[i
];
2616 if (copy_to_user(&optval
->gf_slist
[i
], &ss
, sizeof(ss
)))
2625 * check if a multicast source filter allows delivery for a given <src,dst,intf>
2627 int ip_mc_sf_allow(struct sock
*sk
, __be32 loc_addr
, __be32 rmt_addr
,
2630 struct inet_sock
*inet
= inet_sk(sk
);
2631 struct ip_mc_socklist
*pmc
;
2632 struct ip_sf_socklist
*psl
;
2637 if (!ipv4_is_multicast(loc_addr
))
2641 for_each_pmc_rcu(inet
, pmc
) {
2642 if (pmc
->multi
.imr_multiaddr
.s_addr
== loc_addr
&&
2643 (pmc
->multi
.imr_ifindex
== dif
||
2644 (sdif
&& pmc
->multi
.imr_ifindex
== sdif
)))
2650 psl
= rcu_dereference(pmc
->sflist
);
2651 ret
= (pmc
->sfmode
== MCAST_EXCLUDE
);
2655 for (i
= 0; i
< psl
->sl_count
; i
++) {
2656 if (psl
->sl_addr
[i
] == rmt_addr
)
2660 if (pmc
->sfmode
== MCAST_INCLUDE
&& i
>= psl
->sl_count
)
2662 if (pmc
->sfmode
== MCAST_EXCLUDE
&& i
< psl
->sl_count
)
2672 * A socket is closing.
2675 void ip_mc_drop_socket(struct sock
*sk
)
2677 struct inet_sock
*inet
= inet_sk(sk
);
2678 struct ip_mc_socklist
*iml
;
2679 struct net
*net
= sock_net(sk
);
2685 while ((iml
= rtnl_dereference(inet
->mc_list
)) != NULL
) {
2686 struct in_device
*in_dev
;
2688 inet
->mc_list
= iml
->next_rcu
;
2689 in_dev
= inetdev_by_index(net
, iml
->multi
.imr_ifindex
);
2690 (void) ip_mc_leave_src(sk
, iml
, in_dev
);
2692 ip_mc_dec_group(in_dev
, iml
->multi
.imr_multiaddr
.s_addr
);
2693 /* decrease mem now to avoid the memleak warning */
2694 atomic_sub(sizeof(*iml
), &sk
->sk_omem_alloc
);
2695 kfree_rcu(iml
, rcu
);
2700 /* called with rcu_read_lock() */
2701 int ip_check_mc_rcu(struct in_device
*in_dev
, __be32 mc_addr
, __be32 src_addr
, u8 proto
)
2703 struct ip_mc_list
*im
;
2704 struct ip_mc_list __rcu
**mc_hash
;
2705 struct ip_sf_list
*psf
;
2708 mc_hash
= rcu_dereference(in_dev
->mc_hash
);
2710 u32 hash
= hash_32((__force u32
)mc_addr
, MC_HASH_SZ_LOG
);
2712 for (im
= rcu_dereference(mc_hash
[hash
]);
2714 im
= rcu_dereference(im
->next_hash
)) {
2715 if (im
->multiaddr
== mc_addr
)
2719 for_each_pmc_rcu(in_dev
, im
) {
2720 if (im
->multiaddr
== mc_addr
)
2724 if (im
&& proto
== IPPROTO_IGMP
) {
2728 for (psf
= im
->sources
; psf
; psf
= psf
->sf_next
) {
2729 if (psf
->sf_inaddr
== src_addr
)
2733 rv
= psf
->sf_count
[MCAST_INCLUDE
] ||
2734 psf
->sf_count
[MCAST_EXCLUDE
] !=
2735 im
->sfcount
[MCAST_EXCLUDE
];
2737 rv
= im
->sfcount
[MCAST_EXCLUDE
] != 0;
2739 rv
= 1; /* unspecified source; tentatively allow */
2744 #if defined(CONFIG_PROC_FS)
2745 struct igmp_mc_iter_state
{
2746 struct seq_net_private p
;
2747 struct net_device
*dev
;
2748 struct in_device
*in_dev
;
2751 #define igmp_mc_seq_private(seq) ((struct igmp_mc_iter_state *)(seq)->private)
2753 static inline struct ip_mc_list
*igmp_mc_get_first(struct seq_file
*seq
)
2755 struct net
*net
= seq_file_net(seq
);
2756 struct ip_mc_list
*im
= NULL
;
2757 struct igmp_mc_iter_state
*state
= igmp_mc_seq_private(seq
);
2759 state
->in_dev
= NULL
;
2760 for_each_netdev_rcu(net
, state
->dev
) {
2761 struct in_device
*in_dev
;
2763 in_dev
= __in_dev_get_rcu(state
->dev
);
2766 im
= rcu_dereference(in_dev
->mc_list
);
2768 state
->in_dev
= in_dev
;
2775 static struct ip_mc_list
*igmp_mc_get_next(struct seq_file
*seq
, struct ip_mc_list
*im
)
2777 struct igmp_mc_iter_state
*state
= igmp_mc_seq_private(seq
);
2779 im
= rcu_dereference(im
->next_rcu
);
2781 state
->dev
= next_net_device_rcu(state
->dev
);
2783 state
->in_dev
= NULL
;
2786 state
->in_dev
= __in_dev_get_rcu(state
->dev
);
2789 im
= rcu_dereference(state
->in_dev
->mc_list
);
2794 static struct ip_mc_list
*igmp_mc_get_idx(struct seq_file
*seq
, loff_t pos
)
2796 struct ip_mc_list
*im
= igmp_mc_get_first(seq
);
2798 while (pos
&& (im
= igmp_mc_get_next(seq
, im
)) != NULL
)
2800 return pos
? NULL
: im
;
2803 static void *igmp_mc_seq_start(struct seq_file
*seq
, loff_t
*pos
)
2807 return *pos
? igmp_mc_get_idx(seq
, *pos
- 1) : SEQ_START_TOKEN
;
2810 static void *igmp_mc_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
2812 struct ip_mc_list
*im
;
2813 if (v
== SEQ_START_TOKEN
)
2814 im
= igmp_mc_get_first(seq
);
2816 im
= igmp_mc_get_next(seq
, v
);
2821 static void igmp_mc_seq_stop(struct seq_file
*seq
, void *v
)
2824 struct igmp_mc_iter_state
*state
= igmp_mc_seq_private(seq
);
2826 state
->in_dev
= NULL
;
2831 static int igmp_mc_seq_show(struct seq_file
*seq
, void *v
)
2833 if (v
== SEQ_START_TOKEN
)
2835 "Idx\tDevice : Count Querier\tGroup Users Timer\tReporter\n");
2837 struct ip_mc_list
*im
= (struct ip_mc_list
*)v
;
2838 struct igmp_mc_iter_state
*state
= igmp_mc_seq_private(seq
);
2842 #ifdef CONFIG_IP_MULTICAST
2843 querier
= IGMP_V1_SEEN(state
->in_dev
) ? "V1" :
2844 IGMP_V2_SEEN(state
->in_dev
) ? "V2" :
2850 if (rcu_access_pointer(state
->in_dev
->mc_list
) == im
) {
2851 seq_printf(seq
, "%d\t%-10s: %5d %7s\n",
2852 state
->dev
->ifindex
, state
->dev
->name
, state
->in_dev
->mc_count
, querier
);
2855 delta
= im
->timer
.expires
- jiffies
;
2857 "\t\t\t\t%08X %5d %d:%08lX\t\t%d\n",
2858 im
->multiaddr
, im
->users
,
2860 im
->tm_running
? jiffies_delta_to_clock_t(delta
) : 0,
2866 static const struct seq_operations igmp_mc_seq_ops
= {
2867 .start
= igmp_mc_seq_start
,
2868 .next
= igmp_mc_seq_next
,
2869 .stop
= igmp_mc_seq_stop
,
2870 .show
= igmp_mc_seq_show
,
2873 struct igmp_mcf_iter_state
{
2874 struct seq_net_private p
;
2875 struct net_device
*dev
;
2876 struct in_device
*idev
;
2877 struct ip_mc_list
*im
;
2880 #define igmp_mcf_seq_private(seq) ((struct igmp_mcf_iter_state *)(seq)->private)
2882 static inline struct ip_sf_list
*igmp_mcf_get_first(struct seq_file
*seq
)
2884 struct net
*net
= seq_file_net(seq
);
2885 struct ip_sf_list
*psf
= NULL
;
2886 struct ip_mc_list
*im
= NULL
;
2887 struct igmp_mcf_iter_state
*state
= igmp_mcf_seq_private(seq
);
2891 for_each_netdev_rcu(net
, state
->dev
) {
2892 struct in_device
*idev
;
2893 idev
= __in_dev_get_rcu(state
->dev
);
2894 if (unlikely(!idev
))
2896 im
= rcu_dereference(idev
->mc_list
);
2898 spin_lock_bh(&im
->lock
);
2905 spin_unlock_bh(&im
->lock
);
2911 static struct ip_sf_list
*igmp_mcf_get_next(struct seq_file
*seq
, struct ip_sf_list
*psf
)
2913 struct igmp_mcf_iter_state
*state
= igmp_mcf_seq_private(seq
);
2917 spin_unlock_bh(&state
->im
->lock
);
2918 state
->im
= state
->im
->next
;
2919 while (!state
->im
) {
2920 state
->dev
= next_net_device_rcu(state
->dev
);
2925 state
->idev
= __in_dev_get_rcu(state
->dev
);
2928 state
->im
= rcu_dereference(state
->idev
->mc_list
);
2932 spin_lock_bh(&state
->im
->lock
);
2933 psf
= state
->im
->sources
;
2939 static struct ip_sf_list
*igmp_mcf_get_idx(struct seq_file
*seq
, loff_t pos
)
2941 struct ip_sf_list
*psf
= igmp_mcf_get_first(seq
);
2943 while (pos
&& (psf
= igmp_mcf_get_next(seq
, psf
)) != NULL
)
2945 return pos
? NULL
: psf
;
2948 static void *igmp_mcf_seq_start(struct seq_file
*seq
, loff_t
*pos
)
2952 return *pos
? igmp_mcf_get_idx(seq
, *pos
- 1) : SEQ_START_TOKEN
;
2955 static void *igmp_mcf_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
2957 struct ip_sf_list
*psf
;
2958 if (v
== SEQ_START_TOKEN
)
2959 psf
= igmp_mcf_get_first(seq
);
2961 psf
= igmp_mcf_get_next(seq
, v
);
2966 static void igmp_mcf_seq_stop(struct seq_file
*seq
, void *v
)
2969 struct igmp_mcf_iter_state
*state
= igmp_mcf_seq_private(seq
);
2970 if (likely(state
->im
)) {
2971 spin_unlock_bh(&state
->im
->lock
);
2979 static int igmp_mcf_seq_show(struct seq_file
*seq
, void *v
)
2981 struct ip_sf_list
*psf
= (struct ip_sf_list
*)v
;
2982 struct igmp_mcf_iter_state
*state
= igmp_mcf_seq_private(seq
);
2984 if (v
== SEQ_START_TOKEN
) {
2985 seq_puts(seq
, "Idx Device MCA SRC INC EXC\n");
2989 "0x%08x %6lu %6lu\n",
2990 state
->dev
->ifindex
, state
->dev
->name
,
2991 ntohl(state
->im
->multiaddr
),
2992 ntohl(psf
->sf_inaddr
),
2993 psf
->sf_count
[MCAST_INCLUDE
],
2994 psf
->sf_count
[MCAST_EXCLUDE
]);
2999 static const struct seq_operations igmp_mcf_seq_ops
= {
3000 .start
= igmp_mcf_seq_start
,
3001 .next
= igmp_mcf_seq_next
,
3002 .stop
= igmp_mcf_seq_stop
,
3003 .show
= igmp_mcf_seq_show
,
3006 static int __net_init
igmp_net_init(struct net
*net
)
3008 struct proc_dir_entry
*pde
;
3011 pde
= proc_create_net("igmp", 0444, net
->proc_net
, &igmp_mc_seq_ops
,
3012 sizeof(struct igmp_mc_iter_state
));
3015 pde
= proc_create_net("mcfilter", 0444, net
->proc_net
,
3016 &igmp_mcf_seq_ops
, sizeof(struct igmp_mcf_iter_state
));
3019 err
= inet_ctl_sock_create(&net
->ipv4
.mc_autojoin_sk
, AF_INET
,
3020 SOCK_DGRAM
, 0, net
);
3022 pr_err("Failed to initialize the IGMP autojoin socket (err %d)\n",
3030 remove_proc_entry("mcfilter", net
->proc_net
);
3032 remove_proc_entry("igmp", net
->proc_net
);
3037 static void __net_exit
igmp_net_exit(struct net
*net
)
3039 remove_proc_entry("mcfilter", net
->proc_net
);
3040 remove_proc_entry("igmp", net
->proc_net
);
3041 inet_ctl_sock_destroy(net
->ipv4
.mc_autojoin_sk
);
3044 static struct pernet_operations igmp_net_ops
= {
3045 .init
= igmp_net_init
,
3046 .exit
= igmp_net_exit
,
3050 static int igmp_netdev_event(struct notifier_block
*this,
3051 unsigned long event
, void *ptr
)
3053 struct net_device
*dev
= netdev_notifier_info_to_dev(ptr
);
3054 struct in_device
*in_dev
;
3057 case NETDEV_RESEND_IGMP
:
3058 in_dev
= __in_dev_get_rtnl(dev
);
3060 ip_mc_rejoin_groups(in_dev
);
3068 static struct notifier_block igmp_notifier
= {
3069 .notifier_call
= igmp_netdev_event
,
3072 int __init
igmp_mc_init(void)
3074 #if defined(CONFIG_PROC_FS)
3077 err
= register_pernet_subsys(&igmp_net_ops
);
3080 err
= register_netdevice_notifier(&igmp_notifier
);
3082 goto reg_notif_fail
;
3086 unregister_pernet_subsys(&igmp_net_ops
);
3089 return register_netdevice_notifier(&igmp_notifier
);