Message distribution method, network equipment and storage medium

By obtaining and determining the protocol type and target port number of network packets, the resource conflict problem when the AF_XDP user state protocol stack and the Linux kernel protocol stack share the network interface is solved, and the stability of packet shunt is improved.

CN119211145APending Publication Date: 2024-12-27ZTE CORP
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202310764821.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-06-26
Publication Date
2024-12-27

AI Technical Summary

Technical Problem

In virtual machine or container scenarios, when the AF_XDP user state protocol stack and the Linux kernel protocol stack share a network interface, resource conflicts and errors may occur, affecting system stability.

Method used

By obtaining the protocol type and target port number of the network packet, it is decided to pass it to the user-state protocol stack or the Linux kernel protocol stack for processing to avoid resource conflicts.

Benefits of technology

The AF_XDP user state protocol stack and the Linux kernel protocol stack share the network interface without resource conflicts, which improves the stability of packet diversion.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119211145A_ABST
    Figure CN119211145A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a message distribution method, network equipment and a storage medium, and relates to the technical field of communication. The method comprises the following steps: acquiring a protocol type corresponding to a network message; if the protocol type is a first preset protocol type, obtaining a target port number corresponding to the network message; if the target port number belongs to a preset port number group, transmitting the network message to a corresponding user mode protocol stack, so that the user mode protocol stack processes the network message; and if the target port number does not belong to the preset port number group, transmitting the network message to a Linux kernel protocol stack, so that the Linux kernel protocol stack processes the network message. The embodiment of the invention aims to solve the problem of resource conflict when a user mode protocol stack based on the AFXDP and a Linux kernel protocol stack share a network interface.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of communication technology, and in particular to a message diversion method, a network device and a storage medium. Background Art

[0002] AF_XDP (Address Family eXpress Data Path) is an address family added to the Linux kernel since version 4.18. Specifically, it provides high-performance data processing through AF_XDP socket (XSK). Therefore, applications can complete the reception and transmission of messages through the user-mode protocol stack without calling the traditional Linux kernel protocol stack.

[0003] However, when using a virtual machine or container, there is often only one network interface. If a user-mode protocol stack based on the Address Family eXpress Data Path (AF_XDP) and a Linux kernel protocol stack are used in this scenario, the two protocol stacks need to share the same network interface. Since the two protocol stacks share the same network interface, the application may actively establish a UDP or TCP connection on the two protocol stacks, and the local port numbers allocated by the two protocol stacks may conflict, resulting in resource conflicts and errors, and a poor user experience. Summary of the invention

[0004] The main purpose of the embodiments of the present application is to provide a message diversion method, a network device and a storage medium, aiming to solve the problem of resource conflict faced when the user-mode protocol stack based on AF_XDP and the Linux kernel protocol stack share a network interface.

[0005] In a first aspect, an embodiment of the present application provides a message diversion method, the method comprising:

[0006] Get the protocol type corresponding to the network message;

[0007] If the protocol type is the first preset protocol type, obtaining a target port number corresponding to the network message;

[0008] If the target port number belongs to the preset port number group, the network message is transmitted to the corresponding user state protocol stack so that the user state protocol stack processes the network message;

[0009] If the target port number does not belong to the preset port number group, the network message is transferred to the Linux kernel protocol stack so that the Linux kernel protocol stack processes the network message.

[0010] In a second aspect, an embodiment of the present application provides a network device, the network device comprising:

[0011] A processor, a memory, a computer program stored in the memory and executable by the processor, and a data bus for realizing connection and communication between the processor and the memory, wherein when the computer program is executed by the processor, the steps of the message diversion method as described above are realized.

[0012] In a third aspect, an embodiment of the present application provides a storage medium for computer-readable storage, wherein the storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps of the message diversion method as described above.

[0013] The embodiments of the present application provide a message diversion method, a network device, and a storage medium. Obtain the protocol type corresponding to the network message; if the protocol type is a first preset protocol type, obtain the target port number corresponding to the network message; if the target port number belongs to the preset port number group, pass the network message to the corresponding user-mode protocol stack so that the user-mode protocol stack processes the network message; if the target port number does not belong to the preset port number group, pass the network message to the Linux kernel protocol stack so that the Linux kernel protocol stack processes the network message. In this way, the user-mode protocol stack based on AF_XDP and the traditional Linux kernel protocol stack can share the network interface without resource conflicts, thereby avoiding the problem of error reporting due to resource conflicts and improving the stability of message diversion. BRIEF DESCRIPTION OF THE DRAWINGS

