Skip to content

Commit d4c047b

Browse files
authored
Add tun to static device list in hardware manager (#5547)
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.
1 parent 6183b97 commit d4c047b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

supervisor/hardware/manager.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,33 @@
1616

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

19+
# Some device nodes get created system on startup by kmod-static-nodes.service,
20+
# which in turn uses /usr/bin/kmod to get a list of static device nodes which
21+
# are provided by kernel modules. These type of devices are not listed by udev
22+
# and hence not listed through pyudev. However, on first access the kernel
23+
# module is loaded automatically.
24+
# Which nodes are exposed by module is system specific, so ideally Supervisor
25+
# should read the output of kmod (e.g. /run/tmpfiles.d/static-nodes.conf). But
26+
# this seems a bit overkill, since we are currently only interested in tun.
27+
_STATIC_NODES: list[Device] = [
28+
Device(
29+
"tun",
30+
Path("/dev/net/tun"),
31+
Path("/sys/devices/virtual/misc/tun"),
32+
"misc",
33+
None,
34+
[],
35+
{
36+
"DEVNAME": "/dev/net/tun",
37+
"DEVPATH": "/devices/virtual/misc/tun",
38+
"MAJOR": "10",
39+
"MINOR": "200",
40+
"SUBSYSTEM": "misc",
41+
},
42+
[],
43+
)
44+
]
45+
1946

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

144+
# Add static nodes if not found through udev (e.g. module not yet loaded)
145+
for device in _STATIC_NODES:
146+
if device.name not in self._devices:
147+
self._devices[device.name] = device
148+
117149
async def load(self) -> None:
118150
"""Load hardware backend."""
119151
self._import_devices()

0 commit comments

Comments
 (0)