Merge branch 'master' into net-next

This commit is contained in:
Stephen Hemminger 2015-04-13 09:39:46 -07:00
commit 93531fac41
4 changed files with 56 additions and 34 deletions

19
configure vendored
View File

@ -218,23 +218,6 @@ EOF
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()
{
cat >$TMPDIR/ipsettest.c <<EOF
@ -323,8 +306,6 @@ check_ipt_lib_dir
echo -n "libc has setns: "
check_setns
echo -n "netns has peer id suport: "
check_netnsid
echo -n "SELinux support: "
check_selinux

View File

@ -1 +1 @@
static const char SNAPSHOT[] = "150210";
static const char SNAPSHOT[] = "150413";

View File

@ -16,10 +16,6 @@ ifeq ($(IP_CONFIG_SETNS),y)
CFLAGS += -DHAVE_SETNS
endif
ifeq ($(IP_CONFIG_NETNSID),y)
CFLAGS += -DHAVE_NETNSID
endif
ALLOBJ=$(IPOBJ) $(RTMONOBJ)
SCRIPTS=ifcfg rtpr routel routef
TARGETS=ip rtmon

View File

@ -34,7 +34,56 @@ static int usage(void)
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)
{
struct {
@ -79,12 +128,6 @@ static int get_netnsid_from_name(const char *name)
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)
{
@ -102,9 +145,11 @@ static int netns_list(int argc, char **argv)
if (strcmp(entry->d_name, "..") == 0)
continue;
printf("%s", entry->d_name);
id = get_netnsid_from_name(entry->d_name);
if (id >= 0)
printf(" (id: %d)", id);
if (ipnetns_have_nsid()) {
id = get_netnsid_from_name(entry->d_name);
if (id >= 0)
printf(" (id: %d)", id);
}
printf("\n");
}
closedir(dir);