[0014] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0015] Figure 1 An exemplary block diagram of a structure using an XDP program to split two protocol stacks provided in an embodiment of the present application;

[0016] Figure 2 An exemplary block diagram of the structure of a message diversion system based on AF_XDP provided in an embodiment of the present application;

[0017] Figure 3 A flow chart of a message diversion method provided in an embodiment of the present application;

[0018] Figure 4A control program provided in an embodiment of the present application is a flowchart of working steps for preparing an operating environment for a message diversion system based on AF_XDP;

[0019] Figure 5 A flowchart of the working steps of allocating a local port number for a UDP / TCP connection by a user mode protocol stack provided in an embodiment of the present application;

[0020] Figure 6 A flowchart of the working steps of recording the port number of a UDP / TCP listening service in a user-mode protocol stack provided in an embodiment of the present application;

[0021] Figure 7 A schematic diagram of the working steps of a message diversion method provided in an embodiment of the present application;

[0022] Figure 8 It is a schematic block diagram of a message diversion device provided in an embodiment of the present application;

[0023] Fig. 9 A schematic block diagram of the structure of a network device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0024] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0025] The flowcharts shown in the accompanying drawings are only examples and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may also be decomposed, combined or partially merged, so the actual execution order may change according to actual conditions.

[0026] It should be understood that the terms used in this application specification are only for the purpose of describing specific embodiments and are not intended to limit the application. As used in this application specification and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.

[0027] The basic principle of AF_XDP is: the application creates an AF_XDP socket (XSK), applies for and registers a user space storage area (UMEM), and builds a receive queue (RX ring) and a transmit queue (TXring) on ​​the storage area; at the same time, the user develops an eXpress Data Path (XDP) program and uses the extended Berkerly Packet Filter (eBPF) mechanism to inject the XDP program into the kernel. The XDP program determines whether the message received from the bottom layer should be redirected to the aforementioned user space storage area; the application reads the message in the XSK receive queue, which completes the reception of the network message; the application puts the message to be sent into the XSK send queue, which completes the sending of the network message. In this way, the application completes the reception and transmission of the message in the user mode protocol stack, without calling the traditional Linux kernel protocol stack. In comparison, the protocol stack message processing process provided by the Linux kernel is relatively long, and when the message is transmitted between the kernel protocol stack and the application, the CPU needs to frequently switch between the kernel mode and the user mode, which brings a lot of overhead.

[0028] Using AF_XDP sockets can improve the performance of network message processing. However, network messages sent and received through AF_XDP sockets are complete Ethernet messages, containing protocol message headers of multiple protocol layers, such as Ethernet headers, IP headers, UDP / TCP headers, etc. Applications need to perform message parsing and processing at each protocol layer, which is usually completed by the protocol stack. Therefore, the existing protocol stack code library (such as the FreeBSD protocol stack code library) will be transplanted to the user space to become a user-mode protocol stack, and it will be modified to replace its underlying data transceiver interface with the operation of AF_XDP sockets; the upper-level application calls the user-mode socket interface provided by the user-mode protocol stack to send and receive messages, instead of directly operating the underlying AF_XDP socket.

[0029] like Figure 1As shown in the figure, when using a virtual machine or container, there is often only one network interface. If the user-mode protocol stack based on AF_XDP and the Linux kernel protocol stack are used in this scenario, the XDP program needs to determine which network packets are forwarded to the AF_XDP socket and which network packets are still processed by the Linux kernel protocol stack. In particular, both protocol stacks may use UDP or TCP protocols, so they cannot be simply distinguished based on the protocol type. There may be multiple programs in the system, actively establishing UDP or TCP connections on the two protocol stacks, and the local port numbers independently allocated by the two protocol stacks may conflict. In addition, both protocol stacks may send ARP (Address Resolution Protocol) requests to the outside, so the system should ensure that both protocol stacks can obtain the results of address resolution.

[0030] The embodiment of the present application provides a message diversion method, a network device and a storage medium. The method can be applied to a network device or a message diversion system based on AF_XDP, wherein the network device can be a server, a base station and an operation and maintenance device, etc., but is not limited thereto. As a result, the user-mode protocol stack based on AF_XDP and the traditional Linux kernel protocol stack can share a network interface without resource conflicts, thereby avoiding the problem of error reporting due to resource conflicts and improving the stability of message diversion.

[0031] For example, Figure 2 As shown, the application of the message diversion method in the message diversion system based on AF_XDP is introduced as an example. The message diversion system includes a control program, an XDP program running in the Linux kernel, a Linux kernel protocol stack, a user mode protocol stack and an application program.

