From: Guus Sliepen Date: Mon, 7 Aug 2000 16:27:29 +0000 (+0000) Subject: - Lots o' buglets fixed (-Wall helps) X-Git-Tag: release-1.0pre3~146 X-Git-Url: https://git.tinc-vpn.org/git/browse?a=commitdiff_plain;h=b6997b0050e78a2f2e517beba3ff01d9232b3d1f;p=tinc - Lots o' buglets fixed (-Wall helps) - Made TCPonly work :) --- diff --git a/src/conf.h b/src/conf.h index 94020909..ca3c27e1 100644 --- a/src/conf.h +++ b/src/conf.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: conf.h,v 1.6.4.6 2000/08/07 14:52:14 guus Exp $ + $Id: conf.h,v 1.6.4.7 2000/08/07 16:27:27 guus Exp $ */ #ifndef __TINC_CONF_H__ @@ -82,5 +82,6 @@ extern config_t *add_config_val(config_t **, int, char *); extern int read_config_file(const char *); extern const config_t *get_config_val(which_t type); extern const config_t *get_next_config_val(which_t type, int); +extern void clear_config(); #endif /* __TINC_CONF_H__ */ diff --git a/src/net.c b/src/net.c index 93be1cbc..da39686d 100644 --- a/src/net.c +++ b/src/net.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.c,v 1.35.4.21 2000/08/07 14:52:15 guus Exp $ + $Id: net.c,v 1.35.4.22 2000/08/07 16:27:28 guus Exp $ */ #include "config.h" @@ -95,7 +95,6 @@ cp int xsend(conn_list_t *cl, void *packet) { - int r; real_packet_t rp; cp do_encrypt((vpn_packet_t*)packet, &rp, cl->key); @@ -107,14 +106,14 @@ cp syslog(LOG_ERR, _("Sending packet of %d bytes to %s (%s)"), ntohs(rp.len), cl->vpn_hostname, cl->real_hostname); - total_socket_out += r; + total_socket_out += ntohs(rp.len); cl->want_ping = 1; if((cl->flags | myself->flags) & TCPONLY) - return send_tcppacket(cl, packet, ntohs(rp.len)); + return send_tcppacket(cl, (void*)&rp, ntohs(rp.len)); - if((r = send(cl->socket, (char*)&rp, ntohs(rp.len), 0)) < 0) + if((send(cl->socket, (char*)&rp, ntohs(rp.len), 0)) < 0) { syslog(LOG_ERR, _("Error sending packet to %s (%s): %m"), cl->vpn_hostname, cl->real_hostname); @@ -130,17 +129,18 @@ int xrecv(conn_list_t *cl, void *packet) int lenin; cp do_decrypt((real_packet_t*)packet, &vp, cl->key); +cp add_mac_addresses(&vp); - +cp if(debug_lvl > 3) syslog(LOG_ERR, _("Receiving packet of %d bytes from %s (%s)"), ((real_packet_t*)packet)->len, cl->vpn_hostname, cl->real_hostname); - +cp if((lenin = write(tap_fd, &vp, vp.len + sizeof(vp.len))) < 0) syslog(LOG_ERR, _("Can't write to tap device: %m")); else total_tap_out += lenin; - +cp cl->want_ping = 0; cl->last_ping_time = time(NULL); cp @@ -527,13 +527,13 @@ cp } flags = fcntl(cl->meta_socket, F_GETFL); - if(fcntl(cl->meta_socket, F_SETFL, flags | O_NONBLOCK) < 0) +/* if(fcntl(cl->meta_socket, F_SETFL, flags | O_NONBLOCK) < 0) { syslog(LOG_ERR, _("fcntl for %s port %d: %m"), cl->real_hostname, cl->port); return -1; } - +*/ if(debug_lvl > 0) syslog(LOG_INFO, _("Connected to %s port %hd"), cl->real_hostname, cl->port); @@ -605,11 +605,11 @@ cp else myself->port = cfg->data.val; - if(cfg = get_config_val(indirectdata)) + if((cfg = get_config_val(indirectdata))) if(cfg->data.val == stupid_true) myself->flags |= EXPORTINDIRECTDATA; - if(cfg = get_config_val(tcponly)) + if((cfg = get_config_val(tcponly))) if(cfg->data.val == stupid_true) myself->flags |= TCPONLY; @@ -911,7 +911,7 @@ cp */ void terminate_connection(conn_list_t *cl) { - conn_list_t *p, *q; + conn_list_t *p; cp if(cl->status.remove) @@ -1077,9 +1077,11 @@ cp if(errno==EINTR) return 0; if(errno==0) - if(debug_lvl>0) - syslog(LOG_NOTICE, _("Connection closed by %s (%s)"), - cl->vpn_hostname, cl->real_hostname); + { + if(debug_lvl>0) + syslog(LOG_NOTICE, _("Connection closed by %s (%s)"), + cl->vpn_hostname, cl->real_hostname); + } else syslog(LOG_ERR, _("Metadata socket read error for %s (%s): %m"), cl->vpn_hostname, cl->real_hostname); diff --git a/src/net.h b/src/net.h index 40bc934e..41f90b09 100644 --- a/src/net.h +++ b/src/net.h @@ -16,7 +16,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.7 2000/08/07 14:52:15 guus Exp $ + $Id: net.h,v 1.9.4.8 2000/08/07 16:27:28 guus Exp $ */ #ifndef __TINC_NET_H__ @@ -147,5 +147,7 @@ extern void main_loop(void); extern int setup_vpn_connection(conn_list_t *); extern void terminate_connection(conn_list_t *); extern void flush_queues(conn_list_t*); +extern int xrecv(conn_list_t *, void *); +extern void add_queue(packet_queue_t **, void *, size_t); #endif /* __TINC_NET_H__ */ diff --git a/src/protocol.c b/src/protocol.c index a3fa5f1a..fe3309ae 100644 --- a/src/protocol.c +++ b/src/protocol.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: protocol.c,v 1.28.4.20 2000/08/07 14:52:15 guus Exp $ + $Id: protocol.c,v 1.28.4.21 2000/08/07 16:27:28 guus Exp $ */ #include "config.h" @@ -34,6 +34,8 @@ #include #include +#include + #include "conf.h" #include "encr.h" #include "net.h" @@ -445,7 +447,7 @@ cp is not desirable. */ - if(old=lookup_conn(cl->vpn_ip)) + if((old=lookup_conn(cl->vpn_ip))) { if(debug_lvl>0) syslog(LOG_NOTICE, _("Uplink %s (%s) is already in our connection list"), @@ -531,7 +533,7 @@ cp old connection that has timed out but we don't know it yet. */ - while(old = lookup_conn(cl->vpn_ip)) + while((old = lookup_conn(cl->vpn_ip))) { if(debug_lvl > 1) syslog(LOG_NOTICE, _("Removing old entry for %s at %s in favour of new connection from %s"), @@ -666,8 +668,9 @@ cp int tcppacket_h(conn_list_t *cl) { - char packet[1600]; - int len; + real_packet_t rp; + int len, count = 0, result; + conn_list_t *f; cp if(!cl->status.active) { @@ -690,19 +693,52 @@ cp return -1; } - if(debug_lvl > 1) - syslog(LOG_DEBUG, _("Got PACKET from %s (%s)"), - cl->vpn_hostname, cl->real_hostname); - /* Evil kludge comming up */ - if(read(cl->meta_socket,packet,len)!=len) + while(len) { - syslog(LOG_ERR, _("Error while receiving PACKET data from %s (%s)"), + result=read(cl->meta_socket,&rp+count,len); + if(result<0) + { + syslog(LOG_ERR, _("Error while receiving PACKET data from %s (%s): %m"), + cl->vpn_hostname, cl->real_hostname); + return -1; + } + count+=result; + len-=result; + } + + if(debug_lvl > 3) + syslog(LOG_DEBUG, _("Got PACKET length %d from %s (%s)"), len, cl->vpn_hostname, cl->real_hostname); - return -1; - } - xrecv(cl,packet); + total_socket_in += len; + + rp.data.len = ntohs(rp.data.len); + rp.len = ntohs(rp.len); + rp.from = ntohl(rp.from); + + if(rp.len >= 0) + { + f = lookup_conn(rp.from); + if(!f) + { + syslog(LOG_ERR, _("Got packet from %s (%s) with unknown origin %d.%d.%d.%d?"), + cl->vpn_hostname, cl->real_hostname, IP_ADDR_V(rp.from)); + return -1; + } + + if(f->status.validkey) + xrecv(f, &rp); + else + { + add_queue(&(f->rq), &rp, rp.len); + if(!cl->status.waitingforkey) + send_key_request(rp.from); + } + + if(my_key_expiry <= time(NULL)) + regenerate_keys(); + } cp return 0; } @@ -772,7 +808,7 @@ cp return -1; } - if(old = lookup_conn(vpn_ip)) + if((old = lookup_conn(vpn_ip))) { if((real_ip==old->real_ip) && (vpn_mask==old->vpn_mask) && (port==old->port)) { @@ -817,9 +853,9 @@ cp syslog(LOG_DEBUG, _("Got ADD_HOST for %s (%s) from %s (%s)"), ncn->vpn_hostname, ncn->real_hostname, cl->vpn_hostname, cl->real_hostname); -skip_add_host: - notify_others(ncn, cl, send_add_host); + +skip_add_host: cp return 0; } diff --git a/src/protocol.h b/src/protocol.h index fecaa88e..7e0e8988 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -16,7 +16,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: protocol.h,v 1.5.4.4 2000/08/07 14:52:16 guus Exp $ + $Id: protocol.h,v 1.5.4.5 2000/08/07 16:27:29 guus Exp $ */ #ifndef __TINC_PROTOCOL_H__ @@ -74,6 +74,9 @@ extern int send_timeout(conn_list_t *); extern int send_key_request(ip_t); extern void send_key_changed_all(void); extern int send_del_host(conn_list_t *, conn_list_t *); +extern int send_tcppacket(conn_list_t *, void *, int); +extern int notify_others(conn_list_t *, conn_list_t *, int (*function)(conn_list_t*, conn_list_t*)); #endif /* __TINC_PROTOCOL_H__ */ +