]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - devlink/devlink.c
devlink: extend reload command to add support for network namespace change
[mirror_iproute2.git] / devlink / devlink.c
index 2f084c02076589e9de66edc8dcb44b3021afed6d..a0cd6a47d26fa09f5c7995343b82fad0c472b0fd 100644 (file)
 #include <linux/devlink.h>
 #include <libmnl/libmnl.h>
 #include <netinet/ether.h>
+#include <sys/types.h>
 
 #include "SNAPSHOT.h"
 #include "list.h"
 #include "mnlg.h"
 #include "json_writer.h"
 #include "utils.h"
+#include "namespace.h"
 
 #define ESWITCH_MODE_LEGACY "legacy"
 #define ESWITCH_MODE_SWITCHDEV "switchdev"
@@ -96,6 +98,18 @@ pr_out_sp(unsigned int num, const char *fmt, ...)
        g_new_line_count = 0;                   \
 }
 
+static void __attribute__((format(printf, 1, 2)))
+pr_out_tty(const char *fmt, ...)
+{
+       va_list ap;
+
+       if (!isatty(STDOUT_FILENO))
+               return;
+       va_start(ap, fmt);
+       vprintf(fmt, ap);
+       va_end(ap);
+}
+
 static void __pr_out_indent_inc(void)
 {
        if (g_indent_level + INDENT_STR_STEP > INDENT_STR_MAXLEN)
@@ -135,9 +149,8 @@ static int _mnlg_socket_recv_run(struct mnlg_socket *nlg,
        return 0;
 }
 
-static int _mnlg_socket_sndrcv(struct mnlg_socket *nlg,
-                              const struct nlmsghdr *nlh,
-                              mnl_cb_t data_cb, void *data)
+static int _mnlg_socket_send(struct mnlg_socket *nlg,
+                            const struct nlmsghdr *nlh)
 {
        int err;
 
@@ -146,6 +159,18 @@ static int _mnlg_socket_sndrcv(struct mnlg_socket *nlg,
                pr_err("Failed to call mnlg_socket_send\n");
                return -errno;
        }
+       return 0;
+}
+
+static int _mnlg_socket_sndrcv(struct mnlg_socket *nlg,
+                              const struct nlmsghdr *nlh,
+                              mnl_cb_t data_cb, void *data)
+{
+       int err;
+
+       err = _mnlg_socket_send(nlg, nlh);
+       if (err)
+               return err;
        return _mnlg_socket_recv_run(nlg, data_cb, data);
 }
 
@@ -231,11 +256,12 @@ static void ifname_map_free(struct ifname_map *ifname_map)
 #define DL_OPT_FLASH_FILE_NAME BIT(25)
 #define DL_OPT_FLASH_COMPONENT BIT(26)
 #define DL_OPT_HEALTH_REPORTER_NAME    BIT(27)
-#define DL_OPT_HEALTH_REPORTER_GRACEFUL_PERIOD BIT(27)
-#define DL_OPT_HEALTH_REPORTER_AUTO_RECOVER    BIT(28)
-#define DL_OPT_TRAP_NAME               BIT(29)
-#define DL_OPT_TRAP_ACTION             BIT(30)
-#define DL_OPT_TRAP_GROUP_NAME         BIT(31)
+#define DL_OPT_HEALTH_REPORTER_GRACEFUL_PERIOD BIT(28)
+#define DL_OPT_HEALTH_REPORTER_AUTO_RECOVER    BIT(29)
+#define DL_OPT_TRAP_NAME               BIT(30)
+#define DL_OPT_TRAP_ACTION             BIT(31)
+#define DL_OPT_TRAP_GROUP_NAME         BIT(32)
+#define DL_OPT_NETNS   BIT(33)
 
 struct dl_opts {
        uint64_t present; /* flags of present items */
@@ -275,6 +301,8 @@ struct dl_opts {
        const char *trap_name;
        const char *trap_group_name;
        enum devlink_trap_action trap_action;
+       bool netns_is_pid;
+       uint32_t netns;
 };
 
 struct dl {
@@ -443,6 +471,10 @@ static const enum mnl_attr_data_type devlink_policy[DEVLINK_ATTR_MAX + 1] = {
        [DEVLINK_ATTR_HEALTH_REPORTER_RECOVER_COUNT] = MNL_TYPE_U64,
        [DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS] = MNL_TYPE_U64,
        [DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD] = MNL_TYPE_U64,
+       [DEVLINK_ATTR_FLASH_UPDATE_COMPONENT] = MNL_TYPE_STRING,
+       [DEVLINK_ATTR_FLASH_UPDATE_STATUS_MSG] = MNL_TYPE_STRING,
+       [DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE] = MNL_TYPE_U64,
+       [DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL] = MNL_TYPE_U64,
        [DEVLINK_ATTR_STATS] = MNL_TYPE_NESTED,
        [DEVLINK_ATTR_TRAP_NAME] = MNL_TYPE_STRING,
        [DEVLINK_ATTR_TRAP_ACTION] = MNL_TYPE_U8,
@@ -450,6 +482,7 @@ static const enum mnl_attr_data_type devlink_policy[DEVLINK_ATTR_MAX + 1] = {
        [DEVLINK_ATTR_TRAP_GENERIC] = MNL_TYPE_FLAG,
        [DEVLINK_ATTR_TRAP_METADATA] = MNL_TYPE_NESTED,
        [DEVLINK_ATTR_TRAP_GROUP_NAME] = MNL_TYPE_STRING,
+       [DEVLINK_ATTR_RELOAD_FAILED] = MNL_TYPE_U8,
 };
 
 static const enum mnl_attr_data_type
@@ -1410,6 +1443,22 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,
                        if (err)
                                return err;
                        o_found |= DL_OPT_TRAP_ACTION;
+               } else if (dl_argv_match(dl, "netns") &&
+                       (o_all & DL_OPT_NETNS)) {
+                       const char *netns_str;
+
+                       dl_arg_inc(dl);
+                       err = dl_argv_str(dl, &netns_str);
+                       if (err)
+                               return err;
+                       opts->netns = netns_get_fd(netns_str);
+                       if (opts->netns < 0) {
+                               err = dl_argv_uint32_t(dl, &opts->netns);
+                               if (err)
+                                       return err;
+                               opts->netns_is_pid = true;
+                       }
+                       o_found |= DL_OPT_NETNS;
                } else {
                        pr_err("Unknown option \"%s\"\n", dl_argv(dl));
                        return -EINVAL;
@@ -1532,7 +1581,11 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
        if (opts->present & DL_OPT_TRAP_ACTION)
                mnl_attr_put_u8(nlh, DEVLINK_ATTR_TRAP_ACTION,
                                opts->trap_action);
-
+       if (opts->present & DL_OPT_NETNS)
+               mnl_attr_put_u32(nlh,
+                                opts->netns_is_pid ? DEVLINK_ATTR_NETNS_PID :
+                                                     DEVLINK_ATTR_NETNS_FD,
+                                opts->netns);
 }
 
 static int dl_argv_parse_put(struct nlmsghdr *nlh, struct dl *dl,
@@ -1593,7 +1646,7 @@ static void cmd_dev_help(void)
        pr_err("       devlink dev eswitch show DEV\n");
        pr_err("       devlink dev param set DEV name PARAMETER value VALUE cmode { permanent | driverinit | runtime }\n");
        pr_err("       devlink dev param show [DEV name PARAMETER]\n");
-       pr_err("       devlink dev reload DEV\n");
+       pr_err("       devlink dev reload DEV [ netns { PID | NAME | ID } ]\n");
        pr_err("       devlink dev info [ DEV ]\n");
        pr_err("       devlink dev flash DEV file PATH [ component NAME ]\n");
 }
@@ -1949,11 +2002,6 @@ static void pr_out_region_chunk(struct dl *dl, uint8_t *data, uint32_t len,
        pr_out_region_chunk_end(dl);
 }
 
-static void pr_out_dev(struct dl *dl, struct nlattr **tb)
-{
-       pr_out_handle(dl, tb);
-}
-
 static void pr_out_section_start(struct dl *dl, const char *name)
 {
        if (dl->json_output) {
@@ -2253,6 +2301,31 @@ static const struct param_val_conv param_val_conv[] = {
                .vstr = "flash",
                .vuint = DEVLINK_PARAM_FW_LOAD_POLICY_VALUE_FLASH,
        },
+       {
+               .name = "reset_dev_on_drv_probe",
+               .vstr = "unknown",
+               .vuint = DEVLINK_PARAM_RESET_DEV_ON_DRV_PROBE_VALUE_UNKNOWN,
+       },
+       {
+               .name = "fw_load_policy",
+               .vstr = "unknown",
+               .vuint = DEVLINK_PARAM_FW_LOAD_POLICY_VALUE_UNKNOWN,
+       },
+       {
+               .name = "reset_dev_on_drv_probe",
+               .vstr = "always",
+               .vuint = DEVLINK_PARAM_RESET_DEV_ON_DRV_PROBE_VALUE_ALWAYS,
+       },
+       {
+               .name = "reset_dev_on_drv_probe",
+               .vstr = "never",
+               .vuint = DEVLINK_PARAM_RESET_DEV_ON_DRV_PROBE_VALUE_NEVER,
+       },
+       {
+               .name = "reset_dev_on_drv_probe",
+               .vstr = "disk",
+               .vuint = DEVLINK_PARAM_RESET_DEV_ON_DRV_PROBE_VALUE_DISK,
+       },
 };
 
 #define PARAM_VAL_CONV_LEN ARRAY_SIZE(param_val_conv)
@@ -2629,11 +2702,23 @@ static int cmd_dev_show_cb(const struct nlmsghdr *nlh, void *data)
        struct dl *dl = data;
        struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
        struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
+       uint8_t reload_failed = 0;
 
        mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
        if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME])
                return MNL_CB_ERROR;
-       pr_out_dev(dl, tb);
+
+       if (tb[DEVLINK_ATTR_RELOAD_FAILED])
+               reload_failed = mnl_attr_get_u8(tb[DEVLINK_ATTR_RELOAD_FAILED]);
+
+       if (reload_failed) {
+               __pr_out_handle_start(dl, tb, true, false);
+               pr_out_bool(dl, "reload_failed", true);
+               pr_out_handle_end(dl);
+       } else {
+               pr_out_handle(dl, tb);
+       }
+
        return MNL_CB_OK;
 }
 
@@ -2662,7 +2747,7 @@ static int cmd_dev_show(struct dl *dl)
 
 static void cmd_dev_reload_help(void)
 {
-       pr_err("Usage: devlink dev reload [ DEV ]\n");
+       pr_err("Usage: devlink dev reload DEV [ netns { PID | NAME | ID } ]\n");
 }
 
 static int cmd_dev_reload(struct dl *dl)
@@ -2678,7 +2763,7 @@ static int cmd_dev_reload(struct dl *dl)
        nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_RELOAD,
                               NLM_F_REQUEST | NLM_F_ACK);
 
