| 75 | } |
| 76 | |
| 77 | func CentralConfigValidator(cfg *CentralCfg) error { |
| 78 | nodes := make([]string, 0) |
| 79 | for _, node := range cfg.Routers { |
| 80 | err := NameValidator(string(node.Id)) |
| 81 | if err != nil { |
| 82 | return err |
| 83 | } |
| 84 | if slices.Contains(nodes, string(node.Id)) { |
| 85 | return fmt.Errorf("duplicate router id %s", node.Id) |
| 86 | } |
| 87 | nodes = append(nodes, string(node.Id)) |
| 88 | } |
| 89 | for _, node := range cfg.Clients { |
| 90 | err := NameValidator(string(node.Id)) |
| 91 | if err != nil { |
| 92 | return err |
| 93 | } |
| 94 | if slices.Contains(nodes, string(node.Id)) { |
| 95 | return fmt.Errorf("duplicate client id %s", node.Id) |
| 96 | } |
| 97 | nodes = append(nodes, string(node.Id)) |
| 98 | } |
| 99 | _, err := ParseGraph(cfg.Graph, nodes) |
| 100 | if err != nil { |
| 101 | return err |
| 102 | } |
| 103 | |
| 104 | // ensure each node contains unique prefixes (anycast routing allows duplicate prefixes across nodes) |
| 105 | for _, router := range cfg.Routers { |
| 106 | routerPrefixes := make(map[netip.Prefix]struct{}) |
| 107 | for _, p := range router.Prefixes { |
| 108 | if _, ok := routerPrefixes[p.GetPrefix()]; ok { |
| 109 | return fmt.Errorf("router %s has duplicate prefix %s", router.Id, p) |
| 110 | } |
| 111 | routerPrefixes[p.GetPrefix()] = struct{}{} |
| 112 | } |
| 113 | for _, peer := range cfg.GetPeers(router.Id) { |
| 114 | if cfg.IsClient(peer) { |
| 115 | client := cfg.GetClient(peer) |
| 116 | for _, cp := range client.Prefixes { |
| 117 | if _, ok := routerPrefixes[cp.GetPrefix()]; ok { |
| 118 | return fmt.Errorf("router %s has duplicate prefix %s (provided by client %s)", router.Id, cp, client.Id) |
| 119 | } |
| 120 | routerPrefixes[cp.GetPrefix()] = struct{}{} |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | if cfg.Dist != nil { |
| 127 | // validate repos |
| 128 | for _, repo := range cfg.Dist.Repos { |
| 129 | _, err := url.Parse(repo) |
| 130 | if err != nil { |
| 131 | return err |
| 132 | } |
| 133 | } |
| 134 | } |