- Lots o' buglets fixed (-Wall helps)
- Made TCPonly work :)
This commit is contained in:
parent
fdc6a2f106
commit
b6997b0050
5 changed files with 80 additions and 36 deletions
|
@ -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: 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__
|
#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 int read_config_file(const char *);
|
||||||
extern const config_t *get_config_val(which_t type);
|
extern const config_t *get_config_val(which_t type);
|
||||||
extern const config_t *get_next_config_val(which_t type, int);
|
extern const config_t *get_next_config_val(which_t type, int);
|
||||||
|
extern void clear_config();
|
||||||
|
|
||||||
#endif /* __TINC_CONF_H__ */
|
#endif /* __TINC_CONF_H__ */
|
||||||
|
|
34
src/net.c
34
src/net.c
|
@ -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.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"
|
#include "config.h"
|
||||||
|
@ -95,7 +95,6 @@ cp
|
||||||
|
|
||||||
int xsend(conn_list_t *cl, void *packet)
|
int xsend(conn_list_t *cl, void *packet)
|
||||||
{
|
{
|
||||||
int r;
|
|
||||||
real_packet_t rp;
|
real_packet_t rp;
|
||||||
cp
|
cp
|
||||||
do_encrypt((vpn_packet_t*)packet, &rp, cl->key);
|
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)"),
|
syslog(LOG_ERR, _("Sending packet of %d bytes to %s (%s)"),
|
||||||
ntohs(rp.len), cl->vpn_hostname, cl->real_hostname);
|
ntohs(rp.len), cl->vpn_hostname, cl->real_hostname);
|
||||||
|
|
||||||
total_socket_out += r;
|
total_socket_out += ntohs(rp.len);
|
||||||
|
|
||||||
cl->want_ping = 1;
|
cl->want_ping = 1;
|
||||||
|
|
||||||
if((cl->flags | myself->flags) & TCPONLY)
|
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"),
|
syslog(LOG_ERR, _("Error sending packet to %s (%s): %m"),
|
||||||
cl->vpn_hostname, cl->real_hostname);
|
cl->vpn_hostname, cl->real_hostname);
|
||||||
|
@ -130,17 +129,18 @@ int xrecv(conn_list_t *cl, void *packet)
|
||||||
int lenin;
|
int lenin;
|
||||||
cp
|
cp
|
||||||
do_decrypt((real_packet_t*)packet, &vp, cl->key);
|
do_decrypt((real_packet_t*)packet, &vp, cl->key);
|
||||||
|
cp
|
||||||
add_mac_addresses(&vp);
|
add_mac_addresses(&vp);
|
||||||
|
cp
|
||||||
if(debug_lvl > 3)
|
if(debug_lvl > 3)
|
||||||
syslog(LOG_ERR, _("Receiving packet of %d bytes from %s (%s)"),
|
syslog(LOG_ERR, _("Receiving packet of %d bytes from %s (%s)"),
|
||||||
((real_packet_t*)packet)->len, cl->vpn_hostname, cl->real_hostname);
|
((real_packet_t*)packet)->len, cl->vpn_hostname, cl->real_hostname);
|
||||||
|
cp
|
||||||
if((lenin = write(tap_fd, &vp, vp.len + sizeof(vp.len))) < 0)
|
if((lenin = write(tap_fd, &vp, vp.len + sizeof(vp.len))) < 0)
|
||||||
syslog(LOG_ERR, _("Can't write to tap device: %m"));
|
syslog(LOG_ERR, _("Can't write to tap device: %m"));
|
||||||
else
|
else
|
||||||
total_tap_out += lenin;
|
total_tap_out += lenin;
|
||||||
|
cp
|
||||||
cl->want_ping = 0;
|
cl->want_ping = 0;
|
||||||
cl->last_ping_time = time(NULL);
|
cl->last_ping_time = time(NULL);
|
||||||
cp
|
cp
|
||||||
|
@ -527,13 +527,13 @@ cp
|
||||||
}
|
}
|
||||||
|
|
||||||
flags = fcntl(cl->meta_socket, F_GETFL);
|
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"),
|
syslog(LOG_ERR, _("fcntl for %s port %d: %m"),
|
||||||
cl->real_hostname, cl->port);
|
cl->real_hostname, cl->port);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
if(debug_lvl > 0)
|
if(debug_lvl > 0)
|
||||||
syslog(LOG_INFO, _("Connected to %s port %hd"),
|
syslog(LOG_INFO, _("Connected to %s port %hd"),
|
||||||
cl->real_hostname, cl->port);
|
cl->real_hostname, cl->port);
|
||||||
|
@ -605,11 +605,11 @@ cp
|
||||||
else
|
else
|
||||||
myself->port = cfg->data.val;
|
myself->port = cfg->data.val;
|
||||||
|
|
||||||
if(cfg = get_config_val(indirectdata))
|
if((cfg = get_config_val(indirectdata)))
|
||||||
if(cfg->data.val == stupid_true)
|
if(cfg->data.val == stupid_true)
|
||||||
myself->flags |= EXPORTINDIRECTDATA;
|
myself->flags |= EXPORTINDIRECTDATA;
|
||||||
|
|
||||||
if(cfg = get_config_val(tcponly))
|
if((cfg = get_config_val(tcponly)))
|
||||||
if(cfg->data.val == stupid_true)
|
if(cfg->data.val == stupid_true)
|
||||||
myself->flags |= TCPONLY;
|
myself->flags |= TCPONLY;
|
||||||
|
|
||||||
|
@ -911,7 +911,7 @@ cp
|
||||||
*/
|
*/
|
||||||
void terminate_connection(conn_list_t *cl)
|
void terminate_connection(conn_list_t *cl)
|
||||||
{
|
{
|
||||||
conn_list_t *p, *q;
|
conn_list_t *p;
|
||||||
|
|
||||||
cp
|
cp
|
||||||
if(cl->status.remove)
|
if(cl->status.remove)
|
||||||
|
@ -1077,9 +1077,11 @@ cp
|
||||||
if(errno==EINTR)
|
if(errno==EINTR)
|
||||||
return 0;
|
return 0;
|
||||||
if(errno==0)
|
if(errno==0)
|
||||||
if(debug_lvl>0)
|
{
|
||||||
syslog(LOG_NOTICE, _("Connection closed by %s (%s)"),
|
if(debug_lvl>0)
|
||||||
cl->vpn_hostname, cl->real_hostname);
|
syslog(LOG_NOTICE, _("Connection closed by %s (%s)"),
|
||||||
|
cl->vpn_hostname, cl->real_hostname);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
syslog(LOG_ERR, _("Metadata socket read error for %s (%s): %m"),
|
syslog(LOG_ERR, _("Metadata socket read error for %s (%s): %m"),
|
||||||
cl->vpn_hostname, cl->real_hostname);
|
cl->vpn_hostname, cl->real_hostname);
|
||||||
|
|
|
@ -16,7 +16,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.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__
|
#ifndef __TINC_NET_H__
|
||||||
|
@ -147,5 +147,7 @@ extern void main_loop(void);
|
||||||
extern int setup_vpn_connection(conn_list_t *);
|
extern int setup_vpn_connection(conn_list_t *);
|
||||||
extern void terminate_connection(conn_list_t *);
|
extern void terminate_connection(conn_list_t *);
|
||||||
extern void flush_queues(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__ */
|
#endif /* __TINC_NET_H__ */
|
||||||
|
|
|
@ -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: 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 "config.h"
|
||||||
|
@ -34,6 +34,8 @@
|
||||||
#include <utils.h>
|
#include <utils.h>
|
||||||
#include <xalloc.h>
|
#include <xalloc.h>
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "encr.h"
|
#include "encr.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
@ -445,7 +447,7 @@ cp
|
||||||
is not desirable.
|
is not desirable.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if(old=lookup_conn(cl->vpn_ip))
|
if((old=lookup_conn(cl->vpn_ip)))
|
||||||
{
|
{
|
||||||
if(debug_lvl>0)
|
if(debug_lvl>0)
|
||||||
syslog(LOG_NOTICE, _("Uplink %s (%s) is already in our connection list"),
|
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.
|
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)
|
if(debug_lvl > 1)
|
||||||
syslog(LOG_NOTICE, _("Removing old entry for %s at %s in favour of new connection from %s"),
|
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)
|
int tcppacket_h(conn_list_t *cl)
|
||||||
{
|
{
|
||||||
char packet[1600];
|
real_packet_t rp;
|
||||||
int len;
|
int len, count = 0, result;
|
||||||
|
conn_list_t *f;
|
||||||
cp
|
cp
|
||||||
if(!cl->status.active)
|
if(!cl->status.active)
|
||||||
{
|
{
|
||||||
|
@ -690,19 +693,52 @@ cp
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(debug_lvl > 1)
|
|
||||||
syslog(LOG_DEBUG, _("Got PACKET from %s (%s)"),
|
|
||||||
cl->vpn_hostname, cl->real_hostname);
|
|
||||||
|
|
||||||
/* Evil kludge comming up */
|
/* 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);
|
cl->vpn_hostname, cl->real_hostname);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
count+=result;
|
||||||
|
len-=result;
|
||||||
|
}
|
||||||
|
|
||||||
xrecv(cl,packet);
|
if(debug_lvl > 3)
|
||||||
|
syslog(LOG_DEBUG, _("Got PACKET length %d from %s (%s)"), len,
|
||||||
|
cl->vpn_hostname, cl->real_hostname);
|
||||||
|
|
||||||
|
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
|
cp
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -772,7 +808,7 @@ cp
|
||||||
return -1;
|
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))
|
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)"),
|
syslog(LOG_DEBUG, _("Got ADD_HOST for %s (%s) from %s (%s)"),
|
||||||
ncn->vpn_hostname, ncn->real_hostname, cl->vpn_hostname, cl->real_hostname);
|
ncn->vpn_hostname, ncn->real_hostname, cl->vpn_hostname, cl->real_hostname);
|
||||||
|
|
||||||
skip_add_host:
|
|
||||||
|
|
||||||
notify_others(ncn, cl, send_add_host);
|
notify_others(ncn, cl, send_add_host);
|
||||||
|
|
||||||
|
skip_add_host:
|
||||||
cp
|
cp
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,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: 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__
|
#ifndef __TINC_PROTOCOL_H__
|
||||||
|
@ -74,6 +74,9 @@ extern int send_timeout(conn_list_t *);
|
||||||
extern int send_key_request(ip_t);
|
extern int send_key_request(ip_t);
|
||||||
extern void send_key_changed_all(void);
|
extern void send_key_changed_all(void);
|
||||||
extern int send_del_host(conn_list_t *, conn_list_t *);
|
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__ */
|
#endif /* __TINC_PROTOCOL_H__ */
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue