コード例 #1
0
        public static Boolean SetEntityIdForRawPacket(RawPacket rawPacket, Int32 maxNumberOfShards)
        {
            var entityId = -1;

            if (!RawPacketSignatureParser.ExtractRawPacketSignature(rawPacket, out var sourceIpAddress, out var destinationIpAddress, out var sourcePort,
                                                                    out var destinationPort, out var ipProtocol, out var ipv4FragmentSignature))
            {
                return(false);
            }

            if (ipv4FragmentSignature == null)
            {
                var l3L4ConversationKey = new L3L4ConversationKey(sourceIpAddress, destinationIpAddress, sourcePort, destinationPort, ipProtocol);
                entityId = l3L4ConversationKey.GetHashCode() % maxNumberOfShards;
            }
            else
            {
                // TODO fragments handling
                return(false);
            }

            Debug.Assert(entityId >= 0 && entityId < maxNumberOfShards);
            rawPacket.EntityId = entityId;

            return(true);
        }
コード例 #2
0
        protected IMaybeMultipleValues <RawPacket> ParsePacket(RawCapture rawCapture)
        {
            if (rawCapture == null)
            {
                return(new ProcessRawPacketRequestError("Missing packet payload"));
            }


//      return new RawPacket(rawCapture) {EntityId = 0};



            Packet parsedPacket;

            try
            {
                parsedPacket = Packet.ParsePacket(rawCapture.LinkLayerType, rawCapture.Data);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                return(new ProcessRawPacketRequestError($"Parsing error {ex}"));
            }

            // Ignore non-IP traffic (STP, ... )
            if (!(parsedPacket?.PayloadPacket is IPPacket ipPacket))
            {
                return(new ProcessRawPacketRequestError("Non-IP packet"));
            }

            // Attempt to defragment
            if (ipPacket is IPv4Packet ipv4Packet && Ipv4Helpers.Ipv4PacketIsFragmented(ipv4Packet))
            {
                var(isDefragmentationSuccessful, firstTimestamp, defragmentedIpv4Packet) =
                    this.IPIpv4DefragmentationEngine.TryDefragmentFragments(
                        FrameFactory.CreateFromIpPacket(ipv4Packet, rawCapture.Timeval.Date.Ticks));
                if (!isDefragmentationSuccessful)
                {
                    return(ProcessRawPacketFragmentsRequest.EmptyInstance);
                }

                var defragmentedL3L4Key = new L3L4ConversationKey(defragmentedIpv4Packet);
                return(new RawPacket(firstTimestamp, LinkLayers.Raw, defragmentedIpv4Packet.Bytes, defragmentedL3L4Key,
                                     this.MaxNumberOfShards));
            }

            // Ignore unsupported transport protocols
            var transportPacket = ipPacket.PayloadPacket;

            if (!(transportPacket is TcpPacket || transportPacket is UdpPacket))
            {
                return(new ProcessRawPacketRequestError("Unsupported transport protocol"));
            }

            var l3L4Key = new L3L4ConversationKey(ipPacket);

            return(new RawPacket(rawCapture, l3L4Key, this.MaxNumberOfShards));
        }
コード例 #3
0
        private L7ConversationTrackerBase GetOrCreateL7ReassemblerForFrame(Dictionary <L3L4ConversationKey, L7ConversationTrackerBase> trackers, Frame frame)
        {
            var conversationKey = new L3L4ConversationKey(frame);

            if (!trackers.TryGetValue(conversationKey, out var tracker))
            {
                switch (frame.IpProtocol)
                {
                case IPProtocolType.TCP:
                    tracker = new TcpConversationTracker(frame.SourceEndPoint, frame.DestinationEndPoint);
                    break;

                case IPProtocolType.UDP:
                    tracker = new UdpConversationTracker(frame.SourceEndPoint, frame.DestinationEndPoint);
                    break;

                default:
                    return(null);
                }
                trackers.Add(conversationKey, tracker);
            }
            return(tracker);
        }
コード例 #4
0
ファイル: RawPacket.cs プロジェクト: lulzzz/NTPAC
 public RawPacket(Int64 dateTimeTicks,
                  LinkLayers linkType,
                  Byte[] rawPacketData,
                  L3L4ConversationKey l3L4ConversationKey,
                  Int32 maxNumberOfShards) : this(dateTimeTicks, linkType, rawPacketData) =>
     this.EntityId = Math.Abs(l3L4ConversationKey.GetHashCode() % maxNumberOfShards);
コード例 #5
0
ファイル: RawPacket.cs プロジェクト: lulzzz/NTPAC
 public RawPacket(RawCapture rawCapture, L3L4ConversationKey l3L4ConversationKey, Int32 maxNumberOfShards) : this(
         rawCapture.Timeval.Date.Ticks, rawCapture.LinkLayerType, rawCapture.Data, l3L4ConversationKey, maxNumberOfShards)
 {
 }