diff --git a/config.go b/config.go index 6a9c0ca..bb57037 100644 --- a/config.go +++ b/config.go @@ -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"` diff --git a/routes.go b/routes.go index ff7bccd..ad9173d 100644 --- a/routes.go +++ b/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) diff --git a/srm.json b/srm.json index c17cbbe..7d06103 100644 --- a/srm.json +++ b/srm.json @@ -8,5 +8,8 @@ "timeout": 3, "interval": 10, "port": 8089, - "hotswap": false + "hotswap": false, + "protected":[ + "2.2.2.2/32" + ] }