WireGuard / wgctrl-go

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

internal/wglinux: multicast group listener #120

Open elwhite321 opened 2 years ago

elwhite321 commented 2 years ago

I have a use case where the user program using wgctrl-go needs control over the WireGuard kernel devices. If the wg, ip or similar CLIs are used to change a device, the user program will be out of sync.

What are the thoughts around implementing a multicast group client to update the devices as they change? Does this feature / enhancement justify the discontinuity between the user land device(s)?

I'd be happy to look into this if it makes sense.

mdlayher commented 2 years ago

As of today, wireguard genetlink does not expose any multicast groups:

$ uname -a
Linux matt-3 5.13.0-37-generic #42-Ubuntu SMP Tue Mar 15 14:34:06 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
$ genl ctrl get name wireguard

Name: wireguard
        ID: 0x22  Version: 0x1  header size: 0  max attribs: 8 
        commands supported: 
                #1:  ID-0x0 
                #2:  ID-0x1 

And listening for device changes made by iproute2 would be an rtnetlink operation, which is out of scope for this library.

I don't think there is anything that can be done here today. But maybe notifying on device configuration changes is something that @zx2c4 could consider for the WireGuard kernel module.

elwhite321 commented 2 years ago

Thank you for correcting the title.

I have seen this patch but am unsure of the status. Maybe something for the future.

I was going to open another issue for adding and removing devices. This would also require rtnetlink, and thus I assume out of the scope too?

mdlayher commented 2 years ago

Thanks for the patch link.

That's correct: adding and removing devices is out of scope for this library since it ultimately relies on an entirely separate set of APIs.

stv0g commented 1 year ago

I've implemented a package which watches interfaces using wgctrl and allows you to register callbacks for various events:

https://github.com/stv0g/wice/tree/master/pkg/watcher