diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2017-01-09 19:47:29 -0800 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2017-01-10 05:36:43 +0100 |
commit | 7fcdda0253306475b5abc9318c1cff7022873d69 (patch) | |
tree | 36f92cd60a57ead06a773099c65675fb73577f30 /src | |
parent | 379f198c207afbf7fba71c9fdf2e401e7edcdd3b (diff) |
uapi: use flag instead of C bitfield for portability
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/config.c | 12 | ||||
-rw-r--r-- | src/uapi.h | 31 |
2 files changed, 23 insertions, 20 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)) { @@ -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 */ |