semigodking / redsocks

transparent redirector of any TCP/UDP connection to proxy
Apache License 2.0
1.14k stars 246 forks source link

Fix UDP source address compare #183

Closed jromwu closed 1 year ago

jromwu commented 1 year ago

When comparing the client address, the paddings in the sockaddr_storage is also compared as well. Because the paddings are not necessarily zeroed, the comparison can give non-zero result when the addresses are the same. This can cause every single outgoing UDP packet to have different source ports when being proxied.

First time contributing to projects, please let me know if I have done anything wrong. Cheers!

semigodking commented 1 year ago

又不是用evutil_sockaddr_cmp方便点?

semigodking commented 1 year ago

方便试一下如下改动?

diff --git a/redudp.c b/redudp.c
index d58f9b2..0a851ff 100644
--- a/redudp.c
+++ b/redudp.c
@@ -413,7 +413,10 @@ static void redudp_pkt_from_client(int fd, short what, void *_arg)

     // TODO: this lookup may be SLOOOOOW.
     list_for_each_entry(tmp, &self->clients, list) {
-        if (0 == memcmp(&clientaddr, &tmp->clientaddr, sizeof(clientaddr))) {
+        if (0 == evutil_sockaddr_cmp((struct sockaddr *)&clientaddr,
+                                     (struct sockaddr *)&tmp->clientaddr,
+                                     1)) {
+
             client = tmp;
             break;
         }
semigodking commented 1 year ago

Close. Use simplified code.