WireGuard / wgctrl-go

Package wgctrl enables control of WireGuard interfaces on multiple platforms.
https://godoc.org/golang.zx2c4.com/wireguard/wgctrl
MIT License
730 stars 85 forks source link

Add support for creating an interface #32

Closed martin31821 closed 5 years ago

martin31821 commented 5 years ago

It would be really cool to have support to create and initialize a new wireguard interface. In theory, it should only be neccessary to have a client.CreateWG(name string) error method, which creates a blank interface (basically the equivalent of running ip link add dev wg0 type wireguard)

mdlayher commented 5 years ago

I totally understand why you would want this, but unfortunately it's outside the scope of this library. See the README:

This package implements WireGuard configuration protocol operations, enabling the configuration of existing WireGuard devices. Operations such as creating WireGuard devices, or applying IP addresses to those devices, are out of scope for this package.

You should be able to accomplish this using a route netlink package, such as https://github.com/jsimonetti/rtnetlink. It appears that the proper API for doing so is already in place.

If this type of thing interests you, feel free to join us on #networking on Gophers Slack. There are lots of folks doing networking and netlink things there.

Closing as out of scope for this package.

g00nix commented 5 years ago

I feel like importing rtnetlink is a bit too much for creating one interface, so for cases like this I think it's a lot easier to create the interface before starting the go script that controls it, and if there are multiple interfaces just to run multiple scripts. This is easy to set up with docker. Though I understand the need to control interface creation from go.

Either way, there will be a lot of people asking themselves the same question, and some of them might not end up at this ticket, so a reference to rtnetlink could be useful in the readme.