fix(wan): read the uplink from the gateway's status page (#29)

get_wan_status built its answer from WanIp, WanAccessType,
SystemUpTime, MaxUpstream and MaxDownstream in getBasicInformation.
A VMG4005-B50A sends none of them there, so every gateway's uplink
read as down, with no address and no sync rate; get_nat_translations
built inside_global from the same WanIp and reported ":<port>".

Both now read the DAL's cardpage_status. A bridge has no WAN address
of its own, so it is connected when its DSL line is in sync (a
DslChannelInfo entry with Status "Up"); a router is connected when a
WAN interface that is not IP_Bridged is up with an address. The sync
rates are those of the channels in sync, added up for bonded lines;
a channel out of sync keeps its last rates, which are not reported.
A translation without a WAN address goes to 0.0.0.0, and without
enabled port forwards the status page is not read at all.

The tests read the recorded, anonymised status page of a
VMG4005-B50A bridge whose line was not in sync; the in-sync and
router states are derived from it.

Closes #29
This commit is contained in:
Christian Manivong committed 2026-11-12 19:05:48 +01:00
1 parent a47f9c3970
commit 3213dfaaaa
7 files changed
+672 -28

No files matched your search

+21 -19
View File
@@ -45,6 +45,10 @@ _SESSION_REFUSED = (401, 403)
_T = TypeVar("_T")
#: The inside-global address of a port forward when the gateway has no WAN address
#: (an address reported, not one bound to).
_ANY_ADDRESS = "0.0.0.0" # nosec B104
_PING_UNSUPPORTED = "Not supported on Zyxel VMG: the DAL does not report ping replies"
@@ -629,20 +633,13 @@ class ZyxelVMGDriver(ResidentialGatewayDriver):
pass
def get_wan_status(self) -> WANStatusDict:
"""Return WAN connection status from cached device info."""
info = self._device_info or {}
wan_ip = info.get("WanIp", "")
return {
"connection_type": info.get("WanAccessType", "VDSL"),
"is_connected": bool(wan_ip),
"external_ip": wan_ip,
"uptime": int(info.get("SystemUpTime", 0) or 0),
"bytes_sent": 0,
"bytes_received": 0,
"max_bitrate_up": int(info.get("MaxUpstream", 0) or 0) // 1000,
"max_bitrate_down": int(info.get("MaxDownstream", 0) or 0) // 1000,
"link_status": "Up" if wan_ip else "Down",
}
"""The uplink as the gateway's status page (``cardpage_status``) reports it (#29).
A bridge is connected when its DSL line is in sync and has no external address;
a router is connected when its WAN interface is up with an address. Byte
counters are not read: 0.
"""
return parsers.wan_status(self._status_page())
def get_port_forwards(self) -> list[PortForwardDict]:
"""The gateway's port forwards (DAL ``nat``), else the status page's."""
@@ -705,12 +702,17 @@ class ZyxelVMGDriver(ResidentialGatewayDriver):
return hosts
def get_nat_translations(self) -> list[NATTranslationDict]:
"""Return NAT translations derived from enabled port forwards."""
wan_ip = (self._device_info or {}).get("WanIp", "")
"""The enabled port forwards as translations to the gateway's WAN address.
Without a WAN address of its own (a bridge, or a WAN that is down) the
translation is to any address, ``0.0.0.0``.
"""
forwards = [forward for forward in self.get_port_forwards() if forward["enabled"]]
if not forwards:
return []
wan_ip = parsers.wan_address(self._status_page()) or _ANY_ADDRESS
translations: list[NATTranslationDict] = []
for forward in self.get_port_forwards():
if not forward["enabled"]:
continue
for forward in forwards:
translations.append(
{
"protocol": forward["protocol"].lower(),