I want to write a udev rule (ACTION=add) that will create a new network namespace, move the newly added device to it and exec some commands inside it.
I was using irpoute2 to do so (Inside the rule):
ip netns add device-interface-name
ip netns exec device-interface-name "echo hello world!"
We can find pretty easily in the iproute2 source code, most of the nets code is using the mount syscall. Cf: https://github.com/iproute2/iproute2/blob/main/ip/ipnetns.c.
However, as stated in the udev manpage we cannot use mount inside udev rules.
Note that running programs that access the network or
mount/unmount filesystems is not allowed inside of udev
rules, due to the default sandbox that is enforced on
systemd-udevd.service.
The note seems pretty clear but I really wanted to be able to do so. Or at least have a better understanding of why not.
ip netns add device-interface-name? Do you have some misunderstanding in howip netnsworks (or even how netns works in general)? Have you ever read the man page of it?