From ee78b99c316cff324a40c6b000d23132e44a8dc6 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Mon, 8 Apr 2019 21:57:30 +0200 Subject: Implement faked allocations, server side Reject clients not connecting from an IPv6 address. Reject clients not connecting from the correct port. Fake address allocation. Update allowed-ips with leases handed out. Send response messages. Extend protocol to include lease start and lease time, errno and errmsg. Move common code to common.[ch]. --- common.h | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'common.h') diff --git a/common.h b/common.h index ca76dc4..7c0c0e9 100644 --- a/common.h +++ b/common.h @@ -19,8 +19,12 @@ #define RECV_BUFSIZE 8192 +#define MAX_RESPONSE_SIZE 8192 + static const char WG_DYNAMIC_ADDR[] = "fe80::"; -static const uint16_t WG_DYNAMIC_PORT = 1337; +static const uint16_t WG_DYNAMIC_PORT = 970; /* ASCII sum of "wireguard" */ + +#define WG_DYNAMIC_LEASETIME 10 /* NOTE: 10s is good for testing purposes */ #define ITEMS \ E(WGKEY_UNKNOWN, "") /* must be the first entry */ \ @@ -31,7 +35,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 +59,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 +73,27 @@ 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); +int 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); +int data_attr_cb(const struct nlattr *attr, void *data); #endif -- cgit v1.2.3-59-g8ed1b