add router handler & connector

This commit is contained in:
ginuerzh
2025-02-07 15:44:31 +08:00
parent 379d9a73ad
commit 355c72477a
25 changed files with 1265 additions and 110 deletions
+3 -1
View File
@@ -252,7 +252,9 @@ type SDConfig struct {
}
type RouterRouteConfig struct {
Net string `json:"net"`
// Deprecated: use dst instead
Net string `yaml:",omitempty" json:"net,omitempty"`
Dst string `yaml:",omitempty" json:"dst,omitempty"`
Gateway string `json:"gateway"`
}
+11 -5
View File
@@ -46,17 +46,23 @@ func ParseRouter(cfg *config.RouterConfig) router.Router {
var routes []*router.Route
for _, route := range cfg.Routes {
_, ipNet, _ := net.ParseCIDR(route.Net)
if ipNet == nil {
continue
dst := route.Dst
if dst != "" {
_, ipNet, _ = net.ParseCIDR(dst)
} else {
if ipNet != nil {
dst = ipNet.String()
}
}
gw := net.ParseIP(route.Gateway)
if gw == nil {
if dst == "" || route.Gateway == "" {
continue
}
routes = append(routes, &router.Route{
Net: ipNet,
Gateway: gw,
Dst: dst,
Gateway: route.Gateway,
})
}
opts := []xrouter.Option{