From e0dce0e5dc363b7e307984706c130f6ee769259b Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Thu, 6 Aug 2015 14:24:32 +0200 Subject: [PATCH 01/14] misc/ss: avoid NULL pointer dereference This was working before, but only if realloc a) succeeded and b) did not move the buffer to a different location. ''**buf = **new_buf' then writes the value of *new_buf's first field into that of *buf. Signed-off-by: Phil Sutter --- misc/ss.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/ss.c b/misc/ss.c index f59213b4..d271b950 100644 --- a/misc/ss.c +++ b/misc/ss.c @@ -597,7 +597,7 @@ static int find_entry(unsigned ino, char **buf, int type) fprintf(stderr, "ss: failed to malloc buffer\n"); abort(); } - **buf = **new_buf; + *buf = *new_buf; buf_len = new_buf_len; continue; } else { From 532ca40a52d4103816f2e50690a02e9dd6c1abe5 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Thu, 6 Aug 2015 14:24:33 +0200 Subject: [PATCH 02/14] misc/ss: simplify buffer realloc, fix checking realloc failure Signed-off-by: Phil Sutter --- misc/ss.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/misc/ss.c b/misc/ss.c index d271b950..e61fb2ed 100644 --- a/misc/ss.c +++ b/misc/ss.c @@ -550,7 +550,7 @@ static int find_entry(unsigned ino, char **buf, int type) struct user_ent *p; int cnt = 0; char *ptr; - char **new_buf = buf; + char *new_buf; int len, new_buf_len; int buf_used = 0; int buf_len = 0; @@ -592,12 +592,12 @@ static int find_entry(unsigned ino, char **buf, int type) if (len < 0 || len >= buf_len - buf_used) { new_buf_len = buf_len + ENTRY_BUF_SIZE; - *new_buf = realloc(*buf, new_buf_len); + new_buf = realloc(*buf, new_buf_len); if (!new_buf) { fprintf(stderr, "ss: failed to malloc buffer\n"); abort(); } - *buf = *new_buf; + *buf = new_buf; buf_len = new_buf_len; continue; } else { From b95d28c380c945ac760b128403dc82279cb9cc39 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Thu, 6 Aug 2015 14:24:34 +0200 Subject: [PATCH 03/14] misc/ss: add missing fclose() calls Signed-off-by: Phil Sutter --- misc/ss.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/misc/ss.c b/misc/ss.c index e61fb2ed..90c2eda4 100644 --- a/misc/ss.c +++ b/misc/ss.c @@ -3025,6 +3025,7 @@ static int packet_show_line(char *buf, const struct filter *f, int fam) static int packet_show(struct filter *f) { FILE *fp; + int rc = 0; if (!filter_af_get(f, AF_PACKET) || !(f->states & (1 << SS_CLOSE))) return 0; @@ -3036,9 +3037,10 @@ static int packet_show(struct filter *f) if ((fp = net_packet_open()) == NULL) return -1; if (generic_record_read(fp, packet_show_line, f, AF_PACKET)) - return -1; + rc = -1; - return 0; + fclose(fp); + return rc; } static int netlink_show_one(struct filter *f, @@ -3215,6 +3217,7 @@ static int netlink_show(struct filter *f) netlink_show_one(f, prot, pid, groups, 0, 0, 0, rq, wq, sk, cb); } + fclose(fp); return 0; } From 5950ba914e12b9c942e45e2dda6b1732a3efa058 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Thu, 6 Aug 2015 14:24:35 +0200 Subject: [PATCH 04/14] lib/namespace: don't leak fd in error case Signed-off-by: Phil Sutter --- lib/namespace.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/namespace.c b/lib/namespace.c index a61feb6a..81971652 100644 --- a/lib/namespace.c +++ b/lib/namespace.c @@ -58,32 +58,35 @@ int netns_switch(char *name) if (setns(netns, CLONE_NEWNET) < 0) { fprintf(stderr, "setting the network namespace \"%s\" failed: %s\n", name, strerror(errno)); - return -1; + goto fail_close; } if (unshare(CLONE_NEWNS) < 0) { fprintf(stderr, "unshare failed: %s\n", strerror(errno)); - return -1; + goto fail_close; } /* Don't let any mounts propagate back to the parent */ if (mount("", "/", "none", MS_SLAVE | MS_REC, NULL)) { fprintf(stderr, "\"mount --make-rslave /\" failed: %s\n", strerror(errno)); - return -1; + goto fail_close; } /* Mount a version of /sys that describes the network namespace */ if (umount2("/sys", MNT_DETACH) < 0) { fprintf(stderr, "umount of /sys failed: %s\n", strerror(errno)); - return -1; + goto fail_close; } if (mount(name, "/sys", "sysfs", 0, NULL) < 0) { fprintf(stderr, "mount of /sys failed: %s\n",strerror(errno)); - return -1; + goto fail_close; } /* Setup bind mounts for config files in /etc */ bind_etc(name); return 0; +fail_close: + close(netns); + return -1; } int netns_get_fd(const char *name) From a02371fb3831c8d3d9d53209f2389b250a1fb804 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Thu, 6 Aug 2015 14:24:36 +0200 Subject: [PATCH 05/14] misc/ss: fix memory leak in user_ent_hash_build() Signed-off-by: Phil Sutter --- misc/ss.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/misc/ss.c b/misc/ss.c index 90c2eda4..2f349622 100644 --- a/misc/ss.c +++ b/misc/ss.c @@ -483,8 +483,10 @@ static void user_ent_hash_build(void) sprintf(name + nameoff, "%d/fd/", pid); pos = strlen(name); - if ((dir1 = opendir(name)) == NULL) + if ((dir1 = opendir(name)) == NULL) { + free(pid_context); continue; + } process[0] = '\0'; p = process; From 892e21248cfdb8c1332d46a01df253eae748c9d8 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Thu, 13 Aug 2015 14:09:58 -0700 Subject: [PATCH 06/14] remove unnecessary extern No need for extern on function prototypes. --- include/dlfcn.h | 2 +- include/libnetlink.h | 77 +++++++++++++++++++++++--------------------- include/ll_map.h | 18 +++++------ include/namespace.h | 6 ++-- include/utils.h | 64 ++++++++++++++++++------------------ 5 files changed, 85 insertions(+), 82 deletions(-) diff --git a/include/dlfcn.h b/include/dlfcn.h index c54f8d8e..f15bc2c7 100644 --- a/include/dlfcn.h +++ b/include/dlfcn.h @@ -19,7 +19,7 @@ static inline void *dlopen(const char *file, int flag) return NULL; } -extern void *_dlsym(const char *sym); +void *_dlsym(const char *sym); static inline void *dlsym(void *handle, const char *sym) { if (handle != _FAKE_DLFCN_HDL) diff --git a/include/libnetlink.h b/include/libnetlink.h index 968034ba..0503dea5 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -26,20 +26,20 @@ struct rtnl_handle extern int rcvbuf; -extern int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions) +int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions) __attribute__((warn_unused_result)); -extern int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions, +int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions, int protocol) __attribute__((warn_unused_result)); -extern void rtnl_close(struct rtnl_handle *rth); -extern int rtnl_wilddump_request(struct rtnl_handle *rth, int fam, int type) +void rtnl_close(struct rtnl_handle *rth); +int rtnl_wilddump_request(struct rtnl_handle *rth, int fam, int type) __attribute__((warn_unused_result)); -extern int rtnl_wilddump_req_filter(struct rtnl_handle *rth, int fam, int type, +int rtnl_wilddump_req_filter(struct rtnl_handle *rth, int fam, int type, __u32 filt_mask) __attribute__((warn_unused_result)); -extern int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, +int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len) __attribute__((warn_unused_result)); @@ -60,40 +60,43 @@ struct rtnl_dump_filter_arg void *arg1; }; -extern int rtnl_dump_filter_l(struct rtnl_handle *rth, +int rtnl_dump_filter_l(struct rtnl_handle *rth, const struct rtnl_dump_filter_arg *arg); -extern int rtnl_dump_filter(struct rtnl_handle *rth, rtnl_filter_t filter, - void *arg); -extern int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, - struct nlmsghdr *answer, size_t len) +int rtnl_dump_filter(struct rtnl_handle *rth, rtnl_filter_t filter, void *arg); +int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, + struct nlmsghdr *answer, size_t len) __attribute__((warn_unused_result)); -extern int rtnl_send(struct rtnl_handle *rth, const void *buf, int) +int rtnl_send(struct rtnl_handle *rth, const void *buf, int) __attribute__((warn_unused_result)); -extern int rtnl_send_check(struct rtnl_handle *rth, const void *buf, int) +int rtnl_send_check(struct rtnl_handle *rth, const void *buf, int) __attribute__((warn_unused_result)); -extern int addattr(struct nlmsghdr *n, int maxlen, int type); -extern int addattr8(struct nlmsghdr *n, int maxlen, int type, __u8 data); -extern int addattr16(struct nlmsghdr *n, int maxlen, int type, __u16 data); -extern int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32 data); -extern int addattr64(struct nlmsghdr *n, int maxlen, int type, __u64 data); -extern int addattrstrz(struct nlmsghdr *n, int maxlen, int type, const char *data); +int addattr(struct nlmsghdr *n, int maxlen, int type); +int addattr8(struct nlmsghdr *n, int maxlen, int type, __u8 data); +int addattr16(struct nlmsghdr *n, int maxlen, int type, __u16 data); +int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32 data); +int addattr64(struct nlmsghdr *n, int maxlen, int type, __u64 data); +int addattrstrz(struct nlmsghdr *n, int maxlen, int type, const char *data); -extern int addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data, int alen); -extern int addraw_l(struct nlmsghdr *n, int maxlen, const void *data, int len); -extern struct rtattr *addattr_nest(struct nlmsghdr *n, int maxlen, int type); -extern int addattr_nest_end(struct nlmsghdr *n, struct rtattr *nest); -extern struct rtattr *addattr_nest_compat(struct nlmsghdr *n, int maxlen, int type, const void *data, int len); -extern int addattr_nest_compat_end(struct nlmsghdr *n, struct rtattr *nest); -extern int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data); -extern int rta_addattr_l(struct rtattr *rta, int maxlen, int type, const void *data, int alen); +int addattr_l(struct nlmsghdr *n, int maxlen, int type, + const void *data, int alen); +int addraw_l(struct nlmsghdr *n, int maxlen, const void *data, int len); +struct rtattr *addattr_nest(struct nlmsghdr *n, int maxlen, int type); +int addattr_nest_end(struct nlmsghdr *n, struct rtattr *nest); +struct rtattr *addattr_nest_compat(struct nlmsghdr *n, int maxlen, int type, + const void *data, int len); +int addattr_nest_compat_end(struct nlmsghdr *n, struct rtattr *nest); +int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data); +int rta_addattr_l(struct rtattr *rta, int maxlen, int type, + const void *data, int alen); -extern int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len); -extern int parse_rtattr_flags(struct rtattr *tb[], int max, struct rtattr *rta, +int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len); +int parse_rtattr_flags(struct rtattr *tb[], int max, struct rtattr *rta, int len, unsigned short flags); -extern int parse_rtattr_byindex(struct rtattr *tb[], int max, struct rtattr *rta, int len); -extern struct rtattr *parse_rtattr_one(int type, struct rtattr *rta, int len); -extern int __parse_rtattr_nested_compat(struct rtattr *tb[], int max, struct rtattr *rta, int len); +int parse_rtattr_byindex(struct rtattr *tb[], int max, + struct rtattr *rta, int len); +struct rtattr *parse_rtattr_one(int type, struct rtattr *rta, int len); +int __parse_rtattr_nested_compat(struct rtattr *tb[], int max, struct rtattr *rta, int len); #define parse_rtattr_nested(tb, max, rta) \ (parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta))) @@ -128,11 +131,11 @@ static inline const char *rta_getattr_str(const struct rtattr *rta) return (const char *)RTA_DATA(rta); } -extern int rtnl_listen_all_nsid(struct rtnl_handle *); -extern int rtnl_listen(struct rtnl_handle *, rtnl_listen_filter_t handler, - void *jarg); -extern int rtnl_from_file(FILE *, rtnl_listen_filter_t handler, - void *jarg); +int rtnl_listen_all_nsid(struct rtnl_handle *); +int rtnl_listen(struct rtnl_handle *, rtnl_listen_filter_t handler, + void *jarg); +int rtnl_from_file(FILE *, rtnl_listen_filter_t handler, + void *jarg); #define NLMSG_TAIL(nmsg) \ ((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len))) diff --git a/include/ll_map.h b/include/ll_map.h index b98a5714..949bfc3e 100644 --- a/include/ll_map.h +++ b/include/ll_map.h @@ -1,15 +1,15 @@ #ifndef __LL_MAP_H__ #define __LL_MAP_H__ 1 -extern int ll_remember_index(const struct sockaddr_nl *who, - struct nlmsghdr *n, void *arg); +int ll_remember_index(const struct sockaddr_nl *who, + struct nlmsghdr *n, void *arg); -extern void ll_init_map(struct rtnl_handle *rth); -extern unsigned ll_name_to_index(const char *name); -extern const char *ll_index_to_name(unsigned idx); -extern const char *ll_idx_n2a(unsigned idx, char *buf); -extern int ll_index_to_type(unsigned idx); -extern int ll_index_to_flags(unsigned idx); -extern unsigned namehash(const char *str); +void ll_init_map(struct rtnl_handle *rth); +unsigned ll_name_to_index(const char *name); +const char *ll_index_to_name(unsigned idx); +const char *ll_idx_n2a(unsigned idx, char *buf); +int ll_index_to_type(unsigned idx); +int ll_index_to_flags(unsigned idx); +unsigned namehash(const char *str); #endif /* __LL_MAP_H__ */ diff --git a/include/namespace.h b/include/namespace.h index 5add9d26..51324b21 100644 --- a/include/namespace.h +++ b/include/namespace.h @@ -43,9 +43,9 @@ static inline int setns(int fd, int nstype) } #endif /* HAVE_SETNS */ -extern int netns_switch(char *netns); -extern int netns_get_fd(const char *netns); -extern int netns_foreach(int (*func)(char *nsname, void *arg), void *arg); +int netns_switch(char *netns); +int netns_get_fd(const char *netns); +int netns_foreach(int (*func)(char *nsname, void *arg), void *arg); struct netns_func { int (*func)(char *nsname, void *arg); diff --git a/include/utils.h b/include/utils.h index b78817f4..95d162ce 100644 --- a/include/utils.h +++ b/include/utils.h @@ -42,7 +42,7 @@ extern bool do_all; #define SPRINT_BSIZE 64 #define SPRINT_BUF(x) char x[SPRINT_BSIZE] -extern void incomplete_command(void) __attribute__((noreturn)); +void incomplete_command(void) __attribute__((noreturn)); #define NEXT_ARG() do { argv++; if (--argc <= 0) incomplete_command(); } while(0) #define NEXT_ARG_OK() (argc - 1 > 0) @@ -85,47 +85,47 @@ struct ipx_addr { /* Maximum number of labels the mpls helpers support */ #define MPLS_MAX_LABELS 8 -extern __u32 get_addr32(const char *name); -extern int get_addr_1(inet_prefix *dst, const char *arg, int family); -extern int get_prefix_1(inet_prefix *dst, char *arg, int family); -extern int get_addr(inet_prefix *dst, const char *arg, int family); -extern int get_prefix(inet_prefix *dst, char *arg, int family); -extern int mask2bits(__u32 netmask); +__u32 get_addr32(const char *name); +int get_addr_1(inet_prefix *dst, const char *arg, int family); +int get_prefix_1(inet_prefix *dst, char *arg, int family); +int get_addr(inet_prefix *dst, const char *arg, int family); +int get_prefix(inet_prefix *dst, char *arg, int family); +int mask2bits(__u32 netmask); -extern int get_integer(int *val, const char *arg, int base); -extern int get_unsigned(unsigned *val, const char *arg, int base); -extern int get_time_rtt(unsigned *val, const char *arg, int *raw); +int get_integer(int *val, const char *arg, int base); +int get_unsigned(unsigned *val, const char *arg, int base); +int get_time_rtt(unsigned *val, const char *arg, int *raw); #define get_byte get_u8 #define get_ushort get_u16 #define get_short get_s16 -extern int get_u64(__u64 *val, const char *arg, int base); -extern int get_u32(__u32 *val, const char *arg, int base); -extern int get_s32(__s32 *val, const char *arg, int base); -extern int get_u16(__u16 *val, const char *arg, int base); -extern int get_s16(__s16 *val, const char *arg, int base); -extern int get_u8(__u8 *val, const char *arg, int base); -extern int get_s8(__s8 *val, const char *arg, int base); +int get_u64(__u64 *val, const char *arg, int base); +int get_u32(__u32 *val, const char *arg, int base); +int get_s32(__s32 *val, const char *arg, int base); +int get_u16(__u16 *val, const char *arg, int base); +int get_s16(__s16 *val, const char *arg, int base); +int get_u8(__u8 *val, const char *arg, int base); +int get_s8(__s8 *val, const char *arg, int base); -extern char* hexstring_n2a(const __u8 *str, int len, char *buf, int blen); -extern __u8* hexstring_a2n(const char *str, __u8 *buf, int blen); +char* hexstring_n2a(const __u8 *str, int len, char *buf, int blen); +__u8* hexstring_a2n(const char *str, __u8 *buf, int blen); -extern int af_bit_len(int af); -extern int af_byte_len(int af); +int af_bit_len(int af); +int af_byte_len(int af); -extern const char *format_host(int af, int len, const void *addr, +const char *format_host(int af, int len, const void *addr, char *buf, int buflen); -extern const char *rt_addr_n2a(int af, int len, const void *addr, +const char *rt_addr_n2a(int af, int len, const void *addr, char *buf, int buflen); -extern int read_family(const char *name); -extern const char *family_name(int family); +int read_family(const char *name); +const char *family_name(int family); void missarg(const char *) __attribute__((noreturn)); void invarg(const char *, const char *) __attribute__((noreturn)); void duparg(const char *, const char *) __attribute__((noreturn)); void duparg2(const char *, const char *) __attribute__((noreturn)); int matches(const char *arg, const char *pattern); -extern int inet_addr_match(const inet_prefix *a, const inet_prefix *b, int bits); +int inet_addr_match(const inet_prefix *a, const inet_prefix *b, int bits); const char *dnet_ntop(int af, const void *addr, char *str, size_t len); int dnet_pton(int af, const char *src, void *addr); @@ -137,7 +137,7 @@ const char *mpls_ntop(int af, const void *addr, char *str, size_t len); int mpls_pton(int af, const char *src, void *addr); extern int __iproute2_hz_internal; -extern int __get_hz(void); +__get_hz(void); static __inline__ int get_hz(void) { @@ -147,7 +147,7 @@ static __inline__ int get_hz(void) } extern int __iproute2_user_hz_internal; -extern int __get_user_hz(void); +int __get_user_hz(void); static __inline__ int get_user_hz(void) { @@ -191,16 +191,16 @@ void print_nlmsg_timestamp(FILE *fp, const struct nlmsghdr *n); #endif extern int cmdlineno; -extern ssize_t getcmdline(char **line, size_t *len, FILE *in); -extern int makeargs(char *line, char *argv[], int maxargs); -extern int inet_get_addr(const char *src, __u32 *dst, struct in6_addr *dst6); +ssize_t getcmdline(char **line, size_t *len, FILE *in); +int makeargs(char *line, char *argv[], int maxargs); +int inet_get_addr(const char *src, __u32 *dst, struct in6_addr *dst6); struct iplink_req; int iplink_parse(int argc, char **argv, struct iplink_req *req, char **name, char **type, char **link, char **dev, int *group, int *index); -extern int do_each_netns(int (*func)(char *nsname, void *arg), void *arg, +int do_each_netns(int (*func)(char *nsname, void *arg), void *arg, bool show_label); char *int_to_str(int val, char *buf); From ff1e35edf521ea3a74f457674c7f020b52000882 Mon Sep 17 00:00:00 2001 From: Zhang Shengju Date: Thu, 13 Aug 2015 06:41:50 +0000 Subject: [PATCH 07/14] ip-link: enhance prompt message Enhance promtp message for 'spoofchk' and 'query_rss' flag, and fix a typo. Signed-off-by: Zhang Shengju --- ip/iplink.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ip/iplink.c b/ip/iplink.c index 18368896..520f7508 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -329,7 +329,7 @@ static int iplink_parse_vf(int vf, int *argcp, char ***argvp, else if (matches(*argv, "off") == 0) ivs.setting = 0; else - invarg("Invalid \"spoofchk\" value\n", *argv); + return on_off("spoofchk", *argv); ivs.vf = vf; addattr_l(&req->n, sizeof(*req), IFLA_VF_SPOOFCHK, &ivs, sizeof(ivs)); @@ -341,7 +341,7 @@ static int iplink_parse_vf(int vf, int *argcp, char ***argvp, else if (matches(*argv, "off") == 0) ivs.setting = 0; else - invarg("Invalid \"query_rss\" value\n", *argv); + return on_off("query_rss", *argv); ivs.vf = vf; addattr_l(&req->n, sizeof(*req), IFLA_VF_RSS_QUERY_EN, &ivs, sizeof(ivs)); @@ -1092,7 +1092,7 @@ static int do_set(int argc, char **argv) } else if (strcmp(*argv, "off") == 0) { flags |= IFF_NOARP; } else - return on_off("noarp", *argv); + return on_off("arp", *argv); } else if (matches(*argv, "dynamic") == 0) { NEXT_ARG(); mask |= IFF_DYNAMIC; From 142434dc512fa62e32af3a82fffdd9862d44cb9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20=C5=A0imerda?= Date: Wed, 12 Aug 2015 22:04:06 +0200 Subject: [PATCH 08/14] ip: fix and extend documentation * Use unabbreviated `address` and `maddress` * Keep only `-n` and `-netns` for network namespace --- ip/ip.c | 4 ++-- man/man8/ip.8 | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ip/ip.c b/ip/ip.c index 0cf743f7..e75447e1 100644 --- a/ip/ip.c +++ b/ip/ip.c @@ -48,8 +48,8 @@ static void usage(void) fprintf(stderr, "Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }\n" " ip [ -force ] -batch filename\n" -"where OBJECT := { link | addr | addrlabel | route | rule | neigh | ntable |\n" -" tunnel | tuntap | maddr | mroute | mrule | monitor | xfrm |\n" +"where OBJECT := { link | address | addrlabel | route | rule | neighbor | ntable |\n" +" tunnel | tuntap | maddress | mroute | mrule | monitor | xfrm |\n" " netns | l2tp | fou | tcp_metrics | token | netconf }\n" " OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |\n" " -h[uman-readable] | -iec |\n" diff --git a/man/man8/ip.8 b/man/man8/ip.8 index 045414dd..9da086d3 100644 --- a/man/man8/ip.8 +++ b/man/man8/ip.8 @@ -19,8 +19,8 @@ ip \- show / manipulate routing, devices, policy routing and tunnels .ti -8 .IR OBJECT " := { " -.BR link " | " addr " | " addrlabel " | " route " | " rule " | " neigh " | "\ - ntable " | " tunnel " | " tuntap " | " maddr " | " mroute " | " mrule " | "\ +.BR link " | " address " | " addrlabel " | " route " | " rule " | " neigh " | "\ + ntable " | " tunnel " | " tuntap " | " maddress " | " mroute " | " mrule " | "\ monitor " | " xfrm " | " netns " | " l2tp " | " tcp_metrics " }" .sp @@ -67,7 +67,7 @@ Output more detailed information. .TP .BR "\-l" , " \-loops " -Specify maximum number of loops the 'ip addr flush' logic +Specify maximum number of loops the 'ip address flush' logic will attempt before giving up. The default is 10. Zero (0) means loop until all addresses are removed. @@ -143,7 +143,7 @@ use the system's name resolver to print DNS names instead of host addresses. .TP -.BR "\-n" , " \-net" , " \-netns " +.BR "\-n" , " \-netns " switches .B ip to the specified network namespace From 503aa4e20d0527b248594b4524356f1c604f7a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20=C5=A0imerda?= Date: Wed, 12 Aug 2015 22:04:07 +0200 Subject: [PATCH 09/14] ip-link: fix and extend documentation * Add `can` to list of supported link types * Document `addrgenmode` * Document `link-netnsid` * Document VLAN link type * Improve VXLAN link type documentation - Fix VXLAN srcport/dstport docs - Document `udpcsum`, `udp6zerocsumtx` and `udp6zerocsumrx` --- man/man8/ip-link.8.in | 112 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 108 insertions(+), 4 deletions(-) diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in index 74c764a6..df2fcce8 100644 --- a/man/man8/ip-link.8.in +++ b/man/man8/ip-link.8.in @@ -143,9 +143,13 @@ ip-link \- network device configuration ] | .br .B master -.IR DEVICE +.IR DEVICE " |" .br -.B nomaster +.B nomaster " |" +.br +.B addrgenmode { eui64 | none } +.br +.B link-netnsid ID .BR " }" @@ -185,6 +189,8 @@ Link types: .sp .B bond - Bonding device +.B can +- Controller Area Network interface .sp .B dummy - Dummy network interface @@ -265,6 +271,66 @@ specifies the number of receive queues for new device. .BI index " IDX " specifies the desired index of the new virtual device. The link creation fails, if the index is busy. +.TP +VLAN Type Support +For a link of type +.I VLAN +the following additional arguments are supported: + +.BI "ip link add +.BI link " DEVICE " +.BI name " NAME " +.BI type " vlan " +.R " [ " +.BI protocol " VLAN_PROTO " +.R " ] " +.BI id " VLANID " +.R " [ " +.BR reorder_hdr " { " on " | " off " } " +.R " ] " +.R " [ " +.BR gvrp " { " on " | " off " } " +.R " ] " +.R " [ " +.BR mvrp " { " on " | " off " } " +.R " ] " +.R " [ " +.BR loose_binding " { " on " | " off " } " +.R " ] " +.R " [ " +.BI ingress-qos-map " QOS-MAP " +.R " ] " +.R " [ " +.BI egress-qos-map " QOS-MAP " +.R " ] " + +.in +8 +.sp +.BI protocol " VLAN_PROTO " +- either 802.1Q or 802.1ad. + +.BI id " VLANID " +- specifies the VLAN Identifer to use. Note that numbers with a leading " 0 " or " 0x " are interpreted as octal or hexadeimal, respectively. + +.BR reorder_hdr " { " on " | " off " } " +- specifies whether ethernet headers are reordered or not. + +.BR gvrp " { " on " | " off " } " +- specifies whether this VLAN should be registered using GARP VLAN Registration Protocol. + +.BR mvrp " { " on " | " off " } " +- specifies whether this VLAN should be registered using Multiple VLAN Registration Protocol. + +.BR loose_binding " { " on " | " off " } " +- specifies whether the VLAN device state is bound to the physical device state. + +.BI ingress-qos-map " QOS-MAP " +- defines a mapping between priority code points on incoming frames. The format is FROM:TO with multiple mappings separated by spaces. + +.BI egress-qos-map " QOS-MAP " +- the same as ingress-qos-map but for outgoing frames. +.in -8 + .TP VXLAN Type Support For a link of type @@ -284,7 +350,9 @@ the following additional arguments are supported: .R " ] [ " .BI tos " TOS " .R " ] [ " -.BI port " MIN MAX " +.BI dstport " PORT " +.R " ] [ " +.BI srcport " MIN MAX " .R " ] [ " .I "[no]learning " .R " ] [ " @@ -296,6 +364,12 @@ the following additional arguments are supported: .R " ] [ " .I "[no]l3miss " .R " ] [ " +.I "[no]udpcsum " +.R " ] [ " +.I "[no]udp6zerocsumtx " +.R " ] [ " +.I "[no]udp6zerocsumrx " +.R " ] [ " .BI ageing " SECONDS " .R " ] [ " .BI maxaddress " NUMBER " @@ -340,7 +414,11 @@ parameter. - specifies the TOS value to use in outgoing packets. .sp -.BI port " MIN MAX" +.BI dstport " PORT" +- specifies the UDP destination port to communicate to the remote VXLAN tunnel endpoint. + +.sp +.BI srcport " MIN MAX" - specifies the range of port numbers to use as UDP source ports to communicate to the remote VXLAN tunnel endpoint. @@ -365,6 +443,18 @@ are entered into the VXLAN device forwarding database. .I [no]l3miss - specifies if netlink IP ADDR miss notifications are generated. +.sp +.I [no]udpcsum +- specifies if UDP checksum is filled in + +.sp +.I [no]udp6zerocsumtx +- specifies if UDP checksum is filled in + +.sp +.I [no]udp6zerocsumrx +- specifies if UDP checksum is received + .sp .BI ageing " SECONDS" - specifies the lifetime in seconds of FDB entries learnt by the kernel. @@ -750,6 +840,12 @@ tool can be used. But it allows to change network namespace only for physical de .BI alias " NAME" give the device a symbolic name for easy reference. +.TP +.BI group " GROUP" +specify the group the device belongs to. +The available groups are listed in file +.BR "@SYSCONFDIR@/group" . + .TP .BI vf " NUM" specify a Virtual Function device to be configured. The associated PF device @@ -829,6 +925,14 @@ set master device of the device (enslave device). .BI nomaster unset master device of the device (release device). +.TP +.BR "addrgenmode eui64 " or " addrgenmode none" +set IPv6 address generation mode + +.TP +.BR "link-netnsid " +set peer netnsid for a cross-netns interface + .PP .B Warning: If multiple parameter changes are requested, From 4e972d5ef41b28679a8125ed5289496284a9157f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20=C5=A0imerda?= Date: Wed, 12 Aug 2015 22:04:08 +0200 Subject: [PATCH 10/14] ip-address: fix and extend documentation * Improve manual page synopsis and built-it help * Use full subcommand names (e.g. 'address' and 'maddress') * Specify when IPv4, IPv6 or both are affected * Add lifetimes, home and nodad * Remove any remaining excess spaces Commit 43d29f7 substantially improves generated ip-address.8 instead of ip-address.8.in and commit e419f2d removes the generated one losing the improvements entirely. This commit recovers the lost changes, adapts them to the current manual page and adds more man page and help improvements. Original commit by: Kenyon Ralph --- ip/ipaddress.c | 16 +++--- man/man8/ip-address.8.in | 117 ++++++++++++++++++++++++++++++--------- 2 files changed, 100 insertions(+), 33 deletions(-) diff --git a/ip/ipaddress.c b/ip/ipaddress.c index b7b4e3e6..177b65a9 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -71,15 +71,15 @@ static void usage(void) if (do_link) { iplink_usage(); } - fprintf(stderr, "Usage: ip addr {add|change|replace} IFADDR dev STRING [ LIFETIME ]\n"); + fprintf(stderr, "Usage: ip address {add|change|replace} IFADDR dev IFNAME [ LIFETIME ]\n"); fprintf(stderr, " [ CONFFLAG-LIST ]\n"); - fprintf(stderr, " ip addr del IFADDR dev STRING [mngtmpaddr]\n"); - fprintf(stderr, " ip addr {show|save|flush} [ dev STRING ] [ scope SCOPE-ID ]\n"); - fprintf(stderr, " [ to PREFIX ] [ FLAG-LIST ] [ label PATTERN ] [up]\n"); - fprintf(stderr, " ip addr {showdump|restore}\n"); + fprintf(stderr, " ip address del IFADDR dev IFNAME [mngtmpaddr]\n"); + fprintf(stderr, " ip address {show|save|flush} [ dev IFNAME ] [ scope SCOPE-ID ]\n"); + fprintf(stderr, " [ to PREFIX ] [ FLAG-LIST ] [ label LABEL ] [up]\n"); + fprintf(stderr, " ip address {showdump|restore}\n"); fprintf(stderr, "IFADDR := PREFIX | ADDR peer PREFIX\n"); fprintf(stderr, " [ broadcast ADDR ] [ anycast ADDR ]\n"); - fprintf(stderr, " [ label STRING ] [ scope SCOPE-ID ]\n"); + fprintf(stderr, " [ label IFNAME ] [ scope SCOPE-ID ]\n"); fprintf(stderr, "SCOPE-ID := [ host | link | global | NUMBER ]\n"); fprintf(stderr, "FLAG-LIST := [ FLAG-LIST ] FLAG\n"); fprintf(stderr, "FLAG := [ permanent | dynamic | secondary | primary |\n"); @@ -1126,7 +1126,7 @@ static int ipadd_dump_check_magic(void) __u32 magic = 0; if (isatty(STDIN_FILENO)) { - fprintf(stderr, "Can't restore addr dump from a terminal\n"); + fprintf(stderr, "Can't restore address dump from a terminal\n"); return -1; } @@ -1878,6 +1878,6 @@ int do_ipaddr(int argc, char **argv) return ipaddr_restore(); if (matches(*argv, "help") == 0) usage(); - fprintf(stderr, "Command \"%s\" is unknown, try \"ip addr help\".\n", *argv); + fprintf(stderr, "Command \"%s\" is unknown, try \"ip address help\".\n", *argv); exit(-1); } diff --git a/man/man8/ip-address.8.in b/man/man8/ip-address.8.in index 6e46af88..2ea3e67b 100644 --- a/man/man8/ip-address.8.in +++ b/man/man8/ip-address.8.in @@ -14,18 +14,26 @@ ip-address \- protocol address management .sp .ti -8 -.BR "ip address" " { " add " | " del " } " -.IB IFADDR " dev " STRING +.BR "ip address" " { " add " | " change " | " replace " } " +.IB IFADDR " dev " IFNAME +.RI "[ " LIFETIME " ] [ " CONFFLAG-LIST " ]" .ti -8 -.BR "ip address" " { " show " | " flush " } [ " dev -.IR STRING " ] [ " +.BR "ip address del" +.IB IFADDR " dev " IFNAME " [ " mngtmpaddr " ]" + +.ti -8 +.BR "ip address" " { " show " | " save " | " flush " } [ " dev +.IR IFNAME " ] [ " .B scope .IR SCOPE-ID " ] [ " .B to .IR PREFIX " ] [ " FLAG-LIST " ] [ " .B label -.IR PATTERN " ]" +.IR PATTERN " ] [ " up " ]" + +.ti -8 +.BR "ip address" " { " showdump " | " restore " }" .ti -8 .IR IFADDR " := " PREFIX " | " ADDR @@ -36,7 +44,7 @@ ip-address \- protocol address management .B anycast .IR ADDR " ] [ " .B label -.IR STRING " ] [ " +.IR LABEL " ] [ " .B scope .IR SCOPE-ID " ]" @@ -52,15 +60,33 @@ ip-address \- protocol address management .IR FLAG " := " .RB "[ " permanent " | " dynamic " | " secondary " | " primary " | \ [ - ] " tentative " | [ - ] " deprecated " | [ - ] " dadfailed " | "\ -temporary " ]" +temporary " ] " CONFFLAG-LIST " ]" + +.ti -8 +.IR CONFFLAG-LIST " := [ " CONFFLAG-LIST " ] " CONFFLAG + +.ti -8 +.IR CONFFLAG " := " +.RB "[ " home " | " nodad " ]" + +.ti -8 +.IR LIFETIME " := [ " +.BI valid_lft " LFT" +.RB "| " preferred_lft +.IR LFT " ]" + +.ti -8 +.IR LFT " := [ " +.BR forever " |" +.IR SECONDS " ]" .SH "DESCRIPTION" The .B address -is a protocol (IP or IPv6) address attached -to a network device. Each device must have at least one address -to use the corresponding protocol. It is possible to have several -different addresses attached to one device. These addresses are not +is a protocol (IPv4 or IPv6) address attached +to a network device. Each device must have at least one address +to use the corresponding protocol. It is possible to have several +different addresses attached to one device. These addresses are not discriminated, so that the term .B alias is not quite appropriate for them and we do not use it in this document. @@ -73,7 +99,7 @@ and deletes old ones. .SS ip address add - add new protocol address. .TP -.BI dev " NAME" +.BI dev " IFNAME " the name of the device to add the address to. .TP @@ -107,7 +133,7 @@ instead of the broadcast address. In this case, the broadcast address is derived by setting/resetting the host bits of the interface prefix. .TP -.BI label " NAME" +.BI label " LABEL" Each address may be tagged with a label string. In order to preserve compatibility with Linux-2.0 net aliases, this string must coincide with the name of the device or must be prefixed @@ -125,7 +151,7 @@ Predefined scope values are: - the address is globally valid. .sp .B site -- (IPv6 only) the address is site local, i.e. it is +- (IPv6 only, deprecated) the address is site local, i.e. it is valid inside this site. .sp .B link @@ -135,6 +161,30 @@ valid inside this site. - the address is valid only inside this host. .in -8 +.TP +.BI valid_lft " LFT" +the valid lifetime of this address; see section 5.5.4 of +RFC 4862. When it expires, the address is removed by the kernel. +Defaults to +.BR "forever" . + +.TP +.BI preferred_lft " LFT" +the preferred lifetime of this address; see section 5.5.4 +of RFC 4862. When it expires, the address is no longer used for new +outgoing connections. Defaults to +.BR "forever" . + +.TP +.B home +(IPv6 only) designates this address the "home address" as defined in +RFC 6275. + +.TP +.B nodad +(IPv6 only) do not perform Duplicate Address Detection (RFC 4862) when +adding this address. + .SS ip address delete - delete protocol address .B Arguments: coincide with the arguments of @@ -145,7 +195,7 @@ If no arguments are given, the first address is deleted. .SS ip address show - look at protocol addresses .TP -.BI dev " NAME " (default) +.BI dev " IFNAME " (default) name of device. .TP @@ -219,36 +269,53 @@ The difference is that it does not run when no arguments are given. .PP .B Warning: -This command (and other +This command and other .B flush -commands described below) is pretty dangerous. If you make a mistake, -it will not forgive it, but will cruelly purge all the addresses. +commands are unforgiving. They will cruelly purge all the addresses. .PP With the .B -statistics option, the command becomes verbose. It prints out the number of deleted -addresses and the number of rounds made to flush the address list. If -this option is given twice, +addresses and the number of rounds made to flush the address list. +If this option is given twice, .B ip address flush also dumps all the deleted addresses in the format described in the previous subsection. .SH "EXAMPLES" .PP +ip address show +.RS 4 +Shows IPv4 and IPv6 addresses assigned to all network interfaces. The 'show' +subcommand can be omitted. +.RE +.PP +ip address show up +.RS 4 +Same as above except that only addresses assigned to active network interfaces +are shown. +.RE +.PP ip address show dev eth0 .RS 4 -Shows the addresses assigned to network interface eth0 +Shows IPv4 and IPv6 addresses assigned to network interface eth0. .RE .PP -ip addr add 2001:0db8:85a3::0370:7334/64 dev eth1 +ip address add 2001:0db8:85a3::0370:7334/64 dev eth1 .RS 4 -Adds an IPv6 address to network interface eth1 +Adds an IPv6 address to network interface eth1. .RE .PP -ip addr flush dev eth4 +ip address delete 2001:0db8:85a3::0370:7334/64 dev eth1 .RS 4 -Removes all addresses from device eth4 +Delete the IPv6 address added above. +.RE +.PP +ip address flush dev eth4 scope global +.RS 4 +Removes all global IPv4 and IPv6 addresses from device eth4. Without 'scope +global' it would remove all addresses including IPv6 link-local ones. .RE .SH SEE ALSO From 6a9ce30e78e3a7f8088f9cd084140e2f3e1039e3 Mon Sep 17 00:00:00 2001 From: Zhang Shengju Date: Thu, 13 Aug 2015 07:48:15 +0000 Subject: [PATCH 11/14] ip-link: remove unnecessary return Remove unnecessary retrun, because invarg() exit. Signed-off-by: Zhang Shengju --- ip/iplink_bridge.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/ip/iplink_bridge.c b/ip/iplink_bridge.c index e704e290..61e4cdab 100644 --- a/ip/iplink_bridge.c +++ b/ip/iplink_bridge.c @@ -42,47 +42,41 @@ static int bridge_parse_opt(struct link_util *lu, int argc, char **argv, while (argc > 0) { if (matches(*argv, "forward_delay") == 0) { NEXT_ARG(); - if (get_u32(&val, *argv, 0)) { + if (get_u32(&val, *argv, 0)) invarg("invalid forward_delay", *argv); - return -1; - } + addattr32(n, 1024, IFLA_BR_FORWARD_DELAY, val); } else if (matches(*argv, "hello_time") == 0) { NEXT_ARG(); - if (get_u32(&val, *argv, 0)) { + if (get_u32(&val, *argv, 0)) invarg("invalid hello_time", *argv); - return -1; - } + addattr32(n, 1024, IFLA_BR_HELLO_TIME, val); } else if (matches(*argv, "max_age") == 0) { NEXT_ARG(); - if (get_u32(&val, *argv, 0)) { + if (get_u32(&val, *argv, 0)) invarg("invalid max_age", *argv); - return -1; - } + addattr32(n, 1024, IFLA_BR_MAX_AGE, val); } else if (matches(*argv, "ageing_time") == 0) { NEXT_ARG(); - if (get_u32(&val, *argv, 0)) { + if (get_u32(&val, *argv, 0)) invarg("invalid ageing_time", *argv); - return -1; - } + addattr32(n, 1024, IFLA_BR_AGEING_TIME, val); } else if (matches(*argv, "stp_state") == 0) { NEXT_ARG(); - if (get_u32(&val, *argv, 0)) { + if (get_u32(&val, *argv, 0)) invarg("invalid stp_state", *argv); - return -1; - } + addattr32(n, 1024, IFLA_BR_STP_STATE, val); } else if (matches(*argv, "priority") == 0) { __u16 prio; NEXT_ARG(); - if (get_u16(&prio, *argv, 0)) { + if (get_u16(&prio, *argv, 0)) invarg("invalid priority", *argv); - return -1; - } + addattr16(n, 1024, IFLA_BR_PRIORITY, prio); } else if (matches(*argv, "help") == 0) { explain(); From bcb4a7aa5b267c3e5c15fc7272e779929e6d32de Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Thu, 13 Aug 2015 14:20:40 -0700 Subject: [PATCH 12/14] tc: fix return after invarg --- tc/tc_stab.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/tc/tc_stab.c b/tc/tc_stab.c index a8404f8e..286681f3 100644 --- a/tc/tc_stab.c +++ b/tc/tc_stab.c @@ -67,42 +67,32 @@ int parse_size_table(int *argcp, char ***argvp, struct tc_sizespec *sp) NEXT_ARG(); if (s.mtu) duparg("mtu", *argv); - if (get_u32(&s.mtu, *argv, 10)) { + if (get_u32(&s.mtu, *argv, 10)) invarg("mtu", "invalid mtu"); - return -1; - } } else if (matches(*argv, "mpu") == 0) { NEXT_ARG(); if (s.mpu) duparg("mpu", *argv); - if (get_u32(&s.mpu, *argv, 10)) { + if (get_u32(&s.mpu, *argv, 10)) invarg("mpu", "invalid mpu"); - return -1; - } } else if (matches(*argv, "overhead") == 0) { NEXT_ARG(); if (s.overhead) duparg("overhead", *argv); - if (get_integer(&s.overhead, *argv, 10)) { + if (get_integer(&s.overhead, *argv, 10)) invarg("overhead", "invalid overhead"); - return -1; - } } else if (matches(*argv, "tsize") == 0) { NEXT_ARG(); if (s.tsize) duparg("tsize", *argv); - if (get_u32(&s.tsize, *argv, 10)) { + if (get_u32(&s.tsize, *argv, 10)) invarg("tsize", "invalid table size"); - return -1; - } } else if (matches(*argv, "linklayer") == 0) { NEXT_ARG(); if (s.linklayer != LINKLAYER_UNSPEC) duparg("linklayer", *argv); - if (get_linklayer(&s.linklayer, *argv)) { + if (get_linklayer(&s.linklayer, *argv)) invarg("linklayer", "invalid linklayer"); - return -1; - } } else break; argc--; argv++; From e0f229fb7534991f7f1b4ca16a4fcc091a8d50af Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Thu, 13 Aug 2015 14:20:54 -0700 Subject: [PATCH 13/14] bond: fix return after invarg --- ip/iplink_bond.c | 95 ++++++++++++++++-------------------------------- 1 file changed, 32 insertions(+), 63 deletions(-) diff --git a/ip/iplink_bond.c b/ip/iplink_bond.c index 2a9783e4..2399f922 100644 --- a/ip/iplink_bond.c +++ b/ip/iplink_bond.c @@ -170,10 +170,8 @@ static int bond_parse_opt(struct link_util *lu, int argc, char **argv, while (argc > 0) { if (matches(*argv, "mode") == 0) { NEXT_ARG(); - if (get_index(mode_tbl, *argv) < 0) { + if (get_index(mode_tbl, *argv) < 0) invarg("invalid mode", *argv); - return -1; - } mode = get_index(mode_tbl, *argv); addattr8(n, 1024, IFLA_BOND_MODE, mode); } else if (matches(*argv, "active_slave") == 0) { @@ -186,38 +184,28 @@ static int bond_parse_opt(struct link_util *lu, int argc, char **argv, addattr32(n, 1024, IFLA_BOND_ACTIVE_SLAVE, 0); } else if (matches(*argv, "miimon") == 0) { NEXT_ARG(); - if (get_u32(&miimon, *argv, 0)) { + if (get_u32(&miimon, *argv, 0)) invarg("invalid miimon", *argv); - return -1; - } addattr32(n, 1024, IFLA_BOND_MIIMON, miimon); } else if (matches(*argv, "updelay") == 0) { NEXT_ARG(); - if (get_u32(&updelay, *argv, 0)) { + if (get_u32(&updelay, *argv, 0)) invarg("invalid updelay", *argv); - return -1; - } addattr32(n, 1024, IFLA_BOND_UPDELAY, updelay); } else if (matches(*argv, "downdelay") == 0) { NEXT_ARG(); - if (get_u32(&downdelay, *argv, 0)) { + if (get_u32(&downdelay, *argv, 0)) invarg("invalid downdelay", *argv); - return -1; - } addattr32(n, 1024, IFLA_BOND_DOWNDELAY, downdelay); } else if (matches(*argv, "use_carrier") == 0) { NEXT_ARG(); - if (get_u8(&use_carrier, *argv, 0)) { + if (get_u8(&use_carrier, *argv, 0)) invarg("invalid use_carrier", *argv); - return -1; - } addattr8(n, 1024, IFLA_BOND_USE_CARRIER, use_carrier); } else if (matches(*argv, "arp_interval") == 0) { NEXT_ARG(); - if (get_u32(&arp_interval, *argv, 0)) { + if (get_u32(&arp_interval, *argv, 0)) invarg("invalid arp_interval", *argv); - return -1; - } addattr32(n, 1024, IFLA_BOND_ARP_INTERVAL, arp_interval); } else if (matches(*argv, "arp_ip_target") == 0) { struct rtattr * nest = addattr_nest(n, 1024, @@ -238,18 +226,14 @@ static int bond_parse_opt(struct link_util *lu, int argc, char **argv, addattr_nest_end(n, nest); } else if (matches(*argv, "arp_validate") == 0) { NEXT_ARG(); - if (get_index(arp_validate_tbl, *argv) < 0) { + if (get_index(arp_validate_tbl, *argv) < 0) invarg("invalid arp_validate", *argv); - return -1; - } arp_validate = get_index(arp_validate_tbl, *argv); addattr32(n, 1024, IFLA_BOND_ARP_VALIDATE, arp_validate); } else if (matches(*argv, "arp_all_targets") == 0) { NEXT_ARG(); - if (get_index(arp_all_targets_tbl, *argv) < 0) { + if (get_index(arp_all_targets_tbl, *argv) < 0) invarg("invalid arp_all_targets", *argv); - return -1; - } arp_all_targets = get_index(arp_all_targets_tbl, *argv); addattr32(n, 1024, IFLA_BOND_ARP_ALL_TARGETS, arp_all_targets); } else if (matches(*argv, "primary") == 0) { @@ -260,108 +244,93 @@ static int bond_parse_opt(struct link_util *lu, int argc, char **argv, addattr32(n, 1024, IFLA_BOND_PRIMARY, ifindex); } else if (matches(*argv, "primary_reselect") == 0) { NEXT_ARG(); - if (get_index(primary_reselect_tbl, *argv) < 0) { + if (get_index(primary_reselect_tbl, *argv) < 0) invarg("invalid primary_reselect", *argv); - return -1; - } primary_reselect = get_index(primary_reselect_tbl, *argv); addattr8(n, 1024, IFLA_BOND_PRIMARY_RESELECT, primary_reselect); } else if (matches(*argv, "fail_over_mac") == 0) { NEXT_ARG(); - if (get_index(fail_over_mac_tbl, *argv) < 0) { + if (get_index(fail_over_mac_tbl, *argv) < 0) invarg("invalid fail_over_mac", *argv); - return -1; - } fail_over_mac = get_index(fail_over_mac_tbl, *argv); addattr8(n, 1024, IFLA_BOND_FAIL_OVER_MAC, fail_over_mac); } else if (matches(*argv, "xmit_hash_policy") == 0) { NEXT_ARG(); - if (get_index(xmit_hash_policy_tbl, *argv) < 0) { + if (get_index(xmit_hash_policy_tbl, *argv) < 0) invarg("invalid xmit_hash_policy", *argv); - return -1; - } + xmit_hash_policy = get_index(xmit_hash_policy_tbl, *argv); addattr8(n, 1024, IFLA_BOND_XMIT_HASH_POLICY, xmit_hash_policy); } else if (matches(*argv, "resend_igmp") == 0) { NEXT_ARG(); - if (get_u32(&resend_igmp, *argv, 0)) { + if (get_u32(&resend_igmp, *argv, 0)) invarg("invalid resend_igmp", *argv); - return -1; - } + addattr32(n, 1024, IFLA_BOND_RESEND_IGMP, resend_igmp); } else if (matches(*argv, "num_grat_arp") == 0 || matches(*argv, "num_unsol_na") == 0) { NEXT_ARG(); - if (get_u8(&num_peer_notif, *argv, 0)) { + if (get_u8(&num_peer_notif, *argv, 0)) invarg("invalid num_grat_arp|num_unsol_na", *argv); - return -1; - } + addattr8(n, 1024, IFLA_BOND_NUM_PEER_NOTIF, num_peer_notif); } else if (matches(*argv, "all_slaves_active") == 0) { NEXT_ARG(); - if (get_u8(&all_slaves_active, *argv, 0)) { + if (get_u8(&all_slaves_active, *argv, 0)) invarg("invalid all_slaves_active", *argv); - return -1; - } + addattr8(n, 1024, IFLA_BOND_ALL_SLAVES_ACTIVE, all_slaves_active); } else if (matches(*argv, "min_links") == 0) { NEXT_ARG(); - if (get_u32(&min_links, *argv, 0)) { + if (get_u32(&min_links, *argv, 0)) invarg("invalid min_links", *argv); - return -1; - } + addattr32(n, 1024, IFLA_BOND_MIN_LINKS, min_links); } else if (matches(*argv, "lp_interval") == 0) { NEXT_ARG(); - if (get_u32(&lp_interval, *argv, 0)) { + if (get_u32(&lp_interval, *argv, 0)) invarg("invalid lp_interval", *argv); - return -1; - } + addattr32(n, 1024, IFLA_BOND_LP_INTERVAL, lp_interval); } else if (matches(*argv, "packets_per_slave") == 0) { NEXT_ARG(); - if (get_u32(&packets_per_slave, *argv, 0)) { + if (get_u32(&packets_per_slave, *argv, 0)) invarg("invalid packets_per_slave", *argv); - return -1; - } + addattr32(n, 1024, IFLA_BOND_PACKETS_PER_SLAVE, packets_per_slave); } else if (matches(*argv, "lacp_rate") == 0) { NEXT_ARG(); - if (get_index(lacp_rate_tbl, *argv) < 0) { + if (get_index(lacp_rate_tbl, *argv) < 0) invarg("invalid lacp_rate", *argv); - return -1; - } + lacp_rate = get_index(lacp_rate_tbl, *argv); addattr8(n, 1024, IFLA_BOND_AD_LACP_RATE, lacp_rate); } else if (matches(*argv, "ad_select") == 0) { NEXT_ARG(); - if (get_index(ad_select_tbl, *argv) < 0) { + if (get_index(ad_select_tbl, *argv) < 0) invarg("invalid ad_select", *argv); - return -1; - } + ad_select = get_index(ad_select_tbl, *argv); addattr8(n, 1024, IFLA_BOND_AD_SELECT, ad_select); } else if (matches(*argv, "ad_user_port_key") == 0) { NEXT_ARG(); - if (get_u16(&ad_user_port_key, *argv, 0)) { + if (get_u16(&ad_user_port_key, *argv, 0)) invarg("invalid ad_user_port_key", *argv); - return -1; - } + addattr16(n, 1024, IFLA_BOND_AD_USER_PORT_KEY, ad_user_port_key); } else if (matches(*argv, "ad_actor_sys_prio") == 0) { NEXT_ARG(); - if (get_u16(&ad_actor_sys_prio, *argv, 0)) { + if (get_u16(&ad_actor_sys_prio, *argv, 0)) invarg("invalid ad_actor_sys_prio", *argv); - return -1; - } + addattr16(n, 1024, IFLA_BOND_AD_ACTOR_SYS_PRIO, ad_actor_sys_prio); } else if (matches(*argv, "ad_actor_system") == 0) { From e3c27c2db68d2dc0e9816fd70d80fda7f9aea2ec Mon Sep 17 00:00:00 2001 From: Zhang Shengju Date: Fri, 14 Aug 2015 01:36:20 +0000 Subject: [PATCH 14/14] utils: add missing return value Add missing return value to fix warnings Signed-off-by: Zhang Shengju --- include/utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/utils.h b/include/utils.h index 95d162ce..0c57ccdc 100644 --- a/include/utils.h +++ b/include/utils.h @@ -137,7 +137,7 @@ const char *mpls_ntop(int af, const void *addr, char *str, size_t len); int mpls_pton(int af, const char *src, void *addr); extern int __iproute2_hz_internal; -__get_hz(void); +int __get_hz(void); static __inline__ int get_hz(void) {