|
|
@ -200,14 +200,17 @@ hash_key(const int af, const struct sockaddr_storage *addr) |
|
|
|
} |
|
|
|
|
|
|
|
#if defined(MODULE_REDIR) || defined(MODULE_REMOTE) |
|
|
|
|
|
|
|
static int |
|
|
|
construct_udprelay_header(const struct sockaddr_storage *in_addr, |
|
|
|
char *addr_header) |
|
|
|
{ |
|
|
|
int addr_header_len = 0; |
|
|
|
|
|
|
|
if (in_addr->ss_family == AF_INET) { |
|
|
|
struct sockaddr_in *addr = (struct sockaddr_in *)in_addr; |
|
|
|
size_t addr_len = sizeof(struct in_addr); |
|
|
|
|
|
|
|
addr_header[addr_header_len++] = 1; |
|
|
|
memcpy(addr_header + addr_header_len, &addr->sin_addr, addr_len); |
|
|
|
addr_header_len += addr_len; |
|
|
@ -216,6 +219,7 @@ construct_udprelay_header(const struct sockaddr_storage *in_addr, |
|
|
|
} else if (in_addr->ss_family == AF_INET6) { |
|
|
|
struct sockaddr_in6 *addr = (struct sockaddr_in6 *)in_addr; |
|
|
|
size_t addr_len = sizeof(struct in6_addr); |
|
|
|
|
|
|
|
addr_header[addr_header_len++] = 4; |
|
|
|
memcpy(addr_header + addr_header_len, &addr->sin6_addr, addr_len); |
|
|
|
addr_header_len += addr_len; |
|
|
@ -224,6 +228,7 @@ construct_udprelay_header(const struct sockaddr_storage *in_addr, |
|
|
|
} else { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
return addr_header_len; |
|
|
|
} |
|
|
|
|
|
|
@ -258,7 +263,7 @@ parse_udprelay_header(const char *buf, const size_t buf_len, |
|
|
|
uint8_t name_len = *(uint8_t *)(buf + offset); |
|
|
|
if (name_len + 4 <= buf_len) { |
|
|
|
if (storage != NULL) { |
|
|
|
char tmp[257] = { 0 }; |
|
|
|
char tmp[MAX_HOSTNAME_LEN] = { 0 }; |
|
|
|
struct cork_ip ip; |
|
|
|
memcpy(tmp, buf + offset + 1, name_len); |
|
|
|
if (cork_ip_init(&ip, tmp) != -1) { |
|
|
@ -655,9 +660,6 @@ resolv_cb(struct sockaddr *addr, void *data) |
|
|
|
remote_ctx = new_remote(remotefd, query_ctx->server_ctx); |
|
|
|
remote_ctx->src_addr = query_ctx->src_addr; |
|
|
|
remote_ctx->server_ctx = query_ctx->server_ctx; |
|
|
|
remote_ctx->addr_header_len = query_ctx->addr_header_len; |
|
|
|
memcpy(remote_ctx->addr_header, query_ctx->addr_header, |
|
|
|
query_ctx->addr_header_len); |
|
|
|
} else { |
|
|
|
ERROR("[udp] bind() error"); |
|
|
|
} |
|
|
@ -785,7 +787,7 @@ remote_recv_cb(EV_P_ ev_io *w, int revents) |
|
|
|
rx += buf->len; |
|
|
|
|
|
|
|
// Reconstruct UDP response header |
|
|
|
char addr_header[512]; |
|
|
|
char addr_header[MAX_ADDR_HEADER_SIZE]; |
|
|
|
int addr_header_len = construct_udprelay_header(&src_addr, addr_header); |
|
|
|
|
|
|
|
// Construct packet |
|
|
@ -1002,7 +1004,7 @@ server_recv_cb(EV_P_ ev_io *w, int revents) |
|
|
|
*/ |
|
|
|
|
|
|
|
#ifdef MODULE_REDIR |
|
|
|
char addr_header[512] = { 0 }; |
|
|
|
char addr_header[MAX_ADDR_HEADER_SIZE] = { 0 }; |
|
|
|
int addr_header_len = construct_udprelay_header(&dst_addr, addr_header); |
|
|
|
|
|
|
|
if (addr_header_len == 0) { |
|
|
@ -1018,7 +1020,7 @@ server_recv_cb(EV_P_ ev_io *w, int revents) |
|
|
|
|
|
|
|
#elif MODULE_TUNNEL |
|
|
|
|
|
|
|
char addr_header[512] = { 0 }; |
|
|
|
char addr_header[MAX_ADDR_HEADER_SIZE] = { 0 }; |
|
|
|
char *host = server_ctx->tunnel_addr.host; |
|
|
|
char *port = server_ctx->tunnel_addr.port; |
|
|
|
uint16_t port_num = (uint16_t)atoi(port); |
|
|
@ -1074,8 +1076,8 @@ server_recv_cb(EV_P_ ev_io *w, int revents) |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
char host[257] = { 0 }; |
|
|
|
char port[64] = { 0 }; |
|
|
|
char host[MAX_HOSTNAME_LEN] = { 0 }; |
|
|
|
char port[MAX_PORT_STR_LEN] = { 0 }; |
|
|
|
struct sockaddr_storage dst_addr; |
|
|
|
memset(&dst_addr, 0, sizeof(struct sockaddr_storage)); |
|
|
|
|
|
|
@ -1086,7 +1088,6 @@ server_recv_cb(EV_P_ ev_io *w, int revents) |
|
|
|
goto CLEAN_UP; |
|
|
|
} |
|
|
|
|
|
|
|
char *addr_header = buf->data + offset; |
|
|
|
#endif |
|
|
|
|
|
|
|
#ifdef MODULE_LOCAL |
|
|
@ -1198,9 +1199,6 @@ server_recv_cb(EV_P_ ev_io *w, int revents) |
|
|
|
ev_timer_start(EV_A_ & remote_ctx->watcher); |
|
|
|
} |
|
|
|
|
|
|
|
remote_ctx->addr_header_len = addr_header_len; |
|
|
|
memcpy(remote_ctx->addr_header, addr_header, addr_header_len); |
|
|
|
|
|
|
|
if (offset > 0) { |
|
|
|
buf->len -= offset; |
|
|
|
memmove(buf->data, buf->data + offset, buf->len); |
|
|
@ -1230,6 +1228,8 @@ server_recv_cb(EV_P_ ev_io *w, int revents) |
|
|
|
int cache_hit = 0; |
|
|
|
int need_query = 0; |
|
|
|
|
|
|
|
char *addr_header = buf->data + offset; |
|
|
|
|
|
|
|
if (buf->len - addr_header_len > packet_size) { |
|
|
|
if (verbose) { |
|
|
|
LOGI("[udp] server_recv_sendto fragmentation, MTU at least be: " SSIZE_FMT, |
|
|
@ -1267,8 +1267,6 @@ server_recv_cb(EV_P_ ev_io *w, int revents) |
|
|
|
remote_ctx = new_remote(remotefd, server_ctx); |
|
|
|
remote_ctx->src_addr = src_addr; |
|
|
|
remote_ctx->server_ctx = server_ctx; |
|
|
|
remote_ctx->addr_header_len = addr_header_len; |
|
|
|
memcpy(remote_ctx->addr_header, addr_header, addr_header_len); |
|
|
|
memcpy(&remote_ctx->dst_addr, &dst_addr, sizeof(struct sockaddr_storage)); |
|
|
|
} else { |
|
|
|
ERROR("[udp] bind() error"); |
|
|
|