mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 08:13:54 -06:00
slirp: Add info usernet for dumping connection states
Break out sockstats from the slirp statistics and present them under the new info category "usernet". This patch also improves the current output /wrt proper reporting connection source and destination. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
4a82347a47
commit
6dbe553fe9
9 changed files with 102 additions and 55 deletions
86
slirp/misc.c
86
slirp/misc.c
|
@ -6,6 +6,9 @@
|
|||
*/
|
||||
|
||||
#include <slirp.h>
|
||||
#include <libslirp.h>
|
||||
|
||||
#include "monitor.h"
|
||||
|
||||
u_int curtime, time_fasttimo, last_slowtimo;
|
||||
|
||||
|
@ -906,3 +909,86 @@ rsh_exec(so,ns, user, host, args)
|
|||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void slirp_connection_info(Monitor *mon)
|
||||
{
|
||||
const char * const tcpstates[] = {
|
||||
[TCPS_CLOSED] = "CLOSED",
|
||||
[TCPS_LISTEN] = "LISTEN",
|
||||
[TCPS_SYN_SENT] = "SYN_SENT",
|
||||
[TCPS_SYN_RECEIVED] = "SYN_RCVD",
|
||||
[TCPS_ESTABLISHED] = "ESTABLISHED",
|
||||
[TCPS_CLOSE_WAIT] = "CLOSE_WAIT",
|
||||
[TCPS_FIN_WAIT_1] = "FIN_WAIT_1",
|
||||
[TCPS_CLOSING] = "CLOSING",
|
||||
[TCPS_LAST_ACK] = "LAST_ACK",
|
||||
[TCPS_FIN_WAIT_2] = "FIN_WAIT_2",
|
||||
[TCPS_TIME_WAIT] = "TIME_WAIT",
|
||||
};
|
||||
struct in_addr dst_addr;
|
||||
struct sockaddr_in src;
|
||||
socklen_t src_len;
|
||||
uint16_t dst_port;
|
||||
struct socket *so;
|
||||
const char *state;
|
||||
char buf[20];
|
||||
int n;
|
||||
|
||||
monitor_printf(mon, " Protocol[State] FD Source Address Port "
|
||||
"Dest. Address Port RecvQ SendQ\n");
|
||||
|
||||
for (so = tcb.so_next; so != &tcb; so = so->so_next) {
|
||||
if (so->so_state & SS_HOSTFWD) {
|
||||
state = "HOST_FORWARD";
|
||||
} else if (so->so_tcpcb) {
|
||||
state = tcpstates[so->so_tcpcb->t_state];
|
||||
} else {
|
||||
state = "NONE";
|
||||
}
|
||||
if (so->so_state & (SS_HOSTFWD | SS_INCOMING)) {
|
||||
src_len = sizeof(src);
|
||||
getsockname(so->s, (struct sockaddr *)&src, &src_len);
|
||||
dst_addr = so->so_laddr;
|
||||
dst_port = so->so_lport;
|
||||
} else {
|
||||
src.sin_addr = so->so_laddr;
|
||||
src.sin_port = so->so_lport;
|
||||
dst_addr = so->so_faddr;
|
||||
dst_port = so->so_fport;
|
||||
}
|
||||
n = snprintf(buf, sizeof(buf), " TCP[%s]", state);
|
||||
memset(&buf[n], ' ', 19 - n);
|
||||
buf[19] = 0;
|
||||
monitor_printf(mon, "%s %3d %15s %5d ", buf, so->s,
|
||||
src.sin_addr.s_addr ? inet_ntoa(src.sin_addr) : "*",
|
||||
ntohs(src.sin_port));
|
||||
monitor_printf(mon, "%15s %5d %5d %5d\n",
|
||||
inet_ntoa(dst_addr), ntohs(dst_port),
|
||||
so->so_rcv.sb_cc, so->so_snd.sb_cc);
|
||||
}
|
||||
|
||||
for (so = udb.so_next; so != &udb; so = so->so_next) {
|
||||
if (so->so_state & SS_HOSTFWD) {
|
||||
n = snprintf(buf, sizeof(buf), " UDP[HOST_FORWARD]");
|
||||
src_len = sizeof(src);
|
||||
getsockname(so->s, (struct sockaddr *)&src, &src_len);
|
||||
dst_addr = so->so_laddr;
|
||||
dst_port = so->so_lport;
|
||||
} else {
|
||||
n = snprintf(buf, sizeof(buf), " UDP[%d sec]",
|
||||
(so->so_expire - curtime) / 1000);
|
||||
src.sin_addr = so->so_laddr;
|
||||
src.sin_port = so->so_lport;
|
||||
dst_addr = so->so_faddr;
|
||||
dst_port = so->so_fport;
|
||||
}
|
||||
memset(&buf[n], ' ', 19 - n);
|
||||
buf[19] = 0;
|
||||
monitor_printf(mon, "%s %3d %15s %5d ", buf, so->s,
|
||||
src.sin_addr.s_addr ? inet_ntoa(src.sin_addr) : "*",
|
||||
ntohs(src.sin_port));
|
||||
monitor_printf(mon, "%15s %5d %5d %5d\n",
|
||||
inet_ntoa(dst_addr), ntohs(dst_port),
|
||||
so->so_rcv.sb_cc, so->so_snd.sb_cc);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue