Message forwarding method and switch
By introducing a message preprocessing module into the switch processor, the problem that the forwarding chip requires hardware support to find VLAN ID is solved, and the ability to reduce hardware requirements and avoid program modules from processing VLAN TAG is achieved.
Patent Information
- Application Number
- CN202310953521.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-31
- Publication Date
- 2025-02-14
AI Technical Summary
In the prior art, forwarding chips require hardware support to find VLAN IDs and port numbers, resulting in increased hardware requirements.
The message preprocessing module is introduced into the switch's processor, receives messages sent by the forwarding chip, stores the corresponding relationship between the source MAC address and the VLAN ID in the mapping relationship table, and deletes the VLAN ID and sends it to the program module. After receiving the reply message, find the corresponding VLAN ID and add it to the reply message, and send the forwarding chip.
There is no need to make special hardware settings on the forwarding chip, which reduces hardware requirements and avoids the ability of program modules to handle VLAN TAGs.
Smart Images

Figure CN119449526A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a message forwarding method and a switch. Background Art
[0002] With the rapid development of information networks, network traffic has surged and attacks have occurred frequently. In order to ensure the security of the network and information, the forwarding capabilities of switches are increasingly required. At the same time, the requirements for the diversity of switch functions and the security of their own programs are also increasing. In order to ensure the business interaction between the central processing unit (CPU) and the forwarding chip in the switch, the message forwarding architecture between the CPU and the forwarding chip becomes extremely important.
[0003] In the related art, the forwarding chip usually deletes the virtual local area network (VLAN) identifier in the message before sending the message to the CPU, that is, the message sent by the forwarding chip to the CPU does not include the VLAN identifier. After processing the message without the VLAN identifier, the CPU returns a reply message without the VLAN identifier to the forwarding chip. The forwarding chip searches for the corresponding VLAN identifier and port number based on the destination Media Access Control Address (MAC) address in the reply message, and then forwards the reply message based on the found VLAN identifier and port number.
[0004] However, in the above-mentioned related technologies, the forwarding chip searches for the corresponding VLAN ID and port number based on the MAC address, which requires the support of the forwarding chip hardware, thereby increasing the hardware requirements for the forwarding chip. Summary of the invention
[0005] In view of the problems existing in the prior art, an embodiment of the present invention provides a message forwarding method and a switch.
[0006] The present invention provides a message forwarding method, which is applied to a switch, wherein the switch includes a forwarding chip and a processor, and the processor includes a message preprocessing module and a program module; the method includes:
[0007] When receiving the first message sent by the forwarding chip, the message preprocessing module stores the correspondence between the source MAC address and the first VLAN identifier in the first message into a mapping relationship table, and deletes the first VLAN identifier in the first message to obtain a second message;
[0008] The message preprocessing module sends the second message to the program module, and receives a response message corresponding to the second message sent by the program module;
[0009] The message preprocessing module searches the mapping relationship table for a first VLAN identifier corresponding to a source MAC address that is the same as the destination MAC address in the response message;
[0010] The message preprocessing module adds the first VLAN identifier to the reply message to obtain a third message, and sends the third message to the forwarding chip;
[0011] The forwarding chip determines a first port corresponding to the destination MAC address and the first VLAN identifier, and forwards the third message through the first port.
[0012] According to a message forwarding method provided by the present invention, the switch further includes a data transceiver;
[0013] The message preprocessing module receives a first message sent by the forwarding chip, including:
[0014] The message preprocessing module receives the first message sent by the data transceiver based on the DPDK technology; the first message is a message sent by the forwarding chip to the data transceiver.
[0015] According to a message forwarding method provided by the present invention, the message preprocessing module sends the second message to the program module, and receives a response message corresponding to the second message sent by the program module, including:
[0016] The message preprocessing module sends the second message to the program module based on the kernel virtual network card; the kernel virtual network card is created based on KNI technology;
[0017] The message preprocessing module receives the response message sent by the program module based on the kernel virtual network card.
[0018] According to a message forwarding method provided by the present invention, storing the correspondence between the source MAC address and the first VLAN identifier in the first message in a mapping relationship table includes:
[0019] When the message preprocessing module determines that the first message is a normal message, the message preprocessing module stores the corresponding relationship between the source MAC address and the first VLAN identifier in the first message in the mapping relationship table.
[0020] According to a message forwarding method provided by the present invention, the method further includes:
[0021] The message preprocessing module determines the target number of VLAN identifiers in the mapping relationship table when receiving the first broadcast message sent by the program module and the VLAN identifier corresponding to the broadcast MAC address in the first broadcast message is not found in the mapping relationship table;
[0022] The message preprocessing module copies the target number of first broadcast messages;
[0023] For each of the first broadcast messages, the message preprocessing module adds a second VLAN identifier to the first broadcast message to obtain a second broadcast message; the first broadcast message and the second VLAN identifier correspond one to one; the second VLAN identifier is the VLAN identifier in the mapping relationship table;
[0024] The message preprocessing module sends each of the second broadcast messages to the forwarding chip.
[0025] According to a message forwarding method provided by the present invention, before the message preprocessing module receives the first message sent by the forwarding chip, the method further includes:
[0026] When the second port of the forwarding chip receives a fourth message and the fourth message does not include a VLAN identifier, the forwarding chip determines the first VLAN identifier corresponding to the second port based on the PVID of the second port;
[0027] The forwarding chip adds the first VLAN identifier to the fourth message to obtain the first message.
[0028] The present invention also provides a switch, comprising a forwarding chip and a processor, wherein the processor comprises a message preprocessing module and a program module;
[0029] The message preprocessing module is used to store the corresponding relationship between the source MAC address and the first VLAN identifier in the first message into a mapping relationship table when receiving the first message sent by the forwarding chip, and delete the first VLAN identifier in the first message to obtain a second message;
[0030] The message preprocessing module is further used to send the second message to the program module, and receive a response message corresponding to the second message sent by the program module;
[0031] The message preprocessing module is further used to search the mapping table for a first VLAN identifier corresponding to a source MAC address that is the same as the destination MAC address in the response message;
[0032] The message preprocessing module is further used to add the first VLAN identifier to the reply message to obtain a third message, and send the third message to the forwarding chip;
[0033] The forwarding chip is used to determine a first port corresponding to the destination MAC address and the first VLAN identifier, and forward the third message through the first port.
[0034] The present invention also provides a switch, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, any of the above-mentioned message forwarding methods is implemented.
[0035] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the message forwarding method described in any one of the above methods is implemented.
[0036] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements any of the above-mentioned message forwarding methods.
[0037] The message forwarding method and switch provided by the present invention, when receiving a first message sent by a forwarding chip, the message preprocessing module stores the corresponding relationship between the source MAC address and the first VLAN identifier in the first message in a mapping relationship table, and sends a second message obtained after deleting the first VLAN identifier in the first message to the program module, the message preprocessing module receives a reply message sent by the program module, and searches the mapping relationship table for the first VLAN identifier corresponding to the source MAC address that is the same as the destination MAC address in the reply message, adds the found first VLAN identifier to the reply message to obtain a third message, and sends the third message to the forwarding chip, because the third message includes the destination MAC address and the first VLAN identifier, the forwarding chip can directly search for the corresponding first port based on the destination MAC address and the first VLAN identifier, and forward the third message through the first port. It can be known that the first message sent by the forwarding chip of the present invention to the message preprocessing module of the processor includes the first VLAN identifier, and the second message sent by the message preprocessing module to the program module of the processor is the message after the first VLAN identifier is deleted. The message preprocessing module records the correspondence between the source MAC address in the first message and the first VLAN identifier, so when a reply message is received, the found first VLAN identifier can be added to the reply message based on the correspondence and sent to the forwarding chip, so that the forwarding chip can forward the reply message by searching the corresponding port based on the MAC address and VLAN identifier by default, without the need for special settings of the hardware of the forwarding chip, thereby reducing the hardware requirements for the forwarding chip. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0039] Figure 1 This is one of the flow diagrams of the message forwarding method provided by an embodiment of the present invention;
[0040] Figure 2 This is a second flow chart of the message forwarding method provided by an embodiment of the present invention;
[0041] Figure 3 This is a third flow chart of the message forwarding method provided by an embodiment of the present invention;
[0042] Figure 4 This is one of the structural diagrams of the switch provided by the embodiment of the present invention;
[0043] Figure 5 This is the second structural diagram of the switch provided by the embodiment of the present invention;
[0044] Figure 6 It is a schematic diagram of the physical structure of the switch provided by the present invention. DETAILED DESCRIPTION
[0045] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0046] Management switches usually support VLAN technology. Different access ports of the switch can be configured with different VLANs for business division. However, after the message (such as TELNET message, SSH message or HTTP message) sent from the switch forwarding chip to the CPU reaches the CPU, the CPU needs to distinguish which business VLAN sent the message, and send the processed response message to the corresponding VLAN, so that the forwarding chip can forward it normally. If the message sent by the forwarding chip to the CPU does not carry a VLAN tag (VLAN TAG), the CPU cannot distinguish the business VLAN, and the forwarding chip needs to support the ability to find the corresponding VLAN and egress port based on the MAC address, thereby increasing the hardware requirements for the forwarding chip; if the message sent by the forwarding chip to the CPU carries a VLAN TAG, the CPU will receive messages with different VLAN TAGs, and the CPU needs to be able to record the correspondence between the VLAN TAG and the MAC address, and be able to process the VLAN TAG.
[0047] In view of this, the present invention proposes a message forwarding method, which is applied to a switch. The switch includes a forwarding chip and a processor. The processor includes a message preprocessing module and a program module. The first message sent by the forwarding chip to the message preprocessing module of the processor includes a first VLAN identifier. The second message sent by the message preprocessing module to the program module of the processor is a message after the first VLAN identifier is deleted. The message preprocessing module records the correspondence between the source MAC address and the first VLAN identifier in the first message. Therefore, when a reply message is received, the found first VLAN identifier can be added to the reply message based on the correspondence and sent to the forwarding chip, so that the forwarding chip can forward the reply message by default by searching the corresponding port based on the MAC address and the VLAN identifier. There is no need to perform special settings on the hardware of the forwarding chip, thereby reducing the hardware requirements for the forwarding chip and the program module is not required to have the ability to process VLAN TAG.
[0048] Combine the following Figure 1-Figure 3 The message forwarding method of the present invention is described. The execution subject of the method can be a switch, or a message forwarding device arranged in the switch, and the message forwarding device can be implemented by software, hardware or a combination of the two.
[0049] The message forwarding method provided by the embodiment of the present invention is applied to a switch, wherein the switch comprises a forwarding chip and a processor, wherein the processor comprises a message preprocessing module and a program module; and the forwarding chip comprises a CPU interface and multiple ports.
[0050] Figure 1 is one of the flow charts of the message forwarding method provided by an embodiment of the present invention, such as Figure 1 As shown, the message forwarding method includes the following steps:
[0051] Step 101: When receiving a first message sent by the forwarding chip, the message preprocessing module stores the correspondence between the source MAC address and the first VLAN identifier in the first message in a mapping table, deletes the first VLAN identifier in the first message, and obtains a second message.
[0052] For example, when the port of the forwarding chip receives a message sent by a user device, the port forwards the message within the VLAN corresponding to the port. If the destination MAC address of the message is a broadcast address, a multicast address or the MAC address of the CPU interface, the message is sent to the CPU interface; if the message does not include the first VLAN identifier corresponding to the port, the first VLAN identifier corresponding to the port is added to the message to obtain a first message, and the first message is sent to the message preprocessing module of the processor, so that the message preprocessing module receives the first message sent by the forwarding chip, and the message preprocessing module stores the correspondence between the source MAC address and the first VLAN identifier in the first message in a mapping relationship table, and deletes the first VLAN identifier in the first message to obtain a second message.
[0053] It should be noted that the forwarding chip has multiple ports, and the message received through each port can be added with the VLAN ID corresponding to each port, and the VLAN IDs corresponding to each port can be the same or different.
[0054] It should be noted that the forwarding chip supports VLAN configuration, MAC address learning, the function of forwarding messages based on MAC+VLAN port search, and supports register or external interface configuration, etc., which is not limited in the present invention.
[0055] Step 102: The message preprocessing module sends the second message to the program module, and receives a response message corresponding to the second message sent by the program module.
[0056] For example, when the message preprocessing module obtains the second message that does not include the first VLAN identifier, the second message is sent to the program module. The program module performs business processing based on the data portion in the second message, obtains a reply message, and sends the reply message to the message preprocessing module; for example, the second message is used to request to open a web page, and the reply message includes specific information of the web page.
[0057] It should be noted that the technologies used in business processing may include one of the following: socket technology, Libpcap packet capture technology, Apache and Nginx Web server software.
[0058] It should be noted that the program module runs on a Linux system and supports functions such as a Web server, forwarding chip configuration, asset discovery, monitoring device discovery, and topology drawing, but the present invention does not limit this.
[0059] Step 103: The message preprocessing module searches the mapping table for a first VLAN identifier corresponding to a source MAC address that is the same as the destination MAC address in the response message.
[0060] For example, since the second message sent by the message preprocessing module to the program module does not include the first VLAN identifier, the program module does not know the first VLAN identifier corresponding to the first message, and the reply message sent by the program module to the message preprocessing module will not include the first VLAN identifier either. At this time, the message preprocessing module needs to search the mapping relationship table previously created for the first VLAN identifier corresponding to the source MAC address that is the same as the destination MAC address in the reply message. Since the second message is sent from the message preprocessing module to the program module, and the reply message is sent from the program module to the message preprocessing module, the source MAC address in the second message and the destination MAC address in the reply message are the same MAC address.
[0061] It should be noted that when the message preprocessing module searches the mapping table for the first VLAN identifier corresponding to the source MAC address that is the same as the destination MAC address in the response message, a hash algorithm may be used to search for table entries to increase the search speed.
[0062] Step 104: The message preprocessing module adds the first VLAN identifier to the reply message to obtain a third message, and sends the third message to the forwarding chip.
[0063] For example, when the message preprocessing module finds the first VLAN identifier, it adds the first VLAN identifier to the reply message to obtain the third message, and then sends the third message to the forwarding chip.
[0064] Step 105: The forwarding chip determines a first port corresponding to the destination MAC address and the first VLAN identifier, and forwards the third message through the first port.
[0065] For example, when the forwarding chip receives the third message, it parses the third message to obtain the target MAC address and the first VLAN identifier. Based on the correspondence between the MAC address, VLAN identifier and port in the pre-stored MAC table, it can determine the first port corresponding to the target MAC address and the first VLAN identifier, and then forward the third message to the user device through the first port.
[0066] The message forwarding method provided by the present invention, when receiving a first message sent by a forwarding chip, the message preprocessing module stores the corresponding relationship between the source MAC address and the first VLAN identifier in the first message in a mapping relationship table, and sends a second message obtained after deleting the first VLAN identifier in the first message to the program module, the message preprocessing module receives a reply message sent by the program module, and searches the mapping relationship table for the first VLAN identifier corresponding to the source MAC address that is the same as the destination MAC address in the reply message, adds the found first VLAN identifier to the reply message to obtain a third message, and sends the third message to the forwarding chip, because the third message includes the destination MAC address and the first VLAN identifier, the forwarding chip can directly search for the corresponding first port based on the destination MAC address and the first VLAN identifier, and forward the third message through the first port. It can be seen that the first message sent by the forwarding chip of the present invention to the message preprocessing module of the processor includes the first VLAN identifier, and the second message sent by the message preprocessing module to the program module of the processor is the message after the first VLAN identifier is deleted. The message preprocessing module records the correspondence between the source MAC address in the first message and the first VLAN identifier, so when a reply message is received, the found first VLAN identifier can be added to the reply message based on the correspondence and sent to the forwarding chip, so that the forwarding chip can forward the reply message by searching the corresponding port based on the MAC address and VLAN identifier by default, without special settings for the hardware of the forwarding chip, thereby reducing the hardware requirements for the forwarding chip; in addition, the present invention does not require the program module to have the ability to process VLAN TAG, so when the CPU is upgraded, the software does not need special adaptation, and product expansion and development are simple.
[0067] In addition, after the user device changes the port connected to the switch, since the forwarding chip adds the VLAN ID corresponding to the new port in the message, the new port and the corresponding VLAN ID added to the mapping relationship table on the message preprocessing module are also new. When the message preprocessing module receives the response message returned by the program module, it directly searches for the VLAN ID corresponding to the new port based on the mapping relationship table. Therefore, the VLAN ID added to the message forwarded to the forwarding chip is the VLAN ID corresponding to the new port. Therefore, the message will not be forwarded from the old port to which the user device was previously connected, but from the new port to which the user device is currently connected. Therefore, it will not cause network interruption and there will be no problem of long disconnection time.
[0068] In one embodiment, the switch further includes a data transceiver, and the forwarding chip is connected to the message preprocessing module of the processor via the data transceiver; the message preprocessing module in the above step 101 receives the first message sent by the forwarding chip, which can be specifically implemented in the following manner:
[0069] The message preprocessing module receives the first message sent by the data transceiver based on the data plane development kit (Data Plane Development Kit, DPDK) technology; the first message is a message sent by the forwarding chip to the data transceiver.
[0070] Among them, the data transceiver can be a PYH chip. DPDK is mainly based on the Linux system. It is a set of function libraries and drivers for fast data packet processing, which can greatly improve data processing performance and throughput, and improve the work efficiency of data plane applications.
[0071] By way of example, the message preprocessing module is a newly added module on the CPU of the switch. The present invention adopts DPDK technology to enable the message preprocessing module to communicate with the data transceiver. When the data transceiver receives the first message sent by the forwarding chip, the message preprocessing module can receive the first message sent by the forwarding chip through the data transceiver based on the DPDK technology.
[0072] It should be noted that the entire processing of the message preprocessing module in the present invention is based on the DPDK technology, which will not be described in detail later.
[0073] In this embodiment, the DPDK technology is used to enable the message preprocessing module to communicate with the data transceiver, so that the message preprocessing module can receive the first message sent by the forwarding chip to the data transceiver.
[0074] In one embodiment, the message preprocessing module in step 102 sends the second message to the program module, and receives a response message corresponding to the second message sent by the program module, which can be specifically implemented by the following steps:
[0075] The message preprocessing module sends the second message to the program module based on the kernel virtual network card; the message preprocessing module receives the response message sent by the program module based on the kernel virtual network card; the kernel virtual network card is created based on the kernel network card interface (KNI) technology.
[0076] Among them, KNI is a high-performance communication solution between DPDK and the kernel implemented under the DPDK framework.
[0077] For example, a kernel virtual network card can be created in advance based on KNI technology, so that the message preprocessing module can communicate with the program module through the kernel virtual network card. When the message preprocessing module obtains the second message, it can process the second message in user mode based on DPDK technology and send the second message to the kernel virtual network card. The program module runs on the Linux system and processes based on the kernel. There is no need for the program module to implement the Transmission Control Protocol / Internet Protocol (TCP / IP) protocol stack by itself. Program development can be carried out directly based on Socket or L4 layer and above, which speeds up the progress of program development and reduces the difficulty of development. The program module receives the second message sent by the kernel virtual network card, performs business processing based on the data part in the second message, obtains a reply message, and sends the reply message to the message preprocessing module through the kernel virtual network card. The reply message is returned along the original path and does not require special processing.
[0078] In this embodiment, the message preprocessing module can communicate with the program module through the kernel virtual network card created based on the KNI technology, thereby realizing normal communication between the message preprocessing module and the program module.
[0079] In one embodiment, in the above step 101, the corresponding relationship between the source MAC address and the first VLAN identifier in the first message is stored in the mapping relationship table, which can be specifically implemented in the following manner:
[0080] When the message preprocessing module determines that the first message is a normal message, the message preprocessing module stores the corresponding relationship between the source MAC address and the first VLAN identifier in the first message in the mapping relationship table.
[0081] For example, when the message preprocessing module receives the first message sent by the forwarding chip, it needs to preprocess the first message, that is, determine whether the first message is an abnormal message. When it is determined that the first message is a non-abnormal message, the correspondence between the source MAC address and the first VLAN identifier in the first message is stored in a mapping relationship table; when it is determined that the first message is an abnormal message, the first message is directly discarded.
[0082] Whether the first message is an abnormal message can be determined in at least one of the following ways:
[0083] In the first way, it is determined whether the number of bytes of the first message is greater than the preset number of bytes. When it is determined that the number of bytes of the first message is greater than the preset number of bytes, the first message is determined to be an oversized message, that is, an abnormal message.
[0084] The second method is to determine whether the header field in the first message is a preset header field. When it is determined that the header field in the first message is not a preset header field, it is determined that the header field of the first message is wrong, that is, it is an abnormal message.
[0085] In a third manner, the message preprocessing module is determined to receive the first message for a number of times, and when it is determined that the number of times the first message is received is greater than a preset number, the first message is determined to be an abnormal attack message, that is, an abnormal message.
[0086] In this embodiment, when the message preprocessing module receives the first message sent by the forwarding chip, it needs to determine whether the first message is an abnormal message. Only when it is determined that the first message is not an abnormal message, the corresponding relationship between the source MAC address and the first VLAN identifier in the first message is stored in the mapping relationship table, so as to avoid abnormal effects of abnormal messages on the CPU of the switch and reduce the pressure on the CPU to process messages.
[0087] In one embodiment, Figure 2 FIG. 2 is a flow chart of a message forwarding method according to an embodiment of the present invention. Figure 2 As shown, the message forwarding method also includes the following steps:
[0088] Step 201: When the message preprocessing module receives a first broadcast message sent by the program module and fails to find a VLAN identifier corresponding to a broadcast MAC address in the first broadcast message in the mapping table, the message preprocessing module determines a target number of VLAN identifiers in the mapping table.
[0089] For example, the program module can actively send a first broadcast message, so that the message preprocessing module can receive the first broadcast message sent by the program module through the kernel virtual network card. Since the first broadcast message does not include a VLAN identifier, the message preprocessing module needs to determine whether the previously established mapping relationship table includes the VLAN identifier corresponding to the broadcast MAC address in the first broadcast message. When it is determined that the previously established mapping relationship table does not include the VLAN identifier corresponding to the broadcast MAC address in the first broadcast message, all VLAN identifiers in the mapping relationship table are searched, and the number of all VLAN identifiers is determined as the target number.
[0090] Step 202: The message preprocessing module copies the target number of first broadcast messages.
[0091] For example, when obtaining the target number of all VLAN identifiers in the mapping relationship table, the message preprocessing module copies the first broadcast message to the target number, that is, obtains the target number of first broadcast messages.
[0092] Step 203: For each of the first broadcast messages, the message preprocessing module adds a second VLAN identifier to the first broadcast message to obtain a second broadcast message; the first broadcast message and the second VLAN identifier correspond one to one; the second VLAN identifier is the VLAN identifier in the mapping relationship table.
[0093] For example, the first broadcast message and the second VLAN identifier correspond one to one, so the second VLAN identifier added in each first broadcast message is different, that is, the second VLAN identifier included in each second broadcast message is different.
[0094] Step 204: The message preprocessing module sends each of the second broadcast messages to the forwarding chip.
[0095] For example, when each second broadcast message is obtained, the message preprocessing module sends each second broadcast message to the forwarding chip through the data transceiver module. The forwarding chip forwards the second broadcast message at the port of the corresponding second VLAN based on the second VLAN identifier in the second broadcast message; for example, the second VLAN identifier included in the second broadcast message is VLAN10, then the forwarding chip will send the second broadcast message at all ports that allow VLAN10 to pass.
[0096] In this embodiment, when the message preprocessing module receives the first broadcast message sent by the program module, it can copy the first broadcast message based on the number of all VLAN identifiers in the previously established relationship mapping table, and add the corresponding VLAN identifier to each first broadcast message, thereby realizing forwarding the broadcast message at the port of the corresponding VLAN, and there is no need to perform special configuration on the hardware of the forwarding chip, thereby reducing the hardware requirements for the forwarding chip.
[0097] In one embodiment, Figure 3 FIG. 3 is a flow chart of a message forwarding method provided by an embodiment of the present invention. Figure 3 As shown, before the above step 101, the message forwarding method further includes the following steps:
[0098] Step 106: When a fourth message is received at the second port of the forwarding chip and the fourth message does not include a VLAN identifier, the forwarding chip determines the first VLAN identifier corresponding to the second port based on the PVID of the second port.
[0099] For example, the user device can be connected to any port of the forwarding chip in the switch via a network cable, and the forwarding chip can receive messages through any port. When the second port of the forwarding chip receives the fourth message, the fourth message is first parsed to determine whether the fourth message includes a VLAN identifier. When it is determined that the fourth message does not include a VLAN identifier, it is necessary to determine the VLAN identifier corresponding to the second port based on the PVID (Port-base Vlan ID, the virtual LAN ID number of the port) of the second port, that is, to determine the identifier of the PVID of the second port as the first VLAN identifier corresponding to the second port.
[0100] Step 107: The forwarding chip adds the first VLAN identifier to the fourth message to obtain the first message.
[0101] For example, when the forwarding chip finds the first VLAN identifier corresponding to the second port, the first VLAN identifier is added to the fourth message to obtain the first message including the first VLAN identifier, and then the output port corresponding to the first VLAN identifier is searched in the pre-configured MAC table. If the output port corresponding to the first VLAN identifier is the CPU interface, the first message is sent to the message preprocessing module of the processor through the CPU interface based on the data transceiver module.
[0102] It should be noted that during configuration, the CPU interface can be configured to allow all VLANs to pass, that is, all VLANs are allowed to pass.
[0103] It should be noted that when the message received by the port of the forwarding chip includes a VLAN ID, it is necessary to determine whether the VLAN ID included in the message is the VLAN ID pre-configured corresponding to the port. When it is determined that the VLAN ID included in the message is not the VLAN ID pre-configured corresponding to the port, the message is discarded and waits for the next message.
[0104] Figure 4 FIG. 1 is one of the structural diagrams of the switch provided in the embodiment of the present invention. Figure 4 As shown, the switch includes a forwarding chip 401 and a processor 402, and the processor 402 includes a message preprocessing module 4021 and a program module 4022; wherein:
[0105] The message preprocessing module 4021 is used for storing the correspondence between the source MAC address and the first VLAN identifier in the first message into a mapping relationship table when receiving the first message sent by the forwarding chip 401, and deleting the first VLAN identifier in the first message to obtain a second message;
[0106] The message preprocessing module 4021 is further used to send the second message to the program module 4022, and receive a response message corresponding to the second message sent by the program module 4022;
[0107] The message preprocessing module 4021 is further used to search the mapping table for a first VLAN identifier corresponding to a source MAC address that is the same as the destination MAC address in the response message;
[0108] The message preprocessing module 4021 is further configured to add the first VLAN identifier to the reply message to obtain a third message, and send the third message to the forwarding chip 401;
[0109] The forwarding chip 401 is used to determine the first port corresponding to the destination MAC address and the first VLAN identifier, and forward the third message through the first port.
[0110] In the switch provided by the present invention, when a message preprocessing module of the switch receives a first message sent by a forwarding chip, the message preprocessing module stores the corresponding relationship between the source MAC address and the first VLAN identifier in the first message in a mapping relationship table, and sends a second message obtained after deleting the first VLAN identifier in the first message to a program module. The message preprocessing module receives a reply message sent by the program module, and searches the mapping relationship table for the first VLAN identifier corresponding to the source MAC address that is the same as the destination MAC address in the reply message, adds the found first VLAN identifier to the reply message to obtain a third message, and sends the third message to the forwarding chip. Since the third message includes the destination MAC address and the first VLAN identifier, the forwarding chip can directly search for the corresponding first port based on the destination MAC address and the first VLAN identifier, and forward the third message through the first port. It can be known that the first message sent by the forwarding chip of the present invention to the message preprocessing module of the processor includes the first VLAN identifier, and the second message sent by the message preprocessing module to the program module of the processor is the message after the first VLAN identifier is deleted. The message preprocessing module records the correspondence between the source MAC address in the first message and the first VLAN identifier, so when a reply message is received, the found first VLAN identifier can be added to the reply message based on the correspondence and sent to the forwarding chip, so that the forwarding chip can forward the reply message by searching the corresponding port based on the MAC address and VLAN identifier by default, without the need for special settings of the hardware of the forwarding chip, thereby reducing the hardware requirements for the forwarding chip.
[0111] In one embodiment, Figure 5 FIG. 2 is a schematic diagram of the structure of a switch provided by an embodiment of the present invention. Figure 5As shown, the switch further includes a data transceiver 403 .
[0112] The message preprocessing module 4021 is specifically used to receive the first message sent by the data transceiver 403 based on the DPDK technology; the first message is the message sent by the forwarding chip 401 to the data transceiver 403.
[0113] In one embodiment, the message preprocessing module 4021 is further specifically used to send the second message to the program module 4022 based on the kernel virtual network card; the kernel virtual network card is created based on the KNI technology;
[0114] The message preprocessing module 4021 is further specifically used to receive the response message sent by the program module 4022 based on the kernel virtual network card.
[0115] In one embodiment, the message preprocessing module 4021 is further specifically configured to store the correspondence between the source MAC address and the first VLAN identifier in the first message into the mapping relationship table when it is determined that the first message is a normal message.
[0116] In one embodiment, the message preprocessing module 4021 is further used to determine the target number of VLAN identifiers in the mapping relationship table when the first broadcast message sent by the program module 4022 is received and the VLAN identifier corresponding to the broadcast MAC address in the first broadcast message is not found in the mapping relationship table;
[0117] The message preprocessing module 4021 is further used to copy the target number of first broadcast messages;
[0118] For each of the first broadcast messages, the message preprocessing module 4021 is further used to add a second VLAN identifier to the first broadcast message to obtain a second broadcast message; the first broadcast message and the second VLAN identifier correspond one to one; the second VLAN identifier is the VLAN identifier in the mapping relationship table;
[0119] The message preprocessing module 4021 is further configured to send each of the second broadcast messages to the forwarding chip 401 .
[0120] In one embodiment, when the second port of the forwarding chip 401 receives the fourth message and the fourth message does not include a VLAN identifier, the forwarding chip 401 is further configured to determine the first VLAN identifier corresponding to the second port based on the PVID of the second port;
[0121] The forwarding chip 401 is further configured to add the first VLAN identifier to the fourth message to obtain the first message.
[0122] Figure 6 FIG. 1 is a schematic diagram of the physical structure of a switch provided in an embodiment of the present invention. Figure 6 As shown, the switch may include: a processor 610, a communication interface 620, a memory 630 and a communication bus 640, wherein the processor 610, the communication interface 620 and the memory 630 communicate with each other through the communication bus 640. The processor 610 may call the logic instructions in the memory 630 to execute the message forwarding method, the switch includes a forwarding chip and a processor, the processor includes a message preprocessing module and a program module; the method includes:
[0123] When receiving the first message sent by the forwarding chip, the message preprocessing module stores the correspondence between the source MAC address and the first VLAN identifier in the first message into a mapping relationship table, and deletes the first VLAN identifier in the first message to obtain a second message;
[0124] The message preprocessing module sends the second message to the program module, and receives a response message corresponding to the second message sent by the program module;
[0125] The message preprocessing module searches the mapping relationship table for a first VLAN identifier corresponding to a source MAC address that is the same as the destination MAC address in the response message;
[0126] The message preprocessing module adds the first VLAN identifier to the reply message to obtain a third message, and sends the third message to the forwarding chip;
[0127] The forwarding chip determines a first port corresponding to the destination MAC address and the first VLAN identifier, and forwards the third message through the first port.
[0128] In addition, the logic instructions in the above-mentioned memory 630 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0129] On the other hand, the present invention further provides a computer program product, the computer program product includes a computer program, the computer program can be stored in a non-transitory computer-readable storage medium, when the computer program is executed by a processor, the computer can execute the message forwarding method provided by the above methods, applied to a switch, the switch includes a forwarding chip and a processor, the processor includes a message preprocessing module and a program module; the method includes:
[0130] When receiving the first message sent by the forwarding chip, the message preprocessing module stores the corresponding relationship between the source MAC address and the first VLAN identifier in the first message into a mapping relationship table, and deletes the first VLAN identifier in the first message to obtain a second message;
[0131] The message preprocessing module sends the second message to the program module, and receives a response message corresponding to the second message sent by the program module;
[0132] The message preprocessing module searches the mapping relationship table for a first VLAN identifier corresponding to a source MAC address that is the same as the destination MAC address in the response message;
[0133] The message preprocessing module adds the first VLAN identifier to the reply message to obtain a third message, and sends the third message to the forwarding chip;
[0134] The forwarding chip determines a first port corresponding to the destination MAC address and the first VLAN identifier, and forwards the third message through the first port.
[0135] In another aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which is implemented when the computer program is executed by a processor to execute the message forwarding method provided by the above methods, and is applied to a switch, wherein the switch includes a forwarding chip and a processor, and the processor includes a message preprocessing module and a program module; the method includes:
[0136] When receiving the first message sent by the forwarding chip, the message preprocessing module stores the corresponding relationship between the source MAC address and the first VLAN identifier in the first message into a mapping relationship table, and deletes the first VLAN identifier in the first message to obtain a second message;
[0137] The message preprocessing module sends the second message to the program module, and receives a response message corresponding to the second message sent by the program module;
[0138] The message preprocessing module searches the mapping relationship table for a first VLAN identifier corresponding to a source MAC address that is the same as the destination MAC address in the response message;
[0139] The message preprocessing module adds the first VLAN identifier to the reply message to obtain a third message, and sends the third message to the forwarding chip;
[0140] The forwarding chip determines a first port corresponding to the destination MAC address and the first VLAN identifier, and forwards the third message through the first port.
[0141] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0142] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0143] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A message forwarding method, characterized in that: Applied to a switch, the switch includes a forwarding chip and a processor, the processor includes a message preprocessing module and a program module; the method includes: When receiving the first message sent by the forwarding chip, the message preprocessing module stores the correspondence between the source MAC address and the first VLAN identifier in the first message into a mapping relationship table, and deletes the first VLAN identifier in the first message to obtain a second message; The message preprocessing module sends the second message to the program module, and receives a response message corresponding to the second message sent by the program module; The message preprocessing module searches the mapping relationship table for a first VLAN identifier corresponding to a source MAC address that is the same as the destination MAC address in the response message; The message preprocessing module adds the first VLAN identifier to the reply message to obtain a third message, and sends the third message to the forwarding chip; The forwarding chip determines a first port corresponding to the destination MAC address and the first VLAN identifier, and forwards the third message through the first port.
2. The message forwarding method according to claim 1, characterized in that: The switch also includes a data transceiver; The message preprocessing module receives a first message sent by the forwarding chip, including: The message preprocessing module receives the first message sent by the data transceiver based on the DPDK technology; The first message is a message sent by the forwarding chip to the data transceiver.
3. The message forwarding method according to claim 1, characterized in that: The message preprocessing module sends the second message to the program module, and receives a response message corresponding to the second message sent by the program module, including: The message preprocessing module sends the second message to the program module based on the kernel virtual network card; the kernel virtual network card is created based on KNI technology; The message preprocessing module receives the response message sent by the program module based on the kernel virtual network card.
4. The message forwarding method according to any one of claims 1 to 3, characterized in that: The storing the correspondence between the source MAC address and the first VLAN identifier in the first message into a mapping relationship table includes: When the message preprocessing module determines that the first message is a normal message, the message preprocessing module stores the corresponding relationship between the source MAC address and the first VLAN identifier in the first message in the mapping relationship table.
5. The message forwarding method according to any one of claims 1 to 3, characterized in that: The method further comprises: The message preprocessing module determines the target number of VLAN identifiers in the mapping relationship table when receiving the first broadcast message sent by the program module and the VLAN identifier corresponding to the broadcast MAC address in the first broadcast message is not found in the mapping relationship table; The message preprocessing module copies the target number of first broadcast messages; For each of the first broadcast messages, the message preprocessing module adds a second VLAN identifier to the first broadcast message to obtain a second broadcast message; the first broadcast message and the second VLAN identifier correspond one to one; the second VLAN identifier is the VLAN identifier in the mapping relationship table; The message preprocessing module sends each of the second broadcast messages to the forwarding chip.
6. The message forwarding method according to any one of claims 1 to 3, characterized in that: Before the message preprocessing module receives the first message sent by the forwarding chip, the method further includes: When the second port of the forwarding chip receives a fourth message and the fourth message does not include a VLAN identifier, the forwarding chip determines the first VLAN identifier corresponding to the second port based on the PVID of the second port; The forwarding chip adds the first VLAN identifier to the fourth message to obtain the first message.
7. A switch, characterized in that: It includes a forwarding chip and a processor, and the processor includes a message preprocessing module and a program module; The message preprocessing module is used to store the corresponding relationship between the source MAC address and the first VLAN identifier in the first message into a mapping relationship table when receiving the first message sent by the forwarding chip, and delete the first VLAN identifier in the first message to obtain a second message; The message preprocessing module is further used to send the second message to the program module, and receive a response message corresponding to the second message sent by the program module; The message preprocessing module is further used to search the mapping table for a first VLAN identifier corresponding to a source MAC address that is the same as the destination MAC address in the response message; The message preprocessing module is further used to add the first VLAN identifier to the reply message to obtain a third message, and send the third message to the forwarding chip; The forwarding chip is used to determine a first port corresponding to the destination MAC address and the first VLAN identifier, and forward the third message through the first port.
8. A switch comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the message forwarding method according to any one of claims 1 to 6 is implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the message forwarding method according to any one of claims 1 to 6 is implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the message forwarding method according to any one of claims 1 to 6 is implemented.