-       err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, 0);
+       err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, DL_OPT_NETNS);
        if (err)
                return err;
 
@@ -2826,9 +2911,151 @@ static void cmd_dev_flash_help(void)
        pr_err("Usage: devlink dev flash DEV file PATH [ component NAME ]\n");
 }
 
+
+struct cmd_dev_flash_status_ctx {
+       struct dl *dl;
+       char *last_msg;
+       char *last_component;
+       uint8_t not_first:1,
+               last_pc:1,
+               received_end:1,
+               flash_done:1;
+};
+
+static int nullstrcmp(const char *str1, const char *str2)
+{
+       if (str1 && str2)
+               return strcmp(str1, str2);
+       if (!str1 && !str2)
+               return 0;
+       return str1 ? 1 : -1;
+}
+
+static int cmd_dev_flash_status_cb(const struct nlmsghdr *nlh, void *data)
+{
+       struct cmd_dev_flash_status_ctx *ctx = data;
+       struct dl_opts *opts = &ctx->dl->opts;
+       struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
+       struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
+       const char *component = NULL;
+       uint64_t done = 0, total = 0;
+       const char *msg = NULL;
+       const char *bus_name;
+       const char *dev_name;
+
+       if (genl->cmd != DEVLINK_CMD_FLASH_UPDATE_STATUS &&
+           genl->cmd != DEVLINK_CMD_FLASH_UPDATE_END)
+               return MNL_CB_STOP;
+
+       mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
+       if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME])
+               return MNL_CB_ERROR;
+       bus_name = mnl_attr_get_str(tb[DEVLINK_ATTR_BUS_NAME]);
+       dev_name = mnl_attr_get_str(tb[DEVLINK_ATTR_DEV_NAME]);
+       if (strcmp(bus_name, opts->bus_name) ||
+           strcmp(dev_name, opts->dev_name))
+               return MNL_CB_ERROR;
+
+       if (genl->cmd == DEVLINK_CMD_FLASH_UPDATE_END && ctx->not_first) {
+               pr_out("\n");
+               free(ctx->last_msg);
+               free(ctx->last_component);
+               ctx->received_end = 1;
+               return MNL_CB_STOP;
+       }
+
+       if (tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_MSG])
+               msg = mnl_attr_get_str(tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_MSG]);
+       if (tb[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT])
+               component = mnl_attr_get_str(tb[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT]);
+       if (tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE])
+               done = mnl_attr_get_u64(tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE]);
+       if (tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL])
+               total = mnl_attr_get_u64(tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL]);
+
+       if (!nullstrcmp(msg, ctx->last_msg) &&
+           !nullstrcmp(component, ctx->last_component) &&
+           ctx->last_pc && ctx->not_first) {
+               pr_out_tty("\b\b\b\b\b"); /* clean percentage */
+       } else {
+               if (ctx->not_first)
+                       pr_out("\n");
+               if (component) {
+                       pr_out("[%s] ", component);
+                       free(ctx->last_component);
+                       ctx->last_component = strdup(component);
+               }
+               if (msg) {
+                       pr_out("%s", msg);
+                       free(ctx->last_msg);
+                       ctx->last_msg = strdup(msg);
+               }
+       }
+       if (total) {
+               pr_out_tty(" %3lu%%", (done * 100) / total);
+               ctx->last_pc = 1;
+       } else {
+               ctx->last_pc = 0;
+       }
+       fflush(stdout);
+       ctx->not_first = 1;
+
+       return MNL_CB_STOP;
+}
+
+static int cmd_dev_flash_fds_process(struct cmd_dev_flash_status_ctx *ctx,
+                                    struct mnlg_socket *nlg_ntf,
+                                    int pipe_r)
+{
+       int nlfd = mnlg_socket_get_fd(nlg_ntf);
+       fd_set fds[3];
+       int fdmax;
+       int i;
+       int err;
+       int err2;
+
+       for (i = 0; i < 3; i++)
+               FD_ZERO(&fds[i]);
+       FD_SET(pipe_r, &fds[0]);
+       fdmax = pipe_r + 1;
+       FD_SET(nlfd, &fds[0]);
+       if (nlfd >= fdmax)
+               fdmax = nlfd + 1;
+
+       while (select(fdmax, &fds[0], &fds[1], &fds[2], NULL) < 0) {
+               if (errno == EINTR)
+                       continue;
+               pr_err("select() failed\n");
+               return -errno;
+       }
+       if (FD_ISSET(nlfd, &fds[0])) {
+               err = _mnlg_socket_recv_run(nlg_ntf,
+                                           cmd_dev_flash_status_cb, ctx);
+               if (err)
+                       return err;
+       }
+       if (FD_ISSET(pipe_r, &fds[0])) {
+               err = read(pipe_r, &err2, sizeof(err2));
+               if (err == -1) {
+                       pr_err("Failed to read pipe\n");
+                       return -errno;
+               }
+               if (err2)
+                       return err2;
+               ctx->flash_done = 1;
+       }
+       return 0;
+}
+
+
 static int cmd_dev_flash(struct dl *dl)
 {
+       struct cmd_dev_flash_status_ctx ctx = {.dl = dl,};
+       struct mnlg_socket *nlg_ntf;
        struct nlmsghdr *nlh;
+       int pipe_r, pipe_w;
+       int pipe_fds[2];
+       pid_t pid;
        int err;
 
        if (dl_argv_match(dl, "help") || dl_no_arg(dl)) {
@@ -2844,7 +3071,48 @@ static int cmd_dev_flash(struct dl *dl)
        if (err)
                return err;
 
-       return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+       nlg_ntf = mnlg_socket_open(DEVLINK_GENL_NAME, DEVLINK_GENL_VERSION);
+       if (!nlg_ntf)
+               return err;
+
+       err = _mnlg_socket_group_add(nlg_ntf, DEVLINK_GENL_MCGRP_CONFIG_NAME);
+       if (err)
+               return err;
+
+       err = pipe(pipe_fds);
+       if (err == -1)
+               return -errno;
+       pipe_r = pipe_fds[0];
+       pipe_w = pipe_fds[1];
+
+       pid = fork();
+       if (pid == -1) {
+               close(pipe_r);
+               close(pipe_w);
+               return -errno;
+       } else if (!pid) {
+               /* In child, just execute the flash and pass returned
+                * value through pipe once it is done.
+                */
+               close(pipe_r);
+               err = _mnlg_socket_send(dl->nlg, nlh);
+               write(pipe_w, &err, sizeof(err));
+               close(pipe_w);
+               exit(0);
+       }
+       close(pipe_w);
+
+       do {
+               err = cmd_dev_flash_fds_process(&ctx, nlg_ntf, pipe_r);
+               if (err)
+                       goto out;
+       } while (!ctx.flash_done || (ctx.not_first && !ctx.received_end));
+
+       err = _mnlg_socket_recv_run(dl->nlg, NULL, NULL);
+out:
+       close(pipe_r);
+       mnlg_socket_close(nlg_ntf);
+       return err;
 }
 
 static int cmd_dev(struct dl *dl)
@@ -3878,6 +4146,9 @@ static const char *cmd_name(uint8_t cmd)
        case DEVLINK_CMD_REGION_SET: return "set";
        case DEVLINK_CMD_REGION_NEW: return "new";
        case DEVLINK_CMD_REGION_DEL: return "del";
+       case DEVLINK_CMD_FLASH_UPDATE: return "begin";
+       case DEVLINK_CMD_FLASH_UPDATE_END: return "end";
+       case DEVLINK_CMD_FLASH_UPDATE_STATUS: return "status";
        case DEVLINK_CMD_TRAP_GET: return "get";
        case DEVLINK_CMD_TRAP_SET: return "set";
        case DEVLINK_CMD_TRAP_NEW: return "new";
@@ -3914,6 +4185,10 @@ static const char *cmd_obj(uint8_t cmd)
        case DEVLINK_CMD_REGION_NEW:
        case DEVLINK_CMD_REGION_DEL:
                return "region";
+       case DEVLINK_CMD_FLASH_UPDATE:
+       case DEVLINK_CMD_FLASH_UPDATE_END:
+       case DEVLINK_CMD_FLASH_UPDATE_STATUS:
+               return "flash";
        case DEVLINK_CMD_TRAP_GET:
        case DEVLINK_CMD_TRAP_SET:
        case DEVLINK_CMD_TRAP_NEW:
@@ -3948,6 +4223,29 @@ static bool cmd_filter_check(struct dl *dl, uint8_t cmd)
        return false;
 }
 
