WO2017167098A1 - 一种tcp流重组方法和装置 - Google Patents

一种tcp流重组方法和装置 Download PDF

Info

Publication number
WO2017167098A1
WO2017167098A1 PCT/CN2017/077714 CN2017077714W WO2017167098A1 WO 2017167098 A1 WO2017167098 A1 WO 2017167098A1 CN 2017077714 W CN2017077714 W CN 2017077714W WO 2017167098 A1 WO2017167098 A1 WO 2017167098A1
Authority
WO
WIPO (PCT)
Prior art keywords
valid data
array
data packet
length
packet
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Ceased
Application number
PCT/CN2017/077714
Other languages
English (en)
French (fr)
Inventor
朱友志
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Alibaba Group Holding Ltd
Original Assignee
Alibaba Group Holding Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Alibaba Group Holding Ltd filed Critical Alibaba Group Holding Ltd
Publication of WO2017167098A1 publication Critical patent/WO2017167098A1/zh
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L49/00Packet switching elements
    • H04L49/90Buffering arrangements
    • H04L49/9057Arrangements for supporting packet reassembly or resequencing

Definitions

  • the present application relates to the field of computer technologies, and in particular, to a TCP stream reassembly method and a TCP stream reassembly device.
  • the TCP stream reassembly technique is a technique for restoring a network packet to an original data stream.
  • the most common and common TCP stream reassembly method is implemented by using a linked list to implement a TCP packet buffering. The specific steps are as follows:
  • the system creates an in-order packet queue and an out-of-order packet queue for storing the packets arriving in order and arriving in advance.
  • the data packet arrives in order, that is, the current data packet is a subsequent packet connected to the already arrived data packet, and the early arrival data packet refers to the current data packet that is not connected to the already arrived data packet. Message, but the arrival of the newspaper in advance In this case, the data packet should be placed in the out-of-order packet queue for later recombination.
  • the part reserved for disassembly needs to be inserted into the orderly arrival queue or arrive at the position specified by the queue in advance. Take the packets arriving in order as an example. First, it is necessary to judge whether the newly arrived data packet and the data packet that has been stored in the in-order arrival packet queue correspond to whether there is an overlapping portion of the storage space in the packet queue in order, and if there is no overlapping portion, the new arrival will be directly made.
  • the data packet is stored in the sequence to arrive at the packet queue, and if there is an overlapping portion, it is further determined whether the overlapped portion corresponds to the entire newly arrived data packet, and if so, the newly arrived data packet can be directly discarded, if not
  • the newly arrived packets are disassembled, the overlapping parts are discarded, and the reserved parts are stored in order to arrive at the packet queue.
  • embodiments of the present application have been made in order to provide a TCP stream recombining method and a corresponding TCP stream recombining apparatus that overcome the above problems or at least partially solve the above problems.
  • a TCP stream reorganization method including:
  • For a TCP connection create a first array belonging to the client, and/or a second array belonging to the server;
  • the valid data packet belongs to the client, storing valid data in the valid data packet to the first array belonging to the client according to the offset and the data length of the valid data packet;
  • the valid data in the valid data packet is stored to the second array belonging to the server according to the offset and the data length of the valid data packet.
  • the step of creating a first array belonging to the client and/or belonging to the second array of the server for a TCP connection comprises:
  • a first array belonging to the client is created, and/or a second array belonging to the server.
  • the step of creating a first array belonging to the client and/or belonging to the second array of the server for a TCP connection comprises:
  • the received data packet is a valid data packet containing a TCP payload, determining whether the valid data packet is the first valid data packet;
  • the valid data packet is the first valid data packet, determining whether the valid data packet belongs to the client;
  • the step of calculating an offset and a data length of the valid data packet for the valid data packet with the TCP payload under the TCP connection including:
  • the valid data packet belongs to the client, determining an offset of the valid data packet according to a difference between a TCP sequence number of the valid data packet and a pre-recorded first correction value; the first correcting offset The value is the initial sequence number +1 of the SYN packet belonging to the client;
  • the initial sequence number of the SYN packet is +1.
  • the method further includes:
  • a threshold If the sum of the offset of the valid data packet and the data length is greater than the array length of the first array, a new first array is created, and the array length of the new first array exceeds the original first array.
  • the data stored in the original first array is copied into the new first array, and the valid data of the unstored valid data packet is stored into the new first array.
  • the method further includes:
  • the data stored in the original second array is copied to the new second array, and the valid data of the unstored valid data packet is stored in the new second array.
  • it also includes:
  • the original first array After copying the data stored in the original first array into the new first array, the original first array is released.
  • it also includes:
  • the original second array After copying the data stored in the original second array into the new second array, the original second array is released.
  • the method before the step of creating a first array belonging to the client and/or belonging to the second array of the server for a TCP connection, the method further includes:
  • the initial sequence number ISN(S) of the server is recorded.
  • the step of creating a first array belonging to the client and/or belonging to the second array of the server for a TCP connection comprises:
  • a first array belonging to the client is created in memory, and/or a second array belonging to the server.
  • the step of outputting data in the first array and/or the second array after the current TCP connection ends includes:
  • Steps including:
  • the valid data of the valid data packet is stored at the offset position of the first array until the storage length is the data length.
  • the step of storing the valid data in the valid data packet to the second array belonging to the server according to the offset and the data length of the valid data packet include:
  • the valid data of the overlapping portion of the valid data packets is discarded.
  • the valid data of the valid data packet is stored at the offset position of the second array until the storage length is the data length.
  • the method further includes: outputting data in the first array and/or the second array after the current TCP connection ends.
  • the application also discloses a TCP stream reorganization device, including:
  • a first creating module adapted to create a first array belonging to the client for a TCP connection, and/or a second array belonging to the server;
  • a calculation module configured to calculate an offset and a data length of the valid data packet for a valid data packet with a TCP payload under the TCP connection;
  • a first storage module configured to: when the valid data packet belongs to the client, store the valid data in the valid data packet to the first array belonging to the client according to the offset and the data length of the valid data packet ;
  • the second storage module is adapted to store the valid data in the valid data packet to the second array belonging to the server according to the offset and the data length of the valid data packet when the valid data packet belongs to the server.
  • the first creating module includes:
  • the first creating submodule is adapted to create a first array belonging to the client and/or a second array belonging to the server after the TCP connection is successfully established.
  • the first creating module includes:
  • the TCP judging submodule is adapted to determine, when receiving the data packet of the TCP connection, whether the received data packet is a valid data packet containing a TCP payload; if the received data packet is a valid data packet containing a TCP payload , then enter the first judgment sub-module;
  • the first determining submodule is adapted to determine whether the valid data packet is the first valid data packet; if the valid data packet is the first valid data packet, enter the client determining submodule;
  • the client judgment submodule is adapted to determine whether the valid data packet belongs to the client; if the valid data packet belongs to the client, enter the first array creation submodule; if the valid data packet does not belong to the client, Enter the second array to create a submodule;
  • the first array creates a sub-module adapted to create a first array belonging to the client;
  • the second array creates a submodule and creates a second array belonging to the server.
  • the calculating module includes:
  • a data length calculation submodule configured to calculate a length of valid data in the valid data packet as a data length
  • a first offset calculation submodule configured to determine, when the valid data packet belongs to the client, an offset of the valid data packet according to a difference between a TCP sequence number of the valid data packet and a pre-recorded first correction value
  • the first correction error value is an initial sequence number +1 of the SYN packet belonging to the client;
  • a second offset calculation submodule configured to determine, when the valid data packet belongs to the server, an offset of the valid data packet according to a difference between a TCP sequence number of the valid data packet and a pre-recorded second correction value
  • the second correction error value is an initial sequence number +1 of the SYN packet belonging to the server.
  • the method further includes:
  • a first determining module configured to: when the valid data packet belongs to the client, determine whether the sum of the offset and the data length of the valid data packet is greater than an array length of the first array; if the valid data packet is The sum of the offset and the data length is greater than the array length of the first array, and then enters the first new array creation module;
  • a first new array creation module adapted to create a new first array, the array length of the new first array exceeding a first threshold of the first array
  • the first copy storage module is adapted to copy the data stored in the original first array into the new first array, and store the valid data of the unstored valid data packet into the new first array.
  • the method further includes:
  • a second determining module configured to: when the valid data packet belongs to the server, determine whether the sum of the offset and the data length of the valid data packet is greater than an array length of the second array; if the valid data packet is biased The sum of the shift amount and the data length is greater than the array length of the second array, and then enters the second new array creation module;
  • a second new array creation module adapted to create a new second array, the new second number The array length of the group exceeds the first threshold of the second array;
  • the second copy storage module is adapted to copy the data stored in the original second array into the new second array, and store the valid data of the unstored valid data packet into the new second array.
  • it also includes:
  • the first release module is adapted to release the original first array after copying the data stored in the original first array into the new first array.
  • it also includes:
  • the second release module is adapted to release the original second array after copying the data stored in the original second array into the new second array.
  • the method before the first creating the module, the method further includes:
  • the SYN packet judging module is adapted to: when receiving the SYN packet, determine that the SYN packet is from the client and from the server; if the SYN packet is from the client, enter the first recording module; if the SYN packet is from the server, Entering the second recording module;
  • a first recording module adapted to record an initial serial number of the client, ISN (C);
  • the second recording module is adapted to record the initial serial number ISN(S) of the server.
  • the first creating module includes:
  • the first memory creation sub-module is adapted to create a first array belonging to the client in memory and/or a second array belonging to the server for a TCP connection.
  • the output module includes:
  • a first output sub-module configured to, after receiving the data packet that is not instructed to close the connection under the TCP connection, determine that the idle time of the TCP connection exceeds the first time period, end the TCP connection, Output the data in the first array;
  • a second output submodule configured to: after receiving the data packet indicating that the connection is closed under the TCP connection, determining that the idle time of the TCP connection exceeds the second time period, End the TCP connection and output the data in the first array.
  • the first storage module includes:
  • a first overlap determining submodule configured to determine, according to the offset and the data length of the valid data packet, an overlap between valid data of the valid data packet and valid data of the first array
  • a first discarding sub-module configured to discard valid data of the overlapping portion of the valid data packet if there is valid data that overlaps all of the valid data packets in the first array
  • a first discarding storage submodule adapted to discard valid data of the overlapping portion of the valid data packet if there is valid data partially overlapping the valid data in the first array, and calculate valid data of the non-overlapping portion An offset and a first data length, and then storing the valid data of the non-overlapping portion at a first offset position of the first array until the storage length is the first data length;
  • a first storage submodule adapted to store valid data of the valid data packet at an offset position of the first array until storage is valid if there is no valid data that overlaps all of the valid data in the first array
  • the length is the length of the data.
  • the second storage module includes:
  • a second overlap determining submodule configured to determine, according to the offset and the data length of the valid data packet, an overlap between valid data of the valid data packet and valid data of the second array
  • a second discarding submodule configured to discard valid data of the overlapping portion of the valid data packet if there is valid data in the second array that overlaps with the valid data packet
  • a second discarding storage submodule adapted to discard the valid data of the overlapping portion of the valid data packet if there is valid data partially overlapping the valid data in the second array, and calculate the valid data of the non-overlapping portion a second offset and a second data length, and then storing the valid data of the non-overlapping portion at a second offset position of the second array until the storage length is the second data length;
  • a second discarding storage submodule adapted to be if the second array does not exist with the valid data
  • the valid data of the valid data packet is stored at the offset position of the second array until the storage length is the data length.
  • it also includes:
  • An output module adapted to output data in the first array and/or the second array after the current TCP connection ends.
  • a first array belonging to the client is created, and/or a second array belonging to the server, and then the valid data packet is calculated for the valid data packet with the TCP payload under the TCP connection.
  • the offset and the data length are further stored according to the offset of the valid data packet and the data length, and the valid data in the valid data packet is stored in the first array belonging to the client.
  • FIG. 1 is a flow chart showing the steps of an embodiment of a TCP stream reorganization method of the present application
  • 1A is a schematic diagram showing a state change of a TCP connection of the present application from a start setup process to a connection close;
  • FIG. 1B is a schematic diagram of a method for delaying allocation of memory according to the present application.
  • 1C is a schematic diagram of a process of storing valid data of a plurality of valid data packets to respective locations of a first array according to the present application;
  • FIG. 2 is a flow chart of steps of an embodiment of a TCP stream reorganization method of the present application
  • FIG. 2A is a schematic structural diagram of a TCP packet of the present application.
  • FIG. 3 is a flow chart of steps of an embodiment of a TCP stream reorganization method of the present application
  • FIG. 4 is a flow chart showing the steps of an embodiment of a TCP stream reorganization method of the present application
  • FIG. 5 is a structural block diagram of an embodiment of a TCP stream recombining apparatus of the present application.
  • FIG. 6 is a structural block diagram of an embodiment of a TCP stream recombining apparatus of the present application.
  • FIG. 7 is a structural block diagram of an embodiment of a TCP stream recombining apparatus of the present application.
  • FIG. 8 is a structural block diagram of an embodiment of a TCP stream recombining apparatus of the present application.
  • One of the core concepts of the embodiments of the present application is to create a first array belonging to a client for a TCP connection, and/or a second array belonging to the server, and then for a valid data packet with a TCP payload under the TCP connection, Calculating an offset and a data length of the valid data packet, and further storing, according to the offset and the data length of the valid data packet, valid data in the valid data packet to a first array belonging to the client, where After the TCP connection is completed, the data in the first array and/or the second array is output.
  • the application simplifies the judgment logic and the operation process in the process of stream reorganization, thereby effectively reducing the complexity of the existing TCP stream recombination method, improving the efficiency of stream reorganization, and more easily meeting the system performance requirements.
  • FIG. 1 a flow chart of steps of an embodiment of a TCP stream reorganization method of the present application is shown, which may specifically include the following steps:
  • Step 110 for a TCP connection, create a first array belonging to the client, and/or a second array belonging to the server.
  • TCP Transmission Control Protocol
  • TCP guarantees the order in which packets are transmitted. The order is guaranteed by a serial number.
  • the response packet also includes a serial number indicating that the receiver has prepared the packet of the serial number.
  • TCP transmits a packet it puts the packet into the retransmission queue and starts the timer. If it receives confirmation about the packet, it deletes the packet from the queue. If it is in the timer. If the confirmation message is still not received when the timeout expires, the packet needs to be resent.
  • TCP ensures that all transmitted data can be reassembled in the normal order by the serial number in the data segment, thereby ensuring the integrity of the data transmission.
  • the TCP connection has two corresponding directions of request and return.
  • Each TCP packet has parameters such as a TCP sequence number (Sequence Number), a TCP acknowledgement number (Acknowledgment Number), and a packet length (Len).
  • TCP is a reliable connection-oriented protocol.
  • the TCP sequence number is 32 bits, indicating the number of bytes in the data stream. Is the location of the first byte in the TCP protocol throughout the data stream.
  • the TCP acknowledgment number is 32 bits.
  • the data packet used in the TCP protocol to indicate that the sequence number is the acknowledgment number minus 1 and all previous packets have been received correctly, corresponding to the next sequence number expected to be received.
  • FIG. 1A is a schematic diagram showing a state change of a TCP connection from a start setup process to a connection close.
  • TCP establishes a connection and first needs to go through the "three-way handshake" process.
  • the client sends a connection to the server to explain, the specific steps are as follows:
  • the client sends a synchronization packet (SYN, synchronous) request to the server to establish a connection.
  • the initial sequence number (ISN) is a value randomly generated by the client.
  • the confirmation number is 0; where the initial sequence number is 32 bits, which is the initial sequence number of the TCP connection establishment phase.
  • the server After the server receives the synchronization request packet, it will perform a synchronization confirmation on the client.
  • the sequence number (SN) is a value randomly generated by the server, and the confirmation number is the initial sequence number of the client +1;
  • the client After the client receives the synchronization confirmation packet, it confirms the server.
  • the serial number is the confirmation number value in the previous synchronization request packet, and the confirmation number is the initial sequence number of the server +1.
  • the client and server can begin to transfer data.
  • TCP works in full-duplex mode, which allows simultaneous bidirectional data transfer.
  • the server After the server sends a data packet to the client, after receiving the data packet, the client sends an acknowledgement packet to the server.
  • Send data The server sends a data packet with data to the client, and the serial number and the confirmation number in the data packet are the same as the serial number and the confirmation number in the data packet of the third step of establishing the connection;
  • Confirm receipt The client receives the data packet and sends an acknowledgement packet to the server.
  • the serial number is the confirmation number value in the previous data packet
  • the confirmation number is the last one sent by the server.
  • serial number in the data segment ensures that all transmitted data is reassembled in the normal order and that the integrity of the data transmission is guaranteed by confirmation.
  • TCP connection is a full-duplex mode of operation, it needs to be turned off separately in each direction.
  • the party that first shuts down that is, the one that sent the first termination packet
  • the other party which receives the termination packet
  • the server After the server completes its data transmission task, it will actively send a termination (FIN) packet to the client to close the TCP connection in this direction.
  • FIN termination
  • the serial number is the confirmation number value in the previous data packet sent by the client
  • the confirmation number is the serial number in the last data packet sent by the server + the size of the data carried by the data packet;
  • the client After receiving the termination packet sent by the server, the client will send a confirmation message to the server to close the TCP connection in the direction.
  • the serial number is the confirmation number value in step 1
  • the confirmation number is the serial number +1 in the data packet of the first step
  • the client After the client completes its data sending task, it will also send a termination packet to the server to close the TCP connection in this direction.
  • the serial number is the last data sent by the server.
  • the confirmation number value in the package, and the confirmation number is the serial number in the previous data packet sent by the client + the size of the data carried by the data packet;
  • the server After receiving the termination packet sent by the client, the server will send a confirmation message to the client to close the TCP connection in the direction.
  • the serial number is the confirmation number value in the third step
  • the confirmation number is the serial number +1 in the data packet in the third step
  • the server side creates a first array belonging to the client for a TCP connection, and/or a second array belonging to the server, for reorganizing data in the data packet transmitted in the connection.
  • the size of the first array can be flexibly set according to requirements, which is not limited in this application; the first array and/or the second array can be created in any storage space in which an array can be created, such as memory, cloud storage space, etc. .
  • the client and the server can communicate with each other, so the client can send the data packet, and the server can also respond to the data packet of the client.
  • the TCP connection is to be made for the TCP connection.
  • Data stream reorganization can reorganize the data stream from the client and/or the data stream from the server. If the packet retransmission sent by the client under a TCP connection is simultaneously performed, and the server reassembles the packet for the client response, respectively, a first array belonging to the client and a second array belonging to the server are respectively created, wherein the first array Used to reorganize the data stream from the client, and the second array is used to reassemble the data stream from the server.
  • the first array belonging to the client needs to be created in the content; if only the server is required to respond to the server for a TCP connection To reorganize the package, you only need to create a second array belonging to the server in the content.
  • the first array belonging to the client, and/or the second array belonging to the server may be created according to actual requirements, which is not limited in this embodiment of the present application.
  • the first array in the process of creating a first array belonging to the client for a TCP connection, and/or a second array belonging to the server, the first array may be created in the process of creating a new connection, and/or the second Arrays can also create a first array and/or a second array after the connection is created.
  • This application can select the creation opportunity according to the actual settings.
  • the step 110 includes:
  • Sub-step A111 after the TCP connection is successfully established, create a first array belonging to the client, and/or a second array belonging to the server.
  • FIG. 1B is a schematic diagram of a method for delaying memory allocation.
  • the first array belonging to the client is created, and/or the second array belonging to the server is created, and the first array belonging to the client is created before the TCP connection is successfully established.
  • the first array and/or the second array are created during the TCP connection establishment process, for example, when the server receives the SYN packet sent by the client, then if the SYN flood is received at this time (denial of service) Attack, that is, a hacker sends a large number of SYN packets, and accordingly, a large number of first arrays and/or second arrays are created, which consumes a large amount of system memory and affects the normal operation of the system.
  • the first array and/or the second array may be deferred, that is, after the TCP connection is successfully established, the first array belonging to the client is created, and/or the server belongs to the first Two arrays.
  • the first array may be a normal array, and the size of the array is determined when the file is created, and may also be a dynamic array.
  • the so-called dynamic array refers to an array that does not determine the size of the array when it is created. When you use this dynamic array, you can redefine the size of the dynamic array at any time with a function.
  • the step 110 includes:
  • Sub-step B111 for a TCP connection, creates a first array belonging to the client in memory and/or a second array belonging to the server.
  • the first array belonging to the client may be directly created in the memory of the server, and / or belong to the second array of servers.
  • Step 120 Calculate an offset and a data length of the valid data packet for a valid data packet with a TCP payload under the TCP connection.
  • the TCP payload refers to a portion other than the TCP header information in the TCP packet.
  • the payload data is a variable length field that contains the data described by the next header field.
  • the payload data field is mandatory and its length is an integer multiple of the byte.
  • the valid data packet is also a TCP packet.
  • the data packet is a valid data packet.
  • the offset of the valid data packet is the difference between the sequence number of the valid data packet and the initial sequence number of the foregoing SYN data packet plus 1, that is, the valid data packet and the SYN data packet. the distance between. Since an initial sequence number will occupy a sequence number, 1 is added.
  • the length of the data (Length, Len) refers to the space occupied by the data in the valid data packet, usually in bytes.
  • the data length of the valid data packet can be calculated by using any available technology, and the embodiment of the present application is not limited.
  • Step 130 When the valid data packet belongs to the client, the valid data in the valid data packet is stored in the first array belonging to the client according to the offset and the data length of the valid data packet.
  • the valid data packet belongs to the client, that is, the valid data packet is a valid data packet sent by the client.
  • the storage space for storing the valid data in the valid data packet may be searched in the first array according to the offset of the valid data packet and the data length, and then in a certain order.
  • the valid data in the valid data packet is stored to the location of the corresponding offset and data length of the first array.
  • the valid data in the valid data packet may be stored to the corresponding offset and data of the first array according to the storage order of each valid data in the corresponding valid data packet, or in the reverse order or other set order.
  • the position of the length is not limited in this embodiment.
  • the valid data in the valid data packet is stored in the storage space location of the selection 6-15 in the first array, that is, the valid data is stored from the storage space location 6, and is stored to the storage space location 15, then The valid data of the packet is stored.
  • each valid data packet can be divided into three categories: a valid data packet arriving in order, a valid data packet arriving in advance, and an overlapping valid data packet.
  • the overlapping valid data packets may be valid packets arriving in order or valid packets arriving in advance.
  • the ordered data packet that has arrived has been stored in the Nth element of the array, and the valid data packet arriving in order refers to a valid data packet with an offset equal to N+1; the valid data packet arriving in advance refers to Refers to a valid data packet with an offset greater than N+1; an overlapping valid data packet refers to a valid data packet whose portion of the data in the first array coincides with the data already stored in the first array.
  • Figure 1C shows the process of storing the valid data of each valid data packet to the corresponding location of the first array for six different valid data packets (case 1, case 2, case 3, case 4, case 5, case 6).
  • Case1 and case2 are valid data packets that arrive at the first array in order
  • case 5 is a valid data packet that arrives in the first array in advance
  • case3, case4, and case6 are overlapping valid data packets.
  • the array space of the first array is not opened until the first payload packet arrives, that is, before the first valid data packet arrives.
  • the second valid data packet arrives in order, and the first array in this case stores the valid data of the first valid data packet in case 1.
  • the valid data of the data packet is stored in order, and is stored to the position of the offset 199, and the valid data of the second valid data packet is reorganized.
  • the valid data of the data packet is overwritten until the position of the offset 199, and then continues from the position of the offset 200, and the remaining portion of the fourth valid data packet is stored in order until the position of the offset 249,
  • the valid data of the valid data packet is reorganized.
  • the fifth valid data packet arrives.
  • the sum of the lengths, that is, it is not connected to the received valid data packet, is the data packet arriving in advance.
  • the fifth valid data packet is sequentially stored from the position of the offset 300 until the position of the offset 399. Then, the valid data of the valid data packet is reorganized.
  • the offset of the seventh valid data packet is smaller than the offset of the sixth valid data packet, but the difference between the two is smaller than the length of the seventh valid data packet, so the seventh valid data packet And a portion where the sixth valid data packet overlaps, and the portion where the seventh valid data packet does not overlap with the sixth valid data packet is sequentially stored from the position of the offset 450 until the position of the offset 499 Ending, and then starting from the position of the offset 500, the sixth valid data packet is sequentially overwritten with the portion of the seventh data packet that has not been stored, until the position of the offset 549 ends, the valid data of the valid data packet The reorganization is complete.
  • the valid data that overlaps in the valid data packets that arrive at the overlap can also be directly discarded, and then the valid data packets that arrive in the overlap according to the offset and length of the valid data that are not overlapped therein.
  • the non-overlapping valid data is stored in the first array, which is not limited in the embodiment of the present application. Relative to the direct storage of all valid data of the valid data packets arriving at the overlap to the first array, if it is necessary to determine the specific overlap of the valid data packets that arrive at the overlap, and then discard or store them accordingly, the calculation amount will be slightly larger.
  • step 130 includes:
  • Sub-step 131 judging the overlap of the valid data of the valid data packet with the valid data of the first array according to the offset of the valid data packet and the data length.
  • valid data packets that have not been stored in the first array may overlap with valid arrays in the first array, and for overlapping valid data packets, according to specific overlapping portions, For full overlap and partial overlap.
  • all overlap means that the valid data in the valid data packet corresponds to the valid storage data in the storage space in the first array, such as the valid data packet case3 in FIG. 1C; the partial overlap refers to the valid data in the valid data packet.
  • the valid data is already stored in the partial storage space corresponding to the first array, such as the valid data packet case 6 in FIG. 1C.
  • Sub-step 132 if there is valid data in the first array that overlaps all of the valid data packets, the valid data of the overlapping portion of the valid data packets is discarded.
  • the valid data packet is not required.
  • the valid data is stored again in the corresponding storage space, so that the valid data of the overlapping part of the valid data packet can be directly discarded, that is, the valid data packet can be directly discarded. For example, for the valid packet case 3 in Figure 1C, it can be discarded directly.
  • Sub-step 133 if there is valid data partially overlapping the valid data in the first array, discard the valid data of the overlapping portion in the valid data packet, and calculate the first offset of the valid data of the non-overlapping portion and The first data length, and then storing the valid data of the non-overlapping portion at the first offset position of the first array until the storage length is the first data length.
  • the storage space position of offset 0 to offset 249, offset 300 to offset 399, offset 500 to offset 599 in the first array has stored data, and it can be seen that for case 6, the corresponding partial The valid data of 500 to offset 549 storage space location already exists in the previous valid data packet, and is stored to the first value, for which the partially overlapping valid data can be directly discarded; and for the other corresponding offset 450 to Valid number of storage location for 499
  • the offset and the data length of the non-overlapping portion can be sequentially stored in the first array corresponding storage space.
  • Sub-step 134 if there is no valid data overlapping the valid data in the first array, the valid data of the valid data packet is stored at the offset position of the first array until the storage length is the data. length.
  • the valid data of the valid data packet can be directly in the corresponding valid data of the first array.
  • the offset position of the packet begins to be stored until the storage length is the data length.
  • Step 140 When the valid data packet belongs to the server, store valid data in the valid data packet to a second array belonging to the server according to the offset and the data length of the valid data packet.
  • This step is for storing the valid data in the server-side valid data packet to the second array belonging to the server, which is similar to the foregoing step 130, and details are not described herein again.
  • the valid data packet belongs to the server, it means that the valid data packet is a valid data packet responded by the server.
  • step 140 includes:
  • Sub-step 141 judging the overlap of the valid data of the valid data packet with the valid data of the second array according to the offset of the valid data packet and the data length.
  • Sub-step 142 if there is valid data in the second array that overlaps all of the valid data packets, the valid data of the overlapping portion of the valid data packets is discarded.
  • Sub-step 143 if there is valid data partially overlapping the valid data in the second array, discard the valid data of the overlapping portion of the valid data packet, and calculate a second offset of the valid data of the non-overlapping portion and The second data length, and then storing the valid data of the non-overlapping portion at the second offset position of the second array until the storage length is the second data length.
  • Sub-step 144 if there is no valid data overlapping the valid data in the second array, the valid data of the valid data packet is stored at the offset position of the second array until the storage length is the data. length.
  • Sub-step 141 to sub-step 14 are for storing the valid data in the server-side valid data packet to the second array belonging to the server, which is similar to the foregoing sub-step 131 to sub-step 134, and details are not described herein again.
  • step 130 and step 140 the method further includes:
  • Step 150 After the current TCP connection ends, output data in the first array and/or the second array.
  • the data in the first array and/or the second array is already stream data that completes stream recombination, and thus is output in the first array and/or the second array.
  • the first address and the data length of the first array and/or the second array need to be transmitted, that is, the stream data in the first array and/or the second array may be sequentially acquired.
  • the main reason for the TCP connection end judgment is that the TCP stream ends normally (such as the TCP close connection described in step 110), and is interrupted by RST (one of the six flag bits in the TCP header, indicating that the connection is reset, the connection is reset) or The link timeout releases three cases.
  • the data in the first array and/or the second array may be output in the case where the TCP connection caused by the above three methods ends.
  • the embodiments of the present application are not limited.
  • first, for a TCP connection create a first array belonging to the client, and/or a second array belonging to the server, and then calculate the valid data packet with the TCP payload under the TCP connection. Effective packet offset and data length, further root
  • the valid data in the valid data packet is stored to the first array belonging to the client according to the offset and data length of the valid data packet. It simplifies the judgment logic and the operation process in the process of stream recombination, thereby effectively reducing the complexity of the existing TCP stream reorganization method, improving the efficiency of stream reorganization, and more easily meeting the system performance requirements.
  • the first array belonging to the client is created, and/or the second array belonging to the server, so that the SYN flood can be effectively avoided.
  • Service attacks, which consume a lot of system memory and affect the normal operation of the system.
  • the embodiment of the present application introduces a process of reassembling a data packet sent by a client.
  • FIG. 2 a flow chart of steps of an embodiment of a TCP stream reorganization method of the present application is shown, which may specifically include the following steps:
  • Step 208 when receiving the SYN packet, it is determined that the SYN packet is from the client and is also from the server; if the SYN packet is from the client, then proceeds to step 210;
  • Step 210 records the initial sequence number ISN(C) of the client.
  • the first correction value ISN(C)+1 can be calculated. If the SYN packet is from the server, it can be left unprocessed.
  • TCP is a connection-oriented transport protocol, that is, before using TCP for data transmission, the connection relationship must be established first.
  • the first handshake process of the TCP connection between the client and the server as described in the step 110 of the first embodiment is that the client first sends the SYN packet to the server. The server then returns a SYN packet and an ACK packet.
  • the ISN (C)+1 is directly extracted from the ACK packet as the correction value.
  • the TCP sequence number ISN(C)+1 may also be extracted from the valid data packet as the first correction value when the valid data packet of the first client is received.
  • Step 212 When receiving the data packet belonging to the client of the TCP connection, determining whether the received data packet is a valid data packet containing a TCP payload; if the received data packet is a valid data packet containing a TCP payload, Then proceed to step 214.
  • the received data packet including the data packet containing the TCP payload, does not contain the TCP payload data packet.
  • the data packet containing the TCP payload is called a valid data packet, and for the present application, it is directed to the flow reassembly of the valid data packet containing the TCP payload. Therefore, in the embodiment of the present application, the TCP connection is received.
  • the data packet When the data packet is received, it is judged whether the received data packet is a valid data packet containing a TCP payload; if the received data packet is a valid data packet containing a TCP payload, the subsequent steps are continued, and if the received packet is received, If the packet is not a valid packet containing a TCP payload, the data can be ignored.
  • Step 214 Determine whether the valid data packet is the first valid data packet; if the valid data packet is the first valid data packet, proceed to step 216.
  • the data packet received by the client side can be divided into the following four cases: 1) establishing a connected SYN packet; 2) the first one contains TCP payload packets; 3) other packets containing TCP payloads; 4) termination of connected FIN/RST packets.
  • the received valid data packet is the first data packet containing the TCP payload, that is, the first valid data packet
  • the first array needs to be created at this time, and the valid data in the valid data packet is stored, thereby
  • the secondary TCP connection stores the valid data in the first array created by the other data packets containing the TCP payload received later.
  • the role is only to establish a TCP connection, the data does not have to be stored in the first array, so if the received packet is a TCP packet to establish a connection, there is no need to create a An array, also for the FIN/RST packet that terminates the connection, does not need to create the first array.
  • Step 218, creating a first array belonging to the client.
  • the embodiment of the present application is to perform data stream recombination for a data packet on the client side. Therefore, at this time, it is only necessary to create a first packet belonging to the client for storing valid data in the valid data packet from the client.
  • the first array is created, and this is the best time to create the first array.
  • the first array does not have to be created after receiving the first valid data packet, and may be created in advance before any step before this step. limited.
  • Step 220 Calculate the length of the valid data in the valid data packet as the data length.
  • FIG. 3 shows the structure of a TCP packet.
  • the red box part can be considered as the TCP header information, and the user data can be regarded as the TCP payload, and the data part in the user data can be regarded as the valid data described in the present application.
  • the length of the valid data in the valid data packet is the data length.
  • the valid data in a valid data packet may be a plurality of data structures. In this case, different methods are needed to calculate the length of the valid data.
  • the length of the valid data in the valid data packet may be calculated by using any existing available technology, which is not limited in this embodiment of the present application.
  • Step 222 Determine an offset of the valid data packet according to a difference between a TCP sequence number of the valid data packet and a pre-recorded first correction value.
  • the first correction error value is an initial sequence number of the SYN packet belonging to the client. 1.
  • the offset of the valid data may be set as the difference between the TCP sequence number of the valid data packet and the first correction value.
  • the TCP sequence number is known and stored in the TCP packet, which is the data sequence number in FIG. 2A.
  • the first correction value is the initial sequence number of the SYN packet plus one, because an initial sequence number will occupy a sequence number, so 1 is added.
  • the initial serial number (ISN) (C)) varies over time, and different operating systems have different implementations, so the initial serial number for each connection is different.
  • the first correction value can be obtained and recorded in advance during the TCP connection process.
  • the process of establishing a connection by the TCP indicates that when the client sends a SYN packet to the server, an initial sequence number is written in the SYN packet.
  • the SYN packet sent by the client may be referred to as a SYN packet belonging to the client.
  • the server returns the SYN/ACK packet.
  • the server's SYN/ACK packet is actually a SYN packet.
  • the server will return the client's SYN ISN(C)+1 as the determined serial number to the client, and the server's response SYN.
  • the client When the client sends an ACK, it will carry the serial number of the client's SYN ISN(C)+1 and the ISN(S)+1 return server, and then establish a connection. After the connection is established successfully, the client will start data transmission.
  • ISN(C)+1 In the valid data packet, ISN(C)+1 is used as the start byte in the TCP sequence number, and the number of bytes sent by the client is recorded.
  • the first byte of the valid data sent for this time is recorded in the TCP sequence number.
  • the server starts to respond to a valid data packet, the ISN(S)+1 is used as the start byte in the valid data packet, and the number of bytes responded by the server is recorded. Each time a valid data packet is sent, the TCP serial number is recorded. The first byte of valid data sent.
  • the embodiment of the present application may obtain the ISN (C) in the SYN packet when receiving the SYN packet sent by the client, and then calculate the first correction bias value ISN (C). +1 and record. Or, when receiving the ACK packet sent by the client, obtain the confirmation sequence number ISN(C)+1 in the ACK packet, and record it as the first correction bias value. Or, after the connection is established, when the first valid data packet is received, the TCP serial number is obtained, because it starts to send data from the 0th byte, and it should also be ISN(C)+1, which can be recorded as The first correction bias value of the client.
  • the step 222 may be performed before the step 220, or may be performed at the same time as the step 220.
  • Step 224 determining whether the sum of the offset of the valid data packet and the data length is greater than the length of the array of the first array; if the sum of the offset of the valid data packet and the data length is greater than the array of the first array If the length is reached, step 226 is entered.
  • the valid data packet since the valid data packet has an offset, before storing the valid data in the received valid data packet to the first array, it is also necessary to consider the current array length of the first array. Is it enough to store the valid data received?
  • the first array has a length of 20, the sequential label is 1-20, the received valid data packet has an offset of 11, and the data length is 10. Then, for the valid data in the valid data packet, the recording starts from the 12th position in the first array. At this time, the length of the first array can only store the valid data with the data length of 9, and the received partial offset cannot be completely stored. Valid data for a valid packet with a shift of 11 and a data length of 10.
  • the present application it is determined whether the sum of the offset and the data length of the received valid data packet is greater than the array length of the first array, and if the offset of the valid data packet is the sum of the data length, If the length of the array is larger than the first array, a new array longer than the original first array needs to be created; and if the sum of the offset of the valid data packet and the data length is not greater than the array length of the first array, then Continue to use the original first array, no need to create a new array.
  • step 230 a new first array is created, and the array length of the new first array exceeds the first threshold of the original first array.
  • the array length of the new first array created must exceed the original first array.
  • the array length of the new first array is set to exceed the first threshold of the array length of the original first array.
  • the first threshold may be an integer multiple of the length of the original array of the first array.
  • the length of the array of the original first array is 20, and the length of the array of the new first array created is 40.
  • the array length of the array exceeds the length of the array of the first array by 20, which is the first threshold at this time.
  • the first threshold is 1 times the length of the array of the original first array.
  • the first threshold can also be other values, which can be flexibly set according to requirements.
  • the embodiment of the present application is not limited.
  • the original first array is the aforementioned dynamic array
  • a new first array may not be created at this time, and a function (such as a ReDim function) may be used to re-point the size of the original first array and array it.
  • the length is modified to exceed the first threshold of its original array length.
  • the first array modified by the data length can be said to be the new first array.
  • Step 226 Copy the data stored in the original first array into the new first array, and store the valid data of the unstored valid data packet into the new first array.
  • the data stored in the original first array is copied into the new first array, and then the new array is used.
  • the first array stores valid data of valid packets that have not been stored yet.
  • copying the data stored in the original first array into the new first array can be understood as maintaining the offset and the data length of the valid data packet to which the data stored in the first array belongs, and Stored in the new first array accordingly.
  • the new first array is a dynamic array modified in the length of the array as described in step 230, the process of copying is not required at this time, and the valid data of the unstored valid data packet is directly continued to be stored to the new one. In the first array.
  • Step 228 Store valid data in the valid data packet to a first array belonging to the client according to the offset and the data length of the valid data packet.
  • the first array in this step refers to the new first array created in step 230, for the received unstored valid data packet. . If a new first array is not created, the first array in this step is still the first array created in step 218.
  • the method further includes:
  • Step 230 After the current TCP connection ends, output the data in the first array.
  • the data in the first array of the memory can be output to the specified storage space, for example, output to the hard disk for storage.
  • step 230 includes:
  • Sub-step 2301 after receiving any data packet that is not instructed to close the connection under the TCP connection, determining that the idle time of the TCP connection exceeds the first time period, ending the TCP connection, and outputting the first array The data in .
  • the idle time of the TCP connection exceeds a certain time, then it can be determined at this time. End the current TCP connection.
  • the idle time of the TCP connection is set to exceed the first time period, the TCP connection is ended.
  • the first time period can be flexibly set according to requirements, which is not limited in this embodiment of the present application.
  • the data in the first array is output. Similarly, if a new first array is created after step 230, then the first array in this step refers to the new first array created in step 230. If a new first array is not created, the first array in this step is still the first array created in step 216.
  • the TCP connection After receiving any data packet that is not instructed to close the connection, if it is determined that the idle time of the TCP connection does not exceed the first time period, the TCP connection is not terminated, and the first time is not output. The data in the array.
  • sub-step 2302 after receiving the data packet indicating that the connection is closed under the TCP connection, determining that the idle time of the TCP connection exceeds the second time period, ending the TCP connection, outputting the first The data in the array.
  • the TCP connection if it is determined that the idle time of the TCP connection exceeds the second time period after receiving the data packet indicating that the connection is closed, the TCP connection is terminated and the data in the first array is output. And if the idle time of the TCP connection does not exceed the second time week The period does not end the TCP connection, nor does it output the data in the first array.
  • the second time period can also be flexibly set according to requirements, and is not limited in comparison with the embodiments of the present application.
  • the first array in this step refers to the new first array created in step 230. If a new first array is not created, the first array in this step is still the first array created in step 216.
  • the TCP connection after receiving the data packet indicating that the connection is closed under the TCP connection, the TCP connection is directly ended, and the data in the first array is output, without determining whether the idle time of the TCP connection exceeds the The second time period, that is, the second time period corresponding to this time is zero.
  • the method further includes:
  • Step 232 after copying the data stored in the original first array into the new first array, releasing the original first array.
  • the original first array after copying the data stored in the original first array into the new first array, the original first array no longer has any effect.
  • Release the original first array for example delete the first array. This step may be performed after step 226, or after any step after step 226, which is not limited in this embodiment of the present application.
  • the new first array is a dynamic array modified in the length of the array as described in step 230, then the original first array does not need to be released at this time.
  • the embodiment of the present application is directed to a TCP connection for reorganizing valid data in a valid data packet sent by a client.
  • the specific implementation process is: first, for a TCP connection, create a first array belonging to the client, and then calculate an offset and a data length of the valid data packet for the valid data packet with the TCP payload under the TCP connection, and further And validating the valid data in the valid data packet to the first array belonging to the client according to the offset and the data length of the valid data packet.
  • the original first array is replaced with the new first array. While ensuring the efficiency of stream recombination, the accuracy of stream recombination is improved, making it easier to meet system performance requirements.
  • the embodiment of the present application introduces a process of reorganizing a data packet that the server responds to.
  • FIG. 3 a flow chart of steps of an embodiment of a TCP stream reorganization method of the present application is shown, which may specifically include the following steps:
  • Step 308 when receiving the SYN packet, determining that the SYN packet is from the client and from the server; if the SYN packet is from the server, proceeding to step 310.
  • Step 310 recording the initial sequence number of the server ISN (S).
  • the second correction value ISN(S)+1 can be calculated.
  • the SYN packet if the SYN packet is from the client, it may not come out.
  • Step 312 when receiving the data packet belonging to the server of the TCP connection, determining whether the received data packet is a valid data packet containing a TCP payload; if the received data packet is a valid data packet containing a TCP payload, Then go to step 312.
  • Step 314 Determine whether the valid data packet is the first valid data packet; if the valid data packet is the first valid data packet, proceed to step 314.
  • step 316 a second array belonging to the server is created.
  • the embodiment of the present application is to perform data stream recombination for a data packet on the server side. Therefore, at this time, it is only necessary to create a first packet belonging to the server for storing valid data in a valid data packet from the server.
  • Step 318 Calculate the length of the valid data in the valid data packet as the data length.
  • Step 320 Determine an offset of the valid data packet according to a difference between a TCP sequence number of the valid data packet and a pre-recorded second correction value.
  • the second correction error value is an initial sequence number of the SYN packet belonging to the server. 1.
  • the ISN (S) in the SYN packet may be obtained when the SYN packet of the server response is obtained, and then the second correction bias value ISN(S)+1 is calculated and recording.
  • the client when receiving the ACK packet sent by the client, obtain the confirmation sequence number ISN(S) in the ACK packet, and record it as the second correction bias value.
  • the first server receives the valid data packet, it obtains its TCP serial number, because it starts sending data from the 0th byte, it should also be ISN(S)+1, Recorded as the second correction bias value for the server.
  • Step 322 determining whether the sum of the offset of the valid data packet and the data length is greater than the length of the array of the second array; if the sum of the offset of the valid data packet and the data length is greater than the array of the second array If it is length, it proceeds to step 324.
  • Step 324 creating a new second array, the array length of the new second array exceeding the second threshold of the original first array.
  • Step 326 Copy the data stored in the original second array into the new second array, and store the valid data of the unstored valid data packet into the new second array.
  • Step 328 Store valid data in the valid data packet to a second array belonging to the server according to the offset of the valid data packet and the data length.
  • the method further includes:
  • Step 330 After the current TCP connection ends, output the data in the second array.
  • the method further includes:
  • Step 332 after copying the data stored in the original second array into the new second array, releasing the original second array.
  • This step can be performed at any time after the step 326, which is not limited in this embodiment of the present application.
  • the principle of the reassembly of the valid data packet on the server side in the embodiment of the present application is substantially similar to the recombination principle of the data packet on the client side in the second embodiment.
  • a similar procedure in the first embodiment may be omitted, and details are not described herein.
  • the embodiment of the present application is directed to a TCP connection for reorganizing valid data in a valid data packet sent by a server.
  • the specific implementation process is: first, for a TCP connection, create a second array belonging to the server, and then calculate the offset and data length of the valid data packet for the valid data packet with the TCP payload under the TCP connection, and further The valid data in the valid data packet is stored to a second array belonging to the server according to the offset of the valid data packet and the data length.
  • the original second array is replaced with the new second array. While ensuring the efficiency of stream recombination, the accuracy of stream recombination is improved, making it easier to meet system performance requirements.
  • This embodiment describes a preferred procedure for recombining data packets of a client and data packets of a server at the same time.
  • FIG. 4 a flow chart of steps of an embodiment of a TCP stream reorganization method of the present application is shown, which may specifically include the following steps:
  • Step 410 when receiving the SYN packet, it is determined that the SYN packet is from the client and from the server; if the SYN packet is from the client, then proceeds to step 412; if the SYN packet is from the server, then proceeds to step 414;
  • Step 412 recording the initial serial number of the client ISN (C);
  • step 414 the initial sequence number ISN(S) of the server is recorded.
  • the initial serial number ISN of the client and the server are randomly generated, and the possibility that the client's ISN and the server's initial serial number ISN are the same is very small.
  • the received SYN packet it is first determined that the SYN packet is sent from the client and is also from the server, and then determines whether to record the initial sequence number of the client, ISN (C), or the initial sequence number of the server, ISN ( S).
  • the embodiment of the present application may obtain the ISN (C) in the SYN packet when receiving the SYN packet sent by the client, and then calculate the first correction bias value. ISN(C)+1 and record. Or, when receiving the ACK packet sent by the client, obtain the confirmation sequence number ISN(C)+1 in the ACK packet, and record it as the first correction bias value. Or, after the connection is established, when the valid data packet of the first client is received, the TCP serial number is obtained because it starts to send data from the 0th byte, and it should also be ISN(C)+1, which can be recorded. The first correction bias value for the client.
  • the ISN (S) in the SYN packet of the server may be obtained when the SYN packet of the server response is obtained, and then the second correction bias value ISN(S) is calculated. +1 and record.
  • the second correction bias value ISN(S)+1 in the ACK packet, and record it as the second correction bias value.
  • the TCP serial number is obtained because it starts to send data from the 0th byte, and it should also be ISN(S)+1, which can be recorded.
  • the second correction bias value for the client is the connection is established.
  • Step 416 When obtaining the data packet of the TCP connection, determine whether the received data packet is a valid data packet containing a TCP payload; if the received data packet is a valid data packet containing a TCP payload, enter Step 418.
  • the received packet is not a valid packet containing a TCP payload, then it is not carried out.
  • Reason If the received packet is not a valid packet containing a TCP payload, then it is not carried out.
  • Step 418 Determine whether the valid data packet is the first valid data packet; if the valid data packet is the first valid data packet, proceed to step 420.
  • Step 420 Determine whether the valid data packet belongs to the client; if the valid data packet belongs to the client, go to step 422; if the valid data packet belongs to the server, go to step 424.
  • step 422 a first array belonging to the client is created. Proceed to step 426.
  • step 424 a second array belonging to the server is created. Proceed to step 426.
  • the received data packet in a process of establishing a connection to an end connection by a TCP, may be classified into the following four cases: 1) establishing a connected SYN packet; 2) the first one containing a TCP payload. Packets; 3) other packets containing TCP payloads; 4) termination of connected FIN/RST packets.
  • the received valid data packet is the first data packet containing the TCP payload, that is, the first valid data packet
  • the first array needs to be created at this time, and the valid data in the valid data packet is stored, thereby
  • the secondary TCP connection stores the valid data in the first array created by the other data packets containing the TCP payload received later.
  • the role is only to establish a TCP connection, the data does not have to be stored in the first array, so if the received packet is a TCP packet to establish a connection, there is no need to create a An array, also for the FIN/RST packet that terminates the connection, does not need to create the first array.
  • Step 426 Calculate the length of the valid data in the valid data packet as the data length. The process proceeds to step 428 or step 430 according to the client to which the valid data packet belongs.
  • Step 428 when the valid data packet belongs to the client, determining an offset of the valid data packet according to a difference between a TCP sequence number of the valid data packet and a pre-recorded first correction value; the first corrective value
  • the initial sequence number of the SYN packet belonging to the client is +1. Proceed to step 432.
  • the embodiment of the present application may obtain the ISN (C) in the SYN packet when receiving the SYN packet sent by the client, and then calculate the first correction bias value ISN(C)+1. And record. Or, when receiving the ACK packet sent by the client, obtain the confirmation sequence number ISN(C)+1 in the ACK packet, and record it as the first correction bias value. Or, after the connection is established, when the first valid data packet is received, the TCP serial number is obtained, because it starts to send data from the 0th byte, and it should also be ISN(C)+1, which can be recorded as The first correction bias value of the client.
  • the ISN (S) in the SYN packet may be obtained when the SYN packet of the server response is obtained, and then the second correction bias value ISN(S)+1 is calculated and recording.
  • the client when receiving the ACK packet sent by the client, obtain the confirmation sequence number ISN(S) in the ACK packet, and record it as the second correction bias value.
  • the first server receives the valid data packet, it obtains its TCP serial number, because it starts sending data from the 0th byte, it should also be ISN(S)+1, Recorded as the second correction bias value for the server.
  • Step 430 when the valid data packet belongs to the server, determining an offset of the valid data packet according to a difference between a TCP sequence number of the valid data packet and a pre-recorded second correction value; the second correction value is The initial sequence number of the SYN packet belonging to the server is +1. Proceed to step 438.
  • Step 432 when the valid data packet belongs to the client, determining whether the sum of the offset of the valid data packet and the data length is greater than the array length of the first array; if the offset of the valid data packet is The sum of the data lengths is greater than the array length of the first array, then proceeds to step 434, and then proceeds to step 436; if the sum of the offset of the valid data packet and the data length is not greater than the array length of the first array, then enters Step 446.
  • step 434 a new first array is created, and the array length of the new first array exceeds the first threshold of the original first array.
  • Step 436 copying the data stored in the original first array into the new first array,
  • the valid data of the unstored valid data packet is stored in the new first array.
  • Step 438 when the valid data packet belongs to the server, determining whether the sum of the offset of the valid data packet and the data length is greater than the array length of the second array; if the offset and data of the valid data packet If the sum of the lengths is greater than the array length of the second array, proceed to step 440, and then proceed to step 442; if the sum of the offset of the valid data packet and the data length is not greater than the array length of the second array, proceed to the step 448.
  • step 440 a new second array is created, and the array length of the new second array exceeds the second threshold of the original first array.
  • Step 442 Copy the data stored in the original second array into the new second array, and store the valid data of the unstored valid data packet into the new second array.
  • Step 446 When the valid data packet belongs to the client, the valid data in the valid data packet is stored in the first array belonging to the client according to the offset and the data length of the valid data packet.
  • Step 448 When the valid data packet belongs to the server, store valid data in the valid data packet to a second array belonging to the server according to the offset and the data length of the valid data packet.
  • the method further includes:
  • Step 450 After the current TCP connection ends, output the data in the first array and the second array.
  • the embodiment of the present application is directed to a TCP connection, and respectively reorganizes valid data in valid data packets sent by the client and the server.
  • the specific implementation process is: first, for a TCP connection, creating a first array belonging to the client, and a second array belonging to the server, and then calculating the valid data packet for the valid data packet containing the TCP payload under the TCP connection.
  • An offset and a data length further storing, according to the offset and the data length of the valid data packet, valid data in the valid data packet of the client to a second array belonging to the client, the server
  • the valid data in the valid data packet is stored in the second array belonging to the server.
  • the reorganization of the data flow for the client and the server side is realized at the same time, and the judgment logic and the operation process in the process of the flow reorganization of the client side and the server side are simplified, thereby effectively reducing the existing TCP stream reorganization method.
  • the complexity increases the efficiency of stream reorganization and makes it easier to meet system performance requirements.
  • the received SYN packet when establishing a TCP connection, it is determined that the received SYN packet is sent from the client and is also from the server, and then determines whether to record the initial serial number of the client, or the initial sequence number of the server, ISN;
  • the connected data packet When the connected data packet is received, it also judges the type of the received data packet, and performs different operations for the type of the received data packet; and also receives the offset amount and data length of the valid data packet respectively.
  • the sum exceeds the first array and the second array length, the original first array and the second array are replaced with the new first array and the second array, respectively. While ensuring the efficiency of stream recombination, the accuracy of stream recombination is improved, making it easier to meet system performance requirements.
  • FIG. 5 a structural block diagram of an embodiment of a TCP stream reorganization apparatus of the present application is shown, which may specifically include the following modules:
  • the first creation module 510 is adapted to create a first array belonging to the client and/or a second array belonging to the server for a TCP connection.
  • the first creating module 510 includes:
  • the first creating submodule is adapted to create a first array belonging to the client and/or a second array belonging to the server after the TCP connection is successfully established.
  • the first creating module 510 includes:
  • the first memory creation sub-module is adapted to create a first array belonging to the client in memory and/or a second array belonging to the server for a TCP connection.
  • the calculating module 520 is adapted to calculate an offset and a data length of the valid data packet for the valid data packet with the TCP payload under the TCP connection.
  • the first storage module 530 is adapted to store the valid data in the valid data packet to the first array belonging to the client according to the offset and the data length of the valid data packet.
  • the first storage module 530 includes:
  • the first overlap determining submodule is adapted to determine, according to the offset and the data length of the valid data packet, an overlap of the valid data of the valid data packet with the valid data of the first array.
  • a first discarding submodule adapted to discard the valid data of the overlapping portion of the valid data packet if there is valid data in the first array that overlaps with the valid data packet.
  • a first discarding storage submodule adapted to discard valid data of the overlapping portion of the valid data packet if there is valid data partially overlapping the valid data in the first array, and calculate valid data of the non-overlapping portion An offset and a first data length are further stored in the first offset position of the first array until the storage length is the first data length.
  • a first storage submodule adapted to: if the first array does not exist and the valid data is all The overlapping valid data starts storing the valid data of the valid data packet at the offset position of the first array until the storage length is the data length.
  • the second storage module 540 is adapted to store the valid data in the valid data packet to the second array belonging to the server according to the offset and the data length of the valid data packet when the valid data packet belongs to the server. .
  • the second storage module 540 includes:
  • the second overlap determining submodule is adapted to determine, according to the offset and the data length of the valid data packet, an overlap of the valid data of the valid data packet with the valid data of the second array.
  • a second discarding submodule adapted to discard the valid data of the overlapping portion of the valid data packet if there is valid data in the second array that overlaps with the valid data packet.
  • a second discarding storage submodule adapted to discard the valid data of the overlapping portion of the valid data packet if there is valid data partially overlapping the valid data in the second array, and calculate the valid data of the non-overlapping portion
  • the second offset and the second data length are further stored in the second offset position of the second array until the storage length is the second data length.
  • a second discarding storage submodule configured to: if there is no valid data that overlaps with the valid data in the second array, store the valid data of the valid data packet at an offset position of the second array, until The storage length is the length of the data.
  • the method further includes:
  • the output module 550 is adapted to output data in the first array and/or the second array after the current TCP connection ends.
  • first, for a TCP connection create a first array belonging to the client, and/or a second array belonging to the server, and then calculate the valid data packet with the TCP payload under the TCP connection.
  • Effective packet offset and data length further root And according to the offset and the data length of the valid data packet, storing the valid data in the valid data packet to the first array belonging to the client, and finally outputting the first array and/or the second after the current TCP connection ends
  • the data in the array It simplifies the judgment logic and the operation process in the process of stream recombination, thereby effectively reducing the complexity of the existing TCP stream reorganization method, improving the efficiency of stream reorganization, and more easily meeting the system performance requirements.
  • first, for a TCP connection create a first array belonging to the client, and/or a second array belonging to the server, and then calculate the valid data packet with the TCP payload under the TCP connection.
  • the offset and the data length of the valid data packet and further storing the valid data in the valid data packet to the first array belonging to the client according to the offset and the data length of the valid data packet.
  • the first array belonging to the client is created, and/or the second array belonging to the server, so that the SYN flood can be effectively avoided.
  • Service attacks, which consume a lot of system memory and affect the normal operation of the system.
  • FIG. 6 a structural block diagram of an embodiment of a TCP stream recombining apparatus of the present application is shown, which may specifically include the following modules:
  • the SYN packet judging module 610 is adapted to: when receiving the SYN packet, determine that the SYN packet is from the client and from the server; if the SYN packet is from the client, enter the first recording module 620; if the SYN packet is from the server , you can not handle it.
  • the first recording module 620 is adapted to record the initial serial number ISN (C) of the client;
  • the first creation module 630 is adapted to create a first array belonging to the client for a TCP connection. Specifically include:
  • the TCP judging sub-module 631 is adapted to determine, when receiving the data packet belonging to the client of the TCP connection, whether the received data packet is a valid data packet containing a TCP payload; if the received data packet is a TCP payload Valid packet, then enter the first judgment sub-module 632;
  • the first determining sub-module 632 is adapted to determine whether the valid data packet is the first valid data packet; if the valid data packet is the first valid data packet, enter the first array creating sub-module 633;
  • the first array creation sub-module 633 is adapted to create a first array belonging to the client.
  • the calculating module 640 is adapted to calculate an offset and a data length of the valid data packet for the valid data packet with the TCP payload under the TCP connection. Specifically include:
  • a data length calculation sub-module 641, configured to calculate a length of valid data in the valid data packet as a data length
  • the first offset calculation sub-module 642 is adapted to determine an offset of the valid data packet according to a difference between a TCP sequence number of the valid data packet and a pre-recorded first correction value; the first correction value belongs to The initial sequence number of the client's SYN packet is +1.
  • the first determining module 650 is adapted to determine whether the sum of the offset and the data length of the valid data packet is greater than the array length of the first array; if the sum of the offset of the valid data packet and the data length is greater than The length of the array of the first array enters the first new array creation module 660; if the sum of the offset of the valid data packet and the data length is not greater than the array length of the first array, the first storage module 680 is directly entered. .
  • the first new array creation module 660 is adapted to create a new first array, the array length of the new first array being greater than the first threshold of the original first array.
  • the first copy storage module 670 is adapted to copy the data stored in the original first array into the new first array, and store the valid data of the unstored valid data packets into the new first array.
  • the first storage module 680 is adapted to: when the valid data packet belongs to the client, the valid data in the valid data packet is forwarded to the first array belonging to the client according to the offset and the data length of the valid data packet. storage.
  • the method further includes:
  • the output module 690 is adapted to output data in the first array after the current TCP connection ends.
  • the output module 690 includes:
  • a first output sub-module configured to, after receiving the data packet that is not instructed to close the connection under the TCP connection, determine that the idle time of the TCP connection exceeds the first time period, end the TCP connection, Output the data in the first array.
  • a second output submodule configured to, after receiving the data packet indicating that the connection is closed under the TCP connection, determining that the idle time of the TCP connection exceeds the second time period, ending the TCP connection , output the data in the first array.
  • the method further includes:
  • the first release module is adapted to release the original first array after copying the data stored in the original first array into the new first array.
  • the valid data in the valid data packet is stored in the first array belonging to the client.
  • the embodiment of the present application is directed to a TCP connection, and the valid data in the valid data packet sent by the client is reorganized.
  • the specific implementation process is: first, for a TCP connection, create a first array belonging to the client, and then calculate an offset and a data length of the valid data packet for the valid data packet with the TCP payload under the TCP connection, and further And validating the valid data in the valid data packet to the first array belonging to the client according to the offset and the data length of the valid data packet.
  • the type of the received data packet is also determined, and different operations are performed for different types of the received data packet; and the offset amount of the valid data packet received is also When the sum of the data lengths exceeds the length of the first array, the original first array is replaced with the new first array. While ensuring the efficiency of stream recombination, the accuracy of stream recombination is improved, making it easier to meet system performance requirements.
  • FIG. 7 a structural block diagram of an embodiment of a TCP stream recombining apparatus of the present application is shown, which may specifically include the following modules:
  • the SYN packet judging module 710 is adapted to: when receiving the SYN packet, determine that the SYN packet is from the client and from the server; if the SYN packet is from the server, enter the second recording module 720; if the SYN packet is from the client , you can not process it;
  • the second recording module 720 is adapted to record the initial serial number ISN(S) of the server.
  • the first creation module 730 is adapted to create a first array belonging to the client for a TCP connection and/or a second array belonging to the server. Specifically include:
  • the TCP judging sub-module 731 is adapted to determine, when receiving the data packet of the TCP connection, whether the received data packet is a valid data packet containing a TCP payload; if the received data packet is valid data that includes a TCP payload The packet then enters the first decision sub-module 732.
  • the first determining sub-module 732 is adapted to determine whether the valid data packet is the first valid data packet; if the valid data packet is the first valid data packet, enter the second array creating sub-module 733.
  • the second array creation sub-module 733 is adapted to create a second array belonging to the server.
  • the calculating module 740 is adapted to calculate an offset and a data length of the valid data packet for the valid data packet with the TCP payload under the TCP connection. Specifically include:
  • the data length calculation sub-module 741 is adapted to calculate the length of the valid data in the valid data packet as the data length;
  • the second offset calculation sub-module 742 is adapted to determine an offset of the valid data packet according to a difference between a TCP sequence number of the valid data packet and a pre-recorded second correction value; the second correction value belongs to The initial sequence number of the server's SYN packet is +1.
  • the second determining module 750 is adapted to determine whether the sum of the offset and the data length of the valid data packet is greater than the array length of the second array; if the sum of the offset of the valid data packet and the data length is greater than The length of the array of the second array enters the second new array creation module 760; if the sum of the offset of the valid data packet and the data length is not greater than the array length of the second array, then directly enters the second storage module 780 .
  • the second new array creation module 760 is adapted to create a new second array, the array length of the new second array exceeding the first threshold of the second array.
  • the second copy storage module 770 is adapted to copy the data stored in the original second array into the new second array, and store the valid data of the unstored valid data packets into the new second array.
  • the second storage module 780 is adapted to store the valid data in the valid data packet to the second array belonging to the server according to the offset and the data length of the valid data packet when the valid data packet belongs to the server. .
  • the method further includes:
  • the output module 790 is adapted to output data in the second array after the current TCP connection ends.
  • the method further includes:
  • the second release module is adapted to release the original second array after copying the data stored in the original second array into the new second array.
  • the second release module may be after the second replication storage module 770 or after any module after the second replication storage module 770, and the application is not limited thereto.
  • the embodiment of the present application is directed to a TCP connection for reorganizing valid data in a valid data packet sent by a server.
  • the specific implementation process is to first create a service for a TCP connection. a second array of servers, and then calculating an offset and a data length of the valid data packet for the valid data packet containing the TCP payload under the TCP connection, further based on the offset and data of the valid data packet Length, storing valid data in the valid data packet to a second array belonging to the server.
  • the original second array is replaced with the new second array. While ensuring the efficiency of stream recombination, the accuracy of stream recombination is improved, making it easier to meet system performance requirements.
  • FIG. 8 a structural block diagram of an embodiment of a TCP stream recombining apparatus of the present application is shown, which may specifically include the following modules:
  • the SYN packet judging module 800 is adapted to: when receiving the SYN packet, determine that the SYN packet is from the client and from the server; if the SYN packet is from the client, enter the first recording module 802; if the SYN packet is from the server Go to the second recording module 804;
  • a first recording module adapted to record an initial serial number of the client, ISN (C);
  • the second recording module is adapted to record the initial serial number ISN(S) of the server.
  • the first creation module 810 is adapted to create a first array belonging to the client and a second array belonging to the server for a TCP connection. Specifically include:
  • the TCP judging sub-module 811 is adapted to determine, when receiving the data packet of the TCP connection, whether the received data packet is a valid data packet containing a TCP payload; if the received data packet is valid data that includes a TCP payload The packet then enters the first decision sub-module 812.
  • the first determining sub-module 812 is adapted to determine whether the valid data packet is the first valid data packet; if the valid data packet is the first valid data packet, enter the client judgmentr Module 813.
  • the client judgment sub-module 813 is adapted to determine whether the valid data packet belongs to the client; if the valid data packet belongs to the client, enter the first array creation sub-module 814; if the valid data packet does not belong to the client Then enter the second array creation sub-module 815.
  • the first array creation sub-module 814 is adapted to create a first array belonging to the client. Entering the calculation module 820.
  • the second array creation sub-module 815 is adapted to create a second array belonging to the server. Entering the calculation module 820.
  • the calculating module 820 is adapted to calculate an offset and a data length of the valid data packet for the valid data packet with the TCP payload under the TCP connection. Specifically include:
  • the data length calculation sub-module 821 is adapted to calculate the length of the valid data in the valid data packet as the data length.
  • the first offset calculation sub-module 822 is adapted to determine, when the valid data packet belongs to the client, the partiality of the valid data packet according to a difference between a TCP sequence number of the valid data packet and a pre-recorded first correction value.
  • the first correction error is an initial sequence number +1 of the SYN packet belonging to the client.
  • the first judgment module 830 is entered.
  • the second offset calculation sub-module 823 is adapted to determine an offset of the valid data packet according to a difference between a TCP sequence number of the valid data packet and a pre-recorded second correction value; the second correction value belongs to The initial sequence number of the server's SYN packet is +1.
  • the second judging module 860 is entered.
  • the first determining module 830 is adapted to determine, when the valid data packet belongs to the client, whether the sum of the offset and the data length of the valid data packet is greater than an array length of the first array; if the valid data packet The sum of the offset and the data length is greater than the array length of the first array, then enters the first new array creation module 840, and then enters the first copy storage module 850; if the effective data packet offset and data length The sum, not greater than the array length of the first array, directly enters the first storage module 890.
  • the first new array creation module 840 is adapted to create a new first array, the array length of the new first array being greater than the first threshold of the original first array.
  • the first copy storage module 850 is adapted to copy the data stored in the original first array into the new first array, and store the valid data of the unstored valid data packets into the new first array.
  • the second determining module 860 is adapted to determine whether the sum of the offset and the data length of the valid data packet is greater than the array length of the second array; if the sum of the offset of the valid data packet and the data length is greater than The length of the array of the second array enters the second new array creation module 870; if the sum of the offset of the valid data packet and the data length is not greater than the array length of the second array, the second storage module 8110 is directly entered. .
  • the second new array creation module 870 is adapted to create a new second array, the array length of the new second array being greater than the first threshold of the second array.
  • the second copy storage module 880 is adapted to copy the data stored in the original second array into the new second array, and store the valid data of the unstored valid data packets into the new second array.
  • the first storage module 890 is adapted to: when the valid data packet belongs to the client, the valid data in the valid data packet is directed to the first array belonging to the client according to the offset and the data length of the valid data packet. storage.
  • the second storage module 8110 is adapted to store the valid data in the valid data packet to the second array belonging to the server according to the offset and the data length of the valid data packet when the valid data packet belongs to the server. .
  • the method further includes:
  • the output module 8120 is adapted to output data in the first array and the second array after the current TCP connection ends.
  • the method further includes:
  • the first release module is adapted to release the original first array after copying the data stored in the original first array into the new first array.
  • the second release module is adapted to release the original second array after copying the data stored in the original second array into the new second array.
  • the first release module may be after the first copy storage module or after any module after the first copy storage module; the second release module may be after the second copy storage module or in the second copy storage This application is not limited to any module after the module.
  • the embodiment of the present application is directed to a TCP connection, and respectively reorganizes valid data in valid data packets sent by the client and the server.
  • the specific implementation process is: first, for a TCP connection, creating a first array belonging to the client, and a second array belonging to the server, and then calculating the valid data packet for the valid data packet containing the TCP payload under the TCP connection. Offset and data length, further storing valid data in the valid data packet of the client to a second array belonging to the client according to the offset and data length of the valid data packet, and valid data of the server The valid data in the package is stored to the second array belonging to the server.
  • the reorganization of the data flow for the client and the server side is realized at the same time, and the judgment logic and the operation process in the process of the flow reorganization of the client side and the server side are simplified, thereby effectively reducing the existing TCP stream reorganization method.
  • the complexity increases the efficiency of stream reorganization and makes it easier to meet system performance requirements.
  • the received SYN packet when establishing a TCP connection, it is determined that the received SYN packet is sent from the client and is also from the server, and then determines whether to record the initial serial number of the client, or the initial sequence number of the server, ISN;
  • the connected data packet When the connected data packet is received, it also judges the type of the received data packet, and performs different operations for the type of the received data packet; and also receives the offset amount and data length of the valid data packet respectively.
  • the sum exceeds the length of the first array and the second array, respectively replace the original with the new first array and the second array
  • There are first arrays and second arrays While ensuring the efficiency of stream recombination, the accuracy of stream recombination is improved, making it easier to meet system performance requirements.
  • the description is relatively simple, and the relevant parts can be referred to the description of the method embodiment.
  • embodiments of the embodiments of the present application can be provided as a method, apparatus, or computer program product. Therefore, the embodiments of the present application may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Moreover, embodiments of the present application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) including computer usable program code.
  • computer-usable storage media including but not limited to disk storage, CD-ROM, optical storage, etc.
  • the computer device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
  • Memory may include non-persistent memory, random access memory (RAM), and/or non-volatile memory in a computer readable medium.
  • RAM random access memory
  • Non-volatile memory in a computer readable medium.
  • Form such as read only memory (ROM) or flash memory (flash RAM).
  • ROM read only memory
  • flash RAM flash RAM
  • Memory is an example of a computer readable medium.
  • Computer readable media includes both permanent and non-persistent, removable and non-removable media.
  • Information storage can be implemented by any method or technology. The information can be computer readable instructions, data structures, modules of programs, or other data.
  • Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read only memory. (ROM), electrically erasable programmable read only memory (EEPROM), flash memory or other memory technology, compact disk read only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, Magnetic tape cartridges, magnetic tape storage or other magnetic storage devices or any other non-transportable media can be used to store information that can be accessed by a computing device.
  • computer readable media does not include non-persistent computer readable media, such as modulated data signals and carrier waves.
  • Embodiments of the present application are described with reference to flowcharts and/or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the present application. It will be understood that each flow and/or block of the flowchart illustrations and/or FIG.
  • the computer program instructions can be provided to a processor of a general purpose computer, a special purpose computer, an embedded processor, or other programmable data processing terminal device to produce a machine such that the computer or other programmable data processing terminal device
  • the instructions executed by the processor generate means for implementing the functions specified in one or more blocks of the flowchart or in a block or blocks of the flowchart.
  • the computer program instructions can also be stored in a computer readable memory that can direct a computer or other programmable data processing terminal device to operate in a particular manner, such that the instructions stored in the computer readable memory produce an article of manufacture comprising the instruction device.
  • the instruction device implements the functions specified in one or more blocks of the flowchart or in a flow or block of the flowchart.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

