File: sock.h

package info (click to toggle)
util-linux 2.42~rc1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 101,864 kB
  • sloc: ansic: 185,733; sh: 24,450; yacc: 1,288; makefile: 534; xml: 422; python: 316; lex: 89; ruby: 75; csh: 37; exp: 19; sed: 16; perl: 15; sql: 9
file content (86 lines) | stat: -rw-r--r-- 2,663 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * lsfd(1) - list file descriptors
 *
 * Copyright (C) 2022 Red Hat, Inc. All rights reserved.
 * Written by Masatake YAMATO <yamato@redhat.com>
 *
 * Very generally based on lsof(8) by Victor A. Abell <abe@purdue.edu>
 * It supports multiple OSes. lsfd specializes to Linux.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it would be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
#ifndef UTIL_LINUX_LSFD_SOCK_H
#define UTIL_LINUX_LSFD_SOCK_H

#include <stdbool.h>
#include <sys/stat.h>

#include "libsmartcols.h"

/*
 * xinfo: eXtra information about sockets
 */
struct sock_xinfo {
	ino_t inode;		/* inode in sockfs */
	ino_t netns_inode;	/* inode of the network namespace where
				 * the socket was created */
	const struct sock_xinfo_class *class;
};

struct sock {
	struct file file;
	char *protoname;
	struct sock_xinfo *xinfo;
	struct ipc_endpoint endpoint;

	/*
	 * There are two netns_inode fields reachable from struct sock:
	 *
	 * - sock->xinfo->netns_inode: filled via sock_diag netlink (when available)
	 * - sock->netns_inode: filled via ioctl(SIOCGSKNS)
	 *
	 * Use sock->netns_inode as a fallback when xinfo is unavailable or
	 * does not provide the netns inode.
	 */
	ino_t netns_inode;

};

struct sock_xinfo_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 *);
	bool (*get_listening)(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);
	struct ipc_class *(*get_ipc_class)(struct sock_xinfo *, struct sock *);

	void (*free)(struct sock_xinfo *);
};

void initialize_sock_xinfos(void);
void finalize_sock_xinfos(void);

struct sock_xinfo *get_sock_xinfo(ino_t inode);

#endif /* UTIL_LINUX_LSFD_SOCK_H */