mirror of
https://github.com/fatedier/frp.git
synced 2026-07-23 11:09:18 +08:00
Compare commits
2 Commits
cf396563f8
...
copilot/re
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7993225be1 | ||
|
|
17b27d8d96 |
@@ -16,7 +16,6 @@ package proxy
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
@@ -123,33 +122,6 @@ func (pxy *BaseProxy) Close() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// wrapWorkConn applies rate limiting, encryption, and compression
|
|
||||||
// to a work connection based on the proxy's transport configuration.
|
|
||||||
// The returned recycle function should be called when the stream is no longer in use
|
|
||||||
// to return compression resources to the pool. It is safe to not call recycle,
|
|
||||||
// in which case resources will be garbage collected normally.
|
|
||||||
func (pxy *BaseProxy) wrapWorkConn(conn net.Conn, encKey []byte) (io.ReadWriteCloser, func(), error) {
|
|
||||||
var rwc io.ReadWriteCloser = conn
|
|
||||||
if pxy.limiter != nil {
|
|
||||||
rwc = libio.WrapReadWriteCloser(limit.NewReader(conn, pxy.limiter), limit.NewWriter(conn, pxy.limiter), func() error {
|
|
||||||
return conn.Close()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if pxy.baseCfg.Transport.UseEncryption {
|
|
||||||
var err error
|
|
||||||
rwc, err = libio.WithEncryption(rwc, encKey)
|
|
||||||
if err != nil {
|
|
||||||
conn.Close()
|
|
||||||
return nil, nil, fmt.Errorf("create encryption stream error: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var recycleFn func()
|
|
||||||
if pxy.baseCfg.Transport.UseCompression {
|
|
||||||
rwc, recycleFn = libio.WithCompressionFromPool(rwc)
|
|
||||||
}
|
|
||||||
return rwc, recycleFn, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pxy *BaseProxy) SetInWorkConnCallback(cb func(*v1.ProxyBaseConfig, net.Conn, *msg.StartWorkConn) bool) {
|
func (pxy *BaseProxy) SetInWorkConnCallback(cb func(*v1.ProxyBaseConfig, net.Conn, *msg.StartWorkConn) bool) {
|
||||||
pxy.inWorkConnCallback = cb
|
pxy.inWorkConnCallback = cb
|
||||||
}
|
}
|
||||||
@@ -167,14 +139,30 @@ func (pxy *BaseProxy) InWorkConn(conn net.Conn, m *msg.StartWorkConn) {
|
|||||||
func (pxy *BaseProxy) HandleTCPWorkConnection(workConn net.Conn, m *msg.StartWorkConn, encKey []byte) {
|
func (pxy *BaseProxy) HandleTCPWorkConnection(workConn net.Conn, m *msg.StartWorkConn, encKey []byte) {
|
||||||
xl := pxy.xl
|
xl := pxy.xl
|
||||||
baseCfg := pxy.baseCfg
|
baseCfg := pxy.baseCfg
|
||||||
|
var (
|
||||||
|
remote io.ReadWriteCloser
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
remote = workConn
|
||||||
|
if pxy.limiter != nil {
|
||||||
|
remote = libio.WrapReadWriteCloser(limit.NewReader(workConn, pxy.limiter), limit.NewWriter(workConn, pxy.limiter), func() error {
|
||||||
|
return workConn.Close()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
xl.Tracef("handle tcp work connection, useEncryption: %t, useCompression: %t",
|
xl.Tracef("handle tcp work connection, useEncryption: %t, useCompression: %t",
|
||||||
baseCfg.Transport.UseEncryption, baseCfg.Transport.UseCompression)
|
baseCfg.Transport.UseEncryption, baseCfg.Transport.UseCompression)
|
||||||
|
if baseCfg.Transport.UseEncryption {
|
||||||
remote, recycleFn, err := pxy.wrapWorkConn(workConn, encKey)
|
remote, err = libio.WithEncryption(remote, encKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
xl.Errorf("wrap work connection: %v", err)
|
workConn.Close()
|
||||||
return
|
xl.Errorf("create encryption stream error: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var compressionResourceRecycleFn func()
|
||||||
|
if baseCfg.Transport.UseCompression {
|
||||||
|
remote, compressionResourceRecycleFn = libio.WithCompressionFromPool(remote)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if we need to send proxy protocol info
|
// check if we need to send proxy protocol info
|
||||||
@@ -190,6 +178,7 @@ func (pxy *BaseProxy) HandleTCPWorkConnection(workConn net.Conn, m *msg.StartWor
|
|||||||
}
|
}
|
||||||
|
|
||||||
if baseCfg.Transport.ProxyProtocolVersion != "" && m.SrcAddr != "" && m.SrcPort != 0 {
|
if baseCfg.Transport.ProxyProtocolVersion != "" && m.SrcAddr != "" && m.SrcPort != 0 {
|
||||||
|
// Use the common proxy protocol builder function
|
||||||
header := netpkg.BuildProxyProtocolHeaderStruct(connInfo.SrcAddr, connInfo.DstAddr, baseCfg.Transport.ProxyProtocolVersion)
|
header := netpkg.BuildProxyProtocolHeaderStruct(connInfo.SrcAddr, connInfo.DstAddr, baseCfg.Transport.ProxyProtocolVersion)
|
||||||
connInfo.ProxyProtocolHeader = header
|
connInfo.ProxyProtocolHeader = header
|
||||||
}
|
}
|
||||||
@@ -198,18 +187,12 @@ func (pxy *BaseProxy) HandleTCPWorkConnection(workConn net.Conn, m *msg.StartWor
|
|||||||
|
|
||||||
if pxy.proxyPlugin != nil {
|
if pxy.proxyPlugin != nil {
|
||||||
// if plugin is set, let plugin handle connection first
|
// if plugin is set, let plugin handle connection first
|
||||||
// Don't recycle compression resources here because plugins may
|
|
||||||
// retain the connection after Handle returns.
|
|
||||||
xl.Debugf("handle by plugin: %s", pxy.proxyPlugin.Name())
|
xl.Debugf("handle by plugin: %s", pxy.proxyPlugin.Name())
|
||||||
pxy.proxyPlugin.Handle(pxy.ctx, &connInfo)
|
pxy.proxyPlugin.Handle(pxy.ctx, &connInfo)
|
||||||
xl.Debugf("handle by plugin finished")
|
xl.Debugf("handle by plugin finished")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if recycleFn != nil {
|
|
||||||
defer recycleFn()
|
|
||||||
}
|
|
||||||
|
|
||||||
localConn, err := libnet.Dial(
|
localConn, err := libnet.Dial(
|
||||||
net.JoinHostPort(baseCfg.LocalIP, strconv.Itoa(baseCfg.LocalPort)),
|
net.JoinHostPort(baseCfg.LocalIP, strconv.Itoa(baseCfg.LocalPort)),
|
||||||
libnet.WithTimeout(10*time.Second),
|
libnet.WithTimeout(10*time.Second),
|
||||||
@@ -226,7 +209,6 @@ func (pxy *BaseProxy) HandleTCPWorkConnection(workConn net.Conn, m *msg.StartWor
|
|||||||
if connInfo.ProxyProtocolHeader != nil {
|
if connInfo.ProxyProtocolHeader != nil {
|
||||||
if _, err := connInfo.ProxyProtocolHeader.WriteTo(localConn); err != nil {
|
if _, err := connInfo.ProxyProtocolHeader.WriteTo(localConn); err != nil {
|
||||||
workConn.Close()
|
workConn.Close()
|
||||||
localConn.Close()
|
|
||||||
xl.Errorf("write proxy protocol header to local conn error: %v", err)
|
xl.Errorf("write proxy protocol header to local conn error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -237,4 +219,7 @@ func (pxy *BaseProxy) HandleTCPWorkConnection(workConn net.Conn, m *msg.StartWor
|
|||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
xl.Tracef("join connections errors: %v", errs)
|
xl.Tracef("join connections errors: %v", errs)
|
||||||
}
|
}
|
||||||
|
if compressionResourceRecycleFn != nil {
|
||||||
|
compressionResourceRecycleFn()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package proxy
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -24,10 +25,12 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/fatedier/golib/errors"
|
"github.com/fatedier/golib/errors"
|
||||||
|
libio "github.com/fatedier/golib/io"
|
||||||
|
|
||||||
v1 "github.com/fatedier/frp/pkg/config/v1"
|
v1 "github.com/fatedier/frp/pkg/config/v1"
|
||||||
"github.com/fatedier/frp/pkg/msg"
|
"github.com/fatedier/frp/pkg/msg"
|
||||||
"github.com/fatedier/frp/pkg/proto/udp"
|
"github.com/fatedier/frp/pkg/proto/udp"
|
||||||
|
"github.com/fatedier/frp/pkg/util/limit"
|
||||||
netpkg "github.com/fatedier/frp/pkg/util/net"
|
netpkg "github.com/fatedier/frp/pkg/util/net"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -80,13 +83,27 @@ func (pxy *SUDPProxy) InWorkConn(conn net.Conn, _ *msg.StartWorkConn) {
|
|||||||
xl := pxy.xl
|
xl := pxy.xl
|
||||||
xl.Infof("incoming a new work connection for sudp proxy, %s", conn.RemoteAddr().String())
|
xl.Infof("incoming a new work connection for sudp proxy, %s", conn.RemoteAddr().String())
|
||||||
|
|
||||||
remote, _, err := pxy.wrapWorkConn(conn, pxy.encryptionKey)
|
var rwc io.ReadWriteCloser = conn
|
||||||
if err != nil {
|
var err error
|
||||||
xl.Errorf("wrap work connection: %v", err)
|
if pxy.limiter != nil {
|
||||||
return
|
rwc = libio.WrapReadWriteCloser(limit.NewReader(conn, pxy.limiter), limit.NewWriter(conn, pxy.limiter), func() error {
|
||||||
|
return conn.Close()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
if pxy.cfg.Transport.UseEncryption {
|
||||||
|
rwc, err = libio.WithEncryption(rwc, pxy.encryptionKey)
|
||||||
|
if err != nil {
|
||||||
|
conn.Close()
|
||||||
|
xl.Errorf("create encryption stream error: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if pxy.cfg.Transport.UseCompression {
|
||||||
|
rwc = libio.WithCompression(rwc)
|
||||||
|
}
|
||||||
|
conn = netpkg.WrapReadWriteCloserToConn(rwc, conn)
|
||||||
|
|
||||||
workConn := netpkg.WrapReadWriteCloserToConn(remote, conn)
|
workConn := conn
|
||||||
readCh := make(chan *msg.UDPPacket, 1024)
|
readCh := make(chan *msg.UDPPacket, 1024)
|
||||||
sendCh := make(chan msg.Message, 1024)
|
sendCh := make(chan msg.Message, 1024)
|
||||||
isClose := false
|
isClose := false
|
||||||
|
|||||||
@@ -17,16 +17,19 @@
|
|||||||
package proxy
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/fatedier/golib/errors"
|
"github.com/fatedier/golib/errors"
|
||||||
|
libio "github.com/fatedier/golib/io"
|
||||||
|
|
||||||
v1 "github.com/fatedier/frp/pkg/config/v1"
|
v1 "github.com/fatedier/frp/pkg/config/v1"
|
||||||
"github.com/fatedier/frp/pkg/msg"
|
"github.com/fatedier/frp/pkg/msg"
|
||||||
"github.com/fatedier/frp/pkg/proto/udp"
|
"github.com/fatedier/frp/pkg/proto/udp"
|
||||||
|
"github.com/fatedier/frp/pkg/util/limit"
|
||||||
netpkg "github.com/fatedier/frp/pkg/util/net"
|
netpkg "github.com/fatedier/frp/pkg/util/net"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -91,14 +94,28 @@ func (pxy *UDPProxy) InWorkConn(conn net.Conn, _ *msg.StartWorkConn) {
|
|||||||
// close resources related with old workConn
|
// close resources related with old workConn
|
||||||
pxy.Close()
|
pxy.Close()
|
||||||
|
|
||||||
remote, _, err := pxy.wrapWorkConn(conn, pxy.encryptionKey)
|
var rwc io.ReadWriteCloser = conn
|
||||||
if err != nil {
|
var err error
|
||||||
xl.Errorf("wrap work connection: %v", err)
|
if pxy.limiter != nil {
|
||||||
return
|
rwc = libio.WrapReadWriteCloser(limit.NewReader(conn, pxy.limiter), limit.NewWriter(conn, pxy.limiter), func() error {
|
||||||
|
return conn.Close()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
if pxy.cfg.Transport.UseEncryption {
|
||||||
|
rwc, err = libio.WithEncryption(rwc, pxy.encryptionKey)
|
||||||
|
if err != nil {
|
||||||
|
conn.Close()
|
||||||
|
xl.Errorf("create encryption stream error: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if pxy.cfg.Transport.UseCompression {
|
||||||
|
rwc = libio.WithCompression(rwc)
|
||||||
|
}
|
||||||
|
conn = netpkg.WrapReadWriteCloserToConn(rwc, conn)
|
||||||
|
|
||||||
pxy.mu.Lock()
|
pxy.mu.Lock()
|
||||||
pxy.workConn = netpkg.WrapReadWriteCloserToConn(remote, conn)
|
pxy.workConn = conn
|
||||||
pxy.readCh = make(chan *msg.UDPPacket, 1024)
|
pxy.readCh = make(chan *msg.UDPPacket, 1024)
|
||||||
pxy.sendCh = make(chan msg.Message, 1024)
|
pxy.sendCh = make(chan msg.Message, 1024)
|
||||||
pxy.closed = false
|
pxy.closed = false
|
||||||
|
|||||||
@@ -217,7 +217,6 @@ func (sv *SUDPVisitor) getNewVisitorConn() (net.Conn, error) {
|
|||||||
}
|
}
|
||||||
err = msg.WriteMsg(visitorConn, newVisitorConnMsg)
|
err = msg.WriteMsg(visitorConn, newVisitorConnMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
visitorConn.Close()
|
|
||||||
return nil, fmt.Errorf("frpc send newVisitorConnMsg to frps error: %v", err)
|
return nil, fmt.Errorf("frpc send newVisitorConnMsg to frps error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,13 +224,11 @@ func (sv *SUDPVisitor) getNewVisitorConn() (net.Conn, error) {
|
|||||||
_ = visitorConn.SetReadDeadline(time.Now().Add(10 * time.Second))
|
_ = visitorConn.SetReadDeadline(time.Now().Add(10 * time.Second))
|
||||||
err = msg.ReadMsgInto(visitorConn, &newVisitorConnRespMsg)
|
err = msg.ReadMsgInto(visitorConn, &newVisitorConnRespMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
visitorConn.Close()
|
|
||||||
return nil, fmt.Errorf("frpc read newVisitorConnRespMsg error: %v", err)
|
return nil, fmt.Errorf("frpc read newVisitorConnRespMsg error: %v", err)
|
||||||
}
|
}
|
||||||
_ = visitorConn.SetReadDeadline(time.Time{})
|
_ = visitorConn.SetReadDeadline(time.Time{})
|
||||||
|
|
||||||
if newVisitorConnRespMsg.Error != "" {
|
if newVisitorConnRespMsg.Error != "" {
|
||||||
visitorConn.Close()
|
|
||||||
return nil, fmt.Errorf("start new visitor connection error: %s", newVisitorConnRespMsg.Error)
|
return nil, fmt.Errorf("start new visitor connection error: %s", newVisitorConnRespMsg.Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,7 +238,6 @@ func (sv *SUDPVisitor) getNewVisitorConn() (net.Conn, error) {
|
|||||||
remote, err = libio.WithEncryption(remote, []byte(sv.cfg.SecretKey))
|
remote, err = libio.WithEncryption(remote, []byte(sv.cfg.SecretKey))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
xl.Errorf("create encryption stream error: %v", err)
|
xl.Errorf("create encryption stream error: %v", err)
|
||||||
visitorConn.Close()
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -211,7 +211,6 @@ func (sv *XTCPVisitor) handleConn(userConn net.Conn) {
|
|||||||
muxConnRWCloser, err = libio.WithEncryption(muxConnRWCloser, []byte(sv.cfg.SecretKey))
|
muxConnRWCloser, err = libio.WithEncryption(muxConnRWCloser, []byte(sv.cfg.SecretKey))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
xl.Errorf("create encryption stream error: %v", err)
|
xl.Errorf("create encryption stream error: %v", err)
|
||||||
tunnelConn.Close()
|
|
||||||
tunnelErr = err
|
tunnelErr = err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -374,7 +373,6 @@ func (ks *KCPTunnelSession) Init(listenConn *net.UDPConn, raddr *net.UDPAddr) er
|
|||||||
}
|
}
|
||||||
remote, err := netpkg.NewKCPConnFromUDP(lConn, true, raddr.String())
|
remote, err := netpkg.NewKCPConnFromUDP(lConn, true, raddr.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lConn.Close()
|
|
||||||
return fmt.Errorf("create kcp connection from udp connection error: %v", err)
|
return fmt.Errorf("create kcp connection from udp connection error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"slices"
|
"slices"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/coreos/go-oidc/v3/oidc"
|
"github.com/coreos/go-oidc/v3/oidc"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
@@ -206,8 +205,7 @@ type OidcAuthConsumer struct {
|
|||||||
additionalAuthScopes []v1.AuthScope
|
additionalAuthScopes []v1.AuthScope
|
||||||
|
|
||||||
verifier TokenVerifier
|
verifier TokenVerifier
|
||||||
mu sync.RWMutex
|
subjectsFromLogin []string
|
||||||
subjectsFromLogin map[string]struct{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTokenVerifier(cfg v1.AuthOIDCServerConfig) TokenVerifier {
|
func NewTokenVerifier(cfg v1.AuthOIDCServerConfig) TokenVerifier {
|
||||||
@@ -228,7 +226,7 @@ func NewOidcAuthVerifier(additionalAuthScopes []v1.AuthScope, verifier TokenVeri
|
|||||||
return &OidcAuthConsumer{
|
return &OidcAuthConsumer{
|
||||||
additionalAuthScopes: additionalAuthScopes,
|
additionalAuthScopes: additionalAuthScopes,
|
||||||
verifier: verifier,
|
verifier: verifier,
|
||||||
subjectsFromLogin: make(map[string]struct{}),
|
subjectsFromLogin: []string{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,9 +235,9 @@ func (auth *OidcAuthConsumer) VerifyLogin(loginMsg *msg.Login) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid OIDC token in login: %v", err)
|
return fmt.Errorf("invalid OIDC token in login: %v", err)
|
||||||
}
|
}
|
||||||
auth.mu.Lock()
|
if !slices.Contains(auth.subjectsFromLogin, token.Subject) {
|
||||||
auth.subjectsFromLogin[token.Subject] = struct{}{}
|
auth.subjectsFromLogin = append(auth.subjectsFromLogin, token.Subject)
|
||||||
auth.mu.Unlock()
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,13 +246,11 @@ func (auth *OidcAuthConsumer) verifyPostLoginToken(privilegeKey string) (err err
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid OIDC token in ping: %v", err)
|
return fmt.Errorf("invalid OIDC token in ping: %v", err)
|
||||||
}
|
}
|
||||||
auth.mu.RLock()
|
if !slices.Contains(auth.subjectsFromLogin, token.Subject) {
|
||||||
_, ok := auth.subjectsFromLogin[token.Subject]
|
|
||||||
auth.mu.RUnlock()
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("received different OIDC subject in login and ping. "+
|
return fmt.Errorf("received different OIDC subject in login and ping. "+
|
||||||
|
"original subjects: %s, "+
|
||||||
"new subject: %s",
|
"new subject: %s",
|
||||||
token.Subject)
|
auth.subjectsFromLogin, token.Subject)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,14 +171,15 @@ func Convert_ServerCommonConf_To_v1(conf *ServerCommonConf) *v1.ServerConfig {
|
|||||||
func transformHeadersFromPluginParams(params map[string]string) v1.HeaderOperations {
|
func transformHeadersFromPluginParams(params map[string]string) v1.HeaderOperations {
|
||||||
out := v1.HeaderOperations{}
|
out := v1.HeaderOperations{}
|
||||||
for k, v := range params {
|
for k, v := range params {
|
||||||
k, ok := strings.CutPrefix(k, "plugin_header_")
|
if !strings.HasPrefix(k, "plugin_header_") {
|
||||||
if !ok || k == "" {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if out.Set == nil {
|
if k = strings.TrimPrefix(k, "plugin_header_"); k != "" {
|
||||||
out.Set = make(map[string]string)
|
if out.Set == nil {
|
||||||
|
out.Set = make(map[string]string)
|
||||||
|
}
|
||||||
|
out.Set[k] = v
|
||||||
}
|
}
|
||||||
out.Set[k] = v
|
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ func GetMapWithoutPrefix(set map[string]string, prefix string) map[string]string
|
|||||||
m := make(map[string]string)
|
m := make(map[string]string)
|
||||||
|
|
||||||
for key, value := range set {
|
for key, value := range set {
|
||||||
if trimmed, ok := strings.CutPrefix(key, prefix); ok {
|
if strings.HasPrefix(key, prefix) {
|
||||||
m[trimmed] = value
|
m[strings.TrimPrefix(key, prefix)] = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,11 +15,9 @@
|
|||||||
package source
|
package source
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cmp"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"maps"
|
"sort"
|
||||||
"slices"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
v1 "github.com/fatedier/frp/pkg/config/v1"
|
v1 "github.com/fatedier/frp/pkg/config/v1"
|
||||||
@@ -99,11 +97,21 @@ func (a *Aggregator) mapsToSortedSlices(
|
|||||||
proxyMap map[string]v1.ProxyConfigurer,
|
proxyMap map[string]v1.ProxyConfigurer,
|
||||||
visitorMap map[string]v1.VisitorConfigurer,
|
visitorMap map[string]v1.VisitorConfigurer,
|
||||||
) ([]v1.ProxyConfigurer, []v1.VisitorConfigurer) {
|
) ([]v1.ProxyConfigurer, []v1.VisitorConfigurer) {
|
||||||
proxies := slices.SortedFunc(maps.Values(proxyMap), func(x, y v1.ProxyConfigurer) int {
|
proxies := make([]v1.ProxyConfigurer, 0, len(proxyMap))
|
||||||
return cmp.Compare(x.GetBaseConfig().Name, y.GetBaseConfig().Name)
|
for _, p := range proxyMap {
|
||||||
|
proxies = append(proxies, p)
|
||||||
|
}
|
||||||
|
sort.Slice(proxies, func(i, j int) bool {
|
||||||
|
return proxies[i].GetBaseConfig().Name < proxies[j].GetBaseConfig().Name
|
||||||
})
|
})
|
||||||
visitors := slices.SortedFunc(maps.Values(visitorMap), func(x, y v1.VisitorConfigurer) int {
|
|
||||||
return cmp.Compare(x.GetBaseConfig().Name, y.GetBaseConfig().Name)
|
visitors := make([]v1.VisitorConfigurer, 0, len(visitorMap))
|
||||||
|
for _, v := range visitorMap {
|
||||||
|
visitors = append(visitors, v)
|
||||||
|
}
|
||||||
|
sort.Slice(visitors, func(i, j int) bool {
|
||||||
|
return visitors[i].GetBaseConfig().Name < visitors[j].GetBaseConfig().Name
|
||||||
})
|
})
|
||||||
|
|
||||||
return proxies, visitors
|
return proxies, visitors
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -196,27 +196,6 @@ func TestAggregator_VisitorMerge(t *testing.T) {
|
|||||||
require.Len(visitors, 2)
|
require.Len(visitors, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAggregator_Load_ReturnsSortedByName(t *testing.T) {
|
|
||||||
require := require.New(t)
|
|
||||||
|
|
||||||
agg := newTestAggregator(t, nil)
|
|
||||||
err := agg.ConfigSource().ReplaceAll(
|
|
||||||
[]v1.ProxyConfigurer{mockProxy("charlie"), mockProxy("alice"), mockProxy("bob")},
|
|
||||||
[]v1.VisitorConfigurer{mockVisitor("zulu"), mockVisitor("alpha")},
|
|
||||||
)
|
|
||||||
require.NoError(err)
|
|
||||||
|
|
||||||
proxies, visitors, err := agg.Load()
|
|
||||||
require.NoError(err)
|
|
||||||
require.Len(proxies, 3)
|
|
||||||
require.Equal("alice", proxies[0].GetBaseConfig().Name)
|
|
||||||
require.Equal("bob", proxies[1].GetBaseConfig().Name)
|
|
||||||
require.Equal("charlie", proxies[2].GetBaseConfig().Name)
|
|
||||||
require.Len(visitors, 2)
|
|
||||||
require.Equal("alpha", visitors[0].GetBaseConfig().Name)
|
|
||||||
require.Equal("zulu", visitors[1].GetBaseConfig().Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAggregator_Load_ReturnsDefensiveCopies(t *testing.T) {
|
func TestAggregator_Load_ReturnsDefensiveCopies(t *testing.T) {
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
|
|
||||||
|
|||||||
@@ -70,18 +70,24 @@ func (q *BandwidthQuantity) UnmarshalString(s string) error {
|
|||||||
f float64
|
f float64
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
if fstr, ok := strings.CutSuffix(s, "MB"); ok {
|
switch {
|
||||||
|
case strings.HasSuffix(s, "MB"):
|
||||||
base = MB
|
base = MB
|
||||||
|
fstr := strings.TrimSuffix(s, "MB")
|
||||||
f, err = strconv.ParseFloat(fstr, 64)
|
f, err = strconv.ParseFloat(fstr, 64)
|
||||||
} else if fstr, ok := strings.CutSuffix(s, "KB"); ok {
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case strings.HasSuffix(s, "KB"):
|
||||||
base = KB
|
base = KB
|
||||||
|
fstr := strings.TrimSuffix(s, "KB")
|
||||||
f, err = strconv.ParseFloat(fstr, 64)
|
f, err = strconv.ParseFloat(fstr, 64)
|
||||||
} else {
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
default:
|
||||||
return errors.New("unit not support")
|
return errors.New("unit not support")
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
q.s = s
|
q.s = s
|
||||||
q.i = int64(f * float64(base))
|
q.i = int64(f * float64(base))
|
||||||
|
|||||||
@@ -39,31 +39,6 @@ func TestBandwidthQuantity(t *testing.T) {
|
|||||||
require.Equal(`{"b":"1KB","int":5}`, string(buf))
|
require.Equal(`{"b":"1KB","int":5}`, string(buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBandwidthQuantity_MB(t *testing.T) {
|
|
||||||
require := require.New(t)
|
|
||||||
|
|
||||||
var w Wrap
|
|
||||||
err := json.Unmarshal([]byte(`{"b":"2MB","int":1}`), &w)
|
|
||||||
require.NoError(err)
|
|
||||||
require.EqualValues(2*MB, w.B.Bytes())
|
|
||||||
|
|
||||||
buf, err := json.Marshal(&w)
|
|
||||||
require.NoError(err)
|
|
||||||
require.Equal(`{"b":"2MB","int":1}`, string(buf))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBandwidthQuantity_InvalidUnit(t *testing.T) {
|
|
||||||
var w Wrap
|
|
||||||
err := json.Unmarshal([]byte(`{"b":"1GB","int":1}`), &w)
|
|
||||||
require.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBandwidthQuantity_InvalidNumber(t *testing.T) {
|
|
||||||
var w Wrap
|
|
||||||
err := json.Unmarshal([]byte(`{"b":"abcKB","int":1}`), &w)
|
|
||||||
require.Error(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPortsRangeSlice2String(t *testing.T) {
|
func TestPortsRangeSlice2String(t *testing.T) {
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,9 @@ func StripUserPrefix(user, name string) string {
|
|||||||
if user == "" {
|
if user == "" {
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
if trimmed, ok := strings.CutPrefix(name, user+"."); ok {
|
prefix := user + "."
|
||||||
return trimmed
|
if strings.HasPrefix(name, prefix) {
|
||||||
|
return strings.TrimPrefix(name, prefix)
|
||||||
}
|
}
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,8 +70,12 @@ func ClassifyNATFeature(addresses []string, localIPs []string) (*NatFeature, err
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
portMax = max(portMax, portNum)
|
if portNum > portMax {
|
||||||
portMin = min(portMin, portNum)
|
portMax = portNum
|
||||||
|
}
|
||||||
|
if portNum < portMin {
|
||||||
|
portMin = portNum
|
||||||
|
}
|
||||||
if baseIP != ip {
|
if baseIP != ip {
|
||||||
ipChanged = true
|
ipChanged = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -298,13 +298,11 @@ func waitDetectMessage(
|
|||||||
n, raddr, err := conn.ReadFromUDP(buf)
|
n, raddr, err := conn.ReadFromUDP(buf)
|
||||||
_ = conn.SetReadDeadline(time.Time{})
|
_ = conn.SetReadDeadline(time.Time{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
pool.PutBuf(buf)
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
xl.Debugf("get udp message local %s, from %s", conn.LocalAddr(), raddr)
|
xl.Debugf("get udp message local %s, from %s", conn.LocalAddr(), raddr)
|
||||||
var m msg.NatHoleSid
|
var m msg.NatHoleSid
|
||||||
if err := DecodeMessageInto(buf[:n], key, &m); err != nil {
|
if err := DecodeMessageInto(buf[:n], key, &m); err != nil {
|
||||||
pool.PutBuf(buf)
|
|
||||||
xl.Warnf("decode sid message error: %v", err)
|
xl.Warnf("decode sid message error: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import (
|
|||||||
stdlog "log"
|
stdlog "log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/fatedier/golib/pool"
|
"github.com/fatedier/golib/pool"
|
||||||
|
|
||||||
@@ -69,7 +68,7 @@ func NewHTTP2HTTPPlugin(_ PluginContext, options v1.ClientPluginOptions) (Plugin
|
|||||||
|
|
||||||
p.s = &http.Server{
|
p.s = &http.Server{
|
||||||
Handler: rp,
|
Handler: rp,
|
||||||
ReadHeaderTimeout: 60 * time.Second,
|
ReadHeaderTimeout: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import (
|
|||||||
stdlog "log"
|
stdlog "log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/fatedier/golib/pool"
|
"github.com/fatedier/golib/pool"
|
||||||
|
|
||||||
@@ -78,7 +77,7 @@ func NewHTTP2HTTPSPlugin(_ PluginContext, options v1.ClientPluginOptions) (Plugi
|
|||||||
|
|
||||||
p.s = &http.Server{
|
p.s = &http.Server{
|
||||||
Handler: rp,
|
Handler: rp,
|
||||||
ReadHeaderTimeout: 60 * time.Second,
|
ReadHeaderTimeout: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
|||||||
@@ -62,13 +62,11 @@ func (p *TLS2RawPlugin) Handle(ctx context.Context, connInfo *ConnectionInfo) {
|
|||||||
|
|
||||||
if err := tlsConn.Handshake(); err != nil {
|
if err := tlsConn.Handshake(); err != nil {
|
||||||
xl.Warnf("tls handshake error: %v", err)
|
xl.Warnf("tls handshake error: %v", err)
|
||||||
tlsConn.Close()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rawConn, err := net.Dial("tcp", p.opts.LocalAddr)
|
rawConn, err := net.Dial("tcp", p.opts.LocalAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
xl.Warnf("dial to local addr error: %v", err)
|
xl.Warnf("dial to local addr error: %v", err)
|
||||||
tlsConn.Close()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,13 +54,10 @@ func (uds *UnixDomainSocketPlugin) Handle(ctx context.Context, connInfo *Connect
|
|||||||
localConn, err := net.DialUnix("unix", nil, uds.UnixAddr)
|
localConn, err := net.DialUnix("unix", nil, uds.UnixAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
xl.Warnf("dial to uds %s error: %v", uds.UnixAddr, err)
|
xl.Warnf("dial to uds %s error: %v", uds.UnixAddr, err)
|
||||||
connInfo.Conn.Close()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if connInfo.ProxyProtocolHeader != nil {
|
if connInfo.ProxyProtocolHeader != nil {
|
||||||
if _, err := connInfo.ProxyProtocolHeader.WriteTo(localConn); err != nil {
|
if _, err := connInfo.ProxyProtocolHeader.WriteTo(localConn); err != nil {
|
||||||
localConn.Close()
|
|
||||||
connInfo.Conn.Close()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
"slices"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
v1 "github.com/fatedier/frp/pkg/config/v1"
|
v1 "github.com/fatedier/frp/pkg/config/v1"
|
||||||
@@ -65,7 +64,12 @@ func (p *httpPlugin) Name() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *httpPlugin) IsSupport(op string) bool {
|
func (p *httpPlugin) IsSupport(op string) bool {
|
||||||
return slices.Contains(p.options.Ops, op)
|
for _, v := range p.options.Ops {
|
||||||
|
if v == op {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *httpPlugin) Handle(ctx context.Context, op string, content any) (*Response, any, error) {
|
func (p *httpPlugin) Handle(ctx context.Context, op string, content any) (*Response, any, error) {
|
||||||
|
|||||||
@@ -85,7 +85,6 @@ func Forwarder(dstAddr *net.UDPAddr, readCh <-chan *msg.UDPPacket, sendCh chan<-
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
buf := pool.GetBuf(bufSize)
|
buf := pool.GetBuf(bufSize)
|
||||||
defer pool.PutBuf(buf)
|
|
||||||
for {
|
for {
|
||||||
_ = udpConn.SetReadDeadline(time.Now().Add(30 * time.Second))
|
_ = udpConn.SetReadDeadline(time.Now().Add(30 * time.Second))
|
||||||
n, _, err := udpConn.ReadFromUDP(buf)
|
n, _, err := udpConn.ReadFromUDP(buf)
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"fmt"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
@@ -86,9 +85,7 @@ func newCertPool(caPath string) (*x509.CertPool, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !pool.AppendCertsFromPEM(caCrt) {
|
pool.AppendCertsFromPEM(caCrt)
|
||||||
return nil, fmt.Errorf("failed to parse CA certificate from file %q: no valid PEM certificates found", caPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
return pool, nil
|
return pool, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ type WebsocketListener struct {
|
|||||||
// ln: tcp listener for websocket connections
|
// ln: tcp listener for websocket connections
|
||||||
func NewWebsocketListener(ln net.Listener) (wl *WebsocketListener) {
|
func NewWebsocketListener(ln net.Listener) (wl *WebsocketListener) {
|
||||||
wl = &WebsocketListener{
|
wl = &WebsocketListener{
|
||||||
ln: ln,
|
|
||||||
acceptCh: make(chan net.Conn),
|
acceptCh: make(chan net.Conn),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,12 +63,11 @@ func (l *Logger) AddPrefix(prefix LogPrefix) *Logger {
|
|||||||
if prefix.Priority <= 0 {
|
if prefix.Priority <= 0 {
|
||||||
prefix.Priority = 10
|
prefix.Priority = 10
|
||||||
}
|
}
|
||||||
for i, p := range l.prefixes {
|
for _, p := range l.prefixes {
|
||||||
if p.Name == prefix.Name {
|
if p.Name == prefix.Name {
|
||||||
found = true
|
found = true
|
||||||
l.prefixes[i].Value = prefix.Value
|
p.Value = prefix.Value
|
||||||
l.prefixes[i].Priority = prefix.Priority
|
p.Priority = prefix.Priority
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
|
|||||||
@@ -100,9 +100,8 @@ func (tg *TCPGroup) Listen(proxyName string, group string, groupKey string, addr
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
tcpLn, errRet := net.Listen("tcp", net.JoinHostPort(addr, strconv.Itoa(realPort)))
|
tcpLn, errRet := net.Listen("tcp", net.JoinHostPort(addr, strconv.Itoa(port)))
|
||||||
if errRet != nil {
|
if errRet != nil {
|
||||||
tg.ctl.portManager.Release(realPort)
|
|
||||||
err = errRet
|
err = errRet
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,21 +75,16 @@ func (pxy *HTTPProxy) Run() (remoteAddr string, err error) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
domains := make([]string, 0, len(pxy.cfg.CustomDomains)+1)
|
|
||||||
for _, d := range pxy.cfg.CustomDomains {
|
|
||||||
if d != "" {
|
|
||||||
domains = append(domains, d)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if pxy.cfg.SubDomain != "" {
|
|
||||||
domains = append(domains, pxy.cfg.SubDomain+"."+pxy.serverCfg.SubDomainHost)
|
|
||||||
}
|
|
||||||
|
|
||||||
addrs := make([]string, 0)
|
addrs := make([]string, 0)
|
||||||
for _, domain := range domains {
|
for _, domain := range pxy.cfg.CustomDomains {
|
||||||
|
if domain == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
routeConfig.Domain = domain
|
routeConfig.Domain = domain
|
||||||
for _, location := range locations {
|
for _, location := range locations {
|
||||||
routeConfig.Location = location
|
routeConfig.Location = location
|
||||||
|
|
||||||
tmpRouteConfig := routeConfig
|
tmpRouteConfig := routeConfig
|
||||||
|
|
||||||
// handle group
|
// handle group
|
||||||
@@ -98,6 +93,40 @@ func (pxy *HTTPProxy) Run() (remoteAddr string, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pxy.closeFuncs = append(pxy.closeFuncs, func() {
|
||||||
|
pxy.rc.HTTPGroupCtl.UnRegister(pxy.name, pxy.cfg.LoadBalancer.Group, tmpRouteConfig)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// no group
|
||||||
|
err = pxy.rc.HTTPReverseProxy.Register(routeConfig)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
pxy.closeFuncs = append(pxy.closeFuncs, func() {
|
||||||
|
pxy.rc.HTTPReverseProxy.UnRegister(tmpRouteConfig)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
addrs = append(addrs, util.CanonicalAddr(routeConfig.Domain, pxy.serverCfg.VhostHTTPPort))
|
||||||
|
xl.Infof("http proxy listen for host [%s] location [%s] group [%s], routeByHTTPUser [%s]",
|
||||||
|
routeConfig.Domain, routeConfig.Location, pxy.cfg.LoadBalancer.Group, pxy.cfg.RouteByHTTPUser)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if pxy.cfg.SubDomain != "" {
|
||||||
|
routeConfig.Domain = pxy.cfg.SubDomain + "." + pxy.serverCfg.SubDomainHost
|
||||||
|
for _, location := range locations {
|
||||||
|
routeConfig.Location = location
|
||||||
|
|
||||||
|
tmpRouteConfig := routeConfig
|
||||||
|
|
||||||
|
// handle group
|
||||||
|
if pxy.cfg.LoadBalancer.Group != "" {
|
||||||
|
err = pxy.rc.HTTPGroupCtl.Register(pxy.name, pxy.cfg.LoadBalancer.Group, pxy.cfg.LoadBalancer.GroupKey, routeConfig)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
pxy.closeFuncs = append(pxy.closeFuncs, func() {
|
pxy.closeFuncs = append(pxy.closeFuncs, func() {
|
||||||
pxy.rc.HTTPGroupCtl.UnRegister(pxy.name, pxy.cfg.LoadBalancer.Group, tmpRouteConfig)
|
pxy.rc.HTTPGroupCtl.UnRegister(pxy.name, pxy.cfg.LoadBalancer.Group, tmpRouteConfig)
|
||||||
})
|
})
|
||||||
@@ -110,7 +139,8 @@ func (pxy *HTTPProxy) Run() (remoteAddr string, err error) {
|
|||||||
pxy.rc.HTTPReverseProxy.UnRegister(tmpRouteConfig)
|
pxy.rc.HTTPReverseProxy.UnRegister(tmpRouteConfig)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
addrs = append(addrs, util.CanonicalAddr(routeConfig.Domain, pxy.serverCfg.VhostHTTPPort))
|
addrs = append(addrs, util.CanonicalAddr(tmpRouteConfig.Domain, pxy.serverCfg.VhostHTTPPort))
|
||||||
|
|
||||||
xl.Infof("http proxy listen for host [%s] location [%s] group [%s], routeByHTTPUser [%s]",
|
xl.Infof("http proxy listen for host [%s] location [%s] group [%s], routeByHTTPUser [%s]",
|
||||||
routeConfig.Domain, routeConfig.Location, pxy.cfg.LoadBalancer.Group, pxy.cfg.RouteByHTTPUser)
|
routeConfig.Domain, routeConfig.Location, pxy.cfg.LoadBalancer.Group, pxy.cfg.RouteByHTTPUser)
|
||||||
}
|
}
|
||||||
@@ -138,7 +168,6 @@ func (pxy *HTTPProxy) GetRealConn(remoteAddr string) (workConn net.Conn, err err
|
|||||||
rwc, err = libio.WithEncryption(rwc, pxy.encryptionKey)
|
rwc, err = libio.WithEncryption(rwc, pxy.encryptionKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
xl.Errorf("create encryption stream error: %v", err)
|
xl.Errorf("create encryption stream error: %v", err)
|
||||||
tmpConn.Close()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,18 +53,23 @@ func (pxy *HTTPSProxy) Run() (remoteAddr string, err error) {
|
|||||||
pxy.Close()
|
pxy.Close()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
domains := make([]string, 0, len(pxy.cfg.CustomDomains)+1)
|
addrs := make([]string, 0)
|
||||||
for _, d := range pxy.cfg.CustomDomains {
|
for _, domain := range pxy.cfg.CustomDomains {
|
||||||
if d != "" {
|
if domain == "" {
|
||||||
domains = append(domains, d)
|
continue
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if pxy.cfg.SubDomain != "" {
|
l, err := pxy.listenForDomain(routeConfig, domain)
|
||||||
domains = append(domains, pxy.cfg.SubDomain+"."+pxy.serverCfg.SubDomainHost)
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
pxy.listeners = append(pxy.listeners, l)
|
||||||
|
addrs = append(addrs, util.CanonicalAddr(domain, pxy.serverCfg.VhostHTTPSPort))
|
||||||
|
xl.Infof("https proxy listen for host [%s] group [%s]", domain, pxy.cfg.LoadBalancer.Group)
|
||||||
}
|
}
|
||||||
|
|
||||||
addrs := make([]string, 0)
|
if pxy.cfg.SubDomain != "" {
|
||||||
for _, domain := range domains {
|
domain := pxy.cfg.SubDomain + "." + pxy.serverCfg.SubDomainHost
|
||||||
l, err := pxy.listenForDomain(routeConfig, domain)
|
l, err := pxy.listenForDomain(routeConfig, domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|||||||
@@ -72,19 +72,21 @@ func (pxy *TCPMuxProxy) httpConnectListen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pxy *TCPMuxProxy) httpConnectRun() (remoteAddr string, err error) {
|
func (pxy *TCPMuxProxy) httpConnectRun() (remoteAddr string, err error) {
|
||||||
domains := make([]string, 0, len(pxy.cfg.CustomDomains)+1)
|
addrs := make([]string, 0)
|
||||||
for _, d := range pxy.cfg.CustomDomains {
|
for _, domain := range pxy.cfg.CustomDomains {
|
||||||
if d != "" {
|
if domain == "" {
|
||||||
domains = append(domains, d)
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
addrs, err = pxy.httpConnectListen(domain, pxy.cfg.RouteByHTTPUser, pxy.cfg.HTTPUser, pxy.cfg.HTTPPassword, addrs)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if pxy.cfg.SubDomain != "" {
|
|
||||||
domains = append(domains, pxy.cfg.SubDomain+"."+pxy.serverCfg.SubDomainHost)
|
|
||||||
}
|
|
||||||
|
|
||||||
addrs := make([]string, 0)
|
if pxy.cfg.SubDomain != "" {
|
||||||
for _, domain := range domains {
|
addrs, err = pxy.httpConnectListen(pxy.cfg.SubDomain+"."+pxy.serverCfg.SubDomainHost,
|
||||||
addrs, err = pxy.httpConnectListen(domain, pxy.cfg.RouteByHTTPUser, pxy.cfg.HTTPUser, pxy.cfg.HTTPPassword, addrs)
|
pxy.cfg.RouteByHTTPUser, pxy.cfg.HTTPUser, pxy.cfg.HTTPPassword, addrs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user