本申请实施例提供了一种TCP流重组方法和装置,涉及计算机技术领域。所述方法包括:针对一TCP连接,创建属于客户端的第一数组,和/或属于服务器的第二数组;针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度;当所述有效数据包属于客户端时,根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于客户端的第一数组存储;当所述有效数据包属于服务器时,根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于服务器的第二数组存储。简化了流重组的判断逻辑以及运算过程,从而有效降低了现有TCP流重组方法的复杂度,提高了流重组的效率,更容易满足系统性能方面的需求。

Description

一种TCP流重组方法和装置 技术领域
本申请涉及计算机技术领域,特别是涉及一种TCP流重组方法和一种TCP流重组装置。
背景技术
随着网络犯罪手段不断趋于复杂化和多样化,传统方法无法检测出某些特殊的新型入侵行为,例如利用TCP(Transmission Control Protocol,传输控制协议)协议缺陷,发送大量伪造的TCP连接请求,从而使得被攻击方资源耗尽的SYN flood(拒绝服务)攻击。若敏感信息分片到几个不同的数据包中,数据包特征就会消失从而无法检测出恶意行为,无法满足网络安全防护和打击网络犯罪的实际需要。为了提高恶意数据流检测的准确性,不能只是运用数据包级的处理,必须将每条TCP流的所有数据包重组为完整的会话流,以进行应用级分析。由于TCP流在IP层被切分成多个IP(Internet Protocol,网络协议)分片来传输,使得整个数据传输过程中可能存在TCP报文段失序、重复,甚至还会有丢包的情况。
针对上述情况,在获取TCP数据包之后,如何通过有效的TCP流重组方法实现对TCP连接上传输信息的恢复是一种核心的网络技术。TCP流重组技术是一种将网络包恢复成原始数据流的技术。当前最通用、最常见的TCP流重组方法是采用链表实现的队列缓存TCP包的方式实现的,具体步骤如下:
1、系统创建一个按序到达包队列和一个乱序包队列,用于存储按序到达和提前到达的数据包。其中,按序到达的数据包是指当前到达的数据包是与已经到达的数据包相连的后续报文,提前到达的数据包是指当前到达的数据包不是与已经到达的数据包相连的后续报文,而是提前到来的报 文,此时应该将这个数据包放置到乱序包队列存储起来,以备后续重组使用。
2、在一个新数据包到达之后,先判断该数据包是否为提前到达的数据包,若是提前到达的数据包则存入乱序包队列,若不是提前到达的数据包则存入按序到达包队列。
3、在TCP流结束时则进行合并、组装等一系列较为复杂的运算,完成TCP流重组。
另外,对于每个到达的数据包,都需要对数据包的边界进行多次判断,决定对该数据包做何种处理,例如是拆解还是丢弃。而且对于拆解后保留的部分还需要插入到按序到达队列或者提前到达队列指定的位置。以按序到达的数据包为例。首先需要判断新到达的数据包与已经存入按序到达包队列中的数据包,对应在按序到达包队列中的存储空间是否有重叠的部分,若没有重叠的部分,则直接将新到达的数据包存入按序到达包队列中,而若有重叠的部分,则进一步判断重叠的部分是否对应整个新到达的数据包,若是则可以直接将该新到达的数据包丢弃,若不是则对新到达的数据包进行拆解,丢弃其中重叠的部分,并将保留的部分存入按序到达包队列。
因此可见,现有的流重组方法操作比较复杂,导致效率较低,往往很难满足系统性能方面的需求。
发明内容
鉴于上述问题,提出了本申请实施例以便提供一种克服上述问题或者至少部分地解决上述问题的一种TCP流重组方法和相应的一种TCP流重组装置。
为了解决上述问题,本申请公开了一种TCP流重组方法,包括:
针对一TCP连接,创建属于客户端的第一数组,和/或属于服务器的第二数组;
针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度;
当所述有效数据包属于客户端时,根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于客户端的第一数组存储;
当所述有效数据包属于服务器时,根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于服务器的第二数组存储。
可选地,所述针对一TCP连接,创建属于客户端的第一数组,和/或属于服务器的第二数组的步骤,包括:
在所述TCP连接建立成功之后,创建属于客户端的第一数组,和/或属于服务器的第二数组。
可选地,所述针对一TCP连接,创建属于客户端的第一数组,和/或属于服务器的第二数组的步骤,包括:
在接收所述TCP连接的数据包时,判断所接收到的数据包是否为含有TCP载荷的有效数据包;
如果所接收到的数据包是含有TCP载荷的有效数据包,判断所述有效数据包是否为第一个有效数据包;
如果所述有效数据包是第一个有效数据包,则判断所述有效数据包是否属于客户端;
如果所述有效数据包属于客户端,创建属于客户端的第一数组;
如果所述有效数据包不属于客户端,创建属于服务器的第二数组。
可选地,所述针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度的步骤,包括:
计算所述有效数据包中有效数据的长度作为数据长度;
当所述有效数据包属于客户端,则根据有效数据包的TCP序列号和预先记录的第一纠偏值之差,确定所述有效数据包的偏移量;所述第一纠偏 值为属于客户端的SYN包的初始序列号+1;
当所述有效数据包属于服务器,则根据有效数据包的TCP序列号和预先记录的第二纠偏值之差,确定所述有效数据包的偏移量;所述第二纠偏值为属于服务器的SYN包的初始序列号+1。
可选地,在针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度之后,还包括:
当所述有效数据包属于客户端,则判断所述有效数据包的偏移量和数据长度之和,是否大于第一数组的数组长度;
如果所述有效数据包的偏移量和数据长度之和,大于第一数组的数组长度,则创建一个新的第一数组,所述新的第一数组的数组长度超过原来的第一数组第一阈值;
将原来的第一数组中存储的数据复制到新的第一数组中,并将未存储过的有效数据包的有效数据存储至新的第一数组中。
可选地,在针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度之后,还包括:
当所述有效数据包属于服务器,则判断所述有效数据包的偏移量和数据长度之和,是否大于第二数组的数组长度;
如果所述有效数据包的偏移量和数据长度之和,大于第二数组的数组长度,则创建一个新的第二数组,所述新的第二数组的数组长度超过原来的第一数组第二阈值;
将原来的第二数组中存储的数据复制到新的第二数组中,并将未存储过的有效数据包的有效数据存储至新的第二数组中。
可选地,还包括:
在将原来的第一数组中存储的数据复制到新的第一数组中之后,将原来的第一数组释放。
可选地,还包括:
在将原来的第二数组中存储的数据复制到新的第二数组中之后,将原来的第二数组释放。
可选地,针对一TCP连接,创建属于客户端的第一数组,和/或属于服务器的第二数组的步骤之前,还包括:
当接收到SYN包时,判断所述SYN包是来自客户端还来自服务器;
如果SYN包是来自客户端,则记录客户端的初始序列号ISN(C);
如果SYN包是来自服务器,则记录服务器的初始序列号ISN(S)。
可选地,所述针对一TCP连接,创建属于客户端的第一数组,和/或属于服务器的第二数组的步骤,包括:
针对一TCP连接,在内存中创建属于客户端的第一数组,和/或属于服务器的第二数组。
可选地,所述在当前TCP连接结束后,输出第一数组和/或第二数组中的数据的步骤,包括:
当在所述TCP连接下接收到任一个非指示关闭连接的数据包后,判断出所述TCP连接的空闲时间超过第一时间周期,则结束所述TCP连接,输出第一数组中的数据;
和/或,当在所述TCP连接下接收到指示关闭连接的数据包后,判断出所述TCP连接的空闲时间超过第二时间周期,则结束所述TCP连接,输出第一数组中的数据。
可选地,所述当所述有效数据包属于客户端时,根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于客户端的第一数组存储的步骤,包括:
根据所述有效数据包的偏移量和数据长度,判断所述有效数据包的有效数据与第一数组的有效数据的重叠情况;
如果第一数组中存在与所述有效数据包全部重叠的有效数据,则将所述有效数据包中重叠部分的有效数据丢弃;
如果第一数组中存在与所述有效数据部分重叠的有效数据,将所述有效数据包中重叠部分的有效数据丢弃,并计算不重叠部分的有效数据的第一偏移量和第一数据长度,再将不重叠部分的有效数据在第一数组的第一偏移量位置开始存储,直至存储长度为所述第一数据长度;
如果第一数组中不存在与所述有效数据重叠的有效数据,则将所述有效数据包的有效数据在第一数组的偏移量位置开始存储,直至存储长度为所述数据长度。
可选地,所述当所述有效数据包属于服务器时,根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于服务器的第二数组存储的步骤,包括:
根据所述有效数据包的偏移量和数据长度,判断所述有效数据包的有效数据与第二数组的有效数据的重叠情况;
如果第二数组中存在与所述有效数据包全部重叠的有效数据,则将所述有效数据包中重叠部分的有效数据丢弃,
如果第二数组中存在与所述有效数据部分重叠的有效数据,将所述有效数据包中重叠部分的有效数据丢弃,并计算不重叠部分的有效数据的第二偏移量和第二数据长度,再将不重叠部分的有效数据在第二数组的第二偏移量位置开始存储,直至存储长度为所述第二数据长度;
如果第二数组中不存在与所述有效数据重叠的有效数据,则将所述有效数据包的有效数据在第二数组的偏移量位置开始存储,直至存储长度为所述数据长度。
可选地,还包括:在当前TCP连接结束后,输出第一数组和/或第二数组中的数据。
本申请还公开了一种TCP流重组装置,包括:
第一创建模块,适于针对一TCP连接,创建属于客户端的第一数组,和/或属于服务器的第二数组;
计算模块,适于针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度;
第一存储模块,适于当所述有效数据包属于客户端时,根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于客户端的第一数组存储;
第二存储模块,适于当所述有效数据包属于服务器时,根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于服务器的第二数组存储。
可选地,所述第一创建模块,包括:
第一创建子模块,适于在所述TCP连接建立成功之后,创建属于客户端的第一数组,和/或属于服务器的第二数组。
可选地,所述第一创建模块,包括:
TCP判断子模块,适于在接收所述TCP连接的数据包时,判断所接收到的数据包是否为含有TCP载荷的有效数据包;如果所接收到的数据包是含有TCP载荷的有效数据包,则进入第一判断子模块;
第一判断子模块,适于判断所述有效数据包是否为第一个有效数据包;如果所述有效数据包是第一个有效数据包,则进入客户端判断子模块;
客户端判断子模块,适于判断所述有效数据包是否属于客户端;如果所述有效数据包属于客户端,则进入第一数组创建子模块;如果所述有效数据包不属于客户端,则进入第二数组创建子模块;
第一数组创建子模块,适于创建属于客户端的第一数组;
第二数组创建子模块,创建属于服务器的第二数组。
可选地,所述计算模块,包括:
数据长度计算子模块,适于计算所述有效数据包中有效数据的长度作为数据长度;
第一偏移量计算子模块,适于当所述有效数据包属于客户端,则根据有效数据包的TCP序列号和预先记录的第一纠偏值之差,确定所述有效数据包的偏移量;所述第一纠偏值为属于客户端的SYN包的初始序列号+1;
第二偏移量计算子模块,适于当所述有效数据包属于服务器,则根据有效数据包的TCP序列号和预先记录的第二纠偏值之差,确定所述有效数据包的偏移量;所述第二纠偏值为属于服务器的SYN包的初始序列号+1。
可选地,在所述计算模块之后,还包括:
第一判断模块,适于当所述有效数据包属于客户端,则判断所述有效数据包的偏移量和数据长度之和,是否大于第一数组的数组长度;如果所述有效数据包的偏移量和数据长度之和,大于第一数组的数组长度,则进入第一新数组创建模块;
第一新数组创建模块,适于创建一个新的第一数组,所述新的第一数组的数组长度超过原来的第一数组第一阈值;
第一复制存储模块,适于将原来的第一数组中存储的数据复制到新的第一数组中,并将未存储过的有效数据包的有效数据存储至新的第一数组中。
可选地,在所述计算模块之后,还包括:
第二判断模块,适于当所述有效数据包属于服务器,则判断所述有效数据包的偏移量和数据长度之和,是否大于第二数组的数组长度;如果所述有效数据包的偏移量和数据长度之和,大于第二数组的数组长度,则进入第二新数组创建模块;
第二新数组创建模块,适于创建一个新的第二数组,所述新的第二数 组的数组长度超过原来的第二数组第一阈值;
第二复制存储模块,适于将原来的第二数组中存储的数据复制到新的第二数组中,并将未存储过的有效数据包的有效数据存储至新的第二数组中。
可选地,还包括:
第一释放模块,适于在将原来的第一数组中存储的数据复制到新的第一数组中之后,将原来的第一数组释放。
可选地,还包括:
第二释放模块,适于在将原来的第二数组中存储的数据复制到新的第二数组中之后,将原来的第二数组释放。
可选地,在所述第一创建模块之前,还包括:
SYN包判断模块,适于当接收到SYN包时,判断所述SYN包是来自客户端还来自服务器;如果SYN包是来自客户端,则进入第一记录模块;如果SYN包是来自服务器,则进入第二记录模块;
第一记录模块,适于记录客户端的初始序列号ISN(C);
第二记录模块,适于记录服务器的初始序列号ISN(S)。
可选地,所述第一创建模块,包括:
第一内存创建子模块,适于针对一TCP连接,在内存中创建属于客户端的第一数组,和/或属于服务器的第二数组。
可选地,所述输出模块,包括:
第一输出子模块,适于当在所述TCP连接下接收到任一个非指示关闭连接的数据包后,判断出所述TCP连接的空闲时间超过第一时间周期,则结束所述TCP连接,输出第一数组中的数据;
和/或,第二输出子模块,适于当在所述TCP连接下接收到指示关闭连接的数据包后,判断出所述TCP连接的空闲时间超过第二时间周期,则 结束所述TCP连接,输出第一数组中的数据。
可选地,所述第一存储模块,包括:
第一重叠判断子模块,适于根据所述有效数据包的偏移量和数据长度,判断所述有效数据包的有效数据与第一数组的有效数据的重叠情况;
第一丢弃子模块,适于如果第一数组中存在与所述有效数据包全部重叠的有效数据,则将所述有效数据包中重叠部分的有效数据丢弃;
第一丢弃存储子模块,适于如果第一数组中存在与所述有效数据部分重叠的有效数据,将所述有效数据包中重叠部分的有效数据丢弃,并计算不重叠部分的有效数据的第一偏移量和第一数据长度,再将不重叠部分的有效数据在第一数组的第一偏移量位置开始存储,直至存储长度为所述第一数据长度;
第一存储子模块,适于如果第一数组中不存在与所述有效数据全部重叠的有效数据,则将所述有效数据包的有效数据在第一数组的偏移量位置开始存储,直至存储长度为所述数据长度。
可选地,所述第二存储模块,包括:
第二重叠判断子模块,适于根据所述有效数据包的偏移量和数据长度,判断所述有效数据包的有效数据与第二数组的有效数据的重叠情况;
第二丢弃子模块,适于如果第二数组中存在与所述有效数据包全部重叠的有效数据,则将所述有效数据包中重叠部分的有效数据丢弃,
第二丢弃存储子模块,适于如果第二数组中存在与所述有效数据部分重叠的有效数据,将所述有效数据包中重叠部分的有效数据丢弃,并计算不重叠部分的有效数据的第二偏移量和第二数据长度,再将不重叠部分的有效数据在第二数组的第二偏移量位置开始存储,直至存储长度为所述第二数据长度;
第二丢弃存储子模块,适于如果第二数组中不存在与所述有效数据全 部重叠的有效数据,则将所述有效数据包的有效数据在第二数组的偏移量位置开始存储,直至存储长度为所述数据长度。
可选地,还包括:
输出模块,适于在当前TCP连接结束后,输出第一数组和/或第二数组中的数据。
本申请实施例包括以下优点:
本申请实施例,针对一TCP连接,创建属于客户端的第一数组,和/或属于服务器的第二数组,然后针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度,进一步根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于客户端的第一数组存储。本申请简化了流重组过程中的判断逻辑以及运算过程,从而有效降低了现有TCP流重组方法的复杂度,提高了流重组的效率,更容易满足系统性能方面的需求。
附图说明
图1是本申请的一种TCP流重组方法实施例的步骤流程图;
图1A是本申请的一种TCP连接从开始建立过程到连接关闭的状态变化示意图;
图1B是本申请的一种延迟分配内存的方法示意图;
图1C是本申请的一种将多个有效数据包的有效数据存储至第一数组的相应位置的过程示意图;
图2是本申请的一种TCP流重组方法实施例的步骤流程图;
图2A是本申请的一种TCP数据包结构示意图;
图3是本申请的一种TCP流重组方法实施例的步骤流程图;
图4是本申请的一种TCP流重组方法实施例的步骤流程图;
图5是本申请的一种TCP流重组装置实施例的结构框图;
图6是本申请的一种TCP流重组装置实施例的结构框图;
图7是本申请的一种TCP流重组装置实施例的结构框图;
图8是本申请的一种TCP流重组装置实施例的结构框图。
具体实施方式
为使本申请的上述目的、特征和优点能够更加明显易懂,下面结合附图和具体实施方式对本申请作进一步详细的说明。
本申请实施例的核心构思之一在于,针对一TCP连接,创建属于客户端的第一数组,和/或属于服务器的第二数组,然后针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度,进一步根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于客户端的第一数组存储,在当前TCP连接结束后,输出第一数组和/或第二数组中的数据。本申请简化了流重组过程中的判断逻辑以及运算过程,从而有效降低了现有TCP流重组方法的复杂度,提高了流重组的效率,更容易满足系统性能方面的需求。
实施例一
参照图1,示出了本申请的一种TCP流重组方法实施例的步骤流程图,具体可以包括如下步骤:
步骤110,针对一TCP连接,创建属于客户端的第一数组,和/或属于服务器的第二数组。
TCP(Transmission Control Protocol,传输控制协议)是一种面向连接 的,基于字节流的运输层通信协议。TCP保证了传送数据包的顺序。顺序是用一个序列号来保证的。响应包内也包括一个序列号,表示接收方准备好这个序列号的包。在TCP传送一个数据包时,它会把这个数据包放入重发队列中,同时启动计时器,如果收到了关于这个包的确认信息,便将此数据包从队列中删除,如果在计时器超时的时候仍然没有收到确认信息,则需要重新发送该数据包。另外,TCP通过数据分段中的序列号来保证所有传输的数据可以按照正常的顺序进行重组,从而保障数据传输的完整。TCP连接具有请求和返回两个对应的方向,每个TCP包具有TCP序列号(Sequence Number)、TCP确认号(Acknowledgment Number)及数据包长度(Len)等参数。TCP是一种可靠的面向连接的协议。
其中,TCP序列号为32位,表示数据流中的字节数。是TCP协议中首字节在整个数据流中的位置。
TCP确认号为32位,TCP协议中用于表示序号为确认号减去1的数据包及其以前的所有数据包已经正确接收,对应于期望收到的下一个序列号。
如图1A为TCP连接从开始建立过程到连接关闭的状态变化示意图。在实际应用中,TCP建立连接,首先需要经过“三次握手”的过程。这里以客户端向服务器发起连接来说明,具体步骤如下:
第一次握手:客户端向服务器发送一个同步数据包(SYN,synchronous)请求建立连接,该数据包中,初始序列号(Initial Sequence Number,ISN)是客户端随机产生的一个值,确认号是0;其中,初始序列号为32位,是TCP建立连接阶段的初始序列号。
第二次握手:服务器收到这个同步请求数据包后,会对客户端进行一个同步确认。这个同步确认数据包中,序列号(Sequence Number,SN)是服务器随机产生的一个值,确认号是客户端的初始序列号+1;
第三次握手:客户端收到这个同步确认数据包后,再对服务器进行一个确认。该数据包中,序列号是上一个同步请求数据包中的确认号值,确认号是服务器的初始序列号+1。
完成三次握手后,客户端与服务器可以开始传送数据。
在TCP建立连接后,就可以开始传输数据了。TCP工作在全双工模式,它可以同时进行双向数据传输。这里为了简化,我们只谈服务器向客户端发送数据的情况,而客户端向服务器发送数据的原理和它是类似的,这里便不重复说明。
服务器向客户端发送一个数据包后,客户端收到这个数据包后,会向服务器发送一个确认数据包。
传输数据的简要过程如下:
1)发送数据:服务器向客户端发送一个带有数据的数据包,该数据包中的序列号和确认号与建立连接第三步的数据包中的序列号和确认号相同;
2)确认收到:客户端收到该数据包,向服务器发送一个确认数据包,该数据包中,序列号是为上一个数据包中的确认号值,而确认号为服务器发送的上一个数据包中的序列号+所该数据包中所带数据的大小。
数据分段中的序列号可以保证所有传输的数据按照正常的次序进行重组,而且通过确认保证数据传输的完整性。
前面我们提到,建立一个连接需要3个步骤,但是关闭一个连接需要经过4个步骤。因为TCP连接是全双工的工作模式,所以每个方向上需要单独关闭。在TCP关闭连接时,首先关闭的一方(即发送第一个终止数据包的)将执行主动关闭,而另一方(收到这个终止数据包的)再执行被动关闭。
关闭连接的4个步骤如下:
1、服务器完成它的数据发送任务后,会主动向客户端发送一个终止(FIN)数据包,以关闭在这个方向上的TCP连接。该数据包中,序列号为客户端发送的上一个数据包中的确认号值,而确认号为服务器发送的上一个数据包中的序列号+该数据包所带的数据的大小;
2、客户端收到服务器发送的终止数据包后,将对服务器发送确认信息,以关闭该方向上的TCP连接。这时的数据包中,序列号为第1步中的确认号值,而确认号为第1步的数据包中的序列号+1;
3、同理,客户端完成它的数据发送任务后,就也会向服务器发送一个终止数据包,以关闭在这个方向上的TCP连接,该数据包中,序列号为服务器发送的上一个数据包中的确认号值,而确认号为客户端发送的上一个数据包中的序列号+该数据包所带数据的大小;
4、服务器收到客户端发送的终止数据包后,将对客户端发送确认信息,以关闭该方向上的TCP连接。这时在数据包中,序列号为第3步中的确认号值,而确认号为第3步数据包中的序列号+1;
在本申请实施例中,服务器侧会针对一TCP连接,创建属于客户端的第一数组,和/或属于服务器的第二数组,用以重组在连接中传输的数据包中的数据。其中,第一数组的大小可以根据需求灵活设定,对此本申请不加以限定;可以在任何可以创建数组的存储空间中创建第一数组和/或第二数组,例如内存、云存储空间等。
在实际应用中,针对一TCP连接,客户端与服务器之间是可以互相通信的,因此客户端可以发送数据包,服务器也可以向客户端响应的数据包,此时,若要针对该TCP连接进行数据流重组,可以分别将来自客户端的数据流重组和/或来自服务器的数据流重组。如果要同时针对一TCP连接下客户端发送的数据包重组,以及服务器为客户端响应的数据包重组,则分别创建属于客户端的第一数组,和属于服务器的第二数组,其中第一数组 用以重组来自客户端的数据流,第二数组用以重组来自服务器的数据流。比如,如果只需要针对一TCP连接下客户端发送的数据包进行重组,则此时只需在内容中创建属于客户端的第一数组;如果只需要针对一TCP连接下服务器为客户端响应的数据包重组,则此时只需在内容中创建属于服务器的第二数组。具体地,可以根据实际需求,创建属于客户端的第一数组,和/或属于服务器的第二数组,对此本申请实施例不加以限定。
在本申请实施例中,针对一TCP连接,创建属于客户端的第一数组,和/或属于服务器的第二数组的过程中,可以在新建连接的过程中创建第一数组,和/或第二数组,也可以在连接创建之后,再创建第一数组和/或第二数组。本申请可以根据实际设置选择创建时机。
在本申请的另一个优选地实施例中,所述步骤110,包括:
子步骤A111,在所述TCP连接建立成功之后,创建属于客户端的第一数组,和/或属于服务器的第二数组。
如图1B为延迟分配内存的方法示意图。此时,是在TCP连接建立成功之后,再创建属于客户端的第一数组,和/或属于服务器的第二数组,相对于在TCP连接还未成功建立之前,在创建属于客户端的第一数组,和/或属于服务器的第二数组,延迟了创建用以进行数据流重组的第一数组和/或第二数组。
在实际应用中,若是在TCP连接建立过程中,例如在服务器接收到客户端发送的SYN包时,就创建第一数组和/或第二数组,那么,如果此时受到SYN flood(拒绝服务)攻击,即黑客发送大量的SYN包,则相应地,会创建大量的第一数组和/或第二数组,从而耗费大量的系统内存,影响系统的正常运行。
所以,在本申请中,可以延迟创建第一数组和/或第二数组,即在TCP连接建立成功之后,再创建属于客户端的第一数组,和/或属于服务器的第 二数组。从而可以有效地避免上述的问题。
另外,在本申请实施例中,第一数组可以为普通数组,在创建时即确定数组的大小,也可以为动态数组,所谓动态数组,是指在创建时没有确定数组大小的数组,当使用该动态数组时,可随时用函数重新定义该动态数组的大小。
在本申请的另一个优选地实施例中,所述步骤110,包括:
子步骤B111,针对一TCP连接,在内存中创建属于客户端的第一数组,和/或属于服务器的第二数组。
在本申请实施例中,为了方便将客户端和/或服务器的有效数据包快速地发送至第一数组和/或第二数组,可以直接在服务器的内存中创建属于客户端的第一数组,和/或属于服务器的第二数组。
步骤120,针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度。
其中,TCP载荷是指TCP数据包中除去TCP报头信息以外的部分。载荷数据是变长字段,它包含下一个头字段描述的数据。有效载荷数据字段是强制性的,它的长度是字节的整数倍。该有效数据包还是TCP包。
在发明实施例中,若数据包含有TCP载荷,则说明该数据包为有效数据包。
在本申请实施例中,有效数据包的偏移量(offset)为该有效数据包的序列号与前述的SYN数据包的初始序列号加1的差值,即该有效数据包与SYN数据包之间的距离。因为一个初始序列号将占用一个序号,所以要加1。数据长度(Length,Len)是指有效数据包中的数据所占内存的空间,一般以字节(byte)为单位。
另外,在本申请实施例中,可以采用现有的任何一种可用技术计算有效数据包的数据长度,对此,本申请实施例不加以限定。
步骤130,当所述有效数据包属于客户端时,根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于客户端的第一数组存储。
在本申请实施例中,有效数据包属于客户端是指该有效数据包是由客户端发送的有效数据包。当所述有效数据包属于客户端时,可以根据有效数据包的偏移量以及和数据长度,在第一数组中查找用以存储该有效数据包中的有效数据的存储空间,然后按照一定顺序将有效数据包中的有效数据存储至第一数组的相应偏移量和数据长度的位置。其中,可以按照各有效数据在对应有效数据包中的存储顺序,也可以按照相反的顺序或者其他设定的顺序,将效数据包中的有效数据存储至第一数组的相应偏移量和数据长度的位置,对此,本申请实施例不加以限定。
例如,假设第一数组的长度为20,存储空间位置为1-20,当前接收到的一个有效数据包的偏移量为5,数据长度为10。则会将该有效数据包中的有效数据存储于第一数组中的选择6-15的存储空间位置,也即从存储空间位置6开始存储该有效数据,一直存储到存储空间位置15,则该数据包的有效数据存储完毕。
在实际应用中,根据各有效数据包的偏移量以及数据长度,可以将各有效数据包分为三类:按序到达的有效数据包,提前到达的有效数据包、重叠的有效数据包,其中重叠的有效数据包同时可能为按序到达的有效数据包或提前到达的有效数据包。其中,假设当前已到达的有序数据包已经存储到数组的第N个元素,按序到达的有效数据包是指偏移量等于N+1的有效数据包;提前到达的有效数据包是指指偏移量大于N+1的有效数据包;重叠的有效数据包是指其数据在第一数组中的位置与已经存储于第一数组的数据有重合的部分的有效数据包。
在本申请实施例中,无论按序到达,提前到达,重叠,都可以首先计 算到达包的偏移位置(offset)和长度(len),然后将有效数据包的数据存储到第一数组对应的位置。
如图1C为针对6个不同有效数据包(case1、case2、case3、case4、case5、case6),将各有效数据包的有效数据存储至第一数组的相应位置的过程。其中case1、case2是按序到达第一数组的有效数据包,case5是提前到达第一数组的有效数据包,case3、case4、case6是重叠的有效数据包。
在第一个带载荷数据包到达之前,即第一个有效数据包到达之前,第一数组的数组空间未开辟。
在case1的情况下:第一个带载荷包到达,即第一个有效数据包到达,则此时开辟第一数组的数组空间,该第一个有效数据包的有效数据的偏移值offset=0,长度len=100,则从第一数组的数组空间的0偏移位置开始按序存储该有效数据,存储到偏移99的位置,则该第一数组的有效数据包重组完毕。
在case2的情况下,第二个有效数据包按序到达,此时的第一数组中存储了case1中的第一个有效数据包的有效数据。第二个有效数据包的偏移offset=100,长度len=100,那么则查找第一数组的偏移100的位置,找到之后,则在第一数组的偏移100位置开始将第二个有效数据包的有效数据按序存储,一直存储到偏移199的位置,则第二个有效数据包的有效数据重组完毕。
在case3的情况下,接收到了第三个有效数据包,但是该数据包的偏移offset=50,长度len=100,由于case1第一个有效数据包的偏移offset=0,长度len=100,第二个有效数据包的偏移offset=100,长度len=100,那么该第三个数据包的有效数据在前两个有效数据包的有效数据之内。那么找到第一个数据包的偏移50的位置开始,将第一个有效数据包的有效数据按序进行覆盖,直到偏移149的位置,则该有效数据包的有效数据重组完 毕。
在case4的情况下,第四个有效数据包按序到达,但是该有效数据包的偏移offset=150,长度len=100,由于第二个有效数据包的偏移offset=100,长度len=100,那么该第四个有效数据包与第二个有效数据包由重叠的部分,此时从第二个数据包的偏移150的位置开始,利用第四个有效数据包将第二个有效数据包的有效数据按序进行覆盖,直到偏移199的位置,然后继续从偏移200的位置开始,将第四个有效数据包剩下的部分按序存储,直到偏移249的位置,则该有效数据包的有效数据重组完毕。
在case5的情况下,第五个有效数据包到达,该有效数据包的偏移offset=300,长度len=100,可见其偏移量大于之前接收到的任一个有效数据包的偏移量与长度之和,即其不与接收到有效数据包相连,是提前到达的数据包,此时直接从偏移300的位置开始,按序存储第五有效数据包,直到偏移399的位置为止,则该有效数据包的有效数据重组完毕。
在case6的情况下,第七个有效数据包到达,该有效数据包的偏移offset=450,长度len=100,在其之前已经接收到偏移offset=500,长度len=100的第六个有效数据包,可见第七个有效数据包的偏移小于第六个有效数据包的偏移,但是两者之间的差值小于第七个有效数据包的长度,所以第七个有效数据包和第六个有效数据包存在重叠的部分,此时从偏移450的位置开始将第七个有效数据包不与第六个有效数据包不重叠的部分按序存储,直到偏移499的位置结束,然后从偏移500的位置开始,利用第七个数据包还未存储的部分将第六个有效数据包按序进行覆盖,直至偏移549的位置结束,则该有效数据包的有效数据重组完毕。
可以看出,即使两个有效数据包对应的在第一数组中的位置有重叠的部分,仍然会按照两个有效数据包到达的顺序分别将两个有效数据包中的有效数据存储至第一数组对应的位置,对于其中重叠的部分,后存储的有 效数据可以覆盖之前存储的有效数据。从而保证对于重复接收到的数据,在第一数组中不会重复存储。
可以理解,对于不同类型的case的情况下,对有效数据包都可以无需判断是否有重复的部分,可以直接按照偏移量和长度将各有效数据包中的有效数据存储至第一数组,从而更节省计算量,提高流重组的效率。
但是,对于重叠到达的有效数据包,也可以将重叠到达的有效数据包中重叠的有效数据直接丢弃,然后按照其中未重叠的有效数据的偏移量和长度,将重叠到达的有效数据包中未重叠的有效数据存储至第一数组,本申请实施例不加以限定。相对于直接将重叠到达的有效数据包的全部有效数据存储至第一数组,若需要判断重叠到达的有效数据包具体的重叠情况,然后相应地丢弃或存储,计算量会稍大一点。
优选地,在本申请另一个优选的实施例中,步骤130包括:
子步骤131,根据所述有效数据包的偏移量和数据长度,判断所述有效数据包的有效数据与第一数组的有效数据的重叠情况。
如前述,在实际应用中,还未存储至第一数组的有效数据包可能会与第一数组中的有效数组有重叠,而且对于有重叠的有效数据包,根据具体的重叠部分,又可以分为全部重叠和部分重叠。其中,全部重叠是指有效数据包中的有效数据对应在第一数组中的存储空间已经全部存储过有效数据,例如图1C中的有效数据包case3;部分重叠是指有效数据包中的有效数据对应在第一数组中的部分存储空间已经存储过有效数据,例如图1C中的有效数据包case6。对于不重叠的有效数据包、全部重叠的有效数据包以及部分重叠的有效数据包,本申请实施例只需要将其中未存储至第一数组的有效数据存储至第一数组。因此,首先需要根据有效数据包的偏移量和数据长度,判断所述有效数据包的有效数据与第一数组的有效数据的重叠情况。
子步骤132,如果第一数组中存在与所述有效数据包全部重叠的有效数据,则将所述有效数据包中重叠部分的有效数据丢弃。
如果第一数组中存在与有效数据包全部重叠的有效数据,说明第一数组中对应该有效数据包的存储空间已经存有该有效数据包中的有效数据,则不需要将有效数据包中的有效数据再次存储至对应存储空间,因此可以直接将有效数据包中重叠部分的有效数据丢弃,也即可以直接将该有效数据包丢弃。例如,对于图1C中的有效数据包case3,则可以将其直接丢弃。
子步骤133,如果第一数组中存在与所述有效数据部分重叠的有效数据,将所述有效数据包中重叠部分的有效数据丢弃,并计算不重叠部分的有效数据的第一偏移量和第一数据长度,再将不重叠部分的有效数据在第一数组的第一偏移量位置开始存储,直至存储长度为所述第一数据长度。
如果第一数组中存在与有效数据包部分重叠的有效数据,说明第一数组中对应该有效数据包的存储空间中的部分存储空间已经存有该有效数据包中的对应的部分有效数据,那么对于重叠部分的有效数据,则不需要将重叠部分的有效数据再次存储至对应存储空间,可以直接将有效数据包中的重叠部分的有效数据丢弃;而对于不重叠的有效数据,仍需要按照不重叠的有效数据的偏移量和数据长度,将其存储至第一数组对应存储空间。
例如,对于图1C中的有效数据包case6,偏移量offset=450,数据长度len=100。此时,第一数组中偏移0到偏移249、偏移300到偏移399、偏移500到偏移599的存储空间位置已经存储数据,可以看出,对于case6而言,其对应偏移500至偏移549存储空间位置的有效数据已经存在于之前的有效数据包中,被存储至第一数值,对于此部分重叠的有效数据,可以直接丢弃;而对于另外的对应偏移450至499的存储空间位置的有效数 据,则可以按照此不重叠部分的有效数据的偏移量和数据长度,按序依次将其存储至第一数组对应存储空间。
子步骤134,如果第一数组中不存在与所述有效数据重叠的有效数据,则将所述有效数据包的有效数据在第一数组的偏移量位置开始存储,直至存储长度为所述数据长度。
而如果第一数组中不存在与所述有效数据重叠的有效数据,例如图1C中的有效数据包case1、case2、case5,则可以直接将有效数据包的有效数据在第一数组的对应有效数据包的偏移量位置开始存储,直至存储长度为所述数据长度。
步骤140,当所述有效数据包属于服务器时,根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于服务器的第二数组存储。
本步骤是针对将服务器侧有效数据包中的有效数据向属于服务器的第二数组存储,与前述的步骤130类似,在此不再赘述。其中,有效数据包属于服务器,是指该有效数据包是由服务器响应的有效数据包。
在本申请的另一个优选地实施例中,步骤140,包括:
子步骤141,根据所述有效数据包的偏移量和数据长度,判断所述有效数据包的有效数据与第二数组的有效数据的重叠情况。
子步骤142,如果第二数组中存在与所述有效数据包全部重叠的有效数据,则将所述有效数据包中重叠部分的有效数据丢弃。
子步骤143,如果第二数组中存在与所述有效数据部分重叠的有效数据,将所述有效数据包中重叠部分的有效数据丢弃,并计算不重叠部分的有效数据的第二偏移量和第二数据长度,再将不重叠部分的有效数据在第二数组的第二偏移量位置开始存储,直至存储长度为所述第二数据长度。
子步骤144,如果第二数组中不存在与所述有效数据重叠的有效数据,则将所述有效数据包的有效数据在第二数组的偏移量位置开始存储,直至存储长度为所述数据长度。
子步骤141至子步骤14是针对将服务器侧有效数据包中的有效数据向属于服务器的第二数组存储,与前述的子步骤131至子步骤134类似,在此不再赘述。
在本申请另一个优选地实施例中,在步骤130、步骤140之后,还包括:
步骤150,在当前TCP连接结束后,输出第一数组和/或第二数组中的数据。
在本申请实施例中,经过前述步骤110-140之后,第一数组和/或第二数组中的数据已经是完成流重组的流数据,因此在输出第一数组和/或第二数组中的数据的过程中,只需要将第一数组和/或第二数组的首地址和数据长度传递出来,即可以依次获取第一数组和/或第二数组中的流数据。
其中TCP连接结束判断的主要依据是TCP流正常结束(如步骤110中所述的TCP关闭连接)、被RST(TCP首部中的6个标志比特之一,表示重置连接、复位连接)中断或者链接超时释放三种情况。
在本申请实施例中,对于上述三种方式导致的TCP连接结束的情况,都可以输出第一数组和/或第二数组中的数据。当然,也可以根据需求设定只在上述的三种方式中的任意一种或多种方式导致的TCP连接结束的情况下,输出第一数组和/或第二数组中的数据,对此,本申请实施例不加以限定。
在本申请实施例中,首先针对一TCP连接,创建属于客户端的第一数组,和/或属于服务器的第二数组,然后针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度,进一步根 据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于客户端的第一数组存储。简化了流重组过程中的判断逻辑以及运算过程,从而有效降低了现有TCP流重组方法的复杂度,提高了流重组的效率,更容易满足系统性能方面的需求。
另外,在本申请又一个优选地实施例中,在TCP连接建立成功之后,再创建属于客户端的第一数组,和/或属于服务器的第二数组,从而可以有效地避免因为受到SYN flood(拒绝服务)攻击,而耗费大量的系统内存,影响系统的正常运行的问题。
实施例二
本申请实施例对客户端发送的数据包的重组过程进行介绍。
参照图2,示出了本申请的一种TCP流重组方法实施例的步骤流程图,具体可以包括如下步骤:
步骤208,当接收到SYN包时,判断所述SYN包是来自客户端还来自服务器;如果SYN包是来自客户端,则进入步骤210;
步骤210记录客户端的初始序列号ISN(C)。
当然,记录了客户端的ISN(C)后,可以计算第一纠偏值ISN(C)+1。如果SYN包是来自服务器,可以不处理。
在实际应用中,TCP是面向连接的传输协议,即在利用TCP进行数据传输之前,必须首先建立连接关系。如实施例一步骤110中所述的客户端与服务器之间,TCP连接的第一次握手过程,是客户端先发送SYN包至服务器。然后服务器返回一个SYN包和ACK包。
当然,实际应用中对于第一纠偏值,可以在如图1B的过程中,在收到客户端的ACK包时,直接从ACK包中提取ISN(C)+1作为纠偏值。也可以在收到第一个客户端的有效数据包时,从该有效数据包中提取TCP序列号ISN(C)+1作为第一纠偏值。
步骤212,在接收所述TCP连接的属于客户端的数据包时,判断所接收到的数据包是否为含有TCP载荷的有效数据包;如果所接收到的数据包是含有TCP载荷的有效数据包,则进入步骤214。
在实际应用中,对于TCP连接下,接收到的数据包,其中包括含有TCP载荷的数据包,不含有TCP载荷数据包。其中,含有TCP载荷的数据包,称为有效数据包,而对于本申请而言,针对的是含有TCP载荷的有效数据包的流重组,所以,在本申请实施例中,在接收TCP连接的数据包时,会判断所接收到的数据包是否为含有TCP载荷的有效数据包;如果所接收到的数据包是含有TCP载荷的有效数据包,则继续执行后续的步骤,而若接收到的数据包不是含有TCP载荷的有效数据包,则可以忽略本数据。
步骤214,判断所述有效数据包是否为第一个有效数据包;如果所述有效数据包是第一个有效数据包,则进入步骤216。
在本申请实施例中,在一次TCP建立连接到结束连接的过程中,接收到客户端侧的数据包,可以分为以下四种情况:1)建立连接的SYN包;2)第一个含有TCP载荷的数据包;3)其他含有TCP载荷的数据包;4)终止连接的FIN/RST包。
其中,若接收到的有效数据包是第一个含有TCP载荷的数据包,即第一个有效数据包,则此时需要创建第一数组,存储该有效数据包中的有效数据,从而在本次TCP连接,对于以后接收到的其他含有TCP载荷的数据包,将其中的有效数据都存储于该以创建的第一数组中。而对于建立连接的SYN包,其作用只是为了建立TCP连接,其中的数据并不是必须要存储于第一数组中,所以若接收的数据包是建立连接的TCP包,此时并不需要创建第一数组,同样对于终止连接的FIN/RST包,也不需要创建第一数组。
步骤218,创建属于客户端的第一数组。
本申请实施例是针对客户端侧的数据包,进行数据流重组。所以,此时可以只需创建属于客户端的第一分组,用以存储来自客户端的有效数据包中的有效数据。
在本申请实施例中,若接收的客户端的数据包是第一个有效数据包,则创建第一数组,此时是创建第一数组的最佳时机。但是需要说明的是,第一数组并不是必须在接收到第一个有效数据包之后才可以创建的,其也可以在本步骤之前的任一步骤之前预先创建,对此本申请实施例不加以限定。
步骤220,计算所述有效数据包中有效数据的长度作为数据长度。
如图3所示TCP数据包的结构示意图。其中红色框中部分加上可选选项、填充可以认为是TCP报头信息,用户数据则可认为是TCP载荷,而用户数据中的数据部分可认为是本申请所述的有效数据。
在本申请实施例中,有效数据包中有效数据的长度为数据长度。在实际应用中,有效数据包中的有效数据可能为多种数据结构,此时需要针对性地利用不同的方法计算有效数据的长度。在本申请实施例中,可以利用任何一种现有的可利用技术计算有效数据包中有效数据的长度,对此本申请实施例不加以限定。
步骤222,根据有效数据包的TCP序列号和预先记录的第一纠偏值之差,确定所述有效数据包的偏移量;所述第一纠偏值为属于客户端的SYN包的初始序列号+1。
在本申请实施例中,可以设定有效数据的偏移量为有效数据包的TCP序列号和第一纠偏值之差。其中TCP序列号是已知的,存储于TCP数据包中,即为图2A中的数据序号。第一纠偏值为SYN包的初始序列号加1,因为一个初始序列号将占用一个序号,所以要加1。其中初始序列号(ISN (C))随时间而变化的,而且不同的操作系统也会有不同的实现方式,所以每个连接的初始序列号是不同的。如实施例一所述的TCP连接过程可知,第一纠偏值在TCP连接过程中即可获得并预先记录。
由TCP建立连接的过程可知,客户端发送SYN包给服务器时,会在SYN包中写入一个初始序列号,其中在本申请中,客户端发送的SYN包可以称为属于客户端的SYN包,然后服务器返回SYN/ACK包,服务器的SYN/ACK包实际上是一个SYN包,此时服务器会将客户端的SYN的ISN(C)+1作为确定序列号返回客户端,同时服务器的响应的SYN包中也会有一个服务器的初始序列号ISN(S)。客户端在发送ACK时会携带客户端的SYN的ISN(C)+1的序列号以及ISN(S)+1返回服务器,然后建立连接。建立连接成功后,则客户端会开始进行数据传输,有效数据包则中则会在TCP序列号中以ISN(C)+1为开始字节,记录客户端发送的字节数,每发送一个有效数据包,则在TCP序列号中记录该次发送的有效数据的开头字节。服务器开始响应有效数据包时,则会在有效数据包中以ISN(S)+1为开始字节,记录服务器响应的字节数,每发送一个有效数据包,则在TCP序列号中记录该次发送的有效数据的开头字节。
因此,本申请实施例如果要对客户端的数据包重组,则可以在接收到客户端发送的SYN数据包时,获取SYN包中的ISN(C),然后计算第一纠偏差值ISN(C)+1并记录。或者在接收到客户端发送的ACK数据包时,获取该ACK包中的确认序列号ISN(C)+1,并记录其为第一纠偏差值。或者在建立连接后,接收到的第一个有效数据包时,获取其TCP序列号,因为其是从第0字节开始发送数据,其应该也为ISN(C)+1,可以记录为针对客户端的第一纠偏差值。
需要说明的是,在本申请实施例中步骤222也可以在步骤220之前执行,或者是与步骤220同时执行,对此本申请实施例不加以限定。
步骤224,判断所述有效数据包的偏移量和数据长度之和,是否大于第一数组的数组长度;如果所述有效数据包的偏移量和数据长度之和,大于第一数组的数组长度,则进入步骤226。
在本申请实施例中,因为有效数据包具有偏移量,所以在将接收到的有效数据包中的有效数据存储至第一数组之前,还需要考虑的是,当前的第一数组的数组长度是否足够存储接收到的有效数据。
例如,假设第一数组的长度为20,按序标号为1-20,接收到的有效数据包的偏移量为11,数据长度为10。则对于该有效数据包中的有效数据,会从第一数组中第12个位置开始记录,此时第一数组的长度只可以存储数据长度为9的有效数据,无法完整存储接收到的该偏移量为11,数据长度为10的有效数据包的有效数据。
所以,在本申请实施例中,会判断接收到的有效数据包的偏移量和数据长度之和,是否大于第一数组的数组长度,若有效数据包的偏移量和数据长度之和,大于第一数组的数组长度,则需要新建一个比原来的第一数组更长的第一数组;而若有效数据包的偏移量和数据长度之和,不大于第一数组的数组长度,则继续使用原来的第一数组,不需要新建第一数组。
步骤230,创建一个新的第一数组,所述新的第一数组的数组长度超过原来的第一数组第一阈值。
由步骤224所述,创建的新的第一数组的数组长度必然要超过原来的第一数组。在本申请实施例中,设定新的第一数组的数组长度超过原来的第一数组的数组长度第一阈值。其中第一阈值可以为原来的第一数组的数组长度的整数倍,例如,原来的第一数组的数组长度为20,创建的新的第一数组的数组长度为40,此时新的第一数组的数组长度超过原来的第一数组的数组长度20,即为此时的第一阈值,该第一阈值为原来的第一数组的数组长度的1倍。当然第一阈值也可以为其他取值,可以根据需求灵活设 定,对此本申请实施例不加以限定。
另外,若原来的第一数组为前述的动态数组,则此时可以不另外创建一个新的第一数组,而可以利用函数(如ReDim函数)重新指出原来的第一数组的大小,将其数组长度修改为超过其原来数组长度第一阈值。此时相对于原来数组长度的第一数组,可以称修改过数据长度的第一数组为新的第一数组。
步骤226,将原来的第一数组中存储的数据复制到新的第一数组中,并将未存储过的有效数据包的有效数据存储至新的第一数组中。
为了保证重组数据的完整性,在本申请实施例中,在创建了新的第一数组后,会将原来的第一数组中存储的数据复制到新的第一数组中,然后继续利用该新的第一数组,存储接收到的还未存储过的有效数据包的有效数据。
其中,将原来的第一数组中存储的数据复制到新的第一数组中,可以理解为,保持第一数组中存储的数据所属的有效数据包的偏移量和数据长度不变,将其相应地存储于新的第一数组中。
另外,若该新的第一数组为步骤230中所述的修改了数组长度的动态数组,则此时不需要复制的过程,直接继续将未存储过的有效数据包的有效数据存储至新的第一数组中。
步骤228,根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于客户端的第一数组存储。
需要说明的是,若经过步骤230后创建一个新的第一数组,则针对接收到的未存储的有效数据包,此时本步骤中的第一数组是指步骤230创建的新的第一数组。若未创建一个新的第一数组,则本步骤中的第一数组仍然为步骤218创建的第一数组。
在本申请另一个优选地实施例中,还包括:
步骤230,在当前TCP连接结束后,输出第一数组中的数据。
那么在当前TCP连接后,可以将内存的第一数组中的数据输出至指定存储空间,比如输出至硬盘中进行存储。
在本申请另一个优选的实施例中,在本申请实施例中,步骤230包括:
子步骤2301,当在所述TCP连接下接收到任一个非指示关闭连接的数据包后,判断出所述TCP连接的空闲时间超过第一时间周期,则结束所述TCP连接,输出第一数组中的数据。
在实际应用中,在TCP连接情况下,若接收到任一个非指示关闭连接的数据包后,在一定时间内都未执行任何操作,即TCP连接的空闲时间超过一定时间,则此时可判定结束当前的TCP连接。在本申请实施例中,设定TCP连接的空闲时间超过第一时间周期,则结束所述TCP连接。其中,第一时间周期可以根据需求灵活设定,对此本申请实施例不加以限定。
在TCP连接结束后,即将第一数组中的数据输出。同样,若经过步骤230后创建一个新的第一数组,则此时本步骤中的第一数组是指步骤230创建的新的第一数组。若未创建一个新的第一数组,则本步骤中的第一数组仍然为步骤216创建的第一数组。
而在TCP连接下,接收到任一个非指示关闭连接的数据包后,若判断出所述TCP连接的空闲时间未超过第一时间周期,则不结束TCP连接,此时也不会输出第一数组中的数据。
和/或,子步骤2302,当在所述TCP连接下接收到指示关闭连接的数据包后,判断出所述TCP连接的空闲时间超过第二时间周期,则结束所述TCP连接,输出第一数组中的数据。
还有另外一种情况,在TCP连接情况下,若接收到指示关闭连接的数据包后,判断出TCP连接的空闲时间超过第二时间周期,则结束TCP连接,输出第一数组中的数据。而若TCP连接的空闲时间未超过第二时间周 期,则不结束TCP连接,也不会输出第一数组中的数据。其中的第二时间周期也可以根据需求灵活设定,对比本申请实施例也不加以限定。而且,同样若经过步骤230后创建一个新的第一数组,则此时本步骤中的第一数组是指步骤230创建的新的第一数组。若未创建一个新的第一数组,则本步骤中的第一数组仍然为步骤216创建的第一数组。
另外,在本申请实施例中,也可以在TCP连接下接收到指示关闭连接的数据包后,直接结束TCP连接,输出第一数组中的数据,而不需要判断TCP连接的空闲时间是否超过第二时间周期,即相当于此时的第二时间周期为零。
在本申请一优选的实施例中,在本申请实施例中,还包括:
步骤232,在将原来的第一数组中存储的数据复制到新的第一数组中之后,将原来的第一数组释放。
在本申请实施例中,在将原来的第一数组中存储的数据复制到新的第一数组中之后,此时原来的第一数组就不再具有任何作用,此时为了避免占用内存,可以将原来的第一数组释放,例如删除第一数组。该步骤可以在步骤226之后执行,或者在步骤226之后的任一步骤之后执行,对此本申请实施例不加以限定。
另外,需要说明的是,若该新的第一数组为步骤230中所述的修改了数组长度的动态数组,则此时不需要将原来的第一数组释放。
本申请实施例是针对一TCP连接,对由客户端发送的有效数据包中的有效数据进行重组。具体执行过程为,首先针对一TCP连接,创建属于客户端的第一数组,然后针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度,进一步根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于客户端的第一数组存储。从而简化了对于客户端的流重组过程中的判断逻辑以及运 算过程,从而有效降低了现有TCP流重组方法的复杂度,提高了流重组的效率,更容易满足系统性能方面的需求。
而且,在本申请实施例中,还会在接收到的有效数据包的偏置量和数据长度之和超出第一数组长度时,利用新的第一数组替换原有的第一数组。在保证流重组的效率的同时,提高了流重组的准确性,从而使其更容易满足系统性能方面的需求。
实施例三
本申请实施例对服务器响应的数据包的重组过程进行介绍。
参照图3,示出了本申请的一种TCP流重组方法实施例的步骤流程图,具体可以包括如下步骤:
步骤308,接收到SYN包时,判断所述SYN包是来自客户端还来自服务器;如果SYN包是来自服务器,则进入步骤310。
步骤310,记录服务器的初始序列号ISN(S);
当然,在记录了服务器的初始序列号ISN(S)后,可以计算第二纠偏值ISN(S)+1。
在本申请实施例中,如果SYN包是来自客户端,可以不出来。
步骤312,在接收所述TCP连接的属于服务器的数据包时,判断所接收到的数据包是否为含有TCP载荷的有效数据包;如果所接收到的数据包是含有TCP载荷的有效数据包,则进入步骤312。
步骤314,判断所述有效数据包是否为第一个有效数据包;如果所述有效数据包是第一个有效数据包,则进入步骤314。
步骤316,创建属于服务器的第二数组。
本申请实施例是针对服务器侧的数据包,进行数据流重组。所以,此时可以只需创建属于服务器的第一分组,用以存储来自服务器的有效数据包中的有效数据。
步骤318,计算所述有效数据包中有效数据的长度作为数据长度。
步骤320,根据有效数据包的TCP序列号和预先记录的第二纠偏值之差,确定所述有效数据包的偏移量;所述第二纠偏值为属于服务器的SYN包的初始序列号+1。
本申请实施例如果要对服务器的数据包重组,则可以在获取到服务器响应的SYN数据包时,获取SYN包中的ISN(S),然后计算第二纠偏差值ISN(S)+1并记录。或者在接收到客户端发送的ACK数据包时,获取该ACK包中的确认序列号ISN(S),并记录其为第二纠偏差值。或者在建立连接后,接收到的第一个服务器响应的有效数据包时,获取其TCP序列号,因为其是从第0字节开始发送数据,其应该也为ISN(S)+1,可以记录为针对服务器的第二纠偏差值。
步骤322,判断所述有效数据包的偏移量和数据长度之和,是否大于第二数组的数组长度;如果所述有效数据包的偏移量和数据长度之和,大于第二数组的数组长度,则进入步骤324。
步骤324,创建一个新的第二数组,所述新的第二数组的数组长度超过原来的第一数组第二阈值。
步骤326,将原来的第二数组中存储的数据复制到新的第二数组中,并将未存储过的有效数据包的有效数据存储至新的第二数组中。
步骤328,根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于服务器的第二数组存储。
在本申请另一个优选地实施例中,还包括:
步骤330,在当前TCP连接结束后,输出第二数组中的数据。
在本申请另一个优选地实施例中,还包括:
步骤332,在将原来的第二数组中存储的数据复制到新的第二数组中之后,将原来的第二数组释放。
本步骤可以在步骤326之后的任意时刻执行,对此本申请实施例不加以限定。
本申请实施例对服务器侧的有效数据包的重组原理与实施例二对客户端侧的数据包的重组原理基本类似,参照实施例一类似的步骤即可,在此不再详述。
本申请实施例是针对一TCP连接,对由服务器发送的有效数据包中的有效数据进行重组。具体执行过程为,首先针对一TCP连接,创建属于服务器的第二数组,然后针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度,进一步根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于服务器的第二数组存储。从而简化了对于服务器侧的流重组过程中的判断逻辑以及运算过程,从而有效降低了现有TCP流重组方法的复杂度,提高了流重组的效率,更容易满足系统性能方面的需求。
而且,在本申请实施例中,还会在接收到的有效数据包的偏置量和数据长度之和超出第一数组长度时,利用新的第二数组替换原有的第二数组。在保证流重组的效率的同时,提高了流重组的准确性,从而使其更容易满足系统性能方面的需求。
实施例四
本实施例介绍同时对客户端的数据包和对服务器的数据包进行重组的一种优选的过程。
参照图4,示出了本申请的一种TCP流重组方法实施例的步骤流程图,具体可以包括如下步骤:
步骤410,当接收到SYN包时,判断所述SYN包是来自客户端还来自服务器;如果SYN包是来自客户端,则进入步骤412;如果SYN包是来自服务器,则进入步骤414;
步骤412,记录客户端的初始序列号ISN(C);
步骤414,记录服务器的初始序列号ISN(S)。
而且在实际应用中,客户端和服务器的初始序列号ISN都是随机产生的,客户端的ISN和服务器的初始序列号ISN相同的可能性非常小。
所以,在本申请实施例中,对于接收到的SYN包,先判断SYN包是来自客户端发送还来自服务器,进而确定是记录客户端的初始序列号ISN(C)还是服务器的初始序列号ISN(S)。
结合图1B的描述,本申请实施例如果要对客户端的数据包重组,则可以在接收到客户端发送的SYN数据包时,获取SYN包中的ISN(C),然后计算第一纠偏差值ISN(C)+1并记录。或者在接收到客户端发送的ACK数据包时,获取该ACK包中的确认序列号ISN(C)+1,并记录其为第一纠偏差值。或者在建立连接后,接收到的第一个客户端的有效数据包时,获取其TCP序列号,因为其是从第0字节开始发送数据,其应该也为ISN(C)+1,可以记录为针对客户端的第一纠偏差值。
本申请实施例如果要对服务器响应的数据包重组,则可以在获取到服务器响应的SYN数据包时,获取服务器的SYN包中的ISN(S),然后计算第二纠偏差值ISN(S)+1并记录。或者在接收到客户端发送的ACK数据包时,获取该ACK包中的确认序列号ISN(S)+1,并记录其为第二纠偏差值。或者在建立连接后,接收到的服务器的第一个有效数据包时,获取其TCP序列号,因为其是从第0字节开始发送数据,其应该也为ISN(S)+1,可以记录为针对客户端的第二纠偏差值。
步骤416,在获取到所述TCP连接的数据包时,判断所接收到的数据包是否为含有TCP载荷的有效数据包;如果所接收到的数据包是含有TCP载荷的有效数据包,则进入步骤418。
如果所接收到的数据包不是含有TCP载荷的有效数据包,则不进行处 理。
步骤418,判断所述有效数据包是否为第一个有效数据包;如果所述有效数据包是第一个有效数据包,则进入步骤420。
步骤420,判断所述有效数据包是否属于客户端;如果所述有效数据包属于客户端,则进入步骤422;如果所述有效数据包属于服务器,则进入步骤424。
步骤422,创建属于客户端的第一数组。进入步骤426。
步骤424,创建属于服务器的第二数组。进入步骤426。
在本申请实施例中,在一次TCP建立连接到结束连接的过程中,接收到的数据包,可以分为以下四种情况:1)建立连接的SYN包;2)第一个含有TCP载荷的数据包;3)其他含有TCP载荷的数据包;4)终止连接的FIN/RST包。
其中,若接收到的有效数据包是第一个含有TCP载荷的数据包,即第一个有效数据包,则此时需要创建第一数组,存储该有效数据包中的有效数据,从而在本次TCP连接,对于以后接收到的其他含有TCP载荷的数据包,将其中的有效数据都存储于该以创建的第一数组中。而对于建立连接的SYN包,其作用只是为了建立TCP连接,其中的数据并不是必须要存储于第一数组中,所以若接收的数据包是建立连接的TCP包,此时并不需要创建第一数组,同样对于终止连接的FIN/RST包,也不需要创建第一数组。
步骤426,计算所述有效数据包中有效数据的长度作为数据长度。根据有效数据包所属的客户端进入步骤428或者步骤430。
步骤428,当所述有效数据包属于客户端,则根据有效数据包的TCP序列号和预先记录的第一纠偏值之差,确定所述有效数据包的偏移量;所述第一纠偏值为属于客户端的SYN包的初始序列号+1。进入步骤432。
本申请实施例如果要对客户端的数据包重组,则可以在接收到客户端发送的SYN数据包时,获取SYN包中的ISN(C),然后计算第一纠偏差值ISN(C)+1并记录。或者在接收到客户端发送的ACK数据包时,获取该ACK包中的确认序列号ISN(C)+1,并记录其为第一纠偏差值。或者在建立连接后,接收到的第一个有效数据包时,获取其TCP序列号,因为其是从第0字节开始发送数据,其应该也为ISN(C)+1,可以记录为针对客户端的第一纠偏差值。
本申请实施例如果要对服务器的数据包重组,则可以在获取到服务器响应的SYN数据包时,获取SYN包中的ISN(S),然后计算第二纠偏差值ISN(S)+1并记录。或者在接收到客户端发送的ACK数据包时,获取该ACK包中的确认序列号ISN(S),并记录其为第二纠偏差值。或者在建立连接后,接收到的第一个服务器响应的有效数据包时,获取其TCP序列号,因为其是从第0字节开始发送数据,其应该也为ISN(S)+1,可以记录为针对服务器的第二纠偏差值。
步骤430,当所述有效数据包属于服务器,则根据有效数据包的TCP序列号和预先记录的第二纠偏值之差,确定所述有效数据包的偏移量;所述第二纠偏值为属于服务器的SYN包的初始序列号+1。进入步骤438。
步骤432,当所述有效数据包属于客户端,则判断所述有效数据包的偏移量和数据长度之和,是否大于第一数组的数组长度;如果所述有效数据包的偏移量和数据长度之和,大于第一数组的数组长度,则进入步骤434,然后进入步骤436;如果所述有效数据包的偏移量和数据长度之和,不大于第一数组的数组长度,则进入步骤446。
步骤434,创建一个新的第一数组,所述新的第一数组的数组长度超过原来的第一数组第一阈值。
步骤436,将原来的第一数组中存储的数据复制到新的第一数组中, 并将未存储过的有效数据包的有效数据存储至新的第一数组中。
步骤438,当所述有效数据包属于服务器,则判断所述有效数据包的偏移量和数据长度之和,是否大于第二数组的数组长度;如果所述有效数据包的偏移量和数据长度之和,大于第二数组的数组长度,则进入步骤440,然后进入步骤442;如果所述有效数据包的偏移量和数据长度之和,不大于第二数组的数组长度,则进入步骤448。
步骤440,创建一个新的第二数组,所述新的第二数组的数组长度超过原来的第一数组第二阈值。
步骤442,将原来的第二数组中存储的数据复制到新的第二数组中,并将未存储过的有效数据包的有效数据存储至新的第二数组中。
步骤446,当所述有效数据包属于客户端时,根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于客户端的第一数组存储。
步骤448,当所述有效数据包属于服务器时,根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于服务器的第二数组存储。
在本申请另一个优选地实施例中,还包括:
步骤450,在当前TCP连接结束后,输出第一数组和第二数组中的数据。
本申请实施例是针对一TCP连接,分别对由客户端和服务器发送的有效数据包中的有效数据进行重组。具体执行过程为,首先针对一TCP连接,创建属于客户端的第一数组,和属于服务器的第二数组,然后针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度,进一步根据所述有效数据包的偏移量和数据长度,将所述客户端的有效数据包中的有效数据存储至属于客户端的第二数组,将所述服务器 的有效数据包中的有效数据存储至属于服务器的第二数组。从而实现了同时分别对于客户端以及服务器侧的数据流的重组,而且简化了对于客户端侧以及服务器侧的流重组过程中的判断逻辑以及运算过程,从而有效降低了现有TCP流重组方法的复杂度,提高了流重组的效率,更容易满足系统性能方面的需求。
而且,在本申请实施例中,在建立TCP连接时会判断接收到的SYN包是来自客户端发送还来自服务器,进而决定记录客户端的初始序列号ISN还是服务器的初始序列号ISN;在接收TCP连接的数据包时,还会判断接收到的数据包种类,并且针对接收到的数据包的种类不同,执行不同的操作;同时还会分别在接收到的有效数据包的偏置量和数据长度之和超出第一数组和第二数组长度时,分别利用新的第一数组和第二数组替换原有的第一数组和第二数组。在保证流重组的效率的同时,提高了流重组的准确性,从而使其更容易满足系统性能方面的需求。
并且,是在TCP连接建立成功之后,再创建属于客户端的第一数组,和/或属于服务器的第二数组,相对于在TCP连接还未成功建立之前,在创建属于客户端的第一数组,和属于服务器的第二数组,延迟了创建用以进行数据流重组的第一数组和第二数组。可以有效避免SYN flood(拒绝服务)攻击导致的资源被耗用过度的问题。
需要说明的是,对于方法实施例,为了简单描述,故将其都表述为一系列的动作组合,但是本领域技术人员应该知悉,本申请实施例并不受所描述的动作顺序的限制,因为依据本申请实施例,某些步骤可以采用其他顺序或者同时进行。其次,本领域技术人员也应该知悉,说明书中所描述的实施例均属于优选实施例,所涉及的动作并不一定是本申请实施例所必须的。
实施例五
参照图5,示出了本申请的一种TCP流重组装置实施例的结构框图,具体可以包括如下模块:
第一创建模块510,适于针对一TCP连接,创建属于客户端的第一数组,和/或属于服务器的第二数组。
在本申请另一个优选地实施例中,所述第一创建模块510,包括:
第一创建子模块,适于在所述TCP连接建立成功之后,创建属于客户端的第一数组,和/或属于服务器的第二数组。
在本申请另一个优选地实施例中,所述第一创建模块510,包括:
第一内存创建子模块,适于针对一TCP连接,在内存中创建属于客户端的第一数组,和/或属于服务器的第二数组。
计算模块520,适于针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度。
第一存储模块530,适于根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于客户端的第一数组存储。
在本申请另一个优选的实施例中,第一存储模块530,包括:
第一重叠判断子模块,适于根据所述有效数据包的偏移量和数据长度,判断所述有效数据包的有效数据与第一数组的有效数据的重叠情况。
第一丢弃子模块,适于如果第一数组中存在与所述有效数据包全部重叠的有效数据,则将所述有效数据包中重叠部分的有效数据丢弃。
第一丢弃存储子模块,适于如果第一数组中存在与所述有效数据部分重叠的有效数据,将所述有效数据包中重叠部分的有效数据丢弃,并计算不重叠部分的有效数据的第一偏移量和第一数据长度,再将不重叠部分的有效数据在第一数组的第一偏移量位置开始存储,直至存储长度为所述第一数据长度。
第一存储子模块,适于如果第一数组中不存在与所述有效数据全部 重叠的有效数据,则将所述有效数据包的有效数据在第一数组的偏移量位置开始存储,直至存储长度为所述数据长度。
第二存储模块540,适于当所述有效数据包属于服务器时,根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于服务器的第二数组存储。
在本申请另一个优选的实施例中,第二存储模块540,包括:
第二重叠判断子模块,适于根据所述有效数据包的偏移量和数据长度,判断所述有效数据包的有效数据与第二数组的有效数据的重叠情况。
第二丢弃子模块,适于如果第二数组中存在与所述有效数据包全部重叠的有效数据,则将所述有效数据包中重叠部分的有效数据丢弃。
第二丢弃存储子模块,适于如果第二数组中存在与所述有效数据部分重叠的有效数据,将所述有效数据包中重叠部分的有效数据丢弃,并计算不重叠部分的有效数据的第二偏移量和第二数据长度,再将不重叠部分的有效数据在第二数组的第二偏移量位置开始存储,直至存储长度为所述第二数据长度。
第二丢弃存储子模块,适于如果第二数组中不存在与所述有效数据全部重叠的有效数据,则将所述有效数据包的有效数据在第二数组的偏移量位置开始存储,直至存储长度为所述数据长度。
在本申请另一个优选地实施例中,在第一存储模块530、第二存储模块540之后,还包括:
输出模块550,适于在当前TCP连接结束后,输出第一数组和/或第二数组中的数据。
在本申请实施例中,首先针对一TCP连接,创建属于客户端的第一数组,和/或属于服务器的第二数组,然后针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度,进一步根 据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于客户端的第一数组存储,最后在当前TCP连接结束后,输出第一数组和/或第二数组中的数据。简化了流重组过程中的判断逻辑以及运算过程,从而有效降低了现有TCP流重组方法的复杂度,提高了流重组的效率,更容易满足系统性能方面的需求。
在本申请实施例中,首先针对一TCP连接,创建属于客户端的第一数组,和/或属于服务器的第二数组,然后针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度,进一步根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于客户端的第一数组存储。简化了流重组过程中的判断逻辑以及运算过程,从而有效降低了现有TCP流重组方法的复杂度,提高了流重组的效率,更容易满足系统性能方面的需求。
另外,在本申请又一个优选地实施例中,在TCP连接建立成功之后,再创建属于客户端的第一数组,和/或属于服务器的第二数组,从而可以有效地避免因为受到SYN flood(拒绝服务)攻击,而耗费大量的系统内存,影响系统的正常运行的问题。
实施例六
参照图6,示出了本申请的一种TCP流重组装置实施例的结构框图,具体可以包括如下模块:
SYN包判断模块610,适于当接收到SYN包时,判断所述SYN包是来自客户端还来自服务器;如果SYN包是来自客户端,则进入第一记录模块620;如果SYN包是来自服务器,则可以不处理。
第一记录模块620,适于记录客户端的初始序列号ISN(C);
第一创建模块630,适于针对一TCP连接,创建属于客户端的第一数组。具体包括:
TCP判断子模块631,适于在接收所述TCP连接的属于客户端的数据包时,判断所接收到的数据包是否为含有TCP载荷的有效数据包;如果所接收到的数据包是含有TCP载荷的有效数据包,则进入第一判断子模块632;
第一判断子模块632,适于判断所述有效数据包是否为第一个有效数据包;如果所述有效数据包是第一个有效数据包,则进入第一数组创建子模块633;
第一数组创建子模块633,适于创建属于客户端的第一数组。
计算模块640,适于针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度。具体包括:
数据长度计算子模块641,适于计算所述有效数据包中有效数据的长度作为数据长度;
第一偏移量计算子模块642,适于根据有效数据包的TCP序列号和预先记录的第一纠偏值之差,确定所述有效数据包的偏移量;所述第一纠偏值为属于客户端的SYN包的初始序列号+1。
第一判断模块650,适于判断所述有效数据包的偏移量和数据长度之和,是否大于第一数组的数组长度;如果所述有效数据包的偏移量和数据长度之和,大于第一数组的数组长度,则进入第一新数组创建模块660;如果所述有效数据包的偏移量和数据长度之和,不大于第一数组的数组长度,则直接进入第一存储模块680。
第一新数组创建模块660,适于创建一个新的第一数组,所述新的第一数组的数组长度超过原来的第一数组第一阈值。
第一复制存储模块670,适于将原来的第一数组中存储的数据复制到新的第一数组中,并将未存储过的有效数据包的有效数据存储至新的第一数组中。
第一存储模块680,适于当所述有效数据包属于客户端时,根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于客户端的第一数组存储。
在本申请另一个优选地实施例中,还包括:
输出模块690,适于在当前TCP连接结束后,输出第一数组中的数据。
在本申请一优选的实施例中,在本申请实施例中,输出模块690,包括:
第一输出子模块,适于当在所述TCP连接下接收到任一个非指示关闭连接的数据包后,判断出所述TCP连接的空闲时间超过第一时间周期,则结束所述TCP连接,输出第一数组中的数据。
和/或,第二输出子模块,适于当在所述TCP连接下接收到指示关闭连接的数据包后,判断出所述TCP连接的空闲时间超过第二时间周期,则结束所述TCP连接,输出第一数组中的数据。
在本申请一优选的实施例中,在本申请实施例中,还包括:
第一释放模块,适于在将原来的第一数组中存储的数据复制到新的第一数组中之后,将原来的第一数组释放。
将所述有效数据包中的有效数据向属于客户端的第一数组存储本申请实施例是针对一TCP连接,对由客户端发送的有效数据包中的有效数据进行重组。具体执行过程为,首先针对一TCP连接,创建属于客户端的第一数组,然后针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度,进一步根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于客户端的第一数组存储。从而简化了对于客户端的流重组过程中的判断逻辑以及运算过程,从而有效降低了现有TCP流重组方法的复杂度,提高了流重组的效率,更容易满足系统性能方面的需求。
而且,在本申请实施例中,还会判断接收到的数据包种类,并且针对接收到的数据包的种类不同,执行不同的操作;同时还会在接收到的有效数据包的偏置量和数据长度之和超出第一数组长度时,利用新的第一数组替换原有的第一数组。在保证流重组的效率的同时,提高了流重组的准确性,从而使其更容易满足系统性能方面的需求。
实施例七
参照图7,示出了本申请的一种TCP流重组装置实施例的结构框图,具体可以包括如下模块:
SYN包判断模块710,适于当接收到SYN包时,判断所述SYN包是来自客户端还来自服务器;如果SYN包是来自服务器,则进入第二记录模块720;如果SYN包是来自客户端,则可以不处理;
第二记录模块720,适于则记录服务器的初始序列号ISN(S)。
第一创建模块730,适于针对一TCP连接,创建属于客户端的第一数组,和/或属于服务器的第二数组。具体包括:
TCP判断子模块731,适于在接收所述TCP连接的数据包时,判断所接收到的数据包是否为含有TCP载荷的有效数据包;如果所接收到的数据包是含有TCP载荷的有效数据包,则进入第一判断子模块732。
第一判断子模块732,适于判断所述有效数据包是否为第一个有效数据包;如果所述有效数据包是第一个有效数据包,则进入第二数组创建子模块733。
第二数组创建子模块733,适于创建属于服务器的第二数组。
计算模块740,适于针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度。具体包括:
数据长度计算子模块741,适于计算所述有效数据包中有效数据的长度作为数据长度;
第二偏移量计算子模块742,适于根据有效数据包的TCP序列号和预先记录的第二纠偏值之差,确定所述有效数据包的偏移量;所述第二纠偏值为属于服务器的SYN包的初始序列号+1。
第二判断模块750,适于判断所述有效数据包的偏移量和数据长度之和,是否大于第二数组的数组长度;如果所述有效数据包的偏移量和数据长度之和,大于第二数组的数组长度,则进入第二新数组创建模块760;如果所述有效数据包的偏移量和数据长度之和,不大于第二数组的数组长度,则直接进入第二存储模块780。
第二新数组创建模块760,适于创建一个新的第二数组,所述新的第二数组的数组长度超过原来的第二数组第一阈值。
第二复制存储模块770,适于将原来的第二数组中存储的数据复制到新的第二数组中,并将未存储过的有效数据包的有效数据存储至新的第二数组中。
第二存储模块780,适于当所述有效数据包属于服务器时,根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于服务器的第二数组存储。
在本申请另一个优选地实施例中,还包括:
输出模块790,适于在当前TCP连接结束后,输出第二数组中的数据。
在本申请另一个优选的实施例中,还包括:
第二释放模块,适于在将原来的第二数组中存储的数据复制到新的第二数组中之后,将原来的第二数组释放。
其中,第二释放模块,可以在第二复制存储模块770之后,或者是在第二复制存储模块770之后的任一模块之后,对此本申请不加以限制。
本申请实施例是针对一TCP连接,对由服务器发送的有效数据包中的有效数据进行重组。具体执行过程为,首先针对一TCP连接,创建属于服 务器的第二数组,然后针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度,进一步根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于服务器的第二数组存储。从而简化了对于服务器侧的流重组过程中的判断逻辑以及运算过程,从而有效降低了现有TCP流重组方法的复杂度,提高了流重组的效率,更容易满足系统性能方面的需求。
而且,在本申请实施例中,同时还会在接收到的有效数据包的偏置量和数据长度之和超出第一数组长度时,利用新的第二数组替换原有的第二数组。在保证流重组的效率的同时,提高了流重组的准确性,从而使其更容易满足系统性能方面的需求。
实施例八
参照图8,示出了本申请的一种TCP流重组装置实施例的结构框图,具体可以包括如下模块:
SYN包判断模块800,适于当接收到SYN包时,判断所述SYN包是来自客户端还来自服务器;如果SYN包是来自客户端,则进入第一记录模块802;如果SYN包是来自服务器,则进入第二记录模块804;
第一记录模块,适于记录客户端的初始序列号ISN(C);
第二记录模块,适于记录服务器的初始序列号ISN(S)。
第一创建模块810,适于针对一TCP连接,创建属于客户端的第一数组,和属于服务器的第二数组。具体包括:
TCP判断子模块811,适于在接收所述TCP连接的数据包时,判断所接收到的数据包是否为含有TCP载荷的有效数据包;如果所接收到的数据包是含有TCP载荷的有效数据包,则进入第一判断子模块812。
第一判断子模块812,适于判断所述有效数据包是否为第一个有效数据包;如果所述有效数据包是第一个有效数据包,则进入客户端判断子 模块813。
客户端判断子模块813,适于判断所述有效数据包是否属于客户端;如果所述有效数据包属于客户端,则进入第一数组创建子模块814;如果所述有效数据包不属于客户端,则进入第二数组创建子模块815。
第一数组创建子模块814,适于创建属于客户端的第一数组。进入计算模块820。
第二数组创建子模块815,适于创建属于服务器的第二数组。进入计算模块820。
计算模块820,适于针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度。具体包括:
数据长度计算子模块821,适于计算所述有效数据包中有效数据的长度作为数据长度。
第一偏移量计算子模块822,适于当所述有效数据包属于客户端,则根据有效数据包的TCP序列号和预先记录的第一纠偏值之差,确定所述有效数据包的偏移量;所述第一纠偏值为属于客户端的SYN包的初始序列号+1。进入第一判断模块830。
第二偏移量计算子模块823,适于根据有效数据包的TCP序列号和预先记录的第二纠偏值之差,确定所述有效数据包的偏移量;所述第二纠偏值为属于服务器的SYN包的初始序列号+1。进入第二判断模块860。
第一判断模块830,适于当所述有效数据包属于客户端,则判断所述有效数据包的偏移量和数据长度之和,是否大于第一数组的数组长度;如果所述有效数据包的偏移量和数据长度之和,大于第一数组的数组长度,则进入第一新数组创建模块840,然后进入第一复制存储模块850;如果所述有效数据包的偏移量和数据长度之和,不大于第一数组的数组长度,则直接进入第一存储模块890。
第一新数组创建模块840,适于创建一个新的第一数组,所述新的第一数组的数组长度超过原来的第一数组第一阈值。
第一复制存储模块850,适于将原来的第一数组中存储的数据复制到新的第一数组中,并将未存储过的有效数据包的有效数据存储至新的第一数组中。
第二判断模块860,适于判断所述有效数据包的偏移量和数据长度之和,是否大于第二数组的数组长度;如果所述有效数据包的偏移量和数据长度之和,大于第二数组的数组长度,则进入第二新数组创建模块870;如果所述有效数据包的偏移量和数据长度之和,不大于第二数组的数组长度,则直接进入第二存储模块8110。
第二新数组创建模块870,适于创建一个新的第二数组,所述新的第二数组的数组长度超过原来的第二数组第一阈值。
第二复制存储模块880,适于将原来的第二数组中存储的数据复制到新的第二数组中,并将未存储过的有效数据包的有效数据存储至新的第二数组中。
第一存储模块890,适于当所述有效数据包属于客户端时,根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于客户端的第一数组存储。
第二存储模块8110,适于当所述有效数据包属于服务器时,根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于服务器的第二数组存储。
在本申请另一个优选地实施例中,还包括:
输出模块8120,适于在当前TCP连接结束后,输出第一数组和第二数组中的数据。
在本申请另一个优选的实施例中,还包括:
第一释放模块,适于在将原来的第一数组中存储的数据复制到新的第一数组中之后,将原来的第一数组释放。
第二释放模块,适于在将原来的第二数组中存储的数据复制到新的第二数组中之后,将原来的第二数组释放。
其中,第一释放模块可以在第一复制存储模块之后,或者是在第一复制存储模块之后的任一模块之后;第二释放模块可以在第二复制存储模块之后,或者是在第二复制存储模块之后的任一模块之后,对此本申请不加以限制。
本申请实施例是针对一TCP连接,分别对由客户端和服务器发送的有效数据包中的有效数据进行重组。具体执行过程为,首先针对一TCP连接,创建属于客户端的第一数组,和属于服务器的第二数组,然后针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度,进一步根据所述有效数据包的偏移量和数据长度,将所述客户端的有效数据包中的有效数据存储至属于客户端的第二数组,将所述服务器的有效数据包中的有效数据存储至属于服务器的第二数组。从而实现了同时分别对于客户端以及服务器侧的数据流的重组,而且简化了对于客户端侧以及服务器侧的流重组过程中的判断逻辑以及运算过程,从而有效降低了现有TCP流重组方法的复杂度,提高了流重组的效率,更容易满足系统性能方面的需求。
而且,在本申请实施例中,在建立TCP连接时会判断接收到的SYN包是来自客户端发送还来自服务器,进而决定记录客户端的初始序列号ISN还是服务器的初始序列号ISN;在接收TCP连接的数据包时,还会判断接收到的数据包种类,并且针对接收到的数据包的种类不同,执行不同的操作;同时还会分别在接收到的有效数据包的偏置量和数据长度之和超出第一数组和第二数组长度时,分别利用新的第一数组和第二数组替换原 有的第一数组和第二数组。在保证流重组的效率的同时,提高了流重组的准确性,从而使其更容易满足系统性能方面的需求。
并且,是在TCP连接建立成功之后,再创建属于客户端的第一数组,和/或属于服务器的第二数组,相对于在TCP连接还未成功建立之前,在创建属于客户端的第一数组,和属于服务器的第二数组,延迟了创建用以进行数据流重组的第一数组和第二数组。可以有效避免SYN flood(拒绝服务)攻击导致的资源被耗用过度的问题。
对于装置实施例而言,由于其与方法实施例基本相似,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。
本说明书中的各个实施例均采用递进的方式描述,每个实施例重点说明的都是与其他实施例的不同之处,各个实施例之间相同相似的部分互相参见即可。
本领域内的技术人员应明白,本申请实施例的实施例可提供为方法、装置、或计算机程序产品。因此,本申请实施例可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本申请实施例可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。
在一个典型的配置中,所述计算机设备包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等 形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括非持续性的电脑可读媒体(transitory media),如调制的数据信号和载波。
本申请实施例是参照根据本申请实施例的方法、终端设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理终端设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理终端设备的 处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理终端设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。
这些计算机程序指令也可装载到计算机或其他可编程数据处理终端设备上,使得在计算机或其他可编程终端设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程终端设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。
尽管已描述了本申请实施例的优选实施例,但本领域内的技术人员一旦得知了基本创造性概念,则可对这些实施例做出另外的变更和修改。所以,所附权利要求意欲解释为包括优选实施例以及落入本申请实施例范围的所有变更和修改。
最后,还需要说明的是,在本文中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者终端设备不仅包括那些 要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者终端设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者终端设备中还存在另外的相同要素。
以上对本申请所提供的一种TCP流重组方法和一种TCP流重组装置,进行了详细介绍,本文中应用了具体个例对本申请的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本申请的方法及其核心思想;同时,对于本领域的一般技术人员,依据本申请的思想,在具体实施方式及应用范围上均会有改变之处,综上所述,本说明书内容不应理解为对本申请的限制。

