Scope: implemented support for TFTP server address and generic options.

This commit is contained in:
Shreyas Zare
2022-12-24 12:07:34 +05:30
parent 3f9f7db65b
commit f08b489476

View File

@@ -76,8 +76,10 @@ namespace DnsServerCore.Dhcp
IReadOnlyCollection<ClasslessStaticRouteOption.Route> _staticRoutes;
IReadOnlyDictionary<string, VendorSpecificInformationOption> _vendorInfo;
IReadOnlyCollection<IPAddress> _capwapAcIpAddresses;
IReadOnlyCollection<IPAddress> _tftpServerAddreses;
//advanced options
IReadOnlyCollection<DhcpOption> _genericOptions;
IReadOnlyCollection<Exclusion> _exclusions;
readonly ConcurrentDictionary<ClientIdentifierOption, Lease> _reservedLeases = new ConcurrentDictionary<ClientIdentifierOption, Lease>();
bool _allowOnlyReservedLeases;
@@ -130,6 +132,7 @@ namespace DnsServerCore.Dhcp
case 5:
case 6:
case 7:
case 8:
_name = bR.ReadShortString();
_enabled = bR.ReadBoolean();
@@ -299,6 +302,40 @@ namespace DnsServerCore.Dhcp
}
}
if (version >= 8)
{
int count = bR.ReadByte();
if (count > 0)
{
IPAddress[] tftpServerAddreses = new IPAddress[count];
for (int i = 0; i < count; i++)
tftpServerAddreses[i] = IPAddressExtension.ReadFrom(bR);
_tftpServerAddreses = tftpServerAddreses;
}
}
if (version >= 8)
{
int count = bR.ReadByte();
if (count > 0)
{
DhcpOption[] genericOptions = new DhcpOption[count];
for (int i = 0; i < count; i++)
{
DhcpOptionCode code = (DhcpOptionCode)bR.ReadByte();
short length = bR.ReadInt16();
byte[] value = bR.ReadBytes(length);
genericOptions[i] = new DhcpOption(code, value);
}
_genericOptions = genericOptions;
}
}
{
int count = bR.ReadByte();
if (count > 0)
@@ -1121,6 +1158,27 @@ namespace DnsServerCore.Dhcp
options.Add(new CAPWAPAccessControllerOption(_capwapAcIpAddresses));
break;
case DhcpOptionCode.TftpServerAddress:
if (_tftpServerAddreses is not null)
options.Add(new TftpServerAddressOption(_tftpServerAddreses));
break;
default:
if (_genericOptions is not null)
{
foreach (DhcpOption genericOption in _genericOptions)
{
if (optionCode == genericOption.Code)
{
options.Add(genericOption);
break;
}
}
}
break;
}
}
}
@@ -1429,7 +1487,7 @@ namespace DnsServerCore.Dhcp
public void WriteTo(BinaryWriter bW)
{
bW.Write(Encoding.ASCII.GetBytes("SC"));
bW.Write((byte)7); //version
bW.Write((byte)8); //version
bW.WriteShortString(_name);
bW.Write(_enabled);
@@ -1576,6 +1634,34 @@ namespace DnsServerCore.Dhcp
capwapAcIpAddress.WriteTo(bW);
}
if (_tftpServerAddreses is null)
{
bW.Write((byte)0);
}
else
{
bW.Write(Convert.ToByte(_tftpServerAddreses.Count));
foreach (IPAddress tftpServerAddress in _tftpServerAddreses)
tftpServerAddress.WriteTo(bW);
}
if (_genericOptions is null)
{
bW.Write((byte)0);
}
else
{
bW.Write(Convert.ToByte(_genericOptions.Count));
foreach (DhcpOption genericOption in _genericOptions)
{
bW.Write((byte)genericOption.Code);
bW.Write(Convert.ToInt16(genericOption.RawValue.Length));
bW.Write(genericOption.RawValue);
}
}
if (_exclusions is null)
{
bW.Write((byte)0);
@@ -1898,6 +1984,22 @@ namespace DnsServerCore.Dhcp
}
}
public IReadOnlyCollection<IPAddress> TftpServerAddresses
{
get { return _tftpServerAddreses; }
set
{
ValidateIpv4(value, nameof(TftpServerAddresses));
_tftpServerAddreses = value;
}
}
public IReadOnlyCollection<DhcpOption> GenericOptions
{
get { return _genericOptions; }
set { _genericOptions = value; }
}
public IReadOnlyCollection<Exclusion> Exclusions
{
get { return _exclusions; }