From 9580bad7b993eb80479a5ee08d333c39995cd662 Mon Sep 17 00:00:00 2001 From: Nicolas Dichtel Date: Tue, 5 Jun 2018 15:08:30 +0200 Subject: [PATCH 1/6] ip: display netns name instead of nsid When iproute2 has a name for the nsid, let's display it. It's more user friendly than a number. Signed-off-by: Nicolas Dichtel Signed-off-by: Stephen Hemminger --- ip/ip_common.h | 1 + ip/ipaddress.c | 20 +++++++++++++++----- ip/ipnetns.c | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/ip/ip_common.h b/ip/ip_common.h index 49eb7d7b..794478c5 100644 --- a/ip/ip_common.h +++ b/ip/ip_common.h @@ -60,6 +60,7 @@ void netns_map_init(void); void netns_nsid_socket_init(void); int print_nsid(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg); +char *get_name_from_nsid(int nsid); int do_ipaddr(int argc, char **argv); int do_ipaddrlabel(int argc, char **argv); int do_iproute(int argc, char **argv); diff --git a/ip/ipaddress.c b/ip/ipaddress.c index c7c7e7df..e4a1b985 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -955,10 +955,16 @@ int print_linkinfo(const struct sockaddr_nl *who, if (is_json_context()) { print_int(PRINT_JSON, "link_netnsid", NULL, id); } else { - if (id >= 0) - print_int(PRINT_FP, NULL, - " link-netnsid %d", id); - else + if (id >= 0) { + char *name = get_name_from_nsid(id); + + if (name) + print_string(PRINT_FP, NULL, + " link-netns %s", name); + else + print_int(PRINT_FP, NULL, + " link-netnsid %d", id); + } else print_string(PRINT_FP, NULL, " link-netnsid %s", "unknown"); } @@ -966,8 +972,12 @@ int print_linkinfo(const struct sockaddr_nl *who, if (tb[IFLA_NEW_NETNSID]) { int id = rta_getattr_u32(tb[IFLA_NEW_NETNSID]); + char *name = get_name_from_nsid(id); - print_int(PRINT_FP, NULL, " new-nsid %d", id); + if (name) + print_string(PRINT_FP, NULL, " new-netns %s", name); + else + print_int(PRINT_FP, NULL, " new-netnsid %d", id); } if (tb[IFLA_NEW_IFINDEX]) { int id = rta_getattr_u32(tb[IFLA_NEW_IFINDEX]); diff --git a/ip/ipnetns.c b/ip/ipnetns.c index e06100f4..30af9319 100644 --- a/ip/ipnetns.c +++ b/ip/ipnetns.c @@ -169,6 +169,20 @@ static struct nsid_cache *netns_map_get_by_nsid(int nsid) return NULL; } +char *get_name_from_nsid(int nsid) +{ + struct nsid_cache *c; + + netns_nsid_socket_init(); + netns_map_init(); + + c = netns_map_get_by_nsid(nsid); + if (c) + return c->name; + + return NULL; +} + static int netns_map_add(int nsid, const char *name) { struct nsid_cache *c; From 974ef93bf127172d62a55cb21635138e2964c647 Mon Sep 17 00:00:00 2001 From: Nicolas Dichtel Date: Tue, 5 Jun 2018 15:08:31 +0200 Subject: [PATCH 2/6] iplink: enable to specify a name for the link-netns The 'link-netnsid' argument needs a number. Add 'link-netns' when the user wants to use the iproute2 netns name instead of the nsid. Example: ip link add ipip1 link-netns foo type ipip remote 10.16.0.121 local 10.16.0.249 Signed-off-by: Nicolas Dichtel Signed-off-by: Stephen Hemminger --- ip/ip_common.h | 2 ++ ip/iplink.c | 18 ++++++++++++++++-- ip/ipnetns.c | 8 ++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/ip/ip_common.h b/ip/ip_common.h index 794478c5..4d3227cb 100644 --- a/ip/ip_common.h +++ b/ip/ip_common.h @@ -61,6 +61,8 @@ void netns_nsid_socket_init(void); int print_nsid(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg); char *get_name_from_nsid(int nsid); +int get_netnsid_from_name(const char *name); +int set_netnsid_from_name(const char *name, int nsid); int do_ipaddr(int argc, char **argv); int do_ipaddrlabel(int argc, char **argv); int do_iproute(int argc, char **argv); diff --git a/ip/iplink.c b/ip/iplink.c index 9ff5f692..e4d4da96 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -85,7 +85,7 @@ void iplink_usage(void) " [ broadcast LLADDR ]\n" " [ mtu MTU ]\n" " [ netns { PID | NAME } ]\n" - " [ link-netnsid ID ]\n" + " [ link-netns NAME | link-netnsid ID ]\n" " [ alias NAME ]\n" " [ vf NUM [ mac LLADDR ]\n" " [ vlan VLANID [ qos VLAN-QOS ] [ proto VLAN-PROTO ] ]\n" @@ -865,10 +865,24 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type) IFLA_INET6_ADDR_GEN_MODE, mode); addattr_nest_end(&req->n, afs6); addattr_nest_end(&req->n, afs); + } else if (matches(*argv, "link-netns") == 0) { + NEXT_ARG(); + if (link_netnsid != -1) + duparg("link-netns/link-netnsid", *argv); + link_netnsid = get_netnsid_from_name(*argv); + /* No nsid? Try to assign one. */ + if (link_netnsid < 0) + set_netnsid_from_name(*argv, -1); + link_netnsid = get_netnsid_from_name(*argv); + if (link_netnsid < 0) + invarg("Invalid \"link-netns\" value\n", + *argv); + addattr32(&req->n, sizeof(*req), IFLA_LINK_NETNSID, + link_netnsid); } else if (matches(*argv, "link-netnsid") == 0) { NEXT_ARG(); if (link_netnsid != -1) - duparg("link-netnsid", *argv); + duparg("link-netns/link-netnsid", *argv); if (get_integer(&link_netnsid, *argv, 0)) invarg("Invalid \"link-netnsid\" value\n", *argv); diff --git a/ip/ipnetns.c b/ip/ipnetns.c index 30af9319..368be0cb 100644 --- a/ip/ipnetns.c +++ b/ip/ipnetns.c @@ -91,7 +91,7 @@ static int ipnetns_have_nsid(void) return have_rtnl_getnsid; } -static int get_netnsid_from_name(const char *name) +int get_netnsid_from_name(const char *name) { struct { struct nlmsghdr n; @@ -108,6 +108,8 @@ static int get_netnsid_from_name(const char *name) struct rtgenmsg *rthdr; int len, fd; + netns_nsid_socket_init(); + fd = netns_get_fd(name); if (fd < 0) return fd; @@ -705,7 +707,7 @@ out_delete: return -1; } -static int set_netnsid_from_name(const char *name, int nsid) +int set_netnsid_from_name(const char *name, int nsid) { struct { struct nlmsghdr n; @@ -719,6 +721,8 @@ static int set_netnsid_from_name(const char *name, int nsid) }; int fd, err = 0; + netns_nsid_socket_init(); + fd = netns_get_fd(name); if (fd < 0) return fd; From 313ce6949c0d08a9a04a891ab6d94d0916217c66 Mon Sep 17 00:00:00 2001 From: Hoang Le Date: Fri, 8 Jun 2018 09:19:28 +0700 Subject: [PATCH 3/6] tipc: TIPC_NLA_LINK_NAME value pass on nesting entry TIPC_NLA_LINK In the commit 94f6a80 on next-net, TIPC_NLA_LINK_NAME attribute should be retrieved and validated via TIPC_NLA_LINK nesting entry in tipc_nl_node_get_link(). According to that commit, TIPC_NLA_LINK_NAME value passing via tipc link get command must follow above hierachy. Acked-by: Ying Xue Signed-off-by: Hoang Le Acked-by: Jon Maloy Signed-off-by: Stephen Hemminger --- tipc/link.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tipc/link.c b/tipc/link.c index 02f14aad..a2d7c001 100644 --- a/tipc/link.c +++ b/tipc/link.c @@ -97,6 +97,7 @@ static int cmd_link_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, { int prop; char buf[MNL_SOCKET_BUFFER_SIZE]; + struct nlattr *attrs; struct opt *opt; struct opt opts[] = { { "link", OPT_KEYVAL, NULL }, @@ -131,7 +132,9 @@ static int cmd_link_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, fprintf(stderr, "error, missing link\n"); return -EINVAL; } + attrs = mnl_attr_nest_start(nlh, TIPC_NLA_LINK); mnl_attr_put_strz(nlh, TIPC_NLA_LINK_NAME, opt->val); + mnl_attr_nest_end(nlh, attrs); return msg_doit(nlh, link_get_cb, &prop); } From 4be85d574e46591effc2fc1615f56108e111f8ba Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Fri, 8 Jun 2018 10:09:21 -0700 Subject: [PATCH 4/6] uapi: update bpf.h to include padding Last minute upstream 4.17 change. Signed-off-by: Stephen Hemminger --- include/uapi/linux/bpf.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 02b96cba..39e2543e 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -1017,6 +1017,7 @@ struct bpf_prog_info { __aligned_u64 map_ids; char name[BPF_OBJ_NAME_LEN]; __u32 ifindex; + __u32 :32; __u64 netns_dev; __u64 netns_ino; } __attribute__((aligned(8))); @@ -1030,6 +1031,7 @@ struct bpf_map_info { __u32 map_flags; char name[BPF_OBJ_NAME_LEN]; __u32 ifindex; + __u32 :32; __u64 netns_dev; __u64 netns_ino; } __attribute__((aligned(8))); From 2d3dd6f6c12ff4ad09eed9aea925aa5dee8bf865 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Fri, 8 Jun 2018 10:11:50 -0700 Subject: [PATCH 5/6] v4.17.0 --- include/SNAPSHOT.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/SNAPSHOT.h b/include/SNAPSHOT.h index fe39766b..168c25ce 100644 --- a/include/SNAPSHOT.h +++ b/include/SNAPSHOT.h @@ -1 +1 @@ -static const char SNAPSHOT[] = "180402"; +static const char SNAPSHOT[] = "180608"; From 776f1813b504b345708ad6720188de66f9ef2a16 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Fri, 8 Jun 2018 10:27:13 -0700 Subject: [PATCH 6/6] uapi: update headers from linux-net Signed-off-by: Stephen Hemminger --- include/uapi/linux/rtnetlink.h | 5 +++++ include/uapi/linux/types.h | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h index a501bc79..c3a7d8ec 100644 --- a/include/uapi/linux/rtnetlink.h +++ b/include/uapi/linux/rtnetlink.h @@ -254,6 +254,11 @@ enum { #define RTPROT_DHCP 16 /* DHCP client */ #define RTPROT_MROUTED 17 /* Multicast daemon */ #define RTPROT_BABEL 42 /* Babel daemon */ +#define RTPROT_BGP 186 /* BGP Routes */ +#define RTPROT_ISIS 187 /* ISIS Routes */ +#define RTPROT_OSPF 188 /* OSPF Routes */ +#define RTPROT_RIP 189 /* RIP Routes */ +#define RTPROT_EIGRP 192 /* EIGRP Routes */ /* rtm_scope diff --git a/include/uapi/linux/types.h b/include/uapi/linux/types.h index 5ea4daa7..999cb0fa 100644 --- a/include/uapi/linux/types.h +++ b/include/uapi/linux/types.h @@ -44,11 +44,7 @@ typedef __u32 __bitwise __wsum; #define __aligned_be64 __be64 __attribute__((aligned(8))) #define __aligned_le64 __le64 __attribute__((aligned(8))) -#ifdef __CHECK_POLL typedef unsigned __bitwise __poll_t; -#else -typedef unsigned __poll_t; -#endif #endif /* __ASSEMBLY__ */ #endif /* _LINUX_TYPES_H */