1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2022 Felix Fietkau <nbd@nbd.name>
9 #define WG_KEY_LEN_HEX (WG_KEY_LEN * 2 + 1)
19 union network_endpoint
;
24 bool (*check
)(struct network
*net
);
26 int (*init
)(struct network
*net
);
27 void (*cleanup
)(struct network
*net
);
28 int (*init_local
)(struct network
*net
, struct network_peer
*peer
);
29 int (*peer_refresh
)(struct network
*net
);
30 int (*peer_update
)(struct network
*net
, struct network_peer
*peer
,
31 enum wg_update_cmd cmd
);
32 int (*peer_connect
)(struct network
*net
, struct network_peer
*peer
,
33 union network_endpoint
*ep
);
37 const struct wg_ops
*ops
;
40 extern const struct wg_ops wg_user_ops
;
41 extern const struct wg_ops wg_linux_ops
;
43 int wg_init_network(struct network
*net
);
44 void wg_cleanup_network(struct network
*net
);
46 #define wg_init_local(net, ...) (net)->wg.ops->init_local(net, ##__VA_ARGS__)
47 #define wg_peer_update(net, ...) (net)->wg.ops->peer_update(net, ##__VA_ARGS__)
48 #define wg_peer_connect(net, ...) (net)->wg.ops->peer_connect(net, ##__VA_ARGS__)
49 #define wg_peer_refresh(net) (net)->wg.ops->peer_refresh(net)
52 struct network_peer
*wg_peer_update_start(struct network
*net
, const uint8_t *key
);
53 void wg_peer_update_done(struct network
*net
, struct network_peer
*peer
);
54 void wg_peer_set_last_handshake(struct network
*net
, struct network_peer
*peer
,
55 uint64_t now
, uint64_t sec
);
56 void wg_peer_set_rx_bytes(struct network
*net
, struct network_peer
*peer
,
58 void wg_peer_set_endpoint(struct network
*net
, struct network_peer
*peer
,
59 void *data
, size_t len
);