]> git.meshlink.io Git - meshlink/commitdiff
Let tincctl parse and format dumps.
authorGuus Sliepen <guus@tinc-vpn.org>
Wed, 26 Sep 2012 21:18:32 +0000 (23:18 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Wed, 26 Sep 2012 21:18:32 +0000 (23:18 +0200)
At the moment it just reproduces the old format.

src/connection.c
src/edge.c
src/info.c
src/net_setup.c
src/node.c
src/subnet.c
src/tincctl.c

index 29ad04ee789075672792f5c21ebb1838f1d47715..fafec5db7e85e8e5b4a50b7d0da7990146a4e1a3 100644 (file)
@@ -117,7 +117,7 @@ bool dump_connections(connection_t *cdump) {
 
        for(node = connection_tree->head; node; node = node->next) {
                c = node->data;
-               send_request(cdump, "%d %d %s at %s options %x socket %d status %04x",
+               send_request(cdump, "%d %d %s %s %x %d %x",
                                CONTROL, REQ_DUMP_CONNECTIONS,
                                c->name, c->hostname, c->options, c->socket,
                                bitfield_to_int(&c->status, sizeof c->status));
index f5aa0994412e2b0416467cf03ada7ce423cc3f6b..cee75a7a63816752e2b7a30feced79885c77d201 100644 (file)
@@ -117,7 +117,7 @@ bool dump_edges(connection_t *c) {
                for(node2 = n->edge_tree->head; node2; node2 = node2->next) {
                        e = node2->data;
                        address = sockaddr2hostname(&e->address);
-                       send_request(c, "%d %d %s to %s at %s options %x weight %d",
+                       send_request(c, "%d %d %s %s %s %x %d",
                                        CONTROL, REQ_DUMP_EDGES,
                                        e->from->name, e->to->name, address,
                                        e->options, e->weight);
index ee60a3fe4671c4f2aa9b5f0dd1287b22c9e18ed2..93be24e4eaacbe6e938e783fb4a5181b8260be25 100644 (file)
@@ -62,19 +62,14 @@ static int info_node(int fd, const char *item) {
        long int last_state_change;
 
        while(recvline(fd, line, sizeof line)) {
-               int n = sscanf(line, "%d %d %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) %ld", &code, &req, node, host, port, &cipher, &digest, &maclength, &compression, &options, (unsigned *)&status, nexthop, via, &distance, &pmtu, &minmtu, &maxmtu, &last_state_change);
+               int n = sscanf(line, "%d %d %s %s port %s %d %d %d %d %x %x %s %s %d %hd %hd %hd %ld", &code, &req, node, host, port, &cipher, &digest, &maclength, &compression, &options, (unsigned *)&status, nexthop, via, &distance, &pmtu, &minmtu, &maxmtu, &last_state_change);
 
                if(n == 2)
                        break;
 
                if(n != 18) {
-                       *port = 0;
-                       n = sscanf(line, "%d %d %s at %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) %ld", &code, &req, node, host, &cipher, &digest, &maclength, &compression, &options, (unsigned *)&status, nexthop, via, &distance, &pmtu, &minmtu, &maxmtu, &last_state_change);
-
-                       if(n != 17) {
-                               fprintf(stderr, "Unable to parse node dump from tincd.\n");
-                               return 1;
-                       }
+                       fprintf(stderr, "Unable to parse node dump from tincd.\n");
+                       return 1;
                }
 
                if(!strcmp(node, item)) {
@@ -94,8 +89,7 @@ static int info_node(int fd, const char *item) {
        }
        
        printf("Node:         %s\n", item);
-       if(*port)
-               printf("Address:      %s port %s\n", host, port);
+       printf("Address:      %s port %s\n", host, port);
 
        char timestr[32] = "never";
        if(last_state_change)
@@ -150,7 +144,7 @@ static int info_node(int fd, const char *item) {
        printf("Edges:       ");
        sendline(fd, "%d %d %s", CONTROL, REQ_DUMP_EDGES, item);
        while(recvline(fd, line, sizeof line)) {
-               int n = sscanf(line, "%d %d %s to %s", &code, &req, from, to);
+               int n = sscanf(line, "%d %d %s %s", &code, &req, from, to);
                if(n == 2)
                        break;
                if(n != 4) {
@@ -166,7 +160,7 @@ static int info_node(int fd, const char *item) {
        printf("Subnets:     ");
        sendline(fd, "%d %d %s", CONTROL, REQ_DUMP_SUBNETS, item);
        while(recvline(fd, line, sizeof line)) {
-               int n = sscanf(line, "%d %d %s owner %s", &code, &req, subnet, from);
+               int n = sscanf(line, "%d %d %s %s", &code, &req, subnet, from);
                if(n == 2)
                        break;
                if(n != 4) {
@@ -201,7 +195,7 @@ static int info_subnet(int fd, const char *item) {
 
        sendline(fd, "%d %d %s", CONTROL, REQ_DUMP_SUBNETS, item);
        while(recvline(fd, line, sizeof line)) {
-               int n = sscanf(line, "%d %d %s owner %s", &code, &req, netstr, owner);
+               int n = sscanf(line, "%d %d %s %s", &code, &req, netstr, owner);
                if(n == 2)
                        break;
 
index 3991bd2b366cc75ecff9f7242adebedcf8aece42..ecffed9556730d5579506b2ae77c3c60a5ad6aae 100644 (file)
@@ -574,8 +574,11 @@ static bool setup_myself(void) {
        myself = new_node();
        myself->connection = new_connection();
 
-       myself->hostname = xstrdup("MYSELF");
-       myself->connection->hostname = xstrdup("MYSELF");
+       if(!get_config_string(lookup_config(config_tree, "Port"), &myport))
+               myport = xstrdup("655");
+
+       xasprintf(&myself->hostname, "MYSELF port %s", myport);
+       myself->connection->hostname = xstrdup(myself->hostname);
 
        myself->connection->options = 0;
        myself->connection->protocol_major = PROT_MAJOR;
@@ -603,9 +606,6 @@ static bool setup_myself(void) {
        if(!read_rsa_private_key())
                return false;
 
-       if(!get_config_string(lookup_config(config_tree, "Port"), &myport))
-               myport = xstrdup("655");
-
        if(!atoi(myport)) {
                struct addrinfo *ai = str2addrinfo("localhost", myport, SOCK_DGRAM);
                sockaddr_t sa;
index 8c81d481eec3df19ec00570c2cc3f8e50262dcd4..318af59fc99193c41bcda27ca90ae2d5d7e552b4 100644 (file)
@@ -152,8 +152,8 @@ bool dump_nodes(connection_t *c) {
 
        for(node = node_tree->head; node; node = node->next) {
                n = node->data;
-               send_request(c, "%d %d %s at %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) %ld", CONTROL, REQ_DUMP_NODES,
-                          n->name, n->hostname, cipher_get_nid(&n->outcipher),
+               send_request(c, "%d %d %s %s %d %d %d %d %x %x %s %s %d %hd %hd %hd %ld", CONTROL, REQ_DUMP_NODES,
+                          n->name, n->hostname ?: "unknown port unknown", cipher_get_nid(&n->outcipher),
                           digest_get_nid(&n->outdigest), (int)digest_length(&n->outdigest), n->outcompression,
                           n->options, bitfield_to_int(&n->status, sizeof n->status), n->nexthop ? n->nexthop->name : "-",
                           n->via ? n->via->name ?: "-" : "-", n->distance, n->mtu, n->minmtu, n->maxmtu, (long)n->last_state_change);
index b2c7e7c463b3c80503d988af44b7198021c7cae3..59e4e8245d42efacad377cf28c52f580194c29e6 100644 (file)
@@ -283,7 +283,7 @@ bool dump_subnets(connection_t *c) {
                subnet = node->data;
                if(!net2str(netstr, sizeof netstr, subnet))
                        continue;
-               send_request(c, "%d %d %s owner %s",
+               send_request(c, "%d %d %s %s",
                                CONTROL, REQ_DUMP_SUBNETS,
                                netstr, subnet->owner->name);
        }
index 00d8eb903d27fcddca01741105dea06deb769729..78e2dc1410e37ddf83b02d9984f438da24a3dda1 100644 (file)
@@ -847,7 +847,7 @@ static int cmd_dump(int argc, char *argv[]) {
 
        while(recvline(fd, line, sizeof line)) {
                char node1[4096], node2[4096];
-               int n = sscanf(line, "%d %d %s to %s", &code, &req, node1, node2);
+               int n = sscanf(line, "%d %d %s %s", &code, &req, node1, node2);
                if(n == 2) {
                        if(do_graph && req == REQ_DUMP_NODES)
                                continue;
@@ -860,9 +860,63 @@ static int cmd_dump(int argc, char *argv[]) {
                if(n < 2)
                        break;
 
-               if(!do_graph)
-                       printf("%s\n", line + 5);
-               else {
+               if(!do_graph) {
+                       char node[4096];
+                       char from[4096];
+                       char to[4096];
+                       char subnet[4096];
+                       char host[4096];
+                       char port[4096];
+                       char via[4096];
+                       char nexthop[4096];
+                       int cipher, digest, maclength, compression, distance, socket, weight;
+                       short int pmtu, minmtu, maxmtu;
+                       unsigned int options, status;
+                       long int last_state_change;
+
+                       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, nexthop, via, &distance, &pmtu, &minmtu, &maxmtu, &last_state_change);
+                                       if(n != 16) {
+                                               fprintf(stderr, "Unable to parse node dump from tincd: %s\n", line);
+                                               return 1;
+                                       }
+                                       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, nexthop, via, distance, pmtu, minmtu, maxmtu);
+                               } break;
+
+                               case REQ_DUMP_EDGES: {
+                                       int n = sscanf(line, "%*d %*d %s %s %s port %s %x %d", from, to, host, port, &options, &weight);
+                                       if(n != 6) {
+                                               fprintf(stderr, "Unable to parse edge dump from tincd.\n");
+                                               return 1;
+                                       }
+                                       printf("%s to %s at %s port %s options %x weight %d\n", from, to, host, port, options, weight);
+                               } break;
+
+                               case REQ_DUMP_SUBNETS: {
+                                       int n = sscanf(line, "%*d %*d %s %s", subnet, node);
+                                       if(n != 2) {
+                                               fprintf(stderr, "Unable to parse subnet dump from tincd.\n");
+                                               return 1;
+                                       }
+                                       printf("%s owner %s\n", strip_weight(subnet), node);
+                               } break;
+
+                               case REQ_DUMP_CONNECTIONS: {
+                                       int n = sscanf(line, "%*d %*d %s %s port %s %x %d %x", node, host, port, &options, &socket, &status);
+                                       if(n != 6) {
+                                               fprintf(stderr, "Unable to parse connection dump from tincd.\n");
+                                               return 1;
+                                       }
+                                       printf("%s at %s port %s options %x socket %d status %x\n", node, host, port, options, socket, status);
+                               } break;
+
+                               default:
+                                       fprintf(stderr, "Unable to parse dump from tincd.\n");
+                                       return 1;
+                       }
+               } else {
                        if(req == REQ_DUMP_NODES)
                                printf(" %s [label = \"%s\"];\n", node1, node1);
                        else