добавлена фича защиты маршрутов
This commit is contained in:
parent
81083c61ac
commit
9c0e840c09
|
|
@ -13,6 +13,7 @@ type Gateway struct {
|
|||
type Config struct {
|
||||
Controller string `json:"controller"`
|
||||
Gateway []Gateway `json:"gateway"`
|
||||
Protected []string `json:"protected"`
|
||||
Metric int `json:"metric"`
|
||||
Timeout int `json:"timeout"`
|
||||
Interval int `json:"interval"`
|
||||
|
|
|
|||
14
routes.go
14
routes.go
|
|
@ -103,12 +103,12 @@ func hotswapUpdate(cfg *Config, gatewayStates map[string]bool, subnets []string)
|
|||
}
|
||||
if !gatewayStates[name] {
|
||||
log.Printf("Gateway %q is down, deleting route %s via %s", name, r.Subnet, r.Gateway)
|
||||
delRoute(r.Subnet, r.Gateway)
|
||||
delRoute(r.Subnet, r.Gateway, cfg.Protected)
|
||||
continue
|
||||
}
|
||||
if !subnetsContains(subnets, r.Subnet) {
|
||||
log.Printf("Subnet %s not in subnets list, deleting route via %s", r.Subnet, r.Gateway)
|
||||
delRoute(r.Subnet, r.Gateway)
|
||||
delRoute(r.Subnet, r.Gateway, cfg.Protected)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -150,11 +150,11 @@ func failoverUpdate(cfg *Config, gatewayStates map[string]bool, subnets []string
|
|||
continue
|
||||
}
|
||||
log.Printf("Subnet %s not in subnets, deleting primary route via %s", r.Subnet, r.Gateway)
|
||||
delRoute(r.Subnet, r.Gateway)
|
||||
delRoute(r.Subnet, r.Gateway, cfg.Protected)
|
||||
continue
|
||||
}
|
||||
log.Printf("Deleting route %s via %s (gateway %q)", r.Subnet, r.Gateway, name)
|
||||
delRoute(r.Subnet, r.Gateway)
|
||||
delRoute(r.Subnet, r.Gateway, cfg.Protected)
|
||||
}
|
||||
|
||||
if primaryGW == nil {
|
||||
|
|
@ -171,7 +171,11 @@ func failoverUpdate(cfg *Config, gatewayStates map[string]bool, subnets []string
|
|||
}
|
||||
}
|
||||
|
||||
func delRoute(subnet, gw string) {
|
||||
func delRoute(subnet, gw string, protected []string) {
|
||||
if subnetsContains(protected, subnet) {
|
||||
log.Printf("Route %s is protected, skipping delete", subnet)
|
||||
return
|
||||
}
|
||||
cmd := exec.Command("ip", "route", "del", subnet, "via", gw)
|
||||
if err := cmd.Run(); err != nil {
|
||||
log.Printf("Failed to delete route %s via %s: %v", subnet, gw, err)
|
||||
|
|
|
|||
Loading…
Reference in New Issue