]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
devlink: introduce cmdline option to switch to a different namespace
authorJiri Pirko <jiri@mellanox.com>
Thu, 3 Oct 2019 09:51:14 +0000 (11:51 +0200)
committerDavid Ahern <dsahern@kernel.org>
Mon, 7 Oct 2019 21:59:50 +0000 (21:59 +0000)
Similar to ip tool, add an option to devlink to operate under certain
network namespace. Unfortunately, "-n" is already taken, so use "-N"
instead.

Example:

$ devlink -N testns1 dev show

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
devlink/devlink.c
man/man8/devlink.8

index 5e762e37540cace4080b97cdcaa5348de35e2e3f..852e2257cb64deabc074f75bb6cc673675ab73de 100644 (file)
@@ -32,6 +32,7 @@
 #include "mnlg.h"
 #include "json_writer.h"
 #include "utils.h"
+#include "namespace.h"
 
 #define ESWITCH_MODE_LEGACY "legacy"
 #define ESWITCH_MODE_SWITCHDEV "switchdev"
@@ -7023,7 +7024,7 @@ static int cmd_trap(struct dl *dl)
 static void help(void)
 {
        pr_err("Usage: devlink [ OPTIONS ] OBJECT { COMMAND | help }\n"
-              "       devlink [ -f[orce] ] -b[atch] filename\n"
+              "       devlink [ -f[orce] ] -b[atch] filename -N[etns] netnsname\n"
               "where  OBJECT := { dev | port | sb | monitor | dpipe | resource | region | health | trap }\n"
               "       OPTIONS := { -V[ersion] | -n[o-nice-names] | -j[son] | -p[retty] | -v[erbose] -s[tatistics] }\n");
 }
@@ -7173,6 +7174,7 @@ int main(int argc, char **argv)
                { "pretty",             no_argument,            NULL, 'p' },
                { "verbose",            no_argument,            NULL, 'v' },
                { "statistics",         no_argument,            NULL, 's' },
+               { "Netns",              required_argument,      NULL, 'N' },
                { NULL, 0, NULL, 0 }
        };
        const char *batch_file = NULL;
@@ -7188,7 +7190,7 @@ int main(int argc, char **argv)
                return EXIT_FAILURE;
        }
 
-       while ((opt = getopt_long(argc, argv, "Vfb:njpvs",
+       while ((opt = getopt_long(argc, argv, "Vfb:njpvsN:",
                                  long_options, NULL)) >= 0) {
 
                switch (opt) {
@@ -7217,6 +7219,12 @@ int main(int argc, char **argv)
                case 's':
                        dl->stats = true;
                        break;
+               case 'N':
+                       if (netns_switch(optarg)) {
+                               ret = EXIT_FAILURE;
+                               goto dl_free;
+                       }
+                       break;
                default:
                        pr_err("Unknown option.\n");
                        help();
index 12d489440a3d68712c36e4aaa29985b777a9eddb..7f4eda56808125c12c48026d5be340a9bc35ba88 100644 (file)
@@ -55,6 +55,10 @@ Turn on verbose output.
 .BR "\-s" , " --statistics"
 Output statistics.
 
+.TP
+.BR "\-N", " \-Netns " <NETNSNAME>
+Switches to the specified network namespace.
+
 .SS
 .I OBJECT