]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: add new columns: SOCKNETNS, SOCKSTATE, and SOCKTYPE as stubs
authorMasatake YAMATO <yamato@redhat.com>
Tue, 20 Sep 2022 21:03:56 +0000 (06:03 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Sat, 24 Sep 2022 12:09:15 +0000 (21:09 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
misc-utils/lsfd-sock.c
misc-utils/lsfd-sock.h
misc-utils/lsfd.1.adoc
misc-utils/lsfd.c
misc-utils/lsfd.h

index c768bce5bc47816f95ac39532b5896f758c094a5..06201646dd0cd04de88f4532530173860260a8e2 100644 (file)
 #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;
        }
 
index 0a22fc18100423f186b6713a7f1f0bf7d73d5db2..155bf819ef35a3504ce5881e5599293a25c7c844 100644 (file)
 #ifndef UTIL_LINUX_LSFD_SOCK_H
 #define UTIL_LINUX_LSFD_SOCK_H
 
+#include <stdbool.h>
 #include <sys/stat.h>
 
+#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 *);
 };
 
index 20d9e981e59913302917f1f64f88a77c39bf1074..0ee37c4f1cc0d56772aa46ca2a8e73faeffbc54e 100644 (file)
@@ -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[]
index 740223e43807403eeb854cafabe178acf89d5517..cddf82a19f36a0d36b213bc23ddbe3641fc63381 100644 (file)
@@ -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,
index 1633976dd669b2cee306effa4f8eff684e724f60..ef83d5ef3456517350441e6a5f56af7f84da56da 100644 (file)
@@ -67,6 +67,9 @@ enum {
        COL_PROTONAME,
        COL_RDEV,
        COL_SIZE,
+       COL_SOCKNETNS,
+       COL_SOCKSTATE,
+       COL_SOCKTYPE,
        COL_SOURCE,
        COL_STTYPE,
        COL_TID,