From patchwork Sat Feb 4 17:07:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 13128822 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E42CC61DA4 for ; Sat, 4 Feb 2023 17:11:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231398AbjBDRLx (ORCPT ); Sat, 4 Feb 2023 12:11:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229746AbjBDRLs (ORCPT ); Sat, 4 Feb 2023 12:11:48 -0500 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F0C73251E for ; Sat, 4 Feb 2023 09:11:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=og8kT7B7I29tdp0IdABtav7+M4ao7rekflZ2cmc4jmLZOg5nvmdYzHoEv4YOfYXj2/1kI3kPfKksOVRgHoNjm52fA2ZDGUKxg53cqVx9czotftLZ/825OnqRhUxkqUNLojVnds/ZyHVNPQOQ6gV0SQK8EAB27vZX/1hVqH7y9YVu9uo6+8yHV5wknQJov1kUy/fVGllKWYlRQFzZje/nhaWFTB8fQsni+3LeSHPgGlNJ8YfSKycAuLBGZdbPxPhPlwNqgzgXBiafzHxYJQC4KrP6IRCY6KJzQhM1sj5sqskHFJyJQJKf7YHyLf4596kYeMHRfUW8dvTASs6xzfuPQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HnJRCy5BevDcD7JznBApG4QkbYTYfBiimkz9BfO6Lzo=; b=RETTOCLIB8o5bbL3h+2JbSkhinF1MoNVZ7drdwjMaX7iJh6ah8z0ndCJOZ6HoddXcZ6ZHloRLnnJbJMQs20kkMWPDzaExgOWoUWoSn0lu+vew2wuvDrRaUPA/zP1eDnkyuqExKZ5LD7JKDvNbdExMpBmyM7dgJnA0OkSbbeQxGAqb3syOvVDvHr5ErSGM9RcFNsZ2tX84JcggCMLXQ8TY/Mo74oZhhTDA3P/s+yx6Lxy67SFNf9158vOa7FyF2e43Nvg8deM0AikTw2ShYHFgl7LvnRhKbk8iLTxbqhPAXoeyivwDTXKjnMArk8pBaA4JOaNwAEgC3LVfG+eVXjGuA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HnJRCy5BevDcD7JznBApG4QkbYTYfBiimkz9BfO6Lzo=; b=oe/xDwjTLe/mghUDerGfAc4S4UGc3V86XmSOdJQh4YwGoBM06JNEm9MpZlGonUitJvWKJ0hwOEMBjqukcXzRmAvgOMcsF0T18w02SEsPJGuO496O3Lmg3IWXShc9XzujKx3VelA6ElxWP+bXyucSWzWXDcGEazdSWa0aueDZChQYtPVJLlvExxMenSh2d/YH6NJT0pWQOgrN1Roj68c2J2YYL6F3n8usTw+LhCYHyH9NTf7l7AITyOK/mA7X7nVkMM5dHz7ex3fZerrNUpy1U4og+F2evlv52qdlsW1PScCUcFGavSGJjgRmwVCrBe+8RlMw1Bii15QyfQj+8N0Gcw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) by SA3PR12MB7997.namprd12.prod.outlook.com (2603:10b6:806:307::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.31; Sat, 4 Feb 2023 17:11:46 +0000 Received: from CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab]) by CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab%9]) with mapi id 15.20.6064.025; Sat, 4 Feb 2023 17:11:46 +0000 From: Ido Schimmel To: netdev@vger.kernel.org, bridge@lists.linux-foundation.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, razor@blackwall.org, roopa@nvidia.com, petrm@nvidia.com, mlxsw@nvidia.com, Ido Schimmel Subject: [RFC PATCH net-next 01/13] bridge: mcast: Use correct define in MDB dump Date: Sat, 4 Feb 2023 19:07:49 +0200 Message-Id: <20230204170801.3897900-2-idosch@nvidia.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230204170801.3897900-1-idosch@nvidia.com> References: <20230204170801.3897900-1-idosch@nvidia.com> X-ClientProxiedBy: VI1P191CA0008.EURP191.PROD.OUTLOOK.COM (2603:10a6:800:1ba::6) To CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR12MB6179:EE_|SA3PR12MB7997:EE_ X-MS-Office365-Filtering-Correlation-Id: f864dd64-ad9e-4331-d1f4-08db06d2e539 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cMHK8PBFLWKB7SNs/2gJSVRS/irm+qQ3ZPtFme9Y2Oq5zdxXyKZhDVqBWb32doXMxTkEt5HIM38tdiI0UecOTU9sqxZZ5u/Imm6KjkGFERcabkRAM1iO8oRrE198qTvE2PWaNvUxntfyFgd4zL/YcORxJTFd38/EeBvTwd+pRNttFMdQDuJa9p9Kpw8BK6IQzGeP6y2HSYnA6q1W3P+T+aMdY1YX+iUqaKe1d7seyo6cKSE+Jqmb/IqFB/EDHS8N/Zr2IPi2R+phevfYtPOq2cjcSEUwkyiLOwT5Zqyhe3u6JJ+CASgutZSKOPSAgZreXNN8gf1LnkBA0xTSdkprz0JHstuxHX76cYojmQ5MeENldK20pV2Gb783d3ozR5Idd3G50ASC9hzte01MQVHGzW+CNpy/aDKLxgKvoMW7r13owDCWuN9SAS/LVkAnKIyXSoFNVoULGmFd/id99CX2Tzpx3KIVRmr3UPUz9DZhA7sSxToxZtejN9aLmJXsIPPaagpqxPr39g1bv9DqH5cyKSsKcOCGiMG0ZaYDnt2ZNQaYLcaCUsVw074zDOAMuH8FSKuEehKSln1U2k/z45JQQPcXUG5b4ogbVIqbT8/qNJd9ZO35BqCAWEvlILxxyGsfOtcEYjYZd3ApjykUdyKqYQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY5PR12MB6179.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(39860400002)(136003)(366004)(346002)(396003)(376002)(451199018)(8676002)(41300700001)(66556008)(316002)(66946007)(36756003)(66476007)(6486002)(1076003)(26005)(186003)(478600001)(6506007)(6512007)(4326008)(107886003)(38100700002)(4744005)(2906002)(86362001)(8936002)(5660300002)(83380400001)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9nSxgYGNtwDp0J7Ax5RICQ2VpFxJA00uoEhVITIvyH7t0smAwEep87MCt8iQZ/IsHJ87qb6FqoinBZpSW0GmFJfsVV2HzOR8pg14WFE6JWsgMvC3qK1gskKit7HpQM8wnxFdHuBEV+9ST62oXX/6/tyau6wW5mzN+BCCauW34aT27juW98qG/1uzy3iyPO9c/niKqKMlYJ6GfqMZbs2vI8mjYLNV2uyt8jhvFrlTPvBBgrdS6SsPa0t5Qi6wfOE375+abJbpfIYlp6UugIZ2juOiwsVxNLVZUqGKaFVnxmMFnm30qCGeZTEX1W78gceaMldfwkAvAwBkX383MEB2cGI6k10ImPX36DGylhFUL+hqFA+HvgSGuJS4CziXoRmMUGafXAiddUajvlHHPhVlkWBXI49mo9wJr4RXfVadL47wdnai8XpE11asDtdldxlpbTxkpIpLuldGsTNkg5NfwsSZ7JRNk+tWx755xg9r5GbK1t2uYNXOss4rdwx9b7AbLNCy0PopzuJgq+Gj4xaqdsR1na5gX51GfA3oAYWohQ3VZQzApDeEJq8IYxr5BWA/BMtf6ogxHNsC/S+4CwB1flpOxcOo1Qnz1ist7j5H612eQJeyPxDRhBrkWKs2RAVBNeuXx+1N6aCKAJlQXK9IEKJG2zx7J9NRC35OiOqL4RJU0lWwWnDFl3QOySwkh2C7AmkiQU9go+NgQSizRvtp90pxTKOi5e39oPNBPhl6LCL19zmtDT4zbTdQJ8t5NjM/VQI33XA9Vsx7HzrDa/sGeML94foHDFEia8n4vM+1eXky0FXFV8kJ47TzNneO8s4pr0EHEzYfWAvCnu30t/2XloSoV65MLgb8vGiONhjr4vbJtWK7uaW/mOPDXafZBm4RlG7/JGLVEwJc1/VLEtRRiEwBMPy5FFpmMXWJH7/NkcmZKASkgw/bIpJsWyChOfI+sB68dQBR5ZUE3PByTVS7SYBNN6AjhHN6RFb0wdd45HTPVjmLD2roC2VzAmd/iIerjhKVFNqXpGlF0C0ve2qf5537sWlAemRPLBLDuzikH0AMqV+VWyU7SxqZu6To2tJ1cvra6oyWkLUIrJN9x7UhFfBBRP1ZXqmYL9G6iBQQxWZJTKHiIxcHXiYp7OvkmgnWc97AoUE6kyZhXvXCJLw7lBzfttWZmo4hF+bWCG+17L+YU/M9mx4fglZ6EaSzM4ZesH1J8dkDycJMR6Xq0ZUlrnd6XixqN8yXOqOvLSylpChBgZT3qUJOEmer/YtzGvutahluuacCVngIa6DhRwXEM4I9K1dU3NdTJ/1NsS1auN+E7mukPO/Fw8SCRNbAyo96bSPcRi82az3vJ8lHHK9QgoaphRpaJB3HyWEXPIoS799D7avD1VI5wO1b2XZ7kfb8p+n5C9VITmgLvRdcoGqXNaui4Eyzh2BO0rP58uQ7Vu524Jl8R7aMavtbvrfG6eIk/Jg7ba7lKkvWw1pYXn9x3vYgkais31KJ0pRADqOH0BWSgFFZHlR0sqbHBQLuEy2Vm3NT9m3kT1GXyhlUp12g6OHq4wzMfKOlWM3fBYEFvsWKmQFERKumjfFAHks2assU X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f864dd64-ad9e-4331-d1f4-08db06d2e539 X-MS-Exchange-CrossTenant-AuthSource: CY5PR12MB6179.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2023 17:11:46.2820 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Kc9KDKUu9z7Yt+KuArwLWt7oBbuOKO3TwBB51tdgGUZ9WSqA3qYOxKOf1JUl4Foi9pxA81QdUvfieTO45jc9Ww== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7997 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 'MDB_PG_FLAGS_PERMANENT' and 'MDB_PERMANENT' happen to have the same value, but the latter is uAPI and cannot change, so use it when dumping an MDB entry. Signed-off-by: Ido Schimmel --- net/bridge/br_mdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/bridge/br_mdb.c b/net/bridge/br_mdb.c index 00e5743647b0..fc98c32e5894 100644 --- a/net/bridge/br_mdb.c +++ b/net/bridge/br_mdb.c @@ -259,7 +259,7 @@ static int __mdb_fill_info(struct sk_buff *skb, #endif } else { ether_addr_copy(e.addr.u.mac_addr, mp->addr.dst.mac_addr); - e.state = MDB_PG_FLAGS_PERMANENT; + e.state = MDB_PERMANENT; } e.addr.proto = mp->addr.proto; nest_ent = nla_nest_start_noflag(skb, From patchwork Sat Feb 4 17:07:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 13128823 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE4CEC636CC for ; Sat, 4 Feb 2023 17:12:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230042AbjBDRL7 (ORCPT ); Sat, 4 Feb 2023 12:11:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231987AbjBDRL6 (ORCPT ); Sat, 4 Feb 2023 12:11:58 -0500 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDC9132E58 for ; Sat, 4 Feb 2023 09:11:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SQXPtR/YU0K3zY9wQtDOPzHHOqVrT9fIMB3BrFBlZTDDh9lghNT+l9rcumO5SvdPV/SAyexdTN8gQU7KHFLt/E5Batb3rIbuCMWPQ9iBbrBpyZ3Yp81PAcDuYNZEuvDN/xIPXZ4GBGZrplwOpyzYntkpZ0yz7WaUegZASXoruVGKUwj+6VF3uFJhSiaBFfYbx10k0dlxviUihWcgcQWRvDLtcTc+iaoToIfP2YDdKRQG6KzGM+FXuGebA3StRSaG1wAzK/lGwfu8Uo9vJ3gCm5mdkE+NQiHBsbw0jX5au0bHf87qqfYR9de3w7blfO4a3/uAccHVfrBUUWC4QoXlbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=REBoPD/3fQkhdNFrYHOPfbSU4VP8xl+1/rrOSS6EpiM=; b=As6vhzxWfh1LJHprse45sgMui96vqP+j6kTHjwBzz8jCzDpSDpXdGuyGQAmvYL5NSRqu7zfv/Bm87ByFAGB86fiMK28Xx+kAg1q0RqwyMp5fsmUTaUII/L5GBViH2NGKpfoT/6F5sqxywzMNJkKXUP5tk8WiTd3lvLRfBdreHqlUKK2zeaeT/6JZgW0Tr7MCIoNlBz3ooHHPoJexHrbe3AwpA9Pv9qmmunY6J6LJKs6LOykMvF5VhFxw5sGI62F3ahVsD/kTAtJ+ThUk8EIbpo+FEuS2FbKKOUU8i9R3Ag3x7MZhk0oLOz2d+cdc7sx7c9VPQxB3H6/tCI2MzfUuQg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=REBoPD/3fQkhdNFrYHOPfbSU4VP8xl+1/rrOSS6EpiM=; b=Xpe75xFXp7TfciZj62RfnS5pOJlCDkoe7MrQ4MmSMTbacWdaOso8dwAcNtHWWYU144MuNNqOdM1L6O5TfXXHgdNFvCB2QKM+edQBVkKJMbnipr+gxQpKCjnDk+640ScMro6i6mvxqNOXGTt9pg7BBXLzL9kKGLWTz7nTByBqowg1BtTyrHNIPFJFdbW2enEm1hG8FzPTcowG0Di9nucHRiMYzpnBjd1mgBDptTktnGIjBu67vvNBfe6juOWIHvtZewWsv4lzQ71QAAArg5uEL0hL05z9VE+nC7phqjjBwzrHrTcHDeQpuq14AGTIml4cLbtvM5zEIRikH0XrrvmXJw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) by SA3PR12MB7997.namprd12.prod.outlook.com (2603:10b6:806:307::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.31; Sat, 4 Feb 2023 17:11:53 +0000 Received: from CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab]) by CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab%9]) with mapi id 15.20.6064.025; Sat, 4 Feb 2023 17:11:52 +0000 From: Ido Schimmel To: netdev@vger.kernel.org, bridge@lists.linux-foundation.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, razor@blackwall.org, roopa@nvidia.com, petrm@nvidia.com, mlxsw@nvidia.com, Ido Schimmel Subject: [RFC PATCH net-next 02/13] bridge: mcast: Remove pointless sequence generation counter assignment Date: Sat, 4 Feb 2023 19:07:50 +0200 Message-Id: <20230204170801.3897900-3-idosch@nvidia.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230204170801.3897900-1-idosch@nvidia.com> References: <20230204170801.3897900-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR07CA0257.eurprd07.prod.outlook.com (2603:10a6:803:b4::24) To CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR12MB6179:EE_|SA3PR12MB7997:EE_ X-MS-Office365-Filtering-Correlation-Id: 1a4eed0e-1d4c-41b8-2497-08db06d2e928 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CblcSWtyufgvS3iOU9E1Gsr9OGV+t74dKhsbIS9S9grepzSFAyHzGxKkMm7NqueHDGHFFSggoNkCX8AForWZlW2QOWaLFkpdVHirJXUv2coVj2Mnpszdir+awQK/qqS5YyrGczWH1kiDRsUMz97Sbqrs6BZaexDk9OlSSRGn1n7n36/75aLk+gX3Byt7x84ZD0s2XGrhJwcFOlv9MxfBpfcsWPjSMYTuku+y5sUdOe7NPdPiouVbM9PdlQ26jLdqeXggsbUmL3aHCGTUnnXycxRUaxfCmqUoSuMgoF5+zO25CdSlQ4kmmMO4BlxuY/lsez2fMOLbBODKSUfz32TjO5IITbM2ys7R108Va22bsoKka4lREpFROiZ09x6PmFMhZLUp4hIhEDLIhLFzk/1/mHkNW5sHfd5w3h0r4nCTCT//0J9Ta60sgmEzrP2TUySqbMJ+o83Z2bkZiINzYdA4TPGBESJadpNzs/qprSCsVr/rxvJXwq49ocRzaZwMyqQIGHYXoi8Z2KrP0HFfb/d9bX0+abUGco6hyEae6gthkhwNLTYHLAejFKNbJ3pq6vCrHuMHrkBIwUXTAs1arPHSmZMo2zrrsK1pbX0H9qamt49daoAEo4ANPojuN3g65PRKagxqMnKp/1kKMvmc/B3eng== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY5PR12MB6179.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(39860400002)(136003)(366004)(346002)(396003)(376002)(451199018)(8676002)(41300700001)(66556008)(316002)(66946007)(36756003)(66476007)(6486002)(1076003)(26005)(186003)(478600001)(6506007)(6512007)(4326008)(107886003)(38100700002)(2906002)(86362001)(8936002)(5660300002)(83380400001)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7d8DgBNvFJ7yv8aOs0TWnKuX7Kof8N52g3DVq/wZ1qEs8pNbsglSGDe1ivnbdHlWb3FpWtS5CMsHIExNpWeFGfDmZlQ10tjfAkf5w730Yng6NM55NxDVwnQ+4YP38oR7COyTnBVXC9UCPPnGUo9rPkFYkm31P4EniRO1ijVV7fglu+RI0Knv77fhvZ6X6FkADcVM2uqiOcjj8gOBvswiKqsyLJMYQPIkXpoVK5HIuvRhDdSs21Ks/Mikh1dv5n2YJVewwP21y6qai2i9qfuYnskLx2hsli21ISKSOH9i/yPnokQtE0M5AgHssohcn2QKNsa9BPdB2kgqPGzZq89bNVSNOVv7vSv4o+VsU1VkmJIyxLTLV+BrLFprJkf4Yn6dgNonh75vQfzND1BXXBDMGsS8zRnZfIH1wh9QqZoPdNbzDaiHmzK+BLUMsEEArRhrG1K+/w912z3G7ObJYz+gdPbK7E+s8qYIY7K4dAy8CF3Pk+bMAmNyq9uXj9HMU+GFkCA7a6NzadoNCSYs9lTQi6A3eoHiyMp1MQy5zpBWdmTvnOX3zN+qyzH6LDxpbjPwv/NITmtYDIKrHa5xryFswB+mUblxTLWIrVZulLUYXoA0FXS59aHkRYr3hbjTLbbD+BB0cwsovXejN4OV5K/ojaaEfvuiPz5P6pkOcvxMmx/n1nvgi3rSVbA61CSZjO/5Wcf3Bm5xPuZL8jJtkr7YUlzgF7RXz5sqhztBn+LpjutZqOHlrem/Et/PcHswWVtRIOK0/hft+yLExISBL586tA3m3edSGKdEpd9dsjdyw8CZLtwePIyuadNLbeaA9W2kzPKBdwkhzRUi8t22GjUEGuhL4RoL/pHNwTXn1jlNWCYPzJh/Y3Fln54G6WAYyiWfm0yCNam/D+d/0eaSiD3MaxIK5gNTHU9v9JuUQMy5nut6XF0xqRgVxqYc4iMXWENgGT5fgN+VxiLKjWuEon+IuWbavuY78RgVrluKcYPtHapLhsoXCZJE+81X8o/x/FHP4BBI/qqGJJFQFDzvKGjEEqo29QUP0vrN6g+T9yFPWefqc7zYK9kvTDPfdHsSa2aRkhunLG18UrzFpm+NiBJhUrextNJyf6guRjzV2r65OpZZnGLdiu+znBv9/aUvfqyqAPbhzhRHUcF5Zsou/xhgYwNguOk9uzC+YitG+YmI0bO2dF8uiTBIpbpETCd9K9IKFP4YCuO3sZs+g5KWhBuZusvsFHOVCjtAC/EJqF6rmaCP2JGNHsAnllKREWK+zT6uW2lOhoRXKtkzET8xWdwGEKyxjru6/UOTNKVShuSV3sNfehYhTNJvmr5ep9iSa1bT3RIqdB6YtKY5xU/9u8pQGbhnNReh7EMwWjWA3kStjG0j3udgEsOdzvBKugPnlXMF1SYk4cHrPujs09+hnFUicYbCLAqMrcCgJhWJCCMPnj2PRyRWLCxIBe5tsJo0aujPPtXXUSRor0q85KkUztkMf587pWtQy/rLVdjPdcS0DwxMCylWQqV3xs6c9/lSZsHPJWUCJNQWL13g+5WO8cuWVFFwllfDM3I2PjxJ3rBO3Tvx80dOhq1RuIEud5wNPpMH X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1a4eed0e-1d4c-41b8-2497-08db06d2e928 X-MS-Exchange-CrossTenant-AuthSource: CY5PR12MB6179.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2023 17:11:52.8772 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 6PFia00cxrq3wRHRQYvoRSOU2iDdwN6enMpgicnXNNeiuEqbteJxpnDz3ERXxGY22SwsA0JR1uPij6CjaK5sQA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7997 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The purpose of the sequence generation counter in the netlink callback is to identify if a multipart dump is consistent or not by calling nl_dump_check_consistent() whenever a message is generated. The function is not invoked by the MDB code, rendering the sequence generation counter assignment pointless. Remove it. Note that even the function was invoked, we still could not accurately determine if the dump is consistent or not, as there is no sequence generation counter for MDB entries, unlike nexthop objects, for example. Signed-off-by: Ido Schimmel --- net/bridge/br_mdb.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/net/bridge/br_mdb.c b/net/bridge/br_mdb.c index fc98c32e5894..e40a4c275d63 100644 --- a/net/bridge/br_mdb.c +++ b/net/bridge/br_mdb.c @@ -421,8 +421,6 @@ static int br_mdb_dump(struct sk_buff *skb, struct netlink_callback *cb) rcu_read_lock(); - cb->seq = net->dev_base_seq; - for_each_netdev_rcu(net, dev) { if (netif_is_bridge_master(dev)) { struct net_bridge *br = netdev_priv(dev); From patchwork Sat Feb 4 17:07:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 13128824 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CEC4EC636CC for ; Sat, 4 Feb 2023 17:12:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232228AbjBDRMG (ORCPT ); Sat, 4 Feb 2023 12:12:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231987AbjBDRMF (ORCPT ); Sat, 4 Feb 2023 12:12:05 -0500 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2075.outbound.protection.outlook.com [40.107.95.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBBC432E7A for ; Sat, 4 Feb 2023 09:12:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bpsipdVGqHf+XXz9cHRr5vIfdkPPhjQOVeuUWqSaGOzSIWFWBBpjzT9HijPdDbDX0uE8a54m88lZ+eNrfAgo75sY9F9OGHdPyMlTXRj0U8s22Z18Ax0LlSPL7kThDdWRiihHaLfKfxAvgvxGMYkr0icBobUtTRzRwcC+7gS7TGoJ6dd+XJDp8amDxidW7BWoExeThFXZJGzkWB2puGE+6gOSUvfujARn49BKZ9pE+oipOczopB1wtbGVM4HG5Sr209+fhk7iCBEa6K5q19NPmRDPBE7e73Vci+brBJoOZxCWqIXm8fT5t63xrshYEzLK5tEI4ip2JIjNXVY8r5aBiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Pm2ovCickvnFXCstWja+Dw+7KeSdnFnGAV1e0dRnnTk=; b=jIsFPLiOUUhbL4ESKrMbY0tq20VDzr/+DR5v9uloKkihD6I2ivZ5u2+WHkHgPWt/UTthlRzNdLsvIDNMH02Wqk8BJZQ9ETu3YahJMKPTj7kqlgF7eMIMeaeIGUMgbRGomrQbmf45Byc2LW+pZfZrLPqELCQ3W4q2ic28RoBs4tuUprln8zgK15cv89Kg1ZzAGPZT6Imy0ziz3oxdMBhvN1IH4T7asF1vmmQDrrhQN4RaLUL+HaS+441ZnWUgwqoq0qIBcMkMavSL27/1hZLlfYfl6k7J8ctVwrkiPdVFiaCgH8l5/ORopcVvs+wVA9ibaktbG1wl3Kxqts4kOuL51A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Pm2ovCickvnFXCstWja+Dw+7KeSdnFnGAV1e0dRnnTk=; b=POhQMAWiOh6k1lQLLYeFgL0CAMcU6BCIPZpAHdJDEj2qym2CC+3CRyl5r83IKnX0OE5PSBTM2eXqYBKcLY0LPJEtEavR3N/A35FEBmhq4wkdGq444AqvKoV0TCAYVGra88DCyy30k6jDh58VLl2WKTM+QhmAc9MSAP2VuJ+nbKQL/iDusCrUol+VY327Ed/dNjqoQ+x2JY2IUQR09/NDJPnTzdmyameXMUnxWFM5sWI+9tMD2J1123cd1/300/M2pDOOM/Lenx8n/ns/hJtbH79B/yOpHq6ZZwksH9O5DDAnYo0RfFFZc6qpJfK4a4BfibRedMGM98ZcXe4f4dg42g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) by SA3PR12MB7997.namprd12.prod.outlook.com (2603:10b6:806:307::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.31; Sat, 4 Feb 2023 17:12:00 +0000 Received: from CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab]) by CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab%9]) with mapi id 15.20.6064.025; Sat, 4 Feb 2023 17:12:00 +0000 From: Ido Schimmel To: netdev@vger.kernel.org, bridge@lists.linux-foundation.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, razor@blackwall.org, roopa@nvidia.com, petrm@nvidia.com, mlxsw@nvidia.com, Ido Schimmel Subject: [RFC PATCH net-next 03/13] bridge: mcast: Move validation to a policy Date: Sat, 4 Feb 2023 19:07:51 +0200 Message-Id: <20230204170801.3897900-4-idosch@nvidia.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230204170801.3897900-1-idosch@nvidia.com> References: <20230204170801.3897900-1-idosch@nvidia.com> X-ClientProxiedBy: VI1P190CA0040.EURP190.PROD.OUTLOOK.COM (2603:10a6:800:1bb::17) To CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR12MB6179:EE_|SA3PR12MB7997:EE_ X-MS-Office365-Filtering-Correlation-Id: 80b9188f-7d72-44a4-9c04-08db06d2ed61 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aT2Sl1tXJuOarMRCl3X+RFKBo72ur8gM6t7E97IjbqcGxFsrmwHO9aAf/7CzPJUSSIZMpepxiEzVOUZnIgDqEIEWksYeK9hdge0gb2jiXu7S2U4QZk+lr0GC7m3jDEGNyF0CZnkEgUsg2dU49iDGByY2591WCTyWpSUxt9IgBJ62QJOPIC8TtUzL0cWTuqGQRlYUZCmRbMOwpMaDUzkE5YlS43+zBm0+MkoHwKHQGeMFwvkYXuzSxB/i+uYrt3IQKEyonz4JNYVNQ0tTJjF8Z00iaXbygKSdG/EdsuPJFxpMZOfvAILr2nDFYwS/rIz7wCCVdcuhuvi7tXrmXANmWkN82iLecY7BgH4+yKM4A1grp20qik8qAPxprjrdYOg8G1chcnMPYA8Aq40Q5oWwW9yUs439Je4icbetK71oxJx360C5711Frah1ePxXlI+AUdMQ+lD/+UmqAOjh7fD2ArSisIqVB8COcA9soe4eqJRbzj4A9Cw8XhYsxD2AhxvpLA4p6Fe56pLf0ucdhwy3orJ8M1Us9Ea3mI8UotnrheZDRayWwM2s8PZaZK4UiJ4rMI1QuorJihyRiuXTE1oq3F4TDjrkIacDX+cMsaXPPLZldWC5vL+M+kN9i3nP0vazdukYVyKSOQgVNPeQGCzoKg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY5PR12MB6179.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(39860400002)(136003)(366004)(346002)(396003)(376002)(451199018)(8676002)(41300700001)(66556008)(316002)(66946007)(36756003)(66476007)(6486002)(1076003)(26005)(186003)(478600001)(6506007)(6512007)(4326008)(6666004)(107886003)(38100700002)(2906002)(86362001)(8936002)(5660300002)(83380400001)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: KIfn6ywYNXohTO5HCdburuukCcij+ixf+wI1Xq4DyQCMvKZBMvNE/SfnKMbpYsetTspkqkaEFaZMyVSIcIA2ApynvSudAT+A+DIlabeEZM1NFom3s6LGy5wZl98SWxT/ktlq0O6R4GrQWdUGYcqms97WbnAEyssAPMnj9KOMnfYgXx7pFzAQREeFzU82fOor5eaqyY8OqEsX/vUYooX5pPCOe/Gb0O4wO7cppoDwTp5ox2ri8mbwOcjomSRjUPRg50coeX6MXN4YSOFGTbcwgkPpYkMnpY3VJD0Hzh1Z22lxqE6xiooWkHwLnWu7roHrsqGodTg4NH68X4a2veRbaZlAUq2OYSTU+jJMtke9jXkFCv1v+EUtXAZ4WoRrtyzLqyMTRUHfYe4uNqv2eLrmJYdyGGveck202yDfndxWjdGQSecjDb1OMz5asd5l7lqW/rJdbyHqbbyJPKXWHXhjyycx5Scqx2pv5EYS404NavCJ7FNlJ4V0Y1iZ7yyGXtjw+EO69Pruw7peX/M6/xSpTKO7fHot1W131EPWEnyZ81Ho4G7X1PWPPABTc/m8LOMy3ar3a3acpkDVF5SGlRTFvsHOZ6VVg5XCQJ744GOKxReFas0oJOQvOJsGipH2XhyBYyQQOrtSZAQsBSPpdAZ6AbmHO9BbdpwH96hfwan57/NYRpxjRpYgR8c712jmmivY/6sUexOXpuYicJHcSwB0uN31xuvqgVavzQTuhZRw3gSnbNmjsC2kV0u25gOJVZZhvLg78y1RJbyV9wBOTkKLhXAipQx5GwZRBi0TTcR5F26thTSn3ZhjS9Z3dVy4Mz4B9DiALfFUa6WTg99fcdXDs1SMq7BAyomkui9Ig8OODqnKeGIqogX4ho/dspA2T2xN3FSm5Ta206jpHma0VKL+BY2NyhInfvhit6RgJJiRUhE6BAk/SxzxS89DVxgG9R3M63eB/uIX3ONaE4O5skHaPGf5rLN9HRfe2NRN4FHxRKnhfVVKLQSqaRE6hhqURH27VlazzQwmgeEkRac4vjyq2uGPnTxiOC2AIq1vRSlFgoMmTLZq0rkvbsGdW5IuamRT/8Rh2zqIO0pJXro1k8AGL8do9RGZLMXwBE3XoQ0kYVqvjW60JQLmJqdWIUQZKHmjL/kLpUi3ON/5yqWbkAIyf3JkB3XDFjHfXHI4/s2VZP+5FX7o5P8LX3GY5sUyoM8K8fXVFwyIXt3XXUCbF5Rs/Pz/EfmG0McnflYxeiF5rAkMizDUYbkxoKy9hlGQHHXieuVz+9RvUPiVdthjb//FbZp9FdZlxnBZ7yxkQGAp+E8jzB+9NECOpZWUPDxvkRf8QUOhzMmhKu5ReG4M/ophOWm+rtrJwiNZnZVc61Ni3DqGqnXU4VuHJWo5s3qkdUOiEBOlflA0qqoodwnuLFVYQG1L4SjiViFZAqPb07zLak0+vmpaT3dWZ/1mezUtNTV3PSNEZE080GqGA6my8W6Uv+Wkdh9R90a5ypbGrMpsRYDcIaHCrTMftunfmn/cfgQsuhI9nrPjkkXZEgMN/tDo2s9U8ZeWKqpfVF1Pdt7O8VM0AufiVEgEz1IzIU4K8Dqh X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 80b9188f-7d72-44a4-9c04-08db06d2ed61 X-MS-Exchange-CrossTenant-AuthSource: CY5PR12MB6179.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2023 17:12:00.0583 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: kddfsY2oBNob0dOVx47s1CVsY88rgu2Pw/PAwLp6JaNUC+a4UlBAUaRqrTAA/jw5SWjt2NUkXRxKg5PBLiapXg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7997 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Subsequent patches are going to move parts of the bridge MDB code to the common rtnetlink code in preparation for VXLAN MDB support. To facilitate code sharing between both drivers, move the validation of the top level attributes in RTM_{NEW,DEL}MDB messages to a policy that will eventually be moved to the rtnetlink code. Use 'NLA_NESTED' for 'MDBA_SET_ENTRY_ATTRS' instead of NLA_POLICY_NESTED() as this attribute is going to be validated using different policies in the underlying drivers. Signed-off-by: Ido Schimmel --- net/bridge/br_mdb.c | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/net/bridge/br_mdb.c b/net/bridge/br_mdb.c index e40a4c275d63..b1ece209cfca 100644 --- a/net/bridge/br_mdb.c +++ b/net/bridge/br_mdb.c @@ -683,51 +683,58 @@ static const struct nla_policy br_mdbe_attrs_pol[MDBE_ATTR_MAX + 1] = { [MDBE_ATTR_RTPROT] = NLA_POLICY_MIN(NLA_U8, RTPROT_STATIC), }; -static bool is_valid_mdb_entry(struct br_mdb_entry *entry, - struct netlink_ext_ack *extack) +static int validate_mdb_entry(const struct nlattr *attr, + struct netlink_ext_ack *extack) { + struct br_mdb_entry *entry = nla_data(attr); + + if (nla_len(attr) != sizeof(struct br_mdb_entry)) { + NL_SET_ERR_MSG_MOD(extack, "Invalid MDBA_SET_ENTRY attribute length"); + return -EINVAL; + } + if (entry->ifindex == 0) { NL_SET_ERR_MSG_MOD(extack, "Zero entry ifindex is not allowed"); - return false; + return -EINVAL; } if (entry->addr.proto == htons(ETH_P_IP)) { if (!ipv4_is_multicast(entry->addr.u.ip4)) { NL_SET_ERR_MSG_MOD(extack, "IPv4 entry group address is not multicast"); - return false; + return -EINVAL; } if (ipv4_is_local_multicast(entry->addr.u.ip4)) { NL_SET_ERR_MSG_MOD(extack, "IPv4 entry group address is local multicast"); - return false; + return -EINVAL; } #if IS_ENABLED(CONFIG_IPV6) } else if (entry->addr.proto == htons(ETH_P_IPV6)) { if (ipv6_addr_is_ll_all_nodes(&entry->addr.u.ip6)) { NL_SET_ERR_MSG_MOD(extack, "IPv6 entry group address is link-local all nodes"); - return false; + return -EINVAL; } #endif } else if (entry->addr.proto == 0) { /* L2 mdb */ if (!is_multicast_ether_addr(entry->addr.u.mac_addr)) { NL_SET_ERR_MSG_MOD(extack, "L2 entry group is not multicast"); - return false; + return -EINVAL; } } else { NL_SET_ERR_MSG_MOD(extack, "Unknown entry protocol"); - return false; + return -EINVAL; } if (entry->state != MDB_PERMANENT && entry->state != MDB_TEMPORARY) { NL_SET_ERR_MSG_MOD(extack, "Unknown entry state"); - return false; + return -EINVAL; } if (entry->vid >= VLAN_VID_MASK) { NL_SET_ERR_MSG_MOD(extack, "Invalid entry VLAN id"); - return false; + return -EINVAL; } - return true; + return 0; } static bool is_valid_mdb_source(struct nlattr *attr, __be16 proto, @@ -1295,6 +1302,14 @@ static int br_mdb_config_attrs_init(struct nlattr *set_attrs, return 0; } +static const struct nla_policy mdba_policy[MDBA_SET_ENTRY_MAX + 1] = { + [MDBA_SET_ENTRY_UNSPEC] = { .strict_start_type = MDBA_SET_ENTRY_ATTRS + 1 }, + [MDBA_SET_ENTRY] = NLA_POLICY_VALIDATE_FN(NLA_BINARY, + validate_mdb_entry, + sizeof(struct br_mdb_entry)), + [MDBA_SET_ENTRY_ATTRS] = { .type = NLA_NESTED }, +}; + static int br_mdb_config_init(struct net *net, const struct nlmsghdr *nlh, struct br_mdb_config *cfg, struct netlink_ext_ack *extack) @@ -1305,7 +1320,7 @@ static int br_mdb_config_init(struct net *net, const struct nlmsghdr *nlh, int err; err = nlmsg_parse_deprecated(nlh, sizeof(*bpm), tb, - MDBA_SET_ENTRY_MAX, NULL, extack); + MDBA_SET_ENTRY_MAX, mdba_policy, extack); if (err) return err; @@ -1347,14 +1362,8 @@ static int br_mdb_config_init(struct net *net, const struct nlmsghdr *nlh, NL_SET_ERR_MSG_MOD(extack, "Missing MDBA_SET_ENTRY attribute"); return -EINVAL; } - if (nla_len(tb[MDBA_SET_ENTRY]) != sizeof(struct br_mdb_entry)) { - NL_SET_ERR_MSG_MOD(extack, "Invalid MDBA_SET_ENTRY attribute length"); - return -EINVAL; - } cfg->entry = nla_data(tb[MDBA_SET_ENTRY]); - if (!is_valid_mdb_entry(cfg->entry, extack)) - return -EINVAL; if (cfg->entry->ifindex != cfg->br->dev->ifindex) { struct net_device *pdev; From patchwork Sat Feb 4 17:07:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 13128825 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 655BEC61DA4 for ; Sat, 4 Feb 2023 17:12:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232422AbjBDRMX (ORCPT ); Sat, 4 Feb 2023 12:12:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232529AbjBDRMS (ORCPT ); Sat, 4 Feb 2023 12:12:18 -0500 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D1F333468 for ; Sat, 4 Feb 2023 09:12:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YRHvLfDUFLXEw9DevUgSaUkxhfirRi+d74LrW3cosHPcikYYG4zvwc/iRImf1RfVwkkiIk8B9ffd22kVD7m+L5SDsAjRd47iks563K8B0MKn3YqKHI3aASeVgCw3QTPFGV0My4wbocoXmbvXeez8qfUB8YBhgU3JW124T++hek/KLtjqOsQDY5HPBmuWXtHlr+SoOL5WUgfYHxHwQUACD138L1XbPY7NQ7D7xLg619MgBA3KXGf4GQA5tT9sJUz+RXwwwNpi2liMdNQy3crQHSKznk4HfSFht6zUPF5aT6iLeq4dnSeZm88EsyC0/Neps3K3wR7h43Xq+reB9JzGaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2sxMKfQrl1R9hAAzNNuoFio8mVq87qKkUi/x5UAzYHM=; b=UB9iPFGH/adQd5epxsjEBGbYGRfi3OEdGLuUN0GjMFDJwl5q+N8dIZD9ePsInJ86GI68puccfITjb6quyN1PGTJ9LONqKUGFc4nGXJBQVy8UYclWx1JwTNzcwEs3mHcLotJiWsU7Z6IFLd76PgcoXCO87zfnlExMzAWMdLkgh/XyBDKhhUvnwoOpACXwMNkl6vgukl/z3eO3+heuO7CMs/bioEKSFt+xhU9a4VaA4lBZZK9IjcSyN2ca0RjPTlBDmjpMSrmZvtgyMsQz9MxP6T/7worA3jRlA5a9a5FW4ZZkZY63+l20AvN/pD7BW3tz1M7YxYFD/XnCOV3hvUwKjg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2sxMKfQrl1R9hAAzNNuoFio8mVq87qKkUi/x5UAzYHM=; b=p+eCo8sOukCA+p9AlgxKamZzW4IsZDYMqhX5vX9al7f1HmMAOAC0KB12TLdqBJaL/U0nXWn2/O8oKi2YxLfBfATjgcNEEdYXVOEaz3l9IWwnd1cUhP2Sz8ZxRTcONGnZRB+ObHo4H8HMyHem3aQ8YdExVxYydXR3Lfv0efm4cXzcdW4uSAw+Dw3+EeWDChc9paS4/TvMrL2i63TOJ5oYkNheYf8gG2PEjzIJUOYQJhkTtITepWhKM0vZEd4moorBKbLWHN5NLY/a0JsxNkd4++Q0/hX5GkBrTVuwX+R/E0j7vceB+p5mMEDLZ0YwvNk3dscJ5I/bDFCW2VIeihPryg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) by SA3PR12MB7997.namprd12.prod.outlook.com (2603:10b6:806:307::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.31; Sat, 4 Feb 2023 17:12:06 +0000 Received: from CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab]) by CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab%9]) with mapi id 15.20.6064.025; Sat, 4 Feb 2023 17:12:06 +0000 From: Ido Schimmel To: netdev@vger.kernel.org, bridge@lists.linux-foundation.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, razor@blackwall.org, roopa@nvidia.com, petrm@nvidia.com, mlxsw@nvidia.com, Ido Schimmel Subject: [RFC PATCH net-next 04/13] net: Add MDB net device operations Date: Sat, 4 Feb 2023 19:07:52 +0200 Message-Id: <20230204170801.3897900-5-idosch@nvidia.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230204170801.3897900-1-idosch@nvidia.com> References: <20230204170801.3897900-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR07CA0174.eurprd07.prod.outlook.com (2603:10a6:802:3e::22) To CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR12MB6179:EE_|SA3PR12MB7997:EE_ X-MS-Office365-Filtering-Correlation-Id: 54d9f6b5-fcef-4240-bad8-08db06d2f173 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: i6fayuULSwXqaPTI9omB7NMKohKJDHYQLqv7addQ4NyKTXQ2bjvs3Edokdpe7ysDNdreX3SvOeWCozuSEcLJTomA9nM47cPLJ8suNflCuTr3KyuFB+0jRAILUTD0YbEBEQoFnGMGsUkI3dXO60pv2oMXTAAMdzncHjpp8QuqDczoH6Wuop2XkKAj4UvZySYwQKP592Lpq6s59/Mlg7brlQymo5qtWMsFVg0DatsO0E0OHRlVN4n6cd/aE+QawLEghPo/KPpCeNLGvN/qVHakYfSaA3464+YKBfFVkKtDN6IG7f8zxgjntzZwT24/IwK/t9B+49xBNfBBmTPUqwclZ6hXkVTAk6coKrqh5i086TDDFTuMNUFn5c1EoDKkFNWrElUPn1MQnIkBAiFGqv23znwK4R1ej1iRCUVSxLAVxY8V1VnJz5l77/wWI7+4kvY4gXA/7spiaQfQsPSiRJALQtaziGzbp3pC5Tuq5Tewux/cwhgxNhmm+cPfRsknVPVndoXrlfDJ9rVqwuX26uAjxLC4e7jahh+KMfR3tYezSyF/saeZXsaaToZzSROfjsUyKbdQOpF31STilsc317MZnKkxC4m9GhS8MBylFKILL98SjCFKBaN2+Mpy/zXIKvNgRobPXjbxpdu9idC3sZ8CTg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY5PR12MB6179.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(39860400002)(136003)(366004)(346002)(396003)(376002)(451199018)(8676002)(41300700001)(66556008)(316002)(66946007)(36756003)(66476007)(6486002)(1076003)(26005)(186003)(478600001)(6506007)(6512007)(4326008)(6666004)(107886003)(38100700002)(2906002)(86362001)(8936002)(5660300002)(83380400001)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QcV/uHW0d7Mi8weGgvA1PlK/k69QqXfHCzz28d8W1ZaUCKRjS4RfbqG9G3mgLN6dJH8uJTGGQfBitZeZoQ/vhyNPF12PKWLjsy4AKTgDiKI3qn6yNF1hjr8Qq40GO3EjdyRGYwVy4MmFaXxvuEY4KRyrk0ZsBgxiX5Xunm7vfUuBVNeyCrnwX4riSF9E+Wsp21J2JqZIfe5a0PdgY0UgE/YUnz1fVIeMFplr/UrCosSewsNNfrXBZRoW9JsEfuw8Rc1FTBDfLk4EwBR2FYNVB6iD2L6AOjwovRfuX+uWSjnEJW3+AvKI3WUzXI8QuPvBGA/bsMt/G5eXOqY82q5x6r54NFKO0RYwT3SUMr6N0QhJlZXqhW0QxUucFl78wjHvvun3pUtJ5GpZHsP00+crbSN/Ka9rNuDodMQOcftON9uV5m+rTW15UynndCBy3curSSHa6esIOXbmXaowui4itpEiOejYL//n+PUT8pmVkwaQjiaTVzRqiba8BlxRCbum2XlIPJLIJNLlLiXCnbdI7QuOPGkgSIcwJwSoLlzUqYDBmSAjVOovi01lL425RxHO0Z2rHZ17hrzjlH4Mi4tJBtH5PcV1vCLslCkAL7brriMuSPTNVc0KrxoC1lfssR5mWB8yrBhjaLTAyA4rCD+lvur0U44ah/pjJhBbANgkG3Yfo/gbBTpKQNB16WvJOsecpCTU46PnBfSNbgMk6PWQ9fKLnJUMAPKUgHJJpC9jii/7XXh6R79nElSAaLBHjf7KL6YGY6ke6qVhXHFrTFDoZozgVSeqh9hNf/wd2fs9onHyXN5dnpQ4JDtORLdVO9O8teJceH7x/zWTeec8nKIctRnB3inFar8EyWwgtMfS4Y5i4BY3oWMfJPLaoORBgQedk8C8mwAxDtHouRbl28J1KDcgnhijRaD7nsiq/ykx/M+2K93TRn9N8+HzFqGhGmWFpb1FMchBgtpRW21icy/HpDCtdQatMF2EdHWTrCDlb7vtavOLDiOQdfI52Ch9pfDSLI2VZzzvcsuwu+1z+i1kvfzkBtmsuMPxSmSUX7XhKjhQ7jhxP8OAxyglcQQebn/HMLq7NV4Ni76JcQyjEeqdpND2LgXNSWI/BPcFQLL2gc6oT671fX/vi70Ytbzs9Wqb5TAYxEc6CLYikSw01zKTH4k67wvFkD8Vt2khbnTHVVGkjfSRkUuT963u1/Tq+50v3p+PfeJpyZE9MwtmMzkI+vzM5zuSF7F4lQeTGuJnt/4H1j8NHSWEEsoR2uM4/E89pjgSGvAynPjuon7vMUQMnT+WLtE9onuS+KMkE+lLNC2bWnqc6Ri8rzjfCZ28JabkUCqTl2gboBjX2bkoZk2V+GsJldhfnl5eCcKsOefZPFgipCkDJoqxVJa3sFaKeANDCpozOIpqQuikrf8/4YCHdRCsKGMiUT76CVYadki7huZXzEe4mvxQGbUlwfSWzNdpcvEbj0EzwpPua4HpKwTM8LR57uzDQf93UaYDYqYOB74+1unBjZNg0zj3mb+6W1m1MyYnuaSstInUl/+OC1ybzsHWCsvGylbi0IH69KLNtgBpYlhyrPFwwz90a0Kt7My5 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 54d9f6b5-fcef-4240-bad8-08db06d2f173 X-MS-Exchange-CrossTenant-AuthSource: CY5PR12MB6179.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2023 17:12:06.7955 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: AQdIUmiV2d6w4SodHRhxPz8a6htsruh8g7trLOm9S1qwl9lt+kW3jzhAqm89uY3VN7/f8c5PB8hNDNpa5EH06g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7997 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add MDB net device operations that will be invoked by rtnetlink code in response to received RTM_{NEW,DEL,GET}MDB messages. Subsequent patches will implement these operations in the bridge and VXLAN drivers. Signed-off-by: Ido Schimmel --- include/linux/netdevice.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index d5ef4c1fedd2..47e33c6d314e 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -1305,6 +1305,17 @@ struct netdev_net_notifier { * Used to add FDB entries to dump requests. Implementers should add * entries to skb and update idx with the number of entries. * + * int (*ndo_mdb_add)(struct net_device *dev, struct nlattr *tb[], + * u16 nlmsg_flags, struct netlink_ext_ack *extack); + * Adds an MDB entry to dev. + * int (*ndo_mdb_del)(struct net_device *dev, struct nlattr *tb[], + * struct netlink_ext_ack *extack); + * Deletes the MDB entry from dev. + * int (*ndo_mdb_dump)(struct net_device *dev, struct sk_buff *skb, + * struct netlink_callback *cb); + * Dumps MDB entries from dev. The first argument (marker) in the netlink + * callback is used by core rtnetlink code. + * * int (*ndo_bridge_setlink)(struct net_device *dev, struct nlmsghdr *nlh, * u16 flags, struct netlink_ext_ack *extack) * int (*ndo_bridge_getlink)(struct sk_buff *skb, u32 pid, u32 seq, @@ -1567,6 +1578,16 @@ struct net_device_ops { const unsigned char *addr, u16 vid, u32 portid, u32 seq, struct netlink_ext_ack *extack); + int (*ndo_mdb_add)(struct net_device *dev, + struct nlattr *tb[], + u16 nlmsg_flags, + struct netlink_ext_ack *extack); + int (*ndo_mdb_del)(struct net_device *dev, + struct nlattr *tb[], + struct netlink_ext_ack *extack); + int (*ndo_mdb_dump)(struct net_device *dev, + struct sk_buff *skb, + struct netlink_callback *cb); int (*ndo_bridge_setlink)(struct net_device *dev, struct nlmsghdr *nlh, u16 flags, From patchwork Sat Feb 4 17:07:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 13128826 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C69CC636CC for ; Sat, 4 Feb 2023 17:12:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232489AbjBDRMb (ORCPT ); Sat, 4 Feb 2023 12:12:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232470AbjBDRM1 (ORCPT ); Sat, 4 Feb 2023 12:12:27 -0500 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 415EF3250E for ; Sat, 4 Feb 2023 09:12:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IoRwRQBFzjvBnBGQ1nlg/wOxukhldX0R4wKhMgnM5QCPzi7CtkOxnTsaeoSZdi2apWdzmal/+2vvThe7EUAty5UWv7wiLBKgJLTCwkabKyTAjm6xmnb7emSxjRdnmWvZXM6HPeVjRfcEPbC2VGeqt3MPtCB5XxAbS/6eLN+w8tha8Bp221y0V7049RP7GYlraEuGo9KylC9XgOMMp6i1bffZRtJHrEuXVkH+Ru8Js8r/BdTvauwCMqOBk6mzsFXuAE/wox916uJHoDTus/O9me53O+g4dbAgVGQWBpCkKL+WxrPTavO5sX1Av+trMe78EDWLMuXfZtoyDWfR9HZrOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dITE0nCpbZDklb5l3vSuD6whwHROlN3eE9YbIk7Rfps=; b=LXIk7y5HBHEBJkTa5lpxHP7tIt+sWFJv6mKZLVvUT67VftnJ/xmZPKMnNx26BSi5eDDRc6ySKfi0gq3EAtsyLmkSfDMfP7upLr4vdkkNjTco4O8WQgLqExwJEaTTdVoaUQsMf3+ruux5nA1GivYSGlr3MCmSv86jPGc0liexGk42E7pSFxzupNdihgobUS7Rif6bjjabi3FGz/EYLZQsj5j6+t4KWVL7peqn6n9U22HOPMT4P8aI+fHg0RvYYIG9pt81S+y82TPcOzR6kIC8Uxa8k4+wq1FDX81LcDnl3F92zabDT32X0j+qj5PymYeJ499d9vri1to98sPDPvy4BQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dITE0nCpbZDklb5l3vSuD6whwHROlN3eE9YbIk7Rfps=; b=HFAszDSJjFh57KxogK1F4MfAvUkXjHQYkpkJ/uNZeap7WDDRWo618WzHdsqLk/sJyzj8p9iR0cAv470ijqk4QTk5exeZlabQK5sZBlnLGupDQBMLZhbzNC4RpJ2SPjSVcFzauFY8lYTWEox+YuHQn2425jfIk4Qawuxmyo4ABdB8+TylW13Yz41rMqmzM+3L/Plf91w0rwdclCyavIqMAKkEa6+IF2zVBhdJJorvM6dCrGTgP4Zu3w8eZBvCjmwzNvpxQcCqxZDS82stO5zRUzZujfVwOEYrZAQKqxcwlIVm3c/kOoto3P2RHBv3aJFPP61vDrfHXXOEPQQ+GAMDwg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) by SA3PR12MB7997.namprd12.prod.outlook.com (2603:10b6:806:307::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.31; Sat, 4 Feb 2023 17:12:13 +0000 Received: from CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab]) by CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab%9]) with mapi id 15.20.6064.025; Sat, 4 Feb 2023 17:12:13 +0000 From: Ido Schimmel To: netdev@vger.kernel.org, bridge@lists.linux-foundation.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, razor@blackwall.org, roopa@nvidia.com, petrm@nvidia.com, mlxsw@nvidia.com, Ido Schimmel Subject: [RFC PATCH net-next 05/13] bridge: mcast: Implement MDB net device operations Date: Sat, 4 Feb 2023 19:07:53 +0200 Message-Id: <20230204170801.3897900-6-idosch@nvidia.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230204170801.3897900-1-idosch@nvidia.com> References: <20230204170801.3897900-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR04CA0092.eurprd04.prod.outlook.com (2603:10a6:803:64::27) To CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR12MB6179:EE_|SA3PR12MB7997:EE_ X-MS-Office365-Filtering-Correlation-Id: 5afa9290-3dad-49a8-ae81-08db06d2f56b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LkZbW8OrT6gHe9BO2HDtzfKziU4HZ6Ug1Il8E3/ObZaDMe736aQmp9lzGG17QJipXl8VyNiBC1P2Mv0ANpWbfTjz741L76QMyZheViDjjXLguc+H67TGk3YeIgdKGbYmTVsClv/1w2bDZM1AMdTX/LgDAML0sfquXPMtnt3MZn1SjpkPNGsHDvXXXJffP2k412ITOHfxy+tPR+TfZq5iqF8vi6Ulo5wr2qF6Mk/qJsORToW8gSvH7gB15wT/UrHouSQfAxJGumv4GNsHriunFvh1sG93pSaKd/eEBPtUJHsI6SoM2IHcsUNw3e1qhxalDRTCC8BQ0lBr1YtTVMwi0fIVBBpcsH+kzPgnTq5gjmT9gD/D6zyJ92piDZ2ue9mUa7Cb28D/VkbVS+WfZn852JFudOT6WrM5lQSBIFJDmeY6cGz38LY7RzQcM/+Gd2G5ERmteHdjYuSjsDxkYparhDalbWsI59YH47UzfIWvODPNeO3hIpLhvxPjeIk0uT3HDwOr5RbLNF48WunIe/k+NQR67WEbZVJpiYO994rSsmVWblEpxTqN56h1medDi3qzBii+57ZcnmPaozUF5Bi+NP/M6NzyiKoW78tumYVtKtmPXVJPzbkpJjMyc1NzRVFXwBOjQt9bSE4RW2sV/jKKaA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY5PR12MB6179.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(39860400002)(136003)(366004)(346002)(396003)(376002)(451199018)(8676002)(41300700001)(66556008)(316002)(66946007)(36756003)(66476007)(6486002)(1076003)(26005)(186003)(478600001)(6506007)(6512007)(4326008)(6666004)(107886003)(38100700002)(2906002)(86362001)(8936002)(5660300002)(83380400001)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WI9qMUwqXsYPMr24AeUjmdqBDG+JVdVAGquXSu+tv4kp/QplwwUWt/NA/FzCrwvUDC+wuzI7PkATa2rlnSMT787Cw2AeFmz6dfOKNEkNTz/O6MUedYlYMWbUlhVVzmgDQ3nGbNJuQxhYjNruGQnKmScKKL9oiqYzj41rPgh8yvLh8kDjGckVV5MH44KNNQ9nKpSC9Kj6WXXHAhkOOus8adfgtS1kYRDwDJM1/xIS9JUSLOqJBFqp1E7XhmzhO3TYhGqgbBlzQyxRuN2/uUuoRkRl6vr8s12+nyxokNzOtxyrs+wUGnPEuGlQZH4YwsgRCKxScSGtvuByzaG2AfOBL49Is2XY5rmQtbUUwVVTdEGi0O6t7G+HECfva+knXL6spNdYu5DV6qRjTXQBBvgotIxKnGAoYBuh4Nm6Fxtypajydbdyfwushoq8CQIiqmLxl4jxR0e+Fpsk89HjmkR7o9xjPgmddlAs1mQjdJfZlhCBHLk9fh9vs2zjMQQb7gXpty0foUDo/fADtcPajTbL1dqByNHVQALeLqBEJz5Qj/DQqbEPJ3NexfUBNf7noDjGuHUEPsDYw3sJbNc59KHNhdLKM10jq82L6LgKsq6GG6ImKfZ0gN71fhaROsPAHv9oDqZy1GmE5e5AKc8JsrS9LhsF+aNt1btWxHXh0Fdk0cW0vDWD6xTpaLruoBNs8u61/NrEVIOK+0nT0zqwCU8wcdGz7MmBbz9wLybdKJh2CEi/srMlNMUyw54GItrQWx0xJtNVdZC668/rmmYrIJUztCU/NbRCh469nPIpr98yu/fqEG5ynBEHjpyIYmtMUhehs9N+Vs0Md+kC9QaVzUYn1PGDXmyEUwTtLV/c6sm51jv5dleO2Ns7Ocz9CM0LvGThcYRYQoXa0gJN9JWRoWjHa6tPJsBZlWsSdatiz2+jZHC1OG2u1iBiJNmONkL1qVDSjtVvo7oJUpg2uqqUXZohuIjFOzScwj73F/joLoG5sqM9IBxCGQo7pjTzPcOMD9lcfykJ5n9ajePHh03aRIp0A3lDpfC2RQ6gEuyXOSDLgamngpHkerKYYOjYnc/aSz34HgZGeuVbyhHfGc5sdw7cJ5zQWxSkFjZRkAM+2G+c6+CJyjtV34gzxQYBbb/8cxilCd6wEkYYLK2vXPMQAoU5hxMxgng7hNa6QS0Bic5kl6tuCIYouwYyKXCdwuHxTzouGAOMx3LnTPvoG8W3sHHYu4+x5HuhnmDf3vCKJXSjHcUk+KY4VFCIjuprE7lBGfXAavFPUua8w2yffRre/xPTNhMWM1HqRtz8Wq4B6pIdVcoIF0/jnTgmNGuY1k7YU/aaG55H6Qzoz+dlzm3GimPIeGqV0QHTwhIv7sgX4VB6EJDnw5/SDEbajwXbA1u4btkEOhmcfEJlNA54U1PufH4xfphDakanLp72CEE+vFkJ0em9ELRW3X3Nl+B5EPkz2DvafvMhtFwY5+P9FrDuAdrc42e5VsOfBYMsLlEVi7n9J3v0Qp26xjUef7Vbh/zdVqTCNrePqVEjD/1/+viB+mcV6xM9A+09C0rFiau4gEiXo1ZfwjBzsFDdEm0/1BR7VBOJ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5afa9290-3dad-49a8-ae81-08db06d2f56b X-MS-Exchange-CrossTenant-AuthSource: CY5PR12MB6179.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2023 17:12:13.5148 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: EeFJG2kzAVoCw4UF30kvQI6Mj1G+I1nM5yP1MLfI4M+qph4HN+v/dn1HI4+7cGkvJcnWCZPziQ5u/D8GBz/8Og== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7997 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Implement the previously added MDB net device operations in the bridge driver so that they could be invoked by core rtnetlink code in the next patch. The operations are identical to the existing br_mdb_{dump,add,del} functions. The '_new' suffix will be removed in the next patch. The functions are re-implemented in this patch to make the conversion in the next patch easier to review. Add dummy implementations when 'CONFIG_BRIDGE_IGMP_SNOOPING' is disabled, so that an error will be returned to user space when it is trying to add or delete an MDB entry. This is consistent with existing behavior where the bridge driver does not even register rtnetlink handlers for RTM_{NEW,DEL,GET}MDB messages when this Kconfig option is disabled. Signed-off-by: Ido Schimmel --- net/bridge/br_device.c | 3 + net/bridge/br_mdb.c | 124 ++++++++++++++++++++++++++++++++++++++++ net/bridge/br_private.h | 25 ++++++++ 3 files changed, 152 insertions(+) diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c index b82906fc999a..85fa4d73bb53 100644 --- a/net/bridge/br_device.c +++ b/net/bridge/br_device.c @@ -468,6 +468,9 @@ static const struct net_device_ops br_netdev_ops = { .ndo_fdb_del_bulk = br_fdb_delete_bulk, .ndo_fdb_dump = br_fdb_dump, .ndo_fdb_get = br_fdb_get, + .ndo_mdb_add = br_mdb_add_new, + .ndo_mdb_del = br_mdb_del_new, + .ndo_mdb_dump = br_mdb_dump_new, .ndo_bridge_getlink = br_getlink, .ndo_bridge_setlink = br_setlink, .ndo_bridge_dellink = br_dellink, diff --git a/net/bridge/br_mdb.c b/net/bridge/br_mdb.c index b1ece209cfca..3359ac63c739 100644 --- a/net/bridge/br_mdb.c +++ b/net/bridge/br_mdb.c @@ -458,6 +458,39 @@ static int br_mdb_dump(struct sk_buff *skb, struct netlink_callback *cb) return skb->len; } +int br_mdb_dump_new(struct net_device *dev, struct sk_buff *skb, + struct netlink_callback *cb) +{ + struct net_bridge *br = netdev_priv(dev); + struct br_port_msg *bpm; + struct nlmsghdr *nlh; + int err; + + nlh = nlmsg_put(skb, NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, RTM_GETMDB, sizeof(*bpm), + NLM_F_MULTI); + if (!nlh) + return -EMSGSIZE; + + bpm = nlmsg_data(nlh); + memset(bpm, 0, sizeof(*bpm)); + bpm->ifindex = dev->ifindex; + + rcu_read_lock(); + + err = br_mdb_fill_info(skb, cb, dev); + if (err) + goto out; + err = br_rports_fill_info(skb, &br->multicast_ctx); + if (err) + goto out; + +out: + rcu_read_unlock(); + nlmsg_end(skb, nlh); + return err; +} + static int nlmsg_populate_mdb_fill(struct sk_buff *skb, struct net_device *dev, struct net_bridge_mdb_entry *mp, @@ -1462,6 +1495,65 @@ static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh, return err; } +int br_mdb_add_new(struct net_device *dev, struct nlattr *tb[], u16 nlmsg_flags, + struct netlink_ext_ack *extack) +{ + struct net_bridge_vlan_group *vg; + struct br_mdb_config cfg = {}; + struct net_bridge_vlan *v; + int err; + + /* Configuration structure will be initialized here. */ + + err = -EINVAL; + /* host join errors which can happen before creating the group */ + if (!cfg.p && !br_group_is_l2(&cfg.group)) { + /* don't allow any flags for host-joined IP groups */ + if (cfg.entry->state) { + NL_SET_ERR_MSG_MOD(extack, "Flags are not allowed for host groups"); + goto out; + } + if (!br_multicast_is_star_g(&cfg.group)) { + NL_SET_ERR_MSG_MOD(extack, "Groups with sources cannot be manually host joined"); + goto out; + } + } + + if (br_group_is_l2(&cfg.group) && cfg.entry->state != MDB_PERMANENT) { + NL_SET_ERR_MSG_MOD(extack, "Only permanent L2 entries allowed"); + goto out; + } + + if (cfg.p) { + if (cfg.p->state == BR_STATE_DISABLED && cfg.entry->state != MDB_PERMANENT) { + NL_SET_ERR_MSG_MOD(extack, "Port is in disabled state and entry is not permanent"); + goto out; + } + vg = nbp_vlan_group(cfg.p); + } else { + vg = br_vlan_group(cfg.br); + } + + /* If vlan filtering is enabled and VLAN is not specified + * install mdb entry on all vlans configured on the port. + */ + if (br_vlan_enabled(cfg.br->dev) && vg && cfg.entry->vid == 0) { + list_for_each_entry(v, &vg->vlan_list, vlist) { + cfg.entry->vid = v->vid; + cfg.group.vid = v->vid; + err = __br_mdb_add(&cfg, extack); + if (err) + break; + } + } else { + err = __br_mdb_add(&cfg, extack); + } + +out: + br_mdb_config_fini(&cfg); + return err; +} + static int __br_mdb_del(const struct br_mdb_config *cfg) { struct br_mdb_entry *entry = cfg->entry; @@ -1538,6 +1630,38 @@ static int br_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, return err; } +int br_mdb_del_new(struct net_device *dev, struct nlattr *tb[], + struct netlink_ext_ack *extack) +{ + struct net_bridge_vlan_group *vg; + struct br_mdb_config cfg = {}; + struct net_bridge_vlan *v; + int err = 0; + + /* Configuration structure will be initialized here. */ + + if (cfg.p) + vg = nbp_vlan_group(cfg.p); + else + vg = br_vlan_group(cfg.br); + + /* If vlan filtering is enabled and VLAN is not specified + * delete mdb entry on all vlans configured on the port. + */ + if (br_vlan_enabled(cfg.br->dev) && vg && cfg.entry->vid == 0) { + list_for_each_entry(v, &vg->vlan_list, vlist) { + cfg.entry->vid = v->vid; + cfg.group.vid = v->vid; + err = __br_mdb_del(&cfg); + } + } else { + err = __br_mdb_del(&cfg); + } + + br_mdb_config_fini(&cfg); + return err; +} + void br_mdb_init(void) { rtnl_register_module(THIS_MODULE, PF_BRIDGE, RTM_GETMDB, NULL, br_mdb_dump, 0); diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 15ef7fd508ee..91dba4792469 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -974,6 +974,12 @@ void br_multicast_uninit_stats(struct net_bridge *br); void br_multicast_get_stats(const struct net_bridge *br, const struct net_bridge_port *p, struct br_mcast_stats *dest); +int br_mdb_add_new(struct net_device *dev, struct nlattr *tb[], u16 nlmsg_flags, + struct netlink_ext_ack *extack); +int br_mdb_del_new(struct net_device *dev, struct nlattr *tb[], + struct netlink_ext_ack *extack); +int br_mdb_dump_new(struct net_device *dev, struct sk_buff *skb, + struct netlink_callback *cb); void br_mdb_init(void); void br_mdb_uninit(void); void br_multicast_host_join(const struct net_bridge_mcast *brmctx, @@ -1367,6 +1373,25 @@ static inline bool br_multicast_querier_exists(struct net_bridge_mcast *brmctx, return false; } +static inline int br_mdb_add_new(struct net_device *dev, struct nlattr *tb[], + u16 nlmsg_flags, + struct netlink_ext_ack *extack) +{ + return -EOPNOTSUPP; +} + +static inline int br_mdb_del_new(struct net_device *dev, struct nlattr *tb[], + struct netlink_ext_ack *extack) +{ + return -EOPNOTSUPP; +} + +static inline int br_mdb_dump_new(struct net_device *dev, struct sk_buff *skb, + struct netlink_callback *cb) +{ + return 0; +} + static inline void br_mdb_init(void) { } From patchwork Sat Feb 4 17:07:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 13128827 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 855F3C61DA4 for ; Sat, 4 Feb 2023 17:12:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232519AbjBDRMe (ORCPT ); Sat, 4 Feb 2023 12:12:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232554AbjBDRMa (ORCPT ); Sat, 4 Feb 2023 12:12:30 -0500 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2074.outbound.protection.outlook.com [40.107.244.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EDAC31E15 for ; Sat, 4 Feb 2023 09:12:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MNO2PyhJaDP3BPf230uLCFO/du1d8TZI8knANGTCRp9fBIi1jeoXNr3c5M52O7haDY0NTRA03Jx2hPc4Fn9ajrvBNK2ivcxDmrCAok2w7y5PsCu3TgnsgE+l+XGz0sFY5IFLTi5+oImDzmBYzyLRiUXSnu3GpEWc158AV0isDwqvPjcAzLUAPn1/PPOf+VL+HjCG7SLbRfIoi7q41ITcxAoZeiL87m+x2Gt8sg47YqFWdcum1ohWJ2e27FruVyJ8b6jrY/2I+hwh43ztijT/rXp+U2y3/J00LFt3eNrjQ7RKN7+4znjYUTOLAwtByZgsyZ5W+PEhQbSSr9gqgcefdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=H118GTbbUjYBbWxrSZ76Di052XILnkk7sJAbW42lFL4=; b=k4zBEz9DnKb/hqqDbLtSS4CTsGFxvEo+cyhU3weUJMf2XSGJjpu1W8SvXsipfw6sOyflXx5I2vjQN8IGnA9qhKN02dLcX6X/O4Dl/mJ+9YVtP8R2QBiXFpJbR5K0kUhGIUxc0k+fw/LsiP6Mn5SxYj/nLcY3P9+kQzPMmhMcVLAqxCgTvi9O0hRxKtm1BOKCHyopjC/edKYO2ISaYrCn9r5iDuBU2QLqc1s+jhYNcWkkYNuzo6cUI2fWZ1NS0JTgNLZpv4PddegSSNLETYijljOXYdrz64/+2fmNtaeqgLZMuguF/R5ByIGW0UF8/emPPDeMK7Ke8GUeRjY5K/pJiA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=H118GTbbUjYBbWxrSZ76Di052XILnkk7sJAbW42lFL4=; b=t54L0bLKiktrj5Ii4wA+JgM8DH9764xhXdRQFyV3TDkQ9whtxAWwOuQb9kwwyC7WogZU8//GBAaPGKdFYWqFwVPjgE2pFl40U8zDuS+5vsRX/W5n3g790uD9u8kYK6h7FK2TF4Mx5L/PiziEgFR8dkvM7zYvczXXM2miPc8fOZ3GiaKGvxvWpxjtCTTtn6QTJfCXqKI/Bm+uoykum5yU/zBWaFvYN5JUqNgYBTlxWeb3FiajnaOwPLn/KpTAJQ+nrmO8LPaBLGTku8CYBz2SFX5m3p83m6LzQdMJJCIdnC2jqwfditZC6suj1MQbv28B1vOCVwmw9OPYTEOFfH/Mww== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) by SN7PR12MB6816.namprd12.prod.outlook.com (2603:10b6:806:264::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.31; Sat, 4 Feb 2023 17:12:20 +0000 Received: from CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab]) by CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab%9]) with mapi id 15.20.6064.025; Sat, 4 Feb 2023 17:12:20 +0000 From: Ido Schimmel To: netdev@vger.kernel.org, bridge@lists.linux-foundation.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, razor@blackwall.org, roopa@nvidia.com, petrm@nvidia.com, mlxsw@nvidia.com, Ido Schimmel Subject: [RFC PATCH net-next 06/13] rtnetlink: bridge: mcast: Move MDB handlers out of bridge driver Date: Sat, 4 Feb 2023 19:07:54 +0200 Message-Id: <20230204170801.3897900-7-idosch@nvidia.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230204170801.3897900-1-idosch@nvidia.com> References: <20230204170801.3897900-1-idosch@nvidia.com> X-ClientProxiedBy: VI1P191CA0003.EURP191.PROD.OUTLOOK.COM (2603:10a6:800:1ba::7) To CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR12MB6179:EE_|SN7PR12MB6816:EE_ X-MS-Office365-Filtering-Correlation-Id: a98ac8a9-ceb6-4a1b-0f59-08db06d2f949 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sO0DhxVauMJwcAzUvB6Cvg9Ou8szbk5Q85V+t3nvFKxVW9+ESEpFzf0xfelLSmOn0yrl/fqZCoXDnB5hRWvYohaJZpbmTneBQtqmzqXKNjZIDdWZ89WjTK41uHddeCes/4U1p89567JXcy/ni5S1KMFqAeaDXRYQ9R4R7s9CQfxf719nFLVvcwFpvTirtfwW1UUjAlghZEGtjpADtNmVUuIzFqDyxRzXB1ghqBJBhvo1hPebZeU/Mcvliz2MjC4IHgNPIW90TZGknF0CjpLZRTcfrtKnsRE04FdodRUZakKBdEt5kviRkExb6YNAIk4z9ckVpD2BFEgZ0gmHOgAZ566+cwnFdyjq1Sv4zv+m7HUY2ETFvVSLtooVKUzcBE0/GO0sh5vQKr2ieMg8uMXHs0vq71MWSg847c2VaZt/23hhwAgxSZ3mtgUjRxn69/IHvNN+jOreAmtLAGnog6JqDI7ANyqNTXuuVfO0nvtHwxSi1+Ba/vXSzEz3ISCTsKhDPjrlTwwxaoZVjNo8XzXlDFnqiWRZeMu21lUI45MmARYq55c5/4opYxrB7LTsYaXSHi7dnzHYL+QaXgZ/pkpI9F3RJulfc1ydT+TXbvlLDGhSDcJ972Nn0Tlcvc27mHBpqMwVBg1+oSU4NvC8wnVbIA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY5PR12MB6179.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(366004)(346002)(39860400002)(136003)(376002)(396003)(451199018)(8936002)(36756003)(5660300002)(30864003)(107886003)(1076003)(6666004)(316002)(6506007)(478600001)(38100700002)(6486002)(66476007)(4326008)(8676002)(66946007)(2616005)(83380400001)(66556008)(41300700001)(86362001)(186003)(2906002)(6512007)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sh2oJnR8sH6PCIF8bktyHoT0ISxWCRHSN1DFvfuOvo/bSMFBjiKTnr+KBUDvu++oHaGAJOUkk4N32iYDOmrjrLd5XFJbaw/AujOXzb7zuvZOuyC9K5670Yt7mtPt9h2FWApsatR2cZWfMgnLA3HCsRiTFu9zG6RJvCvEmYIDc0Ljm1s9R4FGAAHT4ChAMVecVU0eAmRxhFNmYoCT7pEtXIvmqJxitylFg66Qc2M+lS9PuiE5tsOEPdys3KE4LnDG7jWxLCo3uQ+2PD/2YXlbHpdnPthreie4dMSd1jov7RSy64DjN7uj5qnP68YesVOyXPAD9zromt6pYTEPVB9ZaGzcI4YWSTTpE58RDKm0Nrgj0Ky9v+TKna+sx6yyBZjzzHobo9YCBTi6zg8EX2mS85LrGtdudBiJi1RDjWAClM7UWC7woKXsffAaSudXQiY+4Twe1IuJJb5wRCJkP+aVxgx/uo1kzeOYroHEVLAGAjgOEzQSezaZOMeM3aQgvhB4Js4zBji4VxVwUoVvQUMLtynJ01NioCU+v1CRw1JoM/BUmyMqB/2QSy3/wDpU69HcRH0WaYjRCAQ5fNaM1G3Y0lUpkwFG7QHB5PO6sPkES8r7RbKm9aUOE9smUoevHLWkXf6HzvuCiASRAFQCBNl320lspMmHdPSgjbWhEDd8Lf62xQXScYz2yJYvseOG/YbS5vv6gCYdG+L1eIGgYJobHJV4AM7VXSCnFnRLwRujBK1MyA1NDf8lpYaFn3ezMdCJm3FkPn6yMV39kiiMsEpCNQ57VUqH7RuHTwNNnk2mwoGYfEYn9qcvL/VxFMY5j8iv4G9m0CJosZ7Zka5sApBIlsYsNrpRXVIYLp/VpBlIXXZ++IMBXL+tEZGfHiPol6WbpSapuDjSuxjICnlO6K9p1DaVYQWWeQ2SB4Nn9o7bJyRfjPocWEs/91iTkM8WsblC1NF+RL6yAyeTEebHl0Y1NiBRqMYo6kdLT9gT70uy+OYUPnM61kel4aqjbrI9Gb3PgW1zbmiCRHMqQPPqqJYUAkJHpTuvxE1rcVuA5/suG7t7p1xeR8PEKU5K5u3FBYPszTgMcu9WBYYDAHGO4GlxUhOs+S0ri1ZxPHvd23KGvm9gzkTKBzsmTYL7Y6KiXggUdgO8CspjGLxMXSygcg1uVbIXmgvToH2pt8/y3GBDVswyF8mbis9oMaifNUkSU7FO+f5dK96h/Pz3wme1ZmnvNISoJxs07bDycU5iURoLVgiLEmYVFOTrLih1gwGWEK6A6ak1VSRfrkrQyVh51XHkcijadphvJ579WMC/1h4AegGsr6eDa3kGk6SArXwMSI/KPlZm+KwjAtJpAg0nqatMi8UOhKhUESIOuxe11IOg6r4qBjiJ54iZYz+Uo1dswjyPIDZ+ThTmQ2dU1mSOBX8mA/uQDMRKqdEeMVUOCXldIWiz2r3I6COM8C4mNxTVaf7J7oBqYNkGXdU6KTmixU2ecuLLOPb3TLJKIubYDS/thb7+OAqwgWwy7xTn6yoRn/FYkpky2NBBlo8TAb+CnJo4Ph6OQD6U7yPeCxvFQ7jlZsciySHi++v/TjEO22sxSLKN X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: a98ac8a9-ceb6-4a1b-0f59-08db06d2f949 X-MS-Exchange-CrossTenant-AuthSource: CY5PR12MB6179.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2023 17:12:20.0770 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: IrTIwX5UHGGj/WWHo5gdauPMOD7aqwFxKE4RYrZiqfbWJELalb0X+sS6WqxBl6lTJcx0KkozD+lE5h36QS8YbQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6816 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Currently, the bridge driver registers handlers for MDB netlink messages, making it impossible for other drivers to implement MDB support. As a preparation for VXLAN MDB support, move the MDB handlers out of the bridge driver to the core rtnetlink code. The rtnetlink code will call into individual drivers by invoking their previously added MDB net device operations. Note that while the diffstat is large, the change is mechanical. It moves code out of the bridge driver to rtnetlink code. Also note that a similar change was made in 2012 with commit 77162022ab26 ("net: add generic PF_BRIDGE:RTM_ FDB hooks") that moved FDB handlers out of the bridge driver to the core rtnetlink code. Signed-off-by: Ido Schimmel --- net/bridge/br_device.c | 6 +- net/bridge/br_mdb.c | 301 ++-------------------------------------- net/bridge/br_netlink.c | 3 - net/bridge/br_private.h | 35 ++--- net/core/rtnetlink.c | 214 ++++++++++++++++++++++++++++ 5 files changed, 241 insertions(+), 318 deletions(-) diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c index 85fa4d73bb53..df47c876230e 100644 --- a/net/bridge/br_device.c +++ b/net/bridge/br_device.c @@ -468,9 +468,9 @@ static const struct net_device_ops br_netdev_ops = { .ndo_fdb_del_bulk = br_fdb_delete_bulk, .ndo_fdb_dump = br_fdb_dump, .ndo_fdb_get = br_fdb_get, - .ndo_mdb_add = br_mdb_add_new, - .ndo_mdb_del = br_mdb_del_new, - .ndo_mdb_dump = br_mdb_dump_new, + .ndo_mdb_add = br_mdb_add, + .ndo_mdb_del = br_mdb_del, + .ndo_mdb_dump = br_mdb_dump, .ndo_bridge_getlink = br_getlink, .ndo_bridge_setlink = br_setlink, .ndo_bridge_dellink = br_dellink, diff --git a/net/bridge/br_mdb.c b/net/bridge/br_mdb.c index 3359ac63c739..f970980e6183 100644 --- a/net/bridge/br_mdb.c +++ b/net/bridge/br_mdb.c @@ -380,86 +380,8 @@ static int br_mdb_fill_info(struct sk_buff *skb, struct netlink_callback *cb, return err; } -static int br_mdb_valid_dump_req(const struct nlmsghdr *nlh, - struct netlink_ext_ack *extack) -{ - struct br_port_msg *bpm; - - if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*bpm))) { - NL_SET_ERR_MSG_MOD(extack, "Invalid header for mdb dump request"); - return -EINVAL; - } - - bpm = nlmsg_data(nlh); - if (bpm->ifindex) { - NL_SET_ERR_MSG_MOD(extack, "Filtering by device index is not supported for mdb dump request"); - return -EINVAL; - } - if (nlmsg_attrlen(nlh, sizeof(*bpm))) { - NL_SET_ERR_MSG(extack, "Invalid data after header in mdb dump request"); - return -EINVAL; - } - - return 0; -} - -static int br_mdb_dump(struct sk_buff *skb, struct netlink_callback *cb) -{ - struct net_device *dev; - struct net *net = sock_net(skb->sk); - struct nlmsghdr *nlh = NULL; - int idx = 0, s_idx; - - if (cb->strict_check) { - int err = br_mdb_valid_dump_req(cb->nlh, cb->extack); - - if (err < 0) - return err; - } - - s_idx = cb->args[0]; - - rcu_read_lock(); - - for_each_netdev_rcu(net, dev) { - if (netif_is_bridge_master(dev)) { - struct net_bridge *br = netdev_priv(dev); - struct br_port_msg *bpm; - - if (idx < s_idx) - goto skip; - - nlh = nlmsg_put(skb, NETLINK_CB(cb->skb).portid, - cb->nlh->nlmsg_seq, RTM_GETMDB, - sizeof(*bpm), NLM_F_MULTI); - if (nlh == NULL) - break; - - bpm = nlmsg_data(nlh); - memset(bpm, 0, sizeof(*bpm)); - bpm->ifindex = dev->ifindex; - if (br_mdb_fill_info(skb, cb, dev) < 0) - goto out; - if (br_rports_fill_info(skb, &br->multicast_ctx) < 0) - goto out; - - cb->args[1] = 0; - nlmsg_end(skb, nlh); - skip: - idx++; - } - } - -out: - if (nlh) - nlmsg_end(skb, nlh); - rcu_read_unlock(); - cb->args[0] = idx; - return skb->len; -} - -int br_mdb_dump_new(struct net_device *dev, struct sk_buff *skb, - struct netlink_callback *cb) +int br_mdb_dump(struct net_device *dev, struct sk_buff *skb, + struct netlink_callback *cb) { struct net_bridge *br = netdev_priv(dev); struct br_port_msg *bpm; @@ -716,60 +638,6 @@ static const struct nla_policy br_mdbe_attrs_pol[MDBE_ATTR_MAX + 1] = { [MDBE_ATTR_RTPROT] = NLA_POLICY_MIN(NLA_U8, RTPROT_STATIC), }; -static int validate_mdb_entry(const struct nlattr *attr, - struct netlink_ext_ack *extack) -{ - struct br_mdb_entry *entry = nla_data(attr); - - if (nla_len(attr) != sizeof(struct br_mdb_entry)) { - NL_SET_ERR_MSG_MOD(extack, "Invalid MDBA_SET_ENTRY attribute length"); - return -EINVAL; - } - - if (entry->ifindex == 0) { - NL_SET_ERR_MSG_MOD(extack, "Zero entry ifindex is not allowed"); - return -EINVAL; - } - - if (entry->addr.proto == htons(ETH_P_IP)) { - if (!ipv4_is_multicast(entry->addr.u.ip4)) { - NL_SET_ERR_MSG_MOD(extack, "IPv4 entry group address is not multicast"); - return -EINVAL; - } - if (ipv4_is_local_multicast(entry->addr.u.ip4)) { - NL_SET_ERR_MSG_MOD(extack, "IPv4 entry group address is local multicast"); - return -EINVAL; - } -#if IS_ENABLED(CONFIG_IPV6) - } else if (entry->addr.proto == htons(ETH_P_IPV6)) { - if (ipv6_addr_is_ll_all_nodes(&entry->addr.u.ip6)) { - NL_SET_ERR_MSG_MOD(extack, "IPv6 entry group address is link-local all nodes"); - return -EINVAL; - } -#endif - } else if (entry->addr.proto == 0) { - /* L2 mdb */ - if (!is_multicast_ether_addr(entry->addr.u.mac_addr)) { - NL_SET_ERR_MSG_MOD(extack, "L2 entry group is not multicast"); - return -EINVAL; - } - } else { - NL_SET_ERR_MSG_MOD(extack, "Unknown entry protocol"); - return -EINVAL; - } - - if (entry->state != MDB_PERMANENT && entry->state != MDB_TEMPORARY) { - NL_SET_ERR_MSG_MOD(extack, "Unknown entry state"); - return -EINVAL; - } - if (entry->vid >= VLAN_VID_MASK) { - NL_SET_ERR_MSG_MOD(extack, "Invalid entry VLAN id"); - return -EINVAL; - } - - return 0; -} - static bool is_valid_mdb_source(struct nlattr *attr, __be16 proto, struct netlink_ext_ack *extack) { @@ -1335,49 +1203,16 @@ static int br_mdb_config_attrs_init(struct nlattr *set_attrs, return 0; } -static const struct nla_policy mdba_policy[MDBA_SET_ENTRY_MAX + 1] = { - [MDBA_SET_ENTRY_UNSPEC] = { .strict_start_type = MDBA_SET_ENTRY_ATTRS + 1 }, - [MDBA_SET_ENTRY] = NLA_POLICY_VALIDATE_FN(NLA_BINARY, - validate_mdb_entry, - sizeof(struct br_mdb_entry)), - [MDBA_SET_ENTRY_ATTRS] = { .type = NLA_NESTED }, -}; - -static int br_mdb_config_init(struct net *net, const struct nlmsghdr *nlh, - struct br_mdb_config *cfg, +static int br_mdb_config_init(struct br_mdb_config *cfg, struct net_device *dev, + struct nlattr *tb[], u16 nlmsg_flags, struct netlink_ext_ack *extack) { - struct nlattr *tb[MDBA_SET_ENTRY_MAX + 1]; - struct br_port_msg *bpm; - struct net_device *dev; - int err; - - err = nlmsg_parse_deprecated(nlh, sizeof(*bpm), tb, - MDBA_SET_ENTRY_MAX, mdba_policy, extack); - if (err) - return err; + struct net *net = dev_net(dev); memset(cfg, 0, sizeof(*cfg)); cfg->filter_mode = MCAST_EXCLUDE; cfg->rt_protocol = RTPROT_STATIC; - cfg->nlflags = nlh->nlmsg_flags; - - bpm = nlmsg_data(nlh); - if (!bpm->ifindex) { - NL_SET_ERR_MSG_MOD(extack, "Invalid bridge ifindex"); - return -EINVAL; - } - - dev = __dev_get_by_index(net, bpm->ifindex); - if (!dev) { - NL_SET_ERR_MSG_MOD(extack, "Bridge device doesn't exist"); - return -ENODEV; - } - - if (!netif_is_bridge_master(dev)) { - NL_SET_ERR_MSG_MOD(extack, "Device is not a bridge"); - return -EOPNOTSUPP; - } + cfg->nlflags = nlmsg_flags; cfg->br = netdev_priv(dev); @@ -1391,11 +1226,6 @@ static int br_mdb_config_init(struct net *net, const struct nlmsghdr *nlh, return -EINVAL; } - if (NL_REQ_ATTR_CHECK(extack, NULL, tb, MDBA_SET_ENTRY)) { - NL_SET_ERR_MSG_MOD(extack, "Missing MDBA_SET_ENTRY attribute"); - return -EINVAL; - } - cfg->entry = nla_data(tb[MDBA_SET_ENTRY]); if (cfg->entry->ifindex != cfg->br->dev->ifindex) { @@ -1433,16 +1263,15 @@ static void br_mdb_config_fini(struct br_mdb_config *cfg) br_mdb_config_src_list_fini(cfg); } -static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh, - struct netlink_ext_ack *extack) +int br_mdb_add(struct net_device *dev, struct nlattr *tb[], u16 nlmsg_flags, + struct netlink_ext_ack *extack) { - struct net *net = sock_net(skb->sk); struct net_bridge_vlan_group *vg; struct net_bridge_vlan *v; struct br_mdb_config cfg; int err; - err = br_mdb_config_init(net, nlh, &cfg, extack); + err = br_mdb_config_init(&cfg, dev, tb, nlmsg_flags, extack); if (err) return err; @@ -1495,65 +1324,6 @@ static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh, return err; } -int br_mdb_add_new(struct net_device *dev, struct nlattr *tb[], u16 nlmsg_flags, - struct netlink_ext_ack *extack) -{ - struct net_bridge_vlan_group *vg; - struct br_mdb_config cfg = {}; - struct net_bridge_vlan *v; - int err; - - /* Configuration structure will be initialized here. */ - - err = -EINVAL; - /* host join errors which can happen before creating the group */ - if (!cfg.p && !br_group_is_l2(&cfg.group)) { - /* don't allow any flags for host-joined IP groups */ - if (cfg.entry->state) { - NL_SET_ERR_MSG_MOD(extack, "Flags are not allowed for host groups"); - goto out; - } - if (!br_multicast_is_star_g(&cfg.group)) { - NL_SET_ERR_MSG_MOD(extack, "Groups with sources cannot be manually host joined"); - goto out; - } - } - - if (br_group_is_l2(&cfg.group) && cfg.entry->state != MDB_PERMANENT) { - NL_SET_ERR_MSG_MOD(extack, "Only permanent L2 entries allowed"); - goto out; - } - - if (cfg.p) { - if (cfg.p->state == BR_STATE_DISABLED && cfg.entry->state != MDB_PERMANENT) { - NL_SET_ERR_MSG_MOD(extack, "Port is in disabled state and entry is not permanent"); - goto out; - } - vg = nbp_vlan_group(cfg.p); - } else { - vg = br_vlan_group(cfg.br); - } - - /* If vlan filtering is enabled and VLAN is not specified - * install mdb entry on all vlans configured on the port. - */ - if (br_vlan_enabled(cfg.br->dev) && vg && cfg.entry->vid == 0) { - list_for_each_entry(v, &vg->vlan_list, vlist) { - cfg.entry->vid = v->vid; - cfg.group.vid = v->vid; - err = __br_mdb_add(&cfg, extack); - if (err) - break; - } - } else { - err = __br_mdb_add(&cfg, extack); - } - -out: - br_mdb_config_fini(&cfg); - return err; -} - static int __br_mdb_del(const struct br_mdb_config *cfg) { struct br_mdb_entry *entry = cfg->entry; @@ -1595,16 +1365,15 @@ static int __br_mdb_del(const struct br_mdb_config *cfg) return err; } -static int br_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, - struct netlink_ext_ack *extack) +int br_mdb_del(struct net_device *dev, struct nlattr *tb[], + struct netlink_ext_ack *extack) { - struct net *net = sock_net(skb->sk); struct net_bridge_vlan_group *vg; struct net_bridge_vlan *v; struct br_mdb_config cfg; int err; - err = br_mdb_config_init(net, nlh, &cfg, extack); + err = br_mdb_config_init(&cfg, dev, tb, 0, extack); if (err) return err; @@ -1629,49 +1398,3 @@ static int br_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, br_mdb_config_fini(&cfg); return err; } - -int br_mdb_del_new(struct net_device *dev, struct nlattr *tb[], - struct netlink_ext_ack *extack) -{ - struct net_bridge_vlan_group *vg; - struct br_mdb_config cfg = {}; - struct net_bridge_vlan *v; - int err = 0; - - /* Configuration structure will be initialized here. */ - - if (cfg.p) - vg = nbp_vlan_group(cfg.p); - else - vg = br_vlan_group(cfg.br); - - /* If vlan filtering is enabled and VLAN is not specified - * delete mdb entry on all vlans configured on the port. - */ - if (br_vlan_enabled(cfg.br->dev) && vg && cfg.entry->vid == 0) { - list_for_each_entry(v, &vg->vlan_list, vlist) { - cfg.entry->vid = v->vid; - cfg.group.vid = v->vid; - err = __br_mdb_del(&cfg); - } - } else { - err = __br_mdb_del(&cfg); - } - - br_mdb_config_fini(&cfg); - return err; -} - -void br_mdb_init(void) -{ - rtnl_register_module(THIS_MODULE, PF_BRIDGE, RTM_GETMDB, NULL, br_mdb_dump, 0); - rtnl_register_module(THIS_MODULE, PF_BRIDGE, RTM_NEWMDB, br_mdb_add, NULL, 0); - rtnl_register_module(THIS_MODULE, PF_BRIDGE, RTM_DELMDB, br_mdb_del, NULL, 0); -} - -void br_mdb_uninit(void) -{ - rtnl_unregister(PF_BRIDGE, RTM_GETMDB); - rtnl_unregister(PF_BRIDGE, RTM_NEWMDB); - rtnl_unregister(PF_BRIDGE, RTM_DELMDB); -} diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c index 4316cc82ae17..aef0b9a3ac74 100644 --- a/net/bridge/br_netlink.c +++ b/net/bridge/br_netlink.c @@ -1869,7 +1869,6 @@ int __init br_netlink_init(void) { int err; - br_mdb_init(); br_vlan_rtnl_init(); rtnl_af_register(&br_af_ops); @@ -1881,13 +1880,11 @@ int __init br_netlink_init(void) out_af: rtnl_af_unregister(&br_af_ops); - br_mdb_uninit(); return err; } void br_netlink_fini(void) { - br_mdb_uninit(); br_vlan_rtnl_uninit(); rtnl_af_unregister(&br_af_ops); rtnl_link_unregister(&br_link_ops); diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 91dba4792469..75aff9bbf17e 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -974,14 +974,12 @@ void br_multicast_uninit_stats(struct net_bridge *br); void br_multicast_get_stats(const struct net_bridge *br, const struct net_bridge_port *p, struct br_mcast_stats *dest); -int br_mdb_add_new(struct net_device *dev, struct nlattr *tb[], u16 nlmsg_flags, - struct netlink_ext_ack *extack); -int br_mdb_del_new(struct net_device *dev, struct nlattr *tb[], - struct netlink_ext_ack *extack); -int br_mdb_dump_new(struct net_device *dev, struct sk_buff *skb, - struct netlink_callback *cb); -void br_mdb_init(void); -void br_mdb_uninit(void); +int br_mdb_add(struct net_device *dev, struct nlattr *tb[], u16 nlmsg_flags, + struct netlink_ext_ack *extack); +int br_mdb_del(struct net_device *dev, struct nlattr *tb[], + struct netlink_ext_ack *extack); +int br_mdb_dump(struct net_device *dev, struct sk_buff *skb, + struct netlink_callback *cb); void br_multicast_host_join(const struct net_bridge_mcast *brmctx, struct net_bridge_mdb_entry *mp, bool notify); void br_multicast_host_leave(struct net_bridge_mdb_entry *mp, bool notify); @@ -1373,33 +1371,24 @@ static inline bool br_multicast_querier_exists(struct net_bridge_mcast *brmctx, return false; } -static inline int br_mdb_add_new(struct net_device *dev, struct nlattr *tb[], - u16 nlmsg_flags, - struct netlink_ext_ack *extack) +static inline int br_mdb_add(struct net_device *dev, struct nlattr *tb[], + u16 nlmsg_flags, struct netlink_ext_ack *extack) { return -EOPNOTSUPP; } -static inline int br_mdb_del_new(struct net_device *dev, struct nlattr *tb[], - struct netlink_ext_ack *extack) +static inline int br_mdb_del(struct net_device *dev, struct nlattr *tb[], + struct netlink_ext_ack *extack) { return -EOPNOTSUPP; } -static inline int br_mdb_dump_new(struct net_device *dev, struct sk_buff *skb, - struct netlink_callback *cb) +static inline int br_mdb_dump(struct net_device *dev, struct sk_buff *skb, + struct netlink_callback *cb) { return 0; } -static inline void br_mdb_init(void) -{ -} - -static inline void br_mdb_uninit(void) -{ -} - static inline int br_mdb_hash_init(struct net_bridge *br) { return 0; diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index b9f584955b77..892d4e8fd394 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -54,6 +54,9 @@ #include #include #include +#if IS_ENABLED(CONFIG_IPV6) +#include +#endif #include "dev.h" @@ -6063,6 +6066,213 @@ static int rtnl_stats_set(struct sk_buff *skb, struct nlmsghdr *nlh, return 0; } +static int rtnl_mdb_valid_dump_req(const struct nlmsghdr *nlh, + struct netlink_ext_ack *extack) +{ + struct br_port_msg *bpm; + + if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*bpm))) { + NL_SET_ERR_MSG(extack, "Invalid header for mdb dump request"); + return -EINVAL; + } + + bpm = nlmsg_data(nlh); + if (bpm->ifindex) { + NL_SET_ERR_MSG(extack, "Filtering by device index is not supported for mdb dump request"); + return -EINVAL; + } + if (nlmsg_attrlen(nlh, sizeof(*bpm))) { + NL_SET_ERR_MSG(extack, "Invalid data after header in mdb dump request"); + return -EINVAL; + } + + return 0; +} + +struct rtnl_mdb_dump_ctx { + long idx; + long dev_markers[5]; +}; + +static int rtnl_mdb_dump(struct sk_buff *skb, struct netlink_callback *cb) +{ + struct rtnl_mdb_dump_ctx *ctx = (void *)cb->ctx; + struct net *net = sock_net(skb->sk); + struct net_device *dev; + int idx, s_idx; + int err; + + BUILD_BUG_ON(sizeof(*ctx) != sizeof(cb->ctx)); + + if (cb->strict_check) { + err = rtnl_mdb_valid_dump_req(cb->nlh, cb->extack); + if (err) + return err; + } + + s_idx = ctx->idx; + idx = 0; + + for_each_netdev(net, dev) { + if (idx < s_idx) + goto skip; + if (!dev->netdev_ops->ndo_mdb_dump) + goto skip; + + err = dev->netdev_ops->ndo_mdb_dump(dev, skb, cb); + if (err == -EMSGSIZE) + goto out; + /* Moving on to next device, reset device's markers. */ + memset(ctx->dev_markers, 0, sizeof(ctx->dev_markers)); +skip: + idx++; + } + +out: + ctx->idx = idx; + return skb->len; +} + +static int rtnl_validate_mdb_entry(const struct nlattr *attr, + struct netlink_ext_ack *extack) +{ + struct br_mdb_entry *entry = nla_data(attr); + + if (nla_len(attr) != sizeof(struct br_mdb_entry)) { + NL_SET_ERR_MSG(extack, "Invalid MDBA_SET_ENTRY attribute length"); + return -EINVAL; + } + + if (entry->ifindex == 0) { + NL_SET_ERR_MSG(extack, "Zero entry ifindex is not allowed"); + return -EINVAL; + } + + if (entry->addr.proto == htons(ETH_P_IP)) { + if (!ipv4_is_multicast(entry->addr.u.ip4)) { + NL_SET_ERR_MSG(extack, "IPv4 entry group address is not multicast"); + return -EINVAL; + } + if (ipv4_is_local_multicast(entry->addr.u.ip4)) { + NL_SET_ERR_MSG(extack, "IPv4 entry group address is local multicast"); + return -EINVAL; + } +#if IS_ENABLED(CONFIG_IPV6) + } else if (entry->addr.proto == htons(ETH_P_IPV6)) { + if (ipv6_addr_is_ll_all_nodes(&entry->addr.u.ip6)) { + NL_SET_ERR_MSG(extack, "IPv6 entry group address is link-local all nodes"); + return -EINVAL; + } +#endif + } else if (entry->addr.proto == 0) { + /* L2 mdb */ + if (!is_multicast_ether_addr(entry->addr.u.mac_addr)) { + NL_SET_ERR_MSG(extack, "L2 entry group is not multicast"); + return -EINVAL; + } + } else { + NL_SET_ERR_MSG(extack, "Unknown entry protocol"); + return -EINVAL; + } + + if (entry->state != MDB_PERMANENT && entry->state != MDB_TEMPORARY) { + NL_SET_ERR_MSG(extack, "Unknown entry state"); + return -EINVAL; + } + if (entry->vid >= VLAN_VID_MASK) { + NL_SET_ERR_MSG(extack, "Invalid entry VLAN id"); + return -EINVAL; + } + + return 0; +} + +static const struct nla_policy mdba_policy[MDBA_SET_ENTRY_MAX + 1] = { + [MDBA_SET_ENTRY_UNSPEC] = { .strict_start_type = MDBA_SET_ENTRY_ATTRS + 1 }, + [MDBA_SET_ENTRY] = NLA_POLICY_VALIDATE_FN(NLA_BINARY, + rtnl_validate_mdb_entry, + sizeof(struct br_mdb_entry)), + [MDBA_SET_ENTRY_ATTRS] = { .type = NLA_NESTED }, +}; + +static int rtnl_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh, + struct netlink_ext_ack *extack) +{ + struct nlattr *tb[MDBA_SET_ENTRY_MAX + 1]; + struct net *net = sock_net(skb->sk); + struct br_port_msg *bpm; + struct net_device *dev; + int err; + + err = nlmsg_parse_deprecated(nlh, sizeof(*bpm), tb, + MDBA_SET_ENTRY_MAX, mdba_policy, extack); + if (err) + return err; + + bpm = nlmsg_data(nlh); + if (!bpm->ifindex) { + NL_SET_ERR_MSG(extack, "Invalid ifindex"); + return -EINVAL; + } + + dev = __dev_get_by_index(net, bpm->ifindex); + if (!dev) { + NL_SET_ERR_MSG(extack, "Device doesn't exist"); + return -ENODEV; + } + + if (NL_REQ_ATTR_CHECK(extack, NULL, tb, MDBA_SET_ENTRY)) { + NL_SET_ERR_MSG(extack, "Missing MDBA_SET_ENTRY attribute"); + return -EINVAL; + } + + if (!dev->netdev_ops->ndo_mdb_add) { + NL_SET_ERR_MSG(extack, "Device does not support MDB operations"); + return -EOPNOTSUPP; + } + + return dev->netdev_ops->ndo_mdb_add(dev, tb, nlh->nlmsg_flags, extack); +} + +static int rtnl_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, + struct netlink_ext_ack *extack) +{ + struct nlattr *tb[MDBA_SET_ENTRY_MAX + 1]; + struct net *net = sock_net(skb->sk); + struct br_port_msg *bpm; + struct net_device *dev; + int err; + + err = nlmsg_parse_deprecated(nlh, sizeof(*bpm), tb, + MDBA_SET_ENTRY_MAX, mdba_policy, extack); + if (err) + return err; + + bpm = nlmsg_data(nlh); + if (!bpm->ifindex) { + NL_SET_ERR_MSG(extack, "Invalid ifindex"); + return -EINVAL; + } + + dev = __dev_get_by_index(net, bpm->ifindex); + if (!dev) { + NL_SET_ERR_MSG(extack, "Device doesn't exist"); + return -ENODEV; + } + + if (NL_REQ_ATTR_CHECK(extack, NULL, tb, MDBA_SET_ENTRY)) { + NL_SET_ERR_MSG(extack, "Missing MDBA_SET_ENTRY attribute"); + return -EINVAL; + } + + if (!dev->netdev_ops->ndo_mdb_del) { + NL_SET_ERR_MSG(extack, "Device does not support MDB operations"); + return -EOPNOTSUPP; + } + + return dev->netdev_ops->ndo_mdb_del(dev, tb, extack); +} + /* Process one rtnetlink message. */ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, @@ -6297,4 +6507,8 @@ void __init rtnetlink_init(void) rtnl_register(PF_UNSPEC, RTM_GETSTATS, rtnl_stats_get, rtnl_stats_dump, 0); rtnl_register(PF_UNSPEC, RTM_SETSTATS, rtnl_stats_set, NULL, 0); + + rtnl_register(PF_BRIDGE, RTM_GETMDB, NULL, rtnl_mdb_dump, 0); + rtnl_register(PF_BRIDGE, RTM_NEWMDB, rtnl_mdb_add, NULL, 0); + rtnl_register(PF_BRIDGE, RTM_DELMDB, rtnl_mdb_del, NULL, 0); } From patchwork Sat Feb 4 17:07:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 13128828 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC1F4C636CC for ; Sat, 4 Feb 2023 17:12:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232566AbjBDRMf (ORCPT ); Sat, 4 Feb 2023 12:12:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231987AbjBDRMd (ORCPT ); Sat, 4 Feb 2023 12:12:33 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2085.outbound.protection.outlook.com [40.107.93.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4A1532E49 for ; Sat, 4 Feb 2023 09:12:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FjaLuS8gwvJf3wHTOv02uHyl5eLB03lRLQ5YMQPjrU+SmoZwOfJhbkfJbf+v/pRpDcDhUD1Kwothojc4+SPPm51CqDtRteiNqzOcLPGZcZOGYQfdyHRXMP60BR58sisL4smbEEZZLnPwpJDjWzfNuVD4hOfkYf9l8NguUKlO6wFdooLYf2Ja7UoF8cNa4NG9lWkq6f02XXGmcwXC9nFjqZ9kWooT8wMP4iYtmIM5U6wLcPWxo3rh2W1MPx2jZe1BmdxRtSvqVPhv59HRfKjaQL07hIUH//e5xwAIl46bYj5jkoye3NIgZtgozM2rh7/LFbgmBf4qRw0xAwTP6HBkNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=W4PXtYbUKyUivLLP3rUrPplalXXEIhuL6DL8cRncPe8=; b=VVb1bBZrlwlM4arhjhR9KRHy8cbijxMoU5aHwGqyhVkOUBDtJQDWrdhiEYCPxzBatviL5K6q3AdanwMVpnGxSmUHiPmAvZ5TDyLW7PGiN2DRn2jJQNG2bNwYqAkVA16Fh6uE1pkCHw96Lxm4XilT8RUS/AKVbUpNGkMU0POtHhzFcgpEH/6DAexG/Z2TiYBuTWDC7h3PiBosmMu3nasmlLuoAk++5hArN7Z7Kw/7DZ/JPNWoT7xuZt8l3FKrC303C+DpMxf05A+G5uQ7R21npGAgGVnIuMjXoWKL+NM3fgCu3+rSYLjNoZkc5fcKTOFXzQ+X/FVL0si+mKH8Vb4LQg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=W4PXtYbUKyUivLLP3rUrPplalXXEIhuL6DL8cRncPe8=; b=dQQsmV0FTx1fcBwZAvgp4P+sw6DUYWcSRS5fmFUvt7GuAtykJvqtm6rtOISPffs0VUArJ/wJdPOAwEhnwdaRXnGV6GXwtbgfgCKIA8GK1BPSFqlfl3Faf2Y55vtSa3ZVO2lHa1/fOoS7inEGsB9nuvqJwrZuFgzXeKGKOQgcBiJjOuWjw5HYzCllkdhMXdKw6TYmNuEfleJTHvxPzZebK65yic5T/0QaT+KSDet3PqEmYMGssAtL7vDUUApqAtwZeGtqnluhJGIooI1tbLv4SVNbuUlYrkVuI14fvMKOt2AM8c1TvIImt+rKu5nw56B1XdijK7wesJ6th77LO4wOKQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) by SN7PR12MB6816.namprd12.prod.outlook.com (2603:10b6:806:264::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.31; Sat, 4 Feb 2023 17:12:28 +0000 Received: from CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab]) by CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab%9]) with mapi id 15.20.6064.025; Sat, 4 Feb 2023 17:12:28 +0000 From: Ido Schimmel To: netdev@vger.kernel.org, bridge@lists.linux-foundation.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, razor@blackwall.org, roopa@nvidia.com, petrm@nvidia.com, mlxsw@nvidia.com, Ido Schimmel Subject: [RFC PATCH net-next 07/13] rtnetlink: bridge: mcast: Relax group address validation in common code Date: Sat, 4 Feb 2023 19:07:55 +0200 Message-Id: <20230204170801.3897900-8-idosch@nvidia.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230204170801.3897900-1-idosch@nvidia.com> References: <20230204170801.3897900-1-idosch@nvidia.com> X-ClientProxiedBy: VI1P190CA0017.EURP190.PROD.OUTLOOK.COM (2603:10a6:802:2b::30) To CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR12MB6179:EE_|SN7PR12MB6816:EE_ X-MS-Office365-Filtering-Correlation-Id: 5c68914f-3c51-4284-f46f-08db06d2fdf3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Xy+iFUaMS2OO5x5nm38ggpFAZeK4y/f5FwaZjnuM2xiL0u6v9epzeQDmqczHTNyd/0k6zzz8yWCOtBx4VV4TIu1iEQQNUChLYtUucrSxK6eT76tjm9B/KWWH8Al105k+3u0gNqgKrPHDD9q8WLMkuU74yDB298pMCKqqFzzmLpiPxIIZ0Q3J5rWhKGuxmigNvSDB1XZHPatWq5jMWgm+AoL0gfP1LCgi/lDIBkwqAY2SGz9zuHaIJpTlCdKwRzYF5spdEoDA+jKlCqz82WS0w/YmX1nt2NuNhAuvHhLN7SjWHf8hkP3mluUP491H2DxnQtsWrQPF0BocizHaG4IiifCzTVbdQb/3xEQvRXV7ucX3jkbSt80dT3WUFkN7jRq1fgR+4tr86GVO6DakFIPbPfbiOuzi7X3nfOai5dixkoDffTaylBXqaLKwRlUzSO5+JkT/x2GVm69AjWM0JPM9nepM/TLt6x10sdDiT7gY+tQzXqChlzJ63Xixbw/76IFAoTxbgqiOYS3nSpmELUORHxNdaixxo0vHRvfLmRrWB+cGs8UKXqRP2ojmXs6c12YImnPJvTga6rd8kJahtDNqJ/cjC41z9JToyJ27Jq0pQBLkxPvOHTBSi9rubhqXCDr9sL5P2WyOBsGr0xjsnV1cL+HjGs6eSMYh+XmKLgAv21FYPG59SKzP0MoD5WNAjlB6D77lHXjKvwJDgvuDAZav1kk8Hjvg+7A4kIAPxyukYmA= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY5PR12MB6179.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(366004)(346002)(39860400002)(136003)(376002)(396003)(451199018)(8936002)(36756003)(5660300002)(107886003)(1076003)(6666004)(316002)(6506007)(478600001)(38100700002)(966005)(6486002)(66476007)(4326008)(8676002)(66946007)(2616005)(83380400001)(66556008)(41300700001)(86362001)(186003)(2906002)(6512007)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5tBATLKlqwck8aBIMiH6kG8/ELH/OQTihgMCm/ckmmdmVF052mAo8fjpJWVE1tqcK3kdLUmQIYyH84V3MY17K7fa2aAnAUJ9KAVurQbu7eRw3k8nOIyFBfpu+/mNQ4wn7lGRKWM10nLl948/WvHVW9TMZSzt4iL7rvUQb8q2UHqI/OaM1R5JqJSp7oZJjibOZA9PC1+prLaBXdMfc52zSm0hc6zCi1WKsS/zimhSfOuvOW3JxqU/atCC4bZiVablqQTnCkTJX9CRKCR0BGSbAb6+KoKNmg38bhyWKJhO/ocK5O5axEFxmb+U1zhM/+cGv6bSYZyV+vSBR/RouKEWj2jCWg46Fk1fW/nzPI29jt8QNVqzCefXdfnvWzNi5sL5/xstloUJThyFoF5RJOVUtAWjLNDOM0V/svZrIGFXPCQBPgDrarkQJKHINedhUybrQz5TlL4AmFtRi9kviaOAZSM+RXauw4ZnkX/0KHlXclBmJWTNOVldLL0Vx8sAYMg2LwhZy4Gwr5Zy6koxRKRsRQ+ZICba9s/5OpieKdV8FCvWvztGTWL5Cg/oWxWzRpLZngcgdSvk12tjtjnffDigGHQc6rGLm8NyoWLDfqTzOnMdGcRlCFsdetH00u8UYCsSN0R8vi22vYeiwKycJwSm16GwfzKkY+VJWzxJCHLIFleWnbWoPxEYqLSFP7eqc9pX8q3CIVHkU4Zuq+csKTlzARCvJeCxRNoXXmy2jKMkGRBbTfASLdFR1BHaJ3kihbcDp2EsTOlrLwX+efS2ZL/3KP6PWevFYTkoQDogU+ljKG7IYhu59YQXxMgQmXobfAKjN1yJUfDpkh/rPY5vshI6XkmTgMfzwMSwkrWT3RhrcFubmrnc7fnDDkggOfgnHZIPXO8zQWo6PE+RBkWBG6jDKRXPph3w8hcz0CIcZYvLhfZMKEf5joH8C+QM4lAjfCaEq1Ba0vVPGKSX4TpmUiq9FrJujROwx8IWEV2nlY5oOKL8EB7kOufor+MEZ5atYLwJPuMSpGDIBsNcneQsNWcZ6iX3kCUa5Z/uRTtzS+JonUJetRjuFG1o/jGl8Bn744+DQwwg3Wlp5Ie3v9XNoMXLuJeXXtCTRylscFuHk7RCW97Vfigm2DVnv+5BYV6LHg/EbtjGOr5w1OU9AdlH3sypsTE/wS2tgHFZ70f3rsiDPrE+EAqhP2Gecf7yXVFIV49XfK08Vym9RuYb1PevBvRJPssJ2O6yt6b6fua0votcxf/ekHd6rG+nuzqw2o2xuhFUymfDvmSMWZnwXiEJ6yfKhE0R6iIHys3f9TBORqS0+Sp9qm22vlJAgcJl/kz55F9WLYYJcG5D42tgFNeaHKpjlbRQ/l6/esUCMEHZSAGMPOSf+w3Xm+gL26OW4gk+7rGe1uwhdjRXPfEHIxIUhUj2sUsFCtUEmwAVsVih96ggqyAQMDQ3bEberr2FIa1TBTBXK/QezyMf0pEtx/xBZ1STIstDE1VDCNUikK5hb7PxWIA79KrQ3IuGoIfRQPAJeMOj3ZTlFC1nPE3vFbXJAFikKmFwwaVWYpGv9r+jR0pnphMo3QD6L1qBH5c6uJwKYJfR X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5c68914f-3c51-4284-f46f-08db06d2fdf3 X-MS-Exchange-CrossTenant-AuthSource: CY5PR12MB6179.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2023 17:12:28.0328 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 0wfrBH7qfDlkIWJRQXrv6UJdfTvjxbDRCz2TRYcj/Qr/2UG1YBdRnpEr0LLtAmBfS+LQz8NCBvSFuREXzeHHjg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6816 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC In the upcoming VXLAN MDB implementation, the 0.0.0.0 and :: MDB entries will act as catchall entries for unregistered IP multicast traffic in a similar fashion to the 00:00:00:00:00:00 VXLAN FDB entry that is used to transmit BUM traffic. In deployments where inter-subnet multicast forwarding is used, not all the VTEPs in a tenant domain are members in all the broadcast domains. It is therefore advantageous to transmit BULL (broadcast, unknown unicast and link-local multicast) and unregistered IP multicast traffic on different tunnels. If the same tunnel was used, a VTEP only interested in IP multicast traffic would also pull all the BULL traffic and drop it as it is not a member in the originating broadcast domain [1]. Prepare for this change by allowing the 0.0.0.0 group address in the common rtnetlink MDB code and forbid it in the bridge driver. A similar change is not needed for IPv6 because the common code only validates that the group address is not the all-nodes address. [1] https://datatracker.ietf.org/doc/html/draft-ietf-bess-evpn-irb-mcast#section-2.6 Signed-off-by: Ido Schimmel --- net/bridge/br_mdb.c | 6 ++++++ net/core/rtnetlink.c | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/net/bridge/br_mdb.c b/net/bridge/br_mdb.c index f970980e6183..88f0519520d2 100644 --- a/net/bridge/br_mdb.c +++ b/net/bridge/br_mdb.c @@ -1249,6 +1249,12 @@ static int br_mdb_config_init(struct br_mdb_config *cfg, struct net_device *dev, } } + if (cfg->entry->addr.proto == htons(ETH_P_IP) && + ipv4_is_zeronet(cfg->entry->addr.u.ip4)) { + NL_SET_ERR_MSG_MOD(extack, "IPv4 entry group address 0.0.0.0 is not allowed"); + return -EINVAL; + } + if (tb[MDBA_SET_ENTRY_ATTRS]) return br_mdb_config_attrs_init(tb[MDBA_SET_ENTRY_ATTRS], cfg, extack); diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 892d4e8fd394..1c7a8cbc4ce1 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -6149,8 +6149,9 @@ static int rtnl_validate_mdb_entry(const struct nlattr *attr, } if (entry->addr.proto == htons(ETH_P_IP)) { - if (!ipv4_is_multicast(entry->addr.u.ip4)) { - NL_SET_ERR_MSG(extack, "IPv4 entry group address is not multicast"); + if (!ipv4_is_multicast(entry->addr.u.ip4) && + !ipv4_is_zeronet(entry->addr.u.ip4)) { + NL_SET_ERR_MSG(extack, "IPv4 entry group address is not multicast or 0.0.0.0"); return -EINVAL; } if (ipv4_is_local_multicast(entry->addr.u.ip4)) { From patchwork Sat Feb 4 17:07:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 13128829 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43911C61DA4 for ; Sat, 4 Feb 2023 17:12:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232895AbjBDRMt (ORCPT ); Sat, 4 Feb 2023 12:12:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232682AbjBDRMj (ORCPT ); Sat, 4 Feb 2023 12:12:39 -0500 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2042.outbound.protection.outlook.com [40.107.96.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EDF232510 for ; Sat, 4 Feb 2023 09:12:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N3N613xYsyyU7kGEI363acHpynJ3qe8ZQRoCTFC93q7vYU0o8V+sZyDPbyJJDH+Er86iSHVeGZVqkWTnBDTxj36FCqR9ZQ8j27nYbKpdISadoyzY/fE0/N4jqctWguRqFy0m8xZMnGnjgj3AxIVRkgumKIgli0lY4uV6yQcpeWhH4L+DSWpAuSLRaJcfoSgglGFAowi+ld1T4D5DLOWMzJGLh0q7XebLT8crypOzwVAfNVDZkMWolVoKmy4YazRIVAu871ghIRBNfqa7Xa4AGYa1Y+MC5KfiGix7VL8bDIRYJaJba/hVPkTMbAksCGEHoaVSwtT1UQghleHoXxFKpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QaDp6w1B8EvD+GP4cf4FpBO7+rXUo3RK+Z9b+7VLSPA=; b=efxFjKfROafDi0ykI4H70CfmML+n25nky77twtUA99G/unxfah9vOEnJCY+zEB/F6DUlKiJXpYYvkcFTumf97pxvOVxCy2i4TeSkMvczP/c0KvMT33+DGUohFPTczqsisX3avk6QGTewYurwOcO+KA3Jyn+RcuGHtjJ1T4t/1SBjefRDvMSBIVZ/HK8ui84628W+wBMSszGzgWbpIYaMfeF00zfJtNoaEouiNwp97wYxzhNrBCIjFZEvtXu6uoXTivhGbmfy9MxehRpXBItHD9f6gs0d5knCf7DXQDN5QV4PZ/NgMCHAXvkUspkGafGwZSLknnwwE23dC2p/ivxP+w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QaDp6w1B8EvD+GP4cf4FpBO7+rXUo3RK+Z9b+7VLSPA=; b=K18h20GuxMwJWdjYSrju0ydXTRVMsO7vTbGpiUX3m96RE2qsPohrf3XPNbDJyJbYLeWF6QomppJ99PEiXM5a4MJMEnqFTuS/GYwCFMBXGAENvaBqOC32flYY2cF3WmEks8CvZaY3/702BOKyeIL9igO9w5Cln4OzCLTo7etHM6K+7T1xZydXqu6bE5qSm4suOFuPJtwHzris6qbLGQzPzsRCjE9WYINKsWDynmIkVauA7li86bCzonOCoyAqtO2JbzSyDM1nMGQLdu8dk49E0gEJ2CXIDNv/+HqFwvxOUf/OGakA4YGs1eT+adXTr7a1sm6p5mEb1fYv0pVxB1xf+A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) by SN7PR12MB6816.namprd12.prod.outlook.com (2603:10b6:806:264::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.31; Sat, 4 Feb 2023 17:12:34 +0000 Received: from CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab]) by CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab%9]) with mapi id 15.20.6064.025; Sat, 4 Feb 2023 17:12:34 +0000 From: Ido Schimmel To: netdev@vger.kernel.org, bridge@lists.linux-foundation.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, razor@blackwall.org, roopa@nvidia.com, petrm@nvidia.com, mlxsw@nvidia.com, Ido Schimmel Subject: [RFC PATCH net-next 08/13] vxlan: Move address helpers to private headers Date: Sat, 4 Feb 2023 19:07:56 +0200 Message-Id: <20230204170801.3897900-9-idosch@nvidia.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230204170801.3897900-1-idosch@nvidia.com> References: <20230204170801.3897900-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR0901CA0102.eurprd09.prod.outlook.com (2603:10a6:800:7e::28) To CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR12MB6179:EE_|SN7PR12MB6816:EE_ X-MS-Office365-Filtering-Correlation-Id: b0c2acc8-3d07-4a9b-75c7-08db06d30230 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +FYxyaNK4EVCNlrL8x51CMqq4BeAYCfCE/FIMgJIHRJoqItcUd7HEPbCKAEm1CvB5c0sWUTxnXgMuusCBvWyFYCt7t5YopyMUM6Tok/ZqAJPquFlHe+uVn2z4f7caeu8IsxSfgK70+t8pR5cD/17tPJd1go1SSPymGCcPdkpfTR5NgkUT4DGdCRGVSbL/KsrXAPPacOXmAXOFNLCw7b1V0b+Iu0bOhy2MGljmge3RpwAtCdVjX+WYDZEvKWOSkOXwc7zmDnLAak7dQW11VqN8uLFPNZ/DYrQW2jKQT3WdEZB+Yiin1WH+DjiBwjb6Jgt7CoimIv1tJTHASejaTD/LlqLghzfFiVW4LvpJ8Ew3K0HjnOtVUygjkl6dnIoE+OsNnn5xB+tKyOuJFarLjpCc3grjK9E9f97VUc5fNbMjVZL7ggxMdODt5ffOhwrYT+P70og1J2JuW6tAdGIDJvzh4Tt9APlpdtPfJprDpomGzc9qxPT2fHyKsv6pLsTHWXE/+vC5a/MZUc5/3HISjUVb+nFKYqBnIHogvEXsrq3CWEwPGEOzcXknHVWKNH1HFpo/KOB3SI0qHvBr76ObU/E/QQnLjXDswTV7Tp5a+ZvyoeFRSeD2xSh69EPK2Q2isa6NwiLfW7Yb0mj9AZU5KZoAQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY5PR12MB6179.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(366004)(346002)(39860400002)(136003)(376002)(396003)(451199018)(8936002)(36756003)(5660300002)(107886003)(1076003)(6666004)(316002)(6506007)(478600001)(38100700002)(6486002)(66476007)(4326008)(8676002)(66946007)(2616005)(83380400001)(66556008)(41300700001)(86362001)(186003)(2906002)(6512007)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: v7zNculMokLq4kNTv7Xq/JQRev8qvfwh+BKSS/+2LwbF1SLmgi8xtWmUGI8LQeOcQ1UUJEk0rr93yKog4O0QRjWmZ8whAbGZ1SjZkLtEmE6UGK076jKtFW5E5p4TeErX0UBKVbr5JDkOW+axdZm0b0oDvZ6eDsjGXSRp9qk0FR+T9nwruZhnfHC8o+noELn9g5TerFxEr3k0fG0VvAmb0NX9kIaAy9MZypDTbWFakVDYSHT6FuXxP2aOS2ij+dClfcLP5F1QR7KYpz0jTsq2E5iYio/SF8dj1nxvlo8QaOTZDTvX864rjoGsejJLWpfHQ/wE5H7264ExhzoiZl9+a6/bKP0ILXyTL2clSuk5aGTfOvB5JLxwqZzgXhsQvXUsmIoaUrETXtm1s42h8uK6dWjFucHn+d1A03Flzzdskq59cKWXWRo4tFjNzFYYIYYxzDEIyJG4ylB8fQHymbkhkgqNAQax4vBFcsQBbNKs7QNXOA/jMEFYj1V83Go441Hfw8Mgw9w0hosnhMMvohZcs6ZI/0TWDNUgWEGKOVfi/Eyz6Ti619VdwHdr4qTkwmXFBbirIiZyZgNX6Qy2bD2LxT8lRzxXBpSD2OVt4XpCftu2+HYaGEmLR3SEBIL3nn8rtiVVyGk00d3LDRj2HRbRrkM40PS09j/h+DE1xd+W2Gsny1kwDc0psVT9iCJOW9VD9veAiCFYqFqeVZ0WbqjYuyD+yeKviTzuxaGR/rRynYxYcf8RpKhm4LhAZPsPTeZZWlIbtf2uAclEkKHEElV2jHzM8LgUVGhv7isnOAws+UfFN0PRk9t+CH3DjicEqJN/2mdR47pcIEVDKiBRQmrAqZcF4NwSQ8r6BsEuH7PGR8ADVyuBpZul5Onc39Boz6TXxZZHNB/DSwgeS4Fo0OLs+dyy9S/kVXnFFHCERi4dPUSXzqrdVft8VaKXJglIi6xS0NQBMNqUw+p5vULlgq17xnlQX6LvWY1IBn9Y0ahtiNmmUuGam+X8foVy3gMyYQ0OZ6mdvzE9JdTcooFKcTd3/+3So18bARWEWUNJpg9prnOa8jKMRVuSBrgzhSHCHsM5xgCLMsdzMCGRQaKXyMRVC1ghYp7tCvdLcW7g94NlJXXqt42r2w/Uf9siU94dLAeAVd7jADh469eo/XMu8vo8cUE+yR03KF1tJzqEFxcpbLDAkyayppuXPc45vjiKKzCKWu/xclHBmaV52y/Rm83geoa3RoZ6pkO4uTM2klSC2SW5hOGmPiPVz1G+WzUjkx5hX7bA5HPWdyD5f3ppczAkhKDBPR412aXo/rhpRs2P9d8yY22a0YMMQdwqvt2Si1aUdGl/hwZrK1R7zC1U0FVepO7+iFsfqzmbXKVhyCuKQtc4xvw6kXOED5CK+epDF/kyhWjvg6LoVVnsUy449gOV3dFQdAYkG1XhnZws2jVIvqj+4DPK5HUaOKFdpZOdfG+fuItGGAYYOVg2XkMRT9Wt4TLMPWW8W88HyOgGOQC80iIY0ZIT2N1LKRUrKwK69CzMofPkuPNOmH9K7j8o2dOfXJHVoCneLmQd/J5O8cl5HWXPV4kEmlf24PRSsR1GbDvY X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b0c2acc8-3d07-4a9b-75c7-08db06d30230 X-MS-Exchange-CrossTenant-AuthSource: CY5PR12MB6179.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2023 17:12:34.8452 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: JfwWNbwd3jvJp7R9PspLLPovyXhPgxDAsoJjPsQ34oZ9Uti2+xWmAu/fPwaK7bpidnuBt8EGaKnwaukJoM43Jw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6816 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Move the helpers out of the core C file to the private header so that they could be used by the upcoming MDB code. While at it, constify the second argument of vxlan_nla_get_addr(). Signed-off-by: Ido Schimmel --- drivers/net/vxlan/vxlan_core.c | 47 ------------------------------- drivers/net/vxlan/vxlan_private.h | 45 +++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 47 deletions(-) diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index b1b179effe2a..a3106abc2b52 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -71,53 +71,6 @@ static inline bool vxlan_collect_metadata(struct vxlan_sock *vs) ip_tunnel_collect_metadata(); } -#if IS_ENABLED(CONFIG_IPV6) -static int vxlan_nla_get_addr(union vxlan_addr *ip, struct nlattr *nla) -{ - if (nla_len(nla) >= sizeof(struct in6_addr)) { - ip->sin6.sin6_addr = nla_get_in6_addr(nla); - ip->sa.sa_family = AF_INET6; - return 0; - } else if (nla_len(nla) >= sizeof(__be32)) { - ip->sin.sin_addr.s_addr = nla_get_in_addr(nla); - ip->sa.sa_family = AF_INET; - return 0; - } else { - return -EAFNOSUPPORT; - } -} - -static int vxlan_nla_put_addr(struct sk_buff *skb, int attr, - const union vxlan_addr *ip) -{ - if (ip->sa.sa_family == AF_INET6) - return nla_put_in6_addr(skb, attr, &ip->sin6.sin6_addr); - else - return nla_put_in_addr(skb, attr, ip->sin.sin_addr.s_addr); -} - -#else /* !CONFIG_IPV6 */ - -static int vxlan_nla_get_addr(union vxlan_addr *ip, struct nlattr *nla) -{ - if (nla_len(nla) >= sizeof(struct in6_addr)) { - return -EAFNOSUPPORT; - } else if (nla_len(nla) >= sizeof(__be32)) { - ip->sin.sin_addr.s_addr = nla_get_in_addr(nla); - ip->sa.sa_family = AF_INET; - return 0; - } else { - return -EAFNOSUPPORT; - } -} - -static int vxlan_nla_put_addr(struct sk_buff *skb, int attr, - const union vxlan_addr *ip) -{ - return nla_put_in_addr(skb, attr, ip->sin.sin_addr.s_addr); -} -#endif - /* Find VXLAN socket based on network namespace, address family, UDP port, * enabled unshareable flags and socket device binding (see l3mdev with * non-default VRF). diff --git a/drivers/net/vxlan/vxlan_private.h b/drivers/net/vxlan/vxlan_private.h index 599c3b4fdd5e..038528f9684a 100644 --- a/drivers/net/vxlan/vxlan_private.h +++ b/drivers/net/vxlan/vxlan_private.h @@ -85,6 +85,31 @@ bool vxlan_addr_equal(const union vxlan_addr *a, const union vxlan_addr *b) return a->sin.sin_addr.s_addr == b->sin.sin_addr.s_addr; } +static inline int vxlan_nla_get_addr(union vxlan_addr *ip, + const struct nlattr *nla) +{ + if (nla_len(nla) >= sizeof(struct in6_addr)) { + ip->sin6.sin6_addr = nla_get_in6_addr(nla); + ip->sa.sa_family = AF_INET6; + return 0; + } else if (nla_len(nla) >= sizeof(__be32)) { + ip->sin.sin_addr.s_addr = nla_get_in_addr(nla); + ip->sa.sa_family = AF_INET; + return 0; + } else { + return -EAFNOSUPPORT; + } +} + +static inline int vxlan_nla_put_addr(struct sk_buff *skb, int attr, + const union vxlan_addr *ip) +{ + if (ip->sa.sa_family == AF_INET6) + return nla_put_in6_addr(skb, attr, &ip->sin6.sin6_addr); + else + return nla_put_in_addr(skb, attr, ip->sin.sin_addr.s_addr); +} + #else /* !CONFIG_IPV6 */ static inline @@ -93,6 +118,26 @@ bool vxlan_addr_equal(const union vxlan_addr *a, const union vxlan_addr *b) return a->sin.sin_addr.s_addr == b->sin.sin_addr.s_addr; } +static inline int vxlan_nla_get_addr(union vxlan_addr *ip, + const struct nlattr *nla) +{ + if (nla_len(nla) >= sizeof(struct in6_addr)) { + return -EAFNOSUPPORT; + } else if (nla_len(nla) >= sizeof(__be32)) { + ip->sin.sin_addr.s_addr = nla_get_in_addr(nla); + ip->sa.sa_family = AF_INET; + return 0; + } else { + return -EAFNOSUPPORT; + } +} + +static inline int vxlan_nla_put_addr(struct sk_buff *skb, int attr, + const union vxlan_addr *ip) +{ + return nla_put_in_addr(skb, attr, ip->sin.sin_addr.s_addr); +} + #endif static inline struct vxlan_vni_node * From patchwork Sat Feb 4 17:07:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 13128830 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4452C636CC for ; Sat, 4 Feb 2023 17:13:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232470AbjBDRNF (ORCPT ); Sat, 4 Feb 2023 12:13:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232978AbjBDRM7 (ORCPT ); Sat, 4 Feb 2023 12:12:59 -0500 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2060.outbound.protection.outlook.com [40.107.96.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBD7834C3D for ; Sat, 4 Feb 2023 09:12:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UxmL8BVH1d4+zA5mwiAfCnJCcIeTgKI6vx21rT2ovNfhHmvWBgQi3pNpWHKTMSg4+7pZ/Ou8FC0EYbIy2lun/8kgvZ/jBwlJlA3BqrLvxCdkqR9Pai5tH0H49/HjcBuCq4y3rQxf99/J3iAQjQgRpjaBgP/Vs6xHklgqffpt3lIc8h/GQhr/+tVOEiisK/qp2c2fLKuOvWfluB5fNfPtGGl9EabO0Ox/WN1wfFjSokBlBhHn1s18py8plGRl0b95/Jj57mUgryOj97Tt5EtPKfoskwyNnhQaS583EWdvsqNaHch4R3TWhJpaidJAY0HBmtOzWL2Z3mdq+Apit4GAeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+wZRvEiTCl/aBueUPQj+epY02aK1I0070LJ8c5Z/BAg=; b=eeDwZWoaU2BTyvz4+P6B2IH5pgQXOA16tLq7w06syhbzNl0H0tWEfVgaM1+EBa/unRmT3B13XRP0TuOHxV2fVanUakiEFSVebcOmhyJjIFCpHx7ANjXZAHXHq8td5u8FJajlt2g8Mk0bvPRpJRpPBVabLLf6xdwd+Td8QMjnQcvaKSHgEUIwBMeQV8Z21sSeriXF0JoEMdLhoCRAL75nVhXtpGWOOvsH7o6i5/EAIfxEwp1WN1VzTz8Pse2lSrDKeeX2h5M8X3nw8BCp2QHj2oGKuPQrgfqTqiIP2V6T88za78tXwQbmcooby4fc7iZEH2clhvILhVF54BqKxVtA0g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+wZRvEiTCl/aBueUPQj+epY02aK1I0070LJ8c5Z/BAg=; b=oP3b3nQSWvWfVbY7gHu3R3bcJmB8cmtdo/EP3GmDXhCCkRxhth2k2t6cL2wEEYBrlfyTQjcnO3m0K1t5iFbUe2yYeXUJf/3ZtWyj0+t3kqFecTAmmST97l3GApLL3K8V4m88qOJxrtBWb78tsEnKdCkoL35HJ6PCzCZvpP451alRHhLrbfx1Kw4LaIl7NELjHz3TRC1bEXUI/EjLlBUBu8mNCzBlaT15q9sb0LWG148x9kvQRNIvCoO7sIGKiu0mT0dEcNxlcW2c3To4ha9vRxoWxs1TCmKpFx/NfLn78kJZTidnDUC2A8ay8+790Mm5Tyspgi5gH1YP36VAurUd3Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) by SN7PR12MB6816.namprd12.prod.outlook.com (2603:10b6:806:264::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.31; Sat, 4 Feb 2023 17:12:42 +0000 Received: from CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab]) by CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab%9]) with mapi id 15.20.6064.025; Sat, 4 Feb 2023 17:12:42 +0000 From: Ido Schimmel To: netdev@vger.kernel.org, bridge@lists.linux-foundation.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, razor@blackwall.org, roopa@nvidia.com, petrm@nvidia.com, mlxsw@nvidia.com, Ido Schimmel Subject: [RFC PATCH net-next 09/13] vxlan: Expose vxlan_xmit_one() Date: Sat, 4 Feb 2023 19:07:57 +0200 Message-Id: <20230204170801.3897900-10-idosch@nvidia.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230204170801.3897900-1-idosch@nvidia.com> References: <20230204170801.3897900-1-idosch@nvidia.com> X-ClientProxiedBy: VI1P194CA0042.EURP194.PROD.OUTLOOK.COM (2603:10a6:803:3c::31) To CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR12MB6179:EE_|SN7PR12MB6816:EE_ X-MS-Office365-Filtering-Correlation-Id: 21a3b827-4877-4972-b4c5-08db06d30680 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dRgZKFilV+DDfvq0rx77hr1vQ6PbkNmjf3Ls0NeIddElfJkeDxfQGpE5BsEqMF2pp/coHIH+XenMrkJUHdFfhSf0NUYt3jrhHZOFwogucPghjQBKvi3YYh5klbb6B0U3mtNMTRs6APt/2TUZe6l7cmDDvdX+HBdb+/YwrynlO8nd987YVx+BbPHK/aKGRrTkg247/6loYINrAb4A1/I5Xxnrsq1fTWiDwTtDsBCAFgChUNiBvMdYP77PGOuH1HwlkHBW/WqqGzi5/k4M7Gp5omU+aJyGxQMCtmLRs8KbdrDj02et/rPSRn2vy0FmtdluWGQ0HF0bh45RIW4CQfa2VM4+2OXXVSRtRsa1ceKSyP6Evvl6zbKHhSnvD0dXInYN+REvIZjY1Kud9Dt0lrlHoJrB+FvOSeSDUbb1h6VWkbtnlzC9HTlQkIzq8JD/ByAF+eL6BoSWoECM43S3MhYtqznbkdurjr6ClK1M/yGDzSsr26hunbPP+pit+aNEIHRRcgJh7SntRF6KG4hn8kPlrGJcYQWWajxLYQnQdx9wDKxSOWRk15Fj2/9XX9c/EkOZWX5bUJJHqkFImr1uuBSChayGC05H9LcXHWMurz+PJdlAcgvQrpbJfr6fFAOSblUs/xWUSXfiuRuhPC3MbdbjWg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY5PR12MB6179.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(366004)(346002)(39860400002)(136003)(376002)(396003)(451199018)(8936002)(36756003)(5660300002)(107886003)(1076003)(6666004)(316002)(6506007)(478600001)(38100700002)(6486002)(66476007)(4326008)(8676002)(66946007)(2616005)(83380400001)(66556008)(41300700001)(86362001)(186003)(2906002)(6512007)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Hs6BpwKmN86aWTutuvMGStLghjPEnXBXI0po7IGE223/L6Iv1ZlDgE11V2l82JFYsam70nhlNkooUhL6myh8w+NcXsVcWCPetZGI+jXf5LLr4pz2dv6ifygAdarhyLGtkQ5SPZKbCQhSC69EJafalUsdbI2ggUVgm+HfWBJmpftqd+XpNTrvNmTkdGrMWlo0wHac8HI7Rb9m77depBeDbERxwaVvvkN0aCOf5UlJgpsYjpp4sgdqJNKIEjIrc2moWnfp6gx/EC+XWECu6VpM3XCbm9mu0pM+Rb4Do33RFIFE+e13/b1tjIDFonHxX4DSSmCuqj8zfqAEMv752zAlvW2wvQUGc7TS+2mMdUNhyLu+gyk5LPpwzDjZaDdN25jLRmMwWMZVHubldZZlrYB7klm4NF/s4cQSdGULlHWE/cR0NwRzE7bK1jTpJZkpcWJizQ9SerYnypr3xq5+uRwajBJ//bQzA6hxJmz216GC3WDSOz7LA7OLnsefsmEwId7N7Uz3HwL+B+D/QOx6GCl+Lk+sZ+Obj1OldiYIeP4g8DGx5oA9LSoRcxH4mo2jvFlVMapyWUO0pz8O/k6XCVgIKJx8+iB0Stf/7wSh5xlyocYLw8B48zR9vuBUpgarQTVXvsjLH2Z1t1zNZGFRy0pbjbtPuLdkg4fvbS17lt+o8Fmo2FNYv0SzLSR+gLJNF0XWsd2EyveXfK6JARmr89xva1De0ETqclx4fktKzD5TlGoK2dZ/I1926wO0uxj8GVI5MCSMuacAKtVzoD2MaX87g5ncKIFjQa9jrbNu9kM4ixksqlffPpW+MuSkWpiNA36+1kjnIEO7lP8sTmK+QhWG/jrjc7hEO1x/b4siu9lrJ/OwM8OmTw9b/iI0wbMgUk4vttq5PTQdwqyckVgDEGFUJujucnd72jIpcWaC8sGOhO1cy3kJvK4aQEnY+7D450OdUojjjpIUTBR/IPf+YFAmCFlnAxhnI9gB5gYEEzrnpb3DFT/L3HZOHKBjeLSvATUu7Nvgcz7jXxYGtdcC3y+JbXAxJX4Khgtu+l/S0bv8JK1CT4YD52dHsKrKYMhYLzkJXmCaK8MZjMuUajrY1ZcmtlCTQhl1WF6Y05t1dVkcF1rw31uHmW9ih874xIaU8crjtqmf0oDV7OEyAG0vPsbtlXNs3TBc8vUv9AqUtLoJowNYz9xo5+TAC9MO2mQuSodGyCjn4MEg49A1wwohVaP44bZbY9W0g4KEV17xdpihd0F5gAIRk5nxbL10g7kOeuYSHbSNlIn5h5a81fuKTQEXX8AswqOTKmj9CyxADO8v70u3rSvVJ4/tAJy5qi5q/NIH/Nd/UjcDAGP/3R+0x6oI2xqbXoZ5B38TjkhPuR1uLHWN3abQZHdpicn/FhvPRrI4LhfI20TFlmzv7A5jQnwho/KNRgX8fwz+BX9O7W/HZ7+OVjPGw3Lpnv8LcDJFFy0THN3WUkckv8LXKJZpnEfo3aFPL2hauk5c0sBOA3hOhSamdc10OTsuZIRPUIAiBxrIdLFk9bK7slzqaekfW2mqeA5dfc+SowB9P9YZZQiz0m47w5rsjesbTl/RkRRQLNNr X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 21a3b827-4877-4972-b4c5-08db06d30680 X-MS-Exchange-CrossTenant-AuthSource: CY5PR12MB6179.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2023 17:12:42.1115 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 61ey+8cd8gU9Y3i0QEFs+XdER0FWJbphb0R+o+kdyNOqkAadRA5zI2Q/lzjgmJFHS9pR1ky74VIeG/U+KGuWrg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6816 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Given a packet and a remote destination, the function will take care of encapsulating the packet and transmitting it to the destination. Expose it so that it could be used in subsequent patches by the MDB code to transmit a packet to the remote destination(s) stored in the MDB entry. It will allow us to keep the MDB code self-contained, not exposing its data structures to the rest of the VXLAN driver. Signed-off-by: Ido Schimmel --- drivers/net/vxlan/vxlan_core.c | 5 ++--- drivers/net/vxlan/vxlan_private.h | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index a3106abc2b52..f8165e40c247 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -2395,9 +2395,8 @@ static int encap_bypass_if_local(struct sk_buff *skb, struct net_device *dev, return 0; } -static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, - __be32 default_vni, struct vxlan_rdst *rdst, - bool did_rsc) +void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, + __be32 default_vni, struct vxlan_rdst *rdst, bool did_rsc) { struct dst_cache *dst_cache; struct ip_tunnel_info *info; diff --git a/drivers/net/vxlan/vxlan_private.h b/drivers/net/vxlan/vxlan_private.h index 038528f9684a..f4977925cb8a 100644 --- a/drivers/net/vxlan/vxlan_private.h +++ b/drivers/net/vxlan/vxlan_private.h @@ -172,6 +172,8 @@ int vxlan_fdb_update(struct vxlan_dev *vxlan, __be16 port, __be32 src_vni, __be32 vni, __u32 ifindex, __u16 ndm_flags, u32 nhid, bool swdev_notify, struct netlink_ext_ack *extack); +void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, + __be32 default_vni, struct vxlan_rdst *rdst, bool did_rsc); int vxlan_vni_in_use(struct net *src_net, struct vxlan_dev *vxlan, struct vxlan_config *conf, __be32 vni); From patchwork Sat Feb 4 17:07:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 13128831 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC655C61DA4 for ; Sat, 4 Feb 2023 17:13:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232554AbjBDRN2 (ORCPT ); Sat, 4 Feb 2023 12:13:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232568AbjBDRN1 (ORCPT ); Sat, 4 Feb 2023 12:13:27 -0500 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2060.outbound.protection.outlook.com [40.107.96.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2530D36471 for ; Sat, 4 Feb 2023 09:12:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PSYvbzeufF60ffkF6QJaiwMoAdLK2Oiu9rBL8gJ0Qh0ZwA7pNL4babXjWyXgwR4O05I5renaBDSSWQmrRuB4NAInaHDleNcMoWFMcjm1mmmVG1hFnF3jkSh+tFIIeL5tyqO0gg928/CZoK/CgM2PEyl8jW1vSCnsc/xvI041snHUq4elyMUNfmADtaX7xuL6g3RFXM7K5dtlma+U4cWedAMo8pLItXykrdnaLAGqnwKngIyWgdaZzNmsb5wgR1KlXevXa5lSuFzcB2dVbN6yfmzJhap+cdWIc3ULoc6U0G/8/2wtoGc0qhwaIDD1FfPmONGxhxWDzDyISdaCcY9/tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pZYSHmCaoG4j2fFWRbMgJl0+SoxGapBIcuw1/KpNU5A=; b=mRRqRvktRWQhtor8vG7icDGtxCNeT2wtautcop7PJxh8bDcQlSDqQ4k5aEPsNBRYFVLBmU2VbUnnwl227GOwW2kzQbcZ48YiAHcNafn2iB6GeJ9GJjDxj3+d8D7YZsBsXE5IPeoK2Vogrh1KptmipeR7K1LtJekTJOliltq9rB3QtVyEFzfVi3CzsGV8PnoCYG8CKnNEkWIcI7XLk8Hd3lUiMan8Bpw8q9Zu8TmS+hDELk8hla1y/RXW1bNy5jnM3Czc1bo9lUa7NSFjQR+y1fDdFI/Fd5hI1o/ZINwN6IutdG4Z28HWDZQnH6kgPIWjmZ5N5JS6nE05cbA1vnyzJQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pZYSHmCaoG4j2fFWRbMgJl0+SoxGapBIcuw1/KpNU5A=; b=ha7iQQrKB9JW07ILIxR1UgItFVc/uT4xI2tIgIgTsFmgIQMzylQT8483qH8fc9PiPYJI/QEORYfEcEovydLHpwMGpo58IxOjkuqAPv1K3Vgo0X+PePKVNuowzjOBmwhqUnYqvCvH6+GWfIFNZO6Y6gCv4JSPJLPSKWcVMCU62pv/I3nXzq/lNlZ073TDQb7eBUJzInV9RbNiGUuTVedWaUo8JBpdLVDDyoKR/1djZJ5wVzvOHszLWJqTDS2ryQcQRxVdBIgGtk9OA1RiAUtec+1vAGZr5GZOS/TvJmzhmK8Ihj2qika0rXMixWGDvwmLsLgaPf1w97oAm5ftOPoUyg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) by SN7PR12MB6816.namprd12.prod.outlook.com (2603:10b6:806:264::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.31; Sat, 4 Feb 2023 17:12:49 +0000 Received: from CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab]) by CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab%9]) with mapi id 15.20.6064.025; Sat, 4 Feb 2023 17:12:49 +0000 From: Ido Schimmel To: netdev@vger.kernel.org, bridge@lists.linux-foundation.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, razor@blackwall.org, roopa@nvidia.com, petrm@nvidia.com, mlxsw@nvidia.com, Ido Schimmel Subject: [RFC PATCH net-next 10/13] vxlan: mdb: Add MDB control path support Date: Sat, 4 Feb 2023 19:07:58 +0200 Message-Id: <20230204170801.3897900-11-idosch@nvidia.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230204170801.3897900-1-idosch@nvidia.com> References: <20230204170801.3897900-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR0701CA0041.eurprd07.prod.outlook.com (2603:10a6:800:90::27) To CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR12MB6179:EE_|SN7PR12MB6816:EE_ X-MS-Office365-Filtering-Correlation-Id: 1c4dc11c-ad3e-4b72-2554-08db06d30ae9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WdCuxu5UXxJmT98KYkxUJImEt5OCU1NKq/VUGaxOLJSjedZ6+b46EHQqcb8F0SQwmRvRSTPQDqVbAn3C2+xwkfom15LX6O5yd66vtusDc6eS4Hk9YGREDr8/jnpukEuwQkY5UPvM2tZUMTmJ5Jy17qIhvYu7ctVlPvilyzg5hllHqgtNN7Ntuz63GJSzF0FQtHWWiUjjyfPuBCfhHmFosGlYGpTIwJXCmQGMqb5/F/9jkodrw2J+Pyd5wgJddoR87d7OYCtLZqGcGNpPfiPX0Rz9fPLAins20mZQBPNwLzV7Ch4mb88gqLtBfKp5S+ngm/IfNh1Vj/ABt5CsYwYK4UXSwAgFQx6+yT99KnBbDztKAyefJlXrp6ZANRcW61YZEPF+4doDHUPqV+E/M5OQljx3vgNHY3IhPrMLng2xc845IodP6UtDngTUAd9XrVsTgJvbU9psRUfVIlJYBIfsC3URycj0lQ7es3f2Ka4QYn3h0py8AiacewuCF16R9oj2vqbM72xRKbBn+d6t5hN07XiHF+7T6BkVlCQzI+9KvoNTnVG8mihqbka/+vZ4AL1em3gtu5kiyhlN397gJUcatYjFBtp1Jjs44NIHWOK1vby1XLM8zxqyTezN1oSPmAlin9BaxTxmqEwKdnHTUfeWDmYy45wWIv+TcZb1Ywe6D6+EgrwlulmX1F3SO8wAsSPtKzbcJ40ag+KI3GhZneiNSgAZPGlTstjK5y5kArHmBWE= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY5PR12MB6179.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(366004)(346002)(39860400002)(136003)(376002)(396003)(451199018)(8936002)(36756003)(5660300002)(30864003)(107886003)(1076003)(6666004)(316002)(6506007)(478600001)(38100700002)(966005)(6486002)(66476007)(4326008)(8676002)(66946007)(2616005)(83380400001)(66556008)(41300700001)(86362001)(186003)(2906002)(6512007)(26005)(579004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: r30df/1Ne9x37e+xrQ2gzjzGVXWUdSDeHKSd4QGX6jrrkNKpO0TgtcbXbsKN3O4b/e/By3gO7XjIfOKY6sN6J9HTa1qtyGXQIJFxdEul/PDOTdtOIQQUo3juJgj6ezz+9MnqR016mclP8v5xc95laFh3e5VDlDKOA1z7g6cy0OlQfQHMvP6YBvTxxNWOITPVKLDjNEZd137ZG/dmlF2XNn/PG9dRDJ/zgjPGZ2Dqj/NWiCIArzucRGexK9s6gm4LHV0u3Xgg+/XiUXc6YzOjDcqQXFx9YXHkyUwpqyYAy6zcs7zdWnPUCvKY3ZXwOWZ6v1LL6QRe3nYXvu6MOgP6LJzSG3jLoFMo1AgrWrJnNzFZqkZVfEi440ZECKu7L9bKpBWTF76kP6BzYJBPBVffuiqtOQ5plpBT+36/QjmaG5A86ZQOD3B5JOe/xHsKBXgP6OirmIYuBiLCQbmk1fVFjyDDNaHUKIR8eCs5VFKH+H+DNUJi/is7U0oeLYJP39LOMm4OVeU6d8reVe+aayxJw/cBHGveBponzk331HKmvxwVVqYClHW8kIysgbOnPI1Ha8Z9S9ZH6efxfRGyFMZxJR4NppiT7hEV62myD70U4Ggy4RfwDVe1gP+ChQkDXfOUAZTZ68MUyybQncRhbMWujUM3evx7tqEvDpndSTF22vqH7tVezKVOR4XRNc3+EJmqnwf0IjJ5Vk9IX/ELvHo0KEQZ6e04+u2tpTXaX1NQFIQED8PsJIatuLVRoRJvfYOw/7atMAATuT2u+0INDAeKOoFyfduZ09+XPXqVAONu//TdULUdBfM/gv4I0yYXzEIswAHsLGEOiMxWPxJUEZoOhIH/xqHtN8jQ+4DgxmanTOWN1q8AB5snYRTuKUO0ut4At8WMypE/6epgmFJSgBf5WX8hdYKH8ZryOpJilfkg0a7xUgZmrfHM9SoqCIAxnSsfra2PCxLBty2QogSSt+ygml08+tKb2ym2QSEtIHmo5JrPHM+sm/qaVlJNfHRJo//CvCyBoso79YI2b45u7BDVzLdfCBxOCcbkPLZXPhd4VkTUxm381HhoJMunSd8rF9JlOevBXaB+TjpIfw5yL7ybGxHRKiegIfdaWGItaSsVYe0djkxqebNWrp4Xdv62lcPd6VKwQbzWacHoM+S6/1cGwAcqtjCafO6XE8uiSinhzsdsXptQoeJISL/VF+zVgtxbRRIQB14kCKg4k3HSLL5xtc4MTrPZbZ1BdagsLJdWwB2faxJByC9K1Iv4bLem7dobDOH8lW3lZOQFSoufaM/BXYPyxQTTggJF8fn8J7o++K34nFFlPl8sZ/pFl8dI1UHgMcGS7PDgAVYqOs9Rzs/mGD5c34WPEPnK3LscDPoqDc3OWFMwvWEHocuIp/rXw4DCdgLyVaLt6D9sfe2l6OFIEE42Zo04pgO20opLxmdm9QDWxGvb5VpoKhyu5VY9xQLLEM6sYRzdQu+76ENnAoaWf3UZc2jNPXuRDgwrma7C90B/fyikqM9mcLtG3KBglH+sSjAqvu4E9mSXjsX0k3ffT5V8fwh1QUKRiB/5fGsjIBzo9Aymmu5PsYjyOia5vSEG X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1c4dc11c-ad3e-4b72-2554-08db06d30ae9 X-MS-Exchange-CrossTenant-AuthSource: CY5PR12MB6179.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2023 17:12:49.6630 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: +455yyFoEryAvLugBYsHSdm78UCLfVvjqIFwFd7mGG7J0z/z3ziXeX/nJGtogxcJRrUDgF2mQrQIyvFyW/cuNQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6816 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Implement MDB control path support, enabling the creation, deletion, replacement and dumping of MDB entries in a similar fashion to the bridge driver. Unlike the bridge driver, each entry stores a list of remote VTEPs to which matched packets need to be replicated to and not a list of bridge ports. The motivating use case is the installation of MDB entries by a user space control plane in response to received EVPN routes. As such, only allow permanent MDB entries to be installed and do not implement snooping functionality, avoiding a lot of unnecessary complexity. Since entries can only be modified by user space under RTNL, use RTNL as the write lock. Use RCU to ensure that MDB entries and remotes are not freed while being accessed from the data path during transmission. In terms of uAPI, reuse the existing MDB netlink interface, but add a few new attributes to request and response messages: * IP address of the destination VXLAN tunnel endpoint where the multicast receivers reside. * UDP destination port number to use to connect to the remote VXLAN tunnel endpoint. * VXLAN VNI Network Identifier to use to connect to the remote VXLAN tunnel endpoint. Required when Ingress Replication (IR) is used and the remote VTEP is not a member of originating broadcast domain (VLAN/VNI) [1]. * Source VNI Network Identifier the MDB entry belongs to. Used only when the VXLAN device is in external mode. * Interface index of the outgoing interface to reach the remote VXLAN tunnel endpoint. This is required when the underlay destination IP is multicast (P2MP), as the multicast routing tables are not consulted. All the new attributes are added under the 'MDBA_SET_ENTRY_ATTRS' nest which is strictly validated by the bridge driver, thereby automatically rejecting the new attributes. [1] https://datatracker.ietf.org/doc/html/draft-ietf-bess-evpn-irb-mcast#section-3.2.2 Signed-off-by: Ido Schimmel --- drivers/net/vxlan/Makefile | 2 +- drivers/net/vxlan/vxlan_core.c | 8 + drivers/net/vxlan/vxlan_mdb.c | 1363 +++++++++++++++++++++++++++++ drivers/net/vxlan/vxlan_private.h | 31 + include/net/vxlan.h | 5 + include/uapi/linux/if_bridge.h | 10 + 6 files changed, 1418 insertions(+), 1 deletion(-) create mode 100644 drivers/net/vxlan/vxlan_mdb.c diff --git a/drivers/net/vxlan/Makefile b/drivers/net/vxlan/Makefile index d4c255499b72..91b8fec8b6cf 100644 --- a/drivers/net/vxlan/Makefile +++ b/drivers/net/vxlan/Makefile @@ -4,4 +4,4 @@ obj-$(CONFIG_VXLAN) += vxlan.o -vxlan-objs := vxlan_core.o vxlan_multicast.o vxlan_vnifilter.o +vxlan-objs := vxlan_core.o vxlan_multicast.o vxlan_vnifilter.o vxlan_mdb.o diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index f8165e40c247..1c98ddd38bc4 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -2878,8 +2878,14 @@ static int vxlan_init(struct net_device *dev) if (err) goto err_free_percpu; + err = vxlan_mdb_init(vxlan); + if (err) + goto err_gro_cells_destroy; + return 0; +err_gro_cells_destroy: + gro_cells_destroy(&vxlan->gro_cells); err_free_percpu: free_percpu(dev->tstats); err_vnigroup_uninit: @@ -2904,6 +2910,8 @@ static void vxlan_uninit(struct net_device *dev) { struct vxlan_dev *vxlan = netdev_priv(dev); + vxlan_mdb_fini(vxlan); + if (vxlan->cfg.flags & VXLAN_F_VNIFILTER) vxlan_vnigroup_uninit(vxlan); diff --git a/drivers/net/vxlan/vxlan_mdb.c b/drivers/net/vxlan/vxlan_mdb.c new file mode 100644 index 000000000000..079741da2599 --- /dev/null +++ b/drivers/net/vxlan/vxlan_mdb.c @@ -0,0 +1,1363 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "vxlan_private.h" + +struct vxlan_mdb_entry_key { + union vxlan_addr src; + union vxlan_addr dst; + __be32 vni; +}; + +struct vxlan_mdb_entry { + struct rhash_head rhnode; + struct list_head remotes; + struct vxlan_mdb_entry_key key; + struct hlist_node mdb_node; + struct rcu_head rcu; +}; + +#define VXLAN_MDB_REMOTE_F_BLOCKED BIT(0) + +struct vxlan_mdb_remote { + struct list_head list; + struct vxlan_rdst __rcu *rd; + u8 flags; + u8 filter_mode; + u8 rt_protocol; + struct hlist_head src_list; + struct rcu_head rcu; +}; + +#define VXLAN_SGRP_F_DELETE BIT(0) + +struct vxlan_mdb_src_entry { + struct hlist_node node; + union vxlan_addr addr; + u8 flags; +}; + +struct vxlan_mdb_dump_ctx { + long reserved; + long entry_idx; + long remote_idx; +}; + +struct vxlan_mdb_config_src_entry { + union vxlan_addr addr; + struct list_head node; +}; + +struct vxlan_mdb_config { + struct vxlan_dev *vxlan; + struct vxlan_mdb_entry_key group; + struct list_head src_list; + union vxlan_addr remote_ip; + u32 remote_ifindex; + __be32 remote_vni; + __be16 remote_port; + u16 nlflags; + u8 flags; + u8 filter_mode; + u8 rt_protocol; +}; + +static const struct rhashtable_params vxlan_mdb_rht_params = { + .head_offset = offsetof(struct vxlan_mdb_entry, rhnode), + .key_offset = offsetof(struct vxlan_mdb_entry, key), + .key_len = sizeof(struct vxlan_mdb_entry_key), + .automatic_shrinking = true, +}; + +static int __vxlan_mdb_add(const struct vxlan_mdb_config *cfg, + struct netlink_ext_ack *extack); +static int __vxlan_mdb_del(const struct vxlan_mdb_config *cfg, + struct netlink_ext_ack *extack); + +static void vxlan_br_mdb_entry_fill(const struct vxlan_dev *vxlan, + const struct vxlan_mdb_entry *mdb_entry, + const struct vxlan_mdb_remote *remote, + struct br_mdb_entry *e) +{ + const union vxlan_addr *dst = &mdb_entry->key.dst; + + memset(e, 0, sizeof(*e)); + e->ifindex = vxlan->dev->ifindex; + e->state = MDB_PERMANENT; + + if (remote->flags & VXLAN_MDB_REMOTE_F_BLOCKED) + e->flags |= MDB_FLAGS_BLOCKED; + + switch (dst->sa.sa_family) { + case AF_INET: + e->addr.u.ip4 = dst->sin.sin_addr.s_addr; + e->addr.proto = htons(ETH_P_IP); + break; +#if IS_ENABLED(CONFIG_IPV6) + case AF_INET6: + e->addr.u.ip6 = dst->sin6.sin6_addr; + e->addr.proto = htons(ETH_P_IPV6); + break; +#endif + } +} + +static int vxlan_mdb_entry_info_fill_srcs(struct sk_buff *skb, + const struct vxlan_mdb_remote *remote) +{ + struct vxlan_mdb_src_entry *ent; + struct nlattr *nest; + + if (hlist_empty(&remote->src_list)) + return 0; + + nest = nla_nest_start(skb, MDBA_MDB_EATTR_SRC_LIST); + if (!nest) + return -EMSGSIZE; + + hlist_for_each_entry(ent, &remote->src_list, node) { + struct nlattr *nest_ent; + + nest_ent = nla_nest_start(skb, MDBA_MDB_SRCLIST_ENTRY); + if (!nest_ent) + goto out_cancel_err; + + if (vxlan_nla_put_addr(skb, MDBA_MDB_SRCATTR_ADDRESS, + &ent->addr) || + nla_put_u32(skb, MDBA_MDB_SRCATTR_TIMER, 0)) + goto out_cancel_err; + + nla_nest_end(skb, nest_ent); + } + + nla_nest_end(skb, nest); + + return 0; + +out_cancel_err: + nla_nest_cancel(skb, nest); + return -EMSGSIZE; +} + +static int vxlan_mdb_entry_info_fill(const struct vxlan_dev *vxlan, + struct sk_buff *skb, + const struct vxlan_mdb_entry *mdb_entry, + const struct vxlan_mdb_remote *remote) +{ + struct vxlan_rdst *rd = rtnl_dereference(remote->rd); + struct br_mdb_entry e; + struct nlattr *nest; + + nest = nla_nest_start_noflag(skb, MDBA_MDB_ENTRY_INFO); + if (!nest) + return -EMSGSIZE; + + vxlan_br_mdb_entry_fill(vxlan, mdb_entry, remote, &e); + + if (nla_put_nohdr(skb, sizeof(e), &e) || + nla_put_u32(skb, MDBA_MDB_EATTR_TIMER, 0)) + goto nest_err; + + if (!vxlan_addr_any(&mdb_entry->key.src) && + vxlan_nla_put_addr(skb, MDBA_MDB_EATTR_SOURCE, &mdb_entry->key.src)) + goto nest_err; + + if (nla_put_u8(skb, MDBA_MDB_EATTR_RTPROT, remote->rt_protocol) || + nla_put_u8(skb, MDBA_MDB_EATTR_GROUP_MODE, remote->filter_mode) || + vxlan_mdb_entry_info_fill_srcs(skb, remote) || + vxlan_nla_put_addr(skb, MDBA_MDB_EATTR_DST, &rd->remote_ip)) + goto nest_err; + + if (rd->remote_port && rd->remote_port != vxlan->cfg.dst_port && + nla_put_u16(skb, MDBA_MDB_EATTR_DST_PORT, + be16_to_cpu(rd->remote_port))) + goto nest_err; + + if (rd->remote_vni != vxlan->default_dst.remote_vni && + nla_put_u32(skb, MDBA_MDB_EATTR_VNI, be32_to_cpu(rd->remote_vni))) + goto nest_err; + + if (rd->remote_ifindex && + nla_put_u32(skb, MDBA_MDB_EATTR_IFINDEX, rd->remote_ifindex)) + goto nest_err; + + if ((vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA) && + mdb_entry->key.vni && nla_put_u32(skb, MDBA_MDB_EATTR_SRC_VNI, + be32_to_cpu(mdb_entry->key.vni))) + goto nest_err; + + nla_nest_end(skb, nest); + + return 0; + +nest_err: + nla_nest_cancel(skb, nest); + return -EMSGSIZE; +} + +static int vxlan_mdb_entry_fill(const struct vxlan_dev *vxlan, + struct sk_buff *skb, + struct vxlan_mdb_dump_ctx *ctx, + const struct vxlan_mdb_entry *mdb_entry) +{ + int remote_idx = 0, s_remote_idx = ctx->remote_idx; + struct vxlan_mdb_remote *remote; + struct nlattr *nest; + int err = 0; + + nest = nla_nest_start_noflag(skb, MDBA_MDB_ENTRY); + if (!nest) + return -EMSGSIZE; + + list_for_each_entry(remote, &mdb_entry->remotes, list) { + if (remote_idx < s_remote_idx) + goto skip; + + err = vxlan_mdb_entry_info_fill(vxlan, skb, mdb_entry, remote); + if (err) + break; +skip: + remote_idx++; + } + + ctx->remote_idx = err ? remote_idx : 0; + nla_nest_end(skb, nest); + return err; +} + +static int vxlan_mdb_fill(const struct vxlan_dev *vxlan, struct sk_buff *skb, + struct vxlan_mdb_dump_ctx *ctx) +{ + int entry_idx = 0, s_entry_idx = ctx->entry_idx; + struct vxlan_mdb_entry *mdb_entry; + struct nlattr *nest; + int err = 0; + + nest = nla_nest_start_noflag(skb, MDBA_MDB); + if (!nest) + return -EMSGSIZE; + + hlist_for_each_entry(mdb_entry, &vxlan->mdb_list, mdb_node) { + if (entry_idx < s_entry_idx) + goto skip; + + err = vxlan_mdb_entry_fill(vxlan, skb, ctx, mdb_entry); + if (err) + break; +skip: + entry_idx++; + } + + ctx->entry_idx = err ? entry_idx : 0; + nla_nest_end(skb, nest); + return err; +} + +int vxlan_mdb_dump(struct net_device *dev, struct sk_buff *skb, + struct netlink_callback *cb) +{ + struct vxlan_mdb_dump_ctx *ctx = (void *)cb->ctx; + struct vxlan_dev *vxlan = netdev_priv(dev); + struct br_port_msg *bpm; + struct nlmsghdr *nlh; + int err; + + ASSERT_RTNL(); + + NL_ASSERT_DUMP_CTX_FITS(struct vxlan_mdb_dump_ctx); + + nlh = nlmsg_put(skb, NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, RTM_NEWMDB, sizeof(*bpm), + NLM_F_MULTI); + if (!nlh) + return -EMSGSIZE; + + bpm = nlmsg_data(nlh); + memset(bpm, 0, sizeof(*bpm)); + bpm->family = AF_BRIDGE; + bpm->ifindex = dev->ifindex; + + err = vxlan_mdb_fill(vxlan, skb, ctx); + + nlmsg_end(skb, nlh); + + cb->seq = vxlan->mdb_seq; + nl_dump_check_consistent(cb, nlh); + + return err; +} + +static const struct nla_policy +vxlan_mdbe_src_list_entry_pol[MDBE_SRCATTR_MAX + 1] = { + [MDBE_SRCATTR_ADDRESS] = NLA_POLICY_RANGE(NLA_BINARY, + sizeof(struct in_addr), + sizeof(struct in6_addr)), +}; + +static const struct nla_policy +vxlan_mdbe_src_list_pol[MDBE_SRC_LIST_MAX + 1] = { + [MDBE_SRC_LIST_ENTRY] = NLA_POLICY_NESTED(vxlan_mdbe_src_list_entry_pol), +}; + +static struct netlink_range_validation vni_range = { + .max = VXLAN_N_VID - 1, +}; + +static const struct nla_policy vxlan_mdbe_attrs_pol[MDBE_ATTR_MAX + 1] = { + [MDBE_ATTR_SOURCE] = NLA_POLICY_RANGE(NLA_BINARY, + sizeof(struct in_addr), + sizeof(struct in6_addr)), + [MDBE_ATTR_GROUP_MODE] = NLA_POLICY_RANGE(NLA_U8, MCAST_EXCLUDE, + MCAST_INCLUDE), + [MDBE_ATTR_SRC_LIST] = NLA_POLICY_NESTED(vxlan_mdbe_src_list_pol), + [MDBE_ATTR_RTPROT] = NLA_POLICY_MIN(NLA_U8, RTPROT_STATIC), + [MDBE_ATTR_DST] = NLA_POLICY_RANGE(NLA_BINARY, + sizeof(struct in_addr), + sizeof(struct in6_addr)), + [MDBE_ATTR_DST_PORT] = { .type = NLA_U16 }, + [MDBE_ATTR_VNI] = NLA_POLICY_FULL_RANGE(NLA_U32, &vni_range), + [MDBE_ATTR_IFINDEX] = NLA_POLICY_MIN(NLA_S32, 1), + [MDBE_ATTR_SRC_VNI] = NLA_POLICY_FULL_RANGE(NLA_U32, &vni_range), +}; + +static bool vxlan_mdb_is_valid_source(const struct nlattr *attr, __be16 proto, + struct netlink_ext_ack *extack) +{ + switch (proto) { + case htons(ETH_P_IP): + if (nla_len(attr) != sizeof(struct in_addr)) { + NL_SET_ERR_MSG_MOD(extack, "IPv4 invalid source address length"); + return false; + } + if (ipv4_is_multicast(nla_get_in_addr(attr))) { + NL_SET_ERR_MSG_MOD(extack, "IPv4 multicast source address is not allowed"); + return false; + } + break; +#if IS_ENABLED(CONFIG_IPV6) + case htons(ETH_P_IPV6): { + struct in6_addr src; + + if (nla_len(attr) != sizeof(struct in6_addr)) { + NL_SET_ERR_MSG_MOD(extack, "IPv6 invalid source address length"); + return false; + } + src = nla_get_in6_addr(attr); + if (ipv6_addr_is_multicast(&src)) { + NL_SET_ERR_MSG_MOD(extack, "IPv6 multicast source address is not allowed"); + return false; + } + break; + } +#endif + default: + NL_SET_ERR_MSG_MOD(extack, "Invalid protocol used with source address"); + return false; + } + + return true; +} + +static void vxlan_mdb_config_group_set(struct vxlan_mdb_config *cfg, + const struct br_mdb_entry *entry, + const struct nlattr *source_attr) +{ + struct vxlan_mdb_entry_key *group = &cfg->group; + + switch (entry->addr.proto) { + case htons(ETH_P_IP): + group->dst.sa.sa_family = AF_INET; + group->dst.sin.sin_addr.s_addr = entry->addr.u.ip4; + break; +#if IS_ENABLED(CONFIG_IPV6) + case htons(ETH_P_IPV6): + group->dst.sa.sa_family = AF_INET6; + group->dst.sin6.sin6_addr = entry->addr.u.ip6; + break; +#endif + } + + if (source_attr) + vxlan_nla_get_addr(&group->src, source_attr); +} + +static bool vxlan_mdb_is_star_g(const struct vxlan_mdb_entry_key *group) +{ + return !vxlan_addr_any(&group->dst) && vxlan_addr_any(&group->src); +} + +static bool vxlan_mdb_is_sg(const struct vxlan_mdb_entry_key *group) +{ + return !vxlan_addr_any(&group->dst) && !vxlan_addr_any(&group->src); +} + +static bool vxlan_mdb_is_all_zeros(const struct vxlan_mdb_entry_key *group) +{ + return vxlan_addr_any(&group->dst) && vxlan_addr_any(&group->src); +} + +static int vxlan_mdb_config_src_entry_init(struct vxlan_mdb_config *cfg, + __be16 proto, + const struct nlattr *src_entry, + struct netlink_ext_ack *extack) +{ + struct nlattr *tb[MDBE_SRCATTR_MAX + 1]; + struct vxlan_mdb_config_src_entry *src; + int err; + + err = nla_parse_nested(tb, MDBE_SRCATTR_MAX, src_entry, + vxlan_mdbe_src_list_entry_pol, extack); + if (err) + return err; + + if (NL_REQ_ATTR_CHECK(extack, src_entry, tb, MDBE_SRCATTR_ADDRESS)) + return -EINVAL; + + if (!vxlan_mdb_is_valid_source(tb[MDBE_SRCATTR_ADDRESS], proto, + extack)) + return -EINVAL; + + src = kzalloc(sizeof(*src), GFP_KERNEL); + if (!src) + return -ENOMEM; + + err = vxlan_nla_get_addr(&src->addr, tb[MDBE_SRCATTR_ADDRESS]); + if (err) + goto err_free_src; + + list_add_tail(&src->node, &cfg->src_list); + + return 0; + +err_free_src: + kfree(src); + return err; +} + +static void +vxlan_mdb_config_src_entry_fini(struct vxlan_mdb_config_src_entry *src) +{ + list_del(&src->node); + kfree(src); +} + +static int vxlan_mdb_config_src_list_init(struct vxlan_mdb_config *cfg, + __be16 proto, + const struct nlattr *src_list, + struct netlink_ext_ack *extack) +{ + struct vxlan_mdb_config_src_entry *src, *tmp; + struct nlattr *src_entry; + int rem, err; + + nla_for_each_nested(src_entry, src_list, rem) { + err = vxlan_mdb_config_src_entry_init(cfg, proto, src_entry, + extack); + if (err) + goto err_src_entry_init; + } + + return 0; + +err_src_entry_init: + list_for_each_entry_safe_reverse(src, tmp, &cfg->src_list, node) + vxlan_mdb_config_src_entry_fini(src); + return err; +} + +static void vxlan_mdb_config_src_list_fini(struct vxlan_mdb_config *cfg) +{ + struct vxlan_mdb_config_src_entry *src, *tmp; + + list_for_each_entry_safe_reverse(src, tmp, &cfg->src_list, node) + vxlan_mdb_config_src_entry_fini(src); +} + +static int vxlan_mdb_config_attrs_init(struct vxlan_mdb_config *cfg, + const struct br_mdb_entry *entry, + const struct nlattr *set_attrs, + struct netlink_ext_ack *extack) +{ + struct nlattr *mdbe_attrs[MDBE_ATTR_MAX + 1]; + int err; + + err = nla_parse_nested(mdbe_attrs, MDBE_ATTR_MAX, set_attrs, + vxlan_mdbe_attrs_pol, extack); + if (err) + return err; + + if (NL_REQ_ATTR_CHECK(extack, set_attrs, mdbe_attrs, MDBE_ATTR_DST)) { + NL_SET_ERR_MSG_MOD(extack, "Missing remote destination IP address"); + return -EINVAL; + } + + if (mdbe_attrs[MDBE_ATTR_SOURCE] && + !vxlan_mdb_is_valid_source(mdbe_attrs[MDBE_ATTR_SOURCE], + entry->addr.proto, extack)) + return -EINVAL; + + vxlan_mdb_config_group_set(cfg, entry, mdbe_attrs[MDBE_ATTR_SOURCE]); + + /* rtnetlink code only validates that IPv4 group address is + * multicast. + */ + if (!vxlan_addr_is_multicast(&cfg->group.dst) && + !vxlan_addr_any(&cfg->group.dst)) { + NL_SET_ERR_MSG_MOD(extack, "Group address is not multicast"); + return -EINVAL; + } + + if (vxlan_mdb_is_all_zeros(&cfg->group) && + mdbe_attrs[MDBE_ATTR_SOURCE]) { + NL_SET_ERR_MSG_MOD(extack, "Source cannot be specified for the all-zeros entry"); + return -EINVAL; + } + + if (vxlan_mdb_is_sg(&cfg->group)) + cfg->filter_mode = MCAST_INCLUDE; + + if (mdbe_attrs[MDBE_ATTR_GROUP_MODE]) { + if (!vxlan_mdb_is_star_g(&cfg->group)) { + NL_SET_ERR_MSG_MOD(extack, "Filter mode can only be set for (*, G) entries"); + return -EINVAL; + } + cfg->filter_mode = nla_get_u8(mdbe_attrs[MDBE_ATTR_GROUP_MODE]); + } + + if (mdbe_attrs[MDBE_ATTR_SRC_LIST]) { + if (!vxlan_mdb_is_star_g(&cfg->group)) { + NL_SET_ERR_MSG_MOD(extack, "Source list can only be set for (*, G) entries"); + return -EINVAL; + } + if (!mdbe_attrs[MDBE_ATTR_GROUP_MODE]) { + NL_SET_ERR_MSG_MOD(extack, "Source list cannot be set without filter mode"); + return -EINVAL; + } + err = vxlan_mdb_config_src_list_init(cfg, entry->addr.proto, + mdbe_attrs[MDBE_ATTR_SRC_LIST], + extack); + if (err) + return err; + } + + if (vxlan_mdb_is_star_g(&cfg->group) && list_empty(&cfg->src_list) && + cfg->filter_mode == MCAST_INCLUDE) { + NL_SET_ERR_MSG_MOD(extack, "Cannot add (*, G) INCLUDE with an empty source list"); + return -EINVAL; + } + + if (mdbe_attrs[MDBE_ATTR_RTPROT]) + cfg->rt_protocol = nla_get_u8(mdbe_attrs[MDBE_ATTR_RTPROT]); + + err = vxlan_nla_get_addr(&cfg->remote_ip, mdbe_attrs[MDBE_ATTR_DST]); + if (err) { + NL_SET_ERR_MSG_MOD(extack, "Invalid remote destination address"); + goto err_src_list_fini; + } + + if (mdbe_attrs[MDBE_ATTR_DST_PORT]) + cfg->remote_port = + cpu_to_be16(nla_get_u16(mdbe_attrs[MDBE_ATTR_DST_PORT])); + + if (mdbe_attrs[MDBE_ATTR_VNI]) + cfg->remote_vni = + cpu_to_be32(nla_get_u32(mdbe_attrs[MDBE_ATTR_VNI])); + + if (mdbe_attrs[MDBE_ATTR_IFINDEX]) { + cfg->remote_ifindex = + nla_get_s32(mdbe_attrs[MDBE_ATTR_IFINDEX]); + if (!__dev_get_by_index(cfg->vxlan->net, cfg->remote_ifindex)) { + NL_SET_ERR_MSG_MOD(extack, "Outgoing interface not found"); + err = -EINVAL; + goto err_src_list_fini; + } + } + + if (mdbe_attrs[MDBE_ATTR_SRC_VNI]) + cfg->group.vni = + cpu_to_be32(nla_get_u32(mdbe_attrs[MDBE_ATTR_SRC_VNI])); + + return 0; + +err_src_list_fini: + vxlan_mdb_config_src_list_fini(cfg); + return err; +} + +static int vxlan_mdb_config_init(struct vxlan_mdb_config *cfg, + struct net_device *dev, struct nlattr *tb[], + u16 nlmsg_flags, + struct netlink_ext_ack *extack) +{ + struct br_mdb_entry *entry = nla_data(tb[MDBA_SET_ENTRY]); + struct vxlan_dev *vxlan = netdev_priv(dev); + + memset(cfg, 0, sizeof(*cfg)); + cfg->vxlan = vxlan; + cfg->group.vni = vxlan->default_dst.remote_vni; + INIT_LIST_HEAD(&cfg->src_list); + cfg->nlflags = nlmsg_flags; + cfg->filter_mode = MCAST_EXCLUDE; + cfg->rt_protocol = RTPROT_STATIC; + cfg->remote_vni = vxlan->default_dst.remote_vni; + cfg->remote_port = vxlan->cfg.dst_port; + + if (entry->ifindex != dev->ifindex) { + NL_SET_ERR_MSG_MOD(extack, "Port net device must be the VXLAN net device"); + return -EINVAL; + } + + /* State is not part of the entry key and can be ignored on deletion + * requests. + */ + if ((nlmsg_flags & (NLM_F_CREATE | NLM_F_REPLACE)) && + entry->state != MDB_PERMANENT) { + NL_SET_ERR_MSG_MOD(extack, "MDB entry must be permanent"); + return -EINVAL; + } + + if (entry->flags) { + NL_SET_ERR_MSG_MOD(extack, "Invalid MDB entry flags"); + return -EINVAL; + } + + if (entry->vid) { + NL_SET_ERR_MSG_MOD(extack, "VID must not be specified"); + return -EINVAL; + } + + if (entry->addr.proto != htons(ETH_P_IP) && + entry->addr.proto != htons(ETH_P_IPV6)) { + NL_SET_ERR_MSG_MOD(extack, "Group address must be an IPv4 / IPv6 address"); + return -EINVAL; + } + + if (NL_REQ_ATTR_CHECK(extack, NULL, tb, MDBA_SET_ENTRY_ATTRS)) { + NL_SET_ERR_MSG_MOD(extack, "Missing MDBA_SET_ENTRY_ATTRS attribute"); + return -EINVAL; + } + + return vxlan_mdb_config_attrs_init(cfg, entry, tb[MDBA_SET_ENTRY_ATTRS], + extack); +} + +static void vxlan_mdb_config_fini(struct vxlan_mdb_config *cfg) +{ + vxlan_mdb_config_src_list_fini(cfg); +} + +static struct vxlan_mdb_entry * +vxlan_mdb_entry_lookup(struct vxlan_dev *vxlan, + const struct vxlan_mdb_entry_key *group) +{ + return rhashtable_lookup_fast(&vxlan->mdb_tbl, group, + vxlan_mdb_rht_params); +} + +static struct vxlan_mdb_remote * +vxlan_mdb_remote_lookup(const struct vxlan_mdb_entry *mdb_entry, + const union vxlan_addr *addr) +{ + struct vxlan_mdb_remote *remote; + + list_for_each_entry(remote, &mdb_entry->remotes, list) { + struct vxlan_rdst *rd = rtnl_dereference(remote->rd); + + if (vxlan_addr_equal(addr, &rd->remote_ip)) + return remote; + } + + return NULL; +} + +static void vxlan_mdb_rdst_free(struct rcu_head *head) +{ + struct vxlan_rdst *rd = container_of(head, struct vxlan_rdst, rcu); + + dst_cache_destroy(&rd->dst_cache); + kfree(rd); +} + +static int vxlan_mdb_remote_rdst_init(const struct vxlan_mdb_config *cfg, + struct vxlan_mdb_remote *remote) +{ + struct vxlan_rdst *rd; + int err; + + rd = kzalloc(sizeof(*rd), GFP_KERNEL); + if (!rd) + return -ENOMEM; + + err = dst_cache_init(&rd->dst_cache, GFP_KERNEL); + if (err) + goto err_free_rdst; + + rd->remote_ip = cfg->remote_ip; + rd->remote_port = cfg->remote_port; + rd->remote_vni = cfg->remote_vni; + rd->remote_ifindex = cfg->remote_ifindex; + rcu_assign_pointer(remote->rd, rd); + + return 0; + +err_free_rdst: + kfree(rd); + return err; +} + +static void vxlan_mdb_remote_rdst_fini(struct vxlan_rdst *rd) +{ + call_rcu(&rd->rcu, vxlan_mdb_rdst_free); +} + +static int vxlan_mdb_remote_init(const struct vxlan_mdb_config *cfg, + struct vxlan_mdb_remote *remote) +{ + int err; + + err = vxlan_mdb_remote_rdst_init(cfg, remote); + if (err) + return err; + + remote->flags = cfg->flags; + remote->filter_mode = cfg->filter_mode; + remote->rt_protocol = cfg->rt_protocol; + INIT_HLIST_HEAD(&remote->src_list); + + return 0; +} + +static void vxlan_mdb_remote_fini(struct vxlan_dev *vxlan, + struct vxlan_mdb_remote *remote) +{ + WARN_ON_ONCE(!hlist_empty(&remote->src_list)); + vxlan_mdb_remote_rdst_fini(rtnl_dereference(remote->rd)); +} + +static struct vxlan_mdb_src_entry * +vxlan_mdb_remote_src_entry_lookup(const struct vxlan_mdb_remote *remote, + const union vxlan_addr *addr) +{ + struct vxlan_mdb_src_entry *ent; + + hlist_for_each_entry(ent, &remote->src_list, node) { + if (vxlan_addr_equal(&ent->addr, addr)) + return ent; + } + + return NULL; +} + +static struct vxlan_mdb_src_entry * +vxlan_mdb_remote_src_entry_add(struct vxlan_mdb_remote *remote, + const union vxlan_addr *addr) +{ + struct vxlan_mdb_src_entry *ent; + + ent = kzalloc(sizeof(*ent), GFP_KERNEL); + if (!ent) + return NULL; + + ent->addr = *addr; + hlist_add_head(&ent->node, &remote->src_list); + + return ent; +} + +static void +vxlan_mdb_remote_src_entry_del(struct vxlan_mdb_src_entry *ent) +{ + hlist_del(&ent->node); + kfree(ent); +} + +static int +vxlan_mdb_remote_src_fwd_add(const struct vxlan_mdb_config *cfg, + const union vxlan_addr *addr, + struct netlink_ext_ack *extack) +{ + struct vxlan_mdb_config sg_cfg; + + memset(&sg_cfg, 0, sizeof(sg_cfg)); + sg_cfg.vxlan = cfg->vxlan; + sg_cfg.group.src = *addr; + sg_cfg.group.dst = cfg->group.dst; + sg_cfg.group.vni = cfg->group.vni; + INIT_LIST_HEAD(&sg_cfg.src_list); + sg_cfg.remote_ip = cfg->remote_ip; + sg_cfg.remote_ifindex = cfg->remote_ifindex; + sg_cfg.remote_vni = cfg->remote_vni; + sg_cfg.remote_port = cfg->remote_port; + sg_cfg.nlflags = cfg->nlflags; + sg_cfg.filter_mode = MCAST_INCLUDE; + if (cfg->filter_mode == MCAST_EXCLUDE) + sg_cfg.flags = VXLAN_MDB_REMOTE_F_BLOCKED; + sg_cfg.rt_protocol = cfg->rt_protocol; + + return __vxlan_mdb_add(&sg_cfg, extack); +} + +static void +vxlan_mdb_remote_src_fwd_del(struct vxlan_dev *vxlan, + const struct vxlan_mdb_entry_key *group, + const struct vxlan_mdb_remote *remote, + const union vxlan_addr *addr) +{ + struct vxlan_rdst *rd = rtnl_dereference(remote->rd); + struct vxlan_mdb_config sg_cfg; + + memset(&sg_cfg, 0, sizeof(sg_cfg)); + sg_cfg.vxlan = vxlan; + sg_cfg.group.src = *addr; + sg_cfg.group.dst = group->dst; + sg_cfg.group.vni = group->vni; + INIT_LIST_HEAD(&sg_cfg.src_list); + sg_cfg.remote_ip = rd->remote_ip; + + __vxlan_mdb_del(&sg_cfg, NULL); +} + +static int +vxlan_mdb_remote_src_add(const struct vxlan_mdb_config *cfg, + struct vxlan_mdb_remote *remote, + const struct vxlan_mdb_config_src_entry *src, + struct netlink_ext_ack *extack) +{ + struct vxlan_mdb_src_entry *ent; + int err; + + ent = vxlan_mdb_remote_src_entry_lookup(remote, &src->addr); + if (!ent) { + ent = vxlan_mdb_remote_src_entry_add(remote, &src->addr); + if (!ent) + return -ENOMEM; + } else if (!(cfg->nlflags & NLM_F_REPLACE)) { + NL_SET_ERR_MSG_MOD(extack, "Source entry already exists"); + return -EEXIST; + } + + err = vxlan_mdb_remote_src_fwd_add(cfg, &ent->addr, extack); + if (err) + goto err_src_del; + + /* Clear flags in case source entry was marked for deletion as part of + * replace flow. + */ + ent->flags = 0; + + return 0; + +err_src_del: + vxlan_mdb_remote_src_entry_del(ent); + return err; +} + +static void vxlan_mdb_remote_src_del(struct vxlan_dev *vxlan, + const struct vxlan_mdb_entry_key *group, + const struct vxlan_mdb_remote *remote, + struct vxlan_mdb_src_entry *ent) +{ + vxlan_mdb_remote_src_fwd_del(vxlan, group, remote, &ent->addr); + vxlan_mdb_remote_src_entry_del(ent); +} + +static int vxlan_mdb_remote_srcs_add(const struct vxlan_mdb_config *cfg, + struct vxlan_mdb_remote *remote, + struct netlink_ext_ack *extack) +{ + struct vxlan_mdb_config_src_entry *src; + struct vxlan_mdb_src_entry *ent; + struct hlist_node *tmp; + int err; + + list_for_each_entry(src, &cfg->src_list, node) { + err = vxlan_mdb_remote_src_add(cfg, remote, src, extack); + if (err) + goto err_src_del; + } + + return 0; + +err_src_del: + hlist_for_each_entry_safe(ent, tmp, &remote->src_list, node) + vxlan_mdb_remote_src_del(cfg->vxlan, &cfg->group, remote, ent); + return err; +} + +static void vxlan_mdb_remote_srcs_del(struct vxlan_dev *vxlan, + const struct vxlan_mdb_entry_key *group, + struct vxlan_mdb_remote *remote) +{ + struct vxlan_mdb_src_entry *ent; + struct hlist_node *tmp; + + hlist_for_each_entry_safe(ent, tmp, &remote->src_list, node) + vxlan_mdb_remote_src_del(vxlan, group, remote, ent); +} + +static size_t +vxlan_mdb_nlmsg_src_list_size(const struct vxlan_mdb_entry_key *group, + const struct vxlan_mdb_remote *remote) +{ + struct vxlan_mdb_src_entry *ent; + size_t nlmsg_size; + + if (hlist_empty(&remote->src_list)) + return 0; + + /* MDBA_MDB_EATTR_SRC_LIST */ + nlmsg_size = nla_total_size(0); + + hlist_for_each_entry(ent, &remote->src_list, node) { + /* MDBA_MDB_SRCLIST_ENTRY */ + nlmsg_size += nla_total_size(0) + + /* MDBA_MDB_SRCATTR_ADDRESS */ + nla_total_size(vxlan_addr_size(&group->dst)) + + /* MDBA_MDB_SRCATTR_TIMER */ + nla_total_size(sizeof(u8)); + } + + return nlmsg_size; +} + +static size_t vxlan_mdb_nlmsg_size(const struct vxlan_dev *vxlan, + const struct vxlan_mdb_entry *mdb_entry, + const struct vxlan_mdb_remote *remote) +{ + const struct vxlan_mdb_entry_key *group = &mdb_entry->key; + struct vxlan_rdst *rd = rtnl_dereference(remote->rd); + size_t nlmsg_size; + + nlmsg_size = NLMSG_ALIGN(sizeof(struct br_port_msg)) + + /* MDBA_MDB */ + nla_total_size(0) + + /* MDBA_MDB_ENTRY */ + nla_total_size(0) + + /* MDBA_MDB_ENTRY_INFO */ + nla_total_size(sizeof(struct br_mdb_entry)) + + /* MDBA_MDB_EATTR_TIMER */ + nla_total_size(sizeof(u32)); + /* MDBA_MDB_EATTR_SOURCE */ + if (vxlan_mdb_is_sg(group)) + nlmsg_size += nla_total_size(vxlan_addr_size(&group->dst)); + /* MDBA_MDB_EATTR_RTPROT */ + nlmsg_size += nla_total_size(sizeof(u8)); + /* MDBA_MDB_EATTR_SRC_LIST */ + nlmsg_size += vxlan_mdb_nlmsg_src_list_size(group, remote); + /* MDBA_MDB_EATTR_GROUP_MODE */ + nlmsg_size += nla_total_size(sizeof(u8)); + /* MDBA_MDB_EATTR_DST */ + nlmsg_size += nla_total_size(vxlan_addr_size(&rd->remote_ip)); + /* MDBA_MDB_EATTR_DST_PORT */ + if (rd->remote_port && rd->remote_port != vxlan->cfg.dst_port) + nlmsg_size += nla_total_size(sizeof(u16)); + /* MDBA_MDB_EATTR_VNI */ + if (rd->remote_vni != vxlan->default_dst.remote_vni) + nlmsg_size += nla_total_size(sizeof(u32)); + /* MDBA_MDB_EATTR_IFINDEX */ + if (rd->remote_ifindex) + nlmsg_size += nla_total_size(sizeof(u32)); + /* MDBA_MDB_EATTR_SRC_VNI */ + if ((vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA) && group->vni) + nlmsg_size += nla_total_size(sizeof(u32)); + + return nlmsg_size; +} + +static int vxlan_mdb_nlmsg_fill(const struct vxlan_dev *vxlan, + struct sk_buff *skb, + const struct vxlan_mdb_entry *mdb_entry, + const struct vxlan_mdb_remote *remote, + int type) +{ + struct nlattr *mdb_nest, *mdb_entry_nest; + struct br_port_msg *bpm; + struct nlmsghdr *nlh; + + nlh = nlmsg_put(skb, 0, 0, type, sizeof(*bpm), 0); + if (!nlh) + return -EMSGSIZE; + + bpm = nlmsg_data(nlh); + memset(bpm, 0, sizeof(*bpm)); + bpm->family = AF_BRIDGE; + bpm->ifindex = vxlan->dev->ifindex; + + mdb_nest = nla_nest_start_noflag(skb, MDBA_MDB); + if (!mdb_nest) + goto cancel; + mdb_entry_nest = nla_nest_start_noflag(skb, MDBA_MDB_ENTRY); + if (!mdb_entry_nest) + goto cancel; + + if (vxlan_mdb_entry_info_fill(vxlan, skb, mdb_entry, remote)) + goto cancel; + + nla_nest_end(skb, mdb_entry_nest); + nla_nest_end(skb, mdb_nest); + nlmsg_end(skb, nlh); + + return 0; + +cancel: + nlmsg_cancel(skb, nlh); + return -EMSGSIZE; +} + +static void vxlan_mdb_remote_notify(const struct vxlan_dev *vxlan, + const struct vxlan_mdb_entry *mdb_entry, + const struct vxlan_mdb_remote *remote, + int type) +{ + struct net *net = dev_net(vxlan->dev); + struct sk_buff *skb; + int err = -ENOBUFS; + + skb = nlmsg_new(vxlan_mdb_nlmsg_size(vxlan, mdb_entry, remote), + GFP_KERNEL); + if (!skb) + goto errout; + + err = vxlan_mdb_nlmsg_fill(vxlan, skb, mdb_entry, remote, type); + if (err) { + kfree_skb(skb); + goto errout; + } + + rtnl_notify(skb, net, 0, RTNLGRP_MDB, NULL, GFP_KERNEL); + return; +errout: + rtnl_set_sk_err(net, RTNLGRP_MDB, err); +} + +static int +vxlan_mdb_remote_srcs_replace(const struct vxlan_mdb_config *cfg, + const struct vxlan_mdb_entry *mdb_entry, + struct vxlan_mdb_remote *remote, + struct netlink_ext_ack *extack) +{ + struct vxlan_dev *vxlan = cfg->vxlan; + struct vxlan_mdb_src_entry *ent; + struct hlist_node *tmp; + int err; + + hlist_for_each_entry(ent, &remote->src_list, node) + ent->flags |= VXLAN_SGRP_F_DELETE; + + err = vxlan_mdb_remote_srcs_add(cfg, remote, extack); + if (err) + goto err_clear_delete; + + hlist_for_each_entry_safe(ent, tmp, &remote->src_list, node) { + if (ent->flags & VXLAN_SGRP_F_DELETE) + vxlan_mdb_remote_src_del(vxlan, &mdb_entry->key, remote, + ent); + } + + return 0; + +err_clear_delete: + hlist_for_each_entry(ent, &remote->src_list, node) + ent->flags &= ~VXLAN_SGRP_F_DELETE; + return err; +} + +static int vxlan_mdb_remote_replace(const struct vxlan_mdb_config *cfg, + const struct vxlan_mdb_entry *mdb_entry, + struct vxlan_mdb_remote *remote, + struct netlink_ext_ack *extack) +{ + struct vxlan_rdst *new_rd, *old_rd = rtnl_dereference(remote->rd); + struct vxlan_dev *vxlan = cfg->vxlan; + int err; + + err = vxlan_mdb_remote_rdst_init(cfg, remote); + if (err) + return err; + new_rd = rtnl_dereference(remote->rd); + + err = vxlan_mdb_remote_srcs_replace(cfg, mdb_entry, remote, extack); + if (err) + goto err_rdst_reset; + + WRITE_ONCE(remote->flags, cfg->flags); + WRITE_ONCE(remote->filter_mode, cfg->filter_mode); + remote->rt_protocol = cfg->rt_protocol; + vxlan_mdb_remote_notify(vxlan, mdb_entry, remote, RTM_NEWMDB); + + vxlan_mdb_remote_rdst_fini(old_rd); + + return 0; + +err_rdst_reset: + rcu_assign_pointer(remote->rd, old_rd); + vxlan_mdb_remote_rdst_fini(new_rd); + return err; +} + +static int vxlan_mdb_remote_add(const struct vxlan_mdb_config *cfg, + struct vxlan_mdb_entry *mdb_entry, + struct netlink_ext_ack *extack) +{ + struct vxlan_mdb_remote *remote; + int err; + + remote = vxlan_mdb_remote_lookup(mdb_entry, &cfg->remote_ip); + if (remote) { + if (!(cfg->nlflags & NLM_F_REPLACE)) { + NL_SET_ERR_MSG_MOD(extack, "Replace not specified and MDB remote entry already exists"); + return -EEXIST; + } + return vxlan_mdb_remote_replace(cfg, mdb_entry, remote, extack); + } + + if (!(cfg->nlflags & NLM_F_CREATE)) { + NL_SET_ERR_MSG_MOD(extack, "Create not specified and entry does not exist"); + return -ENOENT; + } + + if (!list_empty(&mdb_entry->remotes)) { + struct vxlan_rdst *rd; + + remote = list_first_entry(&mdb_entry->remotes, + struct vxlan_mdb_remote, list); + rd = rtnl_dereference(remote->rd); + if (vxlan_addr_is_multicast(&rd->remote_ip)) { + NL_SET_ERR_MSG_MOD(extack, "MDB entry has a multicast destination IP. Cannot add more destinations"); + return -EINVAL; + } + + if (vxlan_addr_is_multicast(&cfg->remote_ip)) { + NL_SET_ERR_MSG_MOD(extack, "Cannot add a multicast destination IP to an existing MDB entry"); + return -EINVAL; + } + } + + remote = kzalloc(sizeof(*remote), GFP_KERNEL); + if (!remote) + return -ENOMEM; + + err = vxlan_mdb_remote_init(cfg, remote); + if (err) { + NL_SET_ERR_MSG_MOD(extack, "Failed to initialize remote MDB entry"); + goto err_free_remote; + } + + err = vxlan_mdb_remote_srcs_add(cfg, remote, extack); + if (err) + goto err_remote_fini; + + list_add_rcu(&remote->list, &mdb_entry->remotes); + vxlan_mdb_remote_notify(cfg->vxlan, mdb_entry, remote, RTM_NEWMDB); + + return 0; + +err_remote_fini: + vxlan_mdb_remote_fini(cfg->vxlan, remote); +err_free_remote: + kfree(remote); + return err; +} + +static void vxlan_mdb_remote_del(struct vxlan_dev *vxlan, + struct vxlan_mdb_entry *mdb_entry, + struct vxlan_mdb_remote *remote) +{ + vxlan_mdb_remote_notify(vxlan, mdb_entry, remote, RTM_DELMDB); + list_del_rcu(&remote->list); + vxlan_mdb_remote_srcs_del(vxlan, &mdb_entry->key, remote); + vxlan_mdb_remote_fini(vxlan, remote); + kfree_rcu(remote, rcu); +} + +static struct vxlan_mdb_entry * +vxlan_mdb_entry_get(struct vxlan_dev *vxlan, + const struct vxlan_mdb_entry_key *group) +{ + struct vxlan_mdb_entry *mdb_entry; + int err; + + mdb_entry = vxlan_mdb_entry_lookup(vxlan, group); + if (mdb_entry) + return mdb_entry; + + mdb_entry = kzalloc(sizeof(*mdb_entry), GFP_KERNEL); + if (!mdb_entry) + return ERR_PTR(-ENOMEM); + + INIT_LIST_HEAD(&mdb_entry->remotes); + memcpy(&mdb_entry->key, group, sizeof(mdb_entry->key)); + hlist_add_head(&mdb_entry->mdb_node, &vxlan->mdb_list); + + err = rhashtable_lookup_insert_fast(&vxlan->mdb_tbl, + &mdb_entry->rhnode, + vxlan_mdb_rht_params); + if (err) + goto err_free_entry; + + return mdb_entry; + +err_free_entry: + hlist_del(&mdb_entry->mdb_node); + kfree(mdb_entry); + return ERR_PTR(err); +} + +static void vxlan_mdb_entry_put(struct vxlan_dev *vxlan, + struct vxlan_mdb_entry *mdb_entry) +{ + if (!list_empty(&mdb_entry->remotes)) + return; + + rhashtable_remove_fast(&vxlan->mdb_tbl, &mdb_entry->rhnode, + vxlan_mdb_rht_params); + hlist_del(&mdb_entry->mdb_node); + kfree_rcu(mdb_entry, rcu); +} + +static int __vxlan_mdb_add(const struct vxlan_mdb_config *cfg, + struct netlink_ext_ack *extack) +{ + struct vxlan_dev *vxlan = cfg->vxlan; + struct vxlan_mdb_entry *mdb_entry; + int err; + + mdb_entry = vxlan_mdb_entry_get(vxlan, &cfg->group); + if (IS_ERR(mdb_entry)) + return PTR_ERR(mdb_entry); + + err = vxlan_mdb_remote_add(cfg, mdb_entry, extack); + if (err) + goto err_entry_put; + + vxlan->mdb_seq++; + + return 0; + +err_entry_put: + vxlan_mdb_entry_put(vxlan, mdb_entry); + return err; +} + +static int __vxlan_mdb_del(const struct vxlan_mdb_config *cfg, + struct netlink_ext_ack *extack) +{ + struct vxlan_dev *vxlan = cfg->vxlan; + struct vxlan_mdb_entry *mdb_entry; + struct vxlan_mdb_remote *remote; + + mdb_entry = vxlan_mdb_entry_lookup(vxlan, &cfg->group); + if (!mdb_entry) { + NL_SET_ERR_MSG_MOD(extack, "Did not find MDB entry"); + return -ENOENT; + } + + remote = vxlan_mdb_remote_lookup(mdb_entry, &cfg->remote_ip); + if (!remote) { + NL_SET_ERR_MSG_MOD(extack, "Did not find MDB remote entry"); + return -ENOENT; + } + + vxlan_mdb_remote_del(vxlan, mdb_entry, remote); + vxlan_mdb_entry_put(vxlan, mdb_entry); + + vxlan->mdb_seq++; + + return 0; +} + +int vxlan_mdb_add(struct net_device *dev, struct nlattr *tb[], u16 nlmsg_flags, + struct netlink_ext_ack *extack) +{ + struct vxlan_mdb_config cfg; + int err; + + ASSERT_RTNL(); + + err = vxlan_mdb_config_init(&cfg, dev, tb, nlmsg_flags, extack); + if (err) + return err; + + err = __vxlan_mdb_add(&cfg, extack); + + vxlan_mdb_config_fini(&cfg); + return err; +} + +int vxlan_mdb_del(struct net_device *dev, struct nlattr *tb[], + struct netlink_ext_ack *extack) +{ + struct vxlan_mdb_config cfg; + int err; + + ASSERT_RTNL(); + + err = vxlan_mdb_config_init(&cfg, dev, tb, 0, extack); + if (err) + return err; + + err = __vxlan_mdb_del(&cfg, extack); + + vxlan_mdb_config_fini(&cfg); + return err; +} + +static void vxlan_mdb_check_empty(void *ptr, void *arg) +{ + WARN_ON_ONCE(1); +} + +static void vxlan_mdb_remotes_flush(struct vxlan_dev *vxlan, + struct vxlan_mdb_entry *mdb_entry) +{ + struct vxlan_mdb_remote *remote, *tmp; + + list_for_each_entry_safe(remote, tmp, &mdb_entry->remotes, list) + vxlan_mdb_remote_del(vxlan, mdb_entry, remote); +} + +static void vxlan_mdb_entries_flush(struct vxlan_dev *vxlan) +{ + struct vxlan_mdb_entry *mdb_entry; + struct hlist_node *tmp; + + /* The removal of an entry cannot trigger the removal of another entry + * since entries are always added to the head of the list. + */ + hlist_for_each_entry_safe(mdb_entry, tmp, &vxlan->mdb_list, mdb_node) { + vxlan_mdb_remotes_flush(vxlan, mdb_entry); + vxlan_mdb_entry_put(vxlan, mdb_entry); + } +} + +int vxlan_mdb_init(struct vxlan_dev *vxlan) +{ + int err; + + err = rhashtable_init(&vxlan->mdb_tbl, &vxlan_mdb_rht_params); + if (err) + return err; + + INIT_HLIST_HEAD(&vxlan->mdb_list); + + return 0; +} + +void vxlan_mdb_fini(struct vxlan_dev *vxlan) +{ + vxlan_mdb_entries_flush(vxlan); + rhashtable_free_and_destroy(&vxlan->mdb_tbl, vxlan_mdb_check_empty, + NULL); +} diff --git a/drivers/net/vxlan/vxlan_private.h b/drivers/net/vxlan/vxlan_private.h index f4977925cb8a..7bcc38faae27 100644 --- a/drivers/net/vxlan/vxlan_private.h +++ b/drivers/net/vxlan/vxlan_private.h @@ -110,6 +110,14 @@ static inline int vxlan_nla_put_addr(struct sk_buff *skb, int attr, return nla_put_in_addr(skb, attr, ip->sin.sin_addr.s_addr); } +static inline bool vxlan_addr_is_multicast(const union vxlan_addr *ip) +{ + if (ip->sa.sa_family == AF_INET6) + return ipv6_addr_is_multicast(&ip->sin6.sin6_addr); + else + return ipv4_is_multicast(ip->sin.sin_addr.s_addr); +} + #else /* !CONFIG_IPV6 */ static inline @@ -138,8 +146,21 @@ static inline int vxlan_nla_put_addr(struct sk_buff *skb, int attr, return nla_put_in_addr(skb, attr, ip->sin.sin_addr.s_addr); } +static inline bool vxlan_addr_is_multicast(const union vxlan_addr *ip) +{ + return ipv4_is_multicast(ip->sin.sin_addr.s_addr); +} + #endif +static inline size_t vxlan_addr_size(const union vxlan_addr *ip) +{ + if (ip->sa.sa_family == AF_INET6) + return sizeof(struct in6_addr); + else + return sizeof(__be32); +} + static inline struct vxlan_vni_node * vxlan_vnifilter_lookup(struct vxlan_dev *vxlan, __be32 vni) { @@ -206,4 +227,14 @@ int vxlan_igmp_join(struct vxlan_dev *vxlan, union vxlan_addr *rip, int rifindex); int vxlan_igmp_leave(struct vxlan_dev *vxlan, union vxlan_addr *rip, int rifindex); + +/* vxlan_mdb.c */ +int vxlan_mdb_dump(struct net_device *dev, struct sk_buff *skb, + struct netlink_callback *cb); +int vxlan_mdb_add(struct net_device *dev, struct nlattr *tb[], u16 nlmsg_flags, + struct netlink_ext_ack *extack); +int vxlan_mdb_del(struct net_device *dev, struct nlattr *tb[], + struct netlink_ext_ack *extack); +int vxlan_mdb_init(struct vxlan_dev *vxlan); +void vxlan_mdb_fini(struct vxlan_dev *vxlan); #endif diff --git a/include/net/vxlan.h b/include/net/vxlan.h index bca5b01af247..110b703d8978 100644 --- a/include/net/vxlan.h +++ b/include/net/vxlan.h @@ -3,6 +3,7 @@ #define __NET_VXLAN_H 1 #include +#include #include #include #include @@ -302,6 +303,10 @@ struct vxlan_dev { struct vxlan_vni_group __rcu *vnigrp; struct hlist_head fdb_head[FDB_HASH_SIZE]; + + struct rhashtable mdb_tbl; + struct hlist_head mdb_list; + unsigned int mdb_seq; }; #define VXLAN_F_LEARN 0x01 diff --git a/include/uapi/linux/if_bridge.h b/include/uapi/linux/if_bridge.h index d9de241d90f9..417e1aa909b9 100644 --- a/include/uapi/linux/if_bridge.h +++ b/include/uapi/linux/if_bridge.h @@ -631,6 +631,11 @@ enum { MDBA_MDB_EATTR_GROUP_MODE, MDBA_MDB_EATTR_SOURCE, MDBA_MDB_EATTR_RTPROT, + MDBA_MDB_EATTR_DST, + MDBA_MDB_EATTR_DST_PORT, + MDBA_MDB_EATTR_VNI, + MDBA_MDB_EATTR_IFINDEX, + MDBA_MDB_EATTR_SRC_VNI, __MDBA_MDB_EATTR_MAX }; #define MDBA_MDB_EATTR_MAX (__MDBA_MDB_EATTR_MAX - 1) @@ -726,6 +731,11 @@ enum { MDBE_ATTR_SRC_LIST, MDBE_ATTR_GROUP_MODE, MDBE_ATTR_RTPROT, + MDBE_ATTR_DST, + MDBE_ATTR_DST_PORT, + MDBE_ATTR_VNI, + MDBE_ATTR_IFINDEX, + MDBE_ATTR_SRC_VNI, __MDBE_ATTR_MAX, }; #define MDBE_ATTR_MAX (__MDBE_ATTR_MAX - 1) From patchwork Sat Feb 4 17:07:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 13128832 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 837F0C61DA4 for ; Sat, 4 Feb 2023 17:14:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232682AbjBDRN7 (ORCPT ); Sat, 4 Feb 2023 12:13:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231987AbjBDRN5 (ORCPT ); Sat, 4 Feb 2023 12:13:57 -0500 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2060.outbound.protection.outlook.com [40.107.96.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5E0C3345A for ; Sat, 4 Feb 2023 09:13:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lvqm3zqTIE5i3S2TTRyXlngr7YJrVLgn+RUZFl7rB5EVPy+vn40xjj8x3UAX5XHuN5JGDVEEGqxRfxj5C/zWTMrDQod/IFwvHlv7UHKouFeeA70HokhyN2sfnh2O0TGuHmGyKtug7ftldi/BDBkCL9ccQ+CBxoXNXXUmd/933gyDz/EBB/cKhCHbBOBgIwN4doeNTva5saOgdLpd6qZPcuNweC6pq98iGCEAQpuY6oI8kaA9w7hCiwTPx14Ies+RbNQrNAK1sgSKTOBtqIIWiYfO3hxNHHf+paxs+iY+9YEXB8CP3pk7tcO8jX9UxG6ipuBqT4jQ1yd6GxqZgDndUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=886fnpq+IvsanNM1sSgN71E2LKYdIG2xDXhWO2Cui5k=; b=TWSZm50f9rExncDEMJxBaU4mLcHwg5ps06AGslQ12dSUtjBuR8lEPRF18ppLFdJO5Aa6SuYMr3YI3musNbbzDwBLM80rUNSC6qiSuH14BieRGa0ISMga5opfrdWp8LHzncTDkRZ3PzsIvxUqgUzyB0X30U+r10hUt8mHTK8Kij/fBjjxioOIn3Bb4YBFCU0ksGcQL/KSAK/OztoTsNiK0wGoa2+V8rLL+g5OcRrtyR+7eVh27mwM8jmjC9dLekOsxoJosX7/ygoLNPtVWwr3mIwgF7BYTm8MjkHUmrRYJZAQPgxmM9VmSjGixuXB4k77kqywLee5eiIbzP2Ec3S0rg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=886fnpq+IvsanNM1sSgN71E2LKYdIG2xDXhWO2Cui5k=; b=OqCzO2EUHuTJmZQIEpECtloRkG1s3hbkTkuKhFDXratuJwoeZAhUgpDnO+5r98ctl98/psj58qbG0jAaJ6X5Jru3KH+eF5/XIRyRZVraJ5E7Dl5sr6mHhbb5uoyf4YZDlU5WrLgGFSJ90T7kUND7sx3V2CR97/2AwUe6nKCLQYOXvxlzt8PSRhfxaLpOTnUgFbEZogLgdOxOUdmejEz9PeQdb8uKMij/r8ovmJleVA82ATIbjgSWYr0j+y3FzOml8CkOcF95krp13IIhOsAdm+ubSiVS6x4PbvXz0yiAxBV9HTwHOIuvlGrBUs+bdN3KkzRWsMX43rt5Si5bgen+SA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) by SN7PR12MB6816.namprd12.prod.outlook.com (2603:10b6:806:264::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.31; Sat, 4 Feb 2023 17:12:56 +0000 Received: from CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab]) by CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab%9]) with mapi id 15.20.6064.025; Sat, 4 Feb 2023 17:12:56 +0000 From: Ido Schimmel To: netdev@vger.kernel.org, bridge@lists.linux-foundation.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, razor@blackwall.org, roopa@nvidia.com, petrm@nvidia.com, mlxsw@nvidia.com, Ido Schimmel Subject: [RFC PATCH net-next 11/13] vxlan: mdb: Add an internal flag to indicate MDB usage Date: Sat, 4 Feb 2023 19:07:59 +0200 Message-Id: <20230204170801.3897900-12-idosch@nvidia.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230204170801.3897900-1-idosch@nvidia.com> References: <20230204170801.3897900-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR10CA0117.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:803:28::46) To CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR12MB6179:EE_|SN7PR12MB6816:EE_ X-MS-Office365-Filtering-Correlation-Id: 57735ccb-484c-49aa-0380-08db06d30f11 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rkzLGdAUaSpEQ3XUGaxjVEbViw7nQ8O+2Hte21qu29wehTrbdlo21ocEZLoycYPTwHfIiUpcLDfZ6ax4wnR3heutqRCfITLsyOjMw9wGScZNfQB5ablhWxtkQkhBlb33W61JpMCYw2zS+jRsjMvH9VskRx6dAgHx4tcnkyS1yGrh5Og/uqfADstvua06U+Fm9mYb4aF5yjiFP/nqHdAeYWtCDtVfPQ91FiOTgFK8rOOWIoBb6NgR15zNHcWqNme4PXDaAy2i2I7B8Ywz/o8RlsGQO3ves+Evy28jstsDu8MB6RKyI7PBTIBV9tOxGHWP0dI0mXzrtWCUdRYfkaiUNjoreWUF60ok1Fs/DCdWmE2q+PSGcgXW0CK+fSScZkEfLU11rRnA8AIlG/1IOx8nkvZiXML8rK6nnHSvhieJhYidQXdV0YtGuGqnmVGoMJ2nvdE5XuF7mr65HyB8ODTg+jd//kF+MUk0NJEp/+lGMmGzYy5/MWuqRwzOPS4bpZKGCH/mDZWvNQMMHo0qOUl0N6fEuMuOxXyzcL7tZc5jiTxtaLwagCPaaE7m1lOW03MUCcKqItK0jgi7uc0n1R48rVp49xl8DP5+FdjNwI1KH66fbTsKlxhdLYFv1jMp1cdLQYKsaVYpaZE22wT693c8EQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY5PR12MB6179.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(366004)(346002)(39860400002)(136003)(376002)(396003)(451199018)(8936002)(36756003)(5660300002)(107886003)(1076003)(316002)(6506007)(478600001)(38100700002)(6486002)(66476007)(4326008)(8676002)(66946007)(2616005)(83380400001)(66556008)(41300700001)(86362001)(186003)(2906002)(6512007)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dN5FDzvRd7jL5OQol5z1328LZPonhS4QseRAwRoozjsUIrd5DLUNogbTyNVus3xMqUZcxD/b7/JMwSf496wdK6fWk92A5y2kB/JViCZ4pGwDw/oSNVr8UW1FIbG0WmCpPnQacPgCPL37WyQ2D1ieo90o+HFAAO0TRT7CQR1bd3X3Q03orgCLHUvnpnKuBqUBfNMg41FC36LjM97OOYhZ78tINwuf2ma7zm7CQiZcVu1KOBykwhIMNJodQ0RRFe8ZvE00IXDtjXgs8rwlJTAOf0ekZGICRAOJYn1qiRn+YfZxaSRMu7bIYvdVc+EKxjTEs05eDKRaRPUKAdTKNqPtVg7d90fP2FBRz2Ayj/FLe9FPXdEE5rG4LLRBH20bHF99fDI24d1H88f9HMtV9AzhsPk1qlQmZvhpqcXDCQlpSmQF9MmCEX0kcHbn0UhCRSH0BAl5yFgbba22VEYIt1q0Q0HxyBH2dg6KBtxtfXxz6HN577HUJ1JfeuxUR+cHZ3iVL7xXH4dTUhVR0d9V9Q34XdiHpYAhOnGxxWq5UssEFT4OAMv9/zjPLUaqMaZgpawBN2HBLaxr29VjAE75J5prj1gR8TyMQOiLm3x2CuyjzJtT3BCVG180zQQQwCsQnd5LEjRd5ge1dTtnYdFR/1MGE4Xl2sw6xEfaHBfxWYjmwwGXhMO5wIA2dWyTYdQQaQvAUOvMopjd78vwN9MN+3guPozjq4z4ns/Fbkvs/vtbK3hKBo4CowIAdGsxjAtIdWJmUlRVDuy9c3dQUkVhHMnFQxSS0tEM/ZEPftdFVDryYI5g5PukuDPtlbk+ITBCGyLQH4UoENuZqN8H+JJqx2HKDpiOrzchf37KJPhLxjwUOU68NlgDRC2trwvmEj6PDah0o+RoH00Pm2C3cWl4a+FQqxItgXPCpNkdo19vQA1mzbIARHkWn3D1LXnISJM8eX+q3wDmfV524H8CnsLPuOJrENXTGIRSy1dKOT4V0qWC7aOnx/+F6RqRVUAgelX7v+wXc6YcHF1bHvkOVOljZhJSBhIt0Iwd4sDWtlfyWiegLkcx4T9AjTjZJ5AVAqeNEcgE1VhlhXPgd0hZoJejtAqitZNWMV7ziptDhCAKSkEKU3i0LLHkUMOBJgxhBddw4jtCn6zkBQYKyc8qRARyTb23+B9c6/f1edAG5D5sZXF0DRLes22v5nX0K4ZqGmWzy3PHOIEpRD0e/4Sl2l7qGkqTwuGOsWWQE4qWLbyYZoDKuUqigGzrH1yaIAljL8IUO4FA2kqCzP0K8Z2NsuSsH1ViyqKYFBpkWG5WWDCCtf9/KAdQqVq+wDyg5JiCpxqTnM1WorzJrrvdUDjv1dOyP6D/+sC8AUcB43qqbOzXAtKE+ESHPZdsEeiHHDDIi0ft5tMKX7M7AKgzbBcnwMrKEiGOuB2W8VQxnrKcd0a9yMQDVzKWTK16CfrJDkIqOKPazOG6ToLN3q8ecdQMsb/itdp3rAwLK1MiXLo3NIeYegInCBS6kOZRNHSymO+9XhoemjpHVq7L8KamAQ1j607SSfSLx/Bbcx01hP1ckcJT0kksGQ8+LR7ecUE575c+BKznX6L2 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 57735ccb-484c-49aa-0380-08db06d30f11 X-MS-Exchange-CrossTenant-AuthSource: CY5PR12MB6179.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2023 17:12:56.6040 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: WGH9rGoaPfZ9DECj6u0+4a9rAstHUqORegIOQ0l1mCsxh8W/qF3e44u9KeJL6FNtD8+dsOcntX0DdmuKpr6C4g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6816 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add an internal flag to indicate whether MDB entries are configured or not. Set the flag after installing the first MDB entry and clear it before deleting the last one. The flag will be consulted by the data path which will only perform an MDB lookup if the flag is set, thereby keeping the MDB overhead to a minimum when the MDB is not used. Another option would have been to use a static key, but it is global and not per-device, unlike the current approach. Signed-off-by: Ido Schimmel --- drivers/net/vxlan/vxlan_mdb.c | 7 +++++++ include/net/vxlan.h | 1 + 2 files changed, 8 insertions(+) diff --git a/drivers/net/vxlan/vxlan_mdb.c b/drivers/net/vxlan/vxlan_mdb.c index 079741da2599..72c922064c02 100644 --- a/drivers/net/vxlan/vxlan_mdb.c +++ b/drivers/net/vxlan/vxlan_mdb.c @@ -1207,6 +1207,9 @@ vxlan_mdb_entry_get(struct vxlan_dev *vxlan, if (err) goto err_free_entry; + if (hlist_is_singular_node(&mdb_entry->mdb_node, &vxlan->mdb_list)) + vxlan->cfg.flags |= VXLAN_F_MDB; + return mdb_entry; err_free_entry: @@ -1221,6 +1224,9 @@ static void vxlan_mdb_entry_put(struct vxlan_dev *vxlan, if (!list_empty(&mdb_entry->remotes)) return; + if (hlist_is_singular_node(&mdb_entry->mdb_node, &vxlan->mdb_list)) + vxlan->cfg.flags &= ~VXLAN_F_MDB; + rhashtable_remove_fast(&vxlan->mdb_tbl, &mdb_entry->rhnode, vxlan_mdb_rht_params); hlist_del(&mdb_entry->mdb_node); @@ -1358,6 +1364,7 @@ int vxlan_mdb_init(struct vxlan_dev *vxlan) void vxlan_mdb_fini(struct vxlan_dev *vxlan) { vxlan_mdb_entries_flush(vxlan); + WARN_ON_ONCE(vxlan->cfg.flags & VXLAN_F_MDB); rhashtable_free_and_destroy(&vxlan->mdb_tbl, vxlan_mdb_check_empty, NULL); } diff --git a/include/net/vxlan.h b/include/net/vxlan.h index 110b703d8978..b7b2e9abfb37 100644 --- a/include/net/vxlan.h +++ b/include/net/vxlan.h @@ -327,6 +327,7 @@ struct vxlan_dev { #define VXLAN_F_IPV6_LINKLOCAL 0x8000 #define VXLAN_F_TTL_INHERIT 0x10000 #define VXLAN_F_VNIFILTER 0x20000 +#define VXLAN_F_MDB 0x40000 /* Flags that are used in the receive path. These flags must match in * order for a socket to be shareable From patchwork Sat Feb 4 17:08:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 13128833 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AD5BC61DA4 for ; Sat, 4 Feb 2023 17:14:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232775AbjBDROQ (ORCPT ); Sat, 4 Feb 2023 12:14:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232568AbjBDROO (ORCPT ); Sat, 4 Feb 2023 12:14:14 -0500 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2060.outbound.protection.outlook.com [40.107.96.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58B4E72A4 for ; Sat, 4 Feb 2023 09:13:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hpJS36iK5DY+sFyvYtf4tTjsmCQIuSQ5CX2cs5EeRRI6QOVLLQ/oexu6MFAM5r+K2/AcYiFLL57u16wAOQBkCdoBUM1NRo8cSLXofHsWGpzUMKYBEccMRdoIAlNZWfLj5a281yeuxMhsHB+5Y5vtm78Y3yoitLK3+5dYUq+dUu8L74mJbHUjNdlLCcHT6x8W9qmOZ3tB9S76t8MMr+XIpAy0FxkX6hgCiEVtEZ0z8t7WFp+dcIfeITzjoRrIw7UURCfcGcgQiB+ALKJrB1jcys6ZprQM/I6aOiFQ0KswWwBtGYk0LXihO8cClkLz/nnAZLFukZgjS/7e0FVmXqceMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=o9vIZfjeNZjPD//rZ4qABhtrQ7NtCZ56VecAMZrz9uA=; b=Hwxt8x3gJOZZVqqLpKBnT9sldNdAInCtjAk9k996M+V3vSOgTjJvJWQ5Yc9pv4kbpw+0zGeOV9R4uf0l2q9crM/UBIHFJjvrxnrCDU3pDn3TG3Yep3gsrruHKZ6+dXanlo/iFrpe3DXZ62RuHn/cNc68k1QJGNhGH/6OOlewmRpRBdJWqsJt21Et7s6IpcRL12Fl3+2iYyjtqm7XLGlvYQ9kUbL2CMaq+f4bBCG+GW5g9aJ0YziH/Bqmu0qx6iFZdJFjW0FirNsSeYZQSBC9c5sWCcytUkMZD5dEAFMkkX+tErqpNBB3CKoEThrAUWMYhou1ouZYHdRWB3i+jD2yYQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=o9vIZfjeNZjPD//rZ4qABhtrQ7NtCZ56VecAMZrz9uA=; b=As65JTzj0hOGgQ/wNH+kEpiKtLB8bX9DYKqV/aVUrVsPwEkadiFmf/mmRZqEz1nb9a4C0oSLsMhq+yTjFT0izlIKKZcneWewzSnMQoFnP8x8wwVL3nHXgEqBc34h8L5VOjLNvk5cgtap3zMq1oFY9otb2EyjuYZncd9znDa2kpgT4IpsR7gOnRAZsEyD0dKCsMzuML2rocAp3wZ83itYbVOqrj/dRpiwpJYUgU8bd99U1d9xTyGXf8fPFb8Si1JDO6PmCbjWaQjoqMh+UlhTOaZlWZdm2+gMBFVPDRv2pUf/K7na4m9vZDB8cGaXpz6YemLDvrm/CaOO0ZGeQz6Ljw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) by SN7PR12MB6816.namprd12.prod.outlook.com (2603:10b6:806:264::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.31; Sat, 4 Feb 2023 17:13:09 +0000 Received: from CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab]) by CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab%9]) with mapi id 15.20.6064.025; Sat, 4 Feb 2023 17:13:09 +0000 From: Ido Schimmel To: netdev@vger.kernel.org, bridge@lists.linux-foundation.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, razor@blackwall.org, roopa@nvidia.com, petrm@nvidia.com, mlxsw@nvidia.com, Ido Schimmel Subject: [RFC PATCH net-next 12/13] vxlan: Add MDB data path support Date: Sat, 4 Feb 2023 19:08:00 +0200 Message-Id: <20230204170801.3897900-13-idosch@nvidia.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230204170801.3897900-1-idosch@nvidia.com> References: <20230204170801.3897900-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR08CA0261.eurprd08.prod.outlook.com (2603:10a6:803:dc::34) To CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR12MB6179:EE_|SN7PR12MB6816:EE_ X-MS-Office365-Filtering-Correlation-Id: 56d1cca9-f6a0-49be-0f0d-08db06d316f0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Wa/+ws7KHyTex8TtzL4lHQ+cu8UIT62fIrWQRLKhwCLSKNvKMM19Xby7jWuEU5kIwhOD10GwZO9sQHTy73hKyBzc4zAqRMPrBAjbo2gdPR4xkDLvJTV+4QLCZQOIjkGkF8PuJ2NMBDUBQE1VG4JN6FqwyK6kGQKgKPWPSTcIEvh+nCCIP0tOTHd8Q37pHDojUSUgHpaaG5J+9QSE3bKxRUgg4xRwhFXX5arUtLgn6Zk8T5WjctqAKxhMPQI2nDabPhxTyxZjy0ODa4PnaQWZ/k/+EMZbRRoBNzzD8ph3NmUMMG4p/DHq48xq2+dXyQkWUMIUR3GgFOF50wfHZTP+KEhkQuTEoqeXvCfB8FtBPb1B9a/rC9Cd9PHeP9SYD5WKKGi19vuBIPd1KUDsV8/8MeKRaV21JQ6ES5xQh9ojtFDGrXLQf49iCSSMDSyuu6YWBE8PkC3eHF99N0+rYbUlh3JqGrUlxuVnU76q5hAJf/XVo5/JbjRJPGrDDvHqZ4lpsOngwrVtRA+XHuG4UymFkLGy8JuATjNop3el6pjWum+Df/AilERkg9AEgSjkq9IMzVhwy3aPwmAKmI2YmWBkgKW0NtPJ0t0Cs9R/ZXN6kNzbTnpB5oJiPcN/lQfU2zXoYX8QL6rMvcQ9rdHA/w3GsIQvocd5IUFQ412TFd+JgVTMoXWsQ+j3ldgueeA+wmPXQCHHwKZeZJuO3BNqSiB0Dg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY5PR12MB6179.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(366004)(346002)(39860400002)(136003)(376002)(396003)(451199018)(8936002)(36756003)(5660300002)(107886003)(1076003)(6666004)(316002)(6506007)(478600001)(38100700002)(966005)(6486002)(66476007)(4326008)(8676002)(66946007)(2616005)(83380400001)(66556008)(41300700001)(86362001)(186003)(2906002)(6512007)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4VAg9F87OLMUnq0F8Zrl0aSyATa+8ck/tU1EfVswiWB+27xD14QvYPzyDC3vC0+RdJX62hRgccTWpVZHJe6ylmYoTKT8cobM4CxxLOEiSeZOq7adWGIBwYuNL5DLZObpT8mT1Po7eeGrc+dOLHmi91a2+TmVH+HxlrgSEIqBB1Xp1t9B4NBpaArZkfZMuLsS6dKIqq6AWNvTUVtGk2fYNZxqURHjkcto8dY518SB+LLrJkCxZCrTWdBRAjZJgV4M/nByDxwS9jNMUWThvapYZtMiIropWzVxUfyGq5hLG6pNQnUBA5JzpSuX8hdTdZ7iGshk+BiBEqly3lbuixlxDYw6eI4iar01GLygB3vqi7EKDsFC7vREzC2aZfax7gALLuvE92GTK/gZUvDd82eQ1wzRakpx5kWOvN8IPct1jqfohcmxTFc55og8WqfCkOx66T7Tuy6hUD7/jToba+4Bj62nIGzpzUUIXVm2gznYcRJLDZMf/k6s2vFpUy1tYAZSOuuOovTrUfHQV/bH2HIwRsfBqotjF4v86dhnS4WiEoS5p1vGTjIQkg71UjAcb4dG5x7fUTj1o0ZU3fqjfABW2jKQqwb42LCUmdtPm0f1vPXtSr0UJjjJHK3+rXg7AQPiwfE8hEOj9eQmAl+vTlqaumEhuk5Og1mJWRyUr2eJtxnJZbSFxvmFQ91Vks3UGtnEsNctZgDIb0XEjSLLhrhf9anYU2aGhgn9MhTQRi9J98crk5mE6ZngcZYY/8p9n6g2AkTio+pbrESmFZ9wX201yev50wkm8LljD8ZbwJJREO3cFtovHLQP/pAkZvh7aXM56n50XqnyVrPCcYv40hyRTlEtN88IXReeoCDVYdZ4AyoMUFR2YHwYFUrmFxTrO+3RMVfk9aJHGuPPIxv7+PgA+ko8NLIZLwjxQqj4eBIsE7+nkhivRmb9KoVUWTfLCBdxjYD/j/8UPDc8PWJRYMpDq1JDKs+Qw0gonic26tUeROTmoIeU4JwixKwBbqnQOyVzp48Wj0VstozN3/hTEm7OO2lUr68r5sgxNtLQxxqFPkugv23hu6ZPw7CtMsZGG6Be9TRK63TtG3qq2kzvgB3JVc9Xk7eTboXh+7k6WszZe2hIVy/8uQMVhVhpxh44U0nbVdCSDnyXJmXlPH00zyqJp4gROKzq1J/26677idGlYC2i2c8PTmaQRg7dQ8R6pZFlCVmClNPzYLCKpqh5jLNGAhTZuAQA4UIzpu/vqZa+iyPHwaR3+mVWcKZ8ZpA8qwlHl2qTm6DpADeUC/sgYg4P+iLeae3EeqyCWNXc9lZUH25781iDVxx+NGjmgM70sDkgw0l0/+qSsQwpmdyHh6bM+kgZHdjVmjB483eS2h4EcwXxSy/MmtagZNPoL7PC/apd82VcI87JB8KfxMTAD/WFN/koE7DsgtfyVSU05v3lm4xg6AYLT7L+V5g3sj+K8GMHhDl+xaqTYSewpSLkZuFhkZgJEJdBSkb/0s+u9auR2B/rJzm6dJJDtDNO/g+pVvFv8O6o5NXT2SHIDPq4xgiAwmnFQ/YGd0GQFPiGVDQ0IBfgkTUqusMnqk/vC4FcGckI X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 56d1cca9-f6a0-49be-0f0d-08db06d316f0 X-MS-Exchange-CrossTenant-AuthSource: CY5PR12MB6179.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2023 17:13:09.8254 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: u19tdOWpUtKMKjZYCt2rFa54PTDHElWqT45y5BDIEzxO1mgNIuE9xscNVNesWGChX5ZjPFCKAM+64D7vT8hmOQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6816 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Integrate MDB support into the Tx path of the VXLAN driver, allowing it to selectively forward IP multicast traffic according to the matched MDB entry. If MDB entries are configured (i.e., 'VXLAN_F_MDB' is set) and the packet is an IP multicast packet, perform up to three different lookups according to the following priority: 1. For an (S, G) entry, using {Source VNI, Source IP, Destination IP}. 2. For a (*, G) entry, using {Source VNI, Destination IP}. 3. For the catchall MDB entry (0.0.0.0 or ::), using the source VNI. The catchall MDB entry is similar to the catchall FDB entry (00:00:00:00:00:00) that is currently used to transmit BUM (broadcast, unknown unicast and multicast) traffic. However, unlike the catchall FDB entry, this entry is only used to transmit unregistered IP multicast traffic that is not link-local. Therefore, when configured, the catchall FDB entry will only transmit BULL (broadcast, unknown unicast, link-local multicast) traffic. The catchall MDB entry is useful in deployments where inter-subnet multicast forwarding is used and not all the VTEPs in a tenant domain are members in all the broadcast domains. In such deployments it is advantageous to transmit BULL (broadcast, unknown unicast and link-local multicast) and unregistered IP multicast traffic on different tunnels. If the same tunnel was used, a VTEP only interested in IP multicast traffic would also pull all the BULL traffic and drop it as it is not a member in the originating broadcast domain [1]. If the packet did not match an MDB entry (or if the packet is not an IP multicast packet), return it to the Tx path, allowing it to be forwarded according to the FDB. If the packet did match an MDB entry, forward it to the associated remote VTEPs. However, if the entry is a (*, G) entry and the associated remote is in INCLUDE mode, then skip over it as the source IP is not in its source list (otherwise the packet would have matched on an (S, G) entry). Similarly, if the associated remote is marked as BLOCKED (can only be set on (S, G) entries), then skip over it as well as the remote is in EXCLUDE mode and the source IP is in its source list. [1] https://datatracker.ietf.org/doc/html/draft-ietf-bess-evpn-irb-mcast#section-2.6 Signed-off-by: Ido Schimmel --- drivers/net/vxlan/vxlan_core.c | 15 ++++ drivers/net/vxlan/vxlan_mdb.c | 114 ++++++++++++++++++++++++++++++ drivers/net/vxlan/vxlan_private.h | 6 ++ 3 files changed, 135 insertions(+) diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 1c98ddd38bc4..1e55c5582e67 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -2743,6 +2743,21 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev) #endif } + if (vxlan->cfg.flags & VXLAN_F_MDB) { + struct vxlan_mdb_entry *mdb_entry; + + rcu_read_lock(); + mdb_entry = vxlan_mdb_entry_skb_get(vxlan, skb, vni); + if (mdb_entry) { + netdev_tx_t ret; + + ret = vxlan_mdb_xmit(vxlan, mdb_entry, skb); + rcu_read_unlock(); + return ret; + } + rcu_read_unlock(); + } + eth = eth_hdr(skb); f = vxlan_find_mac(vxlan, eth->h_dest, vni); did_rsc = false; diff --git a/drivers/net/vxlan/vxlan_mdb.c b/drivers/net/vxlan/vxlan_mdb.c index 72c922064c02..34ffd77cd466 100644 --- a/drivers/net/vxlan/vxlan_mdb.c +++ b/drivers/net/vxlan/vxlan_mdb.c @@ -1320,6 +1320,120 @@ int vxlan_mdb_del(struct net_device *dev, struct nlattr *tb[], return err; } +struct vxlan_mdb_entry *vxlan_mdb_entry_skb_get(struct vxlan_dev *vxlan, + struct sk_buff *skb, + __be32 src_vni) +{ + struct vxlan_mdb_entry *mdb_entry; + struct vxlan_mdb_entry_key group; + + if (!is_multicast_ether_addr(eth_hdr(skb)->h_dest) || + is_broadcast_ether_addr(eth_hdr(skb)->h_dest)) + return NULL; + + /* When not in collect metadata mode, 'src_vni' is zero, but MDB + * entries are stored with the VNI of the VXLAN device. + */ + if (!(vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA)) + src_vni = vxlan->default_dst.remote_vni; + + memset(&group, 0, sizeof(group)); + group.vni = src_vni; + + switch (ntohs(skb->protocol)) { + case ETH_P_IP: + if (!pskb_may_pull(skb, sizeof(struct iphdr))) + return NULL; + group.dst.sa.sa_family = AF_INET; + group.dst.sin.sin_addr.s_addr = ip_hdr(skb)->daddr; + group.src.sa.sa_family = AF_INET; + group.src.sin.sin_addr.s_addr = ip_hdr(skb)->saddr; + break; +#if IS_ENABLED(CONFIG_IPV6) + case ETH_P_IPV6: + if (!pskb_may_pull(skb, sizeof(struct ipv6hdr))) + return NULL; + group.dst.sa.sa_family = AF_INET6; + group.dst.sin6.sin6_addr = ipv6_hdr(skb)->daddr; + group.src.sa.sa_family = AF_INET6; + group.src.sin6.sin6_addr = ipv6_hdr(skb)->saddr; + break; +#endif + default: + return NULL; + } + + mdb_entry = vxlan_mdb_entry_lookup(vxlan, &group); + if (mdb_entry) + return mdb_entry; + + memset(&group.src, 0, sizeof(group.src)); + mdb_entry = vxlan_mdb_entry_lookup(vxlan, &group); + if (mdb_entry) + return mdb_entry; + + /* No (S, G) or (*, G) found. Look up the all-zeros entry, but only if + * the destination IP address is not link-local multicast since we want + * to transmit such traffic together with broadcast and unknown unicast + * traffic. + */ + switch (ntohs(skb->protocol)) { + case ETH_P_IP: + if (ipv4_is_local_multicast(group.dst.sin.sin_addr.s_addr)) + return NULL; + group.dst.sin.sin_addr.s_addr = 0; + break; +#if IS_ENABLED(CONFIG_IPV6) + case ETH_P_IPV6: + if (ipv6_addr_type(&group.dst.sin6.sin6_addr) & + IPV6_ADDR_LINKLOCAL) + return NULL; + memset(&group.dst.sin6.sin6_addr, 0, + sizeof(group.dst.sin6.sin6_addr)); + break; +#endif + default: + return NULL; + } + + return vxlan_mdb_entry_lookup(vxlan, &group); +} + +netdev_tx_t vxlan_mdb_xmit(struct vxlan_dev *vxlan, + const struct vxlan_mdb_entry *mdb_entry, + struct sk_buff *skb) +{ + struct vxlan_mdb_remote *remote, *fremote = NULL; + __be32 src_vni = mdb_entry->key.vni; + + list_for_each_entry_rcu(remote, &mdb_entry->remotes, list) { + struct sk_buff *skb1; + + if ((vxlan_mdb_is_star_g(&mdb_entry->key) && + READ_ONCE(remote->filter_mode) == MCAST_INCLUDE) || + (READ_ONCE(remote->flags) & VXLAN_MDB_REMOTE_F_BLOCKED)) + continue; + + if (!fremote) { + fremote = remote; + continue; + } + + skb1 = skb_clone(skb, GFP_ATOMIC); + if (skb1) + vxlan_xmit_one(skb1, vxlan->dev, src_vni, + rcu_dereference(remote->rd), false); + } + + if (fremote) + vxlan_xmit_one(skb, vxlan->dev, src_vni, + rcu_dereference(fremote->rd), false); + else + kfree_skb(skb); + + return NETDEV_TX_OK; +} + static void vxlan_mdb_check_empty(void *ptr, void *arg) { WARN_ON_ONCE(1); diff --git a/drivers/net/vxlan/vxlan_private.h b/drivers/net/vxlan/vxlan_private.h index 7bcc38faae27..817fa3075842 100644 --- a/drivers/net/vxlan/vxlan_private.h +++ b/drivers/net/vxlan/vxlan_private.h @@ -235,6 +235,12 @@ int vxlan_mdb_add(struct net_device *dev, struct nlattr *tb[], u16 nlmsg_flags, struct netlink_ext_ack *extack); int vxlan_mdb_del(struct net_device *dev, struct nlattr *tb[], struct netlink_ext_ack *extack); +struct vxlan_mdb_entry *vxlan_mdb_entry_skb_get(struct vxlan_dev *vxlan, + struct sk_buff *skb, + __be32 src_vni); +netdev_tx_t vxlan_mdb_xmit(struct vxlan_dev *vxlan, + const struct vxlan_mdb_entry *mdb_entry, + struct sk_buff *skb); int vxlan_mdb_init(struct vxlan_dev *vxlan); void vxlan_mdb_fini(struct vxlan_dev *vxlan); #endif From patchwork Sat Feb 4 17:08:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 13128834 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3687CC61DA4 for ; Sat, 4 Feb 2023 17:14:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232963AbjBDROa (ORCPT ); Sat, 4 Feb 2023 12:14:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233004AbjBDRO1 (ORCPT ); Sat, 4 Feb 2023 12:14:27 -0500 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2060.outbound.protection.outlook.com [40.107.96.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D891F1BEC for ; Sat, 4 Feb 2023 09:14:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S8MtjQz9akSxoORBF5k2MdGvWNz05mWR50wUTDYP+ePW009yb9f1BgBdTfdpIxRi+SQ6Ofz3G9Nrb6znyyxBN7652g4cxDgrhONMAHOyDBDuRDDfSd5VU35Ql8RJP4vcOobwVUEc+Z7rNDTguHQFsI9UIj+A6Ehj4vBBiZmMFn3rXaHwenI5PGoISAfCPakYC/sdNAbWylTv0+nzi2MECuouJawecddQK5G8V6TSvsoi36HnEx92zBp7Ar9LBVZ5+7uHqt61ioMnH0ycrXe9YGeJFeKGj04Fhj+2sL0knygl5hqDRGbaEHCjLzHBZzrJW3YhTSanjuC3Hcp4kNFXyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=DWAS9sy8p3oKjwtrl1G1L1zE48uknaQb+yom1/wew44=; b=dr6wDYPrvX+32D1RSfPYE+LKPs3VRLK/v6Lv+HL5yDC5qjMnJsfV8DI9PRcHSZzUQl57X3ILjc24d1Yu/JV1Zw8d5xRsX+oYullnUNhdv1qBTwo1lnuHqbBwgUqdCOdnFqbv7xnknQ8lX/+gKr+rf3zZou9OICAD97/7SYFr14c2iqa+cE3sd/jA/+dRxc8fEPo5tjvCrpOu/GIDBFDMuTyaSPraVyWCEqMYSXCwo4tnl3TP2UcBbxA3BfCnVycrSYDVMPHgyl85OihpBBvKReDTG9aKi0f2BHBos0OzpASrlmEJzfUYlCQa528s0UJuOsO/jLk69atd1oMfVm5huA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DWAS9sy8p3oKjwtrl1G1L1zE48uknaQb+yom1/wew44=; b=T3e1ZycbrtUJHb8l4UMg8FCf3UpjhIZ/BJZLunxiEjYF+BtyJKfV3VPxxWQu8HUvmxYKkBD7YMuXlYq55buUs6cSdrJnloUkI4LNuS4fR9ga6vSziWP4LX7yJDGlDT/88iFEI/Ti+UG5VYbSc3LbObkh1x7VY9pWgvF6/VlmD6NkwqgTOGLgHctEpu9BMw5EpDzUU7jIwg5g3/bpW78sEhiQOuJP6OQjFxa30Fmx9K1eJ5XlayzqdFzsV+M3fkjg15e+AYCOYHkIFMi2MHm77P0VG/C8CL45FKjwRr2O8qxpaUr1Xjn1XXnpoDJGFViUacLYbbyNm1jCCgRS2YmERg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) by SN7PR12MB6816.namprd12.prod.outlook.com (2603:10b6:806:264::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.31; Sat, 4 Feb 2023 17:13:18 +0000 Received: from CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab]) by CY5PR12MB6179.namprd12.prod.outlook.com ([fe80::7d2c:828f:5cae:7eab%9]) with mapi id 15.20.6064.025; Sat, 4 Feb 2023 17:13:18 +0000 From: Ido Schimmel To: netdev@vger.kernel.org, bridge@lists.linux-foundation.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, razor@blackwall.org, roopa@nvidia.com, petrm@nvidia.com, mlxsw@nvidia.com, Ido Schimmel Subject: [RFC PATCH net-next 13/13] vxlan: Enable MDB support Date: Sat, 4 Feb 2023 19:08:01 +0200 Message-Id: <20230204170801.3897900-14-idosch@nvidia.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230204170801.3897900-1-idosch@nvidia.com> References: <20230204170801.3897900-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR0102CA0071.eurprd01.prod.exchangelabs.com (2603:10a6:803::48) To CY5PR12MB6179.namprd12.prod.outlook.com (2603:10b6:930:24::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR12MB6179:EE_|SN7PR12MB6816:EE_ X-MS-Office365-Filtering-Correlation-Id: 8b5592aa-8eba-409e-95ed-08db06d31b79 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yxGz0CU87kaUC8MSu1P4VPJfdDPqQDvULYfbJB8tqatHMf6WUL0OMAb/usdORbsuot2ASG/Y773Rhz6M+tcVLX5vWwba4AdeslNFsDx9TPP7XogQZDqjkmoX9BQjhp7SzR0wQXqVEy4H3K5GXN92bevAJ+2QCAESyTE60/mM7V1IspMtpsqueVZGMz7tbNL0Sx5JlHbaAOs7EEMkGRYtEOpFPVUyo+vH9OsW3huBZ3PsBlbCjg1TpHPJ9ld9r7+zLScJoaVhMnLqT/W11j+lyt5WTHAclGusXDegwUfXjoTvBlcdLsBCnlJLEIuqyc4V7g1fxHBTSNbHqqz47Fir2IamWTJxtik4RwE39R3BUTMAhnIEwapRG2RzXvr8NN+A5xj2BWZvR5l1aDq8QEKaobvafDPeKTyh30bdVNoUo8qDKCh/D4TKF/6GumqpIKG+1ap726UooQQFtVDEYnq4amAWtkxPfrEgSUiaOzK8VD9IHGIUw6EQ7bMhhaSdkuZohPzi3X2rAs4FprYtrY6JueQDZgJPAZwp3HsQqtQqFOkQ5YW9L9hXGNx0Zxm+lP3b/zR9srQkQkoWMUxraqt3yJ9V+EKOAmbs6/wUUhh4aIBU/R56qbRSwc6e6sehtwtQRPq2hPP3klG/73okTO5uCQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY5PR12MB6179.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(366004)(346002)(39860400002)(136003)(376002)(396003)(451199018)(4744005)(8936002)(36756003)(5660300002)(107886003)(1076003)(6666004)(316002)(6506007)(478600001)(38100700002)(6486002)(66476007)(4326008)(8676002)(66946007)(2616005)(83380400001)(66556008)(41300700001)(86362001)(186003)(2906002)(6512007)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cuPR38JNI6DFwEQQvkRXeTL0fzrpKWMkMSGs8cLhW5oyd7t1Cspa4T4ggas8XzoZE+Hdz4sZ82cwEC41QndoSMDCXNKQnj7oM0GczIhsl5qFizHXwBpQnfnpYMLxbNLvYGuyxBKhAhUw9rLclXJHWkK8/MVZqCD6WT0JUEmpwepg+grE2QudPTYzWMvCVfbXn8enaV+9h40BIvF5M/oZma2UXQzYqC4vCTlxI8Nk3z5v0fSNe2AbZ6/hU+3UuOjA1p73hTMJJlfTeghfwGoMpqNswmPWYhUnZX9kIRJlGR0NydFmBSWibQLAbuHlBNuq4sTeisv9C4XlRPdf+lCf3OkUSwuAq0K6EIUbTdQH3DAt1DMUn37DH7s+qdfTc0RAhRxzgjlQUNUh8XyhJ2Jb/3jJgh7UVw3eIOXQ3GyJUudo+HPI+WQTpgcb5UQUgwByQ+8NzkLRdcHEWkEVzkv5O0I83SaqMv3Sm3DZ4ucaHDezMgjhnU1CEC5xC9ykqt9HunPAgY7ORVqFAM+kDOk4/Ju59x47gItrVCZRY0mCRAQtjBMcWoFExeq1zAEpyrw0WzjbyZwGRYEcnMPxIErkmG+QdKUtL8RKW4Ptd9TQ8qn6eZuUFMrCZZS9EnUm0+evyfSW+zrtlh7buY3T816dW0odXlNJ8YUmedUqKc/GG1eDp9YI5K+4+VIxzl2NhPsmtrjbu7XFgYYuQJkcCnVKCtcMnu6+nBrykzE6V9zIobMxo0c+5A4JdfvLwpqsFSFeropd5pKmHKXcRUDuNXj5AVtlUDAxHQc+2bYPd1DMSMFdVX1oWzJIR7tgtCV3ZOHwd55k6iJgTmnIKLrpo2dPj7NR0AgVYh+cB5u0/qxzZIU6RMUc6AcSoFGTZ8cIOyklqVBD5yWpYoDpI1ffM4mRgU68FvD3Iyx6a7u1V1KnAIuoWrVNGAsxIEMkOjK4GBX8niNObojrPZ2pyKB//M9l5dUAwgdexODNjUupGfulfQ5we559mP1/xAgZpAyIy3pnsbi0LiZFsDMHSZk1ay4+lWZsCkB1dLhs37JUuJRxZI/i3n8hnilRM2D6gUw9wfbPZICeRr2XbXq9THfotKmuhtwSpobXYpOeg6fCXf7Nvregbw7H/v/n5JHJkwGgUS9b+I/E8YTVaUNsXtWIgPX4gi5JKLKI5HsIVfoTHIY0wq6s1C2UpJ07lJWPY2lIX5t/Cp7L3TuR1AK6Bj1WpS/j7KH4t+dqe+Hl0Uvb7wQ1A04UFDTO1ooV/ulI5Cb75atb2Hz5xW3PHDqItzu7juGa5Q9Wdg8oV8go8QXOAdnqckjgZvRb97fW2e7X25pgVANl0f9ZUc5ztZw/w2XxVmp/dXqJ3akUN3c0UbC+kX80OG9+yy3FKg4MPc2wnmxiR36mwCtxcb8kjLlSUTkV7iW/UeSP+N0aDB0hRWiv4cGy5ERl8H/Y2+4DOAPdS7OUjJiwmlOOynY6c8rZz89SSqDptJZuXUiK9EKOGE49xJtFff2K9ulTo0cCu5u1Vt4GPIFJ/ZY6dlvGrF3yubvkqds+qUlgQKufg9a8j1VcyFr363TmlCWPMRMVQTAsp91f5qd2 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8b5592aa-8eba-409e-95ed-08db06d31b79 X-MS-Exchange-CrossTenant-AuthSource: CY5PR12MB6179.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2023 17:13:17.2813 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: bIlhksTlyYnClfNWhhP7p6hWQ3aan1nL6IZz4IpWO8A235mBIOn7cPq36IZDLlEIvY/sbwN608BmR47oh0Bgeg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6816 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Now that the VXLAN MDB control and data paths are in place we can expose the VXLAN MDB functionality to user space. Set the VXLAN MDB net device operations to the appropriate functions, thereby allowing the rtnetlink code to reach the VXLAN driver. Signed-off-by: Ido Schimmel --- drivers/net/vxlan/vxlan_core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 1e55c5582e67..e473200b731f 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -3083,6 +3083,9 @@ static const struct net_device_ops vxlan_netdev_ether_ops = { .ndo_fdb_del = vxlan_fdb_delete, .ndo_fdb_dump = vxlan_fdb_dump, .ndo_fdb_get = vxlan_fdb_get, + .ndo_mdb_add = vxlan_mdb_add, + .ndo_mdb_del = vxlan_mdb_del, + .ndo_mdb_dump = vxlan_mdb_dump, .ndo_fill_metadata_dst = vxlan_fill_metadata_dst, };