aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Dunwoodie <ncon@mail.noconroy.net>2019-10-05 01:57:24 +0100
committerMatt Dunwoodie <ncon@mail.noconroy.net>2019-10-05 11:05:33 +0100
commit61bf6b8e860ce249773c2ef3f3c50f19ca09b970 (patch)
tree740cad2960a66b13eb4ea714b2440c9425394557
parentModify if_wg.h interface (diff)
downloadwireguard-openbsd-61bf6b8e860ce249773c2ef3f3c50f19ca09b970.tar.xz
wireguard-openbsd-61bf6b8e860ce249773c2ef3f3c50f19ca09b970.zip
Add notify to alert new session has been created
-rw-r--r--src/if_wg.c21
-rw-r--r--src/wireguard.c4
-rw-r--r--src/wireguard.h2
3 files changed, 26 insertions, 1 deletions
diff --git a/src/if_wg.c b/src/if_wg.c
index 0533f4c..f96ee1c 100644
--- a/src/if_wg.c
+++ b/src/if_wg.c
@@ -451,6 +451,25 @@ wg_peer_queue(struct wg_peer *peer, enum wg_pkt_type type, uint32_t dst)
}
void
+wg_peer_notify(struct wg_peer *peer)
+{
+ struct mbuf *m;
+ struct sockaddr sa;
+ struct wg_route *route = peer->p_arg;
+ struct wg_softc *sc = route->r_sc;
+
+ if (mq_empty(&route->r_outgoing))
+ wg_route_send_keepalive(route);
+
+ /* We know wg_output only uses sa to verify the AF */
+ while ((m = mq_dequeue(&route->r_outgoing)) != NULL) {
+ sa.sa_family = m->m_pkthdr.ph_family;
+ wg_output(&sc->sc_if, m, &sa, NULL);
+ }
+ task_add(sc->sc_taskq, &sc->sc_tx_task);
+}
+
+void
wg_encrypt_hs(struct mbuf *m)
{
enum wg_error err;
@@ -903,7 +922,7 @@ wg_clone_create(struct if_clone * ifc, int unit)
inp->inp_upcall_arg = sc;
#endif
- wg_device_init(&sc->sc_dev, wg_peer_queue, wg_softc_peer_clean, sc);
+ wg_device_init(&sc->sc_dev, wg_peer_notify, wg_peer_queue, wg_softc_peer_clean, sc);
sc->sc_taskq = taskq_create("wg", ncpus, IPL_NET, TASKQ_MPSAFE);
task_set(&sc->sc_tx_task, wg_tx_task_fn, &sc->sc_tx_queue);
diff --git a/src/wireguard.c b/src/wireguard.c
index bd9e096..2b04d16 100644
--- a/src/wireguard.c
+++ b/src/wireguard.c
@@ -91,12 +91,14 @@ struct wg_session *wg_device_ref_session(struct wg_device *, uint32_t);
/* Some crappy API */
void
wg_device_init(struct wg_device *dev,
+ void (*notify_fn)(struct wg_peer *),
void (*outq_fn)(struct wg_peer *, enum wg_pkt_type, uint32_t),
void (*cleanup_fn)(struct wg_peer *), void *arg)
{
bzero(dev, sizeof(*dev));
dev->d_arg = arg;
dev->d_outq = outq_fn;
+ dev->d_notify = notify_fn;
dev->d_cleanup = cleanup_fn;
fm_init(&dev->d_peers);
fm_init(&dev->d_sessions);
@@ -362,6 +364,8 @@ wg_session_promote(struct wg_session *session)
if (old_session != NULL)
wg_session_drop(old_session);
+
+ peer->p_device->d_notify(peer);
}
void
diff --git a/src/wireguard.h b/src/wireguard.h
index 7d77296..1ee235c 100644
--- a/src/wireguard.h
+++ b/src/wireguard.h
@@ -198,6 +198,7 @@ struct wg_peer {
struct wg_device {
void *d_arg;
void (*d_cleanup)(struct wg_peer *);
+ void (*d_notify)(struct wg_peer *);
void (*d_outq)(struct wg_peer *, enum wg_pkt_type, uint32_t);
struct fixed_map d_peers;
struct fixed_map d_sessions;
@@ -243,6 +244,7 @@ static char *wg_error_str[] = {
/* WireGuard functions */
void wg_device_init(struct wg_device *,
+ void (*)(struct wg_peer *),
void (*)(struct wg_peer *, enum wg_pkt_type, uint32_t),
void (*)(struct wg_peer *), void *);
void wg_device_setkey(struct wg_device *, struct wg_privkey *);