示例#1
0
        public static DHCPv6Packet AsReleaseResponse(DHCPv6Packet requestPacket, UInt32 identityAssocicationId, UInt32 prefixIdentityAssociation, DUID serverDuid)
        {
            DHCPv6Packet innerReceivedPacket = requestPacket.GetInnerPacket();

            List <DHCPv6PacketOption> packetOptions = new List <DHCPv6PacketOption>();

            {
                foreach (var item in innerReceivedPacket.Options)
                {
                    switch (item)
                    {
                    case DHCPv6PacketIdentityAssociationNonTemporaryAddressesOption option:
                        packetOptions.Add(DHCPv6PacketIdentityAssociationNonTemporaryAddressesOption.Error(option, option.Id == identityAssocicationId ? DHCPv6StatusCodes.Success : DHCPv6StatusCodes.NoBinding));
                        break;

                    case DHCPv6PacketIdentityAssociationPrefixDelegationOption option:
                        packetOptions.Add(DHCPv6PacketIdentityAssociationPrefixDelegationOption.Error(option, option.Id == prefixIdentityAssociation ? DHCPv6StatusCodes.Success : DHCPv6StatusCodes.NoBinding));
                        break;

                    default:
                        break;
                    }
                }
            }

            AddOptions(packetOptions, requestPacket, serverDuid, null, null, true);

            DHCPv6Packet innerResponse = new DHCPv6Packet(DHCPv6PacketTypes.REPLY,
                                                          innerReceivedPacket.TransactionId,
                                                          packetOptions);

            DHCPv6Packet response = ConstructPacketWithHeader(requestPacket, innerResponse);

            return(response);
        }
示例#2
0
        public static DHCPv6Packet AsError(DHCPv6Packet requestPacket, DHCPv6StatusCodes errorCode, DUID serverDuid)
        {
            DHCPv6Packet innerReceivedPacket = requestPacket.GetInnerPacket();

            List <DHCPv6PacketOption> packetOptions = new List <DHCPv6PacketOption>();

            {
                foreach (var item in innerReceivedPacket.Options)
                {
                    switch (item)
                    {
                    case DHCPv6PacketIdentityAssociationPrefixDelegationOption option:
                        if (errorCode == DHCPv6StatusCodes.NoAddrsAvail)
                        {
                            packetOptions.Add(DHCPv6PacketIdentityAssociationPrefixDelegationOption.NotAvailable(option));
                        }
                        else
                        {
                            packetOptions.Add(DHCPv6PacketIdentityAssociationPrefixDelegationOption.Error(option, errorCode));
                        }
                        break;

                    case DHCPv6PacketIdentityAssociationNonTemporaryAddressesOption option:
                        packetOptions.Add(DHCPv6PacketIdentityAssociationNonTemporaryAddressesOption.Error(option, errorCode));
                        break;

                    default:
                        break;
                    }
                }
            }

            AddOptions(packetOptions, requestPacket, serverDuid, null, null, true);

            DHCPv6Packet innerResponse = new DHCPv6Packet(DHCPv6PacketTypes.REPLY,
                                                          innerReceivedPacket.TransactionId,
                                                          packetOptions);

            DHCPv6Packet response = ConstructPacketWithHeader(requestPacket, innerResponse);

            return(response);
        }
