Skip to content

networkd: introduce network namespace - #11710

Closed
ssahani wants to merge 1 commit into
systemd:masterfrom
ssahani:netns
Closed

ssahani wants to merge 1 commit into
systemd:masterfrom
ssahani:netns

Conversation

@ssahani

@ssahani ssahani commented Feb 13, 2019 •

Copy link
Copy Markdown
Contributor

This allows to specify the name for network namespace in which networkd will create net device.
If specified namespace doesn't exist then networkd will create it before creating the device

closes #11103

Comment thread src/network/networkd.c Resolved
@yuwata yuwata added the network label Feb 13, 2019

@yuwata yuwata left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not tested yet. Only nitpicky comments.

Comment thread man/systemd.netdev.xml Resolved
Comment thread src/network/netdev/netns.c Resolved
Comment thread src/network/netdev/netns.c Resolved
Comment thread src/network/netdev/netns.c Resolved
Comment thread src/network/netdev/netns.c Resolved
Comment thread src/network/netdev/netns.h Resolved
Comment thread src/network/netdev/netns.c Resolved
Comment thread src/network/netdev/netns.c Resolved
Comment thread src/network/netdev/netns.c Resolved
Comment thread src/network/netdev/netns.c Resolved
@yuwata

yuwata commented Feb 14, 2019

Copy link
Copy Markdown
Member

BTW, what happens when NetNamespace= (or NetworkNamespace=) is set to veth netdev? It seems that veth-peer is not moved to the namespace. Is it ok? Or is my guess wrong?

@yuwata

yuwata commented Feb 14, 2019

Copy link
Copy Markdown
Member

Ah, please also add NetNamespace= (or NetworkNamespace=) to test/fuzz/fuzz-netdev-parser/directives.netdev.

And of course, adding testcases are welcome. If not, I will try to add that later as usual :-)

@yuwata yuwata added the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label Feb 14, 2019
@ssahani
ssahani force-pushed the netns branch 2 times, most recently from 2880739 to ab7d61d Compare February 14, 2019 04:30
@ssahani

ssahani commented Feb 14, 2019 •

Copy link
Copy Markdown
Contributor Author

BTW, what happens when NetNamespace= (or NetworkNamespace=) is set to veth netdev? It seems that veth-peer is not moved to the namespace. Is it ok? Or is my guess wrong?

Usually we move one end not the both end . To communicate from outside. One end in namespace other end in parent system

@poettering

Copy link
Copy Markdown
Member

huh, how is this supposed to be used? I mean, .netdev files are one thing, but if you can't apply .network on them, how are they supposed to be useful?

@ssahani

ssahani commented Feb 14, 2019

Copy link
Copy Markdown
Contributor Author

huh, how is this supposed to be used? I mean, .netdev files are one thing, but if you can't apply .network on them, how are they supposed to be useful?

We can implement similar to ip netns exec do setns and add address bring up interfaces etc.

@poettering

Copy link
Copy Markdown
Member

well, but how would you tell networkd to manage interfaces (as in: apply .network files) in some specific netns?

@poettering

Copy link
Copy Markdown
Member

