]>
git.proxmox.com Git - mirror_iproute2.git/blob - ip/ipnetns.c
1 /* SPDX-License-Identifier: GPL-2.0 */
6 #include <sys/inotify.h>
8 #include <sys/syscall.h>
17 #include <linux/limits.h>
19 #include <linux/net_namespace.h>
23 #include "ip_common.h"
24 #include "namespace.h"
25 #include "json_print.h"
27 static int usage(void)
30 "Usage: ip netns list\n"
31 " ip netns add NAME\n"
32 " ip netns attach NAME PID\n"
33 " ip netns set NAME NETNSID\n"
34 " ip [-all] netns delete [NAME]\n"
35 " ip netns identify [PID]\n"
36 " ip netns pids NAME\n"
37 " ip [-all] netns exec [NAME] cmd ...\n"
39 " ip netns list-id [target-nsid POSITIVE-INT] [nsid POSITIVE-INT]\n"
40 "NETNSID := auto | POSITIVE-INT\n");
44 /* This socket is used to get nsid */
45 static struct rtnl_handle rtnsh
= { .fd
= -1 };
47 static int have_rtnl_getnsid
= -1;
48 static int saved_netns
= -1;
49 static struct link_filter filter
;
51 static int ipnetns_accept_msg(struct rtnl_ctrl_data
*ctrl
,
52 struct nlmsghdr
*n
, void *arg
)
54 struct nlmsgerr
*err
= (struct nlmsgerr
*)NLMSG_DATA(n
);
56 if (n
->nlmsg_type
== NLMSG_ERROR
&&
57 (err
->error
== -EOPNOTSUPP
|| err
->error
== -EINVAL
))
58 have_rtnl_getnsid
= 0;
60 have_rtnl_getnsid
= 1;
64 static int ipnetns_have_nsid(void)
71 .n
.nlmsg_len
= NLMSG_LENGTH(sizeof(struct rtgenmsg
)),
72 .n
.nlmsg_flags
= NLM_F_REQUEST
,
73 .n
.nlmsg_type
= RTM_GETNSID
,
74 .g
.rtgen_family
= AF_UNSPEC
,
78 if (have_rtnl_getnsid
< 0) {
79 fd
= open("/proc/self/ns/net", O_RDONLY
);
81 have_rtnl_getnsid
= 0;
85 addattr32(&req
.n
, 1024, NETNSA_FD
, fd
);
87 if (rtnl_send(&rth
, &req
.n
, req
.n
.nlmsg_len
) < 0) {
88 perror("request send failed");
91 rtnl_listen(&rth
, ipnetns_accept_msg
, NULL
);
95 return have_rtnl_getnsid
;
98 int get_netnsid_from_name(const char *name
)
105 .n
.nlmsg_len
= NLMSG_LENGTH(sizeof(struct rtgenmsg
)),
106 .n
.nlmsg_flags
= NLM_F_REQUEST
,
107 .n
.nlmsg_type
= RTM_GETNSID
,
108 .g
.rtgen_family
= AF_UNSPEC
,
110 struct nlmsghdr
*answer
;
111 struct rtattr
*tb
[NETNSA_MAX
+ 1];
112 struct rtgenmsg
*rthdr
;
113 int len
, fd
, ret
= -1;
115 netns_nsid_socket_init();
117 fd
= netns_get_fd(name
);
121 addattr32(&req
.n
, 1024, NETNSA_FD
, fd
);
122 if (rtnl_talk(&rtnsh
, &req
.n
, &answer
) < 0) {
128 /* Validate message and parse attributes */
129 if (answer
->nlmsg_type
== NLMSG_ERROR
)
132 rthdr
= NLMSG_DATA(answer
);
133 len
= answer
->nlmsg_len
- NLMSG_SPACE(sizeof(*rthdr
));
137 parse_rtattr(tb
, NETNSA_MAX
, NETNS_RTA(rthdr
), len
);
139 if (tb
[NETNSA_NSID
]) {
140 ret
= rta_getattr_s32(tb
[NETNSA_NSID
]);
149 struct hlist_node nsid_hash
;
150 struct hlist_node name_hash
;
155 #define NSIDMAP_SIZE 128
156 #define NSID_HASH_NSID(nsid) (nsid & (NSIDMAP_SIZE - 1))
157 #define NSID_HASH_NAME(name) (namehash(name) & (NSIDMAP_SIZE - 1))
159 static struct hlist_head nsid_head
[NSIDMAP_SIZE
];
160 static struct hlist_head name_head
[NSIDMAP_SIZE
];
162 static struct nsid_cache
*netns_map_get_by_nsid(int nsid
)
164 struct hlist_node
*n
;
170 h
= NSID_HASH_NSID(nsid
);
171 hlist_for_each(n
, &nsid_head
[h
]) {
172 struct nsid_cache
*c
= container_of(n
, struct nsid_cache
,
181 char *get_name_from_nsid(int nsid
)
183 struct nsid_cache
*c
;
188 netns_nsid_socket_init();
191 c
= netns_map_get_by_nsid(nsid
);
198 static int netns_map_add(int nsid
, const char *name
)
200 struct nsid_cache
*c
;
203 if (netns_map_get_by_nsid(nsid
) != NULL
)
206 c
= malloc(sizeof(*c
) + strlen(name
) + 1);
212 strcpy(c
->name
, name
);
214 h
= NSID_HASH_NSID(nsid
);
215 hlist_add_head(&c
->nsid_hash
, &nsid_head
[h
]);
217 h
= NSID_HASH_NAME(name
);
218 hlist_add_head(&c
->name_hash
, &name_head
[h
]);
223 static void netns_map_del(struct nsid_cache
*c
)
225 hlist_del(&c
->name_hash
);
226 hlist_del(&c
->nsid_hash
);
230 void netns_nsid_socket_init(void)
232 if (rtnsh
.fd
> -1 || !ipnetns_have_nsid())
235 if (rtnl_open(&rtnsh
, 0) < 0) {
236 fprintf(stderr
, "Cannot open rtnetlink\n");
242 void netns_map_init(void)
244 static int initialized
;
245 struct dirent
*entry
;
249 if (initialized
|| !ipnetns_have_nsid())
252 dir
= opendir(NETNS_RUN_DIR
);
256 while ((entry
= readdir(dir
)) != NULL
) {
257 if (strcmp(entry
->d_name
, ".") == 0)
259 if (strcmp(entry
->d_name
, "..") == 0)
261 nsid
= get_netnsid_from_name(entry
->d_name
);
264 netns_map_add(nsid
, entry
->d_name
);
270 static int netns_get_name(int nsid
, char *name
)
272 struct dirent
*entry
;
279 dir
= opendir(NETNS_RUN_DIR
);
283 while ((entry
= readdir(dir
)) != NULL
) {
284 if (strcmp(entry
->d_name
, ".") == 0)
286 if (strcmp(entry
->d_name
, "..") == 0)
288 id
= get_netnsid_from_name(entry
->d_name
);
290 if (id
>= 0 && nsid
== id
) {
291 strcpy(name
, entry
->d_name
);
300 int print_nsid(struct nlmsghdr
*n
, void *arg
)
302 struct rtgenmsg
*rthdr
= NLMSG_DATA(n
);
303 struct rtattr
*tb
[NETNSA_MAX
+1];
304 int len
= n
->nlmsg_len
;
305 FILE *fp
= (FILE *)arg
;
306 struct nsid_cache
*c
;
310 if (n
->nlmsg_type
!= RTM_NEWNSID
&& n
->nlmsg_type
!= RTM_DELNSID
)
313 len
-= NLMSG_SPACE(sizeof(*rthdr
));
315 fprintf(stderr
, "BUG: wrong nlmsg len %d in %s\n", len
,
320 parse_rtattr(tb
, NETNSA_MAX
, NETNS_RTA(rthdr
), len
);
321 if (tb
[NETNSA_NSID
] == NULL
) {
322 fprintf(stderr
, "BUG: NETNSA_NSID is missing %s\n", __func__
);
326 open_json_object(NULL
);
327 if (n
->nlmsg_type
== RTM_DELNSID
)
328 print_bool(PRINT_ANY
, "deleted", "Deleted ", true);
330 nsid
= rta_getattr_s32(tb
[NETNSA_NSID
]);
332 print_string(PRINT_FP
, NULL
, "nsid unassigned ", NULL
);
334 print_int(PRINT_ANY
, "nsid", "nsid %d ", nsid
);
336 if (tb
[NETNSA_CURRENT_NSID
]) {
337 current
= rta_getattr_s32(tb
[NETNSA_CURRENT_NSID
]);
339 print_string(PRINT_FP
, NULL
,
340 "current-nsid unassigned ", NULL
);
342 print_int(PRINT_ANY
, "current-nsid",
343 "current-nsid %d ", current
);
346 c
= netns_map_get_by_nsid(tb
[NETNSA_CURRENT_NSID
] ? current
: nsid
);
348 print_string(PRINT_ANY
, "name",
349 "(iproute2 netns name: %s)", c
->name
);
353 /* nsid might not be in cache */
354 if (c
== NULL
&& n
->nlmsg_type
== RTM_NEWNSID
)
355 if (netns_get_name(nsid
, name
) == 0) {
356 print_string(PRINT_ANY
, "name",
357 "(iproute2 netns name: %s)", name
);
358 netns_map_add(nsid
, name
);
361 print_string(PRINT_FP
, NULL
, "\n", NULL
);
367 static int get_netnsid_from_netnsid(int nsid
)
374 .n
.nlmsg_len
= NLMSG_LENGTH(NLMSG_ALIGN(sizeof(struct rtgenmsg
))),
375 .n
.nlmsg_flags
= NLM_F_REQUEST
,
376 .n
.nlmsg_type
= RTM_GETNSID
,
377 .g
.rtgen_family
= AF_UNSPEC
,
379 struct nlmsghdr
*answer
;
382 netns_nsid_socket_init();
384 err
= addattr32(&req
.n
, sizeof(req
), NETNSA_NSID
, nsid
);
388 if (filter
.target_nsid
>= 0) {
389 err
= addattr32(&req
.n
, sizeof(req
), NETNSA_TARGET_NSID
,
395 if (rtnl_talk(&rtnsh
, &req
.n
, &answer
) < 0)
398 /* Validate message and parse attributes */
399 if (answer
->nlmsg_type
== NLMSG_ERROR
)
403 err
= print_nsid(answer
, stdout
);
410 static int netns_filter_req(struct nlmsghdr
*nlh
, int reqlen
)
414 if (filter
.target_nsid
>= 0) {
415 err
= addattr32(nlh
, reqlen
, NETNSA_TARGET_NSID
,
424 static int netns_list_id(int argc
, char **argv
)
428 if (!ipnetns_have_nsid()) {
430 "RTM_GETNSID is not supported by the kernel.\n");
434 filter
.target_nsid
= -1;
436 if (strcmp(*argv
, "target-nsid") == 0) {
437 if (filter
.target_nsid
>= 0)
438 duparg("target-nsid", *argv
);
441 if (get_integer(&filter
.target_nsid
, *argv
, 0))
442 invarg("\"target-nsid\" value is invalid",
444 else if (filter
.target_nsid
< 0)
445 invarg("\"target-nsid\" value should be >= 0",
447 } else if (strcmp(*argv
, "nsid") == 0) {
449 duparg("nsid", *argv
);
452 if (get_integer(&nsid
, *argv
, 0))
453 invarg("\"nsid\" value is invalid", *argv
);
455 invarg("\"nsid\" value should be >= 0",
463 return get_netnsid_from_netnsid(nsid
);
465 if (rtnl_nsiddump_req_filter_fn(&rth
, AF_UNSPEC
,
466 netns_filter_req
) < 0) {
467 perror("Cannot send dump request");
472 if (rtnl_dump_filter(&rth
, print_nsid
, stdout
) < 0) {
474 fprintf(stderr
, "Dump terminated\n");
481 static int netns_list(int argc
, char **argv
)
483 struct dirent
*entry
;
487 dir
= opendir(NETNS_RUN_DIR
);
492 while ((entry
= readdir(dir
)) != NULL
) {
493 if (strcmp(entry
->d_name
, ".") == 0)
495 if (strcmp(entry
->d_name
, "..") == 0)
498 open_json_object(NULL
);
499 print_string(PRINT_ANY
, "name",
500 "%s", entry
->d_name
);
501 if (ipnetns_have_nsid()) {
502 id
= get_netnsid_from_name(entry
->d_name
);
504 print_int(PRINT_ANY
, "id", " (id: %d)", id
);
506 print_string(PRINT_FP
, NULL
, "\n", NULL
);
514 static int do_switch(void *arg
)
518 /* we just changed namespaces. clear any vrf association
519 * with prior namespace before exec'ing command
523 return netns_switch(netns
);
526 static int on_netns_exec(char *nsname
, void *arg
)
530 printf("\nnetns: %s\n", nsname
);
531 cmd_exec(argv
[0], argv
, true, do_switch
, nsname
);
535 static int netns_exec(int argc
, char **argv
)
537 /* Setup the proper environment for apps that are not netns
538 * aware, and execute a program in that environment.
540 if (argc
< 1 && !do_all
) {
541 fprintf(stderr
, "No netns name specified\n");
544 if ((argc
< 2 && !do_all
) || (argc
< 1 && do_all
)) {
545 fprintf(stderr
, "No command specified\n");
550 return netns_foreach(on_netns_exec
, argv
);
552 /* ip must return the status of the child,
553 * but do_cmd() will add a minus to this,
554 * so let's add another one here to cancel it.
556 return -cmd_exec(argv
[1], argv
+ 1, !!batch_mode
, do_switch
, argv
[0]);
559 static int is_pid(const char *str
)
563 for (; (ch
= *str
); str
++) {
570 static int netns_pids(int argc
, char **argv
)
573 char net_path
[PATH_MAX
];
577 struct dirent
*entry
;
580 fprintf(stderr
, "No netns name specified\n");
584 fprintf(stderr
, "extra arguments specified\n");
589 snprintf(net_path
, sizeof(net_path
), "%s/%s", NETNS_RUN_DIR
, name
);
590 netns
= open(net_path
, O_RDONLY
);
592 fprintf(stderr
, "Cannot open network namespace: %s\n",
596 if (fstat(netns
, &netst
) < 0) {
597 fprintf(stderr
, "Stat of netns failed: %s\n",
601 dir
= opendir("/proc/");
603 fprintf(stderr
, "Open of /proc failed: %s\n",
607 while ((entry
= readdir(dir
))) {
608 char pid_net_path
[PATH_MAX
];
611 if (!is_pid(entry
->d_name
))
613 snprintf(pid_net_path
, sizeof(pid_net_path
), "/proc/%s/ns/net",
615 if (stat(pid_net_path
, &st
) != 0)
617 if ((st
.st_dev
== netst
.st_dev
) &&
618 (st
.st_ino
== netst
.st_ino
)) {
619 printf("%s\n", entry
->d_name
);
627 int netns_identify_pid(const char *pidstr
, char *name
, int len
)
629 char net_path
[PATH_MAX
];
633 struct dirent
*entry
;
637 snprintf(net_path
, sizeof(net_path
), "/proc/%s/ns/net", pidstr
);
638 netns
= open(net_path
, O_RDONLY
);
640 fprintf(stderr
, "Cannot open network namespace: %s\n",
644 if (fstat(netns
, &netst
) < 0) {
645 fprintf(stderr
, "Stat of netns failed: %s\n",
649 dir
= opendir(NETNS_RUN_DIR
);
651 /* Succeed treat a missing directory as an empty directory */
655 fprintf(stderr
, "Failed to open directory %s:%s\n",
656 NETNS_RUN_DIR
, strerror(errno
));
660 while ((entry
= readdir(dir
))) {
661 char name_path
[PATH_MAX
];
664 if (strcmp(entry
->d_name
, ".") == 0)
666 if (strcmp(entry
->d_name
, "..") == 0)
669 snprintf(name_path
, sizeof(name_path
), "%s/%s", NETNS_RUN_DIR
,
672 if (stat(name_path
, &st
) != 0)
675 if ((st
.st_dev
== netst
.st_dev
) &&
676 (st
.st_ino
== netst
.st_ino
)) {
677 strlcpy(name
, entry
->d_name
, len
);
685 static int netns_identify(int argc
, char **argv
)
693 } else if (argc
> 1) {
694 fprintf(stderr
, "extra arguments specified\n");
698 if (!is_pid(pidstr
)) {
699 fprintf(stderr
, "Specified string '%s' is not a pid\n",
705 rc
= netns_identify_pid(pidstr
, name
, sizeof(name
));
707 printf("%s\n", name
);
712 static int on_netns_del(char *nsname
, void *arg
)
714 char netns_path
[PATH_MAX
];
716 snprintf(netns_path
, sizeof(netns_path
), "%s/%s", NETNS_RUN_DIR
, nsname
);
717 umount2(netns_path
, MNT_DETACH
);
718 if (unlink(netns_path
) < 0) {
719 fprintf(stderr
, "Cannot remove namespace file \"%s\": %s\n",
720 netns_path
, strerror(errno
));
726 static int netns_delete(int argc
, char **argv
)
728 if (argc
< 1 && !do_all
) {
729 fprintf(stderr
, "No netns name specified\n");
734 return netns_foreach(on_netns_del
, NULL
);
736 return on_netns_del(argv
[0], NULL
);
739 static int create_netns_dir(void)
741 /* Create the base netns directory if it doesn't exist */
742 if (mkdir(NETNS_RUN_DIR
, S_IRWXU
|S_IRGRP
|S_IXGRP
|S_IROTH
|S_IXOTH
)) {
743 if (errno
!= EEXIST
) {
744 fprintf(stderr
, "mkdir %s failed: %s\n",
745 NETNS_RUN_DIR
, strerror(errno
));
753 /* Obtain a FD for the current namespace, so we can reenter it later */
754 static void netns_save(void)
756 if (saved_netns
!= -1)
759 saved_netns
= open("/proc/self/ns/net", O_RDONLY
| O_CLOEXEC
);
760 if (saved_netns
== -1) {
761 perror("Cannot open init namespace");
766 static void netns_restore(void)
768 if (saved_netns
== -1)
771 if (setns(saved_netns
, CLONE_NEWNET
)) {
780 static int netns_add(int argc
, char **argv
, bool create
)
782 /* This function creates a new network namespace and
783 * a new mount namespace and bind them into a well known
784 * location in the filesystem based on the name provided.
786 * If create is true, a new namespace will be created,
787 * otherwise an existing one will be attached to the file.
789 * The mount namespace is created so that any necessary
790 * userspace tweaks like remounting /sys, or bind mounting
791 * a new /etc/resolv.conf can be shared between users.
793 char netns_path
[PATH_MAX
], proc_path
[PATH_MAX
];
797 int made_netns_run_dir_mount
= 0;
801 fprintf(stderr
, "No netns name specified\n");
806 fprintf(stderr
, "No netns name and PID specified\n");
810 if (get_s32(&pid
, argv
[1], 0) || !pid
) {
811 fprintf(stderr
, "Invalid PID: %s\n", argv
[1]);
817 snprintf(netns_path
, sizeof(netns_path
), "%s/%s", NETNS_RUN_DIR
, name
);
819 if (create_netns_dir())
822 /* Make it possible for network namespace mounts to propagate between
823 * mount namespaces. This makes it likely that a unmounting a network
824 * namespace file in one namespace will unmount the network namespace
825 * file in all namespaces allowing the network namespace to be freed
828 while (mount("", NETNS_RUN_DIR
, "none", MS_SHARED
| MS_REC
, NULL
)) {
829 /* Fail unless we need to make the mount point */
830 if (errno
!= EINVAL
|| made_netns_run_dir_mount
) {
831 fprintf(stderr
, "mount --make-shared %s failed: %s\n",
832 NETNS_RUN_DIR
, strerror(errno
));
836 /* Upgrade NETNS_RUN_DIR to a mount point */
837 if (mount(NETNS_RUN_DIR
, NETNS_RUN_DIR
, "none", MS_BIND
| MS_REC
, NULL
)) {
838 fprintf(stderr
, "mount --bind %s %s failed: %s\n",
839 NETNS_RUN_DIR
, NETNS_RUN_DIR
, strerror(errno
));
842 made_netns_run_dir_mount
= 1;
845 /* Create the filesystem state */
846 fd
= open(netns_path
, O_RDONLY
|O_CREAT
|O_EXCL
, 0);
848 fprintf(stderr
, "Cannot create namespace file \"%s\": %s\n",
849 netns_path
, strerror(errno
));
856 if (unshare(CLONE_NEWNET
) < 0) {
857 fprintf(stderr
, "Failed to create a new network namespace \"%s\": %s\n",
858 name
, strerror(errno
));
862 strcpy(proc_path
, "/proc/self/ns/net");
864 snprintf(proc_path
, sizeof(proc_path
), "/proc/%d/ns/net", pid
);
867 /* Bind the netns last so I can watch for it */
868 if (mount(proc_path
, netns_path
, "none", MS_BIND
, NULL
) < 0) {
869 fprintf(stderr
, "Bind %s -> %s failed: %s\n",
870 proc_path
, netns_path
, strerror(errno
));
879 netns_delete(argc
, argv
);
880 } else if (unlink(netns_path
) < 0) {
881 fprintf(stderr
, "Cannot remove namespace file \"%s\": %s\n",
882 netns_path
, strerror(errno
));
887 int set_netnsid_from_name(const char *name
, int nsid
)
894 .n
.nlmsg_len
= NLMSG_LENGTH(sizeof(struct rtgenmsg
)),
895 .n
.nlmsg_flags
= NLM_F_REQUEST
,
896 .n
.nlmsg_type
= RTM_NEWNSID
,
897 .g
.rtgen_family
= AF_UNSPEC
,
901 netns_nsid_socket_init();
903 fd
= netns_get_fd(name
);
907 addattr32(&req
.n
, 1024, NETNSA_FD
, fd
);
908 addattr32(&req
.n
, 1024, NETNSA_NSID
, nsid
);
909 if (rtnl_talk(&rth
, &req
.n
, NULL
) < 0)
916 static int netns_set(int argc
, char **argv
)
918 char netns_path
[PATH_MAX
];
923 fprintf(stderr
, "No netns name specified\n");
927 fprintf(stderr
, "No nsid specified\n");
931 /* If a negative nsid is specified the kernel will select the nsid. */
932 if (strcmp(argv
[1], "auto") == 0)
934 else if (get_integer(&nsid
, argv
[1], 0))
935 invarg("Invalid \"netnsid\" value", argv
[1]);
937 invarg("\"netnsid\" value should be >= 0", argv
[1]);
939 snprintf(netns_path
, sizeof(netns_path
), "%s/%s", NETNS_RUN_DIR
, name
);
940 netns
= open(netns_path
, O_RDONLY
| O_CLOEXEC
);
942 fprintf(stderr
, "Cannot open network namespace \"%s\": %s\n",
943 name
, strerror(errno
));
947 return set_netnsid_from_name(name
, nsid
);
950 static int netns_monitor(int argc
, char **argv
)
953 struct inotify_event
*event
;
958 fprintf(stderr
, "inotify_init failed: %s\n",
963 if (create_netns_dir())
966 if (inotify_add_watch(fd
, NETNS_RUN_DIR
, IN_CREATE
| IN_DELETE
) < 0) {
967 fprintf(stderr
, "inotify_add_watch failed: %s\n",
972 ssize_t len
= read(fd
, buf
, sizeof(buf
));
975 fprintf(stderr
, "read failed: %s\n",
979 for (event
= (struct inotify_event
*)buf
;
980 (char *)event
< &buf
[len
];
981 event
= (struct inotify_event
*)((char *)event
+ sizeof(*event
) + event
->len
)) {
982 if (event
->mask
& IN_CREATE
)
983 printf("add %s\n", event
->name
);
984 if (event
->mask
& IN_DELETE
)
985 printf("delete %s\n", event
->name
);
991 static int invalid_name(const char *name
)
993 return !*name
|| strlen(name
) > NAME_MAX
||
994 strchr(name
, '/') || !strcmp(name
, ".") || !strcmp(name
, "..");
997 int do_netns(int argc
, char **argv
)
999 netns_nsid_socket_init();
1003 return netns_list(0, NULL
);
1006 if (!do_all
&& argc
> 1 && invalid_name(argv
[1])) {
1007 fprintf(stderr
, "Invalid netns name \"%s\"\n", argv
[1]);
1011 if ((matches(*argv
, "list") == 0) || (matches(*argv
, "show") == 0) ||
1012 (matches(*argv
, "lst") == 0)) {
1014 return netns_list(argc
-1, argv
+1);
1017 if ((matches(*argv
, "list-id") == 0)) {
1019 return netns_list_id(argc
-1, argv
+1);
1022 if (matches(*argv
, "help") == 0)
1025 if (matches(*argv
, "add") == 0)
1026 return netns_add(argc
-1, argv
+1, true);
1028 if (matches(*argv
, "set") == 0)
1029 return netns_set(argc
-1, argv
+1);
1031 if (matches(*argv
, "delete") == 0)
1032 return netns_delete(argc
-1, argv
+1);
1034 if (matches(*argv
, "identify") == 0)
1035 return netns_identify(argc
-1, argv
+1);
1037 if (matches(*argv
, "pids") == 0)
1038 return netns_pids(argc
-1, argv
+1);
1040 if (matches(*argv
, "exec") == 0)
1041 return netns_exec(argc
-1, argv
+1);
1043 if (matches(*argv
, "monitor") == 0)
1044 return netns_monitor(argc
-1, argv
+1);
1046 if (matches(*argv
, "attach") == 0)
1047 return netns_add(argc
-1, argv
+1, false);
1049 fprintf(stderr
, "Command \"%s\" is unknown, try \"ip netns help\".\n", *argv
);