示例#3
0
        public static DHCPv6Packet AsReply(DHCPv6Packet requestPacket, DHCPv6ScopeAddressProperties addressProperties, DHCPv6ScopeProperties properties, DHCPv6Lease lease, Boolean adjustTimers, DUID serverDuid, Boolean isRapitCommit)
        {
            DHCPv6Packet innerReceivedPacket = requestPacket.GetInnerPacket();

            GetTimeValues(addressProperties, lease, adjustTimers, out TimeSpan preferredLifetime, out TimeSpan validLifetime, out TimeSpan T1, out TimeSpan T2);

            List <DHCPv6PacketOption> packetOptions = new List <DHCPv6PacketOption>();

            if (innerReceivedPacket.HasOption(DHCPv6PacketOptionTypes.IdentityAssociation_NonTemporary) == true)
            {
                packetOptions.Add(DHCPv6PacketIdentityAssociationNonTemporaryAddressesOption.AsSuccess(
                                      lease.IdentityAssocicationId, T1, T2, lease.Address, preferredLifetime, validLifetime));
            }

            if (innerReceivedPacket.HasOption(DHCPv6PacketOptionTypes.IdentityAssociation_PrefixDelegation) == true)
            {
                if (lease.PrefixDelegation == DHCPv6PrefixDelegation.None)
                {
                    packetOptions.Add(DHCPv6PacketIdentityAssociationPrefixDelegationOption.NotAvailable(
                                          innerReceivedPacket.GetOption <DHCPv6PacketIdentityAssociationPrefixDelegationOption>(DHCPv6PacketOptionTypes.IdentityAssociation_PrefixDelegation)));
                }
                else
                {
                    packetOptions.Add(DHCPv6PacketIdentityAssociationPrefixDelegationOption.AsSuccess(lease.PrefixDelegation.IdentityAssociation, T1, T2, lease.PrefixDelegation.Mask.Identifier, lease.PrefixDelegation.NetworkAddress, preferredLifetime, validLifetime));
                }
            }

            if (isRapitCommit == true)
            {
                packetOptions.Add(new DHCPv6PacketTrueOption(DHCPv6PacketOptionTypes.RapitCommit));
            }

            AddOptions(packetOptions, requestPacket, serverDuid, addressProperties, properties, false);

            DHCPv6Packet innerResponse = new DHCPv6Packet(DHCPv6PacketTypes.REPLY,
                                                          innerReceivedPacket.TransactionId,
                                                          packetOptions);

            DHCPv6Packet response = ConstructPacketWithHeader(requestPacket, innerResponse);

            return(response);
        }
示例#4
0
        public static DHCPv6Packet AsAdvertise(
            DHCPv6Packet requestPacket,
            DHCPv6Lease lease,
            DHCPv6PrefixDelegation prefixDelegation,
            DHCPv6ScopeAddressProperties addressProperties,
            DHCPv6ScopeProperties properties,
            DUID serverDuid
            )
        {
            DHCPv6Packet innerReceivedPacket = requestPacket.GetInnerPacket();

            GetTimeValues(addressProperties, lease, false, out TimeSpan preferredLifetime, out TimeSpan validLifetime, out TimeSpan T1, out TimeSpan T2);

            List <DHCPv6PacketOption> packetOptions = new List <DHCPv6PacketOption>
            {
                DHCPv6PacketIdentityAssociationNonTemporaryAddressesOption.AsSuccess(innerReceivedPacket.GetNonTemporaryIdentityAssocationId().Value, T1, T2, lease.Address, preferredLifetime, validLifetime)
            };

            if (innerReceivedPacket.HasOption(DHCPv6PacketOptionTypes.IdentityAssociation_PrefixDelegation) == true)
            {
                if (prefixDelegation == DHCPv6PrefixDelegation.None)
                {
                    packetOptions.Add(DHCPv6PacketIdentityAssociationPrefixDelegationOption.NotAvailable(
                                          requestPacket.GetOption <DHCPv6PacketIdentityAssociationPrefixDelegationOption>(DHCPv6PacketOptionTypes.IdentityAssociation_PrefixDelegation)));
                }
                else
                {
                    packetOptions.Add(DHCPv6PacketIdentityAssociationPrefixDelegationOption.AsSuccess(prefixDelegation.IdentityAssociation, T1, T2, prefixDelegation.Mask.Identifier, prefixDelegation.NetworkAddress, preferredLifetime, validLifetime));
                }
            }

            AddOptions(packetOptions, requestPacket, serverDuid, addressProperties, properties, false);

            DHCPv6Packet innerResponse = new DHCPv6Packet(DHCPv6PacketTypes.ADVERTISE,
                                                          innerReceivedPacket.TransactionId,
                                                          packetOptions);

            DHCPv6Packet response = ConstructPacketWithHeader(requestPacket, innerResponse);

            return(response);
        }