[0032] Among them, the control program can prepare the operating environment for other parts of the message diversion system, and is responsible for the injection of the XDP program, the setting of system parameters and program configuration parameters. The XDP program is responsible for executing the diversion of the received messages. The user-mode protocol stack based on AF_XDP provides the application with a user-mode socket interface for the application to call when sending and receiving messages. The user-mode protocol stack allows upper-layer applications to send and receive messages in user mode, avoiding the frequent switching between kernel mode and user mode when using the Linux kernel protocol stack to send and receive messages, thereby improving processing performance.

[0033] The application uses the user-mode socket interface provided by the user-mode protocol stack to send and receive messages, replacing the traditional Linux kernel protocol stack. Of course, the application can also use the Linux kernel protocol stack at the same time, that is, support both protocol stacks at the same time, use the user-mode protocol stack on some UDP / TCP connections, and use the Linux kernel protocol stack on other UDP / TCP connections.

[0034] Please refer to Figure 3 , Figure 3 A flow chart of a message diversion method provided in an embodiment of the present application. The message diversion method can enable the user-mode protocol stack based on AF_XDP and the traditional Linux kernel protocol stack to share the network interface without resource conflicts, thereby avoiding the problem of error reporting due to resource conflicts and improving the stability of message diversion.

[0035] like Figure 3 As shown, the message diversion method may include S101 to S104.

[0036] S101. Obtain a protocol type corresponding to a network message.

[0037] The network message may be a message received by a network interface, and may specifically include an ARP message, a TCP message, a UDP message, etc. The protocol type corresponding to the network message may include a first preset protocol type and a second preset protocol type, etc., wherein the first preset protocol type may be a TCP / UDP protocol type, and the second preset protocol type may be an ARP protocol type.

[0038] Specifically, a network message is obtained from a network interface, and message information of the network message is parsed to determine the protocol type of the network message.

[0039] In some embodiments, after obtaining the protocol type corresponding to the network message, if the protocol type is a second preset protocol type, the target field information of the network message is obtained, and the ARP message type corresponding to the network message is determined based on the target field information; if the ARP message type corresponding to the network message is an ARP response type, the network message is redirected to the corresponding AF_XDP socket, so that the corresponding user-mode protocol stack receives the network message from the AF_XDP socket and processes the network message.

[0040] The target field information may be the op field in the message information, and the op field may include multiple values: if the value is 1, it indicates an ARP request; if the value is 2, it indicates an ARP response; if the value is 3, it indicates an RARP request; if the value is 4, it indicates an RARP response, etc. The ARP message type may include an ARP response type, an ARP request type, an RARP request type, and an RARP response type.

[0041] Specifically, after determining that the protocol type corresponding to the network message is the ARP protocol type, if the ARP message type corresponding to the network message is not the ARP response type, the network message is passed to the Linux kernel protocol stack so that the Linux kernel protocol stack processes the network message.

[0042] In some embodiments, the user state protocol stack updates its corresponding address resolution protocol table, and calls the Linux kernel interface to update the corresponding address resolution protocol table in the Linux kernel protocol stack, thereby ensuring that both the user state protocol stack and the Linux kernel protocol stack can obtain the result of address resolution.

[0043] Specifically, after receiving the ARP response message, the user mode protocol stack based on the AF_XDP socket updates its own ARP table based on the ARP response message, and calls the Linux kernel interface at the same time to update the ARP table of the Linux kernel protocol stack based on the ARP response message.

[0044] In some embodiments, after acquiring the network message, if the protocol type is neither the first preset protocol type nor the second preset protocol type, the network message is passed to the Linux kernel protocol stack so that the Linux kernel protocol stack processes the network message. Thus, when the protocol type of the network message is other types, the network message can be accurately passed to the Linux kernel protocol stack so that the Linux kernel protocol stack processes the network message.

[0045] Exemplarily, the network message is parsed to obtain the protocol type of the network message. If the protocol type is not a TCP / UDP protocol type and is not an ARP protocol type, such as a NETBEUI protocol type and an IPX / SPX protocol type, the network message is passed to the Linux kernel protocol stack so that the Linux kernel protocol stack processes the network message.

[0046] S102: If the protocol type is the first preset protocol type, obtain a target port number corresponding to the network message.

[0047] The first preset protocol type may be a TCP / UDP protocol type, and the target port number may be a destination port number of the network message.

[0048] Specifically, if it is determined that the protocol type of the network message is the first preset protocol type, the network message may be parsed to obtain a destination port number corresponding to the network message.

