From: Nick Porter Date: Thu, 12 Sep 2024 08:26:34 +0000 (+0100) Subject: Add tests of ip address / prefix maths X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d1c60079af34c174aef375deed33600f54fb2b83;p=thirdparty%2Ffreeradius-server.git Add tests of ip address / prefix maths --- diff --git a/src/tests/keywords/ipv4prefix b/src/tests/keywords/ipv4prefix new file mode 100644 index 00000000000..f895cb41fc1 --- /dev/null +++ b/src/tests/keywords/ipv4prefix @@ -0,0 +1,33 @@ +# +# PRE: if +# +ipaddr test_addr +ipv4prefix test_prefix + +test_addr := 192.168.10.25 + +# Address & mask -> prefix +test_prefix := test_addr & (uint32)0xffffff00 +if !(test_prefix == 192.168.10.0/24) { + test_fail +} + +# Prefix + offset -> address +test_addr := test_prefix + 23 +if !(test_addr == 192.168.10.23) { + test_fail +} + +# Check we can get the hightest address +test_addr := test_prefix + 255 +if !(test_addr == 192.168.10.255) { + test_fail +} + +# Check we can't assign outside the subnet +test_addr := test_prefix + 256 +if (test_addr) { + test_fail +} + +success