From: Alan T. DeKok Date: Fri, 18 Mar 2022 00:05:49 +0000 (-0400) Subject: one more stupid format for IPv4 prefixes X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4c531e34d69878982cdeeda54d82a4e200277019;p=thirdparty%2Ffreeradius-server.git one more stupid format for IPv4 prefixes --- diff --git a/share/dictionary/dhcpv4/dictionary b/share/dictionary/dhcpv4/dictionary index f60b711ad4b..3b50828e7fa 100644 --- a/share/dictionary/dhcpv4/dictionary +++ b/share/dictionary/dhcpv4/dictionary @@ -24,6 +24,7 @@ $INCLUDE dictionary.freeradius.internal # Fixme should be broken out into separate RFCs $INCLUDE dictionary.rfc2131 $INCLUDE dictionary.rfc2610 +$INCLUDE dictionary.rfc3442 $INCLUDE dictionary.rfc4280 $INCLUDE dictionary.rfc4578 $INCLUDE dictionary.rfc4776 diff --git a/share/dictionary/dhcpv4/dictionary.rfc2131 b/share/dictionary/dhcpv4/dictionary.rfc2131 index 450bdfd1991..670fdf860cd 100644 --- a/share/dictionary/dhcpv4/dictionary.rfc2131 +++ b/share/dictionary/dhcpv4/dictionary.rfc2131 @@ -212,8 +212,7 @@ ATTRIBUTE Subnet-Selection-Option 118 ipaddr ATTRIBUTE Domain-Search 119 octets # really compressed, concatenated, dns_label array # SIP-Servers DHCP Option ATTRIBUTE SIP-Servers-Option 120 octets -# Classless Static Route Option -ATTRIBUTE Classless-Static-Route 121 octets + # CableLabs Client Configuration ATTRIBUTE CCC 122 octets # 16 GeoConf Option diff --git a/share/dictionary/dhcpv4/dictionary.rfc3442 b/share/dictionary/dhcpv4/dictionary.rfc3442 new file mode 100644 index 00000000000..38057a74c5b --- /dev/null +++ b/share/dictionary/dhcpv4/dictionary.rfc3442 @@ -0,0 +1,17 @@ +# -*- text -*- +# Copyright (C) 2022 The FreeRADIUS Server project and contributors +# This work is licensed under CC-BY version 4.0 https://creativecommons.org/licenses/by/4.0 +# Version $Id$ +############################################################################## +# +# RFC3442 - The Classless Static Route Option for DHCPv4 +# +# $Id$ +# +############################################################################## + +ATTRIBUTE Classless-Static-Route 121 struct +MEMBER Destination-Descriptor struct array +MEMBER Subnet ipv4prefix prefix=bits +MEMBER Router-IP-Address ipv4addr + diff --git a/src/protocols/dhcpv4/decode.c b/src/protocols/dhcpv4/decode.c index 8721647bb13..f894e882f8b 100644 --- a/src/protocols/dhcpv4/decode.c +++ b/src/protocols/dhcpv4/decode.c @@ -211,6 +211,51 @@ static ssize_t decode_value(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t vp->vp_ipv4addr = htonl(ipaddr & mask); break; } + + if (da_is_bits_prefix(vp->da)) { + uint32_t ipaddr, mask; + + if ((data_len == 0) || (*p > 32)) goto raw; + + if (exact && (data_len > 5)) goto raw; + + vp->vp_ip.prefix = *p; + + if (*p > 24) { + if (data_len < 5) goto raw; + ipaddr = fr_net_to_uint32(p + 1); + p += 5; + + } else if (*p > 16) { + if (data_len < 4) goto raw; + ipaddr = fr_net_to_uint24(p + 1); + ipaddr <<= 8; + p += 4; + + } else if (*p > 8) { + if (data_len < 3) goto raw; + ipaddr = fr_net_to_uint16(p + 1); + ipaddr <<= 16; + p += 3; + + } else if (*p > 0) { + if (data_len < 2) goto raw; + ipaddr = p[1]; + ipaddr <<= 24; + p += 2; + + } else { + p++; + ipaddr = 0; + } + + mask = ~(uint32_t) 0; + mask <<= (32 - vp->vp_ip.prefix); + + vp->vp_ipv4addr = htonl(ipaddr & mask); + break; + } + FALL_THROUGH; default: diff --git a/src/protocols/dhcpv4/encode.c b/src/protocols/dhcpv4/encode.c index 6a88d6d3aa8..aa959eae545 100644 --- a/src/protocols/dhcpv4/encode.c +++ b/src/protocols/dhcpv4/encode.c @@ -143,6 +143,21 @@ static ssize_t encode_value(fr_dbuff_t *dbuff, fr_dbuff_in(&work_dbuff, mask); break; } + + if (da_is_bits_prefix(vp->da)) { + int num_bytes = (vp->vp_ip.prefix + 0x07) >> 3; + + fr_dbuff_in(&work_dbuff, (uint8_t) vp->vp_ip.prefix); + + if (num_bytes) { + FR_DBUFF_IN_MEMCPY_RETURN(&work_dbuff, + (uint8_t const *)&vp->vp_ipv4addr, + num_bytes); + } + + break; + } + goto from_network; case FR_TYPE_STRING: diff --git a/src/tests/unit/protocols/dhcpv4/rfc3442.txt b/src/tests/unit/protocols/dhcpv4/rfc3442.txt new file mode 100644 index 00000000000..b82bb5f415f --- /dev/null +++ b/src/tests/unit/protocols/dhcpv4/rfc3442.txt @@ -0,0 +1,13 @@ +proto dhcpv4 +proto-dictionary dhcpv4 +fuzzer-out dhcpv4 + +encode-pair Classless-Static-Route = { Destination-Descriptor = { Subnet = 127.0.0.0/8, Router-IP-Address = 127.0.0.1 }, Destination-Descriptor = { Subnet = 192.168.0.0/16, Router-IP-Address = 192.168.0.1 } } +match 79 0d 08 7f 7f 00 00 01 10 c0 a8 c0 a8 00 01 + +decode-pair - +match Classless-Static-Route = { Destination-Descriptor = { Subnet = 127.0.0.0/8, Router-IP-Address = 127.0.0.1 }, Destination-Descriptor = { Subnet = 192.168.0.0/16, Router-IP-Address = 192.168.0.1 } } + + +count +match 7