diff options
-rw-r--r-- | server/rpki.go | 26 | ||||
-rw-r--r-- | server/rpki_test.go | 2 |
2 files changed, 16 insertions, 12 deletions
diff --git a/server/rpki.go b/server/rpki.go index ae5e900a..7851c397 100644 --- a/server/rpki.go +++ b/server/rpki.go @@ -37,11 +37,15 @@ func before(a, b uint32) bool { return int32(a-b) < 0 } -type roaBucket struct { +type RoaBucket struct { Prefix *table.IPPrefix entries []*table.ROA } +func (r *RoaBucket) GetEntries() []*table.ROA { + return r.entries +} + type roas []*table.ROA func (r roas) Len() int { @@ -145,7 +149,7 @@ func (m *roaManager) deleteAllROA(network string) { for _, tree := range m.Roas { deleteKeys := make([]string, 0, tree.Len()) tree.Walk(func(s string, v interface{}) bool { - b, _ := v.(*roaBucket) + b, _ := v.(*RoaBucket) newEntries := make([]*table.ROA, 0, len(b.entries)) for _, r := range b.entries { if r.Src != network { @@ -280,7 +284,7 @@ func (m *roaManager) deleteROA(roa *table.ROA) { tree, key := m.roa2tree(roa) b, _ := tree.Get(key) if b != nil { - bucket := b.(*roaBucket) + bucket := b.(*RoaBucket) newEntries := make([]*table.ROA, 0, len(bucket.entries)) for _, r := range bucket.entries { if !r.Equal(roa) { @@ -307,15 +311,15 @@ func (m *roaManager) deleteROA(roa *table.ROA) { func (m *roaManager) addROA(roa *table.ROA) { tree, key := m.roa2tree(roa) b, _ := tree.Get(key) - var bucket *roaBucket + var bucket *RoaBucket if b == nil { - bucket = &roaBucket{ + bucket = &RoaBucket{ Prefix: roa.Prefix, entries: make([]*table.ROA, 0), } tree.Insert(key, bucket) } else { - bucket = b.(*roaBucket) + bucket = b.(*RoaBucket) for _, r := range bucket.entries { if r.Equal(roa) { // we already have the same one @@ -404,7 +408,7 @@ func (c *roaManager) GetServers() []*config.RpkiServer { prefixes := make(map[string]uint32) tree.Walk(func(s string, v interface{}) bool { - b, _ := v.(*roaBucket) + b, _ := v.(*RoaBucket) tmpRecords := make(map[string]uint32) for _, roa := range b.entries { tmpRecords[roa.Src]++ @@ -474,7 +478,7 @@ func (c *roaManager) GetRoa(family bgp.RouteFamily) ([]*table.ROA, error) { for _, rf := range rfList { if tree, ok := c.Roas[rf]; ok { tree.Walk(func(s string, v interface{}) bool { - b, _ := v.(*roaBucket) + b, _ := v.(*RoaBucket) var roaList roas for _, r := range b.entries { roaList = append(roaList, r) @@ -490,7 +494,7 @@ func (c *roaManager) GetRoa(family bgp.RouteFamily) ([]*table.ROA, error) { return l, nil } -func validatePath(ownAs uint32, tree *radix.Tree, cidr string, asPath *bgp.PathAttributeAsPath) config.RpkiValidationResultType { +func ValidatePath(ownAs uint32, tree *radix.Tree, cidr string, asPath *bgp.PathAttributeAsPath) config.RpkiValidationResultType { var as uint32 if asPath == nil || len(asPath.Value) == 0 { @@ -521,7 +525,7 @@ func validatePath(ownAs uint32, tree *radix.Tree, cidr string, asPath *bgp.PathA result := config.RPKI_VALIDATION_RESULT_TYPE_INVALID fn := radix.WalkFn(func(k string, v interface{}) bool { - bucket, _ := v.(*roaBucket) + bucket, _ := v.(*RoaBucket) for _, r := range bucket.entries { if prefixLen <= r.MaxLen && r.AS != 0 && r.AS == as { result = config.RPKI_VALIDATION_RESULT_TYPE_VALID @@ -545,7 +549,7 @@ func (c *roaManager) validate(pathList []*table.Path) { continue } if tree, ok := c.Roas[path.GetRouteFamily()]; ok { - r := validatePath(c.AS, tree, path.GetNlri().String(), path.GetAsPath()) + r := ValidatePath(c.AS, tree, path.GetNlri().String(), path.GetAsPath()) path.SetValidation(config.RpkiValidationResultType(r)) } } diff --git a/server/rpki_test.go b/server/rpki_test.go index fd29b04f..3273d9dc 100644 --- a/server/rpki_test.go +++ b/server/rpki_test.go @@ -55,7 +55,7 @@ func strToASParam(str string) *bgp.PathAttributeAsPath { } func validateOne(tree *radix.Tree, cidr, aspathStr string) config.RpkiValidationResultType { - return validatePath(65500, tree, cidr, strToASParam(aspathStr)) + return ValidatePath(65500, tree, cidr, strToASParam(aspathStr)) } func TestValidate0(t *testing.T) { |