add entrypoint for router handler

This commit is contained in:
ginuerzh
2025-02-08 23:07:54 +08:00
parent 9cd03b6b59
commit 08ad260606
14 changed files with 259 additions and 122 deletions
+5 -8
View File
@@ -202,17 +202,19 @@ func (p *localRouter) parseRoutes(r io.Reader) (routes []*router.Route, err erro
return
}
func (p *localRouter) GetRoute(ctx context.Context, dst net.IP, opts ...router.Option) *router.Route {
if dst == nil || p == nil {
func (p *localRouter) GetRoute(ctx context.Context, dst string, opts ...router.Option) *router.Route {
if dst == "" || p == nil {
return nil
}
dstIP := net.ParseIP(dst)
p.mu.RLock()
routes := p.routes
p.mu.RUnlock()
for _, route := range routes {
if route.Net != nil && route.Net.Contains(dst) {
if route.Dst == dst || route.Net != nil && route.Net.Contains(dstIP) {
return route
}
}
@@ -255,11 +257,6 @@ func ParseRoute(dst string, gateway string) *router.Route {
}
_, ipNet, _ := net.ParseCIDR(dst)
gw := net.ParseIP(gateway)
if gw == nil {
return nil
}
return &router.Route{
Net: ipNet,
Dst: dst,