aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Dunwoodie <ncon@mail.noconroy.net>2019-10-06 13:55:53 +0100
committerMatt Dunwoodie <ncon@mail.noconroy.net>2019-10-07 10:28:41 +0100
commitf312e4ddaed5348f0106c6af549aa1b2ec197dfa (patch)
tree2c530646c72a5be1e18c37e883074b3f6774a5cd
parentMove mutex and refcnt to fixedmap (diff)
downloadwireguard-openbsd-f312e4ddaed5348f0106c6af549aa1b2ec197dfa.tar.xz
wireguard-openbsd-f312e4ddaed5348f0106c6af549aa1b2ec197dfa.zip
Couple of small fixes
-rw-r--r--src/Makefile3
-rw-r--r--src/if_wg.c4
-rw-r--r--src/kern_wg.c33
-rw-r--r--src/mpq.h2
4 files changed, 32 insertions, 10 deletions
diff --git a/src/Makefile b/src/Makefile
index 87c15e7..40db60f 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -123,6 +123,9 @@ kernel: patch_kernel
make -C /usr/src/sys/arch/${ARCH}/compile/$(CONFIG)/ obj
make -C /usr/src/sys/arch/${ARCH}/compile/$(CONFIG)/ config
make -C /usr/src/sys/arch/${ARCH}/compile/$(CONFIG)/
+.PHONY:
+installgdb:
+ doas cp /usr/obj/sys/arch/${ARCH}/compile/$(CONFIG)/bsd.gdb /
.PHONY:
clean:
diff --git a/src/if_wg.c b/src/if_wg.c
index b055e1b..97fdf83 100644
--- a/src/if_wg.c
+++ b/src/if_wg.c
@@ -1090,8 +1090,8 @@ wg_ioctl_peer_set(struct wg_softc *sc, u_long cmd, struct wg_peer_set *wsp)
return EPERM;
/* Silently ignore set peer when the key is for ourselves */
- //if (!memcmp(sc->sc_kp.pub, wsp->sp_pubkey, WG_KEY_SIZE))
- // return 0;
+ if (!memcmp(sc->sc_dev.d_keypair.pub.k, wsp->sp_pubkey.k, WG_KEY_SIZE))
+ return 0;
if (IS_NULL_KEY(wsp->sp_pubkey.k) || IS_MASKED_KEY(wsp->sp_pubkey.k))
return EINVAL;
diff --git a/src/kern_wg.c b/src/kern_wg.c
index 7b38439..67de06b 100644
--- a/src/kern_wg.c
+++ b/src/kern_wg.c
@@ -155,14 +155,15 @@ bb_load(struct bloom_bucket *bb)
while (sum >>= 1)
log++;
- return log;
+ return log;
}
/*
* fixedmap.h
*/
-void fm_resize(struct fixed_map *, size_t);
+//#define FMPRINTF(...) printf("fm: " __VA_ARGS__)
+#define FMPRINTF(...) 0
void
fm_init(struct fixed_map *fm, size_t size, int ipl)
@@ -212,7 +213,7 @@ fm_destroy(struct fixed_map *fm)
uint32_t
fm_insert(struct fixed_map *fm, void *v)
{
- uint32_t id = 0;
+ uint32_t k = 0;
struct map_item *item = NULL, *iter;
mtx_enter(&fm->mtx);
@@ -225,16 +226,21 @@ fm_insert(struct fixed_map *fm, void *v)
if (item == NULL)
panic("fixed map not large enough");
- while (id == 0)
- id = (arc4random() & ~(fm->size - 1)) + (item - fm->map);
+ while (k == 0)
+ k = (arc4random() & ~(fm->size - 1)) + (item - fm->map);
- item->key = id;
+ item->key = k;
item->state = FM_ITEM_FILLED;
item->value = v;
-
+ refcnt_init(&item->refcnt);
mtx_leave(&fm->mtx);
- return id;
+ FMPRINTF("insert %x in %p - %d\n", k, fm, item->refcnt.refs);
+
+ /* We want to take another reference, as one reference is in the map
+ * and the other one gets returned */
+ refcnt_take(&item->refcnt);
+ return k;
}
void *
@@ -250,6 +256,7 @@ fm_lookup(struct fixed_map *fm, uint32_t k)
v = item->value;
}
mtx_leave(&fm->mtx);
+ FMPRINTF("lookup %x in %p - %d\n", k, fm, item->refcnt.refs);
return v;
}
@@ -263,6 +270,7 @@ fm_put(struct fixed_map *fm, uint32_t k)
if (item->key != k)
panic("element should be in map");
refcnt_rele_wake(&item->refcnt);
+ FMPRINTF("put %x in %p - %d\n", k, fm, item->refcnt.refs);
mtx_leave(&fm->mtx);
}
@@ -276,7 +284,16 @@ fm_drop(struct fixed_map *fm, uint32_t k)
if (item->key != k)
panic("element should be in map");
mtx_leave(&fm->mtx);
+
refcnt_finalize(&item->refcnt, "fm_drop");
+
+ mtx_enter(&fm->mtx);
+ item->key = 0;
+ item->state = FM_ITEM_EMPTY;
+ item->value = NULL;
+ mtx_leave(&fm->mtx);
+
+ FMPRINTF("drop %x in %p - %d\n", k, fm, item->refcnt.refs);
}
/*
diff --git a/src/mpq.h b/src/mpq.h
index 70f0dba..c5c27c4 100644
--- a/src/mpq.h
+++ b/src/mpq.h
@@ -43,6 +43,7 @@ void mpq_done(struct mbuf *m);
void fn_name(void *_mpq) { \
struct mbuf *m; \
struct mpq *mpq = _mpq; \
+ int s = splraise(mpq->mpq_mtx.mtx_wantipl); \
while ((m = mpq_dethread(mpq)) != NULL) { \
parallel_fn(m); \
mpq_threaddone(mpq, m); \
@@ -53,6 +54,7 @@ void fn_name(void *_mpq) { \
} \
mpq_serialize_leave(mpq); \
} \
+ splx(s); \
} \
#endif /* _MPQ_H_ */