On Tue, 1 Sep 2020 20:57:09 +0200
Klemens Nanni <k...@openbsd.org> wrote:

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

High level, I understand the problem and this makes debugging easier.
It shouldn't affect multiple interfaces because it is only used for
debugging, and there is a wgN prefixed to the log message. Overall,
seems fine to me.

The patch isn't fully correct. When you remove a peer, sc_peer_num
will decrement, and if you add a new peer afterwards you will have
duplicate IDs. This is likely to create further headaches. A dedicated
ID counter in wg_softc should probably be used.

> 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