From nobody Wed Dec 14 05:49:47 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NX4FR5CXRz4kvlj; Wed, 14 Dec 2022 05:49:47 +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 4NX4FR4Y5Wz3PhH; Wed, 14 Dec 2022 05:49:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670996987; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=QNpKpayg5m+XAIaRuwFw0UHYb8Gn69XadS8BdP/lTFI=; b=xuAfC1zuw1mLsYk7v7mPITbvGEXaoqPaen7GdDf+sISZetniSfaMxQhyy9Iq61s53dF6ff AUg5tevZ+SkHo7ELkoutn536hlxY1cjAqvXvHjXpqz03IisF1cTxD0bbgrnV8MNQf5jMxh 1VdTtk4RZOGUWHcgRzQ/WeO0ixpdJCp7IJ6vsqRVheO3QDBjbUB0/fgMupviX2AsdNI/4v HrICK03Ysn2ecxt+qwI0F9cCRHG6u7S6JR6ViCuKN7f+JS+gCtp87yo9d4cJAzHtuQs2TY eg+n81gyAkz+AxX8lZm6/FBljQUQikVHzROJdVSLAmyR/Y83+FpdiEgXl+BVpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670996987; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=QNpKpayg5m+XAIaRuwFw0UHYb8Gn69XadS8BdP/lTFI=; b=i5WVYopGFfP7MUaO0nKl5tanQ5zgrGcyXwuqqYNxOpUFmZ/2/phFbv4RQdbH+o78PGHUXP nBzr03b3ZqV+W84imMFFVvYo2ihWWYVMORqj4SMVyGV+uNiptl5wYn7snlKIQpWVPQJTJN 0uHoMTS4ablu1sFW7XIVTPNlg8IlU3Fgo3B1qDSGGKEiSx6wtnw08F5/Y2BHQ9GkEv38JA 61msi2pYkIzoPSY/yF7VtTidF9WMriscFlr9iok/u1xgdW3uy7mf2JosFkqg9/YOs0r79h TEESioGpF6DWPCokkYHuQa3I8qlaCwqdBwyH+xSML0BFSpYgrrXPOd5rN3I7hw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1670996987; a=rsa-sha256; cv=none; b=w0S86xAym5PAE8IEoLCb6R+dt9aD4F1GGXLNsqkNswIZ/i9LNkrg9gt0ZBmKRG1fhcgYpo sHf92gaer396eW41vMFT34W4P/PJH16WCKdeSNOM3HRRIpwJ/ExqSGUQS3Iy3gS1YZn5xo R7YaBw6UqZStc3ColhjmL5MlDDFCFbOIMLe53daz5b1pI9e2pEJX/mghG6hPl4iULZEAdK 4zzfaNpOsyKZOywWnVj2qqxaD8dPtJqqdxlTE/kZWKI49l1ewzUWUS+6mkDOSiMghOdv1G e8ZdmxmMgjm0py1eUHYaprdJZ7vT7XRDnpttSNACn9PX2eJU8caM1+PbUWqReA== 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 4NX4FR3bNxzjB8; Wed, 14 Dec 2022 05:49:47 +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 2BE5nlsb034712; Wed, 14 Dec 2022 05:49:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BE5nlAP034711; Wed, 14 Dec 2022 05:49:47 GMT (envelope-from git) Date: Wed, 14 Dec 2022 05:49:47 GMT Message-Id: <202212140549.2BE5nlAP034711@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: a002c839ec71 - main - if_ovpn: cleanup offsetof() use List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a002c839ec71557c0256bbb4f0f31482af8c6dd6 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=a002c839ec71557c0256bbb4f0f31482af8c6dd6 commit a002c839ec71557c0256bbb4f0f31482af8c6dd6 Author: Kristof Provost AuthorDate: 2022-12-05 13:14:49 +0000 Commit: Kristof Provost CommitDate: 2022-12-14 05:48:59 +0000 if_ovpn: cleanup offsetof() use Move the use of the `offsetof(struct ovpn_counters, fieldname) / sizeof(uint64_t)` construct into a macro. This removes a fair bit of code duplication and should make things a little easier to read. Reviewed by: zlei Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D37607 --- sys/net/if_ovpn.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/sys/net/if_ovpn.c b/sys/net/if_ovpn.c index a11dd0b4a6cb..28a0ed33f010 100644 --- a/sys/net/if_ovpn.c +++ b/sys/net/if_ovpn.c @@ -250,12 +250,16 @@ VNET_DEFINE_STATIC(struct if_clone *, ovpn_cloner); #define OVPN_WASSERT(sc) rm_assert(&(sc)->lock, RA_WLOCKED) #define OVPN_UNLOCK_ASSERT(sc) rm_assert(&(sc)->lock, RA_UNLOCKED) +#define OVPN_COUNTER(sc, name) \ + ((sc)->counters[offsetof(struct ovpn_counters, name)/sizeof(uint64_t)]) +#define OVPN_PEER_COUNTER(peer, name) \ + ((peer)->counters[offsetof(struct ovpn_peer_counters, name) / \ + sizeof(uint64_t)]) + #define OVPN_COUNTER_ADD(sc, name, val) \ - counter_u64_add(sc->counters[offsetof(struct ovpn_counters, name) / \ - sizeof(uint64_t)], val) + counter_u64_add(OVPN_COUNTER(sc, name), val) #define OVPN_PEER_COUNTER_ADD(p, name, val) \ - counter_u64_add(p->counters[offsetof(struct ovpn_peer_counters, name) / \ - sizeof(uint64_t)], val) + counter_u64_add(OVPN_PEER_COUNTER(p, name), val) #define TO_IN(x) ((struct sockaddr_in *)(x)) #define TO_IN6(x) ((struct sockaddr_in6 *)(x)) @@ -442,14 +446,10 @@ ovpn_notify_del_peer(struct ovpn_softc *sc, struct ovpn_kpeer *peer) n->type = OVPN_NOTIF_DEL_PEER; n->del_reason = peer->del_reason; - n->counters.pkt_in = counter_u64_fetch(peer->counters[offsetof( - struct ovpn_peer_counters, pkt_in)/sizeof(uint64_t)]); - n->counters.pkt_out = counter_u64_fetch(peer->counters[offsetof( - struct ovpn_peer_counters, pkt_out)/sizeof(uint64_t)]); - n->counters.bytes_in = counter_u64_fetch(peer->counters[offsetof( - struct ovpn_peer_counters, bytes_in)/sizeof(uint64_t)]); - n->counters.bytes_out = counter_u64_fetch(peer->counters[offsetof( - struct ovpn_peer_counters, bytes_out)/sizeof(uint64_t)]); + n->counters.pkt_in = counter_u64_fetch(OVPN_PEER_COUNTER(peer, pkt_in)); + n->counters.pkt_out = counter_u64_fetch(OVPN_PEER_COUNTER(peer, pkt_out)); + n->counters.bytes_in = counter_u64_fetch(OVPN_PEER_COUNTER(peer, bytes_in)); + n->counters.bytes_out = counter_u64_fetch(OVPN_PEER_COUNTER(peer, bytes_out)); if (buf_ring_enqueue(sc->notifring, n) != 0) { free(n, M_OVPN); @@ -1248,11 +1248,8 @@ ovpn_get_stats(struct ovpn_softc *sc, nvlist_t **onvl) #define OVPN_COUNTER_OUT(name, in, out) \ do { \ - ret = ovpn_add_counters(nvl, name, \ - sc->counters[offsetof(struct ovpn_counters, in) / \ - sizeof(uint64_t)], \ - sc->counters[offsetof(struct ovpn_counters, out) / \ - sizeof(uint64_t)]); \ + ret = ovpn_add_counters(nvl, name, OVPN_COUNTER(sc, in), \ + OVPN_COUNTER(sc, out)); \ if (ret != 0) \ goto error; \ } while(0) @@ -1294,10 +1291,7 @@ ovpn_get_peer_stats(struct ovpn_softc *sc, nvlist_t **nvl) #define OVPN_PEER_COUNTER_OUT(name, in, out) \ do { \ ret = ovpn_add_counters(nvpeer, name, \ - peer->counters[offsetof(struct ovpn_peer_counters, in) / \ - sizeof(uint64_t)], \ - peer->counters[offsetof(struct ovpn_peer_counters, out) / \ - sizeof(uint64_t)]); \ + OVPN_PEER_COUNTER(peer, in), OVPN_PEER_COUNTER(peer, out)); \ if (ret != 0) \ goto error; \ } while(0)