summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--config/default.go17
-rw-r--r--server/peer.go2
-rw-r--r--server/server.go2
-rw-r--r--server/server_test.go3
4 files changed, 16 insertions, 8 deletions
diff --git a/config/default.go b/config/default.go
index 41bcbd40..f69c96aa 100644
--- a/config/default.go
+++ b/config/default.go
@@ -101,11 +101,18 @@ func isLocalLinkLocalAddress(ifindex int, addr net.IP) (bool, error) {
return false, nil
}
-func SetDefaultNeighborConfigValues(n *Neighbor, asn uint32) error {
- return setDefaultNeighborConfigValuesWithViper(nil, n, asn)
+func SetDefaultNeighborConfigValues(n *Neighbor, g *Global) error {
+ return setDefaultNeighborConfigValuesWithViper(nil, n, g)
}
-func setDefaultNeighborConfigValuesWithViper(v *viper.Viper, n *Neighbor, asn uint32) error {
+func setDefaultNeighborConfigValuesWithViper(v *viper.Viper, n *Neighbor, g *Global) error {
+ if n == nil {
+ return fmt.Errorf("neighbor config is nil")
+ }
+ if g == nil {
+ return fmt.Errorf("global config is nil")
+ }
+
if v == nil {
// Determines this function is called against the same Neighbor struct,
// and if already called, returns immediately.
@@ -116,7 +123,7 @@ func setDefaultNeighborConfigValuesWithViper(v *viper.Viper, n *Neighbor, asn ui
}
if n.Config.LocalAs == 0 {
- n.Config.LocalAs = asn
+ n.Config.LocalAs = g.Config.As
}
n.State.LocalAs = n.Config.LocalAs
@@ -407,7 +414,7 @@ func setDefaultConfigValuesWithViper(v *viper.Viper, b *BgpConfigSet) error {
if len(list) > idx {
vv.Set("neighbor", list[idx])
}
- if err := setDefaultNeighborConfigValuesWithViper(vv, &n, b.Global.Config.As); err != nil {
+ if err := setDefaultNeighborConfigValuesWithViper(vv, &n, &b.Global); err != nil {
return err
}
b.Neighbors[idx] = n
diff --git a/server/peer.go b/server/peer.go
index 892395be..135713f9 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -79,7 +79,7 @@ func newDynamicPeer(g *config.Global, neighborAddress string, pg *config.PeerGro
}).Debugf("Can't overwrite neighbor config: %s", err)
return nil
}
- if err := config.SetDefaultNeighborConfigValues(&conf, g.Config.As); err != nil {
+ if err := config.SetDefaultNeighborConfigValues(&conf, g); err != nil {
log.WithFields(log.Fields{
"Topic": "Peer",
"Key": neighborAddress,
diff --git a/server/server.go b/server/server.go
index 18ff196d..9de1c8ad 100644
--- a/server/server.go
+++ b/server/server.go
@@ -1760,7 +1760,7 @@ func (server *BgpServer) addNeighbor(c *config.Neighbor) error {
}
}
- if err := config.SetDefaultNeighborConfigValues(c, server.bgpConfig.Global.Config.As); err != nil {
+ if err := config.SetDefaultNeighborConfigValues(c, &server.bgpConfig.Global); err != nil {
return err
}
diff --git a/server/server_test.go b/server/server_test.go
index ac762176..bb9e7ff1 100644
--- a/server/server_test.go
+++ b/server/server_test.go
@@ -200,7 +200,8 @@ func TestNumGoroutineWithAddDeleteNeighbor(t *testing.T) {
func newPeerandInfo(myAs, as uint32, address string, rib *table.TableManager) (*Peer, *table.PeerInfo) {
nConf := &config.Neighbor{Config: config.NeighborConfig{PeerAs: as, NeighborAddress: address}}
- config.SetDefaultNeighborConfigValues(nConf, myAs)
+ gConf := &config.Global{Config: config.GlobalConfig{As: myAs}}
+ config.SetDefaultNeighborConfigValues(nConf, gConf)
policy := table.NewRoutingPolicy()
policy.Reset(&config.RoutingPolicy{}, nil)
p := NewPeer(