18 #include <netlink-private/netlink.h> 19 #include <netlink/netlink.h> 20 #include <netlink/cache.h> 21 #include <netlink/idiag/idiagnl.h> 22 #include <linux/inet_diag.h> 64 uint16_t states, uint16_t ext)
66 struct inet_diag_req req;
67 memset(&req, 0,
sizeof(req));
71 req.idiag_family = family;
72 req.idiag_states = states;
75 return nl_send_simple(sk, TCPDIAG_GETSOCK, flags, &req,
sizeof(req));
85 static const struct trans_tbl idiag_states[] = {
86 __ADD(TCP_ESTABLISHED, established),
87 __ADD(TCP_SYN_SENT, syn_sent),
88 __ADD(TCP_SYN_RECV, syn_recv),
89 __ADD(TCP_FIN_WAIT1, fin_wait),
90 __ADD(TCP_FIN_WAIT2, fin_wait2),
91 __ADD(TCP_TIME_WAIT, time_wait),
92 __ADD(TCP_CLOSE, close),
93 __ADD(TCP_CLOSE_WAIT, close_wait),
94 __ADD(TCP_LAST_ACK, last_ack),
95 __ADD(TCP_LISTEN, listen),
96 __ADD(TCP_CLOSING, closing),
110 return __type2str(state, buf, len, idiag_states,
111 ARRAY_SIZE(idiag_states));
123 return __str2type(name, idiag_states, ARRAY_SIZE(idiag_states));
126 static const struct trans_tbl idiag_timers[] = {
127 __ADD(IDIAGNL_TIMER_OFF, off),
128 __ADD(IDIAGNL_TIMER_ON, on),
129 __ADD(IDIAGNL_TIMER_KEEPALIVE, keepalive),
130 __ADD(IDIAGNL_TIMER_TIMEWAIT, timewait),
131 __ADD(IDIAGNL_TIMER_PERSIST, persist),
132 __ADD(IDIAGNL_TIMER_UNKNOWN, unknown),
145 return __type2str(timer, buf, len, idiag_timers,
146 ARRAY_SIZE(idiag_timers));
157 return __str2type(name, idiag_timers, ARRAY_SIZE(idiag_timers));
160 static const struct trans_tbl idiag_attrs[] = {
161 __ADD(INET_DIAG_NONE, none),
162 __ADD(INET_DIAG_MEMINFO, meminfo),
163 __ADD(INET_DIAG_INFO, info),
164 __ADD(INET_DIAG_VEGASINFO, vegasinfo),
165 __ADD(INET_DIAG_CONG, congestion),
166 __ADD(INET_DIAG_TOS, tos),
167 __ADD(INET_DIAG_TCLASS, tclass),
168 __ADD(INET_DIAG_SKMEMINFO, skmeminfo),
169 __ADD(INET_DIAG_SHUTDOWN, shutdown),
184 return __type2str(attrs, buf, len, idiag_attrs, ARRAY_SIZE(idiag_attrs));
187 static const struct trans_tbl idiag_exts[] = {
188 __ADD((1 << (INET_DIAG_MEMINFO - 1)), meminfo),
189 __ADD((1 << (INET_DIAG_INFO - 1)), info),
190 __ADD((1 << (INET_DIAG_VEGASINFO - 1)), vegasinfo),
191 __ADD((1 << (INET_DIAG_CONG - 1)), congestion),
192 __ADD((1 << (INET_DIAG_TOS - 1)), tos),
193 __ADD((1 << (INET_DIAG_TCLASS - 1)), tclass),
194 __ADD((1 << (INET_DIAG_SKMEMINFO - 1)), skmeminfo),
195 __ADD((1 << (INET_DIAG_SHUTDOWN - 1)), shutdown),
207 return __flags2str(attrs, buf, len, idiag_exts, ARRAY_SIZE(idiag_exts));
210 static const struct trans_tbl idiagnl_tcpstates[] = {
211 __ADD(TCP_CA_Open, open),
212 __ADD(TCP_CA_Disorder, disorder),
213 __ADD(TCP_CA_CWR, cwr),
214 __ADD(TCP_CA_Recovery, recovery),
215 __ADD(TCP_CA_Loss, loss),
226 return __type2str(state, buf, len, idiagnl_tcpstates,
227 ARRAY_SIZE(idiagnl_tcpstates));
230 static const struct trans_tbl idiagnl_tcpopt_attrs[] = {
231 __ADD(TCPI_OPT_TIMESTAMPS, timestamps),
232 __ADD(TCPI_OPT_SACK, sACK),
233 __ADD(TCPI_OPT_WSCALE, wscale),
234 __ADD(TCPI_OPT_ECN, ecn),
248 return __flags2str(attrs, buf, len, idiagnl_tcpopt_attrs,
249 ARRAY_SIZE(idiagnl_tcpopt_attrs));
263 snprintf(buf, len,
" ");
265 }
else if (shutdown == 1) {
266 snprintf(buf, len,
"receive shutdown");
268 }
else if (shutdown == 2) {
269 snprintf(buf, len,
"send shutdown");
char * idiagnl_exts2str(uint8_t attrs, char *buf, size_t len)
Convert inet diag extension flags to a string.
int nl_connect(struct nl_sock *sk, int protocol)
Create file descriptor and bind socket.
int idiagnl_str2state(const char *name)
Convert inet diag socket state string to int.
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_shutdown2str(uint8_t shutdown, char *buf, size_t len)
Convert shutdown state to string.
char * idiagnl_attrs2str(int attrs, char *buf, size_t len)
Convert inet diag extension type to a string.
int idiagnl_str2timer(const char *name)
Convert inet diag timer string to int.
char * idiagnl_tcpopts2str(uint8_t attrs, char *buf, size_t len)
Convert TCP option attributes to string.
int idiagnl_connect(struct nl_sock *sk)
Create and connect idiag netlink socket.
char * idiagnl_tcpstate2str(uint8_t state, char *buf, size_t len)
Convert inetdiag tcp states to strings.
int nl_send_simple(struct nl_sock *sk, int type, int flags, void *buf, size_t size)
Construct and transmit a Netlink message.
char * idiagnl_timer2str(int timer, char *buf, size_t len)
Convert inet diag timer types to strings.
char * idiagnl_state2str(int state, char *buf, size_t len)
Convert inet diag socket states to strings.