A method for rapid reassembly of IP fragmented messages
Through the fast positioning algorithm of pointer array and bitmap, the problem of delay and failure in reassembly of IP fragmented packets is solved, a fast and reliable reassembly process is achieved, and resource management and implementation complexity are simplified.
Patent Information
- Application Number
- CN202311716173.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-14
- Publication Date
- 2025-09-05
- Estimated Expiration
- 2043-12-14
AI Technical Summary
Existing IP fragment message reassembly methods have problems such as reassembly delay, reassembly failure, resource consumption and implementation complexity, which are particularly evident when the network transmission delay is large or the number of fragments is large.
A fast positioning algorithm using pointer arrays and bitmaps is used to quickly locate the fragment position through the pointer array and use the bitmap to mark the storage position, achieving fast reorganization and handling abnormal situations, including the handling of fragment head and tail overlap, length anomalies, and bitmap anomalies.
It enables reorganization to be completed without waiting for all shards to arrive, quickly discovers anomalies, reduces resource consumption, simplifies the implementation process, and improves reorganization efficiency and reliability.
Smart Images

Figure CN117955940B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of IP network communication, in particular to a method for fast reassembly of IP fragment messages. Background Art
[0002] IP network communication is a network communication method based on the IP protocol (Internet Protocol). The IP protocol is the network layer protocol in the TCP / IP system. The purpose of designing IP is to improve the scalability of the network: first, to solve Internet problems and realize the interconnection and interoperability of large-scale, heterogeneous networks; second, to separate the coupling relationship between top-level network applications and underlying network technologies to facilitate the independent development of the two. IP network communication covers multiple fields, including industry information (IP voice communication, UC unified communications, video conferencing, wireless communications, call centers, three-network convergence, etc.), IP communication technology (IP communication technology, Linux maintenance and management, network security, data storage, routing and switching, databases, etc.), IP communication products, IP communication manufacturers, IP communication talent recruitment and IP communication solutions, etc. In IP network communication, the IP protocol provides the host with a connectionless, unreliable, best-effort data packet transmission service. This service can adapt to the interconnection and interoperability of large-scale, heterogeneous networks, and can separate network applications from underlying network technologies to achieve independent development of the two.
[0003] The rapid reassembly of IP fragmented packets primarily serves network devices or systems, accelerating network data transmission and improving data integrity. This feature offers the following key advantages: Efficiency: By fragmenting data and transmitting it separately, network bandwidth can be more efficiently utilized, increasing transmission speed. Reliability: If a fragment is lost or damaged during transmission, data integrity can be maintained by retransmitting the fragment or the entire packet. Flexibility: Rapid reassembly of IP fragmented packets can adapt to diverse network environments and requirements, operating on different hardware and software platforms. Scalability: This feature can be expanded and optimized to adapt to changing network environments and application requirements as network technology evolves and demand grows. Its implementation typically relies on specific network protocols and algorithms, such as IP and TCP. These protocols and algorithms ensure the correct transmission and reassembly of data, while also providing the necessary control mechanisms to ensure data security and reliability. Overall, rapid reassembly of IP fragmented packets is a critical network feature that can effectively improve network performance and data transmission reliability.
[0004] Fast reassembly of IP fragmented packets is usually used in IP networks to reassemble fragmented data packets into complete IP datagrams, which mainly involves parsing and processing the identification, flags, fragment offset and length fields in the IP header.
[0005] RFC791 stipulates that when a packet larger than the MTU is transmitted in the network, it must be fragmented. Therefore, the IP fragments must be reassembled in the network element that needs to analyze the complete IP message. This is also one of the basic network functions of the network element. As modern networks have increasingly higher requirements for data forwarding performance, each functional module in the network element must pursue the ultimate performance, including the reassembly function of IP fragmented messages.
[0006] The existing method for fast reassembly of IP fragmented packets has the following problems: Reassembly delay: The algorithm needs to wait for all fragments to arrive at the destination host before reassembly, which may increase the time delay of reassembly, especially when the network transmission delay is large or the number of fragments is large, the delay problem will be more obvious; Reassembly failure: Since the algorithm relies on the fragment offset field of each fragment to locate the position of the data packet, if the fragment offset field of a fragment is erroneous or lost, the reassembly of the entire data packet will fail. In addition, if the reassembly buffer is filled, the arrival of new fragments will also cause reassembly failure; Resource consumption: The algorithm needs to allocate a certain amount of memory resources to store fragmented packets and reassembly buffers, which may result in a certain amount of resource consumption, especially when processing a large number of fragmented packets, the resource consumption may be more obvious; Implementation complexity: The implementation process of the algorithm is relatively complex and needs to handle various possible situations and abnormal situations, which may increase the difficulty of implementation and the complexity of the code, and also increase the probability of errors. Summary of the Invention
[0007] The present invention aims at the reassembly function of IP fragment message and some optimizable points of RFC815 reassembly algorithm, and invents a fast reassembly algorithm to improve the reassembly performance of network elements for IP fragment message.
[0008] In order to achieve the above effect, the present invention provides the following technical solution: a method for quickly reassembling IP fragment messages, comprising the following steps:
[0009] S1. Fast positioning of pointer array.
[0010] S2, rapid reassembly of fragments.
[0011] S3. Reorganization completed.
[0012] S4. Handling of abnormal situations.
[0013] S5. Virtual reorganization.
[0014] According to the steps in S1,
[0015] S101. Set the byte size represented by each element of the pointer array to meta_size.
[0016] S102. The number of elements in the pointer array can be set according to the maximum supported IP message length.
[0017] S103. After receiving an IP fragment message, obtain the offset of the fragment, and then calculate the storage position of the fragment header byte in the pointer array: offset*8 / meta_size, point the pointer at the corresponding position in the pointer array to the fragment, and set the corresponding bitmap position to 1.
[0018] S104. Then calculate the position of the tail byte of the slice in the pointer array: (offset*8+len) / meta_size, and point the pointer at the corresponding position in the pointer array to the slice.
[0019] S105. If it is the last fragment, there is no need to find the position of the tail byte; if it is not the first fragment, remove the IP header of the fragment.
[0020] According to the steps in S2,
[0021] S201. When quickly locating the fragment position, find the position of the fragment header byte.
[0022] S202: First determine whether the pointer at the location is NULL. If it is NULL and the corresponding bitmap bit is 0, operate according to the above-mentioned fast positioning algorithm.
[0023] S203. If it is not NULL and the corresponding bitmap bit is 0, it means that the position is the tail byte of the previous fragment, and the pointer points to the previous fragment. Connect this fragment to the end of the previous fragment and point the pointer to NULL.
[0024] S204: After finding the location of the tail byte of the fragment, first determine whether the pointer of the location is NULL.
[0025] S205: If it is NULL and the corresponding bitmap bit is 0, operate according to the above-mentioned fast positioning algorithm.
[0026] S206. If it is not NULL and the corresponding bitmap bit is 1, it means that the position is the header byte of the next fragment, and the pointer points to the next fragment. The next fragment is connected to the end of this fragment, and the pointer points to NULL. The corresponding bitmap position is 0. Similarly, for non-first fragments, the IP header of the fragment is removed.
[0027] Further, according to the operation steps in S3,
[0028] S301. After receiving each fragment, record the message length of the fragment.
[0029] S302: Determine whether it is the first fragment or the last fragment.
[0030] S303. If it is the last fragment, the total length of the original IP message can be obtained. When the first fragment and the last fragment are received and the total length of the fragments is the total length of the original IP message, the reassembly is considered complete. The first pointer in the pointer array points to the IP message after the reassembly, which can be used for subsequent services. The pointer points to NULL and the corresponding bitmap position is 0.
[0031] S304: If there are no abnormalities, after the reorganization is completed, all bits of the bitmap are 0, all pointers in the pointer array point to NULL, and the system returns to the initial state to prepare for the next reorganization.
[0032] Furthermore, according to the operation steps in S4, the abnormal conditions include abnormal overlap of the fragment header position, abnormal overlap of the fragment tail position, abnormal IP fragment message length and abnormal bitmap.
[0033] Further, according to the operation steps in S4, the criterion for judging the abnormal overlap of the position of the header of the slice is that when the header byte of the slice is positioned, if the corresponding position pointer is not NULL and the corresponding bitmap bit is 1, it overlaps with the header byte offset of another slice, or the corresponding position pointer is NULL and the corresponding bitmap bit is 1. It is mainly used to judge whether the slices are crossed at the first time. The implementation method is to set the corresponding bitmaps between the head and tail of the slice to 1 after receiving the slice, and set them to 0 when releasing the slice.
[0034] Further, according to the operation steps in S4, the criterion for determining the abnormal overlap of the tail position of the slice is that when the tail byte of the slice is positioned, if the corresponding position pointer is not NULL and the corresponding bitmap bit is 0, it overlaps with the tail byte offset of another slice, or the corresponding position pointer is NULL and the corresponding bitmap bit is 1.
[0035] Further, according to the operation steps in S4, the IP fragment message length abnormality judgment standard is that the sum of the IP fragment lengths is greater than the total length of the original IP message, or the sum of the IP fragment lengths is less than the total length of the original IP message and the timeout does not reach the total length of the original IP message.
[0036] Furthermore, according to the operation steps in S4, the judgment criterion for the bitmap anomaly is that after the reorganization is completed, there is a bit 1 in the bitmap (which will not appear in theory), which means that some fragments are not linked, or if the reorganization is not completed due to timeout, the bitmap bit will also be 1.
[0037] Further, according to the operation steps in S5,
[0038] S501. When an abnormal situation occurs, release the current IP fragment memory block.
[0039] S502. Find the pointer in the pointer array corresponding to the bitmap bit being 1.
[0040] S503. If it is not NULL, release the memory block of the IP fragment (including the cascaded IP fragment) pointed to, and set the pointer and the pointer corresponding to the tail byte of the fragment (including the cascaded IP fragment) to NULL, and the bitmap position is 0.
[0041] S504, then re-search the pointer in the pointer array corresponding to the bitmap bit being 1.
[0042] S505. Repeat the above operations until all bitmap bits are 0, and finally return to the initial state to prepare for the next reorganization.
[0043] Further, according to the operation steps in S6,
[0044] S601: After receiving the first fragment, the first fragment and subsequent fragments in the cascade may be returned to the service caller.
[0045] S602: Record the position of the last shard in the cascade.
[0046] S603: Repeat the above operation after receiving the subsequent cascade fragments of the fragment to achieve virtual reassembly of the IP fragments.
[0047] Further, according to the operation steps in S1, the pointer array is mainly used to quickly locate the storage location of the IP fragment message and use the pointer to point to the first address of the IP fragment message structure to store the message. The bitmap is mainly used to mark which positions in the pointer array store the IP fragment message, and is used for subsequent judgment of whether the reassembly is abnormal and to clean up the IP fragment message. In the initial state, all bits of the bitmap are 0, and all pointers in the pointer array point to NULL.
[0048] The present invention provides a method for quickly reassembling IP fragment messages, which has the following beneficial effects:
[0049] There is no need to wait for all the fragmented messages to arrive and perform multiple rounds of comparison and sorting on the fragmented messages. The sorting is completed when the message is received, and anomalies can be discovered earlier. For example, the position (offset) overlap of the header or tail bytes of the fragment can be discovered immediately, thereby resisting attacks from abnormal fragmented messages. It is not limited by the number and frequency of fragments. For example, there can be many fragments and many fragments of fragments. Compared with the RFC815 reassembly algorithm, it has the following advantages: there is no need to use a linked list to manage the unfilled area descriptor, and there is no need to traverse the linked list to locate the fragment, saving the time of maintenance and traversal of the linked list, thereby quickly locating the fragment position, and the buffer can be reduced by meta_size / sizeof(char*) times. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] Figure 1 A schematic diagram of a pointer array for rapid positioning of a method for rapid reassembly of IP fragmented messages according to the present invention;
[0051] Figure 2 A schematic diagram of a method for rapidly reassembling IP fragments according to the present invention;
[0052] Figure 3 A schematic diagram of the completion of reassembly of a method for rapid reassembly of IP fragment messages according to the present invention;
[0053] Figure 4 A schematic diagram of anomaly in the position overlap of fragment headers in a method for rapid reassembly of IP fragment messages according to the present invention;
[0054] Figure 5 A schematic diagram of abnormal situation processing of a method for rapid reassembly of IP fragmented messages according to the present invention;
[0055] Figure 6 This is a flow chart of a method for rapidly reassembling IP fragmented messages according to the present invention.
[0056] The present invention provides a technical solution:
[0057] Example 1, please refer to Figure 1-6 A method for quickly reassembling IP fragmented messages includes a pointer array and a bitmap. The pointer array is mainly used to quickly locate the storage location of the IP fragmented message and use the pointer to point to the first address of the IP fragmented message structure to store the message. The bitmap is mainly used to mark which locations in the pointer array store the IP fragmented message and is used for subsequent judgment of whether the reassembly is abnormal and to clean up the IP fragmented message. In the initial state, all bits of the bitmap are 0 and all pointers in the pointer array point to NULL.
[0058] See also Figure 1, Quick positioning of the pointer array: Set the byte size represented by each element of the pointer array to meta_size (the specific value can be set according to the actual situation, the condition is that it must be ≤ pmtu, that is, not greater than the minimum length of the non-last fragment message), the number of elements in the pointer array can be set according to the maximum supported IP message length, when an IP fragment message is received, get the offset of the fragment, and then calculate the storage position of the first byte of the fragment header in the pointer array: offset*8 / meta_size, point the pointer of the corresponding position in the pointer array to the fragment, set the corresponding bitmap position to 1, and then calculate the position of the last byte of the fragment tail in the pointer array: (offset*8+len) / meta_size, point the pointer of the corresponding position in the pointer array to the fragment, if it is the last fragment, there is no need to find the position of the tail byte, if it is not the first fragment, remove the IP header of the fragment.
[0059] See also Figure 2 , Fast fragment reassembly: When quickly locating the fragment position, after finding the position of the fragment header byte, first determine whether the pointer of the position is NULL. If it is NULL and the corresponding bitmap bit is 0, follow the above-mentioned fast positioning algorithm. If it is not NULL and the corresponding bitmap bit is 0, it means that the position is the tail byte of the previous fragment, and the pointer points to the previous fragment. Connect the fragment to the back of the previous fragment, such as the mbuf cascade of dpdk, the same below, and point the pointer to NULL. After finding the position of the fragment tail byte, first determine whether the pointer of the position is NULL. If it is NULL and the corresponding bitmap bit is 0, follow the above-mentioned fast positioning algorithm. If it is not NULL and the corresponding bitmap bit is 1, it means that the position is the header byte of the next fragment, and the pointer points to the next fragment. Connect the next fragment to the back of the fragment, and point the pointer to NULL, and the corresponding bitmap position is 0. Similarly, for non-first fragments, remove the IP header of the fragment.
[0060] See also Figure 3, reassembly is completed: after receiving each fragment, record the message length of the fragment and determine whether it is the first fragment or the last fragment. If it is the last fragment, you can get the total length of the original IP message. When the first fragment and the last fragment are received and the total length of the fragments is the total length of the original IP message, the reassembly is considered complete, and the parameters such as the IP header length of the first fragment need to be modified. The first pointer in the pointer array has a subscript of 0, which corresponds to the first fragment and points to the IP message after the reassembly is completed. It can be used for subsequent services. Point the pointer to NULL and the corresponding bitmap position is 0. If there is no abnormality, after the reassembly is completed, all bits of the bitmap are 0, and all pointers in the pointer array point to NULL, returning to the initial state to prepare for the next reassembly.
[0061] See also Figure 4 , abnormal situation:
[0062] In the fast reassembly algorithm, there are some exceptions: when locating the header byte of a fragment, if the corresponding position pointer is not NULL and the corresponding bitmap bit is 1, and the header byte offset of another fragment overlaps, the attached Figure 4 , or the corresponding position pointer is NULL and the corresponding bitmap bit is 1. When locating the tail byte of the fragment, if the corresponding position pointer is not NULL and the corresponding bitmap bit is 0, it coincides with the tail byte offset of another fragment, or the corresponding position pointer is NULL and the corresponding bitmap bit is 1.
[0063] IP fragment message length is abnormal: if the total length of the IP fragments is greater than the total length of the original IP message, or the total length of the IP fragments is less than the total length of the original IP message and the timeout does not reach the total length of the original IP message.
[0064] Bitmap exception: If there is a 1 bit in the bitmap after the reassembly is completed, which theoretically should not occur, it means that some fragments are not linked, or the reassembly is not completed due to timeout, then the bitmap bit will also be 1.
[0065] See also Figure 5 ,Exception handling: When an exception occurs, release the current IP fragment memory block, and find the pointer in the pointer array corresponding to the bitmap bit 1. If it is not NULL, release the pointed IP fragment memory block, including the cascaded IP fragment memory block, and point the pointer at the current pointer array position and the pointer corresponding to the tail byte of the fragment and its cascaded IP fragment to NULL, the bitmap position is 0, and then re-search for the pointer in the pointer array corresponding to the bitmap bit 1, repeat the above operation until all bitmap bits are 0, and finally return to the initial state to prepare for the next reorganization.
[0066] Virtual reassembly: After receiving the first fragment, the first fragment and the subsequent fragments of the cascade can be returned to the business caller, and the position of the last fragment of the cascade at this time can be recorded. After receiving the subsequent cascade fragments of the fragment, the above operation is repeated to realize the virtual reassembly of the IP fragment. That is, there is no need to wait for all fragments to arrive, but starting from the first fragment, the fragment message is returned as soon as possible in the reassembly order without modifying the IP header of the fragment. It can generally be used for security services.
[0067] While embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions, and variations may be made to these embodiments without departing from the principles and spirit of the invention, and that the scope of the invention is defined by the appended claims and their equivalents.
Claims
1. A method for rapidly reassembling IP fragmented messages, characterized in that: The following steps are involved: S1. Rapid positioning of pointer array; S2, rapid reassembly of fragments; S3, reorganization completed; S4. Abnormal situation handling; S5, virtual reorganization; According to the steps in S1, S101. Set the byte size represented by each element of the pointer array to meta_size; S102, the number of elements in the pointer array can be set according to the maximum supported IP message length; S103. After receiving an IP fragment message, obtain the offset of the fragment, then calculate the storage position of the fragment header byte in the pointer array: offset*8 / meta_size, point the pointer at the corresponding position in the pointer array to the fragment, and set the corresponding bitmap position to 1; S104. Then calculate the position of the tail byte of the slice in the pointer array: (offset*8+len) / meta_size, and point the pointer at the corresponding position in the pointer array to the slice; S105. If it is the last fragment, there is no need to find the position of the tail byte. If it is not the first fragment, remove the IP header of the fragment. According to the steps in S2, S201. When quickly locating a fragment, find the fragment header byte. S202: First determine whether the pointer at the location is NULL. If it is NULL and the corresponding bitmap bit is 0, operate according to the above-mentioned fast positioning algorithm; S203. If it is not NULL and the corresponding bitmap bit is 0, it means that the position is the tail byte of the previous fragment and the pointer points to the previous fragment. Connect this fragment to the end of the previous fragment and set the pointer to NULL. S204: After finding the location of the tail byte of the fragment, first determine whether the pointer of the location is NULL; S205: If the value is NULL and the corresponding bitmap bit is 0, the above-mentioned fast positioning algorithm is used; S206. If it is not NULL and the corresponding bitmap bit is 1, it means that the position is the header byte of the next fragment and the pointer points to the next fragment. The next fragment is connected to the end of the fragment and the pointer points to NULL. The corresponding bitmap position is 0. Similarly, for non-first fragments, the IP header of the fragment is removed. According to the steps in S5, S501: After receiving the first fragment, the first fragment and subsequent fragments of the cascade are returned to the service caller; S502: Record the position of the last shard in the cascade. S503: Repeat the above operation after receiving the subsequent cascade fragments of the fragment to achieve virtual reassembly of the IP fragments.
2. The method for rapidly reassembling IP fragmented messages according to claim 1, wherein: The following steps are involved: According to the operation steps in S3, S301. After receiving each fragment, record the message length of the fragment; S302: Determine whether it is the first fragment or the last fragment; S303. If it is the last fragment, the total length of the original IP message of the fragment can be obtained. When the first fragment and the last fragment are received and the total length of the fragments is the total length of the original IP message, the reassembly is considered complete. The first pointer in the pointer array points to the IP message after the reassembly, which can be used for subsequent services. The pointer points to NULL and the corresponding bitmap position is 0. S304: If there are no abnormalities, after the reorganization is completed, all bits of the bitmap are 0, all pointers in the pointer array point to NULL, and the system returns to the initial state to prepare for the next reorganization.
3. The method for rapidly reassembling IP fragmented messages according to claim 2, wherein: The method includes the following steps: according to the operation steps in S4, the abnormal conditions include abnormal overlap of the fragment header position, abnormal overlap of the fragment tail position, abnormal IP fragment message length and abnormal bitmap.
4. The method for rapidly reassembling IP fragmented messages according to claim 3, wherein: The following steps are involved: According to the operation steps in S4, the criterion for determining the abnormal overlap of the position of the header of the slice is that when the header byte of the slice is positioned, if the corresponding position pointer is not NULL and the corresponding bitmap bit is 1, it overlaps with the header byte offset of another slice, or the corresponding position pointer is NULL and the corresponding bitmap bit is 1. It is mainly used to determine whether the slices are crossed at the first time. The implementation method is to set the corresponding bitmaps between the head and tail of the slice to 1 after receiving the slice, and set them to 0 when releasing the slice.
5. The method for rapidly reassembling IP fragmented messages according to claim 4, wherein: The method comprises the following steps: according to the operation steps in S4, the criterion for determining the abnormal overlap of the tail position of the slice is that when the tail byte of the slice is positioned, if the corresponding position pointer is not NULL and the corresponding bitmap bit is 0, it overlaps with the tail byte offset of another slice, or the corresponding position pointer is NULL and the corresponding bitmap bit is 1.
6. The method for rapidly reassembling IP fragmented messages according to claim 5, wherein: The method comprises the following steps: according to the operation steps in S4, the IP fragment message length abnormality judgment standard is that the total length of the IP fragments is greater than the total length of the original IP message, or the total length of the IP fragments is less than the total length of the original IP message and the total length of the original IP message is not reached within a timeout.
7. The method for rapidly reassembling IP fragmented messages according to claim 6, wherein: The method includes the following steps: according to the operation steps in S4, the judgment criterion for the bitmap abnormality is that after the reorganization is completed, if there is a bit 1 in the bitmap, it means that some fragments are not linked, or if the reorganization is not completed due to timeout, the bitmap bit will also be 1.
8. A method for rapid reassembly of IP fragmented messages according to claim 7, characterized in that: The method comprises the following steps: according to the operation steps in S4, S401. When an abnormal situation occurs, release the current IP fragment memory block; S402, find the pointer in the pointer array corresponding to the bitmap bit being 1; S403. If it is not NULL, the memory block of the IP fragment and its cascaded IP fragment are released, and the pointer of the current pointer array position and the pointer corresponding to the tail byte of the fragment and its cascaded IP fragment are pointed to NULL, and the bitmap position is 0; S404, then re-search the pointer in the pointer array corresponding to the bitmap bit being 1; S405. Repeat the above operations until all bitmap bits are 0, and finally return to the initial state to prepare for the next reorganization.
9. The method for rapidly reassembling IP fragmented messages according to claim 8, wherein: The method comprises the following steps: according to the operation steps in S1, the pointer array is mainly used to quickly locate the storage location of the IP fragment message and use a pointer to point to the first address of the IP fragment message structure to store the message; the bitmap is mainly used to mark which positions in the pointer array store the IP fragment message and is used for subsequent judgment of whether the reassembly is abnormal and clearing the IP fragment message; in the initial state, all bits of the bitmap are 0, and all pointers in the pointer array point to NULL.
Citation Information
Patent Citations
Fragmentation and reassembly method based on network protocol version six
CN101316232A
Anti-attack IPv6 fragmentation message reassembling method and device
CN103491096A