Skip to content

Commit

Permalink
Add tun to static device list in hardware manager (#5547)
Browse files Browse the repository at this point in the history
Some devices are provided by kernel modules which potentially get loaded
later at startup. Those are not listed by udev, and hence add-ons do
not get permissions for these types of devices as long as the kernel
module is not loaded.

Typically, such devices are created by the kmod-static-nodes.service
systemd service. Ideally, we would read the output of that service and
add those specifically. However, there are very few devices which
use static nodes, and we actually only really interested in tun. So
let's simply add this static node in case udev does not list it already.
  • Loading branch information
agners authored Jan 15, 2025
1 parent 6183b97 commit d4c047b
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions supervisor/hardware/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,33 @@

_LOGGER: logging.Logger = logging.getLogger(__name__)

# Some device nodes get created system on startup by kmod-static-nodes.service,
# which in turn uses /usr/bin/kmod to get a list of static device nodes which
# are provided by kernel modules. These type of devices are not listed by udev
# and hence not listed through pyudev. However, on first access the kernel
# module is loaded automatically.
# Which nodes are exposed by module is system specific, so ideally Supervisor
# should read the output of kmod (e.g. /run/tmpfiles.d/static-nodes.conf). But
# this seems a bit overkill, since we are currently only interested in tun.
_STATIC_NODES: list[Device] = [
Device(
"tun",
Path("/dev/net/tun"),
Path("/sys/devices/virtual/misc/tun"),
"misc",
None,
[],
{
"DEVNAME": "/dev/net/tun",
"DEVPATH": "/devices/virtual/misc/tun",
"MAJOR": "10",
"MINOR": "200",
"SUBSYSTEM": "misc",
},
[],
)
]


class HardwareManager(CoreSysAttributes):
"""Hardware manager for supervisor."""
Expand Down Expand Up @@ -114,6 +141,11 @@ def _import_devices(self) -> None:
continue
self._devices[device.sys_name] = Device.import_udev(device)

# Add static nodes if not found through udev (e.g. module not yet loaded)
for device in _STATIC_NODES:
if device.name not in self._devices:
self._devices[device.name] = device

async def load(self) -> None:
"""Load hardware backend."""
self._import_devices()
Expand Down

0 comments on commit d4c047b

Please sign in to comment.