Add UDP discovery mechanism.
[tinc] / src / tincctl.c
index b15676c..2e38203 100644 (file)
@@ -88,7 +88,7 @@ static struct option const long_options[] = {
 static void version(void) {
        printf("%s version %s (built %s %s, protocol %d.%d)\n", PACKAGE,
                   VERSION, BUILD_DATE, BUILD_TIME, PROT_MAJOR, PROT_MINOR);
-       printf("Copyright (C) 1998-2012 Ivo Timmermans, Guus Sliepen and others.\n"
+       printf("Copyright (C) 1998-2014 Ivo Timmermans, Guus Sliepen and others.\n"
                        "See the AUTHORS file for a complete list.\n\n"
                        "tinc comes with ABSOLUTELY NO WARRANTY.  This is free software,\n"
                        "and you are welcome to redistribute it under certain conditions;\n"
@@ -119,8 +119,12 @@ static void usage(bool status) {
                                "  restart [tincd options]    Restart tincd.\n"
                                "  reload                     Partially reload configuration of running tincd.\n"
                                "  pid                        Show PID of currently running tincd.\n"
+#ifdef DISABLE_LEGACY
+                               "  generate-keys              Generate a new Ed25519 public/private keypair.\n"
+#else
                                "  generate-keys [bits]       Generate new RSA and Ed25519 public/private keypairs.\n"
                                "  generate-rsa-keys [bits]   Generate a new RSA public/private keypair.\n"
+#endif
                                "  generate-ed25519-keys      Generate a new Ed25519 public/private keypair.\n"
                                "  dump                       Dump a list of one of the following things:\n"
                                "    [reachable] nodes        - all known nodes in the VPN\n"
@@ -415,6 +419,7 @@ static bool ed25519_keygen(bool ask) {
        return true;
 }
 
+#ifndef DISABLE_LEGACY
 /*
   Generate a public/private RSA keypair, and ask for a file to store
   them in.
@@ -480,6 +485,7 @@ static bool rsa_keygen(int bits, bool ask) {
 
        return true;
 }
+#endif
 
 char buffer[4096];
 size_t blen = 0;
@@ -1002,6 +1008,7 @@ static int cmd_dump(int argc, char *argv[]) {
                        break;
 
                char node[4096];
+               char id[4096];
                char from[4096];
                char to[4096];
                char subnet[4096];
@@ -1019,8 +1026,8 @@ static int cmd_dump(int argc, char *argv[]) {
 
                switch(req) {
                        case REQ_DUMP_NODES: {
-                               int n = sscanf(line, "%*d %*d %s %s port %s %d %d %d %d %x %x %s %s %d %hd %hd %hd %ld", node, host, port, &cipher, &digest, &maclength, &compression, &options, &status_int, nexthop, via, &distance, &pmtu, &minmtu, &maxmtu, &last_state_change);
-                               if(n != 16) {
+                               int n = sscanf(line, "%*d %*d %s %s %s port %s %d %d %d %d %x %x %s %s %d %hd %hd %hd %ld", node, id, host, port, &cipher, &digest, &maclength, &compression, &options, &status_int, nexthop, via, &distance, &pmtu, &minmtu, &maxmtu, &last_state_change);
+                               if(n != 17) {
                                        fprintf(stderr, "Unable to parse node dump from tincd: %s\n", line);
                                        return 1;
                                }
@@ -1043,8 +1050,8 @@ static int cmd_dump(int argc, char *argv[]) {
                                } else {
                                        if(only_reachable && !status.reachable)
                                                continue;
-                                       printf("%s at %s port %s cipher %d digest %d maclength %d compression %d options %x status %04x nexthop %s via %s distance %d pmtu %hd (min %hd max %hd)\n",
-                                                       node, host, port, cipher, digest, maclength, compression, options, status_int, nexthop, via, distance, pmtu, minmtu, maxmtu);
+                                       printf("%s id %s at %s port %s cipher %d digest %d maclength %d compression %d options %x status %04x nexthop %s via %s distance %d pmtu %hd (min %hd max %hd)\n",
+                                                       node, id, host, port, cipher, digest, maclength, compression, options, status_int, nexthop, via, distance, pmtu, minmtu, maxmtu);
                                }
                        } break;
 
@@ -1322,9 +1329,11 @@ const var_t variables[] = {
        {"BindToAddress", VAR_SERVER | VAR_MULTIPLE},
        {"BindToInterface", VAR_SERVER},
        {"Broadcast", VAR_SERVER | VAR_SAFE},
+       {"BroadcastSubnet", VAR_SERVER | VAR_MULTIPLE | VAR_SAFE},
        {"ConnectTo", VAR_SERVER | VAR_MULTIPLE | VAR_SAFE},
        {"DecrementTTL", VAR_SERVER},
        {"Device", VAR_SERVER},
+       {"DeviceStandby", VAR_SERVER},
        {"DeviceType", VAR_SERVER},
        {"DirectOnly", VAR_SERVER},
        {"Ed25519PrivateKeyFile", VAR_SERVER},
@@ -1355,6 +1364,9 @@ const var_t variables[] = {
        {"ScriptsInterpreter", VAR_SERVER},
        {"StrictSubnets", VAR_SERVER},
        {"TunnelServer", VAR_SERVER},
+       {"UDPDiscovery", VAR_SERVER},
+       {"UDPDiscoveryInterval", VAR_SERVER},
+       {"UDPDiscoveryTimeout", VAR_SERVER},
        {"UDPRcvBuf", VAR_SERVER},
        {"UDPSndBuf", VAR_SERVER},
        {"VDEGroup", VAR_SERVER},
@@ -1797,7 +1809,12 @@ static int cmd_init(int argc, char *argv[]) {
        fprintf(f, "Name = %s\n", name);
        fclose(f);
 
-       if(!rsa_keygen(2048, false) || !ed25519_keygen(false))
+#ifndef DISABLE_LEGACY
+       if(!rsa_keygen(2048, false))
+               return 1;
+#endif
+
+       if(!ed25519_keygen(false))
                return 1;
 
        check_port(name);
@@ -1821,7 +1838,11 @@ static int cmd_init(int argc, char *argv[]) {
 }
 
 static int cmd_generate_keys(int argc, char *argv[]) {
+#ifdef DISABLE_LEGACY
+       if(argc > 1) {
+#else
        if(argc > 2) {
+#endif
                fprintf(stderr, "Too many arguments!\n");
                return 1;
        }
@@ -1829,9 +1850,18 @@ static int cmd_generate_keys(int argc, char *argv[]) {
        if(!name)
                name = get_my_name(false);
 
-       return !(rsa_keygen(argc > 1 ? atoi(argv[1]) : 2048, true) && ed25519_keygen(true));
+#ifndef DISABLE_LEGACY
+       if(!rsa_keygen(argc > 1 ? atoi(argv[1]) : 2048, true))
+               return 1;
+#endif
+
+       if(!ed25519_keygen(true))
+               return 1;
+
+       return 0;
 }
 
+#ifndef DISABLE_LEGACY
 static int cmd_generate_rsa_keys(int argc, char *argv[]) {
        if(argc > 2) {
                fprintf(stderr, "Too many arguments!\n");
@@ -1843,6 +1873,7 @@ static int cmd_generate_rsa_keys(int argc, char *argv[]) {
 
        return !rsa_keygen(argc > 1 ? atoi(argv[1]) : 2048, true);
 }
+#endif
 
 static int cmd_generate_ed25519_keys(int argc, char *argv[]) {
        if(argc > 1) {
@@ -2193,7 +2224,9 @@ static const struct {
        {"set", cmd_config},
        {"init", cmd_init},
        {"generate-keys", cmd_generate_keys},
+#ifndef DISABLE_LEGACY
        {"generate-rsa-keys", cmd_generate_rsa_keys},
+#endif
        {"generate-ed25519-keys", cmd_generate_ed25519_keys},
        {"help", cmd_help},
        {"version", cmd_version},