From 5ebb34382db4cc65a166cd5f89fb859f43df9ee8 Mon Sep 17 00:00:00 2001 From: RobWei Date: Thu, 1 Oct 2020 10:12:09 +0200 Subject: [PATCH 1/2] * made interface to an optional parameter Since we are now running a tunneligger broker instance on a routed IP address, I noticed that the tunneligger does not work with a loopback interface. To the basic structure: Our IPv4 subnet is announced via BGP on several interfaces. An IP from the subnet is configured on the loopback interface. A short analysis of the pollable object showed that the UDP socket is bound to an interface. I could not find out why this was done. This change allows to define interfaces optionally. --- broker/src/tunneldigger_broker/main.py | 17 ++++++++++++----- broker/src/tunneldigger_broker/network.py | 3 ++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/broker/src/tunneldigger_broker/main.py b/broker/src/tunneldigger_broker/main.py index 57bba470..1f9d89ae 100644 --- a/broker/src/tunneldigger_broker/main.py +++ b/broker/src/tunneldigger_broker/main.py @@ -91,11 +91,18 @@ broker_host = config.get('broker', 'address') for port in config.get('broker', 'port').split(','): try: - broker_instance = broker.Broker( - (broker_host, int(port)), - config.get('broker', 'interface'), - tunnel_manager, - ) + if config.has_option('broker', 'interface'): + broker_instance = broker.Broker( + (broker_host, int(port)), + config.get('broker', 'interface'), + tunnel_manager, + ) + else: + broker_instance = broker.Broker( + (broker_host, int(port)), + None, + tunnel_manager, + ) logger.info("Listening on %s:%d." % broker_instance.address) except ValueError: logger.warning("Malformed port number '%s', skipping." % port) diff --git a/broker/src/tunneldigger_broker/network.py b/broker/src/tunneldigger_broker/network.py index da058444..bf9b5504 100644 --- a/broker/src/tunneldigger_broker/network.py +++ b/broker/src/tunneldigger_broker/network.py @@ -36,7 +36,8 @@ def __init__(self, address, interface): # Since we want all tunnel and tunnel control traffic to use the same port for # all clients we enable reuse of ports on the sockets we create. self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) - self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE, interface.encode('utf-8')) + if interface is not None: + self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE, interface.encode('utf-8')) self.socket.bind(address) self.address = address From 3936320757ce88a02d867cef3484cb4aefc98c04 Mon Sep 17 00:00:00 2001 From: RobWei Date: Mon, 5 Oct 2020 10:08:58 +0200 Subject: [PATCH 2/2] * docs: made interface optional --- broker/l2tp_broker.cfg.example | 2 +- docs/server.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/broker/l2tp_broker.cfg.example b/broker/l2tp_broker.cfg.example index 19b517d3..d630d9c9 100644 --- a/broker/l2tp_broker.cfg.example +++ b/broker/l2tp_broker.cfg.example @@ -3,7 +3,7 @@ address=127.0.0.1 ; Ports where the broker will listen on port=53,123,8942 -; Interface with that IP address +; Interface with that IP address (optional) interface=lo ; Maximum number of tunnels that will be allowed by the broker. ; On a cheap VPS, more than 256 tunnels usually do not make sense. diff --git a/docs/server.rst b/docs/server.rst index 64512a79..296e58a2 100644 --- a/docs/server.rst +++ b/docs/server.rst @@ -177,7 +177,7 @@ changed and some that can be left as default: * **port** should be configured with the external port (or ports separated by commas) that the clients will use to connect with the broker. -* **interface** should be configured with the name of the external interface that the clients will connect to. +* **interface** is a optional parameter and should be configured with the name of the external interface that the clients will connect to. * Hooks in the **hooks** section should be configured with paths to executable scripts that will be called when certain events occur in the broker. They are empty by default which means that tunnels will be established but they will not be configured.