Claims (28)

  1. 一种TCP流重组方法,其特征在于,包括:
    针对一TCP连接,创建属于客户端的第一数组,和/或属于服务器的第二数组;
    针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度;
    当所述有效数据包属于客户端时,根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于客户端的第一数组存储;
    当所述有效数据包属于服务器时,根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于服务器的第二数组存储。
  2. 根据权利要求1所述的方法,其特征在于,所述针对一TCP连接,创建属于客户端的第一数组,和/或属于服务器的第二数组的步骤,包括:
    在所述TCP连接建立成功之后,创建属于客户端的第一数组,和/或属于服务器的第二数组。
  3. 根据权利要求2所述的方法,其特征在于,所述针对一TCP连接,创建属于客户端的第一数组,和/或属于服务器的第二数组的步骤,包括:
    在接收所述TCP连接的数据包时,判断所接收到的数据包是否为含有TCP载荷的有效数据包;
    如果所接收到的数据包是含有TCP载荷的有效数据包,判断所述有效数据包是否为第一个有效数据包;
    如果所述有效数据包是第一个有效数据包,则判断所述有效数据包是否属于客户端;
    如果所述有效数据包属于客户端,创建属于客户端的第一数组;
    如果所述有效数据包不属于客户端,创建属于服务器的第二数组。
  4. 根据权利要求1所述的方法,其特征在于,所述针对所述TCP连 接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度的步骤,包括:
    计算所述有效数据包中有效数据的长度作为数据长度;
    当所述有效数据包属于客户端,则根据有效数据包的TCP序列号和预先记录的第一纠偏值之差,确定所述有效数据包的偏移量;所述第一纠偏值为属于客户端的SYN包的初始序列号+1;
    当所述有效数据包属于服务器,则根据有效数据包的TCP序列号和预先记录的第二纠偏值之差,确定所述有效数据包的偏移量;所述第二纠偏值为属于服务器的SYN包的初始序列号+1。
  5. 根据权利要求1-4其中之一所述的方法,其特征在于,在针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度之后,还包括:
    当所述有效数据包属于客户端,则判断所述有效数据包的偏移量和数据长度之和,是否大于第一数组的数组长度;
    如果所述有效数据包的偏移量和数据长度之和,大于第一数组的数组长度,则创建一个新的第一数组,所述新的第一数组的数组长度超过原来的第一数组第一阈值;
    将原来的第一数组中存储的数据复制到新的第一数组中,并将未存储过的有效数据包的有效数据存储至新的第一数组中。
  6. 根据权利要求1-4其中之一所述的方法,其特征在于,在针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度之后,还包括:
    当所述有效数据包属于服务器,则判断所述有效数据包的偏移量和数据长度之和,是否大于第二数组的数组长度;
    如果所述有效数据包的偏移量和数据长度之和,大于第二数组的数组 长度,则创建一个新的第二数组,所述新的第二数组的数组长度超过原来的第一数组第二阈值;
    将原来的第二数组中存储的数据复制到新的第二数组中,并将未存储过的有效数据包的有效数据存储至新的第二数组中。
  7. 根据权利要求5所述的方法,其特征在于,还包括:
    在将原来的第一数组中存储的数据复制到新的第一数组中之后,将原来的第一数组释放。
  8. 根据权利要求6所述的方法,其特征在于,还包括:
    在将原来的第二数组中存储的数据复制到新的第二数组中之后,将原来的第二数组释放。
  9. 根据权利要求4所述的方法,其特征在于,针对一TCP连接,创建属于客户端的第一数组,和/或属于服务器的第二数组的步骤之前,还包括:
    当接收到SYN包时,判断所述SYN包是来自客户端还来自服务器;
    如果SYN包是来自客户端,则记录客户端的初始序列号ISN(C);
    如果SYN包是来自服务器,则记录服务器的初始序列号ISN(S)。
  10. 根据权利要求1所述的方法,其特征在于,所述针对一TCP连接,创建属于客户端的第一数组,和/或属于服务器的第二数组的步骤,包括:
    针对一TCP连接,在内存中创建属于客户端的第一数组,和/或属于服务器的第二数组。
  11. 根据权利要求1所述的方法,其特征在于,所述在当前TCP连接结束后,输出第一数组和/或第二数组中的数据的步骤,包括:
    当在所述TCP连接下接收到任一个非指示关闭连接的数据包后,判断出所述TCP连接的空闲时间超过第一时间周期,则结束所述TCP连接,输出第一数组中的数据;
    和/或,当在所述TCP连接下接收到指示关闭连接的数据包后,判断出所述TCP连接的空闲时间超过第二时间周期,则结束所述TCP连接,输出第一数组中的数据。
  12. 根据权利要求1所述的方法,其特征在于,所述当所述有效数据包属于客户端时,根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于客户端的第一数组存储的步骤,包括:
    根据所述有效数据包的偏移量和数据长度,判断所述有效数据包的有效数据与第一数组的有效数据的重叠情况;
    如果第一数组中存在与所述有效数据包全部重叠的有效数据,则将所述有效数据包中重叠部分的有效数据丢弃;
    如果第一数组中存在与所述有效数据部分重叠的有效数据,将所述有效数据包中重叠部分的有效数据丢弃,并计算不重叠部分的有效数据的第一偏移量和第一数据长度,再将不重叠部分的有效数据在第一数组的第一偏移量位置开始存储,直至存储长度为所述第一数据长度;
    如果第一数组中不存在与所述有效数据重叠的有效数据,则将所述有效数据包的有效数据在第一数组的偏移量位置开始存储,直至存储长度为所述数据长度。
  13. 根据权利要求1所述的方法,其特征在于,所述当所述有效数据包属于服务器时,根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于服务器的第二数组存储的步骤,包括:
    根据所述有效数据包的偏移量和数据长度,判断所述有效数据包的有效数据与第二数组的有效数据的重叠情况;
    如果第二数组中存在与所述有效数据包全部重叠的有效数据,则将所述有效数据包中重叠部分的有效数据丢弃,
    如果第二数组中存在与所述有效数据部分重叠的有效数据,将所述有 效数据包中重叠部分的有效数据丢弃,并计算不重叠部分的有效数据的第二偏移量和第二数据长度,再将不重叠部分的有效数据在第二数组的第二偏移量位置开始存储,直至存储长度为所述第二数据长度;
    如果第二数组中不存在与所述有效数据重叠的有效数据,则将所述有效数据包的有效数据在第二数组的偏移量位置开始存储,直至存储长度为所述数据长度。
  14. 根据权利要求1所述的方法,其特征在于,还包括:
    在当前TCP连接结束后,输出第一数组和/或第二数组中的数据。
  15. 一种TCP流重组装置,其特征在于,包括:
    第一创建模块,适于针对一TCP连接,创建属于客户端的第一数组,和/或属于服务器的第二数组;
    计算模块,适于针对所述TCP连接下的含有TCP载荷的有效数据包,计算所述有效数据包的偏移量和数据长度;
    第一存储模块,适于当所述有效数据包属于客户端时,根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于客户端的第一数组存储;
    第二存储模块,适于当所述有效数据包属于服务器时,根据所述有效数据包的偏移量和数据长度,将所述有效数据包中的有效数据向属于服务器的第二数组存储。
  16. 根据权利要求15所述的装置,其特征在于,所述第一创建模块,包括:
    第一创建子模块,适于在所述TCP连接建立成功之后,创建属于客户端的第一数组,和/或属于服务器的第二数组。
  17. 根据权利要求16所述的装置,其特征在于,所述第一创建模块,包括:
    TCP判断子模块,适于在接收所述TCP连接的数据包时,判断所接收到的数据包是否为含有TCP载荷的有效数据包;如果所接收到的数据包是含有TCP载荷的有效数据包,则进入第一判断子模块;
    第一判断子模块,适于判断所述有效数据包是否为第一个有效数据包;如果所述有效数据包是第一个有效数据包,则进入客户端判断子模块;
    客户端判断子模块,适于判断所述有效数据包是否属于客户端;如果所述有效数据包属于客户端,则进入第一数组创建子模块;如果所述有效数据包不属于客户端,则进入第二数组创建子模块;
    第一数组创建子模块,适于创建属于客户端的第一数组;
    第二数组创建子模块,创建属于服务器的第二数组。
  18. 根据权利要求15所述的装置,其特征在于,所述计算模块,包括:
    数据长度计算子模块,适于计算所述有效数据包中有效数据的长度作为数据长度;
    第一偏移量计算子模块,适于当所述有效数据包属于客户端,则根据有效数据包的TCP序列号和预先记录的第一纠偏值之差,确定所述有效数据包的偏移量;所述第一纠偏值为属于客户端的SYN包的初始序列号+1;
    第二偏移量计算子模块,适于当所述有效数据包属于服务器,则根据有效数据包的TCP序列号和预先记录的第二纠偏值之差,确定所述有效数据包的偏移量;所述第二纠偏值为属于服务器的SYN包的初始序列号+1。
  19. 根据权利要求15-18其中之一所述的装置,其特征在于,在所述计算模块之后,还包括:
    第一判断模块,适于当所述有效数据包属于客户端,则判断所述有效数据包的偏移量和数据长度之和,是否大于第一数组的数组长度;如果所述有效数据包的偏移量和数据长度之和,大于第一数组的数组长度,则进 入第一新数组创建模块;
    第一新数组创建模块,适于创建一个新的第一数组,所述新的第一数组的数组长度超过原来的第一数组第一阈值;
    第一复制存储模块,适于将原来的第一数组中存储的数据复制到新的第一数组中,并将未存储过的有效数据包的有效数据存储至新的第一数组中。
  20. 根据权利要求15-18其中之一所述的装置,其特征在于,在所述计算模块之后,还包括:
    第二判断模块,适于当所述有效数据包属于服务器,则判断所述有效数据包的偏移量和数据长度之和,是否大于第二数组的数组长度;如果所述有效数据包的偏移量和数据长度之和,大于第二数组的数组长度,则进入第二新数组创建模块;
    第二新数组创建模块,适于创建一个新的第二数组,所述新的第二数组的数组长度超过原来的第二数组第一阈值;
    第二复制存储模块,适于将原来的第二数组中存储的数据复制到新的第二数组中,并将未存储过的有效数据包的有效数据存储至新的第二数组中。
  21. 根据权利要求19所述的装置,其特征在于,还包括:
    第一释放模块,适于在将原来的第一数组中存储的数据复制到新的第一数组中之后,将原来的第一数组释放。
  22. 根据权利要求20所述的装置,其特征在于,还包括:
    第二释放模块,适于在将原来的第二数组中存储的数据复制到新的第二数组中之后,将原来的第二数组释放。
  23. 根据权利要求18所述的装置,其特征在于,在所述第一创建模块之前,还包括:
    SYN包判断模块,适于当接收到SYN包时,判断所述SYN包是来自客户端还来自服务器;如果SYN包是来自客户端,则进入第一记录模块;如果SYN包是来自服务器,则进入第二记录模块;
    第一记录模块,适于记录客户端的初始序列号ISN(C);
    第二记录模块,适于记录服务器的初始序列号ISN(S)。
  24. 根据权利要求15所述的装置,其特征在于,所述第一创建模块,包括:
    第一内存创建子模块,适于针对一TCP连接,在内存中创建属于客户端的第一数组,和/或属于服务器的第二数组。
  25. 根据权利要求23所述的装置,其特征在于,所述输出模块,包括:
    第一输出子模块,适于当在所述TCP连接下接收到任一个非指示关闭连接的数据包后,判断出所述TCP连接的空闲时间超过第一时间周期,则结束所述TCP连接,输出第一数组中的数据;
    和/或,第二输出子模块,适于当在所述TCP连接下接收到指示关闭连接的数据包后,判断出所述TCP连接的空闲时间超过第二时间周期,则结束所述TCP连接,输出第一数组中的数据。
  26. 根据权利要求15所述的装置,其特征在于,所述第一存储模块,包括:
    第一重叠判断子模块,适于根据所述有效数据包的偏移量和数据长度,判断所述有效数据包的有效数据与第一数组的有效数据的重叠情况;
    第一丢弃子模块,适于如果第一数组中存在与所述有效数据包全部重叠的有效数据,则将所述有效数据包中重叠部分的有效数据丢弃;
    第一丢弃存储子模块,适于如果第一数组中存在与所述有效数据部分重叠的有效数据,将所述有效数据包中重叠部分的有效数据丢弃,并计算 不重叠部分的有效数据的第一偏移量和第一数据长度,再将不重叠部分的有效数据在第一数组的第一偏移量位置开始存储,直至存储长度为所述第一数据长度;
    第一存储子模块,适于如果第一数组中不存在与所述有效数据全部重叠的有效数据,则将所述有效数据包的有效数据在第一数组的偏移量位置开始存储,直至存储长度为所述数据长度。
  27. 根据权利要求14所述的装置,其特征在于,所述第二存储模块,包括:
    第二重叠判断子模块,适于根据所述有效数据包的偏移量和数据长度,判断所述有效数据包的有效数据与第二数组的有效数据的重叠情况;
    第二丢弃子模块,适于如果第二数组中存在与所述有效数据包全部重叠的有效数据,则将所述有效数据包中重叠部分的有效数据丢弃,
    第二丢弃存储子模块,适于如果第二数组中存在与所述有效数据部分重叠的有效数据,将所述有效数据包中重叠部分的有效数据丢弃,并计算不重叠部分的有效数据的第二偏移量和第二数据长度,再将不重叠部分的有效数据在第二数组的第二偏移量位置开始存储,直至存储长度为所述第二数据长度;
    第二丢弃存储子模块,适于如果第二数组中不存在与所述有效数据全部重叠的有效数据,则将所述有效数据包的有效数据在第二数组的偏移量位置开始存储,直至存储长度为所述数据长度。
  28. 根据权利要求14所述的装置,其特征在于,还包括:
    输出模块,适于在当前TCP连接结束后,输出第一数组和/或第二数组中的数据。
