new: make tunnel service working
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"net"
|
||||
"net/netip"
|
||||
"net/url"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
@@ -118,40 +119,42 @@ func BuildConfig(configOpt ConfigOptions, input option.Options) (*option.Options
|
||||
}
|
||||
|
||||
if configOpt.EnableTun {
|
||||
tunInbound := option.Inbound{
|
||||
Type: C.TypeTun,
|
||||
Tag: "tun-in",
|
||||
TunOptions: option.TunInboundOptions{
|
||||
Stack: configOpt.TUNStack,
|
||||
MTU: configOpt.MTU,
|
||||
AutoRoute: true,
|
||||
StrictRoute: configOpt.StrictRoute,
|
||||
EndpointIndependentNat: true,
|
||||
InboundOptions: option.InboundOptions{
|
||||
SniffEnabled: true,
|
||||
SniffOverrideDestination: true,
|
||||
DomainStrategy: inboundDomainStrategy,
|
||||
if runtime.GOOS != "windows" && runtime.GOOS != "darwin" && runtime.GOOS != "linux" {
|
||||
tunInbound := option.Inbound{
|
||||
Type: C.TypeTun,
|
||||
Tag: "tun-in",
|
||||
TunOptions: option.TunInboundOptions{
|
||||
Stack: configOpt.TUNStack,
|
||||
MTU: configOpt.MTU,
|
||||
AutoRoute: true,
|
||||
StrictRoute: configOpt.StrictRoute,
|
||||
EndpointIndependentNat: true,
|
||||
InboundOptions: option.InboundOptions{
|
||||
SniffEnabled: true,
|
||||
SniffOverrideDestination: true,
|
||||
DomainStrategy: inboundDomainStrategy,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
switch configOpt.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 configOpt.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(
|
||||
|
||||
@@ -70,7 +70,7 @@ func patchOutboundTLSTricks(base option.Outbound, configOpt ConfigOptions, obj o
|
||||
if configOpt.TLSTricks.EnablePadding {
|
||||
tlsTricks.PaddingMode = "random"
|
||||
tlsTricks.PaddingSize = configOpt.TLSTricks.PaddingSize
|
||||
fmt.Printf("--------------------%+v----%+v", tlsTricks.PaddingSize, configOpt)
|
||||
// fmt.Printf("--------------------%+v----%+v", tlsTricks.PaddingSize, configOpt)
|
||||
outtls["utls"] = map[string]interface{}{
|
||||
"enabled": true,
|
||||
"fingerprint": "custom",
|
||||
@@ -82,7 +82,7 @@ func patchOutboundTLSTricks(base option.Outbound, configOpt ConfigOptions, obj o
|
||||
// // } else {
|
||||
// // tls["tls_tricks"] = nil
|
||||
// }
|
||||
fmt.Printf("-------%+v------------- ", tlsTricks)
|
||||
// fmt.Printf("-------%+v------------- ", tlsTricks)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
@@ -190,6 +190,12 @@ func patchWarp(base *option.Outbound) error {
|
||||
|
||||
base.Type = C.TypeWireGuard
|
||||
warpConfig.WireGuardOptions.Detour = detour
|
||||
if detour != "" {
|
||||
if warpConfig.WireGuardOptions.MTU > 1000 {
|
||||
warpConfig.WireGuardOptions.MTU -= 100
|
||||
}
|
||||
warpConfig.WireGuardOptions.FakePackets = ""
|
||||
}
|
||||
base.WireGuardOptions = warpConfig.WireGuardOptions
|
||||
|
||||
}
|
||||
|
||||
@@ -188,6 +188,7 @@ func generateWarp(license string, host string, port uint16, fakePackets string)
|
||||
fmt.Println("Error marshaling Singbox configuration:", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fmt.Println(string(singboxJSON))
|
||||
return singboxConfig, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user