Example #1
0
        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            if (data.Length < OptionDataMinimumLength)
            {
                return(null);
            }

            bool isIpV4 = data.ReadBool(Offset.IsIpV4, Mask.IsIpV4);
            bool isIpV6 = data.ReadBool(Offset.IsIpV6, Mask.IsIpV6);

            if (isIpV4 && !isIpV6)
            {
                if (data.Length != OptionDataMinimumLength + IpV4Address.SizeOf)
                {
                    return(null);
                }
                IpV4Address localMobilityAddress = data.ReadIpV4Address(Offset.LocalMobilityAddress, Endianity.Big);
                return(new IpV6MobilityOptionRedirect(localMobilityAddress));
            }
            if (isIpV6 && !isIpV4)
            {
                if (data.Length != OptionDataMinimumLength + IpV6Address.SizeOf)
                {
                    return(null);
                }
                IpV6Address localMobilityAddress = data.ReadIpV6Address(Offset.LocalMobilityAddress, Endianity.Big);
                return(new IpV6MobilityOptionRedirect(localMobilityAddress));
            }

            return(null);
        }
        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            if (data.Length < OptionDataMinimumLength)
            {
                return(null);
            }

            IpV6LocalMobilityAnchorAddressCode code = (IpV6LocalMobilityAnchorAddressCode)data[Offset.Code];

            switch (code)
            {
            case IpV6LocalMobilityAnchorAddressCode.IpV6:
            {
                if (data.Length != Offset.LocalMobilityAnchorAddress + IpV6Address.SizeOf)
                {
                    return(null);
                }
                IpV6Address localMobilityAnchorAddress = data.ReadIpV6Address(Offset.LocalMobilityAnchorAddress, Endianity.Big);
                return(new IpV6MobilityOptionLocalMobilityAnchorAddress(localMobilityAnchorAddress));
            }

            case IpV6LocalMobilityAnchorAddressCode.IpV4:
            {
                if (data.Length != Offset.LocalMobilityAnchorAddress + IpV4Address.SizeOf)
                {
                    return(null);
                }
                IpV4Address localMobilityAnchorAddress = data.ReadIpV4Address(Offset.LocalMobilityAnchorAddress, Endianity.Big);
                return(new IpV6MobilityOptionLocalMobilityAnchorAddress(localMobilityAnchorAddress));
            }

            default:
                return(null);
            }
        }
 internal override IpV6Option CreateInstance(DataSegment data)
 {
     if (data.Length != OptionDataLength)
         return null;
     IpV6Address homeAddress = data.ReadIpV6Address(0, Endianity.Big);
     return new IpV6OptionHomeAddress(homeAddress);
 }
        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            if (data.Length < OptionDataMinimumLength)
                return null;

            IpV6LocalMobilityAnchorAddressCode code = (IpV6LocalMobilityAnchorAddressCode)data[Offset.Code];
            switch (code)
            {
                case IpV6LocalMobilityAnchorAddressCode.IpV6:
                {
                    if (data.Length != Offset.LocalMobilityAnchorAddress + IpV6Address.SizeOf)
                        return null;
                    IpV6Address localMobilityAnchorAddress = data.ReadIpV6Address(Offset.LocalMobilityAnchorAddress, Endianity.Big);
                    return new IpV6MobilityOptionLocalMobilityAnchorAddress(localMobilityAnchorAddress);
                }

                case IpV6LocalMobilityAnchorAddressCode.IpV4:
                {
                    if (data.Length != Offset.LocalMobilityAnchorAddress + IpV4Address.SizeOf)
                        return null;
                    IpV4Address localMobilityAnchorAddress = data.ReadIpV4Address(Offset.LocalMobilityAnchorAddress, Endianity.Big);
                    return new IpV6MobilityOptionLocalMobilityAnchorAddress(localMobilityAnchorAddress);
                }

                default:
                    return null;
            }
        }
        internal static IpV6ExtensionHeaderMobilityHomeAgentSwitchMessage ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
        {
            if (messageData.Length < MinimumMessageDataLength)
            {
                return(null);
            }

            byte numberOfAddresses      = messageData[MessageDataOffset.NumberOfAddresses];
            int  homeAgentAddressesSize = numberOfAddresses * IpV6Address.SizeOf;

            if (messageData.Length < MinimumMessageDataLength + homeAgentAddressesSize)
            {
                return(null);
            }

            IpV6Address[] homeAgentAddresses = new IpV6Address[numberOfAddresses];
            for (int i = 0; i != numberOfAddresses; ++i)
            {
                homeAgentAddresses[i] = messageData.ReadIpV6Address(MessageDataOffset.HomeAgentAddresses + i * IpV6Address.SizeOf, Endianity.Big);
            }

            int optionsOffset           = MessageDataOffset.HomeAgentAddresses + homeAgentAddressesSize;
            IpV6MobilityOptions options = new IpV6MobilityOptions(messageData.Subsegment(optionsOffset, messageData.Length - optionsOffset));

            return(new IpV6ExtensionHeaderMobilityHomeAgentSwitchMessage(nextHeader, checksum, homeAgentAddresses, options));
        }
        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            if (data.Length < OptionDataMinimumLength)
            {
                return(null);
            }

            ushort bindingId = data.ReadUShort(Offset.BindingId, Endianity.Big);
            IpV6BindingAcknowledgementStatus status = (IpV6BindingAcknowledgementStatus)data[Offset.Status];
            bool simultaneousHomeAndForeignBinding  = data.ReadBool(Offset.SimultaneousHomeAndForeignBinding, Mask.SimultaneousHomeAndForeignBinding);
            byte priority = (byte)(data[Offset.Priority] & Mask.Priority);

            if (data.Length == OptionDataMinimumLength)
            {
                return(new IpV6MobilityOptionBindingIdentifier(bindingId, status, simultaneousHomeAndForeignBinding, priority));
            }
            if (data.Length == OptionDataMinimumLength + IpV4Address.SizeOf)
            {
                IpV4Address careOfAddress = data.ReadIpV4Address(Offset.CareOfAddress, Endianity.Big);
                return(new IpV6MobilityOptionBindingIdentifier(bindingId, status, simultaneousHomeAndForeignBinding, priority, careOfAddress));
            }
            if (data.Length == OptionDataMinimumLength + IpV6Address.SizeOf)
            {
                IpV6Address careOfAddress = data.ReadIpV6Address(Offset.CareOfAddress, Endianity.Big);
                return(new IpV6MobilityOptionBindingIdentifier(bindingId, status, simultaneousHomeAndForeignBinding, priority, careOfAddress));
            }
            return(null);
        }
        internal static IpV6ExtensionHeaderRoutingHomeAddress ParseRoutingData(IpV4Protocol nextHeader, byte segmentsLeft, DataSegment routingData)
        {
            if (routingData.Length != RoutingDataLength)
                return null;

            IpV6Address homeAddress = routingData.ReadIpV6Address(RoutingDataOffset.HomeAddress, Endianity.Big);
            return new IpV6ExtensionHeaderRoutingHomeAddress(nextHeader, segmentsLeft, homeAddress);
        }
