public IpV6ExtensionHeaderAuthentication(IpV4Protocol nextHeader, uint securityParametersIndex, uint sequenceNumber, DataSegment authenticationData)
     : base(nextHeader)
 {
     SecurityParametersIndex = securityParametersIndex;
     SequenceNumber = sequenceNumber;
     AuthenticationData = authenticationData;
 }
        internal static IpV6ExtensionHeaderMobilityBindingUpdate ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
        {
            ushort sequenceNumber;
            bool   acknowledge;
            bool   homeRegistration;
            bool   linkLocalAddressCompatibility;
            bool   keyManagementMobilityCapability;
            ushort lifetime;
            IpV6MobilityOptions options;

            if (!ParseMessageDataToFields(messageData, out sequenceNumber, out acknowledge, out homeRegistration, out linkLocalAddressCompatibility,
                                          out keyManagementMobilityCapability, out lifetime, out options))
            {
                return(null);
            }

            bool mapRegistration         = messageData.ReadBool(MessageDataOffset.MapRegistration, MessageDataMask.MapRegistration);
            bool mobileRouter            = messageData.ReadBool(MessageDataOffset.MobileRouter, MessageDataMask.MobileRouter);
            bool proxyRegistration       = messageData.ReadBool(MessageDataOffset.ProxyRegistration, MessageDataMask.ProxyRegistration);
            bool forcingUdpEncapsulation = messageData.ReadBool(MessageDataOffset.ForcingUdpEncapsulation, MessageDataMask.ForcingUdpEncapsulation);
            bool tlvHeaderFormat         = messageData.ReadBool(MessageDataOffset.TlvHeaderFormat, MessageDataMask.TlvHeaderFormat);
            bool bulkBindingUpdate       = messageData.ReadBool(MessageDataOffset.BulkBindingUpdate, MessageDataMask.BulkBindingUpdate);

            return(new IpV6ExtensionHeaderMobilityBindingUpdate(nextHeader, checksum, sequenceNumber, acknowledge, homeRegistration,
                                                                linkLocalAddressCompatibility, keyManagementMobilityCapability, mapRegistration, mobileRouter,
                                                                proxyRegistration, forcingUdpEncapsulation, tlvHeaderFormat, bulkBindingUpdate, lifetime,
                                                                options));
        }
Exemplo n.º 3
0
        private static IpV6ExtensionHeader CreateStandardInstance(IpV4Protocol nextHeader, DataSegment extensionHeaderData, out int numBytesRead)
        {
            numBytesRead = 0;
            if (extensionHeaderData.Length < MinimumLength)
                return null;
            IpV4Protocol nextNextHeader = (IpV4Protocol)extensionHeaderData[Offset.NextHeader];
            int length = (extensionHeaderData[Offset.HeaderExtensionLength] + 1) * 8;
            if (extensionHeaderData.Length < length)
                return null;

            DataSegment data = extensionHeaderData.Subsegment(Offset.Data, length - Offset.Data);
            numBytesRead = data.Length;

            switch (nextHeader)
            {
                case IpV4Protocol.IpV6HopByHopOption: // 0
                    return IpV6ExtensionHeaderHopByHopOptions.ParseData(nextNextHeader, data);

                case IpV4Protocol.IpV6Route: // 43
                    return IpV6ExtensionHeaderRouting.ParseData(nextNextHeader, data);

                case IpV4Protocol.FragmentHeaderForIpV6: // 44
                    return IpV6ExtensionHeaderFragmentData.ParseData(nextNextHeader, data);
                
                case IpV4Protocol.IpV6Opts:                     // 60
                    return IpV6ExtensionHeaderDestinationOptions.ParseData(nextNextHeader, data);

                case IpV4Protocol.MobilityHeader:        // 135
                    return IpV6ExtensionHeaderMobility.ParseData(nextNextHeader, data);

                default:
                    throw new InvalidOperationException("Invalid nextHeader value" + nextHeader);
            }
        }
Exemplo n.º 4
0
 public ConnId(ushort lPort, IpV4Address rIp, ushort rPort, IpV4Protocol protocol)
 {
     this.lPort    = lPort;
     this.rIp      = rIp;
     this.rPort    = rPort;
     this.protocol = protocol;
 }
 /// <summary>
 /// Creates an instance from next header, checksum, sequence number, code and options.
 /// </summary>
 /// <param name="nextHeader">Identifies the type of header immediately following this extension header.</param>
 /// <param name="checksum">
 /// Contains the checksum of the Mobility Header.
 /// The checksum is calculated from the octet string consisting of a "pseudo-header"
 /// followed by the entire Mobility Header starting with the Payload Proto field.
 /// The checksum is the 16-bit one's complement of the one's complement sum of this string.
 /// </param>
 /// <param name="sequenceNumber">
 /// Copied from the corresponding field in the Handover Initiate message to which this message is a response,
 /// to enable the receiver to match this Handover Acknowledge message with an outstanding Handover Initiate message.
 /// </param>
 /// <param name="code">Describes whether the handover was accepted or not and more details.</param>
 /// <param name="options">Zero or more TLV-encoded mobility options.</param>
 public IpV6ExtensionHeaderMobilityHandoverAcknowledgeMessage(IpV4Protocol? nextHeader, ushort checksum, ushort sequenceNumber,
                                                              IpV6MobilityHandoverAcknowledgeCode code, IpV6MobilityOptions options)
     : base(nextHeader, checksum, options, MessageDataOffset.Options)
 {
     SequenceNumber = sequenceNumber;
     Code = code;
 }
Exemplo n.º 6
0
        internal static IpV6ExtensionHeaderRouting ParseData(IpV4Protocol nextHeader, DataSegment data)
        {
            if (data.Length < DataMinimumLength)
                return null;
            IpV6RoutingType routingType = (IpV6RoutingType)data[DataOffset.RoutingType];
            byte segmentsLeft = data[DataOffset.SegmentsLeft];
            DataSegment routingData = data.Subsegment(DataOffset.TypeSpecificData, data.Length - DataOffset.TypeSpecificData);
            switch (routingType)
            {
                case IpV6RoutingType.SourceRoute:
                    return IpV6ExtensionHeaderRoutingSourceRoute.ParseRoutingData(nextHeader, segmentsLeft, routingData);

                case IpV6RoutingType.Nimrod:
                    // Unused.
                    return null;

                case IpV6RoutingType.Type2RoutingHeader:
                    return IpV6ExtensionHeaderRoutingHomeAddress.ParseRoutingData(nextHeader, segmentsLeft, routingData);

                case IpV6RoutingType.RoutingProtocolLowPowerAndLossyNetworksSourceRouteHeader:
                    return IpV6ExtensionHeaderRoutingProtocolLowPowerAndLossyNetworks.ParseRoutingData(nextHeader, segmentsLeft, routingData);

                default:
                    return null;
            }
        }
Exemplo n.º 7
0
 public IpV6ExtensionHeaderAuthentication(IpV4Protocol nextHeader, uint securityParametersIndex, uint sequenceNumber, DataSegment authenticationData)
     : base(nextHeader)
 {
     SecurityParametersIndex = securityParametersIndex;
     SequenceNumber          = sequenceNumber;
     AuthenticationData      = authenticationData;
 }
