summaryrefslogtreecommitdiffhomepage
path: root/server/fsm.go
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2016-03-12 09:34:00 +0900
committerISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2016-03-12 10:05:57 +0900
commit376d5b3bb8fa65ace77bc3423e16ee2078038058 (patch)
tree997e9601849991d89b933d191d5aacc78efc2f81 /server/fsm.go
parent79a8275508e252213c857151f27a93abae43f6a1 (diff)
fsm: support active connection with md5 and binding
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'server/fsm.go')
-rw-r--r--server/fsm.go46
1 files changed, 22 insertions, 24 deletions
diff --git a/server/fsm.go b/server/fsm.go
index 94ee588e..168a0387 100644
--- a/server/fsm.go
+++ b/server/fsm.go
@@ -293,43 +293,41 @@ func (fsm *FSM) connectLoop() error {
host := net.JoinHostPort(addr, strconv.Itoa(bgp.BGP_PORT))
// check if LocalAddress has been configured
laddr := fsm.pConf.Transport.Config.LocalAddress
+ var conn net.Conn
+ var err error
if laddr != "" {
- lhost := net.JoinHostPort(laddr, "0")
- ltcpaddr, err := net.ResolveTCPAddr("tcp", lhost)
- if err != nil {
- log.WithFields(log.Fields{
- "Topic": "Peer",
- "Key": fsm.pConf.Config.NeighborAddress,
- }).Warnf("failed to resolve ltcpaddr: %s", err)
+ if fsm.pConf.Config.AuthPassword != "" {
+ deadline := (MIN_CONNECT_RETRY - 1) * 1000 // msec
+ conn, err = DialTCPTimeoutWithMD5Sig(addr, bgp.BGP_PORT, laddr, fsm.pConf.Config.AuthPassword, deadline)
} else {
- d := net.Dialer{LocalAddr: ltcpaddr, Timeout: time.Duration(MIN_CONNECT_RETRY-1) * time.Second}
- if conn, err := d.Dial("tcp", host); err == nil {
- fsm.connCh <- conn
- } 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,
- }).Debugf("failed to connect from ltcpaddr", err)
+ }).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)
}
-
} else {
- var conn net.Conn
- var err error
if fsm.pConf.Config.AuthPassword != "" {
deadline := (MIN_CONNECT_RETRY - 1) * 1000 // msec
- conn, err = DialTCPTimeoutWithMD5Sig(addr, bgp.BGP_PORT, fsm.pConf.Config.AuthPassword, deadline)
+ conn, err = DialTCPTimeoutWithMD5Sig(addr, bgp.BGP_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)
}
- if err == nil {
- fsm.connCh <- conn
- } else {
- log.WithFields(log.Fields{
- "Topic": "Peer",
- "Key": fsm.pConf.Config.NeighborAddress,
- }).Debugf("failed to connect: %s", err)
- }
+ }
+
+ if err == nil {
+ fsm.connCh <- conn
+ } else {
+ log.WithFields(log.Fields{
+ "Topic": "Peer",
+ "Key": fsm.pConf.Config.NeighborAddress,
+ }).Debugf("failed to connect: %s", err)
}
}
}