From 694ed195a0e3e357f1344f7c0d4781945e1fff2b Mon Sep 17 00:00:00 2001 From: Nicolas Dichtel Date: Mon, 13 Apr 2015 10:34:24 +0200 Subject: [PATCH 1/5] Revert "configure: add missing INCLUDE to netnsid detection" This reverts commit d059de70cafb470f77fc19a42d95f6dc442cf6a3. Signed-off-by: Nicolas Dichtel --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index e54f4b6d..631938e9 100755 --- a/configure +++ b/configure @@ -224,7 +224,7 @@ check_netnsid() #include int test_def = RTM_GETNSID; EOF - $CC -I$INCLUDE -c $TMPDIR/netnsid.c >/dev/null 2>&1 + $CC -c $TMPDIR/netnsid.c >/dev/null 2>&1 if [ $? -eq 0 ] then echo "IP_CONFIG_NETNSID:=y" >> Config From 5a2ce868235cb337a88d2711005eb5972a06e1ac Mon Sep 17 00:00:00 2001 From: Nicolas Dichtel Date: Mon, 13 Apr 2015 10:34:25 +0200 Subject: [PATCH 2/5] Revert "ip netns: Fix rtnl error while print netns list" This reverts commit d116ff34145b00db54a37e2a6282dccd8bc08225. Signed-off-by: Nicolas Dichtel --- configure | 21 +-------------------- ip/Makefile | 4 ---- ip/ipnetns.c | 7 ------- 3 files changed, 1 insertion(+), 31 deletions(-) diff --git a/configure b/configure index 631938e9..c3dacdba 100755 --- a/configure +++ b/configure @@ -201,7 +201,7 @@ check_setns() { cat >$TMPDIR/setnstest.c < -int main(int argc, char **argv) +int main(int argc, char **argv) { (void)setns(0,0); return 0; @@ -218,23 +218,6 @@ EOF rm -f $TMPDIR/setnstest.c $TMPDIR/setnstest } -check_netnsid() -{ - cat >$TMPDIR/netnsid.c < -int test_def = RTM_GETNSID; -EOF - $CC -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 < Date: Mon, 13 Apr 2015 10:34:26 +0200 Subject: [PATCH 3/5] ipnetns: add a runtime check for RTM_GETNSID support The goal of this patch is to test during the runtime if the command RTM_GETNSID is supported by the kernel. Signed-off-by: Nicolas Dichtel --- ip/ipnetns.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/ip/ipnetns.c b/ip/ipnetns.c index 5a213dcf..24df167e 100644 --- a/ip/ipnetns.c +++ b/ip/ipnetns.c @@ -34,6 +34,56 @@ static int usage(void) exit(-1); } +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 { @@ -95,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); From aed6d85d1594bcd1c08c43e8d09c300abaa72a11 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Mon, 13 Apr 2015 08:55:11 -0700 Subject: [PATCH 4/5] v4.0.0 --- include/SNAPSHOT.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/SNAPSHOT.h b/include/SNAPSHOT.h index 35bda66a..8bd0c561 100644 --- a/include/SNAPSHOT.h +++ b/include/SNAPSHOT.h @@ -1 +1 @@ -static const char SNAPSHOT[] = "150210"; +static const char SNAPSHOT[] = "150413"; From 672acc723859290b94b753b8437d8cc2f0810174 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Mon, 13 Apr 2015 09:39:34 -0700 Subject: [PATCH 5/5] fix whitespace --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index c3dacdba..9470c1d4 100755 --- a/configure +++ b/configure @@ -201,7 +201,7 @@ check_setns() { cat >$TMPDIR/setnstest.c < -int main(int argc, char **argv) +int main(int argc, char **argv) { (void)setns(0,0); return 0;