At the moment it just reproduces the old format.
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));
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);
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)) {
}
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)
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) {
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) {
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;
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;
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;
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);
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);
}
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;
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