From fcee6d7ddd644bdd8c44419e7766f5f9f1bf5a90 Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Sun, 1 Nov 2026 21:56:45 +0100 Subject: [PATCH] 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()