From aa9af495182e822b84201e1d708cda7d2d090313 Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Wed, 19 Aug 2015 22:14:11 +0900 Subject: config file support rpki configuration Signed-off-by: FUJITA Tomonori --- config/default.go | 5 +++++ gobgpd/main.go | 8 +++----- packet/rtr.go | 4 ++++ server/server.go | 26 +++++++++++++++++++------- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/config/default.go b/config/default.go index 283ee629..94f5dc9d 100644 --- a/config/default.go +++ b/config/default.go @@ -98,5 +98,10 @@ func SetDefaultConfigValues(md toml.MetaData, bt *Bgp) error { } } } + for _, r := range bt.RpkiServers.RpkiServerList { + if r.RpkiServerConfig.Port == 0 { + r.RpkiServerConfig.Port = bgp.RPKI_DEFAULT_PORT + } + } return nil } diff --git a/gobgpd/main.go b/gobgpd/main.go index 307372f1..bc274e6e 100644 --- a/gobgpd/main.go +++ b/gobgpd/main.go @@ -46,7 +46,6 @@ func main() { DisableStdlog bool `long:"disable-stdlog" description:"disable standard logging"` EnableZapi bool `short:"z" long:"enable-zapi" description:"enable zebra api"` ZapiURL string `long:"zapi-url" description:"specify zebra api url"` - RPKIServer string `long:"rpki-server" description:"specify rpki server url"` } _, err := flags.Parse(&opts) if err != nil { @@ -142,7 +141,7 @@ func main() { reloadCh := make(chan bool) go config.ReadConfigfileServe(opts.ConfigFile, configCh, reloadCh) reloadCh <- true - bgpServer := server.NewBgpServer(bgp.BGP_PORT, opts.RPKIServer) + bgpServer := server.NewBgpServer(bgp.BGP_PORT) go bgpServer.Serve() // start grpc Server @@ -165,13 +164,12 @@ func main() { for { select { case newConfig := <-configCh: - var added []config.Neighbor - var deleted []config.Neighbor - var updated []config.Neighbor + var added, deleted, updated []config.Neighbor if bgpConfig == nil { bgpServer.SetGlobalType(newConfig.Bgp.Global) bgpConfig = &newConfig.Bgp + bgpServer.SetRpkiConfig(newConfig.Bgp.RpkiServers) added = newConfig.Bgp.Neighbors.NeighborList deleted = []config.Neighbor{} updated = []config.Neighbor{} diff --git a/packet/rtr.go b/packet/rtr.go index 8e7ea22a..8eca54f3 100644 --- a/packet/rtr.go +++ b/packet/rtr.go @@ -21,6 +21,10 @@ import ( "net" ) +const ( + RPKI_DEFAULT_PORT = 323 +) + const ( RTR_SERIAL_NOTIFY = iota RTR_SERIAL_QUERY diff --git a/server/server.go b/server/server.go index 6984885f..5f708ea2 100644 --- a/server/server.go +++ b/server/server.go @@ -70,11 +70,13 @@ func (m *broadcastGrpcMsg) send() { } type BgpServer struct { - bgpConfig config.Bgp - globalTypeCh chan config.Global - addedPeerCh chan config.Neighbor - deletedPeerCh chan config.Neighbor - updatedPeerCh chan config.Neighbor + bgpConfig config.Bgp + globalTypeCh chan config.Global + addedPeerCh chan config.Neighbor + deletedPeerCh chan config.Neighbor + updatedPeerCh chan config.Neighbor + rpkiConfigCh chan config.RpkiServers + GrpcReqCh chan *GrpcRequest listenPort int policyUpdateCh chan config.RoutingPolicy @@ -88,18 +90,19 @@ type BgpServer struct { roaClient *roaClient } -func NewBgpServer(port int, roaURL string) *BgpServer { +func NewBgpServer(port int) *BgpServer { b := BgpServer{} b.globalTypeCh = make(chan config.Global) b.addedPeerCh = make(chan config.Neighbor) b.deletedPeerCh = make(chan config.Neighbor) b.updatedPeerCh = make(chan config.Neighbor) + b.rpkiConfigCh = make(chan config.RpkiServers) b.GrpcReqCh = make(chan *GrpcRequest, 1) b.policyUpdateCh = make(chan config.RoutingPolicy) b.localRibMap = make(map[string]*LocalRib) b.neighborMap = make(map[string]*Peer) b.listenPort = port - b.roaClient, _ = newROAClient(roaURL) + b.roaClient, _ = newROAClient("") return &b } @@ -223,6 +226,11 @@ func (server *BgpServer) Serve() { } select { + case c := <-server.rpkiConfigCh: + if len(c.RpkiServerList) > 0 { + url := fmt.Sprintf("%s:%d", c.RpkiServerList[0].RpkiServerConfig.Address, c.RpkiServerList[0].RpkiServerConfig.Port) + server.roaClient, _ = newROAClient(url) + } case rmsg := <-server.roaClient.recieveROA(): server.roaClient.handleRTRMsg(rmsg) case zmsg := <-zapiMsgCh: @@ -707,6 +715,10 @@ func (server *BgpServer) SetGlobalType(g config.Global) { server.globalTypeCh <- g } +func (server *BgpServer) SetRpkiConfig(c config.RpkiServers) { + server.rpkiConfigCh <- c +} + func (server *BgpServer) PeerAdd(peer config.Neighbor) { server.addedPeerCh <- peer } -- cgit v1.2.3