]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
tweak encode IP prefix
authorAlan T. DeKok <aland@freeradius.org>
Tue, 25 Feb 2025 21:57:49 +0000 (16:57 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 25 Feb 2025 21:57:49 +0000 (16:57 -0500)
src/protocols/der/encode.c
src/tests/unit/protocols/der/base.txt

index 4c9152cfb9c7ae4c138efaa529febe6b00b1fadd..409c3a9ed561f621c7f14cd3327d4683a3d126b9 100644 (file)
@@ -414,6 +414,12 @@ static ssize_t fr_der_encode_ipv4_prefix(fr_dbuff_t *dbuff, fr_dcursor_t *cursor
         *      octets" that contain the octets of the bit string.  (For IP
         *      addresses, the encoding of the length will be just the length.)
         */
+       if (vp->vp_ip.prefix == 32) {
+               FR_DBUFF_IN_RETURN(&our_dbuff, (uint8_t) 0x00);
+               FR_DBUFF_IN_MEMCPY_RETURN(&our_dbuff, (uint8_t const *) &vp->vp_ipv4addr, sizeof(vp->vp_ipv4addr));
+               return fr_dbuff_set(dbuff, &our_dbuff);
+       }
+
        FR_DBUFF_IN_RETURN(&our_dbuff, (uint8_t) (8 - (vp->vp_ip.prefix & 0x07)));
 
        len = (vp->vp_ip.prefix + 0x07) >> 3;
@@ -479,6 +485,12 @@ static ssize_t fr_der_encode_ipv6_prefix(fr_dbuff_t *dbuff, fr_dcursor_t *cursor
         *      addresses, the encoding of the length will be just the length.)
         */
 
+       if (vp->vp_ip.prefix == 128) {
+               FR_DBUFF_IN_RETURN(&our_dbuff, (uint8_t) 0x00);
+               FR_DBUFF_IN_MEMCPY_RETURN(&our_dbuff, (uint8_t const *) &vp->vp_ipv6addr, sizeof(vp->vp_ipv6addr));
+               return fr_dbuff_set(dbuff, &our_dbuff);
+       }
+
        FR_DBUFF_IN_RETURN(&our_dbuff, (uint8_t) (8 - (vp->vp_ip.prefix & 0x07)));
 
        len = (vp->vp_ip.prefix + 0x07) >> 3;
index 7c1cf91c93fb306fb15b8c59f4be82350d544f9c..0572ec9a58a771acf1ef7a4f6e020d60f0bbb5f1 100644 (file)
@@ -889,6 +889,9 @@ proto-dictionary der
 encode-pair Test-IPv4-Prefix = 10.5.0.0/23
 match 03 04 01 0a 05 00
 
+encode-pair Test-IPv4-Prefix = 10.5.0.4/32
+match 03 05 00 0a 05 00 04
+
 #
 #  Just the length byte
 #
@@ -900,8 +903,11 @@ proto-dictionary-root Test-IPv4-Prefix
 decode-pair 03 04 01 0a 05 00
 match Test-IPv4-Prefix = 10.5.0.0/23
 
+decode-pair 03 05 00 0a 05 00 04
+match Test-IPv4-Prefix = 10.5.0.4/32
+
 decode-pair 03 01 00
 match Test-IPv4-Prefix = 0.0.0.0/0
 
 count
-match 545
+match 549