Example #8
0
 internal override DnsResourceData CreateInstance(DataSegment data)
 {
     if (data.Length != IpV6Address.SizeOf)
     {
         return(null);
     }
     return(new DnsResourceDataIpV6(data.ReadIpV6Address(0, Endianity.Big)));
 }
Example #9
0
 /// <summary>
 /// Parses an option from the given data.
 /// </summary>
 /// <param name="data">The data to parse.</param>
 /// <returns>The option if parsing was successful, null otherwise.</returns>
 public IpV6Option CreateInstance(DataSegment data)
 {
     if (data == null) 
         throw new ArgumentNullException("data");
     if (data.Length != OptionDataLength)
         return null;
     IpV6Address homeAddress = data.ReadIpV6Address(0, Endianity.Big);
     return new IpV6OptionHomeAddress(homeAddress);
 }
Example #10
0
        internal override IpV6Option CreateInstance(DataSegment data)
        {
            if (data.Length != OptionDataLength)
            {
                return(null);
            }
            IpV6Address homeAddress = data.ReadIpV6Address(0, Endianity.Big);

            return(new IpV6OptionHomeAddress(homeAddress));
        }
        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            if (data.Length != OptionDataLength)
                return null;

            if (data[Offset.AddressLength] != AddressLength)
                return null;

            return new IpV6MobilityOptionMobileAccessGatewayIpV6Address(data.ReadIpV6Address(Offset.Address, Endianity.Big));
        }
