From d5362fd382686fcff2ed10cd364ced52c26cc899 Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Sun, 1 Nov 2026 21:54:55 +0100 Subject: [PATCH 1/3] fix(fingerprint): drop the GS1920 and GS2210 switch patterns GS1920 and GS2210 are Zyxel switches. Counting them as evidence for a VMG gateway driver made discovery score a Zyxel switch higher for this driver than a real VMG gateway. Closes #4 --- CHANGELOG.md | 3 +++ napalm_zyxel/zyxel_driver.py | 2 -- tests/test_zyxel.py | 12 ++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e5098c..3d5e3d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ All notable changes to this driver. The format follows - `get_arp_table()` reports an unknown age as `-1.0` (napalm-device-types' `ARP_AGE_UNKNOWN`) instead of `0.0`, which means "confirmed just now": the host list says a host is active, not when the gateway last saw it (NetOrk/netork#1327). +- The HTTP fingerprint no longer counts `gs1920` and `gs2210` as evidence for this + driver: they are Zyxel switches, and discovery offered this gateway driver for + them (#4). ## [0.3.0] - 2026-10-23 diff --git a/napalm_zyxel/zyxel_driver.py b/napalm_zyxel/zyxel_driver.py index cab9c88..f2afa6d 100644 --- a/napalm_zyxel/zyxel_driver.py +++ b/napalm_zyxel/zyxel_driver.py @@ -95,8 +95,6 @@ class ZyxelVMGDriver(ResidentialGatewayDriver): OUI_PREFIXES = ["00:13:49", "1C:74:0D", "C8:6C:87", "B0:B2:DC", "28:28:5D"] HTTP_FINGERPRINT = [ FingerprintRule("zyxel", weight=7.0, mandatory=True), - FingerprintRule("gs1920", weight=6.0), - FingerprintRule("gs2210", weight=6.0), ] _LOGIN_PATH = "UserLogin" diff --git a/tests/test_zyxel.py b/tests/test_zyxel.py index ed80de2..82bbf75 100644 --- a/tests/test_zyxel.py +++ b/tests/test_zyxel.py @@ -421,3 +421,15 @@ class TestZyxelVMGDriver: def test_cli(self): self._setup_mocked_http() assert self.driver.cli(["show version"]) == {} + + +@pytest.mark.parametrize("switch_model", ["gs1920", "gs2210"]) +def test_a_zyxel_switch_page_adds_no_evidence_for_this_gateway(switch_model): + """GS1920 and GS2210 are Zyxel switches, not VMG gateways.""" + page = f"zyxel {switch_model}-24hp web configurator" + matching = [ + rule.pattern + for rule in ZyxelVMGDriver.HTTP_FINGERPRINT + if not rule.negative and rule.pattern != "zyxel" and rule.pattern in page + ] + assert matching == [] -- 2.54.0 From f7002114ae11c22e88776a9af6871cacd662a65c Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Sun, 1 Nov 2026 21:55:36 +0100 Subject: [PATCH 2/3] fix(http): pass the timeout with every request requests ignores a timeout attribute on a Session, so open() setting one left every call without a timeout and an unresponsive gateway could hang a worker indefinitely. Each get/post/put now carries the driver's timeout. Closes #3 --- CHANGELOG.md | 3 +++ napalm_zyxel/zyxel_driver.py | 9 +++++--- tests/test_zyxel.py | 44 ++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d5e3d2..f79272a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,9 @@ All notable changes to this driver. The format follows - The HTTP fingerprint no longer counts `gs1920` and `gs2210` as evidence for this driver: they are Zyxel switches, and discovery offered this gateway driver for them (#4). +- Every HTTP request to the gateway carries the driver's `timeout`. It was set on + the session, where requests ignores it, so an unresponsive gateway could hang a + call indefinitely (#3). ## [0.3.0] - 2026-10-23 diff --git a/napalm_zyxel/zyxel_driver.py b/napalm_zyxel/zyxel_driver.py index f2afa6d..3b23bc7 100644 --- a/napalm_zyxel/zyxel_driver.py +++ b/napalm_zyxel/zyxel_driver.py @@ -135,7 +135,6 @@ class ZyxelVMGDriver(ResidentialGatewayDriver): """Open a connection and authenticate with the Zyxel device.""" self._session = requests.Session() self._session.verify = self.verify - self._session.timeout = self.timeout self._session.trust_env = False info = self._get_basic_info() @@ -164,6 +163,7 @@ class ZyxelVMGDriver(ResidentialGatewayDriver): resp = self._session.post( self._url(self._LOGIN_PATH), json=enc_payload, + timeout=self.timeout, ) resp.raise_for_status() result = crypto.decrypt_response(resp.json()) @@ -185,6 +185,7 @@ class ZyxelVMGDriver(ResidentialGatewayDriver): self._session.get( self._url(self._LOGOUT_PATH), params={"sessionKey": self._sessionkey}, + timeout=self.timeout, ) except requests.RequestException: pass @@ -206,7 +207,7 @@ class ZyxelVMGDriver(ResidentialGatewayDriver): if self._session is None: return None try: - resp = self._session.get(self._url(self._BASIC_INFO_PATH)) + resp = self._session.get(self._url(self._BASIC_INFO_PATH), timeout=self.timeout) resp.raise_for_status() return resp.json() except (requests.RequestException, json.JSONDecodeError, TypeError): @@ -216,7 +217,7 @@ class ZyxelVMGDriver(ResidentialGatewayDriver): if self._session is None: return None try: - resp = self._session.get(self._url(self._RSA_KEY_PATH)) + resp = self._session.get(self._url(self._RSA_KEY_PATH), timeout=self.timeout) resp.raise_for_status() return resp.json().get("RSAPublicKey") except (requests.RequestException, json.JSONDecodeError, TypeError): @@ -233,6 +234,7 @@ class ZyxelVMGDriver(ResidentialGatewayDriver): self._url(self._DAL_PATH), params={"oid": oid, "sessionkey": self._sessionkey}, json=enc, + timeout=self.timeout, ) resp.raise_for_status() return self._crypto.decrypt_response(resp.json()) @@ -246,6 +248,7 @@ class ZyxelVMGDriver(ResidentialGatewayDriver): resp = self._session.get( self._url(path), params={"sessionKey": self._sessionkey}, + timeout=self.timeout, ) resp.raise_for_status() return resp.text diff --git a/tests/test_zyxel.py b/tests/test_zyxel.py index 82bbf75..1ce5ee9 100644 --- a/tests/test_zyxel.py +++ b/tests/test_zyxel.py @@ -433,3 +433,47 @@ def test_a_zyxel_switch_page_adds_no_evidence_for_this_gateway(switch_model): if not rule.negative and rule.pattern != "zyxel" and rule.pattern in page ] assert matching == [] + + +class TestEveryRequestHasATimeout: + """requests ignores a ``timeout`` attribute on a Session; it must go with each call.""" + + def _driver_with_session(self): + driver = ZyxelVMGDriver("192.168.1.1", "admin", "password", timeout=7) + session = MagicMock(spec=requests.Session) + session.get.return_value = MockResponse(MOCK_BASIC_INFO) + session.post.return_value = MockResponse(MOCK_LOGIN_RESPONSE) + session.put.return_value = MockResponse({}) + return driver, session + + @staticmethod + def _timeouts(session): + calls = session.get.call_args_list + session.post.call_args_list + calls += session.put.call_args_list + assert calls + return {call.kwargs.get("timeout") for call in calls} + + def test_open_login_and_logout(self): + driver, session = self._driver_with_session() + crypto = MagicMock() + crypto.encrypt_json.return_value = {"content": "ENC", "iv": "IV", "key": ""} + crypto.decrypt_response.return_value = {"result": "ZCFG_SUCCESS", "sessionkey": "1"} + session.get.side_effect = lambda url, **kw: MockResponse( + {"RSAPublicKey": MOCK_RSA_KEY} if "getRSAPublickKey" in url else MOCK_BASIC_INFO + ) + with ( + patch("napalm_zyxel.zyxel_driver.ZyxelCrypto", return_value=crypto), + patch("napalm_zyxel.zyxel_driver.requests.Session", return_value=session), + ): + driver.open() + driver.close() + assert self._timeouts(session) == {7} + + def test_dal_query_and_page_fetch(self): + driver, session = self._driver_with_session() + driver._session = session + driver._sessionkey = "1" + driver._crypto = MagicMock() + driver._dal_query("LAN_HOSTS") + driver._fetch_page("Status.htm") + assert self._timeouts(session) == {7} -- 2.54.0 From fcee6d7ddd644bdd8c44419e7766f5f9f1bf5a90 Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Sun, 1 Nov 2026 21:56:45 +0100 Subject: [PATCH 3/3] fix(ping): stop reporting every target alive ping() returned three replies of 0 ms whenever the DAL accepted a PINGTEST request, without reading any result, so a LAN scan through this gateway marked every address alive. The DAL answer is only an acknowledgement with no reply count, so ping() now returns NAPALM's error reply without contacting the gateway and the driver opts out of ping sweeps with SUPPORTS_PING = False. Closes #2 --- CHANGELOG.md | 4 ++++ README.md | 4 +++- napalm_zyxel/zyxel_driver.py | 33 +++++++++++---------------------- tests/test_zyxel.py | 28 ++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f79272a..574cb1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,10 @@ All notable changes to this driver. The format follows - Every HTTP request to the gateway carries the driver's `timeout`. It was set on the session, where requests ignores it, so an unresponsive gateway could hang a call indefinitely (#3). +- `ping()` no longer reports every target as alive. The DAL only acknowledges a + `PINGTEST` request and never says whether the target answered, so `ping()` now + returns an error and the driver opts out of ping sweeps (`SUPPORTS_PING = False`): + a LAN scan through this gateway marked every address alive (#2). ## [0.3.0] - 2026-10-23 diff --git a/README.md b/README.md index 918e4e8..8551658 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,6 @@ with driver("192.0.2.1", "admin", "secret", optional_args={"use_tls": True}) as | `get_port_forwards`, `get_nat_translations` | DAL `NAT_PORTMAP`, else the status page | | `get_wireless_clients`, `get_ssids`, `get_radio_status` | DAL, else the wireless page | | `get_diagnostics` | DAL `DIAGNOSTICS` | -| `ping` | DAL `PINGTEST` | | `is_alive` | TCP connect to the web port | | `reboot_host` | DAL `REBOOT` | | `restart_wifi` | DAL `WIFI_RESTART` | @@ -54,6 +53,9 @@ Configuration changes (`load_merge_candidate` and `load_replace_candidate` raise `NotImplementedError`), `get_config`, LLDP, BGP, NTP, SNMP, users, routes, MAC address table, optics, environment, traceroute, VPN tunnels and the CLI. +`ping` returns an error and `SUPPORTS_PING` is `False`: the DAL accepts a `PINGTEST` +request but does not report whether the target answered. + ## Development The rules are in [STANDARDS.md](https://git.netork.io/NAPALM/driver-standard/src/branch/main/STANDARDS.md). diff --git a/napalm_zyxel/zyxel_driver.py b/napalm_zyxel/zyxel_driver.py index 3b23bc7..80fb9b6 100644 --- a/napalm_zyxel/zyxel_driver.py +++ b/napalm_zyxel/zyxel_driver.py @@ -33,6 +33,8 @@ from napalm_device_types.models import ( WirelessClientDict, ) +_PING_UNSUPPORTED = "Not supported on Zyxel VMG: the DAL does not report ping replies" + class ZyxelCrypto: """AES-256-CBC encryption wrapper for Zyxel DAL protocol payloads.""" @@ -96,6 +98,9 @@ class ZyxelVMGDriver(ResidentialGatewayDriver): HTTP_FINGERPRINT = [ FingerprintRule("zyxel", weight=7.0, mandatory=True), ] + #: The DAL accepts a PINGTEST request but its answer carries no reply count or + #: round-trip time, so this driver cannot tell an answering host from a silent one. + SUPPORTS_PING = False _LOGIN_PATH = "UserLogin" _LOGOUT_PATH = "cgi-bin/UserLogout" @@ -390,28 +395,12 @@ class ZyxelVMGDriver(ResidentialGatewayDriver): vrf: str = "", source_interface: str = "", ) -> dict[str, Any]: - """Ping a destination via the device's DAL diagnostics.""" - result = self._dal_query( - "PINGTEST", - { - "ProtocolVersion": "IPv4", - "Host": destination, - "DiagnosticsState": "Requested", - "DNSServer": "", - "NumberOfRepetitions": count, - "type": 0, - }, - ) - if result is None: - return {"success": {}, "error": "Ping not supported via DAL"} - return { - "success": { - "results": [{"rtt": 0}], - "probes_sent": count, - "probes_received": count, - }, - "error": "", - } + """Not supported: the DAL does not report whether a target answered. + + Returns NAPALM's ``error`` reply without contacting the gateway; see + :attr:`SUPPORTS_PING`. + """ + return {"error": _PING_UNSUPPORTED} def traceroute( self, diff --git a/tests/test_zyxel.py b/tests/test_zyxel.py index 1ce5ee9..ce43f8d 100644 --- a/tests/test_zyxel.py +++ b/tests/test_zyxel.py @@ -477,3 +477,31 @@ class TestEveryRequestHasATimeout: driver._dal_query("LAN_HOSTS") driver._fetch_page("Status.htm") assert self._timeouts(session) == {7} + + +class TestPingReportsNoTargetAlive: + """The DAL PINGTEST call only acknowledges the request; it carries no reply count.""" + + def _connected_driver(self): + driver = ZyxelVMGDriver("192.168.1.1", "admin", "password") + driver._session = MagicMock(spec=requests.Session) + driver._session.put.return_value = MockResponse({}) + driver._sessionkey = "1" + driver._crypto = MagicMock() + driver._crypto.decrypt_response.return_value = {"result": "ZCFG_SUCCESS"} + return driver + + def test_the_driver_opts_out_of_ping_sweeps(self): + assert ZyxelVMGDriver.supports_ping() is False + + def test_an_accepted_request_is_not_a_reply(self): + driver = self._connected_driver() + reply = driver.ping("192.0.2.77") + assert "success" not in reply + assert reply["error"] + assert driver._parse_ping_reply("192.0.2.77", reply)["alive"] is False + + def test_ping_starts_no_diagnostic_on_the_gateway(self): + driver = self._connected_driver() + driver.ping("192.0.2.77") + driver._session.put.assert_not_called() -- 2.54.0