Skip to content

Commit

Permalink
T6267: Check interface wireless module before apply config
Browse files Browse the repository at this point in the history
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 <modu>
    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'
```
  • Loading branch information
sever-sever committed Apr 26, 2024
1 parent aa15f74 commit c9dc6b4
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/conf_mode/interfaces_wireless.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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([]):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c9dc6b4

Please sign in to comment.