Fix gateway & FIx prefix check
This commit is contained in:
parent
07278fb470
commit
10f73346a0
8 changed files with 111 additions and 45 deletions
30
tun.go
30
tun.go
|
|
@ -53,6 +53,8 @@ type Options struct {
|
|||
MTU uint32
|
||||
GSO bool
|
||||
AutoRoute bool
|
||||
Inet4Gateway netip.Addr
|
||||
Inet6Gateway netip.Addr
|
||||
DNSServers []netip.Addr
|
||||
IPRoute2TableIndex int
|
||||
IPRoute2RuleIndex int
|
||||
|
|
@ -82,6 +84,34 @@ type Options struct {
|
|||
EXP_DisableDNSHijack bool
|
||||
}
|
||||
|
||||
func (o *Options) Inet4GatewayAddr() netip.Addr {
|
||||
if o.Inet4Gateway.IsValid() {
|
||||
return o.Inet4Gateway
|
||||
}
|
||||
if len(o.Inet4Address) > 0 {
|
||||
if HasNextAddress(o.Inet4Address[0], 1) {
|
||||
return o.Inet4Address[0].Addr().Next()
|
||||
} else if runtime.GOOS != "linux" {
|
||||
return o.Inet4Address[0].Addr()
|
||||
}
|
||||
}
|
||||
return netip.IPv4Unspecified()
|
||||
}
|
||||
|
||||
func (o *Options) Inet6GatewayAddr() netip.Addr {
|
||||
if o.Inet6Gateway.IsValid() {
|
||||
return o.Inet6Gateway
|
||||
}
|
||||
if len(o.Inet6Address) > 0 {
|
||||
if HasNextAddress(o.Inet6Address[0], 1) {
|
||||
return o.Inet6Address[0].Addr().Next()
|
||||
} else if runtime.GOOS != "linux" {
|
||||
return o.Inet6Address[0].Addr()
|
||||
}
|
||||
}
|
||||
return netip.IPv6Unspecified()
|
||||
}
|
||||
|
||||
func CalculateInterfaceName(name string) (tunName string) {
|
||||
if runtime.GOOS == "darwin" {
|
||||
tunName = "utun"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue