From: Masatake YAMATO Date: Tue, 20 Sep 2022 21:03:56 +0000 (+0900) Subject: lsfd: add new columns: SOCKNETNS, SOCKSTATE, and SOCKTYPE as stubs X-Git-Tag: v2.39-rc1~505^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7b50bd25f4cfa55462151efe5f70efa956fc294f;p=thirdparty%2Futil-linux.git lsfd: add new columns: SOCKNETNS, SOCKSTATE, and SOCKTYPE as stubs Signed-off-by: Masatake YAMATO --- diff --git a/misc-utils/lsfd-sock.c b/misc-utils/lsfd-sock.c index c768bce5bc..06201646dd 100644 --- a/misc-utils/lsfd-sock.c +++ b/misc-utils/lsfd-sock.c @@ -29,12 +29,6 @@ #include "lsfd.h" #include "lsfd-sock.h" -struct sock { - struct file file; - char *protoname; - struct sock_xinfo *xinfo; -}; - static void attach_sock_xinfo(struct file *file) { struct sock *sock = (struct sock *)file; @@ -59,6 +53,14 @@ static bool sock_fill_column(struct proc *proc __attribute__((__unused__)), if (scols_line_set_data(ln, column_index, sock->protoname)) err(EXIT_FAILURE, _("failed to add output data")); return true; + case COL_NAME: + if (sock->xinfo + && sock->xinfo->class && sock->xinfo->class->get_name) { + str = sock->xinfo->class->get_name (sock->xinfo, sock); + if (str) + break; + } + return false; case COL_SOURCE: if (major(file->stat.st_dev) == 0 && strncmp(file->name, "socket:", 7) == 0) { @@ -66,7 +68,37 @@ static bool sock_fill_column(struct proc *proc __attribute__((__unused__)), break; } return false; + case COL_SOCKNETNS: + if (sock->xinfo) { + xasprintf(&str, "%llu", + (unsigned long long)sock->xinfo->netns_inode); + break; + } + return false; + case COL_SOCKTYPE: + if (sock->xinfo + && sock->xinfo->class && sock->xinfo->class->get_type) { + str = sock->xinfo->class->get_type(sock->xinfo, sock); + if (str) + break; + } + return false; + case COL_SOCKSTATE: + if (sock->xinfo + && sock->xinfo->class && sock->xinfo->class->get_state) { + str = sock->xinfo->class->get_state(sock->xinfo, sock); + if (str) + break; + } + return false; default: + if (sock->xinfo && sock->xinfo->class + && sock->xinfo->class->fill_column) { + if (sock->xinfo->class->fill_column(proc, sock->xinfo, sock, ln, + column_id, column_index, + &str)) + break; + } return false; } diff --git a/misc-utils/lsfd-sock.h b/misc-utils/lsfd-sock.h index 0a22fc1810..155bf819ef 100644 --- a/misc-utils/lsfd-sock.h +++ b/misc-utils/lsfd-sock.h @@ -24,8 +24,11 @@ #ifndef UTIL_LINUX_LSFD_SOCK_H #define UTIL_LINUX_LSFD_SOCK_H +#include #include +#include "libsmartcols.h" + /* * xinfo: eXtra inforation about sockets */ @@ -36,8 +39,28 @@ struct sock_xinfo { const struct sock_xinfo_class *class; }; +struct sock { + struct file file; + char *protoname; + struct sock_xinfo *xinfo; +}; + struct sock_xinfo_class { const char *class; + /* Methods for filling socket related columns */ + char * (*get_name)(struct sock_xinfo *, struct sock *); + char * (*get_type)(struct sock_xinfo *, struct sock *); + char * (*get_state)(struct sock_xinfo *, struct sock *); + /* Method for class specific columns. + * Return true when the method fills the column. */ + bool (*fill_column)(struct proc *, + struct sock_xinfo *, + struct sock *, + struct libscols_line *, + int, + size_t, + char **str); + void (*free)(struct sock_xinfo *); }; diff --git a/misc-utils/lsfd.1.adoc b/misc-utils/lsfd.1.adoc index 20d9e981e5..0ee37c4f1c 100644 --- a/misc-utils/lsfd.1.adoc +++ b/misc-utils/lsfd.1.adoc @@ -251,6 +251,24 @@ Device ID (if special file). SIZE <``number``>:: File size. +SOCKNETS <``number``>:: +Inode identifying network namespace where the socket belogs to. + +SOCKSTATE <``string``>:: +State of socket. + +SOCKTYPE <``string``>:: +Type of socket. Here type means the second parameter of +socket system call: ++ +* stream +* dgram +* raw +* rdm +* seqpacket +* dccp +* packet + SOURCE <``string``>:: File system, partition, or device containing the file. @@ -508,6 +526,7 @@ mailto:kzak@redhat.com[Karel Zak] *lsof*(8) *pidof*(1) *proc*(5) +*socket*(2) *stat*(2) include::man-common/bugreports.adoc[] diff --git a/misc-utils/lsfd.c b/misc-utils/lsfd.c index 740223e438..cddf82a19f 100644 --- a/misc-utils/lsfd.c +++ b/misc-utils/lsfd.c @@ -185,6 +185,12 @@ static struct colinfo infos[] = { N_("device ID (if special file)") }, [COL_SIZE] = { "SIZE", 4, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER, N_("file size"), }, + [COL_SOCKNETNS]={"SOCKNETNS", 0, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER, + N_("inode identifying network namespace where the socket belongs to") }, + [COL_SOCKSTATE]={"SOCKSTATE", 0, SCOLS_FL_RIGHT, SCOLS_JSON_STRING, + N_("State of socket") }, + [COL_SOCKTYPE] ={"SOCKTYPE", 0, SCOLS_FL_RIGHT, SCOLS_JSON_STRING, + N_("Type of socket") }, [COL_SOURCE] = { "SOURCE", 0, SCOLS_FL_RIGHT, SCOLS_JSON_STRING, N_("file system, partition, or device containing file") }, [COL_STTYPE] = { "STTYPE", 0, SCOLS_FL_RIGHT, SCOLS_JSON_STRING, diff --git a/misc-utils/lsfd.h b/misc-utils/lsfd.h index 1633976dd6..ef83d5ef34 100644 --- a/misc-utils/lsfd.h +++ b/misc-utils/lsfd.h @@ -67,6 +67,9 @@ enum { COL_PROTONAME, COL_RDEV, COL_SIZE, + COL_SOCKNETNS, + COL_SOCKSTATE, + COL_SOCKTYPE, COL_SOURCE, COL_STTYPE, COL_TID,