diff --git a/tun.go b/tun.go index 6d86228..e08a60b 100644 --- a/tun.go +++ b/tun.go @@ -85,7 +85,7 @@ func CalculateInterfaceName(name string) (tunName string) { for _, netInterface := range interfaces { if strings.HasPrefix(netInterface.Name, tunName) { index, parseErr := strconv.ParseInt(netInterface.Name[len(tunName):], 10, 16) - if parseErr == nil { + if parseErr == nil && int(index) >= tunIndex { tunIndex = int(index) + 1 } } diff --git a/tun_rules.go b/tun_rules.go index 37dcd98..ce5ab31 100644 --- a/tun_rules.go +++ b/tun_rules.go @@ -109,6 +109,11 @@ func (o *Options) BuildAutoRouteRanges(underNetworkExtension bool) ([]netip.Pref var inet4Ranges []netip.Prefix if len(o.Inet4RouteAddress) > 0 { inet4Ranges = o.Inet4RouteAddress + for _, address := range o.Inet4Address { + if address.Bits() < 32 { + inet4Ranges = append(inet4Ranges, netipx.RangeOfPrefix(address).Prefixes()...) + } + } } else if autoRouteUseSubRanges && !underNetworkExtension { inet4Ranges = []netip.Prefix{ netip.PrefixFrom(netip.AddrFrom4([4]byte{0: 1}), 8), @@ -144,6 +149,11 @@ func (o *Options) BuildAutoRouteRanges(underNetworkExtension bool) ([]netip.Pref var inet6Ranges []netip.Prefix if len(o.Inet6RouteAddress) > 0 { inet6Ranges = o.Inet6RouteAddress + for _, address := range o.Inet6Address { + if address.Bits() < 32 { + inet6Ranges = append(inet6Ranges, netipx.RangeOfPrefix(address).Prefixes()...) + } + } } else if autoRouteUseSubRanges && !underNetworkExtension { inet6Ranges = []netip.Prefix{ netip.PrefixFrom(netip.AddrFrom16([16]byte{0: 1}), 8),