Content-Length: 462964 | pFad | http://github.com/liweitianux/dragonflybsd/commit/090e9eb015eafdd35666e530644beb23e2dc4d88

66 wg: Port #7: implement necessary counter(9) bits · liweitianux/dragonflybsd@090e9eb · GitHub
Skip to content

Commit 090e9eb

Browse files
committed
wg: Port DragonFlyBSD#7: implement necessary counter(9) bits
1 parent b437739 commit 090e9eb

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

sys/net/wg/if_wg.c

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#include <sys/param.h>
1414
#include <sys/systm.h>
15-
#include <sys/counter.h>
1615
#include <sys/gtaskqueue.h>
1716
#include <sys/jail.h>
1817
#include <sys/kernel.h>
@@ -202,8 +201,8 @@ struct wg_peer {
202201
struct grouptask p_send;
203202
struct grouptask p_recv;
204203

205-
counter_u64_t p_tx_bytes;
206-
counter_u64_t p_rx_bytes;
204+
uint64_t *p_tx_bytes;
205+
uint64_t *p_rx_bytes;
207206

208207
LIST_HEAD(, wg_aip) p_aips;
209208
size_t p_aips_num;
@@ -390,8 +389,10 @@ wg_peer_alloc(struct wg_softc *sc, const uint8_t pub_key[WG_KEY_SIZE])
390389

391390
peer = kmalloc(sizeof(*peer), M_WG, M_WAITOK | M_ZERO);
392391
peer->p_remote = noise_remote_alloc(sc->sc_local, peer, pub_key);
393-
peer->p_tx_bytes = counter_u64_alloc(M_WAITOK);
394-
peer->p_rx_bytes = counter_u64_alloc(M_WAITOK);
392+
peer->p_tx_bytes = kmalloc(sizeof(*peer->p_tx_bytes) * ncpus,
393+
M_WG, M_WAITOK | M_ZERO);
394+
peer->p_rx_bytes = kmalloc(sizeof(*peer->p_rx_bytes) * ncpus,
395+
M_WG, M_WAITOK | M_ZERO);
395396
peer->p_id = peer_counter++;
396397
peer->p_sc = sc;
397398

@@ -444,8 +445,8 @@ wg_peer_free_deferred(struct noise_remote *r)
444445
wg_queue_deinit(&peer->p_encrypt_serial);
445446
wg_queue_deinit(&peer->p_stage_queue);
446447

447-
counter_u64_free(peer->p_tx_bytes);
448-
counter_u64_free(peer->p_rx_bytes);
448+
kfree(peer->p_tx_bytes, M_WG);
449+
kfree(peer->p_rx_bytes, M_WG);
449450
lockuninit(&peer->p_endpoint_lock);
450451
lockuninit(&peer->p_handshake_mtx);
451452

@@ -1194,7 +1195,7 @@ wg_peer_send_buf(struct wg_peer *peer, uint8_t *buf, size_t len)
11941195
{
11951196
struct wg_endpoint endpoint;
11961197

1197-
counter_u64_add(peer->p_tx_bytes, len);
1198+
peer->p_tx_bytes[mycpuid] += len;
11981199
wg_timers_event_any_authenticated_packet_traversal(peer);
11991200
wg_timers_event_any_authenticated_packet_sent(peer);
12001201
wg_peer_get_endpoint(peer, &endpoint);
@@ -1398,7 +1399,7 @@ wg_handshake(struct wg_softc *sc, struct wg_packet *pkt)
13981399
wg_timers_event_any_authenticated_packet_traversal(peer);
13991400

14001401
not_authenticated:
1401-
counter_u64_add(peer->p_rx_bytes, m->m_pkthdr.len);
1402+
peer->p_rx_bytes[mycpuid] += m->m_pkthdr.len;
14021403
if_inc_counter(sc->sc_ifp, IFCOUNTER_IPACKETS, 1);
14031404
if_inc_counter(sc->sc_ifp, IFCOUNTER_IBYTES, m->m_pkthdr.len);
14041405
error:
@@ -1656,7 +1657,7 @@ wg_deliver_out(struct wg_peer *peer)
16561657
if (rc == 0) {
16571658
if (len > (sizeof(struct wg_pkt_data) + NOISE_AUTHTAG_LEN))
16581659
wg_timers_event_data_sent(peer);
1659-
counter_u64_add(peer->p_tx_bytes, len);
1660+
peer->p_tx_bytes[mycpuid] += len;
16601661
} else if (rc == EADDRNOTAVAIL) {
16611662
wg_peer_clear_src(peer);
16621663
wg_peer_get_endpoint(peer, &endpoint);
@@ -1698,7 +1699,7 @@ wg_deliver_in(struct wg_peer *peer)
16981699
wg_timers_event_any_authenticated_packet_traversal(peer);
16991700
wg_peer_set_endpoint(peer, &pkt->p_endpoint);
17001701

1701-
counter_u64_add(peer->p_rx_bytes, m->m_pkthdr.len +
1702+
peer->p_rx_bytes[mycpuid] += (m->m_pkthdr.len +
17021703
sizeof(struct wg_pkt_data) + NOISE_AUTHTAG_LEN);
17031704
if_inc_counter(sc->sc_ifp, IFCOUNTER_IPACKETS, 1);
17041705
if_inc_counter(sc->sc_ifp, IFCOUNTER_IBYTES, m->m_pkthdr.len +
@@ -2467,12 +2468,13 @@ wgc_get(struct wg_softc *sc, struct wg_data_io *wgd)
24672468
uint8_t private_key[WG_KEY_SIZE] = { 0 };
24682469
uint8_t preshared_key[NOISE_SYMMETRIC_KEY_LEN] = { 0 };
24692470
nvlist_t *nvl, *nvl_peer, *nvl_aip, **nvl_peers, **nvl_aips;
2471+
uint64_t rx_bytes, tx_bytes;
24702472
size_t size, peer_count, aip_count, i, j;
24712473
struct wg_timespec64 ts64;
24722474
struct wg_peer *peer;
24732475
struct wg_aip *aip;
24742476
void *packed;
2475-
int err = 0;
2477+
int cpu, err = 0;
24762478

24772479
nvl = nvlist_create(0);
24782480
if (!nvl)
@@ -2516,8 +2518,15 @@ wgc_get(struct wg_softc *sc, struct wg_data_io *wgd)
25162518
wg_timers_get_last_handshake(peer, &ts64);
25172519
nvlist_add_binary(nvl_peer, "last-handshake-time", &ts64, sizeof(ts64));
25182520
nvlist_add_number(nvl_peer, "persistent-keepalive-interval", peer->p_persistent_keepalive_interval);
2519-
nvlist_add_number(nvl_peer, "rx-bytes", counter_u64_fetch(peer->p_rx_bytes));
2520-
nvlist_add_number(nvl_peer, "tx-bytes", counter_u64_fetch(peer->p_tx_bytes));
2521+
2522+
rx_bytes = 0;
2523+
tx_bytes = 0;
2524+
for (cpu = 0; cpu < ncpus; cpu++) {
2525+
rx_bytes += peer->p_rx_bytes[cpu];
2526+
tx_bytes += peer->p_tx_bytes[cpu];
2527+
}
2528+
nvlist_add_number(nvl_peer, "rx-bytes", rx_bytes);
2529+
nvlist_add_number(nvl_peer, "tx-bytes", tx_bytes);
25212530

25222531
aip_count = peer->p_aips_num;
25232532
if (aip_count) {

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/liweitianux/dragonflybsd/commit/090e9eb015eafdd35666e530644beb23e2dc4d88

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy