Skip to content

Commit

Permalink
Add UDP source IP into golang dialer https connection for Edgeview
Browse files Browse the repository at this point in the history
- have seen on certain EVE devices, even walk through various ports, the
  UDP source IP address used stuck on one particular IP address, and it
  then failed on DNS query and failed Edgeview connection.

Signed-off-by: Naiming Shen <naiming@zededa.com>
  • Loading branch information
naiming-zededa committed Jan 26, 2025
1 parent 7b88861 commit 8d5c06a
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pkg/edgeview/src/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package main

import (
"bytes"
"context"
"crypto/tls"
"crypto/x509"
"encoding/json"
Expand Down Expand Up @@ -175,7 +176,21 @@ func tlsDial(isServer bool, pIP string, pport int, src []net.IP, idx int) (*webs
dialer.Proxy = http.ProxyURL(proxyURL)
}
if idx >= 0 && len(src) > 0 && idx < len(src) {
dialer.NetDialContext = (&net.Dialer{LocalAddr: &net.TCPAddr{IP: src[idx]}}).DialContext
srcSelected := src[idx]
localAddr := &net.TCPAddr{IP: srcSelected}
netDialer := &net.Dialer{
LocalAddr: localAddr,
Resolver: &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
d := net.Dialer{
LocalAddr: &net.UDPAddr{IP: srcSelected},
}
return d.DialContext(ctx, network, address)
},
},
}
dialer.NetDialContext = netDialer.DialContext
}

return dialer, nil
Expand Down

0 comments on commit 8d5c06a

Please sign in to comment.