Exemplo n.º 1
0
        private void ParseExtensionHeaders()
        {
            if (_extensionHeaders != null)
            {
                return;
            }

            List <IpV6ExtensionHeader> extensionHeaders = new List <IpV6ExtensionHeader>();

            if (HeaderLength > RealPayloadLength)
            {
                _isValid          = false;
                _extensionHeaders = extensionHeaders.AsReadOnly();
                return;
            }
            int          extendedHeaderLength = HeaderLength;
            IpV4Protocol?nextHeader           = NextHeader;

            while (extendedHeaderLength + 8 <= RealPayloadLength && nextHeader.HasValue && IsExtensionHeader(nextHeader.Value))
            {
                int numBytesRead;
                IpV6ExtensionHeader extensionHeader = IpV6ExtensionHeader.CreateInstance(nextHeader.Value,
                                                                                         Subsegment(extendedHeaderLength, Length - extendedHeaderLength),
                                                                                         out numBytesRead);
                if (extensionHeader == null)
                {
                    break;
                }
                nextHeader            = extensionHeader.NextHeader;
                extendedHeaderLength += numBytesRead;
            }
            _isValid                = (!nextHeader.HasValue || !IsExtensionHeader(nextHeader.Value)) && (HeaderLength + _extensionHeadersLength == PayloadLength);
            _extensionHeaders       = extensionHeaders.AsReadOnly();
            _extensionHeadersLength = extendedHeaderLength - HeaderLength;
        }
Exemplo n.º 2
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 sealed override bool EqualsData(IpV6ExtensionHeader other)
 {
     return EqualsData(other as IpV6ExtensionHeaderMobility);
 }
 internal sealed override bool EqualsData(IpV6ExtensionHeader other)
 {
     return(EqualsData(other as IpV6ExtensionHeaderMobility));
 }
Exemplo n.º 5
0
 internal sealed override bool EqualsData(IpV6ExtensionHeader other)
 {
     return EqualsData(other as IpV6ExtensionHeaderRouting);
 }
Exemplo n.º 6
0
 public void IpV6ExtensionHeadersConstructors()
 {
     IEnumerable<IpV6ExtensionHeader> extensionHeadersEnumerable = new IpV6ExtensionHeader[0];
     IList<IpV6ExtensionHeader> extensionHeadersIList = new IpV6ExtensionHeader[0];
     Assert.AreEqual(new IpV6ExtensionHeaders(extensionHeadersEnumerable), new IpV6ExtensionHeaders(extensionHeadersIList));
 }
 internal abstract bool EqualsData(IpV6ExtensionHeader other);
 /// <summary>
 /// True iff the given extension header is equal to this extension header.
 /// </summary>
 public override bool Equals(IpV6ExtensionHeader other)
 {
     return(Equals(other as IpV6ExtensionHeaderAuthentication));
 }
        private void ValidateExtensionHeaderUnnamedField(IpV6ExtensionHeader header, XElement headerField, ref int optionsIndex)
        {
            IpV6ExtensionHeaderOptions headerOptions = header as IpV6ExtensionHeaderOptions;

            string[] headerFieldShowParts = headerField.Show().Split(':');
            string headerFieldShowName = headerFieldShowParts[0];
            string headerFieldShowValue = headerFieldShowParts[1];
            switch (headerFieldShowName)
            {
                case "Next header":
                    headerField.AssertValue((byte)header.NextHeader.Value);
                    break;

                case "Length":
                    if (header.IsValid)
                        Assert.IsTrue(headerFieldShowValue.EndsWith(" (" + header.Length + " bytes)"));
                    break;

                case "Router alert":
                    IpV6OptionRouterAlert routerAlert = (IpV6OptionRouterAlert)headerOptions.Options[optionsIndex++];
                    switch (headerFieldShowValue)
                    {
                        case " MLD (4 bytes)":
                            Assert.AreEqual(IpV6RouterAlertType.MulticastListenerDiscovery, routerAlert.RouterAlertType);
                            break;

                        case " RSVP (4 bytes)":
                            Assert.AreEqual(IpV6RouterAlertType.Rsvp, routerAlert.RouterAlertType);
                            break;

                        case " Unknown (4 bytes)":
                            MoreAssert.IsInRange((ushort)IpV6RouterAlertType.ActiveNetwork, (ushort)IpV6RouterAlertType.NextStepsInSignalingNatFirewallLayerProtocol, (ushort)routerAlert.RouterAlertType);
                            headerField.AssertValueInRange(0x05020002, 0x05020044);
                            break;

                        default:
                            throw new InvalidOperationException("Invalid ipv6 header route Router alert value " + headerFieldShowValue);
                    }
                    break;

                case "Jumbo payload":
                    IpV6OptionJumboPayload jumboPayload = (IpV6OptionJumboPayload)headerOptions.Options[optionsIndex++];
                    Assert.AreEqual(" " + jumboPayload.JumboPayloadLength + " (6 bytes)", headerFieldShowValue);
                    break;

                default:
                    throw new InvalidOperationException("Invalid ipv6 header unnamed field show name " + headerFieldShowName);
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// True iff the given extension header is equal to this extension header.
 /// </summary>
 public sealed override bool Equals(IpV6ExtensionHeader other)
 {
     return(other != null &&
            Protocol == other.Protocol && NextHeader == other.NextHeader && EqualsData(other));
 }
 private void ValidateExtensionHeaderUnnamedField(IpV6ExtensionHeader header, XElement headerField)
 {
     int optionIndex = -1;
     ValidateExtensionHeaderUnnamedField(header, headerField, ref optionIndex);
 }
Exemplo n.º 12
0
 internal abstract bool EqualsData(IpV6ExtensionHeader other);
Exemplo n.º 13
0
 /// <summary>
 /// True iff the given extension header is equal to this extension header.
 /// </summary>
 public sealed override bool Equals(IpV6ExtensionHeader other)
 {
     return other != null &&
            Protocol == other.Protocol && NextHeader == other.NextHeader && EqualsData(other);
 }
Exemplo n.º 14
0
 internal override bool EqualsData(IpV6ExtensionHeader other)
 {
     return(EqualsData(other as IpV6ExtensionHeaderFragmentData));
 }
 internal override sealed bool EqualsData(IpV6ExtensionHeader other)
 {
     return EqualsData(other as IpV6ExtensionHeaderOptions);
 }
 /// <summary>
 /// True iff the given extension header is equal to this extension header.
 /// </summary>
 public override bool Equals(IpV6ExtensionHeader other)
 {
     return(Equals(other as IpV6ExtensionHeaderEncapsulatingSecurityPayload));
 }
 internal override bool EqualsData(IpV6ExtensionHeader other)
 {
     return EqualsData(other as IpV6ExtensionHeaderFragmentData);
 }