aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Dunwoodie <ncon@mail.noconroy.net>2019-09-24 07:16:12 +0100
committerMatt Dunwoodie <ncon@mail.noconroy.net>2019-09-24 07:16:12 +0100
commitb8381403f63c65d6e7e8936cf52d4c18efb5e07a (patch)
tree4b7ee63e197f693c57ad8018ac910a28eded3c85
parentFix two bugs (diff)
downloadwireguard-openbsd-b8381403f63c65d6e7e8936cf52d4c18efb5e07a.tar.xz
wireguard-openbsd-b8381403f63c65d6e7e8936cf52d4c18efb5e07a.zip
Add max queue length of 1024 packets
-rw-r--r--src/if_wg.c9
-rw-r--r--src/kern_wg.c14
-rw-r--r--src/mpq.h3
3 files changed, 19 insertions, 7 deletions
diff --git a/src/if_wg.c b/src/if_wg.c
index 61b3d68..1dfc368 100644
--- a/src/if_wg.c
+++ b/src/if_wg.c
@@ -892,8 +892,13 @@ wg_start(struct ifnet *ifp)
struct mbuf *m;
struct wg_softc *sc = ifp->if_softc;
- while ((m = ifq_dequeue(&ifp->if_snd)) != NULL)
- mpq_enqueue(&sc->sc_tx_queue, m);
+ while ((m = ifq_deq_begin(&ifp->if_snd)) != NULL) {
+ if (mpq_enqueue(&sc->sc_tx_queue, m) != 0) {
+ ifq_deq_rollback(&ifp->if_snd, m);
+ break;
+ }
+ ifq_deq_commit(&ifp->if_snd, m);
+ }
task_add(sc->sc_taskq, &sc->sc_tx_task);
}
diff --git a/src/kern_wg.c b/src/kern_wg.c
index 671b8b1..9839929 100644
--- a/src/kern_wg.c
+++ b/src/kern_wg.c
@@ -301,16 +301,22 @@ mpq_serialize_leave(struct mpq *mpq)
mtx_leave(&mpq->mpq_mtx);
}
-void
+int
mpq_enqueue(struct mpq *mpq, struct mbuf *m)
{
/* TODO time based dropping of packets */
+ int dropped = 0;
CLR(m->m_flags, M_LINK0);
mtx_enter(&mpq->mpq_mtx);
- ml_enqueue(&mpq->mpq_list, m);
- if (mpq->mpq_cursor == NULL)
- mpq->mpq_cursor = m;
+ if (ml_len(&mpq->mpq_list) < MPQ_LEN) {
+ ml_enqueue(&mpq->mpq_list, m);
+ if (mpq->mpq_cursor == NULL)
+ mpq->mpq_cursor = m;
+ } else {
+ dropped = 1;
+ }
mtx_leave(&mpq->mpq_mtx);
+ return dropped;
}
void
diff --git a/src/mpq.h b/src/mpq.h
index 146deda..eda5cfa 100644
--- a/src/mpq.h
+++ b/src/mpq.h
@@ -31,12 +31,13 @@ struct mpq {
void mpq_init(struct mpq *, int);
int mpq_serialize_try_enter(struct mpq *);
void mpq_serialize_leave(struct mpq *);
-void mpq_enqueue(struct mpq *, struct mbuf *);
+int mpq_enqueue(struct mpq *, struct mbuf *);
void mpq_enlist(struct mpq *, struct mbuf_list *);
struct mbuf *mpq_dethread(struct mpq *);
struct mbuf *mpq_dequeue(struct mpq *);
void mpq_done(struct mbuf *m);
+#define MPQ_LEN 1024
#define MPQ_WORKER(fn_name, parallel_fn, serial_fn) \
void fn_name(void *_mpq) { \
struct mbuf *m; \