Merge branch 'master' into net-next

This commit is contained in:
Stephen Hemminger 2017-09-05 09:33:29 -07:00
commit a17a01145f
8 changed files with 57 additions and 36 deletions

View File

@ -261,7 +261,7 @@ int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns,
int bpf_prog_attach_fd(int prog_fd, int target_fd, enum bpf_attach_type type); int bpf_prog_attach_fd(int prog_fd, int target_fd, enum bpf_attach_type type);
int bpf_prog_detach_fd(int target_fd, enum bpf_attach_type type); int bpf_prog_detach_fd(int target_fd, enum bpf_attach_type type);
void bpf_dump_prog_info(FILE *f, uint32_t id); int bpf_dump_prog_info(FILE *f, uint32_t id);
#ifdef HAVE_ELF #ifdef HAVE_ELF
int bpf_send_map_fds(const char *path, const char *obj); int bpf_send_map_fds(const char *path, const char *obj);

View File

@ -1146,7 +1146,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
"mtu", "mtu %u ", "mtu", "mtu %u ",
rta_getattr_u32(tb[IFLA_MTU])); rta_getattr_u32(tb[IFLA_MTU]));
if (tb[IFLA_XDP]) if (tb[IFLA_XDP])
xdp_dump(fp, tb[IFLA_XDP]); xdp_dump(fp, tb[IFLA_XDP], do_link, false);
if (tb[IFLA_QDISC]) if (tb[IFLA_QDISC])
print_string(PRINT_ANY, print_string(PRINT_ANY,
"qdisc", "qdisc",
@ -1306,7 +1306,6 @@ int print_linkinfo(const struct sockaddr_nl *who,
} }
} }
if ((do_link || show_details) && tb[IFLA_IFALIAS]) { if ((do_link || show_details) && tb[IFLA_IFALIAS]) {
print_string(PRINT_FP, NULL, "%s ", _SL_); print_string(PRINT_FP, NULL, "%s ", _SL_);
print_string(PRINT_ANY, print_string(PRINT_ANY,
@ -1315,6 +1314,9 @@ int print_linkinfo(const struct sockaddr_nl *who,
rta_getattr_str(tb[IFLA_IFALIAS])); rta_getattr_str(tb[IFLA_IFALIAS]));
} }
if ((do_link || show_details) && tb[IFLA_XDP])
xdp_dump(fp, tb[IFLA_XDP], true, true);
if (do_link && show_stats) { if (do_link && show_stats) {
print_string(PRINT_FP, NULL, "%s", _SL_); print_string(PRINT_FP, NULL, "%s", _SL_);
__print_link_stats(fp, tb); __print_link_stats(fp, tb);

View File

@ -82,9 +82,10 @@ int xdp_parse(int *argc, char ***argv, struct iplink_req *req, bool generic,
return 0; return 0;
} }
void xdp_dump(FILE *fp, struct rtattr *xdp) void xdp_dump(FILE *fp, struct rtattr *xdp, bool link, bool details)
{ {
struct rtattr *tb[IFLA_XDP_MAX + 1]; struct rtattr *tb[IFLA_XDP_MAX + 1];
__u32 prog_id = 0;
__u8 mode; __u8 mode;
parse_rtattr_nested(tb, IFLA_XDP_MAX, xdp); parse_rtattr_nested(tb, IFLA_XDP_MAX, xdp);
@ -98,6 +99,8 @@ void xdp_dump(FILE *fp, struct rtattr *xdp)
} else { } else {
if (mode == XDP_ATTACHED_NONE) if (mode == XDP_ATTACHED_NONE)
return; return;
else if (details && link)
fprintf(fp, "%s prog/xdp", _SL_);
else if (mode == XDP_ATTACHED_DRV) else if (mode == XDP_ATTACHED_DRV)
fprintf(fp, "xdp"); fprintf(fp, "xdp");
else if (mode == XDP_ATTACHED_SKB) else if (mode == XDP_ATTACHED_SKB)
@ -106,11 +109,19 @@ void xdp_dump(FILE *fp, struct rtattr *xdp)
fprintf(fp, "xdpoffload"); fprintf(fp, "xdpoffload");
else else
fprintf(fp, "xdp[%u]", mode); fprintf(fp, "xdp[%u]", mode);
}
if (tb[IFLA_XDP_PROG_ID]) if (tb[IFLA_XDP_PROG_ID])
print_uint(PRINT_ANY, "prog_id", "/id:%u", prog_id = rta_getattr_u32(tb[IFLA_XDP_PROG_ID]);
rta_getattr_u32(tb[IFLA_XDP_PROG_ID])); if (!details) {
if (prog_id && !link)
fprintf(fp, "/id:%u", prog_id);
fprintf(fp, " ");
return;
}
print_string(PRINT_FP, NULL, "%c", " "); if (prog_id) {
fprintf(fp, " ");
bpf_dump_prog_info(fp, prog_id);
}
}
} }

View File

