From 2f29d6bb5089271988a820d1f9596f9973ee2e4d Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Wed, 12 Aug 2015 08:35:54 -0700 Subject: [PATCH 1/6] ipnetns: make net namespace cache variable size Save some space by using variable size for nsid cache elements. Signed-off-by: Stephen Hemminger --- ip/ipnetns.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ip/ipnetns.c b/ip/ipnetns.c index 3b704a45..088096f6 100644 --- a/ip/ipnetns.c +++ b/ip/ipnetns.c @@ -139,7 +139,7 @@ struct nsid_cache { struct hlist_node nsid_hash; struct hlist_node name_hash; int nsid; - char name[NAME_MAX]; + char name[0]; }; #define NSIDMAP_SIZE 128 @@ -164,7 +164,7 @@ static struct nsid_cache *netns_map_get_by_nsid(int nsid) return NULL; } -static int netns_map_add(int nsid, char *name) +static int netns_map_add(int nsid, const char *name) { struct nsid_cache *c; uint32_t h; @@ -172,7 +172,7 @@ static int netns_map_add(int nsid, char *name) if (netns_map_get_by_nsid(nsid) != NULL) return -EEXIST; - c = malloc(sizeof(*c)); + c = malloc(sizeof(*c) + strlen(name)); if (c == NULL) { perror("malloc"); return -ENOMEM; From e52f3ef7113ff6a86a0020d3dd2eae6c1c6dc8f4 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Tue, 11 Aug 2015 19:14:11 +0200 Subject: [PATCH 2/6] ip-link: fix minor typo in manpage Change '-human-readble' to '-human-readable'. Signed-off-by: Phil Sutter --- man/man8/ip-link.8.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in index 372e6c6f..74c764a6 100644 --- a/man/man8/ip-link.8.in +++ b/man/man8/ip-link.8.in @@ -881,7 +881,7 @@ output more statistics about packet usage. output more detailed information. .TP -.BR "\-h", " \-human", " \-human-readble" +.BR "\-h", " \-human", " \-human-readable" output statistics with human readable values number followed by suffix .TP From d8cf93de04d9372f478fc2e59e2fe8bce1953b7a Mon Sep 17 00:00:00 2001 From: Zhang Shengju Date: Wed, 12 Aug 2015 06:03:22 +0000 Subject: [PATCH 3/6] iplink: add missing link type Add missing link type "bridge_slave". Signed-off-by: Zhang Shengju --- ip/iplink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ip/iplink.c b/ip/iplink.c index e296e6f6..a6378e2b 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -93,7 +93,7 @@ void iplink_usage(void) fprintf(stderr, "TYPE := { vlan | veth | vcan | dummy | ifb | macvlan | macvtap |\n"); fprintf(stderr, " bridge | bond | ipoib | ip6tnl | ipip | sit | vxlan |\n"); fprintf(stderr, " gre | gretap | ip6gre | ip6gretap | vti | nlmon |\n"); - fprintf(stderr, " bond_slave | ipvlan | geneve }\n"); + fprintf(stderr, " bond_slave | ipvlan | geneve | bridge_slave }\n"); } exit(-1); } From 43367ef7eb0473ea4ecdc3925f076107f05873a0 Mon Sep 17 00:00:00 2001 From: Zhang Shengju Date: Wed, 12 Aug 2015 06:03:23 +0000 Subject: [PATCH 4/6] iplink: use the short format to print help info Allow to print link type usage by: ip link help bridge Signed-off-by: Zhang Shengju --- ip/iplink_bridge.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ip/iplink_bridge.c b/ip/iplink_bridge.c index 297160c4..1e699601 100644 --- a/ip/iplink_bridge.c +++ b/ip/iplink_bridge.c @@ -17,9 +17,9 @@ #include "utils.h" #include "ip_common.h" -static void explain(void) +static void print_explain(FILE *f) { - fprintf(stderr, + fprintf(f, "Usage: ... bridge [ forward_delay FORWARD_DELAY ]\n" " [ hello_time HELLO_TIME ]\n" " [ max_age MAX_AGE ]\n" @@ -29,6 +29,11 @@ static void explain(void) ); } +static void explain(void) +{ + print_explain(stderr); +} + static int bridge_parse_opt(struct link_util *lu, int argc, char **argv, struct nlmsghdr *n) { @@ -111,9 +116,16 @@ static void bridge_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) rta_getattr_u32(tb[IFLA_BR_MAX_AGE])); } +static void bridge_print_help(struct link_util *lu, int argc, char **argv, + FILE *f) +{ + print_explain(f); +} + struct link_util bridge_link_util = { .id = "bridge", .maxattr = IFLA_BR_MAX, .parse_opt = bridge_parse_opt, .print_opt = bridge_print_opt, + .print_help = bridge_print_help, }; From a560d850d9cd24b06281897c97eb6afef3f00d8b Mon Sep 17 00:00:00 2001 From: Zhang Shengju Date: Wed, 12 Aug 2015 06:03:24 +0000 Subject: [PATCH 5/6] iplink: shortify printing the usage of link type Allow to print link type usage by: ip link help bridge_slave Signed-off-by: Zhang Shengju --- ip/iplink_bridge_slave.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ip/iplink_bridge_slave.c b/ip/iplink_bridge_slave.c index a2851855..4593872e 100644 --- a/ip/iplink_bridge_slave.c +++ b/ip/iplink_bridge_slave.c @@ -19,9 +19,9 @@ #include "utils.h" #include "ip_common.h" -static void explain(void) +static void print_explain(FILE *f) { - fprintf(stderr, + fprintf(f, "Usage: ... bridge_slave [ state STATE ] [ priority PRIO ] [cost COST ]\n" " [ guard {on | off} ]\n" " [ hairpin {on | off} ] \n" @@ -32,6 +32,11 @@ static void explain(void) ); } +static void explain(void) +{ + print_explain(stderr); +} + static const char *port_states[] = { [BR_STATE_DISABLED] = "disabled", [BR_STATE_LISTENING] = "listening", @@ -172,10 +177,17 @@ static int bridge_slave_parse_opt(struct link_util *lu, int argc, char **argv, return 0; } +static void bridge_slave_print_help(struct link_util *lu, int argc, char **argv, + FILE *f) +{ + print_explain(f); +} + struct link_util bridge_slave_link_util = { .id = "bridge", .maxattr = IFLA_BRPORT_MAX, .print_opt = bridge_slave_print_opt, .parse_opt = bridge_slave_parse_opt, + .print_help = bridge_slave_print_help, .slave = true, }; From e543a6a8a082937b89a9e449ec5a54ae395a211f Mon Sep 17 00:00:00 2001 From: Zhang Shengju Date: Wed, 12 Aug 2015 06:29:59 +0000 Subject: [PATCH 6/6] ip-link: fix a typo in help message fix a typo: "noarp" -> "arp" Signed-off-by: Zhang Shengju --- ip/iplink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ip/iplink.c b/ip/iplink.c index a6378e2b..18368896 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -507,7 +507,7 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, } else if (strcmp(*argv, "off") == 0) { req->i.ifi_flags |= IFF_NOARP; } else - return on_off("noarp", *argv); + return on_off("arp", *argv); } else if (strcmp(*argv, "vf") == 0) { struct rtattr *vflist; NEXT_ARG();