mirror of
https://github.com/sigcn/pg.git
synced 2025-10-09 20:20:23 +08:00
netlink: fix RouteUpdate on win and linux
This commit is contained in:
@@ -3,6 +3,7 @@ package netlink
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"slices"
|
||||
|
||||
"github.com/vishvananda/netlink"
|
||||
)
|
||||
@@ -29,14 +30,13 @@ func RouteSubscribe(ctx context.Context, ch chan<- RouteUpdate) error {
|
||||
Dst: e.Dst,
|
||||
Via: e.Gw,
|
||||
}
|
||||
if e.Type == 24 {
|
||||
ru.Type = 1
|
||||
} else if e.Type == 25 {
|
||||
ru.Type = 2
|
||||
} else {
|
||||
if !slices.Contains([]uint16{24, 25}, e.Type) {
|
||||
slog.Debug("DropUnsupportRouteEvent")
|
||||
continue
|
||||
}
|
||||
if e.Type == 24 {
|
||||
ru.New = true
|
||||
}
|
||||
ch <- ru
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ func RouteSubscribe(ctx context.Context, ch chan<- RouteUpdate) error {
|
||||
cb, err := winipcfg.RegisterRouteChangeCallback(func(notificationType winipcfg.MibNotificationType, route *winipcfg.MibIPforwardRow2) {
|
||||
dst := route.DestinationPrefix.Prefix()
|
||||
ch <- RouteUpdate{
|
||||
Type: uint16(notificationType),
|
||||
New: notificationType == 1,
|
||||
Dst: &net.IPNet{IP: net.IP(dst.Addr().AsSlice()), Mask: net.CIDRMask(dst.Bits(), dst.Addr().BitLen())},
|
||||
Via: net.IP(route.NextHop.Addr().AsSlice()),
|
||||
}
|
||||
|
Reference in New Issue
Block a user