]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add tests of ip address / prefix maths
authorNick Porter <nick@portercomputing.co.uk>
Thu, 12 Sep 2024 08:26:34 +0000 (09:26 +0100)
committerNick Porter <nick@portercomputing.co.uk>
Thu, 12 Sep 2024 08:26:34 +0000 (09:26 +0100)
src/tests/keywords/ipv4prefix [new file with mode: 0644]

diff --git a/src/tests/keywords/ipv4prefix b/src/tests/keywords/ipv4prefix
new file mode 100644 (file)
index 0000000..f895cb4
--- /dev/null
@@ -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