Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made interface to an optional parameter #153

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion broker/l2tp_broker.cfg.example
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 12 additions & 5 deletions broker/src/tunneldigger_broker/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
RalfJung marked this conversation as resolved.
Show resolved Hide resolved
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)
Expand Down
3 changes: 2 additions & 1 deletion broker/src/tunneldigger_broker/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down