[0049] Exemplarily, if it is determined that the protocol type of the network message is the first preset protocol type, the field information for storing the destination port number in the network message can be obtained and parsed to obtain that the destination port number corresponding to the network message can be 12433.

[0050] In some embodiments, after obtaining the target port number corresponding to the network message, it is determined whether the target port number is a preset port number and whether the target port number is within the preset port range; if the target port number is the preset port number or the target port number is within the preset port range, it is determined that the target port number belongs to the preset port number group; if the target port number is not the preset port number and the target port number is not within the preset port range, it is determined that the target port number does not belong to the preset port number group. In this way, it is possible to accurately determine whether the target port number belongs to the preset port number group, thereby determining that the network message is assigned to the corresponding protocol stack for processing.

[0051] The preset port number may be a port number pre-configured by the user, or a port number pre-assigned for a UDP protocol type or a TCP protocol type. The preset port range may be a port number range pre-configured by the user, used to indicate that the port numbers within the range are the port numbers that need to be processed by the user-mode protocol stack.

[0052] Exemplarily, if the target port number is 12345, the preset port numbers include 41300 and 54500, and the preset port range is 10000-30000; at this time, it can be determined that the target port number is within the preset port range, and then it can be determined that the target port number belongs to the preset port number group.

[0053] Exemplarily, if the target port number is 32345, the preset port numbers include 32345, 41300 and 54500, and the preset port range is 10000-30000; at this time, it can be determined that the target port number is the preset port number, and it can be determined that the target port number belongs to the preset port number group.

[0054] Exemplarily, if the target port number is 32345, the preset port numbers include 41300 and 54500, and the preset port range is 10000-30000; at this time, it can be determined that the target port number is not the preset port number and the target port number is not within the preset port range, then it can be determined that the target port number does not belong to the preset port number group.

[0055] S103: If the target port number belongs to the preset port number group, the network message is transmitted to the corresponding user-mode protocol stack so that the user-mode protocol stack processes the network message.

[0056] Among them, the port number in the preset port number group can be a preset port number that needs to be processed by the user mode protocol stack, and the port number outside the preset port number group can be a preset port number that needs to be processed by the Linux kernel protocol stack.

[0057] In some embodiments, the network message is redirected to the corresponding socket so that the corresponding user-mode protocol stack receives the network message from the AF_XDP socket and processes the network message. Thus, the user-mode protocol stack can be used to allow the application to send and receive messages in the user-mode protocol stack, thereby avoiding frequent kernel-mode and user-mode mode switching when using the Linux kernel protocol stack to send and receive messages, thereby improving processing performance.

[0058] Among them, using the XDP program to process the received message is a function of the Linux eBPF technology. The processing result types returned by the XDP program may include: XDP_ABORTED, XDP_DROP, XDP_PASS, XDP_TX, XDP_REDIRECT, etc.

[0059] For example, if the user-mode protocol stack receives a network message from an AF_XDP socket and processes the network message, the returned processing result type is XDP_REDIERCT. Specifically, the bpf_redirect_map() interface can be called to determine whether to redirect the message to the relevant AF_XDP socket according to the BPF map of type BPF_MAP_TYPE_XSKMAP.

[0060] S104: If the target port number does not belong to the preset port number group, the network message is transmitted to the Linux kernel protocol stack so that the Linux kernel protocol stack processes the network message.

[0061] Exemplarily, if the Linux kernel protocol stack receives a network message and processes the network message, the returned processing result type is XDP_PASS, so that the Linux kernel protocol stack processes the network message.

[0062] like Figure 2 and Figure 4 As shown, Figure 4 A control program provided in an embodiment of the present application is a flowchart of the working steps of preparing the operating environment for the message diversion system based on AF_XDP. Specifically, in combination with Figure 2 and Figure 4 The following describes the workflow of the control program for preparing the operating environment for the message diversion system based on AF_XDP, specifically including S201-S204.

[0063] S201. Set the local port range parameters in the Linux kernel parameters.

[0064] The control program sets the local port range parameter in the Linux kernel parameter so that it does not overlap with the local port range used by the user-mode protocol stack based on the AF_XDP socket. The Linux kernel parameter referred to here is generally saved in the / proc / sys / net / ipv4 / ip_local_port_range file in the Linux system. For example, the content of this file is set to "20000 39999", that is, the minimum local port number is 20000 and the maximum is 39999.

[0065] S202. Inject the XDP program into the Linux kernel.

[0066] Specifically, in order to enable the user-mode protocol stack based on the AF_XDP socket to receive messages, the control program is responsible for injecting the XDP program into the Linux kernel, and the XDP program diverts the network messages received by the network interface.

