X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fnet_packet.c;h=d372ced633f7c5d5069974c1293d399b56b9ef32;hb=e32d4f3db3f1ed3eebe2e11d57512b60a6c02fa6;hp=dab74e5d305a313fa43991b64835c790b2a273be;hpb=2c6b2d70e6640f39563ad7bb0aa0ba87f883848c;p=tinc diff --git a/src/net_packet.c b/src/net_packet.c index dab74e5d..d372ced6 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -55,10 +55,6 @@ #include "route.h" #include "utils.h" -#ifndef MAX -#define MAX(a, b) ((a) > (b) ? (a) : (b)) -#endif - /* The minimum size of a probe is 14 bytes, but since we normally use CBC mode encryption, we can add a few extra random bytes without increasing the resulting packet size. */ @@ -743,10 +739,10 @@ static void choose_udp_address(const node_t *n, const sockaddr_t **sa, size_t *s So we pick a random edge and a random socket. */ unsigned int i = 0; - unsigned int j = rand() % n->edge_tree->count; + unsigned int j = prng(n->edge_tree.count); edge_t *candidate = NULL; - for splay_each(edge_t, e, n->edge_tree) { + for splay_each(edge_t, e, &n->edge_tree) { if(i++ == j) { candidate = e->reverse; break; @@ -755,7 +751,7 @@ static void choose_udp_address(const node_t *n, const sockaddr_t **sa, size_t *s if(candidate) { *sa = &candidate->address; - *sock = rand() % listen_sockets; + *sock = prng(listen_sockets); } adapt_socket(*sa, sock); @@ -767,10 +763,10 @@ static void choose_local_address(const node_t *n, const sockaddr_t **sa, size_t /* Pick one of the edges from this node at random, then use its local address. */ unsigned int i = 0; - unsigned int j = rand() % n->edge_tree->count; + unsigned int j = prng(n->edge_tree.count); edge_t *candidate = NULL; - for splay_each(edge_t, e, n->edge_tree) { + for splay_each(edge_t, e, &n->edge_tree) { if(i++ == j) { candidate = e; break; @@ -779,7 +775,7 @@ static void choose_local_address(const node_t *n, const sockaddr_t **sa, size_t if(candidate && candidate->local_address.sa.sa_family) { *sa = &candidate->local_address; - *sock = rand() % listen_sockets; + *sock = prng(listen_sockets); adapt_socket(*sa, sock); } } @@ -967,8 +963,8 @@ bool send_sptps_data(node_t *to, node_t *from, int type, const void *data, size_ return send_sptps_tcppacket(to->nexthop->connection, buf, sizeof(buf)); } - char buf[len * 4 / 3 + 5]; - b64encode(data, buf, len); + char buf[B64_SIZE(len)]; + b64encode_tinc(data, buf, len); /* If this is a handshake packet, use ANS_KEY instead of REQ_KEY, for two reasons: - We don't want intermediate nodes to switch to UDP to relay these packets; @@ -1623,7 +1619,7 @@ void broadcast_packet(const node_t *from, vpn_packet_t *packet) { // This guarantees all nodes receive the broadcast packet, and // usually distributes the sending of broadcast packets over all nodes. case BMODE_MST: - for list_each(connection_t, c, connection_list) + for list_each(connection_t, c, &connection_list) if(c->edge && c->status.mst && c != from->nexthop->connection) { send_packet(c->node, packet); } @@ -1638,7 +1634,7 @@ void broadcast_packet(const node_t *from, vpn_packet_t *packet) { break; } - for splay_each(node_t, n, node_tree) + for splay_each(node_t, n, &node_tree) if(n->status.reachable && n != myself && ((n->via == myself && n->nexthop == n) || n->via == n)) { send_packet(n, packet); } @@ -1661,7 +1657,7 @@ static node_t *try_harder(const sockaddr_t *from, const vpn_packet_t *pkt) { bool hard = false; static time_t last_hard_try = 0; - for splay_each(node_t, n, node_tree) { + for splay_each(node_t, n, &node_tree) { if(!n->status.reachable || n == myself) { continue; } @@ -1672,7 +1668,7 @@ static node_t *try_harder(const sockaddr_t *from, const vpn_packet_t *pkt) { bool soft = false; - for splay_each(edge_t, e, n->edge_tree) { + for splay_each(edge_t, e, &n->edge_tree) { if(!e->reverse) { continue; }