From patchwork Mon Mar 15 14:34:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 12139679 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DBECC433E6 for ; Mon, 15 Mar 2021 14:38:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DCD2964F6B for ; Mon, 15 Mar 2021 14:38:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236574AbhCOOg6 (ORCPT ); Mon, 15 Mar 2021 10:36:58 -0400 Received: from mail-dm6nam10on2069.outbound.protection.outlook.com ([40.107.93.69]:28256 "EHLO NAM10-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236558AbhCOOfz (ORCPT ); Mon, 15 Mar 2021 10:35:55 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jqkm5uylnu7bMuCVAW1+2psO6Inaubpby6Qf35/Xl+LN+5FGjA0B3oWijPqsZ1vtR0JxpN3BTE+aeS2m1/gtHxj7neqIAjbLWkfBz79VnKvtP8DMgB+eOInMZTwWI0i9tF5dGvuzSgyzo9jYtEQI0fkB4F4KpJ9bN+jSr3STm9GMlmDph+tzzDCycjWa3S9SBgei/gBxJQmD0gRFQarDZoXxF3ycmYFTTKUbmYigOtbeO8VGdn70Wy2NMnVJAhreXDDqQkkVisbtM5Nifvz7x+SVt12wU4LZpc6K5cjmpgVoayOwxPQWEjjPzsxL+5fCI0wFA/uXUQztYgWoa/zOiQ== 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-SenderADCheck; bh=orKrKWhrp7NT6BGrZmtid8GI7yYCLyAvm8tDvJ7Moik=; b=koKhVoq1psgCVt+afCWJlDPzWDvDTwH4HD77FKLyXT5DzCrwONeAm0DLyE4ljuFhsXQVZp3yINxz3JxdylfuSNlzR0Pc28P6SsEOYOKuS3ZOjQSCvdnspZkAyI3wvc1UJPQco/yAFR6qosgPRYvwBAYV//XeA4T7eAy1Y10sLIWddfVTFX6TGW2ijpk1iT0dIzSAHauJ4RGm5VeADfHtLFUiXt6x0r1catfPLHSLWNbIrhQnBOhL+L4LYUPLj+s1fD3DmxdFk6laejEj8BrXEYo4IZ4tfMwwm7TGDIkvIo7+q6+w58ZyPaf1gToVMeDcG2IxKh3HEdsY1vJ0/79RKw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=networkplumber.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=orKrKWhrp7NT6BGrZmtid8GI7yYCLyAvm8tDvJ7Moik=; b=mJRHZfQYoFIlwld8TJe9j17UuhIuLULyRshFvf8uvDSwvvASdG9/f0wmAFPvBD9EA1N26fVS8uuKKt8G6PggAcXQ0z6/lZBcdbXsRAWe/qqDOvEwQv89QWKeopHQpbUKWRCX6D2auY9g+FnhzRpk5vnv5LR+DXxBUwWEkCrRChTl28I2QBfEmkr+rB6RbFtMJv2KYbE6lw0ECTCq75Nu4GOXQV/t4qhDpB37DTeNDlBMsxh7MF09aQy4J20WGLmnxsRhZTvoD4tES42sbBio5HL6JSrCKM7zmFNcF9e1z0yjU+U5muG+ZkJ4+EO5TOy4J/ev/BWNhnpmSbyasgcWpw== Received: from DM6PR10CA0007.namprd10.prod.outlook.com (2603:10b6:5:60::20) by BL1PR12MB5064.namprd12.prod.outlook.com (2603:10b6:208:30a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.31; Mon, 15 Mar 2021 14:35:53 +0000 Received: from DM6NAM11FT052.eop-nam11.prod.protection.outlook.com (2603:10b6:5:60:cafe::72) by DM6PR10CA0007.outlook.office365.com (2603:10b6:5:60::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.31 via Frontend Transport; Mon, 15 Mar 2021 14:35:52 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; networkplumber.org; dkim=none (message not signed) header.d=none;networkplumber.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by DM6NAM11FT052.mail.protection.outlook.com (10.13.172.111) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.3933.31 via Frontend Transport; Mon, 15 Mar 2021 14:35:52 +0000 Received: from localhost.localdomain (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 15 Mar 2021 14:35:49 +0000 From: Petr Machata To: , , CC: Ido Schimmel , Petr Machata Subject: [PATCH iproute2-next v2 1/6] nexthop: Synchronize uAPI files Date: Mon, 15 Mar 2021 15:34:30 +0100 Message-ID: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e0d0f6c0-4aff-4bbf-ac72-08d8e7bfa2b6 X-MS-TrafficTypeDiagnostic: BL1PR12MB5064: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9GJQo73O5RyrcArtLUvW9UJBvI4LPK+Ri1JEcp2JJ4w8ikGiqE4Ds7eXqJt1QpYi/9jRutQoduRqWVrM5H+ALscj6sEaFuz6v+pf3ZMPN81gM7QQIg7tfmEvrBzh6kSF3dEfuH/YSGHEzaTsxsvkeoK7NQvsRwvCMJ0Krg56JtV6Aipsz72OXpbkYCYZkS1yT6NUrO0vlYbKc+VLOcZZFTQgiJ1oqltjKBPheXCTGAqY8kaL0pDWhLs7AK6xlYHutCx+NREJGugXLndNG3WtTczKWckJGSoLLDjfj0hErFjBfDMHZrVYoPwybBJB5eKEwfnaVeIUgkxIDLN0cY60hxBw3uir580eTjMMYIN/qhuBxJqIciFVLE8SOhggh5BQICF9nwb/q4UfK9xYpjgPDS9mJ8VrEIHo1GcXbqEWhJenpDkySRjO8/l0VHEXSAXhCtCnrltMqBJxPZq84x4htkTPHACo/UyOmCYfRY5aE3s0JqUN9PYqmTYI5J8e5xTbA2r5jPRYynRb/FlILHpRE6EAF1nfer+cqh/2QjrgskmQrleM/W51ALaplHGwk7za6EiUIPWhMP7WmJN5pCrtpUgjw0b7Tlr/fdlFZXt2pZWxsKCU6MuC6/eyMNe7h1d5Va/HtszoBK6U90rBGlrTRaA0kgNGAqFvlaUayKAg0wT8+fjPLMehqEGj/ixZdtpk X-Forefront-Antispam-Report: CIP:216.228.112.34;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid03.nvidia.com;CAT:NONE;SFS:(4636009)(39860400002)(376002)(136003)(396003)(346002)(36840700001)(46966006)(26005)(186003)(36906005)(316002)(16526019)(107886003)(6666004)(86362001)(5660300002)(110136005)(70586007)(70206006)(82740400003)(54906003)(2906002)(356005)(7636003)(8936002)(36860700001)(34020700004)(4326008)(8676002)(478600001)(336012)(426003)(2616005)(83380400001)(47076005)(82310400003)(36756003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2021 14:35:52.6586 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e0d0f6c0-4aff-4bbf-ac72-08d8e7bfa2b6 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.34];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT052.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5064 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com Signed-off-by: Petr Machata --- include/uapi/linux/nexthop.h | 47 +++++++++++++++++++++++++++++++++- include/uapi/linux/rtnetlink.h | 7 +++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/nexthop.h b/include/uapi/linux/nexthop.h index b0a5613905ef..37b14b4ea6c4 100644 --- a/include/uapi/linux/nexthop.h +++ b/include/uapi/linux/nexthop.h @@ -21,7 +21,10 @@ struct nexthop_grp { }; enum { - NEXTHOP_GRP_TYPE_MPATH, /* default type if not specified */ + NEXTHOP_GRP_TYPE_MPATH, /* hash-threshold nexthop group + * default type if not specified + */ + NEXTHOP_GRP_TYPE_RES, /* resilient nexthop group */ __NEXTHOP_GRP_TYPE_MAX, }; @@ -52,8 +55,50 @@ enum { NHA_FDB, /* flag; nexthop belongs to a bridge fdb */ /* if NHA_FDB is added, OIF, BLACKHOLE, ENCAP cannot be set */ + /* nested; resilient nexthop group attributes */ + NHA_RES_GROUP, + /* nested; nexthop bucket attributes */ + NHA_RES_BUCKET, + __NHA_MAX, }; #define NHA_MAX (__NHA_MAX - 1) + +enum { + NHA_RES_GROUP_UNSPEC, + /* Pad attribute for 64-bit alignment. */ + NHA_RES_GROUP_PAD = NHA_RES_GROUP_UNSPEC, + + /* u16; number of nexthop buckets in a resilient nexthop group */ + NHA_RES_GROUP_BUCKETS, + /* clock_t as u32; nexthop bucket idle timer (per-group) */ + NHA_RES_GROUP_IDLE_TIMER, + /* clock_t as u32; nexthop unbalanced timer */ + NHA_RES_GROUP_UNBALANCED_TIMER, + /* clock_t as u64; nexthop unbalanced time */ + NHA_RES_GROUP_UNBALANCED_TIME, + + __NHA_RES_GROUP_MAX, +}; + +#define NHA_RES_GROUP_MAX (__NHA_RES_GROUP_MAX - 1) + +enum { + NHA_RES_BUCKET_UNSPEC, + /* Pad attribute for 64-bit alignment. */ + NHA_RES_BUCKET_PAD = NHA_RES_BUCKET_UNSPEC, + + /* u16; nexthop bucket index */ + NHA_RES_BUCKET_INDEX, + /* clock_t as u64; nexthop bucket idle time */ + NHA_RES_BUCKET_IDLE_TIME, + /* u32; nexthop id assigned to the nexthop bucket */ + NHA_RES_BUCKET_NH_ID, + + __NHA_RES_BUCKET_MAX, +}; + +#define NHA_RES_BUCKET_MAX (__NHA_RES_BUCKET_MAX - 1) + #endif diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h index b34b9add5f65..f62cccc17651 100644 --- a/include/uapi/linux/rtnetlink.h +++ b/include/uapi/linux/rtnetlink.h @@ -178,6 +178,13 @@ enum { RTM_GETVLAN, #define RTM_GETVLAN RTM_GETVLAN + RTM_NEWNEXTHOPBUCKET = 116, +#define RTM_NEWNEXTHOPBUCKET RTM_NEWNEXTHOPBUCKET + RTM_DELNEXTHOPBUCKET, +#define RTM_DELNEXTHOPBUCKET RTM_DELNEXTHOPBUCKET + RTM_GETNEXTHOPBUCKET, +#define RTM_GETNEXTHOPBUCKET RTM_GETNEXTHOPBUCKET + __RTM_MAX, #define RTM_MAX (((__RTM_MAX + 3) & ~3) - 1) }; From patchwork Mon Mar 15 14:34:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 12139681 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 262E0C43381 for ; Mon, 15 Mar 2021 14:38:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE28B64FE3 for ; Mon, 15 Mar 2021 14:38:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237159AbhCOOhA (ORCPT ); Mon, 15 Mar 2021 10:37:00 -0400 Received: from mail-co1nam11on2086.outbound.protection.outlook.com ([40.107.220.86]:1344 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236587AbhCOOf5 (ORCPT ); Mon, 15 Mar 2021 10:35:57 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F0l/zeZV466tUyawGQ/TkJeHgxP5PuO5RwgVqndFo5URBaTiNYjaR1yJHrdFBo80ULbHbxd86p53DMHJ2tP97o7I/+UxX8yLXA6eEFydl9kH9ujSMnV64ir2264zp58mYpHV2B2UslvAR1pbG7w++7qbqEyHBWhZb9KJOIgAQsrdGPtlQgjYBg1pWUdKVmt4QYUTRin8YJQb33qEmmgfl/cYcXCMkmf0bjdKPBTD5rTrhkGKy46S4ChvQ+zED8A3sCnGZmrS0rSrMz0AleiUdyROQOCOTcyONIaPCL8E9ixF29M0iXNA+AutgJ9javX9AjEDVhmzQWj/ZV04pewmjg== 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-SenderADCheck; bh=NisMVXNbyB6hiNoXSyUH8kMatxBXFUxokbytJR0tyhw=; b=d8s8ViIzrfI3qPxxISVB3F0ErMMjQs0DmOqUauDwyZhSLhT633pJGtEocI2STEH+Gwz/qhyn8zLnGhfv1AR/D5SUqRfmtwb18Ifns5rjzTd3y5/m24m3xwxv9ZYI1xvHKwKLSwly/3RIRgUo7m80VZ+AGv1VtoIReyBpF5bYdDbJbC9f5fnoBshHPFsDqP3wxsKTR+yu8OrYFa8I4ZvDC1GT62+CXCzvIsmLis22liK/+EqbHwBcjj6Y25XIItvedGrMu1zk/MhrmiFUlxK2cn7yMycKq1ugmAjDbVcisKWj1MbKdRzSJHmzcg282l2DRS4U16ICZ+peFXlq2XL99A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=networkplumber.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=NisMVXNbyB6hiNoXSyUH8kMatxBXFUxokbytJR0tyhw=; b=YQTTi2pRmCeb5a7KdVCNxWCOIgHK1jXfwDhFzHnsJMtp8ZUNFhgElubQ1A0mbd+2fapeO9xAyOmG3QZLHyswT7dVACt5e46KV9QlR7n5z0Vqg9CY+rEtGspTng47B/PyoU5pNrYx7Q3lWB01QVl0AuMqMi7bXHRRcsuT2IRl1ZWlkpgaw2FMdXfjdatlCKDty6fhOGXGPdA63sGpEXVGHmWvri/3gek70PNypSPOt6dJ4p7r64zfN4mDhfNP5TAGldG2a2VLU4IJhyw3LskfteVXV/jJsxJVvb6H17B+xE3eXyJfWOvUbj8fMwToAszVYTVUyGX73Xac1aaT4ywypg== Received: from DM5PR19CA0025.namprd19.prod.outlook.com (2603:10b6:3:9a::11) by DM6PR12MB3930.namprd12.prod.outlook.com (2603:10b6:5:1c9::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.28; Mon, 15 Mar 2021 14:35:55 +0000 Received: from DM6NAM11FT023.eop-nam11.prod.protection.outlook.com (2603:10b6:3:9a:cafe::b4) by DM5PR19CA0025.outlook.office365.com (2603:10b6:3:9a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.31 via Frontend Transport; Mon, 15 Mar 2021 14:35:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; networkplumber.org; dkim=none (message not signed) header.d=none;networkplumber.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by DM6NAM11FT023.mail.protection.outlook.com (10.13.173.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.3933.31 via Frontend Transport; Mon, 15 Mar 2021 14:35:55 +0000 Received: from localhost.localdomain (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 15 Mar 2021 14:35:52 +0000 From: Petr Machata To: , , CC: Ido Schimmel , Petr Machata Subject: [PATCH iproute2-next v2 2/6] json_print: Add print_tv() Date: Mon, 15 Mar 2021 15:34:31 +0100 Message-ID: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ed84a229-5285-4f40-6c15-08d8e7bfa442 X-MS-TrafficTypeDiagnostic: DM6PR12MB3930: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3513; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MWC1nHc4TahaWM9PI+e43VUycBEESg8QfoFIpNUj2VixeWAUFaL9Mpwp+ls2W4Dm6fo0N/qwb5x1fPWGA/StnabZ04Hs5OnjuNnHMjIOe3akFx9P2CguI4DsScGZwG7bjGTRqv+lCJUR/6AJyR1TBaZlCqw0SDGqmkfCcTQHWby6f1Y0Nhu3knSUHyn8TR8Glv1Hji82KeJ12hgTigo9fBVVkKhQ8xSWBphuXh3TBOmss79H89w9Pcp2ye/+kEeK4N8e5Xdtex2u+2lnSqfaYhv1iV0JLQVu24FcKLWzxz3ckeRmbLat1Iiu7YoEztYJnK1C3p1oJTE+1x/rfCgF+WbPoXSvTsemiaSJYQpzts4YDiOw9au9GzmmglID3ZBzX4cEYF3ppHypbceyzEjRypa9v94PSujFYXeCogdzLmPYmQTMt2Rfn5IgIrSgHyh/QlesxwloH4xTAk0DXJr4o6DN7sWNJYg6pyoJ4ElWymKPRpX/TPaEty+jnKTF4x6j+ch1xyVG8yYxTJCO5Fn+OFgv2Yg0erME1XaQxBMRhls+nGQnjySvQfQ70yXbG2GvzA2zY3hY3zI+UHu9bjxdXaV/ysKljAPjzL83bkfmuW7K50tBoWGga7qTodRv7D7C4sVefiwO2niFo4NAB857brYIq37ZowxXu2ElobG6JFAju1enNlsBIw7NjWjep/2n X-Forefront-Antispam-Report: CIP:216.228.112.34;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid03.nvidia.com;CAT:NONE;SFS:(4636009)(136003)(39860400002)(376002)(346002)(396003)(46966006)(36840700001)(70586007)(26005)(16526019)(70206006)(107886003)(336012)(5660300002)(47076005)(4326008)(186003)(36756003)(2906002)(36860700001)(54906003)(2616005)(110136005)(34020700004)(316002)(36906005)(6666004)(82310400003)(8676002)(86362001)(356005)(426003)(8936002)(82740400003)(7636003)(478600001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2021 14:35:55.2042 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ed84a229-5285-4f40-6c15-08d8e7bfa442 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.34];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT023.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3930 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com Add a helper to dump a timeval. Print by first converting to double and then dispatching to print_color_float(). Signed-off-by: Petr Machata --- include/json_print.h | 1 + lib/json_print.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/json_print.h b/include/json_print.h index 6fcf9fd910ec..63eee3823fe4 100644 --- a/include/json_print.h +++ b/include/json_print.h @@ -81,6 +81,7 @@ _PRINT_FUNC(0xhex, unsigned long long) _PRINT_FUNC(luint, unsigned long) _PRINT_FUNC(lluint, unsigned long long) _PRINT_FUNC(float, double) +_PRINT_FUNC(tv, struct timeval *) #undef _PRINT_FUNC #define _PRINT_NAME_VALUE_FUNC(type_name, type, format_char) \ diff --git a/lib/json_print.c b/lib/json_print.c index 994a2f8d6ae0..1018bfb36d94 100644 --- a/lib/json_print.c +++ b/lib/json_print.c @@ -299,6 +299,19 @@ int print_color_null(enum output_type type, return ret; } +int print_color_tv(enum output_type type, + enum color_attr color, + const char *key, + const char *fmt, + struct timeval *tv) +{ + double usecs = tv->tv_usec; + double secs = tv->tv_sec; + double time = secs + usecs / 1000000; + + return print_color_float(type, color, key, fmt, time); +} + /* Print line separator (if not in JSON mode) */ void print_nl(void) { From patchwork Mon Mar 15 14:34:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 12139683 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3E3AC4332E for ; Mon, 15 Mar 2021 14:38:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BFD1064FE3 for ; Mon, 15 Mar 2021 14:38:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237845AbhCOOhD (ORCPT ); Mon, 15 Mar 2021 10:37:03 -0400 Received: from mail-mw2nam10on2041.outbound.protection.outlook.com ([40.107.94.41]:51873 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236622AbhCOOgB (ORCPT ); Mon, 15 Mar 2021 10:36:01 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BvXzhdBLwSyrxmzAyidsKKpVxZgVDI5Uwp8retppp5yUtgQMkvyN1wJT6y0JwG9CjtgHzVSHrCOVS6yrRlrYd6LhyJh7YZ4+Tfb7Tb9xdWnsgjNejuOQtxmnJR8rYyX4tOnjipJ4GWiycffeuxt/du9+KgMRNJ/EoIb0zH+H39k8Bi29lQPaYJhwl/xck7k4t7QH1+kuOcqSKuMJQ0tCfi3/b9Fjnr7/8JE8h+ZBXJw3X38gAG5/BtjDuI3nsiv0RdkzZwc7tOq6Fv/8VhBhnjbf4lytKex6XOKUV/3WYJoCS7HbGyVcZk2OyRPuWNSeaXAjP/mwjhYS6yqPir3/wQ== 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-SenderADCheck; bh=2PhAeooF7UHYWwgYCsdXUTXGDkxdhUyTUFaLzbVrx+I=; b=cjiBqiGeGd89i07tGn+VoHz5I3vsgwej1ig+GPIq0dq+N2mg+B8GV2emqNeTpwsz4o7shNsrkLdmejodIZPTshRdFo/lxegeX10VfST/BFi0q3egSTVne7NAL6GgTJCbV5fxyayjNZ9NA4+lLKpp8SldR68mBnmw3GFsuVNQV3tPlF4eTjqJzEpbSCnnRy21BqmZtv3vreBhxjFvbLDCD2H1Kvt3b9beDZMo4whZijZWwXUKWpaULPEbDz2eDsgS1usBldxbGJjRMuOEKgFPRBX4Zi4nLQSBc5hml13CxO74GH9/SdUeazYrNrRQMwvNr09Z3QyC6HX+Jrl7gJekrQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=networkplumber.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=2PhAeooF7UHYWwgYCsdXUTXGDkxdhUyTUFaLzbVrx+I=; b=BoSQ9KZCY3MbTW5t0mOibLKm3fmUkuWJhbjWzUMftjS+2Rs+Tmxh0OjYT/M5JH8nKJH2vjVT2mP0g8wWCjkTw63sIKVGJASC7EnkzkQKQW78tJDRmnpazLI5fVYTOrBGY0VeqONDuCO/qIPSEq+qpUEBmZsRxckfJEB9t9wF3WODdA1Npk5Xb9cpw46IzrW4UyUpAczqhyS8l5Ve2reRnICDN269kG1UriB937/10pzzz7YlD0W0w2x/aKaYuLmJaljKBRuoEFBRobpjVkQAGRL1v2V5s3u8uC69YlihALL1x8+qwuIY1T2n8d7dxHSgkQaera4Sxko4/7mmNMRGTg== Received: from DM6PR08CA0033.namprd08.prod.outlook.com (2603:10b6:5:80::46) by BN6PR12MB1651.namprd12.prod.outlook.com (2603:10b6:405:4::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.32; Mon, 15 Mar 2021 14:35:58 +0000 Received: from DM6NAM11FT067.eop-nam11.prod.protection.outlook.com (2603:10b6:5:80:cafe::3f) by DM6PR08CA0033.outlook.office365.com (2603:10b6:5:80::46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.31 via Frontend Transport; Mon, 15 Mar 2021 14:35:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; networkplumber.org; dkim=none (message not signed) header.d=none;networkplumber.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by DM6NAM11FT067.mail.protection.outlook.com (10.13.172.76) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.3933.31 via Frontend Transport; Mon, 15 Mar 2021 14:35:57 +0000 Received: from localhost.localdomain (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 15 Mar 2021 14:35:54 +0000 From: Petr Machata To: , , CC: Ido Schimmel , Petr Machata Subject: [PATCH iproute2-next v2 3/6] nexthop: Extract a helper to parse a NH ID Date: Mon, 15 Mar 2021 15:34:32 +0100 Message-ID: <1a961d43333b47ed18c9ccbec84c838e47eb3067.1615818031.git.petrm@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 405bd703-ac74-4680-aec6-08d8e7bfa5bd X-MS-TrafficTypeDiagnostic: BN6PR12MB1651: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1388; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lHXuGnfPHdRdpRCku6ikvXzsYM2cvEjDVRaP23KlnHEVQhc4BCEeIinVFL7sxkn7g4GJ2gHrXuubtPSHCvANYqMM5jMKp9fQV6z2n695ut6gkbvtrxBZRwTKmeq/iFvLJhJz/m2YHbSZ5+44ICgy0fXbukrNupdX4x6vzIdqOkaeDEFumcFWDKCcd805M895yVHdWe4O92kFD0bQATqsgkeo0T9GpAsDMJl3/ujUpZiESgNmqP+bYMHtd5lRiy4J0tgJ8lKLZcsy7O2m8cDWz7iqAvrba6OjUydr/XjuMCvgrNg4/ge1oPdSimSVnC8S9mXSD4PiwKklxc9d9cMI6qdqbtkSwxYmjVkFaXFWQHfm972apWmLxJ3ZnaTEbwqNjVk5rPOvc3xckXUha9mudJECurWj5X+TovRowKW3WM24/oaWERzchewC4GIL4mP9p4ms34cuOtTdOs+O3i6F2r5Uy83eLWiKBHYzhr4tud+wNtWSJYDTQdWiDJx3co3jgTRB0IeLw4kXy1S64OslgLvW5AlluKwJCvFCVbVEf/UR97l2HAbICUWHh1uqdvu8sZDFgwZiektRfd8Y1SHjnbBWU8VlrM9UmDovv/hhrQBEm6QKrcuNe/zmOUH87Oc64SrbPZYnRiITCM6w6H7L9S8/fkakcms/Z4/PKeJqScm6c8mYYOkAn4JwHTzsXepQ X-Forefront-Antispam-Report: CIP:216.228.112.34;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid03.nvidia.com;CAT:NONE;SFS:(4636009)(39860400002)(376002)(396003)(346002)(136003)(36840700001)(46966006)(2616005)(110136005)(54906003)(316002)(6666004)(478600001)(2906002)(83380400001)(5660300002)(36906005)(86362001)(8676002)(82740400003)(8936002)(70586007)(4326008)(26005)(47076005)(16526019)(7636003)(36860700001)(186003)(36756003)(336012)(82310400003)(34020700004)(426003)(70206006)(356005)(107886003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2021 14:35:57.6667 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 405bd703-ac74-4680-aec6-08d8e7bfa5bd X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.34];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT067.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1651 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com NH ID extraction is a common operation, and will become more common still with the resilient NH groups support. Add a helper that does what it usually done and returns the parsed NH ID. Signed-off-by: Petr Machata --- ip/ipnexthop.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c index 20cde586596b..126b0b17cab4 100644 --- a/ip/ipnexthop.c +++ b/ip/ipnexthop.c @@ -327,6 +327,15 @@ static int add_nh_group_attr(struct nlmsghdr *n, int maxlen, char *argv) return addattr_l(n, maxlen, NHA_GROUP, grps, count * sizeof(*grps)); } +static int ipnh_parse_id(const char *argv) +{ + __u32 id; + + if (get_unsigned(&id, argv, 0)) + invarg("invalid id value", argv); + return id; +} + static int ipnh_modify(int cmd, unsigned int flags, int argc, char **argv) { struct { @@ -343,12 +352,9 @@ static int ipnh_modify(int cmd, unsigned int flags, int argc, char **argv) while (argc > 0) { if (!strcmp(*argv, "id")) { - __u32 id; - NEXT_ARG(); - if (get_unsigned(&id, *argv, 0)) - invarg("invalid id value", *argv); - addattr32(&req.n, sizeof(req), NHA_ID, id); + addattr32(&req.n, sizeof(req), NHA_ID, + ipnh_parse_id(*argv)); } else if (!strcmp(*argv, "dev")) { int ifindex; @@ -485,12 +491,8 @@ static int ipnh_list_flush(int argc, char **argv, int action) if (!filter.master) invarg("VRF does not exist\n", *argv); } else if (!strcmp(*argv, "id")) { - __u32 id; - NEXT_ARG(); - if (get_unsigned(&id, *argv, 0)) - invarg("invalid id value", *argv); - return ipnh_get_id(id); + return ipnh_get_id(ipnh_parse_id(*argv)); } else if (!matches(*argv, "protocol")) { __u32 proto; @@ -536,8 +538,7 @@ static int ipnh_get(int argc, char **argv) while (argc > 0) { if (!strcmp(*argv, "id")) { NEXT_ARG(); - if (get_unsigned(&id, *argv, 0)) - invarg("invalid id value", *argv); + id = ipnh_parse_id(*argv); } else { usage(); } From patchwork Mon Mar 15 14:34:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 12139685 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F65DC43332 for ; Mon, 15 Mar 2021 14:38:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F323165039 for ; Mon, 15 Mar 2021 14:38:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238231AbhCOOhK (ORCPT ); Mon, 15 Mar 2021 10:37:10 -0400 Received: from mail-eopbgr770052.outbound.protection.outlook.com ([40.107.77.52]:20803 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236638AbhCOOgC (ORCPT ); Mon, 15 Mar 2021 10:36:02 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dWaDeMXwtfl6xbVzSrteEi0YBVDMKGal8zhgvKagLIKAq0VOMnrU+sRBdGF1fPTq4pzWOcJlB5t2awJ5ra307Wtr7TAlof+KGerzZNSCVJ0GSBhV48yUOwCT5FE+LK9MCnCO2UEJmY8yTwgaTj8TNygUCrq1U/tjIHftbbZi1Tuz9bMhyAbHjgAZ7HnqJrMjRn+Er7UWOgE+tMtI0CefYgN2LxZeITvCg2WVL98CSEm3Jg44w+wYT+Q3ucPEsjUcIQ8vkkrK0Z1mOjnsR88KNYDCHEMRjR7+BV2GMRPJi9Zv0DMiVfo885ktzHfeNdLLan7U9tMMWu7IUr2ZZXPAxw== 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-SenderADCheck; bh=sJJ0H2cSUk7/V2Q2G33NCiuMrjri0nRsFbphBjnf+GY=; b=e+FZj2/uNxwuwQp925v9yzr2mhzpKF6PB1ZeYKsbSsICZqel+pHcOpsbYtXXfsi/aOt9/iVjVCqS7H85OmNthQ0st/9+BztRsLpeyOExuMsHEuv+Id0kO+P6J+3U/a9ioSfuFeHeHX4hzq+ETTBmuSz3OlGcf089ZZwB0Ls0VUnogcA/U0IV6FhetSIyiDDYnS6PQNyP5UXmQputN8GzNLrjb3ToU9l42cTXubKA7LSaPWyKLlrowzurzjHMdJ23HhPE0//QZHP59AcS9sCY9aIbgsQol6cDy9THlxd4Ae2OMzC6mYYlgYkmUmxwzwKhA4Pfc70MWb2eGIQOF5TOsg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=networkplumber.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=sJJ0H2cSUk7/V2Q2G33NCiuMrjri0nRsFbphBjnf+GY=; b=VBpc/iDRtBia2qGT26OPKRYV37F7N74UyJY+HJu/FefYufCyYZDD/omTaIxyNNyzYiSvpvFrDhf2ObAdL6MB4XTaeWrl9ZUiUckF22UD3kWVZuo0DgJC+v/v9XnNE2jpZg0LqatkHFdd0rcHvBxajY1NIQ6filmiyIL86xRlj6GwM29ZEzfoDMYmtFtj6tGay7TV6AXu2WuBTIvnd5/MflTMJqJr++ILsOhAz8R8RwNU8dcUM75C/9XjcvXrO4/WQJezrN5sHGeEblhQqFetI4LWqrkBiqCcKtUMt/aZkvWJ0zU8U9cq9Kq47GI+WvfbVZ9tFafd4QfzsTO+oUON4A== Received: from DM6PR14CA0070.namprd14.prod.outlook.com (2603:10b6:5:18f::47) by CH0PR12MB5041.namprd12.prod.outlook.com (2603:10b6:610:e0::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.32; Mon, 15 Mar 2021 14:35:59 +0000 Received: from DM6NAM11FT027.eop-nam11.prod.protection.outlook.com (2603:10b6:5:18f:cafe::be) by DM6PR14CA0070.outlook.office365.com (2603:10b6:5:18f::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.32 via Frontend Transport; Mon, 15 Mar 2021 14:35:59 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; networkplumber.org; dkim=none (message not signed) header.d=none;networkplumber.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by DM6NAM11FT027.mail.protection.outlook.com (10.13.172.205) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.3933.31 via Frontend Transport; Mon, 15 Mar 2021 14:35:59 +0000 Received: from localhost.localdomain (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 15 Mar 2021 14:35:57 +0000 From: Petr Machata To: , , CC: Ido Schimmel Subject: [PATCH iproute2-next v2 4/6] nexthop: Add ability to specify group type Date: Mon, 15 Mar 2021 15:34:33 +0100 Message-ID: <2e3328b34e571d00c7ff676624e6af2aebdcec62.1615818031.git.petrm@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d6db66a5-b9e7-4efb-887b-08d8e7bfa6d3 X-MS-TrafficTypeDiagnostic: CH0PR12MB5041: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:849; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5DdKDGx8Ukicv8vicDAKtRiiEdLoPJdx0d/F8Zdu/hM5xFuKQRCnYtYMa8ch6l4UtAX7l1kFMzAp1KL75RdeWYTiWPXp2fOKFm5Rco39g8uOi1ilPyZr269GvFa1zJR+LwtB/ALfWBFl9VfxazB0ZkjShFk3qx+xjVKqKJ64gquO/mPgYgk7USZPxzHvqpipuyF8OWq3YysbGIHInpwOCfM8vN+SoeoDxedQBdjOloQ6LuTJJC9OgP/vn+yvRPLyo4OLYiokjgMPFilVVvekTqMpDiXodfmsV8AODxQSPuK4gYgXxXJSA9ZoToT78juQFvgI2ggDyfSuqZySaZfiLvynNjbO2KeQMiRPFFDFNl9bB2BxpnOB8ulP7NQkwfZkq1jwZN7QG6dM62ZhE2wkeF5xKcV/LInLsD2FcAbKtKkBoALvDY5sJeHp2ye8Y767ITWTqqYcFJFBwNCG4IqvkKhTtS3RU5T5FoNGgCmB1QRUgohzEZlpWwB3Ql4iDxvAWTsDd4IXbtItYUAT3br2C/zMFYrC7LnPL/1OTFzxWSH682w5UbyVPNCig92gnXgKjEDApyoEL/v6whByb+pXz5RJx+teCCPW8BJnahPVenEpBbv75WWCPSGjjPLA7jTiNzzAesxdDPRggXdgodVQkE2BzKiAnSdrgtineW/AHQA2Hsf/PCaoSSVa1gJ2umtq X-Forefront-Antispam-Report: CIP:216.228.112.34;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid03.nvidia.com;CAT:NONE;SFS:(4636009)(346002)(39860400002)(376002)(396003)(136003)(46966006)(36840700001)(36906005)(110136005)(316002)(83380400001)(70206006)(16526019)(70586007)(82310400003)(47076005)(2906002)(8936002)(82740400003)(86362001)(186003)(107886003)(4326008)(8676002)(336012)(6666004)(426003)(5660300002)(36860700001)(478600001)(26005)(7636003)(36756003)(356005)(34020700004)(2616005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2021 14:35:59.5576 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d6db66a5-b9e7-4efb-887b-08d8e7bfa6d3 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.34];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT027.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5041 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com From: Ido Schimmel Next patches are going to add a 'resilient' nexthop group type, so allow users to specify the type using the 'type' argument. Currently, only 'mpath' type is supported. These two commands are equivalent: # ip nexthop add id 10 group 1/2/3 # ip nexthop add id 10 group 1/2/3 type mpath Signed-off-by: Ido Schimmel --- Notes: v2: - Add a missing example command to commit message - Mention in the man page that mpath is the default ip/ipnexthop.c | 32 +++++++++++++++++++++++++++++++- man/man8/ip-nexthop.8 | 19 +++++++++++++++++-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c index 126b0b17cab4..5aae32629edd 100644 --- a/ip/ipnexthop.c +++ b/ip/ipnexthop.c @@ -42,8 +42,10 @@ static void usage(void) "SELECTOR := [ id ID ] [ dev DEV ] [ vrf NAME ] [ master DEV ]\n" " [ groups ] [ fdb ]\n" "NH := { blackhole | [ via ADDRESS ] [ dev DEV ] [ onlink ]\n" - " [ encap ENCAPTYPE ENCAPHDR ] | group GROUP [ fdb ] }\n" + " [ encap ENCAPTYPE ENCAPHDR ] |\n" + " group GROUP [ fdb ] [ type TYPE ] }\n" "GROUP := [ //... ]\n" + "TYPE := { mpath }\n" "ENCAPTYPE := [ mpls ]\n" "ENCAPHDR := [ MPLSLABEL ]\n"); exit(-1); @@ -327,6 +329,32 @@ static int add_nh_group_attr(struct nlmsghdr *n, int maxlen, char *argv) return addattr_l(n, maxlen, NHA_GROUP, grps, count * sizeof(*grps)); } +static int read_nh_group_type(const char *name) +{ + if (strcmp(name, "mpath") == 0) + return NEXTHOP_GRP_TYPE_MPATH; + + return __NEXTHOP_GRP_TYPE_MAX; +} + +static void parse_nh_group_type(struct nlmsghdr *n, int maxlen, int *argcp, + char ***argvp) +{ + char **argv = *argvp; + int argc = *argcp; + __u16 type; + + NEXT_ARG(); + type = read_nh_group_type(*argv); + if (type > NEXTHOP_GRP_TYPE_MAX) + invarg("\"type\" value is invalid\n", *argv); + + *argcp = argc; + *argvp = argv; + + addattr16(n, maxlen, NHA_GROUP_TYPE, type); +} + static int ipnh_parse_id(const char *argv) { __u32 id; @@ -409,6 +437,8 @@ static int ipnh_modify(int cmd, unsigned int flags, int argc, char **argv) if (add_nh_group_attr(&req.n, sizeof(req), *argv)) invarg("\"group\" value is invalid\n", *argv); + } else if (!strcmp(*argv, "type")) { + parse_nh_group_type(&req.n, sizeof(req), &argc, &argv); } else if (matches(*argv, "protocol") == 0) { __u32 prot; diff --git a/man/man8/ip-nexthop.8 b/man/man8/ip-nexthop.8 index 4d55f4dbcc75..b86f307fef35 100644 --- a/man/man8/ip-nexthop.8 +++ b/man/man8/ip-nexthop.8 @@ -54,7 +54,9 @@ ip-nexthop \- nexthop object management .BR fdb " ] | " .B group .IR GROUP " [ " -.BR fdb " ] } " +.BR fdb " ] [ " +.B type +.IR TYPE " ] } " .ti -8 .IR ENCAP " := [ " @@ -71,6 +73,10 @@ ip-nexthop \- nexthop object management .IR GROUP " := " .BR id "[," weight "[/...]" +.ti -8 +.IR TYPE " := { " +.BR mpath " }" + .SH DESCRIPTION .B ip nexthop is used to manipulate entries in the kernel's nexthop tables. @@ -122,9 +128,18 @@ is a set of encapsulation attributes specific to the .in -2 .TP -.BI group " GROUP" +.BI group " GROUP [ " type " TYPE ]" create a nexthop group. Group specification is id with an optional weight (id,weight) and a '/' as a separator between entries. +.sp +.I TYPE +is a string specifying the nexthop group type. Namely: + +.in +8 +.BI mpath +- Multipath nexthop group backed by the hash-threshold algorithm. The +default when the type is unspecified. + .TP .B blackhole create a blackhole nexthop From patchwork Mon Mar 15 14:34:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 12139689 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA817C43331 for ; Mon, 15 Mar 2021 14:38:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 92F2664FC4 for ; Mon, 15 Mar 2021 14:38:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238628AbhCOOhO (ORCPT ); Mon, 15 Mar 2021 10:37:14 -0400 Received: from mail-bn7nam10on2066.outbound.protection.outlook.com ([40.107.92.66]:36173 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236985AbhCOOgE (ORCPT ); Mon, 15 Mar 2021 10:36:04 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iHg3nkVUyNnXABhBN9ytgf6imFUplk0ORyS2knicZnbmJqFKW2AvCzhp/gf+UWejExl9v2L+qwYVokhYr1JSVNiW9sXlsMuF+DnZYpNw7E7T9f25fBbNKqpj4bpMGfwn5Al1G0a1Rs1YhWvtCXbKRxKKyB08pXQkxiw9yBweOLwjA3Gu/dBOxc0DtArNTdg9w+o4VjUmCh/KlZtE7Jz/NPBJt0RWQ/pb2C6SzAp8OYxJj6VR14vBkDhYMZamGBB0r5j9kUWeY3A67xUzvorVwspsMzRF+FI2G1HjFGYtOoArJqJKPYZfyi7u993Ukazd4JCq26S/1b2pF3TeJ2DXHw== 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-SenderADCheck; bh=mnY+ycZrej6yMXYMbLb7ySBOcXaoBbbASSyP9+I/UUM=; b=MkJyh0QpzbZOP3YdzGSKs6Ct92RyhOtMLMK8KW01EHlqFvE7jKCJ/8WpBZDMwir4L5+ywejV/QvMctsQ38C0QWDPKobnK7jXtvymqjq+lz9bwiWWfRKigGY+I46iTweXFLoLCLlRB+W+YRYRbbvCQ7/1NhhXMVKjlUtYgq4V6syuWU1UgbpatEmuEGxd+1J9RYuh1vn/rFmB8Kf5Ta7hNxpQ9phsw+F80VUsDg/MYNqaN5z8B5d7b7XXB5KxZHjx4dhktb1eJVHCt9lkCvnOz3E+1m1qPklYOczhbPLV62wFW1C+NQwJU3J7qSeY6WExIQR5Dcx7yzagRY1WrmqJ/Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=networkplumber.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=mnY+ycZrej6yMXYMbLb7ySBOcXaoBbbASSyP9+I/UUM=; b=DDM0q7X8kZTAkR5HZJkRPJeZA4P2MfYnz2Fu4yFYMpSW57FfJCrmSi5Uz+iLwiM6qF+MPTcuRg2RmoKIcl/CeciXEzLniV6ieF6B9cKX+gjdfOnAhyz1/DjT99GH4JT7a6uJ1waWgmxXeHrlr+oomEvIn1bYU2Vf/FTP8UtF5V3sgltokVXmPCunXFhRvCMf4NJX06NXE9uVe3ZixVFbEcwvYzaOZZln2FgqmZKsYZgGbftGPF69DlsL04gRj7COa1/yVs1QCRbFpHmmvVa28FSO8QMIe0gw6v8SBpuCeS4EXv44CeyXAWAZFQhERmv/WY4ajScidiCqkZ8mKRtjiQ== Received: from DM6PR03CA0055.namprd03.prod.outlook.com (2603:10b6:5:100::32) by SA0PR12MB4541.namprd12.prod.outlook.com (2603:10b6:806:9e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.31; Mon, 15 Mar 2021 14:36:02 +0000 Received: from DM6NAM11FT062.eop-nam11.prod.protection.outlook.com (2603:10b6:5:100:cafe::e8) by DM6PR03CA0055.outlook.office365.com (2603:10b6:5:100::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.32 via Frontend Transport; Mon, 15 Mar 2021 14:36:02 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; networkplumber.org; dkim=none (message not signed) header.d=none;networkplumber.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by DM6NAM11FT062.mail.protection.outlook.com (10.13.173.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.3933.31 via Frontend Transport; Mon, 15 Mar 2021 14:36:02 +0000 Received: from localhost.localdomain (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 15 Mar 2021 14:35:59 +0000 From: Petr Machata To: , , CC: Ido Schimmel Subject: [PATCH iproute2-next v2 5/6] nexthop: Add support for resilient nexthop groups Date: Mon, 15 Mar 2021 15:34:34 +0100 Message-ID: <5d6b10405404674d01d6edb601a6028ddc9a9b6f.1615818031.git.petrm@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ac35e1b4-1192-4f01-014a-08d8e7bfa878 X-MS-TrafficTypeDiagnostic: SA0PR12MB4541: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: i63IK6W2fvDFbwu6Ye1PVK7kj1xy9KWC0Q/lTwp+MQSHWN1ytfdLFlScCUANyLLBzJfHUNSUD7NnAXuvthpJvN4Nl2Ee7f8cpFdg6ro6f8NHQs+v9S+puRHKWx1lsvItAhK5C8gffnQsEgmt8vuy29I91KttScO3oniW3/wtxAR038NMXRK5EAA4oKIuzpWvIz1QaArl839Iki63LkIb3UFEqZQFKakRzPmOgX3G3JGNWgXGty3j7wRWQTrMPNKfLEANlNQeyOvl8yjpwVMMKEtEnIonx6Mn/a72iRUHJx2+nDRO3u95vYx1irtxsVifCgIj41qxemTOTlbdRYNdP681MMN9btutAnyND9Ksd5kAGZKkTQZlG946rNRTz2NQQVMuOoMWO6CxqkcENfIXKXaJMLR43LkWe4/98thkaXhJ9M45uU/OinTlsOKpHdqlme5CZw85xpaSli3i+K1zKTzOTCjPCq1/UHAPqdHOrNi5rk/cqN+w9MbCD0pbkEOjctltOWV5xfmpj8Io0udZEmQEKE0JARA1EAXT4pA7skQNIstbVxthOn4Va4N3cQXOuTirXlqcUbuYi7p4c7SUyr/wqACHXdODiqNVRGRUsDDNG+TBlC1cN11yorZGQdY1n4X/iNZDltF5zWK6/8Ey1cZifSrQ3W3/JPbiEuVDfGKt9TBz8VzVnMzResM8Rg1s X-Forefront-Antispam-Report: CIP:216.228.112.34;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid03.nvidia.com;CAT:NONE;SFS:(4636009)(396003)(136003)(346002)(39860400002)(376002)(36840700001)(46966006)(83380400001)(36756003)(316002)(186003)(336012)(82310400003)(36906005)(26005)(70586007)(70206006)(36860700001)(34020700004)(4326008)(7636003)(16526019)(5660300002)(426003)(8936002)(6666004)(8676002)(356005)(2906002)(107886003)(110136005)(47076005)(2616005)(86362001)(82740400003)(478600001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2021 14:36:02.1923 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ac35e1b4-1192-4f01-014a-08d8e7bfa878 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.34];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT062.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4541 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com From: Ido Schimmel Add ability to configure resilient nexthop groups and show their current configuration. Example: # ip nexthop add id 10 group 1/2 type resilient buckets 8 # ip nexthop show id 10 id 10 group 1/2 type resilient buckets 8 idle_timer 120 unbalanced_timer 0 # ip -j -p nexthop show id 10 [ { "id": 10, "group": [ { "id": 1 },{ "id": 2 } ], "type": "resilient", "resilient_args": { "buckets": 8, "idle_timer": 120, "unbalanced_timer": 0 }, "flags": [ ] } ] Signed-off-by: Ido Schimmel --- ip/ipnexthop.c | 144 +++++++++++++++++++++++++++++++++++++++++- man/man8/ip-nexthop.8 | 55 +++++++++++++++- 2 files changed, 193 insertions(+), 6 deletions(-) diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c index 5aae32629edd..1d50bf7529c4 100644 --- a/ip/ipnexthop.c +++ b/ip/ipnexthop.c @@ -43,9 +43,12 @@ static void usage(void) " [ groups ] [ fdb ]\n" "NH := { blackhole | [ via ADDRESS ] [ dev DEV ] [ onlink ]\n" " [ encap ENCAPTYPE ENCAPHDR ] |\n" - " group GROUP [ fdb ] [ type TYPE ] }\n" + " group GROUP [ fdb ] [ type TYPE [ TYPE_ARGS ] ] }\n" "GROUP := [ //... ]\n" - "TYPE := { mpath }\n" + "TYPE := { mpath | resilient }\n" + "TYPE_ARGS := [ RESILIENT_ARGS ]\n" + "RESILIENT_ARGS := [ buckets BUCKETS ] [ idle_timer IDLE ]\n" + " [ unbalanced_timer UNBALANCED ]\n" "ENCAPTYPE := [ mpls ]\n" "ENCAPHDR := [ MPLSLABEL ]\n"); exit(-1); @@ -203,6 +206,66 @@ static void print_nh_group(FILE *fp, const struct rtattr *grps_attr) close_json_array(PRINT_JSON, NULL); } +static const char *nh_group_type_name(__u16 type) +{ + switch (type) { + case NEXTHOP_GRP_TYPE_MPATH: + return "mpath"; + case NEXTHOP_GRP_TYPE_RES: + return "resilient"; + default: + return ""; + } +} + +static void print_nh_group_type(FILE *fp, const struct rtattr *grp_type_attr) +{ + __u16 type = rta_getattr_u16(grp_type_attr); + + if (type == NEXTHOP_GRP_TYPE_MPATH) + /* Do not print type in order not to break existing output. */ + return; + + print_string(PRINT_ANY, "type", "type %s ", nh_group_type_name(type)); +} + +static void print_nh_res_group(FILE *fp, const struct rtattr *res_grp_attr) +{ + struct rtattr *tb[NHA_RES_GROUP_MAX + 1]; + struct rtattr *rta; + struct timeval tv; + + parse_rtattr_nested(tb, NHA_RES_GROUP_MAX, res_grp_attr); + + open_json_object("resilient_args"); + + if (tb[NHA_RES_GROUP_BUCKETS]) + print_uint(PRINT_ANY, "buckets", "buckets %u ", + rta_getattr_u16(tb[NHA_RES_GROUP_BUCKETS])); + + if (tb[NHA_RES_GROUP_IDLE_TIMER]) { + rta = tb[NHA_RES_GROUP_IDLE_TIMER]; + __jiffies_to_tv(&tv, rta_getattr_u32(rta)); + print_tv(PRINT_ANY, "idle_timer", "idle_timer %g ", &tv); + } + + if (tb[NHA_RES_GROUP_UNBALANCED_TIMER]) { + rta = tb[NHA_RES_GROUP_UNBALANCED_TIMER]; + __jiffies_to_tv(&tv, rta_getattr_u32(rta)); + print_tv(PRINT_ANY, "unbalanced_timer", "unbalanced_timer %g ", + &tv); + } + + if (tb[NHA_RES_GROUP_UNBALANCED_TIME]) { + rta = tb[NHA_RES_GROUP_UNBALANCED_TIME]; + __jiffies_to_tv(&tv, rta_getattr_u32(rta)); + print_tv(PRINT_ANY, "unbalanced_time", "unbalanced_time %g ", + &tv); + } + + close_json_object(); +} + int print_nexthop(struct nlmsghdr *n, void *arg) { struct nhmsg *nhm = NLMSG_DATA(n); @@ -229,7 +292,7 @@ int print_nexthop(struct nlmsghdr *n, void *arg) if (filter.proto && filter.proto != nhm->nh_protocol) return 0; - parse_rtattr(tb, NHA_MAX, RTM_NHA(nhm), len); + parse_rtattr_flags(tb, NHA_MAX, RTM_NHA(nhm), len, NLA_F_NESTED); open_json_object(NULL); @@ -243,6 +306,12 @@ int print_nexthop(struct nlmsghdr *n, void *arg) if (tb[NHA_GROUP]) print_nh_group(fp, tb[NHA_GROUP]); + if (tb[NHA_GROUP_TYPE]) + print_nh_group_type(fp, tb[NHA_GROUP_TYPE]); + + if (tb[NHA_RES_GROUP]) + print_nh_res_group(fp, tb[NHA_RES_GROUP]); + if (tb[NHA_ENCAP]) lwt_print_encap(fp, tb[NHA_ENCAP_TYPE], tb[NHA_ENCAP]); @@ -333,10 +402,70 @@ static int read_nh_group_type(const char *name) { if (strcmp(name, "mpath") == 0) return NEXTHOP_GRP_TYPE_MPATH; + else if (strcmp(name, "resilient") == 0) + return NEXTHOP_GRP_TYPE_RES; return __NEXTHOP_GRP_TYPE_MAX; } +static void parse_nh_group_type_res(struct nlmsghdr *n, int maxlen, int *argcp, + char ***argvp) +{ + char **argv = *argvp; + struct rtattr *nest; + int argc = *argcp; + + if (!NEXT_ARG_OK()) + return; + + nest = addattr_nest(n, maxlen, NHA_RES_GROUP); + nest->rta_type |= NLA_F_NESTED; + + NEXT_ARG_FWD(); + while (argc > 0) { + if (strcmp(*argv, "buckets") == 0) { + __u16 buckets; + + NEXT_ARG(); + if (get_u16(&buckets, *argv, 0)) + invarg("invalid buckets value", *argv); + + addattr16(n, maxlen, NHA_RES_GROUP_BUCKETS, buckets); + } else if (strcmp(*argv, "idle_timer") == 0) { + __u32 idle_timer; + + NEXT_ARG(); + if (get_unsigned(&idle_timer, *argv, 0) || + idle_timer >= ~0UL / 100) + invarg("invalid idle timer value", *argv); + + addattr32(n, maxlen, NHA_RES_GROUP_IDLE_TIMER, + idle_timer * 100); + } else if (strcmp(*argv, "unbalanced_timer") == 0) { + __u32 unbalanced_timer; + + NEXT_ARG(); + if (get_unsigned(&unbalanced_timer, *argv, 0) || + unbalanced_timer >= ~0UL / 100) + invarg("invalid unbalanced timer value", *argv); + + addattr32(n, maxlen, NHA_RES_GROUP_UNBALANCED_TIMER, + unbalanced_timer * 100); + } else { + break; + } + argc--; argv++; + } + + /* argv is currently the first unparsed argument, but ipnh_modify() + * will move to the next, so step back. + */ + *argcp = argc + 1; + *argvp = argv - 1; + + addattr_nest_end(n, nest); +} + static void parse_nh_group_type(struct nlmsghdr *n, int maxlen, int *argcp, char ***argvp) { @@ -349,6 +478,15 @@ static void parse_nh_group_type(struct nlmsghdr *n, int maxlen, int *argcp, if (type > NEXTHOP_GRP_TYPE_MAX) invarg("\"type\" value is invalid\n", *argv); + switch (type) { + case NEXTHOP_GRP_TYPE_MPATH: + /* No additional arguments */ + break; + case NEXTHOP_GRP_TYPE_RES: + parse_nh_group_type_res(n, maxlen, &argc, &argv); + break; + } + *argcp = argc; *argvp = argv; diff --git a/man/man8/ip-nexthop.8 b/man/man8/ip-nexthop.8 index b86f307fef35..c1ac130c2a2f 100644 --- a/man/man8/ip-nexthop.8 +++ b/man/man8/ip-nexthop.8 @@ -56,7 +56,7 @@ ip-nexthop \- nexthop object management .IR GROUP " [ " .BR fdb " ] [ " .B type -.IR TYPE " ] } " +.IR TYPE " [ " TYPE_ARGS " ] ] }" .ti -8 .IR ENCAP " := [ " @@ -75,7 +75,20 @@ ip-nexthop \- nexthop object management .ti -8 .IR TYPE " := { " -.BR mpath " }" +.BR mpath " | " resilient " }" + +.ti -8 +.IR TYPE_ARGS " := [ " +.IR RESILIENT_ARGS " ] " + +.ti -8 +.IR RESILIENT_ARGS " := " +.RB "[ " buckets +.IR BUCKETS " ] [ " +.B idle_timer +.IR IDLE " ] [ " +.B unbalanced_timer +.IR UNBALANCED " ]" .SH DESCRIPTION .B ip nexthop @@ -128,7 +141,7 @@ is a set of encapsulation attributes specific to the .in -2 .TP -.BI group " GROUP [ " type " TYPE ]" +.BI group " GROUP [ " type " TYPE [ TYPE_ARGS ] ]" create a nexthop group. Group specification is id with an optional weight (id,weight) and a '/' as a separator between entries. .sp @@ -139,6 +152,37 @@ is a string specifying the nexthop group type. Namely: .BI mpath - Multipath nexthop group backed by the hash-threshold algorithm. The default when the type is unspecified. +.sp +.BI resilient +- Resilient nexthop group. Group is resilient to addition and deletion of +nexthops. + +.sp +.in -8 +.I TYPE_ARGS +is a set of attributes specific to the +.I TYPE. + +.in +8 +.B resilient +.in +2 +.B buckets +.I BUCKETS +- Number of nexthop buckets. Cannot be changed for an existing group +.sp + +.B idle_timer +.I IDLE +- Time in seconds in which a nexthop bucket does not see traffic and is +therefore considered idle. Default is 120 seconds + +.B unbalanced_timer +.I UNBALANCED +- Time in seconds in which a nexthop group is unbalanced and is therefore +considered unbalanced. The kernel will try to rebalance unbalanced groups, which +might result in some flows being reset. A value of 0 means that no +rebalancing will take place. Default is 0 seconds +.in -2 .TP .B blackhole @@ -225,6 +269,11 @@ ip nexthop add id 7 group 5/6 fdb Adds a fdb nexthop group with id 7. A fdb nexthop group can only have fdb nexthops. .RE +.PP +ip nexthop add id 10 group 1/2 type resilient buckets 32 +.RS 4 +Add a resilient nexthop group with id 10 and 32 nexthop buckets. +.RE .SH SEE ALSO .br .BR ip (8) From patchwork Mon Mar 15 14:34:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 12139687 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E7E7C432C3 for ; Mon, 15 Mar 2021 14:38:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D8EDD65065 for ; Mon, 15 Mar 2021 14:38:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239725AbhCOOhT (ORCPT ); Mon, 15 Mar 2021 10:37:19 -0400 Received: from mail-mw2nam10on2061.outbound.protection.outlook.com ([40.107.94.61]:37344 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S237018AbhCOOgH (ORCPT ); Mon, 15 Mar 2021 10:36:07 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=er52ATy8amKJf3Hygjsu/fH3AHaEqM/tEMPtJIOmBbXXkg1Ws5yNngU0AcBsPx4NASrLOjQ8EPeq/opZKdEVXT6jv3004CsSNbgpL6oFDdrfJZJi1F0E8ETrO1Qf1Z/Ux27L/4IkOkzss4vF8JVBsEBWy2wnP11xX3AvA5kqZ49bvK3gDts7AmlYRSZs989xz37ZsmMDKRS9PHnGeTBbVqqaCUsSH0HoHNUe0VoQjQxRDuqBEC+j0hEwxYzIB9pezcmYgkqHQ6qP77Vq0OnfzRRPPQ5KDvRpc1OsXg7RQPCXrBrP0htOKICHNGJ2/miOjCR1iDm7wihppDfGJZZBLA== 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-SenderADCheck; bh=YTmersw5oXt1OIXICOjbDYQPbrkeSZ4zlUCuzRjsy7k=; b=MiOXj1e6761xAbxuW+IiP3MqEDV6NfoA8Td9aeWp/kmI22yAWJWnF97qBGWR6j53iQQnnIM0Q0E62/xCNzjhJW8SpFE29xEVSxH3hfqDBfDzndNC5CmiVPacHsJ4M7VU10Tr7f+sq0uPeJGd0i5HbmA5LQgeZ7L/tOte3XosSfunCWsi9aDt7nJXmxPmoNitmXIbGpHOPzWqR41YUwbf2Yf8DgnnqpwvFsnqTtvHV1G/++L85w2RLE/qClzRemgxB6xnVDuzwWdbmzNEugaP8eTswL6aFrYBABXiuiKz/94RuMk7vNx5qcyFsljJq9Eovk3KFG3/AikDX6ty3kNwyg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=networkplumber.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=YTmersw5oXt1OIXICOjbDYQPbrkeSZ4zlUCuzRjsy7k=; b=J08CvOvcV1Jg5rI1arIonvQbv4D2ZVlWUZlVJXzkkXsWG5rk2AFF21KIJAxeEH1XhsPlHCq3kR4gAT40QZNFqII1wvkEvBG11XSDGh+7au4LggMNWZy4gcdLveHxPVdIIIvBVdi2uxOqnVDRgdj9mdUZ73nsvx1aaf3X/lHpw2hdkty46sEgJ1PHssPv9B1oELZTAf9Ff0rBPj3O0pXJ0fHaKTEPaY3aU60AKuRxMR9fiT4wkkSVDAiMXZ1AdbNMpk34fLZXlkiEJtLKIstNtaxi0TrIZUJL4qFemwPsqeWBs/+asY35BkfXu5EH32U01IV75VJ/8RX2Xwd40QWapA== Received: from DM6PR03CA0045.namprd03.prod.outlook.com (2603:10b6:5:100::22) by CY4PR12MB1702.namprd12.prod.outlook.com (2603:10b6:903:11f::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.32; Mon, 15 Mar 2021 14:36:05 +0000 Received: from DM6NAM11FT062.eop-nam11.prod.protection.outlook.com (2603:10b6:5:100:cafe::4b) by DM6PR03CA0045.outlook.office365.com (2603:10b6:5:100::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.31 via Frontend Transport; Mon, 15 Mar 2021 14:36:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; networkplumber.org; dkim=none (message not signed) header.d=none;networkplumber.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by DM6NAM11FT062.mail.protection.outlook.com (10.13.173.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.3933.31 via Frontend Transport; Mon, 15 Mar 2021 14:36:04 +0000 Received: from localhost.localdomain (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 15 Mar 2021 14:36:02 +0000 From: Petr Machata To: , , CC: Ido Schimmel Subject: [PATCH iproute2-next v2 6/6] nexthop: Add support for nexthop buckets Date: Mon, 15 Mar 2021 15:34:35 +0100 Message-ID: <819b60850b53a842f5b1ba2221b0e92708d5635f.1615818031.git.petrm@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4a6b3a59-0741-46d9-1ad8-08d8e7bfaa0e X-MS-TrafficTypeDiagnostic: CY4PR12MB1702: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:549; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DpwTVzW4FQ9FxQ0OfurV3ugi9Ftxb1IEPk8neoMZ56d3rLk9smkF8HA2ed5R9QeMqXz/tiGY5g6EGNgY9cJoZIDR0L3r9UnA1phmORGn274B0z/Nx2nrkN9GoOUZ5LLGqJeRBibEIokkbGYH7fpfSATvHdmn5E0/zCeqQf2SQNsUpOGMOBXJT0EUsKA730n8VyK2gsANp7Nci1y7X7jLc1TbHVT9vo4+H+MA1wNXq9+0qJuKMy8O+fWI8/RtRr1lBd8vGrZS496gfWvbTeKjANg90Vl9OmeC37bW+z0PPQDl8pBjO+M/98qfagt08kGVj+Na7h+ZPDuJgtvGEKbrkIZJwVx+ANde1deDrW1bDa9qWssu7/k+DQWDaK2PPBfIGFLNYSVC9Rqyn7iIcv2ikfL/pemwk1hY1apfRWWOcY1ZyhJCNnrwWz0HvYTGfJEeIywZAl4cdzutDDv3hVL2qp6GDMkRpn2EvKgq/QzyipBOv1Xt6jqW7l+SGjLjDUw2T93yGugaYhPxtxW3uVOwk9dj6eVfatG3P1tY+0fWFrth2aigVbT8i8dpajmACJhCUttrfBa/XXcZvfSLr33Z/qOB1KtiwK2lr4vy3JqaIh7M68Wh7utdTX8AyE/LSIUofWXEio5oZWbdvbng3GsFwQDNYzaPHd6oR5WKBEk9O76E9CqoXPL5utKJsn6y09My X-Forefront-Antispam-Report: CIP:216.228.112.34;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid03.nvidia.com;CAT:NONE;SFS:(4636009)(376002)(396003)(39860400002)(136003)(346002)(36840700001)(46966006)(186003)(82740400003)(70206006)(16526019)(110136005)(2616005)(8676002)(47076005)(2906002)(86362001)(336012)(356005)(70586007)(7636003)(107886003)(36756003)(478600001)(4326008)(426003)(26005)(316002)(30864003)(5660300002)(36906005)(83380400001)(6666004)(34020700004)(36860700001)(8936002)(82310400003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2021 14:36:04.9576 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4a6b3a59-0741-46d9-1ad8-08d8e7bfaa0e X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.34];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT062.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1702 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com From: Ido Schimmel Add ability to dump multiple nexthop buckets and get a specific one. Example: # ip nexthop add id 10 group 1/2 type resilient buckets 8 # ip nexthop id 1 via 192.0.2.2 dev dummy10 scope link id 2 via 192.0.2.19 dev dummy20 scope link id 10 group 1/2 type resilient buckets 8 idle_timer 120 unbalanced_timer 0 unbalanced_time 0 # ip nexthop bucket id 10 index 0 idle_time 28.1 nhid 2 id 10 index 1 idle_time 28.1 nhid 2 id 10 index 2 idle_time 28.1 nhid 2 id 10 index 3 idle_time 28.1 nhid 2 id 10 index 4 idle_time 28.1 nhid 1 id 10 index 5 idle_time 28.1 nhid 1 id 10 index 6 idle_time 28.1 nhid 1 id 10 index 7 idle_time 28.1 nhid 1 # ip nexthop bucket show nhid 1 id 10 index 4 idle_time 53.59 nhid 1 id 10 index 5 idle_time 53.59 nhid 1 id 10 index 6 idle_time 53.59 nhid 1 id 10 index 7 idle_time 53.59 nhid 1 # ip nexthop bucket get id 10 index 5 id 10 index 5 idle_time 81 nhid 1 # ip -j -p nexthop bucket get id 10 index 5 [ { "id": 10, "bucket": { "index": 5, "idle_time": 104.89, "nhid": 1 }, "flags": [ ] } ] Signed-off-by: Ido Schimmel --- include/libnetlink.h | 3 + ip/ip_common.h | 1 + ip/ipmonitor.c | 6 + ip/ipnexthop.c | 254 ++++++++++++++++++++++++++++++++++++++++++ lib/libnetlink.c | 26 +++++ man/man8/ip-nexthop.8 | 45 ++++++++ 6 files changed, 335 insertions(+) diff --git a/include/libnetlink.h b/include/libnetlink.h index b9073a6a13ad..e8ed5d7fb495 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -97,6 +97,9 @@ int rtnl_dump_request_n(struct rtnl_handle *rth, struct nlmsghdr *n) int rtnl_nexthopdump_req(struct rtnl_handle *rth, int family, req_filter_fn_t filter_fn) __attribute__((warn_unused_result)); +int rtnl_nexthop_bucket_dump_req(struct rtnl_handle *rth, int family, + req_filter_fn_t filter_fn) + __attribute__((warn_unused_result)); struct rtnl_ctrl_data { int nsid; diff --git a/ip/ip_common.h b/ip/ip_common.h index 9a31e837563f..55a5521c4275 100644 --- a/ip/ip_common.h +++ b/ip/ip_common.h @@ -53,6 +53,7 @@ int print_rule(struct nlmsghdr *n, void *arg); int print_netconf(struct rtnl_ctrl_data *ctrl, struct nlmsghdr *n, void *arg); int print_nexthop(struct nlmsghdr *n, void *arg); +int print_nexthop_bucket(struct nlmsghdr *n, void *arg); void netns_map_init(void); void netns_nsid_socket_init(void); int print_nsid(struct nlmsghdr *n, void *arg); diff --git a/ip/ipmonitor.c b/ip/ipmonitor.c index 99f5fda8ba1f..d7f31cf5d1b5 100644 --- a/ip/ipmonitor.c +++ b/ip/ipmonitor.c @@ -90,6 +90,12 @@ static int accept_msg(struct rtnl_ctrl_data *ctrl, print_nexthop(n, arg); return 0; + case RTM_NEWNEXTHOPBUCKET: + case RTM_DELNEXTHOPBUCKET: + print_headers(fp, "[NEXTHOPBUCKET]", ctrl); + print_nexthop_bucket(n, arg); + return 0; + case RTM_NEWLINK: case RTM_DELLINK: ll_remember_index(n, NULL); diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c index 1d50bf7529c4..0263307c49df 100644 --- a/ip/ipnexthop.c +++ b/ip/ipnexthop.c @@ -21,6 +21,8 @@ static struct { unsigned int master; unsigned int proto; unsigned int fdb; + unsigned int id; + unsigned int nhid; } filter; enum { @@ -39,8 +41,11 @@ static void usage(void) "Usage: ip nexthop { list | flush } [ protocol ID ] SELECTOR\n" " ip nexthop { add | replace } id ID NH [ protocol ID ]\n" " ip nexthop { get | del } id ID\n" + " ip nexthop bucket list BUCKET_SELECTOR\n" + " ip nexthop bucket get id ID index INDEX\n" "SELECTOR := [ id ID ] [ dev DEV ] [ vrf NAME ] [ master DEV ]\n" " [ groups ] [ fdb ]\n" + "BUCKET_SELECTOR := SELECTOR | [ nhid ID ]\n" "NH := { blackhole | [ via ADDRESS ] [ dev DEV ] [ onlink ]\n" " [ encap ENCAPTYPE ENCAPHDR ] |\n" " group GROUP [ fdb ] [ type TYPE [ TYPE_ARGS ] ] }\n" @@ -85,6 +90,36 @@ static int nh_dump_filter(struct nlmsghdr *nlh, int reqlen) return 0; } +static int nh_dump_bucket_filter(struct nlmsghdr *nlh, int reqlen) +{ + struct rtattr *nest; + int err = 0; + + err = nh_dump_filter(nlh, reqlen); + if (err) + return err; + + if (filter.id) { + err = addattr32(nlh, reqlen, NHA_ID, filter.id); + if (err) + return err; + } + + if (filter.nhid) { + nest = addattr_nest(nlh, reqlen, NHA_RES_BUCKET); + nest->rta_type |= NLA_F_NESTED; + + err = addattr32(nlh, reqlen, NHA_RES_BUCKET_NH_ID, + filter.nhid); + if (err) + return err; + + addattr_nest_end(nlh, nest); + } + + return err; +} + static struct rtnl_handle rth_del = { .fd = -1 }; static int delete_nexthop(__u32 id) @@ -266,6 +301,33 @@ static void print_nh_res_group(FILE *fp, const struct rtattr *res_grp_attr) close_json_object(); } +static void print_nh_res_bucket(FILE *fp, const struct rtattr *res_bucket_attr) +{ + struct rtattr *tb[NHA_RES_BUCKET_MAX + 1]; + + parse_rtattr_nested(tb, NHA_RES_BUCKET_MAX, res_bucket_attr); + + open_json_object("bucket"); + + if (tb[NHA_RES_BUCKET_INDEX]) + print_uint(PRINT_ANY, "index", "index %u ", + rta_getattr_u16(tb[NHA_RES_BUCKET_INDEX])); + + if (tb[NHA_RES_BUCKET_IDLE_TIME]) { + struct rtattr *rta = tb[NHA_RES_BUCKET_IDLE_TIME]; + struct timeval tv; + + __jiffies_to_tv(&tv, rta_getattr_u64(rta)); + print_tv(PRINT_ANY, "idle_time", "idle_time %g ", &tv); + } + + if (tb[NHA_RES_BUCKET_NH_ID]) + print_uint(PRINT_ANY, "nhid", "nhid %u ", + rta_getattr_u32(tb[NHA_RES_BUCKET_NH_ID])); + + close_json_object(); +} + int print_nexthop(struct nlmsghdr *n, void *arg) { struct nhmsg *nhm = NLMSG_DATA(n); @@ -346,6 +408,50 @@ int print_nexthop(struct nlmsghdr *n, void *arg) return 0; } +int print_nexthop_bucket(struct nlmsghdr *n, void *arg) +{ + struct nhmsg *nhm = NLMSG_DATA(n); + struct rtattr *tb[NHA_MAX+1]; + FILE *fp = (FILE *)arg; + int len; + + if (n->nlmsg_type != RTM_DELNEXTHOPBUCKET && + n->nlmsg_type != RTM_NEWNEXTHOPBUCKET) { + fprintf(stderr, "Not a nexthop bucket: %08x %08x %08x\n", + n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags); + return -1; + } + + len = n->nlmsg_len - NLMSG_SPACE(sizeof(*nhm)); + if (len < 0) { + close_json_object(); + fprintf(stderr, "BUG: wrong nlmsg len %d\n", len); + return -1; + } + + parse_rtattr_flags(tb, NHA_MAX, RTM_NHA(nhm), len, NLA_F_NESTED); + + open_json_object(NULL); + + if (n->nlmsg_type == RTM_DELNEXTHOP) + print_bool(PRINT_ANY, "deleted", "Deleted ", true); + + if (tb[NHA_ID]) + print_uint(PRINT_ANY, "id", "id %u ", + rta_getattr_u32(tb[NHA_ID])); + + if (tb[NHA_RES_BUCKET]) + print_nh_res_bucket(fp, tb[NHA_RES_BUCKET]); + + print_rt_flags(fp, nhm->nh_flags); + + print_string(PRINT_FP, NULL, "%s", "\n"); + close_json_object(); + fflush(fp); + + return 0; +} + static int add_nh_group_attr(struct nlmsghdr *n, int maxlen, char *argv) { struct nexthop_grp *grps; @@ -721,6 +827,151 @@ static int ipnh_get(int argc, char **argv) return ipnh_get_id(id); } +static int ipnh_bucket_list(int argc, char **argv) +{ + while (argc > 0) { + if (!matches(*argv, "dev")) { + NEXT_ARG(); + filter.ifindex = ll_name_to_index(*argv); + if (!filter.ifindex) + invarg("Device does not exist\n", *argv); + } else if (!matches(*argv, "master")) { + NEXT_ARG(); + filter.master = ll_name_to_index(*argv); + if (!filter.master) + invarg("Device does not exist\n", *argv); + } else if (matches(*argv, "vrf") == 0) { + NEXT_ARG(); + if (!name_is_vrf(*argv)) + invarg("Invalid VRF\n", *argv); + filter.master = ll_name_to_index(*argv); + if (!filter.master) + invarg("VRF does not exist\n", *argv); + } else if (!strcmp(*argv, "id")) { + NEXT_ARG(); + filter.id = ipnh_parse_id(*argv); + } else if (!strcmp(*argv, "nhid")) { + NEXT_ARG(); + filter.nhid = ipnh_parse_id(*argv); + } else if (matches(*argv, "help") == 0) { + usage(); + } else { + invarg("", *argv); + } + argc--; argv++; + } + + if (rtnl_nexthop_bucket_dump_req(&rth, preferred_family, + nh_dump_bucket_filter) < 0) { + perror("Cannot send dump request"); + return -2; + } + + new_json_obj(json); + + if (rtnl_dump_filter(&rth, print_nexthop_bucket, stdout) < 0) { + fprintf(stderr, "Dump terminated\n"); + return -2; + } + + delete_json_obj(); + fflush(stdout); + + return 0; +} + +static int ipnh_bucket_get_id(__u32 id, __u16 bucket_index) +{ + struct { + struct nlmsghdr n; + struct nhmsg nhm; + char buf[1024]; + } req = { + .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct nhmsg)), + .n.nlmsg_flags = NLM_F_REQUEST, + .n.nlmsg_type = RTM_GETNEXTHOPBUCKET, + .nhm.nh_family = preferred_family, + }; + struct nlmsghdr *answer; + struct rtattr *nest; + + addattr32(&req.n, sizeof(req), NHA_ID, id); + + nest = addattr_nest(&req.n, sizeof(req), NHA_RES_BUCKET); + nest->rta_type |= NLA_F_NESTED; + + addattr16(&req.n, sizeof(req), NHA_RES_BUCKET_INDEX, bucket_index); + + addattr_nest_end(&req.n, nest); + + if (rtnl_talk(&rth, &req.n, &answer) < 0) + return -2; + + new_json_obj(json); + + if (print_nexthop_bucket(answer, (void *)stdout) < 0) { + free(answer); + return -1; + } + + delete_json_obj(); + fflush(stdout); + + free(answer); + + return 0; +} + +static int ipnh_bucket_get(int argc, char **argv) +{ + bool bucket_valid = false; + __u16 bucket_index; + __u32 id = 0; + + while (argc > 0) { + if (!strcmp(*argv, "id")) { + NEXT_ARG(); + id = ipnh_parse_id(*argv); + } else if (!strcmp(*argv, "index")) { + NEXT_ARG(); + if (get_u16(&bucket_index, *argv, 0)) + invarg("invalid bucket index value", *argv); + bucket_valid = true; + } else { + usage(); + } + argc--; argv++; + } + + if (!id || !bucket_valid) { + usage(); + return -1; + } + + return ipnh_bucket_get_id(id, bucket_index); +} + +static int do_ipnh_bucket(int argc, char **argv) +{ + if (argc < 1) + return ipnh_bucket_list(0, NULL); + + if (!matches(*argv, "list") || + !matches(*argv, "show") || + !matches(*argv, "lst")) + return ipnh_bucket_list(argc-1, argv+1); + + if (!matches(*argv, "get")) + return ipnh_bucket_get(argc-1, argv+1); + + if (!matches(*argv, "help")) + usage(); + + fprintf(stderr, + "Command \"%s\" is unknown, try \"ip nexthop help\".\n", *argv); + exit(-1); +} + int do_ipnh(int argc, char **argv) { if (argc < 1) @@ -746,6 +997,9 @@ int do_ipnh(int argc, char **argv) if (!matches(*argv, "flush")) return ipnh_list_flush(argc-1, argv+1, IPNH_FLUSH); + if (!matches(*argv, "bucket")) + return do_ipnh_bucket(argc-1, argv+1); + if (!matches(*argv, "help")) usage(); diff --git a/lib/libnetlink.c b/lib/libnetlink.c index c958aa57d0cd..6885087b34f9 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -282,6 +282,32 @@ int rtnl_nexthopdump_req(struct rtnl_handle *rth, int family, return send(rth->fd, &req, sizeof(req), 0); } +int rtnl_nexthop_bucket_dump_req(struct rtnl_handle *rth, int family, + req_filter_fn_t filter_fn) +{ + struct { + struct nlmsghdr nlh; + struct nhmsg nhm; + char buf[128]; + } req = { + .nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct nhmsg)), + .nlh.nlmsg_type = RTM_GETNEXTHOPBUCKET, + .nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST, + .nlh.nlmsg_seq = rth->dump = ++rth->seq, + .nhm.nh_family = family, + }; + + if (filter_fn) { + int err; + + err = filter_fn(&req.nlh, sizeof(req)); + if (err) + return err; + } + + return send(rth->fd, &req, sizeof(req), 0); +} + int rtnl_addrdump_req(struct rtnl_handle *rth, int family, req_filter_fn_t filter_fn) { diff --git a/man/man8/ip-nexthop.8 b/man/man8/ip-nexthop.8 index c1ac130c2a2f..f81a5910bf22 100644 --- a/man/man8/ip-nexthop.8 +++ b/man/man8/ip-nexthop.8 @@ -28,6 +28,14 @@ ip-nexthop \- nexthop object management .BR "ip nexthop" " { " get " | " del " } id " .I ID +.ti -8 +.BI "ip nexthop bucket list " BUCKET_SELECTOR + +.ti -8 +.BR "ip nexthop bucket get " id +.I ID +.RI "index " INDEX + .ti -8 .IR SELECTOR " := " .RB "[ " id @@ -41,6 +49,12 @@ ip-nexthop \- nexthop object management .BR groups " ] [ " .BR fdb " ]" +.ti -8 +.IR BUCKET_SELECTOR " := " +.IR SELECTOR +.RB " | [ " nhid +.IR ID " ]" + .ti -8 .IR NH " := { " .BR blackhole " | [ " @@ -230,6 +244,37 @@ as show. ip nexthop get id ID get a single nexthop by id +.TP +ip nexthop bucket show +show the contents of the nexthop bucket table or the nexthop buckets +selected by some criteria. +.RS +.TP +.BI id " ID " +.in +0 +show the nexthop buckets that belong to a nexthop group with a given id +.TP +.BI nhid " ID " +.in +0 +show the nexthop buckets that hold a nexthop with a given id +.TP +.BI dev " DEV " +.in +0 +show the nexthop buckets using the given device +.TP +.BI vrf " NAME " +.in +0 +show the nexthop buckets using devices associated with the vrf name +.TP +.BI master " DEV " +.in +0 +show the nexthop buckets using devices enslaved to given master device +.RE + +.TP +ip nexthop bucket get id ID index INDEX +get a single nexthop bucket by nexthop group id and bucket index + .SH EXAMPLES .PP ip nexthop ls