summaryrefslogtreecommitdiffhomepage
path: root/config
diff options
context:
space:
mode:
Diffstat (limited to 'config')
-rw-r--r--config/default.go11
-rw-r--r--config/serve.go2
-rw-r--r--config/util.go11
3 files changed, 18 insertions, 6 deletions
diff --git a/config/default.go b/config/default.go
index 3b0db592..1ff57adb 100644
--- a/config/default.go
+++ b/config/default.go
@@ -131,6 +131,7 @@ func setDefaultNeighborConfigValuesWithViper(v *viper.Viper, n *Neighbor, asn ui
}
n.State.PeerAs = n.Config.PeerAs
+ n.State.NeighborAddress = n.Config.NeighborAddress
n.AsPathOptions.State.AllowOwnAs = n.AsPathOptions.Config.AllowOwnAs
if !v.IsSet("neighbor.timers.config.connect-retry") && n.Timers.Config.ConnectRetry == 0 {
@@ -154,14 +155,14 @@ func setDefaultNeighborConfigValuesWithViper(v *viper.Viper, n *Neighbor, asn ui
if err != nil {
return err
}
- n.Config.NeighborAddress = addr
+ n.State.NeighborAddress = addr
}
if n.Transport.Config.LocalAddress == "" {
- if n.Config.NeighborAddress == "" {
+ if n.State.NeighborAddress == "" {
return fmt.Errorf("no neighbor address/interface specified")
}
- ipAddr, err := net.ResolveIPAddr("ip", n.Config.NeighborAddress)
+ ipAddr, err := net.ResolveIPAddr("ip", n.State.NeighborAddress)
if err != nil {
return err
}
@@ -184,8 +185,8 @@ func setDefaultNeighborConfigValuesWithViper(v *viper.Viper, n *Neighbor, asn ui
defaultAfiSafi(AFI_SAFI_TYPE_IPV4_UNICAST, true),
defaultAfiSafi(AFI_SAFI_TYPE_IPV6_UNICAST, true),
}
- } else if ipAddr, err := net.ResolveIPAddr("ip", n.Config.NeighborAddress); err != nil {
- return fmt.Errorf("invalid neighbor address: %s", n.Config.NeighborAddress)
+ } else if ipAddr, err := net.ResolveIPAddr("ip", n.State.NeighborAddress); err != nil {
+ return fmt.Errorf("invalid neighbor address: %s", n.State.NeighborAddress)
} else if ipAddr.IP.To4() != nil {
n.AfiSafis = []AfiSafi{defaultAfiSafi(AFI_SAFI_TYPE_IPV4_UNICAST, true)}
} else {
diff --git a/config/serve.go b/config/serve.go
index 2df31558..8dfda75e 100644
--- a/config/serve.go
+++ b/config/serve.go
@@ -76,7 +76,7 @@ func ReadConfigfileServe(path, format string, configCh chan *BgpConfigSet) {
func inSlice(n Neighbor, b []Neighbor) int {
for i, nb := range b {
- if nb.Config.NeighborAddress == n.Config.NeighborAddress {
+ if nb.State.NeighborAddress == n.State.NeighborAddress {
return i
}
}
diff --git a/config/util.go b/config/util.go
index 36999411..8ecf56d5 100644
--- a/config/util.go
+++ b/config/util.go
@@ -140,3 +140,14 @@ func ParseMaskLength(prefix, mask string) (int, int, error) {
}
return min, max, nil
}
+
+func ExtractNeighborAddress(c *Neighbor) (string, error) {
+ addr := c.State.NeighborAddress
+ if addr == "" {
+ addr = c.Config.NeighborAddress
+ if addr == "" {
+ return "", fmt.Errorf("NeighborAddress is not configured")
+ }
+ }
+ return addr, nil
+}