From patchwork Thu Apr 26 16:32:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 10366369 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 DF93460225 for ; Thu, 26 Apr 2018 16:32:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CEA3728571 for ; Thu, 26 Apr 2018 16:32:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2CC6285E5; Thu, 26 Apr 2018 16:32:51 +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 0021128571 for ; Thu, 26 Apr 2018 16:32:50 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40X2fn1PXQzF252 for ; Fri, 27 Apr 2018 02:32:49 +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="fQglMG+x"; 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.0.51; helo=eur02-am5-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="fQglMG+x"; dkim-atps=neutral Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-eopbgr00051.outbound.protection.outlook.com [40.107.0.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40X2fh2m8hzF25B for ; Fri, 27 Apr 2018 02:32:44 +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=emAADyC5/dshJVOhslGKvdH5SflcM0t8WtY72HR93Fw=; b=fQglMG+x1QlbQQoPkPa5ncrz0+Dr1tBNTz7krncLnpYyWcBkEZzAK0qH/8pvdJygguNHy+kAJrgc7jMPIxfIj+1nKJ3amruvheiIpRLNG9YNS1nJV4+b+VOWQV02O6UkmH/Leg3GJZE92iO6qr2haC0l9wyC/wgsPU2sc4FDSi8= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=petrm@mellanox.com; Received: from t540p (78.45.160.211) by AM6PR05MB4182.eurprd05.prod.outlook.com (2603:10a6:209:40::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.696.13; Thu, 26 Apr 2018 16:32:37 +0000 From: Petr Machata To: Subject: [PATCH net-next mlxsw v2 1/6] net: bridge: Publish bridge accessor functions In-Reply-To: References: Message-Id: Date: Thu, 26 Apr 2018 18:32:32 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 X-Originating-IP: [78.45.160.211] X-ClientProxiedBy: CWLP265CA0027.GBRP265.PROD.OUTLOOK.COM (2603:10a6:401:11::15) To AM6PR05MB4182.eurprd05.prod.outlook.com (2603:10a6:209:40::27) 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:AM6PR05MB4182; X-Microsoft-Exchange-Diagnostics: 1; AM6PR05MB4182; 3:mrqZTKZPU6AIbBG0Kn+SlHt+nEuPfVNyD4EJFtqHxEA/ADzfgzW+rbKiFQij85b9YKsEYngJUS13Ccydftuoeob1cl/9nT5O+exWzCD/jYfA5KUZD/iLBBPqzkWMSeN9yC24wMg4kCUih9S9Ytx2ZRv20g+M8Mw19w/ABjh4Gc+LshEfr/ZJZ2cabksQYUOW4xVtqvEVEjrkwP3GuNBZONJ52W3iGN6ReBd4l13H0n1AsYuK3xX8ODGZ0UMpkmqI; 25:mjPDsiMFPtjv2+o8wF1KMlnbCcVrgOy+5ZJeQ8Q/LSpnHzHSRFLIm0NYxZ6IGz9Z7Jlx8UToOqHUrcPGkcKzlPBysG9Uq51+DF2szMgbJ73dOIkLAl2JpCs9XXFz0QcOJY1vUQEInntefUwasJf5nHFFlfojKvg0TKOS9mcNOcofWZYmYWzEB6684b390GGCh1kVpAAhapMoQ6tu+A8e41pENsDQIsyCbUDNq1z5hP4EtakQji2j1W3nIUZRy234ZRXiD754EHJqkdjxQtJGL3LQRkaq2mmIvdImgCBuyeRG34aHXiZMcfoJspoyrgjbXCoQFSHD1KC2TDFfNfMfbg==; 31:Nvoe8wBWfaEWCtt8BCoBR/bL4AXXp2VfXWJYlBQFmQDc4DSetoZ4qomSdD/325qk10hP/jj5higLbqPpwokneYF6A3ojxw5UHXb31qkKTbmjk+2dm9F4op0AdjSItkByzO0SU6WCan+kOaSMYkUPWWzpcb6QTlueocmIvSgoI1CEKqkgWHTPSWqLF7STCusfr4NDjWdcC7rcaRnZ7TpRzF44LtkZc+onj1IKnhkmwIw= X-MS-TrafficTypeDiagnostic: AM6PR05MB4182: X-Microsoft-Exchange-Diagnostics: 1; AM6PR05MB4182; 20:HVtclgDJQXoBR2zTDSeUq3MLG+IAJYdgMfhTTTQmsSMbzsXPFvKVk8q2x/4nAMERFrQPD9uiar42bJlsaDmVVCHFLDK0vp0RCwo37t14dFmMwcv3Usf+jEa1UcI5czxEjzhNgeEEodz9rc4DIJ7zNIgzOJG+WF2OD40lezIFTy8SEnpfbKviwu7gMymMzIbo+ijUyQh03AqnRLXKpaQzh40nAtk6givFUWPO2eYg/GIontZaT3zG0uUq9znDHejCAEQA8cV1+eoIV+QhH21g2Uva07jPq9OW6FDn8hj8gTsgOqhBHbt0Yuf/8P5ja68z2CBMyo7mL5nUgjKs2/0Aml0sPgg5ZsRUPoT4vIrmyUWOStuamPIwcUyf6E4Fu9qnT+LV8Ijx34oZJTFBc+kMBhKpWv/1Ij57zuUEePZK2W4PYwQjGOZoovB7gJ5hab6yhkDMs1yNOwUVEZYFYmrtKqBZKpO0W7FwEi93JjXQyJhWtjAztlbfDmg8ueb/5Vi6; 4:SGV9SBKfDj4oFa5seD8GQSNHk+ngRkV3mEuYZ3KqJ3WDVKpJwMFTPn2s6QgtYuSI/w8HaXNlO5j4Po5/+8ZCTZrHxoAO9Ff8aR5oHQnriPbvuS1+bSUBdDjcRZ8XBFESHM7A17WkdEDkgjVuinnHcBhkHCOA/nMZ4GecUhk72b/c9oGZvlhn1ilxttME1WdR+P/wqfj84fjKuVVjgqDKggAZgy013FuF3KRrw34xLPJTaV8KK83VhGJdWJS2rncnXoaC6e1WnoRwcRJXUvKtbg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3002001)(3231232)(944501410)(52105095)(10201501046)(6055026)(6041310)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(20161123558120)(6072148)(201708071742011); SRVR:AM6PR05MB4182; BCL:0; PCL:0; RULEID:; SRVR:AM6PR05MB4182; X-Forefront-PRVS: 0654257CF5 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(366004)(376002)(39380400002)(346002)(39860400002)(396003)(189003)(199004)(2616005)(81156014)(66066001)(3846002)(2906002)(47776003)(8676002)(48376002)(25786009)(6116002)(118296001)(106356001)(478600001)(4326008)(956004)(11346002)(446003)(6486002)(7736002)(8936002)(50466002)(81166006)(6916009)(2351001)(105586002)(6666003)(6496006)(86362001)(5660300001)(16586007)(476003)(58126008)(316002)(36756003)(53936002)(386003)(305945005)(16526019)(107886003)(26005)(52116002)(68736007)(51416003)(76176011)(97736004)(486006); DIR:OUT; SFP:1101; SCL:1; SRVR:AM6PR05MB4182; 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; AM6PR05MB4182; 23:FbuSimHFbWGhOy2i1vEf9HmY3R5cbBOADSvxNTE6p?= =?us-ascii?Q?sEPHOR4dT+s+E/DhersegmFRt5UzwOEBEypvgPs+OE1vQAvRMMXa6aHRVr7U?= =?us-ascii?Q?K+hGeLSurcoRoBMSjMFEZ+WHmS/2MMtPpM6NL1abJy8UwPxnOPFml/33A7Yw?= =?us-ascii?Q?VbNI7L3PZaN6SdGDUJyS97l8DaO8Pu+2snZ2j2GXGgCI2x7KhZM1UxQw7d1p?= =?us-ascii?Q?35tNrqqELoqa2fAB3+l/XHAsCXTRMxyeJZcnVilu8U4nSE7IRklytQMFkSzo?= =?us-ascii?Q?XSDPr7n4Eyv47ZoQ8yooO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: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM6PR05MB4182; 7:9d5sfRlmOfrk9Uld8JvHvN7HVt/xC0QbyRJLQktSzfYQqBqpa32DaYL4EBhf7QpCWnFv9RzKQdTeSoImFXgjJvtgHUOMp1BZV6mC8rVNShM+nApnQYHu6a5VyD1o07GV5hWuvajHv8J+uR3amSLXqqTx/nFFZuvCI0eH3olbGt0DXq/tf67rR2SyhOc6yHlQTFoH69dfrTzJCPLrBoYu5TDQ3F2RXoVkWiprV5VmekyR3EfHIAI4BvvRvKUulY+j X-MS-Office365-Filtering-Correlation-Id: a22d2547-f8f7-4efa-7add-08d5ab93527e X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2018 16:32:37.2856 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a22d2547-f8f7-4efa-7add-08d5ab93527e X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR05MB4182 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..769cf71 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_pvid_rtnl(const struct net_device *dev, u16 *p_pvid); +int br_vlan_info_rtnl(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_pvid_rtnl(const struct net_device *dev, u16 *p_pvid) +{ + return -1; +} + +static inline int br_vlan_info_rtnl(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_rtnl(const struct net_device *br_dev, + const unsigned char *addr, + __u16 vid); +#else +static inline struct net_device * +br_fdb_find_port_rtnl(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..51c7720 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_rtnl(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_rtnl); + 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..821014d 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_pvid_rtnl(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_pvid_rtnl); + +int br_vlan_info_rtnl(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_info_rtnl);