aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-01-09 19:47:29 -0800
committerJason A. Donenfeld <Jason@zx2c4.com>2017-01-10 05:36:43 +0100
commitca3f6fa1dd692fae949f090a14f81d3ef0f424d2 (patch)
tree03b68417877028135c6960bf9b7fc98cc08b1fc8 /src
parenttools: ipc: read from socket incrementally (diff)
downloadwireguard-monolithic-historical-ca3f6fa1dd692fae949f090a14f81d3ef0f424d2.tar.xz
wireguard-monolithic-historical-ca3f6fa1dd692fae949f090a14f81d3ef0f424d2.zip
uapi: use flag instead of C bitfield for portability
Diffstat (limited to '')
-rw-r--r--src/config.c12
-rw-r--r--src/tools/config.c17
-rw-r--r--src/uapi.h31
3 files changed, 32 insertions, 28 deletions
diff --git a/src/config.c b/src/config.c
index c061b2d..6158cc8 100644
--- a/src/config.c
+++ b/src/config.c
@@ -59,7 +59,7 @@ static int set_peer(struct wireguard_device *wg, void __user *user_peer, size_t
peer = pubkey_hashtable_lookup(&wg->peer_hashtable, in_peer.public_key);
if (!peer) { /* Peer doesn't exist yet. Add a new one. */
- if (in_peer.remove_me)
+ if (in_peer.flags & WGPEER_REMOVE_ME)
return -ENODEV; /* Tried to remove a non existing peer. */
peer = peer_rcu_get(peer_create(wg, in_peer.public_key));
if (!peer)
@@ -68,7 +68,7 @@ static int set_peer(struct wireguard_device *wg, void __user *user_peer, size_t
timers_init_peer(peer);
}
- if (in_peer.remove_me) {
+ if (in_peer.flags & WGPEER_REMOVE_ME) {
peer_put(peer);
peer_remove(peer);
goto out;
@@ -83,7 +83,7 @@ static int set_peer(struct wireguard_device *wg, void __user *user_peer, size_t
socket_set_peer_endpoint(peer, &endpoint);
}
- if (in_peer.replace_ipmasks)
+ if (in_peer.flags & WGPEER_REPLACE_IPMASKS)
routing_table_remove_by_peer(&wg->peer_routing_table, peer);
for (i = 0, user_ipmask = user_peer + sizeof(struct wgpeer); i < in_peer.num_ipmasks; ++i, user_ipmask += sizeof(struct wgipmask)) {
ret = set_ipmask(peer, user_ipmask);
@@ -134,10 +134,10 @@ int config_set_device(struct wireguard_device *wg, void __user *user_device)
goto out;
}
- if (in_device.replace_peer_list)
+ if (in_device.flags & WGDEVICE_REPLACE_PEERS)
peer_remove_all(wg);
- if (in_device.remove_private_key) {
+ if (in_device.flags & WGDEVICE_REMOVE_PRIVATE_KEY) {
noise_set_static_identity_private_key(&wg->static_identity, NULL);
modified_static_identity = true;
} else if (memcmp(zeros, in_device.private_key, WG_KEY_LEN)) {
@@ -145,7 +145,7 @@ int config_set_device(struct wireguard_device *wg, void __user *user_device)
modified_static_identity = true;
}
- if (in_device.remove_preshared_key) {
+ if (in_device.flags & WGDEVICE_REMOVE_PRESHARED_KEY) {
noise_set_static_identity_preshared_key(&wg->static_identity, NULL);
modified_static_identity = true;
} else if (memcmp(zeros, in_device.preshared_key, WG_KEY_LEN)) {
diff --git a/src/tools/config.c b/src/tools/config.c
index 50bc97c..f326389 100644
--- a/src/tools/config.c
+++ b/src/tools/config.c
@@ -213,7 +213,7 @@ static inline bool parse_ipmasks(struct inflatable_device *buf, size_t peer_offs
return false;
};
peer = peer_from_offset(buf->dev, peer_offset);
- peer->replace_ipmasks = true;
+ peer->flags |= WGPEER_REPLACE_IPMASKS;
if (!strlen(value)) {
free(mutable);
return true;
@@ -271,7 +271,7 @@ static bool process_line(struct config_ctx *ctx, const char *line)
++ctx->buf.dev->num_peers;
ctx->is_peer_section = true;
ctx->is_device_section = false;
- peer_from_offset(ctx->buf.dev, ctx->peer_offset)->replace_ipmasks = true;
+ peer_from_offset(ctx->buf.dev, ctx->peer_offset)->flags |= WGPEER_REPLACE_IPMASKS;
peer_from_offset(ctx->buf.dev, ctx->peer_offset)->persistent_keepalive_interval = (__u16)-1;
return true;
}
@@ -347,7 +347,8 @@ bool config_read_init(struct config_ctx *ctx, struct wgdevice **device, bool app
perror("calloc");
return false;
}
- ctx->buf.dev->replace_peer_list = !append;
+ if (!append)
+ ctx->buf.dev->flags |= WGDEVICE_REPLACE_PEERS;
return true;
}
@@ -361,11 +362,11 @@ bool config_read_finish(struct config_ctx *ctx)
{
size_t i;
struct wgpeer *peer;
- if (ctx->buf.dev->replace_peer_list && !ctx->buf.dev->num_peers) {
+ if (ctx->buf.dev->flags & WGDEVICE_REPLACE_PEERS && !ctx->buf.dev->num_peers) {
fprintf(stderr, "No peers configured\n");
goto err;
}
- if (ctx->buf.dev->replace_peer_list && !key_is_valid(ctx->buf.dev->private_key)) {
+ if (ctx->buf.dev->flags & WGDEVICE_REPLACE_PEERS && !key_is_valid(ctx->buf.dev->private_key)) {
fprintf(stderr, "No private key configured\n");
goto err;
}
@@ -462,7 +463,7 @@ bool config_read_cmd(struct wgdevice **device, char *argv[], int argc)
}
free(line);
} else if (ret == 1)
- buf.dev->remove_private_key = true;
+ buf.dev->flags |= WGDEVICE_REMOVE_PRIVATE_KEY;
else
goto error;
argv += 2;
@@ -477,7 +478,7 @@ bool config_read_cmd(struct wgdevice **device, char *argv[], int argc)
}
free(line);
} else if (ret == 1)
- buf.dev->remove_preshared_key = true;
+ buf.dev->flags |= WGDEVICE_REMOVE_PRESHARED_KEY;
else
goto error;
argv += 2;
@@ -495,7 +496,7 @@ bool config_read_cmd(struct wgdevice **device, char *argv[], int argc)
argv += 2;
argc -= 2;
} else if (!strcmp(argv[0], "remove") && argc >= 1 && buf.dev->num_peers) {
- peer_from_offset(buf.dev, peer_offset)->remove_me = true;
+ peer_from_offset(buf.dev, peer_offset)->flags |= WGPEER_REMOVE_ME;
argv += 1;
argc -= 1;
} else if (!strcmp(argv[0], "endpoint") && argc >= 2 && buf.dev->num_peers) {
diff --git a/src/uapi.h b/src/uapi.h
index cd4b86b..e5d7368 100644
--- a/src/uapi.h
+++ b/src/uapi.h
@@ -48,13 +48,13 @@
* struct wgipmask
* struct wgpeer { .num_ipmasks = 0 }
*
- * If `wgdevice->replace_peer_list` is true, removes all peers of device before adding new ones.
- * If `wgpeer->remove_me` is true, the peer identified by `wgpeer->public_key` is removed.
- * If `wgpeer->replace_ipmasks` is true, removes all ipmasks before adding new ones.
+ * If `wgdevice->flags & WGDEVICE_REPLACE_PEERS` is true, removes all peers of device before adding new ones.
+ * If `wgpeer->flags & WGPEER_REMOVE_ME` is true, the peer identified by `wgpeer->public_key` is removed.
+ * If `wgpeer->flags & WGPEER_REPLACE_IPMASKS` is true, removes all ipmasks before adding new ones.
* If `wgdevice->private_key` is filled with zeros, no action is taken on the private key.
* If `wgdevice->preshared_key` is filled with zeros, no action is taken on the pre-shared key.
- * If `wgdevice->remove_private_key` is true, the private key is removed.
- * If `wgdevice->remove_preshared_key` is true, the pre-shared key is removed.
+ * If `wgdevice->flags & WGDEVICE_REMOVE_PRIVATE_KEY` is true, the private key is removed.
+ * If `wgdevice->flags & WGDEVICE_REMOVE_PRESHARED_KEY` is true, the pre-shared key is removed.
*
* Returns 0 on success, or -errno if an error occurred.
*/
@@ -97,34 +97,37 @@ struct wgipmask {
__u8 cidr;
};
+enum {
+ WGPEER_REMOVE_ME = (1 << 0),
+ WGPEER_REPLACE_IPMASKS = (1 << 1)
+};
struct wgpeer {
__u8 public_key[WG_KEY_LEN]; /* Get/Set */
+ __u32 flags; /* Set */
struct sockaddr_storage endpoint; /* Get/Set */
struct timeval last_handshake_time; /* Get */
__u64 rx_bytes, tx_bytes; /* Get */
-
- __u32 remove_me : 1; /* Set */
- __u32 replace_ipmasks : 1; /* Set */
+ __u16 persistent_keepalive_interval; /* Get/Set -- 0 = off, 0xffff = unset */
__u16 num_ipmasks; /* Get/Set */
- __u16 persistent_keepalive_interval; /* Get/Set -- 0 = off, 0xffff = unset */
};
+enum {
+ WGDEVICE_REPLACE_PEERS = (1 << 0),
+ WGDEVICE_REMOVE_PRIVATE_KEY = (1 << 1),
+ WGDEVICE_REMOVE_PRESHARED_KEY = (1 << 2)
+};
struct wgdevice {
char interface[IFNAMSIZ]; /* Get */
+ __u32 flags; /* Set */
__u8 public_key[WG_KEY_LEN]; /* Get */
__u8 private_key[WG_KEY_LEN]; /* Get/Set */
__u8 preshared_key[WG_KEY_LEN]; /* Get/Set */
-
__u16 port; /* Get/Set */
- __u32 replace_peer_list : 1; /* Set */
- __u32 remove_private_key : 1; /* Set */
- __u32 remove_preshared_key : 1; /* Set */
-
union {
__u16 num_peers; /* Get/Set */
__u64 peers_size; /* Get */