Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4925260pxj; Wed, 12 May 2021 16:44:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwiuLlILH5oTPczDTFlF4Rs3pgGuBDCqhzZ880crxliucYwo1iyTCD7oZoCEw2k8T3dt79 X-Received: by 2002:a05:6602:14d3:: with SMTP id b19mr20983681iow.154.1620863095051; 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=eBOiIVUD07/nIrcFLidVA9jlJCA6ljDZPE+WNQlEEkRxA26bdROMnuGpgfi4Qn/Q5b nwKUvV3FEmc5Y3tvCGchCrIYqdTdw9vmX42imV4L6USux3yOqKcNIpR+Joa7VGYj7Jr/ R6MZP8kDUqAcaH0Ot7RFA1TUfiNlHl2fi9+hOJpi+t6azM33YlIaFFITrp3BSQ421d0e cNb7AiBsB2NXntzqGw8PNZqHpj2mN4goa7TV/ME9iHI2+kPtxKmGkTwdqymjh4IsqF06 qgzsvK3SqAZDhrdM/C9LtsUYbuaVqojsRs6iGr7zSdek20Gt/Qxkkejhm5cgAHdoe4+S WPnQ== 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=IHamgrEupShYV620YMFeeojD1ExyOSEGb/SHg8pkPf0=; b=AYh2lhujcZ3SHDvLPh4vxxOSnibiFS00nKn204ZddD8K+NttLCW4VJ6IqwJ1R4fxGD D86BLFb9doqJeXqIVo9Ggu6hkwvi3XOQsOSNArQOu5xlHACRe4u7JH4b0PB0PJsm3JLn 9pB5hhhyVZOu1SjZW2O+MLseyNf1PevEOl3IFMrjErW7kkghq8jjQZzz4y1klf6g4/TH 9qIDt4RgFnzNQS3EymCQSniPVO9leiRF4/U2WjflvA3LkUiTMrwOMFBXvsl6gJaTQuJI VHr8cS7A6rWnrGTIhTmmBltdXGACoyznLZxpcfFpeh4il+kAIn103inbFxq6w8dIPmsB IWRw== 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 i35si2347709jav.20.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 S238642AbhELXlh (ORCPT + 99 others); Wed, 12 May 2021 19:41:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234300AbhELXVL (ORCPT ); Wed, 12 May 2021 19:21:11 -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 C64AFC06174A; Wed, 12 May 2021 16:19:59 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id DC7C03E942; Thu, 13 May 2021 01:19:57 +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 11/11] net: bridge: mcast: export multicast router presence adjacent to a port Date: Thu, 13 May 2021 01:19:41 +0200 Message-Id: <20210512231941.19211-12-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 To properly support routable multicast addresses in batman-adv in a group-aware way, a batman-adv node needs to know if it serves multicast routers. This adds a function to the bridge to export this so that batman-adv can then make full use of the Multicast Router Discovery capability of the bridge. Signed-off-by: Linus Lüssing --- include/linux/if_bridge.h | 8 ++++++ net/bridge/br_multicast.c | 55 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/include/linux/if_bridge.h b/include/linux/if_bridge.h index 2cc3503..12e9a32 100644 --- a/include/linux/if_bridge.h +++ b/include/linux/if_bridge.h @@ -67,6 +67,7 @@ int br_multicast_list_adjacent(struct net_device *dev, struct list_head *br_ip_list); bool br_multicast_has_querier_anywhere(struct net_device *dev, int proto); bool br_multicast_has_querier_adjacent(struct net_device *dev, int proto); +bool br_multicast_has_router_adjacent(struct net_device *dev, int proto); bool br_multicast_enabled(const struct net_device *dev); bool br_multicast_router(const struct net_device *dev); int br_mdb_replay(struct net_device *br_dev, struct net_device *dev, @@ -87,6 +88,13 @@ static inline bool br_multicast_has_querier_adjacent(struct net_device *dev, { return false; } + +static inline bool br_multicast_has_router_adjacent(struct net_device *dev, + int proto) +{ + return true; +} + static inline bool br_multicast_enabled(const struct net_device *dev) { return false; diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c index 4448490..fe21f52 100644 --- a/net/bridge/br_multicast.c +++ b/net/bridge/br_multicast.c @@ -4061,6 +4061,61 @@ unlock: } EXPORT_SYMBOL_GPL(br_multicast_has_querier_adjacent); +/** + * br_multicast_has_router_adjacent - Checks for a router behind a bridge port + * @dev: The bridge port adjacent to which to check for a multicast router + * @proto: The protocol family to check for: IGMP -> ETH_P_IP, MLD -> ETH_P_IPV6 + * + * Checks whether the given interface has a bridge on top and if so returns + * true if a multicast router is behind one of the other ports of this + * bridge. Otherwise returns false. + */ +bool br_multicast_has_router_adjacent(struct net_device *dev, int proto) +{ + struct net_bridge_port *port, *p; + bool ret = false; + + rcu_read_lock(); + port = br_port_get_check_rcu(dev); + if (!port) + goto unlock; + + switch (proto) { + case ETH_P_IP: + hlist_for_each_entry_rcu(p, &port->br->ip4_mc_router_list, + ip4_rlist) { + if (p == port) + continue; + + ret = true; + goto unlock; + } + break; +#if IS_ENABLED(CONFIG_IPV6) + case ETH_P_IPV6: + hlist_for_each_entry_rcu(p, &port->br->ip6_mc_router_list, + ip6_rlist) { + if (p == port) + continue; + + ret = true; + goto unlock; + } + break; +#endif + default: + /* when compiled without IPv6 support, be conservative and + * always assume presence of an IPv6 multicast router + */ + ret = true; + } + +unlock: + rcu_read_unlock(); + return ret; +} +EXPORT_SYMBOL_GPL(br_multicast_has_router_adjacent); + static void br_mcast_stats_add(struct bridge_mcast_stats __percpu *stats, const struct sk_buff *skb, u8 type, u8 dir) { -- 2.31.0