Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions state/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func CentralConfigValidator(cfg *CentralCfg) error {
routerPrefixes := make(map[netip.Prefix]struct{})
for _, p := range router.Prefixes {
if _, ok := routerPrefixes[p.GetPrefix()]; ok {
return fmt.Errorf("router %s has duplicate prefix %s", router.Id, p)
return fmt.Errorf("router %s has duplicate prefix %s", router.Id, p.GetPrefix())
}
routerPrefixes[p.GetPrefix()] = struct{}{}
}
Expand All @@ -129,7 +129,7 @@ func CentralConfigValidator(cfg *CentralCfg) error {
client := cfg.GetClient(peer)
for _, cp := range client.Prefixes {
if _, ok := routerPrefixes[cp.GetPrefix()]; ok {
return fmt.Errorf("router %s has duplicate prefix %s (provided by client %s)", router.Id, cp, client.Id)
return fmt.Errorf("router %s has duplicate prefix %s (provided by client %s)", router.Id, cp.GetPrefix(), client.Id)
}
routerPrefixes[cp.GetPrefix()] = struct{}{}
}
Expand Down
18 changes: 18 additions & 0 deletions state/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,21 @@ func TestCentralConfigValidator_AnycastPrefix(t *testing.T) {
}
assert.NoError(t, CentralConfigValidator(cfg))
}

func TestCentralConfigValidator_DuplicatePrefixMessage(t *testing.T) {
prefix := PrefixHealthWrapper{&StaticPrefixHealth{Prefix: netip.MustParsePrefix("10.5.0.0/24")}}
cfg := CentralCfg{Routers: []RouterCfg{{NodeCfg: NodeCfg{Id: "r1", Prefixes: []PrefixHealthWrapper{prefix, prefix}}}}}
assert.EqualError(t, CentralConfigValidator(&cfg), "router r1 has duplicate prefix 10.5.0.0/24")

addr := []netip.Addr{netip.MustParseAddr("10.0.0.5")}
cfg = CentralCfg{
Routers: []RouterCfg{{NodeCfg: NodeCfg{Id: "r1"}}},
Clients: []ClientCfg{
{NodeCfg: NodeCfg{Id: "phone", Addresses: addr}},
{NodeCfg: NodeCfg{Id: "laptop", Addresses: addr}},
},
Graph: []string{"r1, phone, laptop"},
}
ExpandCentralConfig(&cfg)
assert.ErrorContains(t, CentralConfigValidator(&cfg), "router r1 has duplicate prefix 10.0.0.5/32 (provided by client")
}
Loading