Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2029948pxj; Sun, 9 May 2021 12:47:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6PuU7JG9LvBd8aewV1kAnnvvgtWA6rsLidBHEjrX9L25CAUioroKqrge/laa+OxQ2AAm1 X-Received: by 2002:a17:906:b104:: with SMTP id u4mr21982849ejy.211.1620589676362; Sun, 09 May 2021 12:47:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620589676; cv=none; d=google.com; s=arc-20160816; b=AqgLr0tiF/3rQsbZo4PF0a2k/BjK/+Eci504ecO/5+EoJbbBI0yNU/DWbkkqg23ToP gWV8APuxIDOvTRtT6VJwcrcNPp0pcpthC+K2BCMV1YE2IO8k4GWEAWSCK1DxOt40yO0X L3LX4KI37Sw0mVA83oOozD2EqA8p5BbaWK63ciQnFnYcFXK42S1X3Ilu+mJBn2jZme5L 8acwX/8JMsEV+g2rW/SQc0maSMsPqHW0H8FkrBuSd3gFyNFLoBuS5xZWfrzyiJPr893d L1NR6RWMw2RcCP8bARdyUTAe6N/h29eOASGNG+ygE+SHQxO8ABEVRm0hnnm1Y+S60+Lc iQJw== 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=4sDySa7v1SHuRzhQ7BUdj2pNzvHoIsJ/yJbCMJzp7fI=; b=AwzL/4MfnxpQXIg1k/TiRW6XPOpUzJq61L4jFVptguuqcL7U6mUtgmnw13OeeuvO9M bGBCuJkcBaoULC+liKoZpC5NXWTGXhr2Z9eIC2zXGNx5we32N/Af8zQH6xSZf7Vdnx/e yOh6JlL87F9miubfoidvefhwyqkBpC97RC5Wb4f6aDSHStOkLaUEH3tKHD5VwTv60alH 6SbogKQoXM2l2MKxDwLRnGXRrwiiUTqKCWZ3QsYnlxtoq7j39XrBT4x4O2JNjmsdIeXb 3PoAXNNLCy1ZeHLSOlx7o7gndEQcIW7vsyXnH7rPmy4SgwnuduAve1iFOVKYpEGYp77M G2rQ== 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 v18si11367843eju.659.2021.05.09.12.47.32; Sun, 09 May 2021 12:47:56 -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 S230012AbhEITqt (ORCPT + 99 others); Sun, 9 May 2021 15:46:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229961AbhEITqb (ORCPT ); Sun, 9 May 2021 15:46:31 -0400 Received: from mail.aperture-lab.de (mail.aperture-lab.de [IPv6:2a01:4f8:c2c:665b::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD10DC061574; Sun, 9 May 2021 12:45:27 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 31B093EDE0; Sun, 9 May 2021 21:45:26 +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, b.a.t.m.a.n@lists.open-mesh.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Linus=20L=C3=BCssing?= Subject: [net-next v2 05/11] net: bridge: mcast: prepare is-router function for mcast router split Date: Sun, 9 May 2021 21:45:03 +0200 Message-Id: <20210509194509.10849-6-linus.luessing@c0d3.blue> In-Reply-To: <20210509194509.10849-1-linus.luessing@c0d3.blue> References: <20210509194509.10849-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 | 36 ++++++++++++++++++++++++++++++++---- 3 files changed, 36 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 26e91d2..ac5ca5b 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -864,11 +864,39 @@ static inline bool br_group_is_l2(const struct br_ip *group) #define mlock_dereference(X, br) \ rcu_dereference_protected(X, lockdep_is_held(&br->multicast_lock)) -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) +{ + if (br->multicast_router == MDB_RTR_TYPE_PERM) + return true; + + if (br->multicast_router == 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); + } + } + + return false; } static inline bool -- 2.31.0