From c9dc6b40e89b39641026a54d42c9c47510b534b7 Mon Sep 17 00:00:00 2001 From: Viacheslav Hletenko Date: Fri, 26 Apr 2024 14:50:22 +0000 Subject: [PATCH] T6267: Check interface wireless module before apply config Check if the wireless device/modem exists in the system and the module `ieee802111` was loaded In cases where we do not have wireless devices, it prevents the unexpected traceback ``` set interfaces wireless wlan0 address 192.0.2.5/32 commit Traceback (most recent call last): File "/usr/libexec/vyos/conf_mode/interfaces_wireless.py", line 269, in c = get_config() ^^^^^^^^^^^^ File "/usr/libexec/vyos/conf_mode/interfaces_wireless.py", line 104, in get_cg tmp = find_other_stations(conf, base, wifi['ifname']) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/libexec/vyos/conf_mode/interfaces_wireless.py", line 54, in find_os for phy in os.listdir('/sys/class/ieee80211'): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FileNotFoundError: [Errno 2] No such file or directory: '/sys/class/ieee80211' ``` --- src/conf_mode/interfaces_wireless.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/conf_mode/interfaces_wireless.py b/src/conf_mode/interfaces_wireless.py index 02b4a2500b7..a931872b5d2 100755 --- a/src/conf_mode/interfaces_wireless.py +++ b/src/conf_mode/interfaces_wireless.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (C) 2019-2020 VyOS maintainers and contributors +# Copyright (C) 2019-2024 VyOS maintainers and contributors # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 or later as @@ -48,9 +48,17 @@ def find_other_stations(conf, base, ifname): Only one wireless interface per phy can be in station mode - find all interfaces attached to a phy which run in station mode """ + dict = {} + # Is class ieee80211 exists + if ( + not os.path.isdir('/sys/class/ieee80211') + or len(os.listdir('/sys/class/ieee80211')) == 0 + ): + return dict + old_level = conf.get_level() conf.set_level(base) - dict = {} + for phy in os.listdir('/sys/class/ieee80211'): list = [] for interface in conf.list_nodes([]): @@ -173,6 +181,13 @@ def verify(wifi): if len(wifi['station_interfaces'][phy]) > 0: raise ConfigError('Only one station per wireless physical interface possible!') + # Wireless interface does not exist or module not loaded + if ( + not os.path.isdir('/sys/class/ieee80211') + or len(os.listdir('/sys/class/ieee80211')) == 0 + ): + raise ConfigError('Wireless module is not found!') + verify_address(wifi) verify_vrf(wifi) verify_bond_bridge_member(wifi)