diff options
author | Jonathan Neuschäfer <j.neuschaefer@gmx.net> | 2018-05-14 16:13:22 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-14 18:01:59 +0200 |
commit | f432bb00cc1c36ff946021e17551d6ddca88b7b1 (patch) | |
tree | 3a6aeffb5305fc643a16b1aee44836e021900bed /src | |
parent | 761f7a06e204d1fb02598f2b2ece32c27d498355 (diff) |
allowedips: Fix graphviz output after endianness patch
Commit 5e3532e ("allowedips: use native endian on lookup") did two
things: It changed the endianness of (struct allowedips_node).bits to
native endian, and it moved the CIDR masking to the output code path
(walk_by_peer).
Adjust print_node in src/selftest/allowedips.h to deal with these
changes.
Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/selftest/allowedips.h | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/selftest/allowedips.h b/src/selftest/allowedips.h index 5ad7612..1cf8c8f 100644 --- a/src/selftest/allowedips.h +++ b/src/selftest/allowedips.h @@ -7,12 +7,22 @@ #ifdef DEBUG_PRINT_TRIE_GRAPHVIZ #include <linux/siphash.h> + +static __init void swap_endian_and_apply_cidr(u8 *dst, const u8 *src, u8 bits, u8 cidr) +{ + swap_endian(dst, src, bits); + memset(dst + (cidr + 7) / 8, 0, bits / 8 - (cidr + 7) / 8); + if (cidr) + dst[(cidr + 7) / 8 - 1] &= ~0U << ((8 - (cidr % 8)) % 8); +} + static __init void print_node(struct allowedips_node *node, u8 bits) { u32 color = 0; char *style = "dotted"; char *fmt_connection = KERN_DEBUG "\t\"%p/%d\" -> \"%p/%d\";\n"; char *fmt_declaration = KERN_DEBUG "\t\"%p/%d\"[style=%s, color=\"#%06x\"];\n"; + u8 ip1[16], ip2[16]; if (bits == 32) { fmt_connection = KERN_DEBUG "\t\"%pI4/%d\" -> \"%pI4/%d\";\n"; fmt_declaration = KERN_DEBUG "\t\"%pI4/%d\"[style=%s, color=\"#%06x\"];\n"; @@ -26,13 +36,16 @@ static __init void print_node(struct allowedips_node *node, u8 bits) color = hsiphash_1u32(0xdeadbeef, &key) % 200 << 16 | hsiphash_1u32(0xbabecafe, &key) % 200 << 8 | hsiphash_1u32(0xabad1dea, &key) % 200; style = "bold"; } - printk(fmt_declaration, node->bits, node->cidr, style, color); + swap_endian_and_apply_cidr(ip1, node->bits, bits, node->cidr); + printk(fmt_declaration, ip1, node->cidr, style, color); if (node->bit[0]) { - printk(fmt_connection, node->bits, node->cidr, node->bit[0]->bits, node->bit[0]->cidr); + swap_endian_and_apply_cidr(ip2, node->bit[0]->bits, bits, node->cidr); + printk(fmt_connection, ip1, node->cidr, ip2, node->bit[0]->cidr); print_node(node->bit[0], bits); } if (node->bit[1]) { - printk(fmt_connection, node->bits, node->cidr, node->bit[1]->bits, node->bit[1]->cidr); + swap_endian_and_apply_cidr(ip2, node->bit[1]->bits, bits, node->cidr); + printk(fmt_connection, ip1, node->cidr, ip2, node->bit[1]->cidr); print_node(node->bit[1], bits); } } |