[0067] S203. Write the local port range used by the user mode protocol stack into the BPF map.

[0068] Among them, the control program needs to write the local port range used by the user-mode protocol stack into the BPF map for use by the XDP program. The local port range used by the user-mode protocol stack does not overlap with the port range in the Linux kernel protocol stack. For example, the local port range parameter of the user-mode protocol stack (that is, the preset port range) is set to "4000060000", that is, the local port number allocated by the user-mode protocol stack is at least 40000 and at most 60000.

[0069] S204. Setting local port range parameters for the user mode protocol stack when it is started.

[0070] Specifically, the control program sets a local port range parameter for the user mode protocol stack based on the AF_XDP socket when it is started, and the parameter value is the same as that set in step 203. Accordingly, the user mode protocol stack based on the AF_XDP socket supports the setting of this parameter.

[0071] It should be noted that part or all of the control program work may also be executed by the application or the user-mode protocol stack based on the AF_XDP socket itself when it is started, that is, they are coupled together.

[0072] In some embodiments, before determining whether the target port number is a preset port number, if the first preset protocol type is a UDP protocol type, the preset port number is determined from the listening service port number information corresponding to the UDP protocol type; if the first preset protocol type is a TCP protocol type, the preset port number is determined from the listening service port number information corresponding to the TCP protocol type. In this way, the preset port number can be accurately determined.

[0073] Specifically, the specific protocol type of the network message can be determined first. If the first preset protocol type is the UDP protocol type, the listening service port number information corresponding to the UDP protocol type is obtained, and the preset port number is obtained from the listening service port number information; if the first preset protocol type is the TCP protocol type, the listening service port number information corresponding to the TCP protocol type is obtained, and the preset port number is determined from the listening service port number information corresponding to the TCP protocol type.

[0074] like Figure 5 As shown, Figure 5 A flowchart of the working steps of a user-mode protocol stack for allocating a local port number for a UDP / TCP connection provided in an embodiment of the present application specifically includes S301-S305.

[0075] S301: The application program calls the user mode protocol stack to initiate the establishment of a UDP or TCP connection.

[0076] Specifically, the application actively initiates the establishment of a UDP or TCP connection using a user-mode socket interface provided by a user-mode protocol stack based on the AF_XDP socket, that is, the application is the client of the UDP or TCP connection.

[0077] S302: The user mode protocol stack allocates a local port number for the UDP / TCP connection.

[0078] The user-mode protocol stack based on the AF_XDP socket allocates a local port number for the UDP or TCP connection, and the value thereof does not exceed the local port range parameter configured for it by the control program.

[0079] S303: The application uses the user-mode socket interface provided by the user-mode protocol stack based on the AF_XDP socket to send and receive data.

[0080] S304: The application deletes the UDP or TCP connection using the user-mode socket interface provided by the user-mode protocol stack based on the AF_XDP socket.

[0081] S305: The user-mode protocol stack based on the AF_XDP socket reclaims the port number of the UDP / TCP connection.

[0082] like Figure 6 As shown, Figure 6 A flowchart of the working steps of a user-mode protocol stack recording the port number of a UDP / TCP listening service provided in an embodiment of the present application specifically includes S401-S405.

[0083] S401, the application calls the user mode protocol stack to establish a UDP or TCP listening service.

[0084] Specifically, when the application uses the user-mode socket interface provided by the user-mode protocol stack based on the AF_XDP socket to establish a UDP or TCP listening service, the application is the server end of the UDP or TCP connection.

[0085] S402. The user-mode protocol stack uses the BPF map to record the UDP / TCP listening port number (ie, the preset port number).

[0086] Specifically, the user-mode protocol stack based on the AF_XDP socket records the listening service port number information using BPFmap for use by the XDP program.

[0087] The BPF maps are recorded as "user-mode protocol stack UDP listening port BPF map" and "user-mode protocol stack TCP listening port BPF map". Of course, they can also be combined into one BPF map. It should be noted that this part of the operation can also be performed in the application.

[0088] S403: The application uses the user-mode socket interface to accept client requests and send and receive data.

[0089] S404: The application program calls the user mode protocol stack to stop the UDP or TCP listening service.

[0090] S405. The user-mode protocol stack based on the AF_XDP socket deletes the UDP / TCP listening port number of the listening service port from the BPF map.

[0091] It should be noted that in order to avoid conflicts, when the Linux kernel-mode protocol stack is used in the system to establish a UDP or TCP listening service, its service port number cannot be within the local port range of the user-mode protocol stack based on the AF_XDP socket. This is avoided during port number planning.

