Lines Matching +full:im +full:-

1 // SPDX-License-Identifier: GPL-2.0-or-later
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
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
37 * Chih-Jen Chang : Added the max_resp_time parameter to
38 * Tsu-Sheng Tsao igmp_heard_query(). Using this parameter
41 * Chih-Jen Chang : Added a timer to revert to IGMP V2 router
42 * Tsu-Sheng Tsao if the specified time expired.
53 * igmp_timer_expire if tm->running is
64 * Alexey Kuznetsov: Accordance to igmp-v2-06 draft.
108 /* Parameter names and values are taken from igmp-v2-06 draft */
123 (IPV4_DEVCONF_ALL(dev_net(in_dev->dev), FORCE_IGMP_VERSION) == 1 || \
125 ((in_dev)->mr_v1_seen && \
126 time_before(jiffies, (in_dev)->mr_v1_seen)))
128 (IPV4_DEVCONF_ALL(dev_net(in_dev->dev), FORCE_IGMP_VERSION) == 2 || \
130 ((in_dev)->mr_v2_seen && \
131 time_before(jiffies, (in_dev)->mr_v2_seen)))
156 static void igmpv3_add_delrec(struct in_device *in_dev, struct ip_mc_list *im,
158 static void igmpv3_del_delrec(struct in_device *in_dev, struct ip_mc_list *im);
167 static void ip_ma_put(struct ip_mc_list *im) in ip_ma_put() argument
169 if (refcount_dec_and_test(&im->refcnt)) { in ip_ma_put()
170 in_dev_put(im->interface); in ip_ma_put()
171 kfree_rcu(im, rcu); in ip_ma_put()
176 for (pmc = rcu_dereference(in_dev->mc_list); \
178 pmc = rcu_dereference(pmc->next_rcu))
181 for (pmc = rtnl_dereference(in_dev->mc_list); \
183 pmc = rtnl_dereference(pmc->next_rcu))
190 next = psf->sf_next; in ip_sf_list_clear_all()
202 static void igmp_stop_timer(struct ip_mc_list *im) in igmp_stop_timer() argument
204 spin_lock_bh(&im->lock); in igmp_stop_timer()
205 if (del_timer(&im->timer)) in igmp_stop_timer()
206 refcount_dec(&im->refcnt); in igmp_stop_timer()
207 im->tm_running = 0; in igmp_stop_timer()
208 im->reporter = 0; in igmp_stop_timer()
209 im->unsolicit_count = 0; in igmp_stop_timer()
210 spin_unlock_bh(&im->lock); in igmp_stop_timer()
213 /* It must be called with locked im->lock */
214 static void igmp_start_timer(struct ip_mc_list *im, int max_delay) in igmp_start_timer() argument
218 im->tm_running = 1; in igmp_start_timer()
219 if (!mod_timer(&im->timer, jiffies+tv+2)) in igmp_start_timer()
220 refcount_inc(&im->refcnt); in igmp_start_timer()
225 int tv = prandom_u32() % in_dev->mr_maxdelay; in igmp_gq_start_timer()
228 if (in_dev->mr_gq_running && in igmp_gq_start_timer()
229 time_after_eq(exp, (in_dev->mr_gq_timer).expires)) in igmp_gq_start_timer()
232 in_dev->mr_gq_running = 1; in igmp_gq_start_timer()
233 if (!mod_timer(&in_dev->mr_gq_timer, exp)) in igmp_gq_start_timer()
241 if (!mod_timer(&in_dev->mr_ifc_timer, jiffies+tv+2)) in igmp_ifc_start_timer()
245 static void igmp_mod_timer(struct ip_mc_list *im, int max_delay) in igmp_mod_timer() argument
247 spin_lock_bh(&im->lock); in igmp_mod_timer()
248 im->unsolicit_count = 0; in igmp_mod_timer()
249 if (del_timer(&im->timer)) { in igmp_mod_timer()
250 if ((long)(im->timer.expires-jiffies) < max_delay) { in igmp_mod_timer()
251 add_timer(&im->timer); in igmp_mod_timer()
252 im->tm_running = 1; in igmp_mod_timer()
253 spin_unlock_bh(&im->lock); in igmp_mod_timer()
256 refcount_dec(&im->refcnt); in igmp_mod_timer()
258 igmp_start_timer(im, max_delay); in igmp_mod_timer()
259 spin_unlock_bh(&im->lock); in igmp_mod_timer()
278 if (!(pmc->gsquery && !psf->sf_gsresp)) { in is_in()
279 if (pmc->sfmode == MCAST_INCLUDE) in is_in()
284 if (psf->sf_count[MCAST_INCLUDE]) in is_in()
286 return pmc->sfcount[MCAST_EXCLUDE] == in is_in()
287 psf->sf_count[MCAST_EXCLUDE]; in is_in()
293 return psf->sf_count[MCAST_INCLUDE] != 0; in is_in()
297 if (pmc->sfcount[MCAST_EXCLUDE] == 0 || in is_in()
298 psf->sf_count[MCAST_INCLUDE]) in is_in()
300 return pmc->sfcount[MCAST_EXCLUDE] == in is_in()
301 psf->sf_count[MCAST_EXCLUDE]; in is_in()
303 if (gdeleted || !psf->sf_crcount) in is_in()
305 return (pmc->sfmode == MCAST_INCLUDE) ^ sdeleted; in is_in()
307 if (pmc->sfmode == MCAST_INCLUDE) in is_in()
308 return gdeleted || (psf->sf_crcount && sdeleted); in is_in()
309 return psf->sf_crcount && !gdeleted && !sdeleted; in is_in()
320 for (psf = pmc->sources; psf; psf = psf->sf_next) { in igmp_scount()
339 if (fl4->saddr == ifa->ifa_local) in igmpv3_get_srcaddr()
340 return fl4->saddr; in igmpv3_get_srcaddr()
355 int tlen = dev->needed_tailroom; in igmpv3_newpack()
367 skb->priority = TC_PRIO_CONTROL; in igmpv3_newpack()
371 IPPROTO_IGMP, 0, dev->ifindex); in igmpv3_newpack()
377 skb_dst_set(skb, &rt->dst); in igmpv3_newpack()
378 skb->dev = dev; in igmpv3_newpack()
387 pip->version = 4; in igmpv3_newpack()
388 pip->ihl = (sizeof(struct iphdr)+4)>>2; in igmpv3_newpack()
389 pip->tos = 0xc0; in igmpv3_newpack()
390 pip->frag_off = htons(IP_DF); in igmpv3_newpack()
391 pip->ttl = 1; in igmpv3_newpack()
392 pip->daddr = fl4.daddr; in igmpv3_newpack()
395 pip->saddr = igmpv3_get_srcaddr(dev, &fl4); in igmpv3_newpack()
398 pip->protocol = IPPROTO_IGMP; in igmpv3_newpack()
399 pip->tot_len = 0; /* filled in later */ in igmpv3_newpack()
406 skb->transport_header = skb->network_header + sizeof(struct iphdr) + 4; in igmpv3_newpack()
409 pig->type = IGMPV3_HOST_MEMBERSHIP_REPORT; in igmpv3_newpack()
410 pig->resv1 = 0; in igmpv3_newpack()
411 pig->csum = 0; in igmpv3_newpack()
412 pig->resv2 = 0; in igmpv3_newpack()
413 pig->ngrec = 0; in igmpv3_newpack()
420 const int igmplen = skb_tail_pointer(skb) - skb_transport_header(skb); in igmpv3_sendpack()
422 pig->csum = ip_compute_csum(igmp_hdr(skb), igmplen); in igmpv3_sendpack()
424 return ip_local_out(dev_net(skb_dst(skb)->dev), skb->sk, skb); in igmpv3_sendpack()
435 struct net_device *dev = pmc->interface->dev; in add_grhead()
445 pgr->grec_type = type; in add_grhead()
446 pgr->grec_auxwords = 0; in add_grhead()
447 pgr->grec_nsrcs = 0; in add_grhead()
448 pgr->grec_mca = pmc->multiaddr; in add_grhead()
450 pih->ngrec = htons(ntohs(pih->ngrec)+1); in add_grhead()
460 struct net_device *dev = pmc->interface->dev; in add_grec()
468 if (pmc->multiaddr == IGMP_ALL_HOSTS) in add_grec()
470 if (ipv4_is_local_multicast(pmc->multiaddr) && !net->ipv4.sysctl_igmp_llm_reports) in add_grec()
473 mtu = READ_ONCE(dev->mtu); in add_grec()
484 psf_list = sdeleted ? &pmc->tomb : &pmc->sources; in add_grec()
493 if (pih && pih->ngrec && in add_grec()
505 psf_next = psf->sf_next; in add_grec()
512 /* Based on RFC3376 5.1. Should not send source-list change in add_grec()
515 if (((gdeleted && pmc->sfmode == MCAST_EXCLUDE) || in add_grec()
516 (!gdeleted && pmc->crcount)) && in add_grec()
518 type == IGMPV3_BLOCK_OLD_SOURCES) && psf->sf_crcount) in add_grec()
523 psf->sf_gsresp = 0; in add_grec()
530 pgr->grec_nsrcs = htons(scount); in add_grec()
544 *psrc = psf->sf_inaddr; in add_grec()
547 type == IGMPV3_BLOCK_OLD_SOURCES) && psf->sf_crcount) { in add_grec()
549 psf->sf_crcount--; in add_grec()
550 if ((sdeleted || gdeleted) && psf->sf_crcount == 0) { in add_grec()
552 psf_prev->sf_next = psf->sf_next; in add_grec()
554 *psf_list = psf->sf_next; in add_grec()
567 if (pmc->crcount || isquery) { in add_grec()
577 pgr->grec_nsrcs = htons(scount); in add_grec()
580 pmc->gsquery = 0; /* clear query state on report */ in add_grec()
587 struct net *net = dev_net(in_dev->dev); in igmpv3_send_report()
593 if (pmc->multiaddr == IGMP_ALL_HOSTS) in igmpv3_send_report()
595 if (ipv4_is_local_multicast(pmc->multiaddr) && in igmpv3_send_report()
596 !net->ipv4.sysctl_igmp_llm_reports) in igmpv3_send_report()
598 spin_lock_bh(&pmc->lock); in igmpv3_send_report()
599 if (pmc->sfcount[MCAST_EXCLUDE]) in igmpv3_send_report()
604 spin_unlock_bh(&pmc->lock); in igmpv3_send_report()
608 spin_lock_bh(&pmc->lock); in igmpv3_send_report()
609 if (pmc->sfcount[MCAST_EXCLUDE]) in igmpv3_send_report()
614 spin_unlock_bh(&pmc->lock); in igmpv3_send_report()
622 * remove zero-count source records from a source filter list
630 psf_next = psf->sf_next; in igmpv3_clear_zeros()
631 if (psf->sf_crcount == 0) { in igmpv3_clear_zeros()
633 psf_prev->sf_next = psf->sf_next; in igmpv3_clear_zeros()
635 *ppsf = psf->sf_next; in igmpv3_clear_zeros()
644 ip_sf_list_clear_all(pmc->sources); in kfree_pmc()
645 ip_sf_list_clear_all(pmc->tomb); in kfree_pmc()
656 spin_lock_bh(&in_dev->mc_tomb_lock); in igmpv3_send_cr()
660 for (pmc = in_dev->mc_tomb; pmc; pmc = pmc_next) { in igmpv3_send_cr()
661 pmc_next = pmc->next; in igmpv3_send_cr()
662 if (pmc->sfmode == MCAST_INCLUDE) { in igmpv3_send_cr()
668 if (pmc->crcount) { in igmpv3_send_cr()
669 if (pmc->sfmode == MCAST_EXCLUDE) { in igmpv3_send_cr()
673 pmc->crcount--; in igmpv3_send_cr()
674 if (pmc->crcount == 0) { in igmpv3_send_cr()
675 igmpv3_clear_zeros(&pmc->tomb); in igmpv3_send_cr()
676 igmpv3_clear_zeros(&pmc->sources); in igmpv3_send_cr()
679 if (pmc->crcount == 0 && !pmc->tomb && !pmc->sources) { in igmpv3_send_cr()
681 pmc_prev->next = pmc_next; in igmpv3_send_cr()
683 in_dev->mc_tomb = pmc_next; in igmpv3_send_cr()
684 in_dev_put(pmc->interface); in igmpv3_send_cr()
689 spin_unlock_bh(&in_dev->mc_tomb_lock); in igmpv3_send_cr()
693 spin_lock_bh(&pmc->lock); in igmpv3_send_cr()
694 if (pmc->sfcount[MCAST_EXCLUDE]) { in igmpv3_send_cr()
705 if (pmc->crcount) { in igmpv3_send_cr()
706 if (pmc->sfmode == MCAST_EXCLUDE) in igmpv3_send_cr()
711 pmc->crcount--; in igmpv3_send_cr()
713 spin_unlock_bh(&pmc->lock); in igmpv3_send_cr()
729 struct net_device *dev = in_dev->dev; in igmp_send_report()
731 __be32 group = pmc ? pmc->multiaddr : 0; in igmp_send_report()
739 if (ipv4_is_local_multicast(group) && !net->ipv4.sysctl_igmp_llm_reports) in igmp_send_report()
749 IPPROTO_IGMP, 0, dev->ifindex); in igmp_send_report()
751 return -1; in igmp_send_report()
754 tlen = dev->needed_tailroom; in igmp_send_report()
758 return -1; in igmp_send_report()
760 skb->priority = TC_PRIO_CONTROL; in igmp_send_report()
762 skb_dst_set(skb, &rt->dst); in igmp_send_report()
770 iph->version = 4; in igmp_send_report()
771 iph->ihl = (sizeof(struct iphdr)+4)>>2; in igmp_send_report()
772 iph->tos = 0xc0; in igmp_send_report()
773 iph->frag_off = htons(IP_DF); in igmp_send_report()
774 iph->ttl = 1; in igmp_send_report()
775 iph->daddr = dst; in igmp_send_report()
776 iph->saddr = fl4.saddr; in igmp_send_report()
777 iph->protocol = IPPROTO_IGMP; in igmp_send_report()
785 ih->type = type; in igmp_send_report()
786 ih->code = 0; in igmp_send_report()
787 ih->csum = 0; in igmp_send_report()
788 ih->group = group; in igmp_send_report()
789 ih->csum = ip_compute_csum((void *)ih, sizeof(struct igmphdr)); in igmp_send_report()
791 return ip_local_out(net, skb->sk, skb); in igmp_send_report()
798 in_dev->mr_gq_running = 0; in igmp_gq_timer_expire()
808 if (in_dev->mr_ifc_count) { in igmp_ifc_timer_expire()
809 in_dev->mr_ifc_count--; in igmp_ifc_timer_expire()
818 struct net *net = dev_net(in_dev->dev); in igmp_ifc_event()
821 in_dev->mr_ifc_count = in_dev->mr_qrv ?: net->ipv4.sysctl_igmp_qrv; in igmp_ifc_event()
828 struct ip_mc_list *im = from_timer(im, t, timer); in igmp_timer_expire() local
829 struct in_device *in_dev = im->interface; in igmp_timer_expire()
831 spin_lock(&im->lock); in igmp_timer_expire()
832 im->tm_running = 0; in igmp_timer_expire()
834 if (im->unsolicit_count && --im->unsolicit_count) in igmp_timer_expire()
835 igmp_start_timer(im, unsolicited_report_interval(in_dev)); in igmp_timer_expire()
837 im->reporter = 1; in igmp_timer_expire()
838 spin_unlock(&im->lock); in igmp_timer_expire()
841 igmp_send_report(in_dev, im, IGMP_HOST_MEMBERSHIP_REPORT); in igmp_timer_expire()
843 igmp_send_report(in_dev, im, IGMPV2_HOST_MEMBERSHIP_REPORT); in igmp_timer_expire()
845 igmp_send_report(in_dev, im, IGMPV3_HOST_MEMBERSHIP_REPORT); in igmp_timer_expire()
847 ip_ma_put(im); in igmp_timer_expire()
850 /* mark EXCLUDE-mode sources */
857 for (psf = pmc->sources; psf; psf = psf->sf_next) { in igmp_xmarksources()
862 if (psf->sf_count[MCAST_INCLUDE] || in igmp_xmarksources()
863 pmc->sfcount[MCAST_EXCLUDE] != in igmp_xmarksources()
864 psf->sf_count[MCAST_EXCLUDE]) in igmp_xmarksources()
866 if (srcs[i] == psf->sf_inaddr) { in igmp_xmarksources()
872 pmc->gsquery = 0; in igmp_xmarksources()
883 if (pmc->sfmode == MCAST_EXCLUDE) in igmp_marksources()
886 /* mark INCLUDE-mode sources */ in igmp_marksources()
888 for (psf = pmc->sources; psf; psf = psf->sf_next) { in igmp_marksources()
892 if (srcs[i] == psf->sf_inaddr) { in igmp_marksources()
893 psf->sf_gsresp = 1; in igmp_marksources()
899 pmc->gsquery = 0; in igmp_marksources()
902 pmc->gsquery = 1; in igmp_marksources()
909 struct ip_mc_list *im; in igmp_heard_report() local
910 struct net *net = dev_net(in_dev->dev); in igmp_heard_report()
912 /* Timers are only set for non-local groups */ in igmp_heard_report()
916 if (ipv4_is_local_multicast(group) && !net->ipv4.sysctl_igmp_llm_reports) in igmp_heard_report()
920 for_each_pmc_rcu(in_dev, im) { in igmp_heard_report()
921 if (im->multiaddr == group) { in igmp_heard_report()
922 igmp_stop_timer(im); in igmp_heard_report()
936 struct ip_mc_list *im; in igmp_heard_query() local
937 __be32 group = ih->group; in igmp_heard_query()
940 struct net *net = dev_net(in_dev->dev); in igmp_heard_query()
944 if (ih->code == 0) { in igmp_heard_query()
948 in_dev->mr_v1_seen = jiffies + in igmp_heard_query()
949 (in_dev->mr_qrv * in_dev->mr_qi) + in igmp_heard_query()
950 in_dev->mr_qri; in igmp_heard_query()
954 max_delay = ih->code*(HZ/IGMP_TIMER_SCALE); in igmp_heard_query()
955 in_dev->mr_v2_seen = jiffies + in igmp_heard_query()
956 (in_dev->mr_qrv * in_dev->mr_qi) + in igmp_heard_query()
957 in_dev->mr_qri; in igmp_heard_query()
960 in_dev->mr_ifc_count = 0; in igmp_heard_query()
961 if (del_timer(&in_dev->mr_ifc_timer)) in igmp_heard_query()
978 max_delay = IGMPV3_MRC(ih3->code)*(HZ/IGMP_TIMER_SCALE); in igmp_heard_query()
986 if (ih3->nsrcs) { in igmp_heard_query()
988 + ntohs(ih3->nsrcs)*sizeof(__be32))) in igmp_heard_query()
993 max_delay = IGMPV3_MRC(ih3->code)*(HZ/IGMP_TIMER_SCALE); in igmp_heard_query()
996 in_dev->mr_maxdelay = max_delay; in igmp_heard_query()
1002 in_dev->mr_qrv = ih3->qrv ?: net->ipv4.sysctl_igmp_qrv; in igmp_heard_query()
1003 in_dev->mr_qi = IGMPV3_QQIC(ih3->qqic)*HZ ?: IGMP_QUERY_INTERVAL; in igmp_heard_query()
1009 if (in_dev->mr_qri >= in_dev->mr_qi) in igmp_heard_query()
1010 in_dev->mr_qri = (in_dev->mr_qi/HZ - 1)*HZ; in igmp_heard_query()
1013 if (ih3->nsrcs) in igmp_heard_query()
1018 /* mark sources to include, if group & source-specific */ in igmp_heard_query()
1019 mark = ih3->nsrcs != 0; in igmp_heard_query()
1023 * - Start the timers in all of our membership records in igmp_heard_query()
1027 * - For timers already running check if they need to in igmp_heard_query()
1029 * - Use the igmp->igmp_code field as the maximum in igmp_heard_query()
1033 for_each_pmc_rcu(in_dev, im) { in igmp_heard_query()
1036 if (group && group != im->multiaddr) in igmp_heard_query()
1038 if (im->multiaddr == IGMP_ALL_HOSTS) in igmp_heard_query()
1040 if (ipv4_is_local_multicast(im->multiaddr) && in igmp_heard_query()
1041 !net->ipv4.sysctl_igmp_llm_reports) in igmp_heard_query()
1043 spin_lock_bh(&im->lock); in igmp_heard_query()
1044 if (im->tm_running) in igmp_heard_query()
1045 im->gsquery = im->gsquery && mark; in igmp_heard_query()
1047 im->gsquery = mark; in igmp_heard_query()
1048 changed = !im->gsquery || in igmp_heard_query()
1049 igmp_marksources(im, ntohs(ih3->nsrcs), ih3->srcs); in igmp_heard_query()
1050 spin_unlock_bh(&im->lock); in igmp_heard_query()
1052 igmp_mod_timer(im, max_delay); in igmp_heard_query()
1061 /* This basically follows the spec line by line -- see RFC1112 */ in igmp_rcv()
1063 struct net_device *dev = skb->dev; in igmp_rcv()
1065 int len = skb->len; in igmp_rcv()
1069 dev = dev_get_by_index_rcu(dev_net(dev), IPCB(skb)->iif); in igmp_rcv()
1085 switch (ih->type) { in igmp_rcv()
1095 if (skb->pkt_type == PACKET_MULTICAST || in igmp_rcv()
1096 skb->pkt_type == PACKET_BROADCAST) in igmp_rcv()
1097 dropped = igmp_heard_report(in_dev, ih->group); in igmp_rcv()
1132 struct net_device *dev = in_dev->dev; in ip_mc_filter_add()
1134 /* Checking for IFF_MULTICAST here is WRONG-WRONG-WRONG. in ip_mc_filter_add()
1138 if (dev->mc_list && dev->flags&IFF_MULTICAST) { do it; } in ip_mc_filter_add()
1139 --ANK in ip_mc_filter_add()
1152 struct net_device *dev = in_dev->dev; in ip_mc_filter_del()
1162 static void igmpv3_add_delrec(struct in_device *in_dev, struct ip_mc_list *im, in igmpv3_add_delrec() argument
1166 struct net *net = dev_net(in_dev->dev); in igmpv3_add_delrec()
1172 * non-deleted or query-response MCA's. in igmpv3_add_delrec()
1177 spin_lock_init(&pmc->lock); in igmpv3_add_delrec()
1178 spin_lock_bh(&im->lock); in igmpv3_add_delrec()
1179 pmc->interface = im->interface; in igmpv3_add_delrec()
1181 pmc->multiaddr = im->multiaddr; in igmpv3_add_delrec()
1182 pmc->crcount = in_dev->mr_qrv ?: net->ipv4.sysctl_igmp_qrv; in igmpv3_add_delrec()
1183 pmc->sfmode = im->sfmode; in igmpv3_add_delrec()
1184 if (pmc->sfmode == MCAST_INCLUDE) { in igmpv3_add_delrec()
1187 pmc->tomb = im->tomb; in igmpv3_add_delrec()
1188 pmc->sources = im->sources; in igmpv3_add_delrec()
1189 im->tomb = im->sources = NULL; in igmpv3_add_delrec()
1190 for (psf = pmc->sources; psf; psf = psf->sf_next) in igmpv3_add_delrec()
1191 psf->sf_crcount = pmc->crcount; in igmpv3_add_delrec()
1193 spin_unlock_bh(&im->lock); in igmpv3_add_delrec()
1195 spin_lock_bh(&in_dev->mc_tomb_lock); in igmpv3_add_delrec()
1196 pmc->next = in_dev->mc_tomb; in igmpv3_add_delrec()
1197 in_dev->mc_tomb = pmc; in igmpv3_add_delrec()
1198 spin_unlock_bh(&in_dev->mc_tomb_lock); in igmpv3_add_delrec()
1204 static void igmpv3_del_delrec(struct in_device *in_dev, struct ip_mc_list *im) in igmpv3_del_delrec() argument
1208 struct net *net = dev_net(in_dev->dev); in igmpv3_del_delrec()
1209 __be32 multiaddr = im->multiaddr; in igmpv3_del_delrec()
1211 spin_lock_bh(&in_dev->mc_tomb_lock); in igmpv3_del_delrec()
1213 for (pmc = in_dev->mc_tomb; pmc; pmc = pmc->next) { in igmpv3_del_delrec()
1214 if (pmc->multiaddr == multiaddr) in igmpv3_del_delrec()
1220 pmc_prev->next = pmc->next; in igmpv3_del_delrec()
1222 in_dev->mc_tomb = pmc->next; in igmpv3_del_delrec()
1224 spin_unlock_bh(&in_dev->mc_tomb_lock); in igmpv3_del_delrec()
1226 spin_lock_bh(&im->lock); in igmpv3_del_delrec()
1228 im->interface = pmc->interface; in igmpv3_del_delrec()
1229 if (im->sfmode == MCAST_INCLUDE) { in igmpv3_del_delrec()
1230 swap(im->tomb, pmc->tomb); in igmpv3_del_delrec()
1231 swap(im->sources, pmc->sources); in igmpv3_del_delrec()
1232 for (psf = im->sources; psf; psf = psf->sf_next) in igmpv3_del_delrec()
1233 psf->sf_crcount = in_dev->mr_qrv ?: net->ipv4.sysctl_igmp_qrv; in igmpv3_del_delrec()
1235 im->crcount = in_dev->mr_qrv ?: net->ipv4.sysctl_igmp_qrv; in igmpv3_del_delrec()
1237 in_dev_put(pmc->interface); in igmpv3_del_delrec()
1240 spin_unlock_bh(&im->lock); in igmpv3_del_delrec()
1250 spin_lock_bh(&in_dev->mc_tomb_lock); in igmpv3_clear_delrec()
1251 pmc = in_dev->mc_tomb; in igmpv3_clear_delrec()
1252 in_dev->mc_tomb = NULL; in igmpv3_clear_delrec()
1253 spin_unlock_bh(&in_dev->mc_tomb_lock); in igmpv3_clear_delrec()
1256 nextpmc = pmc->next; in igmpv3_clear_delrec()
1258 in_dev_put(pmc->interface); in igmpv3_clear_delrec()
1266 spin_lock_bh(&pmc->lock); in igmpv3_clear_delrec()
1267 psf = pmc->tomb; in igmpv3_clear_delrec()
1268 pmc->tomb = NULL; in igmpv3_clear_delrec()
1269 spin_unlock_bh(&pmc->lock); in igmpv3_clear_delrec()
1276 static void __igmp_group_dropped(struct ip_mc_list *im, gfp_t gfp) in __igmp_group_dropped() argument
1278 struct in_device *in_dev = im->interface; in __igmp_group_dropped()
1280 struct net *net = dev_net(in_dev->dev); in __igmp_group_dropped()
1284 if (im->loaded) { in __igmp_group_dropped()
1285 im->loaded = 0; in __igmp_group_dropped()
1286 ip_mc_filter_del(in_dev, im->multiaddr); in __igmp_group_dropped()
1290 if (im->multiaddr == IGMP_ALL_HOSTS) in __igmp_group_dropped()
1292 if (ipv4_is_local_multicast(im->multiaddr) && !net->ipv4.sysctl_igmp_llm_reports) in __igmp_group_dropped()
1295 reporter = im->reporter; in __igmp_group_dropped()
1296 igmp_stop_timer(im); in __igmp_group_dropped()
1298 if (!in_dev->dead) { in __igmp_group_dropped()
1303 igmp_send_report(in_dev, im, IGMP_HOST_LEAVE_MESSAGE); in __igmp_group_dropped()
1307 igmpv3_add_delrec(in_dev, im, gfp); in __igmp_group_dropped()
1314 static void igmp_group_dropped(struct ip_mc_list *im) in igmp_group_dropped() argument
1316 __igmp_group_dropped(im, GFP_KERNEL); in igmp_group_dropped()
1319 static void igmp_group_added(struct ip_mc_list *im) in igmp_group_added() argument
1321 struct in_device *in_dev = im->interface; in igmp_group_added()
1323 struct net *net = dev_net(in_dev->dev); in igmp_group_added()
1326 if (im->loaded == 0) { in igmp_group_added()
1327 im->loaded = 1; in igmp_group_added()
1328 ip_mc_filter_add(in_dev, im->multiaddr); in igmp_group_added()
1332 if (im->multiaddr == IGMP_ALL_HOSTS) in igmp_group_added()
1334 if (ipv4_is_local_multicast(im->multiaddr) && !net->ipv4.sysctl_igmp_llm_reports) in igmp_group_added()
1337 if (in_dev->dead) in igmp_group_added()
1340 im->unsolicit_count = net->ipv4.sysctl_igmp_qrv; in igmp_group_added()
1342 spin_lock_bh(&im->lock); in igmp_group_added()
1343 igmp_start_timer(im, IGMP_INITIAL_REPORT_DELAY); in igmp_group_added()
1344 spin_unlock_bh(&im->lock); in igmp_group_added()
1350 * not send filter-mode change record as the mode should be from in igmp_group_added()
1353 if (im->sfmode == MCAST_EXCLUDE) in igmp_group_added()
1354 im->crcount = in_dev->mr_qrv ?: net->ipv4.sysctl_igmp_qrv; in igmp_group_added()
1365 static u32 ip_mc_hash(const struct ip_mc_list *im) in ip_mc_hash() argument
1367 return hash_32((__force u32)im->multiaddr, MC_HASH_SZ_LOG); in ip_mc_hash()
1371 struct ip_mc_list *im) in ip_mc_hash_add() argument
1376 mc_hash = rtnl_dereference(in_dev->mc_hash); in ip_mc_hash_add()
1378 hash = ip_mc_hash(im); in ip_mc_hash_add()
1379 im->next_hash = mc_hash[hash]; in ip_mc_hash_add()
1380 rcu_assign_pointer(mc_hash[hash], im); in ip_mc_hash_add()
1385 if (in_dev->mc_count < 4) in ip_mc_hash_add()
1393 for_each_pmc_rtnl(in_dev, im) { in ip_mc_hash_add()
1394 hash = ip_mc_hash(im); in ip_mc_hash_add()
1395 im->next_hash = mc_hash[hash]; in ip_mc_hash_add()
1396 RCU_INIT_POINTER(mc_hash[hash], im); in ip_mc_hash_add()
1399 rcu_assign_pointer(in_dev->mc_hash, mc_hash); in ip_mc_hash_add()
1403 struct ip_mc_list *im) in ip_mc_hash_remove() argument
1405 struct ip_mc_list __rcu **mc_hash = rtnl_dereference(in_dev->mc_hash); in ip_mc_hash_remove()
1410 mc_hash += ip_mc_hash(im); in ip_mc_hash_remove()
1411 while ((aux = rtnl_dereference(*mc_hash)) != im) in ip_mc_hash_remove()
1412 mc_hash = &aux->next_hash; in ip_mc_hash_remove()
1413 *mc_hash = im->next_hash; in ip_mc_hash_remove()
1423 struct ip_mc_list *im; in ____ip_mc_inc_group() local
1427 for_each_pmc_rtnl(in_dev, im) { in ____ip_mc_inc_group()
1428 if (im->multiaddr == addr) { in ____ip_mc_inc_group()
1429 im->users++; in ____ip_mc_inc_group()
1435 im = kzalloc(sizeof(*im), gfp); in ____ip_mc_inc_group()
1436 if (!im) in ____ip_mc_inc_group()
1439 im->users = 1; in ____ip_mc_inc_group()
1440 im->interface = in_dev; in ____ip_mc_inc_group()
1442 im->multiaddr = addr; in ____ip_mc_inc_group()
1444 im->sfmode = mode; in ____ip_mc_inc_group()
1445 im->sfcount[mode] = 1; in ____ip_mc_inc_group()
1446 refcount_set(&im->refcnt, 1); in ____ip_mc_inc_group()
1447 spin_lock_init(&im->lock); in ____ip_mc_inc_group()
1449 timer_setup(&im->timer, igmp_timer_expire, 0); in ____ip_mc_inc_group()
1452 im->next_rcu = in_dev->mc_list; in ____ip_mc_inc_group()
1453 in_dev->mc_count++; in ____ip_mc_inc_group()
1454 rcu_assign_pointer(in_dev->mc_list, im); in ____ip_mc_inc_group()
1456 ip_mc_hash_add(in_dev, im); in ____ip_mc_inc_group()
1459 igmpv3_del_delrec(in_dev, im); in ____ip_mc_inc_group()
1461 igmp_group_added(im); in ____ip_mc_inc_group()
1462 if (!in_dev->dead) in ____ip_mc_inc_group()
1487 return -EINVAL; in ip_mc_check_iphdr()
1491 if (iph->version != 4 || ip_hdrlen(skb) < sizeof(*iph)) in ip_mc_check_iphdr()
1492 return -EINVAL; in ip_mc_check_iphdr()
1494 offset += ip_hdrlen(skb) - sizeof(*iph); in ip_mc_check_iphdr()
1497 return -EINVAL; in ip_mc_check_iphdr()
1501 if (unlikely(ip_fast_csum((u8 *)iph, iph->ihl))) in ip_mc_check_iphdr()
1502 return -EINVAL; in ip_mc_check_iphdr()
1504 len = skb_network_offset(skb) + ntohs(iph->tot_len); in ip_mc_check_iphdr()
1505 if (skb->len < len || len < offset) in ip_mc_check_iphdr()
1506 return -EINVAL; in ip_mc_check_iphdr()
1519 return ip_mc_may_pull(skb, len) ? 0 : -EINVAL; in ip_mc_check_igmp_reportv3()
1531 return -EINVAL; in ip_mc_check_igmp_query()
1535 return -EINVAL; in ip_mc_check_igmp_query()
1539 * all-systems destination addresses (224.0.0.1) for general queries in ip_mc_check_igmp_query()
1541 if (!igmp_hdr(skb)->group && in ip_mc_check_igmp_query()
1542 ip_hdr(skb)->daddr != htonl(INADDR_ALLHOSTS_GROUP)) in ip_mc_check_igmp_query()
1543 return -EINVAL; in ip_mc_check_igmp_query()
1550 switch (igmp_hdr(skb)->type) { in ip_mc_check_igmp_msg()
1560 return -ENOMSG; in ip_mc_check_igmp_msg()
1576 return -EINVAL; in ip_mc_check_igmp_csum()
1581 return -EINVAL; in ip_mc_check_igmp_csum()
1590 * ip_mc_check_igmp - checks whether this is a sane IGMP packet
1596 * -EINVAL: A broken packet was detected, i.e. it violates some internet
1598 * -ENOMSG: IP header validation succeeded but it is not an IGMP packet.
1599 * -ENOMEM: A memory allocation failure happened.
1611 if (ip_hdr(skb)->protocol != IPPROTO_IGMP) in ip_mc_check_igmp()
1612 return -ENOMSG; in ip_mc_check_igmp()
1628 struct ip_mc_list *im; in ip_mc_rejoin_groups() local
1630 struct net *net = dev_net(in_dev->dev); in ip_mc_rejoin_groups()
1634 for_each_pmc_rtnl(in_dev, im) { in ip_mc_rejoin_groups()
1635 if (im->multiaddr == IGMP_ALL_HOSTS) in ip_mc_rejoin_groups()
1637 if (ipv4_is_local_multicast(im->multiaddr) && in ip_mc_rejoin_groups()
1638 !net->ipv4.sysctl_igmp_llm_reports) in ip_mc_rejoin_groups()
1650 igmp_send_report(in_dev, im, type); in ip_mc_rejoin_groups()
1666 for (ip = &in_dev->mc_list; in __ip_mc_dec_group()
1668 ip = &i->next_rcu) { in __ip_mc_dec_group()
1669 if (i->multiaddr == addr) { in __ip_mc_dec_group()
1670 if (--i->users == 0) { in __ip_mc_dec_group()
1672 *ip = i->next_rcu; in __ip_mc_dec_group()
1673 in_dev->mc_count--; in __ip_mc_dec_group()
1677 if (!in_dev->dead) in __ip_mc_dec_group()
1727 in_dev->mr_ifc_count = 0; in ip_mc_down()
1728 if (del_timer(&in_dev->mr_ifc_timer)) in ip_mc_down()
1730 in_dev->mr_gq_running = 0; in ip_mc_down()
1731 if (del_timer(&in_dev->mr_gq_timer)) in ip_mc_down()
1741 struct net *net = dev_net(in_dev->dev); in ip_mc_reset()
1743 in_dev->mr_qi = IGMP_QUERY_INTERVAL; in ip_mc_reset()
1744 in_dev->mr_qri = IGMP_QUERY_RESPONSE_INTERVAL; in ip_mc_reset()
1745 in_dev->mr_qrv = net->ipv4.sysctl_igmp_qrv; in ip_mc_reset()
1758 timer_setup(&in_dev->mr_gq_timer, igmp_gq_timer_expire, 0); in ip_mc_init_dev()
1759 timer_setup(&in_dev->mr_ifc_timer, igmp_ifc_timer_expire, 0); in ip_mc_init_dev()
1763 spin_lock_init(&in_dev->mc_tomb_lock); in ip_mc_init_dev()
1801 while ((i = rtnl_dereference(in_dev->mc_list)) != NULL) { in ip_mc_destroy_dev()
1802 in_dev->mc_list = i->next_rcu; in ip_mc_destroy_dev()
1803 in_dev->mc_count--; in ip_mc_destroy_dev()
1814 if (imr->imr_ifindex) { in ip_mc_find_dev()
1815 idev = inetdev_by_index(net, imr->imr_ifindex); in ip_mc_find_dev()
1818 if (imr->imr_address.s_addr) { in ip_mc_find_dev()
1819 dev = __ip_dev_find(net, imr->imr_address.s_addr, false); in ip_mc_find_dev()
1826 imr->imr_multiaddr.s_addr, in ip_mc_find_dev()
1829 dev = rt->dst.dev; in ip_mc_find_dev()
1834 imr->imr_ifindex = dev->ifindex; in ip_mc_find_dev()
1851 for (psf = pmc->sources; psf; psf = psf->sf_next) { in ip_mc_del1_src()
1852 if (psf->sf_inaddr == *psfsrc) in ip_mc_del1_src()
1856 if (!psf || psf->sf_count[sfmode] == 0) { in ip_mc_del1_src()
1858 return -ESRCH; in ip_mc_del1_src()
1860 psf->sf_count[sfmode]--; in ip_mc_del1_src()
1861 if (psf->sf_count[sfmode] == 0) { in ip_mc_del1_src()
1862 ip_rt_multicast_event(pmc->interface); in ip_mc_del1_src()
1864 if (!psf->sf_count[MCAST_INCLUDE] && !psf->sf_count[MCAST_EXCLUDE]) { in ip_mc_del1_src()
1866 struct in_device *in_dev = pmc->interface; in ip_mc_del1_src()
1867 struct net *net = dev_net(in_dev->dev); in ip_mc_del1_src()
1872 psf_prev->sf_next = psf->sf_next; in ip_mc_del1_src()
1874 pmc->sources = psf->sf_next; in ip_mc_del1_src()
1876 if (psf->sf_oldin && in ip_mc_del1_src()
1878 psf->sf_crcount = in_dev->mr_qrv ?: net->ipv4.sysctl_igmp_qrv; in ip_mc_del1_src()
1879 psf->sf_next = pmc->tomb; in ip_mc_del1_src()
1880 pmc->tomb = psf; in ip_mc_del1_src()
1901 return -ENODEV; in ip_mc_del_src()
1904 if (*pmca == pmc->multiaddr) in ip_mc_del_src()
1910 return -ESRCH; in ip_mc_del_src()
1912 spin_lock_bh(&pmc->lock); in ip_mc_del_src()
1918 err = -EINVAL; in ip_mc_del_src()
1919 if (!pmc->sfcount[sfmode]) in ip_mc_del_src()
1921 pmc->sfcount[sfmode]--; in ip_mc_del_src()
1931 if (pmc->sfmode == MCAST_EXCLUDE && in ip_mc_del_src()
1932 pmc->sfcount[MCAST_EXCLUDE] == 0 && in ip_mc_del_src()
1933 pmc->sfcount[MCAST_INCLUDE]) { in ip_mc_del_src()
1936 struct net *net = dev_net(in_dev->dev); in ip_mc_del_src()
1940 pmc->sfmode = MCAST_INCLUDE; in ip_mc_del_src()
1942 pmc->crcount = in_dev->mr_qrv ?: net->ipv4.sysctl_igmp_qrv; in ip_mc_del_src()
1943 in_dev->mr_ifc_count = pmc->crcount; in ip_mc_del_src()
1944 for (psf = pmc->sources; psf; psf = psf->sf_next) in ip_mc_del_src()
1945 psf->sf_crcount = 0; in ip_mc_del_src()
1946 igmp_ifc_event(pmc->interface); in ip_mc_del_src()
1948 igmp_ifc_event(pmc->interface); in ip_mc_del_src()
1952 spin_unlock_bh(&pmc->lock); in ip_mc_del_src()
1957 * Add multicast single-source filter to the interface list
1965 for (psf = pmc->sources; psf; psf = psf->sf_next) { in ip_mc_add1_src()
1966 if (psf->sf_inaddr == *psfsrc) in ip_mc_add1_src()
1973 return -ENOBUFS; in ip_mc_add1_src()
1974 psf->sf_inaddr = *psfsrc; in ip_mc_add1_src()
1976 psf_prev->sf_next = psf; in ip_mc_add1_src()
1978 pmc->sources = psf; in ip_mc_add1_src()
1980 psf->sf_count[sfmode]++; in ip_mc_add1_src()
1981 if (psf->sf_count[sfmode] == 1) { in ip_mc_add1_src()
1982 ip_rt_multicast_event(pmc->interface); in ip_mc_add1_src()
1991 int mca_xcount = pmc->sfcount[MCAST_EXCLUDE]; in sf_markstate()
1993 for (psf = pmc->sources; psf; psf = psf->sf_next) in sf_markstate()
1994 if (pmc->sfcount[MCAST_EXCLUDE]) { in sf_markstate()
1995 psf->sf_oldin = mca_xcount == in sf_markstate()
1996 psf->sf_count[MCAST_EXCLUDE] && in sf_markstate()
1997 !psf->sf_count[MCAST_INCLUDE]; in sf_markstate()
1999 psf->sf_oldin = psf->sf_count[MCAST_INCLUDE] != 0; in sf_markstate()
2005 int mca_xcount = pmc->sfcount[MCAST_EXCLUDE]; in sf_setstate()
2006 int qrv = pmc->interface->mr_qrv; in sf_setstate()
2010 for (psf = pmc->sources; psf; psf = psf->sf_next) { in sf_setstate()
2011 if (pmc->sfcount[MCAST_EXCLUDE]) { in sf_setstate()
2012 new_in = mca_xcount == psf->sf_count[MCAST_EXCLUDE] && in sf_setstate()
2013 !psf->sf_count[MCAST_INCLUDE]; in sf_setstate()
2015 new_in = psf->sf_count[MCAST_INCLUDE] != 0; in sf_setstate()
2017 if (!psf->sf_oldin) { in sf_setstate()
2020 for (dpsf = pmc->tomb; dpsf; dpsf = dpsf->sf_next) { in sf_setstate()
2021 if (dpsf->sf_inaddr == psf->sf_inaddr) in sf_setstate()
2027 prev->sf_next = dpsf->sf_next; in sf_setstate()
2029 pmc->tomb = dpsf->sf_next; in sf_setstate()
2032 psf->sf_crcount = qrv; in sf_setstate()
2035 } else if (psf->sf_oldin) { in sf_setstate()
2037 psf->sf_crcount = 0; in sf_setstate()
2042 for (dpsf = pmc->tomb; dpsf; dpsf = dpsf->sf_next) in sf_setstate()
2043 if (dpsf->sf_inaddr == psf->sf_inaddr) in sf_setstate()
2050 /* pmc->lock held by callers */ in sf_setstate()
2051 dpsf->sf_next = pmc->tomb; in sf_setstate()
2052 pmc->tomb = dpsf; in sf_setstate()
2054 dpsf->sf_crcount = qrv; in sf_setstate()
2073 return -ENODEV; in ip_mc_add_src()
2076 if (*pmca == pmc->multiaddr) in ip_mc_add_src()
2082 return -ESRCH; in ip_mc_add_src()
2084 spin_lock_bh(&pmc->lock); in ip_mc_add_src()
2090 isexclude = pmc->sfmode == MCAST_EXCLUDE; in ip_mc_add_src()
2092 pmc->sfcount[sfmode]++; in ip_mc_add_src()
2103 pmc->sfcount[sfmode]--; in ip_mc_add_src()
2106 } else if (isexclude != (pmc->sfcount[MCAST_EXCLUDE] != 0)) { in ip_mc_add_src()
2109 struct net *net = dev_net(pmc->interface->dev); in ip_mc_add_src()
2110 in_dev = pmc->interface; in ip_mc_add_src()
2114 if (pmc->sfcount[MCAST_EXCLUDE]) in ip_mc_add_src()
2115 pmc->sfmode = MCAST_EXCLUDE; in ip_mc_add_src()
2116 else if (pmc->sfcount[MCAST_INCLUDE]) in ip_mc_add_src()
2117 pmc->sfmode = MCAST_INCLUDE; in ip_mc_add_src()
2121 pmc->crcount = in_dev->mr_qrv ?: net->ipv4.sysctl_igmp_qrv; in ip_mc_add_src()
2122 in_dev->mr_ifc_count = pmc->crcount; in ip_mc_add_src()
2123 for (psf = pmc->sources; psf; psf = psf->sf_next) in ip_mc_add_src()
2124 psf->sf_crcount = 0; in ip_mc_add_src()
2130 spin_unlock_bh(&pmc->lock); in ip_mc_add_src()
2138 spin_lock_bh(&pmc->lock); in ip_mc_clear_src()
2139 tomb = pmc->tomb; in ip_mc_clear_src()
2140 pmc->tomb = NULL; in ip_mc_clear_src()
2141 sources = pmc->sources; in ip_mc_clear_src()
2142 pmc->sources = NULL; in ip_mc_clear_src()
2143 pmc->sfmode = MCAST_EXCLUDE; in ip_mc_clear_src()
2144 pmc->sfcount[MCAST_INCLUDE] = 0; in ip_mc_clear_src()
2145 pmc->sfcount[MCAST_EXCLUDE] = 1; in ip_mc_clear_src()
2146 spin_unlock_bh(&pmc->lock); in ip_mc_clear_src()
2157 __be32 addr = imr->imr_multiaddr.s_addr; in __ip_mc_join_group()
2169 return -EINVAL; in __ip_mc_join_group()
2174 err = -ENODEV; in __ip_mc_join_group()
2178 err = -EADDRINUSE; in __ip_mc_join_group()
2179 ifindex = imr->imr_ifindex; in __ip_mc_join_group()
2181 if (i->multi.imr_multiaddr.s_addr == addr && in __ip_mc_join_group()
2182 i->multi.imr_ifindex == ifindex) in __ip_mc_join_group()
2186 err = -ENOBUFS; in __ip_mc_join_group()
2187 if (count >= net->ipv4.sysctl_igmp_max_memberships) in __ip_mc_join_group()
2193 memcpy(&iml->multi, imr, sizeof(*imr)); in __ip_mc_join_group()
2194 iml->next_rcu = inet->mc_list; in __ip_mc_join_group()
2195 iml->sflist = NULL; in __ip_mc_join_group()
2196 iml->sfmode = mode; in __ip_mc_join_group()
2197 rcu_assign_pointer(inet->mc_list, iml); in __ip_mc_join_group()
2204 /* Join ASM (Any-Source Multicast) group
2212 /* Join SSM (Source-Specific Multicast) group
2223 struct ip_sf_socklist *psf = rtnl_dereference(iml->sflist); in ip_mc_leave_src()
2227 /* any-source empty exclude case */ in ip_mc_leave_src()
2228 return ip_mc_del_src(in_dev, &iml->multi.imr_multiaddr.s_addr, in ip_mc_leave_src()
2229 iml->sfmode, 0, NULL, 0); in ip_mc_leave_src()
2231 err = ip_mc_del_src(in_dev, &iml->multi.imr_multiaddr.s_addr, in ip_mc_leave_src()
2232 iml->sfmode, psf->sl_count, psf->sl_addr, 0); in ip_mc_leave_src()
2233 RCU_INIT_POINTER(iml->sflist, NULL); in ip_mc_leave_src()
2235 atomic_sub(IP_SFLSIZE(psf->sl_max), &sk->sk_omem_alloc); in ip_mc_leave_src()
2247 __be32 group = imr->imr_multiaddr.s_addr; in ip_mc_leave_group()
2249 int ret = -EADDRNOTAVAIL; in ip_mc_leave_group()
2254 if (!imr->imr_ifindex && !imr->imr_address.s_addr && !in_dev) { in ip_mc_leave_group()
2255 ret = -ENODEV; in ip_mc_leave_group()
2258 ifindex = imr->imr_ifindex; in ip_mc_leave_group()
2259 for (imlp = &inet->mc_list; in ip_mc_leave_group()
2261 imlp = &iml->next_rcu) { in ip_mc_leave_group()
2262 if (iml->multi.imr_multiaddr.s_addr != group) in ip_mc_leave_group()
2265 if (iml->multi.imr_ifindex != ifindex) in ip_mc_leave_group()
2267 } else if (imr->imr_address.s_addr && imr->imr_address.s_addr != in ip_mc_leave_group()
2268 iml->multi.imr_address.s_addr) in ip_mc_leave_group()
2273 *imlp = iml->next_rcu; in ip_mc_leave_group()
2279 atomic_sub(sizeof(*iml), &sk->sk_omem_alloc); in ip_mc_leave_group()
2293 __be32 addr = mreqs->imr_multiaddr; in ip_mc_source()
2303 return -EINVAL; in ip_mc_source()
2307 imr.imr_multiaddr.s_addr = mreqs->imr_multiaddr; in ip_mc_source()
2308 imr.imr_address.s_addr = mreqs->imr_interface; in ip_mc_source()
2313 err = -ENODEV; in ip_mc_source()
2316 err = -EADDRNOTAVAIL; in ip_mc_source()
2319 if ((pmc->multi.imr_multiaddr.s_addr == in ip_mc_source()
2321 (pmc->multi.imr_ifindex == imr.imr_ifindex)) in ip_mc_source()
2325 err = -EINVAL; in ip_mc_source()
2329 if (pmc->sflist) { in ip_mc_source()
2330 if (pmc->sfmode != omode) { in ip_mc_source()
2331 err = -EINVAL; in ip_mc_source()
2334 } else if (pmc->sfmode != omode) { in ip_mc_source()
2335 /* allow mode switches for empty-set filters */ in ip_mc_source()
2336 ip_mc_add_src(in_dev, &mreqs->imr_multiaddr, omode, 0, NULL, 0); in ip_mc_source()
2337 ip_mc_del_src(in_dev, &mreqs->imr_multiaddr, pmc->sfmode, 0, in ip_mc_source()
2339 pmc->sfmode = omode; in ip_mc_source()
2342 psl = rtnl_dereference(pmc->sflist); in ip_mc_source()
2345 goto done; /* err = -EADDRNOTAVAIL */ in ip_mc_source()
2347 for (i = 0; i < psl->sl_count; i++) { in ip_mc_source()
2348 rv = memcmp(&psl->sl_addr[i], &mreqs->imr_sourceaddr, in ip_mc_source()
2354 goto done; /* err = -EADDRNOTAVAIL */ in ip_mc_source()
2356 /* special case - (INCLUDE, empty) == LEAVE_GROUP */ in ip_mc_source()
2357 if (psl->sl_count == 1 && omode == MCAST_INCLUDE) { in ip_mc_source()
2363 ip_mc_del_src(in_dev, &mreqs->imr_multiaddr, omode, 1, in ip_mc_source()
2364 &mreqs->imr_sourceaddr, 1); in ip_mc_source()
2366 for (j = i+1; j < psl->sl_count; j++) in ip_mc_source()
2367 psl->sl_addr[j-1] = psl->sl_addr[j]; in ip_mc_source()
2368 psl->sl_count--; in ip_mc_source()
2374 if (psl && psl->sl_count >= net->ipv4.sysctl_igmp_max_msf) { in ip_mc_source()
2375 err = -ENOBUFS; in ip_mc_source()
2378 if (!psl || psl->sl_count == psl->sl_max) { in ip_mc_source()
2383 count += psl->sl_max; in ip_mc_source()
2386 err = -ENOBUFS; in ip_mc_source()
2389 newpsl->sl_max = count; in ip_mc_source()
2390 newpsl->sl_count = count - IP_SFBLOCK; in ip_mc_source()
2392 for (i = 0; i < psl->sl_count; i++) in ip_mc_source()
2393 newpsl->sl_addr[i] = psl->sl_addr[i]; in ip_mc_source()
2395 atomic_sub(IP_SFLSIZE(psl->sl_max), &sk->sk_omem_alloc); in ip_mc_source()
2398 rcu_assign_pointer(pmc->sflist, newpsl); in ip_mc_source()
2402 for (i = 0; i < psl->sl_count; i++) { in ip_mc_source()
2403 rv = memcmp(&psl->sl_addr[i], &mreqs->imr_sourceaddr, in ip_mc_source()
2410 for (j = psl->sl_count-1; j >= i; j--) in ip_mc_source()
2411 psl->sl_addr[j+1] = psl->sl_addr[j]; in ip_mc_source()
2412 psl->sl_addr[i] = mreqs->imr_sourceaddr; in ip_mc_source()
2413 psl->sl_count++; in ip_mc_source()
2416 ip_mc_add_src(in_dev, &mreqs->imr_multiaddr, omode, 1, in ip_mc_source()
2417 &mreqs->imr_sourceaddr, 1); in ip_mc_source()
2428 __be32 addr = msf->imsf_multiaddr; in ip_mc_msfilter()
2437 return -EINVAL; in ip_mc_msfilter()
2438 if (msf->imsf_fmode != MCAST_INCLUDE && in ip_mc_msfilter()
2439 msf->imsf_fmode != MCAST_EXCLUDE) in ip_mc_msfilter()
2440 return -EINVAL; in ip_mc_msfilter()
2444 imr.imr_multiaddr.s_addr = msf->imsf_multiaddr; in ip_mc_msfilter()
2445 imr.imr_address.s_addr = msf->imsf_interface; in ip_mc_msfilter()
2450 err = -ENODEV; in ip_mc_msfilter()
2454 /* special case - (INCLUDE, empty) == LEAVE_GROUP */ in ip_mc_msfilter()
2455 if (msf->imsf_fmode == MCAST_INCLUDE && msf->imsf_numsrc == 0) { in ip_mc_msfilter()
2461 if (pmc->multi.imr_multiaddr.s_addr == msf->imsf_multiaddr && in ip_mc_msfilter()
2462 pmc->multi.imr_ifindex == imr.imr_ifindex) in ip_mc_msfilter()
2466 err = -EINVAL; in ip_mc_msfilter()
2469 if (msf->imsf_numsrc) { in ip_mc_msfilter()
2470 newpsl = sock_kmalloc(sk, IP_SFLSIZE(msf->imsf_numsrc), in ip_mc_msfilter()
2473 err = -ENOBUFS; in ip_mc_msfilter()
2476 newpsl->sl_max = newpsl->sl_count = msf->imsf_numsrc; in ip_mc_msfilter()
2477 memcpy(newpsl->sl_addr, msf->imsf_slist, in ip_mc_msfilter()
2478 msf->imsf_numsrc * sizeof(msf->imsf_slist[0])); in ip_mc_msfilter()
2479 err = ip_mc_add_src(in_dev, &msf->imsf_multiaddr, in ip_mc_msfilter()
2480 msf->imsf_fmode, newpsl->sl_count, newpsl->sl_addr, 0); in ip_mc_msfilter()
2482 sock_kfree_s(sk, newpsl, IP_SFLSIZE(newpsl->sl_max)); in ip_mc_msfilter()
2487 (void) ip_mc_add_src(in_dev, &msf->imsf_multiaddr, in ip_mc_msfilter()
2488 msf->imsf_fmode, 0, NULL, 0); in ip_mc_msfilter()
2490 psl = rtnl_dereference(pmc->sflist); in ip_mc_msfilter()
2492 (void) ip_mc_del_src(in_dev, &msf->imsf_multiaddr, pmc->sfmode, in ip_mc_msfilter()
2493 psl->sl_count, psl->sl_addr, 0); in ip_mc_msfilter()
2495 atomic_sub(IP_SFLSIZE(psl->sl_max), &sk->sk_omem_alloc); in ip_mc_msfilter()
2498 (void) ip_mc_del_src(in_dev, &msf->imsf_multiaddr, pmc->sfmode, in ip_mc_msfilter()
2500 rcu_assign_pointer(pmc->sflist, newpsl); in ip_mc_msfilter()
2501 pmc->sfmode = msf->imsf_fmode; in ip_mc_msfilter()
2514 __be32 addr = msf->imsf_multiaddr; in ip_mc_msfget()
2524 return -EINVAL; in ip_mc_msfget()
2526 imr.imr_multiaddr.s_addr = msf->imsf_multiaddr; in ip_mc_msfget()
2527 imr.imr_address.s_addr = msf->imsf_interface; in ip_mc_msfget()
2532 err = -ENODEV; in ip_mc_msfget()
2535 err = -EADDRNOTAVAIL; in ip_mc_msfget()
2538 if (pmc->multi.imr_multiaddr.s_addr == msf->imsf_multiaddr && in ip_mc_msfget()
2539 pmc->multi.imr_ifindex == imr.imr_ifindex) in ip_mc_msfget()
2544 msf->imsf_fmode = pmc->sfmode; in ip_mc_msfget()
2545 psl = rtnl_dereference(pmc->sflist); in ip_mc_msfget()
2550 count = psl->sl_count; in ip_mc_msfget()
2552 copycount = count < msf->imsf_numsrc ? count : msf->imsf_numsrc; in ip_mc_msfget()
2553 len = copycount * sizeof(psl->sl_addr[0]); in ip_mc_msfget()
2554 msf->imsf_numsrc = count; in ip_mc_msfget()
2557 return -EFAULT; in ip_mc_msfget()
2560 copy_to_user(&optval->imsf_slist[0], psl->sl_addr, len)) in ip_mc_msfget()
2561 return -EFAULT; in ip_mc_msfget()
2579 psin = (struct sockaddr_in *)&gsf->gf_group; in ip_mc_gsfget()
2580 if (psin->sin_family != AF_INET) in ip_mc_gsfget()
2581 return -EINVAL; in ip_mc_gsfget()
2582 addr = psin->sin_addr.s_addr; in ip_mc_gsfget()
2584 return -EINVAL; in ip_mc_gsfget()
2587 if (pmc->multi.imr_multiaddr.s_addr == addr && in ip_mc_gsfget()
2588 pmc->multi.imr_ifindex == gsf->gf_interface) in ip_mc_gsfget()
2592 return -EADDRNOTAVAIL; in ip_mc_gsfget()
2593 gsf->gf_fmode = pmc->sfmode; in ip_mc_gsfget()
2594 psl = rtnl_dereference(pmc->sflist); in ip_mc_gsfget()
2595 count = psl ? psl->sl_count : 0; in ip_mc_gsfget()
2596 copycount = count < gsf->gf_numsrc ? count : gsf->gf_numsrc; in ip_mc_gsfget()
2597 gsf->gf_numsrc = count; in ip_mc_gsfget()
2603 psin->sin_family = AF_INET; in ip_mc_gsfget()
2604 psin->sin_addr.s_addr = psl->sl_addr[i]; in ip_mc_gsfget()
2606 return -EFAULT; in ip_mc_gsfget()
2629 if (pmc->multi.imr_multiaddr.s_addr == loc_addr && in ip_mc_sf_allow()
2630 (pmc->multi.imr_ifindex == dif || in ip_mc_sf_allow()
2631 (sdif && pmc->multi.imr_ifindex == sdif))) in ip_mc_sf_allow()
2634 ret = inet->mc_all; in ip_mc_sf_allow()
2637 psl = rcu_dereference(pmc->sflist); in ip_mc_sf_allow()
2638 ret = (pmc->sfmode == MCAST_EXCLUDE); in ip_mc_sf_allow()
2642 for (i = 0; i < psl->sl_count; i++) { in ip_mc_sf_allow()
2643 if (psl->sl_addr[i] == rmt_addr) in ip_mc_sf_allow()
2647 if (pmc->sfmode == MCAST_INCLUDE && i >= psl->sl_count) in ip_mc_sf_allow()
2649 if (pmc->sfmode == MCAST_EXCLUDE && i < psl->sl_count) in ip_mc_sf_allow()
2668 if (!inet->mc_list) in ip_mc_drop_socket()
2672 while ((iml = rtnl_dereference(inet->mc_list)) != NULL) { in ip_mc_drop_socket()
2675 inet->mc_list = iml->next_rcu; in ip_mc_drop_socket()
2676 in_dev = inetdev_by_index(net, iml->multi.imr_ifindex); in ip_mc_drop_socket()
2679 ip_mc_dec_group(in_dev, iml->multi.imr_multiaddr.s_addr); in ip_mc_drop_socket()
2681 atomic_sub(sizeof(*iml), &sk->sk_omem_alloc); in ip_mc_drop_socket()
2690 struct ip_mc_list *im; in ip_check_mc_rcu() local
2695 mc_hash = rcu_dereference(in_dev->mc_hash); in ip_check_mc_rcu()
2699 for (im = rcu_dereference(mc_hash[hash]); in ip_check_mc_rcu()
2700 im != NULL; in ip_check_mc_rcu()
2701 im = rcu_dereference(im->next_hash)) { in ip_check_mc_rcu()
2702 if (im->multiaddr == mc_addr) in ip_check_mc_rcu()
2706 for_each_pmc_rcu(in_dev, im) { in ip_check_mc_rcu()
2707 if (im->multiaddr == mc_addr) in ip_check_mc_rcu()
2711 if (im && proto == IPPROTO_IGMP) { in ip_check_mc_rcu()
2713 } else if (im) { in ip_check_mc_rcu()
2715 for (psf = im->sources; psf; psf = psf->sf_next) { in ip_check_mc_rcu()
2716 if (psf->sf_inaddr == src_addr) in ip_check_mc_rcu()
2720 rv = psf->sf_count[MCAST_INCLUDE] || in ip_check_mc_rcu()
2721 psf->sf_count[MCAST_EXCLUDE] != in ip_check_mc_rcu()
2722 im->sfcount[MCAST_EXCLUDE]; in ip_check_mc_rcu()
2724 rv = im->sfcount[MCAST_EXCLUDE] != 0; in ip_check_mc_rcu()
2738 #define igmp_mc_seq_private(seq) ((struct igmp_mc_iter_state *)(seq)->private)
2743 struct ip_mc_list *im = NULL; in igmp_mc_get_first() local
2746 state->in_dev = NULL; in igmp_mc_get_first()
2747 for_each_netdev_rcu(net, state->dev) { in igmp_mc_get_first()
2750 in_dev = __in_dev_get_rcu(state->dev); in igmp_mc_get_first()
2753 im = rcu_dereference(in_dev->mc_list); in igmp_mc_get_first()
2754 if (im) { in igmp_mc_get_first()
2755 state->in_dev = in_dev; in igmp_mc_get_first()
2759 return im; in igmp_mc_get_first()
2762 static struct ip_mc_list *igmp_mc_get_next(struct seq_file *seq, struct ip_mc_list *im) in igmp_mc_get_next() argument
2766 im = rcu_dereference(im->next_rcu); in igmp_mc_get_next()
2767 while (!im) { in igmp_mc_get_next()
2768 state->dev = next_net_device_rcu(state->dev); in igmp_mc_get_next()
2769 if (!state->dev) { in igmp_mc_get_next()
2770 state->in_dev = NULL; in igmp_mc_get_next()
2773 state->in_dev = __in_dev_get_rcu(state->dev); in igmp_mc_get_next()
2774 if (!state->in_dev) in igmp_mc_get_next()
2776 im = rcu_dereference(state->in_dev->mc_list); in igmp_mc_get_next()
2778 return im; in igmp_mc_get_next()
2783 struct ip_mc_list *im = igmp_mc_get_first(seq); in igmp_mc_get_idx() local
2784 if (im) in igmp_mc_get_idx()
2785 while (pos && (im = igmp_mc_get_next(seq, im)) != NULL) in igmp_mc_get_idx()
2786 --pos; in igmp_mc_get_idx()
2787 return pos ? NULL : im; in igmp_mc_get_idx()
2794 return *pos ? igmp_mc_get_idx(seq, *pos - 1) : SEQ_START_TOKEN; in igmp_mc_seq_start()
2799 struct ip_mc_list *im; in igmp_mc_seq_next() local
2801 im = igmp_mc_get_first(seq); in igmp_mc_seq_next()
2803 im = igmp_mc_get_next(seq, v); in igmp_mc_seq_next()
2805 return im; in igmp_mc_seq_next()
2813 state->in_dev = NULL; in igmp_mc_seq_stop()
2814 state->dev = NULL; in igmp_mc_seq_stop()
2824 struct ip_mc_list *im = (struct ip_mc_list *)v; in igmp_mc_seq_show() local
2830 querier = IGMP_V1_SEEN(state->in_dev) ? "V1" : in igmp_mc_seq_show()
2831 IGMP_V2_SEEN(state->in_dev) ? "V2" : in igmp_mc_seq_show()
2837 if (rcu_access_pointer(state->in_dev->mc_list) == im) { in igmp_mc_seq_show()
2838 seq_printf(seq, "%d\t%-10s: %5d %7s\n", in igmp_mc_seq_show()
2839 state->dev->ifindex, state->dev->name, state->in_dev->mc_count, querier); in igmp_mc_seq_show()
2842 delta = im->timer.expires - jiffies; in igmp_mc_seq_show()
2845 im->multiaddr, im->users, in igmp_mc_seq_show()
2846 im->tm_running, in igmp_mc_seq_show()
2847 im->tm_running ? jiffies_delta_to_clock_t(delta) : 0, in igmp_mc_seq_show()
2848 im->reporter); in igmp_mc_seq_show()
2864 struct ip_mc_list *im; member
2867 #define igmp_mcf_seq_private(seq) ((struct igmp_mcf_iter_state *)(seq)->private)
2873 struct ip_mc_list *im = NULL; in igmp_mcf_get_first() local
2876 state->idev = NULL; in igmp_mcf_get_first()
2877 state->im = NULL; in igmp_mcf_get_first()
2878 for_each_netdev_rcu(net, state->dev) { in igmp_mcf_get_first()
2880 idev = __in_dev_get_rcu(state->dev); in igmp_mcf_get_first()
2883 im = rcu_dereference(idev->mc_list); in igmp_mcf_get_first()
2884 if (likely(im)) { in igmp_mcf_get_first()
2885 spin_lock_bh(&im->lock); in igmp_mcf_get_first()
2886 psf = im->sources; in igmp_mcf_get_first()
2888 state->im = im; in igmp_mcf_get_first()
2889 state->idev = idev; in igmp_mcf_get_first()
2892 spin_unlock_bh(&im->lock); in igmp_mcf_get_first()
2902 psf = psf->sf_next; in igmp_mcf_get_next()
2904 spin_unlock_bh(&state->im->lock); in igmp_mcf_get_next()
2905 state->im = state->im->next; in igmp_mcf_get_next()
2906 while (!state->im) { in igmp_mcf_get_next()
2907 state->dev = next_net_device_rcu(state->dev); in igmp_mcf_get_next()
2908 if (!state->dev) { in igmp_mcf_get_next()
2909 state->idev = NULL; in igmp_mcf_get_next()
2912 state->idev = __in_dev_get_rcu(state->dev); in igmp_mcf_get_next()
2913 if (!state->idev) in igmp_mcf_get_next()
2915 state->im = rcu_dereference(state->idev->mc_list); in igmp_mcf_get_next()
2917 if (!state->im) in igmp_mcf_get_next()
2919 spin_lock_bh(&state->im->lock); in igmp_mcf_get_next()
2920 psf = state->im->sources; in igmp_mcf_get_next()
2931 --pos; in igmp_mcf_get_idx()
2939 return *pos ? igmp_mcf_get_idx(seq, *pos - 1) : SEQ_START_TOKEN; in igmp_mcf_seq_start()
2957 if (likely(state->im)) { in igmp_mcf_seq_stop()
2958 spin_unlock_bh(&state->im->lock); in igmp_mcf_seq_stop()
2959 state->im = NULL; in igmp_mcf_seq_stop()
2961 state->idev = NULL; in igmp_mcf_seq_stop()
2962 state->dev = NULL; in igmp_mcf_seq_stop()
2977 state->dev->ifindex, state->dev->name, in igmp_mcf_seq_show()
2978 ntohl(state->im->multiaddr), in igmp_mcf_seq_show()
2979 ntohl(psf->sf_inaddr), in igmp_mcf_seq_show()
2980 psf->sf_count[MCAST_INCLUDE], in igmp_mcf_seq_show()
2981 psf->sf_count[MCAST_EXCLUDE]); in igmp_mcf_seq_show()
2998 pde = proc_create_net("igmp", 0444, net->proc_net, &igmp_mc_seq_ops, in igmp_net_init()
3002 pde = proc_create_net("mcfilter", 0444, net->proc_net, in igmp_net_init()
3006 err = inet_ctl_sock_create(&net->ipv4.mc_autojoin_sk, AF_INET, in igmp_net_init()
3017 remove_proc_entry("mcfilter", net->proc_net); in igmp_net_init()
3019 remove_proc_entry("igmp", net->proc_net); in igmp_net_init()
3021 return -ENOMEM; in igmp_net_init()
3026 remove_proc_entry("mcfilter", net->proc_net); in igmp_net_exit()
3027 remove_proc_entry("igmp", net->proc_net); in igmp_net_exit()
3028 inet_ctl_sock_destroy(net->ipv4.mc_autojoin_sk); in igmp_net_exit()