summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/rpki.go28
-rw-r--r--server/rpki_test.go49
-rw-r--r--server/server.go23
3 files changed, 51 insertions, 49 deletions
diff --git a/server/rpki.go b/server/rpki.go
index 8f3e2e45..fe89b136 100644
--- a/server/rpki.go
+++ b/server/rpki.go
@@ -133,20 +133,20 @@ type roaClientEvent struct {
type roaManager struct {
AS uint32
- roas map[bgp.RouteFamily]*radix.Tree
+ Roas map[bgp.RouteFamily]*radix.Tree
config []config.RpkiServer
eventCh chan *roaClientEvent
clientMap map[string]*roaClient
}
-func newROAManager(as uint32, servers []config.RpkiServer) (*roaManager, error) {
+func NewROAManager(as uint32, servers []config.RpkiServer) (*roaManager, error) {
m := &roaManager{
AS: as,
- roas: make(map[bgp.RouteFamily]*radix.Tree),
+ Roas: make(map[bgp.RouteFamily]*radix.Tree),
config: servers,
}
- m.roas[bgp.RF_IPv4_UC] = radix.New()
- m.roas[bgp.RF_IPv6_UC] = radix.New()
+ m.Roas[bgp.RF_IPv4_UC] = radix.New()
+ m.Roas[bgp.RF_IPv6_UC] = radix.New()
m.eventCh = make(chan *roaClientEvent)
m.clientMap = make(map[string]*roaClient)
@@ -165,7 +165,7 @@ func newROAManager(as uint32, servers []config.RpkiServer) (*roaManager, error)
}
func (m *roaManager) deleteAllROA(network string) {
- for _, tree := range m.roas {
+ for _, tree := range m.Roas {
deleteKeys := make([]string, 0, tree.Len())
tree.Walk(func(s string, v interface{}) bool {
b, _ := v.(*roaBucket)
@@ -208,7 +208,7 @@ func (m *roaManager) operate(op api.Operation, address string) error {
return fmt.Errorf("roa server not found %s", address)
}
-func (c *roaManager) recieveROA() chan *roaClientEvent {
+func (c *roaManager) RecieveROA() chan *roaClientEvent {
return c.eventCh
}
@@ -219,7 +219,7 @@ func (c *roaClient) lifetimeout() {
}
}
-func (m *roaManager) handleROAEvent(ev *roaClientEvent) {
+func (m *roaManager) HandleROAEvent(ev *roaClientEvent) {
client, y := m.clientMap[ev.src]
if !y {
if ev.eventType == CONNECTED {
@@ -267,9 +267,9 @@ func (m *roaManager) handleROAEvent(ev *roaClientEvent) {
}
func (m *roaManager) roa2tree(roa *ROA) (*radix.Tree, string) {
- tree := m.roas[bgp.RF_IPv4_UC]
+ tree := m.Roas[bgp.RF_IPv4_UC]
if roa.Family == bgp.AFI_IP6 {
- tree = m.roas[bgp.RF_IPv6_UC]
+ tree = m.Roas[bgp.RF_IPv6_UC]
}
return tree, table.IpToRadixkey(roa.Prefix.Prefix, roa.Prefix.Length)
}
@@ -413,8 +413,8 @@ func (c *roaManager) handleGRPC(grpcReq *GrpcRequest) {
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])
for _, client := range c.clientMap {
state := client.state
@@ -482,7 +482,7 @@ func (c *roaManager) handleGRPC(grpcReq *GrpcRequest) {
rfList = []bgp.RouteFamily{bgp.RF_IPv4_UC, bgp.RF_IPv6_UC}
}
for _, rf := range rfList {
- if tree, ok := c.roas[rf]; ok {
+ if tree, ok := c.Roas[rf]; ok {
tree.Walk(func(s string, v interface{}) bool {
b, _ := v.(*roaBucket)
var roaList roas
@@ -554,7 +554,7 @@ func (c *roaManager) validate(pathList []*table.Path, isMonitor bool) []*api.ROA
if path.IsWithdraw {
continue
}
- if tree, ok := c.roas[path.GetRouteFamily()]; ok {
+ if tree, ok := c.Roas[path.GetRouteFamily()]; ok {
r, roaList := validatePath(c.AS, tree, path.GetNlri().String(), path.GetAsPath())
if isMonitor && path.Validation() != config.RpkiValidationResultType(r) {
apiRoaList := func() []*api.ROA {
diff --git a/server/rpki_test.go b/server/rpki_test.go
index aa0a85be..c51ba1ae 100644
--- a/server/rpki_test.go
+++ b/server/rpki_test.go
@@ -16,14 +16,15 @@
package server
import (
- "github.com/armon/go-radix"
- "github.com/osrg/gobgp/config"
- "github.com/osrg/gobgp/packet"
- "github.com/stretchr/testify/assert"
"net"
"strconv"
"strings"
"testing"
+
+ "github.com/armon/go-radix"
+ "github.com/osrg/gobgp/config"
+ "github.com/osrg/gobgp/packet"
+ "github.com/stretchr/testify/assert"
)
func strToASParam(str string) *bgp.PathAttributeAsPath {
@@ -60,13 +61,13 @@ func validateOne(tree *radix.Tree, cidr, aspathStr string) config.RpkiValidation
func TestValidate0(t *testing.T) {
assert := assert.New(t)
- manager, _ := newROAManager(0, []config.RpkiServer{})
+ manager, _ := NewROAManager(0, []config.RpkiServer{})
manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("192.168.0.0").To4(), 24, 32, 100, ""))
manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("192.168.0.0").To4(), 24, 24, 200, ""))
var r config.RpkiValidationResultType
- tree := manager.roas[bgp.RF_IPv4_UC]
+ tree := manager.Roas[bgp.RF_IPv4_UC]
r = validateOne(tree, "192.168.0.0/24", "100")
assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_VALID)
@@ -89,12 +90,12 @@ func TestValidate0(t *testing.T) {
func TestValidate1(t *testing.T) {
assert := assert.New(t)
- manager, _ := newROAManager(0, []config.RpkiServer{})
+ manager, _ := NewROAManager(0, []config.RpkiServer{})
manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 16, 16, 65000, ""))
var r config.RpkiValidationResultType
- tree := manager.roas[bgp.RF_IPv4_UC]
+ tree := manager.Roas[bgp.RF_IPv4_UC]
r = validateOne(tree, "10.0.0.0/16", "65000")
assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_VALID)
@@ -105,11 +106,11 @@ func TestValidate1(t *testing.T) {
func TestValidate2(t *testing.T) {
assert := assert.New(t)
- manager, _ := newROAManager(0, []config.RpkiServer{})
+ manager, _ := NewROAManager(0, []config.RpkiServer{})
var r config.RpkiValidationResultType
- tree := manager.roas[bgp.RF_IPv4_UC]
+ tree := manager.Roas[bgp.RF_IPv4_UC]
r = validateOne(tree, "10.0.0.0/16", "65000")
assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND)
@@ -120,22 +121,22 @@ func TestValidate2(t *testing.T) {
func TestValidate3(t *testing.T) {
assert := assert.New(t)
- manager, _ := newROAManager(0, []config.RpkiServer{})
+ manager, _ := NewROAManager(0, []config.RpkiServer{})
manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 16, 16, 65000, ""))
var r config.RpkiValidationResultType
- tree := manager.roas[bgp.RF_IPv4_UC]
+ tree := manager.Roas[bgp.RF_IPv4_UC]
r = validateOne(tree, "10.0.0.0/8", "65000")
assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND)
r = validateOne(tree, "10.0.0.0/17", "65000")
assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_INVALID)
- manager, _ = newROAManager(0, []config.RpkiServer{})
+ manager, _ = NewROAManager(0, []config.RpkiServer{})
manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 16, 24, 65000, ""))
- tree = manager.roas[bgp.RF_IPv4_UC]
+ tree = manager.Roas[bgp.RF_IPv4_UC]
r = validateOne(tree, "10.0.0.0/17", "65000")
assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_VALID)
}
@@ -143,12 +144,12 @@ func TestValidate3(t *testing.T) {
func TestValidate4(t *testing.T) {
assert := assert.New(t)
- manager, _ := newROAManager(0, []config.RpkiServer{})
+ manager, _ := NewROAManager(0, []config.RpkiServer{})
manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 16, 16, 65000, ""))
manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 16, 16, 65001, ""))
var r config.RpkiValidationResultType
- tree := manager.roas[bgp.RF_IPv4_UC]
+ tree := manager.Roas[bgp.RF_IPv4_UC]
r = validateOne(tree, "10.0.0.0/16", "65000")
assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_VALID)
@@ -159,12 +160,12 @@ func TestValidate4(t *testing.T) {
func TestValidate5(t *testing.T) {
assert := assert.New(t)
- manager, _ := newROAManager(0, []config.RpkiServer{})
+ manager, _ := NewROAManager(0, []config.RpkiServer{})
manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 17, 17, 65000, ""))
manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("10.0.128.0").To4(), 17, 17, 65000, ""))
var r config.RpkiValidationResultType
- tree := manager.roas[bgp.RF_IPv4_UC]
+ tree := manager.Roas[bgp.RF_IPv4_UC]
r = validateOne(tree, "10.0.0.0/16", "65000")
assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND)
}
@@ -172,11 +173,11 @@ func TestValidate5(t *testing.T) {
func TestValidate6(t *testing.T) {
assert := assert.New(t)
- manager, _ := newROAManager(0, []config.RpkiServer{})
+ manager, _ := NewROAManager(0, []config.RpkiServer{})
manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 8, 32, 0, ""))
var r config.RpkiValidationResultType
- tree := manager.roas[bgp.RF_IPv4_UC]
+ tree := manager.Roas[bgp.RF_IPv4_UC]
r = validateOne(tree, "10.0.0.0/7", "65000")
assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND)
@@ -190,11 +191,11 @@ func TestValidate6(t *testing.T) {
func TestValidate7(t *testing.T) {
assert := assert.New(t)
- manager, _ := newROAManager(0, []config.RpkiServer{})
+ manager, _ := NewROAManager(0, []config.RpkiServer{})
manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 16, 24, 65000, ""))
var r config.RpkiValidationResultType
- tree := manager.roas[bgp.RF_IPv4_UC]
+ tree := manager.Roas[bgp.RF_IPv4_UC]
r = validateOne(tree, "10.0.0.0/24", "{65000}")
assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND)
@@ -208,12 +209,12 @@ func TestValidate7(t *testing.T) {
func TestValidate8(t *testing.T) {
assert := assert.New(t)
- manager, _ := newROAManager(0, []config.RpkiServer{})
+ manager, _ := NewROAManager(0, []config.RpkiServer{})
manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 16, 24, 0, ""))
manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 16, 24, 65000, ""))
var r config.RpkiValidationResultType
- tree := manager.roas[bgp.RF_IPv4_UC]
+ tree := manager.Roas[bgp.RF_IPv4_UC]
r = validateOne(tree, "10.0.0.0/24", "65000")
assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_VALID)
diff --git a/server/server.go b/server/server.go
index 035675f6..d7b83869 100644
--- a/server/server.go
+++ b/server/server.go
@@ -18,6 +18,12 @@ package server
import (
"bytes"
"fmt"
+ "net"
+ "os"
+ "strconv"
+ "sync"
+ "time"
+
log "github.com/Sirupsen/logrus"
"github.com/armon/go-radix"
"github.com/eapache/channels"
@@ -27,11 +33,6 @@ import (
"github.com/osrg/gobgp/table"
"github.com/osrg/gobgp/zebra"
"github.com/satori/go.uuid"
- "net"
- "os"
- "strconv"
- "sync"
- "time"
)
var policyMutex sync.RWMutex
@@ -175,7 +176,7 @@ func NewBgpServer() *BgpServer {
b.policyUpdateCh = make(chan config.RoutingPolicy)
b.neighborMap = make(map[string]*Peer)
b.watchers = Watchers(make(map[watcherType]watcher))
- b.roaManager, _ = newROAManager(0, nil)
+ b.roaManager, _ = NewROAManager(0, nil)
b.policy = table.NewRoutingPolicy()
return &b
}
@@ -206,7 +207,7 @@ func (server *BgpServer) Listeners(addr string) []*net.TCPListener {
}
func (server *BgpServer) Serve() {
- server.roaManager, _ = newROAManager(0, nil)
+ server.roaManager, _ = NewROAManager(0, nil)
w, _ := newGrpcIncomingWatcher()
server.watchers[WATCHER_GRPC_INCOMING] = w
@@ -336,9 +337,9 @@ func (server *BgpServer) Serve() {
select {
case c := <-server.rpkiConfigCh:
- server.roaManager, _ = newROAManager(server.bgpConfig.Global.Config.As, c)
- case rmsg := <-server.roaManager.recieveROA():
- server.roaManager.handleROAEvent(rmsg)
+ server.roaManager, _ = NewROAManager(server.bgpConfig.Global.Config.As, c)
+ case rmsg := <-server.roaManager.RecieveROA():
+ server.roaManager.HandleROAEvent(rmsg)
case zmsg := <-server.zapiMsgCh:
m := handleZapiMsg(zmsg, server)
if len(m) > 0 {
@@ -2925,7 +2926,7 @@ func (server *BgpServer) handleModRpki(grpcReq *GrpcRequest) {
r.Config.Address = arg.Address
r.Config.Port = arg.Port
server.bgpConfig.RpkiServers = append(server.bgpConfig.RpkiServers, r)
- server.roaManager, _ = newROAManager(server.bgpConfig.Global.Config.As, server.bgpConfig.RpkiServers)
+ server.roaManager, _ = NewROAManager(server.bgpConfig.Global.Config.As, server.bgpConfig.RpkiServers)
grpcDone(grpcReq, nil)
return
case api.Operation_ENABLE, api.Operation_DISABLE, api.Operation_RESET, api.Operation_SOFTRESET: