aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/selftest/allowedips.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/selftest/allowedips.h')
-rw-r--r--src/selftest/allowedips.h60
1 files changed, 33 insertions, 27 deletions
diff --git a/src/selftest/allowedips.h b/src/selftest/allowedips.h
index ca5f256..95f247e 100644
--- a/src/selftest/allowedips.h
+++ b/src/selftest/allowedips.h
@@ -176,7 +176,8 @@ static __init int
horrible_allowedips_insert_v4(struct horrible_allowedips *table,
struct in_addr *ip, uint8_t cidr, void *value)
{
- struct horrible_allowedips_node *node = kzalloc(sizeof(*node), GFP_KERNEL);
+ struct horrible_allowedips_node *node = kzalloc(sizeof(*node),
+ GFP_KERNEL);
if (unlikely(!node))
return -ENOMEM;
@@ -192,7 +193,8 @@ static __init int
horrible_allowedips_insert_v6(struct horrible_allowedips *table,
struct in6_addr *ip, uint8_t cidr, void *value)
{
- struct horrible_allowedips_node *node = kzalloc(sizeof(*node), GFP_KERNEL);
+ struct horrible_allowedips_node *node = kzalloc(sizeof(*node),
+ GFP_KERNEL);
if (unlikely(!node))
return -ENOMEM;
@@ -251,7 +253,7 @@ static __init bool randomized_test(void)
mutex_init(&mutex);
- allowedips_init(&t);
+ wg_allowedips_init(&t);
horrible_allowedips_init(&h);
peers = kcalloc(NUM_PEERS, sizeof(*peers), GFP_KERNEL);
@@ -274,8 +276,8 @@ static __init bool randomized_test(void)
prandom_bytes(ip, 4);
cidr = prandom_u32_max(32) + 1;
peer = peers[prandom_u32_max(NUM_PEERS)];
- if (allowedips_insert_v4(&t, (struct in_addr *)ip, cidr, peer,
- &mutex) < 0) {
+ if (wg_allowedips_insert_v4(&t, (struct in_addr *)ip, cidr,
+ peer, &mutex) < 0) {
pr_info("allowedips random self-test: out of memory\n");
goto free;
}
@@ -300,8 +302,9 @@ static __init bool randomized_test(void)
prandom_u32_max(256));
cidr = prandom_u32_max(32) + 1;
peer = peers[prandom_u32_max(NUM_PEERS)];
- if (allowedips_insert_v4(&t, (struct in_addr *)mutated,
- cidr, peer, &mutex) < 0) {
+ if (wg_allowedips_insert_v4(&t,
+ (struct in_addr *)mutated,
+ cidr, peer, &mutex) < 0) {
pr_info("allowedips random self-test: out of memory\n");
goto free;
}
@@ -317,8 +320,8 @@ static __init bool randomized_test(void)
prandom_bytes(ip, 16);
cidr = prandom_u32_max(128) + 1;
peer = peers[prandom_u32_max(NUM_PEERS)];
- if (allowedips_insert_v6(&t, (struct in6_addr *)ip, cidr, peer,
- &mutex) < 0) {
+ if (wg_allowedips_insert_v6(&t, (struct in6_addr *)ip, cidr,
+ peer, &mutex) < 0) {
pr_info("allowedips random self-test: out of memory\n");
goto free;
}
@@ -343,8 +346,9 @@ static __init bool randomized_test(void)
prandom_u32_max(256));
cidr = prandom_u32_max(128) + 1;
peer = peers[prandom_u32_max(NUM_PEERS)];
- if (allowedips_insert_v6(&t, (struct in6_addr *)mutated,
- cidr, peer, &mutex) < 0) {
+ if (wg_allowedips_insert_v6(&t,
+ (struct in6_addr *)mutated,
+ cidr, peer, &mutex) < 0) {
pr_info("allowedips random self-test: out of memory\n");
goto free;
}
@@ -385,7 +389,7 @@ static __init bool randomized_test(void)
free:
mutex_lock(&mutex);
- allowedips_free(&t, &mutex);
+ wg_allowedips_free(&t, &mutex);
mutex_unlock(&mutex);
horrible_allowedips_free(&h);
if (peers) {
@@ -462,9 +466,9 @@ static __init int walk_callback(void *ctx, const u8 *ip, u8 cidr, int family)
kref_init(&name->refcount); \
} while (0)
-#define insert(version, mem, ipa, ipb, ipc, ipd, cidr) \
- allowedips_insert_v##version(&t, ip##version(ipa, ipb, ipc, ipd), \
- cidr, mem, &mutex)
+#define insert(version, mem, ipa, ipb, ipc, ipd, cidr) \
+ wg_allowedips_insert_v##version(&t, ip##version(ipa, ipb, ipc, ipd), \
+ cidr, mem, &mutex)
#define maybe_fail() do { \
++i; \
@@ -491,7 +495,7 @@ static __init int walk_callback(void *ctx, const u8 *ip, u8 cidr, int family)
maybe_fail(); \
} while (0)
-bool __init allowedips_selftest(void)
+bool __init wg_allowedips_selftest(void)
{
struct wireguard_peer *a = NULL, *b = NULL, *c = NULL, *d = NULL,
*e = NULL, *f = NULL, *g = NULL, *h = NULL;
@@ -513,7 +517,7 @@ bool __init allowedips_selftest(void)
mutex_init(&mutex);
mutex_lock(&mutex);
- allowedips_init(&t);
+ wg_allowedips_init(&t);
init_peer(a);
init_peer(b);
init_peer(c);
@@ -592,37 +596,39 @@ bool __init allowedips_selftest(void)
insert(4, a, 128, 0, 0, 0, 32);
insert(4, a, 192, 0, 0, 0, 32);
insert(4, a, 255, 0, 0, 0, 32);
- allowedips_remove_by_peer(&t, a, &mutex);
+ wg_allowedips_remove_by_peer(&t, a, &mutex);
test_negative(4, a, 1, 0, 0, 0);
test_negative(4, a, 64, 0, 0, 0);
test_negative(4, a, 128, 0, 0, 0);
test_negative(4, a, 192, 0, 0, 0);
test_negative(4, a, 255, 0, 0, 0);
- allowedips_free(&t, &mutex);
- allowedips_init(&t);
+ wg_allowedips_free(&t, &mutex);
+ wg_allowedips_init(&t);
insert(4, a, 192, 168, 0, 0, 16);
insert(4, a, 192, 168, 0, 0, 24);
- allowedips_remove_by_peer(&t, a, &mutex);
+ wg_allowedips_remove_by_peer(&t, a, &mutex);
test_negative(4, a, 192, 168, 0, 1);
- /* These will hit the WARN_ON(len >= 128) in free_node if something goes wrong. */
+ /* These will hit the WARN_ON(len >= 128) in free_node if something
+ * goes wrong.
+ */
for (i = 0; i < 128; ++i) {
part = cpu_to_be64(~(1LLU << (i % 64)));
memset(&ip, 0xff, 16);
memcpy((u8 *)&ip + (i < 64) * 8, &part, 8);
- allowedips_insert_v6(&t, &ip, 128, a, &mutex);
+ wg_allowedips_insert_v6(&t, &ip, 128, a, &mutex);
}
- allowedips_free(&t, &mutex);
+ wg_allowedips_free(&t, &mutex);
- allowedips_init(&t);
+ wg_allowedips_init(&t);
insert(4, a, 192, 95, 5, 93, 27);
insert(6, a, 0x26075300, 0x60006b00, 0, 0xc05f0543, 128);
insert(4, a, 10, 1, 0, 20, 29);
insert(6, a, 0x26075300, 0x6d8a6bf8, 0xdab1f1df, 0xc05f1523, 83);
insert(6, a, 0x26075300, 0x6d8a6bf8, 0xdab1f1df, 0xc05f1523, 21);
- allowedips_walk_by_peer(&t, cursor, a, walk_callback, &wctx, &mutex);
+ wg_allowedips_walk_by_peer(&t, cursor, a, walk_callback, &wctx, &mutex);
test_boolean(wctx.count == 5);
test_boolean(wctx.found_a);
test_boolean(wctx.found_b);
@@ -640,7 +646,7 @@ bool __init allowedips_selftest(void)
pr_info("allowedips self-tests: pass\n");
free:
- allowedips_free(&t, &mutex);
+ wg_allowedips_free(&t, &mutex);
kfree(a);
kfree(b);
kfree(c);