aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/allowedips.c
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2018-10-08 11:29:20 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-10-08 19:52:47 +0200
commit8bde328780f0485d69cc95ef04c78fa5d1d613c0 (patch)
tree7253cfcf6605a22c0bcfc917d21255fb9230c1b8 /src/allowedips.c
parenttimers: avoid using control statements in macro (diff)
downloadwireguard-monolithic-historical-8bde328780f0485d69cc95ef04c78fa5d1d613c0.tar.xz
wireguard-monolithic-historical-8bde328780f0485d69cc95ef04c78fa5d1d613c0.zip
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>
Diffstat (limited to 'src/allowedips.c')
-rw-r--r--src/allowedips.c15
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,