-
Notifications
You must be signed in to change notification settings - Fork 1
/
wg.h
61 lines (49 loc) · 1.79 KB
/
wg.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2022 Felix Fietkau <[email protected]>
*/
#ifndef __UNETD_WG_H
#define __UNETD_WG_H
#define WG_KEY_LEN 32
#define WG_KEY_LEN_HEX (WG_KEY_LEN * 2 + 1)
enum wg_update_cmd {
WG_PEER_CREATE,
WG_PEER_UPDATE,
WG_PEER_DELETE,
};
struct network;
struct network_peer;
union network_endpoint;
struct wg_ops {
const char *name;
bool (*check)(struct network *net);
int (*init)(struct network *net);
void (*cleanup)(struct network *net);
int (*init_local)(struct network *net, struct network_peer *peer);
int (*peer_refresh)(struct network *net);
int (*peer_update)(struct network *net, struct network_peer *peer,
enum wg_update_cmd cmd);
int (*peer_connect)(struct network *net, struct network_peer *peer,
union network_endpoint *ep);
};
struct wg {
const struct wg_ops *ops;
};
extern const struct wg_ops wg_user_ops;
extern const struct wg_ops wg_linux_ops;
int wg_init_network(struct network *net);
void wg_cleanup_network(struct network *net);
#define wg_init_local(net, ...) (net)->wg.ops->init_local(net, ##__VA_ARGS__)
#define wg_peer_update(net, ...) (net)->wg.ops->peer_update(net, ##__VA_ARGS__)
#define wg_peer_connect(net, ...) (net)->wg.ops->peer_connect(net, ##__VA_ARGS__)
#define wg_peer_refresh(net) (net)->wg.ops->peer_refresh(net)
/* internal */
struct network_peer *wg_peer_update_start(struct network *net, const uint8_t *key);
void wg_peer_update_done(struct network *net, struct network_peer *peer);
void wg_peer_set_last_handshake(struct network *net, struct network_peer *peer,
uint64_t now, uint64_t sec);
void wg_peer_set_rx_bytes(struct network *net, struct network_peer *peer,
uint64_t bytes);
void wg_peer_set_endpoint(struct network *net, struct network_peer *peer,
void *data, size_t len);
#endif