From f63a4f0cddf5c350ae12e8dd348a8fd3eb34a480 Mon Sep 17 00:00:00 2001 From: fatedier Date: Wed, 5 Jul 2017 01:40:01 +0800 Subject: [PATCH] frps: new parameter 'proxy_bind_addr' --- conf/frps_full.ini | 3 +++ models/config/server_common.go | 17 +++++++++++++---- server/proxy.go | 4 ++-- server/service.go | 8 ++++---- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/conf/frps_full.ini b/conf/frps_full.ini index fa72838..446d86a 100644 --- a/conf/frps_full.ini +++ b/conf/frps_full.ini @@ -9,6 +9,9 @@ bind_port = 7000 # if not set, kcp is disabled in frps kcp_bind_port = 7000 +# specify which address proxy will listen for, default value is same with bind_addr +# proxy_bind_addr = 127.0.0.1 + # if you want to support virtual host, you must set the http port for listening (optional) vhost_http_port = 80 vhost_https_port = 443 diff --git a/models/config/server_common.go b/models/config/server_common.go index 1bf1f25..1795a2a 100644 --- a/models/config/server_common.go +++ b/models/config/server_common.go @@ -27,10 +27,11 @@ var ServerCommonCfg *ServerCommonConf // common config type ServerCommonConf struct { - ConfigFile string - BindAddr string - BindPort int64 - KcpBindPort int64 + ConfigFile string + BindAddr string + BindPort int64 + KcpBindPort int64 + ProxyBindAddr string // If VhostHttpPort equals 0, don't listen a public port for http protocol. VhostHttpPort int64 @@ -66,6 +67,7 @@ func GetDefaultServerCommonConf() *ServerCommonConf { BindAddr: "0.0.0.0", BindPort: 7000, KcpBindPort: 0, + ProxyBindAddr: "0.0.0.0", VhostHttpPort: 0, VhostHttpsPort: 0, DashboardPort: 0, @@ -117,6 +119,13 @@ func LoadServerCommonConf(conf ini.File) (cfg *ServerCommonConf, err error) { } } + tmpStr, ok = conf.Get("common", "proxy_bind_addr") + if ok { + cfg.ProxyBindAddr = tmpStr + } else { + cfg.ProxyBindAddr = cfg.BindAddr + } + tmpStr, ok = conf.Get("common", "vhost_http_port") if ok { cfg.VhostHttpPort, err = strconv.ParseInt(tmpStr, 10, 64) diff --git a/server/proxy.go b/server/proxy.go index ac8ddc0..ecc5875 100644 --- a/server/proxy.go +++ b/server/proxy.go @@ -161,7 +161,7 @@ type TcpProxy struct { } func (pxy *TcpProxy) Run() error { - listener, err := frpNet.ListenTcp(config.ServerCommonCfg.BindAddr, pxy.cfg.RemotePort) + listener, err := frpNet.ListenTcp(config.ServerCommonCfg.ProxyBindAddr, pxy.cfg.RemotePort) if err != nil { return err } @@ -330,7 +330,7 @@ type UdpProxy struct { } func (pxy *UdpProxy) Run() (err error) { - addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", config.ServerCommonCfg.BindAddr, pxy.cfg.RemotePort)) + addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", config.ServerCommonCfg.ProxyBindAddr, pxy.cfg.RemotePort)) if err != nil { return err } diff --git a/server/service.go b/server/service.go index 78e7762..e06447d 100644 --- a/server/service.go +++ b/server/service.go @@ -95,7 +95,7 @@ func NewService() (svr *Service, err error) { // Create http vhost muxer. if config.ServerCommonCfg.VhostHttpPort > 0 { var l frpNet.Listener - l, err = frpNet.ListenTcp(config.ServerCommonCfg.BindAddr, config.ServerCommonCfg.VhostHttpPort) + l, err = frpNet.ListenTcp(config.ServerCommonCfg.ProxyBindAddr, config.ServerCommonCfg.VhostHttpPort) if err != nil { err = fmt.Errorf("Create vhost http listener error, %v", err) return @@ -105,13 +105,13 @@ func NewService() (svr *Service, err error) { err = fmt.Errorf("Create vhost httpMuxer error, %v", err) return } - log.Info("http service listen on %s:%d", config.ServerCommonCfg.BindAddr, config.ServerCommonCfg.VhostHttpPort) + log.Info("http service listen on %s:%d", config.ServerCommonCfg.ProxyBindAddr, config.ServerCommonCfg.VhostHttpPort) } // Create https vhost muxer. if config.ServerCommonCfg.VhostHttpsPort > 0 { var l frpNet.Listener - l, err = frpNet.ListenTcp(config.ServerCommonCfg.BindAddr, config.ServerCommonCfg.VhostHttpsPort) + l, err = frpNet.ListenTcp(config.ServerCommonCfg.ProxyBindAddr, config.ServerCommonCfg.VhostHttpsPort) if err != nil { err = fmt.Errorf("Create vhost https listener error, %v", err) return @@ -121,7 +121,7 @@ func NewService() (svr *Service, err error) { err = fmt.Errorf("Create vhost httpsMuxer error, %v", err) return } - log.Info("https service listen on %s:%d", config.ServerCommonCfg.BindAddr, config.ServerCommonCfg.VhostHttpsPort) + log.Info("https service listen on %s:%d", config.ServerCommonCfg.ProxyBindAddr, config.ServerCommonCfg.VhostHttpsPort) } // Create dashboard web server.