Lines Matching full:pmc

160 static int sf_setstate(struct ip_mc_list *pmc);
161 static void sf_markstate(struct ip_mc_list *pmc);
163 static void ip_mc_clear_src(struct ip_mc_list *pmc);
175 #define for_each_pmc_rcu(in_dev, pmc) \ argument
176 for (pmc = rcu_dereference(in_dev->mc_list); \
177 pmc != NULL; \
178 pmc = rcu_dereference(pmc->next_rcu))
180 #define for_each_pmc_rtnl(in_dev, pmc) \ argument
181 for (pmc = rtnl_dereference(in_dev->mc_list); \
182 pmc != NULL; \
183 pmc = rtnl_dereference(pmc->next_rcu))
270 static int is_in(struct ip_mc_list *pmc, struct ip_sf_list *psf, int type, in is_in() argument
278 if (!(pmc->gsquery && !psf->sf_gsresp)) { in is_in()
279 if (pmc->sfmode == MCAST_INCLUDE) in is_in()
286 return pmc->sfcount[MCAST_EXCLUDE] == in is_in()
297 if (pmc->sfcount[MCAST_EXCLUDE] == 0 || in is_in()
300 return pmc->sfcount[MCAST_EXCLUDE] == in is_in()
305 return (pmc->sfmode == MCAST_INCLUDE) ^ sdeleted; in is_in()
307 if (pmc->sfmode == MCAST_INCLUDE) in is_in()
315 igmp_scount(struct ip_mc_list *pmc, int type, int gdeleted, int sdeleted) in igmp_scount() argument
320 for (psf = pmc->sources; psf; psf = psf->sf_next) { in igmp_scount()
321 if (!is_in(pmc, psf, type, gdeleted, sdeleted)) in igmp_scount()
427 static int grec_size(struct ip_mc_list *pmc, int type, int gdel, int sdel) in grec_size() argument
429 return sizeof(struct igmpv3_grec) + 4*igmp_scount(pmc, type, gdel, sdel); in grec_size()
432 static struct sk_buff *add_grhead(struct sk_buff *skb, struct ip_mc_list *pmc, in add_grhead() argument
435 struct net_device *dev = pmc->interface->dev; in add_grhead()
448 pgr->grec_mca = pmc->multiaddr; in add_grhead()
457 static struct sk_buff *add_grec(struct sk_buff *skb, struct ip_mc_list *pmc, in add_grec() argument
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()
484 psf_list = sdeleted ? &pmc->tomb : &pmc->sources; in add_grec()
494 AVAILABLE(skb) < grec_size(pmc, type, gdeleted, sdeleted)) { in add_grec()
507 if (!is_in(pmc, psf, type, gdeleted, sdeleted)) { in add_grec()
515 if (((gdeleted && pmc->sfmode == MCAST_EXCLUDE) || in add_grec()
516 (!gdeleted && pmc->crcount)) && in add_grec()
538 skb = add_grhead(skb, pmc, type, &pgr, mtu); in add_grec()
567 if (pmc->crcount || isquery) { in add_grec()
573 skb = add_grhead(skb, pmc, type, &pgr, mtu); in add_grec()
580 pmc->gsquery = 0; /* clear query state on report */ in add_grec()
584 static int igmpv3_send_report(struct in_device *in_dev, struct ip_mc_list *pmc) in igmpv3_send_report() argument
590 if (!pmc) { in igmpv3_send_report()
592 for_each_pmc_rcu(in_dev, pmc) { 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()
598 spin_lock_bh(&pmc->lock); in igmpv3_send_report()
599 if (pmc->sfcount[MCAST_EXCLUDE]) in igmpv3_send_report()
603 skb = add_grec(skb, pmc, type, 0, 0); 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()
613 skb = add_grec(skb, pmc, type, 0, 0); in igmpv3_send_report()
614 spin_unlock_bh(&pmc->lock); in igmpv3_send_report()
642 static void kfree_pmc(struct ip_mc_list *pmc) in kfree_pmc() argument
644 ip_sf_list_clear_all(pmc->sources); in kfree_pmc()
645 ip_sf_list_clear_all(pmc->tomb); in kfree_pmc()
646 kfree(pmc); in kfree_pmc()
651 struct ip_mc_list *pmc, *pmc_prev, *pmc_next; in igmpv3_send_cr() local
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()
665 skb = add_grec(skb, pmc, type, 1, 0); in igmpv3_send_cr()
666 skb = add_grec(skb, pmc, dtype, 1, 1); in igmpv3_send_cr()
668 if (pmc->crcount) { in igmpv3_send_cr()
669 if (pmc->sfmode == MCAST_EXCLUDE) { in igmpv3_send_cr()
671 skb = add_grec(skb, pmc, type, 1, 0); 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()
684 in_dev_put(pmc->interface); in igmpv3_send_cr()
685 kfree_pmc(pmc); in igmpv3_send_cr()
687 pmc_prev = pmc; in igmpv3_send_cr()
692 for_each_pmc_rcu(in_dev, pmc) { in igmpv3_send_cr()
693 spin_lock_bh(&pmc->lock); in igmpv3_send_cr()
694 if (pmc->sfcount[MCAST_EXCLUDE]) { in igmpv3_send_cr()
701 skb = add_grec(skb, pmc, type, 0, 0); in igmpv3_send_cr()
702 skb = add_grec(skb, pmc, dtype, 0, 1); /* deleted sources */ in igmpv3_send_cr()
705 if (pmc->crcount) { in igmpv3_send_cr()
706 if (pmc->sfmode == MCAST_EXCLUDE) in igmpv3_send_cr()
710 skb = add_grec(skb, pmc, type, 0, 0); in igmpv3_send_cr()
711 pmc->crcount--; in igmpv3_send_cr()
713 spin_unlock_bh(&pmc->lock); in igmpv3_send_cr()
722 static int igmp_send_report(struct in_device *in_dev, struct ip_mc_list *pmc, in igmp_send_report() argument
731 __be32 group = pmc ? pmc->multiaddr : 0; in igmp_send_report()
737 return igmpv3_send_report(in_dev, pmc); in igmp_send_report()
851 static int igmp_xmarksources(struct ip_mc_list *pmc, int nsrcs, __be32 *srcs) in igmp_xmarksources() argument
857 for (psf = pmc->sources; psf; psf = psf->sf_next) { in igmp_xmarksources()
863 pmc->sfcount[MCAST_EXCLUDE] != in igmp_xmarksources()
872 pmc->gsquery = 0; in igmp_xmarksources()
878 static int igmp_marksources(struct ip_mc_list *pmc, int nsrcs, __be32 *srcs) in igmp_marksources() argument
883 if (pmc->sfmode == MCAST_EXCLUDE) in igmp_marksources()
884 return igmp_xmarksources(pmc, nsrcs, srcs); in igmp_marksources()
888 for (psf = pmc->sources; psf; psf = psf->sf_next) { in igmp_marksources()
899 pmc->gsquery = 0; in igmp_marksources()
902 pmc->gsquery = 1; in igmp_marksources()
1165 struct ip_mc_list *pmc; in igmpv3_add_delrec() local
1174 pmc = kzalloc(sizeof(*pmc), gfp); in igmpv3_add_delrec()
1175 if (!pmc) in igmpv3_add_delrec()
1177 spin_lock_init(&pmc->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()
1190 for (psf = pmc->sources; psf; psf = psf->sf_next) in igmpv3_add_delrec()
1191 psf->sf_crcount = pmc->crcount; 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()
1206 struct ip_mc_list *pmc, *pmc_prev; in igmpv3_del_delrec() local
1213 for (pmc = in_dev->mc_tomb; pmc; pmc = pmc->next) { in igmpv3_del_delrec()
1214 if (pmc->multiaddr == multiaddr) in igmpv3_del_delrec()
1216 pmc_prev = pmc; in igmpv3_del_delrec()
1218 if (pmc) { 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()
1227 if (pmc) { in igmpv3_del_delrec()
1228 im->interface = pmc->interface; in igmpv3_del_delrec()
1230 swap(im->tomb, pmc->tomb); in igmpv3_del_delrec()
1231 swap(im->sources, pmc->sources); in igmpv3_del_delrec()
1237 in_dev_put(pmc->interface); in igmpv3_del_delrec()
1238 kfree_pmc(pmc); in igmpv3_del_delrec()
1248 struct ip_mc_list *pmc, *nextpmc; in igmpv3_clear_delrec() local
1251 pmc = in_dev->mc_tomb; in igmpv3_clear_delrec()
1255 for (; pmc; pmc = nextpmc) { in igmpv3_clear_delrec()
1256 nextpmc = pmc->next; in igmpv3_clear_delrec()
1257 ip_mc_clear_src(pmc); in igmpv3_clear_delrec()
1258 in_dev_put(pmc->interface); in igmpv3_clear_delrec()
1259 kfree_pmc(pmc); in igmpv3_clear_delrec()
1263 for_each_pmc_rcu(in_dev, pmc) { 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()
1693 struct ip_mc_list *pmc; in ip_mc_unmap() local
1697 for_each_pmc_rtnl(in_dev, pmc) in ip_mc_unmap()
1698 igmp_group_dropped(pmc); in ip_mc_unmap()
1703 struct ip_mc_list *pmc; in ip_mc_remap() local
1707 for_each_pmc_rtnl(in_dev, pmc) { in ip_mc_remap()
1709 igmpv3_del_delrec(in_dev, pmc); in ip_mc_remap()
1711 igmp_group_added(pmc); in ip_mc_remap()
1719 struct ip_mc_list *pmc; in ip_mc_down() local
1723 for_each_pmc_rtnl(in_dev, pmc) in ip_mc_down()
1724 igmp_group_dropped(pmc); in ip_mc_down()
1770 struct ip_mc_list *pmc; in ip_mc_up() local
1777 for_each_pmc_rtnl(in_dev, pmc) { in ip_mc_up()
1779 igmpv3_del_delrec(in_dev, pmc); in ip_mc_up()
1781 igmp_group_added(pmc); in ip_mc_up()
1844 static int ip_mc_del1_src(struct ip_mc_list *pmc, int sfmode, in ip_mc_del1_src() argument
1851 for (psf = pmc->sources; psf; psf = psf->sf_next) { in ip_mc_del1_src()
1862 ip_rt_multicast_event(pmc->interface); in ip_mc_del1_src()
1866 struct in_device *in_dev = pmc->interface; in ip_mc_del1_src()
1874 pmc->sources = psf->sf_next; 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()
1896 struct ip_mc_list *pmc; in ip_mc_del_src() local
1903 for_each_pmc_rcu(in_dev, pmc) { in ip_mc_del_src()
1904 if (*pmca == pmc->multiaddr) in ip_mc_del_src()
1907 if (!pmc) { in ip_mc_del_src()
1912 spin_lock_bh(&pmc->lock); in ip_mc_del_src()
1915 sf_markstate(pmc); in ip_mc_del_src()
1919 if (!pmc->sfcount[sfmode]) in ip_mc_del_src()
1921 pmc->sfcount[sfmode]--; in ip_mc_del_src()
1925 int rv = ip_mc_del1_src(pmc, sfmode, &psfsrc[i]); 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()
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()
1946 igmp_ifc_event(pmc->interface); in ip_mc_del_src()
1947 } else if (sf_setstate(pmc) || changerec) { 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()
1959 static int ip_mc_add1_src(struct ip_mc_list *pmc, int sfmode, in ip_mc_add1_src() argument
1965 for (psf = pmc->sources; psf; psf = psf->sf_next) { in ip_mc_add1_src()
1978 pmc->sources = psf; in ip_mc_add1_src()
1982 ip_rt_multicast_event(pmc->interface); in ip_mc_add1_src()
1988 static void sf_markstate(struct ip_mc_list *pmc) in sf_markstate() argument
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()
2002 static int sf_setstate(struct ip_mc_list *pmc) in sf_setstate() argument
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()
2020 for (dpsf = pmc->tomb; dpsf; dpsf = dpsf->sf_next) { in sf_setstate()
2029 pmc->tomb = dpsf->sf_next; in sf_setstate()
2042 for (dpsf = pmc->tomb; dpsf; dpsf = dpsf->sf_next) 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()
2068 struct ip_mc_list *pmc; in ip_mc_add_src() local
2075 for_each_pmc_rcu(in_dev, pmc) { in ip_mc_add_src()
2076 if (*pmca == pmc->multiaddr) in ip_mc_add_src()
2079 if (!pmc) { in ip_mc_add_src()
2084 spin_lock_bh(&pmc->lock); in ip_mc_add_src()
2088 sf_markstate(pmc); 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()
2095 err = ip_mc_add1_src(pmc, sfmode, &psfsrc[i]); in ip_mc_add_src()
2103 pmc->sfcount[sfmode]--; in ip_mc_add_src()
2105 (void) ip_mc_del1_src(pmc, sfmode, &psfsrc[j]); 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()
2126 } else if (sf_setstate(pmc)) { in ip_mc_add_src()
2130 spin_unlock_bh(&pmc->lock); in ip_mc_add_src()
2134 static void ip_mc_clear_src(struct ip_mc_list *pmc) in ip_mc_clear_src() argument
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()
2294 struct ip_mc_socklist *pmc; in ip_mc_source() local
2318 for_each_pmc_rtnl(inet, pmc) { 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()
2324 if (!pmc) { /* must have a prior join */ in ip_mc_source()
2329 if (pmc->sflist) { in ip_mc_source()
2330 if (pmc->sfmode != omode) { in ip_mc_source()
2334 } else if (pmc->sfmode != omode) { 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()
2398 rcu_assign_pointer(pmc->sflist, newpsl); in ip_mc_source()
2429 struct ip_mc_socklist *pmc; in ip_mc_msfilter() local
2460 for_each_pmc_rtnl(inet, pmc) { 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()
2465 if (!pmc) { /* must have a prior join */ 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()
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()
2515 struct ip_mc_socklist *pmc; in ip_mc_msfget() local
2537 for_each_pmc_rtnl(inet, pmc) { 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()
2542 if (!pmc) /* must have a prior join */ in ip_mc_msfget()
2544 msf->imsf_fmode = pmc->sfmode; in ip_mc_msfget()
2545 psl = rtnl_dereference(pmc->sflist); in ip_mc_msfget()
2573 struct ip_mc_socklist *pmc; in ip_mc_gsfget() local
2586 for_each_pmc_rtnl(inet, pmc) { 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()
2591 if (!pmc) /* must have a prior join */ in ip_mc_gsfget()
2593 gsf->gf_fmode = pmc->sfmode; in ip_mc_gsfget()
2594 psl = rtnl_dereference(pmc->sflist); in ip_mc_gsfget()
2618 struct ip_mc_socklist *pmc; in ip_mc_sf_allow() local
2628 for_each_pmc_rcu(inet, pmc) { in ip_mc_sf_allow()
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()
2635 if (!pmc) 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()
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()