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

feat: add support for setting custom udp listen port on the xtcp mode #4681

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/proxy/xtcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (pxy *XTCPProxy) InWorkConn(conn net.Conn, startWorkConnMsg *msg.StartWorkC
}

xl.Tracef("nathole prepare start")
prepareResult, err := nathole.Prepare([]string{pxy.clientCfg.NatHoleSTUNServer})
prepareResult, err := nathole.Prepare([]string{pxy.clientCfg.NatHoleSTUNServer}, "")
if err != nil {
xl.Warnf("nathole prepare error: %v", err)
return
Expand Down
2 changes: 1 addition & 1 deletion client/visitor/xtcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func (sv *XTCPVisitor) makeNatHole() {
}

xl.Tracef("nathole prepare start")
prepareResult, err := nathole.Prepare([]string{sv.clientCfg.NatHoleSTUNServer})
prepareResult, err := nathole.Prepare([]string{sv.clientCfg.NatHoleSTUNServer}, sv.cfg.UDPListen)
if err != nil {
xl.Warnf("nathole prepare error: %v", err)
return
Expand Down
5 changes: 5 additions & 0 deletions pkg/config/v1/visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ type XTCPVisitorConfig struct {
MinRetryInterval int `json:"minRetryInterval,omitempty"`
FallbackTo string `json:"fallbackTo,omitempty"`
FallbackTimeoutMs int `json:"fallbackTimeoutMs,omitempty"`

// Specify the listen addr and port for the UDP NAT hole punching, the format is "addr:port" like "0.0.0.0:7000".
// It is useful when your router's NAT hole punching doesn't work well, so you can explicitly config a UDP port
// forwarding rule on the router to work around.
UDPListen string `json:"udpListen,omitempty"`
}

func (c *XTCPVisitorConfig) Complete(g *ClientCommonConfig) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/nathole/nathole.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ func PreCheck(
}

// Prepare is used to do some preparation work before penetration.
func Prepare(stunServers []string) (*PrepareResult, error) {
func Prepare(stunServers []string, udpListen string) (*PrepareResult, error) {
// discover for Nat type
addrs, localAddr, err := Discover(stunServers, "")
addrs, localAddr, err := Discover(stunServers, udpListen)
if err != nil {
return nil, fmt.Errorf("discover error: %v", err)
}
Expand Down