mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-12-01 14:18:36 +00:00
Fix OpenConnect sessions through detour
This commit is contained in:
@@ -48,7 +48,7 @@ require (
|
||||
github.com/sagernet/sing v0.9.7-0.20261125120655-610c8699131b
|
||||
github.com/sagernet/sing-cloudflared v0.1.4-0.20261125132439-71e2e5ed8ed0
|
||||
github.com/sagernet/sing-mux v0.3.10-0.20261125130604-6c5b46f55eeb
|
||||
github.com/sagernet/sing-openconnect v0.1.1-0.20261119020037-0dad74dcc5e1
|
||||
github.com/sagernet/sing-openconnect v0.1.1-0.20261126032024-f641df2c35c6
|
||||
github.com/sagernet/sing-openvpn v0.1.1-0.20261125120933-494cce526aab
|
||||
github.com/sagernet/sing-quic v0.7.2-0.20261124143824-14ca3448d44b
|
||||
github.com/sagernet/sing-shadowsocks v0.2.9-0.20260929204512-65740e0f0e3e
|
||||
|
||||
@@ -324,8 +324,8 @@ github.com/sagernet/sing-cloudflared v0.1.4-0.20261125132439-71e2e5ed8ed0 h1:xGM
|
||||
github.com/sagernet/sing-cloudflared v0.1.4-0.20261125132439-71e2e5ed8ed0/go.mod h1:XEqEDYRCAYLaoPjZ1ifVWJg5iWAJHL2gOAXe/PM28Cg=
|
||||
github.com/sagernet/sing-mux v0.3.10-0.20261125130604-6c5b46f55eeb h1:iK0uoxfzEEDhez9zXj/Pvu4zEqAwNFzc6nAZzdaaC1Q=
|
||||
github.com/sagernet/sing-mux v0.3.10-0.20261125130604-6c5b46f55eeb/go.mod h1:jricpwCOndDsTEM1TM3piJvhL/2Mm7OhLkm+JadJJ1Q=
|
||||
github.com/sagernet/sing-openconnect v0.1.1-0.20261119020037-0dad74dcc5e1 h1:sgw1JLLn/RASRh6qrVpIaajOnz/9aO1UJcmxjPgDdTE=
|
||||
github.com/sagernet/sing-openconnect v0.1.1-0.20261119020037-0dad74dcc5e1/go.mod h1:4AKZLVcvY3r54UaK2Gbnm7aN8pOwdLz+y4EP0QFZ5Eg=
|
||||
github.com/sagernet/sing-openconnect v0.1.1-0.20261126032024-f641df2c35c6 h1:55lMpRb+98B5rJHrsqYRAjYy6/wWBUiMPYasBqUCEjQ=
|
||||
github.com/sagernet/sing-openconnect v0.1.1-0.20261126032024-f641df2c35c6/go.mod h1:4AKZLVcvY3r54UaK2Gbnm7aN8pOwdLz+y4EP0QFZ5Eg=
|
||||
github.com/sagernet/sing-openvpn v0.1.1-0.20261125120933-494cce526aab h1:EvPC5IZLG3xkq9eCALjDnMc88HI8IGQR9QfmgivE7mE=
|
||||
github.com/sagernet/sing-openvpn v0.1.1-0.20261125120933-494cce526aab/go.mod h1:PWX7WygD8jpwfqfaGNySXpJYTn0SOwjBI1BKHHC2+Bw=
|
||||
github.com/sagernet/sing-quic v0.7.2-0.20261124143824-14ca3448d44b h1:I7h8MDkYIMofFW+BojM/2pNEBVWO1yiapP9keC9Uu9Y=
|
||||
|
||||
@@ -46,6 +46,9 @@ type Endpoint struct {
|
||||
loopContext context.Context
|
||||
cancelLoop context.CancelFunc
|
||||
dnsRouter adapter.DNSRouter
|
||||
outboundManager adapter.OutboundManager
|
||||
detour string
|
||||
clientOptions openconnect.ClientOptions
|
||||
client *openconnect.Client
|
||||
device openconnecttransport.Device
|
||||
server string
|
||||
@@ -107,10 +110,12 @@ func NewEndpoint(ctx context.Context, router adapter.Router, logger log.ContextL
|
||||
router: router,
|
||||
logger: logger,
|
||||
},
|
||||
loopContext: loopContext,
|
||||
cancelLoop: cancelLoop,
|
||||
dnsRouter: service.FromContext[adapter.DNSRouter](ctx),
|
||||
statusUpdated: make(chan struct{}),
|
||||
loopContext: loopContext,
|
||||
cancelLoop: cancelLoop,
|
||||
dnsRouter: service.FromContext[adapter.DNSRouter](ctx),
|
||||
outboundManager: service.FromContext[adapter.OutboundManager](ctx),
|
||||
detour: options.Detour,
|
||||
statusUpdated: make(chan struct{}),
|
||||
}
|
||||
openConnectEndpoint.state.Store(new(clientState))
|
||||
success := false
|
||||
@@ -187,6 +192,7 @@ func NewEndpoint(ctx context.Context, router adapter.Router, logger log.ContextL
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
openConnectEndpoint.clientOptions = clientOptions
|
||||
openConnectEndpoint.client = client
|
||||
success = true
|
||||
return openConnectEndpoint, nil
|
||||
@@ -336,6 +342,7 @@ func (e *Endpoint) buildClientOptions(options option.OpenConnectEndpointOptions,
|
||||
},
|
||||
FormEntries: formEntries,
|
||||
Dialer: outboundDialer,
|
||||
ProxiedDialer: options.Detour != "",
|
||||
Logger: e.logger,
|
||||
OnTunnelConfiguration: e.handleTunnelConfiguration,
|
||||
}, nil
|
||||
@@ -418,6 +425,21 @@ func (e *Endpoint) updateState(update func(state *clientState)) {
|
||||
func (e *Endpoint) Start(stage adapter.StartStage, scope *adapter.Scope) error {
|
||||
switch stage {
|
||||
case adapter.StartStateInitialize:
|
||||
if e.clientOptions.ProxiedDialer {
|
||||
detour, loaded := e.outboundManager.Outbound(e.detour)
|
||||
if loaded && detour.Type() == C.TypeDirect {
|
||||
e.clientOptions.ProxiedDialer = false
|
||||
client, err := openconnect.NewClient(e.clientOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = e.client.Close()
|
||||
if err != nil {
|
||||
return E.Cause(err, "close client")
|
||||
}
|
||||
e.client = client
|
||||
}
|
||||
}
|
||||
scope.Add(func() error {
|
||||
e.notifyStatusUpdated()
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user