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) && in add_grec()
485 psf_list = sdeleted ? &pmc->tomb : &pmc->sources; in add_grec()
495 AVAILABLE(skb) < grec_size(pmc, type, gdeleted, sdeleted)) { in add_grec()
508 if (!is_in(pmc, psf, type, gdeleted, sdeleted)) { in add_grec()
516 if (((gdeleted && pmc->sfmode == MCAST_EXCLUDE) || in add_grec()
517 (!gdeleted && pmc->crcount)) && in add_grec()
539 skb = add_grhead(skb, pmc, type, &pgr, mtu); in add_grec()
568 if (pmc->crcount || isquery) { in add_grec()
574 skb = add_grhead(skb, pmc, type, &pgr, mtu); in add_grec()
581 pmc->gsquery = 0; /* clear query state on report */ in add_grec()
585 static int igmpv3_send_report(struct in_device *in_dev, struct ip_mc_list *pmc) in igmpv3_send_report() argument
591 if (!pmc) { in igmpv3_send_report()
593 for_each_pmc_rcu(in_dev, pmc) { in igmpv3_send_report()
594 if (pmc->multiaddr == IGMP_ALL_HOSTS) in igmpv3_send_report()
596 if (ipv4_is_local_multicast(pmc->multiaddr) && in igmpv3_send_report()
599 spin_lock_bh(&pmc->lock); in igmpv3_send_report()
600 if (pmc->sfcount[MCAST_EXCLUDE]) in igmpv3_send_report()
604 skb = add_grec(skb, pmc, type, 0, 0); in igmpv3_send_report()
605 spin_unlock_bh(&pmc->lock); in igmpv3_send_report()
609 spin_lock_bh(&pmc->lock); in igmpv3_send_report()
610 if (pmc->sfcount[MCAST_EXCLUDE]) in igmpv3_send_report()
614 skb = add_grec(skb, pmc, type, 0, 0); in igmpv3_send_report()
615 spin_unlock_bh(&pmc->lock); in igmpv3_send_report()
643 static void kfree_pmc(struct ip_mc_list *pmc) in kfree_pmc() argument
645 ip_sf_list_clear_all(pmc->sources); in kfree_pmc()
646 ip_sf_list_clear_all(pmc->tomb); in kfree_pmc()
647 kfree(pmc); in kfree_pmc()
652 struct ip_mc_list *pmc, *pmc_prev, *pmc_next; in igmpv3_send_cr() local
661 for (pmc = in_dev->mc_tomb; pmc; pmc = pmc_next) { in igmpv3_send_cr()
662 pmc_next = pmc->next; in igmpv3_send_cr()
663 if (pmc->sfmode == MCAST_INCLUDE) { in igmpv3_send_cr()
666 skb = add_grec(skb, pmc, type, 1, 0); in igmpv3_send_cr()
667 skb = add_grec(skb, pmc, dtype, 1, 1); in igmpv3_send_cr()
669 if (pmc->crcount) { in igmpv3_send_cr()
670 if (pmc->sfmode == MCAST_EXCLUDE) { in igmpv3_send_cr()
672 skb = add_grec(skb, pmc, type, 1, 0); in igmpv3_send_cr()
674 pmc->crcount--; in igmpv3_send_cr()
675 if (pmc->crcount == 0) { in igmpv3_send_cr()
676 igmpv3_clear_zeros(&pmc->tomb); in igmpv3_send_cr()
677 igmpv3_clear_zeros(&pmc->sources); in igmpv3_send_cr()
680 if (pmc->crcount == 0 && !pmc->tomb && !pmc->sources) { in igmpv3_send_cr()
685 in_dev_put(pmc->interface); in igmpv3_send_cr()
686 kfree_pmc(pmc); in igmpv3_send_cr()
688 pmc_prev = pmc; in igmpv3_send_cr()
693 for_each_pmc_rcu(in_dev, pmc) { in igmpv3_send_cr()
694 spin_lock_bh(&pmc->lock); in igmpv3_send_cr()
695 if (pmc->sfcount[MCAST_EXCLUDE]) { in igmpv3_send_cr()
702 skb = add_grec(skb, pmc, type, 0, 0); in igmpv3_send_cr()
703 skb = add_grec(skb, pmc, dtype, 0, 1); /* deleted sources */ in igmpv3_send_cr()
706 if (pmc->crcount) { in igmpv3_send_cr()
707 if (pmc->sfmode == MCAST_EXCLUDE) in igmpv3_send_cr()
711 skb = add_grec(skb, pmc, type, 0, 0); in igmpv3_send_cr()
712 pmc->crcount--; in igmpv3_send_cr()
714 spin_unlock_bh(&pmc->lock); in igmpv3_send_cr()
723 static int igmp_send_report(struct in_device *in_dev, struct ip_mc_list *pmc, in igmp_send_report() argument
732 __be32 group = pmc ? pmc->multiaddr : 0; in igmp_send_report()
738 return igmpv3_send_report(in_dev, pmc); in igmp_send_report()
860 static int igmp_xmarksources(struct ip_mc_list *pmc, int nsrcs, __be32 *srcs) in igmp_xmarksources() argument
866 for (psf = pmc->sources; psf; psf = psf->sf_next) { in igmp_xmarksources()
872 pmc->sfcount[MCAST_EXCLUDE] != in igmp_xmarksources()
881 pmc->gsquery = 0; in igmp_xmarksources()
887 static int igmp_marksources(struct ip_mc_list *pmc, int nsrcs, __be32 *srcs) in igmp_marksources() argument
892 if (pmc->sfmode == MCAST_EXCLUDE) in igmp_marksources()
893 return igmp_xmarksources(pmc, nsrcs, srcs); in igmp_marksources()
897 for (psf = pmc->sources; psf; psf = psf->sf_next) { in igmp_marksources()
908 pmc->gsquery = 0; in igmp_marksources()
911 pmc->gsquery = 1; in igmp_marksources()
1175 struct ip_mc_list *pmc; in igmpv3_add_delrec() local
1184 pmc = kzalloc(sizeof(*pmc), gfp); in igmpv3_add_delrec()
1185 if (!pmc) in igmpv3_add_delrec()
1187 spin_lock_init(&pmc->lock); in igmpv3_add_delrec()
1189 pmc->interface = im->interface; in igmpv3_add_delrec()
1191 pmc->multiaddr = im->multiaddr; in igmpv3_add_delrec()
1192 pmc->crcount = in_dev->mr_qrv ?: READ_ONCE(net->ipv4.sysctl_igmp_qrv); in igmpv3_add_delrec()
1193 pmc->sfmode = im->sfmode; in igmpv3_add_delrec()
1194 if (pmc->sfmode == MCAST_INCLUDE) { in igmpv3_add_delrec()
1197 pmc->tomb = im->tomb; in igmpv3_add_delrec()
1198 pmc->sources = im->sources; in igmpv3_add_delrec()
1200 for (psf = pmc->sources; psf; psf = psf->sf_next) in igmpv3_add_delrec()
1201 psf->sf_crcount = pmc->crcount; in igmpv3_add_delrec()
1206 pmc->next = in_dev->mc_tomb; in igmpv3_add_delrec()
1207 in_dev->mc_tomb = pmc; in igmpv3_add_delrec()
1216 struct ip_mc_list *pmc, *pmc_prev; in igmpv3_del_delrec() local
1223 for (pmc = in_dev->mc_tomb; pmc; pmc = pmc->next) { in igmpv3_del_delrec()
1224 if (pmc->multiaddr == multiaddr) in igmpv3_del_delrec()
1226 pmc_prev = pmc; in igmpv3_del_delrec()
1228 if (pmc) { in igmpv3_del_delrec()
1230 pmc_prev->next = pmc->next; in igmpv3_del_delrec()
1232 in_dev->mc_tomb = pmc->next; in igmpv3_del_delrec()
1237 if (pmc) { in igmpv3_del_delrec()
1238 im->interface = pmc->interface; in igmpv3_del_delrec()
1240 swap(im->tomb, pmc->tomb); in igmpv3_del_delrec()
1241 swap(im->sources, pmc->sources); in igmpv3_del_delrec()
1249 in_dev_put(pmc->interface); in igmpv3_del_delrec()
1250 kfree_pmc(pmc); in igmpv3_del_delrec()
1260 struct ip_mc_list *pmc, *nextpmc; in igmpv3_clear_delrec() local
1263 pmc = in_dev->mc_tomb; in igmpv3_clear_delrec()
1267 for (; pmc; pmc = nextpmc) { in igmpv3_clear_delrec()
1268 nextpmc = pmc->next; in igmpv3_clear_delrec()
1269 ip_mc_clear_src(pmc); in igmpv3_clear_delrec()
1270 in_dev_put(pmc->interface); in igmpv3_clear_delrec()
1271 kfree_pmc(pmc); in igmpv3_clear_delrec()
1275 for_each_pmc_rcu(in_dev, pmc) { in igmpv3_clear_delrec()
1278 spin_lock_bh(&pmc->lock); in igmpv3_clear_delrec()
1279 psf = pmc->tomb; in igmpv3_clear_delrec()
1280 pmc->tomb = NULL; in igmpv3_clear_delrec()
1281 spin_unlock_bh(&pmc->lock); in igmpv3_clear_delrec()
1707 struct ip_mc_list *pmc; in ip_mc_unmap() local
1711 for_each_pmc_rtnl(in_dev, pmc) in ip_mc_unmap()
1712 igmp_group_dropped(pmc); in ip_mc_unmap()
1717 struct ip_mc_list *pmc; in ip_mc_remap() local
1721 for_each_pmc_rtnl(in_dev, pmc) { in ip_mc_remap()
1723 igmpv3_del_delrec(in_dev, pmc); in ip_mc_remap()
1725 igmp_group_added(pmc); in ip_mc_remap()
1733 struct ip_mc_list *pmc; in ip_mc_down() local
1737 for_each_pmc_rtnl(in_dev, pmc) in ip_mc_down()
1738 igmp_group_dropped(pmc); in ip_mc_down()
1784 struct ip_mc_list *pmc; in ip_mc_up() local
1791 for_each_pmc_rtnl(in_dev, pmc) { in ip_mc_up()
1793 igmpv3_del_delrec(in_dev, pmc); in ip_mc_up()
1795 igmp_group_added(pmc); in ip_mc_up()
1859 static int ip_mc_del1_src(struct ip_mc_list *pmc, int sfmode, in ip_mc_del1_src() argument
1866 for (psf = pmc->sources; psf; psf = psf->sf_next) { in ip_mc_del1_src()
1877 ip_rt_multicast_event(pmc->interface); in ip_mc_del1_src()
1881 struct in_device *in_dev = pmc->interface; in ip_mc_del1_src()
1889 pmc->sources = psf->sf_next; in ip_mc_del1_src()
1894 psf->sf_next = pmc->tomb; in ip_mc_del1_src()
1895 pmc->tomb = psf; in ip_mc_del1_src()
1911 struct ip_mc_list *pmc; in ip_mc_del_src() local
1918 for_each_pmc_rcu(in_dev, pmc) { in ip_mc_del_src()
1919 if (*pmca == pmc->multiaddr) in ip_mc_del_src()
1922 if (!pmc) { in ip_mc_del_src()
1927 spin_lock_bh(&pmc->lock); in ip_mc_del_src()
1930 sf_markstate(pmc); in ip_mc_del_src()
1934 if (!pmc->sfcount[sfmode]) in ip_mc_del_src()
1936 pmc->sfcount[sfmode]--; in ip_mc_del_src()
1940 int rv = ip_mc_del1_src(pmc, sfmode, &psfsrc[i]); in ip_mc_del_src()
1946 if (pmc->sfmode == MCAST_EXCLUDE && in ip_mc_del_src()
1947 pmc->sfcount[MCAST_EXCLUDE] == 0 && in ip_mc_del_src()
1948 pmc->sfcount[MCAST_INCLUDE]) { in ip_mc_del_src()
1955 pmc->sfmode = MCAST_INCLUDE; in ip_mc_del_src()
1957 pmc->crcount = in_dev->mr_qrv ?: READ_ONCE(net->ipv4.sysctl_igmp_qrv); in ip_mc_del_src()
1958 WRITE_ONCE(in_dev->mr_ifc_count, pmc->crcount); in ip_mc_del_src()
1959 for (psf = pmc->sources; psf; psf = psf->sf_next) in ip_mc_del_src()
1961 igmp_ifc_event(pmc->interface); in ip_mc_del_src()
1962 } else if (sf_setstate(pmc) || changerec) { in ip_mc_del_src()
1963 igmp_ifc_event(pmc->interface); in ip_mc_del_src()
1967 spin_unlock_bh(&pmc->lock); in ip_mc_del_src()
1974 static int ip_mc_add1_src(struct ip_mc_list *pmc, int sfmode, in ip_mc_add1_src() argument
1980 for (psf = pmc->sources; psf; psf = psf->sf_next) { in ip_mc_add1_src()
1993 pmc->sources = psf; in ip_mc_add1_src()
1997 ip_rt_multicast_event(pmc->interface); in ip_mc_add1_src()
2003 static void sf_markstate(struct ip_mc_list *pmc) in sf_markstate() argument
2006 int mca_xcount = pmc->sfcount[MCAST_EXCLUDE]; in sf_markstate()
2008 for (psf = pmc->sources; psf; psf = psf->sf_next) in sf_markstate()
2009 if (pmc->sfcount[MCAST_EXCLUDE]) { in sf_markstate()
2017 static int sf_setstate(struct ip_mc_list *pmc) in sf_setstate() argument
2020 int mca_xcount = pmc->sfcount[MCAST_EXCLUDE]; in sf_setstate()
2021 int qrv = pmc->interface->mr_qrv; in sf_setstate()
2025 for (psf = pmc->sources; psf; psf = psf->sf_next) { in sf_setstate()
2026 if (pmc->sfcount[MCAST_EXCLUDE]) { in sf_setstate()
2035 for (dpsf = pmc->tomb; dpsf; dpsf = dpsf->sf_next) { in sf_setstate()
2044 pmc->tomb = dpsf->sf_next; in sf_setstate()
2057 for (dpsf = pmc->tomb; dpsf; dpsf = dpsf->sf_next) in sf_setstate()
2065 /* pmc->lock held by callers */ in sf_setstate()
2066 dpsf->sf_next = pmc->tomb; in sf_setstate()
2067 pmc->tomb = dpsf; in sf_setstate()
2083 struct ip_mc_list *pmc; in ip_mc_add_src() local
2090 for_each_pmc_rcu(in_dev, pmc) { in ip_mc_add_src()
2091 if (*pmca == pmc->multiaddr) in ip_mc_add_src()
2094 if (!pmc) { in ip_mc_add_src()
2099 spin_lock_bh(&pmc->lock); in ip_mc_add_src()
2103 sf_markstate(pmc); in ip_mc_add_src()
2105 isexclude = pmc->sfmode == MCAST_EXCLUDE; in ip_mc_add_src()
2107 pmc->sfcount[sfmode]++; in ip_mc_add_src()
2110 err = ip_mc_add1_src(pmc, sfmode, &psfsrc[i]); in ip_mc_add_src()
2118 pmc->sfcount[sfmode]--; in ip_mc_add_src()
2120 (void) ip_mc_del1_src(pmc, sfmode, &psfsrc[j]); in ip_mc_add_src()
2121 } else if (isexclude != (pmc->sfcount[MCAST_EXCLUDE] != 0)) { in ip_mc_add_src()
2124 struct net *net = dev_net(pmc->interface->dev); in ip_mc_add_src()
2125 in_dev = pmc->interface; in ip_mc_add_src()
2129 if (pmc->sfcount[MCAST_EXCLUDE]) in ip_mc_add_src()
2130 pmc->sfmode = MCAST_EXCLUDE; in ip_mc_add_src()
2131 else if (pmc->sfcount[MCAST_INCLUDE]) in ip_mc_add_src()
2132 pmc->sfmode = MCAST_INCLUDE; in ip_mc_add_src()
2136 pmc->crcount = in_dev->mr_qrv ?: READ_ONCE(net->ipv4.sysctl_igmp_qrv); in ip_mc_add_src()
2137 WRITE_ONCE(in_dev->mr_ifc_count, pmc->crcount); in ip_mc_add_src()
2138 for (psf = pmc->sources; psf; psf = psf->sf_next) in ip_mc_add_src()
2141 } else if (sf_setstate(pmc)) { in ip_mc_add_src()
2145 spin_unlock_bh(&pmc->lock); in ip_mc_add_src()
2149 static void ip_mc_clear_src(struct ip_mc_list *pmc) in ip_mc_clear_src() argument
2153 spin_lock_bh(&pmc->lock); in ip_mc_clear_src()
2154 tomb = pmc->tomb; in ip_mc_clear_src()
2155 pmc->tomb = NULL; in ip_mc_clear_src()
2156 sources = pmc->sources; in ip_mc_clear_src()
2157 pmc->sources = NULL; in ip_mc_clear_src()
2158 pmc->sfmode = MCAST_EXCLUDE; in ip_mc_clear_src()
2159 pmc->sfcount[MCAST_INCLUDE] = 0; in ip_mc_clear_src()
2160 pmc->sfcount[MCAST_EXCLUDE] = 1; in ip_mc_clear_src()
2161 spin_unlock_bh(&pmc->lock); in ip_mc_clear_src()
2309 struct ip_mc_socklist *pmc; in ip_mc_source() local
2333 for_each_pmc_rtnl(inet, pmc) { in ip_mc_source()
2334 if ((pmc->multi.imr_multiaddr.s_addr == in ip_mc_source()
2336 (pmc->multi.imr_ifindex == imr.imr_ifindex)) in ip_mc_source()
2339 if (!pmc) { /* must have a prior join */ in ip_mc_source()
2344 if (pmc->sflist) { in ip_mc_source()
2345 if (pmc->sfmode != omode) { in ip_mc_source()
2349 } else if (pmc->sfmode != omode) { in ip_mc_source()
2352 ip_mc_del_src(in_dev, &mreqs->imr_multiaddr, pmc->sfmode, 0, in ip_mc_source()
2354 pmc->sfmode = omode; in ip_mc_source()
2357 psl = rtnl_dereference(pmc->sflist); in ip_mc_source()
2414 rcu_assign_pointer(pmc->sflist, newpsl); in ip_mc_source()
2447 struct ip_mc_socklist *pmc; in ip_mc_msfilter() local
2478 for_each_pmc_rtnl(inet, pmc) { in ip_mc_msfilter()
2479 if (pmc->multi.imr_multiaddr.s_addr == msf->imsf_multiaddr && in ip_mc_msfilter()
2480 pmc->multi.imr_ifindex == imr.imr_ifindex) in ip_mc_msfilter()
2483 if (!pmc) { /* must have a prior join */ in ip_mc_msfilter()
2511 psl = rtnl_dereference(pmc->sflist); in ip_mc_msfilter()
2513 (void) ip_mc_del_src(in_dev, &msf->imsf_multiaddr, pmc->sfmode, in ip_mc_msfilter()
2519 (void) ip_mc_del_src(in_dev, &msf->imsf_multiaddr, pmc->sfmode, in ip_mc_msfilter()
2522 rcu_assign_pointer(pmc->sflist, newpsl); in ip_mc_msfilter()
2525 pmc->sfmode = msf->imsf_fmode; in ip_mc_msfilter()
2538 struct ip_mc_socklist *pmc; in ip_mc_msfget() local
2560 for_each_pmc_rtnl(inet, pmc) { in ip_mc_msfget()
2561 if (pmc->multi.imr_multiaddr.s_addr == msf->imsf_multiaddr && in ip_mc_msfget()
2562 pmc->multi.imr_ifindex == imr.imr_ifindex) in ip_mc_msfget()
2565 if (!pmc) /* must have a prior join */ in ip_mc_msfget()
2567 msf->imsf_fmode = pmc->sfmode; in ip_mc_msfget()
2568 psl = rtnl_dereference(pmc->sflist); in ip_mc_msfget()
2598 struct ip_mc_socklist *pmc; in ip_mc_gsfget() local
2611 for_each_pmc_rtnl(inet, pmc) { in ip_mc_gsfget()
2612 if (pmc->multi.imr_multiaddr.s_addr == addr && in ip_mc_gsfget()
2613 pmc->multi.imr_ifindex == gsf->gf_interface) in ip_mc_gsfget()
2616 if (!pmc) /* must have a prior join */ in ip_mc_gsfget()
2618 gsf->gf_fmode = pmc->sfmode; in ip_mc_gsfget()
2619 psl = rtnl_dereference(pmc->sflist); in ip_mc_gsfget()
2645 struct ip_mc_socklist *pmc; in ip_mc_sf_allow() local
2655 for_each_pmc_rcu(inet, pmc) { in ip_mc_sf_allow()
2656 if (pmc->multi.imr_multiaddr.s_addr == loc_addr && in ip_mc_sf_allow()
2657 (pmc->multi.imr_ifindex == dif || in ip_mc_sf_allow()
2658 (sdif && pmc->multi.imr_ifindex == sdif))) in ip_mc_sf_allow()
2662 if (!pmc) in ip_mc_sf_allow()
2664 psl = rcu_dereference(pmc->sflist); in ip_mc_sf_allow()
2665 ret = (pmc->sfmode == MCAST_EXCLUDE); in ip_mc_sf_allow()
2674 if (pmc->sfmode == MCAST_INCLUDE && i >= psl->sl_count) in ip_mc_sf_allow()
2676 if (pmc->sfmode == MCAST_EXCLUDE && i < psl->sl_count) in ip_mc_sf_allow()