diff options
author | Eiichrio Watanabe <a16tochjp@gmail.com> | 2017-01-17 15:39:29 +0900 |
---|---|---|
committer | Eiichrio Watanabe <a16tochjp@gmail.com> | 2017-01-17 15:39:29 +0900 |
commit | 0624201bb9de570fcd327359f5100467505953fb (patch) | |
tree | f192bea6af52d92c934bdaab12233061a4b11bb1 /server/rpki.go | |
parent | 64a371859477825690999de2e1c801f4af7d78d1 (diff) |
server: add feature to return matched RoaBucket in ValidatePath() for library usage
Diffstat (limited to 'server/rpki.go')
-rw-r--r-- | server/rpki.go | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/server/rpki.go b/server/rpki.go index 7851c397..1d95642b 100644 --- a/server/rpki.go +++ b/server/rpki.go @@ -494,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, *RoaBucket) { var as uint32 if asPath == nil || len(asPath.Value) == 0 { @@ -511,7 +511,7 @@ func ValidatePath(ownAs uint32, tree *radix.Tree, cidr string, asPath *bgp.PathA case bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET, bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ: as = ownAs default: - return config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND + return config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND, nil } } _, n, _ := net.ParseCIDR(cidr) @@ -520,12 +520,13 @@ func ValidatePath(ownAs uint32, tree *radix.Tree, cidr string, asPath *bgp.PathA key := table.IpToRadixkey(n.IP, prefixLen) _, b, _ := tree.LongestPrefix(key) if b == nil { - return config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND + return config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND, nil } result := config.RPKI_VALIDATION_RESULT_TYPE_INVALID + var bucket *RoaBucket 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 @@ -535,7 +536,7 @@ func ValidatePath(ownAs uint32, tree *radix.Tree, cidr string, asPath *bgp.PathA return false }) tree.WalkPath(key, fn) - return result + return result, bucket } func (c *roaManager) validate(pathList []*table.Path) { @@ -549,7 +550,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)) } } |