]> git.meshlink.io Git - meshlink/commitdiff
Allow connections to be closed.
authorGuus Sliepen <guus@tinc-vpn.org>
Wed, 16 Dec 2009 20:16:56 +0000 (21:16 +0100)
committerGuus Sliepen <guus@tinc-vpn.org>
Wed, 16 Dec 2009 20:16:56 +0000 (21:16 +0100)
This only closes existing meta connections, it may not affect node
reachability.

src/control.c
src/control_common.h
src/tincctl.c

index e3901a6da8e496a36c85f58eb67beb4f9a8c13dd..b8e5204b9db0a58d6e1b2e2fbe1bd1f6d82a01f8 100644 (file)
@@ -92,6 +92,27 @@ bool control_h(connection_t *c, char *request) {
                        int result = reload_configuration();
                        return control_return(c, REQ_RELOAD, result);
 
+               case REQ_DISCONNECT: {
+                       char name[MAX_STRING_SIZE];
+                       connection_t *other;
+                       splay_node_t *node, *next;
+                       bool found = false;
+
+                       if(sscanf(request, "%*d %*d " MAX_STRING, name) != 1)
+                               return control_return(c, REQ_DISCONNECT, -1);
+
+                       for(node = connection_tree->head; node; node = next) {
+                               next = node->next;
+                               other = node->data;
+                               if(strcmp(other->name, name))
+                                       continue;
+                               terminate_connection(other, other->status.active);
+                               found = true;
+                       }
+
+                       return control_return(c, REQ_DISCONNECT, found ? 0 : -2);
+               }
+
                default:
                        return send_request(c, "%d %d", CONTROL, REQ_INVALID);
        }
index c89f9de7dcfb61755aa64ef3a60878e1d9d48210..99cf8afff9d19efb560d183280eb19c6cd77cadb 100644 (file)
@@ -35,6 +35,8 @@ enum request_type {
        REQ_PURGE,
        REQ_SET_DEBUG,
        REQ_RETRY,
+       REQ_CONNECT,
+       REQ_DISCONNECT,
 };
 
 #define TINC_CTL_VERSION_CURRENT 0
index ede186ad4be94c1000c300cfee183ee4f4891b71..632e7ac6efa8720197e7623b69b429087c49f528 100644 (file)
@@ -92,6 +92,7 @@ static void usage(bool status) {
                                "  debug N                    Set debug level\n"
                                "  retry                      Retry all outgoing connections\n"
                                "  reload                     Partial reload of configuration\n"
+                               "  disconnect NODE            Close meta connection with NODE\n"
                                "\n");
                printf("Report bugs to tinc@tinc-vpn.org.\n");
        }
@@ -595,6 +596,36 @@ int main(int argc, char *argv[], char *envp[]) {
                return 0;
        }
 
+       if(!strcasecmp(argv[optind], "connect")) {
+               if(argc != optind + 2) {
+                       fprintf(stderr, "Invalid arguments.\n");
+                       return 1;
+               }
+               char *name = argv[optind + 1];
+
+               sendline(fd, "%d %d %s", CONTROL, REQ_CONNECT, name);
+               if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_CONNECT || result) {
+                       fprintf(stderr, "Could not connect to %s\n", name);
+                       return 1;
+               }
+               return 0;
+       }
+
+       if(!strcasecmp(argv[optind], "disconnect")) {
+               if(argc != optind + 2) {
+                       fprintf(stderr, "Invalid arguments.\n");
+                       return 1;
+               }
+               char *name = argv[optind + 1];
+
+               sendline(fd, "%d %d %s", CONTROL, REQ_DISCONNECT, name);
+               if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_DISCONNECT || result) {
+                       fprintf(stderr, "Could not disconnect %s\n", name);
+                       return 1;
+               }
+               return 0;
+       }
+
        fprintf(stderr, "Unknown command `%s'.\n", argv[optind]);
        usage(true);