From: Barry Scott <barry@barrys-emacs.org>
To: Simon Lindhorst <s.lindhorst@wut.de>
Cc: wireguard@lists.zx2c4.com
Subject: Re: Question for wireguard events
Date: Tue, 17 Mar 2020 18:54:26 +0000 [thread overview]
Message-ID: <5F86D785-5A81-4836-8B71-8C3F2F06C630@barrys-emacs.org> (raw)
In-Reply-To: <5b5318f7-415b-e07b-5afd-a1e9b3292432@wut.de>
> 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
>
prev parent reply other threads:[~2020-03-30 2:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-16 12:43 Simon Lindhorst
2020-03-17 18:54 ` Barry Scott [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5F86D785-5A81-4836-8B71-8C3F2F06C630@barrys-emacs.org \
--to=barry@barrys-emacs.org \
--cc=s.lindhorst@wut.de \
--cc=wireguard@lists.zx2c4.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).