]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
tests for ipv4prefix
authorAlan T. DeKok <aland@freeradius.org>
Thu, 12 Feb 2026 02:30:05 +0000 (21:30 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 12 Feb 2026 02:35:04 +0000 (21:35 -0500)
src/protocols/radius/encode.c
src/tests/unit/protocols/radius/rfc.txt
src/tests/unit/protocols/radius/rfc6572.txt [new file with mode: 0644]

index f9d8ef6346dfc7bbdd0576ea01bff4e53d71ac44..8433c5970d22393b5e14dbc0f63c74ef3a3f9ffb 100644 (file)
@@ -475,7 +475,7 @@ static ssize_t encode_value(fr_dbuff_t *dbuff,
                        /*
                         *      If the ipaddr is all zeros, then the prefix length MUST be set to 32.
                         */
-                       FR_DBUFF_IN_BYTES_RETURN(&value_dbuff, 0x00, 0x20);
+                       FR_DBUFF_IN_BYTES_RETURN(&value_dbuff, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00);
                } else {
                        uint32_t ipaddr = vp->vp_ipv4addr;
 
index 0c5bcccdc29e1a073e07f6fc3b6dbfae490cfb8b..adbb0f0a97431b6fab637ff42428d891119272e0 100644 (file)
@@ -152,46 +152,6 @@ match Framed-IPv6-Prefix = 11:22:33:44:55:66:77:88/128
 pair Framed-IPv6-Prefix = *
 match Framed-IPv6-Prefix = ::/128
 
-pair PMIP6-Home-IPv4-HoA = 127/8
-match PMIP6-Home-IPv4-HoA = 127.0.0.0/8
-
-pair PMIP6-Home-IPv4-HoA = 127/8
-match PMIP6-Home-IPv4-HoA = 127.0.0.0/8
-
-#
-#  Octets outside of the mask are OK, but
-#  are mashed to zero.
-#
-pair PMIP6-Home-IPv4-HoA = 127.63/8
-match PMIP6-Home-IPv4-HoA = 127.0.0.0/8
-
-#
-#  Unless you give a good mask.
-#
-pair PMIP6-Home-IPv4-HoA = 127.63/16
-match PMIP6-Home-IPv4-HoA = 127.63.0.0/16
-
-pair PMIP6-Home-IPv4-HoA = 127.999/16
-match Failed to parse IPv4 prefix string "127.999/16"
-
-pair PMIP6-Home-IPv4-HoA = 127.bob/16
-match Failed to parse IPv4 prefix string "127.bob/16"
-
-pair PMIP6-Home-IPv4-HoA = 127.63/15
-match PMIP6-Home-IPv4-HoA = 127.62.0.0/15
-
-pair PMIP6-Home-IPv4-HoA = 127.63.1/24
-match PMIP6-Home-IPv4-HoA = 127.63.1.0/24
-
-pair PMIP6-Home-IPv4-HoA = 127.63.1.6
-match PMIP6-Home-IPv4-HoA = 127.63.1.6/32
-
-pair PMIP6-Home-IPv4-HoA = 256/8
-match Failed to parse IPv4 prefix string "256/8"
-
-pair PMIP6-Home-IPv4-HoA = bob/8
-match Failed to parse IPv4 prefix string "bob/8"
-
 #
 #  Concatenated messages
 #
@@ -205,4 +165,4 @@ decode-pair -
 match EAP-Message = 0x78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787861
 
 count
-match 73
+match 51
diff --git a/src/tests/unit/protocols/radius/rfc6572.txt b/src/tests/unit/protocols/radius/rfc6572.txt
new file mode 100644 (file)
index 0000000..2fe8d2f
--- /dev/null
@@ -0,0 +1,99 @@
+proto radius
+proto-dictionary radius
+fuzzer-out radius
+
+pair PMIP6-Home-IPv4-HoA = 127/8
+match PMIP6-Home-IPv4-HoA = 127.0.0.0/8
+
+pair PMIP6-Home-IPv4-HoA = 127/8
+match PMIP6-Home-IPv4-HoA = 127.0.0.0/8
+
+#
+#  Invalid inputs
+#
+pair PMIP6-Home-IPv4-HoA = 127.63.1.6
+match PMIP6-Home-IPv4-HoA = 127.63.1.6/32
+
+pair PMIP6-Home-IPv4-HoA = 256/8
+match Failed to parse IPv4 prefix string "256/8"
+
+pair PMIP6-Home-IPv4-HoA = bob/8
+match Failed to parse IPv4 prefix string "bob/8"
+
+#
+#  Octets outside of the mask are OK, but
+#  are mashed to zero.
+#
+pair PMIP6-Home-IPv4-HoA = 127.63/8
+match PMIP6-Home-IPv4-HoA = 127.0.0.0/8
+
+#
+#  Unless you give a good mask.
+#
+pair PMIP6-Home-IPv4-HoA = 127.63/16
+match PMIP6-Home-IPv4-HoA = 127.63.0.0/16
+
+pair PMIP6-Home-IPv4-HoA = 127.999/16
+match Failed to parse IPv4 prefix string "127.999/16"
+
+pair PMIP6-Home-IPv4-HoA = 127.bob/16
+match Failed to parse IPv4 prefix string "127.bob/16"
+
+pair PMIP6-Home-IPv4-HoA = 127.63/15
+match PMIP6-Home-IPv4-HoA = 127.62.0.0/15
+
+pair PMIP6-Home-IPv4-HoA = 127.63.1/24
+match PMIP6-Home-IPv4-HoA = 127.63.1.0/24
+
+encode-pair -
+match 9b 08 00 18 7f 3f 01 00
+
+#
+#  Address is all zeros, then the prefix length MUST be set to 32.
+#
+encode-pair PMIP6-Home-IPv4-HoA = 0.0.0.0/0
+match 9b 08 00 20 00 00 00 00
+
+decode-pair -
+match PMIP6-Home-IPv4-HoA = 0.0.0.0/32
+
+encode-pair PMIP6-Home-IPv4-HoA = 0.0.0.0/32
+match 9b 08 00 20 00 00 00 00
+
+decode-pair -
+match PMIP6-Home-IPv4-HoA = 0.0.0.0/32
+
+encode-pair PMIP6-Home-IPv4-HoA = 127.0.0.1/32
+match 9b 08 00 20 7f 00 00 01
+
+decode-pair -
+match PMIP6-Home-IPv4-HoA = 127.0.0.1/32
+
+encode-pair PMIP6-Home-IPv4-HoA = 127.0.0.1/24
+match 9b 08 00 18 7f 00 00 00
+
+decode-pair -
+match PMIP6-Home-IPv4-HoA = 127.0.0.0/24
+
+#
+#  Extra non-zero bits are ignored
+#
+decode-pair 9b 08 00 18 7f 00 00 ad
+match PMIP6-Home-IPv4-HoA = 127.0.0.0/24
+
+#
+#  Invalid prefixes are raw
+#
+decode-pair 9b 08 00 21 7f 00 00 00
+match raw.PMIP6-Home-IPv4-HoA = 0x00217f000000
+
+#
+#  Reserved field is non-zero.  This is raw
+#
+#  @todo - maybe just discard the reserved field?
+#
+decode-pair 9b 08 01 20 7f 00 00 00
+match raw.PMIP6-Home-IPv4-HoA = 0x01207f000000
+
+count
+match 49