12#include <netlink-private/netlink.h>
13#include <netlink/netlink.h>
14#include <netlink/cache.h>
15#include <netlink/idiag/idiagnl.h>
16#include <linux/inet_diag.h>
59 uint16_t states, uint16_t ext)
61 struct inet_diag_req req;
62 memset(&req, 0,
sizeof(req));
66 req.idiag_family = family;
67 req.idiag_states = states;
70 return nl_send_simple(sk, TCPDIAG_GETSOCK, flags, &req,
sizeof(req));
80static const struct trans_tbl idiag_states[] = {
81 __ADD(TCP_ESTABLISHED, established),
82 __ADD(TCP_SYN_SENT, syn_sent),
83 __ADD(TCP_SYN_RECV, syn_recv),
84 __ADD(TCP_FIN_WAIT1, fin_wait),
85 __ADD(TCP_FIN_WAIT2, fin_wait2),
86 __ADD(TCP_TIME_WAIT, time_wait),
87 __ADD(TCP_CLOSE, close),
88 __ADD(TCP_CLOSE_WAIT, close_wait),
89 __ADD(TCP_LAST_ACK, last_ack),
90 __ADD(TCP_LISTEN, listen),
91 __ADD(TCP_CLOSING, closing),
105 return __type2str(state, buf, len, idiag_states,
106 ARRAY_SIZE(idiag_states));
118 return __str2type(name, idiag_states, ARRAY_SIZE(idiag_states));
121static const struct trans_tbl idiag_timers[] = {
122 __ADD(IDIAGNL_TIMER_OFF, off),
123 __ADD(IDIAGNL_TIMER_ON, on),
124 __ADD(IDIAGNL_TIMER_KEEPALIVE, keepalive),
125 __ADD(IDIAGNL_TIMER_TIMEWAIT, timewait),
126 __ADD(IDIAGNL_TIMER_PERSIST, persist),
127 __ADD(IDIAGNL_TIMER_UNKNOWN, unknown),
140 return __type2str(timer, buf, len, idiag_timers,
141 ARRAY_SIZE(idiag_timers));
152 return __str2type(name, idiag_timers, ARRAY_SIZE(idiag_timers));
155static const struct trans_tbl idiag_attrs[] = {
156 __ADD(INET_DIAG_NONE, none),
157 __ADD(INET_DIAG_MEMINFO, meminfo),
158 __ADD(INET_DIAG_INFO, info),
159 __ADD(INET_DIAG_VEGASINFO, vegasinfo),
160 __ADD(INET_DIAG_CONG, congestion),
161 __ADD(INET_DIAG_TOS, tos),
162 __ADD(INET_DIAG_TCLASS, tclass),
163 __ADD(INET_DIAG_SKMEMINFO, skmeminfo),
164 __ADD(INET_DIAG_SHUTDOWN, shutdown),
179 return __type2str(attrs, buf, len, idiag_attrs, ARRAY_SIZE(idiag_attrs));
182static const struct trans_tbl idiag_exts[] = {
183 __ADD((1 << (INET_DIAG_MEMINFO - 1)), meminfo),
184 __ADD((1 << (INET_DIAG_INFO - 1)), info),
185 __ADD((1 << (INET_DIAG_VEGASINFO - 1)), vegasinfo),
186 __ADD((1 << (INET_DIAG_CONG - 1)), congestion),
187 __ADD((1 << (INET_DIAG_TOS - 1)), tos),
188 __ADD((1 << (INET_DIAG_TCLASS - 1)), tclass),
189 __ADD((1 << (INET_DIAG_SKMEMINFO - 1)), skmeminfo),
190 __ADD((1 << (INET_DIAG_SHUTDOWN - 1)), shutdown),
202 return __flags2str(attrs, buf, len, idiag_exts, ARRAY_SIZE(idiag_exts));
205static const struct trans_tbl idiagnl_tcpstates[] = {
206 __ADD(TCP_CA_Open, open),
207 __ADD(TCP_CA_Disorder, disorder),
208 __ADD(TCP_CA_CWR, cwr),
209 __ADD(TCP_CA_Recovery, recovery),
210 __ADD(TCP_CA_Loss, loss),
221 return __type2str(state, buf, len, idiagnl_tcpstates,
222 ARRAY_SIZE(idiagnl_tcpstates));
225static const struct trans_tbl idiagnl_tcpopt_attrs[] = {
226 __ADD(TCPI_OPT_TIMESTAMPS, timestamps),
227 __ADD(TCPI_OPT_SACK, sACK),
228 __ADD(TCPI_OPT_WSCALE, wscale),
229 __ADD(TCPI_OPT_ECN, ecn),
243 return __flags2str(attrs, buf, len, idiagnl_tcpopt_attrs,
244 ARRAY_SIZE(idiagnl_tcpopt_attrs));
258 snprintf(buf, len,
" ");
260 }
else if (shutdown == 1) {
261 snprintf(buf, len,
"receive shutdown");
263 }
else if (shutdown == 2) {
264 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.