123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- #include <netlink-private/netlink.h>
- #include <netlink/netlink.h>
- #include <netlink/cache.h>
- #include <netlink/idiag/idiagnl.h>
- #include <linux/inet_diag.h>
- int idiagnl_connect(struct nl_sock *sk)
- {
- return nl_connect(sk, NETLINK_INET_DIAG);
- }
- int idiagnl_send_simple(struct nl_sock *sk, int flags, uint8_t family,
- uint16_t states, uint16_t ext)
- {
- struct inet_diag_req req;
- memset(&req, 0, sizeof(req));
- flags |= NLM_F_ROOT;
- req.idiag_family = family;
- req.idiag_states = states;
- req.idiag_ext = ext;
- return nl_send_simple(sk, TCPDIAG_GETSOCK, flags, &req, sizeof(req));
- }
- static const struct trans_tbl idiag_states[] = {
- __ADD(IDIAG_SS_UNKNOWN, unknown)
- __ADD(IDIAG_SS_ESTABLISHED, established)
- __ADD(IDIAG_SS_SYN_SENT, syn_sent)
- __ADD(IDIAG_SS_SYN_RECV, syn_recv)
- __ADD(IDIAG_SS_FIN_WAIT1, fin_wait)
- __ADD(IDIAG_SS_FIN_WAIT2, fin_wait2)
- __ADD(IDIAG_SS_TIME_WAIT, time_wait)
- __ADD(IDIAG_SS_CLOSE, close)
- __ADD(IDIAG_SS_CLOSE_WAIT, close_wait)
- __ADD(IDIAG_SS_LAST_ACK, last_ack)
- __ADD(IDIAG_SS_LISTEN, listen)
- __ADD(IDIAG_SS_CLOSING, closing)
- __ADD(IDIAG_SS_MAX, max)
- { ((1<<IDIAG_SS_MAX)-1), "all" }
- };
- char * idiagnl_state2str(int state, char *buf, size_t len)
- {
- return __type2str(state, buf, len, idiag_states,
- ARRAY_SIZE(idiag_states));
- }
- int idiagnl_str2state(const char *name)
- {
- return __str2type(name, idiag_states, ARRAY_SIZE(idiag_states));
- }
- static const struct trans_tbl idiag_timers[] = {
- __ADD(IDIAG_TIMER_OFF, off)
- __ADD(IDIAG_TIMER_ON, on)
- __ADD(IDIAG_TIMER_KEEPALIVE, keepalive)
- __ADD(IDIAG_TIMER_TIMEWAIT, timewait)
- __ADD(IDIAG_TIMER_PERSIST, persist)
- __ADD(IDIAG_TIMER_UNKNOWN, unknown)
- };
- char * idiagnl_timer2str(int timer, char *buf, size_t len)
- {
- return __type2str(timer, buf, len, idiag_timers,
- ARRAY_SIZE(idiag_timers));
- }
- int idiagnl_str2timer(const char *name)
- {
- return __str2type(name, idiag_timers, ARRAY_SIZE(idiag_timers));
- }
- static const struct trans_tbl idiag_attrs[] = {
- __ADD(IDIAG_ATTR_NONE, none)
- __ADD(IDIAG_ATTR_MEMINFO, meminfo)
- __ADD(IDIAG_ATTR_INFO, info)
- __ADD(IDIAG_ATTR_VEGASINFO, vegasinfo)
- __ADD(IDIAG_ATTR_CONG, congestion)
- __ADD(IDIAG_ATTR_TOS, tos)
- __ADD(IDIAG_ATTR_TCLASS, tclass)
- };
- char *idiagnl_attrs2str(int attrs, char *buf, size_t len)
- {
- return __type2str(attrs, buf, len, idiag_attrs, ARRAY_SIZE(idiag_attrs));
- }
- static const struct trans_tbl idiagnl_tcpstates[] = {
- __ADD(TCP_CA_Open, open)
- __ADD(TCP_CA_Disorder, disorder)
- __ADD(TCP_CA_CWR, cwr)
- __ADD(TCP_CA_Recovery, recovery)
- __ADD(TCP_CA_Loss, loss)
- };
- char *idiagnl_tcpstate2str(uint8_t state, char *buf, size_t len)
- {
- return __type2str(state, buf, len, idiagnl_tcpstates,
- ARRAY_SIZE(idiagnl_tcpstates));
- }
- static const struct trans_tbl idiagnl_tcpopt_attrs[] = {
- __ADD(TCPI_OPT_TIMESTAMPS, timestamps)
- __ADD(TCPI_OPT_SACK, sACK)
- __ADD(TCPI_OPT_WSCALE, wscale)
- __ADD(TCPI_OPT_ECN, ecn)
- };
- char *idiagnl_tcpopts2str(uint8_t attrs, char *buf, size_t len)
- {
- return __flags2str(attrs, buf, len, idiagnl_tcpopt_attrs,
- ARRAY_SIZE(idiagnl_tcpopt_attrs));
- }
- char * idiagnl_shutdown2str(uint8_t shutdown, char *buf, size_t len)
- {
- if (shutdown == 0) {
- snprintf(buf, len, " ");
- return buf;
- } else if (shutdown == 1) {
- snprintf(buf, len, "receive shutdown");
- return buf;
- } else if (shutdown == 2) {
- snprintf(buf, len, "send shutdown");
- return buf;
- }
- return NULL;
- }
- static const struct trans_tbl idiag_exts[] = {
- __ADD(IDIAG_ATTR_NONE, none)
- __ADD(IDIAG_ATTR_MEMINFO, meminfo)
- __ADD(IDIAG_ATTR_INFO, info)
- __ADD(IDIAG_ATTR_VEGASINFO, vegasinfo)
- __ADD(IDIAG_ATTR_CONG, congestion)
- __ADD(IDIAG_ATTR_TOS, tos)
- __ADD(IDIAG_ATTR_TCLASS, tclass)
- };
- char *idiagnl_exts2str(uint8_t attrs, char *buf, size_t len)
- {
- return __flags2str(attrs, buf, len, idiag_exts, ARRAY_SIZE(idiag_exts));
- }
|