frpc: add parameter nat_hole_server_addr (#3351)

This commit is contained in:
fatedier 2023-03-10 15:51:14 +08:00 committed by GitHub
parent 968ba4d3a1
commit fccd518512
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 2 deletions

View File

@ -305,8 +305,12 @@ func (pxy *XTCPProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
ProxyName: pxy.cfg.ProxyName,
Sid: natHoleSidMsg.Sid,
}
serverAddr := pxy.clientCfg.NatHoleServerAddr
if serverAddr == "" {
serverAddr = pxy.clientCfg.ServerAddr
}
raddr, _ := net.ResolveUDPAddr("udp",
net.JoinHostPort(pxy.clientCfg.ServerAddr, strconv.Itoa(pxy.serverUDPPort)))
net.JoinHostPort(serverAddr, strconv.Itoa(pxy.serverUDPPort)))
clientConn, err := net.DialUDP("udp", nil, raddr)
if err != nil {
xl.Error("dial server udp addr error: %v", err)

View File

@ -210,8 +210,12 @@ func (sv *XTCPVisitor) handleConn(userConn net.Conn) {
return
}
serverAddr := sv.ctl.clientCfg.NatHoleServerAddr
if serverAddr == "" {
serverAddr = sv.ctl.clientCfg.ServerAddr
}
raddr, err := net.ResolveUDPAddr("udp",
net.JoinHostPort(sv.ctl.clientCfg.ServerAddr, strconv.Itoa(sv.ctl.serverUDPPort)))
net.JoinHostPort(serverAddr, strconv.Itoa(sv.ctl.serverUDPPort)))
if err != nil {
xl.Error("resolve server UDP addr error")
return

View File

@ -6,6 +6,10 @@
server_addr = 0.0.0.0
server_port = 7000
# Specify another address of the server to connect for nat hole. By default, it's same with
# server_addr.
# nat_hole_server_addr = 0.0.0.0
# The maximum amount of time a dial to server will wait for a connect to complete. Default value is 10 seconds.
# dial_server_timeout = 10

View File

@ -35,6 +35,9 @@ type ClientCommonConf struct {
// ServerAddr specifies the address of the server to connect to. By
// default, this value is "0.0.0.0".
ServerAddr string `ini:"server_addr" json:"server_addr"`
// Specify another address of the server to connect for nat hole. By default, it's same with
// ServerAddr.
NatHoleServerAddr string `ini:"nat_hole_server_addr" json:"nat_hole_server_addr"`
// ServerPort specifies the port to connect to the server on. By default,
// this value is 7000.
ServerPort int `ini:"server_port" json:"server_port"`