diff --git a/cmd/frpc/sub/root.go b/cmd/frpc/sub/root.go index 7f09c03e..9b9a2262 100644 --- a/cmd/frpc/sub/root.go +++ b/cmd/frpc/sub/root.go @@ -69,6 +69,7 @@ var ( sk string serverName string bindAddr string + bindPort int ) func init() { diff --git a/cmd/frpc/sub/stcp.go b/cmd/frpc/sub/stcp.go index d3a5d4af..4915e520 100644 --- a/cmd/frpc/sub/stcp.go +++ b/cmd/frpc/sub/stcp.go @@ -39,7 +39,8 @@ func init() { stcpCmd.PersistentFlags().StringVarP(&serverName, "server_name", "", "", "server name") stcpCmd.PersistentFlags().StringVarP(&localIp, "local_ip", "i", "127.0.0.1", "local ip") stcpCmd.PersistentFlags().IntVarP(&localPort, "local_port", "l", 0, "local port") - stcpCmd.PersistentFlags().StringVarP(&bindAddr, "bind_addr", "", "", "bind addr such as 127.0.0.1:9000") + stcpCmd.PersistentFlags().StringVarP(&bindAddr, "bind_addr", "", "", "bind addr") + stcpCmd.PersistentFlags().IntVarP(&bindPort, "bind_port", "", 0, "bind port") stcpCmd.PersistentFlags().BoolVarP(&useEncryption, "ue", "", false, "use encryption") stcpCmd.PersistentFlags().BoolVarP(&useCompression, "uc", "", false, "use compression") @@ -69,6 +70,7 @@ var stcpCmd = &cobra.Command{ cfg.LocalIp = localIp cfg.LocalPort = localPort cfg.BindAddr = bindAddr + cfg.BindPort = bindPort cfg.UseEncryption = useEncryption cfg.UseCompression = useCompression diff --git a/cmd/frpc/sub/xtcp.go b/cmd/frpc/sub/xtcp.go index e7d07526..8c18a859 100644 --- a/cmd/frpc/sub/xtcp.go +++ b/cmd/frpc/sub/xtcp.go @@ -39,7 +39,8 @@ func init() { xtcpCmd.PersistentFlags().StringVarP(&serverName, "server_name", "", "", "server name") xtcpCmd.PersistentFlags().StringVarP(&localIp, "local_ip", "i", "127.0.0.1", "local ip") xtcpCmd.PersistentFlags().IntVarP(&localPort, "local_port", "l", 0, "local port") - xtcpCmd.PersistentFlags().StringVarP(&bindAddr, "bind_addr", "", "", "bind addr such as 127.0.0.1:9000") + xtcpCmd.PersistentFlags().StringVarP(&bindAddr, "bind_addr", "", "", "bind addr") + xtcpCmd.PersistentFlags().IntVarP(&bindPort, "bind_port", "", 0, "bind port") xtcpCmd.PersistentFlags().BoolVarP(&useEncryption, "ue", "", false, "use encryption") xtcpCmd.PersistentFlags().BoolVarP(&useCompression, "uc", "", false, "use compression") @@ -69,6 +70,7 @@ var xtcpCmd = &cobra.Command{ cfg.LocalIp = localIp cfg.LocalPort = localPort cfg.BindAddr = bindAddr + cfg.BindPort = bindPort cfg.UseEncryption = useEncryption cfg.UseCompression = useCompression diff --git a/models/config/proxy.go b/models/config/proxy.go index 9558f5b0..8b6c0821 100644 --- a/models/config/proxy.go +++ b/models/config/proxy.go @@ -675,6 +675,10 @@ func (cfg *StcpProxyConf) CheckForCli() (err error) { err = fmt.Errorf("bind_addr shouldn't be empty") return } + if cfg.BindPort == 0 { + err = fmt.Errorf("bind_port should be set") + return + } } return } @@ -777,6 +781,10 @@ func (cfg *XtcpProxyConf) CheckForCli() (err error) { err = fmt.Errorf("bind_addr shouldn't be empty") return } + if cfg.BindPort == 0 { + err = fmt.Errorf("bind_port should be set") + return + } } return } diff --git a/server/nathole.go b/server/nathole.go index 042ffcce..0ad0c48f 100644 --- a/server/nathole.go +++ b/server/nathole.go @@ -106,10 +106,17 @@ func (nc *NatHoleController) HandleVisitor(m *msg.NatHoleVisitor, raddr *net.UDP } nc.mu.Lock() clientCfg, ok := nc.clientCfgs[m.ProxyName] - if !ok || m.SignKey != util.GetAuthKey(clientCfg.Sk, m.Timestamp) { + if !ok { nc.mu.Unlock() + log.Debug("xtcp server for [%s] doesn't exist", m.ProxyName) return } + if m.SignKey != util.GetAuthKey(clientCfg.Sk, m.Timestamp) { + nc.mu.Unlock() + log.Debug("xtcp connection of [%s] auth failed", m.ProxyName) + return + } + nc.sessions[sid] = session nc.mu.Unlock() log.Trace("handle visitor message, sid [%s]", sid)