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

Avoid using custom dialers for proxy when not mobile #2229

Closed

Conversation

mlsmaycon
Copy link
Collaborator

Describe your changes

Issue ticket number and link

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • Extended the README / documentation, if necessary

Copy link

sonarqubecloud bot commented Jul 2, 2024

if runtime.GOOS == "ios" || runtime.GOOS == "android" {
p.localConn, err = nbnet.NewDialer().DialContext(p.ctx, "udp", fmt.Sprintf(":%d", p.localWGListenPort))
} else {
p.localConn, err = net.Dial("udp", fmt.Sprintf(":%d", p.localWGListenPort))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use DialContext here regardless?

@@ -72,10 +73,10 @@ func (p *WGEBPFProxy) listen() error {

addr := net.UDPAddr{
Port: wgPorxyPort,
IP: net.ParseIP("127.0.0.1"),
IP: net.ParseIP(loopbackIPv4Addres),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like net.IP{127, 0, 0, 1} is a bit better here.

err = nbnet.SetSocketOpt(fd)
if err != nil {
return nil, fmt.Errorf("setting fwmark failed: %w", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only block that should be removed. The other stuff should stay, we should still check if os.NewFile returns nil.

@@ -35,7 +36,11 @@ func (p *WGUserSpaceProxy) AddTurnConn(turnConn net.Conn) (net.Addr, error) {
p.remoteConn = turnConn

var err error
p.localConn, err = nbnet.NewDialer().DialContext(p.ctx, "udp", fmt.Sprintf(":%d", p.localWGListenPort))
if runtime.GOOS == "ios" || runtime.GOOS == "android" {
Copy link
Contributor

@lixmal lixmal Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be android only, iOS already calls net.Dial underneath anyway. I'm not sure about Android either, it likely has 127.0.0.0/8 in the local table as well, so there might be no need to protect the socket there.

@mlsmaycon mlsmaycon closed this Jul 12, 2024
@mlsmaycon mlsmaycon deleted the fix/skip-using-custom-dialer-on-proxy-if-not-mobile branch July 12, 2024 07:21
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

Successfully merging this pull request may close these issues.

2 participants