@ -5,6 +5,6 @@
int xdp_parse(int *argc, char ***argv, struct iplink_req *req, bool generic, int xdp_parse(int *argc, char ***argv, struct iplink_req *req, bool generic,
bool drv, bool offload); bool drv, bool offload);
void xdp_dump(FILE *fp, struct rtattr *tb); void xdp_dump(FILE *fp, struct rtattr *tb, bool link, bool details);
#endif /* __XDP__ */ #endif /* __XDP__ */

View File

@ -179,25 +179,31 @@ static int bpf_prog_info_by_fd(int fd, struct bpf_prog_info *info,
return ret; return ret;
} }
void bpf_dump_prog_info(FILE *f, uint32_t id) int bpf_dump_prog_info(FILE *f, uint32_t id)
{ {
struct bpf_prog_info info = {}; struct bpf_prog_info info = {};
uint32_t len = sizeof(info); uint32_t len = sizeof(info);
int fd, ret; int fd, ret, dump_ok = 0;
SPRINT_BUF(tmp);
fprintf(f, "id %u ", id); fprintf(f, "id %u ", id);
fd = bpf_prog_fd_by_id(id); fd = bpf_prog_fd_by_id(id);
if (fd < 0) if (fd < 0)
return; return dump_ok;
ret = bpf_prog_info_by_fd(fd, &info, &len); ret = bpf_prog_info_by_fd(fd, &info, &len);
if (!ret && len) { if (!ret && len) {
fprintf(f, "tag %s ",
hexstring_n2a(info.tag, sizeof(info.tag),
tmp, sizeof(tmp)));
if (info.jited_prog_len) if (info.jited_prog_len)
fprintf(f, "jited "); fprintf(f, "jited ");
dump_ok = 1;
} }
close(fd); close(fd);
return dump_ok;
} }
static int bpf_parse_string(char *arg, bool from_file, __u16 *bpf_len, static int bpf_parse_string(char *arg, bool from_file, __u16 *bpf_len,
@ -208,8 +214,9 @@ static int bpf_parse_string(char *arg, bool from_file, __u16 *bpf_len,
if (from_file) { if (from_file) {
size_t tmp_len, op_len = sizeof("65535 255 255 4294967295,"); size_t tmp_len, op_len = sizeof("65535 255 255 4294967295,");
char *tmp_string, *pos, c, c_prev = ' '; char *tmp_string, *pos, c_prev = ' ';
FILE *fp; FILE *fp;
int c;
tmp_len = sizeof("4096,") + BPF_MAXINSNS * op_len; tmp_len = sizeof("4096,") + BPF_MAXINSNS * op_len;
tmp_string = pos = calloc(1, tmp_len); tmp_string = pos = calloc(1, tmp_len);
@ -228,18 +235,20 @@ static int bpf_parse_string(char *arg, bool from_file, __u16 *bpf_len,
case '\n': case '\n':
if (c_prev != ',') if (c_prev != ',')
*(pos++) = ','; *(pos++) = ',';
c_prev = ',';
break; break;
case ' ': case ' ':
case '\t': case '\t':
if (c_prev != ' ') if (c_prev != ' ')
*(pos++) = c; *(pos++) = c;
c_prev = ' ';
break; break;
default: default:
*(pos++) = c; *(pos++) = c;
c_prev = c;
} }
if (pos - tmp_string == tmp_len) if (pos - tmp_string == tmp_len)
break; break;
c_prev = c;
} }
if (!feof(fp)) { if (!feof(fp)) {
@ -566,9 +575,9 @@ int bpf_trace_pipe(void)
"/trace", "/trace",
0, 0,
}; };
int fd_in, fd_out = STDERR_FILENO;
char tpipe[PATH_MAX]; char tpipe[PATH_MAX];
const char *mnt; const char *mnt;
int fd;
mnt = bpf_find_mntpt("tracefs", TRACEFS_MAGIC, tracefs_mnt, mnt = bpf_find_mntpt("tracefs", TRACEFS_MAGIC, tracefs_mnt,
sizeof(tracefs_mnt), tracefs_known_mnts); sizeof(tracefs_mnt), tracefs_known_mnts);
@ -579,8 +588,8 @@ int bpf_trace_pipe(void)
snprintf(tpipe, sizeof(tpipe), "%s/trace_pipe", mnt); snprintf(tpipe, sizeof(tpipe), "%s/trace_pipe", mnt);
fd = open(tpipe, O_RDONLY); fd_in = open(tpipe, O_RDONLY);
if (fd < 0) if (fd_in < 0)
return -1; return -1;
fprintf(stderr, "Running! Hang up with ^C!\n\n"); fprintf(stderr, "Running! Hang up with ^C!\n\n");
@ -588,15 +597,14 @@ int bpf_trace_pipe(void)
static char buff[4096]; static char buff[4096];
ssize_t ret; ssize_t ret;
ret = read(fd, buff, sizeof(buff) - 1); ret = read(fd_in, buff, sizeof(buff));
if (ret > 0) { if (ret > 0 && write(fd_out, buff, ret) == ret)
if (write(STDERR_FILENO, buff, ret) != ret) continue;
return -1; break;
fflush(stderr);
}
} }
return 0; close(fd_in);
return -1;
} }
static int bpf_gen_global(const char *bpf_sub_dir) static int bpf_gen_global(const char *bpf_sub_dir)

