diff options
author | Arnd Bergmann <arnd@arndb.de> | 2018-10-08 11:29:20 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-10-08 19:52:47 +0200 |
commit | 1517e939227b8306fc69604c3ad855efea392545 (patch) | |
tree | 1dc11f59b216e28644f60346c22f0cd1e71af42f /src | |
parent | b3e330d12b0778cb0dc28b7d646c038d8e0b5613 (diff) |
allowedips: swap endianness early on
Otherwise if gcc's optimizer is able to look far in but not overly far
in, we wind up with "warning: 'key' may be used uninitialized in this
function [-Wmaybe-uninitialized]".
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/allowedips.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/allowedips.c b/src/allowedips.c index be0fbab..8699fb1 100644 --- a/src/allowedips.c +++ b/src/allowedips.c @@ -242,17 +242,14 @@ node_placement(struct allowedips_node __rcu *trie, const u8 *key, u8 cidr, return exact; } -static int add(struct allowedips_node __rcu **trie, u8 bits, const u8 *be_key, +static int add(struct allowedips_node __rcu **trie, u8 bits, const u8 *key, u8 cidr, struct wg_peer *peer, struct mutex *lock) { struct allowedips_node *node, *parent, *down, *newnode; - u8 key[16] __aligned(__alignof(u64)); if (unlikely(cidr > bits || !peer)) return -EINVAL; - swap_endian(key, be_key, bits); - if (!rcu_access_pointer(*trie)) { node = kzalloc(sizeof(*node), GFP_KERNEL); if (unlikely(!node)) @@ -336,16 +333,22 @@ int wg_allowedips_insert_v4(struct allowedips *table, const struct in_addr *ip, u8 cidr, struct wg_peer *peer, struct mutex *lock) { + u8 key[4] __aligned(__alignof(u32)); + ++table->seq; - return add(&table->root4, 32, (const u8 *)ip, cidr, peer, lock); + swap_endian(key, (const u8 *)ip, 32); + return add(&table->root4, 32, key, cidr, peer, lock); } int wg_allowedips_insert_v6(struct allowedips *table, const struct in6_addr *ip, u8 cidr, struct wg_peer *peer, struct mutex *lock) { + u8 key[16] __aligned(__alignof(u64)); + ++table->seq; - return add(&table->root6, 128, (const u8 *)ip, cidr, peer, lock); + swap_endian(key, (const u8 *)ip, 128); + return add(&table->root6, 128, key, cidr, peer, lock); } void wg_allowedips_remove_by_peer(struct allowedips *table, |