Exemplo n.º 8
0
        internal static void WriteHeader(byte[] buffer, int offset,
                                         byte typeOfService, ushort identification,
                                         IpV4Fragmentation fragmentation,
                                         byte ttl, IpV4Protocol protocol, ushort?headerChecksum,
                                         IpV4Address source, IpV4Address destination,
                                         IpV4Options options, int payloadLength)
        {
            int headerLength = HeaderMinimumLength + options.BytesLength;

            buffer[offset + Offset.VersionAndHeaderLength] = (byte)((DefaultVersion << 4) + headerLength / 4);
            buffer[offset + Offset.TypeOfService]          = typeOfService;
            buffer.Write(offset + Offset.TotalLength, (ushort)(headerLength + payloadLength), Endianity.Big);
            buffer.Write(offset + Offset.Identification, identification, Endianity.Big);
            fragmentation.Write(buffer, offset + Offset.Fragmentation);
            buffer[offset + Offset.Ttl]      = ttl;
            buffer[offset + Offset.Protocol] = (byte)protocol;

            buffer.Write(offset + Offset.Source, source, Endianity.Big);
            buffer.Write(offset + Offset.Destination, destination, Endianity.Big);
            options.Write(buffer, offset + Offset.Options);

            ushort headerChecksumValue =
                headerChecksum == null
                    ? Sum16BitsToChecksum(Sum16Bits(buffer, offset, headerLength))
                    : headerChecksum.Value;

            buffer.Write(offset + Offset.HeaderChecksum, headerChecksumValue, Endianity.Big);
        }
        public IpV6ExtensionHeaderRoutingRpl(IpV4Protocol nextHeader, byte segmentsLeft, byte commonPrefixLengthForNonLastAddresses,
                                             byte commonPrefixLengthForLastAddress, byte padSize, params IpV6Address[] addresses)
            : base(nextHeader, segmentsLeft)
        {
            if (commonPrefixLengthForNonLastAddresses > MaxCommonPrefixLength)
            {
                throw new ArgumentOutOfRangeException("commonPrefixLengthForNonLastAddresses", commonPrefixLengthForNonLastAddresses,
                                                      string.Format("Maximum value is {0}", MaxCommonPrefixLength));
            }
            CommonPrefixLengthForNonLastAddresses = commonPrefixLengthForNonLastAddresses;

            if (commonPrefixLengthForLastAddress > MaxCommonPrefixLength)
            {
                throw new ArgumentOutOfRangeException("commonPrefixLengthForLastAddress", commonPrefixLengthForLastAddress,
                                                      string.Format("Maximum value is {0}", MaxCommonPrefixLength));
            }
            CommonPrefixLengthForLastAddress = commonPrefixLengthForLastAddress;

            if (padSize > MaxPadSize)
            {
                throw new ArgumentOutOfRangeException("padSize", padSize, string.Format("Maximum value is {0}", MaxPadSize));
            }
            PadSize = padSize;

            Addresses = addresses.AsReadOnly();
        }
 internal IpV6ExtensionHeaderMobilityLocalizedRouting(IpV4Protocol? nextHeader, ushort checksum, ushort sequenceNumber, ushort lifetime,
                                                    IpV6MobilityOptions options)
     : base(nextHeader, checksum, options, MessageDataOffset.Options)
 {
     SequenceNumber = sequenceNumber;
     Lifetime = lifetime;
 }
 internal IpV6ExtensionHeaderOptions(IpV4Protocol? nextHeader, IpV6Options options)
     : base(nextHeader)
 {
     if (options.BytesLength % 8 != 6)
         options = options.Pad((14 - options.BytesLength % 8) % 8);
     Options = options;
 }
 /// <summary>
 /// Creates an instance from next header, checksum, status, home address and options.
 /// </summary>
 /// <param name="nextHeader">
 /// Identifies the type of header immediately following this extension header.
 /// </param>
 /// <param name="checksum">
 /// Contains the checksum of the Mobility Header.
 /// The checksum is calculated from the octet string consisting of a "pseudo-header"
 /// followed by the entire Mobility Header starting with the Payload Proto field.
 /// The checksum is the 16-bit one's complement of the one's complement sum of this string.
 /// </param>
 /// <param name="status">Indicating the reason for this message.</param>
 /// <param name="homeAddress">
 /// The home address that was contained in the Home Address destination option.
 /// The mobile node uses this information to determine which binding does not exist, in cases where the mobile node has several home addresses.
 /// </param>
 /// <param name="options">
 /// Zero or more TLV-encoded mobility options.
 /// </param>
 public IpV6ExtensionHeaderMobilityBindingError(IpV4Protocol? nextHeader, ushort checksum, IpV6BindingErrorStatus status, IpV6Address homeAddress,
                                                IpV6MobilityOptions options)
     : base(nextHeader, checksum, options, MessageDataOffset.Options)
 {
     Status = status;
     HomeAddress = homeAddress;
 }
Exemplo n.º 13
0
        /// <summary>
        /// Creates packet by protocol and provided input to constructor
        /// </summary>
        /// <param name="protocol">Packet protocol</param>
        /// <returns>New Custom packet of provided protocol with provided values in it</returns>
        public INewPacket GetPacketByProtocol(IpV4Protocol protocol)
        {
            switch (protocol)
            {
            case IpV4Protocol.Tcp:
                return(new CustomTcpPacket(_layerModifier, _layerExchanger)
                {
                    EthernetLayer = new EthernetLayer(),
                    IpV4Layer = new IpV4Layer(),
                    PayloadLayer = new PayloadLayer(),
                    TcpLayer = new TcpLayer(),
                });

            case IpV4Protocol.Udp:
                return(new CustomUdpPacket(_layerModifier, _layerExchanger)
                {
                    EthernetLayer = new EthernetLayer(),
                    IpV4Layer = new IpV4Layer(),
                    PayloadLayer = new PayloadLayer(),
                    UdpLayer = new UdpLayer(),
                });

            case IpV4Protocol.InternetControlMessageProtocol:
                return(new CustomIcmpPacket(_layerModifier, _layerExchanger)
                {
                    EthernetLayer = new EthernetLayer(),
                    IcmpLayer = new IcmpEchoLayer(),
                    IpV4Layer = new IpV4Layer(),
                });

            default:
                return(null);
            }
        }
Exemplo n.º 14
0
 public ConnId(ushort lPort, IpV4Address rIp, ushort rPort, IpV4Protocol protocol)
 {
     this.lPort = lPort;
     this.rIp = rIp;
     this.rPort = rPort;
     this.protocol = protocol;
 }
 internal override void Write(byte[] buffer, ref int offset, IpV4Protocol nextHeader)
 {
     buffer.Write(offset + Offset.SecurityParametersIndex, SecurityParametersIndex, Endianity.Big);
     buffer.Write(offset + Offset.SequenceNumber, SequenceNumber, Endianity.Big);
     EncryptedDataAndAuthenticationData.Write(buffer, offset + Offset.PayloadData);
     offset += Length;
 }
        internal static IpV6ExtensionHeaderRouting ParseData(IpV4Protocol nextHeader, DataSegment data)
        {
            if (data.Length < DataMinimumLength)
            {
                return(null);
            }
            IpV6RoutingType routingType  = (IpV6RoutingType)data[DataOffset.RoutingType];
            byte            segmentsLeft = data[DataOffset.SegmentsLeft];
            DataSegment     routingData  = data.Subsegment(DataOffset.TypeSpecificData, data.Length - DataOffset.TypeSpecificData);

            switch (routingType)
            {
            case IpV6RoutingType.SourceRoute:
                return(IpV6ExtensionHeaderRoutingSourceRoute.ParseRoutingData(nextHeader, segmentsLeft, routingData));

            case IpV6RoutingType.Nimrod:
                // Unused.
                return(null);

            case IpV6RoutingType.Type2RoutingHeader:
                return(IpV6ExtensionHeaderRoutingHomeAddress.ParseRoutingData(nextHeader, segmentsLeft, routingData));

            case IpV6RoutingType.RoutingProtocolLowPowerAndLossyNetworksSourceRouteHeader:
                return(IpV6ExtensionHeaderRoutingProtocolLowPowerAndLossyNetworks.ParseRoutingData(nextHeader, segmentsLeft, routingData));

            default:
                return(null);
            }
        }
