From patchwork Fri Apr 27 23:00:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 10369977 X-Patchwork-Delegate: idosch@idosch.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C5D7E6038F for ; Fri, 27 Apr 2018 23:00:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B4FD929543 for ; Fri, 27 Apr 2018 23:00:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B27C82957C; Fri, 27 Apr 2018 23:00:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, MAILING_LIST_MULTI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EA9BB29566 for ; Fri, 27 Apr 2018 23:00:39 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40XqCm728JzF25c for ; Sat, 28 Apr 2018 09:00:36 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=mellanox.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=Mellanox.com header.i=@Mellanox.com header.b="UdD0fbVe"; dkim-atps=neutral X-Original-To: linux-mlxsw@lists.ozlabs.org Delivered-To: linux-mlxsw@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=mellanox.com (client-ip=40.107.1.82; helo=eur02-he1-obe.outbound.protection.outlook.com; envelope-from=petrm@mellanox.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=mellanox.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=Mellanox.com header.i=@Mellanox.com header.b="UdD0fbVe"; dkim-atps=neutral Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10082.outbound.protection.outlook.com [40.107.1.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40XqCf1hLvzF24m for ; Sat, 28 Apr 2018 09:00:28 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=xFyq9jYtFRf7ajqPUcN0vHY7/3clhJLS1o66bwS/oao=; b=UdD0fbVeFgZH+XI+6H2geWSSvyB8tyhl5tMXRPiaPokI7a1dYj8JaA5as3cKdlPvGPLR+66f0IE8j2XJo+F7DrXdknSQzgPQUrF1yr71rms+yjJj75mMpViItQblVSZwKdexYMs8GqZY0k6V+dJhBxmoI1nOhBEtS96N18qyhdU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=petrm@mellanox.com; Received: from t540p (89.176.83.59) by VI1PR05MB4191.eurprd05.prod.outlook.com (2603:10a6:803:4e::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.696.15; Fri, 27 Apr 2018 23:00:20 +0000 From: Petr Machata To: Subject: [PATCH net-next mlxsw v3 1/6] net: bridge: Publish bridge accessor functions In-Reply-To: References: Message-Id: <3f0f4ac6af0692f7d8b0b4de0077980fc1fc2af6.1524868933.git.petrm@mellanox.com> Date: Sat, 28 Apr 2018 01:00:17 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 X-Originating-IP: [89.176.83.59] X-ClientProxiedBy: LNXP265CA0028.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5c::16) To VI1PR05MB4191.eurprd05.prod.outlook.com (2603:10a6:803:4e::17) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(2017052603328)(7153060)(7193020); SRVR:VI1PR05MB4191; X-Microsoft-Exchange-Diagnostics: 1; VI1PR05MB4191; 3:NpK3eoXO8yPoqLMd0AmdPxNpLJsGXFToMcMIEm0ET6UbCr1K7emL7QpRSGOI/xBp4/G+uqtMJCMlHcQ3L4r3HS6yHflBIZVeL/CqRQGCtRSmycDjNvn9SFHfSSbcbqMzeNR01QpdDneS5o+rnOLKlOD6MMn46cmXk22td9dXav1nW25xVq4TfCGktBMkeTprL7ztlkYaiMpimNTGPTnajjS5Xe1tqvK1v7JLCX3vxqP/t0kx4kov4sBQTKWuHWPU; 25:hKI38bd5jyDzLmWEuDpATnF50tyG4RLF1J9Z5ph5/i/Am+a0dgYPgUYV/Tr4pdKGEQibwRc6ZCCgtGZR62mIBY+KE+u6UlBpKCxlviwQYJYCSAiexzZVbT+My9YsAmD4L6mOpiies6Lq+uPlBPMQLRZb4pnHCd08OLkWFnFZXHp66wbMJEJ+kxyx+nJyp/uRM4vx+flNrDGBptd25MPy4nf5v0dDzVmmQmzreYqpzcvC9kK0lkTYhDZUL/K9sIKzmPOi4lTTdB7yFa1YkyW6quTNhI/L/EIc9oSol0/8mZc1NlJBoOykGXOxAhN3XVa/Q5p/1S4Vv6GjpcoIHpJy8Q==; 31:Soo3qMI/wIERZ7lEDk1jJ8zKiDz2E7sDvTORWiIioAeQdmdyvbEDJ6X2GlxUh17lByf7raYtm04mP04pBFaeWzs9OuXK2Jz2ZCiIG/5w8RqLR59+wxXwzhwYnCGTJtWmcscMu34RtwMBkqgvlHtyy+Tmqu9J1QQCIb3j6neHhEtITpdSVV+VH7qh97IaK2/ev1VjWgHfifN+rTxd5R60G7IhonFaBnEJu8KG+zA+sY8= X-MS-TrafficTypeDiagnostic: VI1PR05MB4191: X-Microsoft-Exchange-Diagnostics: 1; VI1PR05MB4191; 20:+m3Erc/8aSQdMFSknGFH8daOBT/zCDMrYy20iYgBKgGcBHISOxSEsx3B3Bz0/wL1mH5L4GYFmFN4u2bgs9nKuE/w3JextCSC65J4+X+oUXhBjK4HvgzVMMZLRCXff/b2IxgbZy+MwAd15Neut+q0Wohr8NBWaQCpEDYbIxtDwHaVJwt3loI4VtUziMSKTseCJKw5ObRfiIzRAS4JK/4eTw00xBPpfy4qCW05aQgIvUa1KPM3G6hAS7CeT++C0fn95hErPjLX/KkpxmducdJBjAi2k0u2DAVY3IczBY71I/kfK08zIntAT2F9Y9D2zHkChnrvVXj9c+upLvtV6OHcDTUhzP8+ASe98efIv7K5tu6ffqO73m3OFUkOSgLLQZF2/iLrCMudvLXfAhjwS5F7GUNN4RwueV6OHxIo95CDG6Z2+MaZ3mRSQSbVEXZjpz+8lt34nXt5YQtAZzv7HfmZHJ5moPYL9HUK52N67yrgj1FcXJDjsg9+rpVEVhhOtXMR; 4:JczqgMkSX8s6izzSq/7ZbfQfrvrQw5fyC4aPQ6JkzgrecNN753NGgR0uPthCzqptu86gr6JWNlS1bCHTesDbiBws/uHcDNODxYpAcUAfMQuk6T1qDGBA2aaNA+uD0uwFKm0IYRo4QY9I3nmUp4XtRWuBc8khK84XzhrY3m3t5ECTrsLf08qQILby/BMrZUaipfHA7vFqqxn/N9CDZ/Awkht0+gJphbJFrYsgxqlEYula+khyfjpJKga/bnVtzDXVRDiwA4CKo0qn80IJKZHPqw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3231243)(944501410)(52105095)(3002001)(6055026)(6041310)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(6072148)(201708071742011); SRVR:VI1PR05MB4191; BCL:0; PCL:0; RULEID:; SRVR:VI1PR05MB4191; X-Forefront-PRVS: 0655F9F006 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(376002)(39860400002)(39380400002)(396003)(346002)(366004)(189003)(199004)(476003)(2616005)(5660300001)(6486002)(53936002)(66066001)(486006)(86362001)(97736004)(6916009)(305945005)(26005)(48376002)(105586002)(107886003)(6666003)(50466002)(106356001)(956004)(11346002)(6496006)(446003)(16586007)(2351001)(478600001)(2906002)(4326008)(6116002)(25786009)(51416003)(8936002)(81156014)(36756003)(68736007)(8676002)(118296001)(58126008)(81166006)(386003)(316002)(52116002)(47776003)(7736002)(76176011)(3846002)(16526019); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR05MB4191; H:t540p; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR05MB4191; 23:yDmi503t58LzzdKy6DOfSSiW/aZOin5nLT1xxelOb?= =?us-ascii?Q?Iz71QArPZsARufwkHXLwI2QYAEGfSLPPTNhXVt1s4VFexx5vDnX4GrXbueGo?= =?us-ascii?Q?jPtcMcKTmqHguEB8CpDWtyBOrwhjwe31QZsmSYYyWNAR90V/gKaKmkxvsH43?= =?us-ascii?Q?Mzzw4UqVJ6m1mXAwaqmccK7J/8drZjxQHdqd4jQan8lqFdO1LFEDnWVSVost?= =?us-ascii?Q?acYN4D6lHbhD7s8LHGtV4LFJUwdYL/KNbHWafuNgiv9YMHUDqmd0QCv7ywG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oFYOg= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR05MB4191; 7:UTtci37jU6x24CVjtKJNRbXiLFt4wkA7oPz+HXkLJ1sG7zXl/a8YvoytyToIGsBJR1i6BhQI5EzpWjRTIuzhI2PJwROvbkjp2X3skSEZIk/SumStJsi2q5pic88mjrHXmYDwmzFIfqdGbfnnq22ppZC8NVrUVd930gcgJzZNw8zYGe7Pa3FCrXUOLTAGaV8zWGAybAZW9fkzVl46eKCP4nGyP75rzJ5Lq5RofGmIrNc8crgUPmPlm3mJYso2hODg X-MS-Office365-Filtering-Correlation-Id: 68727a1a-7850-4637-eb99-08d5ac92a6d3 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Apr 2018 23:00:20.3777 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 68727a1a-7850-4637-eb99-08d5ac92a6d3 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR05MB4191 X-BeenThere: linux-mlxsw@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: mlxsw driver development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-internal@mellanox.com Errors-To: linux-mlxsw-bounces+patchwork-linux-mlxsw=patchwork.kernel.org@lists.ozlabs.org Sender: "Linux-mlxsw" X-Virus-Scanned: ClamAV using ClamSMTP Add a couple new functions to allow querying FDB and vlan settings of a bridge. Signed-off-by: Petr Machata --- include/linux/if_bridge.h | 28 ++++++++++++++++++++++++++++ net/bridge/br_fdb.c | 22 ++++++++++++++++++++++ net/bridge/br_private.h | 11 +++++++++++ net/bridge/br_vlan.c | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+) diff --git a/include/linux/if_bridge.h b/include/linux/if_bridge.h index 02639eb..585d271 100644 --- a/include/linux/if_bridge.h +++ b/include/linux/if_bridge.h @@ -93,11 +93,39 @@ static inline bool br_multicast_router(const struct net_device *dev) #if IS_ENABLED(CONFIG_BRIDGE) && IS_ENABLED(CONFIG_BRIDGE_VLAN_FILTERING) bool br_vlan_enabled(const struct net_device *dev); +int br_vlan_get_pvid(const struct net_device *dev, u16 *p_pvid); +int br_vlan_get_info(const struct net_device *dev, u16 vid, + struct bridge_vlan_info *p_vinfo); #else static inline bool br_vlan_enabled(const struct net_device *dev) { return false; } + +static inline int br_vlan_get_pvid(const struct net_device *dev, u16 *p_pvid) +{ + return -1; +} + +static inline int br_vlan_get_info(const struct net_device *dev, u16 vid, + struct bridge_vlan_info *p_vinfo) +{ + return -1; +} +#endif + +#if IS_ENABLED(CONFIG_BRIDGE) +struct net_device *br_fdb_find_port(const struct net_device *br_dev, + const unsigned char *addr, + __u16 vid); +#else +static inline struct net_device * +br_fdb_find_port(const struct net_device *br_dev, + const unsigned char *addr, + __u16 vid) +{ + return NULL; +} #endif #endif diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index d9e69e4..a1c409c 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -121,6 +121,28 @@ static struct net_bridge_fdb_entry *br_fdb_find(struct net_bridge *br, return fdb; } +struct net_device *br_fdb_find_port(const struct net_device *br_dev, + const unsigned char *addr, + __u16 vid) +{ + struct net_bridge_fdb_entry *f; + struct net_device *dev = NULL; + struct net_bridge *br; + + ASSERT_RTNL(); + + if (!netif_is_bridge_master(br_dev)) + return NULL; + + br = netdev_priv(br_dev); + f = br_fdb_find(br, addr, vid); + if (f && f->dst) + dev = f->dst->dev; + + return dev; +} +EXPORT_SYMBOL_GPL(br_fdb_find_port); + struct net_bridge_fdb_entry *br_fdb_find_rcu(struct net_bridge *br, const unsigned char *addr, __u16 vid) diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index a7cb3ec..1a50931 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -594,11 +594,22 @@ static inline bool br_rx_handler_check_rcu(const struct net_device *dev) return rcu_dereference(dev->rx_handler) == br_handle_frame; } +static inline bool br_rx_handler_check_rtnl(const struct net_device *dev) +{ + return rcu_dereference_rtnl(dev->rx_handler) == br_handle_frame; +} + static inline struct net_bridge_port *br_port_get_check_rcu(const struct net_device *dev) { return br_rx_handler_check_rcu(dev) ? br_port_get_rcu(dev) : NULL; } +static inline struct net_bridge_port * +br_port_get_check_rtnl(const struct net_device *dev) +{ + return br_rx_handler_check_rtnl(dev) ? br_port_get_rtnl_rcu(dev) : NULL; +} + /* br_ioctl.c */ int br_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); int br_ioctl_deviceless_stub(struct net *net, unsigned int cmd, diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index 9896f49..df37a51 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c @@ -1149,3 +1149,42 @@ void br_vlan_get_stats(const struct net_bridge_vlan *v, stats->tx_packets += txpackets; } } + +int br_vlan_get_pvid(const struct net_device *dev, u16 *p_pvid) +{ + struct net_bridge_vlan_group *vg; + + ASSERT_RTNL(); + if (netif_is_bridge_master(dev)) + vg = br_vlan_group(netdev_priv(dev)); + else + return -EINVAL; + + *p_pvid = br_get_pvid(vg); + return 0; +} +EXPORT_SYMBOL_GPL(br_vlan_get_pvid); + +int br_vlan_get_info(const struct net_device *dev, u16 vid, + struct bridge_vlan_info *p_vinfo) +{ + struct net_bridge_vlan_group *vg; + struct net_bridge_vlan *v; + struct net_bridge_port *p; + + ASSERT_RTNL(); + p = br_port_get_check_rtnl(dev); + if (p) + vg = nbp_vlan_group(p); + else + return -EINVAL; + + v = br_vlan_find(vg, vid); + if (!v) + return -ENOENT; + + p_vinfo->vid = vid; + p_vinfo->flags = v->flags; + return 0; +} +EXPORT_SYMBOL_GPL(br_vlan_get_info);