From 57d01ddcaa7e929f6c43ef2678afdbb10ec1f67b Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 28 Nov 2022 15:17:59 -0500 Subject: [PATCH] Base all web forwarding from 3901 This makes the web forwarding more predictable for firewall rules --- confluent_server/confluent/forwarder.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/confluent_server/confluent/forwarder.py b/confluent_server/confluent/forwarder.py index 5b7d5ee8..04ae8396 100644 --- a/confluent_server/confluent/forwarder.py +++ b/confluent_server/confluent/forwarder.py @@ -112,8 +112,17 @@ def get_port(addr, clientip, sessionid): if sessionid not in forwardersbyclient: forwardersbyclient[sessionid] = {} if addr not in forwardersbyclient[sessionid]: - newsock = eventlet.listen(('::', 0, 0, 0), - family=socket.AF_INET6) + newsock = socket.socket(socket.AF_INET6) + newport = 3901 + while newport: + try: + newsock.bind(('::', newport, 0, 0)) + newsock.listen(50) + break + except OSError as e: + if e.errno == 98: + newport += 1 + continue forwardersbyclient[sessionid][addr] = newsock sockhandler[newsock] = eventlet.spawn(forward_port, newsock, addr, clientip, sessionid)