DNAT connectivity testing method, device and equipment based on ICMP
Through the ICMP-based DNAT connectivity testing method, the IP address is automatically replaced by custom ICMP packets and hook functions, which solves the problem of low testing efficiency caused by manual configuration of DMZ or DNAT in the existing technology, and realizes automatic internal network equipment Connectivity testing improves the efficiency and safety of the test.
Patent Information
- Application Number
- CN202411018094.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-29
- Publication Date
- 2024-11-08
- Estimated Expiration
- 2044-07-29
AI Technical Summary
The prior art requires manual configuration of DMZ or DNAT when testing network connectivity, resulting in inefficient testing and the inability to automatically detect the connectivity of multiple intranet IP addresses.
Using ICMP-based DNAT connectivity testing method, the destination IP address is automatically replaced by customizing the format and hook function of the ICMP packet, to realize the connectivity test of the external network to internal network devices, and reduce manual operations.
It improves the efficiency and security of network connectivity testing, avoids multiple debugging, realizes automatic testing of multiple intranet devices, and enhances the comprehensiveness of the testing.
Smart Images

Figure CN118573601B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of network communication technology, and in particular to a DNAT connectivity testing method, device and equipment based on ICMP. Background Art
[0002] With the development of the Internet and the increase in network applications, the limited IPv4 public addresses have become a bottleneck restricting the development of the network. To solve this problem, NAT (Network Address Translation) technology has emerged. If the external network wants to test the connectivity with the internal network, it is usually necessary to manually configure the DMZ (Demilitarized Zone) function or Destination NAT (DNAT) on the 5G router device, and further ping the IP address of the device under the router in the page to observe the network connectivity. The DMZ function means opening all service ports of the device to the external network, which is equivalent to mapping all ports and directly exposing the host to the gateway. It is more convenient than port mapping, but less secure, that is: the external network cannot directly use the ping command to test the connectivity with the IP address of the device under the 5G router device.
[0003] Therefore, the router device needs to manually configure DMZ or DNAT to map to the intranet IP address. Secondly, the manually configured DMZ or DNAT cannot be mapped to multiple intranet IP addresses, resulting in low connectivity test efficiency. Summary of the invention
[0004] The purpose of this application is to address the deficiencies of the above-mentioned existing related technologies and propose an ICMP-based DNAT connectivity test method, device and equipment to improve the efficiency of connectivity testing.
[0005] In a first aspect, the present application provides an ICMP-based DNAT connectivity test method, which is applied to a router device. The DNAT connectivity test method includes:
[0006] Receiving an initial network message sent by a network device on an external network; the initial network message is a message of a custom protocol, and the custom protocol includes: an IP header, an ICMP header, and a custom ICMP payload content arranged in sequence;
[0007] If the initial network message satisfies both the protocol field of the IP header and the type field of the ICMP header, judging whether the ICMP payload content conforms to the preset ICMP payload content format according to the custom hook function;
[0008] If the ICMP payload content conforms to the preset ICMP payload content format, extracting the forwarding destination IP address from the ICMP payload content, and using the forwarding destination IP address to replace the destination IP address carried in the IP header of the initial network message, to obtain a first network message after the address is updated;
[0009] According to the destination IP address carried in the IP header of the first network message, the first network message is sent to the downstream device to perform a connectivity test from the external network to the downstream device in the internal network.
[0010] The present application judges the IP header, ICMP header and ICMP payload content of the received initial network message in sequence to determine whether the initial network message complies with the custom protocol. If all of them comply, the forwarding destination IP address in the custom ICMP payload content is automatically replaced with the destination IP address in the IP header to obtain the first network message, and the first network message is forwarded to the corresponding downstream device, thereby eliminating the need for manual configuration of DMZ or DNAT, and enabling the external network to automatically test the connectivity of all downstream devices of the internal network's 5G router device, thereby improving the efficiency of connectivity testing.
[0011] Furthermore, the preset ICMP payload content format includes: a magic number field and a forwarding destination IP address field arranged in sequence; wherein,
[0012] The magic number field is used to identify the custom protocol;
[0013] The forwarding destination IP address field is used to identify the information that needs to be forwarded to a new destination IP address, and when the ICMP payload content conforms to the preset ICMP payload content format, the destination IP address is modified.
[0014] Further, the preset ICMP payload content format also includes: setting a check code field after the forwarding destination IP address field; the check code field is used to verify the legitimacy of the custom protocol; the magic number field and the check code field are also used to identify a custom ICMP message; the custom ICMP message includes: the ICMP header and the ICMP payload content; wherein, if the ICMP payload content conforms to the preset ICMP payload content format, it includes:
[0015] According to the custom hook function, if the magic field corresponding to the initial network message satisfies the preset magic value, the initial network message complies with the custom protocol, and if the corresponding value of the check code field satisfies the preset check code value, the initial network message is the custom ICMP message;
[0016] According to the custom hook function and based on the check code field, if the custom ICMP message meets the legality, the ICMP payload content conforms to the preset ICMP payload content format.
[0017] This application uses multiple step-by-step verifications to determine whether the initial network message conforms to the ICMP payload content format, thereby ensuring the legality and validity of the initial network message, improving the security of connectivity testing between network devices in the external network and downstream devices in the internal network, avoiding multiple debugging to obtain connectivity test results, and indirectly improving the efficiency of connectivity testing.
[0018] Furthermore, the preset ICMP payload content format further includes: setting a content length field after the magic number field and before the forwarding destination IP address; wherein,
[0019] The content length field is used to identify the length of the custom protocol; the length includes: the total length of the IP header, the ICMP header and the custom ICMP payload content.
[0020] Further, after obtaining the first network message after the address is updated, the method further includes:
[0021] According to the first network message, the verification result of the IP header is calculated, and according to the verification result, the value corresponding to the IP header verification code field is updated to obtain a second network message after the IP header verification code is updated; wherein, according to the destination IP address carried in the IP header of the second network message, the second network message is sent to the downstream device, so that after the downstream device receives the second network message, the legitimacy of the second network message is verified according to the value corresponding to the IP header verification code field.
[0022] Further, judging whether the ICMP payload content conforms to a preset ICMP payload content format according to the custom hook function includes:
[0023] According to the custom hook function, determining whether the initial network message belongs to the IP address of the router device;
[0024] If the initial network message belongs to the IP address of the router device, then judging whether the protocol field carried by the IP header of the initial network message is of ICMP type according to the custom hook function;
[0025] If the protocol field carried by the IP header of the initial network message is of ICMP type, then according to the custom hook function, it is determined whether the type field is an echo request message; wherein, if the type field is an echo request message, then according to the custom hook function, it is determined whether the ICMP payload content conforms to the preset ICMP payload content format.
[0026] Further, if the ICMP payload content does not conform to the preset ICMP payload content format, the external network performs a connectivity test on the router device through a Ping command.
[0027] This application also implements connectivity testing between the external network and the automatic 5G router device through the external network directly through the Ping command for the initial network message that does not meet the ICMP payload content format, thereby solving the problem that once the 5G router device is set with a directional DMZ or DNAT function, the 5G router device converts the destination IP address of all initial network messages as the IP address of the router device to the downstream device configured by the DMZ, resulting in the external network device being unable to detect connectivity with the 5G router device, thereby resulting in an incomplete connectivity test. Connectivity with the 5G router device can be detected directly through the external network through the Ping command without additional connectivity testing, thereby further improving the efficiency of connectivity testing.
[0028] In a second aspect, the present application provides a DNAT connectivity test device based on ICMP, which is applied to a router device. The DNAT connectivity test device includes: a receiving module, a load content format judgment module, a destination address modification module and a connectivity test module; wherein,
[0029] The receiving module is used to receive an initial network message sent by a network device on an external network; the initial network message is a message of a custom protocol, and the custom protocol includes: an IP header, an ICMP header and a custom ICMP payload content arranged in sequence;
[0030] The payload content format determination module is used to determine whether the ICMP payload content conforms to a preset ICMP payload content format according to a custom hook function if the initial network message satisfies both the protocol field of the IP header and the type field of the ICMP header;
[0031] The destination address modification module is used to extract the forwarding destination IP address from the ICMP payload content if the ICMP payload content conforms to the preset ICMP payload content format, and use the forwarding destination IP address to replace the destination IP address carried in the IP header of the initial network message, so as to obtain a first network message after the address is updated;
[0032] The connectivity test module is used to send the first network message to the downstream device according to the destination IP address carried in the IP header of the first network message, and perform a connectivity test from the external network to the downstream device in the internal network.
[0033] The present application receives the initial network message through a receiving module, and uses a load content format judgment module to judge the IP header, ICMP header and ICMP load content of the received initial network message in turn to determine whether the initial network message complies with the custom protocol. If all of them comply, the destination address modification module automatically replaces the destination IP address in the IP header with the forwarding destination IP address in the custom ICMP load content to obtain the first network message, and forwards the first network message to the corresponding downstream device through the connectivity test module, thereby eliminating the need for manual configuration of DMZ or DNAT, and enabling the external network to automatically test the connectivity of all downstream devices of the 5G router device in the internal network, thereby improving the efficiency of connectivity testing.
[0034] In a third aspect, the present application provides an electronic device, the electronic device comprising:
[0035] at least one processor; and,
[0036] a memory communicatively connected to the at least one processor; wherein,
[0037] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the ICMP-based DNAT connectivity test method as described in the first aspect.
[0038] The present application integrates the ICMP-based DNAT connectivity test method into electronic devices, which can automatically and instantly test the connectivity from the internal network to the external network through any electronic device with gateway function, and can be compatible with more different types of electronic products, with higher adaptability and applicability. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Figure 1 It is a schematic diagram of the network topology provided in the embodiment of the present application;
[0040] Figure 2 It is a flow chart of a DNAT connectivity testing method based on ICMP provided in an embodiment of the present application;
[0041] Figure 3 It is a format diagram of a custom protocol provided in an embodiment of the present application;
[0042] Figure 4 It is a flowchart of another ICMP-based DNAT connectivity test method provided in an embodiment of the present application;
[0043] Figure 5 It is a structural schematic diagram of an ICMP-based DNAT connectivity testing device provided in this application. DETAILED DESCRIPTION
[0044] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0045] It is worth mentioning that ICMP (Internet Control Message Protocol) is an error reporting mechanism and an important sub-protocol in the TCP / IP protocol suite. It is usually used by the IP layer or higher layer protocols (TCP or UDP). It belongs to the network layer protocol and is mainly used to transmit control messages between IP hosts and routers to report whether the host is reachable, whether the route is available, etc. Although these control messages do not transmit user data, they play a vital role in collecting various network information, diagnosing and troubleshooting various network failures, and transmitting user data.
[0046] See also Figure 1 , is a schematic diagram of the networking topology provided in an embodiment of the present application. The downstream devices A1-A3 and the downstream devices B1-B3 use the same LAN IP address through different 5G routing devices. When the downstream devices of the internal network perform connectivity tests with the network devices of the external network through the router device, the downstream devices can actively ping the network devices to perform a direct connectivity test. When the network devices want to perform connectivity tests with the downstream devices, it is necessary to manually configure the DMZ function or DNAT on the 5G router device, and further ping the IP address of the router downstream device in the page to observe the network connectivity. Connectivity testing of the external network and the downstream devices in this way requires more manual operations, so that automatic connectivity testing cannot be performed directly, resulting in low connectivity test efficiency.
[0047] Specifically, according to Figure 1, the downstream device (including: any one of A1 to A3 and B1 to B3) can actively ping the network device A of the external network, which is achieved by the 5G router device performing NAT network address conversion; however, network device A cannot directly access any of the router's downstream devices A1 / A2 / A3 / B1 / B2 / B3 if it wants to actively ping the test. The existing technology is to enable DMZ on the 5G router device, map it to the downstream device, and network device A sends a ping message with the destination address being the IP address of the router device. The DMZ function of the router device transfers the ping message of network device A to the downstream device, thereby completing the connectivity test of network device A to downstream device A.
[0048] Moreover, once the DMZ is turned on on the 5G router device, the 5G router device will convert the destination IP address of all ping messages to the IP address of the router device to the downstream device configured by the DMZ, causing the external network device to be unable to detect the connectivity with the 5G router device, resulting in an incomplete connectivity test. An additional connectivity test is required to detect the connectivity with the 5G router device, which in turn leads to lower connectivity test efficiency.
[0049] Based on this, the present application provides an ICMP-based DNAT connectivity test method and system, which performs automatic address conversion at the router device in a DNAT manner by judging the ICMP message and the pre-built ICMP payload content, so as to reduce manual operations and realize automatic connectivity testing of external-to-inside network devices and downstream devices, and network devices and router devices, thereby improving the efficiency of connectivity testing.
[0050] In order to better illustrate the scheme of the present application, it will be described in detail from the following examples.
[0051] Example 1
[0052] See also Figure 2 , is a flow chart of an ICMP-based DNAT connectivity test method provided in an embodiment of the present application, which is applied to a router device. The DNAT connectivity test method includes: steps S11 to S14, which are specifically as follows.
[0053] Step S11, receiving an initial network message sent by a network device on an external network; the initial network message is a message of a custom protocol, and the custom protocol includes: an IP header, an ICMP header and a custom ICMP payload content arranged in sequence.
[0054] In some embodiments, receiving an initial network message sent by a network device on an external network includes: performing device initialization and registering a custom hook function in a pre-routing chain of a data packet filtering framework; when receiving an initial network message sent by a network device on an external network, the custom hook function is called one by one to perform judgment and data processing on the initial network message; the judgment includes: judging whether the protocol field and the type field conform to the ICMP payload content format; the data processing includes: modifying the destination IP address.
[0055] It is worth noting that the network device can send a ping message with the destination address being the router device to the router device. The router device analyzes the payload content of the ping message. If the payload content matches a message of a custom protocol, it will further analyze each custom field and perform automatic DNAT (i.e., convert the destination IP address of the network message) based on the custom fields, thereby achieving automatic connectivity testing between the network device and the downstream device from the outside to the inside, thereby improving the efficiency of the connectivity test.
[0056] In some embodiments, the packet filtering framework may be a netfilter framework.
[0057] It is worth mentioning that the netfilter framework is a general architecture of the Linux 2.4 kernel firewall proposed by Rusty Russell. It works in the kernel space and is mainly composed of hook functions with packet filtering functions. Among them, a series of functions are registered in the hook point to process the data packet. These hook functions registered in the hook point are the data packet passage policies set in the network protocol stack. The functions implemented by this framework include: data packet filtering, data packet processing, address masquerading, transparent proxy and network address translation, as well as filtering based on user and media access control (MAC) addresses, state-based filtering and packet rate limiting. In addition, the netfilter framework adopts a modular design concept that runs through the kernel state and user state of the Linux system. At the user state level, different system call tools are provided for upper-level users according to different protocol types, including: iptables for IPv4 protocol, ip6tables for IPv6 protocol, arptables for ARP protocol, ebtables for bridge control, and conntrack for network connection tracking, etc. Different user-mode tools are implemented in corresponding modules in the kernel, and the underlying layers need to call the hook function API of the netfilter framework for implementation.
[0058] In some embodiments, a custom hook function is registered in a pre-routing chain of a data packet filtering framework. The custom hook function is a hook function redefined according to demand and is paired with a custom protocol.
[0059] In some embodiments, the router device is initialized and a custom hook function is registered in the pre-routing chain PRE_ROUTING of its netfilter framework.
[0060] Step S12: If the initial network message satisfies both the protocol field of the IP header and the type field of the ICMP header, it is determined according to the custom hook function whether the ICMP payload content conforms to the preset ICMP payload content format.
[0061] In some embodiments, if the initial network message satisfies both the protocol field of the IP header and the type field of the ICMP header, then according to a custom hook function, it is determined whether the ICMP payload content conforms to a preset ICMP payload content format, including: if the initial network message satisfies both the protocol field of the IP header and the type field of the ICMP header, then according to the custom hook function, it is determined whether the initial network message belongs to the IP address of the present router device; if the initial network message belongs to the IP address of the present router device, then according to the custom hook function, it is determined whether the protocol field carried by the IP header of the initial network message is an ICMP type; if the protocol field carried by the IP header of the initial network message is an ICMP type, then according to the custom hook function, it is determined whether the type field is an echo request message; wherein, if the type field is an echo request message, then according to the custom hook function, it is determined whether the ICMP payload content conforms to the preset ICMP payload content format.
[0062] In some embodiments, when the router device receives the initial network message, the custom hook functions registered to the pre-routing chain PRE_ROUTING are called and run one by one. If the "destination IP address" field carried in the IP header of the initial network message (hereinafter referred to as: message A) is judged according to the custom hook function, if it belongs to the range of the IP address of this routing device, then the custom hook function is continued to judge whether the "protocol" field carried in the IP header of message A is of ICMP type; if the "protocol" field carried in the IP header of message A is of ICMP type, then the ICMP header is further judged whether the type field is an echo request message Echo request; if the type field of the ICMP header is an echo request message Echorequest, then the custom hook function is continued to judge whether the ICMP payload content conforms to the ICMP payload content format of the custom protocol; if the ICMP payload content conforms to the ICMP payload content format of the custom protocol, then the "forwarding destination IP address" is extracted, and the forwarding destination IP address is prepared to be used to replace the destination IP address of the initial network message.
[0063] It is worth noting that the ICMP echo request defines a standard ICMP header, which does not make any requirements on the ICMP payload content. When the receiving end receives the echo request message, it will return the original ICMP payload content to the sending end (for example: network device A) as is.
[0064] In some embodiments, a preset ICMP payload content format includes: a magic number field and a forwarding destination IP address field arranged in sequence; wherein the magic number field is used to identify a custom protocol; the forwarding destination IP address field is used to identify information that needs to be forwarded to a new destination IP address, and when the ICMP payload content conforms to the ICMP payload content format, the destination IP address is modified.
[0065] In some embodiments, the ICMP payload content format further includes: setting a check code field after the forwarding destination IP address field; the check code field is used to verify the legitimacy of the custom protocol.
[0066] In some embodiments, the magic field and the checksum field are also used to identify custom ICMP messages.
[0067] In some embodiments, the custom ICMP message includes: an ICMP header and ICMP payload content.
[0068] In some embodiments, if the ICMP payload content conforms to the ICMP payload content format, including: according to a custom hook function, if the magic field corresponding to the initial network message satisfies a preset magic value, then the initial network message conforms to the custom protocol, and if the corresponding value of the check code field satisfies the check code preset value, then the initial network message is a custom ICMP message; according to the custom hook function and based on the check code field, if the custom ICMP message meets the legality, then the ICMP payload content conforms to the ICMP payload content format.
[0069] The embodiment of the present application uses multiple step-by-step verifications to determine whether the initial network message conforms to the ICMP payload content format, thereby ensuring the legality and validity of the initial network message, improving the security of connectivity testing between network devices in the external network and downstream devices in the internal network, avoiding multiple debugging to obtain the results of the connectivity test, and indirectly improving the efficiency of the connectivity test.
[0070] In some embodiments, the ICMP payload content format also includes: setting a content length field after the magic number field and before forwarding the destination IP address; wherein the content length field is used to identify the length of the custom protocol; the length includes: the total length of the IP header, ICMP header and ICMP payload content.
[0071] In some embodiments, see Figure 3 , is a schematic diagram of the format of a custom protocol provided in an embodiment of the present application. Figure 3 In the figure, the custom protocol includes: IP header, ICMP header, magic field, content length field, forwarding destination IP address field and check code field arranged from left to right; the ICMP payload content format of the custom protocol includes: magic field, content length field, forwarding destination IP address field and check code field arranged from left to right. The ICMP header and ICMP payload content format form an ICMP message, and after adding the IP header to the ICMP message, it forms a message of the custom protocol.
[0072] In some embodiments, the magic field may be 0xF1E2D3C4B5A69788 (a conventional value) to accurately identify the custom protocol and distinguish other normal ICMP messages.
[0073] In some embodiments, the content length field may identify the length of the custom protocol.
[0074] In some embodiments, the forwarding destination IP address field can provide new destination IP address information to be forwarded to, which is used to modify the "destination IP address" field of the IP header of message A.
[0075] In some embodiments, the check code field can be used to verify the legitimacy of the custom protocol and further distinguish other normal ICMP messages.
[0076] It is worth mentioning that the most important content provided by this application is that the router device analyzes the payload content of the ICMP message and automatically forwards it to the corresponding downstream device via DNAT, thereby realizing automatic connectivity testing from outside to inside, reducing manual operations, and thus improving connectivity testing efficiency.
[0077] Step S13: If the ICMP payload content conforms to the ICMP payload content format, extract the forwarding destination IP address from the ICMP payload content, and use the forwarding destination IP address to replace the destination IP address of the initial network message to obtain a first network message with an updated address.
[0078] It is worth noting that the first network message is a network message with a changed destination IP address for the initial network message, and the second network message mentioned later is a network message with a changed destination IP address and an updated check code field.
[0079] In some embodiments, after obtaining the first network message after the address is updated, it includes: calculating the verification result of the IP header according to the first network message, and updating the value corresponding to the verification code field according to the verification result, to obtain the second network message after the IP header verification code is updated; wherein, according to the destination IP address, the second network message is sent to the downstream device, so that after the downstream device receives the second network message, the legitimacy of the second network message is verified according to the value corresponding to the IP header verification code field.
[0080] It is worth noting that the check code of the ICMP payload content of the custom protocol is calculated based on the ICMP payload content to obtain the check code, and the IP header itself also has a check code (i.e., the IP header check code), and the two check codes exist independently. Since the destination IP address of the IP header has been modified, it is also necessary to recalculate the check code in the IP header to obtain the second network message. The downstream device does not interpret or process the "ICMP payload content of the custom protocol", so it does not know that there is a check code field in the ICMP payload content. The downstream device will only check the IP header check code, and when it responds to ICMP, it returns the original content of the ICMP request to the sender (that is, the external network device A as an example in this application).
[0081] In some embodiments, the "forwarding destination IP address" obtained by the custom hook function is modified to the "destination IP address" field of the message AIP header, and the IP header check code is recalculated and the value of the check code field is updated to obtain the second network message, after which the processing using the custom hook function is completed.
[0082] In some embodiments, if the ICMP payload content does not conform to the ICMP payload content format, it includes: the external network performs a connectivity test on the router device through a Ping command.
[0083] This application also implements connectivity testing between the external network and the automatic 5G router device through the external network directly through the Ping command for the initial network message that does not meet the ICMP payload content format, thereby solving the problem that once the 5G router device is set with a directional DMZ or DNAT function, the 5G router device converts the destination IP address of all initial network messages as the IP address of the router device to the downstream device configured by the DMZ, resulting in the external network device being unable to detect connectivity with the 5G router device, thereby resulting in an incomplete connectivity test. Connectivity with the 5G router device can be detected directly through the external network through the Ping command without additional connectivity testing, thereby further improving the efficiency of connectivity testing.
[0084] Step S14: Send the first network message to the downstream device according to the destination IP address, and perform a connectivity test from the external network to the downstream device in the internal network.
[0085] In some embodiments, the second network message is sent to the downstream device according to the destination IP address to perform a connectivity test from the external network to the downstream device in the internal network.
[0086] It is worth mentioning that the most critical content of this application is that the router device analyzes the payload content of the ICMP message and automatically forwards the message that conforms to the custom protocol to the corresponding downstream device by DNAT, thereby achieving the connectivity test of the network device to the downstream device; and, if the router device analyzes that the payload content of the ICMP message does not conform to the custom protocol message, it is processed by the local system (i.e., the router device), that is, the network device can also ping test the connectivity of the router device, thereby realizing the automatic connectivity test of the network device and the downstream device from the outside to the inside, and the automatic connectivity test of the network device and the router device, thereby improving the automatic connectivity test process from the external network to the internal network, and avoiding the low data transmission security caused by direct mapping.
[0087] The present application judges the IP header, ICMP header and ICMP payload content of the received initial network message in sequence to determine whether the initial network message complies with the custom protocol. If all of them comply, the forwarding destination IP address in the custom ICMP payload content is automatically replaced with the destination IP address in the IP header to obtain the first network message, and the first network message is forwarded to the corresponding downstream device, thereby eliminating the need for manual configuration of DMZ or DNAT, and enabling the external network to automatically test the connectivity of all downstream devices of the internal network's 5G router device, thereby improving the efficiency of connectivity testing.
[0088] Example 2
[0089] See also Figure 4 , is a flow chart of another ICMP-based DNAT connectivity test method provided in an embodiment of the present application, including: steps S21 to S27, specifically:
[0090] Step S21, the router device is initialized, and the custom hook function is registered to the system in the pre-routing chain in the data packet filtering framework.
[0091] Step S22: When the system of the router device receives the initial network message, the registered custom hook function is executed in the pre-routing chain. The initial network message should include: an IP header, an ICMP header and a custom ICMP payload content arranged in sequence. The following steps judge the initial network message and perform operations corresponding to the judgment results.
[0092] Step S23, whether the initial network message is an IP message and whether the destination IP address belongs to the IP address of the local system. At this time, it is necessary to determine in sequence whether the initial network message is an IP message and whether the destination IP address in the IP header of the initial network message belongs to the IP address of the local system according to the custom hook function. If the initial network message is an IP message and the destination IP address belongs to the IP address of the local system, then go to step S24, otherwise go to step S27.
[0093] Step S24: Whether the protocol field of the IP header is of ICMP type and whether the type field of the ICMP header is an echo request message. At this time, it is necessary to determine in sequence whether the protocol field of the IP header is of ICMP type and whether the type field of the ICMP header is an echo request message according to the custom hook function. If the protocol field of the IP header is of ICMP type and the type field of the ICMP header is an echo request message, then proceed to step S25, otherwise proceed to step S27.
[0094] Step S25: Whether the ICMP payload content conforms to the ICMP payload content format of the custom protocol. At this time, it is necessary to determine whether the ICMP payload content conforms to the ICMP payload content format of the custom protocol according to the custom hook function. If the ICMP payload content conforms to the ICMP payload content format of the custom protocol, then proceed to step S26, otherwise proceed to step S27.
[0095] Step S26, extract the value of the forwarding destination IP address field, and replace the destination IP address in the initial network message with the value of the forwarding destination IP address field to obtain the first network message, and recalculate the check code field of the first network message to obtain the second network message.
[0096] Step S27, the self-defined function processing ends, and the system performs the next step of processing on the network message. The network message includes: the initial network message, the first network message and the second network message, and other network messages that are not the initial network message and the first network message, other network messages that are not the initial network message and the second network message, other network messages that are not the first network message and the second network message, other network messages that are not the initial network message, other network messages that are not the first network message or other network messages that are not the second network message. Specifically, if step S26 turns to step S27, the self-defined function processing ends, and the local system forwards the second network message to the corresponding down-hung device according to the destination IP address of the second network message, and performs a connectivity test from the external network to the down-hung device in the internal network. If step S23 turns to step S27, the self-defined function processing ends, and the external network performs a connectivity test on the router device through the Ping command. If the process proceeds from step S24 to step S27, it indicates that the initial network message is an IP message and belongs to the IP address range of the local system, but is not an ICMP type message; or if the process proceeds from step S25 to step S27, it indicates that although the initial network message is an ICMP type message, it is not a message of a custom protocol, but a conventional type of ICMP type message, then the custom function processing is terminated, and the system performs other corresponding processing on the initial network message.
[0097] This application uses the method of judging the IP header, ICMP header and ICMP payload content of the received initial network message in turn to determine whether the initial network message complies with the custom protocol. If all of them comply, the forwarding destination IP address in the custom ICMP payload content is automatically replaced with the destination IP address in the IP header to obtain the first network message, and the first network message is forwarded to the corresponding downstream device, so that there is no need to manually configure DMZ or DNAT, and the external network can automatically test the connectivity of all downstream devices of the 5G router device of the internal network, thereby improving the efficiency of connectivity testing. If not all of them comply with the custom protocol, adaptive processing is performed through the corresponding network message processing method, so as to improve the versatility and applicability of connectivity tests of different types of network messages.
[0098] Example 3
[0099] See also Figure 5 , is a structural diagram of an ICMP-based DNAT connectivity test device provided by the present application, which is applied to a router device. The DNAT connectivity test device includes: a receiving module 31, a load content format judgment module 32, a destination address modification module 33 and a connectivity test module 34.
[0100] In some embodiments, after the receiving module 31 receives the initial network message sent by the network device on the external network, the initial network message is transmitted to the load content format judgment module 32; after the load content format judgment module 32 receives the initial network message, it performs a load content format judgment and transmits the load content format judgment result to the destination address modification module 33; after the destination address modification module 33 receives the load content format judgment result, it outputs a first network message and transmits the first network message to the connectivity test module 34; after the connectivity test module 34 receives the first network message, it performs a connectivity test.
[0101] The receiving module 31 is used to receive an initial network message sent by a network device on an external network; the initial network message is a message of a custom protocol, and the custom protocol includes: an IP header, an ICMP header and a custom ICMP payload content arranged in sequence.
[0102] In some embodiments, receiving an initial network message sent by a network device on an external network includes: performing device initialization and registering a custom hook function in a pre-routing chain of a data packet filtering framework. When receiving an initial network message sent by a network device on an external network, the custom hook function is called one by one to perform judgment and data processing on the initial network message; the judgment includes: judging the protocol field, the type field and whether it conforms to the ICMP payload content format; the data processing includes: modifying the destination IP address.
[0103] In some embodiments, the packet filtering framework may be a netfilter framework, which is composed of hook functions having packet filtering functions.
[0104] The payload content format determination module 32 is used to determine whether the ICMP payload content conforms to a preset ICMP payload content format according to a custom hook function if the initial network message satisfies both the protocol field of the IP header and the type field of the ICMP header.
[0105] In some embodiments, if the initial network message satisfies both the protocol field of the IP header and the type field of the ICMP header, it includes: if the initial network message satisfies both the protocol field of the IP header and the type field of the ICMP header, it includes: according to a custom hook function, judging whether the initial network message belongs to the IP address of the present router device; if the initial network message belongs to the IP address of the present router device, then according to the custom hook function, judging whether the protocol field carried by the IP header of the initial network message is of ICMP type; if the protocol field carried by the IP header of the initial network message is of ICMP type, then according to the custom hook function, judging whether the type field is an echo request message; wherein, if the type field is an echo request message, then judging whether the ICMP payload content conforms to the preset ICMP payload content format according to the custom hook function.
[0106] In some embodiments, a preset ICMP payload content format includes: a magic number field and a forwarding destination IP address field arranged in sequence; wherein the magic number field is used to identify a custom protocol; the forwarding destination IP address field is used to identify information that needs to be forwarded to a new destination IP address, and when the ICMP payload content conforms to the ICMP payload content format, the destination IP address is modified.
[0107] In some embodiments, the ICMP payload content format further includes: setting a check code field after the forwarding destination IP address field; the check code field is used to verify the legitimacy of the custom protocol.
[0108] In some embodiments, the magic number field and the checksum field are also used to identify custom ICMP messages.
[0109] In some embodiments, the custom ICMP message includes: an ICMP header and ICMP payload content.
[0110] In some embodiments, if the ICMP payload content conforms to the ICMP payload content format, including: according to a custom hook function, if the magic field corresponding to the initial network message satisfies a preset magic value, then the initial network message conforms to the custom protocol, and if the corresponding value of the check code field satisfies the check code preset value, then the initial network message is a custom ICMP message; according to the custom hook function and based on the check code field, if the custom ICMP message meets the legality, then the ICMP payload content conforms to the ICMP payload content format.
[0111] In some embodiments, the ICMP payload content format also includes: setting a content length field after the magic number field and before forwarding the destination IP address; wherein the content length field is used to identify the length of the custom protocol; the length includes: the total length of the IP header, ICMP header and ICMP payload content format.
[0112] The destination address modification module 33 is used to extract the forwarding destination IP address from the ICMP payload content if the ICMP payload content conforms to the ICMP payload content format, and use the forwarding destination IP address to replace the destination IP address of the initial network message to obtain the first network message after the address is updated.
[0113] In some embodiments, after obtaining the first network message after the address is updated, it includes: calculating the verification result of the IP header according to the first network message, and updating the value corresponding to the verification code field according to the verification result, to obtain the second network message after the IP header verification code is updated; wherein, according to the destination IP address, the second network message is sent to the downstream device, so that after the downstream device receives the second network message, the legitimacy of the second network message is verified according to the value corresponding to the IP header verification code field.
[0114] In some embodiments, if the ICMP payload content does not conform to the ICMP payload content format, it includes: the external network performs a connectivity test on the router device through a Ping command.
[0115] The connectivity test module 34 is used to send the first network message to the downstream device according to the destination IP address, and perform a connectivity test from the external network to the downstream device in the internal network.
[0116] The present application receives the initial network message through the receiving module 31, and uses the load content format judgment module 32 to judge the IP header, ICMP header and ICMP load content of the received initial network message in turn to determine whether the initial network message complies with the custom protocol. If all of them comply, the destination address modification module 33 automatically replaces the destination IP address in the IP header with the forwarding destination IP address in the custom ICMP load content to obtain the first network message, and forwards the first network message to the corresponding downstream device through the connectivity test module 34, thereby eliminating the need for manual configuration of DMZ or DNAT, and enabling the external network to automatically test the connectivity of all downstream devices of the 5G router device in the internal network, thereby improving the efficiency of connectivity testing.
[0117] Example 4
[0118] An electronic device is provided in an embodiment of the present application, and the electronic device includes: at least one processor; and a memory connected to the at least one processor in communication; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the ICMP-based DNAT connectivity test method as described in any one of Embodiment 1 or Embodiment 2.
[0119] The present application integrates the ICMP-based DNAT connectivity test method into electronic devices, which can automatically and instantly test the connectivity from the internal network to the external network through any electronic device with gateway function, and can be compatible with more different types of electronic products, with higher adaptability and applicability.
[0120] Those skilled in the art will appreciate that the embodiments of the present application may also provide computer program products. Therefore, the present application may adopt the form of complete hardware embodiments, complete software embodiments, or embodiments in combination with software and hardware. Moreover, the present application may adopt the form of computer program products implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program codes.
[0121] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (apparatus), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These 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 device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0122] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0123] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0124] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the technical principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A DNAT connectivity test method based on ICMP, applied to router equipment, characterized in that: The DNAT connectivity testing method comprises: Receiving an initial network message sent by a network device on an external network; the initial network message is a message of a custom protocol, and the custom protocol includes: an IP header, an ICMP header, and a custom ICMP payload content arranged in sequence; If the initial network message satisfies both the protocol field of the IP header and the type field of the ICMP header, judging whether the ICMP payload content conforms to the preset ICMP payload content format according to the custom hook function; If the ICMP payload content conforms to the preset ICMP payload content format, extracting the forwarding destination IP address from the ICMP payload content, and using the forwarding destination IP address to replace the destination IP address carried in the IP header of the initial network message, to obtain a first network message after the address is updated; According to the destination IP address carried in the IP header of the first network message, the first network message is sent to the downstream device to perform a connectivity test from the external network to the downstream device in the internal network.
2. The ICMP-based DNAT connectivity testing method according to claim 1, characterized in that: The preset ICMP payload content format includes: a magic number field and a forwarding destination IP address field arranged in sequence; wherein, The magic number field is used to identify the custom protocol; The forwarding destination IP address field is used to identify the information that needs to be forwarded to a new destination IP address, and when the ICMP payload content conforms to the preset ICMP payload content format, the destination IP address is modified.
3. The ICMP-based DNAT connectivity testing method according to claim 2, characterized in that: The preset ICMP payload content format also includes: setting a check code field after the forwarding destination IP address field; the check code field is used to check the legitimacy of the custom protocol; the magic number field and the check code field are also used to identify a custom ICMP message; the custom ICMP message includes: the ICMP header and the ICMP payload content; wherein, judging whether the ICMP payload content conforms to the preset ICMP payload content format according to the custom hook function includes: According to the custom hook function, if the magic field corresponding to the initial network message satisfies the preset magic value, the initial network message complies with the custom protocol, and if the corresponding value of the check code field satisfies the preset check code value, the initial network message is the custom ICMP message; According to the custom hook function and based on the check code field, if the custom ICMP message meets the legality, the ICMP payload content conforms to the preset ICMP payload content format.
4. The ICMP-based DNAT connectivity testing method according to claim 2, wherein: The preset ICMP payload content format also includes: setting a content length field after the magic number field and before the forwarding destination IP address; wherein, The content length field is used to identify the length of the custom protocol; the length includes: the total length of the IP header, the ICMP header and the custom ICMP payload content.
5. The ICMP-based DNAT connectivity testing method according to claim 1, characterized in that: After obtaining the first network message after the address is updated, the method further comprises: According to the first network message, the verification result of the IP header is calculated, and according to the verification result, the value corresponding to the IP header verification code field is updated to obtain a second network message after the IP header verification code is updated; wherein, according to the destination IP address carried in the IP header of the second network message, the second network message is sent to the downstream device, so that after the downstream device receives the second network message, the legitimacy of the second network message is verified according to the value corresponding to the IP header verification code field.
6. The ICMP-based DNAT connectivity testing method according to claim 1, characterized in that: The determining, according to the custom hook function, whether the ICMP payload content conforms to a preset ICMP payload content format comprises: According to the custom hook function, determine whether the initial network message belongs to the IP address of the router device; If the initial network message belongs to the IP address of the router device, then judging whether the protocol field carried in the IP header of the initial network message is of ICMP type according to the custom hook function; If the protocol field carried by the IP header of the initial network message is of ICMP type, then according to the custom hook function, it is determined whether the type field is an echo request message; wherein, if the type field is an echo request message, then according to the custom hook function, it is determined whether the ICMP payload content conforms to the preset ICMP payload content format.
7. The ICMP-based DNAT connectivity testing method according to claim 1, characterized in that: If the ICMP payload content does not conform to the preset ICMP payload content format, the external network performs a connectivity test on the router device through a Ping command.
8. A DNAT connectivity test device based on ICMP, applied to router equipment, characterized in that: The DNAT connectivity test device comprises: a receiving module, a load content format determination module, a destination address modification module and a connectivity test module; wherein, The receiving module is used to receive an initial network message sent by a network device on an external network; the initial network message is a message of a custom protocol, and the custom protocol includes: an IP header, an ICMP header and a custom ICMP payload content arranged in sequence; The payload content format determination module is used to determine whether the ICMP payload content conforms to a preset ICMP payload content format according to a custom hook function if the initial network message satisfies both the protocol field of the IP header and the type field of the ICMP header; The destination address modification module is used to extract the forwarding destination IP address from the ICMP payload content if the ICMP payload content conforms to the preset ICMP payload content format, and use the forwarding destination IP address to replace the destination IP address carried in the IP header of the initial network message, so as to obtain a first network message after the address is updated; The connectivity test module is used to send the first network message to the downstream device according to the destination IP address carried in the IP header of the first network message, and perform a connectivity test from the external network to the downstream device in the internal network.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the ICMP-based DNAT connectivity testing method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Host IP address conversion method and device, computer equipment and storage medium
CN112272157A
Network connectivity performance judgment method based on ICMP protocol
CN113890838A
IP address converting apparatus
JP2004165823A
Data message processing method and system, message forwarding device
WO2013059991A1
Gateway device network connectivity response method and device
WO2017000790A1