PCT/CN2017/077714 2016-03-31 2017-03-22 一种tcp流重组方法和装置 Ceased WO2017167098A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201610201648.4A CN107294877B (zh) 2016-03-31 2016-03-31 一种tcp流重组方法和装置
CN201610201648.4 2016-03-31

Publications (1)

Publication Number Publication Date
WO2017167098A1 true WO2017167098A1 (zh) 2017-10-05

Family

ID=59963424

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2017/077714 Ceased WO2017167098A1 (zh) 2016-03-31 2017-03-22 一种tcp流重组方法和装置

Country Status (3)

Country Link
CN (1) CN107294877B (zh)
TW (1) TWI708494B (zh)
WO (1) WO2017167098A1 (zh)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112583936A (zh) * 2020-12-29 2021-03-30 上海阅维科技股份有限公司 重组传输会话流的方法
CN112738119A (zh) * 2020-12-30 2021-04-30 北京天融信网络安全技术有限公司 报文处理方法、装置、电子设备及可读存储介质
US20210336895A1 (en) * 2019-01-07 2021-10-28 Huawei Technologies Co., Ltd. Data transmission method and network device

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101488960A (zh) * 2009-03-04 2009-07-22 哈尔滨工程大学 基于并行处理的tcp协议及其数据还原装置及方法
CN103117948A (zh) * 2013-02-22 2013-05-22 桂林电子科技大学 基于fpga的分级并行高速网络tcp流重组方法
CN104253863A (zh) * 2014-09-15 2014-12-31 重庆邮电大学 一种基于Hadoop平台和分布式处理编程模型的TCP流重组方法
CN105635058A (zh) * 2014-10-30 2016-06-01 中国科学院声学研究所 一种无协议栈模式下针对tcp的中间人处理方法

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1747444A (zh) * 2004-09-10 2006-03-15 国际商业机器公司 数据处理系统网络中从主机单元分担数据流的方法及引擎

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101488960A (zh) * 2009-03-04 2009-07-22 哈尔滨工程大学 基于并行处理的tcp协议及其数据还原装置及方法
CN103117948A (zh) * 2013-02-22 2013-05-22 桂林电子科技大学 基于fpga的分级并行高速网络tcp流重组方法
CN104253863A (zh) * 2014-09-15 2014-12-31 重庆邮电大学 一种基于Hadoop平台和分布式处理编程模型的TCP流重组方法
CN105635058A (zh) * 2014-10-30 2016-06-01 中国科学院声学研究所 一种无协议栈模式下针对tcp的中间人处理方法

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
HE, XINGGAO ET AL.: "ruqi nfóngyùxìt? ng zh?ng TCP shùjùliú chóngz? de shèjiy? shixi àn", COMPUTER CD SOFTWARE AND APPLICATIONS, 31 December 2012 (2012-12-31), pages 195 and 196 *
WU, QIONG.: "Research and Implementation on Inspection and Monitor Technology of Instant Messaging", CHINA MASTER'S THESES FULL-TEXT DATABASE, INFORMATION TECHNOLOGY, 15 March 2012 (2012-03-15), pages 32 - 36 *

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20210336895A1 (en) * 2019-01-07 2021-10-28 Huawei Technologies Co., Ltd. Data transmission method and network device
CN112583936A (zh) * 2020-12-29 2021-03-30 上海阅维科技股份有限公司 重组传输会话流的方法
CN112738119A (zh) * 2020-12-30 2021-04-30 北京天融信网络安全技术有限公司 报文处理方法、装置、电子设备及可读存储介质
CN112738119B (zh) * 2020-12-30 2022-12-09 北京天融信网络安全技术有限公司 报文处理方法、装置、电子设备及可读存储介质

