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__
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__ */
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"
int xsend(conn_list_t *cl, void *packet)
{
- int r;
real_packet_t rp;
cp
do_encrypt((vpn_packet_t*)packet, &rp, cl->key);
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);
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
}
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);
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;
*/
void terminate_connection(conn_list_t *cl)
{
- conn_list_t *p, *q;
+ conn_list_t *p;
cp
if(cl->status.remove)
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);
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__
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__ */
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"
#include <utils.h>
#include <xalloc.h>
+#include <netinet/in.h>
+
#include "conf.h"
#include "encr.h"
#include "net.h"
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"),
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"),
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)
{
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;
}
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))
{
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;
}
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__
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__ */
+