MCPcopy Create free account
hub / github.com/encodeous/nylon / syncSystemRoutes

Method syncSystemRoutes

core/nylon_wireguard.go:283–308  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

281}
282
283func (n *Nylon) syncSystemRoutes() error {
284 newEntries := n.ComputeSysRouteTable()
285 oldEntries := n.AppliedSystem.Routes
286 for _, oldEntry := range oldEntries {
287 if !slices.Contains(newEntries, oldEntry) {
288 // uninstall route
289 n.Log.Debug("removing old route", "prefix", oldEntry.String())
290 err := RemoveRoute(n.Log, n.Tun, n.Interface, oldEntry)
291 if err != nil {
292 n.Log.Error("failed to remove route", "err", err)
293 }
294 }
295 }
296 for _, newEntry := range newEntries {
297 if !slices.Contains(oldEntries, newEntry) {
298 // install route
299 n.Log.Debug("installing new route", "prefix", newEntry.String())
300 err := ConfigureRoute(n.Log, n.Tun, n.Interface, newEntry)
301 if err != nil {
302 n.Log.Error("failed to configure route", "err", err)
303 }
304 }
305 }
306 n.AppliedSystem.Routes = slices.Clone(newEntries)
307 return nil
308}

Callers 1

SyncSystemStateMethod · 0.95

Calls 6

ComputeSysRouteTableMethod · 0.95
CloneMethod · 0.80
RemoveRouteFunction · 0.70
ConfigureRouteFunction · 0.70
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected