Fix issues related to android client (#4616)

* WireGuard: Fix tunnel not closed

* Dialer: Apply controllers in lc.Control
This commit is contained in:
Cl-He-O 2025-04-14 15:08:26 +00:00 committed by GitHub
parent 53552d73cc
commit 7a2f42f8d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 0 deletions

View File

@ -325,6 +325,7 @@ func (h *Handler) Start() error {
// Close implements common.Closable.
func (h *Handler) Close() error {
common.Close(h.mux)
common.Close(h.proxy)
return nil
}

View File

@ -77,6 +77,20 @@ func New(ctx context.Context, conf *DeviceConfig) (*Handler, error) {
}, nil
}
func (h *Handler) Close() (err error) {
go func() {
h.wgLock.Lock()
defer h.wgLock.Unlock()
if h.net != nil {
_ = h.net.Close()
h.net = nil
}
}()
return nil
}
func (h *Handler) processWireGuard(ctx context.Context, dialer internet.Dialer) (err error) {
h.wgLock.Lock()
defer h.wgLock.Unlock()

View File

@ -61,6 +61,11 @@ func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest ne
}
var lc net.ListenConfig
lc.Control = func(network, address string, c syscall.RawConn) error {
for _, ctl := range d.controllers {
if err := ctl(network, address, c); err != nil {
errors.LogInfoInner(ctx, err, "failed to apply external controller")
}
}
return c.Control(func(fd uintptr) {
if sockopt != nil {
if err := applyOutboundSocketOptions(network, "", fd, sockopt); err != nil {