Open enp6 opened 1 year ago
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.
Thanks for posting this, have you found a workaround? /cc. @yuguorui @erebe @XOR-op
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)
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.
Does this works if you try to contact your udp socks5 from another machine @ddscentral ?
IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0))
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.
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?
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
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.
Agreed, but unfortunately RFC 1928 does not have a detailed description for this part.
Is udp client supported now? See README it's still on the TODO list.
By "udp client" you mean UDP support in the "client" example ?
Yeah, It only has TCP client exmaple.
Does UDP work? Would be nice as most rust based socks5 servers don't support UDP
With a small modification I've posted before, UDP does work for me, at least with tun2socks as client.
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"