From: Guus Sliepen Date: Fri, 22 Aug 2003 11:18:42 +0000 (+0000) Subject: Allow tinc to handle unknown type addresses from other tinc daemons. X-Git-Tag: release-1.0.2~37 X-Git-Url: https://tinc-vpn.org/git/browse?a=commitdiff_plain;h=72bdc05cb7e246e56ed21a25256d441c45fccca8;p=tinc Allow tinc to handle unknown type addresses from other tinc daemons. --- diff --git a/src/edge.c b/src/edge.c index 9dbb0c89..69f2c7f5 100644 --- a/src/edge.c +++ b/src/edge.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: edge.c,v 1.1.2.25 2003/07/30 11:50:45 guus Exp $ + $Id: edge.c,v 1.1.2.26 2003/08/22 11:18:42 guus Exp $ */ #include "system.h" @@ -58,15 +58,14 @@ void init_edges(void) { cp(); - edge_weight_tree = - avl_alloc_tree((avl_compare_t) edge_weight_compare, NULL); + edge_weight_tree = avl_alloc_tree((avl_compare_t) edge_weight_compare, NULL); } avl_tree_t *new_edge_tree(void) { cp(); - return avl_alloc_tree((avl_compare_t) edge_compare, NULL); + return avl_alloc_tree((avl_compare_t) edge_compare, (avl_action_t) free_edge); } void free_edge_tree(avl_tree_t *edge_tree) @@ -95,6 +94,8 @@ edge_t *new_edge(void) void free_edge(edge_t *e) { cp(); + + sockaddrfree(&e->address); free(e); } @@ -119,8 +120,8 @@ void edge_del(edge_t *e) if(e->reverse) e->reverse->reverse = NULL; - avl_delete(e->from->edge_tree, e); avl_delete(edge_weight_tree, e); + avl_delete(e->from->edge_tree, e); } edge_t *lookup_edge(node_t *from, node_t *to) diff --git a/src/graph.c b/src/graph.c index e57ffe50..6ec3724e 100644 --- a/src/graph.c +++ b/src/graph.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: graph.c,v 1.1.2.27 2003/07/22 20:55:19 guus Exp $ + $Id: graph.c,v 1.1.2.28 2003/08/22 11:18:42 guus Exp $ */ /* We need to generate two trees from the graph: @@ -220,7 +220,8 @@ void sssp_bfs(void) if(sockaddrcmp(&e->to->address, &e->address)) { node = avl_unlink(node_udp_tree, e->to); - e->to->address = e->address; + sockaddrfree(&e->to->address); + sockaddrcpy(&e->to->address, &e->address); if(e->to->hostname) free(e->to->hostname); diff --git a/src/meta.c b/src/meta.c index 0e4b0d22..d6bf135a 100644 --- a/src/meta.c +++ b/src/meta.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: meta.c,v 1.1.2.42 2003/08/16 12:40:00 guus Exp $ + $Id: meta.c,v 1.1.2.43 2003/08/22 11:18:42 guus Exp $ */ #include "system.h" @@ -89,8 +89,6 @@ void broadcast_meta(connection_t *from, const char *buffer, int length) bool receive_meta(connection_t *c) { - int x; - socklen_t l = sizeof(x); int oldlen, i; int lenin, reqlen; bool decrypted = false; diff --git a/src/net.h b/src/net.h index 06c0504c..d295fed9 100644 --- a/src/net.h +++ b/src/net.h @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: net.h,v 1.9.4.69 2003/08/02 20:50:38 guus Exp $ + $Id: net.h,v 1.9.4.70 2003/08/22 11:18:42 guus Exp $ */ #ifndef __TINC_NET_H__ @@ -54,10 +54,21 @@ typedef struct ipv6_t { typedef short length_t; +#define AF_UNKNOWN 0xFFFF + +struct sockaddr_unknown { + uint16_t family; + uint16_t pad1; + uint32_t pad2; + char *address; + char *port; +}; + typedef union sockaddr_t { struct sockaddr sa; struct sockaddr_in in; struct sockaddr_in6 in6; + struct sockaddr_unknown unknown; #ifdef HAVE_STRUCT_SOCKADDR_STORAGE struct sockaddr_storage storage; #endif diff --git a/src/net_packet.c b/src/net_packet.c index 0828525f..8f47f23f 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: net_packet.c,v 1.1.2.38 2003/08/16 12:40:01 guus Exp $ + $Id: net_packet.c,v 1.1.2.39 2003/08/22 11:18:42 guus Exp $ */ #include "system.h" @@ -392,7 +392,6 @@ void flush_queue(node_t *n) void handle_incoming_vpn_data(int sock) { vpn_packet_t pkt; - int x, l = sizeof(x); char *hostname; sockaddr_t from; socklen_t fromlen = sizeof(from); diff --git a/src/netutl.c b/src/netutl.c index 7a214702..1ab4c2cb 100644 --- a/src/netutl.c +++ b/src/netutl.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: netutl.c,v 1.12.4.52 2003/08/03 12:38:43 guus Exp $ + $Id: netutl.c,v 1.12.4.53 2003/08/22 11:18:42 guus Exp $ */ #include "system.h" @@ -70,11 +70,12 @@ sockaddr_t str2sockaddr(const char *address, const char *port) err = getaddrinfo(address, port, &hint, &ai); if(err || !ai) { - logger(LOG_ERR, _("Error looking up %s port %s: %s"), address, port, - gai_strerror(err)); - cp_trace(); - raise(SIGFPE); - exit(0); + ifdebug(SCARY_THINGS) + logger(LOG_DEBUG, "Unknown type address %s port %s", address, port); + result.sa.sa_family = AF_UNKNOWN; + result.unknown.address = xstrdup(address); + result.unknown.port = xstrdup(port); + return result; } result = *(sockaddr_t *) ai->ai_addr; @@ -92,6 +93,12 @@ void sockaddr2str(const sockaddr_t *sa, char **addrstr, char **portstr) cp(); + if(sa->sa.sa_family == AF_UNKNOWN) { + *addrstr = xstrdup(sa->unknown.address); + *portstr = xstrdup(sa->unknown.port); + return; + } + err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof(address), port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV); if(err) { @@ -120,6 +127,11 @@ char *sockaddr2hostname(const sockaddr_t *sa) cp(); + if(sa->sa.sa_family == AF_UNKNOWN) { + asprintf(&str, _("%s port %s"), sa->unknown.address, sa->unknown.port); + return str; + } + err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof(address), port, sizeof(port), hostnames ? 0 : (NI_NUMERICHOST | NI_NUMERICSERV)); if(err) { @@ -147,6 +159,14 @@ int sockaddrcmp(const sockaddr_t *a, const sockaddr_t *b) case AF_UNSPEC: return 0; + case AF_UNKNOWN: + result = strcmp(a->unknown.address, b->unknown.address); + + if(result) + return result; + + return strcmp(a->unknown.port, b->unknown.port); + case AF_INET: result = memcmp(&a->in.sin_addr, &b->in.sin_addr, sizeof(a->in.sin_addr)); @@ -172,6 +192,23 @@ int sockaddrcmp(const sockaddr_t *a, const sockaddr_t *b) } } +void sockaddrcpy(sockaddr_t *a, const sockaddr_t *b) { + if(b->sa.sa_family != AF_UNKNOWN) { + *a = *b; + } else { + a->unknown.family = AF_UNKNOWN; + a->unknown.address = xstrdup(b->unknown.address); + a->unknown.port = xstrdup(b->unknown.port); + } +} + +void sockaddrfree(sockaddr_t *a) { + if(a->sa.sa_family == AF_UNKNOWN) { + free(a->unknown.address); + free(a->unknown.port); + } +} + void sockaddrunmap(sockaddr_t *sa) { if(sa->sa.sa_family == AF_INET6 && IN6_IS_ADDR_V4MAPPED(&sa->in6.sin6_addr)) { diff --git a/src/netutl.h b/src/netutl.h index d5a7feb8..ff557efd 100644 --- a/src/netutl.h +++ b/src/netutl.h @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: netutl.h,v 1.2.4.18 2003/07/24 12:08:15 guus Exp $ + $Id: netutl.h,v 1.2.4.19 2003/08/22 11:18:42 guus Exp $ */ #ifndef __TINC_NETUTL_H__ @@ -33,6 +33,8 @@ extern void sockaddr2str(const sockaddr_t *, char **, char **); extern char *sockaddr2hostname(const sockaddr_t *); extern int sockaddrcmp(const sockaddr_t *, const sockaddr_t *); extern void sockaddrunmap(sockaddr_t *); +extern void sockaddrfree(sockaddr_t *); +extern void sockaddrcpy(sockaddr_t *, const sockaddr_t *); extern int maskcmp(const void *, const void *, int, int); extern void maskcpy(void *, const void *, int, int); extern void mask(void *, int, int); diff --git a/src/node.c b/src/node.c index b69c5b1c..f40fb19e 100644 --- a/src/node.c +++ b/src/node.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: node.c,v 1.1.2.26 2003/07/30 11:50:45 guus Exp $ + $Id: node.c,v 1.1.2.27 2003/08/22 11:18:42 guus Exp $ */ #include "system.h" @@ -58,7 +58,7 @@ void init_nodes(void) { cp(); - node_tree = avl_alloc_tree((avl_compare_t) node_compare, NULL); + node_tree = avl_alloc_tree((avl_compare_t) node_compare, (avl_action_t) free_node); node_udp_tree = avl_alloc_tree((avl_compare_t) node_udp_compare, NULL); } @@ -66,8 +66,8 @@ void exit_nodes(void) { cp(); - avl_delete_tree(node_tree); avl_delete_tree(node_udp_tree); + avl_delete_tree(node_tree); } node_t *new_node(void) @@ -106,6 +106,8 @@ void free_node(node_t *n) if(n->edge_tree) free_edge_tree(n->edge_tree); + sockaddrfree(&n->address); + EVP_CIPHER_CTX_cleanup(&n->packet_ctx); free(n);