Exemplo n.º 17
0
        public static IpV6ExtensionHeader NextIpV6ExtensionHeader(this Random random, IpV4Protocol?nextHeader, bool isEncapsulatingSecurityPayloadPossible)
        {
            IpV4Protocol extensionHeaderType =
                random.NextValue(
                    IpV6ExtensionHeader.ExtensionHeaders.Where(extensionHeader => isEncapsulatingSecurityPayloadPossible ||
                                                               extensionHeader != IpV4Protocol.EncapsulatingSecurityPayload).ToList());

            switch (extensionHeaderType)
            {
            case IpV4Protocol.IpV6HopByHopOption:     // 0
                return(new IpV6ExtensionHeaderHopByHopOptions(nextHeader, random.NextIpV6Options()));

            case IpV4Protocol.IpV6Route:     // 43
                IpV6RoutingType routingType = random.NextEnum(IpV6RoutingType.Nimrod);
                switch (routingType)
                {
                case IpV6RoutingType.SourceRoute:
                    return(new IpV6ExtensionHeaderRoutingSourceRoute(nextHeader, random.NextByte(), random.NextIpV6AddressArray(random.NextInt(0, 10))));

                case IpV6RoutingType.Type2RoutingHeader:
                    return(new IpV6ExtensionHeaderRoutingHomeAddress(nextHeader, random.NextByte(), random.NextIpV6Address()));

                case IpV6RoutingType.RoutingProtocolLowPowerAndLossyNetworksSourceRouteHeader:
                    byte          commonPrefixLengthForNonLastAddresses = random.NextByte(IpV6ExtensionHeaderRoutingProtocolLowPowerAndLossyNetworks.MaxCommonPrefixLength + 1);
                    byte          commonPrefixLengthForLastAddress      = random.NextByte(IpV6ExtensionHeaderRoutingProtocolLowPowerAndLossyNetworks.MaxCommonPrefixLength + 1);
                    IpV6Address[] addresses = random.NextIpV6AddressWithLeadingZeroBytesArray(commonPrefixLengthForNonLastAddresses,
                                                                                              random.NextInt(0, 10));
                    if (addresses.Any() || random.NextBool())
                    {
                        addresses = addresses.Concat(random.NextIpV6AddressWithLeadingZeroBytes(commonPrefixLengthForLastAddress)).ToArray();
                    }
                    return(new IpV6ExtensionHeaderRoutingProtocolLowPowerAndLossyNetworks(nextHeader, random.NextByte(), commonPrefixLengthForNonLastAddresses,
                                                                                          commonPrefixLengthForLastAddress, addresses));

                default:
                    throw new InvalidOperationException(string.Format("Invalid routingType value {0}", routingType));
                }

            case IpV4Protocol.FragmentHeaderForIpV6:     // 44
                return(new IpV6ExtensionHeaderFragmentData(nextHeader, random.NextUShort(IpV6ExtensionHeaderFragmentData.MaxFragmentOffset + 1),
                                                           random.NextBool(), random.NextUInt()));

            case IpV4Protocol.IpV6Opts:     // 60
                IpV6Options options = random.NextIpV6Options();
                return(new IpV6ExtensionHeaderDestinationOptions(nextHeader, options));

            case IpV4Protocol.MobilityHeader:     // 135
                return(random.NextIpV6ExtensionHeaderMobility(nextHeader));

            case IpV4Protocol.EncapsulatingSecurityPayload:     // 50
                return(new IpV6ExtensionHeaderEncapsulatingSecurityPayload(random.NextUInt(), random.NextUInt(), random.NextDataSegment(random.Next(100))));

            case IpV4Protocol.AuthenticationHeader:     // 51
                return(new IpV6ExtensionHeaderAuthentication(nextHeader, random.NextUInt(), random.NextUInt(), random.NextDataSegment(random.Next(25) * 4)));

            default:
                throw new InvalidOperationException(string.Format("Invalid extensionHeaderType value {0}", extensionHeaderType));
            }
        }
Exemplo n.º 18
0
 internal sealed override void Write(byte[] buffer, ref int offset, IpV4Protocol nextHeader)
 {
     buffer.Write(offset + Offset.NextHeader, (byte)nextHeader);
     int length = Length;
     buffer.Write(offset + Offset.HeaderExtensionLength, (byte)((length / 8) - 1));
     WriteData(buffer, offset + Offset.Data);
     offset += length;
 }
        internal static IpV6ExtensionHeaderMobilityFastNeighborAdvertisement ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
        {
            if (messageData.Length < MinimumMessageDataLength)
                return null;

            IpV6MobilityOptions options = new IpV6MobilityOptions(messageData.Subsegment(MessageDataOffset.Options, messageData.Length - MessageDataOffset.Options));
            return new IpV6ExtensionHeaderMobilityFastNeighborAdvertisement(nextHeader, checksum, options);
        }
 /// <summary>
 /// Creates an instance from next header, checksum, revocation trigger, sequence number, proxy binding, IPv4 home address binding only, global 
 /// and options.
 /// </summary>
 /// <param name="nextHeader">
 /// Identifies the type of header immediately following this extension header.
 /// </param>
 /// <param name="checksum">
 /// Contains the checksum of the Mobility Header.
 /// The checksum is calculated from the octet string consisting of a "pseudo-header"
 /// followed by the entire Mobility Header starting with the Payload Proto field.
 /// The checksum is the 16-bit one's complement of the one's complement sum of this string.
 /// </param>
 /// <param name="revocationTrigger">
 /// Indicating the event that triggered the initiator to send the BRI message.
 /// </param>
 /// <param name="sequenceNumber">
 /// Used by the initiator to match a returned Binding Revocation Acknowledgement with this Binding Revocation Indication.
 /// This sequence number could be a random number.
 /// At any time, implementations must ensure there is no collision between the sequence numbers of all outstanding Binding Revocation Indication 
 /// Messages.
 /// </param>
 /// <param name="proxyBinding">
 /// Set by the initiator to indicate that the revoked binding(s) is a PMIPv6 binding.
 /// </param>
 /// <param name="ipV4HomeAddressBindingOnly">
 /// Set by the initiator, home agent, or local mobility anchor to indicate to the receiving mobility entity the termination
 /// of the IPv4 Home Address binding only as in Home Agent Operation and Local Mobility Anchor Operation.
 /// </param>
 /// <param name="global">
 /// Set by the initiator, LMA or MAG, to indicate the termination of all Per-Peer mobility Bindings or Multiple Bindings that share 
 /// a common identifier(s) and are served by the initiator and responder as in Local Mobility Anchor Operation and Mobile Access Gateway Operation.
 /// </param>
 /// <param name="options">
 /// Zero or more TLV-encoded mobility options.
 /// </param>
 public IpV6ExtensionHeaderMobilityBindingRevocationIndicationMessage(IpV4Protocol? nextHeader, ushort checksum,
                                                                      Ipv6MobilityBindingRevocationTrigger revocationTrigger, ushort sequenceNumber,
                                                                      bool proxyBinding, bool ipV4HomeAddressBindingOnly, bool global,
                                                                      IpV6MobilityOptions options)
     : base(nextHeader, checksum, sequenceNumber, proxyBinding, ipV4HomeAddressBindingOnly, global, options)
 {
     RevocationTrigger = revocationTrigger;
 }
 /// <summary>
 /// Creates an instance from next header, checksum, sequence number, unsolicited, status, lifetime and options.
 /// </summary>
 /// <param name="nextHeader">Identifies the type of header immediately following this extension header.</param>
 /// <param name="checksum">
 /// Contains the checksum of the Mobility Header.
 /// The checksum is calculated from the octet string consisting of a "pseudo-header"
 /// followed by the entire Mobility Header starting with the Payload Proto field.
 /// The checksum is the 16-bit one's complement of the one's complement sum of this string.
 /// </param>
 /// <param name="sequenceNumber">Copied from the sequence number field of the LRI message being responded to.</param>
 /// <param name="unsolicited">
 /// When true, the LRA message is sent unsolicited.
 /// The Lifetime field indicates a new requested value.
 /// The MAG must wait for the regular LRI message to confirm that the request is acceptable to the LMA.
 /// </param>
 /// <param name="status">The acknowledgement status.</param>
 /// <param name="lifetime">
 /// The time in seconds for which the local forwarding is supported.
 /// Typically copied from the corresponding field in the LRI message.
 /// </param>
 /// <param name="options">Zero or more TLV-encoded mobility options.</param>
 public IpV6ExtensionHeaderMobilityLocalizedRoutingAcknowledgement(IpV4Protocol? nextHeader, ushort checksum, ushort sequenceNumber, bool unsolicited,
                                                                   IpV6MobilityLocalizedRoutingAcknowledgementStatus status, ushort lifetime,
                                                                   IpV6MobilityOptions options)
     : base(nextHeader, checksum, sequenceNumber, lifetime, options)
 {
     Status = status;
     Unsolicited = unsolicited;
 }
        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);
        }
