From: Guus Sliepen Date: Tue, 15 Mar 2022 07:39:35 +0000 (+0100) Subject: Remove unnecessary status bitfield conversions. X-Git-Url: https://tinc-vpn.org/git/browse?a=commitdiff_plain;h=a85198d20f24cd4e20ec5c57e402611fef8b137a;p=tinc Remove unnecessary status bitfield conversions. --- diff --git a/src/connection.c b/src/connection.c index 7d27e706..0de51095 100644 --- a/src/connection.c +++ b/src/connection.c @@ -112,7 +112,7 @@ bool dump_connections(connection_t *cdump) { 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))); + c->status.value); } return send_request(cdump, "%d %d", CONTROL, REQ_DUMP_CONNECTIONS); diff --git a/src/node.c b/src/node.c index fce1217e..53013d2d 100644 --- a/src/node.c +++ b/src/node.c @@ -209,7 +209,7 @@ bool dump_nodes(connection_t *c) { #else cipher_get_nid(n->outcipher), digest_get_nid(n->outdigest), (unsigned long)digest_length(n->outdigest), #endif - n->outcompression, n->options, bitfield_to_int(&n->status, sizeof(n->status)), + n->outcompression, n->options, n->status.value, n->nexthop ? n->nexthop->name : "-", n->via && n->via->name ? n->via->name : "-", n->distance, n->mtu, n->minmtu, n->maxmtu, (long)n->last_state_change, n->udp_ping_rtt, n->in_packets, n->in_bytes, n->out_packets, n->out_bytes); diff --git a/src/tincctl.c b/src/tincctl.c index 215d757c..a3978bcc 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -1244,7 +1244,6 @@ static int cmd_dump(int argc, char *argv[]) { int cipher, digest, maclength, compression, distance, socket, weight; short int pmtu, minmtu, maxmtu; unsigned int options; - uint32_t status_int; node_status_t status; long int last_state_change; int udp_ping_rtt; @@ -1252,15 +1251,13 @@ static int cmd_dump(int argc, char *argv[]) { switch(req) { case REQ_DUMP_NODES: { - int n = sscanf(line, "%*d %*d %4095s %4095s %4095s port %4095s %d %d %d %d %x %"PRIx32" %4095s %4095s %d %hd %hd %hd %ld %d %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64, node, id, host, port, &cipher, &digest, &maclength, &compression, &options, &status_int, nexthop, via, &distance, &pmtu, &minmtu, &maxmtu, &last_state_change, &udp_ping_rtt, &in_packets, &in_bytes, &out_packets, &out_bytes); + int n = sscanf(line, "%*d %*d %4095s %4095s %4095s port %4095s %d %d %d %d %x %"PRIx32" %4095s %4095s %d %hd %hd %hd %ld %d %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64, node, id, host, port, &cipher, &digest, &maclength, &compression, &options, &status.value, nexthop, via, &distance, &pmtu, &minmtu, &maxmtu, &last_state_change, &udp_ping_rtt, &in_packets, &in_bytes, &out_packets, &out_bytes); if(n != 22) { fprintf(stderr, "Unable to parse node dump from tincd: %s\n", line); return 1; } - memcpy(&status, &status_int, sizeof(status)); - if(do_graph) { const char *color = "black"; @@ -1283,7 +1280,7 @@ static int cmd_dump(int argc, char *argv[]) { } 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 %d (min %d max %d) rx %"PRIu64" %"PRIu64" tx %"PRIu64" %"PRIu64, - node, id, host, port, cipher, digest, maclength, compression, options, status_int, nexthop, via, distance, pmtu, minmtu, maxmtu, in_packets, in_bytes, out_packets, out_bytes); + node, id, host, port, cipher, digest, maclength, compression, options, status.value, nexthop, via, distance, pmtu, minmtu, maxmtu, in_packets, in_bytes, out_packets, out_bytes); if(udp_ping_rtt != -1) { printf(" rtt %d.%03d", udp_ping_rtt / 1000, udp_ping_rtt % 1000); @@ -1329,14 +1326,14 @@ static int cmd_dump(int argc, char *argv[]) { break; case REQ_DUMP_CONNECTIONS: { - int n = sscanf(line, "%*d %*d %4095s %4095s port %4095s %x %d %x", node, host, port, &options, &socket, &status_int); + int n = sscanf(line, "%*d %*d %4095s %4095s port %4095s %x %d %x", node, host, port, &options, &socket, &status.value); 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_int); + printf("%s at %s port %s options %x socket %d status %x\n", node, host, port, options, socket, status.value); } break; diff --git a/src/utils.c b/src/utils.c index 6104fada..8b0cd6ed 100644 --- a/src/utils.c +++ b/src/utils.c @@ -195,17 +195,6 @@ const char *winerror(int err) { } #endif -unsigned int bitfield_to_int(const void *bitfield, size_t size) { - unsigned int value = 0; - - if(size > sizeof(value)) { - size = sizeof(value); - } - - memcpy(&value, bitfield, size); - return value; -} - bool check_id(const char *id) { if(!id || !*id) { return false; diff --git a/src/utils.h b/src/utils.h index b7093e1e..9756a3e0 100644 --- a/src/utils.h +++ b/src/utils.h @@ -63,8 +63,6 @@ static inline suseconds_t jitter(void) { } #endif -extern unsigned int bitfield_to_int(const void *bitfield, size_t size); - extern bool check_id(const char *id); extern bool check_netname(const char *netname, bool strict); char *replace_name(const char *name);