{"id":809879,"url":"http://patchwork.ozlabs.org/api/1.0/patches/809879/?format=json","project":{"id":7,"url":"http://patchwork.ozlabs.org/api/1.0/projects/7/?format=json","name":"Linux network development","link_name":"netdev","list_id":"netdev.vger.kernel.org","list_email":"netdev@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null},"msgid":"<1e96ef342a4f34ee8c8119ee8cc1ed7092ea5ced.1504570627.git.daniel@iogearbox.net>","date":"2017-09-05T00:24:32","name":"[iproute2,master,2/2] bpf: consolidate dumps to use bpf_dump_prog_info","commit_ref":null,"pull_url":null,"state":"accepted","archived":true,"hash":"294ceefbe396c388b8c5a530025fba8d4fce279a","submitter":{"id":65705,"url":"http://patchwork.ozlabs.org/api/1.0/people/65705/?format=json","name":"Daniel Borkmann","email":"daniel@iogearbox.net"},"delegate":{"id":389,"url":"http://patchwork.ozlabs.org/api/1.0/users/389/?format=json","username":"shemminger","first_name":"stephen","last_name":"hemminger","email":"shemminger@vyatta.com"},"mbox":"http://patchwork.ozlabs.org/project/netdev/patch/1e96ef342a4f34ee8c8119ee8cc1ed7092ea5ced.1504570627.git.daniel@iogearbox.net/mbox/","series":[{"id":1470,"url":"http://patchwork.ozlabs.org/api/1.0/series/1470/?format=json","date":"2017-09-05T00:24:30","name":"Two minor BPF updates","version":1,"mbox":"http://patchwork.ozlabs.org/series/1470/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/809879/checks/","tags":{},"headers":{"Return-Path":"<netdev-owner@vger.kernel.org>","X-Original-To":"patchwork-incoming@ozlabs.org","Delivered-To":"patchwork-incoming@ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=netdev-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xmSCX2Dd4z9s9Y\n\tfor <patchwork-incoming@ozlabs.org>;\n\tTue,  5 Sep 2017 10:24:56 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1754080AbdIEAYu (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tMon, 4 Sep 2017 20:24:50 -0400","from www62.your-server.de ([213.133.104.62]:49481 \"EHLO\n\twww62.your-server.de\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S1754049AbdIEAYr (ORCPT\n\t<rfc822;netdev@vger.kernel.org>); Mon, 4 Sep 2017 20:24:47 -0400","from [92.105.166.74] (helo=localhost)\n\tby www62.your-server.de with esmtpsa\n\t(TLSv1.2:DHE-RSA-AES128-GCM-SHA256:128) (Exim 4.85_2)\n\t(envelope-from <daniel@iogearbox.net>)\n\tid 1dp1fa-0008GB-0s; Tue, 05 Sep 2017 02:24:46 +0200"],"From":"Daniel Borkmann <daniel@iogearbox.net>","To":"stephen@networkplumber.org","Cc":"ast@fb.com, netdev@vger.kernel.org,\n\tDaniel Borkmann <daniel@iogearbox.net>","Subject":"[PATCH iproute2 master 2/2] bpf: consolidate dumps to use\n\tbpf_dump_prog_info","Date":"Tue,  5 Sep 2017 02:24:32 +0200","Message-Id":"<1e96ef342a4f34ee8c8119ee8cc1ed7092ea5ced.1504570627.git.daniel@iogearbox.net>","X-Mailer":"git-send-email 1.9.3","In-Reply-To":["<cover.1504570627.git.daniel@iogearbox.net>","<cover.1504570627.git.daniel@iogearbox.net>"],"References":["<cover.1504570627.git.daniel@iogearbox.net>","<cover.1504570627.git.daniel@iogearbox.net>"],"X-Authenticated-Sender":"daniel@iogearbox.net","X-Virus-Scanned":"Clear (ClamAV 0.99.2/23772/Mon Sep  4 22:37:02 2017)","Sender":"netdev-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<netdev.vger.kernel.org>","X-Mailing-List":"netdev@vger.kernel.org"},"content":"Consolidate dump of prog info to use bpf_dump_prog_info() when possible.\nMoving forward, we want to have a consistent output for BPF progs when\nbeing dumped. E.g. in cls/act case we used to dump tag as a separate\nnetlink attribute before we had BPF_OBJ_GET_INFO_BY_FD bpf(2) command.\n\nMove dumping tag into bpf_dump_prog_info() as well, and only dump the\nnetlink attribute for older kernels. Also, reuse bpf_dump_prog_info()\nfor XDP case, so we can dump tag and whether program was jited, which\nwe currently don't show.\n\nSigned-off-by: Daniel Borkmann <daniel@iogearbox.net>\n---\n include/bpf_util.h |  2 +-\n ip/ipaddress.c     |  6 ++++--\n ip/iplink_xdp.c    | 19 +++++++++++++++----\n ip/xdp.h           |  2 +-\n lib/bpf.c          | 12 +++++++++---\n tc/f_bpf.c         |  8 ++++----\n tc/m_bpf.c         |  8 ++++----\n 7 files changed, 38 insertions(+), 19 deletions(-)","diff":"diff --git a/include/bpf_util.h b/include/bpf_util.h\nindex 6582ec8..e818221 100644\n--- a/include/bpf_util.h\n+++ b/include/bpf_util.h\n@@ -261,7 +261,7 @@ int bpf_prog_load(enum bpf_prog_type type, const struct bpf_insn *insns,\n int bpf_prog_attach_fd(int prog_fd, int target_fd, enum bpf_attach_type type);\n int bpf_prog_detach_fd(int target_fd, enum bpf_attach_type type);\n \n-void bpf_dump_prog_info(FILE *f, uint32_t id);\n+int bpf_dump_prog_info(FILE *f, uint32_t id);\n \n #ifdef HAVE_ELF\n int bpf_send_map_fds(const char *path, const char *obj);\ndiff --git a/ip/ipaddress.c b/ip/ipaddress.c\nindex c9312f0..dbdd839 100644\n--- a/ip/ipaddress.c\n+++ b/ip/ipaddress.c\n@@ -837,7 +837,7 @@ int print_linkinfo(const struct sockaddr_nl *who,\n \tif (tb[IFLA_MTU])\n \t\tfprintf(fp, \"mtu %u \", rta_getattr_u32(tb[IFLA_MTU]));\n \tif (tb[IFLA_XDP])\n-\t\txdp_dump(fp, tb[IFLA_XDP]);\n+\t\txdp_dump(fp, tb[IFLA_XDP], do_link, false);\n \tif (tb[IFLA_QDISC])\n \t\tfprintf(fp, \"qdisc %s \", rta_getattr_str(tb[IFLA_QDISC]));\n \tif (tb[IFLA_MASTER]) {\n@@ -951,12 +951,14 @@ int print_linkinfo(const struct sockaddr_nl *who,\n \t\t}\n \t}\n \n-\n \tif ((do_link || show_details) && tb[IFLA_IFALIAS]) {\n \t\tfprintf(fp, \"%s    alias %s\", _SL_,\n \t\t\trta_getattr_str(tb[IFLA_IFALIAS]));\n \t}\n \n+\tif ((do_link || show_details) && tb[IFLA_XDP])\n+\t\txdp_dump(fp, tb[IFLA_XDP], true, true);\n+\n \tif (do_link && show_stats) {\n \t\tfprintf(fp, \"%s\", _SL_);\n \t\t__print_link_stats(fp, tb);\ndiff --git a/ip/iplink_xdp.c b/ip/iplink_xdp.c\nindex 9ae9ee5..5aa66fe 100644\n--- a/ip/iplink_xdp.c\n+++ b/ip/iplink_xdp.c\n@@ -81,9 +81,10 @@ int xdp_parse(int *argc, char ***argv, struct iplink_req *req, bool generic,\n \treturn 0;\n }\n \n-void xdp_dump(FILE *fp, struct rtattr *xdp)\n+void xdp_dump(FILE *fp, struct rtattr *xdp, bool link, bool details)\n {\n \tstruct rtattr *tb[IFLA_XDP_MAX + 1];\n+\t__u32 prog_id = 0;\n \t__u8 mode;\n \n \tparse_rtattr_nested(tb, IFLA_XDP_MAX, xdp);\n@@ -94,6 +95,8 @@ void xdp_dump(FILE *fp, struct rtattr *xdp)\n \tmode = rta_getattr_u8(tb[IFLA_XDP_ATTACHED]);\n \tif (mode == XDP_ATTACHED_NONE)\n \t\treturn;\n+\telse if (details && link)\n+\t\tfprintf(fp, \"%s    prog/xdp\", _SL_);\n \telse if (mode == XDP_ATTACHED_DRV)\n \t\tfprintf(fp, \"xdp\");\n \telse if (mode == XDP_ATTACHED_SKB)\n@@ -104,8 +107,16 @@ void xdp_dump(FILE *fp, struct rtattr *xdp)\n \t\tfprintf(fp, \"xdp[%u]\", mode);\n \n \tif (tb[IFLA_XDP_PROG_ID])\n-\t\tfprintf(fp, \"/id:%u\",\n-\t\t\trta_getattr_u32(tb[IFLA_XDP_PROG_ID]));\n+\t\tprog_id = rta_getattr_u32(tb[IFLA_XDP_PROG_ID]);\n+\tif (!details) {\n+\t\tif (prog_id && !link)\n+\t\t\tfprintf(fp, \"/id:%u\", prog_id);\n+\t\tfprintf(fp, \" \");\n+\t\treturn;\n+\t}\n \n-\tfprintf(fp, \" \");\n+\tif (prog_id) {\n+\t\tfprintf(fp, \" \");\n+\t\tbpf_dump_prog_info(fp, prog_id);\n+\t}\n }\ndiff --git a/ip/xdp.h b/ip/xdp.h\nindex ba897a2..1efd591 100644\n--- a/ip/xdp.h\n+++ b/ip/xdp.h\n@@ -5,6 +5,6 @@\n \n int xdp_parse(int *argc, char ***argv, struct iplink_req *req, bool generic,\n \t      bool drv, bool offload);\n-void xdp_dump(FILE *fp, struct rtattr *tb);\n+void xdp_dump(FILE *fp, struct rtattr *tb, bool link, bool details);\n \n #endif /* __XDP__ */\ndiff --git a/lib/bpf.c b/lib/bpf.c\nindex 7463fdc..cfa1f79 100644\n--- a/lib/bpf.c\n+++ b/lib/bpf.c\n@@ -179,25 +179,31 @@ static int bpf_prog_info_by_fd(int fd, struct bpf_prog_info *info,\n \treturn ret;\n }\n \n-void bpf_dump_prog_info(FILE *f, uint32_t id)\n+int bpf_dump_prog_info(FILE *f, uint32_t id)\n {\n \tstruct bpf_prog_info info = {};\n \tuint32_t len = sizeof(info);\n-\tint fd, ret;\n+\tint fd, ret, dump_ok = 0;\n+\tSPRINT_BUF(tmp);\n \n \tfprintf(f, \"id %u \", id);\n \n \tfd = bpf_prog_fd_by_id(id);\n \tif (fd < 0)\n-\t\treturn;\n+\t\treturn dump_ok;\n \n \tret = bpf_prog_info_by_fd(fd, &info, &len);\n \tif (!ret && len) {\n+\t\tfprintf(f, \"tag %s \",\n+\t\t\thexstring_n2a(info.tag, sizeof(info.tag),\n+\t\t\t\t      tmp, sizeof(tmp)));\n \t\tif (info.jited_prog_len)\n \t\t\tfprintf(f, \"jited \");\n+\t\tdump_ok = 1;\n \t}\n \n \tclose(fd);\n+\treturn dump_ok;\n }\n \n static int bpf_parse_string(char *arg, bool from_file, __u16 *bpf_len,\ndiff --git a/tc/f_bpf.c b/tc/f_bpf.c\nindex 2f8d12a..4fb9209 100644\n--- a/tc/f_bpf.c\n+++ b/tc/f_bpf.c\n@@ -177,6 +177,7 @@ static int bpf_print_opt(struct filter_util *qu, FILE *f,\n \t\t\t struct rtattr *opt, __u32 handle)\n {\n \tstruct rtattr *tb[TCA_BPF_MAX + 1];\n+\tint dump_ok = 0;\n \n \tif (opt == NULL)\n \t\treturn 0;\n@@ -221,7 +222,9 @@ static int bpf_print_opt(struct filter_util *qu, FILE *f,\n \t\tbpf_print_ops(f, tb[TCA_BPF_OPS],\n \t\t\t      rta_getattr_u16(tb[TCA_BPF_OPS_LEN]));\n \n-\tif (tb[TCA_BPF_TAG]) {\n+\tif (tb[TCA_BPF_ID])\n+\t\tdump_ok = bpf_dump_prog_info(f, rta_getattr_u32(tb[TCA_BPF_ID]));\n+\tif (!dump_ok && tb[TCA_BPF_TAG]) {\n \t\tSPRINT_BUF(b);\n \n \t\tfprintf(f, \"tag %s \",\n@@ -230,9 +233,6 @@ static int bpf_print_opt(struct filter_util *qu, FILE *f,\n \t\t\t\t      b, sizeof(b)));\n \t}\n \n-\tif (tb[TCA_BPF_ID])\n-\t\tbpf_dump_prog_info(f, rta_getattr_u32(tb[TCA_BPF_ID]));\n-\n \tif (tb[TCA_BPF_POLICE]) {\n \t\tfprintf(f, \"\\n\");\n \t\ttc_print_police(f, tb[TCA_BPF_POLICE]);\ndiff --git a/tc/m_bpf.c b/tc/m_bpf.c\nindex df559bc..e3d0a2b 100644\n--- a/tc/m_bpf.c\n+++ b/tc/m_bpf.c\n@@ -154,6 +154,7 @@ static int bpf_print_opt(struct action_util *au, FILE *f, struct rtattr *arg)\n {\n \tstruct rtattr *tb[TCA_ACT_BPF_MAX + 1];\n \tstruct tc_act_bpf *parm;\n+\tint dump_ok = 0;\n \n \tif (arg == NULL)\n \t\treturn -1;\n@@ -177,7 +178,9 @@ static int bpf_print_opt(struct action_util *au, FILE *f, struct rtattr *arg)\n \t\tfprintf(f, \" \");\n \t}\n \n-\tif (tb[TCA_ACT_BPF_TAG]) {\n+\tif (tb[TCA_ACT_BPF_ID])\n+\t\tdump_ok = bpf_dump_prog_info(f, rta_getattr_u32(tb[TCA_ACT_BPF_ID]));\n+\tif (!dump_ok && tb[TCA_ACT_BPF_TAG]) {\n \t\tSPRINT_BUF(b);\n \n \t\tfprintf(f, \"tag %s \",\n@@ -186,9 +189,6 @@ static int bpf_print_opt(struct action_util *au, FILE *f, struct rtattr *arg)\n \t\t\t\t      b, sizeof(b)));\n \t}\n \n-        if (tb[TCA_ACT_BPF_ID])\n-                bpf_dump_prog_info(f, rta_getattr_u32(tb[TCA_ACT_BPF_ID]));\n-\n \tprint_action_control(f, \"default-action \", parm->action, \"\\n\");\n \tfprintf(f, \"\\tindex %u ref %d bind %d\", parm->index, parm->refcnt,\n \t\tparm->bindcnt);\n","prefixes":["iproute2","master","2/2"]}