[0092] like Figure 7 As shown, Figure 7 A schematic diagram of the working steps of a message diversion method provided in an embodiment of the present application. Specifically, the following Figure 7 The following describes the workflow of the message diversion method provided in the embodiment of the present application, including:

[0093] S501. The XDP program receives a message and parses the protocol type of the message.

[0094] S502: Determine whether the protocol type is the ARP protocol type. If so, jump to S503; if not, jump to S505.

[0095] S503, determine whether the ARP message type is an ARP response type, if so, jump to S504, if not, jump to S509.

[0096] S504: The XDP program redirects the message to the corresponding AF_XDF socket.

[0097] S505, determine whether the protocol type is UDP / TCP protocol type, if so, jump to S506, if not, jump to S509.

[0098] S506: The XDP program parses the target port number corresponding to the network message.

[0099] S507: Is it a user mode protocol stack listening service port? If so, jump to S510; if not, jump to S508.

[0100] S508: Is it within the local port range of the user mode protocol stack? If so, jump to S510; if not, jump to S509.

[0101] S509: The XDP program sends the message to the Linux kernel protocol stack for processing.

[0102] S510. The XDP program redirects the message to the corresponding AF_XDF socket.

[0103] It should be noted that the embodiments of the present application do not limit the actual code implementation of the XDP program. In actual coding, the execution order of the XDP program can be adjusted, more other functions can be implemented, and it can also cooperate with other eBPF programs for execution.

[0104] See also Figure 8 , Figure 8 It is a schematic block diagram of a message diversion device provided in an embodiment of the present application. The message diversion device can be configured in a server to execute the aforementioned message diversion method.

[0105] like Figure 8 As shown, the message diversion device 600 includes: a protocol type determination module 601, a port number acquisition module 602, a first message processing module 603 and a second message processing module 604.

[0106] The protocol type determination module 601 is used to obtain the protocol type corresponding to the network message.

[0107] The port number acquisition module 602 is used to acquire the target port number corresponding to the network message if the protocol type is the first preset protocol type.

[0108] The first message processing module 603 is used to transfer the network message to the corresponding user state protocol stack if the target port number belongs to the preset port number group, so that the user state protocol stack processes the network message.

[0109] The second message processing module 604 is used to transfer the network message to the Linux kernel protocol stack if the target port number does not belong to the preset port number group, so that the Linux kernel protocol stack processes the network message.

[0110] The port number group identification module 605 is used to determine whether the target port number is the preset port number and whether the target port number is within the preset port range; if the target port number is the preset port number or the target port number is within the preset port range, it is determined that the target port number belongs to the preset port number group; if the target port number is not the preset port number and the target port number is not within the preset port range, it is determined that the target port number does not belong to the preset port number group.

[0111] The port number group identification module 605 is also used to determine the preset port number from the listening service port number information corresponding to the UDP protocol type if the first preset protocol type is a UDP protocol type; and to determine the preset port number from the listening service port number information corresponding to the TCP protocol type if the first preset protocol type is a TCP protocol type.

[0112] The first message processing module 603 is further used to redirect the network message to the corresponding socket, so that the corresponding user mode protocol stack receives the network message from the AF_XDP socket and processes the network message.

[0113] The third message processing module 606 is used to obtain the target field information of the network message if the protocol type is the second preset protocol type, and determine the ARP message type corresponding to the network message according to the target field information; if the ARP message type corresponding to the network message is an ARP response type, redirect the network message to the corresponding AF_XDP socket, so that the corresponding user-mode protocol stack receives the network message from the AF_XDP socket and processes the network message.

[0114] The third message processing module 606, the user mode protocol stack is also used to update its corresponding address resolution protocol table, and call the Linux kernel interface to update the corresponding address resolution protocol table in the Linux kernel protocol stack.

[0115] The third message processing module 606 is further configured to transfer the network message to the Linux kernel protocol stack if the ARP message type corresponding to the network message is not an ARP response type, so that the Linux kernel protocol stack processes the network message.

[0116] The fourth message processing module 607 is used to transfer the network message to the Linux kernel protocol stack if the protocol type is neither the first preset protocol type nor the second preset protocol type, so that the Linux kernel protocol stack processes the network message.

[0117] It should be noted that those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and modules and units can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0118] The method and apparatus of the present application can be used in many general or special computing system environments or configurations, such as personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer network devices, network PCs, minicomputers, mainframe computers, and distributed computing environments including any of the above systems or devices.

[0119] See also Fig. 9 , Fig. 9 A schematic block diagram of the structure of a network device provided in an embodiment of the present application.

