aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Dunwoodie <ncon@mail.noconroy.net>2019-09-22 23:29:40 +0200
committerMatt Dunwoodie <ncon@mail.noconroy.net>2019-09-22 23:29:40 +0200
commitb5ba2568f9800eacb9bc0bef1d53bf9b1efcacb8 (patch)
tree212ffdb10ef22925af143eaa036eaded05de626f
parentMove antireplay to it's own header (diff)
downloadwireguard-openbsd-b5ba2568f9800eacb9bc0bef1d53bf9b1efcacb8.tar.xz
wireguard-openbsd-b5ba2568f9800eacb9bc0bef1d53bf9b1efcacb8.zip
Move functions from header files into dedicated file
The header files were nice while experimenting, but they are not ideal. Currently we have all the custom data structures in kerk/kern_wg.c, which would ideally not be named after wireguard, But for the time being, at least they're organised.
-rw-r--r--src/Makefile5
-rw-r--r--src/antireplay.h44
-rw-r--r--src/bloombucket.h89
-rwxr-xr-xsrc/clean_patch.sh1
-rw-r--r--src/fixedmap.h105
-rw-r--r--src/kern_wg.c348
-rw-r--r--src/mpq.h75
-rw-r--r--src/patches/files.patch5
8 files changed, 358 insertions, 314 deletions
diff --git a/src/Makefile b/src/Makefile
index 785bb6d..87c15e7 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -69,6 +69,9 @@ sysctl: patch_sysctl
/usr/src/sys/sys/mpq.h: mpq.h
cp mpq.h /usr/src/sys/sys/mpq.h
+/usr/src/sys/kern/kern_wg.c: kern_wg.c
+ cp kern_wg.c /usr/src/sys/kern/kern_wg.c
+
/usr/src/sys/conf/GENERIC: patches/CONFIG.patch
patch -uN /usr/src/sys/conf/GENERIC < patches/CONFIG.patch || touch /usr/src/sys/conf/GENERIC
@@ -110,7 +113,7 @@ sysctl: patch_sysctl
patch -uN /usr/src/distrib/sets/lists/man/mi < patches/man_mi.patch || touch /usr/src/distrib/sets/lists/man/mi
.PHONY:
-patch_kernel: /usr/src/sys/net/wireguard.c /usr/src/sys/net/wireguard.h /usr/src/sys/crypto/blake2s.c /usr/src/sys/crypto/blake2s.h /usr/src/sys/crypto/curve25519.c /usr/src/sys/crypto/curve25519.h /usr/src/sys/crypto/chacha_private.h /usr/src/sys/crypto/chachapoly.h /usr/src/sys/crypto/chachapoly.c /usr/src/sys/conf/files /usr/src/sys/conf/GENERIC /usr/src/sys/netinet/in_pcb.h /usr/src/sys/netinet/udp_usrreq.c /usr/src/sys/net/if_wg.c /usr/src/sys/net/if_wg.h /usr/src/sys/sys/bloombucket.h /usr/src/sys/sys/fixedmap.h /usr/src/sys/kern/uipc_mbuf.c /usr/src/sys/sys/mpq.h /usr/src/sys/sys/antireplay.h
+patch_kernel: /usr/src/sys/net/wireguard.c /usr/src/sys/net/wireguard.h /usr/src/sys/crypto/blake2s.c /usr/src/sys/crypto/blake2s.h /usr/src/sys/crypto/curve25519.c /usr/src/sys/crypto/curve25519.h /usr/src/sys/crypto/chacha_private.h /usr/src/sys/crypto/chachapoly.h /usr/src/sys/crypto/chachapoly.c /usr/src/sys/conf/files /usr/src/sys/conf/GENERIC /usr/src/sys/netinet/in_pcb.h /usr/src/sys/netinet/udp_usrreq.c /usr/src/sys/net/if_wg.c /usr/src/sys/net/if_wg.h /usr/src/sys/sys/bloombucket.h /usr/src/sys/sys/fixedmap.h /usr/src/sys/kern/uipc_mbuf.c /usr/src/sys/sys/mpq.h /usr/src/sys/sys/antireplay.h /usr/src/sys/kern/kern_wg.c
.PHONY:
patch_userspace: /usr/src/usr.bin/kdump/mkioctls /usr/src/usr.bin/kdump/Makefile /usr/src/distrib/sets/lists/comp/mi
diff --git a/src/antireplay.h b/src/antireplay.h
index 0df6a5f..a903d58 100644
--- a/src/antireplay.h
+++ b/src/antireplay.h
@@ -25,47 +25,7 @@ struct antireplay {
uint64_t ar_bitmap[ARB_BITS / ARI_BITS];
};
-static void antireplay_init(struct antireplay *);
-static int antireplay_update(struct antireplay *, uint64_t);
-
-/*
- * The following defines assist the antireplay_check function. *
- * ANTIREPLAY_INTEGER: the integer in the bitmap corresponding to num *
- * ANTIREPLAY_INTEGERBIT: the integer with corresponding single bit set
- */
-#define ANTIREPLAY_INTEGER(ctx, num) (ctx->ar_bitmap[num % ARB_BITS / ARI_BITS])
-#define ANTIREPLAY_INTEGERBIT(num) (1llu << (num & (ARI_BITS - 1)))
-
-static void
-antireplay_init(struct antireplay *ctx)
-{
- /* We just zero out the struct, expecting that then ctx->ar_head == 0 */
- explicit_bzero(ctx, sizeof(struct antireplay));
-}
-
-static int
-antireplay_update(struct antireplay *ctx, uint64_t num)
-{
- /* Bits after ctx->ar_head need to be zeroed. This is called when num is
- * in front of ctx->ar_head, and those bits need to be set to 0 */
- if (num < ctx->ar_head + ARB_BITS / ARI_BITS) {
- for (; ctx->ar_head <= num; ctx->ar_head += ARI_BITS) {
- ANTIREPLAY_INTEGER(ctx, (ctx->ar_head + 1)) = 0;
- }
- } else {
- bzero(ctx->ar_bitmap, ARB_BITS / ARI_BITS);
- }
-
- if (ctx->ar_head > (num + ARB_BITS - ARI_BITS)) {
- /* Expired */
- return 1;
- } else if (ANTIREPLAY_INTEGER(ctx, num) & ANTIREPLAY_INTEGERBIT(num)) {
- /* Replayed */
- return 1;
- } else {
- /* Unseen */
- return 0;
- }
-}
+void antireplay_init(struct antireplay *);
+int antireplay_update(struct antireplay *, uint64_t);
#endif /* __ANTIREPLAY_H__ */
diff --git a/src/bloombucket.h b/src/bloombucket.h
index 7bcaf86..b69ee5e 100644
--- a/src/bloombucket.h
+++ b/src/bloombucket.h
@@ -35,93 +35,4 @@ void bb_tick(void *);
int bb_recv(struct bloom_bucket *, uint8_t *, size_t);
uint8_t bb_load(struct bloom_bucket *);
-void
-bb_init(struct bloom_bucket *bb, size_t size, size_t keys, uint8_t interval,
- uint8_t thresh, int type, int flags)
-{
- size_t i;
-
- for (bb->size = 1; bb->size < size; bb->size <<= 1);
-
- bb->type = type;
- bb->nkeys = keys;
- bb->thresh = thresh;
- bb->interval = interval;
- bb->keys = mallocarray(bb->nkeys, sizeof(*bb->keys), bb->type, flags);
- bb->bucket = mallocarray(bb->size, 1, bb->type, flags | M_ZERO);
-
- for (i = 0; i < bb->nkeys; i++)
- arc4random_buf(&bb->keys[i], sizeof(*bb->keys));
-
- timeout_set(&bb->tick, bb_tick, bb);
-}
-
-void
-bb_destroy(struct bloom_bucket *bb)
-{
- free(bb->keys, bb->type, bb->nkeys);
- free(bb->bucket, bb->type, bb->size);
-}
-
-void
-bb_tick(void *_bb)
-{
- struct bloom_bucket *bb = _bb;
- int act;
- size_t i;
-
- for (i = 0, act = 0; i < bb->size; i++) {
- /* Check to protect underflow, as well as flag
- * if action has been taken, therefore should
- * schedule again. */
- if (bb->bucket[i] > 0) {
- bb->bucket[i]--;
- act = 1;
- }
- }
-
- if (act && !timeout_pending(&bb->tick))
- timeout_add_sec(&bb->tick, bb->interval);
-}
-
-int
-bb_recv(struct bloom_bucket *bb, uint8_t *buf, size_t n)
-{
- size_t i;
- uint64_t hash;
- uint8_t *elem, min = 0xff;
-
- for (i = 0; i < bb->nkeys; i++) {
- hash = SipHash24(&bb->keys[i], buf, n);
- elem = &bb->bucket[hash & (bb->size - 1)];
- if (*elem < min)
- min = *elem;
- if (*elem < bb->thresh)
- (*elem)++;
- }
-
- if (!timeout_pending(&bb->tick))
- timeout_add_sec(&bb->tick, bb->interval);
-
- return min == bb->thresh;
-}
-
-uint8_t
-bb_load(struct bloom_bucket *bb)
-{
- size_t i;
- uint8_t log;
- uint64_t sum;
- for (i = 0, sum = 0; i < bb->size; i++)
- sum += bb->bucket[i];
-
- sum *= (0xffffffffffffffff / (bb->size * bb->thresh));
-
- log = 0;
- while (sum >>= 1)
- log++;
-
- return log;
-}
-
#endif /* __BLOOMBUCKET_H__ */
diff --git a/src/clean_patch.sh b/src/clean_patch.sh
index fadc5b9..64e55f6 100755
--- a/src/clean_patch.sh
+++ b/src/clean_patch.sh
@@ -30,6 +30,7 @@ cp $DIR/mpq.h /usr/src/sys/sys/
cp $DIR/fixedmap.h /usr/src/sys/sys/
cp $DIR/antireplay.h /usr/src/sys/sys/
cp $DIR/bloombucket.h /usr/src/sys/sys/
+cp $DIR/kern_wg.c /usr/src/sys/kern/
cp $DIR/if_wg.* $DIR/wireguard.* /usr/src/sys/net/
cp $DIR/blake2s.* $DIR/curve25519.* /usr/src/sys/crypto/
diff --git a/src/fixedmap.h b/src/fixedmap.h
index 076628d..0226fd6 100644
--- a/src/fixedmap.h
+++ b/src/fixedmap.h
@@ -43,109 +43,4 @@ uint32_t fm_insert(struct fixed_map *, void *);
void *fm_lookup(struct fixed_map *, uint32_t);
void fm_remove(struct fixed_map *, uint32_t);
-#define FM_SIZE(fm) (1 << (fm)->bits)
-#define FM_ITEM(fm, k) ((fm)->map[(k) & ((fm)->bits - 1)])
-
-void
-fm_init(struct fixed_map *fm)
-{
- rw_init(&fm->lock, "fixed_map");
- fm->bits = 0;
- fm->map = NULL;
-}
-
-void
-fm_destroy(struct fixed_map *fm)
-{
- free(fm->map, M_DEVBUF, 0);
-}
-
-void
-fm_resize(struct fixed_map *fm, size_t size)
-{
- struct map_item *old_map;
- size_t old_size, i;
-
- if (size <= FM_SIZE(fm))
- return;
-
- rw_enter_write(&fm->lock);
- old_size = FM_SIZE(fm);
- old_map = fm->map;
-
- for(fm->bits = 1; size >>= 1; fm->bits++);
- fm->map = mallocarray(FM_SIZE(fm), sizeof(*fm->map), M_DEVBUF, M_WAITOK | M_ZERO);
-
- if (old_map != NULL) {
- for (i = 0; i < old_size; i++)
- FM_ITEM(fm, old_map[i].key) = old_map[i];
- free(old_map, M_DEVBUF, 0);
- }
- rw_exit_write(&fm->lock);
-}
-
-uint32_t
-fm_reserve(struct fixed_map *fm)
-{
- size_t i;
- struct map_item *item = NULL;
-
- rw_enter_write(&fm->lock);
- for (i = 0; i < FM_SIZE(fm); i++) {
- if (fm->map[i].state == FM_ITEM_EMPTY) {
- item = &fm->map[i];
- break;
- }
- }
-
- if (item == NULL)
- panic("unable to find space in fixed map");
-
- item->key = (arc4random() << fm->bits) + i;
- item->state = FM_ITEM_RESERVED;
- rw_exit_write(&fm->lock);
-
- return item->key;
-}
-
-void
-fm_set(struct fixed_map *fm, uint32_t k, void *v)
-{
- rw_enter_write(&fm->lock);
- if (FM_ITEM(fm, k).key == k ) {
- FM_ITEM(fm, k).value = v;
- FM_ITEM(fm, k).state = FM_ITEM_FILLED;
- }
- rw_exit_write(&fm->lock);
-}
-
-uint32_t
-fm_insert(struct fixed_map *fm, void *v)
-{
- uint32_t k = fm_reserve(fm);
- fm_set(fm, k, v);
- return k;
-}
-
-void *
-fm_lookup(struct fixed_map *fm, uint32_t k)
-{
- void *v;
- rw_enter_read(&fm->lock);
- v = FM_ITEM(fm, k).key == k ? FM_ITEM(fm, k).value : NULL;
- rw_exit_read(&fm->lock);
- return v;
-}
-
-void
-fm_remove(struct fixed_map *fm, uint32_t k)
-{
- rw_enter_write(&fm->lock);
- if (FM_ITEM(fm, k).key == k) {
- FM_ITEM(fm, k).value = NULL;
- FM_ITEM(fm, k).state = FM_ITEM_EMPTY;
- }
- rw_exit_write(&fm->lock);
-}
-
#endif /* __FIXEDMAP_H__ */
diff --git a/src/kern_wg.c b/src/kern_wg.c
new file mode 100644
index 0000000..697249e
--- /dev/null
+++ b/src/kern_wg.c
@@ -0,0 +1,348 @@
+/*
+ * Copyright (c) 2019 Matt Dunwoodie <ncon@noconroy.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/param.h>
+
+#include <sys/antireplay.h>
+#include <sys/bloombucket.h>
+#include <sys/fixedmap.h>
+#include <sys/mpq.h>
+
+/*
+ * antireplay.h
+ */
+
+/*
+ * The following defines assist the antireplay_check function. *
+ * ANTIREPLAY_INTEGER: the integer in the bitmap corresponding to num *
+ * ANTIREPLAY_INTEGERBIT: the integer with corresponding single bit set
+ */
+#define ANTIREPLAY_INTEGER(ctx, num) (ctx->ar_bitmap[num % ARB_BITS / ARI_BITS])
+#define ANTIREPLAY_INTEGERBIT(num) (1llu << (num & (ARI_BITS - 1)))
+
+void
+antireplay_init(struct antireplay *ctx)
+{
+ /* We just zero out the struct, expecting that then ctx->ar_head == 0 */
+ explicit_bzero(ctx, sizeof(struct antireplay));
+}
+
+int
+antireplay_update(struct antireplay *ctx, uint64_t num)
+{
+ /* Bits after ctx->ar_head need to be zeroed. This is called when num is
+ * in front of ctx->ar_head, and those bits need to be set to 0 */
+ if (num < ctx->ar_head + ARB_BITS / ARI_BITS) {
+ for (; ctx->ar_head <= num; ctx->ar_head += ARI_BITS) {
+ ANTIREPLAY_INTEGER(ctx, (ctx->ar_head + 1)) = 0;
+ }
+ } else {
+ bzero(ctx->ar_bitmap, ARB_BITS / ARI_BITS);
+ }
+
+ if (ctx->ar_head > (num + ARB_BITS - ARI_BITS)) {
+ /* Expired */
+ return 1;
+ } else if (ANTIREPLAY_INTEGER(ctx, num) & ANTIREPLAY_INTEGERBIT(num)) {
+ /* Replayed */
+ return 1;
+ } else {
+ /* Unseen */
+ return 0;
+ }
+}
+
+/*
+ * bloombucket.h
+ */
+
+void
+bb_init(struct bloom_bucket *bb, size_t size, size_t keys, uint8_t interval,
+ uint8_t thresh, int type, int flags)
+{
+ size_t i;
+
+ for (bb->size = 1; bb->size < size; bb->size <<= 1);
+
+ bb->type = type;
+ bb->nkeys = keys;
+ bb->thresh = thresh;
+ bb->interval = interval;
+ bb->keys = mallocarray(bb->nkeys, sizeof(*bb->keys), bb->type, flags);
+ bb->bucket = mallocarray(bb->size, 1, bb->type, flags | M_ZERO);
+
+ for (i = 0; i < bb->nkeys; i++)
+ arc4random_buf(&bb->keys[i], sizeof(*bb->keys));
+
+ timeout_set(&bb->tick, bb_tick, bb);
+}
+
+void
+bb_destroy(struct bloom_bucket *bb)
+{
+ free(bb->keys, bb->type, bb->nkeys);
+ free(bb->bucket, bb->type, bb->size);
+}
+
+void
+bb_tick(void *_bb)
+{
+ struct bloom_bucket *bb = _bb;
+ int act;
+ size_t i;
+
+ for (i = 0, act = 0; i < bb->size; i++) {
+ /* Check to protect underflow, as well as flag
+ * if action has been taken, therefore should
+ * schedule again. */
+ if (bb->bucket[i] > 0) {
+ bb->bucket[i]--;
+ act = 1;
+ }
+ }
+
+ if (act && !timeout_pending(&bb->tick))
+ timeout_add_sec(&bb->tick, bb->interval);
+}
+
+int
+bb_recv(struct bloom_bucket *bb, uint8_t *buf, size_t n)
+{
+ size_t i;
+ uint64_t hash;
+ uint8_t *elem, min = 0xff;
+
+ for (i = 0; i < bb->nkeys; i++) {
+ hash = SipHash24(&bb->keys[i], buf, n);
+ elem = &bb->bucket[hash & (bb->size - 1)];
+ if (*elem < min)
+ min = *elem;
+ if (*elem < bb->thresh)
+ (*elem)++;
+ }
+
+ if (!timeout_pending(&bb->tick))
+ timeout_add_sec(&bb->tick, bb->interval);
+
+ return min == bb->thresh;
+}
+
+uint8_t
+bb_load(struct bloom_bucket *bb)
+{
+ size_t i;
+ uint8_t log;
+ uint64_t sum;
+ for (i = 0, sum = 0; i < bb->size; i++)
+ sum += bb->bucket[i];
+
+ sum *= (0xffffffffffffffff / (bb->size * bb->thresh));
+
+ log = 0;
+ while (sum >>= 1)
+ log++;
+
+ return log;
+}
+
+/*
+ * fixedmap.h
+ */
+
+#define FM_SIZE(fm) (1 << (fm)->bits)
+#define FM_ITEM(fm, k) ((fm)->map[(k) & ((fm)->bits - 1)])
+
+void
+fm_init(struct fixed_map *fm)
+{
+ rw_init(&fm->lock, "fixed_map");
+ fm->bits = 0;
+ fm->map = NULL;
+}
+
+void
+fm_destroy(struct fixed_map *fm)
+{
+ free(fm->map, M_DEVBUF, 0);
+}
+
+void
+fm_resize(struct fixed_map *fm, size_t size)
+{
+ struct map_item *old_map;
+ size_t old_size, i;
+
+ if (size <= FM_SIZE(fm))
+ return;
+
+ rw_enter_write(&fm->lock);
+ old_size = FM_SIZE(fm);
+ old_map = fm->map;
+
+ for(fm->bits = 1; size >>= 1; fm->bits++);
+ fm->map = mallocarray(FM_SIZE(fm), sizeof(*fm->map), M_DEVBUF, M_WAITOK | M_ZERO);
+
+ if (old_map != NULL) {
+ for (i = 0; i < old_size; i++)
+ FM_ITEM(fm, old_map[i].key) = old_map[i];
+ free(old_map, M_DEVBUF, 0);
+ }
+ rw_exit_write(&fm->lock);
+}
+
+uint32_t
+fm_reserve(struct fixed_map *fm)
+{
+ size_t i;
+ struct map_item *item = NULL;
+
+ rw_enter_write(&fm->lock);
+ for (i = 0; i < FM_SIZE(fm); i++) {
+ if (fm->map[i].state == FM_ITEM_EMPTY) {
+ item = &fm->map[i];
+ break;
+ }
+ }
+
+ if (item == NULL)
+ panic("unable to find space in fixed map");
+
+ item->key = (arc4random() << fm->bits) + i;
+ item->state = FM_ITEM_RESERVED;
+ rw_exit_write(&fm->lock);
+
+ return item->key;
+}
+
+void
+fm_set(struct fixed_map *fm, uint32_t k, void *v)
+{
+ rw_enter_write(&fm->lock);
+ if (FM_ITEM(fm, k).key == k ) {
+ FM_ITEM(fm, k).value = v;
+ FM_ITEM(fm, k).state = FM_ITEM_FILLED;
+ }
+ rw_exit_write(&fm->lock);
+}
+
+uint32_t
+fm_insert(struct fixed_map *fm, void *v)
+{
+ uint32_t k = fm_reserve(fm);
+ fm_set(fm, k, v);
+ return k;
+}
+
+void *
+fm_lookup(struct fixed_map *fm, uint32_t k)
+{
+ void *v;
+ rw_enter_read(&fm->lock);
+ v = FM_ITEM(fm, k).key == k ? FM_ITEM(fm, k).value : NULL;
+ rw_exit_read(&fm->lock);
+ return v;
+}
+
+void
+fm_remove(struct fixed_map *fm, uint32_t k)
+{
+ rw_enter_write(&fm->lock);
+ if (FM_ITEM(fm, k).key == k) {
+ FM_ITEM(fm, k).value = NULL;
+ FM_ITEM(fm, k).state = FM_ITEM_EMPTY;
+ }
+ rw_exit_write(&fm->lock);
+}
+
+/*
+ * mpq.h
+ */
+
+void
+mpq_init(struct mpq *mpq, int ipl)
+{
+ mpq->mpq_cursor = NULL;
+ mpq->mpq_serializer = NULL;
+ mtx_init(&mpq->mpq_mtx, ipl);
+ ml_init(&mpq->mpq_list);
+}
+
+int
+mpq_serialize_try_enter(struct mpq *mpq)
+{
+ int error = 1;
+ mtx_enter(&mpq->mpq_mtx);
+ if (mpq->mpq_serializer == NULL) {
+ mpq->mpq_serializer = curcpu();
+ error = 0;
+ }
+ mtx_leave(&mpq->mpq_mtx);
+ return error;
+}
+
+void
+mpq_serialize_leave(struct mpq *mpq)
+{
+ mtx_enter(&mpq->mpq_mtx);
+ mpq->mpq_serializer = NULL;
+ mtx_leave(&mpq->mpq_mtx);
+}
+
+void
+mpq_enqueue(struct mpq *mpq, struct mbuf *m)
+{
+ /* TODO time based dropping of packets */
+ CLR(m->m_flags, M_LINK0);
+ mtx_enter(&mpq->mpq_mtx);
+ ml_enqueue(&mpq->mpq_list, m);
+ mtx_leave(&mpq->mpq_mtx);
+}
+
+void
+mpq_enlist(struct mpq *mpq, struct mbuf_list *list)
+{
+ mtx_enter(&mpq->mpq_mtx);
+ ml_enlist(&mpq->mpq_list, list);
+ mtx_leave(&mpq->mpq_mtx);
+}
+
+struct mbuf
+*mpq_dethread(struct mpq *mpq)
+{
+ struct mbuf *m;
+ mtx_enter(&mpq->mpq_mtx);
+ if (mpq->mpq_cursor == NULL)
+ mpq->mpq_cursor = MBUF_LIST_FIRST(&mpq->mpq_list);
+ else
+ mpq->mpq_cursor = MBUF_LIST_NEXT(mpq->mpq_cursor);
+ m = mpq->mpq_cursor;
+ mtx_leave(&mpq->mpq_mtx);
+ return m;
+}
+
+struct mbuf
+*mpq_dequeue(struct mpq *mpq)
+{
+ struct mbuf *m;
+ mtx_enter(&mpq->mpq_mtx);
+ m = MBUF_LIST_FIRST(&mpq->mpq_list);
+ if (m != NULL && ISSET(m->m_flags, M_LINK0))
+ m = ml_dequeue(&mpq->mpq_list);
+ else
+ m = NULL;
+ mtx_leave(&mpq->mpq_mtx);
+ return m;
+}
diff --git a/src/mpq.h b/src/mpq.h
index 1629ccc..146deda 100644
--- a/src/mpq.h
+++ b/src/mpq.h
@@ -53,79 +53,4 @@ void fn_name(void *_mpq) { \
} \
} \
-void
-mpq_init(struct mpq *mpq, int ipl)
-{
- mpq->mpq_cursor = NULL;
- mpq->mpq_serializer = NULL;
- mtx_init(&mpq->mpq_mtx, ipl);
- ml_init(&mpq->mpq_list);
-}
-
-int
-mpq_serialize_try_enter(struct mpq *mpq)
-{
- int error = 1;
- mtx_enter(&mpq->mpq_mtx);
- if (mpq->mpq_serializer == NULL) {
- mpq->mpq_serializer = curcpu();
- error = 0;
- }
- mtx_leave(&mpq->mpq_mtx);
- return error;
-}
-
-void
-mpq_serialize_leave(struct mpq *mpq)
-{
- mtx_enter(&mpq->mpq_mtx);
- mpq->mpq_serializer = NULL;
- mtx_leave(&mpq->mpq_mtx);
-}
-
-void
-mpq_enqueue(struct mpq *mpq, struct mbuf *m)
-{
- /* TODO time based dropping of packets */
- CLR(m->m_flags, M_LINK0);
- mtx_enter(&mpq->mpq_mtx);
- ml_enqueue(&mpq->mpq_list, m);
- mtx_leave(&mpq->mpq_mtx);
-}
-
-void
-mpq_enlist(struct mpq *mpq, struct mbuf_list *list)
-{
- mtx_enter(&mpq->mpq_mtx);
- ml_enlist(&mpq->mpq_list, list);
- mtx_leave(&mpq->mpq_mtx);
-}
-
-struct mbuf
-*mpq_dethread(struct mpq *mpq)
-{
- struct mbuf *m;
- mtx_enter(&mpq->mpq_mtx);
- if (mpq->mpq_cursor == NULL)
- mpq->mpq_cursor = MBUF_LIST_FIRST(&mpq->mpq_list);
- else
- mpq->mpq_cursor = MBUF_LIST_NEXT(mpq->mpq_cursor);
- m = mpq->mpq_cursor;
- mtx_leave(&mpq->mpq_mtx);
- return m;
-}
-
-struct mbuf
-*mpq_dequeue(struct mpq *mpq)
-{
- struct mbuf *m;
- mtx_enter(&mpq->mpq_mtx);
- m = MBUF_LIST_FIRST(&mpq->mpq_list);
- if (m != NULL && ISSET(m->m_flags, M_LINK0))
- m = ml_dequeue(&mpq->mpq_list);
- else
- m = NULL;
- mtx_leave(&mpq->mpq_mtx);
- return m;
-}
#endif /* _MPQ_H_ */
diff --git a/src/patches/files.patch b/src/patches/files.patch
index 3b2a3d2..4469026 100644
--- a/src/patches/files.patch
+++ b/src/patches/files.patch
@@ -8,16 +8,17 @@
pseudo-device ksyms
file dev/ksyms.c ksyms needs-flag
-@@ -824,6 +825,8 @@
+@@ -824,6 +825,9 @@
file net/if_pair.c pair needs-count
file net/if_pppx.c pppx needs-count
file net/if_vxlan.c vxlan needs-count
+file net/wireguard.c wg
+file net/if_wg.c wg
++file kern/kern_wg.c wg
file net/bfd.c bfd
file net80211/ieee80211.c wlan
file net80211/ieee80211_amrr.c wlan
-@@ -900,6 +902,8 @@
+@@ -900,6 +903,8 @@
file crypto/chachapoly.c ipsec | crypto
file crypto/poly1305.c ipsec | crypto
file crypto/siphash.c