(i figure you'd have to add a new concept of .netns files or so, that define a netns each, and then only reference these from .netdev and .network files. and probably also .link files. And then networkd would have to subscribe to all network events in all these .netns namespaces too, in addition to the host one. that would be quite some new infrastructure though I#d guess?)

@ssahani

ssahani commented Feb 14, 2019

Copy link
Copy Markdown
Contributor Author

yes mostly we can do that probably simpler I would work on it . Looks interesting to me . thanks.

Comment thread src/network/netdev/netns.c Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may not be necessary, but still I prefer to enable destroy callback.

If you really do not like that, then please drop netdev_ref() below, otherwise the NetDev object will not be freed.

@ssahani

ssahani commented Feb 19, 2019

Copy link
Copy Markdown
Contributor Author

@poettering you were right. It's kind of impossible to manage links in the network namespace for networkd running in one instance . Any other ideas we can implement like in networkctl to set up or add address to links ?

@poettering

Copy link
Copy Markdown
Member

@ssahani one approach for teaching netns support to networkd might be something like this:

  1. allow multiple networkd instances to run. networkd.service would remain the service for the main network namespace, and [email protected] would be a new instantiable service: it would work the same way, but manage a network namespace of the specified instance name. i.e. [email protected] would manager a network namespace called "foo".
  2. When configured with such an instance/netns name networkd would create a new netns by that name, join it, manage it and mount it somewhere in /run/system/netns/… or so.
  3. .network/.netdev files would learn a new [Match] line type: "Namespace=". It would be a glob value and would specify which namespace to apply to. If not specified, the file would apply only to the host namespace, but if you specify something like Namespace=foo* it would be considered in all networkd instances that run for a netns instance starting with "foo" in the name.

I think such an approach would be relatively minimal. And it would make it very easy for people to create a new managed netns: "systemctl enable --now [email protected]" would suffice.

Would that make sense?

@ssahani

ssahani commented Mar 4, 2019

Copy link
Copy Markdown
Contributor Author

yes thanks !

@nafets227

nafets227 commented Apr 13, 2019 •

Copy link
Copy Markdown
Contributor

Sounds good.

Any progress on this?

@poettering
How would the interfaces that need to be created in another namespace (e.g. veth with link to another veth or macvlan with link to physical interface in another namespace) be handled?

@poettering

Copy link
Copy Markdown
Member

@nafets227 when creating such "inter-namespace" interfaces it should be possible to simply specifiy the source namespace to use by its name.

@OJFord

OJFord commented Sep 1, 2019

Copy link
Copy Markdown

Also mentioned in #11103 (which OP states this intends to close) is differing birth to 'running' namespace. This is particularly great with WireGuard, that's where I learnt about it, but I'm sure there's other use cases.

I'd suggest adding NetworkNamespaceAtBirth=, assuming the value of NetworkNamespace= if not specified.

@ZLima12

ZLima12 commented Dec 12, 2019

Copy link
Copy Markdown
Contributor

This seems good, is anyone working on this at the moment?

Comment thread man/systemd.netdev.xml
<para>Specifies the name for network namespace in which networkd will create net device.
If specified namespace doesn't exist then networkd will create it before creating the device.</para>
</listitem>
</varlistentry>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From reading this I'm not clear what a "Network namespace" is...

I mean.. from a kernel point of view, network namespaces don't have names at all. the iproute2 tools have a concept of named namespaces, but it's purely user-space IIUC.

This might also be a unit name in the "JoinNamespaceOf" sense...

I think this deserves to be a bit more explicit.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Network namespace" context: http://man7.org/linux/man-pages/man7/namespaces.7.html

I mean.. from a kernel point of view, network namespaces don't have names at all.

You piqued my curiosity... http://man7.org/linux/man-pages/man8/ip-netns.8.html

So the names come from /var/run/netns/, and ip netns identify can be given a PID to reverse-lookup a name.

(Re-reading your comment it seems you knew all that, but anyway, links for others curious!)

@hexchain

Copy link
Copy Markdown
Contributor

Also curious how this is gonna work with PrivateNetwork and NetworkNamespacePath. I assume that PrivateNetwork should not be touched at all, while NetworkNamespacePath (or a new option) may be used to support networkd-managed namespaces?

@ZLima12

ZLima12 commented Feb 17, 2020

Copy link
Copy Markdown
Contributor

So it seems like this will provide a mechanism for choosing the network namespace of a device at its creation, but what about moving an already created device? This would be very useful when using network namespaces for a VPN setup like the one described here.

This could be useful if either:

  • You want to move a physical device to a new namespace to restrict usage to them (e.g. force through a VPN).
  • You want to move a Wireguard device to a new namespace after creation. The reason for doing this is due to a special trait of Wireguard devices: they will always send the encrypted data in the network namespace where it was created. So you could create an interface in the namespace with either your WiFi card or Ethernet card, then move it to a new namespace (e.g. vpn). Anything running in the vpn namespace will only see the Wireguard interface, and the Wireguard interface will send encrypted packets through its initial network namespace.

@OJFord

OJFord commented Feb 18, 2020

Copy link
Copy Markdown

@ZLima12

So it seems like this will provide a mechanism for choosing the network namespace of a device at its creation

I believe as it stands this patch creates the netns and then moves the device into it, so the creation namespace would be that of the parent process; which is not that helpful for the wg workflow we've described.

@ssahani ssahani closed this Feb 27, 2020
@ssahani
ssahani deleted the netns branch February 27, 2020 12:44
@OJFord

OJFord commented Apr 20, 2020

Copy link
Copy Markdown

NB: Seems to have been superseded by #14915

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

network reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks

Development

Successfully merging this pull request may close these issues.

[RFE] systemd-networkd set netns for netdev

8 participants