Development discussion of WireGuard
 help / color / mirror / Atom feed
* Question for wireguard events
@ 2020-03-16 12:43 Simon Lindhorst
  2020-03-17 18:54 ` Barry Scott
  0 siblings, 1 reply; 2+ messages in thread
From: Simon Lindhorst @ 2020-03-16 12:43 UTC (permalink / raw)
  To: wireguard

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.


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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Question for wireguard events
  2020-03-16 12:43 Question for wireguard events Simon Lindhorst
@ 2020-03-17 18:54 ` Barry Scott
  0 siblings, 0 replies; 2+ messages in thread
From: Barry Scott @ 2020-03-17 18:54 UTC (permalink / raw)
  To: Simon Lindhorst; +Cc: wireguard



> On 16 Mar 2020, at 12:43, Simon Lindhorst <s.lindhorst@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
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-03-30  2:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-16 12:43 Question for wireguard events Simon Lindhorst
2020-03-17 18:54 ` Barry Scott

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).