svinota / pyroute2

Python Netlink and PF_ROUTE library — network configuration and monitoring
https://pyroute2.org/
Other
951 stars 244 forks source link

NDB: using `auto_netns` vs `sources.add()` #694

Open mawiegand opened 4 years ago

mawiegand commented 4 years ago

The auto_netns option for NDB is nice, but why does it handle the attributes target and netns other than it is done when adding an netns manually by using ndb.sources.add(netns='mynetns')?

If I have a netns ns1 using auto_netns results in

<NetNS {'target': 'netns/ns1', 'netns': '/var/run/netns/ns1'}>

But using ndb.sources.add(netns='ns1') results in

<NetNS {'netns': 'ns1', 'target': 'ns1'}>

Is there a reason for this behaviour? Thanks!

svinota commented 4 years ago

The auto_netns option is a bit problematic, and has more pitfalls than one may believe.

I will look into that netns difference and will try to equalize it, but notice also one thing. If there are no netns at the moment of the NDB start, auto_netns may not detect appearing network namespaces as the first netns remounts the directory which is monitored.

I'll try to fix that bug, but as for now it exists.

UPD: s/will not detect/may not detect/

svinota commented 4 years ago

Another question is what to do if we start NDB with auto_netns=True and then manually run ndb.sources.add(netns=…). Right now it adds two sources — the manual one and the auto.

Probably it would be better to reject manual netns source addition when auto_netns is True.

So, any ideas about auto_netns are welcome. Or maybe completely remove it.

svinota commented 4 years ago

The netns attr issue is addressed in this commit: https://github.com/svinota/pyroute2/commit/7af5e766aa3ce4c64f420c55696920e7f688e8a3

Should be better now