aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2021-11-10 16:38:22 -0800
committerJason A. Donenfeld <Jason@zx2c4.com>2022-06-14 00:54:37 +0200
commitb7441e315429e65c5b60c4ebcf05282a8c53456d (patch)
tree3bea3ea032c9d05e5aed03f2b2459fea79d59534
parentbuild: include compat.h for all files (diff)
downloadwireguard-freebsd-b7441e315429e65c5b60c4ebcf05282a8c53456d.tar.xz
wireguard-freebsd-b7441e315429e65c5b60c4ebcf05282a8c53456d.zip
if_wg: wg_peer_alloc and wg_aip_add: Use M_WAITOK with malloc
Signed-off-by: John Baldwin <jhb@FreeBSD.org>
-rw-r--r--src/if_wg.c32
-rw-r--r--src/wg_noise.c3
2 files changed, 7 insertions, 28 deletions
diff --git a/src/if_wg.c b/src/if_wg.c
index bbcaafe..a368d15 100644
--- a/src/if_wg.c
+++ b/src/if_wg.c
@@ -409,18 +409,10 @@ wg_peer_alloc(struct wg_softc *sc, const uint8_t pub_key[WG_KEY_SIZE])
sx_assert(&sc->sc_lock, SX_XLOCKED);
- if ((peer = malloc(sizeof(*peer), M_WG, M_NOWAIT | M_ZERO)) == NULL)
- goto free_none;
-
- if ((peer->p_remote = noise_remote_alloc(sc->sc_local, peer, pub_key)) == NULL)
- goto free_peer;
-
- if ((peer->p_tx_bytes = counter_u64_alloc(M_NOWAIT)) == NULL)
- goto free_remote;
-
- if ((peer->p_rx_bytes = counter_u64_alloc(M_NOWAIT)) == NULL)
- goto free_tx_bytes;
-
+ peer = malloc(sizeof(*peer), M_WG, M_WAITOK | M_ZERO);
+ peer->p_remote = noise_remote_alloc(sc->sc_local, peer, pub_key);
+ peer->p_tx_bytes = counter_u64_alloc(M_WAITOK);
+ peer->p_rx_bytes = counter_u64_alloc(M_WAITOK);
peer->p_id = peer_counter++;
peer->p_sc = sc;
@@ -454,14 +446,6 @@ wg_peer_alloc(struct wg_softc *sc, const uint8_t pub_key[WG_KEY_SIZE])
peer->p_aips_num = 0;
return (peer);
-free_tx_bytes:
- counter_u64_free(peer->p_tx_bytes);
-free_remote:
- noise_remote_free(peer->p_remote, NULL);
-free_peer:
- free(peer, M_WG);
-free_none:
- return NULL;
}
static void
@@ -560,8 +544,7 @@ wg_aip_add(struct wg_softc *sc, struct wg_peer *peer, sa_family_t af, const void
struct wg_aip *aip;
int i, ret = 0;
- if ((aip = malloc(sizeof(*aip), M_WG, M_NOWAIT | M_ZERO)) == NULL)
- return (ENOBUFS);
+ aip = malloc(sizeof(*aip), M_WG, M_WAITOK | M_ZERO);
aip->a_peer = peer;
aip->a_af = af;
@@ -2279,10 +2262,7 @@ wg_peer_add(struct wg_softc *sc, const nvlist_t *nvl)
wg_aip_remove_all(sc, peer);
}
if (peer == NULL) {
- if ((peer = wg_peer_alloc(sc, pub_key)) == NULL) {
- err = ENOMEM;
- goto out;
- }
+ peer = wg_peer_alloc(sc, pub_key);
need_insert = true;
}
if (nvlist_exists_binary(nvl, "endpoint")) {
diff --git a/src/wg_noise.c b/src/wg_noise.c
index d166543..8da001f 100644
--- a/src/wg_noise.c
+++ b/src/wg_noise.c
@@ -295,8 +295,7 @@ noise_remote_alloc(struct noise_local *l, void *arg,
{
struct noise_remote *r;
- if ((r = malloc(sizeof(*r), M_NOISE, M_NOWAIT | M_ZERO)) == NULL)
- return (NULL);
+ r = malloc(sizeof(*r), M_NOISE, M_WAITOK | M_ZERO);
memcpy(r->r_public, public, NOISE_PUBLIC_KEY_LEN);
rw_init(&r->r_handshake_lock, "noise_handshake");