aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile16
-rw-r--r--protocol.capnp20
-rw-r--r--protocol.capnp.c80
-rw-r--r--protocol.capnp.h81
-rw-r--r--protocol.h28
5 files changed, 183 insertions, 42 deletions
diff --git a/Makefile b/Makefile
index 8fd0bbe..eb6372e 100644
--- a/Makefile
+++ b/Makefile
@@ -8,16 +8,24 @@ CFLAGS ?= ${CFLAGS_DEBUG}
LDFLAGS ?= ${LDFLAGS_DEBUG}
.PHONY: clean style
PROGS = wg-dynamic-client wg-dynamic-server
-CLIENT_OBJS = wg-dynamic-client.o
-SERVER_OBJS = wg-dynamic-server.o
+CLIENT_OBJS = wg-dynamic-client.o protocol.capnp.o
+SERVER_OBJS = wg-dynamic-server.o protocol.capnp.o
all: ${PROGS}
-client: ${CLIENT_OBJS}
+wg-dynamic-client: ${CLIENT_OBJS}
${CC} ${LDFLAGS} ${CLIENT_OBJS} -o $@
-server: ${SERVER_OBJS}
+wg-dynamic-server: ${SERVER_OBJS}
${CC} ${LDFLAGS} ${SERVER_OBJS} -o $@
wg-dynamic-client.o: wg-dynamic-client.c
wg-dynamic-server.o: wg-dynamic-server.c
+protocol.capnp.o: protocol.capnp.c
+
+# capnproto
+protocol.capnp.h: protocol.capnp.c
+ ;
+protocol.capnp.c: protocol.capnp
+ capnpc protocol.capnp -oc
+%.capnp: ;
clean:
rm -f ${PROGS} *.o *~
diff --git a/protocol.capnp b/protocol.capnp
index 7450702..64463e9 100644
--- a/protocol.capnp
+++ b/protocol.capnp
@@ -3,22 +3,22 @@
# Copyright (C) 2018 Wireguard LLC
#
-@0xed77208fb3340cc1
+@0xed77208fb3340cc1;
# client request message
-struct wg_client_msg {
- request @0 :wg_client_request_type;
+struct WgClientMsg {
+ request @0 :WgClientRequestType;
- enum wg_client_request_type {
- WG_REQUEST_SIMPLE @0;
+ enum WgClientRequestType {
+ simple @0;
}
}
# server response message
-struct wg_server_simple_msg {
- leased_ipv4 @0 :UInt32; # dynamic IPv4 leased to client
- leased_ipv4_cidr @1 :UInt32; # CIDR of dynamic IPv4 leased to client
- lease_timeout @2 :UInt32; # activity timeout for the IP lease in seconds
+struct WgServerSimpleMsg {
+ leasedIpv4 @0 :UInt32; # dynamic IPv4 leased to client
+ leasedIpv4Cidr @1 :UInt32; # CIDR of dynamic IPv4 leased to client
+ leaseTimeout @2 :UInt32; # activity timeout for the IP lease in seconds
route @3 :UInt32; # route for client
- route @4 :Uint32; # CIDR of route for client
+ routeCidr @4 :UInt32; # CIDR of route for client
}
diff --git a/protocol.capnp.c b/protocol.capnp.c
new file mode 100644
index 0000000..a536f31
--- /dev/null
+++ b/protocol.capnp.c
@@ -0,0 +1,80 @@
+#include "protocol.capnp.h"
+/* AUTO GENERATED - DO NOT EDIT */
+#ifdef __GNUC__
+# define capnp_unused __attribute__((unused))
+# define capnp_use(x) (void) x;
+#else
+# define capnp_unused
+# define capnp_use(x)
+#endif
+
+
+WgClientMsg_ptr new_WgClientMsg(struct capn_segment *s) {
+ WgClientMsg_ptr p;
+ p.p = capn_new_struct(s, 8, 0);
+ return p;
+}
+WgClientMsg_list new_WgClientMsg_list(struct capn_segment *s, int len) {
+ WgClientMsg_list p;
+ p.p = capn_new_list(s, len, 8, 0);
+ return p;
+}
+void read_WgClientMsg(struct WgClientMsg *s capnp_unused, WgClientMsg_ptr p) {
+ capn_resolve(&p.p);
+ capnp_use(s);
+ s->request = (enum WgClientMsg_WgClientRequestType)(int) capn_read16(p.p, 0);
+}
+void write_WgClientMsg(const struct WgClientMsg *s capnp_unused, WgClientMsg_ptr p) {
+ capn_resolve(&p.p);
+ capnp_use(s);
+ capn_write16(p.p, 0, (uint16_t) (s->request));
+}
+void get_WgClientMsg(struct WgClientMsg *s, WgClientMsg_list l, int i) {
+ WgClientMsg_ptr p;
+ p.p = capn_getp(l.p, i, 0);
+ read_WgClientMsg(s, p);
+}
+void set_WgClientMsg(const struct WgClientMsg *s, WgClientMsg_list l, int i) {
+ WgClientMsg_ptr p;
+ p.p = capn_getp(l.p, i, 0);
+ write_WgClientMsg(s, p);
+}
+
+WgServerSimpleMsg_ptr new_WgServerSimpleMsg(struct capn_segment *s) {
+ WgServerSimpleMsg_ptr p;
+ p.p = capn_new_struct(s, 24, 0);
+ return p;
+}
+WgServerSimpleMsg_list new_WgServerSimpleMsg_list(struct capn_segment *s, int len) {
+ WgServerSimpleMsg_list p;
+ p.p = capn_new_list(s, len, 24, 0);
+ return p;
+}
+void read_WgServerSimpleMsg(struct WgServerSimpleMsg *s capnp_unused, WgServerSimpleMsg_ptr p) {
+ capn_resolve(&p.p);
+ capnp_use(s);
+ s->leasedIpv4 = capn_read32(p.p, 0);
+ s->leasedIpv4Cidr = capn_read32(p.p, 4);
+ s->leaseTimeout = capn_read32(p.p, 8);
+ s->route = capn_read32(p.p, 12);
+ s->routeCidr = capn_read32(p.p, 16);
+}
+void write_WgServerSimpleMsg(const struct WgServerSimpleMsg *s capnp_unused, WgServerSimpleMsg_ptr p) {
+ capn_resolve(&p.p);
+ capnp_use(s);
+ capn_write32(p.p, 0, s->leasedIpv4);
+ capn_write32(p.p, 4, s->leasedIpv4Cidr);
+ capn_write32(p.p, 8, s->leaseTimeout);
+ capn_write32(p.p, 12, s->route);
+ capn_write32(p.p, 16, s->routeCidr);
+}
+void get_WgServerSimpleMsg(struct WgServerSimpleMsg *s, WgServerSimpleMsg_list l, int i) {
+ WgServerSimpleMsg_ptr p;
+ p.p = capn_getp(l.p, i, 0);
+ read_WgServerSimpleMsg(s, p);
+}
+void set_WgServerSimpleMsg(const struct WgServerSimpleMsg *s, WgServerSimpleMsg_list l, int i) {
+ WgServerSimpleMsg_ptr p;
+ p.p = capn_getp(l.p, i, 0);
+ write_WgServerSimpleMsg(s, p);
+}
diff --git a/protocol.capnp.h b/protocol.capnp.h
new file mode 100644
index 0000000..ea2f2e2
--- /dev/null
+++ b/protocol.capnp.h
@@ -0,0 +1,81 @@
+#ifndef CAPN_ED77208FB3340CC1
+#define CAPN_ED77208FB3340CC1
+/* AUTO GENERATED - DO NOT EDIT */
+#include <capnp_c.h>
+
+#if CAPN_VERSION != 1
+#error "version mismatch between capnp_c.h and generated code"
+#endif
+
+#ifndef capnp_nowarn
+# ifdef __GNUC__
+# define capnp_nowarn __extension__
+# else
+# define capnp_nowarn
+# endif
+#endif
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct WgClientMsg;
+struct WgServerSimpleMsg;
+
+typedef struct {capn_ptr p;} WgClientMsg_ptr;
+typedef struct {capn_ptr p;} WgServerSimpleMsg_ptr;
+
+typedef struct {capn_ptr p;} WgClientMsg_list;
+typedef struct {capn_ptr p;} WgServerSimpleMsg_list;
+
+enum WgClientMsg_WgClientRequestType {
+ WgClientMsg_WgClientRequestType_simple = 0
+};
+
+struct WgClientMsg {
+ enum WgClientMsg_WgClientRequestType request;
+};
+
+static const size_t WgClientMsg_word_count = 1;
+
+static const size_t WgClientMsg_pointer_count = 0;
+
+static const size_t WgClientMsg_struct_bytes_count = 8;
+
+struct WgServerSimpleMsg {
+ uint32_t leasedIpv4;
+ uint32_t leasedIpv4Cidr;
+ uint32_t leaseTimeout;
+ uint32_t route;
+ uint32_t routeCidr;
+};
+
+static const size_t WgServerSimpleMsg_word_count = 3;
+
+static const size_t WgServerSimpleMsg_pointer_count = 0;
+
+static const size_t WgServerSimpleMsg_struct_bytes_count = 24;
+
+WgClientMsg_ptr new_WgClientMsg(struct capn_segment*);
+WgServerSimpleMsg_ptr new_WgServerSimpleMsg(struct capn_segment*);
+
+WgClientMsg_list new_WgClientMsg_list(struct capn_segment*, int len);
+WgServerSimpleMsg_list new_WgServerSimpleMsg_list(struct capn_segment*, int len);
+
+void read_WgClientMsg(struct WgClientMsg*, WgClientMsg_ptr);
+void read_WgServerSimpleMsg(struct WgServerSimpleMsg*, WgServerSimpleMsg_ptr);
+
+void write_WgClientMsg(const struct WgClientMsg*, WgClientMsg_ptr);
+void write_WgServerSimpleMsg(const struct WgServerSimpleMsg*, WgServerSimpleMsg_ptr);
+
+void get_WgClientMsg(struct WgClientMsg*, WgClientMsg_list, int i);
+void get_WgServerSimpleMsg(struct WgServerSimpleMsg*, WgServerSimpleMsg_list, int i);
+
+void set_WgClientMsg(const struct WgClientMsg*, WgClientMsg_list, int i);
+void set_WgServerSimpleMsg(const struct WgServerSimpleMsg*, WgServerSimpleMsg_list, int i);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/protocol.h b/protocol.h
deleted file mode 100644
index 80b2bd3..0000000
--- a/protocol.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/* SPDX-License-Identifier: MIT */
-/*
- * Copyright (C) 2018 Wireguard LLC
- */
-
-#ifndef PROTOCOL_H
-#define PROTOCOL_H
-
-#include <stdint.h>
-
-/* possible types of requests the client can make */
-enum wg_client_request = { WG_REQUEST_SIMPLE = 0 };
-
-/* client request message */
-struct wg_client_message {
- uint32_t request; /* what type of request to make */
-};
-
-/* server request message */
-struct wg_server_message {
- uint32_t leased_ipv4; /* dynamic IPv4 leased to client */
- uint32_t leased_ipv4_cidr; /* CIDR of dynamic IPv4 leased to client */
- uint32_t lease_timeout; /* activity timeout for the IP lease in seconds */
- uint32_t route; /* route for client */
- uint32_t route_cidr; /* CIDR of route for client */
-};
-
-#endif