[0120] like Fig. 9 As shown, the network device 700 may include a processor 701 and a memory 702 , and the processor 701 and the memory 702 are connected via a bus 703 , such as an I2C (Inter-integrated Circuit) bus.

[0121] In an exemplary embodiment, the processor 701 can be used to provide computing and control capabilities to support the operation of the entire network device. The processor 701 can be a central processing unit (CPU), and the processor 701 can also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc.

[0122] Specifically, the memory 702 may be a Flash chip, a read-only memory (ROM) disk, an optical disk, a USB flash drive, or a mobile hard disk.

[0123] Those skilled in the art will understand that Fig. 9 The structure shown in the figure is only a block diagram of a partial structure related to the embodiment of the present application, and does not constitute a limitation on the network device to which the embodiment of the present application is applied. The specific server may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.

[0124] The processor 701 is used to run a computer program stored in the memory, and implement any one of the message diversion methods provided in the embodiments of the present application when executing the computer program.

[0125] In one embodiment, the processor 701 is used to run a computer program stored in a memory, and implement the following steps when executing the computer program: obtaining a protocol type corresponding to a network message; if the protocol type is a first preset protocol type, obtaining a target port number corresponding to the network message; if the target port number belongs to a preset port number group, passing the network message to a corresponding user-mode protocol stack so that the user-mode protocol stack processes the network message; if the target port number does not belong to the preset port number group, passing the network message to a Linux kernel protocol stack so that the Linux kernel protocol stack processes the network message.

[0126] In one embodiment, the preset port number group includes a preset port number and a preset port range; after obtaining the target port number corresponding to the network message, the processor 701 is used to: determine whether the target port number is the preset port number, and determine whether the target port number is within the preset port range; if the target port number is the preset port number or the target port number is within the preset port range, determine that the target port number belongs to the preset port number group; if the target port number is not the preset port number and the target port number is not within the preset port range, determine that the target port number does not belong to the preset port number group.

[0127] In one embodiment, the first preset protocol type is a UDP protocol type or a TCP protocol type. Before determining whether the target port number is the preset port number, the processor 701 is used to implement: if the first preset protocol type is a UDP protocol type, then determine the preset port number from the listening service port number information corresponding to the UDP protocol type; if the first preset protocol type is a TCP protocol type, then determine the preset port number from the listening service port number information corresponding to the TCP protocol type.

[0128] In one embodiment, when the processor 701 passes the network message to the corresponding user-mode protocol stack so that the user-mode protocol stack processes the network message, it is used to implement: redirecting the network message to the corresponding socket so that the corresponding user-mode protocol stack receives the network message from the AF_XDP socket and processes the network message.

[0129] In one embodiment, after obtaining the protocol type corresponding to the network message, the processor 701 is used to implement: if the protocol type is a second preset protocol type, obtain the target field information of the network message, and determine the ARP message type corresponding to the network message according to the target field information; if the ARP message type corresponding to the network message is an ARP response type, redirect the network message to the corresponding AF_XDP socket, so that the corresponding user-mode protocol stack receives the network message from the AF_XDP socket and processes the network message.

[0130] In one embodiment, when the processor 701 implements the user-mode protocol stack receiving the network message from the AF_XDP socket and processing the network message, it is used to implement: the user-mode protocol stack updates its corresponding address resolution protocol table, and calls the Linux kernel interface to update the corresponding address resolution protocol table in the Linux kernel protocol stack.

[0131] In one embodiment, after determining the ARP message type corresponding to the network message according to the target field information, the processor 701 is used to implement: if the ARP message type corresponding to the network message is not an ARP response type, the network message is passed to the Linux kernel protocol stack so that the Linux kernel protocol stack processes the network message.

[0132] In one embodiment, after acquiring the network message, the processor 701 is used to implement: if the protocol type is not the first preset protocol type and not the second preset protocol type, the network message is passed to the Linux kernel protocol stack so that the Linux kernel protocol stack processes the network message.

[0133] It should be noted that those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the network device described above can refer to the corresponding process in the aforementioned message diversion method embodiment, and will not be repeated here.

[0134] An embodiment of the present application also provides a storage medium for computer-readable storage, wherein the storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps of any message diversion method provided in the description of the embodiment of the present application.

[0135] The storage medium may be an internal storage unit of the network device described in the foregoing embodiment, such as a hard disk or memory of the network device. The storage medium may also be an external storage device of the network device, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (SecureDigital, SD) card, a flash card (Flash Card), etc., provided on the network device.

