12#include "nl-default.h"
14#include <linux/inet_diag.h>
16#include <netlink/netlink.h>
17#include <netlink/cache.h>
18#include <netlink/idiag/idiagnl.h>
20#include "nl-priv-dynamic-core/nl-core.h"
63 uint16_t states, uint16_t ext)
65 struct inet_diag_req req;
66 memset(&req, 0,
sizeof(req));
70 req.idiag_family = family;
71 req.idiag_states = states;
74 return nl_send_simple(sk, TCPDIAG_GETSOCK, flags, &req,
sizeof(req));
84static const struct trans_tbl idiag_states[] = {
85 __ADD(TCP_ESTABLISHED, established),
86 __ADD(TCP_SYN_SENT, syn_sent),
87 __ADD(TCP_SYN_RECV, syn_recv),
88 __ADD(TCP_FIN_WAIT1, fin_wait),
89 __ADD(TCP_FIN_WAIT2, fin_wait2),
90 __ADD(TCP_TIME_WAIT, time_wait),
91 __ADD(TCP_CLOSE, close),
92 __ADD(TCP_CLOSE_WAIT, close_wait),
93 __ADD(TCP_LAST_ACK, last_ack),
94 __ADD(TCP_LISTEN, listen),
95 __ADD(TCP_CLOSING, closing),
109 return __type2str(state, buf, len, idiag_states,
110 ARRAY_SIZE(idiag_states));
122 return __str2type(name, idiag_states, ARRAY_SIZE(idiag_states));
125static const struct trans_tbl idiag_timers[] = {
126 __ADD(IDIAGNL_TIMER_OFF, off),
127 __ADD(IDIAGNL_TIMER_ON, on),
128 __ADD(IDIAGNL_TIMER_KEEPALIVE, keepalive),
129 __ADD(IDIAGNL_TIMER_TIMEWAIT, timewait),
130 __ADD(IDIAGNL_TIMER_PERSIST, persist),
131 __ADD(IDIAGNL_TIMER_UNKNOWN, unknown),
144 return __type2str(timer, buf, len, idiag_timers,
145 ARRAY_SIZE(idiag_timers));
156 return __str2type(name, idiag_timers, ARRAY_SIZE(idiag_timers));
159static const struct trans_tbl idiag_attrs[] = {
160 __ADD(INET_DIAG_NONE, none),
161 __ADD(INET_DIAG_MEMINFO, meminfo),
162 __ADD(INET_DIAG_INFO, info),
163 __ADD(INET_DIAG_VEGASINFO, vegasinfo),
164 __ADD(INET_DIAG_CONG, congestion),
165 __ADD(INET_DIAG_TOS, tos),
166 __ADD(INET_DIAG_TCLASS, tclass),
167 __ADD(INET_DIAG_SKMEMINFO, skmeminfo),
168 __ADD(INET_DIAG_SHUTDOWN, shutdown),
183 return __type2str(attrs, buf, len, idiag_attrs, ARRAY_SIZE(idiag_attrs));
186static const struct trans_tbl idiag_exts[] = {
187 __ADD((1 << (INET_DIAG_MEMINFO - 1)), meminfo),
188 __ADD((1 << (INET_DIAG_INFO - 1)), info),
189 __ADD((1 << (INET_DIAG_VEGASINFO - 1)), vegasinfo),
190 __ADD((1 << (INET_DIAG_CONG - 1)), congestion),
191 __ADD((1 << (INET_DIAG_TOS - 1)), tos),
192 __ADD((1 << (INET_DIAG_TCLASS - 1)), tclass),
193 __ADD((1 << (INET_DIAG_SKMEMINFO - 1)), skmeminfo),
194 __ADD((1 << (INET_DIAG_SHUTDOWN - 1)), shutdown),
206 return __flags2str(attrs, buf, len, idiag_exts, ARRAY_SIZE(idiag_exts));
209static const struct trans_tbl idiagnl_tcpstates[] = {
210 __ADD(TCP_CA_Open, open),
211 __ADD(TCP_CA_Disorder, disorder),
212 __ADD(TCP_CA_CWR, cwr),
213 __ADD(TCP_CA_Recovery, recovery),
214 __ADD(TCP_CA_Loss, loss),
225 return __type2str(state, buf, len, idiagnl_tcpstates,
226 ARRAY_SIZE(idiagnl_tcpstates));
229static const struct trans_tbl idiagnl_tcpopt_attrs[] = {
230 __ADD(TCPI_OPT_TIMESTAMPS, timestamps),
231 __ADD(TCPI_OPT_SACK, sACK),
232 __ADD(TCPI_OPT_WSCALE, wscale),
233 __ADD(TCPI_OPT_ECN, ecn),
247 return __flags2str(attrs, buf, len, idiagnl_tcpopt_attrs,
248 ARRAY_SIZE(idiagnl_tcpopt_attrs));
262 snprintf(buf, len,
" ");
264 }
else if (shutdown == 1) {
265 snprintf(buf, len,
"receive shutdown");
267 }
else if (shutdown == 2) {
268 snprintf(buf, len,
"send shutdown");
int idiagnl_str2timer(const char *name)
Convert inet diag timer string to int.
int idiagnl_str2state(const char *name)
Convert inet diag socket state string to int.
char * idiagnl_timer2str(int timer, char *buf, size_t len)
Convert inet diag timer types to strings.
int idiagnl_connect(struct nl_sock *sk)
Create and connect idiag netlink socket.
char * idiagnl_shutdown2str(uint8_t shutdown, char *buf, size_t len)
Convert shutdown state to string.
char * idiagnl_state2str(int state, char *buf, size_t len)
Convert inet diag socket states to strings.
int idiagnl_send_simple(struct nl_sock *sk, int flags, uint8_t family, uint16_t states, uint16_t ext)
Send trivial idiag netlink message.
char * idiagnl_exts2str(uint8_t attrs, char *buf, size_t len)
Convert inet diag extension flags to a string.
char * idiagnl_attrs2str(int attrs, char *buf, size_t len)
Convert inet diag extension type to a string.
char * idiagnl_tcpstate2str(uint8_t state, char *buf, size_t len)
Convert inetdiag tcp states to strings.
char * idiagnl_tcpopts2str(uint8_t attrs, char *buf, size_t len)
Convert TCP option attributes to string.
int nl_connect(struct nl_sock *sk, int protocol)
Create file descriptor and bind socket.
int nl_send_simple(struct nl_sock *sk, int type, int flags, void *buf, size_t size)
Construct and transmit a Netlink message.