From: Alan T. DeKok Date: Tue, 25 Feb 2025 21:57:49 +0000 (-0500) Subject: tweak encode IP prefix X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7fc7a8688875703c5217fc7e07c011c26f0aff14;p=thirdparty%2Ffreeradius-server.git tweak encode IP prefix --- diff --git a/src/protocols/der/encode.c b/src/protocols/der/encode.c index 4c9152cfb9..409c3a9ed5 100644 --- a/src/protocols/der/encode.c +++ b/src/protocols/der/encode.c @@ -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; diff --git a/src/tests/unit/protocols/der/base.txt b/src/tests/unit/protocols/der/base.txt index 7c1cf91c93..0572ec9a58 100644 --- a/src/tests/unit/protocols/der/base.txt +++ b/src/tests/unit/protocols/der/base.txt @@ -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