[0136] It will be appreciated by those skilled in the art that all or some of the steps, systems, and functional modules / units in the methods disclosed above may be implemented as software, firmware, hardware, and appropriate combinations thereof. In a hardware embodiment, the division between the functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed by several physical components in cooperation. Some or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor, or a microprocessor, or implemented as hardware, or implemented as an integrated circuit, such as an application-specific integrated circuit. Such software may be distributed on a computer-readable medium, which may include a computer storage medium (or non-transitory medium) and a communication medium (or temporary medium). As known to those skilled in the art, the term computer storage medium includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store the desired information and can be accessed by a computer. In addition, it is well known to those skilled in the art that communication media typically contain computer-readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media.

[0137] It should be understood that the term "and / or" used in the present specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, including these combinations. It should be noted that, in this article, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "including a..." does not exclude the presence of other identical elements in the process, method, article or system including the element.

[0138] The serial numbers of the embodiments of the present application are only for description and do not represent the advantages and disadvantages of the embodiments. The above are only specific embodiments of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in the present application, and these modifications or replacements should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.

Claims

1. A message diversion method, characterized in that: The method comprises: Get the protocol type corresponding to the network message; If the protocol type is the first preset protocol type, obtaining a target port number corresponding to the network message; If the target port number belongs to the preset port number group, the network message is transmitted to the corresponding user state protocol stack so that the user state protocol stack processes the network message; If the target port number does not belong to the preset port number group, the network message is transferred to the Linux kernel protocol stack so that the Linux kernel protocol stack processes the network message.

2. The method according to claim 1, characterized in that The preset port number group includes a preset port number and a preset port range; after obtaining the target port number corresponding to the network message, the method further includes: Determine whether the target port number is the preset port number, and determine whether the target port number is within the preset port range; If the target port number is the preset port number or the target port number is within the preset port range, determining that the target port number belongs to the preset port number group; If the target port number is not the preset port number and the target port number is not within the preset port range, it is determined that the target port number does not belong to the preset port number group.

3. The method according to claim 2, characterized in that The first preset protocol type is a UDP protocol type or a TCP protocol type, and before determining whether the target port number is the preset port number, the method further includes: If the first preset protocol type is a UDP protocol type, determining the preset port number from the listening service port number information corresponding to the UDP protocol type; If the first preset protocol type is a TCP protocol type, the preset port number is determined from the listening service port number information corresponding to the TCP protocol type.

4. The method according to claim 1 or 2, characterized in that: The delivering the network message to the corresponding user-mode protocol stack so that the user-mode protocol stack processes the network message includes: The network message is redirected to the corresponding socket, so that the corresponding user-mode protocol stack receives the network message from the AF_XDP socket and processes the network message.

5. The method according to claim 1, characterized in that: After obtaining the protocol type corresponding to the network message, the method further includes: If the protocol type is the second preset protocol type, obtaining target field information of the network message, and determining the ARP message type corresponding to the network message according to the target field information; If the ARP message type corresponding to the network message is an ARP response type, the network message is redirected to the corresponding AF_XDP socket, so that the corresponding user-mode protocol stack receives the network message from the AF_XDP socket and processes the network message.

6. The method according to claim 5, characterized in that The user mode protocol stack receives the network message from the AF_XDP socket and processes the network message, including: The user mode protocol stack updates its corresponding address resolution protocol table, and calls the Linux kernel interface to update the corresponding address resolution protocol table in the Linux kernel protocol stack.

7. The method according to claim 5, characterized in that After determining the ARP message type corresponding to the network message according to the target field information, the method further includes: If the ARP message type corresponding to the network message is not an ARP response type, the network message is transferred to the Linux kernel protocol stack so that the Linux kernel protocol stack processes the network message.

8. The method according to claim 1, characterized in that: After obtaining the network message, the method further includes: If the protocol type is neither the first preset protocol type nor the second preset protocol type, the network message is transferred to the Linux kernel protocol stack so that the Linux kernel protocol stack processes the network message.

9. A network device, characterized in that: The network equipment includes: A processor, a memory, a computer program stored in the memory and executable by the processor, and a data bus for realizing connection and communication between the processor and the memory, wherein when the computer program is executed by the processor, the steps of the message diversion method as described in any one of claims 1 to 8 are realized.

10. A storage medium for computer-readable storage, characterized in that: The storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps of the message diversion method as described in any one of claims 1 to 8.

Citation Information

Cited By

  • Data transmission method and system based on fast network protocol stack

    CN120075318A

  • A data transmission method and system based on fast network protocol stack

    CN120075318B