Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is a bug in udp support #32

Open
enp6 opened this issue Mar 22, 2023 · 15 comments
Open

There is a bug in udp support #32

enp6 opened this issue Mar 22, 2023 · 15 comments

Comments

@enp6
Copy link

enp6 commented Mar 22, 2023

cargo run -- --listen-addr 0.0.0.0:5000 password -u 111 -p 333

In the code, I have written config.set_udp_support(true);

However, it still cannot support UDP and prompts "invalid reply ip"

@ddscentral
Copy link

ddscentral commented Jul 4, 2023

Sorry for necro. Yes, the example does not appear to work with UDP even with UDP support enabled in the library.
I got it working with a small hack to src/server.rs,but it's probably not PR-worthy (still learning Rust). Can post if anyone needs it.

@dizda
Copy link
Owner

dizda commented Feb 1, 2024

Thanks for posting this, have you found a workaround? /cc. @yuguorui @erebe @XOR-op

@erebe
Copy link
Contributor

erebe commented Feb 1, 2024

I don't know, I use this crate as a lib and don't use the implemented server/client. (I disable the exec of cmd).
For UDP, I have a special case where I return the bind addr of the udp server I spawn.
https://github.com/erebe/wstunnel/blob/main/src/socks5.rs#L116

Only difference from https://github.com/dizda/fast-socks5/blob/master/src/server.rs#L699 is that I return the ip of the binded socket, not the one from the reply_ip (which I always discard)

@ddscentral
Copy link

Here's a (very) rough patch which makes UDP work for me in the server example. It does some need cleanup and an extra "rand" dependency.
fast-socks-udpfix.patch

I am a developer but not very familiar with intricacies of Rust. Maybe this patch will at least give you an idea on why the current implementation doesn't work.

@erebe
Copy link
Contributor

erebe commented Feb 1, 2024

Does this works if you try to contact your udp socks5 from another machine @ddscentral ?

IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0))

@ddscentral
Copy link

ddscentral commented Feb 1, 2024

You mean outside of localhost ?
Yes, it does work fine. Server and client are separate machines. I run tun2socks on the client machine with tunnel interface as it's default route (so all traffic goes through a fast-socks5 server). This program has connection logging and I do see DNS requests over UDP going through without errors.

@yuguorui
Copy link
Contributor

yuguorui commented Feb 1, 2024

Thanks for posting this, have you found a workaround? /cc. @yuguorui @erebe @XOR-op

Yeah, it is hard to set a reply_ip without the knowledge of underlay socket.

There is an API set_reply_ip() at https://github.com/dizda/fast-socks5/blob/master/src/server.rs#L292. Could you @enp6 please set an IP with this API?

@yuguorui
Copy link
Contributor

yuguorui commented Feb 1, 2024

And here is the comments about the API.

    /// Set the bind IP address in Socks5Reply.
    ///
    /// Only the inner socket owner knows the correct reply bind addr, so leave this field to be
    /// populated. For those strict clients, users can use this function to set the correct IP
    /// address.
    ///
    /// Most popular SOCKS5 clients [1] [2] ignore BND.ADDR and BND.PORT the reply of command
    /// CONNECT, but this field could be useful in some other command, such as UDP ASSOCIATE.
    ///
    /// [1]. https://github.com/chromium/chromium/blob/bd2c7a8b65ec42d806277dd30f138a673dec233a/net/socket/socks5_client_socket.cc#L481
    /// [2]. https://github.com/curl/curl/blob/d15692ebbad5e9cfb871b0f7f51a73e43762cee2/lib/socks.c#L978

@ddscentral
Copy link

Well setting the reply IP to all zeros (instead of IPv6 localhost) and a random port instead of a zero port seems to work.
But I'm not entirely sure whether this is the correct way to do it, my guess is it isn't or definitely not the best.

@yuguorui
Copy link
Contributor

yuguorui commented Feb 2, 2024

Agreed, but unfortunately RFC 1928 does not have a detailed description for this part.

@mokeyish
Copy link
Contributor

mokeyish commented Feb 5, 2024

Is udp client supported now? See README it's still on the TODO list.

@ddscentral
Copy link

ddscentral commented Feb 5, 2024

By "udp client" you mean UDP support in the "client" example ?

@mokeyish
Copy link
Contributor

mokeyish commented Feb 5, 2024

Yeah, It only has TCP client exmaple.

@osousa
Copy link

osousa commented Feb 24, 2024

Does UDP work? Would be nice as most rust based socks5 servers don't support UDP

@ddscentral
Copy link

With a small modification I've posted before, UDP does work for me, at least with tun2socks as client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants