#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;
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) {
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;
}
#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
*/
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 *);
};
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.
*lsof*(8)
*pidof*(1)
*proc*(5)
+*socket*(2)
*stat*(2)
include::man-common/bugreports.adoc[]
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,
COL_PROTONAME,
COL_RDEV,
COL_SIZE,
+ COL_SOCKNETNS,
+ COL_SOCKSTATE,
+ COL_SOCKTYPE,
COL_SOURCE,
COL_STTYPE,
COL_TID,