diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-12-06 10:20:09 +0900 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-12-29 14:47:06 +0900 |
commit | d01c1586b9b1a25965448f9e15a05d94f2b22a5f (patch) | |
tree | 744609e474a9561dab792b60ab70d82696ab691e /server | |
parent | 58946b7924840f1effc993e95440266479c668d5 (diff) |
config: use viper and support multiple configuration formats
// toml by default
$ gobgpd -f gobgpd.toml
// use -t to change configuration type
$ gobgpd -t yaml -f gobgpd.yaml
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r-- | server/bmp.go | 4 | ||||
-rw-r--r-- | server/fsm.go | 28 | ||||
-rw-r--r-- | server/peer.go | 6 | ||||
-rw-r--r-- | server/rpki.go | 2 | ||||
-rw-r--r-- | server/server.go | 55 | ||||
-rw-r--r-- | server/zclient.go | 2 |
6 files changed, 48 insertions, 49 deletions
diff --git a/server/bmp.go b/server/bmp.go index 2a5b245a..33011048 100644 --- a/server/bmp.go +++ b/server/bmp.go @@ -72,7 +72,7 @@ func newBMPClient(conf config.BmpServers, connCh chan *bmpConn) (*bmpClient, err for _, c := range conf.BmpServerList { b := c.Config - go tryConnect(net.JoinHostPort(b.Address.String(), strconv.Itoa(int(b.Port)))) + go tryConnect(net.JoinHostPort(b.Address, strconv.Itoa(int(b.Port)))) } go func() { @@ -99,7 +99,7 @@ func newBMPClient(conf config.BmpServers, connCh chan *bmpConn) (*bmpClient, err c := func() *config.BmpServerConfig { for _, c := range conf.BmpServerList { b := &c.Config - if host == net.JoinHostPort(b.Address.String(), strconv.Itoa(int(b.Port))) { + if host == net.JoinHostPort(b.Address, strconv.Itoa(int(b.Port))) { return b } } diff --git a/server/fsm.go b/server/fsm.go index d05e9e23..d435b08c 100644 --- a/server/fsm.go +++ b/server/fsm.go @@ -237,11 +237,11 @@ func (fsm *FSM) connectLoop() error { connect := func() { if fsm.state == bgp.BGP_FSM_ACTIVE { addr := fsm.pConf.Config.NeighborAddress - host := net.JoinHostPort(addr.String(), strconv.Itoa(bgp.BGP_PORT)) + host := net.JoinHostPort(addr, strconv.Itoa(bgp.BGP_PORT)) // check if LocalAddress has been configured laddr := fsm.pConf.Transport.Config.LocalAddress - if laddr != nil { - lhost := net.JoinHostPort(laddr.String(), "0") + if laddr != "" { + lhost := net.JoinHostPort(laddr, "0") ltcpaddr, err := net.ResolveTCPAddr("tcp", lhost) if err != nil { log.WithFields(log.Fields{ @@ -427,7 +427,7 @@ func buildopen(gConf *config.Global, pConf *config.Neighbor) *bgp.BGPMessage { if as > (1<<16)-1 { as = bgp.AS_TRANS } - return bgp.NewBGPOpenMessage(uint16(as), holdTime, gConf.Config.RouterId.String(), + return bgp.NewBGPOpenMessage(uint16(as), holdTime, gConf.Config.RouterId, []bgp.OptionParameterInterface{opt}) } @@ -459,8 +459,8 @@ func (h *FSMHandler) recvMessageWithError() error { }).Warn("malformed BGP Header") h.msgCh <- &FsmMsg{ MsgType: FSM_MSG_BGP_MESSAGE, - MsgSrc: h.fsm.pConf.Config.NeighborAddress.String(), - MsgDst: h.fsm.pConf.Transport.Config.LocalAddress.String(), + MsgSrc: h.fsm.pConf.Config.NeighborAddress, + MsgDst: h.fsm.pConf.Transport.Config.LocalAddress, MsgData: err, } return err @@ -482,8 +482,8 @@ func (h *FSMHandler) recvMessageWithError() error { } fmsg := &FsmMsg{ MsgType: FSM_MSG_BGP_MESSAGE, - MsgSrc: h.fsm.pConf.Config.NeighborAddress.String(), - MsgDst: h.fsm.pConf.Transport.Config.LocalAddress.String(), + MsgSrc: h.fsm.pConf.Config.NeighborAddress, + MsgDst: h.fsm.pConf.Transport.Config.LocalAddress, timestamp: now, } if err != nil { @@ -504,7 +504,7 @@ func (h *FSMHandler) recvMessageWithError() error { if err != nil { log.WithFields(log.Fields{ "Topic": "Peer", - "Key": h.fsm.pConf.Config.NeighborAddress.String(), + "Key": h.fsm.pConf.Config.NeighborAddress, "error": err, }).Warn("malformed BGP update message") fmsg.MsgData = err @@ -512,7 +512,7 @@ func (h *FSMHandler) recvMessageWithError() error { // FIXME: we should use the original message for bmp/mrt table.UpdatePathAttrs4ByteAs(body) fmsg.PathList = table.ProcessMessage(m, h.fsm.peerInfo, fmsg.timestamp) - id := h.fsm.pConf.Config.NeighborAddress.String() + id := h.fsm.pConf.Config.NeighborAddress policyMutex.RLock() for _, path := range fmsg.PathList { if h.fsm.policy.ApplyPolicy(id, table.POLICY_DIRECTION_IN, path) == nil { @@ -595,8 +595,8 @@ func (h *FSMHandler) opensent() bgp.FSMState { e := &FsmMsg{ MsgType: FSM_MSG_BGP_MESSAGE, - MsgSrc: fsm.pConf.Config.NeighborAddress.String(), - MsgDst: fsm.pConf.Transport.Config.LocalAddress.String(), + MsgSrc: fsm.pConf.Config.NeighborAddress, + MsgDst: fsm.pConf.Transport.Config.LocalAddress, MsgData: m, } h.incoming <- e @@ -974,8 +974,8 @@ func (h *FSMHandler) loop() error { if nextState >= bgp.BGP_FSM_IDLE { e := &FsmMsg{ MsgType: FSM_MSG_STATE_CHANGE, - MsgSrc: fsm.pConf.Config.NeighborAddress.String(), - MsgDst: fsm.pConf.Transport.Config.LocalAddress.String(), + MsgSrc: fsm.pConf.Config.NeighborAddress, + MsgDst: fsm.pConf.Transport.Config.LocalAddress, MsgData: nextState, } h.incoming <- e diff --git a/server/peer.go b/server/peer.go index f7c31fda..f083baf4 100644 --- a/server/peer.go +++ b/server/peer.go @@ -58,7 +58,7 @@ func NewPeer(g config.Global, conf config.Neighbor, loc *table.TableManager, pol } tableId := table.GLOBAL_RIB_NAME if peer.isRouteServerClient() { - tableId = conf.Config.NeighborAddress.String() + tableId = conf.Config.NeighborAddress } peer.tableId = tableId conf.State.SessionState = uint32(bgp.BGP_FSM_IDLE) @@ -79,7 +79,7 @@ func (peer *Peer) Outgoing() chan *bgp.BGPMessage { } func (peer *Peer) ID() string { - return peer.conf.Config.NeighborAddress.String() + return peer.conf.Config.NeighborAddress } func (peer *Peer) TableID() string { @@ -274,7 +274,7 @@ func (peer *Peer) ToApiStruct() *api.Peer { } conf := &api.PeerConf{ - NeighborAddress: c.Config.NeighborAddress.String(), + NeighborAddress: c.Config.NeighborAddress, Id: peer.fsm.peerInfo.ID.To4().String(), PeerAs: c.Config.PeerAs, LocalAs: c.Config.LocalAs, diff --git a/server/rpki.go b/server/rpki.go index a5f5dbee..57a76bc5 100644 --- a/server/rpki.go +++ b/server/rpki.go @@ -105,7 +105,7 @@ func newROAManager(as uint32, conf config.RpkiServers) (*roaManager, error) { for _, entry := range conf.RpkiServerList { c := entry.Config client := &roaClient{ - host: net.JoinHostPort(c.Address.String(), strconv.Itoa(int(c.Port))), + host: net.JoinHostPort(c.Address, strconv.Itoa(int(c.Port))), eventCh: m.eventCh, } m.clientMap[client.host] = client diff --git a/server/server.go b/server/server.go index a29e7e91..20a8eebc 100644 --- a/server/server.go +++ b/server/server.go @@ -18,7 +18,6 @@ package server import ( "bytes" "fmt" - "github.com/BurntSushi/toml" log "github.com/Sirupsen/logrus" "github.com/armon/go-radix" api "github.com/osrg/gobgp/api" @@ -240,9 +239,9 @@ func (server *BgpServer) Serve() { } } - listener := func(addr net.IP) *net.TCPListener { + listener := func(addr string) *net.TCPListener { var l *net.TCPListener - if addr.To4() != nil { + if net.ParseIP(addr).To4() != nil { l = server.listenerMap["tcp4"] } else { l = server.listenerMap["tcp6"] @@ -296,7 +295,7 @@ func (server *BgpServer) Serve() { return false } return true - }(peer.conf.Transport.Config.LocalAddress) + }(net.ParseIP(peer.conf.Transport.Config.LocalAddress)) if localAddrValid == false { conn.Close() return @@ -360,14 +359,14 @@ func (server *BgpServer) Serve() { case conn := <-acceptCh: passConn(conn) case config := <-server.addedPeerCh: - addr := config.Config.NeighborAddress.String() + addr := config.Config.NeighborAddress _, found := server.neighborMap[addr] if found { log.Warn("Can't overwrite the exising peer ", addr) continue } if g.ListenConfig.Port > 0 { - SetTcpMD5SigSockopts(listener(config.Config.NeighborAddress), addr, config.Config.AuthPassword) + SetTcpMD5SigSockopts(listener(addr), addr, config.Config.AuthPassword) } peer := NewPeer(g, config, server.globalRib, server.policy) server.setPolicyByConfig(peer.ID(), config.ApplyPolicy) @@ -389,8 +388,8 @@ func (server *BgpServer) Serve() { peer.startFSMHandler(server.fsmincomingCh) server.broadcastPeerState(peer) case config := <-server.deletedPeerCh: - addr := config.Config.NeighborAddress.String() - SetTcpMD5SigSockopts(listener(config.Config.NeighborAddress), addr, "") + addr := config.Config.NeighborAddress + SetTcpMD5SigSockopts(listener(addr), addr, "") peer, found := server.neighborMap[addr] if found { log.Info("Delete a peer configuration for ", addr) @@ -414,7 +413,7 @@ func (server *BgpServer) Serve() { log.Info("Can't delete a peer configuration for ", addr) } case config := <-server.updatedPeerCh: - addr := config.Config.NeighborAddress.String() + addr := config.Config.NeighborAddress peer := server.neighborMap[addr] peer.conf = config server.setPolicyByConfig(peer.ID(), config.ApplyPolicy) @@ -448,7 +447,7 @@ func newSenderMsg(peer *Peer, messages []*bgp.BGPMessage) *SenderMsg { return &SenderMsg{ messages: messages, sendCh: peer.outgoing, - destination: peer.conf.Config.NeighborAddress.String(), + destination: peer.conf.Config.NeighborAddress, twoBytesAs: y, } } @@ -484,7 +483,7 @@ func filterpath(peer *Peer, path *table.Path) *table.Path { // RFC4456 8. Avoiding Routing Information Loops // A router that recognizes the ORIGINATOR_ID attribute SHOULD // ignore a route received with its BGP Identifier as the ORIGINATOR_ID. - if id := path.GetOriginatorID(); peer.gConf.Config.RouterId.Equal(id) { + if id := path.GetOriginatorID(); peer.gConf.Config.RouterId == id.String() { log.WithFields(log.Fields{ "Topic": "Peer", "Key": remoteAddr, @@ -524,7 +523,7 @@ func filterpath(peer *Peer, path *table.Path) *table.Path { } } - if remoteAddr.Equal(path.GetSource().Address) { + if remoteAddr == path.GetSource().Address.String() { log.WithFields(log.Fields{ "Topic": "Peer", "Key": remoteAddr, @@ -536,7 +535,7 @@ func filterpath(peer *Peer, path *table.Path) *table.Path { if !peer.isRouteServerClient() && isASLoop(peer, path) { return nil } - return path.Clone(remoteAddr, path.IsWithdraw) + return path.Clone(net.ParseIP(remoteAddr), path.IsWithdraw) } func (server *BgpServer) dropPeerAllRoutes(peer *Peer) []*SenderMsg { @@ -652,7 +651,7 @@ func (server *BgpServer) broadcastPeerState(peer *Peer) { default: } ignore := req.RequestType != REQ_MONITOR_NEIGHBOR_PEER_STATE - ignore = ignore || (req.Name != "" && req.Name != peer.conf.Config.NeighborAddress.String()) + ignore = ignore || (req.Name != "" && req.Name != peer.conf.Config.NeighborAddress) if ignore { remainReqs = append(remainReqs, req) continue @@ -797,7 +796,7 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *FsmMsg, incoming chan * if nextState == bgp.BGP_FSM_ESTABLISHED { // update for export policy laddr, lport := peer.fsm.LocalHostPort() - peer.conf.Transport.Config.LocalAddress = net.ParseIP(laddr) + peer.conf.Transport.Config.LocalAddress = laddr if ch := server.bmpClient.send(); ch != nil { _, rport := peer.fsm.RemoteHostPort() m := &broadcastBMPMsg{ @@ -1093,7 +1092,7 @@ func (server *BgpServer) Api2PathList(resource api.Resource, name string, ApiPat } else { pi = &table.PeerInfo{ AS: server.bgpConfig.Global.Config.As, - LocalID: server.bgpConfig.Global.Config.RouterId, + LocalID: net.ParseIP(server.bgpConfig.Global.Config.RouterId).To4(), } } @@ -1304,7 +1303,7 @@ func (server *BgpServer) handleVrfMod(arg *api.ModVrfArguments) ([]*table.Path, } pi := &table.PeerInfo{ AS: server.bgpConfig.Global.Config.As, - LocalID: server.bgpConfig.Global.Config.RouterId, + LocalID: net.ParseIP(server.bgpConfig.Global.Config.RouterId).To4(), } msgs, err = rib.AddVrf(arg.Vrf.Name, rd, importRt, exportRt, pi) if err != nil { @@ -1406,14 +1405,14 @@ func (server *BgpServer) handleModConfig(grpcReq *GrpcRequest) error { Global: config.Global{ Config: config.GlobalConfig{ As: g.As, - RouterId: net.ParseIP(g.RouterId), + RouterId: g.RouterId, }, ListenConfig: config.ListenConfig{ Port: g.ListenPort, }, }, } - err := config.SetDefaultConfigValues(toml.MetaData{}, &c) + err := config.SetDefaultConfigValues(nil, &c) if err != nil { return err } @@ -1490,7 +1489,7 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { result := &GrpcResponse{ Data: &api.Global{ As: server.bgpConfig.Global.Config.As, - RouterId: server.bgpConfig.Global.Config.RouterId.String(), + RouterId: server.bgpConfig.Global.Config.RouterId, }, } grpcReq.ResponseCh <- result @@ -1723,7 +1722,7 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { pathList := []*table.Path{} for _, path := range peer.adjRibIn.PathList([]bgp.RouteFamily{grpcReq.RouteFamily}, false) { if path = server.policy.ApplyPolicy(peer.ID(), table.POLICY_DIRECTION_IN, path); path != nil { - pathList = append(pathList, path.Clone(peer.conf.Config.NeighborAddress, false)) + pathList = append(pathList, path.Clone(net.ParseIP(peer.conf.Config.NeighborAddress), false)) } } m, _ := server.propagateUpdate(peer, pathList) @@ -1958,8 +1957,8 @@ func (server *BgpServer) handleGrpcModNeighbor(grpcReq *GrpcRequest) (sMsgs []*S apitoConfig := func(a *api.Peer) (config.Neighbor, error) { var pconf config.Neighbor if a.Conf != nil { - pconf.NeighborAddress = net.ParseIP(a.Conf.NeighborAddress) - pconf.Config.NeighborAddress = net.ParseIP(a.Conf.NeighborAddress) + pconf.NeighborAddress = a.Conf.NeighborAddress + pconf.Config.NeighborAddress = a.Conf.NeighborAddress pconf.Config.PeerAs = a.Conf.PeerAs pconf.Config.LocalAs = a.Conf.LocalAs if pconf.Config.PeerAs != server.bgpConfig.Global.Config.As { @@ -1973,7 +1972,7 @@ func (server *BgpServer) handleGrpcModNeighbor(grpcReq *GrpcRequest) (sMsgs []*S pconf.Config.SendCommunity = config.CommunityType(a.Conf.SendCommunity) pconf.Config.Description = a.Conf.Description pconf.Config.PeerGroup = a.Conf.PeerGroup - pconf.Config.NeighborAddress = net.ParseIP(a.Conf.NeighborAddress) + pconf.Config.NeighborAddress = a.Conf.NeighborAddress } if a.Timers != nil { if a.Timers.Config != nil { @@ -2033,7 +2032,7 @@ func (server *BgpServer) handleGrpcModNeighbor(grpcReq *GrpcRequest) (sMsgs []*S } } if a.Transport != nil { - pconf.Transport.Config.LocalAddress = net.ParseIP(a.Transport.LocalAddress) + pconf.Transport.Config.LocalAddress = a.Transport.LocalAddress pconf.Transport.Config.PassiveMode = a.Transport.PassiveMode } return pconf, nil @@ -2443,7 +2442,7 @@ func (server *BgpServer) handleModRpki(grpcReq *GrpcRequest) { switch arg.Operation { case api.Operation_ADD: r := config.RpkiServer{} - r.Config.Address = net.ParseIP(arg.Address) + r.Config.Address = arg.Address r.Config.Port = arg.Port server.bgpConfig.RpkiServers.RpkiServerList = append(server.bgpConfig.RpkiServers.RpkiServerList, r) server.roaManager, _ = newROAManager(server.bgpConfig.Global.Config.As, server.bgpConfig.RpkiServers) @@ -2555,11 +2554,11 @@ func (server *BgpServer) mkMrtPeerIndexTableMsg(t uint32, view string) (*bgp.MRT peers := make([]*bgp.Peer, 0, len(server.neighborMap)) for _, peer := range server.neighborMap { id := peer.fsm.peerInfo.ID.To4().String() - ipaddr := peer.conf.Config.NeighborAddress.String() + ipaddr := peer.conf.Config.NeighborAddress asn := peer.conf.Config.PeerAs peers = append(peers, bgp.NewPeer(id, ipaddr, asn, true)) } - bgpid := server.bgpConfig.Global.Config.RouterId.To4().String() + bgpid := server.bgpConfig.Global.Config.RouterId table := bgp.NewPeerIndexTable(bgpid, view, peers) return bgp.NewMRTMessage(t, bgp.TABLE_DUMPv2, bgp.PEER_INDEX_TABLE, table) } diff --git a/server/zclient.go b/server/zclient.go index 33875476..ba731cce 100644 --- a/server/zclient.go +++ b/server/zclient.go @@ -152,7 +152,7 @@ func handleZapiMsg(msg *zebra.Message, server *BgpServer) []*SenderMsg { case *zebra.IPRouteBody: pi := &table.PeerInfo{ AS: server.bgpConfig.Global.Config.As, - LocalID: server.bgpConfig.Global.Config.RouterId, + LocalID: net.ParseIP(server.bgpConfig.Global.Config.RouterId).To4(), } if b.Prefix != nil && len(b.Nexthops) > 0 && b.Type != zebra.ROUTE_KERNEL { |