Session forwarding method and device and electronic equipment
Through real -time update of the session information in the forwarding device, the package loss problem caused by the renewal of session information was solved, and the reliability of the forwarding process was improved.
Patent Information
- Application Number
- CN202411476806.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-21
- Publication Date
- 2025-01-24
AI Technical Summary
In the forwarding device, because the session information is not updated in time, packet loss is prone to occur during the forwarding process.
Through the relationship between the reference value of the matching value and the search table item based on the session information, the session information is updated in real time. The specific steps include obtaining session information. Find the routing table to update the session information.
It reduces the probability of packaging due to the failure of session information to update, and improves the reliability of the forwarding process.
Smart Images

Figure CN119363645A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer security technology, and in particular to a session forwarding method, device and electronic device. Background Art
[0002] A forwarding device is usually provided with a session table, which is used to store the running status information of each session, including the routing information matched by the session. When the routing table entry referenced by the session becomes invalid due to changes in the interface status, it is necessary to traverse the session table to update the relevant session table entries. However, this method does not update in time, which makes it easy to lose packets during the forwarding process. Summary of the invention
[0003] The present application provides a session forwarding method, device and electronic device, which can update the session information based on the relationship between the matching value on the session information and the reference value of the searched routing table item, and update the session information in real time, thereby reducing the probability of packet loss caused by untimely updating of the session information.
[0004] In a first aspect of the present application, a session forwarding method is provided, comprising:
[0005] Obtaining session information, the session information including the destination IP and the matching value;
[0006] If the first routing table item triggers a routing table update event, the reference value in the first routing table item is updated; wherein the first routing table item is any routing table item among multiple routing table items in the routing table;
[0007] Determine a first routing table entry from the routing table based on the destination IP address of the session information;
[0008] If the matching value of the session information is not equal to the reference value of the first routing table entry, re-searching the route based on the destination IP of the session information to obtain a second routing table entry;
[0009] The session information is forwarded based on the second routing table entry.
[0010] In some embodiments, updating the reference value in the first routing table entry includes:
[0011] The reference value corresponding to the first routing table entry is added to a preset value to obtain the new reference value corresponding to the first routing table entry, and the current reference value of the first routing table entry is replaced by the new reference value.
[0012] In some embodiments, each of the routing table entries includes a destination IP and outbound interface information corresponding to the destination IP; and determining the first routing table entry from the routing table based on the destination IP of the session information includes:
[0013] The routing table entry in which the destination network information is the same as the destination IP and the outbound interface information corresponds to the highest priority is determined as the first routing table entry.
[0014] In some embodiments, the forwarding processing of the session information based on the second routing table entry includes:
[0015] Determine the next hop mac information of the session information based on the second routing table entry, and save the next hop mac information and the outbound interface information of the second routing table entry into the session information;
[0016] The session information is forwarded based on the next hop mac information and the outbound interface information stored in the session information.
[0017] In some embodiments, the method further comprises:
[0018] The matching value of the session information is updated according to the reference value of the second routing table entry.
[0019] In some embodiments, the method further comprises:
[0020] If the matching value of the session information is equal to the reference value of the first routing table entry, forwarding processing is performed on the session information based on the first routing table entry.
[0021] A second aspect of an embodiment of the present application provides a session forwarding device, including:
[0022] An acquisition module is used to acquire session information, wherein the session information includes a destination IP and a matching value;
[0023] An updating module, configured to update a reference value in a first routing table item if the first routing table item triggers a routing table update event; wherein the first routing table item is any one of a plurality of routing table items in the routing table;
[0024] A search module, configured to determine a first routing table entry from the routing table based on the destination IP of the session information; if the matching value of the session information is not equal to the reference value of the first routing table entry, re-search the route based on the destination IP of the session information to obtain a second routing table entry;
[0025] A forwarding module is used to forward the session information based on the second routing table entry.
[0026] According to a third aspect of the embodiments of the present application, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method steps described in any one of the above embodiments are implemented.
[0027] In a fourth aspect of the embodiments of the present application, a non-transitory computer-readable storage medium is provided, on which a computer program is stored, characterized in that when the computer program is executed by a processor, the method steps described in any of the above embodiments are implemented.
[0028] The embodiment of the present application provides a session forwarding method, comprising: acquiring session information, the session information comprising a destination IP and a matching value; if a first routing table item triggers a routing table update event, updating a reference value in the first routing table item; wherein the first routing table item is any routing table item in a routing table; based on the destination IP of the session information, determining a first routing table item from the routing table; if the matching value of the session information is not equal to the reference value of the first routing table item, re-searching a route based on the destination IP of the session information to obtain a second routing table item; forwarding the session information based on the second routing table item; in this way, the session information can be updated in real time based on the relationship between the matching value on the session information and the reference value of the searched routing table item, thereby reducing the probability of packet loss caused by untimely updating of the session information. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 A flow chart of a session forwarding method provided in an embodiment of the present application;
[0030] Figure 2 A flowchart of another session forwarding method provided in an embodiment of the present application;
[0031] Figure 3 A schematic diagram of the structure of a session forwarding device provided in an embodiment of the present application;
[0032] Figure 4 A schematic diagram of the physical structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0033] In order to make the purpose, technical solutions and advantages of the present application clearer, the technical solutions in the present application will be clearly and completely described below in conjunction with the drawings in the present application.
[0034] A forwarding device is usually provided with a session table, which is used to store the running status information of each session, including the routing information matched by the session. When the routing table entry referenced by the session becomes invalid due to changes in the interface status, it is necessary to traverse the session table to update the relevant session table entries. However, this method does not update in time, which makes it easy to lose packets during the forwarding process. In addition, when there are many session information entries, the performance consumption of traversing the session information is relatively large.
[0035] In order to solve the above problems, the present application provides a session forwarding method, which can update the session information based on the relationship between the matching value on the session information and the reference value of the searched routing table item, and update the session information in real time, thereby reducing the probability of packet loss caused by untimely updating of the session information.
[0036] See also Figure 1 , an embodiment of the present application provides a session forwarding method, comprising:
[0037] S101. Obtain session information.
[0038] The session information includes the destination IP and the matching value.
[0039] In some embodiments, the destination IP (Internet Protocol) is the network address to which the data packet corresponding to the session information needs to go. The matching value is the reference value corresponding to the matched routing table entry currently stored in the session information.
[0040] Exemplarily, it is assumed that there is a routing table as shown in Table 1. The smaller the priority value of a route, the higher the priority; the larger the priority value of a route, the lower the priority; that is, the smaller the priority value of a route will be selected first.
[0041] Table 1
[0042]
[0043] Based on the routing table shown in Table 1, when the new session information with the destination IP of 22.22.22.0 / 24 reaches the forwarding device, by checking the routing table, it can be obtained that the message corresponding to the new session information needs to be sent from the output interface ge2, and the reference value (also called g_freshness) of the current routing table item (also called routing information) is 99656. At the same time, the next hop mac information of the new session information can be obtained by querying the neighbor table. Afterwards, the output interface ge2, the next hop mac information and the g_freshness99656 of the current routing table item are saved in the new session information. In this way, the matching value (also called freshness) of the session information with the destination IP of 22.22.22.0 / 24 will be 99656. If the session information is obtained later, the matching value of the session information with the destination IP of 22.22.22.0 / 24 will be 99656. The above solution can be implemented through the following session structure, in which the current session pointer is ct:
[0044]
[0045] ct->o_dev=dev1; / / dev1 stores the pointer to the ge2 interface.
[0046] memcpy(&ct->hh_cache,hh_cache1,sizeof(ct->hh_cache)); / / hh_cache1 is the next hop neighbor mac address of outgoing interface ge2;
[0047] ct->freshness=99656.
[0048] The next hop mac information refers to the physical address of the next network device that the data packet corresponding to the session information needs to pass through during the transmission process.
[0049] In some embodiments, when a new routing table entry is created, a global variable g_freshness initialized to 0 may be defined, and the g_freshness of the global variable may be determined as a reference value of the new routing table entry.
[0050] Exemplarily, the global variable g_freshness may be defined by the following procedure:
[0051] unsigned int g_freshness=0.
[0052] S102: If the first routing table entry triggers a routing table update event, update the reference value in the first routing table entry.
[0053] The first routing table entry is any routing table entry among multiple routing table entries in the routing table.
[0054] In some embodiments, the routing table in the forwarding device will be updated when the routing table update event is triggered; wherein, the routing table update event will be triggered when at least one of the interface status and the routing configuration in the first routing table item is updated.
[0055] Exemplarily, if at least one of the interface status and routing configuration in the routing table is updated, the reference value in the routing table item is also updated. The interface status update in the routing table means that the outbound interface status of the routing table item changes, and the routing configuration update in the routing table means that the routing table item in the routing table is added, deleted or modified.
[0056] In some embodiments, updating the reference value in the first routing table entry includes: adding the reference value corresponding to the first routing table entry to a preset value to obtain a new reference value corresponding to the first routing table entry, and replacing the current reference value of the first routing table entry with the new reference value.
[0057] Among them, the preset value is a preset value and can be set according to needs, and the embodiment of the present application is not limited to this.
[0058] Exemplarily, assuming the preset value is 1, based on Table 1, if the destination network information is the interface status update in the routing table entry of 22.22.22.0 / 24; for example, the next-hop interface of ge2 is down, resulting in the route with the outgoing interface ge2 being unavailable, then the routing table update event will be triggered, and the reference value in the first routing table entry will be updated, that is, the reference value in the first routing table entry will be added to the preset value 1 to obtain a new reference value, and the current reference value of the first routing table entry will be replaced with the new reference value.
[0059] The reference value can be updated through the following procedure:
[0060] g_freshness++;
[0061] Current g_freshness is 99657.
[0062] The updated routing table entries will be as shown in Table 2:
[0063] Table 2
[0064]
[0065] S103: Determine a first routing table entry from the routing table based on the destination IP address of the session information.
[0066] Each routing table entry includes a destination IP and an outbound interface information corresponding to the destination IP; and the first routing table entry represents a route in the routing table that matches the session information.
[0067] Exemplarily, based on the destination IP of the session information, a route is searched in a routing table to determine a routing table entry that matches the session information from a plurality of routing table entries, thereby obtaining a first routing table entry.
[0068] In some embodiments, S103 includes: determining a routing table entry in the routing table with the destination network information being the same as the destination IP and the highest priority corresponding to the outbound interface information as the first routing table entry.
[0069] Exemplarily, based on the routing information shown in Table 1 (also referred to as routing table entries), it can be known that there is a route in the network topology of the forwarding device, and the outbound interfaces to the destination network 22.22.22.0 / 24 are ge2 and ge3. Since the priority of outbound interface ge2 is higher than that of ge3, when the destination IP of the acquired session information is 22.22.22.0 / 24, the selected outbound interface is the routing information corresponding to the route to which ge2 belongs, which is determined as the first routing table entry.
[0070] S104: If the matching value of the session information is not equal to the reference value of the first routing table entry, re-search the route based on the destination IP of the session information to obtain a second routing table entry.
[0071] The second routing table entry represents a route that is re-matched from the routing table when the matching value of the session information is not equal to the reference value of the first routing table entry.
[0072] In some embodiments, if the matching value of the session information is not equal to the reference value of the first routing table entry, it means that the reason table is updated. At this time, the route is searched again based on the destination IP of the session information.
[0073] Exemplarily, if the session information with the destination IP of 22.22.22.0 / 24 has been received before, the session information with the destination IP of 22.22.22.0 / 24 stores the outbound interface information, the matching value and the next-hop mac information. Assume that the outbound interface information stored in the session information with the destination IP of 22.22.22.0 / 24 is ge2, the matching value is 99656, and the first routing table item is determined from the routing table as the routing table item shown in Table 1. If the routing table is updated from Table 1 to Table 2, it means that the reference value (also called g_freshness) of the first routing table item is updated to 99657, that is, the matching value 99656 of the session information with the destination IP of 22.22.22.0 / 24 is not equal to the reference value 99657 of the first routing table item. At this time, the route is searched again based on the destination IP of 22.22.22.0 / 24 to obtain the second routing table item.
[0074] In some embodiments, if the matching value of the session information is equal to the reference value of the first routing table entry, the session information is forwarded based on the first routing table entry.
[0075] For example, if the matching value of the session information with the destination IP of 22.22.22.0 / 24 is equal to the reference value of the first routing table item, it means that the currently saved outgoing interface and next-hop mac information of the session information with the destination IP of 22.22.22.0 / 24 are valid. At this time, the session information can be forwarded according to the currently saved outgoing interface and next-hop mac information of the session information.
[0076] S105: Forward the session information based on the second routing table entry.
[0077] like Figure 2 As shown, in some embodiments, S105 may include S1051 - S1052 .
[0078] S1051. Determine the next hop MAC information of the session information based on the second routing table entry, and save the next hop MAC information and the outbound interface information of the second routing table entry into the session information.
[0079] S1052: forward the session information based on the next hop mac information and outbound interface information stored in the session information.
[0080] Exemplarily, based on the routing information shown in Table 2, if the route is re-searched and the second routing table entry corresponding to the session information with a destination IP of 22.22.22.0 / 24 indicates the route to which the outgoing interface is ge3, and at the same time the neighbor table is queried to obtain the corresponding next-hop mac information, the outgoing interface ge3 and the corresponding next-hop mac information are saved in the session information with a destination IP of 22.22.22.0 / 24; and the session information with a destination IP of 22.22.22.0 / 24 is forwarded according to the outgoing interface ge3 and the corresponding next-hop mac information.
[0081] In some embodiments, the session forwarding method provided by the embodiments of the present application further includes: updating the matching value of the session information according to the reference value of the second routing table item.
[0082] In some embodiments, the matching value of the session information is replaced by the reference value of the second routing table entry to complete the updating of the matching value of the session information.
[0083] Exemplarily, the method of S104-S105 can be implemented by the following procedure:
[0084] ct->freshness is not equal to g_freshness, update the outbound interface information on the session information;
[0085] ct->o_dev=dev2; / / dev2 stores the pointer to the ge3 interface.
[0086] memcpy(&ct->hh_cache,hh_cache2,sizeof(ct->hh_cache)); / / hh_cache2 is the next-hop neighbor MAC address of outbound interface ge3.
[0087] ct->freshness=99657.
[0088] That is, if the reference value of the second routing table entry corresponding to the session information with the destination IP of 22.22.22.0 / 24 is 99657, the matching value of the session information with the destination IP of 22.22.22.0 / 24 is updated to 99657.
[0089] In some embodiments, another session forwarding method provided by an embodiment of the present application includes:
[0090] Define an integer global variable g_freshness (also called a reference value), where the initial value of the integer global variable is set to 0. If an event occurs that will cause the device routing table to be updated, such as an interface status update or a routing configuration update, g_freshness will be incremented by 1. After the newly created session information matches the routing table entry, the matching outbound interface information and next-hop mac information are saved in the session information, and the current g_freshness of the matching routing table entry is saved as freshness (also called a matching value) in the session information. When the subsequent traffic of the session information uses the outgoing interface information and the next-hop mac information, compare the freshness saved in the session information with the g_freshness of the currently matched routing table entry; if the freshness saved in the session information and the g_freshness of the currently matched routing table entry are equal, it means that the outgoing interface information and the next-hop mac information saved in the session information are valid, and the outgoing interface information and the next-hop mac information saved in the session information are directly used; if the freshness saved in the session information and the g_freshness of the currently matched routing table entry are not equal, it means that the outgoing interface information and the next-hop mac information saved in the session information are invalid, and the route is searched again to obtain new outgoing interface information and the next-hop mac information.
[0091] It is understandable that saving the outbound interface information and the next-hop mac information in the session information can improve the throughput performance of the forwarding device. At the same time, by updating the reference value, the routing outbound interface information and the next-hop mac information referenced in the session information can be updated in real time, solving the problem of packet loss caused by the untimely update of the routing outbound interface information and the next-hop mac information in the session information. In addition, there is no need to traverse the session table to clear the session mark, which can reduce performance consumption.
[0092] See also Figure 3 , an embodiment of the present application provides a session forwarding device, including:
[0093] The acquisition module 301 is used to acquire session information, wherein the session information includes a destination IP and a matching value;
[0094] An updating module 302 is configured to update a reference value in a first routing table item if the first routing table item triggers a routing table update event; wherein the first routing table item is any one of a plurality of routing table items in the routing table;
[0095] A search module 303 is used to determine a first routing table item from the routing table based on the destination IP of the session information; if the matching value of the session information is not equal to the reference value of the first routing table item, re-search the route based on the destination IP of the session information to obtain a second routing table item;
[0096] The forwarding module 304 is configured to forward the session information based on the second routing table entry.
[0097] In some embodiments, the updating module 302 is further used to add the reference value corresponding to the first routing table entry to a preset value to obtain the new reference value corresponding to the first routing table entry, and replace the current reference value of the first routing table entry with the new reference value.
[0098] In some embodiments, the search module 303 is further used to determine the routing table entry in the routing table whose destination network information is the same as the destination IP and whose outbound interface information corresponds to the highest priority as the first routing table entry.
[0099] In some embodiments, the forwarding module 304 is further used to determine the next hop mac information of the session information based on the second routing table entry, and save the next hop mac information and the outbound interface information of the second routing table entry into the session information;
[0100] The session information is forwarded based on the next hop mac information and the outbound interface information stored in the session information.
[0101] In some embodiments, the updating module 302 is further configured to update the matching value of the session information according to the reference value of the second routing table item.
[0102] In some embodiments, the forwarding module 304 is further configured to forward the session information based on the first routing table entry if the matching value of the session information is equal to the reference value of the first routing table entry.
[0103] like Figure 4 As shown, an electronic device provided in an embodiment of the present application may include: a processor (processor) 410, a communication interface (Communications Interface) 420, a memory (memory) 430 and a communication bus 440, wherein the processor 410, the communication interface 420, and the memory 430 communicate with each other through the communication bus 440. The processor 410 may call the logic instructions in the memory 430 to execute the above methods.
[0104] In addition, the logic instructions in the above-mentioned memory 430 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the switchgear mechanical state monitoring method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0105] In yet another aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which is implemented to perform the above methods when executed by a processor.
[0106] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0107] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0108] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A session forwarding method, characterized in that: include: Obtaining session information, the session information including the destination IP and the matching value; If the first routing table item triggers a routing table update event, the reference value in the first routing table item is updated; wherein the first routing table item is any routing table item among multiple routing table items in the routing table; Determine a first routing table entry from the routing table based on the destination IP address of the session information; If the matching value of the session information is not equal to the reference value of the first routing table entry, re-searching the route based on the destination IP of the session information to obtain a second routing table entry; The session information is forwarded based on the second routing table entry.
2. The method according to claim 1, characterized in that The updating of the reference value in the first routing table entry includes: The reference value corresponding to the first routing table entry is added to a preset value to obtain a new reference value corresponding to the first routing table entry, and the current reference value of the first routing table entry is replaced by the new reference value.
3. The method according to claim 1, characterized in that: Each of the routing table entries includes a destination IP and outbound interface information corresponding to the destination IP; The determining a first routing table entry from the routing table based on the destination IP address of the session information includes: The routing table entry in which the destination network information is the same as the destination IP and the outbound interface information corresponds to the highest priority is determined as the first routing table entry.
4. The method according to claim 3, characterized in that The forwarding processing of the session information based on the second routing table entry includes: Determine the next hop mac information of the session information based on the second routing table entry, and save the next hop mac information and the outbound interface information of the second routing table entry into the session information; The session information is forwarded based on the next hop mac information and the outbound interface information stored in the session information.
5. The method according to claim 1, characterized in that The method further comprises: The matching value of the session information is updated according to the reference value of the second routing table entry.
6. The method according to claim 1, characterized in that The method further comprises: If the matching value of the session information is equal to the reference value of the first routing table entry, forwarding processing is performed on the session information based on the first routing table entry.
7. A session forwarding device, characterized in that: include: An acquisition module is used to acquire session information, wherein the session information includes a destination IP and a matching value; An updating module, configured to update a reference value in a first routing table item if the first routing table item triggers a routing table update event; wherein the first routing table item is any one of a plurality of routing table items in the routing table; A search module, configured to determine a first routing table entry from the routing table based on the destination IP of the session information; if the matching value of the session information is not equal to the reference value of the first routing table entry, re-search the route based on the destination IP of the session information to obtain a second routing table entry; A forwarding module is used to forward the session information based on the second routing table entry.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the method according to any one of claims 1 to 6 is implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.