Roll back required TUN mappings and verify instance startup failures

This commit is contained in:
evgeny committed 2026-10-24 13:36:22 +02:00
1 parent c4eddfe50e
commit bb2ef05157
2 files changed
+39 -4

No files matched your search

+16 -3
View File
@@ -752,6 +752,9 @@ struct tcp_proxy_client* tcp_proxy_client_create(struct UTUN_INSTANCE* inst, str
}
int need_tun = tun_name && tun_name[0] && tun_ip && tun_ip[0];
if ((tun_name && tun_name[0]) != (tun_ip && tun_ip[0])) {
DEBUG_ERROR(DEBUG_CATEGORY_PROXY, "TCP proxy client: TUN requires both name and IP"); return NULL;
}
if (!need_tun && !socks_enabled && !http_proxy_enabled) {
DEBUG_ERROR(DEBUG_CATEGORY_PROXY, "no proxy mode enabled"); return NULL;
}
@@ -784,10 +787,20 @@ struct tcp_proxy_client* tcp_proxy_client_create(struct UTUN_INSTANCE* inst, str
int j; for (j = 0; j < mapping_count; j++) {
uint16_t port_net = htons(mappings[j].local_port);
struct tcp_pcb *lpcb = tcp_new(p->lwip);
if (!lpcb) continue;
tcp_bind(lpcb, INADDR_ANY, port_net);
if (!lpcb) {
DEBUG_ERROR(DEBUG_CATEGORY_PROXY, "TCP proxy client: mapping PCB allocation failed port=%u", mappings[j].local_port);
tcp_proxy_client_destroy(p); return NULL;
}
if (tcp_bind(lpcb, INADDR_ANY, port_net) != LERR_OK) {
DEBUG_ERROR(DEBUG_CATEGORY_PROXY, "TCP proxy client: mapping bind failed port=%u", mappings[j].local_port);
tcp_abort(lpcb); tcp_proxy_client_destroy(p); return NULL;
}
struct tcp_pcb *listen_pcb = tcp_listen(lpcb);
if (listen_pcb) { tcp_arg(listen_pcb, p); tcp_accept(listen_pcb, tcp_proxy_client_accept_cb); }
if (!listen_pcb) {
DEBUG_ERROR(DEBUG_CATEGORY_PROXY, "TCP proxy client: mapping listen failed port=%u", mappings[j].local_port);
tcp_abort(lpcb); tcp_proxy_client_destroy(p); return NULL;
}
tcp_arg(listen_pcb, p); tcp_accept(listen_pcb, tcp_proxy_client_accept_cb);
}
}
}