diff options
-rw-r--r-- | config/default.go | 11 | ||||
-rw-r--r-- | server/fsm.go | 35 |
2 files changed, 24 insertions, 22 deletions
diff --git a/config/default.go b/config/default.go index 02ec5784..ea1c731f 100644 --- a/config/default.go +++ b/config/default.go @@ -113,6 +113,17 @@ func SetDefaultConfigValues(v *viper.Viper, b *BgpConfigSet) error { n.Timers.Config.IdleHoldTimeAfterReset = float64(DEFAULT_IDLE_HOLDTIME_AFTER_RESET) } + if !vv.IsSet("neighbor.transport.config.local-address") { + v6 := true + if ip := net.ParseIP(n.Config.NeighborAddress); ip.To4() != nil { + v6 = false + } + if v6 { + n.Transport.Config.LocalAddress = "::" + } else { + n.Transport.Config.LocalAddress = "0.0.0.0" + } + } if !vv.IsSet("neighbor.afi-safis") { if ip := net.ParseIP(n.Config.NeighborAddress); ip.To4() != nil { n.AfiSafis = []AfiSafi{defaultAfiSafi(AFI_SAFI_TYPE_IPV4_UNICAST, true)} diff --git a/server/fsm.go b/server/fsm.go index c369b432..3069893b 100644 --- a/server/fsm.go +++ b/server/fsm.go @@ -294,30 +294,21 @@ func (fsm *FSM) connectLoop() error { laddr := fsm.pConf.Transport.Config.LocalAddress var conn net.Conn var err error - if laddr != "" { - if fsm.pConf.Config.AuthPassword != "" { - deadline := (MIN_CONNECT_RETRY - 1) * 1000 // msec - conn, err = DialTCPTimeoutWithMD5Sig(addr, port, laddr, fsm.pConf.Config.AuthPassword, deadline) - } else { - lhost := net.JoinHostPort(laddr, "0") - ltcpaddr, e := net.ResolveTCPAddr("tcp", lhost) - if e != nil { - log.WithFields(log.Fields{ - "Topic": "Peer", - "Key": fsm.pConf.Config.NeighborAddress, - }).Warnf("failed to resolve ltcpaddr: %s", e) - return - } - d := net.Dialer{LocalAddr: ltcpaddr, Timeout: time.Duration(MIN_CONNECT_RETRY-1) * time.Second} - conn, err = d.Dial("tcp", host) - } + if fsm.pConf.Config.AuthPassword != "" { + deadline := (MIN_CONNECT_RETRY - 1) * 1000 // msec + conn, err = DialTCPTimeoutWithMD5Sig(addr, port, laddr, fsm.pConf.Config.AuthPassword, deadline) } else { - if fsm.pConf.Config.AuthPassword != "" { - deadline := (MIN_CONNECT_RETRY - 1) * 1000 // msec - conn, err = DialTCPTimeoutWithMD5Sig(addr, port, "0.0.0.0", fsm.pConf.Config.AuthPassword, deadline) - } else { - conn, err = net.DialTimeout("tcp", host, time.Duration(MIN_CONNECT_RETRY-1)*time.Second) + lhost := net.JoinHostPort(laddr, "0") + ltcpaddr, e := net.ResolveTCPAddr("tcp", lhost) + if e != nil { + log.WithFields(log.Fields{ + "Topic": "Peer", + "Key": fsm.pConf.Config.NeighborAddress, + }).Warnf("failed to resolve ltcpaddr: %s", e) + return } + d := net.Dialer{LocalAddr: ltcpaddr, Timeout: time.Duration(MIN_CONNECT_RETRY-1) * time.Second} + conn, err = d.Dial("tcp", host) } if err == nil { |