From 9c0e840c09e5e1e3344b309c6872ab22bb2b2860 Mon Sep 17 00:00:00 2001 From: kirillius Date: Wed, 15 Jul 2026 16:44:28 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=84=D0=B8=D1=87=D0=B0=20=D0=B7=D0=B0=D1=89?= =?UTF-8?q?=D0=B8=D1=82=D1=8B=20=D0=BC=D0=B0=D1=80=D1=88=D1=80=D1=83=D1=82?= =?UTF-8?q?=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.go | 1 + routes.go | 14 +++++++++----- srm.json | 5 ++++- 3 files changed, 14 insertions(+), 6 deletions(-) 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" + ] }