From b43de5932ba01c8acbcdfc7aebd48b87514f4af2 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Thu, 4 Apr 2019 11:54:42 +0200 Subject: WIP poc0 --- common.h | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'common.h') diff --git a/common.h b/common.h index ca76dc4..c73350e 100644 --- a/common.h +++ b/common.h @@ -19,9 +19,14 @@ #define RECV_BUFSIZE 8192 +#define MAX_RESPONSE_SIZE 8192 + static const char WG_DYNAMIC_ADDR[] = "fe80::"; static const uint16_t WG_DYNAMIC_PORT = 1337; +#define WG_DYNAMIC_LEASETIME 10 /* NOTE: 10s is good for testing purposes */ + +/* TODO: Move client specific items to its own CLIENT_ITEMS */ #define ITEMS \ E(WGKEY_UNKNOWN, "") /* must be the first entry */ \ /* CMD START */ \ @@ -31,7 +36,10 @@ static const uint16_t WG_DYNAMIC_PORT = 1337; E(WGKEY_INCOMPLETE, "") \ E(WGKEY_IPV4, "ipv4") \ E(WGKEY_IPV6, "ipv6") \ - E(WGKEY_LEASETIME, "leasetime") + E(WGKEY_LEASESTART, "leasestart") \ + E(WGKEY_LEASETIME, "leasetime") \ + E(WGKEY_ERRNO, "errno") \ + E(WGKEY_ERRMSG, "errmsg") #define E(x, y) x, enum wg_dynamic_key { ITEMS }; @@ -52,6 +60,8 @@ struct wg_dynamic_request { enum wg_dynamic_key cmd; uint32_t version; wg_key pubkey; + unsigned char *buf; + size_t buflen; struct wg_dynamic_attr *first, *last; }; @@ -64,11 +74,26 @@ struct wg_combined_ip { uint8_t cidr; }; +struct wg_dynamic_lease { + struct wg_combined_ip ip4; + struct wg_combined_ip ip6; + uint32_t start; + uint32_t leasetime; + struct wg_dynamic_lease *next; +}; + #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) void free_wg_dynamic_request(struct wg_dynamic_request *req); bool handle_request(int fd, struct wg_dynamic_request *req, - void (*success)(int, struct wg_dynamic_request *req), - void (*error)(int, int)); - + bool (*success)(int, struct wg_dynamic_request *), + bool (*error)(int, int)); +size_t send_message(int fd, unsigned char *buf, size_t *len); +void send_later(struct wg_dynamic_request *req, unsigned char *const buf, + size_t msglen); +size_t print_to_buf(char *buf, size_t bufsize, size_t len, char *fmt, ...); +uint32_t current_time(); +void close_connection(int *fd, struct wg_dynamic_request *req); +bool is_link_local(unsigned char *addr); +void iface_get_all_addrs(uint8_t family, mnl_cb_t data_cb, void *cb_data); #endif -- cgit v1.2.3-59-g8ed1b