Merge branch 'master' into net-next

This commit is contained in:
Stephen Hemminger 2017-08-18 09:43:00 -07:00
commit fa93d9a8aa
10 changed files with 71 additions and 43 deletions

View File

@ -532,7 +532,7 @@ cbq_off () {
### Prefixed message ### Prefixed message
cbq_message () { cbq_message () {
echo -e "**CBQ: $@" echo -e "**CBQ: $*"
} # cbq_message } # cbq_message
### Failure message ### Failure message
@ -560,15 +560,15 @@ cbq_time2abs () {
### Display CBQ setup ### Display CBQ setup
cbq_show () { cbq_show () {
for dev in `cbq_device_list`; do for dev in `cbq_device_list`; do
[ `tc qdisc show dev $dev| wc -l` -eq 0 ] && continue [ "`tc qdisc show dev $dev| wc -l`" -eq 0 ] && continue
echo -e "### $dev: queueing disciplines\n" echo -e "### $dev: queueing disciplines\n"
tc $1 qdisc show dev $dev; echo tc $1 qdisc show dev $dev; echo
[ `tc class show dev $dev| wc -l` -eq 0 ] && continue [ "`tc class show dev $dev| wc -l`" -eq 0 ] && continue
echo -e "### $dev: traffic classes\n" echo -e "### $dev: traffic classes\n"
tc $1 class show dev $dev; echo tc $1 class show dev $dev; echo
[ `tc filter show dev $dev| wc -l` -eq 0 ] && continue [ "`tc filter show dev $dev| wc -l`" -eq 0 ] && continue
echo -e "### $dev: filtering rules\n" echo -e "### $dev: filtering rules\n"
tc $1 filter show dev $dev; echo tc $1 filter show dev $dev; echo
done done
@ -585,7 +585,7 @@ cbq_init () {
### Gather all DEVICE fields from $1/cbq-* ### Gather all DEVICE fields from $1/cbq-*
DEVFIELDS=`find $1 -maxdepth 1 \( -type f -or -type l \) -name 'cbq-*' \ DEVFIELDS=`find $1 -maxdepth 1 \( -type f -or -type l \) -name 'cbq-*' \
-not -name '*~' | xargs sed -n 's/#.*//; \ -not -name '*~' -print0 | xargs -0 sed -n 's/#.*//; \
s/[[:space:]]//g; /^DEVICE=[^,]*,[^,]*\(,[^,]*\)\?/ \ s/[[:space:]]//g; /^DEVICE=[^,]*,[^,]*\(,[^,]*\)\?/ \
{ s/.*=//; p; }'| sort -u` { s/.*=//; p; }'| sort -u`
[ -z "$DEVFIELDS" ] && [ -z "$DEVFIELDS" ] &&
@ -593,7 +593,7 @@ cbq_init () {
### Check for different DEVICE fields for the same device ### Check for different DEVICE fields for the same device
DEVICES=`echo "$DEVFIELDS"| sed 's/,.*//'| sort -u` DEVICES=`echo "$DEVFIELDS"| sed 's/,.*//'| sort -u`
[ `echo "$DEVICES"| wc -l` -ne `echo "$DEVFIELDS"| wc -l` ] && [ "`echo "$DEVICES"| wc -l`" -ne "`echo "$DEVFIELDS"| wc -l`" ] &&
cbq_failure "different DEVICE fields for single device!\n$DEVFIELDS" cbq_failure "different DEVICE fields for single device!\n$DEVFIELDS"
} # cbq_init } # cbq_init
@ -618,7 +618,7 @@ cbq_load_class () {
PRIO_MARK=$PRIO_MARK_DEFAULT PRIO_MARK=$PRIO_MARK_DEFAULT
PRIO_REALM=$PRIO_REALM_DEFAULT PRIO_REALM=$PRIO_REALM_DEFAULT
eval `echo "$CFILE"| grep -E "^($CBQ_WORDS)="` eval "`echo "$CFILE"| grep -E "^($CBQ_WORDS)="`"
### Require RATE/WEIGHT ### Require RATE/WEIGHT
[ -z "$RATE" -o -z "$WEIGHT" ] && [ -z "$RATE" -o -z "$WEIGHT" ] &&
@ -661,7 +661,7 @@ if [ "$1" = "compile" ]; then
### echo-only version of "tc" command ### echo-only version of "tc" command
tc () { tc () {
echo "$TC $@" echo "$TC $*"
} # tc } # tc
elif [ -n "$CBQ_DEBUG" ]; then elif [ -n "$CBQ_DEBUG" ]; then
@ -669,13 +669,13 @@ elif [ -n "$CBQ_DEBUG" ]; then
### Logging version of "ip" command ### Logging version of "ip" command
ip () { ip () {
echo -e "\n# ip $@" >> $CBQ_DEBUG echo -e "\n# ip $*" >> $CBQ_DEBUG
$IP "$@" 2>&1 | tee -a $CBQ_DEBUG $IP "$@" 2>&1 | tee -a $CBQ_DEBUG
} # ip } # ip
### Logging version of "tc" command ### Logging version of "tc" command
tc () { tc () {
echo -e "\n# tc $@" >> $CBQ_DEBUG echo -e "\n# tc $*" >> $CBQ_DEBUG
$TC "$@" 2>&1 | tee -a $CBQ_DEBUG $TC "$@" 2>&1 | tee -a $CBQ_DEBUG
} # tc } # tc
else else
@ -711,8 +711,8 @@ if [ "$1" != "compile" -a "$2" != "nocache" -a -z "$CBQ_DEBUG" ]; then
### validate the cache ### validate the cache
[ "$2" = "invalidate" -o ! -f $CBQ_CACHE ] && VALID=0 [ "$2" = "invalidate" -o ! -f $CBQ_CACHE ] && VALID=0
if [ $VALID -eq 1 ]; then if [ $VALID -eq 1 ]; then
[ `find $CBQ_PATH -maxdepth 1 -newer $CBQ_CACHE| \ [ "`find $CBQ_PATH -maxdepth 1 -newer $CBQ_CACHE| \
wc -l` -gt 0 ] && VALID=0 wc -l`" -gt 0 ] && VALID=0
fi fi
### compile the config if the cache is invalid ### compile the config if the cache is invalid

View File

@ -131,7 +131,7 @@ noarp=$?
ip route add unreachable 224.0.0.0/24 >& /dev/null ip route add unreachable 224.0.0.0/24 >& /dev/null
ip route add unreachable 255.255.255.255 >& /dev/null ip route add unreachable 255.255.255.255 >& /dev/null
if [ `ip link ls $dev | grep -c MULTICAST` -ge 1 ]; then if [ "`ip link ls $dev | grep -c MULTICAST`" -ge 1 ]; then
ip route add 224.0.0.0/4 dev $dev scope global >& /dev/null ip route add 224.0.0.0/4 dev $dev scope global >& /dev/null
fi fi

View File

@ -268,7 +268,7 @@ static char *ila_csum_mode2name(__u8 csum_mode)
} }
} }
static __u8 ila_csum_name2mode(char *name) static int ila_csum_name2mode(char *name)
{ {
if (strcmp(name, "adj-transport") == 0) if (strcmp(name, "adj-transport") == 0)
return ILA_CSUM_ADJUST_TRANSPORT; return ILA_CSUM_ADJUST_TRANSPORT;
@ -742,7 +742,7 @@ static int parse_encap_ila(struct rtattr *rta, size_t len,
while (argc > 0) { while (argc > 0) {
if (strcmp(*argv, "csum-mode") == 0) { if (strcmp(*argv, "csum-mode") == 0) {
__u8 csum_mode; int csum_mode;
NEXT_ARG(); NEXT_ARG();
@ -751,7 +751,8 @@ static int parse_encap_ila(struct rtattr *rta, size_t len,
invarg("\"csum-mode\" value is invalid\n", invarg("\"csum-mode\" value is invalid\n",
*argv); *argv);
rta_addattr8(rta, 1024, ILA_ATTR_CSUM_MODE, csum_mode); rta_addattr8(rta, 1024, ILA_ATTR_CSUM_MODE,
(__u8)csum_mode);
argc--; argv++; argc--; argv++;
} else { } else {
@ -867,7 +868,7 @@ static int lwt_parse_bpf(struct rtattr *rta, size_t len,
err = bpf_parse_common(bpf_type, &cfg, &bpf_cb_ops, &x); err = bpf_parse_common(bpf_type, &cfg, &bpf_cb_ops, &x);
if (err < 0) { if (err < 0) {
fprintf(stderr, "Failed to parse eBPF program: %s\n", fprintf(stderr, "Failed to parse eBPF program: %s\n",
strerror(err)); strerror(-err));
return -1; return -1;
} }
rta_nest_end(rta, nest); rta_nest_end(rta, nest);

View File

@ -372,12 +372,12 @@ static int vrf_switch(const char *name)
/* -1 on length to add '/' to the end */ /* -1 on length to add '/' to the end */
if (ipvrf_get_netns(netns, sizeof(netns) - 1) < 0) if (ipvrf_get_netns(netns, sizeof(netns) - 1) < 0)
return -1; goto out;
if (vrf_path(vpath, sizeof(vpath)) < 0) { if (vrf_path(vpath, sizeof(vpath)) < 0) {
fprintf(stderr, "Failed to get base cgroup path: %s\n", fprintf(stderr, "Failed to get base cgroup path: %s\n",
strerror(errno)); strerror(errno));
return -1; goto out;
} }
/* if path already ends in netns then don't add it again */ /* if path already ends in netns then don't add it again */
@ -428,13 +428,14 @@ static int vrf_switch(const char *name)
snprintf(pid, sizeof(pid), "%d", getpid()); snprintf(pid, sizeof(pid), "%d", getpid());
if (write(fd, pid, strlen(pid)) < 0) { if (write(fd, pid, strlen(pid)) < 0) {
fprintf(stderr, "Failed to join cgroup\n"); fprintf(stderr, "Failed to join cgroup\n");
goto out; goto out2;
} }
rc = 0; rc = 0;
out2:
close(fd);
out: out:
free(mnt); free(mnt);
close(fd);
return rc; return rc;
} }

View File

@ -49,13 +49,17 @@ static int err_attr_cb(const struct nlattr *attr, void *data)
const struct nlattr **tb = data; const struct nlattr **tb = data;
uint16_t type; uint16_t type;
if (mnl_attr_type_valid(attr, NLMSGERR_ATTR_MAX) < 0) if (mnl_attr_type_valid(attr, NLMSGERR_ATTR_MAX) < 0) {
fprintf(stderr, "Invalid extack attribute\n");
return MNL_CB_ERROR; return MNL_CB_ERROR;
}
type = mnl_attr_get_type(attr); type = mnl_attr_get_type(attr);
if (mnl_attr_validate(attr, extack_policy[type]) < 0) if (mnl_attr_validate(attr, extack_policy[type]) < 0) {
fprintf(stderr, "extack attribute %d failed validation\n",
type);
return MNL_CB_ERROR; return MNL_CB_ERROR;
}
tb[type] = attr; tb[type] = attr;
return MNL_CB_OK; return MNL_CB_OK;
@ -64,7 +68,7 @@ static int err_attr_cb(const struct nlattr *attr, void *data)
/* dump netlink extended ack error message */ /* dump netlink extended ack error message */
static int nl_dump_ext_err(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn) static int nl_dump_ext_err(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn)
{ {
struct nlattr *tb[NLMSGERR_ATTR_MAX + 1]; struct nlattr *tb[NLMSGERR_ATTR_MAX + 1] = {};
const struct nlmsgerr *err = mnl_nlmsg_get_payload(nlh); const struct nlmsgerr *err = mnl_nlmsg_get_payload(nlh);
const struct nlmsghdr *err_nlh = NULL; const struct nlmsghdr *err_nlh = NULL;
unsigned int hlen = sizeof(*err); unsigned int hlen = sizeof(*err);
@ -79,7 +83,8 @@ static int nl_dump_ext_err(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn)
if (!(nlh->nlmsg_flags & NLM_F_CAPPED)) if (!(nlh->nlmsg_flags & NLM_F_CAPPED))
hlen += mnl_nlmsg_get_payload_len(&err->msg); hlen += mnl_nlmsg_get_payload_len(&err->msg);
mnl_attr_parse(nlh, hlen, err_attr_cb, tb); if (mnl_attr_parse(nlh, hlen, err_attr_cb, tb) != MNL_CB_OK)
return 0;
if (tb[NLMSGERR_ATTR_MSG]) if (tb[NLMSGERR_ATTR_MSG])
errmsg = mnl_attr_get_str(tb[NLMSGERR_ATTR_MSG]); errmsg = mnl_attr_get_str(tb[NLMSGERR_ATTR_MSG]);

View File

@ -143,8 +143,10 @@ static int get_nlmsg_extended(const struct sockaddr_nl *who,
struct rtattr *attr; struct rtattr *attr;
attr = parse_rtattr_one_nested(sub_type, tb[filter_type]); attr = parse_rtattr_one_nested(sub_type, tb[filter_type]);
if (attr == NULL) if (attr == NULL) {
free(n);
return 0; return 0;
}
memcpy(&n->val, RTA_DATA(attr), sizeof(n->val)); memcpy(&n->val, RTA_DATA(attr), sizeof(n->val));
} }
memset(&n->rate, 0, sizeof(n->rate)); memset(&n->rate, 0, sizeof(n->rate));
@ -533,8 +535,12 @@ static void dump_kern_db(FILE *fp)
else else
print_one_if(fp, n, n->val); print_one_if(fp, n, n->val);
} }
if (json_output) if (jw) {
fprintf(fp, "\n} }\n"); jsonw_end_object(jw);
jsonw_end_object(jw);
jsonw_destroy(&jw);
}
} }
static void dump_incr_db(FILE *fp) static void dump_incr_db(FILE *fp)

View File

@ -2688,41 +2688,44 @@ static int tcp_show_netlink_file(struct filter *f)
{ {
FILE *fp; FILE *fp;
char buf[16384]; char buf[16384];
int err = -1;
if ((fp = fopen(getenv("TCPDIAG_FILE"), "r")) == NULL) { if ((fp = fopen(getenv("TCPDIAG_FILE"), "r")) == NULL) {
perror("fopen($TCPDIAG_FILE)"); perror("fopen($TCPDIAG_FILE)");
return -1; return err;
} }
while (1) { while (1) {
int status, err; int status, err2;
struct nlmsghdr *h = (struct nlmsghdr *)buf; struct nlmsghdr *h = (struct nlmsghdr *)buf;
struct sockstat s = {}; struct sockstat s = {};
status = fread(buf, 1, sizeof(*h), fp); status = fread(buf, 1, sizeof(*h), fp);
if (status < 0) { if (status < 0) {
perror("Reading header from $TCPDIAG_FILE"); perror("Reading header from $TCPDIAG_FILE");
return -1; break;
} }
if (status != sizeof(*h)) { if (status != sizeof(*h)) {
perror("Unexpected EOF reading $TCPDIAG_FILE"); perror("Unexpected EOF reading $TCPDIAG_FILE");
return -1; break;
} }
status = fread(h+1, 1, NLMSG_ALIGN(h->nlmsg_len-sizeof(*h)), fp); status = fread(h+1, 1, NLMSG_ALIGN(h->nlmsg_len-sizeof(*h)), fp);
if (status < 0) { if (status < 0) {
perror("Reading $TCPDIAG_FILE"); perror("Reading $TCPDIAG_FILE");
return -1; break;
} }
if (status + sizeof(*h) < h->nlmsg_len) { if (status + sizeof(*h) < h->nlmsg_len) {
perror("Unexpected EOF reading $TCPDIAG_FILE"); perror("Unexpected EOF reading $TCPDIAG_FILE");
return -1; break;
} }
/* The only legal exit point */ /* The only legal exit point */
if (h->nlmsg_type == NLMSG_DONE) if (h->nlmsg_type == NLMSG_DONE) {
return 0; err = 0;
break;
}
if (h->nlmsg_type == NLMSG_ERROR) { if (h->nlmsg_type == NLMSG_ERROR) {
struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(h); struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(h);
@ -2733,7 +2736,7 @@ static int tcp_show_netlink_file(struct filter *f)
errno = -err->error; errno = -err->error;
perror("TCPDIAG answered"); perror("TCPDIAG answered");
} }
return -1; break;
} }
parse_diag_msg(h, &s); parse_diag_msg(h, &s);
@ -2742,10 +2745,15 @@ static int tcp_show_netlink_file(struct filter *f)
if (f && f->f && run_ssfilter(f->f, &s) == 0) if (f && f->f && run_ssfilter(f->f, &s) == 0)
continue; continue;
err = inet_show_sock(h, &s); err2 = inet_show_sock(h, &s);
if (err < 0) if (err2 < 0) {
return err; err = err2;
break;
}
} }
fclose(fp);
return err;
} }
static int tcp_show(struct filter *f, int socktype) static int tcp_show(struct filter *f, int socktype)
@ -3162,8 +3170,10 @@ static int unix_show(struct filter *f)
if (name[0]) { if (name[0]) {
u->name = strdup(name); u->name = strdup(name);
if (!u->name) if (!u->name) {
free(u);
break; break;
}
} }
if (u->rport) { if (u->rport) {

View File

@ -84,6 +84,7 @@ static int get_version(unsigned int *version)
res = getsockopt(sockfd, SOL_IP, SO_IP_SET, &req_version, &size); res = getsockopt(sockfd, SOL_IP, SO_IP_SET, &req_version, &size);
if (res != 0) { if (res != 0) {
perror("xt_set getsockopt"); perror("xt_set getsockopt");
close(sockfd);
return -1; return -1;
} }

View File

@ -163,6 +163,7 @@ static int nl_add_udp_enable_opts(struct nlmsghdr *nlh, struct opt *opts,
if (!remip) { if (!remip) {
if (generate_multicast(loc->ai_family, buf, sizeof(buf))) { if (generate_multicast(loc->ai_family, buf, sizeof(buf))) {
fprintf(stderr, "Failed to generate multicast address\n"); fprintf(stderr, "Failed to generate multicast address\n");
freeaddrinfo(loc);
return -EINVAL; return -EINVAL;
} }
remip = buf; remip = buf;
@ -177,6 +178,8 @@ static int nl_add_udp_enable_opts(struct nlmsghdr *nlh, struct opt *opts,
if (rem->ai_family != loc->ai_family) { if (rem->ai_family != loc->ai_family) {
fprintf(stderr, "UDP local and remote AF mismatch\n"); fprintf(stderr, "UDP local and remote AF mismatch\n");
freeaddrinfo(rem);
freeaddrinfo(loc);
return -EINVAL; return -EINVAL;
} }

View File

@ -109,7 +109,8 @@ static int cmd_node_get_addr(struct nlmsghdr *nlh, const struct cmd *cmd,
socklen_t sz = sizeof(struct sockaddr_tipc); socklen_t sz = sizeof(struct sockaddr_tipc);
struct sockaddr_tipc addr; struct sockaddr_tipc addr;
if (!(sk = socket(AF_TIPC, SOCK_RDM, 0))) { sk = socket(AF_TIPC, SOCK_RDM, 0);
if (sk < 0) {
fprintf(stderr, "opening TIPC socket: %s\n", strerror(errno)); fprintf(stderr, "opening TIPC socket: %s\n", strerror(errno));
return -1; return -1;
} }