Import Upstream version 1.0.7

This commit is contained in:
Guus Sliepen 2019-08-26 13:44:37 +02:00
parent b030f7d21e
commit 77e8278660
16 changed files with 131 additions and 73 deletions

View file

@ -1,7 +1,7 @@
/*
device.c -- Interaction BSD tun/tap device
Copyright (C) 2001-2005 Ivo Timmermans,
2001-2006 Guus Sliepen <guus@tinc-vpn.org>
2001-2007 Guus Sliepen <guus@tinc-vpn.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -245,7 +245,7 @@ bool write_packet(vpn_packet_t *packet)
case DEVICE_TYPE_TUNIFHEAD: {
u_int32_t type;
struct iovec vector[2] = {{&type, sizeof(type)}, {packet->data + 14, MTU - 14}};
struct iovec vector[2] = {{&type, sizeof(type)}, {packet->data + 14, packet->len - 14}};
int af;
af = (packet->data[12] << 8) + packet->data[13];

View file

@ -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 1476 2006-12-12 14:54:39Z guus $
$Id: graph.c 1494 2007-01-05 05:44:01Z guus $
*/
/* We need to generate two trees from the graph:
@ -374,6 +374,9 @@ void dump_graph(void)
pclose(file);
} else {
fclose(file);
#ifdef HAVE_MINGW
unlink(filename);
#endif
rename(tmpname, filename);
free(tmpname);
}

View file

@ -1,7 +1,7 @@
/*
device.c -- Interaction with Windows tap driver in a MinGW environment
Copyright (C) 2002-2005 Ivo Timmermans,
2002-2006 Guus Sliepen <guus@tinc-vpn.org>
2002-2007 Guus Sliepen <guus@tinc-vpn.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -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: device.c 1452 2006-04-26 13:52:58Z guus $
$Id: device.c 1496 2007-01-05 13:18:36Z guus $
*/
#include "system.h"
@ -45,16 +45,23 @@ static int device_total_out = 0;
extern char *myport;
static struct packetbuf {
uint8_t data[MTU];
length_t len;
} *bufs;
static int nbufs = 64;
DWORD WINAPI tapreader(void *bla) {
int sock, err, status;
struct addrinfo *ai;
struct addrinfo hint = {
.ai_family = AF_UNSPEC,
.ai_socktype = SOCK_DGRAM,
.ai_protocol = IPPROTO_UDP,
.ai_socktype = SOCK_STREAM,
.ai_protocol = IPPROTO_TCP,
.ai_flags = 0,
};
char buf[MTU];
unsigned char bufno = 0;
long len;
OVERLAPPED overlapped;
@ -67,7 +74,7 @@ DWORD WINAPI tapreader(void *bla) {
return -1;
}
sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
sock = socket(ai->ai_family, SOCK_STREAM, IPPROTO_TCP);
freeaddrinfo(ai);
@ -92,7 +99,7 @@ DWORD WINAPI tapreader(void *bla) {
overlapped.OffsetHigh = 0;
ResetEvent(overlapped.hEvent);
status = ReadFile(device_handle, buf, sizeof(buf), &len, &overlapped);
status = ReadFile(device_handle, bufs[bufno].data, MTU, &len, &overlapped);
if(!status) {
if(GetLastError() == ERROR_IO_PENDING) {
@ -106,8 +113,11 @@ DWORD WINAPI tapreader(void *bla) {
}
}
if(send(sock, buf, len, 0) <= 0)
bufs[bufno].len = len;
if(send(sock, &bufno, 1, 0) <= 0)
return -1;
if(++bufno >= nbufs)
bufno = 0;
}
}
@ -131,8 +141,8 @@ bool setup_device(void)
struct addrinfo *ai;
struct addrinfo hint = {
.ai_family = AF_UNSPEC,
.ai_socktype = SOCK_DGRAM,
.ai_protocol = IPPROTO_UDP,
.ai_socktype = SOCK_STREAM,
.ai_protocol = IPPROTO_TCP,
.ai_flags = 0,
};
@ -228,6 +238,16 @@ bool setup_device(void)
overwrite_mac = 1;
}
/* Set up ringbuffer */
get_config_int(lookup_config(config_tree, "RingBufferSize"), &nbufs);
if(nbufs <= 1)
nbufs = 1;
else if(nbufs > 256)
nbufs = 256;
bufs = xmalloc_and_zero(nbufs * sizeof *bufs);
/* Create a listening socket */
err = getaddrinfo(NULL, myport, &hint, &ai);
@ -237,7 +257,7 @@ bool setup_device(void)
return false;
}
sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
sock = socket(ai->ai_family, SOCK_STREAM, IPPROTO_TCP);
if(sock < 0) {
logger(LOG_ERR, _("System call `%s' failed: %s"), "socket", strerror(errno));
@ -295,17 +315,18 @@ void close_device(void)
bool read_packet(vpn_packet_t *packet)
{
int lenin;
unsigned char bufno;
cp();
if((lenin = recv(device_fd, packet->data, MTU, 0)) <= 0) {
if((recv(device_fd, &bufno, 1, 0)) <= 0) {
logger(LOG_ERR, _("Error while reading from %s %s: %s"), device_info,
device, strerror(errno));
return false;
}
packet->len = lenin;
packet->len = bufs[bufno].len;
memcpy(packet->data, bufs[bufno].data, bufs[bufno].len);
device_total_in += packet->len;

View file

@ -1,7 +1,7 @@
/*
tincd.c -- the main file for tincd
Copyright (C) 1998-2005 Ivo Timmermans
2000-2006 Guus Sliepen <guus@tinc-vpn.org>
2000-2007 Guus Sliepen <guus@tinc-vpn.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -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: tincd.c 1474 2006-11-29 17:18:39Z guus $
$Id: tincd.c 1496 2007-01-05 13:18:36Z guus $
*/
#include "system.h"
@ -408,7 +408,7 @@ int main(int argc, char **argv)
if(show_version) {
printf(_("%s version %s (built %s %s, protocol %d)\n"), PACKAGE,
VERSION, __DATE__, __TIME__, PROT_CURRENT);
printf(_("Copyright (C) 1998-2006 Ivo Timmermans, Guus Sliepen and others.\n"
printf(_("Copyright (C) 1998-2007 Ivo Timmermans, Guus Sliepen and others.\n"
"See the AUTHORS file for a complete list.\n\n"
"tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n"
"and you are welcome to redistribute it under certain conditions;\n"