Exemplo n.º 23
0
 public NetworkEvent(ushort id, IpV4Address source, IpV4Address target, IpV4Protocol protocol, IEnumerable <DnsResourceRecord> queries)
 {
     Id       = id;
     Source   = source;
     Target   = target;
     Protocol = protocol;
     Queries  = queries;
 }
 /// <summary>
 /// Creates an instance from next header, checksum, status, sequence number, proxy binding, IPv4 home address binding only, global and options.
 /// </summary>
 /// <param name="nextHeader">
 /// Identifies the type of header immediately following this extension header.
 /// </param>
 /// <param name="checksum">
 /// Contains the checksum of the Mobility Header.
 /// The checksum is calculated from the octet string consisting of a "pseudo-header"
 /// followed by the entire Mobility Header starting with the Payload Proto field.
 /// The checksum is the 16-bit one's complement of the one's complement sum of this string.
 /// </param>
 /// <param name="status">
 /// Indicating the result of processing the Binding Revocation Indication message by the responder.
 /// </param>
 /// <param name="sequenceNumber">
 /// Copied from the Sequence Number field in the Binding Revocation Indication.
 /// It is used by the initiator, e.g., HA, LMA, MAG, in matching this Binding Revocation Acknowledgement 
 /// with the outstanding Binding Revocation Indication.
 /// </param>
 /// <param name="proxyBinding">
 /// Set if set in the corresponding Binding Revocation Indication message.
 /// </param>
 /// <param name="ipV4HomeAddressBindingOnly">
 /// Set if the it is set in the corresponding Binding Revocation Indication message.
 /// </param>
 /// <param name="global">
 /// Set if it is set in the corresponding Binding Revocation Indication message.
 /// </param>
 /// <param name="options">
 /// Zero or more TLV-encoded mobility options.
 /// </param>
 public IpV6ExtensionHeaderMobilityBindingRevocationAcknowledgementMessage(IpV4Protocol? nextHeader, ushort checksum,
                                                                           Ipv6MobilityBindingRevocationStatus status, ushort sequenceNumber,
                                                                           bool proxyBinding, bool ipV4HomeAddressBindingOnly, bool global,
                                                                           IpV6MobilityOptions options)
     : base(nextHeader, checksum, sequenceNumber, proxyBinding, ipV4HomeAddressBindingOnly, global, options)
 {
     Status = status;
 }
 /// <summary>
 /// Creates an instance from next header, checksum, care of nonce index, care of init cookie, care of keygen token and options.
 /// </summary>
 /// <param name="nextHeader">Identifies the type of header immediately following this extension header.</param>
 /// <param name="checksum">
 /// Contains the checksum of the Mobility Header.
 /// The checksum is calculated from the octet string consisting of a "pseudo-header"
 /// followed by the entire Mobility Header starting with the Payload Proto field.
 /// The checksum is the 16-bit one's complement of the one's complement sum of this string.
 /// </param>
 /// <param name="careOfNonceIndex">Will be echoed back by the mobile node to the correspondent node in a subsequent Binding Update.</param>
 /// <param name="careOfInitCookie">Contains the care-of init cookie.</param>
 /// <param name="careOfKeygenToken">Contains the 64-bit care-of keygen token used in the return routability procedure.</param>
 /// <param name="options">Zero or more TLV-encoded mobility options.</param>
 public IpV6ExtensionHeaderMobilityCareOfTest(IpV4Protocol? nextHeader, ushort checksum, ushort careOfNonceIndex, ulong careOfInitCookie,
                                              ulong careOfKeygenToken, IpV6MobilityOptions options)
     : base(nextHeader, checksum, options, MessageDataOffset.Options)
 {
     CareOfNonceIndex = careOfNonceIndex;
     CareOfInitCookie = careOfInitCookie;
     CareOfKeygenToken = careOfKeygenToken;
 }
 /// <summary>
 /// Creates an instance from next header, checksum, home nonce index, home init cookie, home keygen token and options.
 /// </summary>
 /// <param name="nextHeader">Identifies the type of header immediately following this extension header.</param>
 /// <param name="checksum">
 /// Contains the checksum of the Mobility Header.
 /// The checksum is calculated from the octet string consisting of a "pseudo-header"
 /// followed by the entire Mobility Header starting with the Payload Proto field.
 /// The checksum is the 16-bit one's complement of the one's complement sum of this string.
 /// </param>
 /// <param name="homeNonceIndex">Will be echoed back by the mobile node to the correspondent node in a subsequent Binding Update.</param>
 /// <param name="homeInitCookie">Contains the home init cookie.</param>
 /// <param name="homeKeygenToken">Contains the 64-bit home keygen token used in the return routability procedure.</param>
 /// <param name="options">Zero or more TLV-encoded mobility options.</param>
 public IpV6ExtensionHeaderMobilityHomeTest(IpV4Protocol? nextHeader, ushort checksum, ushort homeNonceIndex, ulong homeInitCookie, ulong homeKeygenToken,
                                            IpV6MobilityOptions options)
     : base(nextHeader, checksum, options, MessageDataOffset.Options)
 {
     HomeNonceIndex = homeNonceIndex;
     HomeInitCookie = homeInitCookie;
     HomeKeygenToken = homeKeygenToken;
 }
 /// <summary>
 /// Creates an instance from next header, checksum, is unsolicited heartbeat response, is response, sequence number and options.
 /// </summary>
 /// <param name="nextHeader">Identifies the type of header immediately following this extension header.</param>
 /// <param name="checksum">
 /// Contains the checksum of the Mobility Header.
 /// The checksum is calculated from the octet string consisting of a "pseudo-header"
 /// followed by the entire Mobility Header starting with the Payload Proto field.
 /// The checksum is the 16-bit one's complement of the one's complement sum of this string.
 /// </param>
 /// <param name="isUnsolicitedHeartbeatResponse">Set to true in Unsolicited Heartbeat Response.</param>
 /// <param name="isResponse">
 /// Indicates whether the message is a request or a response. 
 /// When it's set to false, it indicates that the Heartbeat message is a request.
 /// When it's set to true, it indicates that the Heartbeat message is a response.
 /// </param>
 /// <param name="sequenceNumber">Sequence number used for matching the request to the reply.</param>
 /// <param name="options">Zero or more TLV-encoded mobility options.</param>
 public IpV6ExtensionHeaderMobilityHeartbeatMessage(IpV4Protocol? nextHeader, ushort checksum, bool isUnsolicitedHeartbeatResponse, bool isResponse,
                                                    uint sequenceNumber, IpV6MobilityOptions options)
     : base(nextHeader, checksum, options, MessageDataOffset.MobilityOptions)
 {
     IsUnsolicitedHeartbeatResponse = isUnsolicitedHeartbeatResponse;
     IsResponse = isResponse;
     SequenceNumber = sequenceNumber;
 }
 public IpV6ExtensionHeaderFragmentData(IpV4Protocol nextHeader, ushort fragmentOffset, bool moreFragments, uint identification)
     : base(nextHeader)
 {
     if (fragmentOffset > MaxFragmentOffset)
         throw new ArgumentOutOfRangeException("fragmentOffset", fragmentOffset, "Max value is " + MaxFragmentOffset);
     FragmentOffset = fragmentOffset;
     MoreFragments = moreFragments;
     Identification = identification;
 }
