+ 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 new_debug_level);
+ 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;
+
+respond:
+ res.length = (sizeof res)
+ + ((res_data == NULL) ? 0 : EVBUFFER_LENGTH(res_data));
+ evbuffer_drain(event->input, req.length);
+ if(bufferevent_write(event, &res, sizeof res) == -1)
+ goto failure;
+ if(res_data != NULL) {
+ if(bufferevent_write_buffer(event, res_data) == -1)
+ goto failure;
+ evbuffer_free(res_data);
+ }
+ return;
+
+failure:
+ logger(LOG_INFO, "Closing control socket on error");
+ evbuffer_free(res_data);