diff options
-rw-r--r-- | api/gobgp.pb.go | 19 | ||||
-rw-r--r-- | api/gobgp.proto | 2 | ||||
-rw-r--r-- | gobgp/cmd/rpki.go | 26 | ||||
-rw-r--r-- | server/rpki.go | 52 |
4 files changed, 65 insertions, 34 deletions
diff --git a/api/gobgp.pb.go b/api/gobgp.pb.go index a4f6069b..4b59a079 100644 --- a/api/gobgp.pb.go +++ b/api/gobgp.pb.go @@ -1450,7 +1450,8 @@ func (m *MrtMessage) String() string { return proto.CompactTextString(m) } func (*MrtMessage) ProtoMessage() {} type RPKIConf struct { - Address string `protobuf:"bytes,1,opt,name=address" json:"address,omitempty"` + Address string `protobuf:"bytes,1,opt,name=address" json:"address,omitempty"` + RemotePort uint32 `protobuf:"varint,2,opt,name=remote_port" json:"remote_port,omitempty"` } func (m *RPKIConf) Reset() { *m = RPKIConf{} } @@ -1492,16 +1493,24 @@ func (m *RPKI) GetState() *RPKIState { } type ROA struct { - As uint32 `protobuf:"varint,1,opt,name=as" json:"as,omitempty"` - Prefixlen uint32 `protobuf:"varint,2,opt,name=prefixlen" json:"prefixlen,omitempty"` - Maxlen uint32 `protobuf:"varint,3,opt,name=maxlen" json:"maxlen,omitempty"` - Prefix string `protobuf:"bytes,4,opt,name=prefix" json:"prefix,omitempty"` + As uint32 `protobuf:"varint,1,opt,name=as" json:"as,omitempty"` + Prefixlen uint32 `protobuf:"varint,2,opt,name=prefixlen" json:"prefixlen,omitempty"` + Maxlen uint32 `protobuf:"varint,3,opt,name=maxlen" json:"maxlen,omitempty"` + Prefix string `protobuf:"bytes,4,opt,name=prefix" json:"prefix,omitempty"` + Conf *RPKIConf `protobuf:"bytes,5,opt,name=conf" json:"conf,omitempty"` } func (m *ROA) Reset() { *m = ROA{} } func (m *ROA) String() string { return proto.CompactTextString(m) } func (*ROA) ProtoMessage() {} +func (m *ROA) GetConf() *RPKIConf { + if m != nil { + return m.Conf + } + return nil +} + type Vrf struct { Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` Rd []byte `protobuf:"bytes,2,opt,name=rd,proto3" json:"rd,omitempty"` diff --git a/api/gobgp.proto b/api/gobgp.proto index 2d5cde94..b052aaa6 100644 --- a/api/gobgp.proto +++ b/api/gobgp.proto @@ -530,6 +530,7 @@ message MrtMessage { message RPKIConf { string address = 1; + uint32 remote_port = 2; } message RPKIState { @@ -549,6 +550,7 @@ message ROA { uint32 prefixlen = 2; uint32 maxlen = 3; string prefix = 4; + RPKIConf conf = 5; } message Vrf { diff --git a/gobgp/cmd/rpki.go b/gobgp/cmd/rpki.go index 484a990c..a2d72edc 100644 --- a/gobgp/cmd/rpki.go +++ b/gobgp/cmd/rpki.go @@ -22,7 +22,9 @@ import ( "github.com/spf13/cobra" "golang.org/x/net/context" "io" + "net" "os" + "strconv" "time" ) @@ -52,17 +54,16 @@ func showRPKIServer(args []string) error { } func showRPKITable(args []string) error { - if len(args) == 0 { - return fmt.Errorf("Needs to specify RPKI server address") - } - rf, err := checkAddressFamily(bgp.RF_IPv4_UC) + rf, err := checkAddressFamily(bgp.RouteFamily(0)) if err != nil { fmt.Println(err) os.Exit(1) } arg := &api.Arguments{ - Rf: uint32(rf), - Name: args[0], + Rf: uint32(rf), + } + if len(args) > 0 { + arg.Name = args[0] } stream, err := client.GetROA(context.Background(), arg) if err != nil { @@ -73,11 +74,11 @@ func showRPKITable(args []string) error { var format string afi, _ := bgp.RouteFamilyToAfiSafi(rf) if afi == bgp.AFI_IP { - format = "%-18s %-6s %s\n" + format = "%-18s %-6s %-10s %s\n" } else { - format = "%-42s %-6s %s\n" + format = "%-42s %-6s %-10s %s\n" } - fmt.Printf(format, "Network", "Maxlen", "AS") + fmt.Printf(format, "Network", "Maxlen", "AS", "Server") for { r, err := stream.Recv() if err == io.EOF { @@ -85,7 +86,12 @@ func showRPKITable(args []string) error { } else if err != nil { return err } - fmt.Printf(format, fmt.Sprintf("%s/%d", r.Prefix, r.Prefixlen), fmt.Sprint(r.Maxlen), fmt.Sprint(r.As)) + if len(args) > 0 && args[0] != r.Conf.Address { + continue + } + + server := net.JoinHostPort(r.Conf.Address, strconv.Itoa(int(r.Conf.RemotePort))) + fmt.Printf(format, fmt.Sprintf("%s/%d", r.Prefix, r.Prefixlen), fmt.Sprint(r.Maxlen), fmt.Sprint(r.As), server) } return nil } diff --git a/server/rpki.go b/server/rpki.go index e7775b2c..e4350f6e 100644 --- a/server/rpki.go +++ b/server/rpki.go @@ -145,32 +145,46 @@ func (c *roaClient) handleGRPC(grpcReq *GrpcRequest) { go sendMultipleResponses(grpcReq, results) case REQ_ROA: - if len(c.config.RpkiServerList) == 0 || c.config.RpkiServerList[0].RpkiServerConfig.Address.String() != grpcReq.Name { + if len(c.config.RpkiServerList) == 0 { result := &GrpcResponse{} - result.ResponseErr = fmt.Errorf("RPKI server that has %v doesn't exist.", grpcReq.Name) - + result.ResponseErr = fmt.Errorf("RPKI server isn't configured.") grpcReq.ResponseCh <- result break } - + conf := c.config.RpkiServerList[0].RpkiServerConfig results := make([]*GrpcResponse, 0) - if tree, ok := c.roas[grpcReq.RouteFamily]; ok { - tree.Walk(func(s string, v interface{}) bool { - b, _ := v.(*roaBucket) - for _, r := range b.entries { - for _, as := range r.AS { - result := &GrpcResponse{} - result.Data = &api.ROA{ - As: as, - Maxlen: uint32(r.MaxLen), - Prefixlen: uint32(b.PrefixLen), - Prefix: b.Prefix.String(), + 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} + } + for _, rf := range rfList { + if tree, ok := c.roas[rf]; ok { + tree.Walk(func(s string, v interface{}) bool { + b, _ := v.(*roaBucket) + for _, r := range b.entries { + for _, as := range r.AS { + result := &GrpcResponse{} + result.Data = &api.ROA{ + As: as, + Maxlen: uint32(r.MaxLen), + Prefixlen: uint32(b.PrefixLen), + Prefix: b.Prefix.String(), + Conf: &api.RPKIConf{ + Address: conf.Address.String(), + RemotePort: conf.Port, + }, + } + results = append(results, result) } - results = append(results, result) } - } - return false - }) + return false + }) + } } go sendMultipleResponses(grpcReq, results) } |