Method, device, cloud gateway device and medium for providing automatic port mapping service
By installing a virtual network port device in a cloud gateway device and using its protocol stack to resolve and encapsulate packets, the problem that cloud gateway devices cannot effectively implement the UPnP protocol automatic port mapping service, and the automatic port mapping service of the UPnP protocol is provided on a cloud gateway device that transmits messages through transit.
Patent Information
- Application Number
- CN202211719911.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-30
- Publication Date
- 2025-03-28
- Estimated Expiration
- 2042-12-30
AI Technical Summary
When existing cloud gateway devices provide automatic port mapping services for UPnP protocol, they lack a mature Linux kernel protocol stack, which makes it impossible to effectively implement TCP/IP protocol interaction, affecting the functions of automatic port mapping services.
Install a virtual network port device in a cloud gateway device, and write HTTP request messages to the virtual network port device through a universal plug-and-play module, using its protocol stack to parse and encapsulate messages, thereby realizing the automatic port mapping service of the UPnP protocol.
Without using the mature Linux kernel protocol stack, the automatic port mapping service of the UPnP protocol on cloud gateway devices is implemented, which improves the device's ability to provide services on terminals within the LAN.
Smart Images

Figure CN115987937B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a method, apparatus, cloud gateway device and computer-readable storage medium for providing automatic port mapping services. Background Art
[0002] Due to the shortage of public IP addresses in the IPV4 network environment, private network addresses are introduced and network address translation (NAT) is performed through the gateway to access the public network. However, private network addresses are not unique and are not recognized by the outside world, and the private network addresses in different LANs can be the same, which results in the public network devices being unable to actively access the services provided by private network devices; port mapping is to map a port of a host in the intranet to a port of an external host to provide corresponding services. When a user accesses this port of the external host, the server automatically maps the request to the machine in the corresponding LAN.
[0003] Port mapping is divided into dynamic port mapping and static port mapping. Static port mapping is to open a fixed port on the gateway, and then set the IP and port of the host in the intranet to which the data received by this port will be forwarded. This mapping relationship will always exist regardless of whether there is a connection or not, so that the public network device can actively access a terminal in the intranet. Dynamic port mapping does not require the configuration of a fixed port, and the terminal can spontaneously use an unused port to establish a mapping relationship in the gateway.
[0004] The Universal Plug and Play (UPnP) protocol specification is based on the TCP / IP protocol and a set of network protocols developed for communication between devices. There are protocols that support port mapping in the protocol family, which can be applied to dynamic port mapping to achieve automatic port mapping. When the intranet terminal uses the UPnP protocol to perform dynamic port mapping, the gateway needs to have a protocol interaction function, which is equivalent to the gateway playing the role of a server to implement the interactive part of the UPnP protocol involving port mapping. Only in this way can the intranet terminal apply for port mapping and complete automatic port mapping.
[0005] The cloud gateway software in the current popular cloud gateway devices runs in containers. The data transmission and reception performance of the underlying cloud gateway device is the most critical for the entire cloud gateway device. Therefore, the current cloud gateway devices do not use the mature Linux kernel protocol stack. Some cloud gateway device manufacturers bypass the kernel protocol stack to achieve fast message transmission and reception, which is equivalent to the cloud gateway device being an intermediate device. The message is transmitted through transparent transmission, achieving the purpose of fast message transmission and reception. The disadvantage brought by this is that the gateway cannot use the existing mature kernel protocol stack to provide services for the terminals in the LAN.
[0006] The automatic port mapping part of the UPnP protocol is based on the TCP / IP protocol. However, the cloud gateway device does not use the mature Linux kernel protocol stack to provide services, that is, it cannot use the TCP / IP protocol in the mature Linux kernel protocol stack. Therefore, how to provide the automatic port mapping service of the UPnP protocol on the cloud gateway device that implements transparent transmission of messages is a technical problem that needs to be solved. Summary of the invention
[0007] The embodiments of the present application provide a method, an apparatus, a cloud gateway device, and a computer-readable storage medium for providing an automatic port mapping service, which can provide an automatic port mapping service of the UPnP protocol on a cloud gateway device that implements transparent transmission of messages.
[0008] The present application embodiment provides a method for providing an automatic port mapping service, which is applied to a cloud gateway device, wherein the cloud gateway device includes a virtual network port device, and the method includes:
[0009] When the cloud gateway device receives an HTTP request message for requesting automatic port mapping service from a terminal in the local area network, the HTTP request message is written to the virtual network port device through the universal plug and play module, so as to use the protocol stack of the virtual network port device to parse the HTTP request message to obtain the request information of the terminal requesting automatic port mapping service;
[0010] Reading the request information from the virtual network port device through the universal plug and play module, and responding to the request information using the automatic port mapping service to determine the service port number of the automatic port mapping service;
[0011] Writing the service port number into the virtual network port device through the universal plug and play module, so as to encapsulate the service port number using the protocol stack of the virtual network port device to generate a network layer response message in response to the HTTP request message;
[0012] The network layer response message is read from the virtual network port device through the universal plug and play module, and the network layer response message is sent to the terminal to respond to the HTTP request message.
[0013] At the same time, an embodiment of the present application also provides a device for providing automatic port mapping services, which is applied to a cloud gateway device, wherein the cloud gateway device includes a virtual network port device, and the device includes:
[0014] A receiving module, used for receiving an HTTP request message for requesting automatic port mapping service from a terminal in a local area network;
[0015] A writing module, used for writing the HTTP request message to the virtual network port device through the universal plug and play module when the cloud gateway device receives an HTTP request message for requesting automatic port mapping service from a terminal in the local area network;
[0016] A network port parsing module, used to parse the HTTP request message using the protocol stack of the virtual network port device to obtain the request information of the terminal requesting the automatic port mapping service;
[0017] a reading module, configured to read the request information from the virtual network port device through the universal plug and play module,
[0018] A response module, used for responding to the request information to determine the service port number of the automatic port mapping service;
[0019] The writing module is further used to write the service port number into the virtual network port device through the universal plug and play module;
[0020] A network port encapsulation module, used to encapsulate the service port number using the protocol stack of the virtual network port device to generate a network layer response message in response to the HTTP request message;
[0021] The reading module is further used to read the network layer response message from the virtual network port device through the universal plug and play module;
[0022] A sending module is used to send the network layer response message to the terminal in response to the HTTP request message.
[0023] At the same time, an embodiment of the present application also provides a cloud gateway device, which includes one or more processors; a memory; and one or more computer programs, wherein the processor and the memory are connected, and the one or more computer programs are stored in the memory and configured to be executed by the processor.
[0024] At the same time, an embodiment of the present application provides a computer-readable storage medium, in which a plurality of instructions are stored, and the instructions are used to load a processor to execute the steps in the above method.
[0025] The embodiment of the present application provides a method, apparatus, cloud gateway device and computer-readable storage medium for providing automatic port mapping service. A virtual network port device is pre-installed in the cloud gateway device. When the cloud gateway device receives an HTTP request message for requesting automatic port mapping service from a terminal in a local area network, the HTTP request message is written to the virtual network port device through a universal plug and play module, so as to use the protocol stack of the virtual network port device to parse the HTTP request message to obtain request information for requesting automatic port mapping service, read the request information from the virtual network port device through the universal plug and play module, and respond to the request information to determine the service port number of the automatic port mapping service, write the service port number to the virtual network port device through the universal plug and play module, so as to use the protocol stack of the virtual network port device to encapsulate the service port number to generate a network layer response message in response to the HTTP request message, and send the response layer message to the terminal to respond to the HTTP request message. In the embodiment of the present application, the protocol stack function of the virtual network port device is used to parse the HTTP request message and encapsulate the response message, so as to provide the automatic port mapping service of the universal plug and play protocol on the cloud gateway device that transmits the message in a transparent transmission manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] The technical solution and other beneficial effects of the present application will be made apparent by describing in detail the specific implementation methods of the present application in conjunction with the accompanying drawings.
[0027] Figure 1 A schematic diagram of an application scenario provided for an embodiment of the present application.
[0028] Figure 2 A flowchart of the discovery phase in the method for providing automatic port mapping service provided in an embodiment of the present application.
[0029] Figure 3 A schematic diagram of a process of establishing a connection with a terminal in a method for providing an automatic port mapping service provided in an embodiment of the present application.
[0030] Figure 4 A flowchart of a method for providing automatic port mapping service provided in an embodiment of the present application.
[0031] Figure 5 A flowchart of a method for providing automatic port mapping service provided in an embodiment of the present application.
[0032] Figure 6 A schematic diagram of the structure of an apparatus for providing automatic port mapping service provided in an embodiment of the present application.
[0033] Figure 7 A schematic diagram of the structure of a cloud gateway device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0034] The technical solutions in the embodiments of the present application will be described clearly and completely 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, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present application.
[0035] The embodiments of the present application provide a method, an apparatus, a cloud gateway device, and a computer-readable storage medium for providing an automatic port mapping service. Any of the methods and apparatuses for providing an automatic port mapping service provided by the embodiments of the present application can be integrated in a cloud gateway device.
[0036] The local area network in the embodiment of the present application may be a local area network corresponding to multiple different home broadband accounts. Each home broadband account generally connects to at least one terminal, such as multiple terminals, which constitute a local area network. Different home broadband accounts constitute multiple local area networks. The network segments of the terminals in the multiple local area networks may be configured as private network segments. The private IP addresses of different terminals in different local area networks may be the same or different.
[0037] Among them, terminals include but are not limited to smart phones, tablet computers, laptops, touch screens, game consoles, personal computers (PCs), smart robots, smart home devices, smart wearable devices and other terminal devices.
[0038] The cloud gateway device in this application is different from traditional home gateway devices such as optical modems, routers, etc. The firmware in traditional home gateway devices is generally developed and applied based on the Linux system. Such gateway devices integrate the Linux kernel protocol stack and support most common protocols. Developers do not need to implement a certain type of protocol separately, allowing developers to focus on their own application areas.
[0039] The currently popular cloud gateway devices, which are used in the edge node servers of operators, can basically realize the functions of traditional gateways and bring more scalability on this basis. The data transmission and reception performance of the underlying cloud gateway device is the most critical of the entire cloud gateway device. If the mature Linux kernel protocol stack is directly used, the message parsing and copying from kernel state to user state will greatly affect the parsing efficiency of the protocol. Therefore, some manufacturers have adopted the Data Plane Development Kit (DPDK) method. The DPDK method can bypass the kernel protocol stack to achieve fast message transmission and reception, but this method is equivalent to the cloud gateway device being an intermediate device, and the message is transmitted through the transparent transmission method, thereby achieving the purpose of fast message transmission and reception. The disadvantage brought by this is that the cloud gateway device cannot use the existing mature Linux kernel protocol stack to provide services for terminals in the LAN.
[0040] If the automatic port mapping part is implemented based on the existing UPnP protocol (Universal Plug and Play protocol), the automatic port mapping part in the UPnP protocol involves the interaction of HTTP messages, which needs to be based on the TCP / IP protocol. The cloud gateway software running in the docker container does not have the ability to interact with the TCP / IP protocol, that is, it cannot use the TCP / IP protocol in the mature Linux kernel protocol stack. If the interaction and status maintenance of each stage of the TCP / IP protocol are implemented in order to implement the automatic port mapping in the UPnP protocol, it is obviously not achievable in a short time, and even if it is implemented, it is difficult to reach the level of a mature kernel protocol stack.
[0041] In order to provide an automatic port mapping service of the UPnP protocol on a cloud gateway device that implements transparent transmission of messages, the embodiments of the present application provide a method, an apparatus, a cloud gateway device and a computer-readable storage medium for providing an automatic port mapping service, which will be introduced below. It should be noted that the order in which the following embodiments are described does not constitute a limitation on the importance of the embodiments.
[0042] like Figure 1 As shown, it is a schematic diagram of the application scenario provided by this embodiment of the present application. In this application scenario, a cloud gateway device (which may be referred to as a cloud gateway) is included, and a plurality of home broadband accounts are stored in the cloud gateway device, and the home broadband accounts may also be referred to as home broadband accounts, such as account1, account2, ..., accountN.
[0043] The cloud gateway device also includes a physical network port, which is driven by DPDK to read the message received from the physical network port, so the cloud gateway device can bypass the Liunx kernel protocol stack and transmit the message in a transparent manner. It should be noted that the cloud gateway device in this application provides automatic port mapping service based on this premise.
[0044] The cloud gateway device also includes a virtual network card device, which is installed in the cloud gateway device. It should be noted that the virtual network card device is not installed in a container, but in the physical device where the cloud gateway device is located. For example, when the cloud gateway device is started, a virtual network port device can be created, and the network parameters of the virtual network port device similar to those of an ordinary real network port can be set, such as setting IP address, subnet mask, routing and other information. Among them, the virtual network port device is a virtual TUN port device.
[0045] Among them, the part corresponding to the UPnP protocol in the cloud gateway device can also be called a UPnP module (Universal Plug and Play module). The UPnP module is installed in a container in the cloud gateway device and provides corresponding services through the automatic port mapping service in the UPnP module.
[0046] In this application scenario, it also includes at least one local area network corresponding to a home broadband account, such as Figure 1 Account1 corresponds to LAN1, account2 corresponds to LAN2, account3 corresponds to LAN3, and so on. Each local area network includes at least one terminal device, such as LAN1 includes terminal 1 (192.168.2.2) and terminal 2 (192.168.2.3), LAN2 includes terminal 1 (192.168.2.2) and terminal 2 (192.168.2.4), and LAN3 includes terminal 1 (192.168.2.3) and terminal 2 (192.168.2.5).
[0047] In this application scenario, intermediate network devices are also included. The intermediate network devices may be optical line terminals (OLT, terminal devices for connecting optical fiber trunks), optical network units (ONU), switches, etc. For example, a terminal in a local area network corresponding to a home-wide account sends a request message for the automatic port mapping service in the UPnP module in the cloud gateway device to the cloud gateway device through the intermediate network device. The cloud gateway device responds to the request message, obtains a response message, and sends the response message to the terminal in the local area network corresponding to the home-wide account through the intermediate network device.
[0048] The specific scheme in the embodiment of the present application will be described in detail below based on the application scenario.
[0049] The entire process of the automatic port mapping service provided by the UPnP module is divided into a discovery phase and a control phase. The discovery phase uses User Datagram Protocol (UDP) messages, i.e., UDP messages, to interact, and does not require special processing by the virtual network port device, because UDP messages do not need to be implemented based on the TCP protocol.
[0050] After the terminals in the local area network corresponding to different home broadband accounts enable the UPnP protocol function, they will automatically multicast and send UPnP discovery messages in UDP message format. In one embodiment, the process of the discovery phase can be as follows Figure 2 As shown, the following steps are included.
[0051] 101. When the physical interface of the cloud gateway device receives a UPnP discovery message from a terminal in the local area network corresponding to the home broadband account, a destination port number is determined from the idle ports of the cloud gateway device.
[0052] Among them, after the physical network port of the cloud gateway device receives the hardware layer discovery message sent by the terminal, the DPDK driver is used to read the hardware layer discovery message of the physical network port, and the hardware layer discovery message is submitted to the cloud gateway process. The cloud gateway process calls the protocol parser to parse the hardware layer discovery message. For example, the hardware layer discovery message is parsed into a link layer discovery message, and then into a UDP message, etc. When the parsed message is a UDP message and the destination port is the well-known port 1900, it is determined that the corresponding message is a UPnP discovery message, and the UPnP discovery message is sent to the UPnP module for processing.
[0053] When the UPnP module receives the UPnP discovery message, it determines a port number from the available free ports of the cloud gateway device, uses the port number as the destination port number, and allocates the destination port number to the automatic port mapping service of the home broadband account. It should be noted that the purpose of the destination port number is to distinguish different home broadband accounts under the automatic port mapping service, which is different from the role of the general port number. The general port number is used to connect to the service in the server or to distinguish different services in the server.
[0054] Since the port number is determined from the available idle ports of the cloud gateway device, for the automatic port mapping service, the destination port number corresponding to each different home broadband account is different.
[0055] 102, allocate a destination port number for the automatic port mapping service of the home broadband account, save the relationship between the destination port number and the home broadband account in the cloud gateway device, and monitor the destination port number.
[0056] When the cloud gateway device receives the UPnP discovery message corresponding to each different home broadband account, a destination port number is assigned to each different home broadband account corresponding to the automatic port mapping service, and the relationship between the destination port number and the home broadband account is stored in the cloud gateway device. Figure 1 As shown in the figure, the destination port numbers allocated to different home broadband accounts account1, account2 and account3 are port1, port2 and port3.
[0057] In addition, it is necessary to monitor each different destination port number. The UPnP module of the cloud gateway device monitors the destination port number assigned to each different home broadband account.
[0058] 103, sending the destination port number to the terminal corresponding to the home broadband account.
[0059] After the UPnP module of the cloud gateway device allocates a destination port number for the home broadband account, it sends the destination port number to the terminal, and receives TCP connections initiated by terminals in different home broadband accounts based on the destination port number to realize message interaction in the control phase.
[0060] In the control stage, a TCP connection with the terminal is first established. Since the automatic port mapping service of the UPnP module is based on the HTTP protocol, a TCP connection with the terminal needs to be established. On the basis of the TCP protocol, the automatic port mapping service based on the HTTP protocol is implemented.
[0061] In one embodiment, when the cloud gateway device receives a connection request message for the automatic port mapping service of the UPnP module sent from a terminal in the local area network corresponding to the home broadband account, the connection request message is written to the virtual network port device through the UPnP module, and a connection with the terminal is established through the protocol stack of the virtual network port device. The connection request message includes the destination port number allocated for the automatic port mapping service of the home broadband account.
[0062] like Figure 4 As shown, the file descriptor of the destination port number can be represented by sock_fd, where, because it is based on the Linux system, all files, ports, etc. are regarded as files and represented by file descriptors. Listen (sock_fd) means listening to the destination port number allocated for the home broadband account.
[0063] In one embodiment, if Figure 3 As shown, the above steps of establishing a connection with the terminal include the following steps, which can be specifically combined with Figure 4 See the flowchart shown for understanding.
[0064] 201. When the cloud gateway device receives a connection request message for the automatic port mapping service of the UPnP module sent from a terminal in the local area network corresponding to the home broadband account, the cloud gateway device uses the UPnP module to write the connection request message to the loopback interface of the virtual network port device.
[0065] Among them, when the physical network port of the cloud gateway device receives a hardware layer connection message sent by a terminal in the local area network corresponding to the home broadband account, the DPDK driver is used to read the hardware layer connection message of the physical network port, and the hardware layer connection message is submitted to the cloud gateway process. The cloud gateway process calls the protocol parser to parse the hardware layer connection message, for example, the hardware layer message is parsed into a link layer message, and then parsed into a network layer connection message, etc. When the destination port of the parsed connection message is the pre-assigned destination port number monitored, and the protocol involved is the TCP protocol, it is determined to be a connection request message (SYN message) for the automatic port mapping service of the UPnP module.
[0066] Submit the connection request message (SYN message) to the UPnP module, such as Figure 4 As shown, the UPnP module is used to write the connection request message to the loopback interface of the virtual network port device. Specifically, write(lo_fd) is called to write the connection request message to the loopback interface of the virtual network port device. Wherein lo_fd is the file descriptor of the loopback interface (loopback).
[0067] 202 : Utilize the protocol stack of the virtual network port device to respond to the connection request message to generate a connection confirmation message.
[0068] The virtual network port device is a virtual TUN port device, and the virtual TUN port device works at the third layer, namely, the network layer. Therefore, the protocol stack of the virtual network port device can respond to messages of the network layer, the transport layer, the application layer, and the like.
[0069] Since the connection request message requests a TCP connection, it corresponds to a TCP message. The protocol stack of the virtual network port device is used to parse the connection request message and respond to the connection request message to generate a connection confirmation message, which is a SYN-ACK message. Figure 4 shown.
[0070] 203, using the UPnP module to read the connection confirmation message from the loopback interface, and sending the connection confirmation message to the terminal.
[0071] The UPnP module calls the read(lo_fd) function to read the SYN-ACK message from the loopback interface, such as Figure 4After the UPnP module reads the connection confirmation message, it hands the connection confirmation message to the cloud gateway process, which encapsulates the network layer connection confirmation message corresponding to the connection confirmation message to encapsulate it into a link layer connection confirmation message, and then encapsulates the link layer connection confirmation message to obtain a hardware layer connection confirmation message, and sends the hardware layer connection confirmation message from the physical network port to the terminal.
[0072] 204. When the UPnP module receives the confirmation message of the terminal to the connection confirmation message, the UPnP module writes the confirmation message to the loopback interface of the virtual network port device.
[0073] After receiving the hardware layer connection confirmation message, the terminal encapsulates the hardware layer connection confirmation message layer by layer to obtain a connection confirmation message, and generates a confirmation message in response to the connection confirmation message. The confirmation message is an ACK message, such as Figure 4 As shown, the confirmation message is encapsulated as a hardware layer confirmation message and sent to the cloud gateway device. The destination port in the confirmation message is the pre-allocated destination port number monitored.
[0074] After the physical network port of the cloud gateway device receives the hardware layer confirmation message, it is handed over to the cloud gateway process for parsing and processing to obtain the network layer confirmation message. The destination port of the confirmation message is the pre-assigned destination port number. Therefore, the confirmation message is handed over to the UPnP module. After the UPnP module receives the confirmation message, it calls the write(lo_fd) function to write the confirmation message to the loopback interface of the virtual network port device, such as Figure 4 shown.
[0075] 205 , using the virtual network port device to respond to the confirmation message to establish a connection with the terminal.
[0076] After the virtual network port device receives the confirmation message, due to the three-way handshake, all processes of the TCP connection are completed and the connection with the terminal is established. Specifically, the accept(sock_fd,...) function is called to establish a connection with the terminal, and the connection is represented by conn_fd, that is, a connection descriptor.
[0077] So far, a TCP connection with the terminal has been established. The established TCP connection is a connection instance, and the established TCP connection lays the foundation for the subsequent automatic port mapping service.
[0078] like Figure 5 The figure shows a flow chart of a method for providing automatic port mapping service. The method is implemented when the discovery phase has been completed and a TCP connection has been established. The method includes the following steps.
[0079] 301, when the cloud gateway device receives an HTTP request message for requesting automatic port mapping service from a terminal in the local area network, the cloud gateway device writes the HTTP request message to the virtual network port device through the UPnP module.
[0080] The terminal in the local area network encapsulates the HTTP request message for requesting the automatic port mapping service of the cloud gateway device to obtain a hardware layer request message, and sends the hardware layer message to the cloud gateway device.
[0081] After the physical network port of the cloud gateway device receives the hardware layer request message, it reads the hardware layer request message and calls the cloud gateway process to parse the hardware layer request message to obtain the network layer request message. For example, the DPDK driver is used to read the hardware layer request message of the physical network port, and the hardware layer request message is submitted to the cloud gateway process. The cloud gateway process calls the corresponding protocol parser to parse the hardware layer request message to obtain the network layer request message. When the destination port in the network layer request message is parsed to be the pre-allocated destination port number monitored, and the protocol type is HTTP protocol, it is determined that it is an HTTP request message requesting automatic port mapping service from the local area network.
[0082] When it is determined that the network layer request message is an HTTP request message for requesting automatic port mapping service of the UPnP module, the cloud gateway process submits the network layer request message to the UPnP module, so as to use the UPnP module to write the network layer request message to the loopback interface of the virtual network port device. Specifically, the write(lo_fd) function is called to write the network layer request message to the loopback interface of the virtual network port device, such as Figure 4 shown.
[0083] 302, using the protocol stack of the virtual network port device to parse the HTTP request message to obtain the request information of the terminal requesting the automatic port mapping service.
[0084] The protocol stack function of the virtual network port device can be used to parse the network layer request message and the data of the upper layer message. For example, the protocol stack function of the virtual network port device is used to parse the network layer request message to obtain the transport layer request message, and the transport layer request message is parsed again to obtain the application layer request message, which is the original HTTP request message of the terminal application layer.
[0085] According to the application layer request message, the terminal obtains the request information for the automatic port mapping service, which includes requesting the automatic port mapping service to provide a port number for port mapping. In order to distinguish it from the destination port number mentioned above, this port number is called the service port number.
[0086] The data of the parsed network layer request message and its upper layer message are stored in the connection instance corresponding to the pre-established connection.
[0087] 303, reading request information from the virtual network port device through the UPnP module.
[0088] The UPnP module calls read(conn_fd) to read the network layer request message and its upper layer message data stored in the connection instance from the loopback interface of the virtual network port device, such as Figure 4 For example, read the request information parsed by the virtual network port device.
[0089] 304: Use the automatic port mapping service to respond to the request information to determine the service port number of the automatic port mapping service.
[0090] The automatic port mapping service of the UPnP module is called to respond to the request information, for example, a port is determined from available idle ports of the cloud gateway device, and the determined port is used as the service port number of the automatic port mapping service.
[0091] In one embodiment, steps 303 to 304 may be performed multiple times. For example, after the virtual network port device parses the message once, it transmits the message data to the UPnP module. After the UPnP module processes it, it sends the upper layer message to the virtual network port device. The virtual network port device then parses the upper layer message and transmits the parsed upper layer message data to the UPnP module.
[0092] 305, write the service port number into the virtual network port device through the UPnP module.
[0093] The UPnP module calls the write(conn_fd) function to write the network layer request message and the data of the upper layer message into the connection instance through the loopback interface of the virtual network port device, such as Figure 4 For example, the determined service port number is written to the loopback interface of the virtual network port device through the write(conn_fd) function.
[0094] 306 , encapsulate the service port number using the protocol stack of the virtual network port device to generate a network layer response message in response to the HTTP request message.
[0095] The service port number is encapsulated using the protocol stack of the virtual network port device to obtain an application layer response message in response to the HTTP request message, and then the application layer response message is encapsulated to obtain a transport layer response message, and then the transport layer response message is encapsulated to obtain a network layer response message.
[0096] 307 , reading the network layer response message from the virtual network port device through the UPnP module, and sending the network layer response message to the terminal to respond to the HTTP request message.
[0097] The UPnP module calls the read(lo_fd) function to read the network layer request message from the loopback interface of the virtual network port device, encapsulates the network response layer message to generate a hardware layer response message, and sends the hardware layer response message to the terminal to respond to the HTTP request message.
[0098] Specifically, after the UPnP module reads the network layer response message from the loopback interface, it submits the network layer response message to the cloud gateway process. The cloud gateway process calls the corresponding protocol encapsulator to encapsulate the network layer response message to generate a link layer response message, and then encapsulates the link layer response message to obtain a hardware layer response message, and sends the hardware layer response message to the terminal to respond to the HTTP request message.
[0099] In this embodiment, the cloud gateway process parses the message to obtain the network layer message, and sends it to the virtual network port module through the UPnP module, so that the protocol stack of the virtual network port module parses and processes the messages at the network layer and above, and encapsulates the network layer response message to send it to the terminal. In this way, the automatic port mapping service of the UPnP protocol can be provided on the cloud gateway device that implements the transparent transmission of messages.
[0100] After obtaining the service port number, the service port number and terminal information are saved as a port mapping entry. The terminal in the local area network accesses the external network through the corresponding external IP address and the mapped service port number. When the external network accesses the cloud gateway device through the external IP address corresponding to the terminal and the mapped service interface number, the cloud gateway device can forward it to the corresponding terminal in the local area network according to the recorded port mapping entry.
[0101] In one embodiment, the method further comprises: disconnecting the connection and closing the destination port number, such as calling the close(conn_fd) function to disconnect and close the connection, and calling the close(conn_fd) function to close the destination port number.
[0102] In order to better implement the method for providing automatic port mapping service in the embodiment of the present invention, the embodiment of the present application also provides a device for providing automatic port mapping service, such as Figure 6 As shown, the device 400 for providing automatic port mapping service includes a receiving module 401 , a writing module 402 , a network port parsing module 403 , a reading module 404 , a responding module 405 , a network port encapsulation module 406 , and a sending module 407 .
[0103] The receiving module 401 is used to receive an HTTP request message for requesting automatic port mapping service from a terminal in a local area network.
[0104] The writing module 402 is used to write the HTTP request message to the virtual network port device through the UPnP module when the cloud gateway device receives an HTTP request message for requesting automatic port mapping service from a terminal in the local area network.
[0105] The network port parsing module 403 is used to parse the HTTP request message using the protocol stack of the virtual network port device to obtain the request information of the terminal requesting the automatic port mapping service.
[0106] The reading module 404 is used to read the request information from the virtual network port device through the UPnP module.
[0107] The response module 405 is used to respond to the request information to determine the service port number of the automatic port mapping service.
[0108] The writing module 402 is further used to write the service port number into the virtual network port device through the UPnP module.
[0109] The network port encapsulation module 406 is used to encapsulate the service port number by using the protocol stack of the virtual network port device to generate a network layer response message in response to the HTTP request message.
[0110] The reading module 404 is further configured to read the network layer response message from the virtual network port device through the UPnP module.
[0111] The sending module 407 is used to send the network layer response message to the terminal in response to the HTTP request message.
[0112] In one embodiment, if Figure 6 As shown, the device 400 also includes a process parsing module 408, which is used to read the hardware layer request message when the cloud gateway device receives the hardware layer request message from the local area network terminal, and call the cloud gateway process to parse the hardware layer request message to obtain the network layer request message. Correspondingly, the writing module 402 is used to write the network layer request message to the loopback interface of the virtual network port device using the UPnP module when the network layer request message is an HTTP request message for requesting automatic port mapping service of the UPnP module.
[0113] In one embodiment, if Figure 6As shown, the device 400 also includes a process encapsulation module 409. Correspondingly, the reading module 404 is also used to read the network layer response message from the virtual network port device through the UPnP module. The process encapsulation module 409 is used to call the cloud gateway process to encapsulate the network response layer message to generate a hardware layer response message. The sending module 407 is also used to send the hardware layer response message to the terminal to respond to the HTTP request message.
[0114] In one embodiment, if Figure 6 As shown, the device 400 also includes a connection establishment module 410. Correspondingly, the receiving module 401 is also used to receive a connection request message for the automatic port mapping service of the UPnP module sent from a terminal in the local area network corresponding to the home broadband account. The writing module 402 is also used to write the connection request message to the virtual network port device through the UPnP module when the cloud gateway device receives a connection request message for the automatic port mapping service of the UPnP module sent from a terminal in the local area network corresponding to the home broadband account. The connection establishment module is used to establish a connection with the terminal through the protocol stack of the virtual network port device. The connection request message includes the destination port number allocated for the automatic port mapping service of the home broadband account, and the destination port numbers corresponding to the automatic port mapping services of different home broadband accounts are different.
[0115] In one embodiment, the connection establishment module 410 is specifically used to respond to the connection request message using the protocol stack of the virtual network port device to generate a connection confirmation message; use the UPnP module to read the connection confirmation message from the loopback interface, and send the connection confirmation message to the terminal; when the UPnP module receives a confirmation message from the terminal for the connection confirmation message, write the confirmation message to the loopback interface of the virtual network port device, and use the virtual network port device to respond to the confirmation message to establish a connection with the terminal.
[0116] In one embodiment, if Figure 6 As shown, the device 400 also includes a discovery module 411. The discovery module 411 is used to determine a destination port number from the idle ports of the cloud gateway device when the cloud gateway device receives a UPnP discovery message from a terminal in the local area network corresponding to the home broadband account; allocate a destination port number for the automatic port mapping service of the home broadband account, save the relationship between the destination port number and the home broadband account in the cloud gateway device, and monitor the destination port number; send the destination port number to the terminal corresponding to the home broadband account.
[0117] The present application also provides a cloud gateway device. Figure 7 As shown, Figure 7 A schematic diagram of the structure of a cloud gateway device provided in an embodiment of the present application. The cloud gateway device 500 includes one or more physical network ports 503, a processor 501 with one or more processing cores, a memory 502 with one or more computer-readable storage media, and a computer program stored in the memory 502 and executable on the processor, such as a cloud gateway software program. The processor 501 is electrically connected to the memory 502.
[0118] The processor 501 is the control center of the cloud gateway device 500. It uses various interfaces and lines to connect various parts of the entire cloud gateway device 500, and executes various functions of the computer device 500 and processes data by running or loading software programs (computer programs) and / or modules stored in the memory 502, and calling data stored in the memory 502, thereby monitoring the cloud gateway device 500 as a whole.
[0119] In the embodiment of the present application, the processor 501 in the cloud gateway device 500 will load instructions corresponding to the processes of one or more application programs / computer programs into the memory 502 according to the following steps, and the processor 501 will run the application program / computer program stored in the memory 502 to implement various functions, for example, as shown below:
[0120] When the cloud gateway device receives an HTTP request message for requesting automatic port mapping service from a terminal in the local area network, the HTTP request message is written to the virtual network port device through the UPnP module, so as to use the protocol stack of the virtual network port device to parse the HTTP request message to obtain the request information of the terminal requesting automatic port mapping service;
[0121] Reading the request information from the virtual network port device through the UPnP module, and responding to the request information using the automatic port mapping service to determine the service port number of the automatic port mapping service;
[0122] Writing the service port number into the virtual network port device through the UPnP module, so as to encapsulate the service port number using the protocol stack of the virtual network port device to generate a network layer response message in response to the HTTP request message;
[0123] The network layer response message is read from the virtual network port device through the UPnP module, and the network layer response message is sent to the terminal to respond to the HTTP request message.
[0124] The processor 501 can execute the steps / operations in any of the above method embodiments. Please refer to the description in the method embodiments above for details, which will not be repeated here. The specific implementation of the above operations and the beneficial effects that can be achieved can be referred to the previous embodiments, which will not be repeated here.
[0125] like Figure 6 As shown, the cloud gateway device 500 may further include: a virtual network port device 506. The content of the virtual network port device 506 is described above and will not be repeated here. Figure 6 As shown, the cloud gateway device 500 may also include: a radio frequency circuit 504, a wireless fidelity (WiFi, Wireless Fidelity) module 505 and a power supply 507 and other components. Those skilled in the art will understand that Figure 6 The cloud gateway device structure shown in the figure does not constitute a limitation on the cloud gateway device, and may include more or fewer components than shown in the figure, or combine certain parts, or arrange the components differently.
[0126] The RF circuit 504 may be used for receiving and sending signals during the process of sending and receiving information. In particular, after receiving the downlink information from the base station, it is handed over to one or more processors 501 for processing; in addition, data related to the uplink is sent to the base station.
[0127] WiFi is a short-range wireless transmission technology. The cloud gateway provides users with wireless broadband Internet access through the WiFi module 505. Figure 6 A WiFi module 505 is shown, but it is understandable that it is not a necessary component of the cloud gateway device and can be omitted as needed without changing the essence of the application.
[0128] The cloud gateway device also includes a power supply 507 (such as a battery) for supplying power to each component. Preferably, the power supply can be logically connected to the processor 501 through a power management system, so that the power management system can manage functions such as charging, discharging, and power consumption management.
[0129] In the above embodiments, the description of each embodiment has its own emphasis. For the part that is not described in detail in a certain embodiment, please refer to the detailed description above and will not be repeated here.
[0130] Those skilled in the art will appreciate that all or part of the steps in the various methods of the above-described embodiments may be accomplished by instructions / computer programs, or by controlling related hardware through instructions / computer programs, and the instructions / computer programs may be stored in a computer-readable storage medium and loaded and executed by a processor.
[0131] To this end, an embodiment of the present application provides a computer-readable storage medium, in which a plurality of instructions / computer programs are stored, and the instructions / computer programs can be loaded by a processor to implement the following functions:
[0132] When the cloud gateway device receives an HTTP request message for requesting automatic port mapping service from a terminal in the local area network, the HTTP request message is written to the virtual network port device through the UPnP module, so as to use the protocol stack of the virtual network port device to parse the HTTP request message to obtain the request information of the terminal requesting automatic port mapping service;
[0133] Reading the request information from the virtual network port device through the UPnP module, and responding to the request information using the automatic port mapping service to determine the service port number of the automatic port mapping service;
[0134] Writing the service port number into the virtual network port device through the UPnP module, so as to encapsulate the service port number using the protocol stack of the virtual network port device to generate a network layer response message in response to the HTTP request message;
[0135] The network layer response message is read from the virtual network port device through the UPnP module, and the network layer response message is sent to the terminal to respond to the HTTP request message.
[0136] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0137] The storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0138] Since the instructions / computer programs stored in the storage medium can execute the steps in any method for providing automatic port mapping services provided in the embodiments of the present application, the beneficial effects that can be achieved by any method for providing automatic port mapping services provided in the embodiments of the present application can be achieved. For details, please refer to the previous embodiments and will not be repeated here.
[0139] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0140] The above is a detailed introduction to a method and apparatus for providing automatic port mapping services, a cloud gateway device, and a computer-readable storage medium provided in an embodiment of the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the technical solutions and core ideas of the present application. Ordinary technicians in this field should understand that they can still modify the technical solutions recorded in the aforementioned embodiments, or replace some of the technical features therein with equivalents; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for providing automatic port mapping service, characterized in that: Applied to a cloud gateway device, the cloud gateway device includes a virtual network port device, and the method includes: When the cloud gateway device receives an HTTP request message for requesting automatic port mapping service from a terminal in the local area network, the HTTP request message is written to the virtual network port device through the universal plug and play module, so as to use the protocol stack of the virtual network port device to parse the HTTP request message to obtain the request information of the terminal requesting automatic port mapping service; Reading the request information from the virtual network port device through the universal plug and play module, and responding to the request information using the automatic port mapping service to determine the service port number of the automatic port mapping service; Writing the service port number into the virtual network port device through the universal plug and play module, so as to encapsulate the service port number using the protocol stack of the virtual network port device to generate a network layer response message in response to the HTTP request message; Reading the network layer response message from the virtual network port device through the universal plug and play module, and sending the network layer response message to the terminal to respond to the HTTP request message; Among them, when the cloud gateway device receives an HTTP request message requesting automatic port mapping service from a terminal in a local area network, the step of writing the HTTP request message to the virtual network port device through the universal plug and play module includes: When the cloud gateway device receives a hardware layer request message from a local area network terminal, it reads the hardware layer request message and calls the cloud gateway process to parse the hardware layer request message to obtain a network layer request message; When the network layer request message is an HTTP request message for requesting automatic port mapping service of a universal plug and play module, the universal plug and play module is used to write the network layer request message into the loopback interface of the virtual network port device.
2. The method according to claim 1, characterized in that Before the cloud gateway device receives an HTTP request message for requesting automatic port mapping service from a terminal in a local area network, the method further includes: When the cloud gateway device receives a connection request message for the automatic port mapping service of the universal plug and play module sent from a terminal in the local area network corresponding to the home broadband account, the cloud gateway device writes the connection request message to the virtual network port device through the universal plug and play module, and establishes a connection with the terminal through the protocol stack of the virtual network port device; The connection request message includes a destination port number allocated by the automatic port mapping service of the home broadband account, and the destination port numbers corresponding to the automatic port mapping services of different home broadband accounts are different.
3. The method according to claim 2, characterized in that The step of writing the connection request message to the virtual network port device through the universal plug and play module, and establishing a connection with the terminal through the protocol stack of the virtual network port device, comprises: Using a universal plug and play module to write the connection request message to the loopback interface of the virtual network port device, so as to respond to the connection request message using the protocol stack of the virtual network port device to generate a connection confirmation message; Reading the connection confirmation message from the loopback interface using the universal plug and play module, and sending the connection confirmation message to the terminal; When the universal plug and play module receives a confirmation message from the terminal to the connection confirmation message, the confirmation message is written to the loopback interface of the virtual network port device, and the virtual network port device is used to respond to the confirmation message to establish a connection with the terminal.
4. The method according to claim 2, characterized in that: Before the cloud gateway device receives a connection request message for an automatic port mapping service of a universal plug and play module sent from a terminal in a local area network corresponding to a home broadband account, the step further includes: When the cloud gateway device receives a universal plug and play discovery message from a terminal in the local area network corresponding to the home broadband account, determining a destination port number from an idle port of the cloud gateway device; Allocate a destination port number for the automatic port mapping service of the home broadband account, save the relationship between the destination port number and the home broadband account in the cloud gateway device, and monitor the destination port number; The destination port number is sent to the terminal corresponding to the home broadband account.
5. The method according to claim 2, characterized in that: The step of reading the request information from the virtual network port device through the universal plug and play module comprises: using the universal plug and play module to read the request information corresponding to the connection from the loopback interface of the virtual network port device; The step of writing the service port number into the virtual network port device through the universal plug and play module, and encapsulating the service port number using the protocol stack of the virtual network port device to generate a network layer response message in response to the HTTP request message, comprises: Using the universal plug and play module, writing the service port number corresponding to the connection into the loopback interface of the virtual network port device; The service port number is encapsulated using the protocol stack of the virtual network port device to generate an application layer response message, and the application layer response message is re-encapsulated to finally generate a network layer response message in response to the HTTP request message.
6. The method according to claim 2, characterized in that The step of reading the network layer response message from the virtual network port device through the universal plug and play module and sending the network layer response message to the terminal to respond to the HTTP request message includes: Reading the network layer response message from the virtual network port device through the universal plug and play module, and calling the cloud gateway process to encapsulate the network layer response message to generate a hardware layer response message; The hardware layer response message is sent to the terminal to respond to the HTTP request message.
7. A device for providing automatic port mapping service, characterized in that: Applied to a cloud gateway device, the cloud gateway device includes a virtual network port device, and the device includes: A receiving module, used for receiving an HTTP request message for requesting automatic port mapping service from a terminal in a local area network; A writing module, used for writing the HTTP request message to the virtual network port device through the universal plug and play module when the cloud gateway device receives an HTTP request message for requesting automatic port mapping service from a terminal in the local area network; A network port parsing module, used to parse the HTTP request message using the protocol stack of the virtual network port device to obtain the request information of the terminal requesting the automatic port mapping service; a reading module, configured to read the request information from the virtual network port device through the universal plug and play module, A response module, used for responding to the request information to determine the service port number of the automatic port mapping service; The writing module is further used to write the service port number into the virtual network port device through the universal plug and play module; A network port encapsulation module, used to encapsulate the service port number using the protocol stack of the virtual network port device to generate a network layer response message in response to the HTTP request message; The reading module is further used to read the network layer response message from the virtual network port device through the universal plug and play module; A sending module, used for sending the network layer response message to the terminal in response to the HTTP request message; A process parsing module, configured to read the hardware layer request message when the cloud gateway device receives the hardware layer request message from the local area network terminal, and call the cloud gateway process to parse the hardware layer request message to obtain the network layer request message; The writing module is also used to use the universal plug and play module to write the network layer request message to the loopback interface of the virtual network port device when the network layer request message is an HTTP request message requesting automatic port mapping service of the universal plug and play module.
8. A cloud gateway device, characterized in that: The cloud gateway device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method described in any one of claims 1 to 6 when executing the program.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the method described in any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Data access method, gateway equipment, system, storage medium and device
CN110493337A
Data transmission method and system between DPDK user mode and linux kernel network protocol stack
CN111147391A