X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fcontrol.c;h=a7958437db94394b102e4ebc91df8634316be7c5;hb=b1f8c65a2cfa307d9b8ed8cc3c8d4819f605e4f6;hp=7b27f69afe8f4f956b88cc4298febe553e5da37d;hpb=50ad3f2a895c38f8d546f87490ca96ab7d9e011e;p=tinc diff --git a/src/control.c b/src/control.c index 7b27f69a..a7958437 100644 --- a/src/control.c +++ b/src/control.c @@ -38,6 +38,7 @@ static void handle_control_data(struct bufferevent *event, void *data) { size_t size; tinc_ctl_request_t res; struct evbuffer *res_data = NULL; + void *req_data; if(EVBUFFER_LENGTH(event->input) < sizeof(tinc_ctl_request_t)) return; @@ -47,6 +48,7 @@ static void handle_control_data(struct bufferevent *event, void *data) { if(EVBUFFER_LENGTH(event->input) < req.length) return; + req_data = EVBUFFER_DATA(event->input) + sizeof(tinc_ctl_request_t); if(req.length < sizeof(tinc_ctl_request_t)) goto failure; @@ -56,17 +58,84 @@ static void handle_control_data(struct bufferevent *event, void *data) { res.id = req.id; res_data = evbuffer_new(); - if (res_data == NULL) { + if(res_data == NULL) { res.res_errno = ENOMEM; goto respond; } if(req.type == REQ_STOP) { - logger(LOG_NOTICE, _("Got stop command")); + logger(LOG_NOTICE, _("Got '%s' command"), "stop"); event_loopexit(NULL); goto respond; } + if(req.type == REQ_DUMP_NODES) { + logger(LOG_NOTICE, _("Got '%s' command"), "dump nodes"); + res.res_errno = dump_nodes(res_data); + goto respond; + } + + if(req.type == REQ_DUMP_EDGES) { + logger(LOG_NOTICE, _("Got '%s' command"), "dump edges"); + res.res_errno = dump_edges(res_data); + goto respond; + } + + if(req.type == REQ_DUMP_SUBNETS) { + logger(LOG_NOTICE, _("Got '%s' command"), "dump subnets"); + res.res_errno = dump_subnets(res_data); + goto respond; + } + + if(req.type == REQ_DUMP_CONNECTIONS) { + logger(LOG_NOTICE, _("Got '%s' command"), "dump connections"); + res.res_errno = dump_connections(res_data); + goto respond; + } + + if(req.type == REQ_DUMP_GRAPH) { + logger(LOG_NOTICE, _("Got '%s' command"), "dump graph"); + res.res_errno = dump_graph(res_data); + goto respond; + } + + if(req.type == REQ_PURGE) { + logger(LOG_NOTICE, _("Got '%s' command"), "purge"); + purge(); + goto respond; + } + + if(req.type == REQ_SET_DEBUG) { + debug_t new_debug_level; + + logger(LOG_NOTICE, _("Got '%s' command"), "debug"); + if(req.length != sizeof(req) + sizeof debug_level) + res.res_errno = EINVAL; + else { + memcpy(&new_debug_level, req_data, sizeof(debug_t)); + logger(LOG_NOTICE, _("Changing debug level from %d to %d"), + debug_level, new_debug_level); + if(evbuffer_add_printf(res_data, + _("Changing debug level from %d to %d\n"), + debug_level, new_debug_level) == -1) + res.res_errno = errno; + debug_level = new_debug_level; + } + goto respond; + } + + if(req.type == REQ_RETRY) { + logger(LOG_NOTICE, _("Got '%s' command"), "retry"); + retry(); + goto respond; + } + + if(req.type == REQ_RELOAD) { + logger(LOG_NOTICE, _("Got '%s' command"), "reload"); + res.res_errno = reload_configuration(); + goto respond; + } + logger(LOG_DEBUG, _("Malformed control command received")); res.res_errno = EINVAL;