From patchwork Mon Sep 18 10:54:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13389430 X-Patchwork-Delegate: dsahern@gmail.com Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E76E663B6 for ; Mon, 18 Sep 2023 10:54:50 +0000 (UTC) Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54EE612A for ; Mon, 18 Sep 2023 03:54:21 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-9ad8bba8125so574938666b.3 for ; Mon, 18 Sep 2023 03:54:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1695034460; x=1695639260; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0xm57SUfFZHH+8dv1S0QHpRMRBULiYAXcl59n2S0Yyw=; b=ITJikVE1t+gBhy8OlVP4h7YARNmw+Q/QRHpfbhJ0hY14YMucyDCoisJwANPCXPrZs8 y4S6AcmG6yN/IrEA79IujN9DsWTpMpG91PjVH4UNiu57YQ00GbMtMFSAKb3f+i+4R9tb o+zKc3xa0Niuznro2nxRz5po86foTufKfkWQqnZ5YLT8Q2WMbY9EpojtTLpDjtJMpwJr ZofosniW/OeBiKeayPLd977sgXlgDAGsztPt+XPJ2mAJeo7wwIbp8U9tE5v2Podotvh1 eddyMdY0Zak9MCCRoQttaPegnAGeoQ8rfIMybx6DRBkV8Pic0e1c8QlXJ7Edckz8/+Su Pkgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695034460; x=1695639260; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0xm57SUfFZHH+8dv1S0QHpRMRBULiYAXcl59n2S0Yyw=; b=V1Ics5I7xcfnGB+8I1M0L2TAnMxQeIXNsyJBKWTotI3iRLqMGwpHDu7cMphfwatxHF 4oMezxA81/imWgqKH1LBZnruBO2ASgUMYVMgaNFODUGcDfD/3sHyIC9x+/fn+fivLoMi YgCYjdrJRHQ6Z1yYCr8ltnAAM4XoTGbZMn9EjIcnUPRlS/ob5szISk60U/oKweqTvHAS vdQN0fGzO5yMKwFbq4EY3MYknLSo2ypNqRAZGNkQmIKx9CH6SgIVAYdUP4TTbX7a91s0 EbNHm28nkp60iP3tdoNJjPacvpMpJstO0M8/Ne+QWxv9jbtgQuTuTClm7B35MB6WhYvR DQ5A== X-Gm-Message-State: AOJu0YwrtgOAZ5UjANRzxjF1z6n8Cp9Oc/DRmem/7nJa7lAs7Wes1Ltp SwFDzUZtKwmdNFskTVE/ZrUOoZPgxJDglUQTNTs= X-Google-Smtp-Source: AGHT+IF2RVJ/5N/TLNvDdBK1ZeINZe4seUB9s3rEMUo75tDL+sTndStCCuCpa/uiUthUQy3rCFmNSw== X-Received: by 2002:a17:906:3053:b0:9a1:e994:3440 with SMTP id d19-20020a170906305300b009a1e9943440mr7926965ejd.4.1695034459855; Mon, 18 Sep 2023 03:54:19 -0700 (PDT) Received: from localhost ([86.61.181.4]) by smtp.gmail.com with ESMTPSA id vr6-20020a170907a50600b009adce1c97ccsm4848143ejc.53.2023.09.18.03.54.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 03:54:19 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: stephen@networkplumber.org, dsahern@gmail.com Subject: [patch iproute2-next 1/4] devlink: update headers Date: Mon, 18 Sep 2023 12:54:13 +0200 Message-ID: <20230918105416.1107260-2-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918105416.1107260-1-jiri@resnulli.us> References: <20230918105416.1107260-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: dsahern@gmail.com From: Jiri Pirko Update the devlink headers to recent net-next. Signed-off-by: Jiri Pirko --- include/uapi/linux/devlink.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h index 8b9b98e75059..6c4721270910 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -680,6 +680,7 @@ enum devlink_port_function_attr { DEVLINK_PORT_FN_ATTR_STATE, /* u8 */ DEVLINK_PORT_FN_ATTR_OPSTATE, /* u8 */ DEVLINK_PORT_FN_ATTR_CAPS, /* bitfield32 */ + DEVLINK_PORT_FN_ATTR_DEVLINK, /* nested */ __DEVLINK_PORT_FUNCTION_ATTR_MAX, DEVLINK_PORT_FUNCTION_ATTR_MAX = __DEVLINK_PORT_FUNCTION_ATTR_MAX - 1 From patchwork Mon Sep 18 10:54:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13389432 X-Patchwork-Delegate: dsahern@gmail.com Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D81E6FC3 for ; Mon, 18 Sep 2023 10:54:51 +0000 (UTC) Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 271F3188 for ; Mon, 18 Sep 2023 03:54:23 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-991c786369cso590158166b.1 for ; Mon, 18 Sep 2023 03:54:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1695034461; x=1695639261; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uvAKdPrFmWu5KYQYiGqglh6LusMwFEKr0TU1U+69is8=; b=dRf61l3V7p/d1qKEuXskPJcLyE2kdIiLl6pBwC4A7JPimPJvnLs0xIcXGPvZIqWZiq GYYqhkBFnDFazMr/lYyPCjR4BJDepmaF3NiOjCxkwMgbUOfisoQuMQyehQubdUMS7Enl 58SamEYArnaHKP4po2HWiqx4ujh1vvfYxEB3Jue13WNvjnvFHgyp5ZLLESVopmP71Yob sGw304NrbZXAs0kFiMhdclvFks1IP0TQG9rquDNw1wkPXuVtwx5nsB+yoKM+GRbSBHi5 2u5NDaMstn+gzwXja1yZ8Mnv+wpAjybsSjbBPyDS2YhVCJODIqmwUwehA3pFabrBgScn 7ihg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695034461; x=1695639261; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uvAKdPrFmWu5KYQYiGqglh6LusMwFEKr0TU1U+69is8=; b=dI76Wz41rXJQsMkUjJwMye2ppAzcpV7CAqP7avyeitBMT9sTXN1R840uc5JJlqlgk7 bhMfRDK9GT/n5N4TJ++VjW8fgOUEBjJXdgLvpar6u0gh1HDyVqRuHj91w29L46JQSF7k AHIxRX1J303CjJrnZi1UfJj8JnKskqxB/nxsRAQF2sPoc8bHmeC/LmPEUoIKilDjIYnk mqJbUsnp8hIlWIitcERNixcnPlydTE1bF8AGNuCEsEXEOBamQi7xpfG9IGrN3OVn4viT FF2aZLMKzCUuMJ9KVt8NSSPo6Ha333u65ZK+ymRPOt2NfuA9wYkXoS3yYeL/+rZ2Ve2g qlKQ== X-Gm-Message-State: AOJu0YyY78m+EgUk1hq59agqhfZkLM29jHAZohbYIl4mulf0Cy/0lJQ+ /VvnsJwBX7sYxmGBmZoe4HmT82XuLIjaWywBlyU= X-Google-Smtp-Source: AGHT+IHf5xB7lISVdo/1SFGdn9z0VAAfMStmpbEooajetvSEXaZNGx1dZBimib/20hRzOvxMxJTVbA== X-Received: by 2002:a17:906:329a:b0:9a9:e6c3:ad28 with SMTP id 26-20020a170906329a00b009a9e6c3ad28mr7796416ejw.69.1695034461461; Mon, 18 Sep 2023 03:54:21 -0700 (PDT) Received: from localhost ([86.61.181.4]) by smtp.gmail.com with ESMTPSA id y3-20020a17090629c300b009929d998abcsm6239020eje.209.2023.09.18.03.54.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 03:54:20 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: stephen@networkplumber.org, dsahern@gmail.com Subject: [patch iproute2-next 2/4] devlink: introduce support for netns id for nested handle Date: Mon, 18 Sep 2023 12:54:14 +0200 Message-ID: <20230918105416.1107260-3-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918105416.1107260-1-jiri@resnulli.us> References: <20230918105416.1107260-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: dsahern@gmail.com From: Jiri Pirko Nested handle may contain DEVLINK_ATTR_NETNS_ID attribute that indicates the network namespace where the nested devlink instance resides. Process this converting to netns name if possible and print to user. Signed-off-by: Jiri Pirko --- devlink/devlink.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/devlink/devlink.c b/devlink/devlink.c index d1795f616ca0..31dd29452c39 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -722,6 +723,7 @@ static const enum mnl_attr_data_type devlink_policy[DEVLINK_ATTR_MAX + 1] = { [DEVLINK_ATTR_LINECARD_SUPPORTED_TYPES] = MNL_TYPE_NESTED, [DEVLINK_ATTR_NESTED_DEVLINK] = MNL_TYPE_NESTED, [DEVLINK_ATTR_SELFTESTS] = MNL_TYPE_NESTED, + [DEVLINK_ATTR_NETNS_ID] = MNL_TYPE_U32, }; static const enum mnl_attr_data_type @@ -2723,6 +2725,85 @@ static bool should_arr_last_handle_end(struct dl *dl, const char *bus_name, !cmp_arr_last_handle(dl, bus_name, dev_name); } +static int32_t netns_id_by_name(const char *name) +{ + struct { + struct nlmsghdr n; + struct rtgenmsg g; + char buf[1024]; + } req = { + .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtgenmsg)), + .n.nlmsg_flags = NLM_F_REQUEST, + .n.nlmsg_type = RTM_GETNSID, + .g.rtgen_family = AF_UNSPEC, + }; + int ret = NETNSA_NSID_NOT_ASSIGNED; + struct rtattr *tb[NETNSA_MAX + 1]; + struct nlmsghdr *n = NULL; + struct rtnl_handle rth; + struct rtgenmsg *rtg; + int len; + int fd; + + fd = netns_get_fd(name); + if (fd < 0) + return ret; + + if (rtnl_open(&rth, 0) < 0) + return ret; + + addattr32(&req.n, sizeof(req), NETNSA_FD, fd); + if (rtnl_talk(&rth, &req.n, &n) < 0) + goto out; + + if (n->nlmsg_type == NLMSG_ERROR) + goto out; + + rtg = NLMSG_DATA(n); + len = n->nlmsg_len; + + len -= NLMSG_SPACE(sizeof(*rtg)); + if (len < 0) + goto out; + + parse_rtattr(tb, NETNSA_MAX, NETNS_RTA(rtg), len); + if (tb[NETNSA_NSID]) + ret = rta_getattr_s32(tb[NETNSA_NSID]); + +out: + free(n); + rtnl_close(&rth); + close(fd); + return ret; +} + +struct netns_name_by_id_ctx { + int32_t id; + char *name; +}; + +static int nesns_name_by_id_func(char *nsname, void *arg) +{ + struct netns_name_by_id_ctx *ctx = arg; + int32_t ret; + + ret = netns_id_by_name(nsname); + if (ret < 0 || ret != ctx->id) + return 0; + ctx->name = strdup(nsname); + return 1; +} + +static char *netns_name_by_id(int32_t id) +{ + struct netns_name_by_id_ctx ctx = { + .id = id, + }; + + netns_foreach(nesns_name_by_id_func, &ctx); + return ctx.name; +} + static void pr_out_nested_handle(struct nlattr *nla_nested_dl) { struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {}; @@ -2740,6 +2821,30 @@ static void pr_out_nested_handle(struct nlattr *nla_nested_dl) sprintf(buf, "%s/%s", mnl_attr_get_str(tb[DEVLINK_ATTR_BUS_NAME]), mnl_attr_get_str(tb[DEVLINK_ATTR_DEV_NAME])); print_string(PRINT_ANY, "nested_devlink", " nested_devlink %s", buf); + + if (tb[DEVLINK_ATTR_NETNS_ID]) { + int32_t id = mnl_attr_get_u32(tb[DEVLINK_ATTR_NETNS_ID]); + + if (id >= 0) { + char *name = netns_name_by_id(id); + + if (name) { + print_string(PRINT_ANY, + "nested_devlink_netns", + " nested_devlink_netns %s", name); + free(name); + } else { + print_int(PRINT_ANY, + "nested_devlink_netnsid", + " nested_devlink_netnsid %d", id); + } + } else { + print_string(PRINT_FP, NULL, + " nested_devlink_netnsid %s", "unknown"); + print_int(PRINT_JSON, + "nested_devlink_netnsid", NULL, id); + } + } } static void __pr_out_handle_start(struct dl *dl, struct nlattr **tb, From patchwork Mon Sep 18 10:54:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13389433 X-Patchwork-Delegate: dsahern@gmail.com Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 262B614AB3 for ; Mon, 18 Sep 2023 10:54:54 +0000 (UTC) Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7D5C129 for ; Mon, 18 Sep 2023 03:54:24 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-9a9d82d73f9so538610166b.3 for ; Mon, 18 Sep 2023 03:54:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1695034463; x=1695639263; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aKd06wBuxPIH0zq8nwAImCSv1mwa2d7HOT+ZZ81oxZQ=; b=gINrMPpaLXJWiVUh5m+9sC36fvA7HviLBDhIc0bQgIN4qU4/BPWwEXFMpwi2rIGGyL Avn2RPwCeHCycaZ1rtU4KDV+ViCSJwlziChEaZFC/BsbU9inzPUf/Q8ds94KoBdhVO9h g6xjK7tA/Ua/qYG7San9Dd7AFCFniRCH+je/fMRloV4TiTknCC4hPOjc26JMtCo5dC9E y3r9Pay2w+lvWER+ws7KBN4T9PKMIeWbkwVoDgT6CwqNCueh7H9gSA/upgaDHnLK3l22 wMdRnZR7uBJO8s43Ko/KsAZAqVBMUKid2KxCDECHPhgtiEKqKlmX912IpYhFWTayUrjm g4Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695034463; x=1695639263; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aKd06wBuxPIH0zq8nwAImCSv1mwa2d7HOT+ZZ81oxZQ=; b=dqgvLHW3/6fscaEMBFOcoWDb8jc7P78957os0VLtM5fxui7JTdtwmVa2OwyQbqJ1cH rdxCKpxz6IObi8v4FY4ztTnWE8za99IzyuMoyEIjQQsgvFrQFD9QpIrjdzbPKF8Ejbfj GiE3ycpssoJFhFFM4DGrtqfVx9N2rqsmdZYbUVOZJ/o7+c1b6PTSQ2vRLtmZ/LvFZ1SS 2pvb5/lvqdPfG5oA/cGmP7E5o5GqGcCB/o2iQWC2EpzEK0BK5Ibli6pi8x06KuAWI5FY BoIl/teysvrWjh12Ph9dBcpmedpdXuO5KF2S9IjZd+7dClsdThZjq5T9LDGwsCmNU/w0 b7PA== X-Gm-Message-State: AOJu0YxdAeIrQVxFJgpdLnVIYSoR9WiONL6+VqOAE6ByVjCWgGXn+p0r i8DylTpR6Pv+ynm4zE1WzkQtLZM1NzJ7nZ/r7as= X-Google-Smtp-Source: AGHT+IHbmK7PmlWEZGUuKIqXF1NL/Q/8wqB8riFsOVMRiGKzCQjQENJ8ISDjYQxb8XvRRWcoZvqINw== X-Received: by 2002:a17:907:75cd:b0:9a9:dfbe:ca98 with SMTP id jl13-20020a17090775cd00b009a9dfbeca98mr7442942ejc.7.1695034462988; Mon, 18 Sep 2023 03:54:22 -0700 (PDT) Received: from localhost ([86.61.181.4]) by smtp.gmail.com with ESMTPSA id qb18-20020a1709077e9200b009adc5802d08sm5346503ejc.190.2023.09.18.03.54.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 03:54:22 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: stephen@networkplumber.org, dsahern@gmail.com Subject: [patch iproute2-next 3/4] devlink: print nested handle for port function Date: Mon, 18 Sep 2023 12:54:15 +0200 Message-ID: <20230918105416.1107260-4-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918105416.1107260-1-jiri@resnulli.us> References: <20230918105416.1107260-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: dsahern@gmail.com From: Jiri Pirko If port function contains nested handle attribute, print it. Signed-off-by: Jiri Pirko --- devlink/devlink.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/devlink/devlink.c b/devlink/devlink.c index 31dd29452c39..8ea7b268c63c 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -772,6 +772,7 @@ static const enum mnl_attr_data_type devlink_function_policy[DEVLINK_PORT_FUNCTION_ATTR_MAX + 1] = { [DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR ] = MNL_TYPE_BINARY, [DEVLINK_PORT_FN_ATTR_STATE] = MNL_TYPE_U8, + [DEVLINK_PORT_FN_ATTR_DEVLINK] = MNL_TYPE_NESTED, }; static int function_attr_cb(const struct nlattr *attr, void *data) @@ -4875,6 +4876,8 @@ static void pr_out_port_function(struct dl *dl, struct nlattr **tb_port) port_fn_caps->value & DEVLINK_PORT_FN_CAP_MIGRATABLE ? "enable" : "disable"); } + if (tb[DEVLINK_PORT_FN_ATTR_DEVLINK]) + pr_out_nested_handle(tb[DEVLINK_PORT_FN_ATTR_DEVLINK]); if (!dl->json_output) __pr_out_indent_dec(); From patchwork Mon Sep 18 10:54:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13389434 X-Patchwork-Delegate: dsahern@gmail.com Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C74B318E31 for ; Mon, 18 Sep 2023 10:54:54 +0000 (UTC) Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48007103 for ; Mon, 18 Sep 2023 03:54:26 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-9ad8bf9bfabso570101866b.3 for ; Mon, 18 Sep 2023 03:54:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1695034464; x=1695639264; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GCJBECLpFEzbWQFVcPazQjZw8/sVT/dSGgBqqUOQozM=; b=F8nq0XgbV8g8glfiu7XFyYVKn7zjNK+ZPP2FikicnK1mAvKl0FNO3QJwb0RHbefTxW FWyF2ntDE6du0NgdCF2adr4PrfdbLT3Pvrz8AS3b7Nxd+7PEDPyPNYTYvgMc/j1cBMUK ueK3kxdD35dSdnmPGOeI8aeLDvr0SQ1jh4EZhHC3dCzsW4u88RZk9C5cUFykNfef/idt t1SkKP021GVeDhWKUIjLgsJsRXsd7zFQIbvcD1+wPKPPP3zP9fgP/bALwqNvficBf1+D LeUu7zWQdkDNfUXJitA4d1xvAittDhkGA0SiHVsLcD6qo0IgJRHH8cbyrBVk6t2WgwgC kYQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695034465; x=1695639265; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GCJBECLpFEzbWQFVcPazQjZw8/sVT/dSGgBqqUOQozM=; b=WBmELus479H4/xQ3+YqJOyXyurzq6VtNDs3OSGALaBUNSlA3Sx9WeGTj+KgSlHy4FN U+a3+YdNidXPUz2qUiwTrHxgIYYMfa1Csa99rd6ohd/eSLWc8LV9JHxxlLOqQJqh1kDG XdiHUcqOHMA1CvOul9HN/nlSucSTw3ZaLTxXQSDVfgYUwNRkNhZFPrvv/xVtzBAiOflE 4A8PtzsbuCpE0vztkl8540xTh0c4IUahRlQ/d0HmHWBDr/h2zRiDb5gZs/1/nXoIlZou TRe9HGolvJaigUKXw3f+WSt2WJtFxRYvyuNuZaM2IqWtxqSQxbwTDO9k0cgp/WrnUXKE z6ZQ== X-Gm-Message-State: AOJu0Yy83oB9HIiaOGvo/lz4Yw2FUjECR8H0UzrwyBSbI0L0qBnpNgVA hpkLhdT+CbSdjmtH718Ldio+OIE/nLF2iC2v8zE= X-Google-Smtp-Source: AGHT+IGLIZqFeSZ9y5y5qe1jxRaaMamIMBxFFw12QTywncg/BYdqK7SBec9/YFH4ShYLKUETsKLmjQ== X-Received: by 2002:a17:906:105c:b0:9a3:c4f4:12de with SMTP id j28-20020a170906105c00b009a3c4f412demr7206375ejj.37.1695034464664; Mon, 18 Sep 2023 03:54:24 -0700 (PDT) Received: from localhost ([86.61.181.4]) by smtp.gmail.com with ESMTPSA id h24-20020a170906829800b009ae0042e48bsm2169552ejx.5.2023.09.18.03.54.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 03:54:24 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: stephen@networkplumber.org, dsahern@gmail.com Subject: [patch iproute2-next 4/4] devlink: print nested devlink handle for devlink dev Date: Mon, 18 Sep 2023 12:54:16 +0200 Message-ID: <20230918105416.1107260-5-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918105416.1107260-1-jiri@resnulli.us> References: <20230918105416.1107260-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: dsahern@gmail.com From: Jiri Pirko Devlink dev may contain one or more nested devlink instances. If one is present, print it out simple. If more are present (there is no such case in current kernel, but may be in theory in the future), print them in array. Signed-off-by: Jiri Pirko --- devlink/devlink.c | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/devlink/devlink.c b/devlink/devlink.c index 8ea7b268c63c..a387da0f4995 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -3889,13 +3889,50 @@ static void pr_out_reload_data(struct dl *dl, struct nlattr **tb) pr_out_object_end(dl); } +static void pr_out_dev_nested(struct dl *dl, const struct nlmsghdr *nlh) +{ + struct nlattr *attr, *attr2; + int count = 0; + + mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) { + if (mnl_attr_get_type(attr) == DEVLINK_ATTR_NESTED_DEVLINK) { + count++; + attr2 = attr; + } + } + if (!count) { + return; + } else if (count == 1) { + pr_out_nested_handle(attr2); + return; + } + + pr_out_array_start(dl, "nested_devlinks"); + mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) { + if (mnl_attr_get_type(attr) == DEVLINK_ATTR_NESTED_DEVLINK) { + check_indent_newline(dl); + if (dl->json_output) + open_json_object(NULL); + check_indent_newline(dl); + pr_out_nested_handle(attr); + if (dl->json_output) + close_json_object(); + else + __pr_out_newline(); + } + } + pr_out_array_end(dl); +} -static void pr_out_dev(struct dl *dl, struct nlattr **tb) +static void pr_out_dev(struct dl *dl, const struct nlmsghdr *nlh, + struct nlattr **tb) { if ((tb[DEVLINK_ATTR_RELOAD_FAILED] && mnl_attr_get_u8(tb[DEVLINK_ATTR_RELOAD_FAILED])) || - (tb[DEVLINK_ATTR_DEV_STATS] && dl->stats)) { + (tb[DEVLINK_ATTR_DEV_STATS] && dl->stats) || + tb[DEVLINK_ATTR_NESTED_DEVLINK]) { __pr_out_handle_start(dl, tb, true, false); pr_out_reload_data(dl, tb); + pr_out_dev_nested(dl, nlh); pr_out_handle_end(dl); } else { pr_out_handle(dl, tb); @@ -3912,7 +3949,7 @@ static int cmd_dev_show_cb(const struct nlmsghdr *nlh, void *data) if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME]) return MNL_CB_ERROR; - pr_out_dev(dl, tb); + pr_out_dev(dl, nlh, tb); return MNL_CB_OK; } @@ -6828,7 +6865,7 @@ static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data) return MNL_CB_ERROR; pr_out_mon_header(genl->cmd); dl->stats = true; - pr_out_dev(dl, tb); + pr_out_dev(dl, nlh, tb); pr_out_mon_footer(); break; case DEVLINK_CMD_PORT_GET: /* fall through */