aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatt Dunwoodie <ncon@noconroy.net>2021-04-20 08:55:08 +1000
committerMatt Dunwoodie <ncon@noconroy.net>2021-04-20 10:52:36 +1000
commit0fa8645fe431c29a8d9371679398bf7839bffec1 (patch)
tree05b69fe7b654c16dc4c9349d7164fb6e8f8c942b /src
parentif_wg: add missing return parens to follow style(9) (diff)
downloadwireguard-freebsd-0fa8645fe431c29a8d9371679398bf7839bffec1.tar.xz
wireguard-freebsd-0fa8645fe431c29a8d9371679398bf7839bffec1.zip
wg_noise: lookup both keypair and handshake index at once
Signed-off-by: Matt Dunwoodie <ncon@noconroy.net>
Diffstat (limited to 'src')
-rw-r--r--src/if_wg.c9
-rw-r--r--src/wg_noise.c10
2 files changed, 10 insertions, 9 deletions
diff --git a/src/if_wg.c b/src/if_wg.c
index c1ebb0c..a64403b 100644
--- a/src/if_wg.c
+++ b/src/if_wg.c
@@ -1260,7 +1260,6 @@ wg_handshake(struct wg_softc *sc, struct wg_packet *pkt)
struct wg_endpoint *e;
struct wg_peer *peer;
struct mbuf *m;
- struct noise_keypair *keypair;
struct noise_remote *remote = NULL;
int res, underload = 0;
static struct timeval wg_last_underload; /* microuptime */
@@ -1353,12 +1352,8 @@ wg_handshake(struct wg_softc *sc, struct wg_packet *pkt)
cook = mtod(m, struct wg_pkt_cookie *);
if ((remote = noise_remote_index_lookup(sc->sc_local, cook->r_idx)) == NULL) {
- if ((keypair = noise_keypair_lookup(sc->sc_local, cook->r_idx)) == NULL) {
- DPRINTF(sc, "Unknown cookie index\n");
- goto error;
- }
- remote = noise_keypair_remote(keypair);
- noise_keypair_put(keypair);
+ DPRINTF(sc, "Unknown cookie index\n");
+ goto error;
}
peer = noise_remote_arg(remote);
diff --git a/src/wg_noise.c b/src/wg_noise.c
index 7cf160b..4a1134d 100644
--- a/src/wg_noise.c
+++ b/src/wg_noise.c
@@ -380,13 +380,19 @@ noise_remote_index_lookup(struct noise_local *l, uint32_t idx0)
{
struct epoch_tracker et;
struct noise_index *i;
+ struct noise_keypair *kp;
struct noise_remote *r, *ret = NULL;
uint32_t idx = idx0 & HT_INDEX_MASK;
NET_EPOCH_ENTER(et);
CK_LIST_FOREACH(i, &l->l_index_hash[idx], i_entry) {
- if (i->i_local_index == idx0 && !i->i_is_keypair) {
- r = (struct noise_remote *) i;
+ if (i->i_local_index == idx0) {
+ if (i->i_is_keypair) {
+ kp = (struct noise_keypair *) i;
+ r = kp->kp_remote;
+ } else {
+ r = (struct noise_remote *) i;
+ }
if (refcount_acquire_if_not_zero(&r->r_refcnt))
ret = r;
break;