Beispiel #1
0
        /// <summary>
        /// Gets the key for Ethernet frame.
        /// </summary>
        /// <param name="frameBytes">Bytes that contains Ethernet frame.</param>
        /// <returns><see cref="FlowKey"/> for the provided Ethernet frame.</returns>
        public static FlowKey GetKeyForEthernetFrame(byte[] frameBytes)
        {
            var etherType    = EthernetFrame.GetEtherType(frameBytes);
            var etherPayload = EthernetFrame.GetPayloadBytes(frameBytes);

            Span <Byte> ipPayload     = stackalloc byte[0];
            var         protocol      = 0;
            Span <Byte> sourceAddress = stackalloc byte[4];
            Span <Byte> destinAddress = stackalloc byte[4];
            UInt16      sourcePort    = 0;
            UInt16      destinPort    = 0;

            switch (etherType)
            {
            case (ushort)EthernetFrame.EtherTypeEnum.Ipv4:
            {
                sourceAddress = Ipv4Packet.GetSourceAddress(etherPayload);
                destinAddress = Ipv4Packet.GetDestinationAddress(etherPayload);
                ipPayload     = Ipv4Packet.GetPayloadBytes(etherPayload);
                protocol      = Ipv4Packet.GetProtocol(etherPayload);
                break;
            }

            case (ushort)EthernetFrame.EtherTypeEnum.Ipv6:
            {
                sourceAddress = Ipv6Packet.GetSourceAddress(etherPayload);
                destinAddress = Ipv6Packet.GetDestinationAddress(etherPayload);
                ipPayload     = Ipv6Packet.GetPayloadBytes(etherPayload);
                protocol      = Ipv6Packet.GetProtocol(etherPayload);
                break;
            }

            default:
                break;
            }
            switch (protocol)
            {
            case 6:      // TCP
            {
                sourcePort = TcpSegment.GetSourcePort(ipPayload);
                destinPort = TcpSegment.GetDestinationPort(ipPayload);
                break;
            }

            case 17:     // UDP
            {
                sourcePort = UdpDatagram.GetSourcePort(ipPayload);
                destinPort = UdpDatagram.GetDestinationPort(ipPayload);
                break;
            }

            default:
                break;
            }
            // ok we have enough information for creating packet's flow key
            return(FlowKey.Create((byte)protocol, sourceAddress, sourcePort, destinAddress, destinPort));
        }
Beispiel #2
0
        private NetStatus OnPersistTimeout(Dispatcher.CallbackArgs timeoutArg)
        {
            //
            // NOTE: This is a hack. A proper TCP stack is supposed to
            // transmit a packet consisting of just one byte when probing the
            // remote host to see if it has reopened its receive window.
            // However, we prepacketize data, so we don't have that option.
            // Instead, we probe using full packets.
            //
            TcpSessionEventsSource.EventLog.LogTimeout(
                Uid,
                currentState.StateEnum,
                TcpTimeoutType.Persist);

            TcpSegment seg = null;

            if (retransmitQ.Count > 0)
            {
                // Use the oldest unacknowledged packet to probe
                seg = (TcpSegment)retransmitQ[0];
            }
            else
            {
                // Nothing in the retransmit queue; probe using the next
                // normal packet. This will transition the packet to the
                // retransmission queue.
                seg = GetNextPacket(true /*ignore window*/);
            }

            if (seg != null)
            {
                seg.Mux = BoundMux;
                NetStatus err = Protocol.OnProtocolSend(seg);
                assert    err == NetStatus.Code.PROTOCOL_OK;
            }

            if (currentState != TCPFSM.CLOSED)
            {
                // rearm
                StartPersistTimer();
            }

            return(NetStatus.Code.PROTOCOL_OK);
        }
Beispiel #3
0
        private void _read()
        {
            switch (Protocol)
            {
            case ProtocolEnum.Ipv6Nonxt: {
                _body = new NoNextHeader(m_io, this, m_root);
                break;
            }

            case ProtocolEnum.Ipv4: {
                _body = new Ipv4Packet(m_io);
                break;
            }

            case ProtocolEnum.Udp: {
                _body = new UdpDatagram(m_io);
                break;
            }

            case ProtocolEnum.Icmp: {
                _body = new IcmpPacket(m_io);
                break;
            }

            case ProtocolEnum.Hopopt: {
                _body = new OptionHopByHop(m_io, this, m_root);
                break;
            }

            case ProtocolEnum.Ipv6: {
                _body = new Ipv6Packet(m_io);
                break;
            }

            case ProtocolEnum.Tcp: {
                _body = new TcpSegment(m_io);
                break;
            }
            }
        }
Beispiel #4
0
 public TcpSegment(KaitaiStream p__io, KaitaiStruct p__parent = null, TcpSegment p__root = null) : base(p__io)
 {
     m_parent = p__parent;
     m_root   = p__root ?? this;
     _read();
 }