Chore: make fake ip pool start with the third ip

This commit is contained in:
yaling888
2022-03-18 05:17:47 +08:00
parent 8d0ae4284d
commit 546f2fa739
4 changed files with 32 additions and 28 deletions

View File

@ -20,7 +20,7 @@ func ConfigInterfaceAddress(dev device.Device, addr netip.Prefix, forceMTU int,
var (
interfaceName = dev.Name()
ip = addr.Masked().Addr().Next()
gw = ip
gw = ip.Next()
netmask = IPv4MaskString(addr.Bits())
)
@ -31,10 +31,10 @@ func ConfigInterfaceAddress(dev device.Device, addr netip.Prefix, forceMTU int,
return err
}
// _, err = cmd.ExecCmd(fmt.Sprintf("ipconfig set %s automatic-v6", interfaceName))
// if err != nil {
// return err
// }
_, err = cmd.ExecCmd(fmt.Sprintf("ipconfig set %s automatic-v6", interfaceName))
if err != nil {
return err
}
if autoRoute {
err = configInterfaceRouting(interfaceName, addr)
@ -43,15 +43,18 @@ func ConfigInterfaceAddress(dev device.Device, addr netip.Prefix, forceMTU int,
}
func configInterfaceRouting(interfaceName string, addr netip.Prefix) error {
routes := append(Routes, addr.String())
var (
routes = append(Routes, addr.String())
gateway = addr.Masked().Addr().Next()
)
for _, route := range routes {
if err := execRouterCmd("add", "-inet", route, interfaceName); err != nil {
for _, destination := range routes {
if _, err := cmd.ExecCmd(fmt.Sprintf("route add -net %s %s", destination, gateway)); err != nil {
return err
}
}
// return execRouterCmd("add", "-inet6", "2000::/3", interfaceName)
return execRouterCmd("add", "-inet6", "2000::/3", interfaceName)
return nil
}

View File

@ -25,11 +25,11 @@ import (
// New TunAdapter
func New(tunConf *config.Tun, tunAddressPrefix string, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.PacketAdapter) (ipstack.Stack, error) {
var (
tunAddress = netip.MustParsePrefix(tunAddressPrefix)
devName = tunConf.Device
stackType = tunConf.Stack
autoRoute = tunConf.AutoRoute
mtu = 9000
tunAddress, _ = netip.ParsePrefix(tunAddressPrefix)
devName = tunConf.Device
stackType = tunConf.Stack
autoRoute = tunConf.AutoRoute
mtu = 9000
tunDevice device.Device
tunStack ipstack.Stack