From 9a9fc8a9aae81cc8015c2624d835f1c700c6a11b Mon Sep 17 00:00:00 2001 From: ruti <> Date: Fri, 16 Aug 2024 19:10:09 +0300 Subject: [PATCH] Set TTL before connect (UDP) --- proxy.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/proxy.c b/proxy.c index bad27c7..b96301a 100644 --- a/proxy.c +++ b/proxy.c @@ -437,17 +437,22 @@ int udp_associate(struct poolhd *pool, return -1; } if (dst->in6.sin6_port != 0) { + if (socket_mod(ufd, &addr.sa) < 0) { + del_event(pool, pair); + return -1; + } if (connect(ufd, &addr.sa, SA_SIZE(&addr)) < 0) { uniperror("connect"); del_event(pool, pair); return -1; } - if (socket_mod(ufd, &addr.sa) < 0) { - del_event(pool, pair); - return -1; - } pair->in6 = addr.in6; } + if (params.debug) { + INIT_ADDR_STR((*dst)); + LOG(LOG_S, "udp associate: fd=%d, addr=%s:%d\n", + ufd, ADDR_STR, ntohs(dst->in.sin_port)); + } // socklen_t sz = sizeof(addr); @@ -689,11 +694,11 @@ int on_udp_tunnel(struct eval *val, char *buffer, size_t bfsize) if (params.baddr.sin6_family != addr.sa.sa_family) { return -1; } - if (connect(val->pair->fd, &addr.sa, SA_SIZE(&addr)) < 0) { - uniperror("connect"); + if (socket_mod(val->pair->fd, &addr.sa) < 0) { return -1; } - if (socket_mod(val->pair->fd, &addr.sa) < 0) { + if (connect(val->pair->fd, &addr.sa, SA_SIZE(&addr)) < 0) { + uniperror("connect"); return -1; } val->pair->in6 = addr.in6;