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