Commit 93531fac authored by Stephen Hemminger's avatar Stephen Hemminger

Merge branch 'master' into net-next

parents 6256f8c9 672acc72
...@@ -218,23 +218,6 @@ EOF ...@@ -218,23 +218,6 @@ EOF
rm -f $TMPDIR/setnstest.c $TMPDIR/setnstest rm -f $TMPDIR/setnstest.c $TMPDIR/setnstest
} }
check_netnsid()
{
cat >$TMPDIR/netnsid.c <<EOF
#include <linux/rtnetlink.h>
int test_def = RTM_GETNSID;
EOF
$CC -I$INCLUDE -c $TMPDIR/netnsid.c >/dev/null 2>&1
if [ $? -eq 0 ]
then
echo "IP_CONFIG_NETNSID:=y" >> Config
echo "yes"
else
echo "no"
fi
rm -f $TMPDIR/netnsid.c $TMPDIR/netnsid.o
}
check_ipset() check_ipset()
{ {
cat >$TMPDIR/ipsettest.c <<EOF cat >$TMPDIR/ipsettest.c <<EOF
...@@ -323,8 +306,6 @@ check_ipt_lib_dir ...@@ -323,8 +306,6 @@ check_ipt_lib_dir
echo -n "libc has setns: " echo -n "libc has setns: "
check_setns check_setns
echo -n "netns has peer id suport: "
check_netnsid
echo -n "SELinux support: " echo -n "SELinux support: "
check_selinux check_selinux
......
static const char SNAPSHOT[] = "150210"; static const char SNAPSHOT[] = "150413";
...@@ -16,10 +16,6 @@ ifeq ($(IP_CONFIG_SETNS),y) ...@@ -16,10 +16,6 @@ ifeq ($(IP_CONFIG_SETNS),y)
CFLAGS += -DHAVE_SETNS CFLAGS += -DHAVE_SETNS
endif endif
ifeq ($(IP_CONFIG_NETNSID),y)
CFLAGS += -DHAVE_NETNSID
endif
ALLOBJ=$(IPOBJ) $(RTMONOBJ) ALLOBJ=$(IPOBJ) $(RTMONOBJ)
SCRIPTS=ifcfg rtpr routel routef SCRIPTS=ifcfg rtpr routel routef
TARGETS=ip rtmon TARGETS=ip rtmon
......
...@@ -34,7 +34,56 @@ static int usage(void) ...@@ -34,7 +34,56 @@ static int usage(void)
exit(-1); exit(-1);
} }
#ifdef HAVE_NETNSID static int have_rtnl_getnsid = -1;
static int ipnetns_accept_msg(const struct sockaddr_nl *who,
struct nlmsghdr *n, void *arg)
{
struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(n);
if (n->nlmsg_type == NLMSG_ERROR &&
(err->error == -EOPNOTSUPP || err->error == -EINVAL))
have_rtnl_getnsid = 0;
else
have_rtnl_getnsid = 1;
return -1;
}
static int ipnetns_have_nsid(void)
{
struct {
struct nlmsghdr n;
struct rtgenmsg g;
char buf[1024];
} req;
int fd;
if (have_rtnl_getnsid < 0) {
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtgenmsg));
req.n.nlmsg_flags = NLM_F_REQUEST;
req.n.nlmsg_type = RTM_GETNSID;
req.g.rtgen_family = AF_UNSPEC;
fd = open("/proc/self/ns/net", O_RDONLY);
if (fd < 0) {
perror("open(\"/proc/self/ns/net\")");
exit(1);
}
addattr32(&req.n, 1024, NETNSA_FD, fd);
if (rtnl_send(&rth, &req.n, req.n.nlmsg_len) < 0) {
perror("request send failed");
exit(1);
}
rtnl_listen(&rth, ipnetns_accept_msg, NULL);
close(fd);
}
return have_rtnl_getnsid;
}
static int get_netnsid_from_name(const char *name) static int get_netnsid_from_name(const char *name)
{ {
struct { struct {
...@@ -79,12 +128,6 @@ static int get_netnsid_from_name(const char *name) ...@@ -79,12 +128,6 @@ static int get_netnsid_from_name(const char *name)
return -1; return -1;
} }
#else
static int get_netnsid_from_name(const char *name)
{
return -1;
}
#endif /* HAVE_NETNSID */
static int netns_list(int argc, char **argv) static int netns_list(int argc, char **argv)
{ {
...@@ -102,9 +145,11 @@ static int netns_list(int argc, char **argv) ...@@ -102,9 +145,11 @@ static int netns_list(int argc, char **argv)
if (strcmp(entry->d_name, "..") == 0) if (strcmp(entry->d_name, "..") == 0)
continue; continue;
printf("%s", entry->d_name); printf("%s", entry->d_name);
id = get_netnsid_from_name(entry->d_name); if (ipnetns_have_nsid()) {
if (id >= 0) id = get_netnsid_from_name(entry->d_name);
printf(" (id: %d)", id); if (id >= 0)
printf(" (id: %d)", id);
}
printf("\n"); printf("\n");
} }
closedir(dir); closedir(dir);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment