| 20 | ) |
| 21 | |
| 22 | func (n *Nylon) ApplyCentralConfig(cfg *state.CentralCfg) (ApplyResult, error) { |
| 23 | err, next := cfg.Clone() |
| 24 | if err != nil { |
| 25 | return ApplyRejected, err |
| 26 | } |
| 27 | state.ExpandCentralConfig(next) |
| 28 | if err := state.CentralConfigValidator(next); err != nil { |
| 29 | return ApplyRejected, err |
| 30 | } |
| 31 | if !next.IsRouter(n.LocalCfg.Id) { |
| 32 | return ApplyRestartRequired, errors.New("local node is not a router in the new central config") |
| 33 | } |
| 34 | if reflect.DeepEqual(n.CentralCfg, next) { |
| 35 | return ApplyNoop, nil |
| 36 | } |
| 37 | |
| 38 | if err := n.reconcileRouterState(next); err != nil { |
| 39 | return ApplyRejected, err |
| 40 | } |
| 41 | n.reconcileAdvertisedPrefixes(next) |
| 42 | n.CentralCfg = *next |
| 43 | |
| 44 | if err := n.SyncWireGuard(); err != nil { |
| 45 | return ApplyRejected, err |
| 46 | } |
| 47 | if err := n.SyncSystemState(); err != nil { |
| 48 | return ApplyRejected, err |
| 49 | } |
| 50 | ComputeRoutes(n.RouterState, n) |
| 51 | |
| 52 | return ApplyApplied, nil |
| 53 | } |
| 54 | |
| 55 | func (n *Nylon) reconcileRouterState(next *state.CentralCfg) error { |
| 56 | desired := make(map[state.NodeId]state.RouterCfg) |