The minimum value for buffer-size option is GT_PKT_MAX

This commit is contained in:
angt
2016-01-15 17:02:11 +01:00
parent 6fd6cf8c4a
commit b2cb8ebcbe
2 changed files with 22 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

@@ -40,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;
@@ -1065,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;
@@ -1128,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) {
@@ -1395,6 +1395,8 @@ int main (int argc, char **argv)
}
}
buffer_shift(&sock.write);
if _1_(!stop_loop)
gt_encrypt(&ctx, &sock.write, &tun.read);
@@ -1417,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);