Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2030982pxj; Sun, 9 May 2021 12:50:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwz2dIHaWMu8p8Ae6y2xCOkwbbV95iIO4bhofrP7kOOhX9ks6+V0fuhmNGuQA/+ZnN1ODtD X-Received: by 2002:a17:906:d969:: with SMTP id rp9mr22502517ejb.516.1620589843130; Sun, 09 May 2021 12:50:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620589843; cv=none; d=google.com; s=arc-20160816; b=bW0qWiE7XkHY4d42cT+KbMc/hcTtatkYx4CFSJChQ4ZQ+oj2hXBH+7zry9pQdS+WI/ 1LqEXT3usq87WTULpLUDn6lUv7FLYMMwRfvr3tsn/Y0bHavJSDbgTspwSNpUcDkXUQK5 RMD0D6kmYnAAiEuJuduFHyxPLVveLiiNOvUusCyngZVtQwOkfcGPmdnl1vFekXa7tVZr Fa09C8XQhgjIJ7RYEFcARmSN5RpceTIwaZaWR3B5Qbom9DfQg0Eiq1YTpDYFVsI86ndM tJX6NyFr+g56xb46730Ha83q8sLeMPO59vgU6iwq4EFKUQlu2d3JrG1541/josdg9zK3 1o/A== 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=Y/xWHgZW15t2k875gWtkdbnBAcDpxFMVFRHX/PAn3GA=; b=MhsMfA/Em+amAILAg+LAI0sHUYKS01Xniy3yYRL5EjjQBFZUpxntPf6K5DOVmQU3B4 84eJ/PrRjZYUIzoU3Oph9kUAjhvu6gJVT8mYp6QZbBQDiWjJm8RXr+ipj98VM1FUwvAw odVTF61Q1PqhJEsLXVkD7gMPwnKET8/Cfd5uYEsc2RRx9M8L/RBvLtmQkfUp/gawLrMo 5U9IOfNdhLZencP+Mpd5jGNPXPDQi5Bdpi6QgbcRtmrPBtE8kKxSUnTm9+KQHJeP+xvO eUu5DF5z8EF8zGVTT4FfKmzBoF9VWOOpc1OKdY/+2sn8KUzBHuR6ZW+uws6oF/NXtJFk ljFg== 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 v19si11388757ejf.170.2021.05.09.12.50.20; Sun, 09 May 2021 12:50:43 -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 S230314AbhEITrG (ORCPT + 99 others); Sun, 9 May 2021 15:47:06 -0400 Received: from mail.aperture-lab.de ([116.203.183.178]:56020 "EHLO mail.aperture-lab.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229987AbhEITqh (ORCPT ); Sun, 9 May 2021 15:46:37 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 5BFED3EDDE; Sun, 9 May 2021 21:45:32 +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 11/11] net: bridge: mcast: export multicast router presence adjacent to a port Date: Sun, 9 May 2021 21:45:09 +0200 Message-Id: <20210509194509.10849-12-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 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 --- net/bridge/br_multicast.c | 58 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c index b625fd6..e963de5 100644 --- a/net/bridge/br_multicast.c +++ b/net/bridge/br_multicast.c @@ -4061,6 +4061,64 @@ 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(); + if (!netif_is_bridge_port(dev)) + goto unlock; + + port = br_port_get_rcu(dev); + if (!port || !port->br) + 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