From patchwork Tue Oct 24 10:03:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13434168 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 316F6250ED for ; Tue, 24 Oct 2023 10:04:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b="oleDd+hb" 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 094ADEA for ; Tue, 24 Oct 2023 03:04:09 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-9bf0ac97fdeso604641266b.2 for ; Tue, 24 Oct 2023 03:04:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1698141847; x=1698746647; 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=X2yDAqtESHRIhVQtHN6xfONaeCRWGymWxnQhzScD7Z0=; b=oleDd+hb20Rlad+Ik6GEsHRz7Oe47FR9NpUfqFpFHZmMPI1VR3vGYU1dq9L/MgVLDq /tjfRGiPpU9G0s4B5pDjdVRfsEWdZTsIYzeI7Bdet5PZaKLEivCcJi9mKicBDTWzvVaL 7iX/LQGkm7BvQ/KRtsdKxACoTz9khoAKX+/SlNN5iffE8MTu6NZ1y2rODDjzIu0/e+lB klQZsBU2I643uNLzDPfOLOuGqYyqMyEH+CXlZ5OhFLK7EIczHBBIxfN8M4md/6bYAzJq iyXHs6sUiCbCJF82nsqDnGcFXv8rKF/v/ERE4SvaJ0CHgJztGSxegx2V7w83DJNZBnxW VZbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698141847; x=1698746647; 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=X2yDAqtESHRIhVQtHN6xfONaeCRWGymWxnQhzScD7Z0=; b=R5xdF053ay4/GN9KKFuLsUVf9BdZQplwq7AQngFzodKhIYm2MgJkKGaAnDOJPFxe/K hDgvSAW1sMwnKSo1hzrgwGRHAoAn0QvL/Ircv6QwFuDus2Thh91vdUDGptQka8iX81KB KdKcgkHPiqEiPYYX/sj76zh64AFATCC1F7QPZAKxbAFBJAMZk1O/pzaPPc0PBvqSlsJ1 BrqOhiav54gqHsETWWD0kjsaOtRRDTgQTiDTZZ/k+i4zJQtiksuM2TUK+3azIjRyEDIp faENkZXMYXrCZ7d6xOOwo6rJZgfaukDT6JSUu45CItZtU0wM4vbmIOWqJneQK4ShBUHE IuRw== X-Gm-Message-State: AOJu0Yx/ploLSk/hB7OZTN/CAbdu6k8YVagMmEpad3XUhud4QOEjpeL5 9zTnMxP5lWy2uOYg+mwESzUsUZwzluCIqt7C3AE9lw== X-Google-Smtp-Source: AGHT+IFrGbtmSzRXwwnu/RnChI3fdR6JyvWoGdAgWPAV4MfdlJOYj6C807TjSOyU5ei6wZCyKCgmRQ== X-Received: by 2002:a17:906:ef0e:b0:9be:834a:f80b with SMTP id f14-20020a170906ef0e00b009be834af80bmr8775123ejs.75.1698141847299; Tue, 24 Oct 2023 03:04:07 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id c26-20020a170906171a00b009c921a8aae2sm4128236eje.7.2023.10.24.03.04.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 03:04:06 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: stephen@networkplumber.org, dsahern@gmail.com, daniel.machon@microchip.com Subject: [patch iproute2-next v3 1/6] ip/ipnetns: move internals of get_netnsid_from_name() into namespace.c Date: Tue, 24 Oct 2023 12:03:58 +0200 Message-ID: <20231024100403.762862-2-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231024100403.762862-1-jiri@resnulli.us> References: <20231024100403.762862-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: dsahern@gmail.com From: Jiri Pirko In order to be able to reuse get_netnsid_from_name() function outside of ip code, move the internals to lib/namespace.c to a new function called netns_id_from_name(). Signed-off-by: Jiri Pirko --- v2->v3: - s/netns_netnsid_from_name/netns_id_from_name/ v1->v2: - new patch --- include/namespace.h | 4 ++++ ip/ipnetns.c | 45 +---------------------------------------- lib/namespace.c | 49 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 44 deletions(-) diff --git a/include/namespace.h b/include/namespace.h index e47f9b5d49d1..e860a4b8ee5b 100644 --- a/include/namespace.h +++ b/include/namespace.h @@ -8,6 +8,8 @@ #include #include +#include "namespace.h" + #ifndef NETNS_RUN_DIR #define NETNS_RUN_DIR "/var/run/netns" #endif @@ -58,4 +60,6 @@ struct netns_func { void *arg; }; +int netns_id_from_name(struct rtnl_handle *rtnl, const char *name); + #endif /* __NAMESPACE_H__ */ diff --git a/ip/ipnetns.c b/ip/ipnetns.c index 9d996832aef8..0ae46a874a0c 100644 --- a/ip/ipnetns.c +++ b/ip/ipnetns.c @@ -105,52 +105,9 @@ static int ipnetns_have_nsid(void) int get_netnsid_from_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, - }; - struct nlmsghdr *answer; - struct rtattr *tb[NETNSA_MAX + 1]; - struct rtgenmsg *rthdr; - int len, fd, ret = -1; - netns_nsid_socket_init(); - fd = netns_get_fd(name); - if (fd < 0) - return fd; - - addattr32(&req.n, 1024, NETNSA_FD, fd); - if (rtnl_talk(&rtnsh, &req.n, &answer) < 0) { - close(fd); - return -2; - } - close(fd); - - /* Validate message and parse attributes */ - if (answer->nlmsg_type == NLMSG_ERROR) - goto out; - - rthdr = NLMSG_DATA(answer); - len = answer->nlmsg_len - NLMSG_SPACE(sizeof(*rthdr)); - if (len < 0) - goto out; - - parse_rtattr(tb, NETNSA_MAX, NETNS_RTA(rthdr), len); - - if (tb[NETNSA_NSID]) { - ret = rta_getattr_s32(tb[NETNSA_NSID]); - } - -out: - free(answer); - return ret; + return netns_id_from_name(&rtnsh, name); } struct nsid_cache { diff --git a/lib/namespace.c b/lib/namespace.c index 1202fa85f97d..f03f4bbabceb 100644 --- a/lib/namespace.c +++ b/lib/namespace.c @@ -7,9 +7,11 @@ #include #include #include +#include #include "utils.h" #include "namespace.h" +#include "libnetlink.h" static void bind_etc(const char *name) { @@ -139,3 +141,50 @@ int netns_foreach(int (*func)(char *nsname, void *arg), void *arg) closedir(dir); return 0; } + +int netns_id_from_name(struct rtnl_handle *rtnl, 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, + }; + struct nlmsghdr *answer; + struct rtattr *tb[NETNSA_MAX + 1]; + struct rtgenmsg *rthdr; + int len, fd, ret = -1; + + fd = netns_get_fd(name); + if (fd < 0) + return fd; + + addattr32(&req.n, 1024, NETNSA_FD, fd); + if (rtnl_talk(rtnl, &req.n, &answer) < 0) { + close(fd); + return -2; + } + close(fd); + + /* Validate message and parse attributes */ + if (answer->nlmsg_type == NLMSG_ERROR) + goto out; + + rthdr = NLMSG_DATA(answer); + len = answer->nlmsg_len - NLMSG_SPACE(sizeof(*rthdr)); + if (len < 0) + goto out; + + parse_rtattr(tb, NETNSA_MAX, NETNS_RTA(rthdr), len); + + if (tb[NETNSA_NSID]) + ret = rta_getattr_s32(tb[NETNSA_NSID]); + +out: + free(answer); + return ret; +} From patchwork Tue Oct 24 10:03:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13434169 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 1C0D7250EE for ; Tue, 24 Oct 2023 10:04:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b="azrISm/C" Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B328BDC for ; Tue, 24 Oct 2023 03:04:10 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-9ae2cc4d17eso645660866b.1 for ; Tue, 24 Oct 2023 03:04:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1698141849; x=1698746649; 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=ccMtuO+zt1fMw+Gu4Yh5qATQ62lLyHlYSWuS8GbJO90=; b=azrISm/CGPrsg1ucr1XaPrMKe8lSnixQrp6YOCI5E5ZHwg4TAn9jlCY93ccBI1/+jj 4MT4M5KoRpytaNJKo+6qNAfLjuEga8f5i9LCiMannmDLEeNydsZMK9I1H/TvDWXlDKMR QQXqmzkbcx3yHtspsOF85pIKyZbkguHn+xsbVkf+IZxNTyOvU4RdLa0N+hejYMV51riW Op//XjMTx5N+CnJPnSh5ON8iZ8nDIGlL+pZ33VZhCnRwJbHrpdufEE4hlX7vIzS2ZFHV Ei1P/IOdd2GsDsY2xnezB1g6chHKucDPaeTkWLp0Uvf89MqWct9HgHf9DQQ/+InqdXmy 7pRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698141849; x=1698746649; 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=ccMtuO+zt1fMw+Gu4Yh5qATQ62lLyHlYSWuS8GbJO90=; b=Q2NH0FU1cHgEKqDzgRdkBsgwqnv0QjyiUep8EP17H5OAuxzv0Fwm3sujNTtWRR+j1e ZFLmRED6BvnZ7dQ5jHyPjJ69BTRvria9t/GboWSvFDg/zWwDEtrsGONWtRe50/r9Og/v r95wORgEvvJhH9xu8OCY8TPbAobWjOMGZI0jibCKtAO09quQGcylcmaI3UdKQOpNSzfO ak6FLfLUrr0JzOyya8CvBa2I/+SiUmuGdnatx0iw894Og1BTKdo5mx9MlctNX7nPweRw x0aZ6f67+eACVhboIYtJWGGZ0nBiO3Y4OvGwzvUgYgR8YVWHJ9KV3/LjNM9DhW4dhE+o /X4g== X-Gm-Message-State: AOJu0Yz9c+lpWyG9/irdvtRmZntx+y1IK0oDnzlEr8MjfXxpk5Bc2765 GZ6IOzIINd92o+UgALEyVsS1f7u87TiRc9Qhm212Ig== X-Google-Smtp-Source: AGHT+IHKZM6mU6cYOLPZ5N6AjcvwrCtcU1Tnl2Dc0yBF2jXZ1RjlkXEZg1l8lrfUAxZmLBemXki4uQ== X-Received: by 2002:a17:907:970c:b0:9a5:a0c6:9e8e with SMTP id jg12-20020a170907970c00b009a5a0c69e8emr9639512ejc.31.1698141849039; Tue, 24 Oct 2023 03:04:09 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id fx4-20020a170906b74400b009b9a1714524sm8118186ejb.12.2023.10.24.03.04.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 03:04:08 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: stephen@networkplumber.org, dsahern@gmail.com, daniel.machon@microchip.com Subject: [patch iproute2-next v3 2/6] devlink: do conditional new line print in pr_out_port_handle_end() Date: Tue, 24 Oct 2023 12:03:59 +0200 Message-ID: <20231024100403.762862-3-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231024100403.762862-1-jiri@resnulli.us> References: <20231024100403.762862-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: dsahern@gmail.com From: Jiri Pirko Instead of printing out new line unconditionally, use __pr_out_newline() to print it only when needed avoiding double prints. Signed-off-by: Jiri Pirko --- v2->v3: - new patch --- devlink/devlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devlink/devlink.c b/devlink/devlink.c index 3baad355759e..c18a4a4fbc5a 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -2974,7 +2974,7 @@ static void pr_out_port_handle_end(struct dl *dl) if (dl->json_output) close_json_object(); else - pr_out("\n"); + __pr_out_newline(); } static void pr_out_region_chunk_start(struct dl *dl, uint64_t addr) From patchwork Tue Oct 24 10:04:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13434170 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 8ADF5250F6 for ; Tue, 24 Oct 2023 10:04:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b="UzdXe7pw" Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44FDAF9 for ; Tue, 24 Oct 2023 03:04:12 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-99bdeae1d0aso637537866b.1 for ; Tue, 24 Oct 2023 03:04:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1698141851; x=1698746651; 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=mitkHMxFPrlJNS1H9PyNiOCeZEz/WwBpqGxo02llvo8=; b=UzdXe7pw9hMsqOFUwDl6jtjZ7/tsjB22UfytbffEgFtFa0Vn1NL237IoQO9HX4VdYS 3dRp9FVW1ktrc7pSOKgrgemk9ORAsy9eKKKSdIu+Ar+CIjD51l/hisXqe+257U0FpSgD OBDI3qZkjADBjPqUMmz0GK+8ArRo1K5msuwq/7GAFAln+x3bUHCTLzShzzMfY1zgUIYw vHqUwnFtc3TEPxwBa7Dt8TSxXPKhyMSFaXwsnKCDtInzzGjBAcy2QTUzK0d72m5GElp1 AxGjbsx0EA+GzN6LNIqpYwnLSthRwXF81Woxf9XxB8JTOxMHBv2UdQTxtUxtCkYs7nVH 55WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698141851; x=1698746651; 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=mitkHMxFPrlJNS1H9PyNiOCeZEz/WwBpqGxo02llvo8=; b=ieR/JaJBIVRHrpiGEgNZ48SXqJPxT5hGmuRa/D6H93fhv6nE0HdtBk9fJwJcguqlRc 48JrtQU/RcNMG+L1NNodRUGZmctlNElBGcS0RT5JY08dpziXfV53WhzKnVcXinZNF5X3 5Uk6zgSzSKGRZyW0A9d7G+quD9W1dPM06alN5YbpZfstJIpcDAmmQ2u8gY+VxWBrfw9U e8Dv+p8qUajO1pWU7MZMPR1+1w0D6IHzjz5FAU5n599WDOVVxjcC9cfefNr1Z2cUyMGF rgIR6/wiLa0cemD/bsN9kRSZT0GDGtpi7HVNMKyWXH0x680dSNwMglgilJN9U6ndc31Y eNhg== X-Gm-Message-State: AOJu0YxjLS9LtKfasReKeWDfpg1IVvVCRdbl3bY6pKqDCOwcORDS3eLl CagwXdrreMM1plU8lpyJzkSYeC8C9SFqQVwj1agGOw== X-Google-Smtp-Source: AGHT+IFavFCVPs4D5iivBChGBrRwCB4QDAP9NU3jss8A+skDTLgAGkyU6fGRQaynxyEOzyD1U0N4Mw== X-Received: by 2002:a17:907:2dab:b0:9b9:b12c:133d with SMTP id gt43-20020a1709072dab00b009b9b12c133dmr8966246ejc.53.1698141850584; Tue, 24 Oct 2023 03:04:10 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id v21-20020a170906489500b009b928eb8dd3sm7948706ejq.163.2023.10.24.03.04.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 03:04:10 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: stephen@networkplumber.org, dsahern@gmail.com, daniel.machon@microchip.com Subject: [patch iproute2-next v3 3/6] devlink: extend pr_out_nested_handle() to print object Date: Tue, 24 Oct 2023 12:04:00 +0200 Message-ID: <20231024100403.762862-4-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231024100403.762862-1-jiri@resnulli.us> References: <20231024100403.762862-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: dsahern@gmail.com From: Jiri Pirko For existing pr_out_nested_handle() user (line card), the output stays the same. For the new users, introduce __pr_out_nested_handle() to allow to print devlink instance as object allowing to carry attributes in it (like netns). Note that as __pr_out_handle_start() and pr_out_handle_end() are newly used, the function is moved below the definitions. Signed-off-by: Jiri Pirko --- v2->v3: - new patch --- devlink/devlink.c | 51 +++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/devlink/devlink.c b/devlink/devlink.c index c18a4a4fbc5a..f7325477f271 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -2747,25 +2747,6 @@ static bool should_arr_last_handle_end(struct dl *dl, const char *bus_name, !cmp_arr_last_handle(dl, bus_name, dev_name); } -static void pr_out_nested_handle(struct nlattr *nla_nested_dl) -{ - struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {}; - char buf[64]; - int err; - - err = mnl_attr_parse_nested(nla_nested_dl, attr_cb, tb); - if (err != MNL_CB_OK) - return; - - if (!tb[DEVLINK_ATTR_BUS_NAME] || - !tb[DEVLINK_ATTR_DEV_NAME]) - return; - - 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); -} - static void __pr_out_handle_start(struct dl *dl, struct nlattr **tb, bool content, bool array) { @@ -2861,6 +2842,38 @@ static void pr_out_selftests_handle_end(struct dl *dl) __pr_out_newline(); } +static void __pr_out_nested_handle(struct dl *dl, struct nlattr *nla_nested_dl, + bool is_object) +{ + struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {}; + int err; + + err = mnl_attr_parse_nested(nla_nested_dl, attr_cb, tb); + if (err != MNL_CB_OK) + return; + + if (!tb[DEVLINK_ATTR_BUS_NAME] || + !tb[DEVLINK_ATTR_DEV_NAME]) + return; + + if (!is_object) { + char buf[64]; + + 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); + return; + } + + __pr_out_handle_start(dl, tb, false, false); + pr_out_handle_end(dl); +} + +static void pr_out_nested_handle(struct nlattr *nla_nested_dl) +{ + __pr_out_nested_handle(NULL, nla_nested_dl, false); +} + static bool cmp_arr_last_port_handle(struct dl *dl, const char *bus_name, const char *dev_name, uint32_t port_index) { From patchwork Tue Oct 24 10:04:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13434171 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 84E0725116 for ; Tue, 24 Oct 2023 10:04:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b="RFG+xRoo" Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D650AEA for ; Tue, 24 Oct 2023 03:04:13 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-9adb9fa7200so893764966b.0 for ; Tue, 24 Oct 2023 03:04:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1698141852; x=1698746652; 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=FN5skjm3FQLBaaFGgLJ1QaTSvXrhhqX4sfb8M9dwKFc=; b=RFG+xRooNBD7XkyOthAGIcJcXgJt/23Qd6SmQ+MlqYO8+rxksfbNr6hYYVuzXsyyzU 77mfxyS4lUmByxZSmxD8XNN4feR+AGpuIBo4p2wPrDnGw9vsh6AChE0gxtfG99pxhaUQ ZUiqChSdDf7vnyzRT2M8LbgybpL2sA2N2HDCkK3qx/dBX9VD4nIrCaWe3FIIz4uhsYAk EdBdZECnOFbjBuHr+qkAY8iJvpWdqW8PXQnVph745qDdfSiYRvGPoOT8PsMPNH2gGCQR 9B0pGmWuysq05a3p5y6DgCggrtUllYzh2ao2p4v0ujn6QQcnf6xVhK4N8Swz5eTHZJiX +eSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698141852; x=1698746652; 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=FN5skjm3FQLBaaFGgLJ1QaTSvXrhhqX4sfb8M9dwKFc=; b=p2o2PfxEuFYFF46A4rikOZl8sglo5IQDX/ODwDWKQfTOXrRU21Nb9+f6UeTJZLr2tm aTPIml3fucjEUeXPtx3E2H72rYQMFzHZ53vdlPd+FTM8c+6g25zFuAtgdqKMBoMAktlc soniU48z0FiGzDdxXujmowKEHbDfhq8od/R2JBHp9WQ1y8FfLkUGWdAyZb7iHY/EP8xB UxSf0T+rygRDEbjfLEaQQwrNgROWOwh2vUOyIKhMLXySfJOuK56qjIRK/gBrdeXHDweG YPq5OMOAnItdaYjw4CqcaAhosM3XSA3MKAroMvju0kr97xk0fy5cEoiRmtPGN5N5kk00 Da4A== X-Gm-Message-State: AOJu0Yzw3Vf5Fz56fTqqKs+d1m6RNRTWNB8qw5AJttWGNLka3yuqCUhO PqDLmhOBpEe2prA6Qzabu4lz7z2kPlZa6SMv7tEYRw== X-Google-Smtp-Source: AGHT+IGoTH263BxDbZR4LHNSSHDXyXEGogvQ7nrS1UZGjXoTx9CCeLeDBQkE+DcdiNii3Its8adNrw== X-Received: by 2002:a17:907:728f:b0:9a5:7dec:fab9 with SMTP id dt15-20020a170907728f00b009a57decfab9mr13943879ejc.9.1698141852307; Tue, 24 Oct 2023 03:04:12 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id j12-20020a170906050c00b009c764341f74sm8022871eja.71.2023.10.24.03.04.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 03:04:11 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: stephen@networkplumber.org, dsahern@gmail.com, daniel.machon@microchip.com Subject: [patch iproute2-next v3 4/6] devlink: introduce support for netns id for nested handle Date: Tue, 24 Oct 2023 12:04:01 +0200 Message-ID: <20231024100403.762862-5-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231024100403.762862-1-jiri@resnulli.us> References: <20231024100403.762862-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- v2->v3: - moved netns_name_by_id() into lib/namespace.c - s/netns_name_by_id/netns_name_from_id/ - rebased on top of new patch "devlink: extend pr_out_nested_handle() to print object" v1->v2: - use previously introduced netns_netnsid_from_name() instead of code duplication for the same function. - s/nesns_name_by_id_func/netns_name_by_id_func/ --- devlink/devlink.c | 23 ++++++++++++++++++++++- include/namespace.h | 1 + lib/namespace.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/devlink/devlink.c b/devlink/devlink.c index f7325477f271..7ba2d0dcac72 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 @@ -2865,7 +2867,26 @@ static void __pr_out_nested_handle(struct dl *dl, struct nlattr *nla_nested_dl, return; } - __pr_out_handle_start(dl, tb, false, false); + __pr_out_handle_start(dl, tb, tb[DEVLINK_ATTR_NETNS_ID], false); + 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_from_id(id); + + if (name) { + print_string(PRINT_ANY, "netns", + " netns %s", name); + free(name); + } else { + print_int(PRINT_ANY, "netnsid", + " netnsid %d", id); + } + } else { + print_string(PRINT_FP, NULL, " netnsid %s", "unknown"); + print_int(PRINT_JSON, "netnsid", NULL, id); + } + } pr_out_handle_end(dl); } diff --git a/include/namespace.h b/include/namespace.h index e860a4b8ee5b..fbdfbc9a1c3b 100644 --- a/include/namespace.h +++ b/include/namespace.h @@ -61,5 +61,6 @@ struct netns_func { }; int netns_id_from_name(struct rtnl_handle *rtnl, const char *name); +char *netns_name_from_id(int32_t id); #endif /* __NAMESPACE_H__ */ diff --git a/lib/namespace.c b/lib/namespace.c index f03f4bbabceb..d3aeb9658e73 100644 --- a/lib/namespace.c +++ b/lib/namespace.c @@ -188,3 +188,37 @@ out: free(answer); return ret; } + +struct netns_name_from_id_ctx { + int32_t id; + char *name; + struct rtnl_handle *rth; +}; + +static int netns_name_from_id_func(char *nsname, void *arg) +{ + struct netns_name_from_id_ctx *ctx = arg; + int32_t ret; + + ret = netns_id_from_name(ctx->rth, nsname); + if (ret < 0 || ret != ctx->id) + return 0; + ctx->name = strdup(nsname); + return 1; +} + +char *netns_name_from_id(int32_t id) +{ + struct rtnl_handle rth; + struct netns_name_from_id_ctx ctx = { + .id = id, + .rth = &rth, + }; + + if (rtnl_open(&rth, 0) < 0) + return NULL; + netns_foreach(netns_name_from_id_func, &ctx); + rtnl_close(&rth); + + return ctx.name; +} From patchwork Tue Oct 24 10:04:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13434172 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 08EE426286 for ; Tue, 24 Oct 2023 10:04:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b="ZiLKlpUb" Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B8DBDC for ; Tue, 24 Oct 2023 03:04:15 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-9b96c3b4be4so622734766b.1 for ; Tue, 24 Oct 2023 03:04:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1698141854; x=1698746654; 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=81SBX46mZgSFAffJdzM0cdJyxil5JN/2dUrVLPqnkFY=; b=ZiLKlpUbLi+hovxx9oJX0PwVw8FX/IohJye4RIx9mx+pmvwStIsMdtK4LyYwqSu9d8 6OtB3eted9jUjgSTQkjGUBFgXk8A//DTUn3NIj4l60P69qbQoVWZQdfzxdASI1nTyU5p zLA9HY/Q1wOFybx0A5+fF6Jhite6KBSup4+E0HcD+agr+Ji42lUIYSS4nVSuBUZK+VnQ I/3c3dRtS4wMTZDB4WmjoDXoeUn/n4q0HrN4VP33c9cqrGiEdLXIWAiGjYTUqGvCYKff GOxlNT9C5TP+PfmXr7r5b3m5t6oMAuFhf6xAIXEj9Rbu6BQiKAaOw2t9nuZqb2L2hngc +D0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698141854; x=1698746654; 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=81SBX46mZgSFAffJdzM0cdJyxil5JN/2dUrVLPqnkFY=; b=P+IK7w6ZyGy1YTmIq4GqpVbd1vbJ4F/mO+rSZZOLWvW6NixUKtUWJRdeplEJEHGiFd EgYGz1R9/bSD6TYWONr1Pzp3IJXO1ysqmNlhkjlwsCLsdfUXKy5aNN3WF13NuRufZtrT 3ZgJugWjjJPdK3HlGaq7eWdxjAtKGgyhvpU65Pi6VCv2qa5yV8AcrNS3zs/79YPTUSJf K51iin73bCoSlauruPrp3q8yVnGW0LUdyzXPOUPXzY4WnmXdInWAlu4yjDvuDCxXTGIF qBgnaLvCWzHD4qeiyqe8h0pSsGPfrJahxcvaMHq4B07m/DQRByMq/YvaS5e862yg+wzb 4hhQ== X-Gm-Message-State: AOJu0Yxqqc2qYVg7i109UshAbVoaAcu8xWL8QNLDxn65YMjZ2L8GjsMt J1VtnmSSaq76rGaDS4oR6WwsABfZIfXBMJn04FjEaw== X-Google-Smtp-Source: AGHT+IF0sWV1p08fSU6+zDSEsz/vu0zhBPsv+SbMY818HYxWCFWz5VtQebnr5Db7RWbBKe0j0YFuRA== X-Received: by 2002:a17:907:84d:b0:9c5:1100:9b8c with SMTP id ww13-20020a170907084d00b009c511009b8cmr8739438ejb.56.1698141853978; Tue, 24 Oct 2023 03:04:13 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id t7-20020a1709066bc700b009b9f87b34b6sm7983398ejs.189.2023.10.24.03.04.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 03:04:13 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: stephen@networkplumber.org, dsahern@gmail.com, daniel.machon@microchip.com Subject: [patch iproute2-next v3 5/6] devlink: print nested handle for port function Date: Tue, 24 Oct 2023 12:04:02 +0200 Message-ID: <20231024100403.762862-6-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231024100403.762862-1-jiri@resnulli.us> References: <20231024100403.762862-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: dsahern@gmail.com From: Jiri Pirko If port function contains nested handle attribute, print it. Signed-off-by: Jiri Pirko --- v2->v3: - rebased on top of new patch "devlink: extend pr_out_nested_handle() to print object" --- devlink/devlink.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/devlink/devlink.c b/devlink/devlink.c index 7ba2d0dcac72..90e8872b07ef 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) @@ -2895,6 +2896,22 @@ static void pr_out_nested_handle(struct nlattr *nla_nested_dl) __pr_out_nested_handle(NULL, nla_nested_dl, false); } +static void pr_out_nested_handle_obj(struct dl *dl, + struct nlattr *nla_nested_dl, + bool obj_start, bool obj_end) +{ + if (obj_start) { + pr_out_object_start(dl, "nested_devlink"); + check_indent_newline(dl); + } + __pr_out_nested_handle(dl, nla_nested_dl, true); + if (obj_end) { + if (!dl->json_output) + __pr_out_indent_dec(); + pr_out_object_end(dl); + } +} + static bool cmp_arr_last_port_handle(struct dl *dl, const char *bus_name, const char *dev_name, uint32_t port_index) { @@ -4837,6 +4854,9 @@ static void pr_out_port_function(struct dl *dl, struct nlattr **tb_port) port_fn_caps->value & DEVLINK_PORT_FN_CAP_IPSEC_PACKET ? "enable" : "disable"); } + if (tb[DEVLINK_PORT_FN_ATTR_DEVLINK]) + pr_out_nested_handle_obj(dl, tb[DEVLINK_PORT_FN_ATTR_DEVLINK], + true, true); if (!dl->json_output) __pr_out_indent_dec(); From patchwork Tue Oct 24 10:04:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13434173 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 CFB9D26290 for ; Tue, 24 Oct 2023 10:04:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b="VSN4lK3Z" Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BD0CDA for ; Tue, 24 Oct 2023 03:04:17 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-9ba081173a3so675809366b.1 for ; Tue, 24 Oct 2023 03:04:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1698141856; x=1698746656; 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=cMD+/2AEbaBoagYEL4uOL6ECD86C589TD6FuI5XI2ZU=; b=VSN4lK3Zh/lGUwg+Laihtv2UNavXNPjmyGX8cBBGSs83uuxNvTrGMnPDZZ4Nnjsk7V k7FG+4nHbQu3bcm/o1kFDemld+Q00cfx1pfuvk4SusAKkVTOPGuJU6kVhq3fjChmGhA0 G3aci20EnDdUHuwwU1lRVPMfg+FQPq4jCLRPsXBcjPTuCUizQLyOH+1ZHFmRKWYaAeCs 5LZdXYvCcBukCPC6XP1wwHMm+GhCd9sRydeJ+0O+6Fqwo6yxBS7f2LCHViVtX1Fvvxqp 3RsQeC0lmBpQT7mlYCnTh24BEY4cYxiDi/eZ2yXy4W7aXUe7a1rolautADEIKUpjf6cp BYJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698141856; x=1698746656; 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=cMD+/2AEbaBoagYEL4uOL6ECD86C589TD6FuI5XI2ZU=; b=VfptDev8l7djh7+yged4TCtwkXkGTJInh1V1BdXtI+VQrjhLbJBe7e0VZz6WitVex2 cW5dRIaYduw6Bb0r4XmkV1KYGe+NPEZ64CyHkAt3X2ajbvlOAB7Lqyk89lbE+0ouyzCb umrUy2avkElRvZtUwB9l6i7oL9Lfs3gcFzhBH9tFWhzmWZS4snykuv4yYNSb5MKJyHQv M342iJY5OFhJY3jJVHwT/HSrNlBzoyeSfeiObG530vCPaVxP/AwVzwPUsnBZLqw0fVht izkDL8+kONP7hNY97/08UxUtm/1Sn8krGFdCu4N3F8e7QRyYTucOJ0IT5wE3oV6H5avz SJmw== X-Gm-Message-State: AOJu0YyKk4DYDtpbLVI5olqm6i+XCwkvjHDQfjAQ/veZU4A583CaEhyz t97X90mgaMP5C7+kTjfrV5POTegyCzhNdEj+qt2Jow== X-Google-Smtp-Source: AGHT+IHhDamTEZ7+DnZOw1o/Unb9eed63LjrWeIaCu1s6zyufwCnw5QZ94MJ067QZtCpUcbgmXBeVw== X-Received: by 2002:a17:907:3d9f:b0:9b2:b152:b0f2 with SMTP id he31-20020a1709073d9f00b009b2b152b0f2mr8672380ejc.10.1698141855777; Tue, 24 Oct 2023 03:04:15 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id lt13-20020a170906fa8d00b009c4cb1553edsm8033791ejb.95.2023.10.24.03.04.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 03:04:15 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: stephen@networkplumber.org, dsahern@gmail.com, daniel.machon@microchip.com Subject: [patch iproute2-next v3 6/6] devlink: print nested devlink handle for devlink dev Date: Tue, 24 Oct 2023 12:04:03 +0200 Message-ID: <20231024100403.762862-7-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231024100403.762862-1-jiri@resnulli.us> References: <20231024100403.762862-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: dsahern@gmail.com From: Jiri Pirko Devlink dev may contain one or more nested devlink instances. Print them using previously introduced pr_out_nested_handle_obj() helper. Signed-off-by: Jiri Pirko --- v2->v3: - rebased on top of new patch "devlink: extend pr_out_nested_handle() to print object" and previous patch to use pr_out_nested_handle_obj() --- devlink/devlink.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/devlink/devlink.c b/devlink/devlink.c index 90e8872b07ef..09ac347051f4 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -3858,13 +3858,35 @@ 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) +{ + int i = 0, count = 0; + struct nlattr *attr; + + mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) { + if (mnl_attr_get_type(attr) == DEVLINK_ATTR_NESTED_DEVLINK) + count++; + } + if (!count) + return; + + mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) { + if (mnl_attr_get_type(attr) != DEVLINK_ATTR_NESTED_DEVLINK) + continue; + pr_out_nested_handle_obj(dl, attr, i == 0, i == count - 1); + i++; + } +} -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); @@ -3881,7 +3903,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; } @@ -6808,7 +6830,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 */