Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4925263pxj; Wed, 12 May 2021 16:44:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbEzhjp1Kc3mE5yvpGWJR9/UhxNVM15Wwk8FFHQh/iDb2rG3yEPOxMuPkKDMig82Q+f2IB X-Received: by 2002:a05:6e02:128a:: with SMTP id y10mr32250382ilq.166.1620863095178; Wed, 12 May 2021 16:44:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620863095; cv=none; d=google.com; s=arc-20160816; b=reytBA0O/bZ1p0y4Z7Qn7ktbaoeI+bK9kQFGb63oD/xDHM6vu2Es0hKsBbD5zUOuzv vA2Oc8gobT3Qjt6EC3BZ2WnB6/G+OEcQByaaEG7GY2Iu5SW1fnUWt/OQA69VctEFbv7B 1DJFpTz8UarKHAqOWMrk/YaX0WTHSp1+Fd0AxySB9iKYNS5QpUj0pwsxKjTEQGD5lg/y gDr1vWRKNGFpnppV/EpxzjWDkJ8Nt1JsnxL2EUrjU1xKJOSyBxbGKt6thRVg4eWRZSs7 qRZKvlrnIh8pzuWCg41VM6/KJ+wHyNpOJWSDzyjHfKhmFMZ4vGZGW6zDhEqg/TZuPQwQ cLTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=vhxBCYpVdxHjmYHQK9ICoPFNzrEazVhCV90G3dy0j1M=; b=0qcRfXrL3UL7gxedfwTtP13K0bYTawAQLORKfoYeK77DeUX0QlEZg+xPqY4OT4tEcX AOYhe8jx5Ku47OQdmw5umrASDu/QtbJ8Htmv+5cdsPMGaoHOwIujOcd24OvLirhb/iDx 7NIgX1g2ME9phQUWN/pvyOSNZEJT0ARjnihLuWO5vw+cDsmXEH8VOPfygpQWQKUG47wU ZQSnY63Pd+hgg2a+Wg9ot/VUO1YUfKgQ3ilpaou49nzA+XG69Dc9TfbOp3W3iCFs0q9n IswlyBVF2d5xg4rG6Zp3UnJZa7k+7m0IYb9U/h/o2S5LJ2BQXPwKKkKaodCmIFGh8ild 21Qg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v14si1275412ilu.122.2021.05.12.16.44.42; Wed, 12 May 2021 16:44:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239200AbhELXlz (ORCPT + 99 others); Wed, 12 May 2021 19:41:55 -0400 Received: from mail.aperture-lab.de ([116.203.183.178]:50830 "EHLO mail.aperture-lab.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234169AbhELXVM (ORCPT ); Wed, 12 May 2021 19:21:12 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id A1D274100C; Thu, 13 May 2021 01:19:53 +0200 (CEST) From: =?UTF-8?q?Linus=20L=C3=BCssing?= To: netdev@vger.kernel.org Cc: Roopa Prabhu , Nikolay Aleksandrov , Jakub Kicinski , "David S . Miller" , bridge@lists.linux-foundation.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Linus=20L=C3=BCssing?= Subject: [net-next v3 07/11] net: bridge: mcast: prepare add-router function for mcast router split Date: Thu, 13 May 2021 01:19:37 +0200 Message-Id: <20210512231941.19211-8-linus.luessing@c0d3.blue> In-Reply-To: <20210512231941.19211-1-linus.luessing@c0d3.blue> References: <20210512231941.19211-1-linus.luessing@c0d3.blue> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation for the upcoming split of multicast router state into their IPv4 and IPv6 variants move the protocol specific router list access to an ip4 wrapper function. Signed-off-by: Linus Lüssing --- net/bridge/br_multicast.c | 59 +++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c index 7815991..1d55709 100644 --- a/net/bridge/br_multicast.c +++ b/net/bridge/br_multicast.c @@ -51,8 +51,8 @@ static const struct rhashtable_params br_sg_port_rht_params = { static void br_multicast_start_querier(struct net_bridge *br, struct bridge_mcast_own_query *query); -static void br_multicast_add_router(struct net_bridge *br, - struct net_bridge_port *port); +static void br_ip4_multicast_add_router(struct net_bridge *br, + struct net_bridge_port *port); static void br_ip4_multicast_leave_group(struct net_bridge *br, struct net_bridge_port *port, __be32 group, @@ -1689,7 +1689,7 @@ static void __br_multicast_enable_port(struct net_bridge_port *port) #endif if (port->multicast_router == MDB_RTR_TYPE_PERM && hlist_unhashed(&port->ip4_rlist)) - br_multicast_add_router(br, port); + br_ip4_multicast_add_router(br, port); } void br_multicast_enable_port(struct net_bridge_port *port) @@ -2659,28 +2659,51 @@ static void br_port_mc_router_state_change(struct net_bridge_port *p, * and locked by br->multicast_lock and RCU */ static void br_multicast_add_router(struct net_bridge *br, - struct net_bridge_port *port) + struct net_bridge_port *port, + struct hlist_node *slot, + struct hlist_node *rlist, + struct hlist_head *mc_router_list) { - struct net_bridge_port *p; - struct hlist_node *slot = NULL; - - if (!hlist_unhashed(&port->ip4_rlist)) + if (!hlist_unhashed(rlist)) return; - hlist_for_each_entry(p, &br->ip4_mc_router_list, ip4_rlist) { - if ((unsigned long) port >= (unsigned long) p) - break; - slot = &p->ip4_rlist; - } - if (slot) - hlist_add_behind_rcu(&port->ip4_rlist, slot); + hlist_add_behind_rcu(rlist, slot); else - hlist_add_head_rcu(&port->ip4_rlist, &br->ip4_mc_router_list); + hlist_add_head_rcu(rlist, mc_router_list); + br_rtr_notify(br->dev, port, RTM_NEWMDB); br_port_mc_router_state_change(port, true); } +static struct hlist_node * +br_ip4_multicast_get_rport_slot(struct net_bridge *br, struct net_bridge_port *port) +{ + struct hlist_node *slot = NULL; + struct net_bridge_port *p; + + hlist_for_each_entry(p, &br->ip4_mc_router_list, ip4_rlist) { + if ((unsigned long)port >= (unsigned long)p) + break; + slot = &p->ip4_rlist; + } + + return slot; +} + +/* Add port to router_list + * list is maintained ordered by pointer value + * and locked by br->multicast_lock and RCU + */ +static void br_ip4_multicast_add_router(struct net_bridge *br, + struct net_bridge_port *port) +{ + struct hlist_node *slot = br_ip4_multicast_get_rport_slot(br, port); + + br_multicast_add_router(br, port, slot, &port->ip4_rlist, + &br->ip4_mc_router_list); +} + static void br_multicast_mark_router(struct net_bridge *br, struct net_bridge_port *port) { @@ -2700,7 +2723,7 @@ static void br_multicast_mark_router(struct net_bridge *br, port->multicast_router == MDB_RTR_TYPE_PERM) return; - br_multicast_add_router(br, port); + br_ip4_multicast_add_router(br, port); mod_timer(&port->ip4_mc_router_timer, now + br->multicast_querier_interval); @@ -3526,7 +3549,7 @@ int br_multicast_set_port_router(struct net_bridge_port *p, unsigned long val) case MDB_RTR_TYPE_PERM: p->multicast_router = MDB_RTR_TYPE_PERM; del_timer(&p->ip4_mc_router_timer); - br_multicast_add_router(br, p); + br_ip4_multicast_add_router(br, p); break; case MDB_RTR_TYPE_TEMP: p->multicast_router = MDB_RTR_TYPE_TEMP; -- 2.31.0