Use SIGUSR1 to show tcp_info

This commit is contained in:
angt
2015-11-29 18:10:15 +01:00
parent 3472771a6f
commit 2f2e5e6f99

View File

@@ -48,6 +48,7 @@ struct crypto_ctx {
}; };
volatile sig_atomic_t gt_close = 0; volatile sig_atomic_t gt_close = 0;
volatile sig_atomic_t gt_info = 0;
static int64_t dt_ms (struct timeval *ta, struct timeval *tb) static int64_t dt_ms (struct timeval *ta, struct timeval *tb)
{ {
@@ -319,20 +320,29 @@ static void gt_sa_stop (int sig)
{ {
switch (sig) { switch (sig) {
case SIGINT: case SIGINT:
case SIGQUIT:
case SIGTERM: case SIGTERM:
gt_close = 1; gt_close = 1;
break;
case SIGUSR1:
gt_info = 1;
break;
} }
} }
static void gt_set_signal (void) static void gt_set_signal (void)
{ {
struct sigaction sa; struct sigaction sa = {
.sa_flags = 0,
};
byte_set(&sa, 0, sizeof(sa)); sigemptyset(&sa.sa_mask);
sa.sa_handler = gt_sa_stop; sa.sa_handler = gt_sa_stop;
sigaction(SIGINT, &sa, NULL); sigaction(SIGINT, &sa, NULL);
sigaction(SIGQUIT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL); sigaction(SIGTERM, &sa, NULL);
sigaction(SIGUSR1, &sa, NULL);
sa.sa_handler = SIG_IGN; sa.sa_handler = SIG_IGN;
sigaction(SIGHUP, &sa, NULL); sigaction(SIGHUP, &sa, NULL);
@@ -644,13 +654,6 @@ int main (int argc, char **argv)
long ka_idle = -1; long ka_idle = -1;
long ka_interval = -1; long ka_interval = -1;
#ifdef TCP_INFO
struct {
struct timeval time;
struct tcp_info info;
} tcpinfo = {0};
#endif
struct option ka_opts[] = { struct option ka_opts[] = {
{ "count", &ka_count, option_long }, { "count", &ka_count, option_long },
{ "idle", &ka_idle, option_long }, { "idle", &ka_idle, option_long },
@@ -671,7 +674,6 @@ int main (int argc, char **argv)
{ "buffer-size", &buffer_size, option_long }, { "buffer-size", &buffer_size, option_long },
{ "noquickack", NULL, option_option }, { "noquickack", NULL, option_option },
{ "daemon", NULL, option_option }, { "daemon", NULL, option_option },
{ "debug", NULL, option_option },
{ "version", NULL, option_option }, { "version", NULL, option_option },
{ NULL }, { NULL },
}; };
@@ -686,7 +688,6 @@ int main (int argc, char **argv)
int listener = option_is_set(opts, "listener"); int listener = option_is_set(opts, "listener");
int delay = option_is_set(opts, "delay"); int delay = option_is_set(opts, "delay");
int debug = option_is_set(opts, "debug");
int keepalive = option_is_set(opts, "keepalive"); int keepalive = option_is_set(opts, "keepalive");
int noquickack = option_is_set(opts, "noquickack"); int noquickack = option_is_set(opts, "noquickack");
@@ -843,14 +844,18 @@ int main (int argc, char **argv)
FD_CLR(sock.fd, &wfds); FD_CLR(sock.fd, &wfds);
FD_CLR(tun.fd, &wfds); FD_CLR(tun.fd, &wfds);
#ifdef TCP_INFO // TODO
struct timeval now; // struct timeval now;
gettimeofday(&now, NULL); // gettimeofday(&now, NULL);
if (debug && dt_ms(&now, &tcpinfo.time)>1000LL) { #ifdef TCP_INFO
tcpinfo.time = now; if (gt_info) {
if (sk_get_info(sock.fd, &tcpinfo.info)) struct tcp_info ti;
print_tcp_info(sockname, &tcpinfo.info);
if (sk_get_info(sock.fd, &ti))
print_tcp_info(sockname, &ti);
gt_info = 0;
} }
#endif #endif