diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-07-28 20:47:01 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-07-28 20:47:01 +0900 |
commit | c3560d1224f7759455b6916843341b20355dbfe5 (patch) | |
tree | b227d666143a6e7feade9267f4a993f189615824 /server/rpki.go | |
parent | 70251f7175f1b30a9ed58d240b7e04419c91d601 (diff) |
move gRPC-related code for RPKI to grpc_server.go
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server/rpki.go')
-rw-r--r-- | server/rpki.go | 162 |
1 files changed, 78 insertions, 84 deletions
diff --git a/server/rpki.go b/server/rpki.go index fb675314..c91ee7c0 100644 --- a/server/rpki.go +++ b/server/rpki.go @@ -423,102 +423,96 @@ func (c *roaManager) handleRTRMsg(client *roaClient, state *config.RpkiServerSta } } -func (c *roaManager) handleGRPC(grpcReq *GrpcRequest) *GrpcResponse { - switch grpcReq.RequestType { - case REQ_GET_RPKI: - f := func(tree *radix.Tree) (map[string]uint32, map[string]uint32) { - records := make(map[string]uint32) - prefixes := make(map[string]uint32) +func (c *roaManager) GetServers() []*config.RpkiServer { + f := func(tree *radix.Tree) (map[string]uint32, map[string]uint32) { + records := make(map[string]uint32) + prefixes := make(map[string]uint32) - tree.Walk(func(s string, v interface{}) bool { - b, _ := v.(*roaBucket) - tmpRecords := make(map[string]uint32) - for _, roa := range b.entries { - tmpRecords[roa.Src]++ - } + tree.Walk(func(s string, v interface{}) bool { + b, _ := v.(*roaBucket) + tmpRecords := make(map[string]uint32) + for _, roa := range b.entries { + tmpRecords[roa.Src]++ + } - for src, r := range tmpRecords { - if r > 0 { - records[src] += r - prefixes[src]++ - } + for src, r := range tmpRecords { + if r > 0 { + records[src] += r + prefixes[src]++ } - return false - }) - return records, prefixes - } + } + return false + }) + return records, prefixes + } - recordsV4, prefixesV4 := f(c.Roas[bgp.RF_IPv4_UC]) - recordsV6, prefixesV6 := f(c.Roas[bgp.RF_IPv6_UC]) + recordsV4, prefixesV4 := f(c.Roas[bgp.RF_IPv4_UC]) + recordsV6, prefixesV6 := f(c.Roas[bgp.RF_IPv6_UC]) - l := make([]*config.RpkiServer, 0, len(c.clientMap)) - for _, client := range c.clientMap { - state := &client.state + l := make([]*config.RpkiServer, 0, len(c.clientMap)) + for _, client := range c.clientMap { + state := &client.state - addr, port, _ := net.SplitHostPort(client.host) - l = append(l, &config.RpkiServer{ - Config: config.RpkiServerConfig{ - Address: addr, - Port: func() uint32 { p, _ := strconv.Atoi(port); return uint32(p) }(), - }, - State: client.state, - }) + addr, port, _ := net.SplitHostPort(client.host) + l = append(l, &config.RpkiServer{ + Config: config.RpkiServerConfig{ + Address: addr, + Port: func() uint32 { p, _ := strconv.Atoi(port); return uint32(p) }(), + }, + State: client.state, + }) - if client.conn == nil { - state.Up = false - } else { - state.Up = true - } - f := func(m map[string]uint32, key string) uint32 { - if r, ok := m[key]; ok { - return r - } - return 0 - } - state.RecordsV4 = f(recordsV4, client.host) - state.RecordsV6 = f(recordsV6, client.host) - state.PrefixesV4 = f(prefixesV4, client.host) - state.PrefixesV6 = f(prefixesV6, client.host) - state.SerialNumber = client.serialNumber - } - return &GrpcResponse{ - Data: l, + if client.conn == nil { + state.Up = false + } else { + state.Up = true } - case REQ_ROA: - if len(c.clientMap) == 0 { - return &GrpcResponse{ - ResponseErr: fmt.Errorf("RPKI server isn't configured."), + f := func(m map[string]uint32, key string) uint32 { + if r, ok := m[key]; ok { + return r } + return 0 } - var rfList []bgp.RouteFamily - switch grpcReq.RouteFamily { - case bgp.RF_IPv4_UC: - rfList = []bgp.RouteFamily{bgp.RF_IPv4_UC} - case bgp.RF_IPv6_UC: - rfList = []bgp.RouteFamily{bgp.RF_IPv6_UC} - default: - rfList = []bgp.RouteFamily{bgp.RF_IPv4_UC, bgp.RF_IPv6_UC} - } - l := make([]*ROA, 0) - for _, rf := range rfList { - if tree, ok := c.Roas[rf]; ok { - tree.Walk(func(s string, v interface{}) bool { - b, _ := v.(*roaBucket) - var roaList roas - for _, r := range b.entries { - roaList = append(roaList, r) - } - sort.Sort(roaList) - for _, roa := range roaList { - l = append(l, roa) - } - return false - }) - } + state.RecordsV4 = f(recordsV4, client.host) + state.RecordsV6 = f(recordsV6, client.host) + state.PrefixesV4 = f(prefixesV4, client.host) + state.PrefixesV6 = f(prefixesV6, client.host) + state.SerialNumber = client.serialNumber + } + return l +} + +func (c *roaManager) GetRoa(family bgp.RouteFamily) ([]*ROA, error) { + if len(c.clientMap) == 0 { + return []*ROA{}, fmt.Errorf("RPKI server isn't configured.") + } + var rfList []bgp.RouteFamily + switch family { + case bgp.RF_IPv4_UC: + rfList = []bgp.RouteFamily{bgp.RF_IPv4_UC} + case bgp.RF_IPv6_UC: + rfList = []bgp.RouteFamily{bgp.RF_IPv6_UC} + default: + rfList = []bgp.RouteFamily{bgp.RF_IPv4_UC, bgp.RF_IPv6_UC} + } + l := make([]*ROA, 0) + for _, rf := range rfList { + if tree, ok := c.Roas[rf]; ok { + tree.Walk(func(s string, v interface{}) bool { + b, _ := v.(*roaBucket) + var roaList roas + for _, r := range b.entries { + roaList = append(roaList, r) + } + sort.Sort(roaList) + for _, roa := range roaList { + l = append(l, roa) + } + return false + }) } - return &GrpcResponse{Data: l} } - return nil + return l, nil } func validatePath(ownAs uint32, tree *radix.Tree, cidr string, asPath *bgp.PathAttributeAsPath) config.RpkiValidationResultType { |