diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-02-20 21:15:38 -0800 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-02-21 06:04:41 -0800 |
commit | 7899f30f3a8875256b49c579953ca5cee3fe7eaf (patch) | |
tree | 231170bb830b5105a69c824e348a8ea4378cf429 /server | |
parent | 08df3e5fb185e7afe5f6d5b9c96de288866a0f2d (diff) |
rpki: simplify ROA data structure
This changes ROA data structure to enable one IP Prefix message to be
converted into one ROA data structure.
this is preparation for a patch that make roaClient not insert ROAs
into a global tree until it gets an End of Data message.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r-- | server/rpki.go | 95 |
1 files changed, 30 insertions, 65 deletions
diff --git a/server/rpki.go b/server/rpki.go index 12769ef7..aadb2fdd 100644 --- a/server/rpki.go +++ b/server/rpki.go @@ -43,26 +43,21 @@ type roa struct { bucket *roaBucket Src string MaxLen uint8 - AS []uint32 + AS uint32 } -func (r *roa) toApiStruct() []*api.ROA { - l := make([]*api.ROA, 0, len(r.AS)) - for _, as := range r.AS { - host, port, _ := net.SplitHostPort(r.Src) - a := &api.ROA{ - As: as, - Maxlen: uint32(r.MaxLen), - Prefixlen: uint32(r.bucket.PrefixLen), - Prefix: r.bucket.Prefix.String(), - Conf: &api.RPKIConf{ - Address: host, - RemotePort: port, - }, - } - l = append(l, a) +func (r *roa) toApiStruct() *api.ROA { + host, port, _ := net.SplitHostPort(r.Src) + return &api.ROA{ + As: r.AS, + Maxlen: uint32(r.MaxLen), + Prefixlen: uint32(r.bucket.PrefixLen), + Prefix: r.bucket.Prefix.String(), + Conf: &api.RPKIConf{ + Address: host, + RemotePort: port, + }, } - return l } type roas []*api.ROA @@ -246,19 +241,19 @@ func deleteROA(client *roaClient, family int, tree *radix.Tree, as uint32, prefi isDeleted := func() bool { if b != nil { bucket := b.(*roaBucket) + newEntries := make([]*roa, 0, len(bucket.entries)) for _, r := range bucket.entries { - if r.MaxLen == maxLen && r.Src == host { - for idx, a := range r.AS { - if a == as { - r.AS = append(r.AS[:idx], r.AS[idx+1:]...) - if len(bucket.entries) == 0 { - tree.Delete(key) - } - return true - } - } + if r.MaxLen != maxLen || r.Src != host || r.AS != as { + newEntries = append(newEntries, r) } } + if len(newEntries) != len(bucket.entries) { + bucket.entries = newEntries + if len(newEntries) == 0 { + tree.Delete(key) + } + return true + } } return false }() @@ -294,7 +289,7 @@ func addROA(client *roaClient, family int, tree *radix.Tree, as uint32, prefix [ copy(p, prefix) r := &roa{ - AS: []uint32{as}, + AS: as, MaxLen: maxLen, Src: host, } @@ -324,22 +319,15 @@ func addROA(client *roaClient, family int, tree *radix.Tree, as uint32, prefix [ } for _, r := range bucket.entries { - if r.MaxLen == maxLen && r.Src == host { - // we already have? - for _, a := range r.AS { - if a == as { - return - } - } - r.AS = append(r.AS, as) - client.records[family]++ + if r.MaxLen == maxLen && r.Src == host && r.AS == as { + // we already have return } } r := &roa{ bucket: bucket, MaxLen: maxLen, - AS: []uint32{as}, + AS: as, Src: host, } bucket.entries = append(bucket.entries, r) @@ -463,20 +451,7 @@ func (c *roaManager) handleGRPC(grpcReq *GrpcRequest) { b, _ := v.(*roaBucket) var roaList roas for _, r := range b.entries { - for _, as := range r.AS { - host, port, _ := net.SplitHostPort(r.Src) - roa := &api.ROA{ - As: as, - Maxlen: uint32(r.MaxLen), - Prefixlen: uint32(b.PrefixLen), - Prefix: b.Prefix.String(), - Conf: &api.RPKIConf{ - Address: host, - RemotePort: port, - }, - } - roaList = append(roaList, roa) - } + roaList = append(roaList, r.toApiStruct()) } sort.Sort(roaList) for _, roa := range roaList { @@ -526,18 +501,8 @@ func validatePath(ownAs uint32, tree *radix.Tree, cidr string, asPath *bgp.PathA if prefixLen > r.MaxLen { continue } - - y := func(x uint32, asList []uint32) bool { - for _, as := range asList { - if x == as { - return true - } - } - return false - }(as, r.AS) - - if y { - return config.RPKI_VALIDATION_RESULT_TYPE_VALID, []*roa{r} + if r.AS == as { + result = config.RPKI_VALIDATION_RESULT_TYPE_VALID } roaList = append(roaList, r) } @@ -559,7 +524,7 @@ func (c *roaManager) validate(pathList []*table.Path, isMonitor bool) []*api.ROA apiRoaList := func() []*api.ROA { apiRoaList := make([]*api.ROA, 0) for _, r := range roaList { - apiRoaList = append(apiRoaList, r.toApiStruct()...) + apiRoaList = append(apiRoaList, r.toApiStruct()) } return apiRoaList }() |