View File

@ -177,6 +177,7 @@ static int bpf_print_opt(struct filter_util *qu, FILE *f,
struct rtattr *opt, __u32 handle) struct rtattr *opt, __u32 handle)
{ {
struct rtattr *tb[TCA_BPF_MAX + 1]; struct rtattr *tb[TCA_BPF_MAX + 1];
int dump_ok = 0;
if (opt == NULL) if (opt == NULL)
return 0; return 0;
@ -221,7 +222,9 @@ static int bpf_print_opt(struct filter_util *qu, FILE *f,
bpf_print_ops(f, tb[TCA_BPF_OPS], bpf_print_ops(f, tb[TCA_BPF_OPS],
rta_getattr_u16(tb[TCA_BPF_OPS_LEN])); rta_getattr_u16(tb[TCA_BPF_OPS_LEN]));
if (tb[TCA_BPF_TAG]) { if (tb[TCA_BPF_ID])
dump_ok = bpf_dump_prog_info(f, rta_getattr_u32(tb[TCA_BPF_ID]));
if (!dump_ok && tb[TCA_BPF_TAG]) {
SPRINT_BUF(b); SPRINT_BUF(b);
fprintf(f, "tag %s ", fprintf(f, "tag %s ",
@ -230,9 +233,6 @@ static int bpf_print_opt(struct filter_util *qu, FILE *f,
b, sizeof(b))); b, sizeof(b)));
} }
if (tb[TCA_BPF_ID])
bpf_dump_prog_info(f, rta_getattr_u32(tb[TCA_BPF_ID]));
if (tb[TCA_BPF_POLICE]) { if (tb[TCA_BPF_POLICE]) {
fprintf(f, "\n"); fprintf(f, "\n");
tc_print_police(f, tb[TCA_BPF_POLICE]); tc_print_police(f, tb[TCA_BPF_POLICE]);

View File

@ -242,7 +242,7 @@ done0:
invarg("cookie must be a hex string\n", invarg("cookie must be a hex string\n",
*argv); *argv);
act_ck_len = slen; act_ck_len = slen / 2;
argc--; argc--;
argv++; argv++;
} }
@ -307,7 +307,7 @@ static int tc_print_one_action(FILE *f, struct rtattr *arg)
print_tcstats2_attr(f, tb[TCA_ACT_STATS], "\t", NULL); print_tcstats2_attr(f, tb[TCA_ACT_STATS], "\t", NULL);
if (tb[TCA_ACT_COOKIE]) { if (tb[TCA_ACT_COOKIE]) {
int strsz = RTA_PAYLOAD(tb[TCA_ACT_COOKIE]); int strsz = RTA_PAYLOAD(tb[TCA_ACT_COOKIE]);
char b1[strsz+1]; char b1[strsz * 2 + 1];
fprintf(f, "\n\tcookie len %d %s ", strsz, fprintf(f, "\n\tcookie len %d %s ", strsz,
hexstring_n2a(RTA_DATA(tb[TCA_ACT_COOKIE]), hexstring_n2a(RTA_DATA(tb[TCA_ACT_COOKIE]),

View File

@ -154,6 +154,7 @@ static int bpf_print_opt(struct action_util *au, FILE *f, struct rtattr *arg)
{ {
struct rtattr *tb[TCA_ACT_BPF_MAX + 1]; struct rtattr *tb[TCA_ACT_BPF_MAX + 1];
struct tc_act_bpf *parm; struct tc_act_bpf *parm;
int dump_ok = 0;
if (arg == NULL) if (arg == NULL)
return -1; return -1;
@ -177,7 +178,9 @@ static int bpf_print_opt(struct action_util *au, FILE *f, struct rtattr *arg)
fprintf(f, " "); fprintf(f, " ");
} }
if (tb[TCA_ACT_BPF_TAG]) { if (tb[TCA_ACT_BPF_ID])
dump_ok = bpf_dump_prog_info(f, rta_getattr_u32(tb[TCA_ACT_BPF_ID]));
if (!dump_ok && tb[TCA_ACT_BPF_TAG]) {
SPRINT_BUF(b); SPRINT_BUF(b);
fprintf(f, "tag %s ", fprintf(f, "tag %s ",
@ -186,9 +189,6 @@ static int bpf_print_opt(struct action_util *au, FILE *f, struct rtattr *arg)
b, sizeof(b))); b, sizeof(b)));
} }
if (tb[TCA_ACT_BPF_ID])
bpf_dump_prog_info(f, rta_getattr_u32(tb[TCA_ACT_BPF_ID]));
print_action_control(f, "default-action ", parm->action, "\n"); print_action_control(f, "default-action ", parm->action, "\n");
fprintf(f, "\tindex %u ref %d bind %d", parm->index, parm->refcnt, fprintf(f, "\tindex %u ref %d bind %d", parm->index, parm->refcnt,
parm->bindcnt); parm->bindcnt);