Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp345886pxj; Thu, 13 May 2021 06:23:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxPCsgVtSWVsnN2CW8AYyg+ffzgM8Yp5Y3P6tydME+wAvJAohACMlWFMQsDUjZ2WyDBUPJ X-Received: by 2002:a17:906:a2d1:: with SMTP id by17mr45243124ejb.426.1620912216592; Thu, 13 May 2021 06:23:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620912216; cv=none; d=google.com; s=arc-20160816; b=I1OnoILpHg0KkhaYtSp5enpFJ2I2+8Zn9xJLzx8aRK/sRggh0SkP9Q6V6WXUNAAvbc mjgx6hzbDsqz0aoVEQ/tZSmp+k+RabsJQbaqcvt2SqTSDtS2p9uMkKI+iNftDEbfPC/J XWFO9fVcVLj/QTDDXp34LK7v75TXhCI//zJJyYa1s+PMCF6oJnepcPrGlYeGw9cxxZqo rmINUD0C9bH12TupFZnd8R2D196lKe4qFGIc5/wUROmJH09MwLty4V/kW/z0B0JOAwmS QATQCYHxBNaGl9SIEY/kyhSUJFTH2BP1cp5hFFmiB1TzXHN+qIuCky2kbaHo4yeDO/y0 SrQA== 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=LLto6+DYu97pqm7cHcgGPrXPOOqsxUJwz9X4meXVg2o=; b=NLpp5xXOQW6I7COl+pav14zaUVz19m6+04ImZ8madCfUgXW0IDaUWBZrTu0NRp3CV2 osy0OY7iUfUBRDsnKTbPPrMUD/oaUXjsD7vyRo9h8bISB6oC5zgWV9z0R37+tffOMEZA 8wjipASKrEVnvJaaI8triJeDmEhOaVuSSHmO3t/8CSVF7ISY1sh1VjUPIhCVU5DM4FY+ PLZ9/e95x9k1GHqR5PleWogKm3QcMq3UU2s/cVV1ZenShvf0zGDZRRji4FqiEx9CF+cb NHnLcMIJdtC8LBADhlhCzBlSrzXiuX8vZ9MhF+3zn0RbkSrXkjWriHUmGLGYLaXk94Mx 1A0g== 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 j8si3972981ejk.38.2021.05.13.06.23.10; Thu, 13 May 2021 06:23:36 -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 S234118AbhEMNW7 (ORCPT + 99 others); Thu, 13 May 2021 09:22:59 -0400 Received: from mail.aperture-lab.de ([116.203.183.178]:52814 "EHLO mail.aperture-lab.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233981AbhEMNWZ (ORCPT ); Thu, 13 May 2021 09:22:25 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 197FA4100A; Thu, 13 May 2021 15:21:03 +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 v4 05/11] net: bridge: mcast: prepare is-router function for mcast router split Date: Thu, 13 May 2021 15:20:47 +0200 Message-Id: <20210513132053.23445-6-linus.luessing@c0d3.blue> In-Reply-To: <20210513132053.23445-1-linus.luessing@c0d3.blue> References: <20210513132053.23445-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 d970ef7..f9a381f 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -874,11 +874,40 @@ br_multicast_rport_from_node_skb(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