Skip to content
This repository has been archived by the owner on Aug 22, 2021. It is now read-only.

How can I add standard socks Udp Associate feature into this tun2socks? #56

Closed
GF-Huang opened this issue Jan 30, 2018 · 11 comments · May be fixed by #71
Closed

How can I add standard socks Udp Associate feature into this tun2socks? #56

GF-Huang opened this issue Jan 30, 2018 · 11 comments · May be fixed by #71

Comments

@GF-Huang
Copy link

This project is complex, would you give me a starting point ?

@GF-Huang GF-Huang changed the title How can I add standard socks Udp Associate feature into this project ? How can I add standard socks Udp Associate feature into this tun2socks? Jan 30, 2018
@ambrop72
Copy link
Owner

Hi,

  • Software is based on a single-threaded event-driven architecture, so read up on event loops etc.. The event loop implementation is in system/BReactor_badvpn.{h,c}.
  • To work with UDP, use the existing BDatagram facility (look at system/BDatagram.h for the API).
  • The tun2socks main implementation is in tun2socks/tun2socks.c. The most important functions here are:
    • process_device_udp_packet (called to handle a UDP packet coming in from the TUN and needs to be sent),
    • BTap_Send - use this when you receive a packet to send it into the TUN, see for example what udpgw_client_handler_received does.
  • The current UDP support in tun2socks uses the custom "udpgw" server - you will need to add conditionals (e.g. in the above mentioned places) so that UDP support is provided either by udpgw or UDP Associate.
  • You will need to maintain a collection of UDP "associations", and you will need to associate packets coming from TUN with a association possibly involving creation of one. Each "association" object will be responsible for a particular (LocalPort, RemotePort, LocalAddress, RemoteAddress) combination.
  • Each association object will need to do the SOCKS handshaking using TCP. You can probably copy a lot of code from current socksclient/ code which is for TCP connections. It would be best to separate this code into its own module. Or maybe the existing socksclient could be extended to also do UDP Associate, your call.
  • You will probably need to buffer packets within associations while you are doing the SOCKS handshaking, to prevent undesired loss.

I need to go right now, I can provide further guidance...

@GF-Huang
Copy link
Author

Well, thanks your detailed guides.
I go to have a try first.

@GF-Huang
Copy link
Author

GF-Huang commented Jan 31, 2018

Hi,
Another question: Why not use map(dictionary) (use source port or destination port as key or both) to manage connections instead of AVL tree for enhance performance of finding connection in "UdpGwClient.c Line 529"?

bemasc pushed a commit to bemasc/badvpn that referenced this issue Dec 14, 2018
This change adds a new option, --socks5-udp.  If this option is
present, and no UDP gateway is specified, UDP packets will no
longer be dropped.  Instead, the client will use the SOCKS5
UDP ASSOCIATE command to route UDP packets through the proxy
server.

This implementation is intended for use with any UDP data, and it
includes an optimization for packets containing DNS queries.
However, this implementation is currently limited to localhost
SOCKS5 servers. SOCKS5-UDP does not perform well over actual
network links, as it requires several roundtrips to the server and
is not compatible with NAT.

This implementation is currently in use in a fork of tun2socks used
by Outline (https://getoutline.org) and Intra (https://getintra.org).

Fixes ambrop72#56
bemasc pushed a commit to bemasc/badvpn that referenced this issue Jan 15, 2019
This change adds a new option, --socks5-udp.  If this option is
present, and no UDP gateway is specified, UDP packets will no
longer be dropped.  Instead, the client will use the SOCKS5
UDP ASSOCIATE command to route UDP packets through the proxy
server.

This implementation is intended for use with any UDP data, and it
includes an optimization for packets containing DNS queries.
However, this implementation is currently limited to localhost
SOCKS5 servers. SOCKS5-UDP does not perform well over actual
network links, as it requires several roundtrips to the server and
is not compatible with NAT.

This implementation is currently in use in a fork of tun2socks used
by Outline (https://getoutline.org) and Intra (https://getintra.org).

Fixes ambrop72#56
@4-FLOSS-Free-Libre-Open-Source-Software

@greatfirewall give #71 a try

@diegocr
Copy link

diegocr commented Aug 6, 2019

While waiting for #71 to get merged (any eta?) a good workaround would be using dns2socks

@GF-Huang
Copy link
Author

GF-Huang commented Aug 6, 2019

Emm.. I had built myself product to implement this feature..
If anyone is interested, you can take a look Win2Socks.

@diegocr
Copy link

diegocr commented Aug 6, 2019

Interesting :)

@ambrop72
Copy link
Owner

ambrop72 commented Aug 6, 2019

@greatfirewall, it is not clear to me if your product is based on tun2socks code?

@GF-Huang
Copy link
Author

GF-Huang commented Aug 6, 2019

@greatfirewall, it is not clear to me if your product is based on tun2socks code?

No, I completely developed it myself. I am sorry to make you feel confused. :)

@ambrop72
Copy link
Owner

ambrop72 commented Aug 6, 2019

@greatfirewall, okay good for you, thanks for the info!

@GF-Huang
Copy link
Author

GF-Huang commented Aug 6, 2019

@ambrop72 You're welcome.

ambrop72 pushed a commit that referenced this issue Feb 1, 2020
This change adds a new option, --socks5-udp.  If this option is
present, and no UDP gateway is specified, UDP packets will no
longer be dropped.  Instead, the client will use the SOCKS5
UDP ASSOCIATE command to route UDP packets through the proxy
server.

This implementation is intended for use with any UDP data, and it
includes an optimization for packets containing DNS queries.
However, this implementation is currently limited to localhost
SOCKS5 servers. SOCKS5-UDP does not perform well over actual
network links, as it requires several roundtrips to the server and
is not compatible with NAT.

This implementation is currently in use in a fork of tun2socks used
by Outline (https://getoutline.org) and Intra (https://getintra.org).

Fixes #56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants