]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: add BPF-PROG.TAG column
authorMasatake YAMATO <yamato@redhat.com>
Mon, 14 Oct 2024 07:31:02 +0000 (16:31 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Fri, 25 Oct 2024 20:55:36 +0000 (05:55 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
configure.ac
lsfd-cmd/lsfd.1.adoc
lsfd-cmd/lsfd.c
lsfd-cmd/lsfd.h
lsfd-cmd/unkn.c
meson.build

index 96519e08820438ce4edd427a47bd86aaf713712a..0081b1da958e62b0c6b7cbaeacc6d62a3be81130 100644 (file)
@@ -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 <linux/bpf.h>])
+AC_CHECK_DECL([BPF_TAG_SIZE],
+             [have_bpf_tag_size=yes], [have_bpf_tag_size=no],
+             [#include <linux/bpf.h>])
 
 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],
index 0c15d6dd06325f3d34105b0c2861ea359c1e37ef..915bfa36d1bd5a4617fb9b3a863882f16b650bdd 100644 (file)
@@ -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_
index 09ef9a588366098d2c4fd0a8c9b63aa1bf17f3e9..49d31a16e2248ad03a12f4154573cee1d5ad844b 100644 (file)
@@ -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)") },
index 29ecb639593f2587e00133a8c426416c95ec6b1b..a34a756c7225d8bd6e9b5aac53ecdb6f7ace8634 100644 (file)
@@ -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,
index d93b2dda0c99270cfe9ee7ed0e56d372a25d1beb..5338d8cec85683d49109662272d4b2934b8e5e6c 100644 (file)
@@ -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;
 }
 
index 71f88a163aa26bbdcfebc80f85e3ee0b6638bc1c..61282187c525814c65c3b3a2e81b040ac41afe2c 100644 (file)
@@ -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,