From f55004a574aecd11f31e2d0a54bca11c70db9934 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sun, 3 Nov 2024 17:54:59 +0200 Subject: [PATCH 1/5] Allow binding to IPv6 (if present) If an interface has an IPv6 address record associated with it then, and only then, prefer that. Otherwise AF_INET is used (Ipv4 address) --- RNS/Interfaces/TCPInterface.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/RNS/Interfaces/TCPInterface.py b/RNS/Interfaces/TCPInterface.py index 54eadb0..2c6a036 100644 --- a/RNS/Interfaces/TCPInterface.py +++ b/RNS/Interfaces/TCPInterface.py @@ -412,6 +412,11 @@ class TCPServerInterface(Interface): def get_address_for_if(name): import RNS.vendor.ifaddr.niwrapper as netinfo ifaddr = netinfo.ifaddresses(name) + + # IPv6 preference (if present) + if(netinfo.AF_INET6 in ifaddr): + return ifaddr[netinfo.AF_INET6][0]["addr"] + return ifaddr[netinfo.AF_INET][0]["addr"] @staticmethod From 18c2a38b97e4040ac3ee50070bff700abfd3e965 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Mon, 4 Nov 2024 13:02:45 +0200 Subject: [PATCH 2/5] Test --- RNS/Interfaces/TCPInterface.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/RNS/Interfaces/TCPInterface.py b/RNS/Interfaces/TCPInterface.py index 2c6a036..6c02c74 100644 --- a/RNS/Interfaces/TCPInterface.py +++ b/RNS/Interfaces/TCPInterface.py @@ -200,7 +200,9 @@ class TCPClientInterface(Interface): if initial: RNS.log("Establishing TCP connection for "+str(self)+"...", RNS.LOG_DEBUG) - self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + addrInfo=socket.getaddrinfo(self.target_ip, self.target_port) + addrFam=addrInfo[0] + self.socket = socket.socket(addrFam, socket.SOCK_STREAM) self.socket.settimeout(TCPClientInterface.INITIAL_CONNECT_TIMEOUT) self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) self.socket.connect((self.target_ip, self.target_port)) From 35990663564724796fb25381d197ae9ec08a195a Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Mon, 4 Nov 2024 13:05:27 +0200 Subject: [PATCH 3/5] Revert "Test" This reverts commit 18c2a38b97e4040ac3ee50070bff700abfd3e965. --- RNS/Interfaces/TCPInterface.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/RNS/Interfaces/TCPInterface.py b/RNS/Interfaces/TCPInterface.py index 6c02c74..2c6a036 100644 --- a/RNS/Interfaces/TCPInterface.py +++ b/RNS/Interfaces/TCPInterface.py @@ -200,9 +200,7 @@ class TCPClientInterface(Interface): if initial: RNS.log("Establishing TCP connection for "+str(self)+"...", RNS.LOG_DEBUG) - addrInfo=socket.getaddrinfo(self.target_ip, self.target_port) - addrFam=addrInfo[0] - self.socket = socket.socket(addrFam, socket.SOCK_STREAM) + self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.socket.settimeout(TCPClientInterface.INITIAL_CONNECT_TIMEOUT) self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) self.socket.connect((self.target_ip, self.target_port)) From 61712d322ae45f5944656239b042884d44732364 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Mon, 4 Nov 2024 13:25:46 +0200 Subject: [PATCH 4/5] Revert "Allow binding to IPv6 (if present)" This reverts commit f55004a574aecd11f31e2d0a54bca11c70db9934. --- RNS/Interfaces/TCPInterface.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/RNS/Interfaces/TCPInterface.py b/RNS/Interfaces/TCPInterface.py index 2c6a036..54eadb0 100644 --- a/RNS/Interfaces/TCPInterface.py +++ b/RNS/Interfaces/TCPInterface.py @@ -412,11 +412,6 @@ class TCPServerInterface(Interface): def get_address_for_if(name): import RNS.vendor.ifaddr.niwrapper as netinfo ifaddr = netinfo.ifaddresses(name) - - # IPv6 preference (if present) - if(netinfo.AF_INET6 in ifaddr): - return ifaddr[netinfo.AF_INET6][0]["addr"] - return ifaddr[netinfo.AF_INET][0]["addr"] @staticmethod From 63ad2afe3ff52fa9330a99f01f8c7191e0252bda Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Mon, 4 Nov 2024 13:25:55 +0200 Subject: [PATCH 5/5] Reapply "Allow binding to IPv6 (if present)" This reverts commit 61712d322ae45f5944656239b042884d44732364. --- RNS/Interfaces/TCPInterface.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/RNS/Interfaces/TCPInterface.py b/RNS/Interfaces/TCPInterface.py index 54eadb0..2c6a036 100644 --- a/RNS/Interfaces/TCPInterface.py +++ b/RNS/Interfaces/TCPInterface.py @@ -412,6 +412,11 @@ class TCPServerInterface(Interface): def get_address_for_if(name): import RNS.vendor.ifaddr.niwrapper as netinfo ifaddr = netinfo.ifaddresses(name) + + # IPv6 preference (if present) + if(netinfo.AF_INET6 in ifaddr): + return ifaddr[netinfo.AF_INET6][0]["addr"] + return ifaddr[netinfo.AF_INET][0]["addr"] @staticmethod