summaryrefslogtreecommitdiffstats
path: root/src/wireguard.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/wireguard.c')
-rw-r--r--src/wireguard.c77
1 files changed, 44 insertions, 33 deletions
diff --git a/src/wireguard.c b/src/wireguard.c
index 5e06dcf77c0..b2f9b63e4f8 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,