|
|
|
|
@ -57,7 +57,7 @@ static int send_msg(struct UTUN_INSTANCE* inst, uint64_t group_id, uint64_t dst,
|
|
|
|
|
if (!e) { DEBUG_ERROR(DEBUG_CATEGORY_PROXY, "tcp_proxy_server: queue_entry_new failed subcmd=%02x sid=%08x", subcmd, sid); return -1; } |
|
|
|
|
e->dgram = u_malloc(TCP_PROXY_HDR_SIZE + len); |
|
|
|
|
if (!e->dgram) { DEBUG_ERROR(DEBUG_CATEGORY_PROXY, "tcp_proxy_server: malloc(%zu) failed", TCP_PROXY_HDR_SIZE + len); queue_entry_free(e); return -1; } |
|
|
|
|
e->dgram[0] = ETCP_RT_ID_TCP_PROXY; |
|
|
|
|
e->dgram[0] = ETCP_RT_ID_TCP_PROXY_CLIENT; |
|
|
|
|
e->dgram[1] = subcmd; |
|
|
|
|
memcpy(e->dgram + 2, &sid, 4); |
|
|
|
|
if (len > 0) memcpy(e->dgram + TCP_PROXY_HDR_SIZE, data, len); |
|
|
|
|
@ -228,7 +228,7 @@ static void read_queue_drain_cb(struct ll_queue* q, void* arg) {
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
etcp_router_on_send_ready(inst, TOPO_GROUP_UTUN, rc->peer_node_id, ETCP_RT_ID_TCP_PROXY, |
|
|
|
|
etcp_router_on_send_ready(inst, TOPO_GROUP_UTUN, rc->peer_node_id, ETCP_RT_ID_TCP_PROXY_CLIENT, |
|
|
|
|
&rc->pause_waiter, pause_resume_cb, rc); |
|
|
|
|
if (!rc->retry_timer) rc->retry_timer = uasync_set_timeout(rc->ua, 5000, rc, retry_timer_cb, "tps_retry"); |
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_PROXY, "TPS TXBUF BP AGAIN: sid=%08x waiter_reg", rc->stream_id); |
|
|
|
|
@ -267,7 +267,7 @@ static void read_queue_drain_cb(struct ll_queue* q, void* arg) {
|
|
|
|
|
memory_pool_free(rc->tc->data_pool, e->dgram); queue_entry_free(e); |
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_PROXY, "SOCK:BACKPRESSURE fd=%d sid=%08x — buffered %u for retry", |
|
|
|
|
(int)rc->tc->sock, rc->stream_id, rc->tx_len); |
|
|
|
|
etcp_router_on_send_ready(inst, TOPO_GROUP_UTUN, rc->peer_node_id, ETCP_RT_ID_TCP_PROXY, |
|
|
|
|
etcp_router_on_send_ready(inst, TOPO_GROUP_UTUN, rc->peer_node_id, ETCP_RT_ID_TCP_PROXY_CLIENT, |
|
|
|
|
&rc->pause_waiter, pause_resume_cb, rc); |
|
|
|
|
if (!rc->retry_timer) rc->retry_timer = uasync_set_timeout(rc->ua, 5000, rc, retry_timer_cb, "tps_retry"); |
|
|
|
|
} |
|
|
|
|
@ -334,7 +334,7 @@ void tcp_proxy_server_conn_free(struct tcp_proxy_server_conn* rc) {
|
|
|
|
|
struct tcp_proxy_server_conn** prev = &rc->ctx->conns; |
|
|
|
|
while (*prev) { if (*prev == rc) { *prev = rc->next; rc->ctx->conn_count--; break; } prev = &(*prev)->next; } |
|
|
|
|
} |
|
|
|
|
if (rc->ctx && rc->ctx->inst) etcp_router_cancel_send_ready(rc->ctx->inst, TOPO_GROUP_UTUN, rc->peer_node_id, ETCP_RT_ID_TCP_PROXY, &rc->pause_waiter); |
|
|
|
|
if (rc->ctx && rc->ctx->inst) etcp_router_cancel_send_ready(rc->ctx->inst, TOPO_GROUP_UTUN, rc->peer_node_id, ETCP_RT_ID_TCP_PROXY_CLIENT, &rc->pause_waiter); |
|
|
|
|
if (rc->tx_buf) { u_free(rc->tx_buf); rc->tx_buf = NULL; rc->tx_len = 0; } |
|
|
|
|
if (rc->retry_timer) { uasync_cancel_timeout(rc->ua, rc->retry_timer); rc->retry_timer = NULL; } |
|
|
|
|
if (rc->close_timer) { uasync_cancel_timeout(rc->ua, rc->close_timer); rc->close_timer = NULL; } |
|
|
|
|
@ -506,7 +506,7 @@ void tcp_proxy_server_recv_cb(struct ETCP_CONN* conn, struct ll_entry* entry) {
|
|
|
|
|
struct UTUN_INSTANCE* inst = conn ? conn->instance : NULL; |
|
|
|
|
|
|
|
|
|
if (!entry || !entry->dgram || entry->len < TCP_PROXY_HDR_SIZE) { |
|
|
|
|
if (entry && entry->len == 9 && !conn && entry->dgram[0] == ETCP_RT_ID_TCP_PROXY) { |
|
|
|
|
if (entry && entry->len == 9 && !conn && entry->dgram[0] == ETCP_RT_ID_TCP_PROXY_SERVER) { |
|
|
|
|
uint64_t peer_id; |
|
|
|
|
memcpy(&peer_id, entry->dgram + 1, 8); |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_PROXY, "PROXY CLOSE_ALL from %016llx — clearing server conns for peer", |
|
|
|
|
@ -562,7 +562,7 @@ int tcp_proxy_server_init(struct UTUN_INSTANCE* inst) {
|
|
|
|
|
ctx->inst = inst; |
|
|
|
|
if (!ctx->enabled) return 0; |
|
|
|
|
g_tcp_proxy_server_ctx = ctx; |
|
|
|
|
etcp_router_bind(inst, ETCP_RT_ID_TCP_PROXY, tcp_proxy_server_recv_cb); |
|
|
|
|
etcp_router_bind(inst, ETCP_RT_ID_TCP_PROXY_SERVER, tcp_proxy_server_recv_cb); |
|
|
|
|
if (!inst->config->global.tcp_proxy_client_enabled) { |
|
|
|
|
udp_proxy_init(inst, inst->ua); |
|
|
|
|
icmp_proxy_init(inst, inst->ua); |
|
|
|
|
|