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
);
335 const struct in_ifaddr
*ifa
;
338 return htonl(INADDR_ANY
);
340 in_dev_for_each_ifa_rcu(ifa
, in_dev
) {
341 if (fl4
->saddr
== ifa
->ifa_local
)
345 return htonl(INADDR_ANY
);
348 static struct sk_buff
*igmpv3_newpack(struct net_device
*dev
, unsigned int mtu
)
353 struct igmpv3_report
*pig
;
354 struct net
*net
= dev_net(dev
);
356 int hlen
= LL_RESERVED_SPACE(dev
);
357 int tlen
= dev
->needed_tailroom
;
358 unsigned int size
= mtu
;
361 skb
= alloc_skb(size
+ hlen
+ tlen
,
362 GFP_ATOMIC
| __GFP_NOWARN
);
369 skb
->priority
= TC_PRIO_CONTROL
;
371 rt
= ip_route_output_ports(net
, &fl4
, NULL
, IGMPV3_ALL_MCR
, 0,
373 IPPROTO_IGMP
, 0, dev
->ifindex
);
379 skb_dst_set(skb
, &rt
->dst
);
382 skb_reserve(skb
, hlen
);
383 skb_tailroom_reserve(skb
, mtu
, tlen
);
385 skb_reset_network_header(skb
);
387 skb_put(skb
, sizeof(struct iphdr
) + 4);
390 pip
->ihl
= (sizeof(struct iphdr
)+4)>>2;
392 pip
->frag_off
= htons(IP_DF
);
394 pip
->daddr
= fl4
.daddr
;
397 pip
->saddr
= igmpv3_get_srcaddr(dev
, &fl4
);
400 pip
->protocol
= IPPROTO_IGMP
;
401 pip
->tot_len
= 0; /* filled in later */
402 ip_select_ident(net
, skb
, NULL
);
403 ((u8
*)&pip
[1])[0] = IPOPT_RA
;
404 ((u8
*)&pip
[1])[1] = 4;
405 ((u8
*)&pip
[1])[2] = 0;
406 ((u8
*)&pip
[1])[3] = 0;
408 skb
->transport_header
= skb
->network_header
+ sizeof(struct iphdr
) + 4;
409 skb_put(skb
, sizeof(*pig
));
410 pig
= igmpv3_report_hdr(skb
);
411 pig
->type
= IGMPV3_HOST_MEMBERSHIP_REPORT
;
419 static int igmpv3_sendpack(struct sk_buff
*skb
)
421 struct igmphdr
*pig
= igmp_hdr(skb
);
422 const int igmplen
= skb_tail_pointer(skb
) - skb_transport_header(skb
);
424 pig
->csum
= ip_compute_csum(igmp_hdr(skb
), igmplen
);
426 return ip_local_out(dev_net(skb_dst(skb
)->dev
), skb
->sk
, skb
);
429 static int grec_size(struct ip_mc_list
*pmc
, int type
, int gdel
, int sdel
)
431 return sizeof(struct igmpv3_grec
) + 4*igmp_scount(pmc
, type
, gdel
, sdel
);
434 static struct sk_buff
*add_grhead(struct sk_buff
*skb
, struct ip_mc_list
*pmc
,
435 int type
, struct igmpv3_grec
**ppgr
, unsigned int mtu
)
437 struct net_device
*dev
= pmc
->interface
->dev
;
438 struct igmpv3_report
*pih
;
439 struct igmpv3_grec
*pgr
;
442 skb
= igmpv3_newpack(dev
, mtu
);
446 pgr
= skb_put(skb
, sizeof(struct igmpv3_grec
));
447 pgr
->grec_type
= type
;
448 pgr
->grec_auxwords
= 0;
450 pgr
->grec_mca
= pmc
->multiaddr
;
451 pih
= igmpv3_report_hdr(skb
);
452 pih
->ngrec
= htons(ntohs(pih
->ngrec
)+1);
457 #define AVAILABLE(skb) ((skb) ? skb_availroom(skb) : 0)
459 static struct sk_buff
*add_grec(struct sk_buff
*skb
, struct ip_mc_list
*pmc
,
460 int type
, int gdeleted
, int sdeleted
)
462 struct net_device
*dev
= pmc
->interface
->dev
;
463 struct net
*net
= dev_net(dev
);
464 struct igmpv3_report
*pih
;
465 struct igmpv3_grec
*pgr
= NULL
;
466 struct ip_sf_list
*psf
, *psf_next
, *psf_prev
, **psf_list
;
467 int scount
, stotal
, first
, isquery
, truncate
;
470 if (pmc
->multiaddr
== IGMP_ALL_HOSTS
)
472 if (ipv4_is_local_multicast(pmc
->multiaddr
) && !net
->ipv4
.sysctl_igmp_llm_reports
)
475 mtu
= READ_ONCE(dev
->mtu
);
476 if (mtu
< IPV4_MIN_MTU
)
479 isquery
= type
== IGMPV3_MODE_IS_INCLUDE
||
480 type
== IGMPV3_MODE_IS_EXCLUDE
;
481 truncate
= type
== IGMPV3_MODE_IS_EXCLUDE
||
482 type
== IGMPV3_CHANGE_TO_EXCLUDE
;
486 psf_list
= sdeleted
? &pmc
->tomb
: &pmc
->sources
;
491 pih
= skb
? igmpv3_report_hdr(skb
) : NULL
;
493 /* EX and TO_EX get a fresh packet, if needed */
495 if (pih
&& pih
->ngrec
&&
496 AVAILABLE(skb
) < grec_size(pmc
, type
, gdeleted
, sdeleted
)) {
498 igmpv3_sendpack(skb
);
499 skb
= igmpv3_newpack(dev
, mtu
);
504 for (psf
= *psf_list
; psf
; psf
= psf_next
) {
507 psf_next
= psf
->sf_next
;
509 if (!is_in(pmc
, psf
, type
, gdeleted
, sdeleted
)) {
514 /* Based on RFC3376 5.1. Should not send source-list change
515 * records when there is a filter mode change.
517 if (((gdeleted
&& pmc
->sfmode
== MCAST_EXCLUDE
) ||
518 (!gdeleted
&& pmc
->crcount
)) &&
519 (type
== IGMPV3_ALLOW_NEW_SOURCES
||
520 type
== IGMPV3_BLOCK_OLD_SOURCES
) && psf
->sf_crcount
)
521 goto decrease_sf_crcount
;
523 /* clear marks on query responses */
527 if (AVAILABLE(skb
) < sizeof(__be32
) +
528 first
*sizeof(struct igmpv3_grec
)) {
529 if (truncate
&& !first
)
530 break; /* truncate these */
532 pgr
->grec_nsrcs
= htons(scount
);
534 igmpv3_sendpack(skb
);
535 skb
= igmpv3_newpack(dev
, mtu
);
540 skb
= add_grhead(skb
, pmc
, type
, &pgr
, mtu
);
545 psrc
= skb_put(skb
, sizeof(__be32
));
546 *psrc
= psf
->sf_inaddr
;
548 if ((type
== IGMPV3_ALLOW_NEW_SOURCES
||
549 type
== IGMPV3_BLOCK_OLD_SOURCES
) && psf
->sf_crcount
) {
552 if ((sdeleted
|| gdeleted
) && psf
->sf_crcount
== 0) {
554 psf_prev
->sf_next
= psf
->sf_next
;
556 *psf_list
= psf
->sf_next
;
566 if (type
== IGMPV3_ALLOW_NEW_SOURCES
||
567 type
== IGMPV3_BLOCK_OLD_SOURCES
)
569 if (pmc
->crcount
|| isquery
) {
570 /* make sure we have room for group header */
571 if (skb
&& AVAILABLE(skb
) < sizeof(struct igmpv3_grec
)) {
572 igmpv3_sendpack(skb
);
573 skb
= NULL
; /* add_grhead will get a new one */
575 skb
= add_grhead(skb
, pmc
, type
, &pgr
, mtu
);
579 pgr
->grec_nsrcs
= htons(scount
);
582 pmc
->gsquery
= 0; /* clear query state on report */
586 static int igmpv3_send_report(struct in_device
*in_dev
, struct ip_mc_list
*pmc
)
588 struct sk_buff
*skb
= NULL
;
589 struct net
*net
= dev_net(in_dev
->dev
);
594 for_each_pmc_rcu(in_dev
, pmc
) {
595 if (pmc
->multiaddr
== IGMP_ALL_HOSTS
)
597 if (ipv4_is_local_multicast(pmc
->multiaddr
) &&
598 !net
->ipv4
.sysctl_igmp_llm_reports
)
600 spin_lock_bh(&pmc
->lock
);
601 if (pmc
->sfcount
[MCAST_EXCLUDE
])
602 type
= IGMPV3_MODE_IS_EXCLUDE
;
604 type
= IGMPV3_MODE_IS_INCLUDE
;
605 skb
= add_grec(skb
, pmc
, type
, 0, 0);
606 spin_unlock_bh(&pmc
->lock
);
610 spin_lock_bh(&pmc
->lock
);
611 if (pmc
->sfcount
[MCAST_EXCLUDE
])
612 type
= IGMPV3_MODE_IS_EXCLUDE
;
614 type
= IGMPV3_MODE_IS_INCLUDE
;
615 skb
= add_grec(skb
, pmc
, type
, 0, 0);
616 spin_unlock_bh(&pmc
->lock
);
620 return igmpv3_sendpack(skb
);
624 * remove zero-count source records from a source filter list
626 static void igmpv3_clear_zeros(struct ip_sf_list
**ppsf
)
628 struct ip_sf_list
*psf_prev
, *psf_next
, *psf
;
631 for (psf
= *ppsf
; psf
; psf
= psf_next
) {
632 psf_next
= psf
->sf_next
;
633 if (psf
->sf_crcount
== 0) {
635 psf_prev
->sf_next
= psf
->sf_next
;
637 *ppsf
= psf
->sf_next
;
644 static void kfree_pmc(struct ip_mc_list
*pmc
)
646 ip_sf_list_clear_all(pmc
->sources
);
647 ip_sf_list_clear_all(pmc
->tomb
);
651 static void igmpv3_send_cr(struct in_device
*in_dev
)
653 struct ip_mc_list
*pmc
, *pmc_prev
, *pmc_next
;
654 struct sk_buff
*skb
= NULL
;
658 spin_lock_bh(&in_dev
->mc_tomb_lock
);
662 for (pmc
= in_dev
->mc_tomb
; pmc
; pmc
= pmc_next
) {
663 pmc_next
= pmc
->next
;
664 if (pmc
->sfmode
== MCAST_INCLUDE
) {
665 type
= IGMPV3_BLOCK_OLD_SOURCES
;
666 dtype
= IGMPV3_BLOCK_OLD_SOURCES
;
667 skb
= add_grec(skb
, pmc
, type
, 1, 0);
668 skb
= add_grec(skb
, pmc
, dtype
, 1, 1);
671 if (pmc
->sfmode
== MCAST_EXCLUDE
) {
672 type
= IGMPV3_CHANGE_TO_INCLUDE
;
673 skb
= add_grec(skb
, pmc
, type
, 1, 0);
676 if (pmc
->crcount
== 0) {
677 igmpv3_clear_zeros(&pmc
->tomb
);
678 igmpv3_clear_zeros(&pmc
->sources
);
681 if (pmc
->crcount
== 0 && !pmc
->tomb
&& !pmc
->sources
) {
683 pmc_prev
->next
= pmc_next
;
685 in_dev
->mc_tomb
= pmc_next
;
686 in_dev_put(pmc
->interface
);
691 spin_unlock_bh(&in_dev
->mc_tomb_lock
);
694 for_each_pmc_rcu(in_dev
, pmc
) {
695 spin_lock_bh(&pmc
->lock
);
696 if (pmc
->sfcount
[MCAST_EXCLUDE
]) {
697 type
= IGMPV3_BLOCK_OLD_SOURCES
;
698 dtype
= IGMPV3_ALLOW_NEW_SOURCES
;
700 type
= IGMPV3_ALLOW_NEW_SOURCES
;
701 dtype
= IGMPV3_BLOCK_OLD_SOURCES
;
703 skb
= add_grec(skb
, pmc
, type
, 0, 0);
704 skb
= add_grec(skb
, pmc
, dtype
, 0, 1); /* deleted sources */
706 /* filter mode changes */
708 if (pmc
->sfmode
== MCAST_EXCLUDE
)
709 type
= IGMPV3_CHANGE_TO_EXCLUDE
;
711 type
= IGMPV3_CHANGE_TO_INCLUDE
;
712 skb
= add_grec(skb
, pmc
, type
, 0, 0);
715 spin_unlock_bh(&pmc
->lock
);
721 (void) igmpv3_sendpack(skb
);
724 static int igmp_send_report(struct in_device
*in_dev
, struct ip_mc_list
*pmc
,
731 struct net_device
*dev
= in_dev
->dev
;
732 struct net
*net
= dev_net(dev
);
733 __be32 group
= pmc
? pmc
->multiaddr
: 0;
738 if (type
== IGMPV3_HOST_MEMBERSHIP_REPORT
)
739 return igmpv3_send_report(in_dev
, pmc
);
741 if (ipv4_is_local_multicast(group
) && !net
->ipv4
.sysctl_igmp_llm_reports
)
744 if (type
== IGMP_HOST_LEAVE_MESSAGE
)
745 dst
= IGMP_ALL_ROUTER
;
749 rt
= ip_route_output_ports(net
, &fl4
, NULL
, dst
, 0,
751 IPPROTO_IGMP
, 0, dev
->ifindex
);
755 hlen
= LL_RESERVED_SPACE(dev
);
756 tlen
= dev
->needed_tailroom
;
757 skb
= alloc_skb(IGMP_SIZE
+ hlen
+ tlen
, GFP_ATOMIC
);
762 skb
->priority
= TC_PRIO_CONTROL
;
764 skb_dst_set(skb
, &rt
->dst
);
766 skb_reserve(skb
, hlen
);
768 skb_reset_network_header(skb
);
770 skb_put(skb
, sizeof(struct iphdr
) + 4);
773 iph
->ihl
= (sizeof(struct iphdr
)+4)>>2;
775 iph
->frag_off
= htons(IP_DF
);
778 iph
->saddr
= fl4
.saddr
;
779 iph
->protocol
= IPPROTO_IGMP
;
780 ip_select_ident(net
, skb
, NULL
);
781 ((u8
*)&iph
[1])[0] = IPOPT_RA
;
782 ((u8
*)&iph
[1])[1] = 4;
783 ((u8
*)&iph
[1])[2] = 0;
784 ((u8
*)&iph
[1])[3] = 0;
786 ih
= skb_put(skb
, sizeof(struct igmphdr
));
791 ih
->csum
= ip_compute_csum((void *)ih
, sizeof(struct igmphdr
));
793 return ip_local_out(net
, skb
->sk
, skb
);
796 static void igmp_gq_timer_expire(struct timer_list
*t
)
798 struct in_device
*in_dev
= from_timer(in_dev
, t
, mr_gq_timer
);
800 in_dev
->mr_gq_running
= 0;
801 igmpv3_send_report(in_dev
, NULL
);
805 static void igmp_ifc_timer_expire(struct timer_list
*t
)
807 struct in_device
*in_dev
= from_timer(in_dev
, t
, mr_ifc_timer
);
809 igmpv3_send_cr(in_dev
);
810 if (in_dev
->mr_ifc_count
) {
811 in_dev
->mr_ifc_count
--;
812 igmp_ifc_start_timer(in_dev
,
813 unsolicited_report_interval(in_dev
));
818 static void igmp_ifc_event(struct in_device
*in_dev
)
820 struct net
*net
= dev_net(in_dev
->dev
);
821 if (IGMP_V1_SEEN(in_dev
) || IGMP_V2_SEEN(in_dev
))
823 in_dev
->mr_ifc_count
= in_dev
->mr_qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
824 igmp_ifc_start_timer(in_dev
, 1);
828 static void igmp_timer_expire(struct timer_list
*t
)
830 struct ip_mc_list
*im
= from_timer(im
, t
, timer
);
831 struct in_device
*in_dev
= im
->interface
;
833 spin_lock(&im
->lock
);
836 if (im
->unsolicit_count
&& --im
->unsolicit_count
)
837 igmp_start_timer(im
, unsolicited_report_interval(in_dev
));
840 spin_unlock(&im
->lock
);
842 if (IGMP_V1_SEEN(in_dev
))
843 igmp_send_report(in_dev
, im
, IGMP_HOST_MEMBERSHIP_REPORT
);
844 else if (IGMP_V2_SEEN(in_dev
))
845 igmp_send_report(in_dev
, im
, IGMPV2_HOST_MEMBERSHIP_REPORT
);
847 igmp_send_report(in_dev
, im
, IGMPV3_HOST_MEMBERSHIP_REPORT
);
852 /* mark EXCLUDE-mode sources */
853 static int igmp_xmarksources(struct ip_mc_list
*pmc
, int nsrcs
, __be32
*srcs
)
855 struct ip_sf_list
*psf
;
859 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
) {
862 for (i
= 0; i
< nsrcs
; i
++) {
863 /* skip inactive filters */
864 if (psf
->sf_count
[MCAST_INCLUDE
] ||
865 pmc
->sfcount
[MCAST_EXCLUDE
] !=
866 psf
->sf_count
[MCAST_EXCLUDE
])
868 if (srcs
[i
] == psf
->sf_inaddr
) {
875 if (scount
== nsrcs
) /* all sources excluded */
880 static int igmp_marksources(struct ip_mc_list
*pmc
, int nsrcs
, __be32
*srcs
)
882 struct ip_sf_list
*psf
;
885 if (pmc
->sfmode
== MCAST_EXCLUDE
)
886 return igmp_xmarksources(pmc
, nsrcs
, srcs
);
888 /* mark INCLUDE-mode sources */
890 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
) {
893 for (i
= 0; i
< nsrcs
; i
++)
894 if (srcs
[i
] == psf
->sf_inaddr
) {
908 /* return true if packet was dropped */
909 static bool igmp_heard_report(struct in_device
*in_dev
, __be32 group
)
911 struct ip_mc_list
*im
;
912 struct net
*net
= dev_net(in_dev
->dev
);
914 /* Timers are only set for non-local groups */
916 if (group
== IGMP_ALL_HOSTS
)
918 if (ipv4_is_local_multicast(group
) && !net
->ipv4
.sysctl_igmp_llm_reports
)
922 for_each_pmc_rcu(in_dev
, im
) {
923 if (im
->multiaddr
== group
) {
932 /* return true if packet was dropped */
933 static bool igmp_heard_query(struct in_device
*in_dev
, struct sk_buff
*skb
,
936 struct igmphdr
*ih
= igmp_hdr(skb
);
937 struct igmpv3_query
*ih3
= igmpv3_query_hdr(skb
);
938 struct ip_mc_list
*im
;
939 __be32 group
= ih
->group
;
942 struct net
*net
= dev_net(in_dev
->dev
);
947 /* Alas, old v1 router presents here. */
949 max_delay
= IGMP_QUERY_RESPONSE_INTERVAL
;
950 in_dev
->mr_v1_seen
= jiffies
+
951 (in_dev
->mr_qrv
* in_dev
->mr_qi
) +
955 /* v2 router present */
956 max_delay
= ih
->code
*(HZ
/IGMP_TIMER_SCALE
);
957 in_dev
->mr_v2_seen
= jiffies
+
958 (in_dev
->mr_qrv
* in_dev
->mr_qi
) +
961 /* cancel the interface change timer */
962 in_dev
->mr_ifc_count
= 0;
963 if (del_timer(&in_dev
->mr_ifc_timer
))
964 __in_dev_put(in_dev
);
965 /* clear deleted report items */
966 igmpv3_clear_delrec(in_dev
);
967 } else if (len
< 12) {
968 return true; /* ignore bogus packet; freed by caller */
969 } else if (IGMP_V1_SEEN(in_dev
)) {
970 /* This is a v3 query with v1 queriers present */
971 max_delay
= IGMP_QUERY_RESPONSE_INTERVAL
;
973 } else if (IGMP_V2_SEEN(in_dev
)) {
974 /* this is a v3 query with v2 queriers present;
975 * Interpretation of the max_delay code is problematic here.
976 * A real v2 host would use ih_code directly, while v3 has a
977 * different encoding. We use the v3 encoding as more likely
978 * to be intended in a v3 query.
980 max_delay
= IGMPV3_MRC(ih3
->code
)*(HZ
/IGMP_TIMER_SCALE
);
982 max_delay
= 1; /* can't mod w/ 0 */
984 if (!pskb_may_pull(skb
, sizeof(struct igmpv3_query
)))
987 ih3
= igmpv3_query_hdr(skb
);
989 if (!pskb_may_pull(skb
, sizeof(struct igmpv3_query
)
990 + ntohs(ih3
->nsrcs
)*sizeof(__be32
)))
992 ih3
= igmpv3_query_hdr(skb
);
995 max_delay
= IGMPV3_MRC(ih3
->code
)*(HZ
/IGMP_TIMER_SCALE
);
997 max_delay
= 1; /* can't mod w/ 0 */
998 in_dev
->mr_maxdelay
= max_delay
;
1000 /* RFC3376, 4.1.6. QRV and 4.1.7. QQIC, when the most recently
1001 * received value was zero, use the default or statically
1004 in_dev
->mr_qrv
= ih3
->qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
1005 in_dev
->mr_qi
= IGMPV3_QQIC(ih3
->qqic
)*HZ
?: IGMP_QUERY_INTERVAL
;
1007 /* RFC3376, 8.3. Query Response Interval:
1008 * The number of seconds represented by the [Query Response
1009 * Interval] must be less than the [Query Interval].
1011 if (in_dev
->mr_qri
>= in_dev
->mr_qi
)
1012 in_dev
->mr_qri
= (in_dev
->mr_qi
/HZ
- 1)*HZ
;
1014 if (!group
) { /* general query */
1016 return true; /* no sources allowed */
1017 igmp_gq_start_timer(in_dev
);
1020 /* mark sources to include, if group & source-specific */
1021 mark
= ih3
->nsrcs
!= 0;
1025 * - Start the timers in all of our membership records
1026 * that the query applies to for the interface on
1027 * which the query arrived excl. those that belong
1028 * to a "local" group (224.0.0.X)
1029 * - For timers already running check if they need to
1031 * - Use the igmp->igmp_code field as the maximum
1035 for_each_pmc_rcu(in_dev
, im
) {
1038 if (group
&& group
!= im
->multiaddr
)
1040 if (im
->multiaddr
== IGMP_ALL_HOSTS
)
1042 if (ipv4_is_local_multicast(im
->multiaddr
) &&
1043 !net
->ipv4
.sysctl_igmp_llm_reports
)
1045 spin_lock_bh(&im
->lock
);
1047 im
->gsquery
= im
->gsquery
&& mark
;
1050 changed
= !im
->gsquery
||
1051 igmp_marksources(im
, ntohs(ih3
->nsrcs
), ih3
->srcs
);
1052 spin_unlock_bh(&im
->lock
);
1054 igmp_mod_timer(im
, max_delay
);
1060 /* called in rcu_read_lock() section */
1061 int igmp_rcv(struct sk_buff
*skb
)
1063 /* This basically follows the spec line by line -- see RFC1112 */
1065 struct net_device
*dev
= skb
->dev
;
1066 struct in_device
*in_dev
;
1068 bool dropped
= true;
1070 if (netif_is_l3_master(dev
)) {
1071 dev
= dev_get_by_index_rcu(dev_net(dev
), IPCB(skb
)->iif
);
1076 in_dev
= __in_dev_get_rcu(dev
);
1080 if (!pskb_may_pull(skb
, sizeof(struct igmphdr
)))
1083 if (skb_checksum_simple_validate(skb
))
1088 case IGMP_HOST_MEMBERSHIP_QUERY
:
1089 dropped
= igmp_heard_query(in_dev
, skb
, len
);
1091 case IGMP_HOST_MEMBERSHIP_REPORT
:
1092 case IGMPV2_HOST_MEMBERSHIP_REPORT
:
1093 /* Is it our report looped back? */
1094 if (rt_is_output_route(skb_rtable(skb
)))
1096 /* don't rely on MC router hearing unicast reports */
1097 if (skb
->pkt_type
== PACKET_MULTICAST
||
1098 skb
->pkt_type
== PACKET_BROADCAST
)
1099 dropped
= igmp_heard_report(in_dev
, ih
->group
);
1102 #ifdef CONFIG_IP_PIMSM_V1
1103 return pim_rcv_v1(skb
);
1105 case IGMPV3_HOST_MEMBERSHIP_REPORT
:
1108 case IGMP_HOST_LEAVE_MESSAGE
:
1110 case IGMP_MTRACE_RESP
:
1128 * Add a filter to a device
1131 static void ip_mc_filter_add(struct in_device
*in_dev
, __be32 addr
)
1133 char buf
[MAX_ADDR_LEN
];
1134 struct net_device
*dev
= in_dev
->dev
;
1136 /* Checking for IFF_MULTICAST here is WRONG-WRONG-WRONG.
1137 We will get multicast token leakage, when IFF_MULTICAST
1138 is changed. This check should be done in ndo_set_rx_mode
1139 routine. Something sort of:
1140 if (dev->mc_list && dev->flags&IFF_MULTICAST) { do it; }
1143 if (arp_mc_map(addr
, buf
, dev
, 0) == 0)
1144 dev_mc_add(dev
, buf
);
1148 * Remove a filter from a device
1151 static void ip_mc_filter_del(struct in_device
*in_dev
, __be32 addr
)
1153 char buf
[MAX_ADDR_LEN
];
1154 struct net_device
*dev
= in_dev
->dev
;
1156 if (arp_mc_map(addr
, buf
, dev
, 0) == 0)
1157 dev_mc_del(dev
, buf
);
1160 #ifdef CONFIG_IP_MULTICAST
1162 * deleted ip_mc_list manipulation
1164 static void igmpv3_add_delrec(struct in_device
*in_dev
, struct ip_mc_list
*im
,
1167 struct ip_mc_list
*pmc
;
1168 struct net
*net
= dev_net(in_dev
->dev
);
1170 /* this is an "ip_mc_list" for convenience; only the fields below
1171 * are actually used. In particular, the refcnt and users are not
1172 * used for management of the delete list. Using the same structure
1173 * for deleted items allows change reports to use common code with
1174 * non-deleted or query-response MCA's.
1176 pmc
= kzalloc(sizeof(*pmc
), gfp
);
1179 spin_lock_init(&pmc
->lock
);
1180 spin_lock_bh(&im
->lock
);
1181 pmc
->interface
= im
->interface
;
1182 in_dev_hold(in_dev
);
1183 pmc
->multiaddr
= im
->multiaddr
;
1184 pmc
->crcount
= in_dev
->mr_qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
1185 pmc
->sfmode
= im
->sfmode
;
1186 if (pmc
->sfmode
== MCAST_INCLUDE
) {
1187 struct ip_sf_list
*psf
;
1189 pmc
->tomb
= im
->tomb
;
1190 pmc
->sources
= im
->sources
;
1191 im
->tomb
= im
->sources
= NULL
;
1192 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
)
1193 psf
->sf_crcount
= pmc
->crcount
;
1195 spin_unlock_bh(&im
->lock
);
1197 spin_lock_bh(&in_dev
->mc_tomb_lock
);
1198 pmc
->next
= in_dev
->mc_tomb
;
1199 in_dev
->mc_tomb
= pmc
;
1200 spin_unlock_bh(&in_dev
->mc_tomb_lock
);
1204 * restore ip_mc_list deleted records
1206 static void igmpv3_del_delrec(struct in_device
*in_dev
, struct ip_mc_list
*im
)
1208 struct ip_mc_list
*pmc
, *pmc_prev
;
1209 struct ip_sf_list
*psf
;
1210 struct net
*net
= dev_net(in_dev
->dev
);
1211 __be32 multiaddr
= im
->multiaddr
;
1213 spin_lock_bh(&in_dev
->mc_tomb_lock
);
1215 for (pmc
= in_dev
->mc_tomb
; pmc
; pmc
= pmc
->next
) {
1216 if (pmc
->multiaddr
== multiaddr
)
1222 pmc_prev
->next
= pmc
->next
;
1224 in_dev
->mc_tomb
= pmc
->next
;
1226 spin_unlock_bh(&in_dev
->mc_tomb_lock
);
1228 spin_lock_bh(&im
->lock
);
1230 im
->interface
= pmc
->interface
;
1231 if (im
->sfmode
== MCAST_INCLUDE
) {
1232 swap(im
->tomb
, pmc
->tomb
);
1233 swap(im
->sources
, pmc
->sources
);
1234 for (psf
= im
->sources
; psf
; psf
= psf
->sf_next
)
1235 psf
->sf_crcount
= in_dev
->mr_qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
1237 im
->crcount
= in_dev
->mr_qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
1239 in_dev_put(pmc
->interface
);
1242 spin_unlock_bh(&im
->lock
);
1246 * flush ip_mc_list deleted records
1248 static void igmpv3_clear_delrec(struct in_device
*in_dev
)
1250 struct ip_mc_list
*pmc
, *nextpmc
;
1252 spin_lock_bh(&in_dev
->mc_tomb_lock
);
1253 pmc
= in_dev
->mc_tomb
;
1254 in_dev
->mc_tomb
= NULL
;
1255 spin_unlock_bh(&in_dev
->mc_tomb_lock
);
1257 for (; pmc
; pmc
= nextpmc
) {
1258 nextpmc
= pmc
->next
;
1259 ip_mc_clear_src(pmc
);
1260 in_dev_put(pmc
->interface
);
1263 /* clear dead sources, too */
1265 for_each_pmc_rcu(in_dev
, pmc
) {
1266 struct ip_sf_list
*psf
;
1268 spin_lock_bh(&pmc
->lock
);
1271 spin_unlock_bh(&pmc
->lock
);
1272 ip_sf_list_clear_all(psf
);
1278 static void __igmp_group_dropped(struct ip_mc_list
*im
, gfp_t gfp
)
1280 struct in_device
*in_dev
= im
->interface
;
1281 #ifdef CONFIG_IP_MULTICAST
1282 struct net
*net
= dev_net(in_dev
->dev
);
1288 ip_mc_filter_del(in_dev
, im
->multiaddr
);
1291 #ifdef CONFIG_IP_MULTICAST
1292 if (im
->multiaddr
== IGMP_ALL_HOSTS
)
1294 if (ipv4_is_local_multicast(im
->multiaddr
) && !net
->ipv4
.sysctl_igmp_llm_reports
)
1297 reporter
= im
->reporter
;
1298 igmp_stop_timer(im
);
1300 if (!in_dev
->dead
) {
1301 if (IGMP_V1_SEEN(in_dev
))
1303 if (IGMP_V2_SEEN(in_dev
)) {
1305 igmp_send_report(in_dev
, im
, IGMP_HOST_LEAVE_MESSAGE
);
1309 igmpv3_add_delrec(in_dev
, im
, gfp
);
1311 igmp_ifc_event(in_dev
);
1316 static void igmp_group_dropped(struct ip_mc_list
*im
)
1318 __igmp_group_dropped(im
, GFP_KERNEL
);
1321 static void igmp_group_added(struct ip_mc_list
*im
)
1323 struct in_device
*in_dev
= im
->interface
;
1324 #ifdef CONFIG_IP_MULTICAST
1325 struct net
*net
= dev_net(in_dev
->dev
);
1328 if (im
->loaded
== 0) {
1330 ip_mc_filter_add(in_dev
, im
->multiaddr
);
1333 #ifdef CONFIG_IP_MULTICAST
1334 if (im
->multiaddr
== IGMP_ALL_HOSTS
)
1336 if (ipv4_is_local_multicast(im
->multiaddr
) && !net
->ipv4
.sysctl_igmp_llm_reports
)
1342 im
->unsolicit_count
= net
->ipv4
.sysctl_igmp_qrv
;
1343 if (IGMP_V1_SEEN(in_dev
) || IGMP_V2_SEEN(in_dev
)) {
1344 spin_lock_bh(&im
->lock
);
1345 igmp_start_timer(im
, IGMP_INITIAL_REPORT_DELAY
);
1346 spin_unlock_bh(&im
->lock
);
1351 /* Based on RFC3376 5.1, for newly added INCLUDE SSM, we should
1352 * not send filter-mode change record as the mode should be from
1355 if (im
->sfmode
== MCAST_EXCLUDE
)
1356 im
->crcount
= in_dev
->mr_qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
1358 igmp_ifc_event(in_dev
);
1364 * Multicast list managers
1367 static u32
ip_mc_hash(const struct ip_mc_list
*im
)
1369 return hash_32((__force u32
)im
->multiaddr
, MC_HASH_SZ_LOG
);
1372 static void ip_mc_hash_add(struct in_device
*in_dev
,
1373 struct ip_mc_list
*im
)
1375 struct ip_mc_list __rcu
**mc_hash
;
1378 mc_hash
= rtnl_dereference(in_dev
->mc_hash
);
1380 hash
= ip_mc_hash(im
);
1381 im
->next_hash
= mc_hash
[hash
];
1382 rcu_assign_pointer(mc_hash
[hash
], im
);
1386 /* do not use a hash table for small number of items */
1387 if (in_dev
->mc_count
< 4)
1390 mc_hash
= kzalloc(sizeof(struct ip_mc_list
*) << MC_HASH_SZ_LOG
,
1395 for_each_pmc_rtnl(in_dev
, im
) {
1396 hash
= ip_mc_hash(im
);
1397 im
->next_hash
= mc_hash
[hash
];
1398 RCU_INIT_POINTER(mc_hash
[hash
], im
);
1401 rcu_assign_pointer(in_dev
->mc_hash
, mc_hash
);
1404 static void ip_mc_hash_remove(struct in_device
*in_dev
,
1405 struct ip_mc_list
*im
)
1407 struct ip_mc_list __rcu
**mc_hash
= rtnl_dereference(in_dev
->mc_hash
);
1408 struct ip_mc_list
*aux
;
1412 mc_hash
+= ip_mc_hash(im
);
1413 while ((aux
= rtnl_dereference(*mc_hash
)) != im
)
1414 mc_hash
= &aux
->next_hash
;
1415 *mc_hash
= im
->next_hash
;
1420 * A socket has joined a multicast group on device dev.
1422 static void ____ip_mc_inc_group(struct in_device
*in_dev
, __be32 addr
,
1423 unsigned int mode
, gfp_t gfp
)
1425 struct ip_mc_list
*im
;
1429 for_each_pmc_rtnl(in_dev
, im
) {
1430 if (im
->multiaddr
== addr
) {
1432 ip_mc_add_src(in_dev
, &addr
, mode
, 0, NULL
, 0);
1437 im
= kzalloc(sizeof(*im
), gfp
);
1442 im
->interface
= in_dev
;
1443 in_dev_hold(in_dev
);
1444 im
->multiaddr
= addr
;
1445 /* initial mode is (EX, empty) */
1447 im
->sfcount
[mode
] = 1;
1448 refcount_set(&im
->refcnt
, 1);
1449 spin_lock_init(&im
->lock
);
1450 #ifdef CONFIG_IP_MULTICAST
1451 timer_setup(&im
->timer
, igmp_timer_expire
, 0);
1454 im
->next_rcu
= in_dev
->mc_list
;
1456 rcu_assign_pointer(in_dev
->mc_list
, im
);
1458 ip_mc_hash_add(in_dev
, im
);
1460 #ifdef CONFIG_IP_MULTICAST
1461 igmpv3_del_delrec(in_dev
, im
);
1463 igmp_group_added(im
);
1465 ip_rt_multicast_event(in_dev
);
1470 void __ip_mc_inc_group(struct in_device
*in_dev
, __be32 addr
, gfp_t gfp
)
1472 ____ip_mc_inc_group(in_dev
, addr
, MCAST_EXCLUDE
, gfp
);
1474 EXPORT_SYMBOL(__ip_mc_inc_group
);
1476 void ip_mc_inc_group(struct in_device
*in_dev
, __be32 addr
)
1478 __ip_mc_inc_group(in_dev
, addr
, GFP_KERNEL
);
1480 EXPORT_SYMBOL(ip_mc_inc_group
);
1482 static int ip_mc_check_iphdr(struct sk_buff
*skb
)
1484 const struct iphdr
*iph
;
1486 unsigned int offset
= skb_network_offset(skb
) + sizeof(*iph
);
1488 if (!pskb_may_pull(skb
, offset
))
1493 if (iph
->version
!= 4 || ip_hdrlen(skb
) < sizeof(*iph
))
1496 offset
+= ip_hdrlen(skb
) - sizeof(*iph
);
1498 if (!pskb_may_pull(skb
, offset
))
1503 if (unlikely(ip_fast_csum((u8
*)iph
, iph
->ihl
)))
1506 len
= skb_network_offset(skb
) + ntohs(iph
->tot_len
);
1507 if (skb
->len
< len
|| len
< offset
)
1510 skb_set_transport_header(skb
, offset
);
1515 static int ip_mc_check_igmp_reportv3(struct sk_buff
*skb
)
1517 unsigned int len
= skb_transport_offset(skb
);
1519 len
+= sizeof(struct igmpv3_report
);
1521 return ip_mc_may_pull(skb
, len
) ? 0 : -EINVAL
;
1524 static int ip_mc_check_igmp_query(struct sk_buff
*skb
)
1526 unsigned int transport_len
= ip_transport_len(skb
);
1530 if (transport_len
!= sizeof(struct igmphdr
)) {
1532 if (transport_len
< sizeof(struct igmpv3_query
))
1535 len
= skb_transport_offset(skb
) + sizeof(struct igmpv3_query
);
1536 if (!ip_mc_may_pull(skb
, len
))
1540 /* RFC2236+RFC3376 (IGMPv2+IGMPv3) require the multicast link layer
1541 * all-systems destination addresses (224.0.0.1) for general queries
1543 if (!igmp_hdr(skb
)->group
&&
1544 ip_hdr(skb
)->daddr
!= htonl(INADDR_ALLHOSTS_GROUP
))
1550 static int ip_mc_check_igmp_msg(struct sk_buff
*skb
)
1552 switch (igmp_hdr(skb
)->type
) {
1553 case IGMP_HOST_LEAVE_MESSAGE
:
1554 case IGMP_HOST_MEMBERSHIP_REPORT
:
1555 case IGMPV2_HOST_MEMBERSHIP_REPORT
:
1557 case IGMPV3_HOST_MEMBERSHIP_REPORT
:
1558 return ip_mc_check_igmp_reportv3(skb
);
1559 case IGMP_HOST_MEMBERSHIP_QUERY
:
1560 return ip_mc_check_igmp_query(skb
);
1566 static __sum16
ip_mc_validate_checksum(struct sk_buff
*skb
)
1568 return skb_checksum_simple_validate(skb
);
1571 static int ip_mc_check_igmp_csum(struct sk_buff
*skb
)
1573 unsigned int len
= skb_transport_offset(skb
) + sizeof(struct igmphdr
);
1574 unsigned int transport_len
= ip_transport_len(skb
);
1575 struct sk_buff
*skb_chk
;
1577 if (!ip_mc_may_pull(skb
, len
))
1580 skb_chk
= skb_checksum_trimmed(skb
, transport_len
,
1581 ip_mc_validate_checksum
);
1592 * ip_mc_check_igmp - checks whether this is a sane IGMP packet
1593 * @skb: the skb to validate
1595 * Checks whether an IPv4 packet is a valid IGMP packet. If so sets
1596 * skb transport header accordingly and returns zero.
1598 * -EINVAL: A broken packet was detected, i.e. it violates some internet
1600 * -ENOMSG: IP header validation succeeded but it is not an IGMP packet.
1601 * -ENOMEM: A memory allocation failure happened.
1603 * Caller needs to set the skb network header and free any returned skb if it
1604 * differs from the provided skb.
1606 int ip_mc_check_igmp(struct sk_buff
*skb
)
1608 int ret
= ip_mc_check_iphdr(skb
);
1613 if (ip_hdr(skb
)->protocol
!= IPPROTO_IGMP
)
1616 ret
= ip_mc_check_igmp_csum(skb
);
1620 return ip_mc_check_igmp_msg(skb
);
1622 EXPORT_SYMBOL(ip_mc_check_igmp
);
1625 * Resend IGMP JOIN report; used by netdev notifier.
1627 static void ip_mc_rejoin_groups(struct in_device
*in_dev
)
1629 #ifdef CONFIG_IP_MULTICAST
1630 struct ip_mc_list
*im
;
1632 struct net
*net
= dev_net(in_dev
->dev
);
1636 for_each_pmc_rtnl(in_dev
, im
) {
1637 if (im
->multiaddr
== IGMP_ALL_HOSTS
)
1639 if (ipv4_is_local_multicast(im
->multiaddr
) &&
1640 !net
->ipv4
.sysctl_igmp_llm_reports
)
1643 /* a failover is happening and switches
1644 * must be notified immediately
1646 if (IGMP_V1_SEEN(in_dev
))
1647 type
= IGMP_HOST_MEMBERSHIP_REPORT
;
1648 else if (IGMP_V2_SEEN(in_dev
))
1649 type
= IGMPV2_HOST_MEMBERSHIP_REPORT
;
1651 type
= IGMPV3_HOST_MEMBERSHIP_REPORT
;
1652 igmp_send_report(in_dev
, im
, type
);
1658 * A socket has left a multicast group on device dev
1661 void __ip_mc_dec_group(struct in_device
*in_dev
, __be32 addr
, gfp_t gfp
)
1663 struct ip_mc_list
*i
;
1664 struct ip_mc_list __rcu
**ip
;
1668 for (ip
= &in_dev
->mc_list
;
1669 (i
= rtnl_dereference(*ip
)) != NULL
;
1670 ip
= &i
->next_rcu
) {
1671 if (i
->multiaddr
== addr
) {
1672 if (--i
->users
== 0) {
1673 ip_mc_hash_remove(in_dev
, i
);
1676 __igmp_group_dropped(i
, gfp
);
1680 ip_rt_multicast_event(in_dev
);
1689 EXPORT_SYMBOL(__ip_mc_dec_group
);
1691 /* Device changing type */
1693 void ip_mc_unmap(struct in_device
*in_dev
)
1695 struct ip_mc_list
*pmc
;
1699 for_each_pmc_rtnl(in_dev
, pmc
)
1700 igmp_group_dropped(pmc
);
1703 void ip_mc_remap(struct in_device
*in_dev
)
1705 struct ip_mc_list
*pmc
;
1709 for_each_pmc_rtnl(in_dev
, pmc
) {
1710 #ifdef CONFIG_IP_MULTICAST
1711 igmpv3_del_delrec(in_dev
, pmc
);
1713 igmp_group_added(pmc
);
1717 /* Device going down */
1719 void ip_mc_down(struct in_device
*in_dev
)
1721 struct ip_mc_list
*pmc
;
1725 for_each_pmc_rtnl(in_dev
, pmc
)
1726 igmp_group_dropped(pmc
);
1728 #ifdef CONFIG_IP_MULTICAST
1729 in_dev
->mr_ifc_count
= 0;
1730 if (del_timer(&in_dev
->mr_ifc_timer
))
1731 __in_dev_put(in_dev
);
1732 in_dev
->mr_gq_running
= 0;
1733 if (del_timer(&in_dev
->mr_gq_timer
))
1734 __in_dev_put(in_dev
);
1737 ip_mc_dec_group(in_dev
, IGMP_ALL_HOSTS
);
1740 #ifdef CONFIG_IP_MULTICAST
1741 static void ip_mc_reset(struct in_device
*in_dev
)
1743 struct net
*net
= dev_net(in_dev
->dev
);
1745 in_dev
->mr_qi
= IGMP_QUERY_INTERVAL
;
1746 in_dev
->mr_qri
= IGMP_QUERY_RESPONSE_INTERVAL
;
1747 in_dev
->mr_qrv
= net
->ipv4
.sysctl_igmp_qrv
;
1750 static void ip_mc_reset(struct in_device
*in_dev
)
1755 void ip_mc_init_dev(struct in_device
*in_dev
)
1759 #ifdef CONFIG_IP_MULTICAST
1760 timer_setup(&in_dev
->mr_gq_timer
, igmp_gq_timer_expire
, 0);
1761 timer_setup(&in_dev
->mr_ifc_timer
, igmp_ifc_timer_expire
, 0);
1763 ip_mc_reset(in_dev
);
1765 spin_lock_init(&in_dev
->mc_tomb_lock
);
1768 /* Device going up */
1770 void ip_mc_up(struct in_device
*in_dev
)
1772 struct ip_mc_list
*pmc
;
1776 ip_mc_reset(in_dev
);
1777 ip_mc_inc_group(in_dev
, IGMP_ALL_HOSTS
);
1779 for_each_pmc_rtnl(in_dev
, pmc
) {
1780 #ifdef CONFIG_IP_MULTICAST
1781 igmpv3_del_delrec(in_dev
, pmc
);
1783 igmp_group_added(pmc
);
1788 * Device is about to be destroyed: clean up.
1791 void ip_mc_destroy_dev(struct in_device
*in_dev
)
1793 struct ip_mc_list
*i
;
1797 /* Deactivate timers */
1799 #ifdef CONFIG_IP_MULTICAST
1800 igmpv3_clear_delrec(in_dev
);
1803 while ((i
= rtnl_dereference(in_dev
->mc_list
)) != NULL
) {
1804 in_dev
->mc_list
= i
->next_rcu
;
1810 /* RTNL is locked */
1811 static struct in_device
*ip_mc_find_dev(struct net
*net
, struct ip_mreqn
*imr
)
1813 struct net_device
*dev
= NULL
;
1814 struct in_device
*idev
= NULL
;
1816 if (imr
->imr_ifindex
) {
1817 idev
= inetdev_by_index(net
, imr
->imr_ifindex
);
1820 if (imr
->imr_address
.s_addr
) {
1821 dev
= __ip_dev_find(net
, imr
->imr_address
.s_addr
, false);
1827 struct rtable
*rt
= ip_route_output(net
,
1828 imr
->imr_multiaddr
.s_addr
,
1836 imr
->imr_ifindex
= dev
->ifindex
;
1837 idev
= __in_dev_get_rtnl(dev
);
1843 * Join a socket to a group
1846 static int ip_mc_del1_src(struct ip_mc_list
*pmc
, int sfmode
,
1849 struct ip_sf_list
*psf
, *psf_prev
;
1853 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
) {
1854 if (psf
->sf_inaddr
== *psfsrc
)
1858 if (!psf
|| psf
->sf_count
[sfmode
] == 0) {
1859 /* source filter not found, or count wrong => bug */
1862 psf
->sf_count
[sfmode
]--;
1863 if (psf
->sf_count
[sfmode
] == 0) {
1864 ip_rt_multicast_event(pmc
->interface
);
1866 if (!psf
->sf_count
[MCAST_INCLUDE
] && !psf
->sf_count
[MCAST_EXCLUDE
]) {
1867 #ifdef CONFIG_IP_MULTICAST
1868 struct in_device
*in_dev
= pmc
->interface
;
1869 struct net
*net
= dev_net(in_dev
->dev
);
1872 /* no more filters for this source */
1874 psf_prev
->sf_next
= psf
->sf_next
;
1876 pmc
->sources
= psf
->sf_next
;
1877 #ifdef CONFIG_IP_MULTICAST
1878 if (psf
->sf_oldin
&&
1879 !IGMP_V1_SEEN(in_dev
) && !IGMP_V2_SEEN(in_dev
)) {
1880 psf
->sf_crcount
= in_dev
->mr_qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
1881 psf
->sf_next
= pmc
->tomb
;
1891 #ifndef CONFIG_IP_MULTICAST
1892 #define igmp_ifc_event(x) do { } while (0)
1895 static int ip_mc_del_src(struct in_device
*in_dev
, __be32
*pmca
, int sfmode
,
1896 int sfcount
, __be32
*psfsrc
, int delta
)
1898 struct ip_mc_list
*pmc
;
1905 for_each_pmc_rcu(in_dev
, pmc
) {
1906 if (*pmca
== pmc
->multiaddr
)
1910 /* MCA not found?? bug */
1914 spin_lock_bh(&pmc
->lock
);
1916 #ifdef CONFIG_IP_MULTICAST
1921 if (!pmc
->sfcount
[sfmode
])
1923 pmc
->sfcount
[sfmode
]--;
1926 for (i
= 0; i
< sfcount
; i
++) {
1927 int rv
= ip_mc_del1_src(pmc
, sfmode
, &psfsrc
[i
]);
1929 changerec
|= rv
> 0;
1933 if (pmc
->sfmode
== MCAST_EXCLUDE
&&
1934 pmc
->sfcount
[MCAST_EXCLUDE
] == 0 &&
1935 pmc
->sfcount
[MCAST_INCLUDE
]) {
1936 #ifdef CONFIG_IP_MULTICAST
1937 struct ip_sf_list
*psf
;
1938 struct net
*net
= dev_net(in_dev
->dev
);
1941 /* filter mode change */
1942 pmc
->sfmode
= MCAST_INCLUDE
;
1943 #ifdef CONFIG_IP_MULTICAST
1944 pmc
->crcount
= in_dev
->mr_qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
1945 in_dev
->mr_ifc_count
= pmc
->crcount
;
1946 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
)
1947 psf
->sf_crcount
= 0;
1948 igmp_ifc_event(pmc
->interface
);
1949 } else if (sf_setstate(pmc
) || changerec
) {
1950 igmp_ifc_event(pmc
->interface
);
1954 spin_unlock_bh(&pmc
->lock
);
1959 * Add multicast single-source filter to the interface list
1961 static int ip_mc_add1_src(struct ip_mc_list
*pmc
, int sfmode
,
1964 struct ip_sf_list
*psf
, *psf_prev
;
1967 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
) {
1968 if (psf
->sf_inaddr
== *psfsrc
)
1973 psf
= kzalloc(sizeof(*psf
), GFP_ATOMIC
);
1976 psf
->sf_inaddr
= *psfsrc
;
1978 psf_prev
->sf_next
= psf
;
1982 psf
->sf_count
[sfmode
]++;
1983 if (psf
->sf_count
[sfmode
] == 1) {
1984 ip_rt_multicast_event(pmc
->interface
);
1989 #ifdef CONFIG_IP_MULTICAST
1990 static void sf_markstate(struct ip_mc_list
*pmc
)
1992 struct ip_sf_list
*psf
;
1993 int mca_xcount
= pmc
->sfcount
[MCAST_EXCLUDE
];
1995 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
)
1996 if (pmc
->sfcount
[MCAST_EXCLUDE
]) {
1997 psf
->sf_oldin
= mca_xcount
==
1998 psf
->sf_count
[MCAST_EXCLUDE
] &&
1999 !psf
->sf_count
[MCAST_INCLUDE
];
2001 psf
->sf_oldin
= psf
->sf_count
[MCAST_INCLUDE
] != 0;
2004 static int sf_setstate(struct ip_mc_list
*pmc
)
2006 struct ip_sf_list
*psf
, *dpsf
;
2007 int mca_xcount
= pmc
->sfcount
[MCAST_EXCLUDE
];
2008 int qrv
= pmc
->interface
->mr_qrv
;
2012 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
) {
2013 if (pmc
->sfcount
[MCAST_EXCLUDE
]) {
2014 new_in
= mca_xcount
== psf
->sf_count
[MCAST_EXCLUDE
] &&
2015 !psf
->sf_count
[MCAST_INCLUDE
];
2017 new_in
= psf
->sf_count
[MCAST_INCLUDE
] != 0;
2019 if (!psf
->sf_oldin
) {
2020 struct ip_sf_list
*prev
= NULL
;
2022 for (dpsf
= pmc
->tomb
; dpsf
; dpsf
= dpsf
->sf_next
) {
2023 if (dpsf
->sf_inaddr
== psf
->sf_inaddr
)
2029 prev
->sf_next
= dpsf
->sf_next
;
2031 pmc
->tomb
= dpsf
->sf_next
;
2034 psf
->sf_crcount
= qrv
;
2037 } else if (psf
->sf_oldin
) {
2039 psf
->sf_crcount
= 0;
2041 * add or update "delete" records if an active filter
2044 for (dpsf
= pmc
->tomb
; dpsf
; dpsf
= dpsf
->sf_next
)
2045 if (dpsf
->sf_inaddr
== psf
->sf_inaddr
)
2048 dpsf
= kmalloc(sizeof(*dpsf
), GFP_ATOMIC
);
2052 /* pmc->lock held by callers */
2053 dpsf
->sf_next
= pmc
->tomb
;
2056 dpsf
->sf_crcount
= qrv
;
2065 * Add multicast source filter list to the interface list
2067 static int ip_mc_add_src(struct in_device
*in_dev
, __be32
*pmca
, int sfmode
,
2068 int sfcount
, __be32
*psfsrc
, int delta
)
2070 struct ip_mc_list
*pmc
;
2077 for_each_pmc_rcu(in_dev
, pmc
) {
2078 if (*pmca
== pmc
->multiaddr
)
2082 /* MCA not found?? bug */
2086 spin_lock_bh(&pmc
->lock
);
2089 #ifdef CONFIG_IP_MULTICAST
2092 isexclude
= pmc
->sfmode
== MCAST_EXCLUDE
;
2094 pmc
->sfcount
[sfmode
]++;
2096 for (i
= 0; i
< sfcount
; i
++) {
2097 err
= ip_mc_add1_src(pmc
, sfmode
, &psfsrc
[i
]);
2105 pmc
->sfcount
[sfmode
]--;
2106 for (j
= 0; j
< i
; j
++)
2107 (void) ip_mc_del1_src(pmc
, sfmode
, &psfsrc
[j
]);
2108 } else if (isexclude
!= (pmc
->sfcount
[MCAST_EXCLUDE
] != 0)) {
2109 #ifdef CONFIG_IP_MULTICAST
2110 struct ip_sf_list
*psf
;
2111 struct net
*net
= dev_net(pmc
->interface
->dev
);
2112 in_dev
= pmc
->interface
;
2115 /* filter mode change */
2116 if (pmc
->sfcount
[MCAST_EXCLUDE
])
2117 pmc
->sfmode
= MCAST_EXCLUDE
;
2118 else if (pmc
->sfcount
[MCAST_INCLUDE
])
2119 pmc
->sfmode
= MCAST_INCLUDE
;
2120 #ifdef CONFIG_IP_MULTICAST
2121 /* else no filters; keep old mode for reports */
2123 pmc
->crcount
= in_dev
->mr_qrv
?: net
->ipv4
.sysctl_igmp_qrv
;
2124 in_dev
->mr_ifc_count
= pmc
->crcount
;
2125 for (psf
= pmc
->sources
; psf
; psf
= psf
->sf_next
)
2126 psf
->sf_crcount
= 0;
2127 igmp_ifc_event(in_dev
);
2128 } else if (sf_setstate(pmc
)) {
2129 igmp_ifc_event(in_dev
);
2132 spin_unlock_bh(&pmc
->lock
);
2136 static void ip_mc_clear_src(struct ip_mc_list
*pmc
)
2138 struct ip_sf_list
*tomb
, *sources
;
2140 spin_lock_bh(&pmc
->lock
);
2143 sources
= pmc
->sources
;
2144 pmc
->sources
= NULL
;
2145 pmc
->sfmode
= MCAST_EXCLUDE
;
2146 pmc
->sfcount
[MCAST_INCLUDE
] = 0;
2147 pmc
->sfcount
[MCAST_EXCLUDE
] = 1;
2148 spin_unlock_bh(&pmc
->lock
);
2150 ip_sf_list_clear_all(tomb
);
2151 ip_sf_list_clear_all(sources
);
2154 /* Join a multicast group
2156 static int __ip_mc_join_group(struct sock
*sk
, struct ip_mreqn
*imr
,
2159 __be32 addr
= imr
->imr_multiaddr
.s_addr
;
2160 struct ip_mc_socklist
*iml
, *i
;
2161 struct in_device
*in_dev
;
2162 struct inet_sock
*inet
= inet_sk(sk
);
2163 struct net
*net
= sock_net(sk
);
2170 if (!ipv4_is_multicast(addr
))
2173 in_dev
= ip_mc_find_dev(net
, imr
);
2181 ifindex
= imr
->imr_ifindex
;
2182 for_each_pmc_rtnl(inet
, i
) {
2183 if (i
->multi
.imr_multiaddr
.s_addr
== addr
&&
2184 i
->multi
.imr_ifindex
== ifindex
)
2189 if (count
>= net
->ipv4
.sysctl_igmp_max_memberships
)
2191 iml
= sock_kmalloc(sk
, sizeof(*iml
), GFP_KERNEL
);
2195 memcpy(&iml
->multi
, imr
, sizeof(*imr
));
2196 iml
->next_rcu
= inet
->mc_list
;
2199 rcu_assign_pointer(inet
->mc_list
, iml
);
2200 ____ip_mc_inc_group(in_dev
, addr
, mode
, GFP_KERNEL
);
2206 /* Join ASM (Any-Source Multicast) group
2208 int ip_mc_join_group(struct sock
*sk
, struct ip_mreqn
*imr
)
2210 return __ip_mc_join_group(sk
, imr
, MCAST_EXCLUDE
);
2212 EXPORT_SYMBOL(ip_mc_join_group
);
2214 /* Join SSM (Source-Specific Multicast) group
2216 int ip_mc_join_group_ssm(struct sock
*sk
, struct ip_mreqn
*imr
,
2219 return __ip_mc_join_group(sk
, imr
, mode
);
2222 static int ip_mc_leave_src(struct sock
*sk
, struct ip_mc_socklist
*iml
,
2223 struct in_device
*in_dev
)
2225 struct ip_sf_socklist
*psf
= rtnl_dereference(iml
->sflist
);
2229 /* any-source empty exclude case */
2230 return ip_mc_del_src(in_dev
, &iml
->multi
.imr_multiaddr
.s_addr
,
2231 iml
->sfmode
, 0, NULL
, 0);
2233 err
= ip_mc_del_src(in_dev
, &iml
->multi
.imr_multiaddr
.s_addr
,
2234 iml
->sfmode
, psf
->sl_count
, psf
->sl_addr
, 0);
2235 RCU_INIT_POINTER(iml
->sflist
, NULL
);
2236 /* decrease mem now to avoid the memleak warning */
2237 atomic_sub(IP_SFLSIZE(psf
->sl_max
), &sk
->sk_omem_alloc
);
2238 kfree_rcu(psf
, rcu
);
2242 int ip_mc_leave_group(struct sock
*sk
, struct ip_mreqn
*imr
)
2244 struct inet_sock
*inet
= inet_sk(sk
);
2245 struct ip_mc_socklist
*iml
;
2246 struct ip_mc_socklist __rcu
**imlp
;
2247 struct in_device
*in_dev
;
2248 struct net
*net
= sock_net(sk
);
2249 __be32 group
= imr
->imr_multiaddr
.s_addr
;
2251 int ret
= -EADDRNOTAVAIL
;
2255 in_dev
= ip_mc_find_dev(net
, imr
);
2256 if (!imr
->imr_ifindex
&& !imr
->imr_address
.s_addr
&& !in_dev
) {
2260 ifindex
= imr
->imr_ifindex
;
2261 for (imlp
= &inet
->mc_list
;
2262 (iml
= rtnl_dereference(*imlp
)) != NULL
;
2263 imlp
= &iml
->next_rcu
) {
2264 if (iml
->multi
.imr_multiaddr
.s_addr
!= group
)
2267 if (iml
->multi
.imr_ifindex
!= ifindex
)
2269 } else if (imr
->imr_address
.s_addr
&& imr
->imr_address
.s_addr
!=
2270 iml
->multi
.imr_address
.s_addr
)
2273 (void) ip_mc_leave_src(sk
, iml
, in_dev
);
2275 *imlp
= iml
->next_rcu
;
2278 ip_mc_dec_group(in_dev
, group
);
2280 /* decrease mem now to avoid the memleak warning */
2281 atomic_sub(sizeof(*iml
), &sk
->sk_omem_alloc
);
2282 kfree_rcu(iml
, rcu
);
2288 EXPORT_SYMBOL(ip_mc_leave_group
);
2290 int ip_mc_source(int add
, int omode
, struct sock
*sk
, struct
2291 ip_mreq_source
*mreqs
, int ifindex
)
2294 struct ip_mreqn imr
;
2295 __be32 addr
= mreqs
->imr_multiaddr
;
2296 struct ip_mc_socklist
*pmc
;
2297 struct in_device
*in_dev
= NULL
;
2298 struct inet_sock
*inet
= inet_sk(sk
);
2299 struct ip_sf_socklist
*psl
;
2300 struct net
*net
= sock_net(sk
);
2304 if (!ipv4_is_multicast(addr
))
2309 imr
.imr_multiaddr
.s_addr
= mreqs
->imr_multiaddr
;
2310 imr
.imr_address
.s_addr
= mreqs
->imr_interface
;
2311 imr
.imr_ifindex
= ifindex
;
2312 in_dev
= ip_mc_find_dev(net
, &imr
);
2318 err
= -EADDRNOTAVAIL
;
2320 for_each_pmc_rtnl(inet
, pmc
) {
2321 if ((pmc
->multi
.imr_multiaddr
.s_addr
==
2322 imr
.imr_multiaddr
.s_addr
) &&
2323 (pmc
->multi
.imr_ifindex
== imr
.imr_ifindex
))
2326 if (!pmc
) { /* must have a prior join */
2330 /* if a source filter was set, must be the same mode as before */
2332 if (pmc
->sfmode
!= omode
) {
2336 } else if (pmc
->sfmode
!= omode
) {
2337 /* allow mode switches for empty-set filters */
2338 ip_mc_add_src(in_dev
, &mreqs
->imr_multiaddr
, omode
, 0, NULL
, 0);
2339 ip_mc_del_src(in_dev
, &mreqs
->imr_multiaddr
, pmc
->sfmode
, 0,
2341 pmc
->sfmode
= omode
;
2344 psl
= rtnl_dereference(pmc
->sflist
);
2347 goto done
; /* err = -EADDRNOTAVAIL */
2349 for (i
= 0; i
< psl
->sl_count
; i
++) {
2350 rv
= memcmp(&psl
->sl_addr
[i
], &mreqs
->imr_sourceaddr
,
2355 if (rv
) /* source not found */
2356 goto done
; /* err = -EADDRNOTAVAIL */
2358 /* special case - (INCLUDE, empty) == LEAVE_GROUP */
2359 if (psl
->sl_count
== 1 && omode
== MCAST_INCLUDE
) {
2364 /* update the interface filter */
2365 ip_mc_del_src(in_dev
, &mreqs
->imr_multiaddr
, omode
, 1,
2366 &mreqs
->imr_sourceaddr
, 1);
2368 for (j
= i
+1; j
< psl
->sl_count
; j
++)
2369 psl
->sl_addr
[j
-1] = psl
->sl_addr
[j
];
2374 /* else, add a new source to the filter */
2376 if (psl
&& psl
->sl_count
>= net
->ipv4
.sysctl_igmp_max_msf
) {
2380 if (!psl
|| psl
->sl_count
== psl
->sl_max
) {
2381 struct ip_sf_socklist
*newpsl
;
2382 int count
= IP_SFBLOCK
;
2385 count
+= psl
->sl_max
;
2386 newpsl
= sock_kmalloc(sk
, IP_SFLSIZE(count
), GFP_KERNEL
);
2391 newpsl
->sl_max
= count
;
2392 newpsl
->sl_count
= count
- IP_SFBLOCK
;
2394 for (i
= 0; i
< psl
->sl_count
; i
++)
2395 newpsl
->sl_addr
[i
] = psl
->sl_addr
[i
];
2396 /* decrease mem now to avoid the memleak warning */
2397 atomic_sub(IP_SFLSIZE(psl
->sl_max
), &sk
->sk_omem_alloc
);
2398 kfree_rcu(psl
, rcu
);
2400 rcu_assign_pointer(pmc
->sflist
, newpsl
);
2403 rv
= 1; /* > 0 for insert logic below if sl_count is 0 */
2404 for (i
= 0; i
< psl
->sl_count
; i
++) {
2405 rv
= memcmp(&psl
->sl_addr
[i
], &mreqs
->imr_sourceaddr
,
2410 if (rv
== 0) /* address already there is an error */
2412 for (j
= psl
->sl_count
-1; j
>= i
; j
--)
2413 psl
->sl_addr
[j
+1] = psl
->sl_addr
[j
];
2414 psl
->sl_addr
[i
] = mreqs
->imr_sourceaddr
;
2417 /* update the interface list */
2418 ip_mc_add_src(in_dev
, &mreqs
->imr_multiaddr
, omode
, 1,
2419 &mreqs
->imr_sourceaddr
, 1);
2422 err
= ip_mc_leave_group(sk
, &imr
);
2426 int ip_mc_msfilter(struct sock
*sk
, struct ip_msfilter
*msf
, int ifindex
)
2429 struct ip_mreqn imr
;
2430 __be32 addr
= msf
->imsf_multiaddr
;
2431 struct ip_mc_socklist
*pmc
;
2432 struct in_device
*in_dev
;
2433 struct inet_sock
*inet
= inet_sk(sk
);
2434 struct ip_sf_socklist
*newpsl
, *psl
;
2435 struct net
*net
= sock_net(sk
);
2438 if (!ipv4_is_multicast(addr
))
2440 if (msf
->imsf_fmode
!= MCAST_INCLUDE
&&
2441 msf
->imsf_fmode
!= MCAST_EXCLUDE
)
2446 imr
.imr_multiaddr
.s_addr
= msf
->imsf_multiaddr
;
2447 imr
.imr_address
.s_addr
= msf
->imsf_interface
;
2448 imr
.imr_ifindex
= ifindex
;
2449 in_dev
= ip_mc_find_dev(net
, &imr
);
2456 /* special case - (INCLUDE, empty) == LEAVE_GROUP */
2457 if (msf
->imsf_fmode
== MCAST_INCLUDE
&& msf
->imsf_numsrc
== 0) {
2462 for_each_pmc_rtnl(inet
, pmc
) {
2463 if (pmc
->multi
.imr_multiaddr
.s_addr
== msf
->imsf_multiaddr
&&
2464 pmc
->multi
.imr_ifindex
== imr
.imr_ifindex
)
2467 if (!pmc
) { /* must have a prior join */
2471 if (msf
->imsf_numsrc
) {
2472 newpsl
= sock_kmalloc(sk
, IP_SFLSIZE(msf
->imsf_numsrc
),
2478 newpsl
->sl_max
= newpsl
->sl_count
= msf
->imsf_numsrc
;
2479 memcpy(newpsl
->sl_addr
, msf
->imsf_slist
,
2480 msf
->imsf_numsrc
* sizeof(msf
->imsf_slist
[0]));
2481 err
= ip_mc_add_src(in_dev
, &msf
->imsf_multiaddr
,
2482 msf
->imsf_fmode
, newpsl
->sl_count
, newpsl
->sl_addr
, 0);
2484 sock_kfree_s(sk
, newpsl
, IP_SFLSIZE(newpsl
->sl_max
));
2489 (void) ip_mc_add_src(in_dev
, &msf
->imsf_multiaddr
,
2490 msf
->imsf_fmode
, 0, NULL
, 0);
2492 psl
= rtnl_dereference(pmc
->sflist
);
2494 (void) ip_mc_del_src(in_dev
, &msf
->imsf_multiaddr
, pmc
->sfmode
,
2495 psl
->sl_count
, psl
->sl_addr
, 0);
2496 /* decrease mem now to avoid the memleak warning */
2497 atomic_sub(IP_SFLSIZE(psl
->sl_max
), &sk
->sk_omem_alloc
);
2498 kfree_rcu(psl
, rcu
);
2500 (void) ip_mc_del_src(in_dev
, &msf
->imsf_multiaddr
, pmc
->sfmode
,
2502 rcu_assign_pointer(pmc
->sflist
, newpsl
);
2503 pmc
->sfmode
= msf
->imsf_fmode
;
2507 err
= ip_mc_leave_group(sk
, &imr
);
2511 int ip_mc_msfget(struct sock
*sk
, struct ip_msfilter
*msf
,
2512 struct ip_msfilter __user
*optval
, int __user
*optlen
)
2514 int err
, len
, count
, copycount
;
2515 struct ip_mreqn imr
;
2516 __be32 addr
= msf
->imsf_multiaddr
;
2517 struct ip_mc_socklist
*pmc
;
2518 struct in_device
*in_dev
;
2519 struct inet_sock
*inet
= inet_sk(sk
);
2520 struct ip_sf_socklist
*psl
;
2521 struct net
*net
= sock_net(sk
);
2525 if (!ipv4_is_multicast(addr
))
2528 imr
.imr_multiaddr
.s_addr
= msf
->imsf_multiaddr
;
2529 imr
.imr_address
.s_addr
= msf
->imsf_interface
;
2530 imr
.imr_ifindex
= 0;
2531 in_dev
= ip_mc_find_dev(net
, &imr
);
2537 err
= -EADDRNOTAVAIL
;
2539 for_each_pmc_rtnl(inet
, pmc
) {
2540 if (pmc
->multi
.imr_multiaddr
.s_addr
== msf
->imsf_multiaddr
&&
2541 pmc
->multi
.imr_ifindex
== imr
.imr_ifindex
)
2544 if (!pmc
) /* must have a prior join */
2546 msf
->imsf_fmode
= pmc
->sfmode
;
2547 psl
= rtnl_dereference(pmc
->sflist
);
2552 count
= psl
->sl_count
;
2554 copycount
= count
< msf
->imsf_numsrc
? count
: msf
->imsf_numsrc
;
2555 len
= copycount
* sizeof(psl
->sl_addr
[0]);
2556 msf
->imsf_numsrc
= count
;
2557 if (put_user(IP_MSFILTER_SIZE(copycount
), optlen
) ||
2558 copy_to_user(optval
, msf
, IP_MSFILTER_SIZE(0))) {
2562 copy_to_user(&optval
->imsf_slist
[0], psl
->sl_addr
, len
))
2569 int ip_mc_gsfget(struct sock
*sk
, struct group_filter
*gsf
,
2570 struct group_filter __user
*optval
, int __user
*optlen
)
2572 int err
, i
, count
, copycount
;
2573 struct sockaddr_in
*psin
;
2575 struct ip_mc_socklist
*pmc
;
2576 struct inet_sock
*inet
= inet_sk(sk
);
2577 struct ip_sf_socklist
*psl
;
2581 psin
= (struct sockaddr_in
*)&gsf
->gf_group
;
2582 if (psin
->sin_family
!= AF_INET
)
2584 addr
= psin
->sin_addr
.s_addr
;
2585 if (!ipv4_is_multicast(addr
))
2588 err
= -EADDRNOTAVAIL
;
2590 for_each_pmc_rtnl(inet
, pmc
) {
2591 if (pmc
->multi
.imr_multiaddr
.s_addr
== addr
&&
2592 pmc
->multi
.imr_ifindex
== gsf
->gf_interface
)
2595 if (!pmc
) /* must have a prior join */
2597 gsf
->gf_fmode
= pmc
->sfmode
;
2598 psl
= rtnl_dereference(pmc
->sflist
);
2599 count
= psl
? psl
->sl_count
: 0;
2600 copycount
= count
< gsf
->gf_numsrc
? count
: gsf
->gf_numsrc
;
2601 gsf
->gf_numsrc
= count
;
2602 if (put_user(GROUP_FILTER_SIZE(copycount
), optlen
) ||
2603 copy_to_user(optval
, gsf
, GROUP_FILTER_SIZE(0))) {
2606 for (i
= 0; i
< copycount
; i
++) {
2607 struct sockaddr_storage ss
;
2609 psin
= (struct sockaddr_in
*)&ss
;
2610 memset(&ss
, 0, sizeof(ss
));
2611 psin
->sin_family
= AF_INET
;
2612 psin
->sin_addr
.s_addr
= psl
->sl_addr
[i
];
2613 if (copy_to_user(&optval
->gf_slist
[i
], &ss
, sizeof(ss
)))
2622 * check if a multicast source filter allows delivery for a given <src,dst,intf>
2624 int ip_mc_sf_allow(struct sock
*sk
, __be32 loc_addr
, __be32 rmt_addr
,
2627 struct inet_sock
*inet
= inet_sk(sk
);
2628 struct ip_mc_socklist
*pmc
;
2629 struct ip_sf_socklist
*psl
;
2634 if (!ipv4_is_multicast(loc_addr
))
2638 for_each_pmc_rcu(inet
, pmc
) {
2639 if (pmc
->multi
.imr_multiaddr
.s_addr
== loc_addr
&&
2640 (pmc
->multi
.imr_ifindex
== dif
||
2641 (sdif
&& pmc
->multi
.imr_ifindex
== sdif
)))
2647 psl
= rcu_dereference(pmc
->sflist
);
2648 ret
= (pmc
->sfmode
== MCAST_EXCLUDE
);
2652 for (i
= 0; i
< psl
->sl_count
; i
++) {
2653 if (psl
->sl_addr
[i
] == rmt_addr
)
2657 if (pmc
->sfmode
== MCAST_INCLUDE
&& i
>= psl
->sl_count
)
2659 if (pmc
->sfmode
== MCAST_EXCLUDE
&& i
< psl
->sl_count
)
2669 * A socket is closing.
2672 void ip_mc_drop_socket(struct sock
*sk
)
2674 struct inet_sock
*inet
= inet_sk(sk
);
2675 struct ip_mc_socklist
*iml
;
2676 struct net
*net
= sock_net(sk
);
2682 while ((iml
= rtnl_dereference(inet
->mc_list
)) != NULL
) {
2683 struct in_device
*in_dev
;
2685 inet
->mc_list
= iml
->next_rcu
;
2686 in_dev
= inetdev_by_index(net
, iml
->multi
.imr_ifindex
);
2687 (void) ip_mc_leave_src(sk
, iml
, in_dev
);
2689 ip_mc_dec_group(in_dev
, iml
->multi
.imr_multiaddr
.s_addr
);
2690 /* decrease mem now to avoid the memleak warning */
2691 atomic_sub(sizeof(*iml
), &sk
->sk_omem_alloc
);
2692 kfree_rcu(iml
, rcu
);
2697 /* called with rcu_read_lock() */
2698 int ip_check_mc_rcu(struct in_device
*in_dev
, __be32 mc_addr
, __be32 src_addr
, u8 proto
)
2700 struct ip_mc_list
*im
;
2701 struct ip_mc_list __rcu
**mc_hash
;
2702 struct ip_sf_list
*psf
;
2705 mc_hash
= rcu_dereference(in_dev
->mc_hash
);
2707 u32 hash
= hash_32((__force u32
)mc_addr
, MC_HASH_SZ_LOG
);
2709 for (im
= rcu_dereference(mc_hash
[hash
]);
2711 im
= rcu_dereference(im
->next_hash
)) {
2712 if (im
->multiaddr
== mc_addr
)
2716 for_each_pmc_rcu(in_dev
, im
) {
2717 if (im
->multiaddr
== mc_addr
)
2721 if (im
&& proto
== IPPROTO_IGMP
) {
2725 for (psf
= im
->sources
; psf
; psf
= psf
->sf_next
) {
2726 if (psf
->sf_inaddr
== src_addr
)
2730 rv
= psf
->sf_count
[MCAST_INCLUDE
] ||
2731 psf
->sf_count
[MCAST_EXCLUDE
] !=
2732 im
->sfcount
[MCAST_EXCLUDE
];
2734 rv
= im
->sfcount
[MCAST_EXCLUDE
] != 0;
2736 rv
= 1; /* unspecified source; tentatively allow */
2741 #if defined(CONFIG_PROC_FS)
2742 struct igmp_mc_iter_state
{
2743 struct seq_net_private p
;
2744 struct net_device
*dev
;
2745 struct in_device
*in_dev
;
2748 #define igmp_mc_seq_private(seq) ((struct igmp_mc_iter_state *)(seq)->private)
2750 static inline struct ip_mc_list
*igmp_mc_get_first(struct seq_file
*seq
)
2752 struct net
*net
= seq_file_net(seq
);
2753 struct ip_mc_list
*im
= NULL
;
2754 struct igmp_mc_iter_state
*state
= igmp_mc_seq_private(seq
);
2756 state
->in_dev
= NULL
;
2757 for_each_netdev_rcu(net
, state
->dev
) {
2758 struct in_device
*in_dev
;
2760 in_dev
= __in_dev_get_rcu(state
->dev
);
2763 im
= rcu_dereference(in_dev
->mc_list
);
2765 state
->in_dev
= in_dev
;
2772 static struct ip_mc_list
*igmp_mc_get_next(struct seq_file
*seq
, struct ip_mc_list
*im
)
2774 struct igmp_mc_iter_state
*state
= igmp_mc_seq_private(seq
);
2776 im
= rcu_dereference(im
->next_rcu
);
2778 state
->dev
= next_net_device_rcu(state
->dev
);
2780 state
->in_dev
= NULL
;
2783 state
->in_dev
= __in_dev_get_rcu(state
->dev
);
2786 im
= rcu_dereference(state
->in_dev
->mc_list
);
2791 static struct ip_mc_list
*igmp_mc_get_idx(struct seq_file
*seq
, loff_t pos
)
2793 struct ip_mc_list
*im
= igmp_mc_get_first(seq
);
2795 while (pos
&& (im
= igmp_mc_get_next(seq
, im
)) != NULL
)
2797 return pos
? NULL
: im
;
2800 static void *igmp_mc_seq_start(struct seq_file
*seq
, loff_t
*pos
)
2804 return *pos
? igmp_mc_get_idx(seq
, *pos
- 1) : SEQ_START_TOKEN
;
2807 static void *igmp_mc_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
2809 struct ip_mc_list
*im
;
2810 if (v
== SEQ_START_TOKEN
)
2811 im
= igmp_mc_get_first(seq
);
2813 im
= igmp_mc_get_next(seq
, v
);
2818 static void igmp_mc_seq_stop(struct seq_file
*seq
, void *v
)
2821 struct igmp_mc_iter_state
*state
= igmp_mc_seq_private(seq
);
2823 state
->in_dev
= NULL
;
2828 static int igmp_mc_seq_show(struct seq_file
*seq
, void *v
)
2830 if (v
== SEQ_START_TOKEN
)
2832 "Idx\tDevice : Count Querier\tGroup Users Timer\tReporter\n");
2834 struct ip_mc_list
*im
= (struct ip_mc_list
*)v
;
2835 struct igmp_mc_iter_state
*state
= igmp_mc_seq_private(seq
);
2839 #ifdef CONFIG_IP_MULTICAST
2840 querier
= IGMP_V1_SEEN(state
->in_dev
) ? "V1" :
2841 IGMP_V2_SEEN(state
->in_dev
) ? "V2" :
2847 if (rcu_access_pointer(state
->in_dev
->mc_list
) == im
) {
2848 seq_printf(seq
, "%d\t%-10s: %5d %7s\n",
2849 state
->dev
->ifindex
, state
->dev
->name
, state
->in_dev
->mc_count
, querier
);
2852 delta
= im
->timer
.expires
- jiffies
;
2854 "\t\t\t\t%08X %5d %d:%08lX\t\t%d\n",
2855 im
->multiaddr
, im
->users
,
2857 im
->tm_running
? jiffies_delta_to_clock_t(delta
) : 0,
2863 static const struct seq_operations igmp_mc_seq_ops
= {
2864 .start
= igmp_mc_seq_start
,
2865 .next
= igmp_mc_seq_next
,
2866 .stop
= igmp_mc_seq_stop
,
2867 .show
= igmp_mc_seq_show
,
2870 struct igmp_mcf_iter_state
{
2871 struct seq_net_private p
;
2872 struct net_device
*dev
;
2873 struct in_device
*idev
;
2874 struct ip_mc_list
*im
;
2877 #define igmp_mcf_seq_private(seq) ((struct igmp_mcf_iter_state *)(seq)->private)
2879 static inline struct ip_sf_list
*igmp_mcf_get_first(struct seq_file
*seq
)
2881 struct net
*net
= seq_file_net(seq
);
2882 struct ip_sf_list
*psf
= NULL
;
2883 struct ip_mc_list
*im
= NULL
;
2884 struct igmp_mcf_iter_state
*state
= igmp_mcf_seq_private(seq
);
2888 for_each_netdev_rcu(net
, state
->dev
) {
2889 struct in_device
*idev
;
2890 idev
= __in_dev_get_rcu(state
->dev
);
2891 if (unlikely(!idev
))
2893 im
= rcu_dereference(idev
->mc_list
);
2895 spin_lock_bh(&im
->lock
);
2902 spin_unlock_bh(&im
->lock
);
2908 static struct ip_sf_list
*igmp_mcf_get_next(struct seq_file
*seq
, struct ip_sf_list
*psf
)
2910 struct igmp_mcf_iter_state
*state
= igmp_mcf_seq_private(seq
);
2914 spin_unlock_bh(&state
->im
->lock
);
2915 state
->im
= state
->im
->next
;
2916 while (!state
->im
) {
2917 state
->dev
= next_net_device_rcu(state
->dev
);
2922 state
->idev
= __in_dev_get_rcu(state
->dev
);
2925 state
->im
= rcu_dereference(state
->idev
->mc_list
);
2929 spin_lock_bh(&state
->im
->lock
);
2930 psf
= state
->im
->sources
;
2936 static struct ip_sf_list
*igmp_mcf_get_idx(struct seq_file
*seq
, loff_t pos
)
2938 struct ip_sf_list
*psf
= igmp_mcf_get_first(seq
);
2940 while (pos
&& (psf
= igmp_mcf_get_next(seq
, psf
)) != NULL
)
2942 return pos
? NULL
: psf
;
2945 static void *igmp_mcf_seq_start(struct seq_file
*seq
, loff_t
*pos
)
2949 return *pos
? igmp_mcf_get_idx(seq
, *pos
- 1) : SEQ_START_TOKEN
;
2952 static void *igmp_mcf_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
2954 struct ip_sf_list
*psf
;
2955 if (v
== SEQ_START_TOKEN
)
2956 psf
= igmp_mcf_get_first(seq
);
2958 psf
= igmp_mcf_get_next(seq
, v
);
2963 static void igmp_mcf_seq_stop(struct seq_file
*seq
, void *v
)
2966 struct igmp_mcf_iter_state
*state
= igmp_mcf_seq_private(seq
);
2967 if (likely(state
->im
)) {
2968 spin_unlock_bh(&state
->im
->lock
);
2976 static int igmp_mcf_seq_show(struct seq_file
*seq
, void *v
)
2978 struct ip_sf_list
*psf
= (struct ip_sf_list
*)v
;
2979 struct igmp_mcf_iter_state
*state
= igmp_mcf_seq_private(seq
);
2981 if (v
== SEQ_START_TOKEN
) {
2982 seq_puts(seq
, "Idx Device MCA SRC INC EXC\n");
2986 "0x%08x %6lu %6lu\n",
2987 state
->dev
->ifindex
, state
->dev
->name
,
2988 ntohl(state
->im
->multiaddr
),
2989 ntohl(psf
->sf_inaddr
),
2990 psf
->sf_count
[MCAST_INCLUDE
],
2991 psf
->sf_count
[MCAST_EXCLUDE
]);
2996 static const struct seq_operations igmp_mcf_seq_ops
= {
2997 .start
= igmp_mcf_seq_start
,
2998 .next
= igmp_mcf_seq_next
,
2999 .stop
= igmp_mcf_seq_stop
,
3000 .show
= igmp_mcf_seq_show
,
3003 static int __net_init
igmp_net_init(struct net
*net
)
3005 struct proc_dir_entry
*pde
;
3008 pde
= proc_create_net("igmp", 0444, net
->proc_net
, &igmp_mc_seq_ops
,
3009 sizeof(struct igmp_mc_iter_state
));
3012 pde
= proc_create_net("mcfilter", 0444, net
->proc_net
,
3013 &igmp_mcf_seq_ops
, sizeof(struct igmp_mcf_iter_state
));
3016 err
= inet_ctl_sock_create(&net
->ipv4
.mc_autojoin_sk
, AF_INET
,
3017 SOCK_DGRAM
, 0, net
);
3019 pr_err("Failed to initialize the IGMP autojoin socket (err %d)\n",
3027 remove_proc_entry("mcfilter", net
->proc_net
);
3029 remove_proc_entry("igmp", net
->proc_net
);
3034 static void __net_exit
igmp_net_exit(struct net
*net
)
3036 remove_proc_entry("mcfilter", net
->proc_net
);
3037 remove_proc_entry("igmp", net
->proc_net
);
3038 inet_ctl_sock_destroy(net
->ipv4
.mc_autojoin_sk
);
3041 static struct pernet_operations igmp_net_ops
= {
3042 .init
= igmp_net_init
,
3043 .exit
= igmp_net_exit
,
3047 static int igmp_netdev_event(struct notifier_block
*this,
3048 unsigned long event
, void *ptr
)
3050 struct net_device
*dev
= netdev_notifier_info_to_dev(ptr
);
3051 struct in_device
*in_dev
;
3054 case NETDEV_RESEND_IGMP
:
3055 in_dev
= __in_dev_get_rtnl(dev
);
3057 ip_mc_rejoin_groups(in_dev
);
3065 static struct notifier_block igmp_notifier
= {
3066 .notifier_call
= igmp_netdev_event
,
3069 int __init
igmp_mc_init(void)
3071 #if defined(CONFIG_PROC_FS)
3074 err
= register_pernet_subsys(&igmp_net_ops
);
3077 err
= register_netdevice_notifier(&igmp_notifier
);
3079 goto reg_notif_fail
;
3083 unregister_pernet_subsys(&igmp_net_ops
);
3086 return register_netdevice_notifier(&igmp_notifier
);