aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Dunwoodie <ncon@mail.noconroy.net>2019-10-02 23:35:08 +0100
committerMatt Dunwoodie <ncon@mail.noconroy.net>2019-10-03 20:22:25 +0100
commit74cd9bcc84ce34b82a7671bed31a44acdf10d93e (patch)
tree19eca3e3ef86ff33dac6a8ba969a555e3b788699
parentMove wg_peer_ref to wg_device_new_peer (diff)
downloadwireguard-openbsd-74cd9bcc84ce34b82a7671bed31a44acdf10d93e.tar.xz
wireguard-openbsd-74cd9bcc84ce34b82a7671bed31a44acdf10d93e.zip
Further simplify the wireguard.h interface
-rw-r--r--src/wireguard.c77
-rw-r--r--src/wireguard.h11
2 files changed, 49 insertions, 39 deletions
diff --git a/src/wireguard.c b/src/wireguard.c
index 5e06dcf..b2f9b63 100644
--- a/src/wireguard.c
+++ b/src/wireguard.c
@@ -81,6 +81,9 @@ enum wg_error wg_msg_response_valid_mac2(struct wg_msg_response *, struct wg_coo
void wg_session_drop(struct wg_session *);
void wg_session_ref(struct wg_session *);
void wg_peer_ref(struct wg_peer *);
+void wg_peer_attach_session(struct wg_peer *, struct wg_session *);
+struct wg_session *wg_device_new_session(struct wg_device *);
+struct wg_session *wg_device_ref_session(struct wg_device *, uint32_t);
/* Some crappy API */
void
@@ -95,6 +98,22 @@ wg_device_init(struct wg_device *dev,
/* d_cookie_maker, d_keypair initialised to 0 */
}
+void
+wg_device_setkey(struct wg_device *dev, struct wg_privkey *key)
+{
+ rw_enter_write(&dev->d_lock);
+ wg_keypair_from_key(&dev->d_keypair, key);
+ rw_exit_write(&dev->d_lock);
+}
+
+void
+wg_device_destroy(struct wg_device *dev)
+{
+ /* TODO */
+ fm_destroy(&dev->d_sessions);
+ fm_destroy(&dev->d_peers);
+}
+
struct wg_peer *
wg_device_new_peer(struct wg_device *dev, struct wg_pubkey *key, void *arg)
{
@@ -270,6 +289,31 @@ wg_peer_reset_attempts(struct wg_peer *peer)
}
void
+wg_peer_clean(struct wg_peer *peer)
+{
+ struct wg_session *hs, *ks, *ks_old;
+ rw_enter_write(&peer->p_lock);
+
+ hs = peer->p_hs_session;
+ ks = peer->p_ks_session;
+ ks_old = peer->p_ks_session_old;
+
+ peer->p_hs_session = NULL;
+ peer->p_ks_session = NULL;
+ peer->p_ks_session_old = NULL;
+
+ rw_exit_write(&peer->p_lock);
+
+ if (hs != NULL)
+ wg_session_drop(hs);
+ if (ks != NULL)
+ wg_session_drop(ks);
+ if (ks_old != NULL)
+ wg_session_drop(ks_old);
+
+}
+
+void
wg_session_promote(struct wg_session *session)
{
struct wg_session *old_session;
@@ -335,14 +379,6 @@ wg_peer_ks_session(struct wg_peer *peer)
}
void
-wg_device_setkey(struct wg_device *dev, struct wg_privkey *key)
-{
- rw_enter_write(&dev->d_lock);
- wg_keypair_from_key(&dev->d_keypair, key);
- rw_exit_write(&dev->d_lock);
-}
-
-void
wg_peer_setshared(struct wg_peer *peer, struct wg_privkey *key)
{
rw_enter_write(&peer->p_lock);
@@ -369,31 +405,6 @@ wg_peer_last_handshake(struct wg_peer *peer)
return ret;
}
-void
-wg_peer_clean(struct wg_peer *peer)
-{
- struct wg_session *hs, *ks, *ks_old;
- rw_enter_write(&peer->p_lock);
-
- hs = peer->p_hs_session;
- ks = peer->p_ks_session;
- ks_old = peer->p_ks_session_old;
-
- peer->p_hs_session = NULL;
- peer->p_ks_session = NULL;
- peer->p_ks_session_old = NULL;
-
- rw_exit_write(&peer->p_lock);
-
- if (hs != NULL)
- wg_session_drop(hs);
- if (ks != NULL)
- wg_session_drop(ks);
- if (ks_old != NULL)
- wg_session_drop(ks_old);
-
-}
-
/* Crypto */
enum wg_error
wg_device_rx_initiation(struct wg_device *dev, struct wg_msg_initiation *init,
diff --git a/src/wireguard.h b/src/wireguard.h
index 401a7f7..2add51d 100644
--- a/src/wireguard.h
+++ b/src/wireguard.h
@@ -245,23 +245,22 @@ static char *wg_error_str[] = {
void wg_device_init(struct wg_device *,
void (*)(struct wg_peer *, enum wg_pkt_type, uint32_t));
void wg_device_setkey(struct wg_device *, struct wg_privkey *);
+void wg_device_destroy(struct wg_device *);
+
struct wg_peer *wg_device_new_peer(struct wg_device *, struct wg_pubkey *, void *);
struct wg_peer *wg_device_ref_peerkey(struct wg_device *, struct wg_pubkey *);
struct wg_peer *wg_device_ref_peerid(struct wg_device *, uint32_t);
-
void wg_peer_put(struct wg_peer *);
void wg_peer_drop(struct wg_peer *);
-void wg_peer_attach_session(struct wg_peer *, struct wg_session *);
+
void wg_peer_reset_attempts(struct wg_peer *);
+void wg_peer_clean(struct wg_peer *);
void wg_peer_setshared(struct wg_peer *, struct wg_privkey *);
void wg_peer_getshared(struct wg_peer *, struct wg_privkey *);
-void wg_peer_clean(struct wg_peer *);
struct timespec wg_peer_last_handshake(struct wg_peer *);
+
struct wg_session *wg_peer_hs_session(struct wg_peer *);
struct wg_session *wg_peer_ks_session(struct wg_peer *);
-
-struct wg_session *wg_device_new_session(struct wg_device *);
-struct wg_session *wg_device_ref_session(struct wg_device *, uint32_t);
void wg_session_put(struct wg_session *);
enum wg_error wg_device_rx_initiation(struct wg_device *,