示例#5
0
 static DHCPv6PacketOptionFactory()
 {
     _constructorDict = new Dictionary <ushort, Func <byte[], DHCPv6PacketOption> >
     {
         { (UInt16)DHCPv6PacketOptionTypes.ClientIdentifier, (data) => DHCPv6PacketIdentifierOption.FromByteArray(data, 0) },
         { (UInt16)DHCPv6PacketOptionTypes.ServerIdentifer, (data) => DHCPv6PacketIdentifierOption.FromByteArray(data, 0) },
         { (UInt16)DHCPv6PacketOptionTypes.IdentityAssociation_NonTemporary, (data) => DHCPv6PacketIdentityAssociationNonTemporaryAddressesOption.FromByteArray(data, 0) },
         { (UInt16)DHCPv6PacketOptionTypes.IdentityAssociation_Temporary, (data) => DHCPv6PacketIdentityAssociationTemporaryAddressesOption.FromByteArray(data, 0) },
         { (UInt16)DHCPv6PacketOptionTypes.OptionRequest, (data) => DHCPv6PacketOptionRequestOption.FromByteArray(data, 0) },
         { (UInt16)DHCPv6PacketOptionTypes.Preference, (data) => DHCPv6PacketByteOption.FromByteArray(data, 0) },
         { (UInt16)DHCPv6PacketOptionTypes.ElapsedTime, (data) => DHCPv6PacketTimeOption.FromByteArray(data, 0, DHCPv6PacketTimeOption.DHCPv6PacketTimeOptionUnits.HundredsOfSeconds) },
         { (UInt16)DHCPv6PacketOptionTypes.ServerUnicast, (data) => DHCPv6PacketIPAddressOption.FromByteArray(data, 0) },
         { (UInt16)DHCPv6PacketOptionTypes.RapitCommit, (data) => DHCPv6PacketTrueOption.FromByteArray(data, 0) },
         { (UInt16)DHCPv6PacketOptionTypes.UserClass, (data) => DHCPv6PacketUserClassOption.FromByteArray(data, 0) },
         { (UInt16)DHCPv6PacketOptionTypes.VendorClass, (data) => DHCPv6PacketVendorClassOption.FromByteArray(data, 0) },
         { (UInt16)DHCPv6PacketOptionTypes.VendorOptions, (data) => DHCPv6PacketVendorSpecificInformationOption.FromByteArray(data, 0) },
         { (UInt16)DHCPv6PacketOptionTypes.InterfaceId, (data) => DHCPv6PacketByteArrayOption.FromByteArray(data, 0) },
         { (UInt16)DHCPv6PacketOptionTypes.Reconfigure, (data) => DHCPv6PacketReconfigureOption.FromByteArray(data, 0) },
         { (UInt16)DHCPv6PacketOptionTypes.ReconfigureAccepte, (data) => DHCPv6PacketTrueOption.FromByteArray(data, 0) },
         { (UInt16)DHCPv6PacketOptionTypes.IdentityAssociation_PrefixDelegation, (data) => DHCPv6PacketIdentityAssociationPrefixDelegationOption.FromByteArray(data, 0) },
         { (UInt16)DHCPv6PacketOptionTypes.InformationRefreshTime, (data) => DHCPv6PacketTimeOption.FromByteArray(data, 0, DHCPv6PacketTimeOption.DHCPv6PacketTimeOptionUnits.Seconds) },
         { (UInt16)DHCPv6PacketOptionTypes.RemoteIdentifier, (data) => DHCPv6PacketRemoteIdentifierOption.FromByteArray(data, 0) },
         { (UInt16)DHCPv6PacketOptionTypes.SOL_MAX_RT, (data) => DHCPv6PacketUInt32Option.FromByteArray(data, 0) },
         { (UInt16)DHCPv6PacketOptionTypes.INF_MAX_RT, (data) => DHCPv6PacketUInt32Option.FromByteArray(data, 0) },
         { (UInt16)DHCPv6PacketOptionTypes.DNSServer, (data) => DHCPv6PacketIPAddressListOption.FromByteArray(data, 0) },
         { (UInt16)DHCPv6PacketOptionTypes.NTPServer, (data) => DHCPv6PacketIPAddressListOption.FromByteArray(data, 0) },
         { (UInt16)DHCPv6PacketOptionTypes.SNTPServer, (data) => DHCPv6PacketIPAddressListOption.FromByteArray(data, 0) },
     };
 }