+static void pr_out_flash_update(struct dl *dl, struct nlattr **tb)
+{
+       __pr_out_handle_start(dl, tb, true, false);
+
+       if (tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_MSG])
+               pr_out_str(dl, "msg",
+                          mnl_attr_get_str(tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_MSG]));
+
+       if (tb[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT])
+               pr_out_str(dl, "component",
+                          mnl_attr_get_str(tb[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT]));
+
+       if (tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE])
+               pr_out_u64(dl, "done",
+                          mnl_attr_get_u64(tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE]));
+
+       if (tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL])
+               pr_out_u64(dl, "total",
+                          mnl_attr_get_u64(tb[DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL]));
+
+       pr_out_handle_end(dl);
+}
+
 static void pr_out_region(struct dl *dl, struct nlattr **tb);
 static void pr_out_trap(struct dl *dl, struct nlattr **tb, bool array);
 static void pr_out_trap_group(struct dl *dl, struct nlattr **tb, bool array);
@@ -3971,7 +4269,7 @@ static int cmd_mon_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_mon_header(genl->cmd);
-               pr_out_dev(dl, tb);
+               pr_out_handle(dl, tb);
                break;
        case DEVLINK_CMD_PORT_GET: /* fall through */
        case DEVLINK_CMD_PORT_SET: /* fall through */
@@ -4006,6 +4304,15 @@ static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data)
                pr_out_mon_header(genl->cmd);
                pr_out_region(dl, tb);
                break;
+       case DEVLINK_CMD_FLASH_UPDATE: /* fall through */
+       case DEVLINK_CMD_FLASH_UPDATE_END: /* fall through */
+       case DEVLINK_CMD_FLASH_UPDATE_STATUS:
+               mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
+               if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME])
+                       return MNL_CB_ERROR;
+               pr_out_mon_header(genl->cmd);
+               pr_out_flash_update(dl, tb);
+               break;
        case DEVLINK_CMD_TRAP_GET: /* fall through */
        case DEVLINK_CMD_TRAP_SET: /* fall through */
        case DEVLINK_CMD_TRAP_NEW: /* fall through */
@@ -6740,7 +7047,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");
 }
@@ -6890,6 +7197,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;
@@ -6905,7 +7213,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) {
@@ -6934,6 +7242,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();