Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4929126pxj; Wed, 12 May 2021 16:52:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxObe50iB1Yrt8fx9b5g0Rh5WbLYiFiqsjs7peybAchNCwYe+4WH6UXf3slfpyGaq/Uwdwe X-Received: by 2002:a4a:270d:: with SMTP id l13mr29956289oof.11.1620863554058; Wed, 12 May 2021 16:52:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620863554; cv=none; d=google.com; s=arc-20160816; b=KQvzcz2Cpu0I4k83aEjrlstm+/WBglLGPmILIBUy6DrPKyF4+Dj61CKnrHpObiB1bu +B/3CwzpzpGyZe1I+XG34FxfvrUbJmB7BW2V74bB2VKa37s0Wzt6DRgrhGJU23YRpyDj aL9+gbmcJDRV9CrCJgRdvVeidmUfimqMGvhUL2zZQWl4xIrT8lJ+nGlQuNq3HxML1Nm3 AMPIM/i0cQ+Gz2DBGr65lK5h8HWflhJ3r9CLcJjn0BDyrDysTVlIexLtGdHArKHdYd/F A4q7LMteISggialWwM+lkhKFARZhEuNb1ISP89OB+5onopZtQ+pifuSZUHj0SY1FPvnq ESAQ== 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=h/oq1cKMrgkDp+U9R6xRtX9Zbzv1Ur9hGczedgqBp1Q=; b=g4T+nGWjTsgGGesZi1CM9+nheFCuxWXoicPY0GT8Wfv5DqXOqp4wKXgMysAa5dTOyr pMPokcyW77wakle4ZXubGved0b5fD5eBkEHj2hyHtkuvDw+1mF6ODoW7hOFld9u+dlST EzyyIwLy6p+u+u1+1yWobjzVJDVpWTriy9GxwzxIV4ZKMgFw1ft0ZZvnQgFYCYTxaLjh xgG6QgEjsqwglyDFDn3v+sUWJK5TtELdfm0evrCYX32rrMI4V86/2Yi0xQkf8eOm2yZZ Ih3mjcCiYjR6OzzVS+4wFQOrArqLta5Brc1sVGlhOAQG7ToNILtnCkSnmTgsWxm/JAVj uAYA== 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 h5si1194238oti.40.2021.05.12.16.52.08; Wed, 12 May 2021 16:52:34 -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 S237762AbhELXlB (ORCPT + 99 others); Wed, 12 May 2021 19:41:01 -0400 Received: from mail.aperture-lab.de ([116.203.183.178]:50760 "EHLO mail.aperture-lab.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234120AbhELXVK (ORCPT ); Wed, 12 May 2021 19:21:10 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id BB3EF4100A; Thu, 13 May 2021 01:19:51 +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 05/11] net: bridge: mcast: prepare is-router function for mcast router split Date: Thu, 13 May 2021 01:19:35 +0200 Message-Id: <20210512231941.19211-6-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 make br_multicast_is_router() protocol family aware. Note that for now br_ip6_multicast_is_router() uses the currently still common ip4_mc_router_timer for now. It will be renamed to ip6_mc_router_timer later when the split is performed. While at it also renames the "1" and "2" constants in br_multicast_is_router() to the MDB_RTR_TYPE_TEMP_QUERY and MDB_RTR_TYPE_PERM enums. Signed-off-by: Linus Lüssing --- net/bridge/br_input.c | 2 +- net/bridge/br_multicast.c | 5 +++-- net/bridge/br_private.h | 37 +++++++++++++++++++++++++++++++++---- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/net/bridge/br_input.c b/net/bridge/br_input.c index 8875e95..1f50630 100644 --- a/net/bridge/br_input.c +++ b/net/bridge/br_input.c @@ -132,7 +132,7 @@ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb if ((mdst || BR_INPUT_SKB_CB_MROUTERS_ONLY(skb)) && br_multicast_querier_exists(br, eth_hdr(skb), mdst)) { if ((mdst && mdst->host_joined) || - br_multicast_is_router(br)) { + br_multicast_is_router(br, skb)) { local_rcv = true; br->dev->stats.multicast++; } diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c index 7edbbc9..048b5b9 100644 --- a/net/bridge/br_multicast.c +++ b/net/bridge/br_multicast.c @@ -1391,7 +1391,8 @@ static void br_multicast_local_router_expired(struct timer_list *t) spin_lock(&br->multicast_lock); if (br->multicast_router == MDB_RTR_TYPE_DISABLED || br->multicast_router == MDB_RTR_TYPE_PERM || - timer_pending(&br->ip4_mc_router_timer)) + br_ip4_multicast_is_router(br) || + br_ip6_multicast_is_router(br)) goto out; br_mc_router_state_change(br, false); @@ -3622,7 +3623,7 @@ bool br_multicast_router(const struct net_device *dev) bool is_router; spin_lock_bh(&br->multicast_lock); - is_router = br_multicast_is_router(br); + is_router = br_multicast_is_router(br, NULL); spin_unlock_bh(&br->multicast_lock); return is_router; } diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 5b9a6b2..41ed3fe 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -874,11 +874,40 @@ br_multicast_rport_from_node(struct hlist_node *rp, struct sk_buff *skb) { return hlist_entry_safe(rp, struct net_bridge_port, ip4_rlist); } -static inline bool br_multicast_is_router(struct net_bridge *br) +static inline bool br_ip4_multicast_is_router(struct net_bridge *br) { - return br->multicast_router == 2 || - (br->multicast_router == 1 && - timer_pending(&br->ip4_mc_router_timer)); + return timer_pending(&br->ip4_mc_router_timer); +} + +static inline bool br_ip6_multicast_is_router(struct net_bridge *br) +{ +#if IS_ENABLED(CONFIG_IPV6) + return timer_pending(&br->ip4_mc_router_timer); +#else + return false; +#endif +} + +static inline bool +br_multicast_is_router(struct net_bridge *br, struct sk_buff *skb) +{ + switch (br->multicast_router) { + case MDB_RTR_TYPE_PERM: + return true; + case MDB_RTR_TYPE_TEMP_QUERY: + if (skb) { + if (skb->protocol == htons(ETH_P_IP)) + return br_ip4_multicast_is_router(br); + else if (skb->protocol == htons(ETH_P_IPV6)) + return br_ip6_multicast_is_router(br); + } else { + return br_ip4_multicast_is_router(br) || + br_ip6_multicast_is_router(br); + } + fallthrough; + default: + return false; + } } static inline bool -- 2.31.0