Three fixes for reads that came back empty or wrong on a VMG4005-B50A (V5.17(ABQA.3.1)C0). There is one commit per issue.
#25: the DAL's answer is decrypted before it is read
What was wrong: hosts, the ARP table, port forwards, SSIDs, radios and Wi-Fi clients were always empty.
Cause: a GET of the DAL answers sealed ({"content", "iv"}), the same as a PUT. _read_dal_or_page parsed that envelope as it came and found none of its keys in it. Nothing raised, so the HTML fallback never ran either. Two more problems showed up once the answer was decrypted:
The data sits under Object.
The gateway answers LAN_HOSTS and NAT_PORTMAP the same way it answers any name it does not know: ZCFG_SUCCESS with an empty Object. Its own web interface reads lanhosts and nat instead.
Fix:
Every DAL GET goes through _dal_get, which decrypts the answer, requires ZCFG_SUCCESS with an Object list, and returns that list.
_status_page and the System page now share the same decryption (_unseal).
Hosts are read from lanhosts:
A host the gateway calls "Unknown" gets the host name "".
interface_type is LAN or WLAN.
Only DHCP hosts carry a lease.
Port forwards are read from nat. The field names come from the gateway's own NAT page (ExternalPortStart, InternalClient, ...):
A TCP/UDP rule is reported once per protocol.
A rule limited to one source address reports it as remote_host.
The new parsers live in napalm_zyxel/parsers.py, which is under strict mypy.
Not verified: the Wi-Fi getters are now decrypted too, but they still ask for WIFI_CLIENTS, WIFI_SSIDS and WIFI_RADIO. The recorded gateway has no Wi-Fi, so there was no answer to check these names or their fields against. The README says so.
#29: the uplink is read from the gateway's status page
What was wrong:get_wan_status reported every uplink as down. get_nat_translations reported ":<port>".
Cause: both read WanIp, WanAccessType, SystemUpTime, MaxUpstream and MaxDownstream from getBasicInformation, which does not contain them.
Fix: both now read the DAL's cardpage_status.
Bridge: it has no WAN address of its own. It counts as connected when its DSL line is in sync, meaning a DslChannelInfo entry has Status"Up".
Router: it counts as connected when a WAN interface that is not IP_Bridged is up and has an address. That address is external_ip.
Rates: the sync rates are those of the channels in sync, added up for bonded lines. A channel out of sync keeps the rates of its last sync; those are not reported.
NAT translations: a translation goes to the WAN address, or to 0.0.0.0 when there is none. Without enabled forwards, the status page is not read at all.
Line state at recording time: both DSL lines read Down/LowerLayerDown. DslLineInfo in oid=status says LinkStatus: NoSignal. So that gateway still reads as down after this fix, and correctly so. The in-sync and router cases are derived from the recorded page, not recorded.
#24: get_facts is checked against the recorded answers
Already fixed in code:#26 reads the host name and domain from the System page, and #28 reads the serial number and uptime from cardpage_status.
What this commit changes:
The invented MOCK_BASIC_INFO (serial number, WanIp, MAC, uptime) becomes the recorded getBasicInformation, which holds model, firmware and language settings only.
A new test reads the facts from the recorded, sealed status page. Run against the driver from before #26, it fails with this issue's symptoms: serial "", uptime 0, and the connection address as host name.
The README names the sources get_facts reads.
Host name: the gateway does have a source for it. It is the System page, as since #26; oid=statusSystemInfo.HostName carries the same name.
Tests
How it was tested: fixtures only. They were recorded read-only from a VMG4005-B50A (V5.17(ABQA.3.1)C0), using only GETs. They are stored in tests/fixtures/ and anonymised:
addresses moved to 192.0.2.0/24
MAC addresses replaced by placeholders
the serial number replaced
the provisioning key and PLOAM password emptied
tests/gateway.py seals each fixture with a real ZyxelCrypto, so the driver decrypts what it reads.
Three fixes for reads that came back empty or wrong on a VMG4005-B50A (V5.17(ABQA.3.1)C0). There is one commit per issue.
## #25: the DAL's answer is decrypted before it is read
**What was wrong:** hosts, the ARP table, port forwards, SSIDs, radios and Wi-Fi clients were always empty.
**Cause:** a GET of the DAL answers sealed (`{"content", "iv"}`), the same as a PUT. `_read_dal_or_page` parsed that envelope as it came and found none of its keys in it. Nothing raised, so the HTML fallback never ran either. Two more problems showed up once the answer was decrypted:
- The data sits under `Object`.
- The gateway answers `LAN_HOSTS` and `NAT_PORTMAP` the same way it answers any name it does not know: `ZCFG_SUCCESS` with an empty `Object`. Its own web interface reads `lanhosts` and `nat` instead.
**Fix:**
- Every DAL GET goes through `_dal_get`, which decrypts the answer, requires `ZCFG_SUCCESS` with an `Object` list, and returns that list.
- `_status_page` and the System page now share the same decryption (`_unseal`).
- Hosts are read from `lanhosts`:
- A host the gateway calls `"Unknown"` gets the host name `""`.
- `interface_type` is `LAN` or `WLAN`.
- Only DHCP hosts carry a lease.
- Port forwards are read from `nat`. The field names come from the gateway's own NAT page (`ExternalPortStart`, `InternalClient`, ...):
- A `TCP/UDP` rule is reported once per protocol.
- A rule limited to one source address reports it as `remote_host`.
- The new parsers live in `napalm_zyxel/parsers.py`, which is under strict mypy.
**Not verified:** the Wi-Fi getters are now decrypted too, but they still ask for `WIFI_CLIENTS`, `WIFI_SSIDS` and `WIFI_RADIO`. The recorded gateway has no Wi-Fi, so there was no answer to check these names or their fields against. The README says so.
## #29: the uplink is read from the gateway's status page
**What was wrong:** `get_wan_status` reported every uplink as down. `get_nat_translations` reported `":<port>"`.
**Cause:** both read `WanIp`, `WanAccessType`, `SystemUpTime`, `MaxUpstream` and `MaxDownstream` from `getBasicInformation`, which does not contain them.
**Fix:** both now read the DAL's `cardpage_status`.
- **Bridge:** it has no WAN address of its own. It counts as connected when its DSL line is in sync, meaning a `DslChannelInfo` entry has `Status` `"Up"`.
- **Router:** it counts as connected when a WAN interface that is not `IP_Bridged` is up and has an address. That address is `external_ip`.
- **Rates:** the sync rates are those of the channels in sync, added up for bonded lines. A channel out of sync keeps the rates of its last sync; those are not reported.
- **NAT translations:** a translation goes to the WAN address, or to `0.0.0.0` when there is none. Without enabled forwards, the status page is not read at all.
**Line state at recording time:** both DSL lines read `Down`/`LowerLayerDown`. `DslLineInfo` in `oid=status` says `LinkStatus: NoSignal`. So that gateway still reads as down after this fix, and correctly so. The in-sync and router cases are derived from the recorded page, not recorded.
## #24: get_facts is checked against the recorded answers
**Already fixed in code:** #26 reads the host name and domain from the System page, and #28 reads the serial number and uptime from `cardpage_status`.
**What this commit changes:**
- The invented `MOCK_BASIC_INFO` (serial number, `WanIp`, MAC, uptime) becomes the recorded `getBasicInformation`, which holds model, firmware and language settings only.
- A new test reads the facts from the recorded, sealed status page. Run against the driver from before #26, it fails with this issue's symptoms: serial `""`, uptime 0, and the connection address as host name.
- The README names the sources `get_facts` reads.
**Host name:** the gateway does have a source for it. It is the System page, as since #26; `oid=status` `SystemInfo.HostName` carries the same name.
## Tests
How it was tested: fixtures only. They were recorded read-only from a VMG4005-B50A (V5.17(ABQA.3.1)C0), using only GETs. They are stored in `tests/fixtures/` and anonymised:
- addresses moved to 192.0.2.0/24
- MAC addresses replaced by placeholders
- the serial number replaced
- the provisioning key and PLOAM password emptied
`tests/gateway.py` seals each fixture with a real `ZyxelCrypto`, so the driver decrypts what it reads.
New test files:
- `tests/test_dal_reads.py` (#25)
- `tests/test_wan_status.py` (#29)
- new cases in `tests/test_facts.py` (#24)
Results:
- 132 tests pass; coverage is 88%.
- `ruff`, `mypy`, `bandit`, `napalm-standard check` and `ratchet` are green.
- `_parse_wireless_clients_dal` has dropped below complexity 10, so its baseline entry is removed.
Closes #25
Closes #24
Closes #29
A GET of the DAL answers sealed ({"content", "iv"}), like a PUT does.
_read_dal_or_page parsed the envelope as it came, so hosts, the ARP
table, port forwards and the Wi-Fi getters found nothing on every
gateway, and since nothing raised the HTML fallback never ran either.
Every DAL GET now goes through one helper that decrypts the answer,
checks for ZCFG_SUCCESS and returns its Object list; the status page
and the System page share the decryption. Hosts are read from
lanhosts and port forwards from nat, the names the gateway's web
interface uses: LAN_HOSTS and NAT_PORTMAP are answered like any
unknown name, with an empty Object. The new parsers live in
napalm_zyxel/parsers.py, under strict mypy.
Tests seal recorded, anonymised answers of a VMG4005-B50A
(V5.17(ABQA.3.1)C0) with a real ZyxelCrypto, so the driver decrypts
them. The Wi-Fi DAL names stay unverified: that gateway has no Wi-Fi.
Closes#25
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
get_facts read SerialNumber, HostName, SystemUpTime and MacAddress
from getBasicInformation, which a VMG4005-B50A (V5.17(ABQA.3.1)C0)
answers with model, firmware and language settings only. The code
was fixed by #26 (host name and domain from the System page) and #28
(serial number and uptime from cardpage_status); the tests still fed
it an invented getBasicInformation (MOCK_BASIC_INFO) that carried
those fields, with an invented serial number and firmware.
MOCK_BASIC_INFO is now the recorded answer, and a new test reads the
facts from the recorded, sealed status page and the System page: it
fails against the driver before #26 with the symptoms of this issue
(serial "", uptime 0, host name the connection address). The README
names the sources get_facts reads.
Closes#24
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Three fixes for reads that came back empty or wrong on a VMG4005-B50A (V5.17(ABQA.3.1)C0). There is one commit per issue.
#25: the DAL's answer is decrypted before it is read
What was wrong: hosts, the ARP table, port forwards, SSIDs, radios and Wi-Fi clients were always empty.
Cause: a GET of the DAL answers sealed (
{"content", "iv"}), the same as a PUT._read_dal_or_pageparsed that envelope as it came and found none of its keys in it. Nothing raised, so the HTML fallback never ran either. Two more problems showed up once the answer was decrypted:Object.LAN_HOSTSandNAT_PORTMAPthe same way it answers any name it does not know:ZCFG_SUCCESSwith an emptyObject. Its own web interface readslanhostsandnatinstead.Fix:
_dal_get, which decrypts the answer, requiresZCFG_SUCCESSwith anObjectlist, and returns that list._status_pageand the System page now share the same decryption (_unseal).lanhosts:"Unknown"gets the host name"".interface_typeisLANorWLAN.nat. The field names come from the gateway's own NAT page (ExternalPortStart,InternalClient, ...):TCP/UDPrule is reported once per protocol.remote_host.napalm_zyxel/parsers.py, which is under strict mypy.Not verified: the Wi-Fi getters are now decrypted too, but they still ask for
WIFI_CLIENTS,WIFI_SSIDSandWIFI_RADIO. The recorded gateway has no Wi-Fi, so there was no answer to check these names or their fields against. The README says so.#29: the uplink is read from the gateway's status page
What was wrong:
get_wan_statusreported every uplink as down.get_nat_translationsreported":<port>".Cause: both read
WanIp,WanAccessType,SystemUpTime,MaxUpstreamandMaxDownstreamfromgetBasicInformation, which does not contain them.Fix: both now read the DAL's
cardpage_status.DslChannelInfoentry hasStatus"Up".IP_Bridgedis up and has an address. That address isexternal_ip.0.0.0.0when there is none. Without enabled forwards, the status page is not read at all.Line state at recording time: both DSL lines read
Down/LowerLayerDown.DslLineInfoinoid=statussaysLinkStatus: NoSignal. So that gateway still reads as down after this fix, and correctly so. The in-sync and router cases are derived from the recorded page, not recorded.#24: get_facts is checked against the recorded answers
Already fixed in code: #26 reads the host name and domain from the System page, and #28 reads the serial number and uptime from
cardpage_status.What this commit changes:
MOCK_BASIC_INFO(serial number,WanIp, MAC, uptime) becomes the recordedgetBasicInformation, which holds model, firmware and language settings only."", uptime 0, and the connection address as host name.get_factsreads.Host name: the gateway does have a source for it. It is the System page, as since #26;
oid=statusSystemInfo.HostNamecarries the same name.Tests
How it was tested: fixtures only. They were recorded read-only from a VMG4005-B50A (V5.17(ABQA.3.1)C0), using only GETs. They are stored in
tests/fixtures/and anonymised:tests/gateway.pyseals each fixture with a realZyxelCrypto, so the driver decrypts what it reads.New test files:
tests/test_dal_reads.py(#25)tests/test_wan_status.py(#29)tests/test_facts.py(#24)Results:
ruff,mypy,bandit,napalm-standard checkandratchetare green._parse_wireless_clients_dalhas dropped below complexity 10, so its baseline entry is removed.Closes #25
Closes #24
Closes #29
A GET of the DAL answers sealed ({"content", "iv"}), like a PUT does. _read_dal_or_page parsed the envelope as it came, so hosts, the ARP table, port forwards and the Wi-Fi getters found nothing on every gateway, and since nothing raised the HTML fallback never ran either. Every DAL GET now goes through one helper that decrypts the answer, checks for ZCFG_SUCCESS and returns its Object list; the status page and the System page share the decryption. Hosts are read from lanhosts and port forwards from nat, the names the gateway's web interface uses: LAN_HOSTS and NAT_PORTMAP are answered like any unknown name, with an empty Object. The new parsers live in napalm_zyxel/parsers.py, under strict mypy. Tests seal recorded, anonymised answers of a VMG4005-B50A (V5.17(ABQA.3.1)C0) with a real ZyxelCrypto, so the driver decrypts them. The Wi-Fi DAL names stay unverified: that gateway has no Wi-Fi. Closes #25