1 /*
2  * netlink/idiag/idiagnl.h		Inetdiag Netlink
3  *
4  *	This library is free software; you can redistribute it and/or
5  *	modify it under the terms of the GNU Lesser General Public
6  *	License as published by the Free Software Foundation version 2.1
7  *	of the License.
8  *
9  * Copyright (c) 2013 Sassano Systems LLC <joe@sassanosystems.com>
10  */
11 
12 #ifndef NETLINK_IDIAGNL_H_
13 #define NETLINK_IDIAGNL_H_
14 
15 #include <netlink/netlink.h>
16 #include <linux/sock_diag.h>
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 /*************************************************************
23  * The following part contains DEPRECATED names and defines.
24  * Don't use them.
25  *************************************************************/
26 
27 /**
28  * Inet Diag message types
29  *
30  * deprecated: use TCPDIAG_GETSOCK, DCCPDIAG_GETSOCK and
31  * INET_DIAG_GETSOCK_MAX from linux/inet_diag.h
32  */
33 #define IDIAG_TCPDIAG_GETSOCK	18
34 #define IDIAG_DCCPDIAG_GETSOCK	19
35 #define IDIAG_GETSOCK_MAX	24
36 
37 /**
38  * Socket state identifiers
39  * @ingroup idiag
40  * @deprecated: use instead the TCP_* defines from netinet/tcp.h.
41  */
42 enum {
43 	IDIAG_SS_UNKNOWN           = 0,
44 
45 	IDIAG_SS_ESTABLISHED       = 1,  /* TCP_ESTABLISHED */
46 	IDIAG_SS_SYN_SENT          = 2,  /* TCP_SYN_SENT */
47 	IDIAG_SS_SYN_RECV          = 3,  /* TCP_SYN_RECV */
48 	IDIAG_SS_FIN_WAIT1         = 4,  /* TCP_FIN_WAIT1 */
49 	IDIAG_SS_FIN_WAIT2         = 5,  /* TCP_FIN_WAIT2 */
50 	IDIAG_SS_TIME_WAIT         = 6,  /* TCP_TIME_WAIT */
51 	IDIAG_SS_CLOSE             = 7,  /* TCP_CLOSE */
52 	IDIAG_SS_CLOSE_WAIT        = 8,  /* TCP_CLOSE_WAIT */
53 	IDIAG_SS_LAST_ACK          = 9,  /* TCP_LAST_ACK */
54 	IDIAG_SS_LISTEN            = 10, /* TCP_LISTEN */
55 	IDIAG_SS_CLOSING           = 11, /* TCP_CLOSING */
56 
57 	IDIAG_SS_MAX               = 12,
58 };
59 
60 /**
61  * Macro to represent all socket states.
62  * @ingroup idiag
63  * @deprecated
64  */
65 #define IDIAG_SS_ALL  IDIAGNL_SS_ALL
66 
67 
68 /**
69  * Inet Diag extended attributes
70  * @ingroup idiag
71  * @deprecated These attributes should not be used. They mirror the
72  * INET_DIAG_* extension flags from kernel headers. Use those instead. */
73 enum {
74 	IDIAG_ATTR_NONE         = 0, /* INET_DIAG_NONE */
75 	IDIAG_ATTR_MEMINFO      = 1, /* INET_DIAG_MEMINFO */
76 	IDIAG_ATTR_INFO         = 2, /* INET_DIAG_INFO */
77 	IDIAG_ATTR_VEGASINFO    = 3, /* INET_DIAG_VEGASINFO */
78 	IDIAG_ATTR_CONG         = 4, /* INET_DIAG_CONG */
79 	IDIAG_ATTR_TOS          = 5, /* INET_DIAG_TOS */
80 	IDIAG_ATTR_TCLASS       = 6, /* INET_DIAG_TCLASS */
81 	IDIAG_ATTR_SKMEMINFO    = 7, /* INET_DIAG_SKMEMINFO */
82 	IDIAG_ATTR_SHUTDOWN     = 8, /* INET_DIAG_SHUTDOWN */
83 
84 	/* IDIAG_ATTR_MAX was wrong, because it did not correspond to
85 	 * INET_DIAG_MAX. Anyway, freeze it to the previous value. */
86 	IDIAG_ATTR_MAX          = 9,
87 
88 	IDIAG_ATTR_ALL          = (1<<IDIAG_ATTR_MAX) - 1,
89 };
90 
91 
92 /* deprectated keep these only for compatibility, DO NOT USE THEM */
93 #define IDIAG_SK_MEMINFO_RMEM_ALLOC                      0  /* SK_MEMINFO_RMEM_ALLOC */
94 #define IDIAG_SK_MEMINFO_RCVBUF                          1  /* SK_MEMINFO_RCVBUF */
95 #define IDIAG_SK_MEMINFO_WMEM_ALLOC                      2  /* SK_MEMINFO_WMEM_ALLOC */
96 #define IDIAG_SK_MEMINFO_SNDBUF                          3  /* SK_MEMINFO_SNDBUF */
97 #define IDIAG_SK_MEMINFO_FWD_ALLOC                       4  /* SK_MEMINFO_FWD_ALLOC */
98 #define IDIAG_SK_MEMINFO_WMEM_QUEUED                     5  /* SK_MEMINFO_WMEM_QUEUED */
99 #define IDIAG_SK_MEMINFO_OPTMEM                          6  /* SK_MEMINFO_OPTMEM */
100 #define IDIAG_SK_MEMINFO_BACKLOG                         7  /* SK_MEMINFO_BACKLOG */
101 #define IDIAG_SK_MEMINFO_VARS              SK_MEMINFO_VARS
102 
103 /* deprecated names. */
104 #define IDIAG_TIMER_OFF                 IDIAGNL_TIMER_OFF
105 #define IDIAG_TIMER_ON                  IDIAGNL_TIMER_ON
106 #define IDIAG_TIMER_KEEPALIVE           IDIAGNL_TIMER_KEEPALIVE
107 #define IDIAG_TIMER_TIMEWAIT            IDIAGNL_TIMER_TIMEWAIT
108 #define IDIAG_TIMER_PERSIST             IDIAGNL_TIMER_PERSIST
109 #define IDIAG_TIMER_UNKNOWN             IDIAGNL_TIMER_UNKNOWN
110 
111 /*************************************************************/
112 
113 /**
114  * Macro to represent all socket states.
115  * @ingroup idiag
116  */
117 #define IDIAGNL_SS_ALL (((1<<12)-1))
118 
119 /**
120  * Socket timer indentifiers
121  * @ingroupd idiag
122  */
123 enum {
124 	IDIAGNL_TIMER_OFF               = 0,
125 	IDIAGNL_TIMER_ON                = 1,
126 	IDIAGNL_TIMER_KEEPALIVE         = 2,
127 	IDIAGNL_TIMER_TIMEWAIT          = 3,
128 	IDIAGNL_TIMER_PERSIST           = 4,
129 	IDIAGNL_TIMER_UNKNOWN           = 5,
130 };
131 
132 extern char *	idiagnl_state2str(int, char *, size_t);
133 extern int	idiagnl_str2state(const char *);
134 
135 extern int	idiagnl_connect(struct nl_sock *);
136 extern int	idiagnl_send_simple(struct nl_sock *, int, uint8_t, uint16_t,
137                                     uint16_t);
138 
139 extern char *		idiagnl_timer2str(int, char *, size_t);
140 extern int		idiagnl_str2timer(const char *);
141 extern char *		idiagnl_attrs2str(int, char *, size_t);
142 extern char *		idiagnl_tcpstate2str(uint8_t, char *, size_t);
143 extern char *		idiagnl_tcpopts2str(uint8_t, char *, size_t);
144 extern char *		idiagnl_shutdown2str(uint8_t, char *, size_t);
145 extern char *		idiagnl_exts2str(uint8_t, char *, size_t);
146 
147 #ifdef __cplusplus
148 }
149 #endif /* __cplusplus */
150 
151 #endif /* NETLINK_IDIAGNL_H_ */
152