Allow tinc to handle unknown type addresses from other tinc daemons.

This commit is contained in:
Guus Sliepen 2003-08-22 11:18:42 +00:00
parent 5ac4179df6
commit 72bdc05cb7
8 changed files with 74 additions and 23 deletions

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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" #include "system.h"
@ -58,15 +58,14 @@ void init_edges(void)
{ {
cp(); cp();
edge_weight_tree = edge_weight_tree = avl_alloc_tree((avl_compare_t) edge_weight_compare, NULL);
avl_alloc_tree((avl_compare_t) edge_weight_compare, NULL);
} }
avl_tree_t *new_edge_tree(void) avl_tree_t *new_edge_tree(void)
{ {
cp(); 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) void free_edge_tree(avl_tree_t *edge_tree)
@ -95,6 +94,8 @@ edge_t *new_edge(void)
void free_edge(edge_t *e) void free_edge(edge_t *e)
{ {
cp(); cp();
sockaddrfree(&e->address);
free(e); free(e);
} }
@ -119,8 +120,8 @@ void edge_del(edge_t *e)
if(e->reverse) if(e->reverse)
e->reverse->reverse = NULL; e->reverse->reverse = NULL;
avl_delete(e->from->edge_tree, e);
avl_delete(edge_weight_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) edge_t *lookup_edge(node_t *from, node_t *to)

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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: /* We need to generate two trees from the graph:
@ -220,7 +220,8 @@ void sssp_bfs(void)
if(sockaddrcmp(&e->to->address, &e->address)) { if(sockaddrcmp(&e->to->address, &e->address)) {
node = avl_unlink(node_udp_tree, e->to); 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) if(e->to->hostname)
free(e->to->hostname); free(e->to->hostname);

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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" #include "system.h"
@ -89,8 +89,6 @@ void broadcast_meta(connection_t *from, const char *buffer, int length)
bool receive_meta(connection_t *c) bool receive_meta(connection_t *c)
{ {
int x;
socklen_t l = sizeof(x);
int oldlen, i; int oldlen, i;
int lenin, reqlen; int lenin, reqlen;
bool decrypted = false; bool decrypted = false;

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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__ #ifndef __TINC_NET_H__
@ -54,10 +54,21 @@ typedef struct ipv6_t {
typedef short length_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 { typedef union sockaddr_t {
struct sockaddr sa; struct sockaddr sa;
struct sockaddr_in in; struct sockaddr_in in;
struct sockaddr_in6 in6; struct sockaddr_in6 in6;
struct sockaddr_unknown unknown;
#ifdef HAVE_STRUCT_SOCKADDR_STORAGE #ifdef HAVE_STRUCT_SOCKADDR_STORAGE
struct sockaddr_storage storage; struct sockaddr_storage storage;
#endif #endif

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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" #include "system.h"
@ -392,7 +392,6 @@ void flush_queue(node_t *n)
void handle_incoming_vpn_data(int sock) void handle_incoming_vpn_data(int sock)
{ {
vpn_packet_t pkt; vpn_packet_t pkt;
int x, l = sizeof(x);
char *hostname; char *hostname;
sockaddr_t from; sockaddr_t from;
socklen_t fromlen = sizeof(from); socklen_t fromlen = sizeof(from);

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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" #include "system.h"
@ -70,11 +70,12 @@ sockaddr_t str2sockaddr(const char *address, const char *port)
err = getaddrinfo(address, port, &hint, &ai); err = getaddrinfo(address, port, &hint, &ai);
if(err || !ai) { if(err || !ai) {
logger(LOG_ERR, _("Error looking up %s port %s: %s"), address, port, ifdebug(SCARY_THINGS)
gai_strerror(err)); logger(LOG_DEBUG, "Unknown type address %s port %s", address, port);
cp_trace(); result.sa.sa_family = AF_UNKNOWN;
raise(SIGFPE); result.unknown.address = xstrdup(address);
exit(0); result.unknown.port = xstrdup(port);
return result;
} }
result = *(sockaddr_t *) ai->ai_addr; result = *(sockaddr_t *) ai->ai_addr;
@ -92,6 +93,12 @@ void sockaddr2str(const sockaddr_t *sa, char **addrstr, char **portstr)
cp(); 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); err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof(address), port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV);
if(err) { if(err) {
@ -120,6 +127,11 @@ char *sockaddr2hostname(const sockaddr_t *sa)
cp(); 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), err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof(address), port, sizeof(port),
hostnames ? 0 : (NI_NUMERICHOST | NI_NUMERICSERV)); hostnames ? 0 : (NI_NUMERICHOST | NI_NUMERICSERV));
if(err) { if(err) {
@ -147,6 +159,14 @@ int sockaddrcmp(const sockaddr_t *a, const sockaddr_t *b)
case AF_UNSPEC: case AF_UNSPEC:
return 0; 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: case AF_INET:
result = memcmp(&a->in.sin_addr, &b->in.sin_addr, sizeof(a->in.sin_addr)); 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) void sockaddrunmap(sockaddr_t *sa)
{ {
if(sa->sa.sa_family == AF_INET6 && IN6_IS_ADDR_V4MAPPED(&sa->in6.sin6_addr)) { if(sa->sa.sa_family == AF_INET6 && IN6_IS_ADDR_V4MAPPED(&sa->in6.sin6_addr)) {

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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__ #ifndef __TINC_NETUTL_H__
@ -33,6 +33,8 @@ extern void sockaddr2str(const sockaddr_t *, char **, char **);
extern char *sockaddr2hostname(const sockaddr_t *); extern char *sockaddr2hostname(const sockaddr_t *);
extern int sockaddrcmp(const sockaddr_t *, const sockaddr_t *); extern int sockaddrcmp(const sockaddr_t *, const sockaddr_t *);
extern void sockaddrunmap(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 int maskcmp(const void *, const void *, int, int);
extern void maskcpy(void *, const void *, int, int); extern void maskcpy(void *, const void *, int, int);
extern void mask(void *, int, int); extern void mask(void *, int, int);

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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" #include "system.h"
@ -58,7 +58,7 @@ void init_nodes(void)
{ {
cp(); 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); node_udp_tree = avl_alloc_tree((avl_compare_t) node_udp_compare, NULL);
} }
@ -66,8 +66,8 @@ void exit_nodes(void)
{ {
cp(); cp();
avl_delete_tree(node_tree);
avl_delete_tree(node_udp_tree); avl_delete_tree(node_udp_tree);
avl_delete_tree(node_tree);
} }
node_t *new_node(void) node_t *new_node(void)
@ -106,6 +106,8 @@ void free_node(node_t *n)
if(n->edge_tree) if(n->edge_tree)
free_edge_tree(n->edge_tree); free_edge_tree(n->edge_tree);
sockaddrfree(&n->address);
EVP_CIPHER_CTX_cleanup(&n->packet_ctx); EVP_CIPHER_CTX_cleanup(&n->packet_ctx);
free(n); free(n);