From 48f7c3522ad47876c481dd39f4fd8f4547dd922b Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 9 Jan 2017 19:47:29 -0800 Subject: [PATCH] uapi: use flag instead of C bitfield for portability Signed-off-by: Jason A. Donenfeld --- src/config.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/config.c b/src/config.c index 50bc97c..f326389 100644 --- a/src/config.c +++ b/src/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) {