|
12 | 12 |
|
13 | 13 | #include <sys/param.h>
|
14 | 14 | #include <sys/systm.h>
|
15 |
| -#include <sys/counter.h> |
16 | 15 | #include <sys/gtaskqueue.h>
|
17 | 16 | #include <sys/jail.h>
|
18 | 17 | #include <sys/kernel.h>
|
@@ -202,8 +201,8 @@ struct wg_peer {
|
202 | 201 | struct grouptask p_send;
|
203 | 202 | struct grouptask p_recv;
|
204 | 203 |
|
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; |
207 | 206 |
|
208 | 207 | LIST_HEAD(, wg_aip) p_aips;
|
209 | 208 | size_t p_aips_num;
|
@@ -390,8 +389,10 @@ wg_peer_alloc(struct wg_softc *sc, const uint8_t pub_key[WG_KEY_SIZE])
|
390 | 389 |
|
391 | 390 | peer = kmalloc(sizeof(*peer), M_WG, M_WAITOK | M_ZERO);
|
392 | 391 | 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); |
395 | 396 | peer->p_id = peer_counter++;
|
396 | 397 | peer->p_sc = sc;
|
397 | 398 |
|
@@ -444,8 +445,8 @@ wg_peer_free_deferred(struct noise_remote *r)
|
444 | 445 | wg_queue_deinit(&peer->p_encrypt_serial);
|
445 | 446 | wg_queue_deinit(&peer->p_stage_queue);
|
446 | 447 |
|
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); |
449 | 450 | lockuninit(&peer->p_endpoint_lock);
|
450 | 451 | lockuninit(&peer->p_handshake_mtx);
|
451 | 452 |
|
@@ -1194,7 +1195,7 @@ wg_peer_send_buf(struct wg_peer *peer, uint8_t *buf, size_t len)
|
1194 | 1195 | {
|
1195 | 1196 | struct wg_endpoint endpoint;
|
1196 | 1197 |
|
1197 |
| - counter_u64_add(peer->p_tx_bytes, len); |
| 1198 | + peer->p_tx_bytes[mycpuid] += len; |
1198 | 1199 | wg_timers_event_any_authenticated_packet_traversal(peer);
|
1199 | 1200 | wg_timers_event_any_authenticated_packet_sent(peer);
|
1200 | 1201 | wg_peer_get_endpoint(peer, &endpoint);
|
@@ -1398,7 +1399,7 @@ wg_handshake(struct wg_softc *sc, struct wg_packet *pkt)
|
1398 | 1399 | wg_timers_event_any_authenticated_packet_traversal(peer);
|
1399 | 1400 |
|
1400 | 1401 | not_authenticated:
|
1401 |
| - counter_u64_add(peer->p_rx_bytes, m->m_pkthdr.len); |
| 1402 | + peer->p_rx_bytes[mycpuid] += m->m_pkthdr.len; |
1402 | 1403 | if_inc_counter(sc->sc_ifp, IFCOUNTER_IPACKETS, 1);
|
1403 | 1404 | if_inc_counter(sc->sc_ifp, IFCOUNTER_IBYTES, m->m_pkthdr.len);
|
1404 | 1405 | error:
|
@@ -1656,7 +1657,7 @@ wg_deliver_out(struct wg_peer *peer)
|
1656 | 1657 | if (rc == 0) {
|
1657 | 1658 | if (len > (sizeof(struct wg_pkt_data) + NOISE_AUTHTAG_LEN))
|
1658 | 1659 | wg_timers_event_data_sent(peer);
|
1659 |
| - counter_u64_add(peer->p_tx_bytes, len); |
| 1660 | + peer->p_tx_bytes[mycpuid] += len; |
1660 | 1661 | } else if (rc == EADDRNOTAVAIL) {
|
1661 | 1662 | wg_peer_clear_src(peer);
|
1662 | 1663 | wg_peer_get_endpoint(peer, &endpoint);
|
@@ -1698,7 +1699,7 @@ wg_deliver_in(struct wg_peer *peer)
|
1698 | 1699 | wg_timers_event_any_authenticated_packet_traversal(peer);
|
1699 | 1700 | wg_peer_set_endpoint(peer, &pkt->p_endpoint);
|
1700 | 1701 |
|
1701 |
| - counter_u64_add(peer->p_rx_bytes, m->m_pkthdr.len + |
| 1702 | + peer->p_rx_bytes[mycpuid] += (m->m_pkthdr.len + |
1702 | 1703 | sizeof(struct wg_pkt_data) + NOISE_AUTHTAG_LEN);
|
1703 | 1704 | if_inc_counter(sc->sc_ifp, IFCOUNTER_IPACKETS, 1);
|
1704 | 1705 | 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)
|
2467 | 2468 | uint8_t private_key[WG_KEY_SIZE] = { 0 };
|
2468 | 2469 | uint8_t preshared_key[NOISE_SYMMETRIC_KEY_LEN] = { 0 };
|
2469 | 2470 | nvlist_t *nvl, *nvl_peer, *nvl_aip, **nvl_peers, **nvl_aips;
|
| 2471 | + uint64_t rx_bytes, tx_bytes; |
2470 | 2472 | size_t size, peer_count, aip_count, i, j;
|
2471 | 2473 | struct wg_timespec64 ts64;
|
2472 | 2474 | struct wg_peer *peer;
|
2473 | 2475 | struct wg_aip *aip;
|
2474 | 2476 | void *packed;
|
2475 |
| - int err = 0; |
| 2477 | + int cpu, err = 0; |
2476 | 2478 |
|
2477 | 2479 | nvl = nvlist_create(0);
|
2478 | 2480 | if (!nvl)
|
@@ -2516,8 +2518,15 @@ wgc_get(struct wg_softc *sc, struct wg_data_io *wgd)
|
2516 | 2518 | wg_timers_get_last_handshake(peer, &ts64);
|
2517 | 2519 | nvlist_add_binary(nvl_peer, "last-handshake-time", &ts64, sizeof(ts64));
|
2518 | 2520 | 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); |
2521 | 2530 |
|
2522 | 2531 | aip_count = peer->p_aips_num;
|
2523 | 2532 | if (aip_count) {
|
|
0 commit comments