Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b2cb8ebcbe | ||
|
|
6fd6cf8c4a | ||
|
|
f0fc2751e5 |
19
src/buffer.h
19
src/buffer.h
@@ -49,15 +49,18 @@ static inline size_t buffer_read_size (buffer_t *buffer)
|
|||||||
|
|
||||||
static inline void buffer_shift (buffer_t *buffer)
|
static inline void buffer_shift (buffer_t *buffer)
|
||||||
{
|
{
|
||||||
|
if (buffer->read==buffer->data)
|
||||||
|
return;
|
||||||
|
|
||||||
if (buffer->read==buffer->write) {
|
if (buffer->read==buffer->write) {
|
||||||
buffer_format(buffer);
|
buffer_format(buffer);
|
||||||
} else {
|
return;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const size_t size = buffer_read_size(buffer);
|
||||||
|
|
||||||
|
memmove(buffer->data, buffer->read, size);
|
||||||
|
|
||||||
|
buffer->read = buffer->data;
|
||||||
|
buffer->write = buffer->data+size;
|
||||||
}
|
}
|
||||||
|
|||||||
23
src/main.c
23
src/main.c
@@ -13,6 +13,7 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
@@ -39,11 +40,11 @@
|
|||||||
#define O_CLOEXEC 0
|
#define O_CLOEXEC 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define GT_BUFFER_SIZE (64*1024)
|
#define GT_TIMEOUT (5000)
|
||||||
#define GT_TIMEOUT (5000)
|
#define GT_MTU_MAX (1500)
|
||||||
#define GT_MTU_MAX (1500)
|
#define GT_PKT_MAX (32*1024)
|
||||||
#define GT_TUNR_SIZE (0x7FFF-16)
|
#define GT_TUNR_SIZE (GT_PKT_MAX-16-2)
|
||||||
#define GT_TUNW_SIZE (0x7FFF)
|
#define GT_TUNW_SIZE (GT_PKT_MAX)
|
||||||
|
|
||||||
struct fdbuf {
|
struct fdbuf {
|
||||||
int fd;
|
int fd;
|
||||||
@@ -1064,7 +1065,7 @@ int main (int argc, char **argv)
|
|||||||
char *congestion = NULL;
|
char *congestion = NULL;
|
||||||
char *statefile = NULL;
|
char *statefile = NULL;
|
||||||
|
|
||||||
long buffer_size = GT_BUFFER_SIZE;
|
long buffer_size = GT_PKT_MAX;
|
||||||
|
|
||||||
long ka_count = -1;
|
long ka_count = -1;
|
||||||
long ka_idle = -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 noquickack = option_is_set(opts, "noquickack");
|
||||||
const int debug = option_is_set(opts, "debug");
|
const int debug = option_is_set(opts, "debug");
|
||||||
|
|
||||||
if (buffer_size < 2048) {
|
if (buffer_size < GT_PKT_MAX) {
|
||||||
buffer_size = 2048;
|
buffer_size = GT_PKT_MAX;
|
||||||
gt_log("buffer size must be greater than 2048\n");
|
gt_log("buffer size must be greater than or equal to %li\n", buffer_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!listener) {
|
if (!listener) {
|
||||||
@@ -1394,6 +1395,8 @@ int main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buffer_shift(&sock.write);
|
||||||
|
|
||||||
if _1_(!stop_loop)
|
if _1_(!stop_loop)
|
||||||
gt_encrypt(&ctx, &sock.write, &tun.read);
|
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 (FD_ISSET(sock.fd, &rfds)) {
|
||||||
if (noquickack)
|
if (noquickack)
|
||||||
sk_set_int(sock.fd, sk_quickack, 0);
|
sk_set_int(sock.fd, sk_quickack, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user