From owner-dev-commits-src-all@freebsd.org Tue Mar 9 19:50:57 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 60C7556E351; Tue, 9 Mar 2021 19:50:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Dw5Rj2KjWz4sbF; Tue, 9 Mar 2021 19:50:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 42F39217DA; Tue, 9 Mar 2021 19:50:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 129JovmO024365; Tue, 9 Mar 2021 19:50:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 129Jov76024364; Tue, 9 Mar 2021 19:50:57 GMT (envelope-from git) Date: Tue, 9 Mar 2021 19:50:57 GMT Message-Id: <202103091950.129Jov76024364@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 94dddbfd00b9 - main - if_wg: export tx_bytes, rx_bytes, and last_handshake MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 94dddbfd00b9d53d1b6a45a58bc87b323cae6791 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Mar 2021 19:50:57 -0000 The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=94dddbfd00b9d53d1b6a45a58bc87b323cae6791 commit 94dddbfd00b9d53d1b6a45a58bc87b323cae6791 Author: Kyle Evans AuthorDate: 2021-03-09 10:57:01 +0000 Commit: Kyle Evans CommitDate: 2021-03-09 19:50:41 +0000 if_wg: export tx_bytes, rx_bytes, and last_handshake The names are self-explanatory; these are currently only used by the wg(8) tool, but they are handy data points to have. Reviewed by: grehan MFC after: 3 days Discussed with: decke Differential Revision: https://reviews.freebsd.org/D29143 --- sys/dev/if_wg/module/module.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/sys/dev/if_wg/module/module.c b/sys/dev/if_wg/module/module.c index ad2f17c1e803..4ca1c24b56b9 100644 --- a/sys/dev/if_wg/module/module.c +++ b/sys/dev/if_wg/module/module.c @@ -69,11 +69,19 @@ MALLOC_DEFINE(M_WG, "WG", "wireguard"); TASKQGROUP_DECLARE(if_io_tqg); +struct wg_timespec64 { + uint64_t tv_sec; + uint64_t tv_nsec; +}; + struct wg_peer_export { struct sockaddr_storage endpoint; + struct timespec last_handshake; uint8_t public_key[WG_KEY_SIZE]; size_t endpoint_sz; struct wg_allowedip *aip; + uint64_t rx_bytes; + uint64_t tx_bytes; int aip_count; uint16_t persistent_keepalive; }; @@ -419,6 +427,9 @@ wg_peer_to_export(struct wg_peer *peer, struct wg_peer_export *exp) exp->persistent_keepalive = peer->p_timers.t_persistent_keepalive_interval; + wg_timers_get_last_handshake(&peer->p_timers, &exp->last_handshake); + exp->rx_bytes = counter_u64_fetch(peer->p_rx_bytes); + exp->tx_bytes = counter_u64_fetch(peer->p_tx_bytes); exp->aip_count = 0; CK_LIST_FOREACH(rt, &peer->p_routes, r_entry) { @@ -449,6 +460,7 @@ wg_peer_to_export(struct wg_peer *peer, struct wg_peer_export *exp) static nvlist_t * wg_peer_export_to_nvl(struct wg_peer_export *exp) { + struct wg_timespec64 ts64; nvlist_t *nvl; if ((nvl = nvlist_create(0)) == NULL) @@ -462,10 +474,19 @@ wg_peer_export_to_nvl(struct wg_peer_export *exp) nvlist_add_binary(nvl, "allowed-ips", exp->aip, exp->aip_count * sizeof(*exp->aip)); + ts64.tv_sec = exp->last_handshake.tv_sec; + ts64.tv_nsec = exp->last_handshake.tv_nsec; + nvlist_add_binary(nvl, "last_handshake", &ts64, sizeof(ts64)); + if (exp->persistent_keepalive != 0) nvlist_add_number(nvl, "persistent-keepalive-interval", exp->persistent_keepalive); + if (exp->rx_bytes != 0) + nvlist_add_number(nvl, "rx_bytes", exp->rx_bytes); + if (exp->tx_bytes != 0) + nvlist_add_number(nvl, "tx_bytes", exp->tx_bytes); + return (nvl); }