Mark Bergsma has submitted this change and it was merged. ( )

Change subject: Allow BGP socket to listen on specific IPs and port

Allow BGP socket to listen on specific IPs and port

Add global config option bgp-local-ips (default empty: all IPs) which
takes a set of IPs for BGP to bind to.
Add global config option bgp-local-port to override the
default TCP port 179.

Error handling has been altered to log a critical message and raise
an exception if pybal fails to bind to the port on on one of the IP
addresses, instead of ignoring it.

Bug: T103882
Change-Id: I0e4a1cae515602eea8ab07bffb61b9009d5a995a
M pybal/
1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/pybal/ b/pybal/
index 5392bcb..b967837 100755
--- a/pybal/
+++ b/pybal/
@@ -8,6 +8,7 @@
 from twisted.internet import reactor
+from twisted.internet.error import CannotListenError
 from pybal.util import log
@@ -67,11 +68,23 @@
             reactor.addSystemEventTrigger('before', 'shutdown', 
self.closeSession, self.bgpPeering)
-            try:
-                # Try to listen on the BGP port, not fatal if fails
-                reactor.listenTCP(bgp.PORT, 
bgp.BGPServerFactory({self.bgpPeering.peerAddr: self.bgpPeering}))
-            except Exception:
-                pass
+            # Bind on the IPs listed in 'bgp_local_ips'. Default to
+            # localhost v4 and v6 if no IPs have been specified in the
+            # configuration.
+            bgp_local_ips = eval(self.globalConfig.get('bgp-local-ips', 
+            bgp_local_port = self.globalConfig.getint('bgp-local-port', 
+            # Try to listen on the BGP port, not fatal if fails
+            for ip in bgp_local_ips:
+                try:
+                    reactor.listenTCP(
+                        bgp_local_port,
+                        bgp.BGPServerFactory({self.bgpPeering.peerAddr: 
+                        interface=ip)
+                except CannotListenError as e:
+                    log.critical(
+                        "Could not listen for BGP connections: " + str(e))
+                    raise
     def closeSession(self, peering):"Clearing session to {}".format(peering.peerAddr))

To view, visit
To unsubscribe, visit

Gerrit-MessageType: merged
Gerrit-Change-Id: I0e4a1cae515602eea8ab07bffb61b9009d5a995a
Gerrit-PatchSet: 3
Gerrit-Project: operations/debs/pybal
Gerrit-Branch: master
Gerrit-Owner: Mark Bergsma <>
Gerrit-Reviewer: Giuseppe Lavagetto <>
Gerrit-Reviewer: Mark Bergsma <>
Gerrit-Reviewer: Volans <>
Gerrit-Reviewer: jenkins-bot <>

MediaWiki-commits mailing list

Reply via email to