Example #12
0
        internal static bool Read(DataSegment data, out IpV6Address address)
        {
            if (data.Length != OptionDataLength)
            {
                address = IpV6Address.Zero;
                return(false);
            }

            address = data.ReadIpV6Address(0, Endianity.Big);
            return(true);
        }
        internal static IpV6ExtensionHeaderRoutingHomeAddress ParseRoutingData(IpV4Protocol nextHeader, byte segmentsLeft, DataSegment routingData)
        {
            if (routingData.Length != ConstRoutingDataLength)
            {
                return(null);
            }

            IpV6Address homeAddress = routingData.ReadIpV6Address(RoutingDataOffset.HomeAddress, Endianity.Big);

            return(new IpV6ExtensionHeaderRoutingHomeAddress(nextHeader, segmentsLeft, homeAddress));
        }
        internal static bool Read(DataSegment data, out IpV6Address address)
        {
            if (data.Length != OptionDataLength)
            {
                address = IpV6Address.Zero;
                return false;
            }

            address = data.ReadIpV6Address(0, Endianity.Big);
            return true;
        }
        internal static bool Read(DataSegment data, out byte prefixLength, out IpV6Address networkPrefix)
        {
            if (data.Length != OptionDataLength)
            {
                prefixLength  = 0;
                networkPrefix = IpV6Address.Zero;
                return(false);
            }

            prefixLength  = data[Offset.PrefixLength];
            networkPrefix = data.ReadIpV6Address(Offset.NetworkPrefix, Endianity.Big);
            return(true);
        }
Example #16
0
        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            if (data.Length != OptionDataLength)
            {
                return(null);
            }

            IpV6MobilityIpV6AddressPrefixCode code = (IpV6MobilityIpV6AddressPrefixCode)data[Offset.Code];
            byte        prefixLength    = data[Offset.PrefixLength];
            IpV6Address addressOrPrefix = data.ReadIpV6Address(Offset.AddressOrPrefix, Endianity.Big);

            return(new IpV6MobilityOptionIpV6AddressPrefix(code, prefixLength, addressOrPrefix));
        }
Example #17
0
        internal static IpV6ExtensionHeaderMobilityBindingError ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
        {
            if (messageData.Length < MinimumMessageDataLength)
            {
                return(null);
            }

            IpV6BindingErrorStatus status      = (IpV6BindingErrorStatus)messageData[MessageDataOffset.Status];
            IpV6Address            homeAddress = messageData.ReadIpV6Address(MessageDataOffset.HomeAddress, Endianity.Big);
            IpV6MobilityOptions    options     = new IpV6MobilityOptions(messageData.Subsegment(MessageDataOffset.Options, messageData.Length - MessageDataOffset.Options));

            return(new IpV6ExtensionHeaderMobilityBindingError(nextHeader, checksum, status, homeAddress, options));
        }
        internal static IpV6ExtensionHeaderRoutingSourceRoute ParseRoutingData(IpV4Protocol nextHeader, byte segmentsLeft, DataSegment routingData)
        {
            if (routingData.Length < RoutingDataMinimumLength)
                return null;

            if ((routingData.Length - RoutingDataMinimumLength) % IpV6Address.SizeOf != 0)
                return null;

            int numAddresses = (routingData.Length - RoutingDataMinimumLength) / 8;
            IpV6Address[] addresses = new IpV6Address[numAddresses];
            for (int i = 0; i != numAddresses; ++i)
                addresses[i] = routingData.ReadIpV6Address(RoutingDataOffset.Addresses + i * IpV6Address.SizeOf, Endianity.Big);
            return new IpV6ExtensionHeaderRoutingSourceRoute(nextHeader, segmentsLeft, addresses);
        }
Example #19
0
        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            if (data.Length != OptionDataLength)
            {
                return(null);
            }

            if (data[Offset.AddressLength] != AddressLength)
            {
                return(null);
            }

            return(new IpV6MobilityOptionMobileAccessGatewayIpV6Address(data.ReadIpV6Address(Offset.Address, Endianity.Big)));
        }
