diff options
author | Eiichrio Watanabe <a16tochjp@gmail.com> | 2017-01-17 15:34:15 +0900 |
---|---|---|
committer | Eiichrio Watanabe <a16tochjp@gmail.com> | 2017-01-17 15:34:15 +0900 |
commit | 64a371859477825690999de2e1c801f4af7d78d1 (patch) | |
tree | d905673943e3f6d3bd5d4672202b1ae1b226c047 /server/rpki.go | |
parent | 7babf94567da75d09d7df5ce1a0d7433a5f04c96 (diff) |
server: export some rpki property for library usage
Diffstat (limited to 'server/rpki.go')
-rw-r--r-- | server/rpki.go | 26 |
1 files changed, 15 insertions, 11 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)) } } |