Setting the transit namespace at runtime

Jason A. Donenfeld Jason at zx2c4.com
Fri Sep 7 03:26:33 CEST 2018


Hi Julian,

I'd thought of this early on, but failed to come up with what seemed
like an actually realistic use case for it.

On Thu, Sep 6, 2018 at 10:15 AM Julian Orth <ju.orth at gmail.com> wrote:
> * If multiple processes are creating Wireguard devices at the same time, then
>   their device namespaces are isolated as long as each process uses its own
>   network namespace. This means that there is no problem if two processes try
>   to create the `wg0` device at the same time.

The typical solution for this is to create "wg%d":

zx2c4 at thinkpad ~ $ ip link add wg%d type wireguard
zx2c4 at thinkpad ~ $ ip link add wg%d type wireguard
zx2c4 at thinkpad ~ $ ip link add wg%d type wireguard
zx2c4 at thinkpad ~ $ ip link add wg%d type wireguard
zx2c4 at thinkpad ~ $ ip link add wg%d type wireguard
zx2c4 at thinkpad ~ $ ip link show | grep wg
47: wg0: <POINTOPOINT,NOARP> mtu 1420 qdisc noop state DOWN mode
DEFAULT group default qlen 1000
48: wg1: <POINTOPOINT,NOARP> mtu 1420 qdisc noop state DOWN mode
DEFAULT group default qlen 1000
49: wg2: <POINTOPOINT,NOARP> mtu 1420 qdisc noop state DOWN mode
DEFAULT group default qlen 1000
50: wg3: <POINTOPOINT,NOARP> mtu 1420 qdisc noop state DOWN mode
DEFAULT group default qlen 1000
51: wg4: <POINTOPOINT,NOARP> mtu 1420 qdisc noop state DOWN mode
DEFAULT group default qlen 1000

Or you just use a try-loop, incrementing until there are no races with
another process who has already claimed it.

Alternatively if you just generate a random byte sequence that's also
a valid interface name, you get around 119.5 bits of randomness, which
makes the possibility of collision for this use case sufficiently
unlikely. (A random UUID only has 122 bits of randomness, for
comparison.)

> * The intention is for the `wg0` device to be used only within the `vpn`
>   namespace. It does not feel clean that the device has to live in the init
>   namespace for an arbitrarily short but non-zero amount of time. This also
>   leaks the existence of the `wg0` device to all processes living in the init
>   namespace.

I wonder what happens with that "leak" that you're concerned with. It
doesn't have to be configured with any information like ip addresses
or routes, and the original name can be entirely different from the
final name used.

Jason


More information about the WireGuard mailing list