Compare commits

..

3 Commits

Author SHA1 Message Date
angt
b2cb8ebcbe The minimum value for buffer-size option is GT_PKT_MAX 2016-01-15 17:02:11 +01:00
angt
6fd6cf8c4a Merge pull request #10 from jedisct1/socket
Include <sys/socket.h> for AF_INET/AF_INET6 definitions
2016-01-14 17:14:56 +01:00
Frank Denis
f0fc2751e5 Include <sys/socket.h> for AF_INET/AF_INET6 definitions
Required on OpenBSD
2016-01-14 17:11:27 +01:00
2 changed files with 23 additions and 19 deletions

View File

@@ -49,15 +49,18 @@ static inline size_t buffer_read_size (buffer_t *buffer)
static inline void buffer_shift (buffer_t *buffer)
{
if (buffer->read==buffer->data)
return;
if (buffer->read==buffer->write) {
buffer_format(buffer);
} else {
const uint8_t *src = PALIGN_DOWN(buffer->read);
const size_t size = ALIGN(buffer->write-src);
if (buffer->data+size<src) {
memcpy(buffer->data, src, size);
buffer->read -= src-buffer->data;
buffer->write -= src-buffer->data;
}
return;
}
const size_t size = buffer_read_size(buffer);
memmove(buffer->data, buffer->read, size);
buffer->read = buffer->data;
buffer->write = buffer->data+size;
}

View File

@@ -13,6 +13,7 @@
#include <signal.h>
#include <poll.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/stat.h>
@@ -39,11 +40,11 @@
#define O_CLOEXEC 0
#endif
#define GT_BUFFER_SIZE (64*1024)
#define GT_TIMEOUT (5000)
#define GT_MTU_MAX (1500)
#define GT_TUNR_SIZE (0x7FFF-16)
#define GT_TUNW_SIZE (0x7FFF)
#define GT_TIMEOUT (5000)
#define GT_MTU_MAX (1500)
#define GT_PKT_MAX (32*1024)
#define GT_TUNR_SIZE (GT_PKT_MAX-16-2)
#define GT_TUNW_SIZE (GT_PKT_MAX)
struct fdbuf {
int fd;
@@ -1064,7 +1065,7 @@ int main (int argc, char **argv)
char *congestion = NULL;
char *statefile = NULL;
long buffer_size = GT_BUFFER_SIZE;
long buffer_size = GT_PKT_MAX;
long ka_count = -1;
long ka_idle = -1;
@@ -1127,9 +1128,9 @@ int main (int argc, char **argv)
const int noquickack = option_is_set(opts, "noquickack");
const int debug = option_is_set(opts, "debug");
if (buffer_size < 2048) {
buffer_size = 2048;
gt_log("buffer size must be greater than 2048\n");
if (buffer_size < GT_PKT_MAX) {
buffer_size = GT_PKT_MAX;
gt_log("buffer size must be greater than or equal to %li\n", buffer_size);
}
if (!listener) {
@@ -1394,6 +1395,8 @@ int main (int argc, char **argv)
}
}
buffer_shift(&sock.write);
if _1_(!stop_loop)
gt_encrypt(&ctx, &sock.write, &tun.read);
@@ -1416,8 +1419,6 @@ int main (int argc, char **argv)
}
}
buffer_shift(&sock.write);
if (FD_ISSET(sock.fd, &rfds)) {
if (noquickack)
sk_set_int(sock.fd, sk_quickack, 0);