|
1 | 1 | import enum
|
2 |
| -import ipaddress |
3 | 2 | import logging
|
4 | 3 | import os
|
5 | 4 | import time
|
|
12 | 11 | from tempfile import mkdtemp
|
13 | 12 | from typing import Any, Callable, Optional, TextIO, Tuple
|
14 | 13 |
|
15 |
| -from eduvpn_common.main import Jar |
| 14 | +from eduvpn_common.main import EduVPN, Jar |
16 | 15 | from gi.repository.Gio import Cancellable, Task # type: ignore
|
17 | 16 |
|
18 | 17 | from eduvpn.ovpn import Ovpn
|
@@ -81,15 +80,16 @@ def from_active_state(cls, state: "NM.ActiveConnectionState") -> "ConnectionStat
|
81 | 80 |
|
82 | 81 | # A manager for a manager :-)
|
83 | 82 | class NMManager:
|
84 |
| - def __init__(self, variant: ApplicationVariant): |
| 83 | + def __init__(self, variant: ApplicationVariant, common_lib: EduVPN): |
85 | 84 | self.variant = variant
|
86 | 85 | self.proxy = None
|
87 | 86 | try:
|
88 | 87 | self._client = NM.Client.new(None)
|
89 |
| - self.wg_gateway_ip: Optional[ipaddress.IPv4Address] = None |
| 88 | + self.wg_gateway_ip: Optional[str] = None |
90 | 89 | except Exception:
|
91 | 90 | self._client = None
|
92 | 91 | self.cancel_jar = Jar(lambda x: x.cancel())
|
| 92 | + self.common_lib = common_lib |
93 | 93 |
|
94 | 94 | @property
|
95 | 95 | def client(self) -> "NM.Client":
|
@@ -304,7 +304,7 @@ def failover_endpoint_ip(self) -> Optional[str]:
|
304 | 304 | if not self.wg_gateway_ip:
|
305 | 305 | _logger.debug("no wg gateway ip found in failover endpoint")
|
306 | 306 | return None
|
307 |
| - return str(self.wg_gateway_ip) |
| 307 | + return self.wg_gateway_ip |
308 | 308 | else:
|
309 | 309 | _logger.debug(f"Unknown protocol: {protocol}")
|
310 | 310 | return None
|
@@ -452,7 +452,8 @@ def start_wireguard_connection( # noqa: C901
|
452 | 452 | addr = ip_interface(ip.strip())
|
453 | 453 | if addr.version == 4:
|
454 | 454 | if not self.wg_gateway_ip:
|
455 |
| - self.wg_gateway_ip = addr.network[1] |
| 455 | + net_str = str(addr.network) |
| 456 | + self.wg_gateway_ip = self.common_lib.calculate_gateway(net_str) |
456 | 457 | ipv4s.append(NM.IPAddress(AF_INET, str(addr.ip), addr.network.prefixlen))
|
457 | 458 | elif addr.version == 6:
|
458 | 459 | ipv6s.append(NM.IPAddress(AF_INET6, str(addr.ip), addr.network.prefixlen))
|
|
0 commit comments