summaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2016-11-07 23:28:01 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2016-11-07 23:28:01 +0100
commitaf99fb525b41d945dc2e5b87c791a5a9a80931cc (patch)
treee968f8f4361b6744a34ff5c0c69da3cbe93df2fa /src
parentselftest: add routing table tests for small subnets (diff)
downloadwireguard-monolithic-historical-af99fb525b41d945dc2e5b87c791a5a9a80931cc.tar.xz
wireguard-monolithic-historical-af99fb525b41d945dc2e5b87c791a5a9a80931cc.zip
routing-table: mask self for better IP display
Diffstat (limited to 'src')
-rw-r--r--src/routingtable.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/routingtable.c b/src/routingtable.c
index fcdca71..af71631 100644
--- a/src/routingtable.c
+++ b/src/routingtable.c
@@ -215,7 +215,9 @@ static int add(struct routing_table_node __rcu **trie, uint8_t bits, const uint8
if (!node)
return -ENOMEM;
node->peer = peer;
- memcpy(node->bits, key, (bits + 7) / 8);
+ memcpy(node->bits, key, (cidr + 7) / 8);
+ /* Not strictly neccessary for the data structure, but helps keep the data cleaner: */
+ node->bits[(cidr + 7) / 8 - 1] &= 0xff << ((8 - (cidr % 8)) % 8);
assign_cidr(node, cidr);
rcu_assign_pointer(*trie, node);
return 0;
@@ -231,7 +233,9 @@ static int add(struct routing_table_node __rcu **trie, uint8_t bits, const uint8
if (!newnode)
return -ENOMEM;
newnode->peer = peer;
- memcpy(newnode->bits, key, (bits + 7) / 8);
+ memcpy(newnode->bits, key, (cidr + 7) / 8);
+ /* Not strictly neccessary for the data structure, but helps keep the data cleaner: */
+ newnode->bits[(cidr + 7) / 8 - 1] &= 0xff << ((8 - (cidr % 8)) % 8);
assign_cidr(newnode, cidr);
if (!node)