Example #20
0
        /// <summary>
        /// Parses an option from the given data.
        /// </summary>
        /// <param name="data">The data to parse.</param>
        /// <returns>The option if parsing was successful, null otherwise.</returns>
        public IpV6Option CreateInstance(DataSegment data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            if (data.Length != OptionDataLength)
            {
                return(null);
            }
            IpV6Address homeAddress = data.ReadIpV6Address(0, Endianity.Big);

            return(new IpV6OptionHomeAddress(homeAddress));
        }
        internal static IpV6ExtensionHeaderRoutingSourceRoute ParseRoutingData(IpV4Protocol nextHeader, byte segmentsLeft, DataSegment routingData)
        {
            if (routingData.Length < RoutingDataMinimumLength)
                return null;

            if ((routingData.Length - RoutingDataMinimumLength) % IpV6Address.SizeOf != 0)
                return null;

            int numAddresses = (routingData.Length - RoutingDataMinimumLength) / 8;
            IpV6Address[] addresses = new IpV6Address[numAddresses];
            for (int i = 0; i != numAddresses; ++i)
                addresses[i] = routingData.ReadIpV6Address(RoutingDataOffset.Addresses + i * IpV6Address.SizeOf, Endianity.Big);
            return new IpV6ExtensionHeaderRoutingSourceRoute(nextHeader, segmentsLeft, addresses);
        }
        internal static IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetectionSequenceBased CreateSpecificInstance(DataSegment data)
        {
            IpV6TaggerIdType taggerIdType = (IpV6TaggerIdType)((data[Offset.TaggerIdType] & Mask.TaggerIdType) >> Shift.TaggerIdType);
            int taggerIdLength            = (taggerIdType == IpV6TaggerIdType.Null ? 0 : (data[Offset.TaggerIdLength] & Mask.TaggerIdLength) + 1);

            if (data.Length < Offset.TaggerId + taggerIdLength)
            {
                return(null);
            }
            DataSegment identifier = data.Subsegment(Offset.TaggerId + taggerIdLength, data.Length - Offset.TaggerId - taggerIdLength);

            switch (taggerIdType)
            {
            case IpV6TaggerIdType.Null:
                return(new IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetectionNull(identifier));

            case IpV6TaggerIdType.Default:
                return(new IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetectionDefault(data.Subsegment(Offset.TaggerId, taggerIdLength), identifier));

            case IpV6TaggerIdType.IpV4:
                if (taggerIdLength != IpV4Address.SizeOf)
                {
                    return(null);
                }
                IpV4Address ipV4Address = data.ReadIpV4Address(Offset.TaggerId, Endianity.Big);
                return(new IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetectionIpV4(ipV4Address, identifier));

            case IpV6TaggerIdType.IpV6:
                if (taggerIdLength != IpV6Address.SizeOf)
                {
                    return(null);
                }
                IpV6Address ipV6Address = data.ReadIpV6Address(Offset.TaggerId, Endianity.Big);
                return(new IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetectionIpV6(ipV6Address, identifier));

            default:
                return(null);
            }
        }
        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            if (data.Length != OptionDataLength)
                return null;

            IpV6MobilityIpV6AddressPrefixCode code = (IpV6MobilityIpV6AddressPrefixCode)data[Offset.Code];
            byte prefixLength = data[Offset.PrefixLength];
            IpV6Address addressOrPrefix = data.ReadIpV6Address(Offset.AddressOrPrefix, Endianity.Big);
            return new IpV6MobilityOptionIpV6AddressPrefix(code, prefixLength, addressOrPrefix);
        }
        internal static IpV6ExtensionHeaderMobilityHomeAgentSwitchMessage ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
        {
            if (messageData.Length < MinimumMessageDataLength)
                return null;

            byte numberOfAddresses = messageData[MessageDataOffset.NumberOfAddresses];
            int homeAgentAddressesSize = numberOfAddresses * IpV6Address.SizeOf;
            if (messageData.Length < MinimumMessageDataLength + homeAgentAddressesSize)
                return null;

            IpV6Address[] homeAgentAddresses = new IpV6Address[numberOfAddresses];
            for (int i = 0; i != numberOfAddresses; ++i)
                homeAgentAddresses[i] = messageData.ReadIpV6Address(MessageDataOffset.HomeAgentAddresses + i * IpV6Address.SizeOf, Endianity.Big);

            int optionsOffset = MessageDataOffset.HomeAgentAddresses + homeAgentAddressesSize;
            IpV6MobilityOptions options = new IpV6MobilityOptions(messageData.Subsegment(optionsOffset, messageData.Length - optionsOffset));
            return new IpV6ExtensionHeaderMobilityHomeAgentSwitchMessage(nextHeader, checksum, homeAgentAddresses, options);
        }
        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            if (data.Length < OptionDataMinimumLength)
                return null;

            ushort bindingId = data.ReadUShort(Offset.BindingId, Endianity.Big);
            IpV6BindingAcknowledgementStatus status = (IpV6BindingAcknowledgementStatus)data[Offset.Status];
            bool simultaneousHomeAndForeignBinding = data.ReadBool(Offset.SimultaneousHomeAndForeignBinding, Mask.SimultaneousHomeAndForeignBinding);
            byte priority = (byte)(data[Offset.Priority] & Mask.Priority);
            if (data.Length == OptionDataMinimumLength)
                return new IpV6MobilityOptionBindingIdentifier(bindingId, status, simultaneousHomeAndForeignBinding, priority);
            if (data.Length == OptionDataMinimumLength + IpV4Address.SizeOf)
            {
                IpV4Address careOfAddress = data.ReadIpV4Address(Offset.CareOfAddress, Endianity.Big);
                return new IpV6MobilityOptionBindingIdentifier(bindingId, status, simultaneousHomeAndForeignBinding, priority, careOfAddress);
            }
            if (data.Length == OptionDataMinimumLength + IpV6Address.SizeOf)
            {
                IpV6Address careOfAddress = data.ReadIpV6Address(Offset.CareOfAddress, Endianity.Big);
                return new IpV6MobilityOptionBindingIdentifier(bindingId, status, simultaneousHomeAndForeignBinding, priority, careOfAddress);
            }
            return null;
        }
        internal static bool Read(DataSegment data, out byte prefixLength, out IpV6Address networkPrefix)
        {
            if (data.Length != OptionDataLength)
            {
                prefixLength = 0;
                networkPrefix = IpV6Address.Zero;
                return false;
            }

            prefixLength = data[Offset.PrefixLength];
            networkPrefix = data.ReadIpV6Address(Offset.NetworkPrefix, Endianity.Big);
            return true;
        }
        internal static IpV6ExtensionHeaderMobilityBindingError ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
        {
            if (messageData.Length < MinimumMessageDataLength)
                return null;

            IpV6BindingErrorStatus status = (IpV6BindingErrorStatus)messageData[MessageDataOffset.Status];
            IpV6Address homeAddress = messageData.ReadIpV6Address(MessageDataOffset.HomeAddress, Endianity.Big);
            IpV6MobilityOptions options = new IpV6MobilityOptions(messageData.Subsegment(MessageDataOffset.Options, messageData.Length - MessageDataOffset.Options));
            return new IpV6ExtensionHeaderMobilityBindingError(nextHeader, checksum, status, homeAddress, options);
        }
        internal static IpV6OptionSmfDpdSequenceBased CreateSpecificInstance(DataSegment data)
        {
            IpV6TaggerIdType taggerIdType = (IpV6TaggerIdType)((data[Offset.TaggerIdType] & Mask.TaggerIdType) >> Shift.TaggerIdType);
            int taggerIdLength = (taggerIdType == IpV6TaggerIdType.Null ? 0 : (data[Offset.TaggerIdLength] & Mask.TaggerIdLength) + 1);
            if (data.Length < Offset.TaggerId + taggerIdLength)
                return null;
            DataSegment identifier = data.Subsegment(Offset.TaggerId + taggerIdLength, data.Length - Offset.TaggerId - taggerIdLength);
            switch (taggerIdType)
            {
                case IpV6TaggerIdType.Null:
                    return new IpV6OptionSmfDpdNull(identifier);
                    
                case IpV6TaggerIdType.Default:
                    return new IpV6OptionSmfDpdDefault(data.Subsegment(Offset.TaggerId, taggerIdLength), identifier);

                case IpV6TaggerIdType.IpV4:
                    if (taggerIdLength != IpV4Address.SizeOf)
                        return null;
                    IpV4Address ipV4Address = data.ReadIpV4Address(0, Endianity.Big);
                    return new IpV6OptionSmfDpdIpV4(ipV4Address, identifier);

                case IpV6TaggerIdType.IpV6:
                    if (taggerIdLength != IpV6Address.SizeOf)
                        return null;
                    IpV6Address ipV6Address = data.ReadIpV6Address(0, Endianity.Big);
                    return new IpV6OptionSmfDpdIpV6(ipV6Address, identifier);

                default:
                    return null;
            }
        }
        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            if (data.Length < OptionDataMinimumLength)
                return null;

            bool isIpV4 = data.ReadBool(Offset.IsIpV4, Mask.IsIpV4);
            bool isIpV6 = data.ReadBool(Offset.IsIpV6, Mask.IsIpV6);

            if (isIpV4 && !isIpV6)
            {
                if (data.Length != OptionDataMinimumLength + IpV4Address.SizeOf)
                    return null;
                IpV4Address localMobilityAddress = data.ReadIpV4Address(Offset.LocalMobilityAddress, Endianity.Big);
                return new IpV6MobilityOptionRedirect(localMobilityAddress);
            }
            if (isIpV6 && !isIpV4)
            {
                if (data.Length != OptionDataMinimumLength + IpV6Address.SizeOf)
                    return null;
                IpV6Address localMobilityAddress = data.ReadIpV6Address(Offset.LocalMobilityAddress, Endianity.Big);
                return new IpV6MobilityOptionRedirect(localMobilityAddress);
            }

            return null;
        }