diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-07-28 10:11:43 +0000 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-07-29 16:31:35 +0900 |
commit | 59997e8daaf9793caecf178c770d9bb3882b148f (patch) | |
tree | 16ec6f729b9902d6711829647fbe8620d6fdd9ca /api/grpc_server.go | |
parent | f3ae68b9f28e0ddbe33be3ecf09c2015cfba6078 (diff) |
server: move default config setting logic inside BgpServer's methods
We have three ways to configure gobgp. config file, grpc api and native lib.
Every methods eventually call (*server.BgpServer).Start() or
(*server.BgpServer).AddNeighbor() when starting bgp server or adding
neighbors.
This commit moves default config setting logic inside them to remove
redundant code in grpc_server.go and simplify the usage of native lib.
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'api/grpc_server.go')
-rw-r--r-- | api/grpc_server.go | 55 |
1 files changed, 8 insertions, 47 deletions
diff --git a/api/grpc_server.go b/api/grpc_server.go index 69ade16c..37841ff9 100644 --- a/api/grpc_server.go +++ b/api/grpc_server.go @@ -735,18 +735,12 @@ func (s *Server) DeleteVrf(ctx context.Context, arg *DeleteVrfRequest) (*DeleteV } func (s *Server) AddNeighbor(ctx context.Context, arg *AddNeighborRequest) (*AddNeighborResponse, error) { - c, err := func(a *Peer) (config.Neighbor, error) { - pconf := config.Neighbor{} + c, err := func(a *Peer) (*config.Neighbor, error) { + pconf := &config.Neighbor{} if a.Conf != nil { pconf.Config.NeighborAddress = a.Conf.NeighborAddress pconf.Config.PeerAs = a.Conf.PeerAs pconf.Config.LocalAs = a.Conf.LocalAs - - if pconf.Config.PeerAs != pconf.Config.LocalAs { - pconf.Config.PeerType = config.PEER_TYPE_EXTERNAL - } else { - pconf.Config.PeerType = config.PEER_TYPE_INTERNAL - } pconf.Config.AuthPassword = a.Conf.AuthPassword pconf.Config.RemovePrivateAs = config.RemovePrivateAsOption(a.Conf.RemovePrivateAs) pconf.Config.RouteFlapDamping = a.Conf.RouteFlapDamping @@ -755,17 +749,11 @@ func (s *Server) AddNeighbor(ctx context.Context, arg *AddNeighborRequest) (*Add pconf.Config.PeerGroup = a.Conf.PeerGroup pconf.Config.NeighborAddress = a.Conf.NeighborAddress } - if a.Timers != nil { - if a.Timers.Config != nil { - pconf.Timers.Config.ConnectRetry = float64(a.Timers.Config.ConnectRetry) - pconf.Timers.Config.HoldTime = float64(a.Timers.Config.HoldTime) - pconf.Timers.Config.KeepaliveInterval = float64(a.Timers.Config.KeepaliveInterval) - pconf.Timers.Config.MinimumAdvertisementInterval = float64(a.Timers.Config.MinimumAdvertisementInterval) - } - } else { - pconf.Timers.Config.ConnectRetry = float64(config.DEFAULT_CONNECT_RETRY) - pconf.Timers.Config.HoldTime = float64(config.DEFAULT_HOLDTIME) - pconf.Timers.Config.KeepaliveInterval = float64(config.DEFAULT_HOLDTIME / 3) + if a.Timers != nil && a.Timers.Config != nil { + pconf.Timers.Config.ConnectRetry = float64(a.Timers.Config.ConnectRetry) + pconf.Timers.Config.HoldTime = float64(a.Timers.Config.HoldTime) + pconf.Timers.Config.KeepaliveInterval = float64(a.Timers.Config.KeepaliveInterval) + pconf.Timers.Config.MinimumAdvertisementInterval = float64(a.Timers.Config.MinimumAdvertisementInterval) } if a.RouteReflector != nil { pconf.RouteReflector.Config.RouteReflectorClusterId = config.RrClusterIdType(a.RouteReflector.RouteReflectorClusterId) @@ -807,34 +795,10 @@ func (s *Server) AddNeighbor(ctx context.Context, arg *AddNeighborRequest) (*Add } pconf.AfiSafis = append(pconf.AfiSafis, cAfiSafi) } - } else { - if net.ParseIP(a.Conf.NeighborAddress).To4() != nil { - pconf.AfiSafis = []config.AfiSafi{ - config.AfiSafi{ - Config: config.AfiSafiConfig{ - AfiSafiName: "ipv4-unicast", - }, - }, - } - } else { - pconf.AfiSafis = []config.AfiSafi{ - config.AfiSafi{ - Config: config.AfiSafiConfig{ - AfiSafiName: "ipv6-unicast", - }, - }, - } - } } if a.Transport != nil { pconf.Transport.Config.LocalAddress = a.Transport.LocalAddress pconf.Transport.Config.PassiveMode = a.Transport.PassiveMode - } else { - if net.ParseIP(a.Conf.NeighborAddress).To4() != nil { - pconf.Transport.Config.LocalAddress = "0.0.0.0" - } else { - pconf.Transport.Config.LocalAddress = "::" - } } if a.EbgpMultihop != nil { pconf.EbgpMultihop.Config.Enabled = a.EbgpMultihop.Enabled @@ -845,7 +809,7 @@ func (s *Server) AddNeighbor(ctx context.Context, arg *AddNeighborRequest) (*Add if err != nil { return nil, err } - return &AddNeighborResponse{}, s.bgpServer.AddNeighbor(&c) + return &AddNeighborResponse{}, s.bgpServer.AddNeighbor(c) } func (s *Server) DeleteNeighbor(ctx context.Context, arg *DeleteNeighborRequest) (*DeleteNeighborResponse, error) { @@ -1662,9 +1626,6 @@ func (s *Server) StartServer(ctx context.Context, arg *StartServerRequest) (*Sta AfiSafis: families, }, } - if err := config.SetDefaultConfigValues(b); err != nil { - return nil, err - } return &StartServerResponse{}, s.bgpServer.Start(&b.Global) } |