summaryrefslogtreecommitdiffhomepage
path: root/server/fsm.go
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2017-07-11 10:45:30 +0900
committerIWASE Yusuke <iwase.yusuke0@gmail.com>2017-07-18 15:11:01 +0900
commit178e65f8f113da82f8dfcc56b5fa7682da1bd932 (patch)
tree52b423ccf52b64d14b278fb39d8e6a3e399488b2 /server/fsm.go
parenteb95f000bf4ab70c2dad7589e58045fbce1addf1 (diff)
server: Set outgoing TTL before dialing
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'server/fsm.go')
-rw-r--r--server/fsm.go46
1 files changed, 25 insertions, 21 deletions
diff --git a/server/fsm.go b/server/fsm.go
index 953e2f7d..55a3aa0c 100644
--- a/server/fsm.go
+++ b/server/fsm.go
@@ -329,28 +329,32 @@ func (fsm *FSM) connectLoop() error {
if fsm.pConf.Transport.Config.RemotePort != 0 {
port = int(fsm.pConf.Transport.Config.RemotePort)
}
- host := net.JoinHostPort(addr, strconv.Itoa(port))
- // check if LocalAddress has been configured
- laddr := fsm.pConf.Transport.Config.LocalAddress
+ laddr, err := net.ResolveTCPAddr("tcp", net.JoinHostPort(fsm.pConf.Transport.Config.LocalAddress, "0"))
+ if err != nil {
+ log.WithFields(log.Fields{
+ "Topic": "Peer",
+ "Key": fsm.pConf.State.NeighborAddress,
+ }).Warn("failed to resolve local address: %s", err)
+ return
+ }
var conn net.Conn
- var err error
- 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.State.NeighborAddress,
- }).Warnf("failed to resolve ltcpaddr: %s", e)
- return
+ d := TCPDialer{
+ Dialer: net.Dialer{
+ LocalAddr: laddr,
+ Timeout: time.Duration(MIN_CONNECT_RETRY-1) * time.Second,
+ },
+ AuthPassword: fsm.pConf.Config.AuthPassword,
+ }
+ if fsm.pConf.TtlSecurity.Config.Enabled {
+ d.Ttl = 255
+ d.TtlMin = fsm.pConf.TtlSecurity.Config.TtlMin
+ } else if fsm.pConf.Config.PeerAs != 0 && fsm.pConf.Config.PeerType == config.PEER_TYPE_EXTERNAL {
+ d.Ttl = 1
+ if fsm.pConf.EbgpMultihop.Config.Enabled {
+ d.Ttl = fsm.pConf.EbgpMultihop.Config.MultihopTtl
}
- d := net.Dialer{LocalAddr: ltcpaddr, Timeout: time.Duration(MIN_CONNECT_RETRY-1) * time.Second}
- conn, err = d.Dial("tcp", host)
}
-
+ conn, err = d.DialTCP(addr, port)
if err == nil {
select {
case fsm.connCh <- conn:
@@ -505,7 +509,7 @@ func (h *FSMHandler) active() (bgp.FSMState, FsmStateReason) {
ttl = int(fsm.pConf.Transport.Config.Ttl)
}
if ttl != 0 {
- if err := SetTcpTTLSockopts(conn.(*net.TCPConn), ttl); err != nil {
+ if err := SetTcpTTLSockopt(conn.(*net.TCPConn), ttl); err != nil {
log.WithFields(log.Fields{
"Topic": "Peer",
"Key": fsm.pConf.Config.NeighborAddress,
@@ -514,7 +518,7 @@ func (h *FSMHandler) active() (bgp.FSMState, FsmStateReason) {
}
}
if ttlMin != 0 {
- if err := SetTcpMinTTLSockopts(conn.(*net.TCPConn), ttlMin); err != nil {
+ if err := SetTcpMinTTLSockopt(conn.(*net.TCPConn), ttlMin); err != nil {
log.WithFields(log.Fields{
"Topic": "Peer",
"Key": fsm.pConf.Config.NeighborAddress,