Port mapping method and device for network address translation and storage medium
By compressing node table entry data on IoT terminal devices and retaining only one port to store the current network address, the problem of insufficient memory during deployment of NAT64 conversion function is solved, and network address conversion efficiency and port mapping capabilities are improved.
Patent Information
- Application Number
- CN202411603300.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-11
- Publication Date
- 2025-02-25
AI Technical Summary
When deploying NAT64 conversion function, IoT terminal devices have insufficient memory due to excessive memory consumption, which seriously affects the conversion efficiency of network addresses.
By determining the network node of the terminal device under the current network and compressing the node table entry data, only one port is retained to store the current network address, reducing memory consumption.
It effectively reduces the memory consumption during network address conversion, improves the efficiency of network address conversion, and improves the port mapping capability of network nodes.
Smart Images

Figure CN119520471A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of smart home technology, and more specifically, to a port mapping method, device and storage medium for network address translation. Background Art
[0002] At present, with the increasing popularity of IPv6 networks, IPv6 network nodes can be deployed on IoT terminal devices. However, IoT terminal devices have the need to interact and communicate with traditional IPv4 networks. Therefore, when deploying IPv6 network nodes on IoT terminal devices, NAT64 conversion technology must also be deployed on IoT terminal devices. Among them, NAT64 conversion technology is a NAT (Net Address Translation) conversion technology that converts IPv6 network addresses into IPv4 network addresses.
[0003] Due to the high equipment cost of IoT terminal devices, the terminal nodes corresponding to IoT terminal devices use low-cost MCUs (Microcontroller Units) with limited resources as the communication main control units. After the necessary functions are deployed, the available memory of the resource-limited MCU is very limited. However, in the related art, the NAT64 port mapping method for NAT64 conversion requires a large amount of memory. Therefore, when the NAT64 conversion function is deployed on the above-mentioned resource-limited MCU chip, there is a problem of insufficient memory due to excessive memory consumption, which seriously affects the conversion efficiency of the network address.
[0004] In view of the technical problem of low efficiency of network address translation in related technologies, no effective solution has been proposed yet. Summary of the invention
[0005] The embodiments of the present application provide a port mapping method, device and storage medium for network address translation, so as to at least solve the technical problem of low efficiency of network address translation in the related art.
[0006] According to an embodiment of the present application, a port mapping method for network address translation is provided, including: determining a network node of a terminal device in a current network, wherein only one port of the network node stores the current network address of the network node; compressing node table item data of the network node to obtain target node table item data, wherein the node table item data at least includes session table item data of the network node, and the target node table item data at least includes compressed session table item data; determining a target session mapping relationship based on the compressed session table item data, and mapping the current node port of the network node from the current network to the target network based on the target session mapping relationship.
[0007] In an exemplary embodiment, after determining the network node of the terminal device in the current network, the method further includes: selecting any one port from multiple ports of the network node, retaining the current network address stored in the any one port, and deleting the current network addresses stored in other ports among the multiple ports except the any one port.
[0008] In an exemplary embodiment, the node table entry data also includes the node address data of the network node, and compression processing is performed on the node table entry data of the network node, including: processing the address prefix data of the node table entry data, wherein the processing of the address prefix data of the node table entry data includes: extracting all address prefixes from the node address data, and storing all the address prefixes in a prefix table; or, for multiple network nodes, storing the same address prefixes of the multiple network nodes in the prefix table.
[0009] In an exemplary embodiment, the node table entry data of the network node is compressed, including: compressing the node address data, including: obtaining the node physical address, the node prefix index and the aging counter data from the node address data; compressing the node physical address, the node prefix index and the aging counter data respectively to obtain compressed node address data, wherein the compressed node address data does not include an address prefix, and the data volume of the compressed node address data is less than the data volume of the node address data.
[0010] In an exemplary embodiment, compressing the node table entry data of the network node includes: compressing the session table entry data, including: determining that the current node port is mapped to the target node port of the target network based on the session table entry data; compressing the port data of the target node port to obtain compressed port data, wherein the compressed port data only includes the target node port offset, and the data volume of the compressed port data is less than the data volume of the port data.
[0011] In an exemplary embodiment, compressing the session table entry data further includes: determining a network protocol type field corresponding to the network session from the session table entry data; compressing the field length occupied by the network protocol type field to obtain a compressed network protocol type field, wherein the field length occupied by the compressed network protocol type field is smaller than the field length occupied by the network protocol type field.
[0012] In an exemplary embodiment, determining that the current node port is mapped to the target node port of the target network based on the session table entry data includes: determining the network address translation protocol type indicated by the compressed network protocol type field, wherein the network address translation protocol type is used to represent the network address translation protocol required for mapping the current network to the target network; determining that the current node port is mapped to the target node port of the target network based on the network address translation protocol type; determining the target session mapping relationship based on the compressed session table entry data includes: determining the target session mapping relationship based on the network session between the current node port and the target node port.
[0013] In an exemplary embodiment, the method further includes: sorting all ports of the network node according to the size of the port address to obtain sorted ports; and selecting a port from the sorted ports to store the current network address.
[0014] According to another aspect of an embodiment of the present application, a port mapping device for network address translation is also provided, including: a determination module, used to determine a network node of a terminal device in a current network, wherein only one port of the network node stores the current network address of the network node; an obtaining module, used to compress the node table item data of the network node to obtain target node table item data, wherein the node table item data at least includes session table item data of the network node, and the target node table item data at least includes compressed session table item data; a mapping module, used to determine a target session mapping relationship based on the compressed session table item data, and map the current node port of the network node from the current network to the target network based on the target session mapping relationship.
[0015] According to another aspect of the embodiments of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the above-mentioned port mapping method of network address translation when running.
[0016] According to another aspect of an embodiment of the present application, an electronic device is also provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the port mapping method of network address translation through the computer program.
[0017] According to another embodiment of the present application, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps in any of the above method embodiments are implemented.
[0018] In an embodiment of the present application, a network node of a terminal device in a current network is determined; node table item data of the network node is compressed to obtain target node table item data, wherein the node table item data at least includes session table item data of the network node, and the target node table item data at least includes compressed session table item data; a target session mapping relationship is determined according to the compressed session table item data, and the current node port of the network node is mapped from the current network to the target network according to the target session mapping relationship; a new port mapping method is proposed for the NAT64 conversion technology required when the terminal device converts from the current network (corresponding to the IPv6 network) to the target network (corresponding to the IPv4 network address), specifically, only one port is reserved in the network node to store the current network address, and the session table item data is compressed, so that the chip memory occupied during network address conversion can be reduced, which not only solves the technical problem of low network address conversion efficiency, improves the network address conversion efficiency, but also improves the port mapping capability of the network node. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0020] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0021] Figure 1 It is a hardware environment diagram of a port mapping method of network address translation in an embodiment of the present application;
[0022] Figure 2 is a flow chart of a port mapping method for network address translation according to an embodiment of the present application;
[0023] Figure 3 is a schematic diagram of address compression according to an embodiment of the present application (I);
[0024] Figure 4 is a schematic diagram of address compression according to an embodiment of the present application (II);
[0025] Figure 5 is a schematic diagram of address compression according to an embodiment of the present application (III);
[0026] Figure 6 is a schematic diagram of session entry data compression according to an embodiment of the present application (I);
[0027] Figure 7 is a schematic diagram of session entry data compression according to an embodiment of the present application (II);
[0028] Figure 8 is a schematic diagram of node table entry data compression according to an embodiment of the present application;
[0029] Fig. 9 It is a structural block diagram of a port mapping device for network address translation according to an embodiment of the present application. DETAILED DESCRIPTION
[0030] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings 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 should fall within the scope of protection of the present application.
[0031] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0032] According to one aspect of an embodiment of the present application, a network address translation port mapping method is provided. The network address translation port mapping method is widely used in smart home (Smart Home), smart home, smart home device ecology, smart residential (Intelligence House) ecology and other whole-house intelligent digital control application scenarios. Optionally, in this embodiment, the above-mentioned network address translation port mapping method can be applied to Figure 1 In the hardware environment composed of the terminal device 102 and the server 104 shown in FIG. Figure 1As shown, the server 104 is connected to the terminal device 102 via a network, and can be used to provide services (such as application services, etc.) for the terminal or a client installed on the terminal. A database can be set on the server or independently of the server to provide data storage services for the server 104. Cloud computing and / or edge computing services can be configured on the server or independently of the server to provide data computing services for the server 104.
[0033] The network may include but is not limited to at least one of the following: wired network, wireless network. The wired network may include but is not limited to at least one of the following: wide area network, metropolitan area network, local area network, and the wireless network may include but is not limited to at least one of the following: WIFI (Wireless Fidelity), Bluetooth. The terminal device 102 may be but is not limited to a PC, a mobile phone, a tablet computer, a smart air conditioner, a smart range hood, a smart refrigerator, a smart oven, a smart stove, a smart washing machine, a smart water heater, a smart washing device, a smart dishwasher, a smart projection device, a smart TV, a smart clothes drying rack, a smart curtain, a smart audio and video, a smart socket, a smart speaker, a smart fresh air device, a smart kitchen and bathroom device, a smart bathroom device, a smart sweeping robot, a smart window cleaning robot, a smart mopping robot, a smart air purification device, a smart steamer, a smart microwave oven, a smart kitchen treasure, a smart purifier, a smart water dispenser, a smart door lock, etc.
[0034] In this embodiment, a port mapping method of network address translation is provided, which is applied to the above terminal device. Figure 2 : is a flow chart of a port mapping method for network address translation according to an embodiment of the present application, and the flow includes the following steps:
[0035] Step S202, determining a network node of the terminal device in the current network, wherein only one port of the network node stores the current network address of the network node;
[0036] It should be noted that, in this embodiment, the current network represents an IPv6 network, the target network represents an IPv4 network, and the network address translation represents the translation from the IPv6 network to the IPv4 network.
[0037] In this embodiment, by reserving one port from multiple ports of a network node for storing the current network address of the network node, the memory storing the address of the network node can be compressed, thereby implementing a storage method in which the network node of each device stores only one IPv6 address.
[0038] Step S204, compressing the node table entry data of the network node to obtain target node table entry data, wherein the node table entry data at least includes the session table entry data of the network node, and the target node table entry data at least includes the compressed session table entry data;
[0039] Step S206: determining a target session mapping relationship according to the compressed session table entry data, and mapping the current node port of the network node from the current network to the target network according to the target session mapping relationship.
[0040] Through the above steps, the network node of the terminal device in the current network is determined; the node table item data of the network node is compressed to obtain the target node table item data, wherein the node table item data at least includes the session table item data of the network node, and the target node table item data at least includes the compressed session table item data; the target session mapping relationship is determined according to the compressed session table item data, and the current node port of the network node is mapped from the current network to the target network according to the target session mapping relationship; the NAT64 conversion technology required when the terminal device converts from the current network (corresponding to the IPv6 network) to the target network (corresponding to the IPv4 network address) proposes a new port mapping method, specifically, only one port is reserved in the network node to store the current network address, and the session table item data is compressed, so that the chip memory occupied during the network address conversion can be reduced, which not only solves the technical problem of low network address conversion efficiency, improves the network address conversion efficiency, but also improves the port mapping capability of the network node.
[0041] Exemplarily, a five-tuple mapping table can be used for the NAT64 port mapping method, wherein the five-tuple includes: the intranet IPv6 address (corresponding to the above-mentioned current network address), the intranet port number, the extranet IPv4 address (corresponding to the target network address), the extranet IPv4 port number, and the protocol type (corresponding to the network protocol type field). Among them, the intranet IPv6 address occupies 16 bytes. The intranet port number occupies 2 bytes. The extranet IPv4 address occupies 4 bytes. The extranet IPv4 port number occupies 2 bytes. The protocol type occupies 1 byte.
[0042] The C language structure is expressed as follows:
[0043]
[0044] Then, taking the memory consumption of a port mapping as an example, the above five-tuple consumes at least 16+2+4+2+1=25 bytes of memory. As the number of ports continues to increase, the memory consumption is also increasing. If 256 ports are mapped, the memory consumption will be greater than 6K bytes. If 1024 ports are mapped, the memory consumption is at least 25K bytes. In addition, in the actual implementation process, some necessary auxiliary information needs to be stored in the memory (for example, occupying 10K-30K bytes), which will cause the overall memory consumption to be higher than the above derived value. Therefore, the storage logic of the above NAT64 mapping method is complex, and a lot of common redundant data is stored, resulting in unnecessary memory consumption. As the number of mapped ports increases, the memory resources consumed will also increase.
[0045] In view of this, the present application optimizes the storage logic of the port mapping method, extracts redundant data, and compresses it to achieve the purpose of reducing memory consumption.
[0046] Specifically, for the intranet IPv6 address, considering that each intranet device only needs to store one IPv6 address to meet the requirements, there is no need to store the IPv6 address on each port of the device, and only one port needs to be reserved to store the complete IPv6 address. In addition, since the IPv6 address of each device has a common IPv6 prefix (corresponding to the address prefix data), the common IPv6 prefix can be regarded as redundant data, and only one complete IPv6 address is stored on one device, and it does not need to be stored on all intranet devices.
[0047] To further save memory, external IPv4 addresses can be omitted and no longer stored.
[0048] For the external network IPv4 port number, considering that the number of networks connected to IoT terminal devices during network conversion is small and the number of ports required to be mapped is not large, 6 BITS can be directly used to represent the range of 64 port numbers, compressing the original 2 bytes to 6 BITS. Among them, 6 BITs are usually used as bit fields (bit_field) in C language structures.
[0049] For the protocol type field, this application sets the IoT terminal device to use three protocols: TCP (Transmission Control Protocol), UDP (User Datagram Protocol) and PING, and uses 2 BITs to represent them. These 2 BITs and the 6 BITs occupied by the above external network IPv4 port form a complete byte to reduce memory usage.
[0050] Among them, TCP is a connection-oriented, reliable, byte-stream-based transport layer communication protocol. It ensures the reliability and order of data transmission in the network and is widely used in situations that require reliable transmission, such as Web browsing and file transfer. UDP is a connectionless transport layer protocol that allows data packets to be sent independently without guaranteeing the order, integrity or reliability of data packets. UDP is suitable for applications with high real-time requirements, such as video conferencing and online games. PING is a network management tool used to test the reachability and quality of network connections. It measures the round-trip time (RTT) and checks network delay or packet loss by sending ICMP (Internet Control Message Protocol) echo request messages to the target host and waiting for echo replies.
[0051] In an exemplary embodiment, the method further includes: sorting all ports of the network node according to the size of the port address to obtain sorted ports; and selecting a port from the sorted ports to store the current network address.
[0052] Optionally, in an exemplary embodiment, the multiple ports can be sorted according to port addresses to obtain a first port with the smallest address among the multiple ports, retain the current network address stored in the first port, and delete the current network addresses stored in the remaining ports among the multiple ports except the first port.
[0053] Optionally, in an exemplary embodiment, the multiple ports can be sorted according to port addresses to obtain a last port with the largest address among the multiple ports, retain the current network address stored in the last port, and delete the current network addresses stored in the remaining ports among the multiple ports except the last port.
[0054] Optionally, in an exemplary embodiment, the multiple ports can be sorted according to port priority to obtain the port with the lowest priority among the multiple ports, retain the current network address stored in the port with the lowest priority, and delete the current network addresses stored in the remaining ports among the multiple ports except the port with the lowest priority.
[0055] Optionally, in an exemplary embodiment, the multiple ports can be sorted according to port priority to obtain the port with the highest priority among the multiple ports, retain the current network address stored in the port with the highest priority, and delete the current network addresses stored in the remaining ports among the multiple ports except the port with the highest priority.
[0056] In an exemplary embodiment, after determining the network node of the terminal device in the current network, further, any one port can be selected from multiple ports of the network node, the current network address stored in the any one port can be retained, and the current network addresses stored in other ports of the multiple ports except the any one port can be deleted. This embodiment corresponds to the above-mentioned processing of the intranet IPv6 address, and only one IPv6 address is stored on one device by retaining only one network node in each device to store the current network address.
[0057] In one embodiment, Figure 3 As shown, the node table of the terminal device includes multiple nodes. Taking node 1 as an example, after expanding the node data of node 1, the node table item data obtained includes: node address data and session table. Multiple session table items can be stored in the session table, corresponding to multiple port mapping sessions of this node. This design forms a two-level nested storage and implicit index mechanism, which can save a node index field.
[0058] In an exemplary embodiment, the node table entry data also includes the node address data of the network node, and the process of compressing the node table entry data of the network node includes: processing the address prefix data of the node table entry data, wherein the processing of the address prefix data of the node table entry data includes: extracting all address prefixes from the node address data, and storing all address prefixes in a prefix table; or, for multiple network nodes, storing the same address prefixes of the multiple network nodes in the prefix table. In this embodiment, by storing the common address prefix in the prefix table, the IPV6 address is further compressed and stored, reducing the memory occupied by the network address, thereby saving more memory resources.
[0059] In one embodiment, Figure 4 As shown, all IPv6 prefixes (corresponding to prefix 1 to prefix n) can be extracted separately as a prefix table, and the same IPv6 prefixes of the nodes in the node table are stored in the prefix table. In this way, for the same IPv6 prefix, it only needs to be stored once, which greatly reduces the memory usage. Next, the node address data included in the node table entry data is split into three fields: node MAC address (corresponding to node physical address), node prefix index and TTL (Time ToLive, life cycle) aging counter.
[0060] Among them, the prefix index points to the position of the node corresponding to the prefix table, such as Figure 4 As shown, node 1, node 2, and node 3 all point to prefix 1 in the prefix table.
[0061] This embodiment corresponds to the compression processing process of the above-mentioned intranet IPv6 address. In this embodiment, the node MAC address only occupies 6 bytes, and the prefix index is compressed to 1 byte, plus the 1 byte occupied by the TTL aging counter, the node address data occupies a total of 8 bytes. Compared with the related art that requires 16 bytes to store the intranet IPv6 address, this embodiment saves 8 bytes when storing the intranet IPv6 address, reducing the memory consumption by half.
[0062] The node address data is represented by a C language structure as follows:
[0063]
[0064] Further, combined with Figure 5 This section describes the compressed storage process of IPv6 addresses. For example, there are three IPv6 addresses as follows:
[0065] FD01:0203:0405:00E0:A082:22FF:FE64:80F1 / 64.
[0066] FD01:0203:0405:00E0:A082:22FF:FE64:80F2 / 64.
[0067] FD01:0203:0405:00E0:A082:22FF:FE64:80F3 / 64.
[0068] Obviously, the above three nodes have a common 8-byte prefix "FD01:0203:0405:00E0", so this prefix is stored in the prefix table. The common two bytes 0xFF 0xFE in the last 8 bytes of the node IPv6 address are fixed bytes and do not need to be stored. Then after removing the common two bytes 0xFF 0xFE in the last 8 bytes, the remaining 6 bytes are the node's MAC address. The MAC addresses of the three nodes can be stored in the node table entry in sequence.
[0069] In an exemplary embodiment, a technical solution for compressing the node address data is also proposed, and the specific steps include: obtaining the node physical address, node prefix index and aging counter data from the node address data; compressing the node physical address, the node prefix index and the aging counter data respectively to obtain compressed node address data, wherein the compressed node address data does not include an address prefix, and the data volume of the compressed node address data is less than the data volume of the node address data. This embodiment can reduce the memory occupied by the network address and reduce the data conversion volume of the network address by compressing the node physical address, the node prefix index and the aging counter data respectively, thereby improving the conversion efficiency of the network address.
[0070] In an exemplary embodiment, the process of compressing the node table entry data of the network node also includes compressing the session table entry data, and the specific process is: determining the mapping of the current node port to the target node port of the target network according to the session table entry data; compressing the port data of the target node port to obtain compressed port data, wherein the compressed port data only includes the target node port offset, and the data volume of the compressed port data is less than the data volume of the port data. In this embodiment, by only compressing the target node port offset, the memory occupied by the port data can be reduced, and the memory consumption can be reduced.
[0071] In an exemplary embodiment, further, the session table entry data can be compressed by the following steps: determining the network protocol type field corresponding to the network session from the session table entry data; compressing the field length occupied by the network protocol type field to obtain a compressed network protocol type field, wherein the field length occupied by the compressed network protocol type field is less than the field length occupied by the network protocol type field. In this embodiment, by compressing the network protocol type field, the memory occupied by the network protocol type field can be reduced, thereby reducing memory consumption.
[0072] In an exemplary embodiment, the process of determining that the current node port is mapped to the target node port of the target network based on the session table entry data is further described, and the specific process includes: determining the network address translation protocol type indicated by the compressed network protocol type field, wherein the network address translation protocol type is used to indicate the network address translation protocol required for the current network to be mapped to the target network; determining that the current node port is mapped to the target node port of the target network based on the network address translation protocol type. Exemplarily, the network address translation protocol type is, for example, NAT64. When converting network addresses, the terminal device can also select a protocol from TCP, UDP and PING for data transmission. This embodiment can perform network address conversion based on the network address translation protocol type indicated by the compressed network protocol type field, while reducing the memory occupied by the network protocol type field, and also improving the success rate of network address conversion.
[0073] Furthermore, in this embodiment, the process of determining the target session mapping relationship according to the compressed session table entry data further includes: determining the target session mapping relationship based on the network session between the current node port and the target node port.
[0074] In one embodiment, in combination Figure 6 The process of compressing the fields in the session table entry is described below. Figure 6 As shown, the session table contains multiple sessions such as session_1, wherein each session has a corresponding session table entry (ie, session table entry data).
[0075] The field length in the session table entry only occupies 4 bytes after compression.
[0076] For the intranet IPv6 port, since this field must be stored completely and cannot be compressed, the original byte length of 2 bytes is maintained.
[0077] For the external network IPv4 port, only the port offset of the external network IPv4 port can be stored, so that after compression, only 6 BITS are occupied. Referring to the above compression processing process of the external network IPv4 port number, it can be understood that because the number of network connections of the Internet of Things terminal device will not be too many, the number of ports required to be mapped will usually not be greater than 64, and 6 BITS can be used to represent the range of 64 port numbers, so the external network IPv4 port number does not need to store the complete 2 bytes. Compared with the practice of using 2 bytes to store the external network IPv4 port in the related art, this embodiment only needs 6 BITs to store the port offset of the external network IPv4 port, reducing memory loss.
[0078] For the protocol type (network protocol type) field, it occupies 2 BITS after compression. Referring to the above compression process of the protocol type field, it is sufficient to use TCP, UDP, and PING protocols in the Internet of Things terminal equipment, and 2 BITs can be used to represent the three protocols. The above-mentioned external network IPv4 port only occupies 6 BITs in a complete byte, and the remaining 2 BITs are reserved for the protocol type field. In this way, there is no need to store 1 byte in the protocol type field. Compared with the practice in the related art that requires 1 byte to store the external network IPv4 port, this embodiment only requires 2 BITs to store the protocol type field, and the above-mentioned external network IPv4 port occupies a complete byte together, so that the 3 bytes occupied by the external network port number and the protocol type field are compressed to 1 byte, which greatly reduces memory consumption.
[0079] Finally, adding the 1 byte occupied by the aging counter field, the session entry data occupies a total of 4 bytes. It can be seen that this embodiment optimizes the memory space by compressing the field length.
[0080] The above fields are represented by C language structure bit fields as follows:
[0081]
[0082] Further, in one embodiment, if Figure 7 As shown, the three nodes establish two TCP connections through NAT64, and the IPv6 port numbers are 55057 and 55058 respectively.
[0083] After the above compression steps, the following content can be expressed using C language structure:
[0084]
[0085]
[0086]
[0087] In order to better understand the process of the port mapping method of the above-mentioned network address translation, the implementation method flow of the port mapping of the above-mentioned network address translation is described below in combination with an optional embodiment, but it is not used to limit the technical solution of the embodiment of the present application.
[0088] In this embodiment, combined Figure 8 Provides a port mapping method for network address translation, such as Figure 8As shown, the node table entry data of each node in the node table includes node address data and multiple session table entries. The same prefix of the nodes in the node table entry data is extracted and stored separately as a prefix table, so that the node address data including the MAC address and prefix index of the node only occupies 8 bytes after compression. Among them, the field of each session table entry only occupies 4 bytes after compression.
[0089] The complete NAT64 mapping table above is expressed in C language as follows:
[0090] / / The complete nat64 mapping table includes: node tables node_list of multiple nodes, and a two-level nested storage structure of session_list nested in each node;
[0091]
[0092]
[0093] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods of each embodiment of the present application.
[0094] Fig. 9 is a structural block diagram of a port mapping device for network address translation according to an embodiment of the present application; Fig. 9 As shown, including:
[0095] A determination module 92, configured to determine a network node of the terminal device in the current network, wherein only one port of the network node stores the current network address of the network node;
[0096] An obtaining module 94 is used to compress the node table entry data of the network node to obtain the target node table entry data, wherein the node table entry data at least includes the session table entry data of the network node, and the target node table entry data at least includes the compressed session table entry data;
[0097] The mapping module 96 is used to determine a target session mapping relationship according to the compressed session table entry data, and map the current node port of the network node from the current network to the target network according to the target session mapping relationship.
[0098] Through the above-mentioned device, by determining the network node of the terminal device in the current network; compressing the node table item data of the network node to obtain the target node table item data, wherein the node table item data at least includes the session table item data of the network node, and the target node table item data at least includes the compressed session table item data; determining the target session mapping relationship according to the compressed session table item data, and mapping the current node port of the network node from the current network to the target network according to the target session mapping relationship; the NAT64 conversion technology required when the terminal device converts from the current network (corresponding to the IPv6 network) to the target network (corresponding to the IPv4 network address) proposes a new port mapping method, specifically, only retaining one port in the network node to store the current network address, and compressing the session table item data, so that the chip memory occupied during network address conversion can be reduced, which not only solves the technical problem of low network address conversion efficiency, improves the network address conversion efficiency, but also improves the port mapping capability of the network node.
[0099] In an exemplary embodiment, the determination module 92 is also used to: after determining the network node of the terminal device in the current network, further, select any one port from multiple ports of the network node, retain the current network address stored in the any one port, and delete the current network addresses stored in other ports among the multiple ports except the any one port.
[0100] In an exemplary embodiment, the node table entry data also includes the node address data of the network node, and module 94 is obtained, which is also used to: process the address prefix data of the node table entry data, wherein the processing of the address prefix data of the node table entry data includes: extracting all address prefixes from the node address data, and storing all address prefixes in a prefix table; or, for multiple network nodes, storing the same address prefixes of the multiple network nodes in the prefix table.
[0101] In an exemplary embodiment, module 94 is obtained and is also used to: obtain a node physical address, a node prefix index and an aging counter data from the node address data; and compress the node physical address, the node prefix index and the aging counter data respectively to obtain compressed node address data, wherein the compressed node address data does not include an address prefix, and the amount of data of the compressed node address data is less than the amount of data of the node address data.
[0102] In an exemplary embodiment, module 94 is obtained and is also used to: compress the session table entry data, and the specific process is: determine the mapping of the current node port to the target node port of the target network based on the session table entry data; compress the port data of the target node port to obtain compressed port data, wherein the compressed port data only includes the target node port offset, and the data volume of the compressed port data is less than the data volume of the port data.
[0103] In an exemplary embodiment, further, module 94 is obtained, and is also used to compress the session table entry data through the following steps: determining the network protocol type field corresponding to the network session from the session table entry data; compressing the field length occupied by the network protocol type field to obtain a compressed network protocol type field, wherein the field length occupied by the compressed network protocol type field is smaller than the field length occupied by the network protocol type field.
[0104] In an exemplary embodiment, module 94 is obtained and is also used to: determine the network address translation protocol type indicated by the compressed network protocol type field, wherein the network address translation protocol type is used to represent the network address translation protocol required for mapping the current network to the target network; determine the mapping of the current node port to the target node port of the target network based on the network address translation protocol type.
[0105] Furthermore, the mapping module is further used to: determine the target session mapping relationship based on the network session between the current node port and the target node port.
[0106] In an exemplary embodiment, the determination module 92 is further configured to: sort all ports of the network node according to the size of the port address to obtain sorted ports; and select one port from the sorted ports to store the current network address.
[0107] An embodiment of the present application further provides a storage medium, which includes a stored program, wherein the program executes any of the above methods when it is run.
[0108] Optionally, in this embodiment, the storage medium may be configured to store program codes for executing the following steps:
[0109] S1, determining a network node of the terminal device in the current network, wherein only one port of the network node stores the current network address of the network node;
[0110] S2, compressing the node table entry data of the network node to obtain target node table entry data, wherein the node table entry data at least includes the session table entry data of the network node, and the target node table entry data at least includes the compressed session table entry data;
[0111] S3, determining a target session mapping relationship according to the compressed session table entry data, and mapping a current node port of the network node from the current network to a target network according to the target session mapping relationship.
[0112] An embodiment of the present application further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0113] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0114] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:
[0115] S1, determining a network node of the terminal device in the current network, wherein only one port of the network node stores the current network address of the network node;
[0116] S2, compressing the node table entry data of the network node to obtain target node table entry data, wherein the node table entry data at least includes the session table entry data of the network node, and the target node table entry data at least includes the compressed session table entry data;
[0117] S3, determining a target session mapping relationship according to the compressed session table entry data, and mapping a current node port of the network node from the current network to a target network according to the target session mapping relationship.
[0118] Optionally, in this embodiment, the above-mentioned storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store program codes.
[0119] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.
[0120] Obviously, those skilled in the art should understand that the above modules or steps of the present application can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, and optionally, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present application is not limited to any specific combination of hardware and software.
[0121] 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 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 port mapping method for network address translation, characterized in that: include: Determine a network node of the terminal device in the current network, wherein only one port of the network node stores the current network address of the network node; Compressing the node table entry data of the network node to obtain target node table entry data, wherein the node table entry data at least includes the session table entry data of the network node, and the target node table entry data at least includes the compressed session table entry data; A target session mapping relationship is determined according to the compressed session table entry data, and a current node port of the network node is mapped from the current network to a target network according to the target session mapping relationship.
2. The port mapping method of network address translation according to claim 1, characterized in that: After determining the network node of the terminal device in the current network, the method further includes: An arbitrary port is selected from the plurality of ports of the network node, a current network address stored in the arbitrary port is retained, and the current network addresses stored in the plurality of ports except the arbitrary port are deleted.
3. The port mapping method of network address translation according to claim 1, characterized in that: The node table entry data also includes node address data of the network node, and compressing the node table entry data of the network node includes: Processing the address prefix data of the node table entry data, wherein the processing of the address prefix data of the node table entry data includes: Extract all address prefixes from the node address data, and store all address prefixes in a prefix table; Alternatively, for a plurality of network nodes, the same address prefixes of the plurality of network nodes are stored in the prefix table.
4. The port mapping method of network address translation according to claim 3, characterized in that: The node table entry data of the network node is compressed, including: The node address data is compressed, including: Obtaining a node physical address, a node prefix index and aging counter data from the node address data; The node physical address, the node prefix index and the aging counter data are compressed respectively to obtain compressed node address data, wherein the compressed node address data does not include an address prefix and the data volume of the compressed node address data is smaller than the data volume of the node address data.
5. The port mapping method of network address translation according to claim 1, characterized in that: The node table entry data of the network node is compressed, including: The session entry data is compressed, including: Determine, according to the session table entry data, that the current node port is mapped to a target node port of the target network; The port data of the target node port is compressed to obtain compressed port data, wherein the compressed port data only includes the target node port offset, and the data volume of the compressed port data is smaller than the data volume of the port data.
6. The port mapping method of network address translation according to claim 5, characterized in that: The step of compressing the session entry data further includes: Determine a network protocol type field corresponding to the network session from the session table entry data; The field length occupied by the network protocol type field is compressed to obtain a compressed network protocol type field, wherein the field length occupied by the compressed network protocol type field is smaller than the field length occupied by the network protocol type field.
7. The port mapping method of network address translation according to claim 6, characterized in that: Determining, according to the session entry data, that the current node port is mapped to a target node port of the target network includes: Determine the network address translation protocol type indicated by the compressed network protocol type field, wherein the network address translation protocol type is used to indicate the network address translation protocol required for mapping the current network to the target network; determine the mapping of the current node port to the target node port of the target network according to the network address translation protocol type; The determining the target session mapping relationship according to the compressed session table entry data includes: determining the target session mapping relationship based on a network session between the current node port and the target node port.
8. The port mapping method of network address translation according to claim 1, characterized in that: The method further comprises: Sorting all ports of the network node according to the size of the port address to obtain sorted ports; A port is selected from the sorted ports to store the current network address.
9. A port mapping device for network address translation, characterized in that: include: A determination module, used to determine a network node of the terminal device in the current network, wherein only one port of the network node stores the current network address of the network node; an obtaining module, configured to compress the node table entry data of the network node to obtain the target node table entry data, wherein the node table entry data at least includes the session table entry data of the network node, and the target node table entry data at least includes the compressed session table entry data; A mapping module is used to determine a target session mapping relationship according to the compressed session table entry data, and map the current node port of the network node from the current network to the target network according to the target session mapping relationship.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein the program executes the method described in any one of claims 1 to 8 when executed.