From 1065879c8c6e8cdf8d3755024241f31eaabd4138 Mon Sep 17 00:00:00 2001 From: Scott Lamb Date: Wed, 7 Nov 2007 02:49:57 +0000 Subject: [PATCH] Purge through the control socket --- doc/tinc.texi | 6 +++--- doc/tincctl.8.in | 2 ++ doc/tincd.8.in | 2 -- src/control.c | 6 ++++++ src/control_common.h | 1 + src/net.c | 11 +---------- src/net.h | 2 +- src/tincctl.c | 5 +++++ 8 files changed, 19 insertions(+), 16 deletions(-) diff --git a/doc/tinc.texi b/doc/tinc.texi index 541d2de7..e9534728 100644 --- a/doc/tinc.texi +++ b/doc/tinc.texi @@ -1569,9 +1569,6 @@ New outgoing connections specified in @file{tinc.conf} will be made. Temporarily increases debug level to 5. Send this signal again to revert to the original level. -@item WINCH -Purges all information remembered about unreachable nodes. - @end table @c ================================================================== @@ -1854,6 +1851,9 @@ Dump a list of all meta connections with ourself. @item dump graph Dump a graph of the VPN in dotty format. +@item purge +Purges all information remembered about unreachable nodes. + @end table diff --git a/doc/tincctl.8.in b/doc/tincctl.8.in index 734bb4f5..40bd1361 100644 --- a/doc/tincctl.8.in +++ b/doc/tincctl.8.in @@ -76,6 +76,8 @@ Dump a list of all meta connections with ourself. Dump a graph of the VPN in .Xr dotty 1 format. +.It purge +Purges all information remembered about unreachable nodes. .El .Sh BUGS The "start", "restart", and "reload" commands are not yet implemented. diff --git a/doc/tincd.8.in b/doc/tincd.8.in index f136a1bc..96c773f1 100644 --- a/doc/tincd.8.in +++ b/doc/tincd.8.in @@ -98,8 +98,6 @@ will be made. .It INT Temporarily increases debug level to 5. Send this signal again to revert to the original level. -.It WINCH -Purges all information remembered about unreachable nodes. .El .Sh DEBUG LEVELS The tinc daemon can send a lot of messages to the syslog. diff --git a/src/control.c b/src/control.c index 19ac37a4..2c5d4be8 100644 --- a/src/control.c +++ b/src/control.c @@ -97,6 +97,12 @@ static void handle_control_data(struct bufferevent *event, void *data) { goto respond; } + if(req.type == REQ_PURGE) { + logger(LOG_NOTICE, _("Got '%s' command"), "purge"); + purge(); + goto respond; + } + logger(LOG_DEBUG, _("Malformed control command received")); res.res_errno = EINVAL; diff --git a/src/control_common.h b/src/control_common.h index 750098e3..bceaa710 100644 --- a/src/control_common.h +++ b/src/control_common.h @@ -31,6 +31,7 @@ enum request_type { REQ_DUMP_SUBNETS, REQ_DUMP_CONNECTIONS, REQ_DUMP_GRAPH, + REQ_PURGE, }; #define TINC_CTL_VERSION_CURRENT 0 diff --git a/src/net.c b/src/net.c index 1be4ed84..9d4a0a2b 100644 --- a/src/net.c +++ b/src/net.c @@ -41,7 +41,7 @@ /* Purge edges and subnets of unreachable nodes. Use carefully. */ -static void purge(void) { +void purge(void) { splay_node_t *nnode, *nnext, *enode, *enext, *snode, *snext; node_t *n; edge_t *e; @@ -252,11 +252,6 @@ static void sigint_handler(int signal, short events, void *data) { } } -static void sigwinch_handler(int signal, short events, void *data) { - logger(LOG_NOTICE, _("Got %s signal"), strsignal(signal)); - purge(); -} - static void sighup_handler(int signal, short events, void *data) { connection_t *c; splay_node_t *node, *next; @@ -333,7 +328,6 @@ int main_loop(void) { struct event sigint_event; struct event sigterm_event; struct event sigquit_event; - struct event sigwinch_event; struct event sigalrm_event; cp(); @@ -348,8 +342,6 @@ int main_loop(void) { signal_add(&sigterm_event, NULL); signal_set(&sigquit_event, SIGQUIT, sigterm_handler, NULL); signal_add(&sigquit_event, NULL); - signal_set(&sigwinch_event, SIGWINCH, sigwinch_handler, NULL); - signal_add(&sigwinch_event, NULL); signal_set(&sigalrm_event, SIGALRM, sigalrm_handler, NULL); signal_add(&sigalrm_event, NULL); @@ -362,7 +354,6 @@ int main_loop(void) { signal_del(&sigint_event); signal_del(&sigterm_event); signal_del(&sigquit_event); - signal_del(&sigwinch_event); signal_del(&sigalrm_event); event_del(&timeout_event); diff --git a/src/net.h b/src/net.h index 943b7e61..fd14c37b 100644 --- a/src/net.h +++ b/src/net.h @@ -126,7 +126,6 @@ extern listen_socket_t listen_socket[MAXSOCKETS]; extern int listen_sockets; extern int keylifetime; extern bool do_prune; -extern bool do_purge; extern char *myport; extern EVP_CIPHER_CTX packet_ctx; @@ -156,6 +155,7 @@ extern void send_mtu_probe(struct node_t *); extern void handle_device_data(int, short, void *); extern void handle_meta_connection_data(int, short, void *); extern void regenerate_key(); +extern void purge(void); #ifndef HAVE_MINGW #define closesocket(s) close(s) diff --git a/src/tincctl.c b/src/tincctl.c index 4982e6b2..56179c6e 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -89,6 +89,7 @@ static void usage(bool status) { " subnets - all known subnets in the VPN\n" " connections - all meta connections with ourself\n" " graph - graph of the VPN in dotty format\n" + " purge Purge unreachable nodes\n" "\n")); printf(_("Report bugs to tinc@tinc-vpn.org.\n")); } @@ -578,6 +579,10 @@ int main(int argc, char *argv[], char *envp[]) { return 1; } + if(!strcasecmp(argv[optind], "purge")) { + return send_ctl_request_cooked(fd, REQ_PURGE, NULL, 0) != -1; + } + fprintf(stderr, _("Unknown command `%s'.\n"), argv[optind]); usage(true); -- 2.20.1