From patchwork Tue Sep 19 11:56:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13391276 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 811CD4684 for ; Tue, 19 Sep 2023 11:56:52 +0000 (UTC) Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07F4AF2 for ; Tue, 19 Sep 2023 04:56:51 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-401d80f4ef8so61429095e9.1 for ; Tue, 19 Sep 2023 04:56:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1695124609; x=1695729409; 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=tgBpvOAT/yGrTizC+Br7B1vSxPFnsOgNxrtOraG+AFmRWQZjACRZnadFnk6Qca14i5 ErWQQrl/N9kh2tQ5As3lSTHvP96WDGwHAErqg3bCjioiqohy7hqT8p5QFx/vT5gEEF0s wPxHPmIUiG3wJjZoMS7rK34L0cx9/8EUe/qrkSjHDWmjvGbLerLcGTC8EwU8YlHosE5p PaSwKT2Jv/0rSRK8hwx9sf7kZQJs8nd4DWlSWvhUR+j30xNXgG2UNHt4m8uOlP5TXplj z4feX+xu7Ax6B3ChQa9ZDvY+pwKPtmEYKFWLDtho1Ig2KD0EgAqWjYxRxlWupsG4SwUV sUAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695124609; x=1695729409; 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=jLr4sy5cB1YVVTzIa14+NDZ4dLTg0uoyg7+GlAZO+//EDZZ/Ac0Jeekkzsi4FRwZ6j FrPegwDCbnH9//Lehfyj8XfbEPUGz0sutZom8wYXbYQ5EyQzmOlb5OaH0+OeX9f76MUE hB0yz5d6IHnmJ1hd7XVlTAekLeYdD8yZow9CqdWdLmprGCo8ktPlVwmjC9/izncH60q7 52cgl32FGI3YfffKmL/5bQ4iX3C57COHIaCmxZ59hHXxrDqUDOKhiwnN3DPUVjgRnfbT ObQ5GbNqBkOb2ToM9dNUnFAXD9v4GGW2GfzdT6xQIRo1DDh5NQlNBzmhc0TfQfxjXkT1 Jt5A== X-Gm-Message-State: AOJu0YwgdVj9UmhNhffRJcxCB+xkZf6kJJtFcXBw4OuEZELrYhJSSttm hDWaUfBp2MnXi7ERaPePWO7IGhNmICrekk/mFgM= X-Google-Smtp-Source: AGHT+IERuXkKzqWlNabyKXx9B/ctZ6jonv0eP33OXRWP1UQZWSMs5DUjyzJeJSl1NMxfQOyU48j9gQ== X-Received: by 2002:a7b:c3d0:0:b0:3fb:a506:5656 with SMTP id t16-20020a7bc3d0000000b003fba5065656mr9314254wmj.32.1695124609452; Tue, 19 Sep 2023 04:56:49 -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 u17-20020a05600c00d100b003fe0a0e03fcsm17923654wmm.12.2023.09.19.04.56.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 04:56:48 -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 v2 1/5] devlink: update headers Date: Tue, 19 Sep 2023 13:56:40 +0200 Message-ID: <20230919115644.1157890-2-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230919115644.1157890-1-jiri@resnulli.us> References: <20230919115644.1157890-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 Tue Sep 19 11:56:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13391277 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 A8A054684 for ; Tue, 19 Sep 2023 11:56:54 +0000 (UTC) Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48BA4F4 for ; Tue, 19 Sep 2023 04:56:53 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-403012f27e1so59766855e9.1 for ; Tue, 19 Sep 2023 04:56:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1695124611; x=1695729411; 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=4v1bi9Ax+r3HNBGakQouTlqyU8diAgcvaJU2xPHBrys=; b=D0sAeEMB2uZ8CkSHeb+RQ5KaDf32w8V3IfcBlLzvJye9Nu7VQf5omcLDe+n9YI5iDF Y9EOC6MQyRZacs0qPILbXZR98/QADo8x6uNGEu53pNxf5UM5ISyyqLcbPbe+Tgm9Hqzj 5DDVLaPq8fO2bqYnlfZb60LvjZvRKgSAUGadUnbyGnmg3Z4spH4uxcTfLzBpmeggrZu5 TxcNVu7qvRdT14XG3sW+eFZZImVDjDzLR9Dd9vyQEU+rGQgtGD+BuLtSyNEoSVxa0vEv 2XbyHBH08IY45wS7rQ1Xc5CY7GvE6FCXW9AmCRyjgDppOEWEuo+lTiMSI5KJ4lPLYada cwXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695124611; x=1695729411; 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=4v1bi9Ax+r3HNBGakQouTlqyU8diAgcvaJU2xPHBrys=; b=u/BBqtDNTipmOqIBw/OITLWo0UvuT7MAMkTQkUQ1rbHK54CMnK6Pa+lZ4zfPU9S6in ocw2ZfuNRVXjbqLvFezTsC6rdwWOiu5x62Svpid2UExhvSsaFA+XcZDKArN8YjZXiTx+ cncqu/X7e/5tKTeqiJJRfIrjR+Gc54TX8IAcXEtmxG2aIMO3gkGm5iA77/MTXsmvpu8G R03dv9ux/rcgeTQUb3FtX4G4l0Uv0VPuoh8x0P9gtJ+jSksFACjj9tM+m1/DMNhrUlg7 myHyY2P+Zel9fL7VC/kZqxW5Gif0FegEt7FiqCikUExLkXrZR+WD+4rC+43e3RDVuEPP KwJQ== X-Gm-Message-State: AOJu0YzjIDPOlp7ulV2Il/BwXJPIDhsMkWVqVQcn0xRFzV/KAJWylq64 QZBuPjOLD6X2tNgGw6rIgeUFTiA9owQIeQUYtY4= X-Google-Smtp-Source: AGHT+IEYmjqjEVm+Zw0g7BP199crX+SZ5vzrQ1bwoA1PCK7/ywj2SzWi1feE6akDq7eJ9UGPc1+7CQ== X-Received: by 2002:a05:600c:2194:b0:3fe:f45:772d with SMTP id e20-20020a05600c219400b003fe0f45772dmr9112775wme.28.1695124611721; Tue, 19 Sep 2023 04:56:51 -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 g8-20020a7bc4c8000000b003ff013a4fd9sm14978718wmk.7.2023.09.19.04.56.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 04:56:50 -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 v2 2/5] ip/ipnetns: move internals of get_netnsid_from_name() into namespace.c Date: Tue, 19 Sep 2023 13:56:41 +0200 Message-ID: <20230919115644.1157890-3-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230919115644.1157890-1-jiri@resnulli.us> References: <20230919115644.1157890-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 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_netnsid_from_name(). Signed-off-by: Jiri Pirko --- 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..f564a574d200 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_netnsid_from_name(struct rtnl_handle *rtnl, const char *name); + #endif /* __NAMESPACE_H__ */ diff --git a/ip/ipnetns.c b/ip/ipnetns.c index 9d996832aef8..642873432a4b 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_netnsid_from_name(&rtnsh, name); } struct nsid_cache { diff --git a/lib/namespace.c b/lib/namespace.c index 1202fa85f97d..39981d835aa5 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_netnsid_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 Sep 19 11:56:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13391278 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 1FE5B4684 for ; Tue, 19 Sep 2023 11:56:57 +0000 (UTC) Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78151E3 for ; Tue, 19 Sep 2023 04:56:55 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-402cc6b8bedso63413645e9.1 for ; Tue, 19 Sep 2023 04:56:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1695124614; x=1695729414; 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=GINydlvgKxtCz7GPVUksnC/Rw9cajTwwmUDJjZKOa1w=; b=UttJQnsxwbparp8/FjEgkCF5aeUuoW93GpzGYg6eH6H2MjF1n3en387T4b8k+y5GDa roUAcdfb7Q+OeDn+kFOhAdkfXVPaqYyurQszCiqhTibf9UThpa0/FK60wzJZPfteDnXh 4W3VnzDreNBL7FBzc0j9Q04HMYG30N30CC98uSQaSxgcIZM4e4T1zArQbINmgTiotaOE KcrJl190F75s7JcX2xedZocuFdK9xD9v4dtoTrAt0YRgCtwkYWCuLAv2MW11MSJtuBS8 4MIncUNqVugy6YAABhGOxQMnbMMnJaJFKG+Gh6FzMLwi6L5KfHHi0kJI2yKk9fAo3EAs 0SeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695124614; x=1695729414; 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=GINydlvgKxtCz7GPVUksnC/Rw9cajTwwmUDJjZKOa1w=; b=wC5CczWVjRXUHpqTmmJBfyrAPh/9BVSZKBFg4z6uwyZxth+HPrUAEgwwCYxQ8rAyJ7 FZoG0zLDTL48jKKa0b9OePZ8dZbw00GpPpnWfjca8F/XnPqYwag5kD74WiML83SpvcGC JmzcabvwgSEyu6LxCCxlhLtgaCqNuUp6GFs+EaoJ1VOpuFZ5d8WvHc9blfizjVqpu4UZ plHE//1dXJSPDpGM8GYh6a0FLznciBnPawg2NBIyD9QWF9EbO8q3tO7/6KdOZ0MNe1UO FE3/ZSI/QGnORPkj7cAdhv7inIVqZcllsa4fTHX6w/MVRz71Hf3V5wKqtDIgGmcqboq+ 6R8w== X-Gm-Message-State: AOJu0Yzy668xMhM5K8LSY3ki4Z0xIPmbSgfISZebofrm9BILKmEF4Y9x p1yzHD+kUdb8bRRnmdaQHTDKKPwDnmWbNuIuQVg= X-Google-Smtp-Source: AGHT+IEH+fsE9Vh/4YUzGD6NtFhwfSFaSY7nxTIBcshnhGywjTvyw7QEBHNxbM8+Ocq0QDNj+2jHqA== X-Received: by 2002:adf:f3c6:0:b0:31f:e980:df87 with SMTP id g6-20020adff3c6000000b0031fe980df87mr9765890wrp.38.1695124614000; Tue, 19 Sep 2023 04:56:54 -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 v3-20020adff683000000b0031980294e9fsm3346564wrp.116.2023.09.19.04.56.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 04:56:53 -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 v2 3/5] devlink: introduce support for netns id for nested handle Date: Tue, 19 Sep 2023 13:56:42 +0200 Message-ID: <20230919115644.1157890-4-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230919115644.1157890-1-jiri@resnulli.us> References: <20230919115644.1157890-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 --- 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 | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/devlink/devlink.c b/devlink/devlink.c index d1795f616ca0..cf5d466bfc9d 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,40 @@ static bool should_arr_last_handle_end(struct dl *dl, const char *bus_name, !cmp_arr_last_handle(dl, bus_name, dev_name); } +struct netns_name_by_id_ctx { + int32_t id; + char *name; + struct rtnl_handle *rth; +}; + +static int netns_name_by_id_func(char *nsname, void *arg) +{ + struct netns_name_by_id_ctx *ctx = arg; + int32_t ret; + + ret = netns_netnsid_from_name(ctx->rth, 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 rtnl_handle rth; + struct netns_name_by_id_ctx ctx = { + .id = id, + .rth = &rth, + }; + + if (rtnl_open(&rth, 0) < 0) + return NULL; + netns_foreach(netns_name_by_id_func, &ctx); + rtnl_close(&rth); + + return ctx.name; +} + static void pr_out_nested_handle(struct nlattr *nla_nested_dl) { struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {}; @@ -2740,6 +2776,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 Tue Sep 19 11:56:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13391279 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 BDE8A15BE for ; Tue, 19 Sep 2023 11:56:58 +0000 (UTC) Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E08EF3 for ; Tue, 19 Sep 2023 04:56:57 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-401b393ddd2so63075865e9.0 for ; Tue, 19 Sep 2023 04:56:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1695124616; x=1695729416; 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=4hHBZOs2rf1I/VMlyQcfPqiLybJTaYIhu/DVUyX2Ryg=; b=atzk5gQ4AjYrp00gyt24xAKa8PwShm7wgah8eOxBujL438EFbXxYV0VghEM+igGffU RiDyEh6QYbC12NsBdl2eNtHSJCEqLXWbwzEjhBHX6i9ZQtYdGonxRj+GfhTjzJdRZxjc 3C1kB6RN2BE0PmkKcxpFjxx8cXgIKYV2nKQOXwh0LRZAyEdMvmClJ4GMGP1nZZckgqEd bERD48sXdnrvL0ZO4B84wlDcK/GiRsBO/eSUfBm2nGv0vFsiZUToUm79f3I2DMPdNXK1 v909lXDy4HoHgHhB9sOBECzeHileIYJijDerarWl/nKn66QsSGA83T2vIuEO900NDo+n FlFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695124616; x=1695729416; 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=4hHBZOs2rf1I/VMlyQcfPqiLybJTaYIhu/DVUyX2Ryg=; b=n1yMp6pgT6lnSX/tLJ2lR0RCQJwDKdRl3YRKFP5Fab9g7WB5w+XyaEIqk5wi86bBMJ d2ceq3keObSUaLmf+Vv/QPc7Tr925B+kUYQHJAyMhBIG1qhGqpeHu+w6e1T9bKBQWufB cXsBzYDbM8xOhDQCrjELTrbfRbz8VKjaNkwnrLsPgOQAuOo4ICD5fgf/2bH5JbZT28d+ fuE0V0XvueYdfvcEf8UFKSZMizxbRDMZaNWEz8O2gBNQmNBK8/CGLl6FGB6Vo9h0CqoL v+qMvVfL7WYBmcCli2kWARQGCPzPlJlVLjxdIKppqesmXZ8+lbX9/uk7038XtgoMnJYt YHQQ== X-Gm-Message-State: AOJu0YzxZ6Tt4+yoNuXzExDgdiTt9G5+NzE71iyyTKkSj8oVfmrm6osR wb0bBUGHfUbG9+XJi8pP3ACQigIFcGdV1jhYo1I= X-Google-Smtp-Source: AGHT+IEVZ+kXQOgV7hpXTpISZp+PVU4vCGR2hMmYiFnP15akH53v5zbSS/KIJoWVUmOrwlkkhgXmFg== X-Received: by 2002:a05:600c:3b97:b0:405:1c14:9227 with SMTP id n23-20020a05600c3b9700b004051c149227mr807279wms.33.1695124616119; Tue, 19 Sep 2023 04:56:56 -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-20020a1c7707000000b003fedcd02e2asm15100502wmi.35.2023.09.19.04.56.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 04:56:55 -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 v2 4/5] devlink: print nested handle for port function Date: Tue, 19 Sep 2023 13:56:43 +0200 Message-ID: <20230919115644.1157890-5-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230919115644.1157890-1-jiri@resnulli.us> References: <20230919115644.1157890-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 cf5d466bfc9d..b30e4fd8e282 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) @@ -4830,6 +4831,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 Tue Sep 19 11:56:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13391280 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 36BBC15BE for ; Tue, 19 Sep 2023 11:57:01 +0000 (UTC) Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B082FF4 for ; Tue, 19 Sep 2023 04:56:59 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-403012f27e3so63296055e9.3 for ; Tue, 19 Sep 2023 04:56:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1695124618; x=1695729418; 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=WY/dd8qXYtYbD0sLTcojKvwEIrcDT96hMholuoW3bIg=; b=ClHA9ALD1KgmKPFjzdPmG7gXJ2KxZSmGJBMNOIeeKR5wxl3sBfpmHN0JSFA3Qgyprj oxg2DZNw8hINuRQScXw8kr7kYpMpX64a2o4hHTTXjSgIwUna4nrENf0HP4SRiFvRkf64 VdM0VML5HAnC8vMTCsfH9VH4U1pA6FsTVFRVV+DxJE2tfvVeGXF5TSoSaiTxC7vrdcMH 19g8EvSCgCfIsCh1vr0d1gnRbP3MbpW65LLhIqD5LDo8xu8MfdbNd25zjh/Cj+/2HuAI jbHfz3AfvtHmirHIMV5DoPRkEq8PfJjP3IFiVJwSwr7wKnY3hXi22ET/T6ayPQW+KpoP OG+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695124618; x=1695729418; 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=WY/dd8qXYtYbD0sLTcojKvwEIrcDT96hMholuoW3bIg=; b=pQmLrVlJBl20kRAbiXsg5ttvP3sYQsIBQbqr5ogBfpWnoxNj8dNsuXi333eJxJuTS7 /gqn7KOEo6vxY4YUNRmHUMC5Tdl0JJNyB786nmVVE2dxNc1zaHF2xZ5E5mkILgppLftT YYmuUD/OwqL9tVHCKW6pkSfGMJjW3Pv8f+u6SQJoLSpDJm1q17tujKIhX4R+9cCA9/p6 JaYXZbJaywuQbUDmnab/N1kW6eF1VZRGhf2hfzwJY7ZIk1vOYcghYAVk75HV11EhD//v JIf4d7tVAvkjL1L9QBQ/6BSnFWYmQLN64N7PeHsg+gx8HUGLLJZe/Lhypp51r+hpx19L R1Fw== X-Gm-Message-State: AOJu0YwK189U6ApyCDRfFDYibv2hbglqRlhk+4f9hVtworuloPXWgCeg 9QMxTSBI4tVxv3VE+1VGexh6/kgMci7HdNzJrtM= X-Google-Smtp-Source: AGHT+IHda+rhFfeLOHgxr3h78IktT/bw8hZ2J0jw4f8WCe0Nsv5FKVlQb0Xi//ZZN75qByTSY+Av9A== X-Received: by 2002:a7b:c4cc:0:b0:401:aa8f:7570 with SMTP id g12-20020a7bc4cc000000b00401aa8f7570mr10875626wmk.1.1695124618222; Tue, 19 Sep 2023 04:56:58 -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 s24-20020a7bc398000000b003feee8d8011sm18125856wmj.41.2023.09.19.04.56.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 04:56:57 -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 v2 5/5] devlink: print nested devlink handle for devlink dev Date: Tue, 19 Sep 2023 13:56:44 +0200 Message-ID: <20230919115644.1157890-6-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230919115644.1157890-1-jiri@resnulli.us> References: <20230919115644.1157890-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 b30e4fd8e282..06c1fbaa2404 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -3844,13 +3844,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); @@ -3867,7 +3904,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; } @@ -6783,7 +6820,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 */