[ADDED] 增加remote_addr 客户端指定监听地址
This commit is contained in:
parent
7ebcc7503a
commit
9e28fd248c
@ -94,6 +94,7 @@ type BaseProxyConf struct {
|
|||||||
|
|
||||||
UseEncryption bool `json:"use_encryption"`
|
UseEncryption bool `json:"use_encryption"`
|
||||||
UseCompression bool `json:"use_compression"`
|
UseCompression bool `json:"use_compression"`
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *BaseProxyConf) GetName() string {
|
func (cfg *BaseProxyConf) GetName() string {
|
||||||
@ -140,16 +141,22 @@ func (cfg *BaseProxyConf) UnMarshalToMsg(pMsg *msg.NewProxy) {
|
|||||||
pMsg.ProxyType = cfg.ProxyType
|
pMsg.ProxyType = cfg.ProxyType
|
||||||
pMsg.UseEncryption = cfg.UseEncryption
|
pMsg.UseEncryption = cfg.UseEncryption
|
||||||
pMsg.UseCompression = cfg.UseCompression
|
pMsg.UseCompression = cfg.UseCompression
|
||||||
|
//pMsg.RemoteAddr = cfg.RemoteAddr
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind info
|
// Bind info
|
||||||
type BindInfoConf struct {
|
type BindInfoConf struct {
|
||||||
BindAddr string `json:"bind_addr"`
|
BindAddr string `json:"bind_addr"`
|
||||||
RemotePort int64 `json:"remote_port"`
|
RemotePort int64 `json:"remote_port"`
|
||||||
|
RemoteAddr string `json:"remote_addr"`
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *BindInfoConf) LoadFromMsg(pMsg *msg.NewProxy) {
|
func (cfg *BindInfoConf) LoadFromMsg(pMsg *msg.NewProxy) {
|
||||||
|
|
||||||
cfg.BindAddr = ServerCommonCfg.BindAddr
|
cfg.BindAddr = ServerCommonCfg.BindAddr
|
||||||
|
cfg.RemoteAddr = pMsg.RemoteAddr
|
||||||
cfg.RemotePort = pMsg.RemotePort
|
cfg.RemotePort = pMsg.RemotePort
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,6 +165,14 @@ func (cfg *BindInfoConf) LoadFromFile(name string, section ini.Section) (err err
|
|||||||
tmpStr string
|
tmpStr string
|
||||||
ok bool
|
ok bool
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if tmpStr, ok = section["remote_addr"]; ok {
|
||||||
|
cfg.RemoteAddr = tmpStr
|
||||||
|
} else {
|
||||||
|
cfg.RemoteAddr = ""
|
||||||
|
}
|
||||||
|
|
||||||
if tmpStr, ok = section["remote_port"]; ok {
|
if tmpStr, ok = section["remote_port"]; ok {
|
||||||
if cfg.RemotePort, err = strconv.ParseInt(tmpStr, 10, 64); err != nil {
|
if cfg.RemotePort, err = strconv.ParseInt(tmpStr, 10, 64); err != nil {
|
||||||
return fmt.Errorf("Parse conf error: proxy [%s] remote_port error", name)
|
return fmt.Errorf("Parse conf error: proxy [%s] remote_port error", name)
|
||||||
@ -170,6 +185,7 @@ func (cfg *BindInfoConf) LoadFromFile(name string, section ini.Section) (err err
|
|||||||
|
|
||||||
func (cfg *BindInfoConf) UnMarshalToMsg(pMsg *msg.NewProxy) {
|
func (cfg *BindInfoConf) UnMarshalToMsg(pMsg *msg.NewProxy) {
|
||||||
pMsg.RemotePort = cfg.RemotePort
|
pMsg.RemotePort = cfg.RemotePort
|
||||||
|
pMsg.RemoteAddr = cfg.RemoteAddr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *BindInfoConf) check() (err error) {
|
func (cfg *BindInfoConf) check() (err error) {
|
||||||
|
@ -90,7 +90,8 @@ type NewProxy struct {
|
|||||||
|
|
||||||
// tcp and udp only
|
// tcp and udp only
|
||||||
RemotePort int64 `json:"remote_port"`
|
RemotePort int64 `json:"remote_port"`
|
||||||
|
RemoteAddr string `json:"remote_addr"`
|
||||||
|
|
||||||
// http and https only
|
// http and https only
|
||||||
CustomDomains []string `json:"custom_domains"`
|
CustomDomains []string `json:"custom_domains"`
|
||||||
SubDomain string `json:"subdomain"`
|
SubDomain string `json:"subdomain"`
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"golang.org/x/net/context"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
@ -156,13 +156,13 @@ type TcpProxy struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pxy *TcpProxy) Run() error {
|
func (pxy *TcpProxy) Run() error {
|
||||||
listener, err := frpNet.ListenTcp(config.ServerCommonCfg.BindAddr, pxy.cfg.RemotePort)
|
listener, err := frpNet.ListenTcp(pxy.cfg.RemoteAddr, pxy.cfg.RemotePort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
listener.AddLogPrefix(pxy.name)
|
listener.AddLogPrefix(pxy.name)
|
||||||
pxy.listeners = append(pxy.listeners, listener)
|
pxy.listeners = append(pxy.listeners, listener)
|
||||||
pxy.Info("tcp proxy listen port [%d]", pxy.cfg.RemotePort)
|
pxy.Info("tcp proxy listen host:port [%s:%d]", pxy.cfg.RemoteAddr,pxy.cfg.RemotePort)
|
||||||
|
|
||||||
pxy.startListenHandler(pxy, HandleUserTcpConnection)
|
pxy.startListenHandler(pxy, HandleUserTcpConnection)
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user