Exemplo n.º 29
0
        //Captures packets while issuing concurrent calls to update the GUI
        /// <summary>
        /// Capture packets and stores their information
        /// </summary>
        private void CapturePackets()
        {
            // Take the selected adapter
            PacketDevice selectedDevice = allDevices[this.deviceIndex];
            int          prevInd        = 0;

            // Open the device
            using (PacketCommunicator communicator =
                       selectedDevice.Open(65536,                                  // portion of the packet to capture
                                                                                   // 65536 guarantees that the whole packet will be captured on all the link layers
                                           PacketDeviceOpenAttributes.Promiscuous, // promiscuous mode
                                           1000))                                  // read timeout
            {
                communicator.SetFilter(filter);
                while (captFlag)
                {
                    PacketCommunicatorReceiveResult result = communicator.ReceivePacket(out Packet packet);
                    byte[] packetInfo;

                    switch (result)
                    {
                    case PacketCommunicatorReceiveResult.Timeout:
                        // Timeout elapsed
                        break;

                    case PacketCommunicatorReceiveResult.Ok:
                        IpV4Datagram ipv4 = packet.Ethernet.IpV4;
                        IpV4Protocol i    = ipv4.Protocol;

                        CougarPacket cp = new CougarPacket(packet.Timestamp.ToString("hh:mm:ss.fff"),
                                                           ++packetNumber,
                                                           packet.Length,
                                                           ipv4.Source.ToString(),
                                                           ipv4.Destination.ToString());

                        packetInfo = Encoding.ASCII.GetBytes(cp.ToString() + "\n");
                        packetBytes.Add(packetInfo);

                        this.Invoke((MethodInvoker)(() =>
                        {
                            packetView.Items.Add(new ListViewItem(cp.toPropertyArray()));

                            ++prevInd;
                            if (chkAutoScroll.Checked && prevInd > 12)
                            {
                                packetView.Items[packetView.Items.Count - 1].EnsureVisible();
                                prevInd = 0;
                            }
                        }));
                        break;

                    default:
                        throw new InvalidOperationException("The result " + result + " should never be reached here");
                    }
                }
            }
        }
 /// <summary>
 /// Creates an instance from next header, checksum, home agent addresses and options.
 /// </summary>
 /// <param name="nextHeader">Identifies the type of header immediately following this extension header.</param>
 /// <param name="checksum">
 /// Contains the checksum of the Mobility Header.
 /// The checksum is calculated from the octet string consisting of a "pseudo-header"
 /// followed by the entire Mobility Header starting with the Payload Proto field.
 /// The checksum is the 16-bit one's complement of the one's complement sum of this string.
 /// </param>
 /// <param name="homeAgentAddresses">A list of alternate home agent addresses for the mobile node.</param>
 /// <param name="options">Zero or more TLV-encoded mobility options.</param>
 public IpV6ExtensionHeaderMobilityHomeAgentSwitchMessage(IpV4Protocol? nextHeader, ushort checksum, ReadOnlyCollection<IpV6Address> homeAgentAddresses,
                                                          IpV6MobilityOptions options)
     : base(nextHeader, checksum, options,
            MessageDataOffset.HomeAgentAddresses + (homeAgentAddresses == null ? 0 : homeAgentAddresses.Count) * IpV6Address.SizeOf)
 {
     if (homeAgentAddresses == null)
         throw new ArgumentNullException("homeAgentAddresses");
     HomeAgentAddresses = homeAgentAddresses;
 }
 /// <summary>
 /// Creates an instance from next header, checksum, sequence number, assigned address configuration, buffer, code and options.
 /// </summary>
 /// <param name="nextHeader">Identifies the type of header immediately following this extension header.</param>
 /// <param name="checksum">
 /// Contains the checksum of the Mobility Header.
 /// The checksum is calculated from the octet string consisting of a "pseudo-header"
 /// followed by the entire Mobility Header starting with the Payload Proto field.
 /// The checksum is the 16-bit one's complement of the one's complement sum of this string.
 /// </param>
 /// <param name="sequenceNumber">Must be set by the sender so replies can be matched to this message.</param>
 /// <param name="assignedAddressConfiguration">
 /// Assigned address configuration flag.  
 /// When set to true, this message requests a new CoA to be returned by the destination.
 /// May be set when Code = 0. Must be false when Code = 1.
 /// </param>
 /// <param name="buffer">
 /// When set, the destination should buffer any packets toward the node indicated in the options of this message.
 /// Used when Code = 0, should be set to false when Code = 1.
 /// </param>
 /// <param name="code">Describes whether the source ip address is a previous care of address.</param>
 /// <param name="options">Zero or more TLV-encoded mobility options.</param>
 public IpV6ExtensionHeaderMobilityHandoverInitiateMessage(IpV4Protocol? nextHeader, ushort checksum, ushort sequenceNumber, bool assignedAddressConfiguration,
                                                           bool buffer, IpV6HandoverInitiateMessageCode code, IpV6MobilityOptions options)
     : base(nextHeader, checksum, options, MessageDataOffset.Options)
 {
     SequenceNumber = sequenceNumber;
     AssignedAddressConfiguration = assignedAddressConfiguration;
     Buffer = buffer;
     Code = code;
 }
 internal IpV6ExtensionHeaderMobilityBindingRevocationMessage(IpV4Protocol? nextHeader, ushort checksum, ushort sequenceNumber, bool proxyBinding,
                                                              bool ipV4HomeAddressBindingOnly, bool global, IpV6MobilityOptions options)
     : base(nextHeader, checksum, options, MessageDataOffset.Options)
 {
     SequenceNumber = sequenceNumber;
     ProxyBinding = proxyBinding;
     IpV4HomeAddressBindingOnly = ipV4HomeAddressBindingOnly;
     Global = global;
 }
 /// <summary>
 /// Creates an instance from next header, checksum and message data.
 /// </summary>
 /// <param name="nextHeader">
 /// Identifies the type of header immediately following this extension header.
 /// </param>
 /// <param name="checksum">
 /// Contains the checksum of the Mobility Header.
 /// The checksum is calculated from the octet string consisting of a "pseudo-header"
 /// followed by the entire Mobility Header starting with the Payload Proto field.
 /// The checksum is the 16-bit one's complement of the one's complement sum of this string.
 /// </param>
 /// <param name="messageData">
 /// Carries the data specific to the experimental protocol extension.
 /// </param>
 public IpV6ExtensionHeaderMobilityExperimental(IpV4Protocol? nextHeader, ushort checksum, DataSegment messageData)
     : base(nextHeader, checksum, IpV6MobilityOptions.None, null)
 {
     if (messageData == null) 
         throw new ArgumentNullException("messageData");
     if (messageData.Length % 8 != 2)
         throw new ArgumentException("Message data size must be an integral product of 8 bytes plus 2 bytes", "messageData");
     MessageData = messageData;
 }
 /// <summary>
 /// Creates an instance from next header, checksum, status, key management mobility capability, mobile router, proxy registration, TLV header format,
 /// sequence number, lifetime and options.
 /// </summary>
 /// <param name="nextHeader">Identifies the type of header immediately following this extension header.</param>
 /// <param name="checksum">
 /// Contains the checksum of the Mobility Header.
 /// The checksum is calculated from the octet string consisting of a "pseudo-header"
 /// followed by the entire Mobility Header starting with the Payload Proto field.
 /// The checksum is the 16-bit one's complement of the one's complement sum of this string.
 /// </param>
 /// <param name="status">
 /// Indicating the disposition of the Binding Update.
 /// Values of the Status field less than 128 indicate that the Binding Update was accepted by the receiving node.
 /// Values greater than or equal to 128 indicate that the Binding Update was rejected by the receiving node.
 /// </param>
 /// <param name="keyManagementMobilityCapability">
 /// If this is cleared, the protocol used by the home agent for establishing the IPsec security associations between the mobile node and the home agent
 /// does not survive movements.
 /// It may then have to be rerun.
 /// (Note that the IPsec security associations themselves are expected to survive movements.)
 /// </param>
 /// <param name="mobileRouter">
 /// Indicates that the Home Agent that processed the Binding Update supports Mobile Routers.
 /// True only if the corresponding Binding Update had the Mobile Router set to true.
 /// </param>
 /// <param name="proxyRegistration">
 /// Indicates that the local mobility anchor that processed the corresponding Proxy Binding Update message supports proxy registrations.
 /// True only if the corresponding Proxy Binding Update had the Proxy Registration set to true.
 /// </param>
 /// <param name="typeLengthValueHeaderFormat">
 /// Indicates that the sender of the Proxy Binding Acknowledgement, the LMA, supports tunneling IPv6-or-IPv4 in IPv4 using TLV-header format.
 /// </param>
 /// <param name="sequenceNumber">
 /// Copied from the Sequence Number field in the Binding Update.
 /// It is used by the mobile node in matching this Binding Acknowledgement with an outstanding Binding Update.
 /// </param>
 /// <param name="lifetime">
 /// The granted lifetime, in time units of 4 seconds for Binding Acknowledgement and 1 second for Fast Binding Acknowledgement, 
 /// for which this node should retain the entry for this mobile node in its Binding Cache.
 /// </param>
 /// <param name="options">Zero or more TLV-encoded mobility options.</param>
 public IpV6ExtensionHeaderMobilityBindingAcknowledgement(IpV4Protocol? nextHeader, ushort checksum, IpV6BindingAcknowledgementStatus status,
                                                          bool keyManagementMobilityCapability, bool mobileRouter, bool proxyRegistration,
                                                          bool typeLengthValueHeaderFormat, ushort sequenceNumber, ushort lifetime, IpV6MobilityOptions options)
     : base(nextHeader, checksum, status, keyManagementMobilityCapability, sequenceNumber, lifetime, options)
 {
     MobileRouter = mobileRouter;
     ProxyRegistration = proxyRegistration;
     TypeLengthValueHeaderFormat = typeLengthValueHeaderFormat;
 }
