From: Masatake YAMATO Date: Mon, 14 Oct 2024 07:31:02 +0000 (+0900) Subject: lsfd: add BPF-PROG.TAG column X-Git-Tag: v2.42-start~170^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ae08e49075af4737b499131e0cbbfb8410923bae;p=thirdparty%2Futil-linux.git lsfd: add BPF-PROG.TAG column Signed-off-by: Masatake YAMATO --- diff --git a/configure.ac b/configure.ac index 96519e088..0081b1da9 100644 --- a/configure.ac +++ b/configure.ac @@ -568,6 +568,9 @@ AC_CHECK_DECL([strsignal], AC_CHECK_DECL([BPF_OBJ_NAME_LEN], [have_bpf_obj_name_len=yes], [have_bpf_obj_name_len=no], [#include ]) +AC_CHECK_DECL([BPF_TAG_SIZE], + [have_bpf_tag_size=yes], [have_bpf_tag_size=no], + [#include ]) AC_CHECK_DECL([TIOCGLCKTRMIOS], [have_tiocglcktrmios=yes], [have_tiocglcktrmios=no], @@ -1868,6 +1871,7 @@ UL_REQUIRES_LINUX([lsfd]) UL_REQUIRES_BUILD([lsfd], [libsmartcols]) UL_REQUIRES_HAVE([lsfd], [linux_bpf_h], [linux/bpf.h header file]) UL_REQUIRES_HAVE([lsfd], [bpf_obj_name_len], [BPF_OBJ_NAME_LEN macro in linux/bpf.h]) +UL_REQUIRES_HAVE([lsfd], [bpf_tag_size], [BPF_TAG_SIZE macro in linux/bpf.h]) AM_CONDITIONAL([BUILD_LSFD], [test "x$build_lsfd" = xyes]) AC_ARG_ENABLE([lslogins], diff --git a/lsfd-cmd/lsfd.1.adoc b/lsfd-cmd/lsfd.1.adoc index 0c15d6dd0..915bfa36d 100644 --- a/lsfd-cmd/lsfd.1.adoc +++ b/lsfd-cmd/lsfd.1.adoc @@ -147,6 +147,9 @@ Bpf object name. BPF-PROG.ID <``number``>:: Bpf program ID. +BPF-PROG.TAG <``string``>:: +Bpf program TAG. + BPF-PROG.TYPE <``string``>:: Decoded name of bpf program type. @@ -273,7 +276,7 @@ bpf-map::: id=_BPF-MAP.ID_ type=_BPF-MAP.TYPE_[ name=_BPF.NAME_] + bpf-prog::: -id=_BPF-PROG.ID_ type=_BPF-PROG.TYPE_[ name=_BPF.NAME_] +id=_BPF-PROG.ID_ type=_BPF-PROG.TYPE_ tag= _BPF-PROG.TAG_ [ name=_BPF.NAME_] + eventpoll::: tfds=_EVENTPOLL.TFDS_ diff --git a/lsfd-cmd/lsfd.c b/lsfd-cmd/lsfd.c index 09ef9a588..49d31a16e 100644 --- a/lsfd-cmd/lsfd.c +++ b/lsfd-cmd/lsfd.c @@ -194,6 +194,9 @@ static const struct colinfo infos[] = { [COL_BPF_PROG_ID] = { "BPF-PROG.ID", 0, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER, N_("bpf program id associated with the fd") }, + [COL_BPF_PROG_TAG] = { "BPF-PROG.TAG", + 0, SCOLS_FL_RIGHT, SCOLS_JSON_STRING, + N_("bpf program tag") }, [COL_BPF_PROG_TYPE] = { "BPF-PROG.TYPE", 0, SCOLS_FL_RIGHT, SCOLS_JSON_STRING, N_("bpf program type (decoded)") }, diff --git a/lsfd-cmd/lsfd.h b/lsfd-cmd/lsfd.h index 29ecb6395..a34a756c7 100644 --- a/lsfd-cmd/lsfd.h +++ b/lsfd-cmd/lsfd.h @@ -63,6 +63,7 @@ enum { COL_BPF_MAP_TYPE_RAW, COL_BPF_NAME, COL_BPF_PROG_ID, + COL_BPF_PROG_TAG, COL_BPF_PROG_TYPE, COL_BPF_PROG_TYPE_RAW, COL_CHRDRV, diff --git a/lsfd-cmd/unkn.c b/lsfd-cmd/unkn.c index d93b2dda0..5338d8cec 100644 --- a/lsfd-cmd/unkn.c +++ b/lsfd-cmd/unkn.c @@ -979,6 +979,8 @@ struct anon_bpf_prog_data { int type; int id; char name[BPF_OBJ_NAME_LEN + 1]; +#define BPF_TAG_SIZE_AS_STRING (BPF_TAG_SIZE * 2) + char tag[BPF_TAG_SIZE_AS_STRING + 1]; }; static bool anon_bpf_prog_probe(const char *str) @@ -1007,6 +1009,9 @@ static bool anon_bpf_prog_fill_column(struct proc *proc __attribute__((__unused case COL_BPF_PROG_ID: xasprintf(str, "%d", data->id); return true; + case COL_BPF_PROG_TAG: + *str = xstrdup(data->tag); + return true; case COL_BPF_PROG_TYPE_RAW: xasprintf(str, "%d", data->type); return true; @@ -1037,6 +1042,9 @@ static char *anon_bpf_prog_get_name(struct unkn *unkn) else xasprintf(&str, "id=%d type=UNKNOWN(%d)", data->id, data->type); + if (data->tag[0] != '\0') + xstrfappend(&str, " tag=%s", data->tag); + if (*data->name) xstrfappend(&str, " name=%s", data->name); @@ -1050,6 +1058,7 @@ static void anon_bpf_prog_init(struct unkn *unkn) data->type = -1; data->id = -1; data->name[0] = '\0'; + data->tag[0] = '\0'; unkn->anon_data = data; } @@ -1107,6 +1116,13 @@ static int anon_bpf_prog_handle_fdinfo(struct unkn *unkn, const char *key, const return 1; } + if (strcmp(key, "prog_tag") == 0) { + char *dst = ((struct anon_bpf_prog_data *)unkn->anon_data)->tag; + strncpy(dst, value, BPF_TAG_SIZE_AS_STRING); + dst[BPF_TAG_SIZE_AS_STRING] = '\0'; + return 1; + } + return 0; } diff --git a/meson.build b/meson.build index 71f88a163..61282187c 100644 --- a/meson.build +++ b/meson.build @@ -2897,7 +2897,8 @@ errnos_h = custom_target('errnos.h', ) opt = not get_option('build-lsfd').require(lib_rt.found()).disabled() \ - and cc.has_header_symbol('linux/bpf.h', 'BPF_OBJ_NAME_LEN') + and cc.has_header_symbol('linux/bpf.h', 'BPF_OBJ_NAME_LEN') \ + and cc.has_header_symbol('linux/bpf.h', 'BPF_TAG_SIZE') exe = executable( 'lsfd', lsfd_sources, errnos_h,