Lines Matching +full:ports +full:- +full:block +full:- +full:group +full:- +full:count

1 // SPDX-License-Identifier: GPL-2.0-or-later
59 __be32 group,
71 const struct in6_addr *group,
77 struct br_ip *group,
93 lockdep_assert_held_once(&br->multicast_lock); in br_sg_port_find()
95 return rhashtable_lookup_fast(&br->sg_port_tbl, sg_p, in br_sg_port_find()
102 return rhashtable_lookup(&br->mdb_hash_tbl, dst, br_mdb_rht_params); in br_mdb_ip_get_rcu()
110 lockdep_assert_held_once(&br->multicast_lock); in br_mdb_ip_get()
113 ent = rhashtable_lookup(&br->mdb_hash_tbl, dst, br_mdb_rht_params); in br_mdb_ip_get()
152 struct net_bridge *br = brmctx->br; in br_mdb_entry_skb_get()
159 if (BR_INPUT_SKB_CB(skb)->igmp) in br_mdb_entry_skb_get()
163 ip.proto = skb->protocol; in br_mdb_entry_skb_get()
166 switch (skb->protocol) { in br_mdb_entry_skb_get()
168 ip.dst.ip4 = ip_hdr(skb)->daddr; in br_mdb_entry_skb_get()
169 if (brmctx->multicast_igmp_version == 3) { in br_mdb_entry_skb_get()
172 ip.src.ip4 = ip_hdr(skb)->saddr; in br_mdb_entry_skb_get()
181 ip.dst.ip6 = ipv6_hdr(skb)->daddr; in br_mdb_entry_skb_get()
182 if (brmctx->multicast_mld_version == 2) { in br_mdb_entry_skb_get()
185 ip.src.ip6 = ipv6_hdr(skb)->saddr; in br_mdb_entry_skb_get()
195 ether_addr_copy(ip.dst.mac_addr, eth_hdr(skb)->h_dest); in br_mdb_entry_skb_get()
202 * passed down (e.g. timer) and must be used for read-only purposes because
204 * (non-vlan or vlan). Its initial intended purpose is to read timer values
207 * which needs to re-arm with a specific delay taken from the old context
212 struct net_bridge_mcast_port *pmctx = &pg->key.port->multicast_ctx; in br_multicast_pg_to_port_ctx()
215 lockdep_assert_held_once(&pg->key.port->br->multicast_lock); in br_multicast_pg_to_port_ctx()
218 if (!pg->key.addr.vid || in br_multicast_pg_to_port_ctx()
219 !br_opt_get(pg->key.port->br, BROPT_MCAST_VLAN_SNOOPING_ENABLED)) in br_multicast_pg_to_port_ctx()
229 vlan = br_vlan_find(nbp_vlan_group_rcu(pg->key.port), pg->key.addr.vid); in br_multicast_pg_to_port_ctx()
230 if (vlan && !br_multicast_port_ctx_vlan_disabled(&vlan->port_mcast_ctx)) in br_multicast_pg_to_port_ctx()
231 pmctx = &vlan->port_mcast_ctx; in br_multicast_pg_to_port_ctx()
245 lockdep_assert_held_once(&port->br->multicast_lock); in br_multicast_port_vid_to_port_ctx()
247 if (!br_opt_get(port->br, BROPT_MCAST_VLAN_SNOOPING_ENABLED)) in br_multicast_port_vid_to_port_ctx()
254 if (vlan && !br_multicast_port_ctx_vlan_disabled(&vlan->port_mcast_ctx)) in br_multicast_port_vid_to_port_ctx()
255 pmctx = &vlan->port_mcast_ctx; in br_multicast_port_vid_to_port_ctx()
264 * - if pmctx is non-NULL (port), check if it should be used
265 * - if pmctx is NULL (bridge), check if brmctx should be used
271 if (!netif_running(brmctx->br->dev)) in br_multicast_ctx_should_use()
284 if (p->key.port != port) in br_port_group_equal()
287 if (!(port->flags & BR_MULTICAST_TO_UNICAST)) in br_port_group_equal()
290 return ether_addr_equal(src, p->eth_addr); in br_port_group_equal()
303 sg_key.port = pg->key.port; in __fwd_add_star_excl()
305 if (br_sg_port_find(brmctx->br, &sg_key)) in __fwd_add_star_excl()
309 sg_ip, pg->eth_addr, in __fwd_add_star_excl()
312 src_pg->rt_protocol != RTPROT_KERNEL) in __fwd_add_star_excl()
315 src_pg->flags |= MDB_PG_FLAGS_STAR_EXCL; in __fwd_add_star_excl()
322 struct net_bridge *br = pg->key.port->br; in __fwd_del_star_excl()
326 sg_key.port = pg->key.port; in __fwd_del_star_excl()
329 if (!src_pg || !(src_pg->flags & MDB_PG_FLAGS_STAR_EXCL) || in __fwd_del_star_excl()
330 src_pg->rt_protocol != RTPROT_KERNEL) in __fwd_del_star_excl()
336 /* When a port group transitions to (or is added as) EXCLUDE we need to add it
337 * to all other ports' S,G entries which are not blocked by the current group
340 * When a port group transitions from EXCLUDE -> INCLUDE mode or is being
341 * deleted we need to remove it from all ports' S,G entries where it was
347 struct net_bridge *br = pg->key.port->br; in br_multicast_star_g_handle_mode()
353 if (WARN_ON(!br_multicast_is_star_g(&pg->key.addr))) in br_multicast_star_g_handle_mode()
356 mp = br_mdb_ip_get(br, &pg->key.addr); in br_multicast_star_g_handle_mode()
364 sg_ip = pg->key.addr; in br_multicast_star_g_handle_mode()
366 for (pg_lst = mlock_dereference(mp->ports, br); in br_multicast_star_g_handle_mode()
368 pg_lst = mlock_dereference(pg_lst->next, br)) { in br_multicast_star_g_handle_mode()
373 hlist_for_each_entry(src_ent, &pg_lst->src_list, node) { in br_multicast_star_g_handle_mode()
374 if (!(src_ent->flags & BR_SGRP_F_INSTALLED)) in br_multicast_star_g_handle_mode()
376 sg_ip.src = src_ent->addr.src; in br_multicast_star_g_handle_mode()
395 if (WARN_ON(!br_multicast_is_star_g(&star_mp->addr))) in br_multicast_sg_host_state()
397 if (!star_mp->host_joined) in br_multicast_sg_host_state()
400 sg_mp = br_mdb_ip_get(star_mp->br, &sg->key.addr); in br_multicast_sg_host_state()
403 sg_mp->host_joined = true; in br_multicast_sg_host_state()
409 struct net_bridge *br = star_mp->br; in br_multicast_star_g_host_state()
414 if (WARN_ON(!br_multicast_is_star_g(&star_mp->addr))) in br_multicast_star_g_host_state()
418 sg_ip = star_mp->addr; in br_multicast_star_g_host_state()
419 for (pg = mlock_dereference(star_mp->ports, br); in br_multicast_star_g_host_state()
421 pg = mlock_dereference(pg->next, br)) { in br_multicast_star_g_host_state()
424 hlist_for_each_entry(src_ent, &pg->src_list, node) { in br_multicast_star_g_host_state()
425 if (!(src_ent->flags & BR_SGRP_F_INSTALLED)) in br_multicast_star_g_host_state()
427 sg_ip.src = src_ent->addr.src; in br_multicast_star_g_host_state()
431 sg_mp->host_joined = star_mp->host_joined; in br_multicast_star_g_host_state()
441 /* *,G exclude ports are only added to S,G entries */ in br_multicast_sg_del_exclude_ports()
442 if (WARN_ON(br_multicast_is_star_g(&sgmp->addr))) in br_multicast_sg_del_exclude_ports()
445 /* we need the STAR_EXCLUDE ports if there are non-STAR_EXCLUDE ports in br_multicast_sg_del_exclude_ports()
446 * we should ignore perm entries since they're managed by user-space in br_multicast_sg_del_exclude_ports()
448 for (pp = &sgmp->ports; in br_multicast_sg_del_exclude_ports()
449 (p = mlock_dereference(*pp, sgmp->br)) != NULL; in br_multicast_sg_del_exclude_ports()
450 pp = &p->next) in br_multicast_sg_del_exclude_ports()
451 if (!(p->flags & (MDB_PG_FLAGS_STAR_EXCL | in br_multicast_sg_del_exclude_ports()
459 sgmp->host_joined = false; in br_multicast_sg_del_exclude_ports()
461 for (pp = &sgmp->ports; in br_multicast_sg_del_exclude_ports()
462 (p = mlock_dereference(*pp, sgmp->br)) != NULL;) { in br_multicast_sg_del_exclude_ports()
463 if (!(p->flags & MDB_PG_FLAGS_PERMANENT)) in br_multicast_sg_del_exclude_ports()
466 pp = &p->next; in br_multicast_sg_del_exclude_ports()
474 struct net_bridge *br = star_mp->br; in br_multicast_sg_add_exclude_ports()
479 if (WARN_ON(br_multicast_is_star_g(&sg->key.addr))) in br_multicast_sg_add_exclude_ports()
481 if (WARN_ON(!br_multicast_is_star_g(&star_mp->addr))) in br_multicast_sg_add_exclude_ports()
486 sg_key.addr = sg->key.addr; in br_multicast_sg_add_exclude_ports()
487 /* we need to add all exclude ports to the S,G */ in br_multicast_sg_add_exclude_ports()
488 for (pg = mlock_dereference(star_mp->ports, br); in br_multicast_sg_add_exclude_ports()
490 pg = mlock_dereference(pg->next, br)) { in br_multicast_sg_add_exclude_ports()
493 if (pg == sg || pg->filter_mode == MCAST_INCLUDE) in br_multicast_sg_add_exclude_ports()
496 sg_key.port = pg->key.port; in br_multicast_sg_add_exclude_ports()
506 &sg->key.addr, in br_multicast_sg_add_exclude_ports()
507 sg->eth_addr, in br_multicast_sg_add_exclude_ports()
510 src_pg->rt_protocol != RTPROT_KERNEL) in br_multicast_sg_add_exclude_ports()
512 src_pg->flags |= MDB_PG_FLAGS_STAR_EXCL; in br_multicast_sg_add_exclude_ports()
524 if (src->flags & BR_SGRP_F_INSTALLED) in br_multicast_fwd_src_add()
528 pmctx = br_multicast_pg_to_port_ctx(src->pg); in br_multicast_fwd_src_add()
532 sg_ip = src->pg->key.addr; in br_multicast_fwd_src_add()
533 sg_ip.src = src->addr.src; in br_multicast_fwd_src_add()
536 src->pg->eth_addr, MCAST_INCLUDE, false, in br_multicast_fwd_src_add()
537 !timer_pending(&src->timer)); in br_multicast_fwd_src_add()
540 src->flags |= BR_SGRP_F_INSTALLED; in br_multicast_fwd_src_add()
541 sg->flags &= ~MDB_PG_FLAGS_STAR_EXCL; in br_multicast_fwd_src_add()
543 /* if it was added by user-space as perm we can skip next steps */ in br_multicast_fwd_src_add()
544 if (sg->rt_protocol != RTPROT_KERNEL && in br_multicast_fwd_src_add()
545 (sg->flags & MDB_PG_FLAGS_PERMANENT)) in br_multicast_fwd_src_add()
549 del_timer(&sg->timer); in br_multicast_fwd_src_add()
550 star_mp = br_mdb_ip_get(src->br, &src->pg->key.addr); in br_multicast_fwd_src_add()
560 struct net_bridge_port_group *p, *pg = src->pg; in br_multicast_fwd_src_remove()
566 sg_ip = pg->key.addr; in br_multicast_fwd_src_remove()
567 sg_ip.src = src->addr.src; in br_multicast_fwd_src_remove()
569 mp = br_mdb_ip_get(src->br, &sg_ip); in br_multicast_fwd_src_remove()
573 for (pp = &mp->ports; in br_multicast_fwd_src_remove()
574 (p = mlock_dereference(*pp, src->br)) != NULL; in br_multicast_fwd_src_remove()
575 pp = &p->next) { in br_multicast_fwd_src_remove()
576 if (!br_port_group_equal(p, pg->key.port, pg->eth_addr)) in br_multicast_fwd_src_remove()
579 if (p->rt_protocol != RTPROT_KERNEL && in br_multicast_fwd_src_remove()
580 (p->flags & MDB_PG_FLAGS_PERMANENT) && in br_multicast_fwd_src_remove()
581 !(src->flags & BR_SGRP_F_USER_ADDED)) in br_multicast_fwd_src_remove()
585 p->flags |= MDB_PG_FLAGS_FAST_LEAVE; in br_multicast_fwd_src_remove()
589 src->flags &= ~BR_SGRP_F_INSTALLED; in br_multicast_fwd_src_remove()
602 sg_key.addr = src->pg->key.addr; in br_multicast_fwd_src_handle()
603 sg_key.addr.src = src->addr.src; in br_multicast_fwd_src_handle()
604 sg_key.port = src->pg->key.port; in br_multicast_fwd_src_handle()
606 sg = br_sg_port_find(src->br, &sg_key); in br_multicast_fwd_src_handle()
607 if (!sg || (sg->flags & MDB_PG_FLAGS_PERMANENT)) in br_multicast_fwd_src_handle()
610 old_flags = sg->flags; in br_multicast_fwd_src_handle()
611 if (timer_pending(&src->timer)) in br_multicast_fwd_src_handle()
612 sg->flags &= ~MDB_PG_FLAGS_BLOCKED; in br_multicast_fwd_src_handle()
614 sg->flags |= MDB_PG_FLAGS_BLOCKED; in br_multicast_fwd_src_handle()
616 if (old_flags != sg->flags) { in br_multicast_fwd_src_handle()
619 sg_mp = br_mdb_ip_get(src->br, &sg_key.addr); in br_multicast_fwd_src_handle()
622 br_mdb_notify(src->br->dev, sg_mp, sg, RTM_NEWMDB); in br_multicast_fwd_src_handle()
631 WARN_ON(!hlist_unhashed(&mp->mdb_node)); in br_multicast_destroy_mdb_entry()
632 WARN_ON(mp->ports); in br_multicast_destroy_mdb_entry()
634 timer_shutdown_sync(&mp->timer); in br_multicast_destroy_mdb_entry()
640 struct net_bridge *br = mp->br; in br_multicast_del_mdb_entry()
642 rhashtable_remove_fast(&br->mdb_hash_tbl, &mp->rhnode, in br_multicast_del_mdb_entry()
644 hlist_del_init_rcu(&mp->mdb_node); in br_multicast_del_mdb_entry()
645 hlist_add_head(&mp->mcast_gc.gc_node, &br->mcast_gc_list); in br_multicast_del_mdb_entry()
646 queue_work(system_long_wq, &br->mcast_gc_work); in br_multicast_del_mdb_entry()
652 struct net_bridge *br = mp->br; in br_multicast_group_expired()
654 spin_lock(&br->multicast_lock); in br_multicast_group_expired()
655 if (hlist_unhashed(&mp->mdb_node) || !netif_running(br->dev) || in br_multicast_group_expired()
656 timer_pending(&mp->timer)) in br_multicast_group_expired()
661 if (mp->ports) in br_multicast_group_expired()
665 spin_unlock(&br->multicast_lock); in br_multicast_group_expired()
673 WARN_ON(!hlist_unhashed(&src->node)); in br_multicast_destroy_group_src()
675 timer_shutdown_sync(&src->timer); in br_multicast_destroy_group_src()
681 struct net_bridge *br = src->pg->key.port->br; in __br_multicast_del_group_src()
683 hlist_del_init_rcu(&src->node); in __br_multicast_del_group_src()
684 src->pg->src_ents--; in __br_multicast_del_group_src()
685 hlist_add_head(&src->mcast_gc.gc_node, &br->mcast_gc_list); in __br_multicast_del_group_src()
686 queue_work(system_long_wq, &br->mcast_gc_work); in __br_multicast_del_group_src()
701 u32 max = READ_ONCE(pmctx->mdb_max_entries); in br_multicast_port_ngroups_inc_one()
702 u32 n = READ_ONCE(pmctx->mdb_n_entries); in br_multicast_port_ngroups_inc_one()
707 return -E2BIG; in br_multicast_port_ngroups_inc_one()
710 WRITE_ONCE(pmctx->mdb_n_entries, n + 1); in br_multicast_port_ngroups_inc_one()
716 u32 n = READ_ONCE(pmctx->mdb_n_entries); in br_multicast_port_ngroups_dec_one()
719 WRITE_ONCE(pmctx->mdb_n_entries, n - 1); in br_multicast_port_ngroups_dec_one()
723 const struct br_ip *group, in br_multicast_port_ngroups_inc() argument
729 lockdep_assert_held_once(&port->br->multicast_lock); in br_multicast_port_ngroups_inc()
731 /* Always count on the port context. */ in br_multicast_port_ngroups_inc()
732 err = br_multicast_port_ngroups_inc_one(&port->multicast_ctx, extack, in br_multicast_port_ngroups_inc()
735 trace_br_mdb_full(port->dev, group); in br_multicast_port_ngroups_inc()
739 /* Only count on the VLAN context if VID is given, and if snooping on in br_multicast_port_ngroups_inc()
742 if (!group->vid) in br_multicast_port_ngroups_inc()
745 pmctx = br_multicast_port_vid_to_port_ctx(port, group->vid); in br_multicast_port_ngroups_inc()
749 err = br_multicast_port_ngroups_inc_one(pmctx, extack, "Port-VLAN"); in br_multicast_port_ngroups_inc()
751 trace_br_mdb_full(port->dev, group); in br_multicast_port_ngroups_inc()
758 br_multicast_port_ngroups_dec_one(&port->multicast_ctx); in br_multicast_port_ngroups_inc()
766 lockdep_assert_held_once(&port->br->multicast_lock); in br_multicast_port_ngroups_dec()
773 br_multicast_port_ngroups_dec_one(&port->multicast_ctx); in br_multicast_port_ngroups_dec()
778 return READ_ONCE(pmctx->mdb_n_entries); in br_multicast_ngroups_get()
783 WRITE_ONCE(pmctx->mdb_max_entries, max); in br_multicast_ngroups_set_max()
788 return READ_ONCE(pmctx->mdb_max_entries); in br_multicast_ngroups_get_max()
796 WARN_ON(!hlist_unhashed(&pg->mglist)); in br_multicast_destroy_port_group()
797 WARN_ON(!hlist_empty(&pg->src_list)); in br_multicast_destroy_port_group()
799 timer_shutdown_sync(&pg->rexmit_timer); in br_multicast_destroy_port_group()
800 timer_shutdown_sync(&pg->timer); in br_multicast_destroy_port_group()
808 struct net_bridge *br = pg->key.port->br; in br_multicast_del_pg()
812 rcu_assign_pointer(*pp, pg->next); in br_multicast_del_pg()
813 hlist_del_init(&pg->mglist); in br_multicast_del_pg()
815 hlist_for_each_entry_safe(ent, tmp, &pg->src_list, node) in br_multicast_del_pg()
817 br_mdb_notify(br->dev, mp, pg, RTM_DELMDB); in br_multicast_del_pg()
818 if (!br_multicast_is_star_g(&mp->addr)) { in br_multicast_del_pg()
819 rhashtable_remove_fast(&br->sg_port_tbl, &pg->rhnode, in br_multicast_del_pg()
825 br_multicast_port_ngroups_dec(pg->key.port, pg->key.addr.vid); in br_multicast_del_pg()
826 hlist_add_head(&pg->mcast_gc.gc_node, &br->mcast_gc_list); in br_multicast_del_pg()
827 queue_work(system_long_wq, &br->mcast_gc_work); in br_multicast_del_pg()
829 if (!mp->ports && !mp->host_joined && netif_running(br->dev)) in br_multicast_del_pg()
830 mod_timer(&mp->timer, jiffies); in br_multicast_del_pg()
840 mp = br_mdb_ip_get(br, &pg->key.addr); in br_multicast_find_del_pg()
844 for (pp = &mp->ports; in br_multicast_find_del_pg()
846 pp = &p->next) { in br_multicast_find_del_pg()
861 struct net_bridge *br = pg->key.port->br; in br_multicast_port_group_expired()
865 spin_lock(&br->multicast_lock); in br_multicast_port_group_expired()
866 if (!netif_running(br->dev) || timer_pending(&pg->timer) || in br_multicast_port_group_expired()
867 hlist_unhashed(&pg->mglist) || pg->flags & MDB_PG_FLAGS_PERMANENT) in br_multicast_port_group_expired()
870 changed = !!(pg->filter_mode == MCAST_EXCLUDE); in br_multicast_port_group_expired()
871 pg->filter_mode = MCAST_INCLUDE; in br_multicast_port_group_expired()
872 hlist_for_each_entry_safe(src_ent, tmp, &pg->src_list, node) { in br_multicast_port_group_expired()
873 if (!timer_pending(&src_ent->timer)) { in br_multicast_port_group_expired()
879 if (hlist_empty(&pg->src_list)) { in br_multicast_port_group_expired()
882 struct net_bridge_mdb_entry *mp = br_mdb_ip_get(br, &pg->key.addr); in br_multicast_port_group_expired()
884 if (changed && br_multicast_is_star_g(&pg->key.addr)) in br_multicast_port_group_expired()
889 br_mdb_notify(br->dev, mp, pg, RTM_NEWMDB); in br_multicast_port_group_expired()
892 spin_unlock(&br->multicast_lock); in br_multicast_port_group_expired()
901 hlist_del_init(&gcent->gc_node); in br_multicast_gc()
902 gcent->destroy(gcent); in br_multicast_gc()
913 vlan = pmctx->vlan; in __br_multicast_query_handle_vlan()
915 vlan = brmctx->vlan; in __br_multicast_query_handle_vlan()
917 if (vlan && !(vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED)) { in __br_multicast_query_handle_vlan()
920 if (br_vlan_get_proto(brmctx->br->dev, &vlan_proto) != 0) in __br_multicast_query_handle_vlan()
922 __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vlan->vid); in __br_multicast_query_handle_vlan()
929 __be32 ip_dst, __be32 group, in br_ip4_multicast_alloc_query() argument
934 struct net_bridge_port *p = pg ? pg->key.port : NULL; in br_ip4_multicast_alloc_query()
949 if (brmctx->multicast_igmp_version == 3) { in br_ip4_multicast_alloc_query()
952 lmqt = now + (brmctx->multicast_last_member_interval * in br_ip4_multicast_alloc_query()
953 brmctx->multicast_last_member_count); in br_ip4_multicast_alloc_query()
954 hlist_for_each_entry(ent, &pg->src_list, node) { in br_ip4_multicast_alloc_query()
955 if (over_lmqt == time_after(ent->timer.expires, in br_ip4_multicast_alloc_query()
957 ent->src_query_rexmit_cnt > 0) in br_ip4_multicast_alloc_query()
968 if ((p && pkt_size > p->dev->mtu) || in br_ip4_multicast_alloc_query()
969 pkt_size > brmctx->br->dev->mtu) in br_ip4_multicast_alloc_query()
972 skb = netdev_alloc_skb_ip_align(brmctx->br->dev, pkt_size); in br_ip4_multicast_alloc_query()
977 skb->protocol = htons(ETH_P_IP); in br_ip4_multicast_alloc_query()
982 ether_addr_copy(eth->h_source, brmctx->br->dev->dev_addr); in br_ip4_multicast_alloc_query()
983 ip_eth_mc_map(ip_dst, eth->h_dest); in br_ip4_multicast_alloc_query()
984 eth->h_proto = htons(ETH_P_IP); in br_ip4_multicast_alloc_query()
987 skb_set_network_header(skb, skb->len); in br_ip4_multicast_alloc_query()
989 iph->tot_len = htons(pkt_size - sizeof(*eth)); in br_ip4_multicast_alloc_query()
991 iph->version = 4; in br_ip4_multicast_alloc_query()
992 iph->ihl = 6; in br_ip4_multicast_alloc_query()
993 iph->tos = 0xc0; in br_ip4_multicast_alloc_query()
994 iph->id = 0; in br_ip4_multicast_alloc_query()
995 iph->frag_off = htons(IP_DF); in br_ip4_multicast_alloc_query()
996 iph->ttl = 1; in br_ip4_multicast_alloc_query()
997 iph->protocol = IPPROTO_IGMP; in br_ip4_multicast_alloc_query()
998 iph->saddr = br_opt_get(brmctx->br, BROPT_MULTICAST_QUERY_USE_IFADDR) ? in br_ip4_multicast_alloc_query()
999 inet_select_addr(brmctx->br->dev, 0, RT_SCOPE_LINK) : 0; in br_ip4_multicast_alloc_query()
1000 iph->daddr = ip_dst; in br_ip4_multicast_alloc_query()
1008 skb_set_transport_header(skb, skb->len); in br_ip4_multicast_alloc_query()
1011 switch (brmctx->multicast_igmp_version) { in br_ip4_multicast_alloc_query()
1014 ih->type = IGMP_HOST_MEMBERSHIP_QUERY; in br_ip4_multicast_alloc_query()
1015 ih->code = (group ? brmctx->multicast_last_member_interval : in br_ip4_multicast_alloc_query()
1016 brmctx->multicast_query_response_interval) / in br_ip4_multicast_alloc_query()
1018 ih->group = group; in br_ip4_multicast_alloc_query()
1019 ih->csum = 0; in br_ip4_multicast_alloc_query()
1020 csum = &ih->csum; in br_ip4_multicast_alloc_query()
1025 ihv3->type = IGMP_HOST_MEMBERSHIP_QUERY; in br_ip4_multicast_alloc_query()
1026 ihv3->code = (group ? brmctx->multicast_last_member_interval : in br_ip4_multicast_alloc_query()
1027 brmctx->multicast_query_response_interval) / in br_ip4_multicast_alloc_query()
1029 ihv3->group = group; in br_ip4_multicast_alloc_query()
1030 ihv3->qqic = brmctx->multicast_query_interval / HZ; in br_ip4_multicast_alloc_query()
1031 ihv3->nsrcs = htons(lmqt_srcs); in br_ip4_multicast_alloc_query()
1032 ihv3->resv = 0; in br_ip4_multicast_alloc_query()
1033 ihv3->suppress = sflag; in br_ip4_multicast_alloc_query()
1034 ihv3->qrv = 2; in br_ip4_multicast_alloc_query()
1035 ihv3->csum = 0; in br_ip4_multicast_alloc_query()
1036 csum = &ihv3->csum; in br_ip4_multicast_alloc_query()
1042 hlist_for_each_entry(ent, &pg->src_list, node) { in br_ip4_multicast_alloc_query()
1043 if (over_lmqt == time_after(ent->timer.expires, in br_ip4_multicast_alloc_query()
1045 ent->src_query_rexmit_cnt > 0) { in br_ip4_multicast_alloc_query()
1046 ihv3->srcs[lmqt_srcs++] = ent->addr.src.ip4; in br_ip4_multicast_alloc_query()
1047 ent->src_query_rexmit_cnt--; in br_ip4_multicast_alloc_query()
1048 if (need_rexmit && ent->src_query_rexmit_cnt) in br_ip4_multicast_alloc_query()
1052 if (WARN_ON(lmqt_srcs != ntohs(ihv3->nsrcs))) { in br_ip4_multicast_alloc_query()
1077 const struct in6_addr *group, in br_ip6_multicast_alloc_query() argument
1082 struct net_bridge_port *p = pg ? pg->key.port : NULL; in br_ip6_multicast_alloc_query()
1099 if (brmctx->multicast_mld_version == 2) { in br_ip6_multicast_alloc_query()
1102 llqt = now + (brmctx->multicast_last_member_interval * in br_ip6_multicast_alloc_query()
1103 brmctx->multicast_last_member_count); in br_ip6_multicast_alloc_query()
1104 hlist_for_each_entry(ent, &pg->src_list, node) { in br_ip6_multicast_alloc_query()
1105 if (over_llqt == time_after(ent->timer.expires, in br_ip6_multicast_alloc_query()
1107 ent->src_query_rexmit_cnt > 0) in br_ip6_multicast_alloc_query()
1118 if ((p && pkt_size > p->dev->mtu) || in br_ip6_multicast_alloc_query()
1119 pkt_size > brmctx->br->dev->mtu) in br_ip6_multicast_alloc_query()
1122 skb = netdev_alloc_skb_ip_align(brmctx->br->dev, pkt_size); in br_ip6_multicast_alloc_query()
1127 skb->protocol = htons(ETH_P_IPV6); in br_ip6_multicast_alloc_query()
1133 ether_addr_copy(eth->h_source, brmctx->br->dev->dev_addr); in br_ip6_multicast_alloc_query()
1134 eth->h_proto = htons(ETH_P_IPV6); in br_ip6_multicast_alloc_query()
1138 skb_set_network_header(skb, skb->len); in br_ip6_multicast_alloc_query()
1142 ip6h->payload_len = htons(8 + mld_hdr_size); in br_ip6_multicast_alloc_query()
1143 ip6h->nexthdr = IPPROTO_HOPOPTS; in br_ip6_multicast_alloc_query()
1144 ip6h->hop_limit = 1; in br_ip6_multicast_alloc_query()
1145 ip6h->daddr = *ip6_dst; in br_ip6_multicast_alloc_query()
1146 if (ipv6_dev_get_saddr(dev_net(brmctx->br->dev), brmctx->br->dev, in br_ip6_multicast_alloc_query()
1147 &ip6h->daddr, 0, &ip6h->saddr)) { in br_ip6_multicast_alloc_query()
1149 br_opt_toggle(brmctx->br, BROPT_HAS_IPV6_ADDR, false); in br_ip6_multicast_alloc_query()
1153 br_opt_toggle(brmctx->br, BROPT_HAS_IPV6_ADDR, true); in br_ip6_multicast_alloc_query()
1154 ipv6_eth_mc_map(&ip6h->daddr, eth->h_dest); in br_ip6_multicast_alloc_query()
1169 skb_set_transport_header(skb, skb->len); in br_ip6_multicast_alloc_query()
1170 interval = ipv6_addr_any(group) ? in br_ip6_multicast_alloc_query()
1171 brmctx->multicast_query_response_interval : in br_ip6_multicast_alloc_query()
1172 brmctx->multicast_last_member_interval; in br_ip6_multicast_alloc_query()
1174 switch (brmctx->multicast_mld_version) { in br_ip6_multicast_alloc_query()
1177 mldq->mld_type = ICMPV6_MGM_QUERY; in br_ip6_multicast_alloc_query()
1178 mldq->mld_code = 0; in br_ip6_multicast_alloc_query()
1179 mldq->mld_cksum = 0; in br_ip6_multicast_alloc_query()
1180 mldq->mld_maxdelay = htons((u16)jiffies_to_msecs(interval)); in br_ip6_multicast_alloc_query()
1181 mldq->mld_reserved = 0; in br_ip6_multicast_alloc_query()
1182 mldq->mld_mca = *group; in br_ip6_multicast_alloc_query()
1183 csum = &mldq->mld_cksum; in br_ip6_multicast_alloc_query()
1188 mld2q->mld2q_mrc = htons((u16)jiffies_to_msecs(interval)); in br_ip6_multicast_alloc_query()
1189 mld2q->mld2q_type = ICMPV6_MGM_QUERY; in br_ip6_multicast_alloc_query()
1190 mld2q->mld2q_code = 0; in br_ip6_multicast_alloc_query()
1191 mld2q->mld2q_cksum = 0; in br_ip6_multicast_alloc_query()
1192 mld2q->mld2q_resv1 = 0; in br_ip6_multicast_alloc_query()
1193 mld2q->mld2q_resv2 = 0; in br_ip6_multicast_alloc_query()
1194 mld2q->mld2q_suppress = sflag; in br_ip6_multicast_alloc_query()
1195 mld2q->mld2q_qrv = 2; in br_ip6_multicast_alloc_query()
1196 mld2q->mld2q_nsrcs = htons(llqt_srcs); in br_ip6_multicast_alloc_query()
1197 mld2q->mld2q_qqic = brmctx->multicast_query_interval / HZ; in br_ip6_multicast_alloc_query()
1198 mld2q->mld2q_mca = *group; in br_ip6_multicast_alloc_query()
1199 csum = &mld2q->mld2q_cksum; in br_ip6_multicast_alloc_query()
1205 hlist_for_each_entry(ent, &pg->src_list, node) { in br_ip6_multicast_alloc_query()
1206 if (over_llqt == time_after(ent->timer.expires, in br_ip6_multicast_alloc_query()
1208 ent->src_query_rexmit_cnt > 0) { in br_ip6_multicast_alloc_query()
1209 mld2q->mld2q_srcs[llqt_srcs++] = ent->addr.src.ip6; in br_ip6_multicast_alloc_query()
1210 ent->src_query_rexmit_cnt--; in br_ip6_multicast_alloc_query()
1211 if (need_rexmit && ent->src_query_rexmit_cnt) in br_ip6_multicast_alloc_query()
1215 if (WARN_ON(llqt_srcs != ntohs(mld2q->mld2q_nsrcs))) { in br_ip6_multicast_alloc_query()
1227 *csum = csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr, mld_hdr_size, in br_ip6_multicast_alloc_query()
1242 struct br_ip *group, in br_multicast_alloc_query() argument
1249 switch (group->proto) { in br_multicast_alloc_query()
1251 ip4_dst = ip_dst ? ip_dst->dst.ip4 : htonl(INADDR_ALLHOSTS_GROUP); in br_multicast_alloc_query()
1253 ip4_dst, group->dst.ip4, in br_multicast_alloc_query()
1262 ip6_dst = ip_dst->dst.ip6; in br_multicast_alloc_query()
1268 &ip6_dst, &group->dst.ip6, in br_multicast_alloc_query()
1279 struct br_ip *group) in br_multicast_new_group() argument
1284 mp = br_mdb_ip_get(br, group); in br_multicast_new_group()
1288 if (atomic_read(&br->mdb_hash_tbl.nelems) >= br->hash_max) { in br_multicast_new_group()
1289 trace_br_mdb_full(br->dev, group); in br_multicast_new_group()
1290 br_mc_disabled_update(br->dev, false, NULL); in br_multicast_new_group()
1292 return ERR_PTR(-E2BIG); in br_multicast_new_group()
1297 return ERR_PTR(-ENOMEM); in br_multicast_new_group()
1299 mp->br = br; in br_multicast_new_group()
1300 mp->addr = *group; in br_multicast_new_group()
1301 mp->mcast_gc.destroy = br_multicast_destroy_mdb_entry; in br_multicast_new_group()
1302 timer_setup(&mp->timer, br_multicast_group_expired, 0); in br_multicast_new_group()
1303 err = rhashtable_lookup_insert_fast(&br->mdb_hash_tbl, &mp->rhnode, in br_multicast_new_group()
1309 hlist_add_head_rcu(&mp->mdb_node, &br->mdb_list); in br_multicast_new_group()
1319 struct net_bridge *br = src->br; in br_multicast_group_src_expired()
1321 spin_lock(&br->multicast_lock); in br_multicast_group_src_expired()
1322 if (hlist_unhashed(&src->node) || !netif_running(br->dev) || in br_multicast_group_src_expired()
1323 timer_pending(&src->timer)) in br_multicast_group_src_expired()
1326 pg = src->pg; in br_multicast_group_src_expired()
1327 if (pg->filter_mode == MCAST_INCLUDE) { in br_multicast_group_src_expired()
1329 if (!hlist_empty(&pg->src_list)) in br_multicast_group_src_expired()
1337 spin_unlock(&br->multicast_lock); in br_multicast_group_src_expired()
1345 switch (ip->proto) { in br_multicast_find_group_src()
1347 hlist_for_each_entry(ent, &pg->src_list, node) in br_multicast_find_group_src()
1348 if (ip->src.ip4 == ent->addr.src.ip4) in br_multicast_find_group_src()
1353 hlist_for_each_entry(ent, &pg->src_list, node) in br_multicast_find_group_src()
1354 if (!ipv6_addr_cmp(&ent->addr.src.ip6, &ip->src.ip6)) in br_multicast_find_group_src()
1368 if (unlikely(pg->src_ents >= PG_SRC_ENT_LIMIT)) in br_multicast_new_group_src()
1371 switch (src_ip->proto) { in br_multicast_new_group_src()
1373 if (ipv4_is_zeronet(src_ip->src.ip4) || in br_multicast_new_group_src()
1374 ipv4_is_multicast(src_ip->src.ip4)) in br_multicast_new_group_src()
1379 if (ipv6_addr_any(&src_ip->src.ip6) || in br_multicast_new_group_src()
1380 ipv6_addr_is_multicast(&src_ip->src.ip6)) in br_multicast_new_group_src()
1390 grp_src->pg = pg; in br_multicast_new_group_src()
1391 grp_src->br = pg->key.port->br; in br_multicast_new_group_src()
1392 grp_src->addr = *src_ip; in br_multicast_new_group_src()
1393 grp_src->mcast_gc.destroy = br_multicast_destroy_group_src; in br_multicast_new_group_src()
1394 timer_setup(&grp_src->timer, br_multicast_group_src_expired, 0); in br_multicast_new_group_src()
1396 hlist_add_head_rcu(&grp_src->node, &pg->src_list); in br_multicast_new_group_src()
1397 pg->src_ents++; in br_multicast_new_group_src()
1404 const struct br_ip *group, in br_multicast_new_port_group() argument
1415 err = br_multicast_port_ngroups_inc(port, group, extack); in br_multicast_new_port_group()
1421 NL_SET_ERR_MSG_MOD(extack, "Couldn't allocate new port group"); in br_multicast_new_port_group()
1425 p->key.addr = *group; in br_multicast_new_port_group()
1426 p->key.port = port; in br_multicast_new_port_group()
1427 p->flags = flags; in br_multicast_new_port_group()
1428 p->filter_mode = filter_mode; in br_multicast_new_port_group()
1429 p->rt_protocol = rt_protocol; in br_multicast_new_port_group()
1430 p->eht_host_tree = RB_ROOT; in br_multicast_new_port_group()
1431 p->eht_set_tree = RB_ROOT; in br_multicast_new_port_group()
1432 p->mcast_gc.destroy = br_multicast_destroy_port_group; in br_multicast_new_port_group()
1433 INIT_HLIST_HEAD(&p->src_list); in br_multicast_new_port_group()
1435 if (!br_multicast_is_star_g(group) && in br_multicast_new_port_group()
1436 rhashtable_lookup_insert_fast(&port->br->sg_port_tbl, &p->rhnode, in br_multicast_new_port_group()
1438 NL_SET_ERR_MSG_MOD(extack, "Couldn't insert new port group"); in br_multicast_new_port_group()
1442 rcu_assign_pointer(p->next, next); in br_multicast_new_port_group()
1443 timer_setup(&p->timer, br_multicast_port_group_expired, 0); in br_multicast_new_port_group()
1444 timer_setup(&p->rexmit_timer, br_multicast_port_group_rexmit, 0); in br_multicast_new_port_group()
1445 hlist_add_head(&p->mglist, &port->mglist); in br_multicast_new_port_group()
1448 memcpy(p->eth_addr, src, ETH_ALEN); in br_multicast_new_port_group()
1450 eth_broadcast_addr(p->eth_addr); in br_multicast_new_port_group()
1457 br_multicast_port_ngroups_dec(port, group->vid); in br_multicast_new_port_group()
1463 struct net_bridge_port *port = p->key.port; in br_multicast_del_port_group()
1464 __u16 vid = p->key.addr.vid; in br_multicast_del_port_group()
1466 hlist_del_init(&p->mglist); in br_multicast_del_port_group()
1467 if (!br_multicast_is_star_g(&p->key.addr)) in br_multicast_del_port_group()
1468 rhashtable_remove_fast(&port->br->sg_port_tbl, &p->rhnode, in br_multicast_del_port_group()
1477 if (!mp->host_joined) { in br_multicast_host_join()
1478 mp->host_joined = true; in br_multicast_host_join()
1479 if (br_multicast_is_star_g(&mp->addr)) in br_multicast_host_join()
1482 br_mdb_notify(mp->br->dev, mp, NULL, RTM_NEWMDB); in br_multicast_host_join()
1485 if (br_group_is_l2(&mp->addr)) in br_multicast_host_join()
1488 mod_timer(&mp->timer, jiffies + brmctx->multicast_membership_interval); in br_multicast_host_join()
1493 if (!mp->host_joined) in br_multicast_host_leave()
1496 mp->host_joined = false; in br_multicast_host_leave()
1497 if (br_multicast_is_star_g(&mp->addr)) in br_multicast_host_leave()
1500 br_mdb_notify(mp->br->dev, mp, NULL, RTM_DELMDB); in br_multicast_host_leave()
1506 struct br_ip *group, in __br_multicast_add_group() argument
1520 mp = br_multicast_new_group(brmctx->br, group); in __br_multicast_add_group()
1529 for (pp = &mp->ports; in __br_multicast_add_group()
1530 (p = mlock_dereference(*pp, brmctx->br)) != NULL; in __br_multicast_add_group()
1531 pp = &p->next) { in __br_multicast_add_group()
1532 if (br_port_group_equal(p, pmctx->port, src)) in __br_multicast_add_group()
1534 if ((unsigned long)p->key.port < (unsigned long)pmctx->port) in __br_multicast_add_group()
1538 p = br_multicast_new_port_group(pmctx->port, group, *pp, 0, src, in __br_multicast_add_group()
1541 p = ERR_PTR(-ENOMEM); in __br_multicast_add_group()
1546 p->flags |= MDB_PG_FLAGS_BLOCKED; in __br_multicast_add_group()
1547 br_mdb_notify(brmctx->br->dev, mp, p, RTM_NEWMDB); in __br_multicast_add_group()
1551 mod_timer(&p->timer, in __br_multicast_add_group()
1552 now + brmctx->multicast_membership_interval); in __br_multicast_add_group()
1560 struct br_ip *group, in br_multicast_add_group() argument
1568 spin_lock(&brmctx->br->multicast_lock); in br_multicast_add_group()
1569 pg = __br_multicast_add_group(brmctx, pmctx, group, src, filter_mode, in br_multicast_add_group()
1573 spin_unlock(&brmctx->br->multicast_lock); in br_multicast_add_group()
1580 __be32 group, in br_ip4_multicast_add_group() argument
1588 if (ipv4_is_local_multicast(group)) in br_ip4_multicast_add_group()
1592 br_group.dst.ip4 = group; in br_ip4_multicast_add_group()
1604 const struct in6_addr *group, in br_ip6_multicast_add_group() argument
1612 if (ipv6_addr_is_ll_all_nodes(group)) in br_ip6_multicast_add_group()
1616 br_group.dst.ip6 = *group; in br_ip6_multicast_add_group()
1637 return br_multicast_rport_del(&pmctx->ip4_rlist); in br_ip4_multicast_rport_del()
1643 return br_multicast_rport_del(&pmctx->ip6_rlist); in br_ip6_multicast_rport_del()
1653 struct net_bridge *br = pmctx->port->br; in br_multicast_router_expired()
1656 spin_lock(&br->multicast_lock); in br_multicast_router_expired()
1657 if (pmctx->multicast_router == MDB_RTR_TYPE_DISABLED || in br_multicast_router_expired()
1658 pmctx->multicast_router == MDB_RTR_TYPE_PERM || in br_multicast_router_expired()
1665 spin_unlock(&br->multicast_lock); in br_multicast_router_expired()
1673 br_multicast_router_expired(pmctx, t, &pmctx->ip4_rlist); in br_ip4_multicast_router_expired()
1682 br_multicast_router_expired(pmctx, t, &pmctx->ip6_rlist); in br_ip6_multicast_router_expired()
1690 .orig_dev = p->dev, in br_mc_router_state_change()
1696 switchdev_port_attr_set(p->dev, &attr, NULL); in br_mc_router_state_change()
1702 spin_lock(&brmctx->br->multicast_lock); in br_multicast_local_router_expired()
1703 if (brmctx->multicast_router == MDB_RTR_TYPE_DISABLED || in br_multicast_local_router_expired()
1704 brmctx->multicast_router == MDB_RTR_TYPE_PERM || in br_multicast_local_router_expired()
1709 br_mc_router_state_change(brmctx->br, false); in br_multicast_local_router_expired()
1711 spin_unlock(&brmctx->br->multicast_lock); in br_multicast_local_router_expired()
1735 spin_lock(&brmctx->br->multicast_lock); in br_multicast_querier_expired()
1736 if (!netif_running(brmctx->br->dev) || in br_multicast_querier_expired()
1738 !br_opt_get(brmctx->br, BROPT_MULTICAST_ENABLED)) in br_multicast_querier_expired()
1744 spin_unlock(&brmctx->br->multicast_lock); in br_multicast_querier_expired()
1752 br_multicast_querier_expired(brmctx, &brmctx->ip4_own_query); in br_ip4_multicast_querier_expired()
1761 br_multicast_querier_expired(brmctx, &brmctx->ip6_own_query); in br_ip6_multicast_querier_expired()
1773 if (ip->proto == htons(ETH_P_IP)) in br_multicast_select_own_querier()
1774 brmctx->ip4_querier.addr.src.ip4 = ip_hdr(skb)->saddr; in br_multicast_select_own_querier()
1777 brmctx->ip6_querier.addr.src.ip6 = ipv6_hdr(skb)->saddr; in br_multicast_select_own_querier()
1785 struct br_ip *group, in __br_multicast_send_query() argument
1799 skb = br_multicast_alloc_query(brmctx, pmctx, pg, ip_dst, group, in __br_multicast_send_query()
1806 skb->dev = pmctx->port->dev; in __br_multicast_send_query()
1807 br_multicast_count(brmctx->br, pmctx->port, skb, igmp_type, in __br_multicast_send_query()
1810 dev_net(pmctx->port->dev), NULL, skb, NULL, skb->dev, in __br_multicast_send_query()
1818 br_multicast_select_own_querier(brmctx, group, skb); in __br_multicast_send_query()
1819 br_multicast_count(brmctx->br, NULL, skb, igmp_type, in __br_multicast_send_query()
1832 seq = read_seqcount_begin(&querier->seq); in br_multicast_read_querier()
1833 dest->port_ifidx = querier->port_ifidx; in br_multicast_read_querier()
1834 memcpy(&dest->addr, &querier->addr, sizeof(struct br_ip)); in br_multicast_read_querier()
1835 } while (read_seqcount_retry(&querier->seq, seq)); in br_multicast_read_querier()
1843 write_seqcount_begin(&querier->seq); in br_multicast_update_querier()
1844 querier->port_ifidx = ifindex; in br_multicast_update_querier()
1845 memcpy(&querier->addr, saddr, sizeof(*saddr)); in br_multicast_update_querier()
1846 write_seqcount_end(&querier->seq); in br_multicast_update_querier()
1859 !br_opt_get(brmctx->br, BROPT_MULTICAST_ENABLED) || in br_multicast_send_query()
1860 !brmctx->multicast_querier) in br_multicast_send_query()
1865 if (pmctx ? (own_query == &pmctx->ip4_own_query) : in br_multicast_send_query()
1866 (own_query == &brmctx->ip4_own_query)) { in br_multicast_send_query()
1867 querier = &brmctx->ip4_querier; in br_multicast_send_query()
1868 other_query = &brmctx->ip4_other_query; in br_multicast_send_query()
1872 querier = &brmctx->ip6_querier; in br_multicast_send_query()
1873 other_query = &brmctx->ip6_other_query; in br_multicast_send_query()
1878 if (!other_query || timer_pending(&other_query->timer)) in br_multicast_send_query()
1882 if (!pmctx && querier->port_ifidx) { in br_multicast_send_query()
1892 time += own_query->startup_sent < brmctx->multicast_startup_query_count ? in br_multicast_send_query()
1893 brmctx->multicast_startup_query_interval : in br_multicast_send_query()
1894 brmctx->multicast_query_interval; in br_multicast_send_query()
1895 mod_timer(&own_query->timer, time); in br_multicast_send_query()
1902 struct net_bridge *br = pmctx->port->br; in br_multicast_port_query_expired()
1905 spin_lock(&br->multicast_lock); in br_multicast_port_query_expired()
1910 if (query->startup_sent < brmctx->multicast_startup_query_count) in br_multicast_port_query_expired()
1911 query->startup_sent++; in br_multicast_port_query_expired()
1916 spin_unlock(&br->multicast_lock); in br_multicast_port_query_expired()
1924 br_multicast_port_query_expired(pmctx, &pmctx->ip4_own_query); in br_ip4_multicast_port_query_expired()
1933 br_multicast_port_query_expired(pmctx, &pmctx->ip6_own_query); in br_ip6_multicast_port_query_expired()
1941 struct net_bridge *br = pg->key.port->br; in br_multicast_port_group_rexmit()
1946 spin_lock(&br->multicast_lock); in br_multicast_port_group_rexmit()
1947 if (!netif_running(br->dev) || hlist_unhashed(&pg->mglist) || in br_multicast_port_group_rexmit()
1955 if (!brmctx->multicast_querier) in br_multicast_port_group_rexmit()
1958 if (pg->key.addr.proto == htons(ETH_P_IP)) in br_multicast_port_group_rexmit()
1959 other_query = &brmctx->ip4_other_query; in br_multicast_port_group_rexmit()
1962 other_query = &brmctx->ip6_other_query; in br_multicast_port_group_rexmit()
1965 if (!other_query || timer_pending(&other_query->timer)) in br_multicast_port_group_rexmit()
1968 if (pg->grp_query_rexmit_cnt) { in br_multicast_port_group_rexmit()
1969 pg->grp_query_rexmit_cnt--; in br_multicast_port_group_rexmit()
1970 __br_multicast_send_query(brmctx, pmctx, pg, &pg->key.addr, in br_multicast_port_group_rexmit()
1971 &pg->key.addr, false, 1, NULL); in br_multicast_port_group_rexmit()
1973 __br_multicast_send_query(brmctx, pmctx, pg, &pg->key.addr, in br_multicast_port_group_rexmit()
1974 &pg->key.addr, true, 0, &need_rexmit); in br_multicast_port_group_rexmit()
1976 if (pg->grp_query_rexmit_cnt || need_rexmit) in br_multicast_port_group_rexmit()
1977 mod_timer(&pg->rexmit_timer, jiffies + in br_multicast_port_group_rexmit()
1978 brmctx->multicast_last_member_interval); in br_multicast_port_group_rexmit()
1980 spin_unlock(&br->multicast_lock); in br_multicast_port_group_rexmit()
2000 pmctx->port = port; in br_multicast_port_ctx_init()
2001 pmctx->vlan = vlan; in br_multicast_port_ctx_init()
2002 pmctx->multicast_router = MDB_RTR_TYPE_TEMP_QUERY; in br_multicast_port_ctx_init()
2003 timer_setup(&pmctx->ip4_mc_router_timer, in br_multicast_port_ctx_init()
2005 timer_setup(&pmctx->ip4_own_query.timer, in br_multicast_port_ctx_init()
2008 timer_setup(&pmctx->ip6_mc_router_timer, in br_multicast_port_ctx_init()
2010 timer_setup(&pmctx->ip6_own_query.timer, in br_multicast_port_ctx_init()
2018 del_timer_sync(&pmctx->ip6_mc_router_timer); in br_multicast_port_ctx_deinit()
2020 del_timer_sync(&pmctx->ip4_mc_router_timer); in br_multicast_port_ctx_deinit()
2027 port->multicast_eht_hosts_limit = BR_MCAST_DEFAULT_EHT_HOSTS_LIMIT; in br_multicast_add_port()
2028 br_multicast_port_ctx_init(port, NULL, &port->multicast_ctx); in br_multicast_add_port()
2030 err = br_mc_disabled_update(port->dev, in br_multicast_add_port()
2031 br_opt_get(port->br, in br_multicast_add_port()
2034 if (err && err != -EOPNOTSUPP) in br_multicast_add_port()
2037 port->mcast_stats = netdev_alloc_pcpu_stats(struct bridge_mcast_stats); in br_multicast_add_port()
2038 if (!port->mcast_stats) in br_multicast_add_port()
2039 return -ENOMEM; in br_multicast_add_port()
2046 struct net_bridge *br = port->br; in br_multicast_del_port()
2051 spin_lock_bh(&br->multicast_lock); in br_multicast_del_port()
2052 hlist_for_each_entry_safe(pg, n, &port->mglist, mglist) in br_multicast_del_port()
2054 spin_unlock_bh(&br->multicast_lock); in br_multicast_del_port()
2055 flush_work(&br->mcast_gc_work); in br_multicast_del_port()
2056 br_multicast_port_ctx_deinit(&port->multicast_ctx); in br_multicast_del_port()
2057 free_percpu(port->mcast_stats); in br_multicast_del_port()
2062 query->startup_sent = 0; in br_multicast_enable()
2064 if (try_to_del_timer_sync(&query->timer) >= 0 || in br_multicast_enable()
2065 del_timer(&query->timer)) in br_multicast_enable()
2066 mod_timer(&query->timer, jiffies); in br_multicast_enable()
2071 struct net_bridge *br = pmctx->port->br; in __br_multicast_enable_port_ctx()
2076 !netif_running(br->dev)) in __br_multicast_enable_port_ctx()
2079 br_multicast_enable(&pmctx->ip4_own_query); in __br_multicast_enable_port_ctx()
2081 br_multicast_enable(&pmctx->ip6_own_query); in __br_multicast_enable_port_ctx()
2083 if (pmctx->multicast_router == MDB_RTR_TYPE_PERM) { in __br_multicast_enable_port_ctx()
2100 hlist_for_each_entry(pg, &pmctx->port->mglist, mglist) { in __br_multicast_enable_port_ctx()
2101 if (pg->key.addr.vid == pmctx->vlan->vid) in __br_multicast_enable_port_ctx()
2104 WRITE_ONCE(pmctx->mdb_n_entries, n); in __br_multicast_enable_port_ctx()
2110 struct net_bridge *br = port->br; in br_multicast_enable_port()
2112 spin_lock_bh(&br->multicast_lock); in br_multicast_enable_port()
2113 __br_multicast_enable_port_ctx(&port->multicast_ctx); in br_multicast_enable_port()
2114 spin_unlock_bh(&br->multicast_lock); in br_multicast_enable_port()
2123 hlist_for_each_entry_safe(pg, n, &pmctx->port->mglist, mglist) in __br_multicast_disable_port_ctx()
2124 if (!(pg->flags & MDB_PG_FLAGS_PERMANENT) && in __br_multicast_disable_port_ctx()
2126 pg->key.addr.vid == pmctx->vlan->vid)) in __br_multicast_disable_port_ctx()
2127 br_multicast_find_del_pg(pmctx->port->br, pg); in __br_multicast_disable_port_ctx()
2130 del_timer(&pmctx->ip4_mc_router_timer); in __br_multicast_disable_port_ctx()
2131 del_timer(&pmctx->ip4_own_query.timer); in __br_multicast_disable_port_ctx()
2134 del_timer(&pmctx->ip6_mc_router_timer); in __br_multicast_disable_port_ctx()
2135 del_timer(&pmctx->ip6_own_query.timer); in __br_multicast_disable_port_ctx()
2142 spin_lock_bh(&port->br->multicast_lock); in br_multicast_disable_port()
2143 __br_multicast_disable_port_ctx(&port->multicast_ctx); in br_multicast_disable_port()
2144 spin_unlock_bh(&port->br->multicast_lock); in br_multicast_disable_port()
2153 hlist_for_each_entry_safe(ent, tmp, &pg->src_list, node) in __grp_src_delete_marked()
2154 if (ent->flags & BR_SGRP_F_DELETE) { in __grp_src_delete_marked()
2165 mod_timer(&src->timer, expires); in __grp_src_mod_timer()
2174 u32 lmqc = brmctx->multicast_last_member_count; in __grp_src_query_marked_and_rexmit()
2178 if (!netif_running(brmctx->br->dev) || in __grp_src_query_marked_and_rexmit()
2179 !br_opt_get(brmctx->br, BROPT_MULTICAST_ENABLED)) in __grp_src_query_marked_and_rexmit()
2182 if (pg->key.addr.proto == htons(ETH_P_IP)) in __grp_src_query_marked_and_rexmit()
2183 other_query = &brmctx->ip4_other_query; in __grp_src_query_marked_and_rexmit()
2186 other_query = &brmctx->ip6_other_query; in __grp_src_query_marked_and_rexmit()
2190 hlist_for_each_entry(ent, &pg->src_list, node) { in __grp_src_query_marked_and_rexmit()
2191 if (ent->flags & BR_SGRP_F_SEND) { in __grp_src_query_marked_and_rexmit()
2192 ent->flags &= ~BR_SGRP_F_SEND; in __grp_src_query_marked_and_rexmit()
2193 if (ent->timer.expires > lmqt) { in __grp_src_query_marked_and_rexmit()
2194 if (brmctx->multicast_querier && in __grp_src_query_marked_and_rexmit()
2196 !timer_pending(&other_query->timer)) in __grp_src_query_marked_and_rexmit()
2197 ent->src_query_rexmit_cnt = lmqc; in __grp_src_query_marked_and_rexmit()
2203 if (!brmctx->multicast_querier || in __grp_src_query_marked_and_rexmit()
2204 !other_query || timer_pending(&other_query->timer)) in __grp_src_query_marked_and_rexmit()
2207 __br_multicast_send_query(brmctx, pmctx, pg, &pg->key.addr, in __grp_src_query_marked_and_rexmit()
2208 &pg->key.addr, true, 1, NULL); in __grp_src_query_marked_and_rexmit()
2210 lmi = now + brmctx->multicast_last_member_interval; in __grp_src_query_marked_and_rexmit()
2211 if (!timer_pending(&pg->rexmit_timer) || in __grp_src_query_marked_and_rexmit()
2212 time_after(pg->rexmit_timer.expires, lmi)) in __grp_src_query_marked_and_rexmit()
2213 mod_timer(&pg->rexmit_timer, lmi); in __grp_src_query_marked_and_rexmit()
2223 if (!netif_running(brmctx->br->dev) || in __grp_send_query_and_rexmit()
2224 !br_opt_get(brmctx->br, BROPT_MULTICAST_ENABLED)) in __grp_send_query_and_rexmit()
2227 if (pg->key.addr.proto == htons(ETH_P_IP)) in __grp_send_query_and_rexmit()
2228 other_query = &brmctx->ip4_other_query; in __grp_send_query_and_rexmit()
2231 other_query = &brmctx->ip6_other_query; in __grp_send_query_and_rexmit()
2234 if (brmctx->multicast_querier && in __grp_send_query_and_rexmit()
2235 other_query && !timer_pending(&other_query->timer)) { in __grp_send_query_and_rexmit()
2236 lmi = now + brmctx->multicast_last_member_interval; in __grp_send_query_and_rexmit()
2237 pg->grp_query_rexmit_cnt = brmctx->multicast_last_member_count - 1; in __grp_send_query_and_rexmit()
2238 __br_multicast_send_query(brmctx, pmctx, pg, &pg->key.addr, in __grp_send_query_and_rexmit()
2239 &pg->key.addr, false, 0, NULL); in __grp_send_query_and_rexmit()
2240 if (!timer_pending(&pg->rexmit_timer) || in __grp_send_query_and_rexmit()
2241 time_after(pg->rexmit_timer.expires, lmi)) in __grp_send_query_and_rexmit()
2242 mod_timer(&pg->rexmit_timer, lmi); in __grp_send_query_and_rexmit()
2245 if (pg->filter_mode == MCAST_EXCLUDE && in __grp_send_query_and_rexmit()
2246 (!timer_pending(&pg->timer) || in __grp_send_query_and_rexmit()
2247 time_after(pg->timer.expires, now + br_multicast_lmqt(brmctx)))) in __grp_send_query_and_rexmit()
2248 mod_timer(&pg->timer, now + br_multicast_lmqt(brmctx)); in __grp_send_query_and_rexmit()
2254 * EXCLUDE (X,Y) ALLOW (A) EXCLUDE (X+A,Y-A) (A)=GMI
2268 src_ip.proto = pg->key.addr.proto; in br_multicast_isinc_allow()
2290 * INCLUDE (A) IS_EX (B) EXCLUDE (A*B,B-A) (B-A)=0
2291 * Delete (A-B)
2292 * Group Timer=GMI
2303 hlist_for_each_entry(ent, &pg->src_list, node) in __grp_src_isexc_incl()
2304 ent->flags |= BR_SGRP_F_DELETE; in __grp_src_isexc_incl()
2307 src_ip.proto = pg->key.addr.proto; in __grp_src_isexc_incl()
2312 ent->flags &= ~BR_SGRP_F_DELETE; in __grp_src_isexc_incl()
2326 * EXCLUDE (X,Y) IS_EX (A) EXCLUDE (A-Y,Y*A) (A-X-Y)=GMI
2327 * Delete (X-A)
2328 * Delete (Y-A)
2329 * Group Timer=GMI
2342 hlist_for_each_entry(ent, &pg->src_list, node) in __grp_src_isexc_excl()
2343 ent->flags |= BR_SGRP_F_DELETE; in __grp_src_isexc_excl()
2346 src_ip.proto = pg->key.addr.proto; in __grp_src_isexc_excl()
2351 ent->flags &= ~BR_SGRP_F_DELETE; in __grp_src_isexc_excl()
2379 switch (pg->filter_mode) { in br_multicast_isexc()
2392 pg->filter_mode = MCAST_EXCLUDE; in br_multicast_isexc()
2393 mod_timer(&pg->timer, jiffies + br_multicast_gmi(brmctx)); in br_multicast_isexc()
2400 * Send Q(G,A-B)
2408 u32 src_idx, to_send = pg->src_ents; in __grp_src_toin_incl()
2414 hlist_for_each_entry(ent, &pg->src_list, node) in __grp_src_toin_incl()
2415 ent->flags |= BR_SGRP_F_SEND; in __grp_src_toin_incl()
2418 src_ip.proto = pg->key.addr.proto; in __grp_src_toin_incl()
2423 ent->flags &= ~BR_SGRP_F_SEND; in __grp_src_toin_incl()
2424 to_send--; in __grp_src_toin_incl()
2445 * EXCLUDE (X,Y) TO_IN (A) EXCLUDE (X+A,Y-A) (A)=GMI
2446 * Send Q(G,X-A)
2455 u32 src_idx, to_send = pg->src_ents; in __grp_src_toin_excl()
2461 hlist_for_each_entry(ent, &pg->src_list, node) in __grp_src_toin_excl()
2462 if (timer_pending(&ent->timer)) in __grp_src_toin_excl()
2463 ent->flags |= BR_SGRP_F_SEND; in __grp_src_toin_excl()
2466 src_ip.proto = pg->key.addr.proto; in __grp_src_toin_excl()
2471 if (timer_pending(&ent->timer)) { in __grp_src_toin_excl()
2472 ent->flags &= ~BR_SGRP_F_SEND; in __grp_src_toin_excl()
2473 to_send--; in __grp_src_toin_excl()
2504 switch (pg->filter_mode) { in br_multicast_toin()
2516 pg->flags |= MDB_PG_FLAGS_FAST_LEAVE; in br_multicast_toin()
2517 br_multicast_find_del_pg(pg->key.port->br, pg); in br_multicast_toin()
2528 * INCLUDE (A) TO_EX (B) EXCLUDE (A*B,B-A) (B-A)=0
2529 * Delete (A-B)
2531 * Group Timer=GMI
2543 hlist_for_each_entry(ent, &pg->src_list, node) in __grp_src_toex_incl()
2544 ent->flags = (ent->flags & ~BR_SGRP_F_SEND) | BR_SGRP_F_DELETE; in __grp_src_toex_incl()
2547 src_ip.proto = pg->key.addr.proto; in __grp_src_toex_incl()
2552 ent->flags = (ent->flags & ~BR_SGRP_F_DELETE) | in __grp_src_toex_incl()
2571 * EXCLUDE (X,Y) TO_EX (A) EXCLUDE (A-Y,Y*A) (A-X-Y)=Group Timer
2572 * Delete (X-A)
2573 * Delete (Y-A)
2574 * Send Q(G,A-Y)
2575 * Group Timer=GMI
2588 hlist_for_each_entry(ent, &pg->src_list, node) in __grp_src_toex_excl()
2589 ent->flags = (ent->flags & ~BR_SGRP_F_SEND) | BR_SGRP_F_DELETE; in __grp_src_toex_excl()
2592 src_ip.proto = pg->key.addr.proto; in __grp_src_toex_excl()
2597 ent->flags &= ~BR_SGRP_F_DELETE; in __grp_src_toex_excl()
2601 __grp_src_mod_timer(ent, pg->timer.expires); in __grp_src_toex_excl()
2605 if (ent && timer_pending(&ent->timer)) { in __grp_src_toex_excl()
2606 ent->flags |= BR_SGRP_F_SEND; in __grp_src_toex_excl()
2631 switch (pg->filter_mode) { in br_multicast_toex()
2644 pg->filter_mode = MCAST_EXCLUDE; in br_multicast_toex()
2645 mod_timer(&pg->timer, jiffies + br_multicast_gmi(brmctx)); in br_multicast_toex()
2651 * INCLUDE (A) BLOCK (B) INCLUDE (A) Send Q(G,A*B)
2663 hlist_for_each_entry(ent, &pg->src_list, node) in __grp_src_block_incl()
2664 ent->flags &= ~BR_SGRP_F_SEND; in __grp_src_block_incl()
2667 src_ip.proto = pg->key.addr.proto; in __grp_src_block_incl()
2672 ent->flags |= BR_SGRP_F_SEND; in __grp_src_block_incl()
2688 * EXCLUDE (X,Y) BLOCK (A) EXCLUDE (X+(A-Y),Y) (A-X-Y)=Group Timer
2689 * Send Q(G,A-Y)
2701 hlist_for_each_entry(ent, &pg->src_list, node) in __grp_src_block_excl()
2702 ent->flags &= ~BR_SGRP_F_SEND; in __grp_src_block_excl()
2705 src_ip.proto = pg->key.addr.proto; in __grp_src_block_excl()
2712 __grp_src_mod_timer(ent, pg->timer.expires); in __grp_src_block_excl()
2716 if (ent && timer_pending(&ent->timer)) { in __grp_src_block_excl()
2717 ent->flags |= BR_SGRP_F_SEND; in __grp_src_block_excl()
2739 switch (pg->filter_mode) { in br_multicast_block()
2750 if ((pg->filter_mode == MCAST_INCLUDE && hlist_empty(&pg->src_list)) || in br_multicast_block()
2753 pg->flags |= MDB_PG_FLAGS_FAST_LEAVE; in br_multicast_block()
2754 br_multicast_find_del_pg(pg->key.port->br, pg); in br_multicast_block()
2769 struct net_bridge *br __maybe_unused = mp->br; in br_multicast_find_port()
2772 for (pg = mlock_dereference(mp->ports, br); in br_multicast_find_port()
2774 pg = mlock_dereference(pg->next, br)) in br_multicast_find_port()
2786 bool igmpv2 = brmctx->multicast_igmp_version == 2; in br_ip4_multicast_igmp3_report()
2793 __be32 group, *h_addr; in br_ip4_multicast_igmp3_report() local
2799 num = ntohs(ih->ngrec); in br_ip4_multicast_igmp3_report()
2805 return -EINVAL; in br_ip4_multicast_igmp3_report()
2807 grec = (void *)(skb->data + len - sizeof(*grec)); in br_ip4_multicast_igmp3_report()
2808 group = grec->grec_mca; in br_ip4_multicast_igmp3_report()
2809 type = grec->grec_type; in br_ip4_multicast_igmp3_report()
2810 nsrcs = ntohs(grec->grec_nsrcs); in br_ip4_multicast_igmp3_report()
2814 return -EINVAL; in br_ip4_multicast_igmp3_report()
2829 src = eth_hdr(skb)->h_source; in br_ip4_multicast_igmp3_report()
2835 group, vid, src); in br_ip4_multicast_igmp3_report()
2839 err = br_ip4_multicast_add_group(brmctx, pmctx, group, in br_ip4_multicast_igmp3_report()
2848 spin_lock(&brmctx->br->multicast_lock); in br_ip4_multicast_igmp3_report()
2852 mdst = br_mdb_ip4_get(brmctx->br, group, vid); in br_ip4_multicast_igmp3_report()
2855 pg = br_multicast_find_port(mdst, pmctx->port, src); in br_ip4_multicast_igmp3_report()
2856 if (!pg || (pg->flags & MDB_PG_FLAGS_PERMANENT)) in br_ip4_multicast_igmp3_report()
2859 grec = (void *)(skb->data + len - sizeof(*grec) - (nsrcs * 4)); in br_ip4_multicast_igmp3_report()
2860 h_addr = &ip_hdr(skb)->saddr; in br_ip4_multicast_igmp3_report()
2864 grec->grec_src, in br_ip4_multicast_igmp3_report()
2869 grec->grec_src, in br_ip4_multicast_igmp3_report()
2874 grec->grec_src, in br_ip4_multicast_igmp3_report()
2879 grec->grec_src, in br_ip4_multicast_igmp3_report()
2884 grec->grec_src, in br_ip4_multicast_igmp3_report()
2889 grec->grec_src, in br_ip4_multicast_igmp3_report()
2894 br_mdb_notify(brmctx->br->dev, mdst, pg, RTM_NEWMDB); in br_ip4_multicast_igmp3_report()
2896 spin_unlock(&brmctx->br->multicast_lock); in br_ip4_multicast_igmp3_report()
2908 bool mldv1 = brmctx->multicast_mld_version == 1; in br_ip6_multicast_mld2_report()
2922 return -EINVAL; in br_ip6_multicast_mld2_report()
2925 num = ntohs(mld2r->mld2r_ngrec); in br_ip6_multicast_mld2_report()
2936 return -EINVAL; in br_ip6_multicast_mld2_report()
2941 return -EINVAL; in br_ip6_multicast_mld2_report()
2947 return -EINVAL; in br_ip6_multicast_mld2_report()
2949 grec = (struct mld2_grec *)(skb->data + len); in br_ip6_multicast_mld2_report()
2952 switch (grec->grec_type) { in br_ip6_multicast_mld2_report()
2965 src = eth_hdr(skb)->h_source; in br_ip6_multicast_mld2_report()
2966 if ((grec->grec_type == MLD2_CHANGE_TO_INCLUDE || in br_ip6_multicast_mld2_report()
2967 grec->grec_type == MLD2_MODE_IS_INCLUDE) && in br_ip6_multicast_mld2_report()
2971 &grec->grec_mca, in br_ip6_multicast_mld2_report()
2977 &grec->grec_mca, vid, in br_ip6_multicast_mld2_report()
2986 spin_lock(&brmctx->br->multicast_lock); in br_ip6_multicast_mld2_report()
2990 mdst = br_mdb_ip6_get(brmctx->br, &grec->grec_mca, vid); in br_ip6_multicast_mld2_report()
2993 pg = br_multicast_find_port(mdst, pmctx->port, src); in br_ip6_multicast_mld2_report()
2994 if (!pg || (pg->flags & MDB_PG_FLAGS_PERMANENT)) in br_ip6_multicast_mld2_report()
2996 h_addr = &ipv6_hdr(skb)->saddr; in br_ip6_multicast_mld2_report()
2997 switch (grec->grec_type) { in br_ip6_multicast_mld2_report()
3000 grec->grec_src, nsrcs, in br_ip6_multicast_mld2_report()
3002 grec->grec_type); in br_ip6_multicast_mld2_report()
3006 grec->grec_src, nsrcs, in br_ip6_multicast_mld2_report()
3008 grec->grec_type); in br_ip6_multicast_mld2_report()
3012 grec->grec_src, nsrcs, in br_ip6_multicast_mld2_report()
3014 grec->grec_type); in br_ip6_multicast_mld2_report()
3018 grec->grec_src, nsrcs, in br_ip6_multicast_mld2_report()
3020 grec->grec_type); in br_ip6_multicast_mld2_report()
3024 grec->grec_src, nsrcs, in br_ip6_multicast_mld2_report()
3026 grec->grec_type); in br_ip6_multicast_mld2_report()
3030 grec->grec_src, nsrcs, in br_ip6_multicast_mld2_report()
3032 grec->grec_type); in br_ip6_multicast_mld2_report()
3036 br_mdb_notify(brmctx->br->dev, mdst, pg, RTM_NEWMDB); in br_ip6_multicast_mld2_report()
3038 spin_unlock(&brmctx->br->multicast_lock); in br_ip6_multicast_mld2_report()
3049 int port_ifidx = pmctx ? pmctx->port->dev->ifindex : 0; in br_multicast_select_querier()
3053 switch (saddr->proto) { in br_multicast_select_querier()
3055 querier = &brmctx->ip4_querier; in br_multicast_select_querier()
3056 own_timer = &brmctx->ip4_own_query.timer; in br_multicast_select_querier()
3057 other_timer = &brmctx->ip4_other_query.timer; in br_multicast_select_querier()
3058 if (!querier->addr.src.ip4 || in br_multicast_select_querier()
3059 ntohl(saddr->src.ip4) <= ntohl(querier->addr.src.ip4)) in br_multicast_select_querier()
3064 querier = &brmctx->ip6_querier; in br_multicast_select_querier()
3065 own_timer = &brmctx->ip6_own_query.timer; in br_multicast_select_querier()
3066 other_timer = &brmctx->ip6_other_query.timer; in br_multicast_select_querier()
3067 if (ipv6_addr_cmp(&saddr->src.ip6, &querier->addr.src.ip6) <= 0) in br_multicast_select_querier()
3090 int port_ifidx = READ_ONCE(querier->port_ifidx); in __br_multicast_get_querier_port()
3097 dev = dev_get_by_index_rcu(dev_net(br->dev), port_ifidx); in __br_multicast_get_querier_port()
3101 if (!p || p->br != br) in __br_multicast_get_querier_port()
3130 if (!br_opt_get(brmctx->br, BROPT_MULTICAST_ENABLED) || in br_multicast_dump_querier_state()
3136 return -EMSGSIZE; in br_multicast_dump_querier_state()
3139 if (!brmctx->multicast_querier && in br_multicast_dump_querier_state()
3140 !timer_pending(&brmctx->ip4_other_query.timer)) in br_multicast_dump_querier_state()
3143 br_multicast_read_querier(&brmctx->ip4_querier, &querier); in br_multicast_dump_querier_state()
3150 p = __br_multicast_get_querier_port(brmctx->br, &querier); in br_multicast_dump_querier_state()
3151 if (timer_pending(&brmctx->ip4_other_query.timer) && in br_multicast_dump_querier_state()
3153 br_timer_value(&brmctx->ip4_other_query.timer), in br_multicast_dump_querier_state()
3155 (p && nla_put_u32(skb, BRIDGE_QUERIER_IP_PORT, p->dev->ifindex)))) { in br_multicast_dump_querier_state()
3162 if (!brmctx->multicast_querier && in br_multicast_dump_querier_state()
3163 !timer_pending(&brmctx->ip6_other_query.timer)) in br_multicast_dump_querier_state()
3166 br_multicast_read_querier(&brmctx->ip6_querier, &querier); in br_multicast_dump_querier_state()
3173 p = __br_multicast_get_querier_port(brmctx->br, &querier); in br_multicast_dump_querier_state()
3174 if (timer_pending(&brmctx->ip6_other_query.timer) && in br_multicast_dump_querier_state()
3176 br_timer_value(&brmctx->ip6_other_query.timer), in br_multicast_dump_querier_state()
3179 p->dev->ifindex)))) { in br_multicast_dump_querier_state()
3194 return -EMSGSIZE; in br_multicast_dump_querier_state()
3202 if (!timer_pending(&query->timer)) in br_multicast_update_query_timer()
3203 mod_timer(&query->delay_timer, jiffies + max_delay); in br_multicast_update_query_timer()
3205 mod_timer(&query->timer, jiffies + brmctx->multicast_querier_interval); in br_multicast_update_query_timer()
3212 .orig_dev = p->dev, in br_port_mc_router_state_change()
3218 switchdev_port_attr_set(p->dev, &attr, NULL); in br_port_mc_router_state_change()
3229 if (mc_router_list == &brmctx->ip6_mc_router_list) in br_multicast_rport_from_node()
3237 return pmctx->port; in br_multicast_rport_from_node()
3266 if (rnode != &pmctx->ip6_rlist) in br_multicast_no_router_otherpf()
3267 return hlist_unhashed(&pmctx->ip6_rlist); in br_multicast_no_router_otherpf()
3269 return hlist_unhashed(&pmctx->ip4_rlist); in br_multicast_no_router_otherpf()
3277 * and locked by br->multicast_lock and RCU
3289 slot = br_multicast_get_rport_slot(brmctx, pmctx->port, mc_router_list); in br_multicast_add_router()
3301 br_rtr_notify(pmctx->port->br->dev, pmctx, RTM_NEWMDB); in br_multicast_add_router()
3302 br_port_mc_router_state_change(pmctx->port, true); in br_multicast_add_router()
3308 * and locked by br->multicast_lock and RCU
3313 br_multicast_add_router(brmctx, pmctx, &pmctx->ip4_rlist, in br_ip4_multicast_add_router()
3314 &brmctx->ip4_mc_router_list); in br_ip4_multicast_add_router()
3319 * and locked by br->multicast_lock and RCU
3325 br_multicast_add_router(brmctx, pmctx, &pmctx->ip6_rlist, in br_ip6_multicast_add_router()
3326 &brmctx->ip6_mc_router_list); in br_ip6_multicast_add_router()
3342 if (brmctx->multicast_router == MDB_RTR_TYPE_TEMP_QUERY) { in br_multicast_mark_router()
3345 br_mc_router_state_change(brmctx->br, true); in br_multicast_mark_router()
3346 mod_timer(timer, now + brmctx->multicast_querier_interval); in br_multicast_mark_router()
3351 if (pmctx->multicast_router == MDB_RTR_TYPE_DISABLED || in br_multicast_mark_router()
3352 pmctx->multicast_router == MDB_RTR_TYPE_PERM) in br_multicast_mark_router()
3356 mod_timer(timer, now + brmctx->multicast_querier_interval); in br_multicast_mark_router()
3362 struct timer_list *timer = &brmctx->ip4_mc_router_timer; in br_ip4_multicast_mark_router()
3366 timer = &pmctx->ip4_mc_router_timer; in br_ip4_multicast_mark_router()
3367 rlist = &pmctx->ip4_rlist; in br_ip4_multicast_mark_router()
3371 &brmctx->ip4_mc_router_list); in br_ip4_multicast_mark_router()
3378 struct timer_list *timer = &brmctx->ip6_mc_router_timer; in br_ip6_multicast_mark_router()
3382 timer = &pmctx->ip6_mc_router_timer; in br_ip6_multicast_mark_router()
3383 rlist = &pmctx->ip6_rlist; in br_ip6_multicast_mark_router()
3387 &brmctx->ip6_mc_router_list); in br_ip6_multicast_mark_router()
3436 __be32 group; in br_ip4_multicast_query() local
3438 spin_lock(&brmctx->br->multicast_lock); in br_ip4_multicast_query()
3442 group = ih->group; in br_ip4_multicast_query()
3445 max_delay = ih->code * (HZ / IGMP_TIMER_SCALE); in br_ip4_multicast_query()
3449 group = 0; in br_ip4_multicast_query()
3453 if (ih3->nsrcs || in br_ip4_multicast_query()
3454 (brmctx->multicast_igmp_version == 3 && group && in br_ip4_multicast_query()
3455 ih3->suppress)) in br_ip4_multicast_query()
3458 max_delay = ih3->code ? in br_ip4_multicast_query()
3459 IGMPV3_MRC(ih3->code) * (HZ / IGMP_TIMER_SCALE) : 1; in br_ip4_multicast_query()
3464 if (!group) { in br_ip4_multicast_query()
3466 saddr.src.ip4 = iph->saddr; in br_ip4_multicast_query()
3469 &brmctx->ip4_other_query, in br_ip4_multicast_query()
3474 mp = br_mdb_ip4_get(brmctx->br, group, vid); in br_ip4_multicast_query()
3478 max_delay *= brmctx->multicast_last_member_count; in br_ip4_multicast_query()
3480 if (mp->host_joined && in br_ip4_multicast_query()
3481 (timer_pending(&mp->timer) ? in br_ip4_multicast_query()
3482 time_after(mp->timer.expires, now + max_delay) : in br_ip4_multicast_query()
3483 try_to_del_timer_sync(&mp->timer) >= 0)) in br_ip4_multicast_query()
3484 mod_timer(&mp->timer, now + max_delay); in br_ip4_multicast_query()
3486 for (pp = &mp->ports; in br_ip4_multicast_query()
3487 (p = mlock_dereference(*pp, brmctx->br)) != NULL; in br_ip4_multicast_query()
3488 pp = &p->next) { in br_ip4_multicast_query()
3489 if (timer_pending(&p->timer) ? in br_ip4_multicast_query()
3490 time_after(p->timer.expires, now + max_delay) : in br_ip4_multicast_query()
3491 try_to_del_timer_sync(&p->timer) >= 0 && in br_ip4_multicast_query()
3492 (brmctx->multicast_igmp_version == 2 || in br_ip4_multicast_query()
3493 p->filter_mode == MCAST_EXCLUDE)) in br_ip4_multicast_query()
3494 mod_timer(&p->timer, now + max_delay); in br_ip4_multicast_query()
3498 spin_unlock(&brmctx->br->multicast_lock); in br_ip4_multicast_query()
3517 const struct in6_addr *group = NULL; in br_ip6_multicast_query() local
3521 spin_lock(&brmctx->br->multicast_lock); in br_ip6_multicast_query()
3527 err = -EINVAL; in br_ip6_multicast_query()
3531 max_delay = msecs_to_jiffies(ntohs(mld->mld_maxdelay)); in br_ip6_multicast_query()
3533 group = &mld->mld_mca; in br_ip6_multicast_query()
3536 err = -EINVAL; in br_ip6_multicast_query()
3540 if (!mld2q->mld2q_nsrcs) in br_ip6_multicast_query()
3541 group = &mld2q->mld2q_mca; in br_ip6_multicast_query()
3542 if (brmctx->multicast_mld_version == 2 && in br_ip6_multicast_query()
3543 !ipv6_addr_any(&mld2q->mld2q_mca) && in br_ip6_multicast_query()
3544 mld2q->mld2q_suppress) in br_ip6_multicast_query()
3550 is_general_query = group && ipv6_addr_any(group); in br_ip6_multicast_query()
3554 saddr.src.ip6 = ipv6_hdr(skb)->saddr; in br_ip6_multicast_query()
3557 &brmctx->ip6_other_query, in br_ip6_multicast_query()
3560 } else if (!group) { in br_ip6_multicast_query()
3564 mp = br_mdb_ip6_get(brmctx->br, group, vid); in br_ip6_multicast_query()
3568 max_delay *= brmctx->multicast_last_member_count; in br_ip6_multicast_query()
3569 if (mp->host_joined && in br_ip6_multicast_query()
3570 (timer_pending(&mp->timer) ? in br_ip6_multicast_query()
3571 time_after(mp->timer.expires, now + max_delay) : in br_ip6_multicast_query()
3572 try_to_del_timer_sync(&mp->timer) >= 0)) in br_ip6_multicast_query()
3573 mod_timer(&mp->timer, now + max_delay); in br_ip6_multicast_query()
3575 for (pp = &mp->ports; in br_ip6_multicast_query()
3576 (p = mlock_dereference(*pp, brmctx->br)) != NULL; in br_ip6_multicast_query()
3577 pp = &p->next) { in br_ip6_multicast_query()
3578 if (timer_pending(&p->timer) ? in br_ip6_multicast_query()
3579 time_after(p->timer.expires, now + max_delay) : in br_ip6_multicast_query()
3580 try_to_del_timer_sync(&p->timer) >= 0 && in br_ip6_multicast_query()
3581 (brmctx->multicast_mld_version == 1 || in br_ip6_multicast_query()
3582 p->filter_mode == MCAST_EXCLUDE)) in br_ip6_multicast_query()
3583 mod_timer(&p->timer, now + max_delay); in br_ip6_multicast_query()
3587 spin_unlock(&brmctx->br->multicast_lock); in br_ip6_multicast_query()
3595 struct br_ip *group, in br_multicast_leave_group() argument
3605 spin_lock(&brmctx->br->multicast_lock); in br_multicast_leave_group()
3609 mp = br_mdb_ip_get(brmctx->br, group); in br_multicast_leave_group()
3613 if (pmctx && (pmctx->port->flags & BR_MULTICAST_FAST_LEAVE)) { in br_multicast_leave_group()
3616 for (pp = &mp->ports; in br_multicast_leave_group()
3617 (p = mlock_dereference(*pp, brmctx->br)) != NULL; in br_multicast_leave_group()
3618 pp = &p->next) { in br_multicast_leave_group()
3619 if (!br_port_group_equal(p, pmctx->port, src)) in br_multicast_leave_group()
3622 if (p->flags & MDB_PG_FLAGS_PERMANENT) in br_multicast_leave_group()
3625 p->flags |= MDB_PG_FLAGS_FAST_LEAVE; in br_multicast_leave_group()
3631 if (timer_pending(&other_query->timer)) in br_multicast_leave_group()
3634 if (brmctx->multicast_querier) { in br_multicast_leave_group()
3635 __br_multicast_send_query(brmctx, pmctx, NULL, NULL, &mp->addr, in br_multicast_leave_group()
3638 time = jiffies + brmctx->multicast_last_member_count * in br_multicast_leave_group()
3639 brmctx->multicast_last_member_interval; in br_multicast_leave_group()
3641 mod_timer(&own_query->timer, time); in br_multicast_leave_group()
3643 for (p = mlock_dereference(mp->ports, brmctx->br); in br_multicast_leave_group()
3645 p = mlock_dereference(p->next, brmctx->br)) { in br_multicast_leave_group()
3646 if (!br_port_group_equal(p, pmctx->port, src)) in br_multicast_leave_group()
3649 if (!hlist_unhashed(&p->mglist) && in br_multicast_leave_group()
3650 (timer_pending(&p->timer) ? in br_multicast_leave_group()
3651 time_after(p->timer.expires, time) : in br_multicast_leave_group()
3652 try_to_del_timer_sync(&p->timer) >= 0)) { in br_multicast_leave_group()
3653 mod_timer(&p->timer, time); in br_multicast_leave_group()
3661 time = now + brmctx->multicast_last_member_count * in br_multicast_leave_group()
3662 brmctx->multicast_last_member_interval; in br_multicast_leave_group()
3665 if (mp->host_joined && in br_multicast_leave_group()
3666 (timer_pending(&mp->timer) ? in br_multicast_leave_group()
3667 time_after(mp->timer.expires, time) : in br_multicast_leave_group()
3668 try_to_del_timer_sync(&mp->timer) >= 0)) { in br_multicast_leave_group()
3669 mod_timer(&mp->timer, time); in br_multicast_leave_group()
3675 for (p = mlock_dereference(mp->ports, brmctx->br); in br_multicast_leave_group()
3677 p = mlock_dereference(p->next, brmctx->br)) { in br_multicast_leave_group()
3678 if (p->key.port != pmctx->port) in br_multicast_leave_group()
3681 if (!hlist_unhashed(&p->mglist) && in br_multicast_leave_group()
3682 (timer_pending(&p->timer) ? in br_multicast_leave_group()
3683 time_after(p->timer.expires, time) : in br_multicast_leave_group()
3684 try_to_del_timer_sync(&p->timer) >= 0)) { in br_multicast_leave_group()
3685 mod_timer(&p->timer, time); in br_multicast_leave_group()
3691 spin_unlock(&brmctx->br->multicast_lock); in br_multicast_leave_group()
3696 __be32 group, in br_ip4_multicast_leave_group() argument
3703 if (ipv4_is_local_multicast(group)) in br_ip4_multicast_leave_group()
3706 own_query = pmctx ? &pmctx->ip4_own_query : &brmctx->ip4_own_query; in br_ip4_multicast_leave_group()
3709 br_group.dst.ip4 = group; in br_ip4_multicast_leave_group()
3714 &brmctx->ip4_other_query, in br_ip4_multicast_leave_group()
3721 const struct in6_addr *group, in br_ip6_multicast_leave_group() argument
3728 if (ipv6_addr_is_ll_all_nodes(group)) in br_ip6_multicast_leave_group()
3731 own_query = pmctx ? &pmctx->ip6_own_query : &brmctx->ip6_own_query; in br_ip6_multicast_leave_group()
3734 br_group.dst.ip6 = *group; in br_ip6_multicast_leave_group()
3739 &brmctx->ip6_other_query, in br_ip6_multicast_leave_group()
3755 stats = p->mcast_stats; in br_multicast_err_count()
3757 stats = br->mcast_stats; in br_multicast_err_count()
3763 u64_stats_update_begin(&pstats->syncp); in br_multicast_err_count()
3766 pstats->mstats.igmp_parse_errors++; in br_multicast_err_count()
3770 pstats->mstats.mld_parse_errors++; in br_multicast_err_count()
3774 u64_stats_update_end(&pstats->syncp); in br_multicast_err_count()
3789 spin_lock(&brmctx->br->multicast_lock); in br_multicast_pim()
3791 spin_unlock(&brmctx->br->multicast_lock); in br_multicast_pim()
3798 if (ip_hdr(skb)->protocol != IPPROTO_IGMP || in br_ip4_multicast_mrd_rcv()
3799 igmp_hdr(skb)->type != IGMP_MRDISC_ADV) in br_ip4_multicast_mrd_rcv()
3800 return -ENOMSG; in br_ip4_multicast_mrd_rcv()
3802 spin_lock(&brmctx->br->multicast_lock); in br_ip4_multicast_mrd_rcv()
3804 spin_unlock(&brmctx->br->multicast_lock); in br_ip4_multicast_mrd_rcv()
3814 struct net_bridge_port *p = pmctx ? pmctx->port : NULL; in br_multicast_ipv4_rcv()
3821 if (err == -ENOMSG) { in br_multicast_ipv4_rcv()
3822 if (!ipv4_is_local_multicast(ip_hdr(skb)->daddr)) { in br_multicast_ipv4_rcv()
3823 BR_INPUT_SKB_CB(skb)->mrouters_only = 1; in br_multicast_ipv4_rcv()
3824 } else if (pim_ipv4_all_pim_routers(ip_hdr(skb)->daddr)) { in br_multicast_ipv4_rcv()
3825 if (ip_hdr(skb)->protocol == IPPROTO_PIM) in br_multicast_ipv4_rcv()
3827 } else if (ipv4_is_all_snoopers(ip_hdr(skb)->daddr)) { in br_multicast_ipv4_rcv()
3833 br_multicast_err_count(brmctx->br, p, skb->protocol); in br_multicast_ipv4_rcv()
3838 src = eth_hdr(skb)->h_source; in br_multicast_ipv4_rcv()
3839 BR_INPUT_SKB_CB(skb)->igmp = ih->type; in br_multicast_ipv4_rcv()
3841 switch (ih->type) { in br_multicast_ipv4_rcv()
3844 BR_INPUT_SKB_CB(skb)->mrouters_only = 1; in br_multicast_ipv4_rcv()
3845 err = br_ip4_multicast_add_group(brmctx, pmctx, ih->group, vid, in br_multicast_ipv4_rcv()
3855 br_ip4_multicast_leave_group(brmctx, pmctx, ih->group, vid, src); in br_multicast_ipv4_rcv()
3859 br_multicast_count(brmctx->br, p, skb, BR_INPUT_SKB_CB(skb)->igmp, in br_multicast_ipv4_rcv()
3870 if (icmp6_hdr(skb)->icmp6_type != ICMPV6_MRDISC_ADV) in br_ip6_multicast_mrd_rcv()
3873 spin_lock(&brmctx->br->multicast_lock); in br_ip6_multicast_mrd_rcv()
3875 spin_unlock(&brmctx->br->multicast_lock); in br_ip6_multicast_mrd_rcv()
3883 struct net_bridge_port *p = pmctx ? pmctx->port : NULL; in br_multicast_ipv6_rcv()
3890 if (err == -ENOMSG || err == -ENODATA) { in br_multicast_ipv6_rcv()
3891 if (!ipv6_addr_is_ll_all_nodes(&ipv6_hdr(skb)->daddr)) in br_multicast_ipv6_rcv()
3892 BR_INPUT_SKB_CB(skb)->mrouters_only = 1; in br_multicast_ipv6_rcv()
3893 if (err == -ENODATA && in br_multicast_ipv6_rcv()
3894 ipv6_addr_is_all_snoopers(&ipv6_hdr(skb)->daddr)) in br_multicast_ipv6_rcv()
3899 br_multicast_err_count(brmctx->br, p, skb->protocol); in br_multicast_ipv6_rcv()
3904 BR_INPUT_SKB_CB(skb)->igmp = mld->mld_type; in br_multicast_ipv6_rcv()
3906 switch (mld->mld_type) { in br_multicast_ipv6_rcv()
3908 src = eth_hdr(skb)->h_source; in br_multicast_ipv6_rcv()
3909 BR_INPUT_SKB_CB(skb)->mrouters_only = 1; in br_multicast_ipv6_rcv()
3910 err = br_ip6_multicast_add_group(brmctx, pmctx, &mld->mld_mca, in br_multicast_ipv6_rcv()
3920 src = eth_hdr(skb)->h_source; in br_multicast_ipv6_rcv()
3921 br_ip6_multicast_leave_group(brmctx, pmctx, &mld->mld_mca, vid, in br_multicast_ipv6_rcv()
3926 br_multicast_count(brmctx->br, p, skb, BR_INPUT_SKB_CB(skb)->igmp, in br_multicast_ipv6_rcv()
3940 BR_INPUT_SKB_CB(skb)->igmp = 0; in br_multicast_rcv()
3941 BR_INPUT_SKB_CB(skb)->mrouters_only = 0; in br_multicast_rcv()
3943 if (!br_opt_get((*brmctx)->br, BROPT_MULTICAST_ENABLED)) in br_multicast_rcv()
3946 if (br_opt_get((*brmctx)->br, BROPT_MCAST_VLAN_SNOOPING_ENABLED) && vlan) { in br_multicast_rcv()
3954 *brmctx = &vlan->br_mcast_ctx; in br_multicast_rcv()
3957 masterv = vlan->brvlan; in br_multicast_rcv()
3958 *brmctx = &vlan->brvlan->br_mcast_ctx; in br_multicast_rcv()
3959 *pmctx = &vlan->port_mcast_ctx; in br_multicast_rcv()
3962 if (!(masterv->priv_flags & BR_VLFLAG_GLOBAL_MCAST_ENABLED)) in br_multicast_rcv()
3966 switch (skb->protocol) { in br_multicast_rcv()
3984 spin_lock(&brmctx->br->multicast_lock); in br_multicast_query_expired()
3988 if (query->startup_sent < brmctx->multicast_startup_query_count) in br_multicast_query_expired()
3989 query->startup_sent++; in br_multicast_query_expired()
3993 spin_unlock(&brmctx->br->multicast_lock); in br_multicast_query_expired()
4001 br_multicast_query_expired(brmctx, &brmctx->ip4_own_query, in br_ip4_multicast_query_expired()
4002 &brmctx->ip4_querier); in br_ip4_multicast_query_expired()
4011 br_multicast_query_expired(brmctx, &brmctx->ip6_own_query, in br_ip6_multicast_query_expired()
4012 &brmctx->ip6_querier); in br_ip6_multicast_query_expired()
4022 spin_lock_bh(&br->multicast_lock); in br_multicast_gc_work()
4023 hlist_move_list(&br->mcast_gc_list, &deleted_head); in br_multicast_gc_work()
4024 spin_unlock_bh(&br->multicast_lock); in br_multicast_gc_work()
4033 brmctx->br = br; in br_multicast_ctx_init()
4034 brmctx->vlan = vlan; in br_multicast_ctx_init()
4035 brmctx->multicast_router = MDB_RTR_TYPE_TEMP_QUERY; in br_multicast_ctx_init()
4036 brmctx->multicast_last_member_count = 2; in br_multicast_ctx_init()
4037 brmctx->multicast_startup_query_count = 2; in br_multicast_ctx_init()
4039 brmctx->multicast_last_member_interval = HZ; in br_multicast_ctx_init()
4040 brmctx->multicast_query_response_interval = 10 * HZ; in br_multicast_ctx_init()
4041 brmctx->multicast_startup_query_interval = 125 * HZ / 4; in br_multicast_ctx_init()
4042 brmctx->multicast_query_interval = 125 * HZ; in br_multicast_ctx_init()
4043 brmctx->multicast_querier_interval = 255 * HZ; in br_multicast_ctx_init()
4044 brmctx->multicast_membership_interval = 260 * HZ; in br_multicast_ctx_init()
4046 brmctx->ip4_querier.port_ifidx = 0; in br_multicast_ctx_init()
4047 seqcount_spinlock_init(&brmctx->ip4_querier.seq, &br->multicast_lock); in br_multicast_ctx_init()
4048 brmctx->multicast_igmp_version = 2; in br_multicast_ctx_init()
4050 brmctx->multicast_mld_version = 1; in br_multicast_ctx_init()
4051 brmctx->ip6_querier.port_ifidx = 0; in br_multicast_ctx_init()
4052 seqcount_spinlock_init(&brmctx->ip6_querier.seq, &br->multicast_lock); in br_multicast_ctx_init()
4055 timer_setup(&brmctx->ip4_mc_router_timer, in br_multicast_ctx_init()
4057 timer_setup(&brmctx->ip4_other_query.timer, in br_multicast_ctx_init()
4059 timer_setup(&brmctx->ip4_other_query.delay_timer, in br_multicast_ctx_init()
4061 timer_setup(&brmctx->ip4_own_query.timer, in br_multicast_ctx_init()
4064 timer_setup(&brmctx->ip6_mc_router_timer, in br_multicast_ctx_init()
4066 timer_setup(&brmctx->ip6_other_query.timer, in br_multicast_ctx_init()
4068 timer_setup(&brmctx->ip6_other_query.delay_timer, in br_multicast_ctx_init()
4070 timer_setup(&brmctx->ip6_own_query.timer, in br_multicast_ctx_init()
4082 br->hash_max = BR_MULTICAST_DEFAULT_HASH_MAX; in br_multicast_init()
4084 br_multicast_ctx_init(br, NULL, &br->multicast_ctx); in br_multicast_init()
4089 spin_lock_init(&br->multicast_lock); in br_multicast_init()
4090 INIT_HLIST_HEAD(&br->mdb_list); in br_multicast_init()
4091 INIT_HLIST_HEAD(&br->mcast_gc_list); in br_multicast_init()
4092 INIT_WORK(&br->mcast_gc_work, br_multicast_gc_work); in br_multicast_init()
4097 struct in_device *in_dev = in_dev_get(br->dev); in br_ip4_multicast_join_snoopers()
4112 ipv6_dev_mc_inc(br->dev, &addr); in br_ip6_multicast_join_snoopers()
4128 struct in_device *in_dev = in_dev_get(br->dev); in br_ip4_multicast_leave_snoopers()
4143 ipv6_dev_mc_dec(br->dev, &addr); in br_ip6_multicast_leave_snoopers()
4160 query->startup_sent = 0; in __br_multicast_open_query()
4165 mod_timer(&query->timer, jiffies); in __br_multicast_open_query()
4170 __br_multicast_open_query(brmctx->br, &brmctx->ip4_own_query); in __br_multicast_open()
4172 __br_multicast_open_query(brmctx->br, &brmctx->ip6_own_query); in __br_multicast_open()
4186 list_for_each_entry(vlan, &vg->vlan_list, vlist) { in br_multicast_open()
4189 brmctx = &vlan->br_mcast_ctx; in br_multicast_open()
4192 __br_multicast_open(&vlan->br_mcast_ctx); in br_multicast_open()
4196 __br_multicast_open(&br->multicast_ctx); in br_multicast_open()
4202 del_timer_sync(&brmctx->ip4_mc_router_timer); in __br_multicast_stop()
4203 del_timer_sync(&brmctx->ip4_other_query.timer); in __br_multicast_stop()
4204 del_timer_sync(&brmctx->ip4_other_query.delay_timer); in __br_multicast_stop()
4205 del_timer_sync(&brmctx->ip4_own_query.timer); in __br_multicast_stop()
4207 del_timer_sync(&brmctx->ip6_mc_router_timer); in __br_multicast_stop()
4208 del_timer_sync(&brmctx->ip6_other_query.timer); in __br_multicast_stop()
4209 del_timer_sync(&brmctx->ip6_other_query.delay_timer); in __br_multicast_stop()
4210 del_timer_sync(&brmctx->ip6_own_query.timer); in __br_multicast_stop()
4219 * can only change under RTNL -> multicast_lock, we need the latter to in br_multicast_toggle_one_vlan()
4222 if (on == !!(vlan->priv_flags & BR_VLFLAG_MCAST_ENABLED)) in br_multicast_toggle_one_vlan()
4226 br = vlan->br; in br_multicast_toggle_one_vlan()
4230 br_multicast_ctx_vlan_global_disabled(&vlan->br_mcast_ctx))) in br_multicast_toggle_one_vlan()
4233 spin_lock_bh(&br->multicast_lock); in br_multicast_toggle_one_vlan()
4234 vlan->priv_flags ^= BR_VLFLAG_MCAST_ENABLED; in br_multicast_toggle_one_vlan()
4235 spin_unlock_bh(&br->multicast_lock); in br_multicast_toggle_one_vlan()
4238 __br_multicast_open(&vlan->br_mcast_ctx); in br_multicast_toggle_one_vlan()
4240 __br_multicast_stop(&vlan->br_mcast_ctx); in br_multicast_toggle_one_vlan()
4244 brmctx = br_multicast_port_ctx_get_global(&vlan->port_mcast_ctx); in br_multicast_toggle_one_vlan()
4248 br = vlan->port->br; in br_multicast_toggle_one_vlan()
4249 spin_lock_bh(&br->multicast_lock); in br_multicast_toggle_one_vlan()
4250 vlan->priv_flags ^= BR_VLFLAG_MCAST_ENABLED; in br_multicast_toggle_one_vlan()
4252 __br_multicast_enable_port_ctx(&vlan->port_mcast_ctx); in br_multicast_toggle_one_vlan()
4254 __br_multicast_disable_port_ctx(&vlan->port_mcast_ctx); in br_multicast_toggle_one_vlan()
4255 spin_unlock_bh(&br->multicast_lock); in br_multicast_toggle_one_vlan()
4266 list_for_each_entry(p, &vlan->br->port_list, list) { in br_multicast_toggle_vlan()
4269 vport = br_vlan_find(nbp_vlan_group(p), vlan->vid); in br_multicast_toggle_vlan()
4291 return -EINVAL; in br_multicast_toggle_vlan_snooping()
4300 /* disable/enable non-vlan mcast contexts based on vlan snooping */ in br_multicast_toggle_vlan_snooping()
4302 __br_multicast_stop(&br->multicast_ctx); in br_multicast_toggle_vlan_snooping()
4304 __br_multicast_open(&br->multicast_ctx); in br_multicast_toggle_vlan_snooping()
4305 list_for_each_entry(p, &br->port_list, list) { in br_multicast_toggle_vlan_snooping()
4312 list_for_each_entry(vlan, &vg->vlan_list, vlist) in br_multicast_toggle_vlan_snooping()
4325 if (on == !!(vlan->priv_flags & BR_VLFLAG_GLOBAL_MCAST_ENABLED)) in br_multicast_toggle_global_vlan()
4328 vlan->priv_flags ^= BR_VLFLAG_GLOBAL_MCAST_ENABLED; in br_multicast_toggle_global_vlan()
4344 list_for_each_entry(vlan, &vg->vlan_list, vlist) { in br_multicast_stop()
4347 brmctx = &vlan->br_mcast_ctx; in br_multicast_stop()
4350 __br_multicast_stop(&vlan->br_mcast_ctx); in br_multicast_stop()
4354 __br_multicast_stop(&br->multicast_ctx); in br_multicast_stop()
4364 spin_lock_bh(&br->multicast_lock); in br_multicast_dev_del()
4365 hlist_for_each_entry_safe(mp, tmp, &br->mdb_list, mdb_node) in br_multicast_dev_del()
4367 hlist_move_list(&br->mcast_gc_list, &deleted_head); in br_multicast_dev_del()
4368 spin_unlock_bh(&br->multicast_lock); in br_multicast_dev_del()
4370 br_multicast_ctx_deinit(&br->multicast_ctx); in br_multicast_dev_del()
4372 cancel_work_sync(&br->mcast_gc_work); in br_multicast_dev_del()
4379 int err = -EINVAL; in br_multicast_set_router()
4381 spin_lock_bh(&brmctx->br->multicast_lock); in br_multicast_set_router()
4386 br_mc_router_state_change(brmctx->br, val == MDB_RTR_TYPE_PERM); in br_multicast_set_router()
4387 del_timer(&brmctx->ip4_mc_router_timer); in br_multicast_set_router()
4389 del_timer(&brmctx->ip6_mc_router_timer); in br_multicast_set_router()
4391 brmctx->multicast_router = val; in br_multicast_set_router()
4395 if (brmctx->multicast_router != MDB_RTR_TYPE_TEMP_QUERY) in br_multicast_set_router()
4396 br_mc_router_state_change(brmctx->br, false); in br_multicast_set_router()
4397 brmctx->multicast_router = val; in br_multicast_set_router()
4402 spin_unlock_bh(&brmctx->br->multicast_lock); in br_multicast_set_router()
4416 if (!hlist_unhashed(&pmctx->ip4_rlist)) in br_multicast_rport_del_notify()
4419 if (!hlist_unhashed(&pmctx->ip6_rlist)) in br_multicast_rport_del_notify()
4423 br_rtr_notify(pmctx->port->br->dev, pmctx, RTM_DELMDB); in br_multicast_rport_del_notify()
4424 br_port_mc_router_state_change(pmctx->port, false); in br_multicast_rport_del_notify()
4427 if (pmctx->multicast_router == MDB_RTR_TYPE_TEMP) in br_multicast_rport_del_notify()
4428 pmctx->multicast_router = MDB_RTR_TYPE_TEMP_QUERY; in br_multicast_rport_del_notify()
4436 int err = -EINVAL; in br_multicast_set_port_router()
4440 spin_lock_bh(&brmctx->br->multicast_lock); in br_multicast_set_port_router()
4441 if (pmctx->multicast_router == val) { in br_multicast_set_port_router()
4443 if (pmctx->multicast_router == MDB_RTR_TYPE_TEMP) { in br_multicast_set_port_router()
4444 mod_timer(&pmctx->ip4_mc_router_timer, in br_multicast_set_port_router()
4445 now + brmctx->multicast_querier_interval); in br_multicast_set_port_router()
4447 mod_timer(&pmctx->ip6_mc_router_timer, in br_multicast_set_port_router()
4448 now + brmctx->multicast_querier_interval); in br_multicast_set_port_router()
4456 pmctx->multicast_router = MDB_RTR_TYPE_DISABLED; in br_multicast_set_port_router()
4458 del_timer(&pmctx->ip4_mc_router_timer); in br_multicast_set_port_router()
4461 del_timer(&pmctx->ip6_mc_router_timer); in br_multicast_set_port_router()
4466 pmctx->multicast_router = MDB_RTR_TYPE_TEMP_QUERY; in br_multicast_set_port_router()
4472 pmctx->multicast_router = MDB_RTR_TYPE_PERM; in br_multicast_set_port_router()
4473 del_timer(&pmctx->ip4_mc_router_timer); in br_multicast_set_port_router()
4476 del_timer(&pmctx->ip6_mc_router_timer); in br_multicast_set_port_router()
4481 pmctx->multicast_router = MDB_RTR_TYPE_TEMP; in br_multicast_set_port_router()
4490 spin_unlock_bh(&brmctx->br->multicast_lock); in br_multicast_set_port_router()
4500 err = br_multicast_set_router(&v->br_mcast_ctx, mcast_router); in br_multicast_set_vlan_router()
4502 err = br_multicast_set_port_router(&v->port_mcast_ctx, in br_multicast_set_vlan_router()
4516 __br_multicast_open_query(brmctx->br, query); in br_multicast_start_querier()
4519 list_for_each_entry_rcu(port, &brmctx->br->port_list, list) { in br_multicast_start_querier()
4525 if (br_multicast_port_ctx_state_stopped(&port->multicast_ctx)) in br_multicast_start_querier()
4532 brmctx->vlan->vid); in br_multicast_start_querier()
4534 br_multicast_port_ctx_state_stopped(&vlan->port_mcast_ctx)) in br_multicast_start_querier()
4537 ip4_own_query = &vlan->port_mcast_ctx.ip4_own_query; in br_multicast_start_querier()
4539 ip6_own_query = &vlan->port_mcast_ctx.ip6_own_query; in br_multicast_start_querier()
4542 ip4_own_query = &port->multicast_ctx.ip4_own_query; in br_multicast_start_querier()
4544 ip6_own_query = &port->multicast_ctx.ip6_own_query; in br_multicast_start_querier()
4548 if (query == &brmctx->ip4_own_query) in br_multicast_start_querier()
4565 spin_lock_bh(&br->multicast_lock); in br_multicast_toggle()
4569 err = br_mc_disabled_update(br->dev, val, extack); in br_multicast_toggle()
4570 if (err == -EOPNOTSUPP) in br_multicast_toggle()
4581 if (!netif_running(br->dev)) in br_multicast_toggle()
4585 list_for_each_entry(port, &br->port_list, list) in br_multicast_toggle()
4586 __br_multicast_enable_port_ctx(&port->multicast_ctx); in br_multicast_toggle()
4591 spin_unlock_bh(&br->multicast_lock); in br_multicast_toggle()
4628 spin_lock_bh(&br->multicast_lock); in br_multicast_router()
4629 is_router = br_multicast_is_router(&br->multicast_ctx, NULL); in br_multicast_router()
4630 spin_unlock_bh(&br->multicast_lock); in br_multicast_router()
4641 spin_lock_bh(&brmctx->br->multicast_lock); in br_multicast_set_querier()
4642 if (brmctx->multicast_querier == val) in br_multicast_set_querier()
4645 WRITE_ONCE(brmctx->multicast_querier, val); in br_multicast_set_querier()
4649 max_delay = brmctx->multicast_query_response_interval; in br_multicast_set_querier()
4651 if (!timer_pending(&brmctx->ip4_other_query.timer)) in br_multicast_set_querier()
4652 mod_timer(&brmctx->ip4_other_query.delay_timer, in br_multicast_set_querier()
4655 br_multicast_start_querier(brmctx, &brmctx->ip4_own_query); in br_multicast_set_querier()
4658 if (!timer_pending(&brmctx->ip6_other_query.timer)) in br_multicast_set_querier()
4659 mod_timer(&brmctx->ip6_other_query.delay_timer, in br_multicast_set_querier()
4662 br_multicast_start_querier(brmctx, &brmctx->ip6_own_query); in br_multicast_set_querier()
4666 spin_unlock_bh(&brmctx->br->multicast_lock); in br_multicast_set_querier()
4680 return -EINVAL; in br_multicast_set_igmp_version()
4683 spin_lock_bh(&brmctx->br->multicast_lock); in br_multicast_set_igmp_version()
4684 brmctx->multicast_igmp_version = val; in br_multicast_set_igmp_version()
4685 spin_unlock_bh(&brmctx->br->multicast_lock); in br_multicast_set_igmp_version()
4700 return -EINVAL; in br_multicast_set_mld_version()
4703 spin_lock_bh(&brmctx->br->multicast_lock); in br_multicast_set_mld_version()
4704 brmctx->multicast_mld_version = val; in br_multicast_set_mld_version()
4705 spin_unlock_bh(&brmctx->br->multicast_lock); in br_multicast_set_mld_version()
4717 br_info(brmctx->br, in br_multicast_set_query_intvl()
4724 brmctx->multicast_query_interval = intvl_jiffies; in br_multicast_set_query_intvl()
4733 br_info(brmctx->br, in br_multicast_set_startup_query_intvl()
4740 brmctx->multicast_startup_query_interval = intvl_jiffies; in br_multicast_set_startup_query_intvl()
4744 * br_multicast_list_adjacent - Returns snooped multicast addresses
4749 * snooping feature on all bridge ports of dev's bridge device, excluding
4755 * - br_ip_list needs to be initialized by caller
4756 * - br_ip_list might contain duplicates in the end
4758 * - br_ip_list needs to be freed by caller
4765 struct net_bridge_port_group *group; in br_multicast_list_adjacent() local
4767 int count = 0; in br_multicast_list_adjacent() local
4774 if (!port || !port->br) in br_multicast_list_adjacent()
4777 br = port->br; in br_multicast_list_adjacent()
4779 list_for_each_entry_rcu(port, &br->port_list, list) { in br_multicast_list_adjacent()
4780 if (!port->dev || port->dev == dev) in br_multicast_list_adjacent()
4783 hlist_for_each_entry_rcu(group, &port->mglist, mglist) { in br_multicast_list_adjacent()
4788 entry->addr = group->key.addr; in br_multicast_list_adjacent()
4789 list_add(&entry->list, br_ip_list); in br_multicast_list_adjacent()
4790 count++; in br_multicast_list_adjacent()
4796 return count; in br_multicast_list_adjacent()
4801 * br_multicast_has_querier_anywhere - Checks for a querier on a bridge
4803 * @proto: The protocol family to check for: IGMP -> ETH_P_IP, MLD -> ETH_P_IPV6
4821 if (!port || !port->br) in br_multicast_has_querier_anywhere()
4824 br = port->br; in br_multicast_has_querier_anywhere()
4829 ret = br_multicast_querier_exists(&br->multicast_ctx, &eth, NULL); in br_multicast_has_querier_anywhere()
4838 * br_multicast_has_querier_adjacent - Checks for a querier behind a bridge port
4840 * @proto: The protocol family to check for: IGMP -> ETH_P_IP, MLD -> ETH_P_IPV6
4843 * true if a selected querier is behind one of the other ports of this
4859 if (!port || !port->br) in br_multicast_has_querier_adjacent()
4862 br = port->br; in br_multicast_has_querier_adjacent()
4863 brmctx = &br->multicast_ctx; in br_multicast_has_querier_adjacent()
4867 port_ifidx = brmctx->ip4_querier.port_ifidx; in br_multicast_has_querier_adjacent()
4868 if (!timer_pending(&brmctx->ip4_other_query.timer) || in br_multicast_has_querier_adjacent()
4869 port_ifidx == port->dev->ifindex) in br_multicast_has_querier_adjacent()
4874 port_ifidx = brmctx->ip6_querier.port_ifidx; in br_multicast_has_querier_adjacent()
4875 if (!timer_pending(&brmctx->ip6_other_query.timer) || in br_multicast_has_querier_adjacent()
4876 port_ifidx == port->dev->ifindex) in br_multicast_has_querier_adjacent()
4892 * br_multicast_has_router_adjacent - Checks for a router behind a bridge port
4894 * @proto: The protocol family to check for: IGMP -> ETH_P_IP, MLD -> ETH_P_IPV6
4897 * true if a multicast router is behind one of the other ports of this
4912 brmctx = &port->br->multicast_ctx; in br_multicast_has_router_adjacent()
4915 hlist_for_each_entry_rcu(pmctx, &brmctx->ip4_mc_router_list, in br_multicast_has_router_adjacent()
4917 if (pmctx->port == port) in br_multicast_has_router_adjacent()
4926 hlist_for_each_entry_rcu(pmctx, &brmctx->ip6_mc_router_list, in br_multicast_has_router_adjacent()
4928 if (pmctx->port == port) in br_multicast_has_router_adjacent()
4953 __be16 proto = skb->protocol; in br_mcast_stats_add()
4956 u64_stats_update_begin(&pstats->syncp); in br_mcast_stats_add()
4959 t_len = ntohs(ip_hdr(skb)->tot_len) - ip_hdrlen(skb); in br_mcast_stats_add()
4962 pstats->mstats.igmp_v1reports[dir]++; in br_mcast_stats_add()
4965 pstats->mstats.igmp_v2reports[dir]++; in br_mcast_stats_add()
4968 pstats->mstats.igmp_v3reports[dir]++; in br_mcast_stats_add()
4972 pstats->mstats.igmp_v3queries[dir]++; in br_mcast_stats_add()
4981 if (!ih->code) in br_mcast_stats_add()
4982 pstats->mstats.igmp_v1queries[dir]++; in br_mcast_stats_add()
4984 pstats->mstats.igmp_v2queries[dir]++; in br_mcast_stats_add()
4988 pstats->mstats.igmp_leaves[dir]++; in br_mcast_stats_add()
4994 t_len = ntohs(ipv6_hdr(skb)->payload_len) + in br_mcast_stats_add()
4996 t_len -= skb_network_header_len(skb); in br_mcast_stats_add()
4999 pstats->mstats.mld_v1reports[dir]++; in br_mcast_stats_add()
5002 pstats->mstats.mld_v2reports[dir]++; in br_mcast_stats_add()
5006 pstats->mstats.mld_v2queries[dir]++; in br_mcast_stats_add()
5008 pstats->mstats.mld_v1queries[dir]++; in br_mcast_stats_add()
5011 pstats->mstats.mld_leaves[dir]++; in br_mcast_stats_add()
5017 u64_stats_update_end(&pstats->syncp); in br_mcast_stats_add()
5031 stats = p->mcast_stats; in br_multicast_count()
5033 stats = br->mcast_stats; in br_multicast_count()
5042 br->mcast_stats = netdev_alloc_pcpu_stats(struct bridge_mcast_stats); in br_multicast_init_stats()
5043 if (!br->mcast_stats) in br_multicast_init_stats()
5044 return -ENOMEM; in br_multicast_init_stats()
5051 free_percpu(br->mcast_stats); in br_multicast_uninit_stats()
5071 stats = p->mcast_stats; in br_multicast_get_stats()
5073 stats = br->mcast_stats; in br_multicast_get_stats()
5084 start = u64_stats_fetch_begin(&cpu_stats->syncp); in br_multicast_get_stats()
5085 memcpy(&temp, &cpu_stats->mstats, sizeof(temp)); in br_multicast_get_stats()
5086 } while (u64_stats_fetch_retry(&cpu_stats->syncp, start)); in br_multicast_get_stats()
5111 err = rhashtable_init(&br->sg_port_tbl, &br_sg_port_rht_params); in br_mdb_hash_init()
5115 err = rhashtable_init(&br->mdb_hash_tbl, &br_mdb_rht_params); in br_mdb_hash_init()
5117 rhashtable_destroy(&br->sg_port_tbl); in br_mdb_hash_init()
5126 rhashtable_destroy(&br->sg_port_tbl); in br_mdb_hash_fini()
5127 rhashtable_destroy(&br->mdb_hash_tbl); in br_mdb_hash_fini()