Exemplo n.º 35
0
        internal sealed override void Write(byte[] buffer, ref int offset, IpV4Protocol nextHeader)
        {
            buffer.Write(offset + Offset.NextHeader, (byte)nextHeader);
            int length = Length;

            buffer.Write(offset + Offset.HeaderExtensionLength, (byte)((length / 8) - 1));
            WriteData(buffer, offset + Offset.Data);
            offset += length;
        }
Exemplo n.º 36
0
        public static IpV6ExtensionHeader NextIpV6ExtensionHeader(this Random random, IpV4Protocol? nextHeader, bool isEncapsulatingSecurityPayloadPossible)
        {
            IpV4Protocol extensionHeaderType =
                random.NextValue(
                    IpV6ExtensionHeader.ExtensionHeaders.Where(extensionHeader => isEncapsulatingSecurityPayloadPossible ||
                                                                                  extensionHeader != IpV4Protocol.EncapsulatingSecurityPayload).ToList());
            switch (extensionHeaderType)
            {
                case IpV4Protocol.IpV6HopByHopOption: // 0
                    return new IpV6ExtensionHeaderHopByHopOptions(nextHeader, random.NextIpV6Options());

                case IpV4Protocol.IpV6Route: // 43
                    IpV6RoutingType routingType = random.NextEnum(IpV6RoutingType.Nimrod);
                    switch (routingType)
                    {
                        case IpV6RoutingType.SourceRoute:
                            return new IpV6ExtensionHeaderRoutingSourceRoute(nextHeader, random.NextByte(), random.NextIpV6AddressArray(random.NextInt(0, 10)));

                        case IpV6RoutingType.Type2RoutingHeader:
                            return new IpV6ExtensionHeaderRoutingHomeAddress(nextHeader, random.NextByte(), random.NextIpV6Address());

                        case IpV6RoutingType.RoutingProtocolLowPowerAndLossyNetworksSourceRouteHeader:
                            byte commonPrefixLengthForNonLastAddresses = random.NextByte(IpV6ExtensionHeaderRoutingProtocolLowPowerAndLossyNetworks.MaxCommonPrefixLength + 1);
                            byte commonPrefixLengthForLastAddress = random.NextByte(IpV6ExtensionHeaderRoutingProtocolLowPowerAndLossyNetworks.MaxCommonPrefixLength + 1);
                            IpV6Address[] addresses = random.NextIpV6AddressWithLeadingZeroBytesArray(commonPrefixLengthForNonLastAddresses,
                                                                                                      random.NextInt(0, 10));
                            if (addresses.Any() || random.NextBool())
                                addresses = addresses.Concat(random.NextIpV6AddressWithLeadingZeroBytes(commonPrefixLengthForLastAddress)).ToArray();
                            return new IpV6ExtensionHeaderRoutingProtocolLowPowerAndLossyNetworks(nextHeader, random.NextByte(), commonPrefixLengthForNonLastAddresses,
                                                                     commonPrefixLengthForLastAddress, addresses);

                        default:
                            throw new InvalidOperationException(string.Format("Invalid routingType value {0}", routingType));
                    }

                case IpV4Protocol.FragmentHeaderForIpV6: // 44
                    return new IpV6ExtensionHeaderFragmentData(nextHeader, random.NextUShort(IpV6ExtensionHeaderFragmentData.MaxFragmentOffset + 1),
                                                               random.NextBool(), random.NextUInt());

                case IpV4Protocol.IpV6Opts: // 60
                    IpV6Options options = random.NextIpV6Options();
                    return new IpV6ExtensionHeaderDestinationOptions(nextHeader, options);

                case IpV4Protocol.MobilityHeader: // 135
                    return random.NextIpV6ExtensionHeaderMobility(nextHeader);

                case IpV4Protocol.EncapsulatingSecurityPayload: // 50
                    return new IpV6ExtensionHeaderEncapsulatingSecurityPayload(random.NextUInt(), random.NextUInt(), random.NextDataSegment(random.Next(100)));

                case IpV4Protocol.AuthenticationHeader: // 51
                    return new IpV6ExtensionHeaderAuthentication(nextHeader, random.NextUInt(), random.NextUInt(), random.NextDataSegment(random.Next(25) * 4));

                default:
                    throw new InvalidOperationException(string.Format("Invalid extensionHeaderType value {0}", extensionHeaderType));
            }
        }
        internal static IpV6ExtensionHeaderMobilityLocalizedRoutingInitiation ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
        {
            ushort sequenceNumber;
            ushort lifetime;
            IpV6MobilityOptions options;
            if (!ParseMessageDataToFields(messageData, out sequenceNumber, out lifetime, out options))
                return null;

            return new IpV6ExtensionHeaderMobilityLocalizedRoutingInitiation(nextHeader, checksum, sequenceNumber, lifetime, options);
        }
 internal IpV6ExtensionHeaderMobilityBindingAcknowledgementBase(IpV4Protocol? nextHeader, ushort checksum, IpV6BindingAcknowledgementStatus status,
                                                                bool keyManagementMobilityCapability, ushort sequenceNumber, ushort lifetime,
                                                                IpV6MobilityOptions options)
     : base(nextHeader, checksum, options, MessageDataOffset.Options)
 {
     Status = status;
     KeyManagementMobilityCapability = keyManagementMobilityCapability;
     SequenceNumber = sequenceNumber;
     Lifetime = lifetime;
 }
        internal static IpV6ExtensionHeaderFragmentData ParseData(IpV4Protocol nextHeader, DataSegment data)
        {
            if (data.Length != DataLength)
                return null;

            ushort fragmentOffset = (ushort)((data.ReadUShort(DataOffset.FragmentOffset, Endianity.Big) & DataMask.FragmentOffset) >> DataShift.FragmentOffset);
            bool moreFragments = data.ReadBool(DataOffset.MoreFragments, DataMask.MoreFragments);
            uint identification = data.ReadUInt(DataOffset.Identification, Endianity.Big);

            return new IpV6ExtensionHeaderFragmentData(nextHeader, fragmentOffset, moreFragments, identification);
        }
        internal override void Write(byte[] buffer, ref int offset, IpV4Protocol nextHeader)
        {
            buffer.Write(offset + Offset.NextHeader, (byte)(nextHeader));
            int length = Length;

            buffer.Write(offset + Offset.PayloadLength, (byte)((length / 4) - 2));
            buffer.Write(offset + Offset.SecurityParametersIndex, SecurityParametersIndex, Endianity.Big);
            buffer.Write(offset + Offset.SequenceNumber, SequenceNumber, Endianity.Big);
            AuthenticationData.Write(buffer, offset + Offset.AuthenticationData);
            offset += length;
        }
        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 IpV6ExtensionHeaderMobilityBindingUpdateBase(IpV4Protocol? nextHeader, ushort checksum, ushort sequenceNumber, bool acknowledge,
                                                       bool homeRegistration, bool linkLocalAddressCompatibility, bool keyManagementMobilityCapability,
                                                       ushort lifetime, IpV6MobilityOptions options)
     : base(nextHeader, checksum, options, MessageDataOffset.Options)
 {
     SequenceNumber = sequenceNumber;
     Acknowledge = acknowledge;
     HomeRegistration = homeRegistration;
     LinkLocalAddressCompatibility = linkLocalAddressCompatibility;
     KeyManagementMobilityCapability = keyManagementMobilityCapability;
     Lifetime = lifetime;
 }
