Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion dnsu2t.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
#include "dnsu2t.h"
#include "utils.h"

#ifndef MSG_FASTOPEN
#define MSG_FASTOPEN 0x20000000 /* Send data in TCP SYN. */
#endif

#define dnsu2t_log_error(prio, msg...) \
redsocks_log_write_plain(__FILE__, __LINE__, __func__, 0, &clientaddr, &self->config.bindaddr, prio, ## msg)
#define dnsu2t_log_errno(prio, msg...) \
Expand Down Expand Up @@ -242,7 +246,7 @@ void dnsu2t_pkt_from_relay(int fd, short what, void *_arg)
if (what & EV_READ) {
char* dst = ((char*)&self->pkt) + self->pkt_size;
if (self->pkt_size)
log_error(LOG_DEBUG, "partial packet, off=%lu", self->pkt_size);
log_error(LOG_DEBUG, "partial packet, off=%d", self->pkt_size);
const size_t bufsz = sizeof(self->pkt) - self->pkt_size;
assert(bufsz > 0 && self->pkt_size >= 0);
ssize_t rcvd = recv(fd, dst, bufsz, 0);
Expand Down
10 changes: 10 additions & 0 deletions redsocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ static parser_entry redsocks_entries[] =
{ .key = "splice", .type = pt_bool },
{ .key = "disclose_src", .type = pt_disclose_src },
{ .key = "on_proxy_fail", .type = pt_on_proxy_fail },
{ .key = "timeout", .type = pt_uint16 },
{ }
};

Expand Down Expand Up @@ -137,6 +138,7 @@ static int redsocks_onenter(parser_section *section)
instance->config.use_splice = is_splice_good();
instance->config.disclose_src = DISCLOSE_NONE;
instance->config.on_proxy_fail = ONFAIL_CLOSE;
instance->config.timeout = 0;

for (parser_entry *entry = &section->entries[0]; entry->key; entry++)
entry->addr =
Expand All @@ -151,6 +153,7 @@ static int redsocks_onenter(parser_section *section)
(strcmp(entry->key, "splice") == 0) ? (void*)&instance->config.use_splice :
(strcmp(entry->key, "disclose_src") == 0) ? (void*)&instance->config.disclose_src :
(strcmp(entry->key, "on_proxy_fail") == 0) ? (void*)&instance->config.on_proxy_fail :
(strcmp(entry->key, "timeout") == 0) ? (void*)&instance->config.timeout :
NULL;
section->data = instance;
return 0;
Expand Down Expand Up @@ -976,6 +979,12 @@ void redsocks_connect_relay(redsocks_client *client)
redsocks_log_errno(client, LOG_ERR, "red_connect_relay");
redsocks_drop_client(client);
}
else {
if (client->timeout > 0) {
redsocks_log_error(client, LOG_INFO, "settimeout");
bufferevent_settimeout(client->relay, client->timeout,client->timeout);
}
}
}

static struct timeval drop_idle_connections()
Expand Down Expand Up @@ -1225,6 +1234,7 @@ static void redsocks_accept_client(int fd, short what, void *_arg)

redsocks_touch_client(client);

client->timeout = self->config.timeout;
client->client = bufferevent_new(client_fd, NULL, NULL, redsocks_event_error, client);
if (!client->client) {
log_errno(LOG_ERR, "bufferevent_new");
Expand Down
2 changes: 2 additions & 0 deletions redsocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ typedef struct redsocks_config_t {
bool use_splice;
enum disclose_src_e disclose_src;
enum on_proxy_fail_e on_proxy_fail;
uint16_t timeout;
} redsocks_config;

typedef struct redsocks_instance_t {
Expand All @@ -60,6 +61,7 @@ typedef struct redsocks_client_t {
evshut_t relay_evshut;
struct timeval first_event;
struct timeval last_event;
uint16_t timeout;
} redsocks_client;

typedef struct splice_pipe_t {
Expand Down