aboutsummaryrefslogtreecommitdiffstats
path: root/common.h
diff options
context:
space:
mode:
Diffstat (limited to 'common.h')
-rw-r--r--common.h35
1 files changed, 30 insertions, 5 deletions
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