Exemplo n.º 43
0
        internal static IpV6ExtensionHeaderMobilityCareOfTestInit ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
        {
            if (messageData.Length < MinimumMessageDataLength)
            {
                return(null);
            }

            ulong careOfInitCookie      = messageData.ReadULong(MessageDataOffset.CareOfInitCookie, Endianity.Big);
            IpV6MobilityOptions options = new IpV6MobilityOptions(messageData.Subsegment(MessageDataOffset.Options, messageData.Length - MessageDataOffset.Options));

            return(new IpV6ExtensionHeaderMobilityCareOfTestInit(nextHeader, checksum, careOfInitCookie, options));
        }
Exemplo n.º 44
0
 public static IpV6ExtensionHeaders NextIpV6ExtensionHeaders(this Random random, int count, IpV4Protocol? nextHeader, bool allowEncapsulatingSecurityPayload)
 {
     if (count == 0)
         return IpV6ExtensionHeaders.Empty;
     IpV6ExtensionHeader[] headers = new IpV6ExtensionHeader[count];
     for (int i = headers.Length - 1; i >= 0; --i)
     {
         headers[i] = random.NextIpV6ExtensionHeader(nextHeader, allowEncapsulatingSecurityPayload && i == headers.Length - 1);
         nextHeader = headers[i].Protocol;
     }
     return new IpV6ExtensionHeaders(headers);
 }
        internal override DnsResourceData CreateInstance(DataSegment data)
        {
            if (data.Length < ConstantPartLength)
            {
                return(null);
            }

            IpV4Address  address  = data.ReadIpV4Address(Offset.Address, Endianity.Big);
            IpV4Protocol protocol = (IpV4Protocol)data[Offset.Protocol];
            DataSegment  bitmap   = data.Subsegment(Offset.Bitmap, data.Length - Offset.Bitmap);

            return(new DnsResourceDataWellKnownService(address, protocol, bitmap));
        }
Exemplo n.º 46
0
        internal static IpV6ExtensionHeaderFragmentData ParseData(IpV4Protocol nextHeader, DataSegment data)
        {
            if (data.Length != ExtensionHeaderDataLength)
            {
                return(null);
            }

            ushort fragmentOffset = (ushort)((data.ReadUShort(DataOffset.FragmentOffset, Endianity.Big) & DataMask.FragmentOffset) >> DataShift.FragmentOffset);
            bool   moreFragments  = data.ReadBool(DataOffset.MoreFragments, DataMask.MoreFragments);
            uint   identification = data.ReadUInt(DataOffset.Identification, Endianity.Big);

            return(new IpV6ExtensionHeaderFragmentData(nextHeader, fragmentOffset, moreFragments, identification));
        }
Exemplo n.º 47
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 IpV6ExtensionHeaderMobilityFastBindingAcknowledgement ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
        {
            IpV6BindingAcknowledgementStatus status;
            bool keyManagementMobilityCapability;
            ushort sequenceNumber;
            ushort lifetime;
            IpV6MobilityOptions options;
            if (!ParseMessageDataFields(messageData, out status, out keyManagementMobilityCapability, out sequenceNumber, out lifetime, out options))
                return null;

            return new IpV6ExtensionHeaderMobilityFastBindingAcknowledgement(nextHeader, checksum, status, keyManagementMobilityCapability, sequenceNumber,
                                                                             lifetime, options);
        }
        internal static IpV6ExtensionHeaderMobilityHeartbeatMessage ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
        {
            if (messageData.Length < MinimumMessageDataLength)
            {
                return(null);
            }

            bool isUnsolicitedHeartbeatResponse = messageData.ReadBool(MessageDataOffset.IsUnsolicitedHeartbeatResponse, MessageDataMask.IsUnsolicitedHeartbeatResponse);
            bool isResponse             = messageData.ReadBool(MessageDataOffset.IsResponse, MessageDataMask.IsResponse);
            uint sequenceNumber         = messageData.ReadUInt(MessageDataOffset.SequenceNumber, Endianity.Big);
            IpV6MobilityOptions options = new IpV6MobilityOptions(messageData.Subsegment(MessageDataOffset.MobilityOptions, messageData.Length - MessageDataOffset.MobilityOptions));

            return(new IpV6ExtensionHeaderMobilityHeartbeatMessage(nextHeader, checksum, isUnsolicitedHeartbeatResponse, isResponse, sequenceNumber, options));
        }
