summaryrefslogtreecommitdiffhomepage
path: root/server/rpki.go
diff options
context:
space:
mode:
Diffstat (limited to 'server/rpki.go')
-rw-r--r--server/rpki.go87
1 files changed, 53 insertions, 34 deletions
diff --git a/server/rpki.go b/server/rpki.go
index af2c4bb2..1463fd9b 100644
--- a/server/rpki.go
+++ b/server/rpki.go
@@ -77,9 +77,9 @@ func (r *ROA) Equal(roa *ROA) bool {
return false
}
-func (r *ROA) toApiStruct() *api.ROA {
+func (r *ROA) toApiStruct() *api.Roa {
host, port, _ := net.SplitHostPort(r.Src)
- return &api.ROA{
+ return &api.Roa{
As: r.AS,
Maxlen: uint32(r.MaxLen),
Prefixlen: uint32(r.Prefix.Length),
@@ -91,7 +91,7 @@ func (r *ROA) toApiStruct() *api.ROA {
}
}
-type roas []*api.ROA
+type roas []*api.Roa
func (r roas) Len() int {
return len(r)
@@ -214,20 +214,45 @@ func (m *roaManager) deleteAllROA(network string) {
}
}
-func (m *roaManager) operate(op api.Operation, address string) error {
+func (m *roaManager) Enable(address string) error {
for network, client := range m.clientMap {
add, _, _ := net.SplitHostPort(network)
if add == address {
- switch op {
- case api.Operation_ENABLE:
- client.enable(client.serialNumber)
- case api.Operation_DISABLE:
- case api.Operation_RESET:
- client.reset()
- case api.Operation_SOFTRESET:
- client.softReset()
- m.deleteAllROA(network)
- }
+ client.enable(client.serialNumber)
+ return nil
+ }
+ }
+ return fmt.Errorf("roa server not found %s", address)
+}
+
+func (m *roaManager) Disable(address string) error {
+ for network, client := range m.clientMap {
+ add, _, _ := net.SplitHostPort(network)
+ if add == address {
+ client.reset()
+ return nil
+ }
+ }
+ return fmt.Errorf("roa server not found %s", address)
+}
+
+func (m *roaManager) Reset(address string) error {
+ for network, client := range m.clientMap {
+ add, _, _ := net.SplitHostPort(network)
+ if add == address {
+ client.reset()
+ return nil
+ }
+ }
+ return fmt.Errorf("roa server not found %s", address)
+}
+
+func (m *roaManager) SoftReset(address string) error {
+ for network, client := range m.clientMap {
+ add, _, _ := net.SplitHostPort(network)
+ if add == address {
+ client.softReset()
+ m.deleteAllROA(network)
return nil
}
}
@@ -412,11 +437,9 @@ func (c *roaManager) handleRTRMsg(client *roaClient, state *config.RpkiServerSta
}
}
-func (c *roaManager) handleGRPC(grpcReq *GrpcRequest) {
+func (c *roaManager) handleGRPC(grpcReq *GrpcRequest) *GrpcResponse {
switch grpcReq.RequestType {
- case REQ_RPKI:
- results := make([]*GrpcResponse, 0)
-
+ 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)
@@ -442,6 +465,7 @@ func (c *roaManager) handleGRPC(grpcReq *GrpcRequest) {
recordsV4, prefixesV4 := f(c.Roas[bgp.RF_IPv4_UC])
recordsV6, prefixesV6 := f(c.Roas[bgp.RF_IPv6_UC])
+ l := make([]*api.Rpki, 0, len(c.clientMap))
for _, client := range c.clientMap {
state := client.state
addr, port, _ := net.SplitHostPort(client.host)
@@ -459,7 +483,7 @@ func (c *roaManager) handleGRPC(grpcReq *GrpcRequest) {
return 0
}
- rpki := &api.RPKI{
+ rpki := &api.Rpki{
Conf: &api.RPKIConf{
Address: addr,
RemotePort: port,
@@ -484,20 +508,16 @@ func (c *roaManager) handleGRPC(grpcReq *GrpcRequest) {
ResetQuery: sent.ResetQuery,
},
}
- result := &GrpcResponse{}
- result.Data = rpki
- results = append(results, result)
+ l = append(l, rpki)
}
- go sendMultipleResponses(grpcReq, results)
-
+ return &GrpcResponse{Data: &api.GetRpkiResponse{Servers: l}}
case REQ_ROA:
if len(c.clientMap) == 0 {
- result := &GrpcResponse{}
- result.ResponseErr = fmt.Errorf("RPKI server isn't configured.")
- grpcReq.ResponseCh <- result
- break
+ return &GrpcResponse{
+ ResponseErr: fmt.Errorf("RPKI server isn't configured."),
+ Data: &api.GetRoaResponse{},
+ }
}
- results := make([]*GrpcResponse, 0)
var rfList []bgp.RouteFamily
switch grpcReq.RouteFamily {
case bgp.RF_IPv4_UC:
@@ -507,6 +527,7 @@ func (c *roaManager) handleGRPC(grpcReq *GrpcRequest) {
default:
rfList = []bgp.RouteFamily{bgp.RF_IPv4_UC, bgp.RF_IPv6_UC}
}
+ l := make([]*api.Roa, 0)
for _, rf := range rfList {
if tree, ok := c.Roas[rf]; ok {
tree.Walk(func(s string, v interface{}) bool {
@@ -517,17 +538,15 @@ func (c *roaManager) handleGRPC(grpcReq *GrpcRequest) {
}
sort.Sort(roaList)
for _, roa := range roaList {
- result := &GrpcResponse{
- Data: roa,
- }
- results = append(results, result)
+ l = append(l, roa)
}
return false
})
}
}
- go sendMultipleResponses(grpcReq, results)
+ return &GrpcResponse{Data: &api.GetRoaResponse{Roas: l}}
}
+ return nil
}
func validatePath(ownAs uint32, tree *radix.Tree, cidr string, asPath *bgp.PathAttributeAsPath) config.RpkiValidationResultType {