Feature request: fallback outbound group based on the tunnel's own connection state (WireGuard handshake, OpenVPN/OpenConnect session)

Aperta
#4,729 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
20/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
networking

Direzione di ricerca

Start from the proposed fallback outbound group and the connection-state hooks it needs: SetSessionStateFunc, Peer.ExpireCurrentKeypairs and Peer.SendHandshakeInitiation in the WireGuard endpoint, plus the OpenVPN client and OpenConnect endpoints. The linked branch V1rgul:fallback-outbound-group has commits for both parts, but the issue does not settle the design, so it needs maintainer agreement first. Done means the group selects the first connected outbound with timeout and fast switch-back, backed by tests, docs and the schema entry.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Problem

I want to prefer a WireGuard endpoint (UDP) and automatically use an OpenVPN endpoint over TCP/443 on networks where the WireGuard handshake never completes (UDP filtered), then return to WireGuard as soon as its handshake succeeds again.

This cannot be expressed today:

  • selector does not fail over by itself.
  • urltest selects by the latency of an HTTP(S) request sent through each outbound. It has no strict order of preference, and it measures a third-party URL rather than the tunnel: the signal I need is whether the tunnel itself is connected.
  • A WireGuard endpoint is started as soon as its local device is up, before any peer has answered, so nothing in the configuration can react to a handshake that does not complete.
Proposal

A fallback outbound group that selects the first outbound in the list whose own connection is established, using the state each tunnel already knows, without URL tests:

{
  "type": "fallback",
  "tag": "vpn",
  "outbounds": [
    "wireguard",
    "openvpn"
  ],
  "timeout": "10s",
  "interrupt_exist_connections": false
}
  • The first connected outbound is selected. An outbound that is not connected yet is waited for during timeout before the next one is considered.
  • The group switches back to an earlier outbound as soon as it is connected again.
  • An outbound that reports a terminal error (for example an OpenVPN authentication failure) is skipped without waiting.
  • Outbounds without a connection state (direct, proxies, other groups) are always considered connected.
Type Connected when
wireguard every peer with an address has an established session (completed handshake, not expired)
openvpn-client the tunnel is established and configured
openconnect the tunnel is established and configured

For WireGuard this needs two things while the endpoint is used by such a group: initiating the handshake without waiting for traffic, and forcing a fresh handshake after a network change, because an established session otherwise stays established for up to 3 minutes on a path that now drops UDP.

Related
  • #4627, #2130 and #4065 ask for priority-based selection, and #4217 implements priority tiers, all with URL tests as the health signal. #4436 asks for non-HTTP probes.
  • This request is about the health signal: the tunnel's own authenticated state instead of a probe through it. The two are complementary: a URL test could later provide the state of outbounds that have none.
Implementation

I have an implementation with tests and documentation (en + zh): V1rgul:fallback-outbound-group, two commits on top of testing:

  • ab0a9e303 adds a connection state to the WireGuard, OpenVPN client and OpenConnect endpoints. It needs no wireguard-go change: it uses SetSessionStateFunc, Peer.ExpireCurrentKeypairs and Peer.SendHandshakeInitiation of the pinned version.
  • 06f2dd943 adds the group, its documentation, the schema entry and the tests.

Pull requests on this repository can only be created by collaborators, so I could not open one. I can open it if that is possible, or the branch can be taken as is.

Lingua principale
Go
Stelle
40.4k
Fork
5k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

  • Include un Dockerfile o un file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di SagerNet/sing-box

Tutte le issue di SagerNet/sing-box

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.