Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp2951090pxy; Sun, 25 Apr 2021 09:05:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUlLexGa/Cw4+MY26HZ//mHea9inZ4LjJ8BNcnXD6EAwyAVMswmUtoENkFtOXHt/+fPV7V X-Received: by 2002:a17:906:c34d:: with SMTP id ci13mr13781001ejb.430.1619366758335; Sun, 25 Apr 2021 09:05:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619366758; cv=none; d=google.com; s=arc-20160816; b=zAzZO1gHCGNlSSmQIWP74ifVLG4eQ+yyOc+H6Sv8Ezu2o45+znXPLYFitWG7g/v/H4 jbaJqIQVfMLmllTmQ854gpml37E2Xe+FEHmNFfJNw3rL7IGZj6H3a+79sMjC86be4uop PzF8x4GFLW3SSwr7KZZeRq+8gL5Tw/0sweGvVHDvbWZvo6XZ0PoXk/cb7ZN5irVT1Hja AYQCQhaVxSxf3r67PobQ++Yv9kaXiDVJc+Dow+xcYl2M/C75fupF9AlUpE1jsnLzAAGd /zRCibEowU5oJ7MRtr0WRwTJoOIugcjhV3HhTL7tr9/vMVAfpafsHpzaByCCB0yLtGTL aJlg== 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=IPsOpR6OHNsu1fDLF0OsVzqClKWdJO2qZvqjYpIRPvg=; b=ukTSWGdKSC0kc76VJPt+69MLgWsMZjZQtMy6UEe0OkKp6KXhtuXSGBA9/MHS9QdM7C I/F+pwYlP40GWwAi+jsNwfiKV7GvtiKZfyp8Vm7hJBLYnSVnBp7WVWciStOC4Z3W79dE gm29kNYCW2Lq0vLUFOGPy+wWQ2SHxnV5YIKoxwJAF0P8azQqBfaCyBCZ1PzrNWZwzGHE ZB6J04l8u9kR4AAU5bRih7r/NS4AYZgkQ9D0RaQ9doyqrUwcrNb5T0bno0G6KDWkeX29 k24Xh95LiBMfXN6cvaCukEx6GwiRSm9y8n9JCWc0fdMLaWVfnIwBzOenBuLQXv9qKuoi +sxQ== 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 bo20si11184802edb.260.2021.04.25.09.05.34; Sun, 25 Apr 2021 09:05:58 -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 S230511AbhDYQCd (ORCPT + 99 others); Sun, 25 Apr 2021 12:02:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231134AbhDYQC3 (ORCPT ); Sun, 25 Apr 2021 12:02:29 -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 34DE0C06175F; Sun, 25 Apr 2021 09:01:49 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 609933ED90; Sun, 25 Apr 2021 18:01:47 +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: [PATCH net-next 2/2] net: bridge: mcast: export multicast router presence adjacent to a port Date: Sun, 25 Apr 2021 18:00:50 +0200 Message-Id: <20210425160050.8732-3-linus.luessing@c0d3.blue> In-Reply-To: <20210425160050.8732-1-linus.luessing@c0d3.blue> References: <20210425160050.8732-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 | 58 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/include/linux/if_bridge.h b/include/linux/if_bridge.h index 2cc35038a8ca..12e9a32dbca0 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 0ebdbf09f44c..4afaf011f171 100644 --- a/net/bridge/br_multicast.c +++ b/net/bridge/br_multicast.c @@ -4013,6 +4013,64 @@ bool br_multicast_has_querier_adjacent(struct net_device *dev, int proto) } 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