From patchwork Fri Mar 12 17:23:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 12135419 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, URIBL_BLOCKED,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 B818AC43381 for ; Fri, 12 Mar 2021 17:25:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 84ED16502F for ; Fri, 12 Mar 2021 17:25:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232493AbhCLRYh (ORCPT ); Fri, 12 Mar 2021 12:24:37 -0500 Received: from mail-bn7nam10on2041.outbound.protection.outlook.com ([40.107.92.41]:23329 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232553AbhCLRYP (ORCPT ); Fri, 12 Mar 2021 12:24:15 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dSpah8scX6HO3oIYWzpO9JP6sN43g/TlrmVpmjCLEbGUVlNiyeos70fJgw2B+42OCEJrh1IqjWUPkzGlDDbFdLhPOBO+MrqC7jTikFItXSgAtxHMp5/WV/J6KEhh80djnbxIiKERrylavua70TS22mX4a/XS3x/NObCcHb+13s0vxu+qnU/BjeaIGeWhlEmeI0Ss+opAXuQW+AYGIdoqKiUHHMay0rGPq/ebHWxJFi5IZLVyNwI3QNEgY4xR+ixMd2xYDfS+iuKJ/vwYuW3sO90IdXT331aYPsMB+zoXObpQ+P4DJ0p7gw/r//fGeZHyjJc8f9u4qrLjsw3izE2MmA== 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=qfLTnOVFGTg8SGQKogtpYedrhEsufuokgsnAKpXT6iE=; b=B0qvkDMHZM7ffymcTV9lgTcS6PgkyLhy1VIvjl02Se3kr5AEYWG3lsEfmU1HgmvswtGjqobqrHzzUV0EYCYmtGrDQ7W37A4QfqRGP6KKntXnL8+6KEacIktKp5KTNNJLjF4qZwYPRc4M17Gk7+uKcksQnCTrroQcyV4BKMURxxzBELSDanvbvUPwo+cMCtLn8ZBvDDq9uSnx5Xx95Ga5mcZo+95JuB44Ey9owIyzqxgXOTUeD/5TDZhin9/Try3DhupjK6CaN+Pf7yiNb2UYTreBoMa4u4IwaixQ0PcK8PdymwqDUqaiFvaCp7i8M0Dy0j/pPH2pn/6XrcZDPVzTtA== 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=qfLTnOVFGTg8SGQKogtpYedrhEsufuokgsnAKpXT6iE=; b=n5PVaEXva0xB//ARURVcSm59c86yO3f6ZFpvnvXU/M1qth26YQnZyAkmZhPoMj1FMOtrw9xoieBEbfXVVw6yyo6+dKVmjxpf+hqKkhmiD46suF0UTQr7bXnvdqiNYqkd+5cXmHkYzFd9j4i4bkNEbRAdlvYqcX4TLjmpQtKyNEpjucK4y1bwxCLcenBBWLU0zeKPorZyd2vWgUMFJ1tVIUGWljrhVg1gW1X4gpfYtQXOEl9GQfPxTri3oAbSmUWY6tXYbUMILQaEsw6NDKd68J5VS/DJaDpiSc4msuUumKG1TAN4xj7ZGBb45dQo8Z/faZCa3ZCEQImmFkd8zcE0xQ== Received: from MW4PR03CA0007.namprd03.prod.outlook.com (2603:10b6:303:8f::12) by SN6PR12MB4717.namprd12.prod.outlook.com (2603:10b6:805:e2::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.31; Fri, 12 Mar 2021 17:24:09 +0000 Received: from CO1NAM11FT003.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8f:cafe::fd) by MW4PR03CA0007.outlook.office365.com (2603:10b6:303:8f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.17 via Frontend Transport; Fri, 12 Mar 2021 17:24:08 +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 CO1NAM11FT003.mail.protection.outlook.com (10.13.175.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.3933.31 via Frontend Transport; Fri, 12 Mar 2021 17:24:08 +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; Fri, 12 Mar 2021 17:24:05 +0000 From: Petr Machata To: , , CC: Ido Schimmel , Petr Machata , "Petr Machata" Subject: [PATCH iproute2-next 1/6] nexthop: Synchronize uAPI files Date: Fri, 12 Mar 2021 18:23:04 +0100 Message-ID: <5d05fcf97867f9dbf096f5849708ba645e0f96a9.1615568866.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: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 21e672a0-4b87-4a0d-dfc4-08d8e57ba53a X-MS-TrafficTypeDiagnostic: SN6PR12MB4717: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: q5+sLUHCX5CeYmrshB1g8RgNTc26KIdosM25IFS5uSaY571plDLeA0Xp5+BUajVveAjJovvmBFUTDOqIlV4bbYk31M16iOOAOhUNsLlbxlri6n4nNHa4wpy2c2nIP43mYURiusYiiv/YMe/ku29Fb3zNaBQDwGpuW353UGBptNOTPy0KzPSSi1DtdYVAsapPugbXVcmEYM1JtTCr4D9fIYBRkgpH4Jgz1auwGJ7p5CI0kwV8Cq/HBge8aiyoHzo9VbNC9FfdtmKKzAAmyJCYoffDMA2CRUAgrcx7GMAj7arLCd8brXVKm3cp00ektvzHgnaUgjG6K967KNo1/4VboxwR/3uqB+3lBxb20ZLspTbiRmOQmrS3XDy5bxnILUTsfkx/X8ASzLVi84Ltp4XOtnxyXbMvaLpPSeZuZvIEFmGlf4snbb8xqwHn5KbsaSSuhH6MPntO8nHvk8dG9sfW2DO/nySaqXuqiR0vIbV4yAh3T5uncJKywbTKqRVBFkq2yVOUnpbyIimfTwnk9WxpNsR6mZvLb00i40HO4z6BivQEZsikPqaEZMQivRehSBUy0i9B39/yQ87uXUccfK5/y1VsqYcf5929cuaiw4k7jnm+EyUgfe+dOt2+09BjQP2uv2Yo9NxYqIqPGq91q6D8Bk1cimXw17oPaYNriDs/991is6Hp99gOaUnV/2s4sV1U 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)(346002)(136003)(39860400002)(396003)(46966006)(36840700001)(34020700004)(36860700001)(82310400003)(356005)(36756003)(7636003)(83380400001)(82740400003)(70206006)(70586007)(86362001)(47076005)(5660300002)(36906005)(478600001)(16526019)(54906003)(8676002)(107886003)(316002)(2906002)(8936002)(2616005)(426003)(4326008)(110136005)(336012)(186003)(26005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Mar 2021 17:24:08.7652 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 21e672a0-4b87-4a0d-dfc4-08d8e57ba53a 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: CO1NAM11FT003.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB4717 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com From: Petr Machata From: Ido Schimmel 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 Fri Mar 12 17:23:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 12135409 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, URIBL_BLOCKED,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 8DE5FC433DB for ; Fri, 12 Mar 2021 17:25:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 62F6B64E76 for ; Fri, 12 Mar 2021 17:25:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232653AbhCLRYf (ORCPT ); Fri, 12 Mar 2021 12:24:35 -0500 Received: from mail-eopbgr680041.outbound.protection.outlook.com ([40.107.68.41]:55357 "EHLO NAM04-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232530AbhCLRYN (ORCPT ); Fri, 12 Mar 2021 12:24:13 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O0Ewp3BjAXaJEboCXyml04liMrTSBONJhyL71jXpuli9T9K6jqdAJSjMY9A0g3UXX2aQ4amX0ZRWCbnqCDDb5bGKzRQt7/wRRxL/vwyZwIaCbt/QXuqHFeMB/Q/akOC/035Rh5JrHEFs4M6yKWJm4aGs4cjkfyA8ty8zB9mSAZSHrs/jAjamp7FoBqXYhg0MoIrSrXhiX/y4M9GYmI8FgfN4Pee3AtDUnZiH/wKQP/0MdmoXTHmpUUDgjFa7IHwsgB5hnac5cu3VPUcaw4kEREc65oKCXcsytDpOCZwMqmWqDlDYOY9bSsCMt2xC1CIow0FTSIcouzHee/lcNriYdQ== 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=/ok/doblIRG4rn6r1iqKIICkELgKMHd6dsybsQer1Mw=; b=FADfCEy1sdJpIc8Y6rDhHnJcGFRWqH16v3wNJw/CEpDurxrq9Iz9vYYLs4NQf4fyn0cX1RlzUIlW/2rFBh1AZJJXEtaDJ46U8dKT6Un3n3lvpCD/imaYmvVxR27LkNJNMKP/+PNz8B8ecryoJkTIajrYaKK+YHT6nWE6n8NI5JiVf3blCbrVgeVqJ4kQP+ddyXT8mwZ93t+C314v93QPrImb5O2SqGxoOEjNVjEdN58MR0HhyXEcZTGDP63PiqCkFlxh0Je/kjULZBJEBl83lPybyMAcd6c9h6d7KnWomhnitlYg1fwoGugwyM/+aKRP+xAfQyIRR3JYK/YZdsdg0A== 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=/ok/doblIRG4rn6r1iqKIICkELgKMHd6dsybsQer1Mw=; b=TuQrexEnpD1dKHSy1T+Gsgbz5kKsFchNL/YBheP0XKxqOSMI82SEkVseR2tibyJeZvH+bSUe6/m90MHhykjiERhWujItUzbxsesf+5szlWHRTtL9PapWWJV462QFwuq19rjtMjE/w7u7RxipJUei+nE6ZCkvs3fGzyTtyZEwbj9+PHSVoNDZQoo3hFZwi663SYrZfT6rZL+phNXFwmVHkn1QlatNQoipQ+qxV1koKWZcIyyCC7PxaivnBbSuwz7M5BcGobF21r9zHFLdpuI63Cpbvw8xKZ+XZz6UN4Y1MgnJPNrMTi24NUNtGUZcXQSFn2+FLkk3LQUkCoH8a5vlEQ== Received: from MWHPR1701CA0006.namprd17.prod.outlook.com (2603:10b6:301:14::16) by BN6PR12MB1538.namprd12.prod.outlook.com (2603:10b6:405:4::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.32; Fri, 12 Mar 2021 17:24:11 +0000 Received: from CO1NAM11FT040.eop-nam11.prod.protection.outlook.com (2603:10b6:301:14:cafe::9d) by MWHPR1701CA0006.outlook.office365.com (2603:10b6:301:14::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.17 via Frontend Transport; Fri, 12 Mar 2021 17:24:11 +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 CO1NAM11FT040.mail.protection.outlook.com (10.13.174.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.3933.31 via Frontend Transport; Fri, 12 Mar 2021 17:24:11 +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; Fri, 12 Mar 2021 17:24:08 +0000 From: Petr Machata To: , , CC: Ido Schimmel , Petr Machata , "Petr Machata" Subject: [PATCH iproute2-next 2/6] json_print: Add print_tv() Date: Fri, 12 Mar 2021 18:23:05 +0100 Message-ID: <24b7728566932f41e825bf20098375016a9c01c2.1615568866.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: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8f770a80-f573-4693-f780-08d8e57ba699 X-MS-TrafficTypeDiagnostic: BN6PR12MB1538: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2958; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BCAGXvEvZOrXWm3V1wMfWgcIlzHTL+x7ijZ4+E3UwBjuvt+mcNsBQJGnlL5edPurgBIm4T9kXDFTOzGTJTFeRSJFHT6IwA+fQa+x7YmEoc/Ak3jh1VVJKchWAXc2uyT1RZfRTFfrz+YFS6Wms71RQHz4V6RGi/50xER9MlGuVuTzu97SLzoyyw4zJHcHgxtBYyeXGgdy2yTHW2GeovGz4W2VO+p4DegbHnW/nxukKbY8UowfHYkwvlNW4pXkLE1yVqYyFbeVivaDiuVKupOakImIAJJ8cMfaCX6rKcxJBLC7JvJ1VQgUFFAzzqA4BJgpbzOyh9IIdA2bbUeWRFHTlT+pzljBRvpSKPWkucfeWkM2/sZrd/LNmLp1spE3YpmkYjBSBejclYu+F2Px+Z7gMW84sLindkBQiDpIRsvP9ttOyp1M1CttelQ4lnxyTUr6cyYIdbwaeX5nAQ1Ey5dD3IjIGUugAUl2znJfgYzDMmv3u0h2i93g2hPgQ9yp8dVoevyRbQXdXB7+y8nJ7KVE1wPgoQgBvIhUiY3YE3RafqMmpdOfFaAACKNXWswvnLSrsFLNJa5fGMbCwfRzyfGaPQed0sFtwstC8YbhA+5rIODUQO6Vf5HLVEQ9LtfEq3zDvGvuHYyeEnXWaMFg2hdcMcVWBUbiH4b9gAm2xlRTAHvQI/UE7ewfIF4bHSj98G7F 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)(376002)(136003)(39860400002)(346002)(36840700001)(46966006)(82740400003)(356005)(47076005)(336012)(7636003)(82310400003)(70586007)(70206006)(34020700004)(36860700001)(36756003)(316002)(2906002)(5660300002)(26005)(426003)(86362001)(2616005)(8676002)(4326008)(54906003)(107886003)(478600001)(110136005)(6666004)(36906005)(8936002)(186003)(16526019);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Mar 2021 17:24:11.0692 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8f770a80-f573-4693-f780-08d8e57ba699 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: CO1NAM11FT040.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1538 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com From: Petr Machata From: Petr Machata 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 Fri Mar 12 17:23:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 12135415 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, URIBL_BLOCKED,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 DF6A9C4332D for ; Fri, 12 Mar 2021 17:25:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 94EA465028 for ; Fri, 12 Mar 2021 17:25:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232849AbhCLRYj (ORCPT ); Fri, 12 Mar 2021 12:24:39 -0500 Received: from mail-bn8nam11on2078.outbound.protection.outlook.com ([40.107.236.78]:42465 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232602AbhCLRYU (ORCPT ); Fri, 12 Mar 2021 12:24:20 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SiUe54+AnBQW8l56f+FtklduLQTcYcQT/TWHImR3fbwYp1CaQJW+a5IHoD756a9W+vLaupIICWcCV8hWEXme7WM0+d1P6qvqGCvPpQg+EYPSvxiMGJ5qYiHsw7eDzW341CWHLD7pM+2xi+ljiWNXmr06S8TTd46rSTXacMX44lg4u6nwVSolZorvAD89aL32vJlPCO4SYKRCG9GQNfZWkWQdhV/stCrQBN2Y7USSzx9pZIBurslT4ZD0R18094K6K1p2MigV5HZQFhOb7znuOxGYpS/OU97H+HLUC1ywrXmSuT1BnDdOaKihihpmIJfU1QwcSL3DniKPaVW4Xgf9vQ== 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=r/TGUO8zWSRnFCZkQMCj+rqjIqTB4/qKKuGKifW4YoA=; b=LEbbGnlkkPtRdn14+t8jCXiKehY6D6Rd8tQ/IzbRJJI+GkHx9b5gk1/dURQdL32eW74WkePW/hRj3BtWzVBIb/DK3mUHW1VZGiiGnwrArPsZHDiDkv06cBbPKcZZhwSHwEGL8MzoEuI5ICMi5mw0I2GnLm97Aiduewozzl1I363c5H63EtsYGkJy/ZRiUxvkF2bG+1Ca6ZloTZ5R1Vp7b5rZhP1lQE5SMQepZtRwPcjPyTcgjQ7MPnBIPX2LBsyynB/ok1Ar/v/BSiVgHd+IbudoT8vzJDOFekVNlFKQK2v7028YD6Kgn1KYajWqX8RtRRUIupv9LTwMCWl+ZNtASw== 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=r/TGUO8zWSRnFCZkQMCj+rqjIqTB4/qKKuGKifW4YoA=; b=ueGGO2yuY/RA6Nmuur+qz+8bjcss5sR9BvpKmnFkU8zC2JE+MzkRypCT+AlzhohV9BvwWZT3hBXnvqSEKJaXLAG060hp7ugX6JEUayTQZps9UdV5NYiIAQaLMOKfgQHpbyf8bkDlMbBIsMe8Ok6RqQCn7bQLM8uoyiEL3AolbQnRxbvncvyl1h9YsfCQN11CiH3AWU9GKapxmQj1Z4avkrw0HVlDPPPRStBlI0ATm+lGIamGrjLS1XZMaF3M+MWNKeUZ/2turUfUc5zvits2tonL92T6GdPYm1kmuyIDFSPCFuB3NcxZjcDyp8ziAp2mKmVcTuktJfMwQ47L76QPxw== Received: from MW3PR06CA0009.namprd06.prod.outlook.com (2603:10b6:303:2a::14) by DM6PR12MB4697.namprd12.prod.outlook.com (2603:10b6:5:32::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.31; Fri, 12 Mar 2021 17:24:14 +0000 Received: from CO1NAM11FT020.eop-nam11.prod.protection.outlook.com (2603:10b6:303:2a:cafe::a9) by MW3PR06CA0009.outlook.office365.com (2603:10b6:303:2a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.26 via Frontend Transport; Fri, 12 Mar 2021 17:24:14 +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 CO1NAM11FT020.mail.protection.outlook.com (10.13.174.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.3933.31 via Frontend Transport; Fri, 12 Mar 2021 17:24:13 +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; Fri, 12 Mar 2021 17:24:11 +0000 From: Petr Machata To: , , CC: Ido Schimmel , Petr Machata , "Petr Machata" Subject: [PATCH iproute2-next 3/6] nexthop: Extract a helper to parse a NH ID Date: Fri, 12 Mar 2021 18:23:06 +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: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 052797c7-42fd-4bd4-5f84-08d8e57ba84b X-MS-TrafficTypeDiagnostic: DM6PR12MB4697: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1122; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Jw5w90Hn6XYTe2N71uLVHeVSQcWlp6973A+ReMpHqTuyDpAx4NZ1VtAseoAv8SjLdS9BktyhzPCuFZyDeldCoSDdev9eB1DHaITVq2kidKg/2qW1aHnRXqUN3UME+5ZOuS7v5vVwrZ6o7OHej0oSYal4RJphFl4KIr8gLtggUXClrCP0odW1JMIxboe+widM65EzsqHmt32kDfLjxLgGnUYGrjj4z1xAu3l/GTvgyM70XnNKDClIqg2GTqMYDp9UkG+ITrxXAw6HUfS8lzjqSknylsQpohLURxfhXu3YFqH9hl60rdAPZ7uVR5Wb+MBRo4cAnqv6NBYkjijM8zru7p4C8XS7FBcW/o2BCCKEv/7FNWISFzA5AfK0ek06s1YBpZfw7iJaP1DL3yljygkIyim0N0iDJxQ2LAgw2Pwwoc7HwHVVHaL+QeFe6ydXxKsWw40VV81PcayftrPdw5NIFdyGnomjmbRA0rnE9vZIbsvYE8A5Qw4SAEFSa+H5hT+/IYgUIO2GjqCpT8ZMJ56U9MlfkuaO/wyC+XZv1w4Ux8aeONsOqQeGUCRYBoiUH2ZVK+eaJBwi8O2wnnbRsgOKD4pX5UJ1WPRTbSYOTaDCqIoOkjOSCp6bAkgScPoNIzBxzOUOKP1OqRg/vvuobeqSYkIwYHwjr2WML5Zq3Q/kO8IVKhQO2tVtLRrsoJPWVP9P 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)(36860700001)(86362001)(7636003)(36756003)(26005)(356005)(8676002)(83380400001)(2906002)(336012)(2616005)(36906005)(316002)(107886003)(82740400003)(82310400003)(4326008)(70206006)(110136005)(54906003)(70586007)(8936002)(478600001)(47076005)(34020700004)(16526019)(426003)(186003)(6666004)(5660300002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Mar 2021 17:24:13.9155 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 052797c7-42fd-4bd4-5f84-08d8e57ba84b 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: CO1NAM11FT020.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4697 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com From: Petr Machata From: Petr Machata 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 Fri Mar 12 17:23:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 12135411 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, URIBL_BLOCKED,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 DDA25C433E9 for ; Fri, 12 Mar 2021 17:25:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B691D65039 for ; Fri, 12 Mar 2021 17:25:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232814AbhCLRYi (ORCPT ); Fri, 12 Mar 2021 12:24:38 -0500 Received: from mail-dm6nam12on2064.outbound.protection.outlook.com ([40.107.243.64]:36896 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232590AbhCLRYT (ORCPT ); Fri, 12 Mar 2021 12:24:19 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fsqGNaQfG8d/7trjd/XqmNqNow1FeH7t6mjLqfHEzhErzb8+jZd/SxHRanrJO3FrjEEZ+fGxtm10EEVkyVgOZy8QE9EHemugfl5IhmbQFLNDgrRcTA//IOVl+l/fSqE0gswDLTtgs6d2lHxQks0BplUqAfMjGNYnfmbeJbnSPhGu5tJ5sh7hSjWIs30BD8IMZVrBddPGcQ37bYKpqb8UEjslRhK6tJTnJYr2/wOaWfsCpJSnfmHeyZcyhvB7ka0enWScIZ0tOeFyg2u1NZb74NrlNSh2S/8jXYaaPBxD4+hjo139Uyvj7zbwZN+w4w5vm54nKM526E8g9gOEMbAm7Q== 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=pwd5zm7DY9tbzAkTvovHNlt/ssa2LcupvbcS35NeCJQ=; b=HkUo/2yfqlnNnL03s2QcfeFShUmdPS740IxWovp+pW0WmsyAtbjKK+LZLK3TYgeef+XtCQdLVi8DoXRjFoGNQeaB40hEOnu8vMuuRl3IDbVl86rKgXfV+NNxpmiYdP/1AemjEbpUchwByadzHowlMRO/jJcCWrny0PNYpmWMj4ZShSPBjI0xVmgIK2bZwM1eJJQP7WlvtJWl2KE92Eb7O/Ja8TAiE3gmgi8QeZ5lNTFGugC436rUK08WXo1JdIPYa79T3lGAZ4xP33erAjZeMMSTYYliZIzQNWFVtmqLq28A8D9gnsrJv0OwztSr1KOSMNy46JkrBqLqOQ8oAF+czQ== 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=pwd5zm7DY9tbzAkTvovHNlt/ssa2LcupvbcS35NeCJQ=; b=cA+7HQWYxg+d73h3QN98ELGRg9d4aZKbAI8rKlUchVNK1S1oc5cRJ3BKrH09zQo2WfKLvRER8TyEB///lJhyWQtol2hrA6deg+GYKDxctuLoJU9n7UFHn7+ljG9n6cR/IdgKYLF5rYNjmz7Rx8y4FIMVdjNCKlHOfo82uuy+sYnivyREN131KJDaJYfY+FrTgFfJJZZovoJZ5h1OC7vB1cyNUFJVNHRC9m14d/2wSOFy1bn+3BoSp69TNmKyAQqP+Jq+G5gj6zivlHiZ/360TbWkwDQvfEqDRnjDyJL21BmgoJyUedPxoFbIjNhGhTXxGfRF7M07p2rPtoqjHU/Dzw== Received: from MWHPR14CA0031.namprd14.prod.outlook.com (2603:10b6:300:12b::17) by BY5PR12MB3906.namprd12.prod.outlook.com (2603:10b6:a03:1a9::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.26; Fri, 12 Mar 2021 17:24:16 +0000 Received: from CO1NAM11FT058.eop-nam11.prod.protection.outlook.com (2603:10b6:300:12b:cafe::4d) by MWHPR14CA0031.outlook.office365.com (2603:10b6:300:12b::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.31 via Frontend Transport; Fri, 12 Mar 2021 17:24:16 +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 CO1NAM11FT058.mail.protection.outlook.com (10.13.174.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.3933.31 via Frontend Transport; Fri, 12 Mar 2021 17:24:16 +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; Fri, 12 Mar 2021 17:24:13 +0000 From: Petr Machata To: , , CC: Ido Schimmel , Petr Machata Subject: [PATCH iproute2-next 4/6] nexthop: Add ability to specify group type Date: Fri, 12 Mar 2021 18:23:07 +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: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3b14b46e-804c-406c-5a41-08d8e57ba9d4 X-MS-TrafficTypeDiagnostic: BY5PR12MB3906: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tITje3HVE7eVBXJQbxjjxn9s94T0eUcJU894NdBQo64xo4BdJOdhOfpIRTamnABo3yCbh8EcSZ5zPPCLX3YUBzQf+ixb39uaKuM/PR1XpHaY1YTWcr1y3Dgs0H30ApQIFuUtdeFzDWxBNGxVLRtufTMboa4qbTtIOq3FX9tZgacdaBhX/uqdGV6kCgCyL4mxTQlAPeeQFY0HFxDyerDJgExfyv19qwkiQscxkEf/xGRgvTpb/wLddYnUQQFIMhh82yEjvxre0rdggkiThLQS37/Ulby1sovACOX9ccS/yUri43InTi5rxJjPGjck72C5onhqYrHQVbEb5MptGAuLqDocFaRbdWX2k/TIQRY3JJHbcnu04l1o1haoiNpMG81pekshZILt20P/cCydkve0DhJ1vPngqpgXB8yw5gEFETDFiJjsmlBWpJ0AJyVJvYCbZpnOX/5nlLfC1nyVM/go80H1xhV/h1Gi8tlPOtiMfEOcAAQ5gD2BUjxZBKdSWmNHEXE9APliiOD4lwyXe1ibWeRQLnXZOO+k+3bdclxMd1iooS2BYx7zvZvz1OdnWiMj/LSSUht1N+ESCpQkBSNsbCvGaxkAlpaCUeeo+xJC4LEpSLBl9CBAoLNqXzix3IbJ0UCJGyJgyWES44k5zZYp1jt3/l0zG2RkUROPvp2IMqFIVY0LvcJD17dyzcV5woGC 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)(346002)(396003)(136003)(36840700001)(46966006)(70206006)(82310400003)(47076005)(110136005)(356005)(34020700004)(83380400001)(7636003)(16526019)(6666004)(70586007)(36906005)(8676002)(54906003)(478600001)(2906002)(2616005)(5660300002)(316002)(336012)(36860700001)(186003)(82740400003)(426003)(86362001)(4326008)(26005)(8936002)(36756003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Mar 2021 17:24:16.4860 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3b14b46e-804c-406c-5a41-08d8e57ba9d4 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: CO1NAM11FT058.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB3906 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com From: Petr Machata 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 command are equivalent: Signed-off-by: Ido Schimmel --- ip/ipnexthop.c | 32 +++++++++++++++++++++++++++++++- man/man8/ip-nexthop.8 | 18 ++++++++++++++++-- 2 files changed, 47 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..f02e0555a000 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,17 @@ 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 + .TP .B blackhole create a blackhole nexthop From patchwork Fri Mar 12 17:23:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 12135421 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, URIBL_BLOCKED,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 0E510C4332E for ; Fri, 12 Mar 2021 17:25:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CA90665030 for ; Fri, 12 Mar 2021 17:25:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232862AbhCLRYj (ORCPT ); Fri, 12 Mar 2021 12:24:39 -0500 Received: from mail-dm6nam11on2063.outbound.protection.outlook.com ([40.107.223.63]:38976 "EHLO NAM11-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232627AbhCLRYW (ORCPT ); Fri, 12 Mar 2021 12:24:22 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BZXXRI9QVfreb/yNL4heYZVPNGdj2IRQOkmlvO7bpTw9v4S3VgIfB1VloVO+3yqqOAHZK5lF5zHmQm6BWozHl2FfRMqr1lDKgIh7LcNhAVAKIqVRu05nmL9m3a1wT0mXEDd8e9oFYpPn18AIx6sYqKE6Kl7Bsd9UMEtBBgK2O1KrprZywxesYId/hl/yyOnrHgqKubfKBJl+2NRlQtDXJMes2pJimxOTmINchvGrIEYCHnTpctB/eZ+MJ0Iaerh1M4cyMmk3HUPWceqqNaYpioTMDEwSrwVoOCYSS6Bi+vEcV2P0fa+hVi1B2y9w801RpbyMX2biDdqg/pFVTxAy1w== 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=6QHLq81fz4D3mIYsSmlD+z+TChfg8JmFwbBAAcprJuE=; b=fMjVPUfiFj6hQsainp5Salf+pNA8p6MEiWfSNNc/6JJ/aooCe5LFxg68yGSQNubZsSyWNldlDechjdFHdDMwhZ+IkWpO/Fn12p8IbQqv70ZTSTKhGAC9QOfcblmKxyMM+gFFC1k4ptMlpT/3fRGH2wEzQHQhXoCBmWYnHziEdYFun6cZ1Gb/FUVDlQcEO1G+2rIS3QF21A7RF6MWPsSOpb0gWWA24q8cIhIYK8DH1Ji+J6DyLdrTbqk1Sjx8K9kqKXGPyr8EDgC1ajYI3P2jDlGXVB86ZumJBcSEF+Salm85rhM65QK0aDn1BaT+D03aBPNO8MP/sObP1Y70BBxF3w== 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=6QHLq81fz4D3mIYsSmlD+z+TChfg8JmFwbBAAcprJuE=; b=rUB/30rPpRhi9akF8AyMUTrhbGEVhGUUSILl3MCIAfYNqqpxv/wBssT0d1dyshkdIu6dGK7Bpjvpd7ggOeQ9UvQv4gagJv+Ao0AFhhfu4B/li/QKsFbVbzShgGY4YhYE3k5tMx7thYWnRuPf87ir6IAPEg3Zr56WzpSH7djEpig10992K+gc2mCB0nu75GwdOg50B5O+g/kUdQZFX3FZXeuPorH46v+PIR16tnJZg/Dr2FSkic+Nqvkyr2FjT7JH0acNiLlA83s6mI1LwdHzRRzFKDbz51TFfN3EsIm9bs5VDrbHFbWGRz/lL+ZaRaE0BREwi7t3VbdNq2mh1gb1Tg== Received: from MWHPR1601CA0023.namprd16.prod.outlook.com (2603:10b6:300:da::33) by MN2PR12MB3120.namprd12.prod.outlook.com (2603:10b6:208:cf::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.31; Fri, 12 Mar 2021 17:24:19 +0000 Received: from CO1NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:300:da:cafe::74) by MWHPR1601CA0023.outlook.office365.com (2603:10b6:300:da::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.26 via Frontend Transport; Fri, 12 Mar 2021 17:24:19 +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 CO1NAM11FT045.mail.protection.outlook.com (10.13.175.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.3933.31 via Frontend Transport; Fri, 12 Mar 2021 17:24:19 +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; Fri, 12 Mar 2021 17:24:16 +0000 From: Petr Machata To: , , CC: Ido Schimmel , Petr Machata Subject: [PATCH iproute2-next 5/6] nexthop: Add support for resilient nexthop groups Date: Fri, 12 Mar 2021 18:23:08 +0100 Message-ID: <50c7ea2e4398f703e9e78c461f8ca7dea3e703f8.1615568866.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: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b7ab671e-d6ea-4702-e454-08d8e57bab70 X-MS-TrafficTypeDiagnostic: MN2PR12MB3120: 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: wRT7k9t7QjkFXwq9z0xhtWti2T4Yy3AV8qtYf9wbHagZjDmJgwkt4dku1MnvBpVS63jhctb3i4GxoBnwF2/KsSu6za3y3QI6m0Gr1le1+TIGg+GyGRAPNM14O9OPnVQhgyac+1VHvjxCyl98GNoJ3+Im62gpp7w9m1/IfL6Mf5ZwD/dS4k2xcB/Kj0nxM9QakFwAS2kIiC//Hts8Getjw27CzSyUJo8Lmlyo0uFRwzxnUVusBroH5eKRT1QA4R8qoGbQK+QAMZcgzaNX/cN1AjwyetdHmdKAaxhFXzeCfYrozfYGEPewCUIjcZcc+FLWCd7GC26Vead3Q/9k0FEHNs8TX8h/gOkJaemoa1ezwNVB0zgB3YPA6XhxP7PnTgSmVVZL8euqHlGbOlsTUF5Tp3XfEcf6fmC3yoUYSwqJ79uw3Tv19NGeNcH6/ZzKgiAxQ/3J6ow+EaKjoj/DmzPKxtwjPVqsj4dJe4FP8pJlI2gr585FgAZIAySb6lM4jpETnQUCwCYLV5nXcalU480mGWpAVCQikTpQEvIQkceVn6cICu8J331DuqdULFRotIq+8A51ZnM0ygn+0eJ7TNDKGb1UcA5O8jYfesyLlvpiVkgEDvRptoLZWbTvz8q0PahPh9j2PKpgsjAbTw9hc4rMkxOAmo+rkhZVYVfkz6JCpw/OGZVTsYppFqPeAabw88A9 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)(346002)(136003)(39860400002)(396003)(36840700001)(46966006)(2616005)(34020700004)(82310400003)(36756003)(426003)(316002)(36906005)(336012)(86362001)(36860700001)(83380400001)(47076005)(26005)(186003)(356005)(6666004)(2906002)(82740400003)(478600001)(110136005)(16526019)(5660300002)(8936002)(70206006)(70586007)(54906003)(4326008)(7636003)(8676002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Mar 2021 17:24:19.1606 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b7ab671e-d6ea-4702-e454-08d8e57bab70 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: CO1NAM11FT045.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3120 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com From: Petr Machata 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 f02e0555a000..c68fcc0f9cf5 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 @@ -138,6 +151,37 @@ is a string specifying the nexthop group type. Namely: .in +8 .BI mpath - multipath nexthop group +.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 @@ -224,6 +268,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 Fri Mar 12 17:23:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 12135417 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, URIBL_BLOCKED,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 096F8C4332B for ; Fri, 12 Mar 2021 17:25:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D9CCB64E76 for ; Fri, 12 Mar 2021 17:25:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232884AbhCLRYl (ORCPT ); Fri, 12 Mar 2021 12:24:41 -0500 Received: from mail-bn8nam12on2067.outbound.protection.outlook.com ([40.107.237.67]:18272 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232311AbhCLRY0 (ORCPT ); Fri, 12 Mar 2021 12:24:26 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Lpd/uAwziT4t81GV/LIM986frnmBLG08w8gTePzGtBM9SqPttm7+zVgrdAeV+Gf97TU/mE20+C62G1UWTQ6l2z5LyCbEMugkouQTXvx2EBSyCDJXNfA67+m4u0A9lFieZimXfOMfsJt1Sbo6NhS6HIYH4SrcyS4YQ++5SJSzexMcfaU8ed+6ic3oHbLcrtfzsXNWho2GmcQybo1643/X6odmSSXqTfpPlXDpSr1Dcp9gOef2w6B2jyK+/tCk4l2YjuiI70g5BtUSwoETDLxHkMRnhT2p23FVy7vqGP52Iz1VLB2PNQbVOQKhLM/jkIyMY8llTWCL7FRVTl+Dzi2w8w== 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=59pQxEPVVyN0JUPer4TUKD4gThKqPDwQV5xjfdiTpQA=; b=BC/GVwcbB3e4n83vdv3b7qL2N+BAXhzEdwPxIrxaN+JBFfiV4JQNmvKT+pKNFcd7Tbb5xyq4nN97Rj/RuMpcnpmWxru2pwwQgn5juHx51PFYS8SdDv1oU3dMOzOZi/hVSwWGCQAUGNf46KV3EoEmZPGAp1sE0zvq8PSDuN9wq3Pf8htE/U49UbKI6Cs+oaVoLlG7fmJTPFC1Xbj+exQf8HIR2FrXgwT1d5DwpMUz4s1hTBK+Aqb5UsJioh8Z5wxgsdhzFirnVoASg/dsqWtS7zVe1bq6RDKV5YkYEwZY685Hc+hoLmVHbEX8MxA3LMXerQvg300ApIeps7j0IxIxSQ== 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=59pQxEPVVyN0JUPer4TUKD4gThKqPDwQV5xjfdiTpQA=; b=EGowzuSFB7XAvB3G4hu2GQmR5v5kPr7CAm+4V5G1XN7UlIEanfzAoyI6rclsAOB3CDksWKB9gaSxuhM4/2MvJq9m5IK097qWo/fKsCM3J7IMGljbyR2/hJ0zYFs3pSY6iYqPIT2lM5dWqsULyAJvTFSj8A9fBwj3fgVJE/xxDMll5zdTg/8sztsNLJUmliU/FFrHe1uQJb9ZTsWam5EgZ1xigIj8PA9T5MXEGrRWVyh9fKqa/uKfFQsJUshxMSWN0lXvJof2hjP1lmp9bfwH+EgqksLCWxO93eIZebV9JC8646EYF3hGTfB2IRUYANr3pzIuF8OQvNYyDSVDVTD8ag== Received: from MWHPR04CA0048.namprd04.prod.outlook.com (2603:10b6:300:ee::34) by BN8PR12MB3346.namprd12.prod.outlook.com (2603:10b6:408:45::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.26; Fri, 12 Mar 2021 17:24:24 +0000 Received: from CO1NAM11FT014.eop-nam11.prod.protection.outlook.com (2603:10b6:300:ee:cafe::87) by MWHPR04CA0048.outlook.office365.com (2603:10b6:300:ee::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.26 via Frontend Transport; Fri, 12 Mar 2021 17:24:23 +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 CO1NAM11FT014.mail.protection.outlook.com (10.13.175.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.3933.31 via Frontend Transport; Fri, 12 Mar 2021 17:24:23 +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; Fri, 12 Mar 2021 17:24:19 +0000 From: Petr Machata To: , , CC: Ido Schimmel , Petr Machata Subject: [PATCH iproute2-next 6/6] nexthop: Add support for nexthop buckets Date: Fri, 12 Mar 2021 18:23:09 +0100 Message-ID: <437055b04926ca1b15b17056199aa3e981d8a424.1615568866.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: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1dcc7a1d-f330-4263-3000-08d8e57bae12 X-MS-TrafficTypeDiagnostic: BN8PR12MB3346: 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: l+CT4Km8hKERc+dkqxlUEbBlhgZokJLBfXxrvRG/vSsb7DEYuh55L1XnQN0bfL6DPho+EM34Wtq/15OpgzuxoZqS+dTQD4Q4npDzAMx3Csm+qiemn/Y+jxXqeZghD0M3lROjeLnGmKez1cExFWYofzn8Sqi2/kTT+ZJ/+tG2Tv5/A9Lqwf3VobScmQMzEsIvwIOiR/KGph0+YbnVSPjmtSibi5Owm3Eld39VKWnQVO9twjA7NZEptIXrtvX0u6FMJLEoUoJdUzvNTKUleQTDM3f0WVwXFKx/rk7X58cQOSpqRJolK9WrMHPEcWnetnY2vRLvD+1ujXszM662xF5hA0QkULG6o7M/RZY3E9nGZgeGmGsRgK406AjzN9Xn0e+SdfNVNw3A2AWRVAmtDHLo2XrUr8x6lgoG5BEnOQ84gbgKBM2wj0zv40vwxfnc1g75Mqji9QRrnaAw/0HOeuLBoMSRkdJA4wGwxh6ZdrhqGt6Xt7SUDzFwat40GP7Dd2TaLQGfRlmXPovXKEEf0p9iVjhQKhMtoZr2Nz82KHhZZPvfhsenrqCu63vpa7cItqeXzhYNjpk4RePqj+uHKYcTB4Uh9Lu6hT+l5S9PF2lwdG89g7Op/L3NErnIP0rI17CIggF2y2UZKGzRhu9NuEEKlT4uidiOykhP0ZyBJpIkacQ0k9gN1Joq6X3qE2NSa1lQ 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)(396003)(376002)(136003)(346002)(36840700001)(46966006)(16526019)(186003)(8676002)(30864003)(26005)(7636003)(316002)(82740400003)(70206006)(6666004)(2906002)(36860700001)(336012)(83380400001)(47076005)(82310400003)(34020700004)(356005)(70586007)(86362001)(5660300002)(54906003)(36906005)(110136005)(426003)(4326008)(2616005)(36756003)(8936002)(478600001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Mar 2021 17:24:23.5921 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1dcc7a1d-f330-4263-3000-08d8e57bae12 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: CO1NAM11FT014.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3346 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com From: Petr Machata 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 c68fcc0f9cf5..d9ce634fb3d8 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 " | [ " @@ -229,6 +243,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