mirror of
https://github.com/netbirdio/netbird.git
synced 2025-02-08 22:39:55 +01:00
Fix windows route zones (#2164)
* Fix windows zone and add additional debug output * Fix routes zone on BSD * Remove redundant Unmap * Add zone to windows routes
This commit is contained in:
parent
c347a4c2ca
commit
b075009ef7
@ -101,11 +101,14 @@ func routeChanged(nexthop systemops.Nexthop, intf *net.Interface, routes map[net
|
|||||||
|
|
||||||
if r, ok := routes[unspec]; ok {
|
if r, ok := routes[unspec]; ok {
|
||||||
if r.Nexthop != nexthop.IP || compareIntf(r.Interface, intf) != 0 {
|
if r.Nexthop != nexthop.IP || compareIntf(r.Interface, intf) != 0 {
|
||||||
intf := "<nil>"
|
oldIntf, newIntf := "<nil>", "<nil>"
|
||||||
if r.Interface != nil {
|
if intf != nil {
|
||||||
intf = r.Interface.Name
|
oldIntf = intf.Name
|
||||||
}
|
}
|
||||||
log.Infof("network monitor: default route changed: %s via %s (%s)", r.Destination, r.Nexthop, intf)
|
if r.Interface != nil {
|
||||||
|
newIntf = r.Interface.Name
|
||||||
|
}
|
||||||
|
log.Infof("network monitor: default route changed: %s from %s (%s) to %s (%s)", r.Destination, nexthop.IP, oldIntf, nexthop.IP, newIntf)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -92,7 +92,7 @@ func toNetIP(a route.Addr) netip.Addr {
|
|||||||
case *route.Inet6Addr:
|
case *route.Inet6Addr:
|
||||||
ip := netip.AddrFrom16(t.IP)
|
ip := netip.AddrFrom16(t.IP)
|
||||||
if t.ZoneID != 0 {
|
if t.ZoneID != 0 {
|
||||||
ip.WithZone(strconv.Itoa(t.ZoneID))
|
ip = ip.WithZone(strconv.Itoa(t.ZoneID))
|
||||||
}
|
}
|
||||||
return ip
|
return ip
|
||||||
default:
|
default:
|
||||||
|
@ -356,7 +356,7 @@ func GetNextHop(ip netip.Addr) (Nexthop, error) {
|
|||||||
return Nexthop{}, fmt.Errorf("convert preferred source to address: %w", err)
|
return Nexthop{}, fmt.Errorf("convert preferred source to address: %w", err)
|
||||||
}
|
}
|
||||||
return Nexthop{
|
return Nexthop{
|
||||||
IP: addr.Unmap(),
|
IP: addr,
|
||||||
Intf: intf,
|
Intf: intf,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@ -380,12 +380,12 @@ func ipToAddr(ip net.IP, intf *net.Interface) (netip.Addr, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if intf != nil && (addr.IsLinkLocalMulticast() || addr.IsLinkLocalUnicast()) {
|
if intf != nil && (addr.IsLinkLocalMulticast() || addr.IsLinkLocalUnicast()) {
|
||||||
log.Tracef("Adding zone %s to address %s", intf.Name, addr)
|
zone := intf.Name
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
addr = addr.WithZone(strconv.Itoa(intf.Index))
|
zone = strconv.Itoa(intf.Index)
|
||||||
} else {
|
|
||||||
addr = addr.WithZone(intf.Name)
|
|
||||||
}
|
}
|
||||||
|
log.Tracef("Adding zone %s to address %s", zone, addr)
|
||||||
|
addr = addr.WithZone(zone)
|
||||||
}
|
}
|
||||||
|
|
||||||
return addr.Unmap(), nil
|
return addr.Unmap(), nil
|
||||||
|
@ -71,7 +71,6 @@ func (r *SysOps) addToRouteTable(prefix netip.Prefix, nexthop Nexthop) error {
|
|||||||
return fmt.Errorf("invalid zone: %w", err)
|
return fmt.Errorf("invalid zone: %w", err)
|
||||||
}
|
}
|
||||||
nexthop.Intf = &net.Interface{Index: zone}
|
nexthop.Intf = &net.Interface{Index: zone}
|
||||||
nexthop.IP.WithZone("")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return addRouteCmd(prefix, nexthop)
|
return addRouteCmd(prefix, nexthop)
|
||||||
@ -80,8 +79,8 @@ func (r *SysOps) addToRouteTable(prefix netip.Prefix, nexthop Nexthop) error {
|
|||||||
func (r *SysOps) removeFromRouteTable(prefix netip.Prefix, nexthop Nexthop) error {
|
func (r *SysOps) removeFromRouteTable(prefix netip.Prefix, nexthop Nexthop) error {
|
||||||
args := []string{"delete", prefix.String()}
|
args := []string{"delete", prefix.String()}
|
||||||
if nexthop.IP.IsValid() {
|
if nexthop.IP.IsValid() {
|
||||||
nexthop.IP.WithZone("")
|
ip := nexthop.IP.WithZone("")
|
||||||
args = append(args, nexthop.IP.Unmap().String())
|
args = append(args, ip.Unmap().String())
|
||||||
}
|
}
|
||||||
|
|
||||||
routeCmd := uspfilter.GetSystem32Command("route")
|
routeCmd := uspfilter.GetSystem32Command("route")
|
||||||
@ -146,6 +145,10 @@ func GetRoutes() ([]Route, error) {
|
|||||||
Index: int(entry.InterfaceIndex),
|
Index: int(entry.InterfaceIndex),
|
||||||
Name: entry.InterfaceAlias,
|
Name: entry.InterfaceAlias,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if nexthop.Is6() && (nexthop.IsLinkLocalUnicast() || nexthop.IsLinkLocalMulticast()) {
|
||||||
|
nexthop = nexthop.WithZone(strconv.Itoa(int(entry.InterfaceIndex)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
routes = append(routes, Route{
|
routes = append(routes, Route{
|
||||||
@ -189,7 +192,8 @@ func addRouteCmd(prefix netip.Prefix, nexthop Nexthop) error {
|
|||||||
args := []string{"add", prefix.String()}
|
args := []string{"add", prefix.String()}
|
||||||
|
|
||||||
if nexthop.IP.IsValid() {
|
if nexthop.IP.IsValid() {
|
||||||
args = append(args, nexthop.IP.Unmap().String())
|
ip := nexthop.IP.WithZone("")
|
||||||
|
args = append(args, ip.Unmap().String())
|
||||||
} else {
|
} else {
|
||||||
addr := "0.0.0.0"
|
addr := "0.0.0.0"
|
||||||
if prefix.Addr().Is6() {
|
if prefix.Addr().Is6() {
|
||||||
|
Loading…
Reference in New Issue
Block a user