p2p: set IPV6_FREEBIND for tentative nan_data0 and fallback Direct passphrase

This commit is contained in:
nayan
2026-12-02 18:49:44 -05:00
parent f75aabc2c9
commit 4b3fa2dc4e
2 changed files with 8 additions and 0 deletions
@@ -127,6 +127,11 @@ class P2pTlsServer:
except OSError:
pass
if family == socket.AF_INET6:
ipv6_freebind = getattr(socket, "IPV6_FREEBIND", 78)
try:
sock.setsockopt(socket.IPPROTO_IPV6, ipv6_freebind, 1)
except OSError:
pass
scope_id = socket.if_nametoindex(self._bind_interface) if self._bind_interface else 0
sock.bind((host_clean, self._port, 0, scope_id))
else:
@@ -95,6 +95,9 @@ class WifiDirectTransport:
kv = dict(line.split("=", 1) for line in status_out.splitlines() if "=" in line)
ssid = kv.get("ssid", f"DIRECT-{session_id[:6]}")
passphrase = subprocess.run(["wpa_cli", "-i", iface, "p2p_get_passphrase"], capture_output=True, text=True, timeout=5, check=False).stdout.strip()
if not passphrase or passphrase == "FAIL":
passphrase = secrets.token_urlsafe(12)
subprocess.run(["wpa_cli", "-i", iface, "set_network", "0", "psk", f'"{passphrase}"'], capture_output=True, text=True, timeout=5, check=False)
subprocess.run(["sudo", "ip", "addr", "replace", f"{P2P_DIRECT_IP}/24", "dev", iface], check=False, timeout=5)
subprocess.run(["sudo", "ip", "link", "set", iface, "up"], check=False, timeout=5)