summaryrefslogtreecommitdiffstats
path: root/src/wireguard.h
diff options
context:
space:
mode:
authorMatt Dunwoodie <ncon@mail.noconroy.net>2019-04-30 22:59:11 +1000
committerMatt Dunwoodie <ncon@mail.noconroy.net>2019-05-01 01:42:04 +1000
commitb76f66bc301e9ac96d6f206289de346c008ffb54 (patch)
tree87f3b473a2f6617319980ac272428b79efe88170 /src/wireguard.h
parentRemove unecessary references to p_local_cookie (diff)
downloadwireguard-openbsd-b76f66bc301e9ac96d6f206289de346c008ffb54.tar.xz
wireguard-openbsd-b76f66bc301e9ac96d6f206289de346c008ffb54.zip
Allow wireguard.h to reply initiation with cookie
Due to the design prior, it was not easy to send a cookie message in reply to an initiation. This is because the cookie value was stored in the peer (wg_peer) struct and could not be retrieved until the pubkey was decrypted in the initiation packet, defeating the purpose of the cookie. The biggest change this required was merging wg_upcall and wg_peer_lookup structs into one, as well as removing the plain wg_peer_rx and replace it with wg_peer_rx_lookup. This is to simplify the interface, and comes at no cost. A p2p device can still limit itself to one peer.
Diffstat (limited to 'src/wireguard.h')
-rw-r--r--src/wireguard.h32
1 files changed, 12 insertions, 20 deletions
diff --git a/src/wireguard.h b/src/wireguard.h
index 2e5da94ac11..3935a1a2e6e 100644
--- a/src/wireguard.h
+++ b/src/wireguard.h
@@ -37,7 +37,6 @@ enum wg_key_type {
enum wg_handshake_state {
WG_HS_UNINITIALISED,
- WG_HS_INITIALISED,
WG_HS_RECV_INITIATION,
WG_HS_RECV_RESPONSE,
WG_HS_SENT_INITIATION,
@@ -114,23 +113,17 @@ struct wg_peer {
extern void (*const wg_task_fn[WG_TASK_NUM])(struct wg_peer *, struct mbuf_list *);
-/* Upcall is a struct to store callbacks for wireguard
- * - register_id: associate peer to id
- * - run_task_in:
- */
+/* Upcall is a struct to store callbacks for wireguard */
struct wg_upcall {
- void (*register_id)(struct wg_peer *, u_int32_t, bool);
- void (*run_task_in)(struct wg_peer *, enum wg_task, struct timespec *);
- u_int8_t *(*get_cookie)(struct wg_peer *, struct mbuf *);
-};
-
-struct wg_peer_lookup {
- void *plu_arg;
- u_int8_t *(*plu_localpubkey)(void *);
- u_int8_t *(*plu_localprivkey)(void *);
- u_int8_t *(*plu_cookie)(void *, struct mbuf *);
- struct wg_peer *(*plu_peerkey)(void *, u_int8_t [WG_KEY_SIZE]);
- struct wg_peer *(*plu_id)(void *, u_int32_t);
+ void (*uc_register_id)(struct wg_peer *, u_int32_t, bool);
+ void (*uc_run_task_in)(struct wg_peer *, enum wg_task, struct timespec *);
+
+ void *uc_arg;
+ u_int8_t *(*uc_getpubkey)(void *);
+ u_int8_t *(*uc_getprivkey)(void *);
+ u_int8_t *(*uc_getcookie)(void *, struct mbuf *);
+ struct wg_peer *(*uc_lookupkey)(void *, u_int8_t [WG_KEY_SIZE]);
+ struct wg_peer *(*uc_lookupid)(void *, u_int32_t);
};
/* Create and destroy a peer, upcall must live at least as long as the peer */
@@ -144,9 +137,8 @@ void wg_peer_get_key(struct wg_peer *, const enum wg_key_type, u_int8_t [WG_KEY_
void wg_peer_get_state(struct wg_peer *, struct timespec *, enum wg_role *);
/* For when a transport packet needs to be sent, or a packet arrives */
-bool wg_peer_tx(struct wg_peer *, struct mbuf *, struct mbuf_list *);
-bool wg_peer_rx(struct wg_peer *, struct mbuf *, struct mbuf_list *, struct mbuf_list *);
-struct wg_peer * wg_peer_rx_lookup(struct wg_peer_lookup *, struct mbuf *, struct mbuf_list *, struct mbuf_list *);
+void wg_peer_tx(struct wg_peer *, struct mbuf *, struct mbuf_list *);
+struct wg_peer *wg_peer_rx(struct wg_upcall *, struct mbuf *, struct mbuf_list *, struct mbuf_list *);
/* Misc functions */
void wg_util_key_generate(u_int8_t pubkey[WG_KEY_SIZE], u_int8_t privkey[WG_KEY_SIZE]);