Question for wireguard events
Barry Scott
barry at barrys-emacs.org
Tue Mar 17 19:54:26 CET 2020
> On 16 Mar 2020, at 12:43, Simon Lindhorst <s.lindhorst at wut.de> wrote:
>
> Hi,
>
> is there a way to get events for wireguard?
>
> I want to show in an gui which clients are connected or not. For that I could poll the wireguard netlink socket. The better way in my opinion is to wait for events, so no polling is required.
I don't know if there are events that you can hook, others understand this better then I do.
What I did is:
wg show all dump
I extract the latest_handshake field out of the dump for each client.
I know the client_keepalive from my client database.
Then I do this calculation based on information from people on #wireguard IRC:
ago = now - latest_handshake
# handshake is every 2 minutes + keep alive + 2 (error margin)
down_after = (60*2) + client_keepalive + 2
if latest_handshake == 0 or ago > down_after:
state = 'Down'
else:
state = 'Up (%d%%)' % (100-(ago*100//down_after),)
I only have a handful of clients so this is fast for me. I show the results
in a web page that shows the status of my firewall.
If I was going to scale this to large size I'm use the netlink interface
so that I only fetched the perr info I needed.
Barry
>
>
> Best regards,
>
> Simon
>
> -- Unsere Aussagen koennen Irrtuemer und Missverstaendnisse enthalten.
> Bitte pruefen Sie die Aussagen fuer Ihren Fall, bevor Sie Entscheidungen auf Grundlage dieser Aussagen treffen.
> Wiesemann & Theis GmbH, Porschestr. 12, D-42279 Wuppertal
> Geschaeftsfuehrer: Dipl.-Ing. Ruediger Theis
> Registergericht: Amtsgericht Wuppertal, HRB 6377 Infos zum Datenschutz: http://www.wut.de/datenschutz
> Tel. +49-202/2680-0, Fax +49-202/2680-265, http://www.wut.de
>
More information about the WireGuard
mailing list