netns icon indicating copy to clipboard operation
netns copied to clipboard

Is there a way to get notified when new netns is created

Open msherif1234 opened this issue 1 year ago • 3 comments

my application when it starts it detect all available netns by looking at /var/run/netns but while its running if new netns is created my application won't know anything about it and as a result it won't know about links and their attributes

what is the best way to know runtime when netns is created so we can use LinkSubscribeAt() for it ?

msherif1234 avatar Sep 01 '23 03:09 msherif1234

I believe we can use inotify to watch for creation/deletion events in /var/run/netns

bn222 avatar Sep 01 '23 08:09 bn222

Yeah I added inotify and when netns is created I subscribe for notificatoin using netlink.LinkSubscribeAt but it failed here

msherif1234 avatar Sep 01 '23 12:09 msherif1234

cc'd @vishvananda I have an easy reproducer w/o using k8s or docker

  • clone https://github.com/netobserv/netobserv-ebpf-agent
  • make build
  • sudo FLOWS_TARGET_HOST=127.0.0.1 FLOWS_TARGET_PORT=9999 ./bin/netobserv-ebpf-agent
  • sudo ip netns add n1 that will result into
ERRO[0009] can't subscribe to links netns NS(16: 25, 58164)  component=ifaces.Watcher error="failed to set into network namespace 16 while creating netlink socket: invalid argument"

msherif1234 avatar Mar 06 '24 20:03 msherif1234