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

internal/wgnl: consider using rtnetlink to filter and fetch only WireGuard devices #5

Closed mdlayher closed 5 years ago

mdlayher commented 5 years ago

Right now, we try to probe every network interface on the system to determine if it's a WireGuard device, but this is a bit inefficient.

We could consider using rtnetlink and using the ifinfomsg structure directly to determine which devices are WireGuard devices:

https://lists.zx2c4.com/pipermail/wireguard/2018-July/003148.html

The thing you're dumping from a single device is all the peers. If you
want a list of all interfaces, then the place to NLM_F_DUMP is
RTM_GETLINK, where you can then inspect
ifinfomsg->IFLA_LINKINFO->IFLA_INFO_KIND and make sure that it's
"wireguard". WireGuard itself doesn't [necessarily need to] know all
of the instances of itself, since it's instantiated by the rtnl
subsystem. Check out kernel_get_wireguard_interfaces here:

https://git.zx2c4.com/WireGuard/tree/src/tools/ipc.c#n458
mdlayher commented 5 years ago

Fixed: https://github.com/mdlayher/wireguardctrl/commit/26021bc61280ba8cfd40c98119a6ac92271955c4.