summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Dunwoodie <ncon@mail.noconroy.net>2019-09-11 20:58:52 +1000
committerMatt Dunwoodie <ncon@mail.noconroy.net>2019-09-11 20:58:52 +1000
commitbbc0571b61f65a1045840e5edbeba54f5ba6c703 (patch)
tree6f5fa9f339cca78268fbb8122e7f3af1e1c19337
parentExtract common packet allocation. (diff)
downloadwireguard-openbsd-bbc0571b61f65a1045840e5edbeba54f5ba6c703.tar.xz
wireguard-openbsd-bbc0571b61f65a1045840e5edbeba54f5ba6c703.zip
Use ifq for output queueing
-rw-r--r--src/if_wg.c51
1 files changed, 28 insertions, 23 deletions
diff --git a/src/if_wg.c b/src/if_wg.c
index c3590187f01..64933f0b326 100644
--- a/src/if_wg.c
+++ b/src/if_wg.c
@@ -152,7 +152,6 @@ int wg_ioctl(struct ifnet *, u_long, caddr_t);
RB_PROTOTYPE(peer_tree, wg_peer, p_entry, wg_peer_cmp)
RB_GENERATE(peer_tree, wg_peer, p_entry, wg_peer_cmp)
-struct mpq wg_queue_tx;
struct mpq wg_queue_rx;
struct mpq wg_queue_rx_slow;
struct bloom_bucket wg_bb;
@@ -212,7 +211,6 @@ wg_peer_destroy(struct wg_softc *sc, struct wg_peer *p)
wg_peer_cleanup(p);
/* Barrier on packets */
- mpq_barrier(&wg_queue_tx);
mpq_barrier(&wg_queue_rx);
mpq_barrier(&wg_queue_rx_slow);
@@ -353,8 +351,7 @@ wg_peer_new_session(struct wg_softc *sc, struct wg_peer *p)
wg_peer_keepalive(p);
while ((m = mq_dequeue(&p->p_outgoing)) != NULL)
- if ((m = wg_transport_encrypt(m)) != NULL)
- wg_output_deliver(m);
+ wg_transport_encrypt(m);
}
void
@@ -509,7 +506,6 @@ wg_input(void *_sc, struct mbuf *m, struct sockaddr *sa, int hlen)
break;
case WG_PKT_UNKNOWN:
goto free;
- break;
}
return NULL;
@@ -520,9 +516,26 @@ leave:
return NULL;
}
+void
+wg_start(struct ifqueue *ifq)
+{
+ struct mbuf *m;
+ struct ifnet *ifp = ifq->ifq_if;
+ struct wg_softc *sc = ifp->if_softc;
+
+ while ((m = ifq_dequeue(ifq)) != NULL) {
+ m->m_pkthdr.ph_cookie = wg_route_lookup(sc, m, true);
+ if (m->m_pkthdr.ph_cookie != NULL)
+ wg_transport_encrypt(m);
+ else
+ m_freem(m);
+ }
+}
+
int
wg_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *sa, struct rtentry *rt)
{
+ int error = 0;
struct wg_peer *p;
struct wg_softc *sc = ifp->if_softc;
@@ -560,15 +573,10 @@ wg_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *sa, struct rtentry
return ENETUNREACH;
}
- m->m_pkthdr.ph_cookie = p;
-
- if (mpq_enqueue(&wg_queue_tx, m) != 0) {
- m_freem(m);
+ if ((error = if_enqueue(ifp, m)) != 0)
counters_inc(sc->sc_if.if_counters, ifc_oqdrops);
- return ENOBUFS;
- }
- return 0;
+ return error;
}
void
@@ -659,10 +667,8 @@ wg_transmit_keepalive(struct wg_peer *p)
m->m_pkthdr.ph_cookie = p;
m_calchdrlen(m);
- if ((m = wg_transport_encrypt(m)) != NULL) {
- DPRINTF_PEER("transmit keepalive", p);
- wg_output_deliver(m);
- }
+ DPRINTF_PEER("transmit keepalive", p);
+ wg_transport_encrypt(m);
}
struct mbuf *
@@ -826,6 +832,8 @@ wg_transport_encrypt(struct mbuf *m)
m_freem(m);
+ wg_output_deliver(em);
+
return em;
}
@@ -1031,7 +1039,6 @@ wg_clone_create(struct if_clone * ifc, int unit)
sc = wg_softc_create();
if (SLIST_EMPTY(&wg_devs)) {
- mpq_init(&wg_queue_tx, IPL_NET, (void *(*)(void *)) wg_transport_encrypt, (void (*)(void *)) wg_output_deliver);
mpq_init(&wg_queue_rx, IPL_NET, (void *(*)(void *)) wg_transport_decrypt, (void (*)(void *)) wg_input_deliver);
mpq_init(&wg_queue_rx_slow, IPL_NET, (void *(*)(void *)) wg_receive_slow, wg_queue_rx_slow_nop);
mpq_size(&wg_queue_rx_slow, 8);
@@ -1046,10 +1053,11 @@ wg_clone_create(struct if_clone * ifc, int unit)
ifp->if_mtu = 1420;
ifp->if_flags = IFF_NOARP | IFF_MULTICAST | IFF_BROADCAST;
- ifp->if_xflags = IFXF_CLONED;
+ ifp->if_xflags = IFXF_CLONED | IFXF_MPSAFE;
ifp->if_ioctl = wg_ioctl;
ifp->if_output = wg_output;
+ ifp->if_qstart = wg_start;
ifp->if_rtrequest = p2p_rtrequest;
ifp->if_type = IFT_TUNNEL;
@@ -1091,7 +1099,6 @@ wg_clone_destroy(struct ifnet * ifp)
if (SLIST_EMPTY(&wg_devs)) {
DPRINTF("killing threads\n");
- mpq_destroy(&wg_queue_tx);
mpq_destroy(&wg_queue_rx);
mpq_destroy(&wg_queue_rx_slow);
}
@@ -1395,13 +1402,12 @@ net_wireguard_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
switch (name[0]) {
case NET_LINK_WIREGUARD_THREADS:
- val = wg_queue_tx.mpq_nthreads;
+ val = wg_queue_rx.mpq_nthreads;
error = sysctl_int(oldp, oldlenp, newp, newlen, &val);
if (error != 0)
return (error);
if (val < 1 || val > ncpus)
return (EINVAL);
- mpq_nthreads(&wg_queue_tx, val);
mpq_nthreads(&wg_queue_rx, val);
mpq_nthreads(&wg_queue_rx_slow, val);
break;
@@ -1415,13 +1421,12 @@ net_wireguard_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
wg_debug_enabled = val;
break;
case NET_LINK_WIREGUARD_QUEUE:
- val = wg_queue_tx.mpq_size;
+ val = wg_queue_rx.mpq_size;
error = sysctl_int(oldp, oldlenp, newp, newlen, &val);
if (error != 0)
return (error);
if (val < 1)
return (EINVAL);
- mpq_size(&wg_queue_tx, val);
mpq_size(&wg_queue_rx, val);
break;
case NET_LINK_WIREGUARD_HSQUEUE: