From: Vadim Kochan Date: Tue, 13 Jan 2015 20:08:44 +0000 (+0200) Subject: netns: Rename & move get_netns_fd to lib X-Git-Tag: v3.19.0~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c3087c10f167ab30fc8f4fbe9897156a619f1c67;p=thirdparty%2Fiproute2.git netns: Rename & move get_netns_fd to lib Renamed get_netns_fd -> netns_get_fd and moved to lib/namespace.c Signed-off-by: Vadim Kochan --- diff --git a/include/namespace.h b/include/namespace.h index 2f13e6594..b8c5cad6a 100644 --- a/include/namespace.h +++ b/include/namespace.h @@ -42,5 +42,6 @@ static int setns(int fd, int nstype) #endif /* HAVE_SETNS */ extern int netns_switch(char *netns); +extern int netns_get_fd(const char *netns); #endif /* __NAMESPACE_H__ */ diff --git a/ip/ip_common.h b/ip/ip_common.h index 75bfb824a..89a495ea1 100644 --- a/ip/ip_common.h +++ b/ip/ip_common.h @@ -87,7 +87,6 @@ struct link_util struct link_util *get_link_kind(const char *kind); struct link_util *get_link_slave_kind(const char *slave_kind); -int get_netns_fd(const char *name); #ifndef INFINITY_LIFE_TIME #define INFINITY_LIFE_TIME 0xFFFFFFFFU diff --git a/ip/iplink.c b/ip/iplink.c index 2709173a1..c93d1dc3d 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -32,6 +32,7 @@ #include "rt_names.h" #include "utils.h" #include "ip_common.h" +#include "namespace.h" #define IPLINK_IOCTL_COMPAT 1 #ifndef LIBDIR @@ -440,7 +441,7 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, NEXT_ARG(); if (netns != -1) duparg("netns", *argv); - if ((netns = get_netns_fd(*argv)) >= 0) + if ((netns = netns_get_fd(*argv)) >= 0) addattr_l(&req->n, sizeof(*req), IFLA_NET_NS_FD, &netns, 4); else if (get_integer(&netns, *argv, 0) == 0) addattr_l(&req->n, sizeof(*req), IFLA_NET_NS_PID, &netns, 4); diff --git a/ip/ipnetns.c b/ip/ipnetns.c index 519d51836..123318eb6 100644 --- a/ip/ipnetns.c +++ b/ip/ipnetns.c @@ -31,21 +31,6 @@ static int usage(void) exit(-1); } -int get_netns_fd(const char *name) -{ - char pathbuf[MAXPATHLEN]; - const char *path, *ptr; - - path = name; - ptr = strchr(name, '/'); - if (!ptr) { - snprintf(pathbuf, sizeof(pathbuf), "%s/%s", - NETNS_RUN_DIR, name ); - path = pathbuf; - } - return open(path, O_RDONLY); -} - static int netns_list(int argc, char **argv) { struct dirent *entry; diff --git a/lib/namespace.c b/lib/namespace.c index 1554ce084..65c1e3d7c 100644 --- a/lib/namespace.c +++ b/lib/namespace.c @@ -84,3 +84,18 @@ int netns_switch(char *name) bind_etc(name); return 0; } + +int netns_get_fd(const char *name) +{ + char pathbuf[MAXPATHLEN]; + const char *path, *ptr; + + path = name; + ptr = strchr(name, '/'); + if (!ptr) { + snprintf(pathbuf, sizeof(pathbuf), "%s/%s", + NETNS_RUN_DIR, name ); + path = pathbuf; + } + return open(path, O_RDONLY); +}