Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T6267: Check interface wireless module before apply config #3368

Merged
merged 1 commit into from Apr 30, 2024

Conversation

sever-sever
Copy link
Member

Change Summary

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'

(I do not have an actual wireless device to check if it will work when the device really exists, will be perfect to re-check it)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes)
  • Migration from an old Vyatta component to vyos-1x, please link to related PR inside obsoleted component
  • Other (please describe):

Related Task(s)

Related PR(s)

Component(s) name

wireless

Proposed changes

How to test

In the instance without a wireless device try to configure a wireless interface:

set interfaces wireless wlan0 address 192.0.2.5/32
commit

Before the fix:

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'

After the fix:

vyos@r4# commit
[ interfaces wireless wlan0 ]
Wireless module is not found!

[[interfaces wireless wlan0]] failed
Commit failed
[edit]
vyos@r4# 

Smoketest result

Checklist:

  • I have read the CONTRIBUTING document
  • I have linked this PR to one or more Phabricator Task(s)
  • I have run the components SMOKETESTS if applicable
  • My commit headlines contain a valid Task id
  • My change requires a change to the documentation
  • I have updated the documentation accordingly

@vyosbot vyosbot requested review from a team, dmbaturin, sarthurdev, zdc, jestabro and c-po and removed request for a team April 26, 2024 15:02
Copy link
Member

@c-po c-po left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A proper fix should be:

from vyos.utils.kernel import check_kmod
...
if __name__ == '__main__':
    try:
        check_kmod('mac80211')
        c = get_config()
        verify(c)

Which will create /sys/class/ieee80211. Calling the module loader is what we already do for other drivers like l2tpv3

@sever-sever
Copy link
Member Author

sever-sever commented Apr 29, 2024

A proper fix should be:

from vyos.utils.kernel import check_kmod
...
if __name__ == '__main__':
    try:
        check_kmod('mac80211')
        c = get_config()
        verify(c)

Which will create /sys/class/ieee80211. Calling the module loader is what we already do for other drivers like l2tpv3

@c-po, it doesn't work

vyos@r4# set interfaces wireless wlan0 address 192.0.2.5/32
[edit]
vyos@r4# commit
[ interfaces wireless wlan0 ]
VyOS had an issue completing a command.

Traceback (most recent call last):
  File "/usr/libexec/vyos/conf_mode/interfaces_wireless.py", line 273, in <module>
    generate(c)
  File "/usr/libexec/vyos/conf_mode/interfaces_wireless.py", line 211, in generate
    with open('/sys/class/ieee80211/{physical_device}/addresses'.format(**wifi), 'r') as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/sys/class/ieee80211/phy0/addresses'


The modules are loaded, but I don't have any real wireless device:

vyos@r4# sudo lsmod | grep 80211
mac80211             1368064  0
cfg80211             1314816  1 mac80211
rfkill                 40960  2 cfg80211
libarc4                12288  1 mac80211
[edit]
vyos@r4# 

@c-po
Copy link
Member

c-po commented Apr 29, 2024

cpo@vyos# commit
[ interfaces wireless wlan0 ]
Wirelss interface PHY "phy0" does not exist!

[[interfaces wireless wlan0]] failed
Commit failed
diff --git i/src/conf_mode/interfaces_wireless.py w/src/conf_mode/interfaces_wireless.py
index 02b4a2500..c0a17c0bc 100755
--- i/src/conf_mode/interfaces_wireless.py
+++ w/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
@@ -31,8 +31,9 @@
 from vyos.configverify import verify_bond_bridge_member
 from vyos.ifconfig import WiFiIf
 from vyos.template import render
-from vyos.utils.process import call
 from vyos.utils.dict import dict_search
+from vyos.utils.kernel import check_kmod
+from vyos.utils.process import call
 from vyos import ConfigError
 from vyos import airbag
 airbag.enable()
@@ -118,6 +119,10 @@ def verify(wifi):
     if 'physical_device' not in wifi:
         raise ConfigError('You must specify a physical-device "phy"')

+    physical_device = wifi['physical_device']
+    if not os.path.exists(f'/sys/class/ieee80211/{physical_device}'):
+        raise ConfigError(f'Wirelss interface PHY "{physical_device}" does not exist!')
+
     if 'type' not in wifi:
         raise ConfigError('You must specify a WiFi mode')

@@ -266,6 +271,7 @@ def apply(wifi):

 if __name__ == '__main__':
     try:
+        check_kmod('mac80211')
         c = get_config()
         verify(c)
         generate(c)

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'
```
@c-po
Copy link
Member

c-po commented Apr 30, 2024

@Mergifyio backport sagitta

Copy link

mergify bot commented Apr 30, 2024

backport sagitta

✅ Backports have been created

@c-po c-po merged commit b111c6c into vyos:current Apr 30, 2024
7 of 8 checks passed
c-po added a commit that referenced this pull request Apr 30, 2024
T6267: Check interface wireless module before apply config (backport #3368)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 participants