Also Published As

Publication number Publication date
TW201737678A (zh) 2017-10-16
CN107294877B (zh) 2020-05-08
CN107294877A (zh) 2017-10-24
TWI708494B (zh) 2020-10-21

Similar Documents

Publication Publication Date Title
Postel Transmission control protocol
Postel DoD standard transmission control protocol
JP6705003B2 (ja) データ伝送方法および関連するデバイス
EP2974202B1 (en) Identification of originating ip address and client port connection
Eddy Rfc 9293: Transmission control protocol (tcp)
WO2015096149A1 (zh) Tcp链路配置方法、装置及设备
US10530644B2 (en) Techniques for establishing a communication connection between two network entities via different network flows
CN101414949A (zh) 一种链式数据传输方法、节点及系统
TW201713093A (zh) 應用於伺服器負載均衡中的連接建立方法及裝置
CN100571266C (zh) 一种数据传输方法和系统
WO2014037760A1 (zh) 增加数据流传输的方法和系统
CN110838935A (zh) 高可用sdn控制器集群方法、系统、存储介质及设备
Gomez et al. Tcp usage guidance in the internet of things (iot)
TWI708494B (zh) 一種tcp流重組方法和裝置
US7339900B2 (en) Method and apparatus for preventing spanning tree loops during traffic overload conditions
WO2016197498A1 (zh) 一种防止网络攻击的方法及设备、存储介质
WO2024093011A1 (zh) 一种针对syn代理的服务链编排的方法、装置、介质
Chihani et al. A Multipath TCP model for ns-3 simulator
Kulkarni et al. Analysis of TCP performance in data center networks
CN112153001A (zh) 基于waf的网络通信方法、系统、电子装置和存储介质
Postel RFC0761: DoD standard Transmission Control Protocol
TWI477112B (zh) Chain data transmission method, node and system
CN106254264B (zh) 一种非对称式网络传输协议设计方法
WO2015048999A1 (en) Method and proxy node for source to destination packet transfer
US11683327B2 (en) Demand management of sender of network traffic flow

Legal Events

Date Code Title Description
NENP Non-entry into the national phase

Ref country code: DE

121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 17773128

Country of ref document: EP

Kind code of ref document: A1

122 Ep: pct application non-entry in european phase

Ref document number: 17773128

Country of ref document: EP

Kind code of ref document: A1