diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-11-07 23:28:01 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-11-07 23:28:01 +0100 |
commit | 66d2934004f39527c77c09a0ab09bc91f0310891 (patch) | |
tree | d189564efb3a615e153efc2c7e2ae580d6d2d78f /src | |
parent | aee74552baf256d5531519a861a8ddfd9e2cd44a (diff) |
routing-table: mask self for better IP display
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/routingtable.c | 8 |
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) |