aboutsummaryrefslogtreecommitdiffstats
path: root/common.h
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2019-04-04 11:54:42 +0200
committerLinus Nordberg <linus@nordberg.se>2019-04-04 12:09:19 +0200
commitb43de5932ba01c8acbcdfc7aebd48b87514f4af2 (patch)
tree80321048763a71ca43c80988db735588dd41e9e8 /common.h
parentSpecify scope id in addresses to ping6 (diff)
downloadwg-dynamic-b43de5932ba01c8acbcdfc7aebd48b87514f4af2.tar.xz
wg-dynamic-b43de5932ba01c8acbcdfc7aebd48b87514f4af2.zip
WIP poc0
Diffstat (limited to 'common.h')
-rw-r--r--common.h33
1 files changed, 29 insertions, 4 deletions
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