diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-10-01 17:03:53 +0900 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-10-01 17:03:53 +0900 |
commit | 40742a4194f137a7add1e1fb612919e25fde6a28 (patch) | |
tree | 8bc609c632a2a0e5350b3f05ecbff7fc6ecf4b14 /server | |
parent | f9300d8cfeafa4b69c236cb64004094a495c52bb (diff) |
server: give change to handle accepted conn before handling paths
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r-- | server/server.go | 76 |
1 files changed, 41 insertions, 35 deletions
diff --git a/server/server.go b/server/server.go index 88fad8d6..1e111c09 100644 --- a/server/server.go +++ b/server/server.go @@ -268,12 +268,52 @@ func (server *BgpServer) Serve() { firstBroadcastMsg = server.broadcastMsgs[0] } + passConn := func(conn *net.TCPConn) { + remoteAddr, _, _ := net.SplitHostPort(conn.RemoteAddr().String()) + peer, found := server.neighborMap[remoteAddr] + if found { + localAddrValid := func(laddr net.IP) bool { + if laddr == nil { + return true + } + l := conn.LocalAddr() + if l == nil { + // already closed + return false + } + + host, _, _ := net.SplitHostPort(l.String()) + if host != laddr.String() { + log.WithFields(log.Fields{ + "Topic": "Peer", + "Key": remoteAddr, + "Configured addr": laddr.String(), + "Addr": host, + }).Info("Mismatched local address") + return false + } + return true + }(peer.conf.Transport.TransportConfig.LocalAddress) + if localAddrValid == false { + conn.Close() + return + } + log.Debug("accepted a new passive connection from ", remoteAddr) + peer.PassConn(conn) + } else { + log.Info("can't find configuration for a new passive connection from ", remoteAddr) + conn.Close() + } + } + select { case grpcReq := <-server.GrpcReqCh: m := server.handleGrpc(grpcReq) if len(m) > 0 { senderMsgs = append(senderMsgs, m...) } + case conn := <-acceptCh: + passConn(conn) default: } @@ -314,41 +354,7 @@ func (server *BgpServer) Serve() { senderMsgs = append(senderMsgs, m...) } case conn := <-acceptCh: - remoteAddr, _, _ := net.SplitHostPort(conn.RemoteAddr().String()) - peer, found := server.neighborMap[remoteAddr] - if found { - localAddrValid := func(laddr net.IP) bool { - if laddr == nil { - return true - } - l := conn.LocalAddr() - if l == nil { - // already closed - return false - } - - host, _, _ := net.SplitHostPort(l.String()) - if host != laddr.String() { - log.WithFields(log.Fields{ - "Topic": "Peer", - "Key": remoteAddr, - "Configured addr": laddr.String(), - "Addr": host, - }).Info("Mismatched local address") - return false - } - return true - }(peer.conf.Transport.TransportConfig.LocalAddress) - if localAddrValid == false { - conn.Close() - continue - } - log.Debug("accepted a new passive connection from ", remoteAddr) - peer.PassConn(conn) - } else { - log.Info("can't find configuration for a new passive connection from ", remoteAddr) - conn.Close() - } + passConn(conn) case config := <-server.addedPeerCh: addr := config.NeighborConfig.NeighborAddress.String() _, found := server.neighborMap[addr] |