Exemplo n.º 50
0
        internal static IpV6ExtensionHeaderMobilityHomeTest ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
        {
            if (messageData.Length < MinimumMessageDataLength)
            {
                return(null);
            }

            ushort homeNonceIndex       = messageData.ReadUShort(MessageDataOffset.HomeNonceIndex, Endianity.Big);
            ulong  homeInitCookie       = messageData.ReadULong(MessageDataOffset.HomeInitCookie, Endianity.Big);
            ulong  homeKeygenToken      = messageData.ReadULong(MessageDataOffset.HomeKeygenToken, Endianity.Big);
            IpV6MobilityOptions options = new IpV6MobilityOptions(messageData.Subsegment(MessageDataOffset.Options, messageData.Length - MessageDataOffset.Options));

            return(new IpV6ExtensionHeaderMobilityHomeTest(nextHeader, checksum, homeNonceIndex, homeInitCookie, homeKeygenToken, 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);
        }
Exemplo n.º 52
0
        internal static bool IsStandard(IpV4Protocol nextHeader)
        {
            switch (nextHeader)
            {
            case IpV4Protocol.IpV6HopByHopOption:    // 0
            case IpV4Protocol.IpV6Route:             // 43
            case IpV4Protocol.FragmentHeaderForIpV6: // 44
            case IpV4Protocol.IpV6Opts:              // 60
            case IpV4Protocol.MobilityHeader:        // 135
                return(true);

            default:
                return(false);
            }
        }
Exemplo n.º 53
0
        /// <summary>
        /// Gets user packet with values to copy from to other packets
        /// </summary>
        /// <param name="isFilteringByProtocolEnabled">If filtering is enabled, then autosending is possible</param>
        /// <returns>New packet with ONLY user values in it, all other values are set to default state</returns>
        private INewPacket GetPacketFilledWithUserValuesToCopyFrom(IpV4Protocol ipV4Protocol, bool isSendingEnabled)
        {
            INewPacket packetWithUserValuesToModify = _packetFactory.GetPacketByProtocol(ipV4Protocol)
                                                      .ModifyLayers(); // Give user default packet to fill with his values, so we would know, what values to modify in all other packets

            _userExperience.UserTextDisplayer.PrintText("Now all packets will be modified according to changed values in new packet, press any key to continue...");
            if (!isSendingEnabled)
            {
                _userExperience.UserTextDisplayer.PrintText("NOTE: Packet sending is disabled, modified packets will NOT be sended!");
            }

            Console.ReadKey();

            return(packetWithUserValuesToModify);
        }
Exemplo n.º 54
0
        // Callback function invoked by Pcap.Net for ps4 udp messages
        private void PacketHandlerUdp(Packet packet)
        {
            IpV4Datagram ip       = packet.Ethernet.IpV4;
            IpV4Protocol protocol = ip.Protocol;

            if (protocol == IpV4Protocol.Udp)
            {
                PcapDotNet.Packets.Transport.UdpDatagram udpDatagram = ip.Udp;
                if (udpDatagram.Length > 0 && udpDatagram.Payload.Length > 0 && _livePcapContext.Session != null)
                {
                    byte[] payload = udpDatagram.Payload.ToMemoryStream().ToArray();

                    HandleControlMessage(payload, _livePcapContext.Session);
                }
            }
        }
Exemplo n.º 55
0
        private static bool IsExtensionHeader(IpV4Protocol nextHeader)
        {
            switch (nextHeader)
            {
            case IpV4Protocol.IpV6HopByHopOption:               // 0
            case IpV4Protocol.IpV6Route:                        // 43
            case IpV4Protocol.FragmentHeaderForIpV6:            // 44
            case IpV4Protocol.EncapsulatingSecurityPayload:     // 50
            case IpV4Protocol.AuthenticationHeader:             // 51
            case IpV4Protocol.IpV6Opts:                         // 60
            case IpV4Protocol.MobilityHeader:                   // 135
                return(true);

            default:
                return(false);
            }
        }
Exemplo n.º 56
0
        protected override bool CalculateIsValid()
        {
            if (this.Length < 20 || this.Length < this.HeaderLength || !this.IsHeaderChecksumCorrect)
            {
                return(false);
            }
            IpV4Protocol protocol = this.Protocol;

            if ((uint)protocol <= 6U)
            {
                switch (protocol)
                {
                case IpV4Protocol.InternetControlMessageProtocol:
                    return(this.Icmp.IsValid);

                case IpV4Protocol.InternetGroupManagementProtocol:
                    return(this.Igmp.IsValid);

                case IpV4Protocol.Tcp:
                    break;

                default:
                    goto label_14;
                }
            }
            else if (protocol != IpV4Protocol.Udp)
            {
                if (protocol == IpV4Protocol.Gre)
                {
                    return(this.Gre.IsValid);
                }
                goto label_14;
            }
            if (!this.Transport.IsValid)
            {
                return(false);
            }
            if (!this.Transport.IsChecksumOptional || (int)this.Transport.Checksum != 0)
            {
                return(this.IsTransportChecksumCorrect);
            }
            return(true);

label_14:
            return(true);
        }
        internal static bool IsExtensionHeader(IpV4Protocol nextHeader)
        {
            if (IpV6ExtensionHeaderStandard.IsStandard(nextHeader))
            {
                return(true);
            }

            switch (nextHeader)
            {
            case IpV4Protocol.EncapsulatingSecurityPayload: // 50
            case IpV4Protocol.AuthenticationHeader:         // 51
                return(true);

            default:
                return(false);
            }
        }
Exemplo n.º 58
0
        // Callback function invoked by Pcap.Net for ps4 tcp messages
        private void PacketHandlerTcp(Packet packet)
        {
            IpV4Datagram ip       = packet.Ethernet.IpV4;
            IpV4Protocol protocol = ip.Protocol;

            if (protocol == IpV4Protocol.Tcp)
            {
                TcpDatagram  tcpDatagram  = ip.Tcp;
                HttpDatagram httpDatagram = tcpDatagram.Http;
                if (httpDatagram.Length > 0 && httpDatagram.Header != null)
                {
                    string httpPacket = httpDatagram.Decode(Encoding.UTF8);
                    if (httpPacket.StartsWith("GET /sce/rp/session HTTP/1.1\r\n"))
                    {
                        Dictionary <string, string> header = HttpUtils.SplitHttpResponse(httpPacket);
                        header.TryGetValue("RP-Registkey", out var registKey);
                        this.textBoxPcapLogOutput.Invoke(new MethodInvoker(() => AppendLogOutputToPcapLogTextBox("RP-Registkey: " + registKey)));

                        _livePcapContext.LivePcapState = LivePcapState.SESSION_REQUEST;
                        _livePcapContext.Session       = null;
                    }
                    else if (httpDatagram.IsResponse && httpPacket.StartsWith("HTTP/1.1 200 OK\r\n") && _livePcapContext.LivePcapState == LivePcapState.SESSION_REQUEST)
                    {
                        Dictionary <string, string> header = HttpUtils.SplitHttpResponse(httpPacket);
                        header.TryGetValue("RP-Nonce", out var rpNonce);
                        if (rpNonce == null)
                        {
                            return;
                        }

                        byte[] rpKeyBuffer    = HexUtil.Unhexlify(_settingManager.GetRemotePlayData().RemotePlay.RpKey);
                        byte[] rpNonceDecoded = Convert.FromBase64String(rpNonce);

                        this.textBoxPcapLogOutput.Invoke(new MethodInvoker(() => AppendLogOutputToPcapLogTextBox("RP-Nonce from \"/sce/rp/session\" response: " + HexUtil.Hexlify(rpNonceDecoded))));

                        string controlAesKey = HexUtil.Hexlify(CryptoService.GetSessionAesKeyForControl(rpKeyBuffer, rpNonceDecoded));
                        string controlNonce  = HexUtil.Hexlify(CryptoService.GetSessionNonceValueForControl(rpNonceDecoded));
                        this.textBoxPcapLogOutput.Invoke(new MethodInvoker(() => AppendLogOutputToPcapLogTextBox("!!! Control AES Key: " + controlAesKey)));
                        this.textBoxPcapLogOutput.Invoke(new MethodInvoker(() => AppendLogOutputToPcapLogTextBox("!!! Control AES Nonce: " + controlNonce + Environment.NewLine)));
                        _livePcapContext.LivePcapState = LivePcapState.SESSION_RESPONSE;
                        _livePcapContext.Session       = CryptoService.GetSessionForControl(rpKeyBuffer, rpNonceDecoded);
                    }
                }
            }
        }
        internal static IpV6ExtensionHeader CreateInstance(IpV4Protocol nextHeader, DataSegment extensionHeaderData, out int numBytesRead)
        {
            if (IpV6ExtensionHeaderStandard.IsStandard(nextHeader))
            {
                return(IpV6ExtensionHeaderStandard.CreateInstanceStandard(nextHeader, extensionHeaderData, out numBytesRead));
            }

            switch (nextHeader)
            {
            case IpV4Protocol.EncapsulatingSecurityPayload:     // 50
                return(IpV6ExtensionHeaderEncapsulatingSecurityPayload.CreateInstance(extensionHeaderData, out numBytesRead));

            case IpV4Protocol.AuthenticationHeader:     // 51
                return(IpV6ExtensionHeaderAuthentication.CreateInstance(extensionHeaderData, out numBytesRead));

            default:
                throw new InvalidOperationException("Invalid next header value" + nextHeader);
            }
        }
Exemplo n.º 60
0
        internal static IpV6ExtensionHeader CreateInstanceStandard(IpV4Protocol nextHeader, DataSegment extensionHeaderData, out int numBytesRead)
        {
            numBytesRead = 0;
            if (extensionHeaderData.Length < MinimumLength)
            {
                return(null);
            }
            IpV4Protocol nextNextHeader = (IpV4Protocol)extensionHeaderData[Offset.NextHeader];
            int          length         = (extensionHeaderData[Offset.HeaderExtensionLength] + 1) * 8;

            if (extensionHeaderData.Length < length)
            {
                return(null);
            }

            DataSegment data = extensionHeaderData.Subsegment(Offset.Data, length - Offset.Data);

            numBytesRead = length;

            // TODO: Implement Shim6.
            switch (nextHeader)
            {
            case IpV4Protocol.IpV6HopByHopOption:     // 0
                return(IpV6ExtensionHeaderHopByHopOptions.ParseData(nextNextHeader, data));

            case IpV4Protocol.IpV6Route:     // 43
                return(IpV6ExtensionHeaderRouting.ParseData(nextNextHeader, data));

            case IpV4Protocol.FragmentHeaderForIpV6:     // 44
                return(IpV6ExtensionHeaderFragmentData.ParseData(nextNextHeader, data));

            case IpV4Protocol.IpV6Opts:                         // 60
                return(IpV6ExtensionHeaderDestinationOptions.ParseData(nextNextHeader, data));

            case IpV4Protocol.MobilityHeader:            // 135
                return(IpV6ExtensionHeaderMobility.ParseData(nextNextHeader, data));

            default:
                throw new InvalidOperationException("Invalid next header value" + nextHeader);
            }
        }