diff options
Diffstat (limited to 'src/selftest')
-rw-r--r-- | src/selftest/allowedips.h | 60 | ||||
-rw-r--r-- | src/selftest/counter.h | 2 | ||||
-rw-r--r-- | src/selftest/ratelimiter.h | 33 |
3 files changed, 51 insertions, 44 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); diff --git a/src/selftest/counter.h b/src/selftest/counter.h index 2a0e5a5..1b78eb6 100644 --- a/src/selftest/counter.h +++ b/src/selftest/counter.h @@ -4,7 +4,7 @@ */ #ifdef DEBUG -bool __init packet_counter_selftest(void) +bool __init wg_packet_counter_selftest(void) { unsigned int test_num = 0, i; union noise_counter counter; diff --git a/src/selftest/ratelimiter.h b/src/selftest/ratelimiter.h index e0c65ea..cf94407 100644 --- a/src/selftest/ratelimiter.h +++ b/src/selftest/ratelimiter.h @@ -30,7 +30,7 @@ static __init unsigned int maximum_jiffies_at_index(int index) return msecs_to_jiffies(total_msecs); } -bool __init ratelimiter_selftest(void) +bool __init wg_ratelimiter_selftest(void) { int i, test = 0, tries = 0, ret = false; unsigned long loop_start_time; @@ -47,17 +47,17 @@ bool __init ratelimiter_selftest(void) BUILD_BUG_ON(MSEC_PER_SEC % PACKETS_PER_SECOND != 0); - if (ratelimiter_init()) + if (wg_ratelimiter_init()) goto out; ++test; - if (ratelimiter_init()) { - ratelimiter_uninit(); + if (wg_ratelimiter_init()) { + wg_ratelimiter_uninit(); goto out; } ++test; - if (ratelimiter_init()) { - ratelimiter_uninit(); - ratelimiter_uninit(); + if (wg_ratelimiter_init()) { + wg_ratelimiter_uninit(); + wg_ratelimiter_uninit(); goto out; } ++test; @@ -104,13 +104,13 @@ restart: msleep(expected_results[i].msec_to_sleep_before); ensure_time; - if (ratelimiter_allow(skb4, &init_net) != + if (wg_ratelimiter_allow(skb4, &init_net) != expected_results[i].result) goto err; ++test; hdr4->saddr = htonl(ntohl(hdr4->saddr) + i + 1); ensure_time; - if (!ratelimiter_allow(skb4, &init_net)) + if (!wg_ratelimiter_allow(skb4, &init_net)) goto err; ++test; hdr4->saddr = htonl(ntohl(hdr4->saddr) - i - 1); @@ -119,14 +119,14 @@ restart: hdr6->saddr.in6_u.u6_addr32[2] = hdr6->saddr.in6_u.u6_addr32[3] = htonl(i); ensure_time; - if (ratelimiter_allow(skb6, &init_net) != + if (wg_ratelimiter_allow(skb6, &init_net) != expected_results[i].result) goto err; ++test; hdr6->saddr.in6_u.u6_addr32[0] = htonl(ntohl(hdr6->saddr.in6_u.u6_addr32[0]) + i + 1); ensure_time; - if (!ratelimiter_allow(skb6, &init_net)) + if (!wg_ratelimiter_allow(skb6, &init_net)) goto err; ++test; hdr6->saddr.in6_u.u6_addr32[0] = @@ -146,7 +146,8 @@ restart2: for (i = 0; i <= max_entries; ++i) { hdr4->saddr = htonl(i); - if (ratelimiter_allow(skb4, &init_net) != (i != max_entries)) { + if (wg_ratelimiter_allow(skb4, &init_net) != + (i != max_entries)) { if (++tries < 5000) goto restart2; goto err; @@ -162,11 +163,11 @@ err: kfree_skb(skb6); #endif err_nofree: - ratelimiter_uninit(); - ratelimiter_uninit(); - ratelimiter_uninit(); + wg_ratelimiter_uninit(); + wg_ratelimiter_uninit(); + wg_ratelimiter_uninit(); /* Uninit one extra time to check underflow detection. */ - ratelimiter_uninit(); + wg_ratelimiter_uninit(); out: if (ret) pr_info("ratelimiter self-tests: pass\n"); |