Skip to content

Commit

Permalink
BMP Receiver: Close Connection Explicitly and with log message (#417)
Browse files Browse the repository at this point in the history
Co-authored-by: Marvin Gaube <marvin.gaube@exaring.de>
  • Loading branch information
margau and Marvin Gaube authored Jan 19, 2023
1 parent ecd3fda commit e47d554
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion protocols/bgp/server/bmp_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,14 @@ func (b *BMPReceiver) Serve() error {
}

// Do we know this router from configuration or have seen it before?
r := b.getRouter(c.RemoteAddr().(*net.TCPAddr).IP.String())
remoteAddr := c.RemoteAddr().(*net.TCPAddr).IP.String()
r := b.getRouter(remoteAddr)
dynamic := false
if r == nil {
// If we don't know this router and don't accept connection from anyone, we drop it
if !b.acceptAny {
log.Infof("Drop connection from %v, not in routers and acceptAny disabled", remoteAddr)
c.Close()
continue
}

Expand All @@ -127,12 +130,15 @@ func (b *BMPReceiver) Serve() error {
err := b.AddRouter(tcpRemoteAddr.IP, localPort, true, dynamic)
if err != nil {
log.Errorf("failed to add router: %v", err)
c.Close()
continue
}

r = b.getRouter(tcpRemoteAddr.IP.String())
// Potentially we could have already removed this router if it were connecting twice and did not offer an init message
if r == nil {
log.Infof("Drop connection from %v, not in routers", remoteAddr)
c.Close()
continue
}
}
Expand Down

0 comments on commit e47d554

Please sign in to comment.