zerotier / ZeroTierOne

A Smart Ethernet Switch for Earth
https://zerotier.com
Other
14.53k stars 1.7k forks source link

Persistent TAP on Linux #1038

Open aadnehovda opened 5 years ago

aadnehovda commented 5 years ago

Is your feature request related to a problem? Please describe.

I'm bridging the zt adapter to Linux bridge, but have to resort to "hacks" to get the bridge set up before the tap adapter is constructed during startup.

[Match]
Name=brzt0

[Network]
ConfigureWithoutCarrier=yes

Describe the solution you'd like With openvpn you can run openvpn --dev mytap0 --dev-type tap --mktun to create a persistent tap adapter and when you start openvpn it will pick it up and simply push packets to it.

I'd like a config option in <nwid>.local.conf to set that zerotier-one will use an existing tap. I looked through the code and it seems as if the check is pretty simple, it will fall back to create a new adapter if it finds one already with the name it expects (nwid-hash based or through devicemap).

Describe alternatives you've considered I guess I can tweak startup scripts to start ZT before networking is brought up, but I'm not sure about timing issues. Perhaps the tap adapter will not come up quick enough for the bridge to see it when being formed. I'm running unmanaged by the central with manual IP and setting up my own IP and IGP, so I want to configure all adapters and bridges and then just have ZT "plug in the cable".

laduke commented 5 years ago

Hello, this seems to just work with systemd networkd, unless I'm misunderstanding.

==> 25-bridge-enp.network <==
[Match]
Name=enp*

[Network]
Bridge=bridge0

==> 25-bridge-static.network <==
[Match]
Name=bridge0

[Network]
Address=10.211.55.21/24
Gateway=10.211.55.1
DNS=10.211.55.1

==> 25-bridge-zt.network <==
[Match]
Name=zt*

[Network]
Bridge=bridge0

==> bridge0.netdev <==
[NetDev]
Name=bridge0
Kind=bridge

I actually installed zerotier and joined a network after doing the config, and the system added the new zt interface to the bridge.

%brctl show

bridge name bridge id       STP enabled interfaces
bridge0     8000.06600aa497f0   no      enp0s5
                            zt3jnvorze
aadnehovda commented 5 years ago

That's right, I guess systemd-networkd is capable of making the bridge consistent eventually. I just tried it with ifupdown/ifupdown2 and the bridge port is not coming up. I've tried it with NetworkManager too in the past without success. If the TAP could exist it would solve both of these, plus the case where you want to assign an IP address, but ignore the managed routes.

aadnehovda commented 5 years ago

On Windows, the adapter is just disabled on service shutdown. Only if you leave the network it will be deleted. I have not tested other platforms.

Once you set allowManaged=0 you could argue that the service should not destroy the TAP (perhaps just create it) on either platform. But that would slightly change the meaning of that flag, at least on Linux.

aadnehovda commented 3 years ago

Related to #659