new: add vpn service mode as seperated option, fix crash of wireguard in wireguard and more stable wireguard

This commit is contained in:
Hiddify
2024-02-14 15:49:47 +01:00
parent 43d9ef9bbd
commit 3111671d6e
7 changed files with 76 additions and 70 deletions

View File

@@ -3,6 +3,7 @@ package config
import (
"fmt"
"io"
"time"
"net/http"
"net/url"
@@ -96,9 +97,12 @@ func runTunnelService(opt ConfigOptions) (bool, error) {
out, err := ExecuteCmd(executablePath, "install", false)
fmt.Println("Shell command executed:", out, err)
if err != nil {
out, err := ExecuteCmd(executablePath, "", true)
out, err = ExecuteCmd(executablePath, "", true)
fmt.Println("Shell command executed without flag:", out, err)
}
if err == nil {
<-time.After(1 * time.Second) //wait until service loaded completely
}
return startTunnelRequest(opt, false)
}

View File

@@ -135,44 +135,44 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
} else {
inboundDomainStrategy = opt.IPv6Mode
}
if opt.EnableTun {
if ok, _ := ActivateTunnelService(opt); !ok {
tunInbound := option.Inbound{
Type: C.TypeTun,
Tag: InboundTUNTag,
TunOptions: option.TunInboundOptions{
Stack: opt.TUNStack,
MTU: opt.MTU,
AutoRoute: true,
StrictRoute: opt.StrictRoute,
EndpointIndependentNat: true,
InboundOptions: option.InboundOptions{
SniffEnabled: true,
SniffOverrideDestination: true,
DomainStrategy: inboundDomainStrategy,
},
if opt.EnableTunService {
ActivateTunnelService(opt)
} else if opt.EnableTun {
tunInbound := option.Inbound{
Type: C.TypeTun,
Tag: InboundTUNTag,
TunOptions: option.TunInboundOptions{
Stack: opt.TUNStack,
MTU: opt.MTU,
AutoRoute: true,
StrictRoute: opt.StrictRoute,
EndpointIndependentNat: true,
InboundOptions: option.InboundOptions{
SniffEnabled: true,
SniffOverrideDestination: true,
DomainStrategy: inboundDomainStrategy,
},
}
switch opt.IPv6Mode {
case option.DomainStrategy(dns.DomainStrategyUseIPv4):
tunInbound.TunOptions.Inet4Address = []netip.Prefix{
netip.MustParsePrefix("172.19.0.1/28"),
}
case option.DomainStrategy(dns.DomainStrategyUseIPv6):
tunInbound.TunOptions.Inet6Address = []netip.Prefix{
netip.MustParsePrefix("fdfe:dcba:9876::1/126"),
}
default:
tunInbound.TunOptions.Inet4Address = []netip.Prefix{
netip.MustParsePrefix("172.19.0.1/28"),
}
tunInbound.TunOptions.Inet6Address = []netip.Prefix{
netip.MustParsePrefix("fdfe:dcba:9876::1/126"),
}
}
options.Inbounds = append(options.Inbounds, tunInbound)
},
}
switch opt.IPv6Mode {
case option.DomainStrategy(dns.DomainStrategyUseIPv4):
tunInbound.TunOptions.Inet4Address = []netip.Prefix{
netip.MustParsePrefix("172.19.0.1/28"),
}
case option.DomainStrategy(dns.DomainStrategyUseIPv6):
tunInbound.TunOptions.Inet6Address = []netip.Prefix{
netip.MustParsePrefix("fdfe:dcba:9876::1/126"),
}
default:
tunInbound.TunOptions.Inet4Address = []netip.Prefix{
netip.MustParsePrefix("172.19.0.1/28"),
}
tunInbound.TunOptions.Inet6Address = []netip.Prefix{
netip.MustParsePrefix("fdfe:dcba:9876::1/126"),
}
}
options.Inbounds = append(options.Inbounds, tunInbound)
}
options.Inbounds = append(

View File

@@ -33,13 +33,14 @@ type DNSOptions struct {
}
type InboundOptions struct {
EnableTun bool `json:"enable-tun"`
SetSystemProxy bool `json:"set-system-proxy"`
MixedPort uint16 `json:"mixed-port"`
LocalDnsPort uint16 `json:"local-dns-port"`
MTU uint32 `json:"mtu"`
StrictRoute bool `json:"strict-route"`
TUNStack string `json:"tun-stack"`
EnableTun bool `json:"enable-tun"`
EnableTunService bool `json:"enable-tun-service"`
SetSystemProxy bool `json:"set-system-proxy"`
MixedPort uint16 `json:"mixed-port"`
LocalDnsPort uint16 `json:"local-dns-port"`
MTU uint32 `json:"mtu"`
StrictRoute bool `json:"strict-route"`
TUNStack string `json:"tun-stack"`
}
type URLTestOptions struct {

View File

@@ -105,17 +105,17 @@ func patchOutboundFragment(base option.Outbound, configOpt ConfigOptions, obj ou
func isOutboundReality(base option.Outbound) bool {
// this function checks reality status ONLY FOR VLESS.
// Some other protocols can also use reality, but it's discouraged as stated in the reality document
isReality := false
switch base.Type {
case C.TypeVLESS:
if base.VLESSOptions.OutboundTLSOptionsContainer.TLS == nil {
return false
}
if base.VLESSOptions.OutboundTLSOptionsContainer.TLS.Reality != nil {
isReality = base.VLESSOptions.OutboundTLSOptionsContainer.TLS.Reality.Enabled
}
if base.Type != C.TypeVLESS {
return false
}
return isReality
if base.VLESSOptions.OutboundTLSOptionsContainer.TLS == nil {
return false
}
if base.VLESSOptions.OutboundTLSOptionsContainer.TLS.Reality == nil {
return false
}
return base.VLESSOptions.OutboundTLSOptionsContainer.TLS.Reality.Enabled
}
func patchOutbound(base option.Outbound, configOpt ConfigOptions) (*option.Outbound, string, error) {