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 <vadim4j@gmail.com>
This commit is contained in:
parent
ddb1129b75
commit
c3087c10f1
|
|
@ -42,5 +42,6 @@ static int setns(int fd, int nstype)
|
||||||
#endif /* HAVE_SETNS */
|
#endif /* HAVE_SETNS */
|
||||||
|
|
||||||
extern int netns_switch(char *netns);
|
extern int netns_switch(char *netns);
|
||||||
|
extern int netns_get_fd(const char *netns);
|
||||||
|
|
||||||
#endif /* __NAMESPACE_H__ */
|
#endif /* __NAMESPACE_H__ */
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,6 @@ struct link_util
|
||||||
|
|
||||||
struct link_util *get_link_kind(const char *kind);
|
struct link_util *get_link_kind(const char *kind);
|
||||||
struct link_util *get_link_slave_kind(const char *slave_kind);
|
struct link_util *get_link_slave_kind(const char *slave_kind);
|
||||||
int get_netns_fd(const char *name);
|
|
||||||
|
|
||||||
#ifndef INFINITY_LIFE_TIME
|
#ifndef INFINITY_LIFE_TIME
|
||||||
#define INFINITY_LIFE_TIME 0xFFFFFFFFU
|
#define INFINITY_LIFE_TIME 0xFFFFFFFFU
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@
|
||||||
#include "rt_names.h"
|
#include "rt_names.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "ip_common.h"
|
#include "ip_common.h"
|
||||||
|
#include "namespace.h"
|
||||||
|
|
||||||
#define IPLINK_IOCTL_COMPAT 1
|
#define IPLINK_IOCTL_COMPAT 1
|
||||||
#ifndef LIBDIR
|
#ifndef LIBDIR
|
||||||
|
|
@ -440,7 +441,7 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req,
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
if (netns != -1)
|
if (netns != -1)
|
||||||
duparg("netns", *argv);
|
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);
|
addattr_l(&req->n, sizeof(*req), IFLA_NET_NS_FD, &netns, 4);
|
||||||
else if (get_integer(&netns, *argv, 0) == 0)
|
else if (get_integer(&netns, *argv, 0) == 0)
|
||||||
addattr_l(&req->n, sizeof(*req), IFLA_NET_NS_PID, &netns, 4);
|
addattr_l(&req->n, sizeof(*req), IFLA_NET_NS_PID, &netns, 4);
|
||||||
|
|
|
||||||
15
ip/ipnetns.c
15
ip/ipnetns.c
|
|
@ -31,21 +31,6 @@ static int usage(void)
|
||||||
exit(-1);
|
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)
|
static int netns_list(int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
|
|
|
||||||
|
|
@ -84,3 +84,18 @@ int netns_switch(char *name)
|
||||||
bind_etc(name);
|
bind_etc(name);
|
||||||
return 0;
|
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);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue