+ if(EVBUFFER_LENGTH(event->input) < sizeof(tinc_ctl_request_t))
+ return;
+
+ /* Copy the structure to ensure alignment */
+ memcpy(&req, EVBUFFER_DATA(event->input), sizeof(tinc_ctl_request_t));
+
+ if(EVBUFFER_LENGTH(event->input) < req.length)
+ return;
+
+ if(req.length < sizeof(tinc_ctl_request_t))
+ goto failure;
+
+ memset(&res, 0, sizeof res);
+ res.type = req.type;
+ res.id = req.id;
+
+ res_data = evbuffer_new();
+ if (res_data == NULL) {
+ res.res_errno = ENOMEM;
+ goto respond;
+ }
+
+ if(req.type == REQ_STOP) {
+ 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;
+ }