Commit 9023497d authored by Tobias Klauser's avatar Tobias Klauser Committed by Daniel Borkmann

tools, bpftool: Define prog_type_name array only once

Define prog_type_name in prog.c instead of main.h so it is only defined
once. This leads to a slight decrease in the binary size of bpftool.

Before:

   text	   data	    bss	    dec	    hex	filename
 401032	  11936	1573160	1986128	 1e4e50	bpftool

After:

   text	   data	    bss	    dec	    hex	filename
 399024	  11168	1573160	1983352	 1e4378	bpftool
Signed-off-by: default avatarTobias Klauser <tklauser@distanz.ch>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Reviewed-by: default avatarQuentin Monnet <quentin@isovalent.com>
Link: https://lore.kernel.org/bpf/20200624143124.12914-1-tklauser@distanz.ch
parent 74765da1
...@@ -695,7 +695,7 @@ section_program_types(bool *supported_types, const char *define_prefix, ...@@ -695,7 +695,7 @@ section_program_types(bool *supported_types, const char *define_prefix,
"/*** eBPF program types ***/", "/*** eBPF program types ***/",
define_prefix); define_prefix);
for (i = BPF_PROG_TYPE_UNSPEC + 1; i < ARRAY_SIZE(prog_type_name); i++) for (i = BPF_PROG_TYPE_UNSPEC + 1; i < prog_type_name_size; i++)
probe_prog_type(i, supported_types, define_prefix, ifindex); probe_prog_type(i, supported_types, define_prefix, ifindex);
print_end_section(); print_end_section();
...@@ -741,7 +741,7 @@ section_helpers(bool *supported_types, const char *define_prefix, __u32 ifindex) ...@@ -741,7 +741,7 @@ section_helpers(bool *supported_types, const char *define_prefix, __u32 ifindex)
" %sBPF__PROG_TYPE_ ## prog_type ## __HELPER_ ## helper\n", " %sBPF__PROG_TYPE_ ## prog_type ## __HELPER_ ## helper\n",
define_prefix, define_prefix, define_prefix, define_prefix, define_prefix, define_prefix,
define_prefix); define_prefix);
for (i = BPF_PROG_TYPE_UNSPEC + 1; i < ARRAY_SIZE(prog_type_name); i++) for (i = BPF_PROG_TYPE_UNSPEC + 1; i < prog_type_name_size; i++)
probe_helpers_for_progtype(i, supported_types[i], define_prefix, probe_helpers_for_progtype(i, supported_types[i], define_prefix,
ifindex); ifindex);
......
...@@ -108,7 +108,7 @@ static int show_link_close_json(int fd, struct bpf_link_info *info) ...@@ -108,7 +108,7 @@ static int show_link_close_json(int fd, struct bpf_link_info *info)
if (err) if (err)
return err; return err;
if (prog_info.type < ARRAY_SIZE(prog_type_name)) if (prog_info.type < prog_type_name_size)
jsonw_string_field(json_wtr, "prog_type", jsonw_string_field(json_wtr, "prog_type",
prog_type_name[prog_info.type]); prog_type_name[prog_info.type]);
else else
...@@ -187,7 +187,7 @@ static int show_link_close_plain(int fd, struct bpf_link_info *info) ...@@ -187,7 +187,7 @@ static int show_link_close_plain(int fd, struct bpf_link_info *info)
if (err) if (err)
return err; return err;
if (prog_info.type < ARRAY_SIZE(prog_type_name)) if (prog_info.type < prog_type_name_size)
printf("\n\tprog_type %s ", printf("\n\tprog_type %s ",
prog_type_name[prog_info.type]); prog_type_name[prog_info.type]);
else else
......
...@@ -56,37 +56,8 @@ ...@@ -56,37 +56,8 @@
#define HELP_SPEC_LINK \ #define HELP_SPEC_LINK \
"LINK := { id LINK_ID | pinned FILE }" "LINK := { id LINK_ID | pinned FILE }"
static const char * const prog_type_name[] = { extern const char * const prog_type_name[];
[BPF_PROG_TYPE_UNSPEC] = "unspec", extern const size_t prog_type_name_size;
[BPF_PROG_TYPE_SOCKET_FILTER] = "socket_filter",
[BPF_PROG_TYPE_KPROBE] = "kprobe",
[BPF_PROG_TYPE_SCHED_CLS] = "sched_cls",
[BPF_PROG_TYPE_SCHED_ACT] = "sched_act",
[BPF_PROG_TYPE_TRACEPOINT] = "tracepoint",
[BPF_PROG_TYPE_XDP] = "xdp",
[BPF_PROG_TYPE_PERF_EVENT] = "perf_event",
[BPF_PROG_TYPE_CGROUP_SKB] = "cgroup_skb",
[BPF_PROG_TYPE_CGROUP_SOCK] = "cgroup_sock",
[BPF_PROG_TYPE_LWT_IN] = "lwt_in",
[BPF_PROG_TYPE_LWT_OUT] = "lwt_out",
[BPF_PROG_TYPE_LWT_XMIT] = "lwt_xmit",
[BPF_PROG_TYPE_SOCK_OPS] = "sock_ops",
[BPF_PROG_TYPE_SK_SKB] = "sk_skb",
[BPF_PROG_TYPE_CGROUP_DEVICE] = "cgroup_device",
[BPF_PROG_TYPE_SK_MSG] = "sk_msg",
[BPF_PROG_TYPE_RAW_TRACEPOINT] = "raw_tracepoint",
[BPF_PROG_TYPE_CGROUP_SOCK_ADDR] = "cgroup_sock_addr",
[BPF_PROG_TYPE_LWT_SEG6LOCAL] = "lwt_seg6local",
[BPF_PROG_TYPE_LIRC_MODE2] = "lirc_mode2",
[BPF_PROG_TYPE_SK_REUSEPORT] = "sk_reuseport",
[BPF_PROG_TYPE_FLOW_DISSECTOR] = "flow_dissector",
[BPF_PROG_TYPE_CGROUP_SYSCTL] = "cgroup_sysctl",
[BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE] = "raw_tracepoint_writable",
[BPF_PROG_TYPE_CGROUP_SOCKOPT] = "cgroup_sockopt",
[BPF_PROG_TYPE_TRACING] = "tracing",
[BPF_PROG_TYPE_STRUCT_OPS] = "struct_ops",
[BPF_PROG_TYPE_EXT] = "ext",
};
static const char * const attach_type_name[__MAX_BPF_ATTACH_TYPE] = { static const char * const attach_type_name[__MAX_BPF_ATTACH_TYPE] = {
[BPF_CGROUP_INET_INGRESS] = "ingress", [BPF_CGROUP_INET_INGRESS] = "ingress",
......
...@@ -473,7 +473,7 @@ static int show_map_close_json(int fd, struct bpf_map_info *info) ...@@ -473,7 +473,7 @@ static int show_map_close_json(int fd, struct bpf_map_info *info)
if (owner_prog_type) { if (owner_prog_type) {
unsigned int prog_type = atoi(owner_prog_type); unsigned int prog_type = atoi(owner_prog_type);
if (prog_type < ARRAY_SIZE(prog_type_name)) if (prog_type < prog_type_name_size)
jsonw_string_field(json_wtr, "owner_prog_type", jsonw_string_field(json_wtr, "owner_prog_type",
prog_type_name[prog_type]); prog_type_name[prog_type]);
else else
...@@ -558,7 +558,7 @@ static int show_map_close_plain(int fd, struct bpf_map_info *info) ...@@ -558,7 +558,7 @@ static int show_map_close_plain(int fd, struct bpf_map_info *info)
if (owner_prog_type) { if (owner_prog_type) {
unsigned int prog_type = atoi(owner_prog_type); unsigned int prog_type = atoi(owner_prog_type);
if (prog_type < ARRAY_SIZE(prog_type_name)) if (prog_type < prog_type_name_size)
printf("owner_prog_type %s ", printf("owner_prog_type %s ",
prog_type_name[prog_type]); prog_type_name[prog_type]);
else else
......
...@@ -29,6 +29,40 @@ ...@@ -29,6 +29,40 @@
#include "main.h" #include "main.h"
#include "xlated_dumper.h" #include "xlated_dumper.h"
const char * const prog_type_name[] = {
[BPF_PROG_TYPE_UNSPEC] = "unspec",
[BPF_PROG_TYPE_SOCKET_FILTER] = "socket_filter",
[BPF_PROG_TYPE_KPROBE] = "kprobe",
[BPF_PROG_TYPE_SCHED_CLS] = "sched_cls",
[BPF_PROG_TYPE_SCHED_ACT] = "sched_act",
[BPF_PROG_TYPE_TRACEPOINT] = "tracepoint",
[BPF_PROG_TYPE_XDP] = "xdp",
[BPF_PROG_TYPE_PERF_EVENT] = "perf_event",
[BPF_PROG_TYPE_CGROUP_SKB] = "cgroup_skb",
[BPF_PROG_TYPE_CGROUP_SOCK] = "cgroup_sock",
[BPF_PROG_TYPE_LWT_IN] = "lwt_in",
[BPF_PROG_TYPE_LWT_OUT] = "lwt_out",
[BPF_PROG_TYPE_LWT_XMIT] = "lwt_xmit",
[BPF_PROG_TYPE_SOCK_OPS] = "sock_ops",
[BPF_PROG_TYPE_SK_SKB] = "sk_skb",
[BPF_PROG_TYPE_CGROUP_DEVICE] = "cgroup_device",
[BPF_PROG_TYPE_SK_MSG] = "sk_msg",
[BPF_PROG_TYPE_RAW_TRACEPOINT] = "raw_tracepoint",
[BPF_PROG_TYPE_CGROUP_SOCK_ADDR] = "cgroup_sock_addr",
[BPF_PROG_TYPE_LWT_SEG6LOCAL] = "lwt_seg6local",
[BPF_PROG_TYPE_LIRC_MODE2] = "lirc_mode2",
[BPF_PROG_TYPE_SK_REUSEPORT] = "sk_reuseport",
[BPF_PROG_TYPE_FLOW_DISSECTOR] = "flow_dissector",
[BPF_PROG_TYPE_CGROUP_SYSCTL] = "cgroup_sysctl",
[BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE] = "raw_tracepoint_writable",
[BPF_PROG_TYPE_CGROUP_SOCKOPT] = "cgroup_sockopt",
[BPF_PROG_TYPE_TRACING] = "tracing",
[BPF_PROG_TYPE_STRUCT_OPS] = "struct_ops",
[BPF_PROG_TYPE_EXT] = "ext",
};
const size_t prog_type_name_size = ARRAY_SIZE(prog_type_name);
enum dump_mode { enum dump_mode {
DUMP_JITED, DUMP_JITED,
DUMP_XLATED, DUMP_XLATED,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment