Skip to content

Commit 46f00de

Browse files
committed
Add openvpn and openconnect
1 parent cd3ee75 commit 46f00de

66 files changed

Lines changed: 12491 additions & 382 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

adapter/openconnect.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package adapter
2+
3+
import (
4+
"net/netip"
5+
"time"
6+
)
7+
8+
const (
9+
OpenConnectStateConnecting = "connecting"
10+
OpenConnectStateAuthPending = "auth-pending"
11+
OpenConnectStateConnected = "connected"
12+
OpenConnectStateError = "error"
13+
)
14+
15+
type OpenConnectEndpoint interface {
16+
Endpoint
17+
OpenConnectStatus() OpenConnectStatus
18+
StatusUpdated() <-chan struct{}
19+
CompleteAuthForm(formID string, values map[string]string) error
20+
CancelAuthForm(formID string) error
21+
}
22+
23+
type OpenConnectStatus struct {
24+
State string
25+
AuthForm *OpenConnectAuthForm
26+
Error string
27+
TunnelInfo *OpenConnectTunnelInfo
28+
}
29+
30+
type OpenConnectTunnelInfo struct {
31+
Server string
32+
Flavor string
33+
Transport string
34+
IPv4 []netip.Prefix
35+
IPv6 []netip.Prefix
36+
DNS []netip.Addr
37+
MTU uint32
38+
ConnectedSince time.Time
39+
}
40+
41+
type OpenConnectAuthForm struct {
42+
ID string
43+
Banner string
44+
Message string
45+
Error string
46+
URL string
47+
Fields []OpenConnectAuthFormField
48+
}
49+
50+
type OpenConnectAuthFormField struct {
51+
SubmissionKey string
52+
Name string
53+
Label string
54+
Kind string
55+
Value string
56+
Options []OpenConnectAuthFormChoice
57+
}
58+
59+
type OpenConnectAuthFormChoice struct {
60+
Value string
61+
Label string
62+
}

adapter/openvpn.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package adapter
2+
3+
import (
4+
"net/netip"
5+
"time"
6+
)
7+
8+
const (
9+
OpenVPNStateConnecting = "connecting"
10+
OpenVPNStateAuthPending = "auth-pending"
11+
OpenVPNStateConnected = "connected"
12+
OpenVPNStateError = "error"
13+
)
14+
15+
type OpenVPNEndpoint interface {
16+
Endpoint
17+
OpenVPNStatus() OpenVPNStatus
18+
StatusUpdated() <-chan struct{}
19+
CompleteChallenge(challengeID string, response OpenVPNChallengeResponse) error
20+
CancelChallenge(challengeID string) error
21+
}
22+
23+
type OpenVPNStatus struct {
24+
State string
25+
Challenge *OpenVPNChallenge
26+
Error string
27+
TunnelInfo *OpenVPNTunnelInfo
28+
}
29+
30+
type OpenVPNTunnelInfo struct {
31+
Server string
32+
Network string
33+
Cipher string
34+
IPv4 []netip.Prefix
35+
IPv6 []netip.Prefix
36+
DNS []netip.Addr
37+
MTU uint32
38+
ConnectedSince time.Time
39+
}
40+
41+
type OpenVPNChallenge struct {
42+
ID string
43+
Kind string
44+
Username string
45+
Message string
46+
URL string
47+
SecretMessage string
48+
Echo bool
49+
PreviousError string
50+
Deadline time.Time
51+
}
52+
53+
type OpenVPNChallengeResponse struct {
54+
Username string
55+
Password string
56+
Secret string
57+
}

cmd/internal/app_store_connect/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func prepareAppStore(ctx context.Context) error {
289289
return err
290290
}
291291
if len(builds.Data) == 0 {
292-
log.Fatal(platform, " ", tag, " no build found")
292+
log.Fatal(string(platform), " ", tag, " no build found")
293293
}
294294
buildID := common.Ptr(builds.Data[0].ID)
295295
if version.ID == "" {

cmd/internal/build_libbox/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func init() {
6363
sharedFlags = append(sharedFlags, "-ldflags", build_shared.LinkerFlags(currentTag, false))
6464
debugFlags = append(debugFlags, "-ldflags", build_shared.LinkerFlags(currentTag, true))
6565

66-
sharedTags = append(sharedTags, "with_gvisor", "with_quic", "with_wireguard", "with_utls", "with_naive_outbound", "with_clash_api", "with_usbip", "badlinkname", "tfogo_checklinkname0")
66+
sharedTags = append(sharedTags, "with_gvisor", "with_quic", "with_wireguard", "with_utls", "with_naive_outbound", "with_clash_api", "with_usbip", "with_openvpn", "with_openconnect", "badlinkname", "tfogo_checklinkname0")
6767
darwinTags = append(darwinTags, "with_dhcp", "grpcnotrace")
6868
// memcTags = append(memcTags, "with_tailscale")
6969
sharedTags = append(sharedTags, "with_tailscale", "ts_omit_logtail", "ts_omit_ssh", "ts_omit_drive", "ts_omit_taildrop", "ts_omit_webclient", "ts_omit_doctor", "ts_omit_capture", "ts_omit_kube", "ts_omit_aws", "ts_omit_synology", "ts_omit_bird")

common/dialer/default.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
var (
2626
_ ParallelInterfaceDialer = (*DefaultDialer)(nil)
27-
_ WireGuardListener = (*DefaultDialer)(nil)
27+
_ UDPListener = (*DefaultDialer)(nil)
2828
)
2929

3030
type DefaultDialer struct {
@@ -381,7 +381,7 @@ func (d *DefaultDialer) ListenSerialInterfacePacket(ctx context.Context, destina
381381
return d.trackPacketConn(packetConn, nil)
382382
}
383383

384-
func (d *DefaultDialer) WireGuardControl() (control.Func, bool) {
384+
func (d *DefaultDialer) UDPListenerControl() (control.Func, bool) {
385385
return d.udpListener.Control, d.autoDetectBindFunc != nil && d.netns == ""
386386
}
387387

common/dialer/udp_listener.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package dialer
2+
3+
import (
4+
"github.com/sagernet/sing/common/control"
5+
)
6+
7+
type UDPListener interface {
8+
UDPListenerControl() (control.Func, bool)
9+
}

common/dialer/wireguard.go

Lines changed: 0 additions & 9 deletions
This file was deleted.

common/listener/listener_udp.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ import (
2222
const udpOutputBatchSize = 128
2323

2424
func (l *Listener) ListenUDP() (net.PacketConn, error) {
25+
return l.ListenUDPWithConfig(net.ListenConfig{})
26+
}
27+
28+
func (l *Listener) ListenUDPWithConfig(listenConfig net.ListenConfig) (net.PacketConn, error) {
2529
bindAddr := M.SocksaddrFrom(l.listenOptions.Listen.Build(netip.AddrFrom4([4]byte{127, 0, 0, 1})), l.listenOptions.ListenPort)
26-
var listenConfig net.ListenConfig
2730
if l.listenOptions.BindInterface != "" {
2831
listenConfig.Control = control.Append(listenConfig.Control, control.BindToInterface(service.FromContext[adapter.NetworkManager](l.ctx).InterfaceFinder(), l.listenOptions.BindInterface, -1))
2932
}

constant/proxy.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ const (
2626
TypeVLESS = "vless"
2727
TypeTUIC = "tuic"
2828
TypeHysteria2 = "hysteria2"
29+
TypeOpenConnect = "openconnect"
30+
TypeOpenVPNClient = "openvpn-client"
31+
TypeOpenVPNServer = "openvpn-server"
2932
TypeTailscale = "tailscale"
3033
TypeCloudflared = "cloudflared"
3134
TypeDERP = "derp"
@@ -99,6 +102,12 @@ func ProxyDisplayName(proxyType string) string {
99102
return "Hysteria2"
100103
case TypeAnyTLS:
101104
return "AnyTLS"
105+
case TypeOpenConnect:
106+
return "OpenConnect"
107+
case TypeOpenVPNClient:
108+
return "OpenVPN Client"
109+
case TypeOpenVPNServer:
110+
return "OpenVPN Server"
102111
case TypeTailscale:
103112
return "Tailscale"
104113
case TypeCloudflared:

0 commit comments

Comments
 (0)