The driver increases a static peer counter across all wg interfaces when
creating peers, the peer number is only used in debug output, though.

Output from console around recreating an interface  (2 and 4 are the same):

        wg1: Receiving handshake response from peer 2
        wg1: Receiving keepalive packet from peer 2
        wg1: Sending keepalive packet to peer 2
        # ifconfig wg0 destroy
        wg1: Peer 1 destroyed
        wg1: Peer 2 destroyed
        wg1: Destroyed interface
        # sh /etc/netstart wg0
        wg1: Sending handshake initiation to peer 4
        wg1: Receiving handshake response from peer 4
        wg1: Receiving keepalive packet from peer 4
        wg1: Sending keepalive packet to peer 4

I'm looking into an issue caused by having multiple `wgpeer's defined
on a single wg(4) interface and debug log is helpful, but having to
count along is not helpful, so I'd like to replace the global counter
with an interface specific one that's already in place.

There's another completely unused global counter which I remove as well
in the diff below.

Recreating as above now shows this:

        # ifconfig wg1 destroy
        wg1: Peer 0 destroyed
        wg1: Peer 1 destroyed
        wg1: Destroyed interface
        # sh /etc/netstart wg0
        wg1: Peer 0 created
        wg1: Sending handshake initiation to peer 0
        wg1: Receiving handshake response from peer 0
        wg1: Peer 1 created
        wg1: Receiving keepalive packet from peer 0

Feedback? OK?


Index: if_wg.c
===================================================================
RCS file: /cvs/src/sys/net/if_wg.c,v
retrieving revision 1.13
diff -u -p -r1.13 if_wg.c
--- if_wg.c     27 Aug 2020 21:27:17 -0000      1.13
+++ if_wg.c     1 Sep 2020 18:35:41 -0000
@@ -370,8 +370,6 @@ int wg_clone_create(struct if_clone *, i
 int    wg_clone_destroy(struct ifnet *);
 void   wgattach(int);
 
-uint64_t       peer_counter = 0;
-uint64_t       keypair_counter = 0;
 struct pool    wg_aip_pool;
 struct pool    wg_peer_pool;
 struct pool    wg_ratelimit_pool;
@@ -398,7 +396,6 @@ wg_peer_create(struct wg_softc *sc, uint
        if ((peer = pool_get(&wg_peer_pool, PR_NOWAIT)) == NULL)
                return NULL;
 
-       peer->p_id = peer_counter++;
        peer->p_sc = sc;
 
        noise_remote_init(&peer->p_remote, public, &sc->sc_local);
@@ -442,7 +439,7 @@ wg_peer_create(struct wg_softc *sc, uint
        rw_enter_write(&sc->sc_peer_lock);
        LIST_INSERT_HEAD(&sc->sc_peer[idx], peer, p_pubkey_entry);
        TAILQ_INSERT_TAIL(&sc->sc_peer_seq, peer, p_seq_entry);
-       sc->sc_peer_num++;
+       peer->p_id = sc->sc_peer_num++;
        rw_exit_write(&sc->sc_peer_lock);
 
        DPRINTF(sc, "Peer %llu created\n", peer->p_id);

Reply via email to