Virtual local area network device registration method and apparatus, computer device, and storage medium
By generating and sending test messages containing device identifiers, the problem of not being able to determine normal use after successful registration of VLAN devices was solved, enabling timely release of resources and normal use of devices, and reducing debugging costs.
Patent Information
- Application Number
- CN202510120678.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-24
- Publication Date
- 2025-12-12
- Estimated Expiration
- 2045-01-24
AI Technical Summary
Existing virtual LAN device registration methods cannot determine whether a device is in normal use, and cannot release unusable resources in a timely manner, resulting in additional debugging costs and unusable devices left in the kernel.
By generating a test message containing the device identifier and sending it to the target device to determine the identifier consistency, resources are released if there is a discrepancy, thus ensuring the normal use of the virtual LAN device and timely resource release.
This ensures that the virtual LAN device can be used normally in the future and releases unusable resources in a timely manner, reducing debugging costs and the risk of legacy devices in the kernel.
Smart Images

Figure CN119945835B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a virtual local area network device registration method and device, computer equipment and storage medium. BACKGROUND
[0002] The current VLAN (Virtual Local Area Network) device registration method can only ensure that the Linux kernel applies for the memory and other resources required by the virtual local area network device and registers it as a network device. However, after the virtual local area network device is successfully registered, it cannot be guaranteed that the virtual local area network device can be normally used subsequently. The virtual local area network device may have errors when sending data packets through a physical transmission port. Because it cannot be determined whether the registered virtual local area network device can be normally used, additional debugging costs will be increased in the subsequent testing and debugging process of the virtual local area network device.
[0003] In addition, if the registered virtual local area network device cannot be used, it will cause a virtual local area network device that cannot be used to exist in the Linux kernel, and the resources occupied by the virtual local area network device cannot be released in time, and the virtual local area network device may cause errors in the Linux kernel.
[0004] Therefore, the related technology cannot determine whether the virtual local area network device can be normally used, and cannot release the resources occupied by the virtual local area network device that cannot be normally used in time. SUMMARY
[0005] Therefore, the present application provides a virtual local area network device registration method and device, computer equipment and storage medium to solve the problem that whether the virtual local area network device can be normally used cannot be determined, and the resources occupied by the virtual local area network device that cannot be normally used cannot be released in time.
[0006] In a first aspect, the present application provides a virtual local area network device registration method, which comprises:
[0007] Registering an initial virtual local area network device and determining the device identifier of the initial virtual local area network device;
[0008] Generating a test packet containing the device identifier;
[0009] Sending the test packet to a target device, so that the target device judges whether the identifier contained in the intermediate packet is consistent with the device identifier, wherein the intermediate packet is the test packet received by the target device;
[0010] In the case that the target device does not receive the test packet, or the identifier contained in the intermediate packet is not consistent with the device identifier, releasing the resources occupied by the initial virtual local area network device.
[0011] In the case that the identification contained in the intermediate message is consistent with the device identification, the initial virtual local area network device is set as the target virtual local area network device.
[0012] The virtual local area network device registration method provided by the embodiment increases the test on whether the initial virtual local area network device can normally transmit and receive data messages. The device label is written in the test message, the test message is sent to the target device, and the target device is used to judge whether the identification in the received test message is consistent with the device identification. Only in the case that the two are consistent, it is determined that the virtual local area network device registration is successful. Otherwise, the memory and other resources applied by the virtual local area network device will be released, and the virtual local area network device that cannot be used will not be left in the kernel. It is ensured that the registered virtual local area network device can be normally used subsequently, and the resources occupied by the virtual local area network device that cannot be normally used are released in time. The problem that whether the virtual local area network device can be normally used cannot be determined, and the resources occupied by the virtual local area network device that cannot be normally used cannot be released in time is solved.
[0013] In a second aspect, the present application provides a virtual local area network device registration device, which comprises:
[0014] A registration module is configured to register an initial virtual local area network device and determine a device identification of the initial virtual local area network device.
[0015] A generation module is configured to generate a test message containing the device identification.
[0016] A sending module is configured to send the test message to a target device, so that the target device judges whether the identification contained in an intermediate message is consistent with the device identification, wherein the intermediate message is the test message received by the target device.
[0017] A release module is configured to release the resources occupied by the initial virtual local area network device in the case that the target device does not receive the test message, or the identification contained in the intermediate message is not consistent with the device identification.
[0018] A setting module is configured to set the initial virtual local area network device as the target virtual local area network device in the case that the identification contained in the intermediate message is consistent with the device identification.
[0019] In a third aspect, the present application provides a computer device, which comprises a memory and a processor, the memory and the processor are communicatively connected with each other, the memory stores computer instructions, and the processor executes the computer instructions, thereby executing the virtual local area network device registration method of the first aspect or any of the corresponding embodiments thereof.
[0020] In a fourth aspect, the present application provides a computer nonvolatile readable storage medium, which stores computer instructions for making a computer execute the virtual local area network device registration method of the first aspect or any of the corresponding embodiments thereof.
[0021] In a fifth aspect, the present application provides a computer program product, which comprises computer instructions for making a computer execute the virtual local area network device registration method of the first aspect or any of the corresponding embodiments thereof. BRIEF DESCRIPTION OF DRAWINGS
[0022] In order to more clearly illustrate the technical solutions in the specific embodiments of the present application or the technical solutions in the related art, the drawings needed to be used in the specific embodiments or the related art description will be briefly introduced. Obviously, the drawings in the following description are some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor on the basis of these drawings.
[0023] Figure 1 Fig. 1 is a flowchart of a virtual local area network device registration method according to an embodiment of the present application;
[0024] Figure 2 Fig. 2 is a schematic diagram of a data frame according to an embodiment of the present application;
[0025] Figure 3 Fig. 3 is a flowchart of another virtual local area network device registration method according to an embodiment of the present application;
[0026] Figure 4 Fig. 4 is a structural block diagram of a virtual local area network device registration apparatus according to an embodiment of the present application;
[0027] Figure 5 Fig. 5 is a hardware structure schematic diagram of a computer device according to an embodiment of the present application. DETAILED DESCRIPTION
[0028] In order to make the purposes, technical solutions and advantages of the embodiments of the present application more clear, the technical solutions in the embodiments of the present application will be described clearly and completely with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are some of the embodiments of the present application, but not all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the present application.
[0029] The development of a local area network (LAN) is the basis for the generation of a VLAN. Hubs, bridges, switches and other network devices connect all nodes within the same network segment to form a LAN, which is usually a single broadcast domain. Network nodes within the same LAN can communicate directly with each other. A virtual LAN is a group of logical devices and users that are not limited by a physical network segment. They can be organized according to functions, departments and applications, and communicate with each other as if they were in the same network segment. In the Linux kernel, a virtual LAN is a special network device. Before using the virtual LAN function, a virtual LAN device needs to be created through an ioctl (Input / Output Control) interface and then operated.
[0030] The current virtual LAN usage process first registers a virtual LAN device, then activates the interface corresponding to the virtual LAN device, and waits for the host device of the virtual LAN device to send data packets when in use. Among them, the process of registering a virtual LAN device simply applies some data structures. As long as the corresponding resources and memory are applied in the kernel, the registration of the virtual LAN device as a network device will return a signal indicating that the registration of the virtual LAN device is successful. Only when the registration as a network device fails will the memory and other resources applied for the virtual LAN device be released. Currently, only the memory and other resources required by the virtual LAN device can be guaranteed to be applied in the Linux kernel and registered as a network device. Even if the virtual LAN device is successfully registered, it cannot be guaranteed that the virtual LAN device can be truly used later. Errors may occur when the virtual LAN device sends data packets through the physical transmission port.
[0031] The current virtual LAN device registration method has some problems: although the data structures required to create a virtual LAN device can be created, the registered virtual LAN device cannot determine whether it has truly and successfully integrated into the entire network transmission system. It cannot be guaranteed that data packets containing a virtual LAN tag can be sent through a physical transmission port. There is a situation where a virtual LAN device is successfully registered but cannot normally use the VLAN function, which will increase the additional debugging cost in the subsequent testing and debugging process. The current virtual LAN device registration method does not detect errors in the physical transmission port. In the case where the physical transmission port does not provide correct support after the virtual LAN device is successfully registered as a network device, the memory and other resources occupied by the virtual LAN device cannot be released in time, and there is a virtual LAN device that cannot be used in the kernel.
[0032] Based on the above, the embodiment of the present application provides a virtual local area network device registration method, in which a test is added to determine whether the physical transmission port can normally receive and send virtual local area network data messages during the registration process of the virtual local area network device. Only when the virtual local area network device is successfully registered as a network device and the physical transmission port can normally receive and send data messages, a signal indicating that the virtual local area network device is successfully registered is returned. After the virtual local area network device is successfully registered as a network device, if the test of the physical transmission port fails, the memory and other resources applied by the virtual local area network device are released, and the virtual local area network device which cannot be used is not left in the kernel. In addition, the test can test whether the current physical transmission port can normally receive and send data messages in an offline state, and the data of the test process is deleted after the test is completed. The test does not affect the subsequent normal use of the network device after the test is completed. The technical effects of ensuring that the registered virtual local area network device can be normally used subsequently and releasing the resources occupied by the virtual local area network device which cannot be normally used in time are achieved.
[0033] According to the embodiment of the present application, a virtual local area network device registration embodiment is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer device with data processing capability, such as a computer, a server, etc. Although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0034] In the embodiment, a virtual local area network device registration method is provided, Figure 1 is a flowchart of the virtual local area network device registration method according to the embodiment of the present application, as Figure 1 shown, the flowchart includes the following steps:
[0035] In step S101, an initial virtual local area network device is registered, and the device identifier of the initial virtual local area network device is determined.
[0036] Specifically, a new virtual local area network device is registered as an initial virtual local area network device, and the registration process can include: registering the new virtual local area network device using the vconfig add command, calling the vlan_ioctl_handler function in the Linux kernel, vconfig add is a command for adding a virtual local area network sub-interface in a Linux system, and the vlan_ioctl_handler function is a processor for handling input-output control interface calls related to virtual local area networks, which is responsible for parsing input-output control commands from the user space and performing corresponding operations according to these commands. The function calls the virtual local area network registration device (register_vlan_device) to register a new virtual local area network device. First, the memory resources of the virtual local area network device are applied, the properties of the virtual local area network device in the network device structure body are configured, and the virtual local area network device is bound with the real network device, that is, the host device of the virtual local area network device.
[0037] The device identifier of the initial virtual local area network device is determined, for example: virtual local area network ID (Identity document, identity identifier). The device identifier is written to the real network device bound to the initial virtual local area network device.
[0038] Step S102, a test packet containing the device identifier is generated.
[0039] Specifically, when sending a test packet through a network device under the Linux kernel, the vlan_dev_hard_start_xmit function of the network device is called, which transmits the test packet to the network device already registered in the kernel through vlan_netdev_ops, vlan_netdev_ops is an instance of a structure body, which contains pointers to various network device operation functions, such as sending data packets, opening or closing devices, etc. The vlan_dev_hard_start_xmit function is mainly used to transmit network data packets to the hardware of the network device, so that these packets can be transmitted through the network, and the specific implementation process is: taking the device identifier as a virtual local area network tag (VLAN tag), adding a virtual local area network tag to the test packet. Configure the physical transmission port of the data packet under the virtual local area network; put the data packet into the network device queue and send it out by the physical transmission port.
[0040] Step S103, the test packet is sent to the target device, so that the target device judges whether the identifier contained in the intermediate packet is consistent with the device identifier, wherein the intermediate packet is the test packet received by the target device.
[0041] Specifically, the target device is, for example, a host device of the initial virtual local area network device or other network device containing the device identifier of the initial virtual local area network device, and the device identifier of the initial virtual local area network device is recorded in the host device.
[0042] When the test packet is sent, the address of the target device is set as the target address of the sending. After the target device receives the test packet, the target device receives the test packet as an intermediate packet. The identifier contained in the intermediate packet is extracted and compared with the device identifier of the initial virtual local area network device saved thereby.
[0043] Step S104, in the case that the target device does not receive the test packet, or the identifier contained in the intermediate packet is inconsistent with the device identifier, the resources occupied by the initial virtual local area network device are released.
[0044] Specifically, if the test packet is not transmitted successfully within a specified time, the unregister function of the network device in the kernel is called to release the resources and memory applied for by the initial virtual local area network device, and the device identifier in the real network device bound by the initial virtual local area network device is deleted. The unregister function is a function for unregistering or removing a certain resource or device from the system.
[0045] Step S105, in the case that the identifier contained in the intermediate packet is consistent with the device identifier, the initial virtual local area network device is set as the target virtual local area network device.
[0046] Specifically, if the test packet is successfully sent within a specified time, and the matching of the device identifier is successfully completed, the identifier contained in the intermediate packet is consistent with the device identifier, which indicates that the virtual local area network device is registered successfully, a signal that the virtual local area network device is registered successfully is returned, and the initial virtual local area network device is set as the target virtual local area network device.
[0047] It should be noted that the technical solution can be used to add virtual local area network devices in different protocols, and only the corresponding detection process needs to be modified, so that whether the physical transmission port can normally send and receive test packets of multiple protocols can be tested. In addition, a test function for the basic function of the device can be added when other devices are created, so as to ensure that the added device can complete the basic use.
[0048] The virtual local area network device registration method provided by the embodiment increases the test on whether the initial virtual local area network device can normally send and receive data packets. The device label is written in the test packet, the test packet is sent to the target device, and the target device is used to determine whether the identification in the received test packet is consistent with the device identification. Only when the two are consistent, it is determined that the virtual local area network device registration is successful. Otherwise, the memory and other resources applied by the virtual local area network device will be released, and the virtual local area network device that cannot be used will not be left in the kernel. It is ensured that the registered virtual local area network device can be normally used subsequently, and the resources occupied by the virtual local area network device that cannot be normally used are released in time. The problem that whether the virtual local area network device can be normally used cannot be determined, and the resources occupied by the virtual local area network device that cannot be normally used cannot be released in time is solved.
[0049] In some optional embodiments, sending the test packet to the target device comprises:
[0050] Determining a host device to which the initial virtual local area network device is bound;
[0051] Setting an address of the host device as a target address, wherein the target device comprises the host device;
[0052] Determining a physical transmission port by using a preset packet sending function, and putting the test packet into a network device queue, wherein the physical transmission port is used to send the test packet in the network device queue to the target address.
[0053] Specifically, a real physical device to which the initial virtual local area network device is bound, i.e., a host device, is determined. The target device comprises the host device, i.e., the target device can be the host device of the initial virtual local area network device, or other network device comprising the device identification of the initial virtual local area network device.
[0054] The preset packet sending function is, for example, a dev_direct_xmit function in the kernel. The dev_direct_xmit function is used to directly send a packet to a specified network device queue. The function usually directly submits the packet to the underlying hardware for transmission without the need for complex scheduling and queuing. The preset packet sending function is called to send the test packet configured. The destination address of the test packet is the real network device to which the virtual local area network device to be registered is bound, i.e., the address of the host device is set as the target address. It can be understood that the test packet is sent to the host device by the host device.
[0055] The physical transmission port is determined by using the preset packet sending function, and the test packet is put into the network device queue. The physical transmission port is used to send the test packet in the network device queue to the target address.
[0056] In the embodiment, the test message is put into the network device queue by using the preset message sending function, and the test message is sent to the target device through the physical transmission port. The target device judges whether the identifier contained in the intermediate message is consistent with the device identifier, and further determines whether the initial virtual local area network device is available, thereby avoiding the situation that the initial virtual local area network device which has been registered as a network device cannot be used but the memory and other resources occupied by the initial virtual local area network device cannot be released in time.
[0057] In some optional embodiments, after the test message is sent to the target device, the method further comprises:
[0058] monitoring the sending process of the test message by the physical transmission port within a preset time, and judging whether the test message is received by the target device within the preset time;
[0059] in the case that the test message is not received by the target device within the preset time, generating a first signal, wherein the first signal is used to represent that the test message is not received by the target device;
[0060] in the case that the test message is received by the target device within the preset time, comparing the identifier contained in the intermediate message with the device identifier, and generating a second signal or a third signal according to the comparison result, wherein the second signal is used to represent that the identifier contained in the intermediate message is inconsistent with the device identifier, and the third signal is used to represent that the identifier contained in the intermediate message is consistent with the device identifier.
[0061] Specifically, in the improved virtual local area network device registration method, whether the virtual local area network test data message is successfully sent by the physical transmission port is judged. After the virtual local area network test data message is configured, the test message is directly transmitted by using the physical transmission port, and the transmission process is monitored within a specified time. The preset time is, for example, 5 minutes, 10 minutes or other time meeting the actual demand. The sending process of the test message by the physical transmission port is monitored within the preset time, and whether the test message is received by the target device within the preset time is judged.
[0062] If the test message is not sent to the target device within the preset time, it is indicated that the initial virtual local area network device is not available, and a first signal, for example, a signal of virtual local area network device registration failure, is generated.
[0063] If the test message is successfully sent to the target device within the preset time, the identifier contained in the intermediate message is compared with the device identifier. If the identifier contained in the intermediate message is inconsistent with the device identifier, it is indicated that the initial virtual local area network device is not available, and a second signal, for example, a signal of virtual local area network device registration failure, is generated. If the identifier contained in the intermediate message is consistent with the device identifier, a third signal, for example, a signal of virtual local area network device registration success, is generated.
[0064] If the first signal or the second signal is generated, a unregister function of the network device in the kernel is called to release the resources and the memory applied by the virtual local area network device and to delete the device identifier of the real network device, and a dev_remove_pack interface of the kernel is called to delete the message type (text_pack_type) related to the virtual local area network test message in the protocol stack, and the dev_remove_pack interface is used to remove the text_pack_type from a packet processing chain table of the network protocol.
[0065] In the embodiment, whether the identifier contained in the intermediate message is consistent with the device identifier is determined by the target device, and then whether the initial virtual local area network device is available is determined, the second signal or the third signal is generated, and the situation that the initial virtual local area network device which has been registered as the network device cannot be used but the memory and other resources occupied by the initial virtual local area network device cannot be released in time is avoided.
[0066] In some optional embodiments, the comparison between the identifier contained in the intermediate message and the device identifier includes:
[0067] The message type corresponding to the intermediate message is determined by the host device, and the message processing function is determined according to the message type;
[0068] The identifier contained in the intermediate message is extracted from the intermediate message according to the message processing function;
[0069] The device identifier is obtained from the host device, and the identifier contained in the intermediate message is compared with the device identifier.
[0070] Specifically, after the memory resource application of the initial virtual local area network device, the initial virtual local area network device structure attribute configuration, and the binding process of the real network device and the initial virtual local area network device are completed, the test message related message type needs to be configured first, and the message processing function (test_func) is defined in the message type.
[0071] The intermediate message is, for example, the sk_buff (socket buffer) data received by the target device, and the sk_buff is a key data structure for managing and controlling network packets in the Linux kernel. The identifier contained in the intermediate message is extracted from the intermediate message according to the message processing function. The device identifier is obtained from the host device, and the identifier contained in the intermediate message is compared with the device identifier to determine whether the identifier in the received test message is consistent with the device identifier added when the message is sent.
[0072] In some optional embodiments, the initial virtual local area network device is registered, including:
[0073] The initial network device is created based on a preset structure, and the corresponding storage space is allocated for the initial network device;
[0074] determining an initialization function corresponding to the initial network device, and determining the device type of the initial network device by using the initialization function;
[0075] determining the running logic of the initial network device;
[0076] determining the device identification of the initial network device and the bound host device, recording the device identification to the host device, and recording the device identification and the information of the host device to the storage space;
[0077] registering the initial network device into the network device linked list of the kernel, and obtaining the initial virtual local area network device according to the initial network device, the storage space, the device type and the running logic.
[0078] Specifically, the virtual local area network device is a special network device in the Linux kernel, and before using the function of the virtual local area network device, the virtual local area network device needs to be created through ioctl and then operated. The virtual local area network device is created through ioctl operation.
[0079] First, a new network device structure is applied as a preset structure. The initial network device is created based on the preset structure, and a private space of the vlan_dev_priv type is allocated as the storage space for the initial network device. The initialization function of the initial network device is indicated, for example: the virtual local area network setting function. The vlan_dev_priv is a private data structure for managing the virtual network device in the Linux kernel, which contains various states and configuration information related to the virtual network device.
[0080] The device type of the initial network device is determined by using the initialization function, for example: the initialization function sets the function flag bit of the initial network device to a certain value, and in this way the device type is determined and the virtual local area network corresponding to the initial network device is defined to work based on the port. The running logic of the initial network device is determined, for example: the initial network device includes some operation functions, and through these operation functions, the running logic of various operations of the initial network device is realized, such as opening and closing the device, sending data packets, etc.
[0081] The device identification of the initial network device and the bound host device are determined, the storage space of the initial network device is modified, and the information of the host device of the initial network device and the device identification are recorded in the storage space. And the virtual local area network information in the host device is modified accordingly, and the device identification is recorded to the host device.
[0082] The initial network device is registered in a network device chain table in the kernel, and an initial virtual local area network device is obtained according to the initial network device, storage space, device type and running logic. At this time, the initial virtual local area network device is an actual device for the upper protocol stack, and has an equal status with all other devices, and can be configured by a command line tool or added to a bridge.
[0083] In addition, in order to successfully use the virtual local area network function in the Linux kernel, in addition to registering the virtual local area network device, the EMAC (Ethernet Media Access Controller) needs to support the virtual local area network function. The EMAC needs to edit the data packet and correctly add the device identifier according to the information of the private space of the virtual local area network device at the corresponding position of the Ethernet frame. The correctness of adding the virtual local area network device and the EMAC is a necessary condition for the normal use of the virtual local area network function.
[0084] In some optional embodiments, the resources occupied by the initial virtual local area network device are released, including:
[0085] The initial network device is removed from the network device chain table by using a resource release function in the kernel;
[0086] The resources corresponding to the preset structure, the device type, the running logic and the device identifier are released, and the storage space is released;
[0087] The initial virtual local area network device and the host device are unbound, and a preset interface of the kernel is called to delete the packet type corresponding to the test packet in the protocol stack.
[0088] Specifically, the resource release function is, for example, an unregister function of the network device in the kernel. If the test packet is not transmitted successfully within a specified time, or the identifier contained in the intermediate packet is inconsistent with the device identifier, it is determined that the registration of the initial virtual local area network device fails, and the resource release function in the kernel is called to release the resources and the memory applied by the virtual local area network device, and to delete the device identifier of the real network device, and the dev_remove_pack interface of the kernel is called to delete the VLAN test data packet type in the protocol stack. Specifically, the initial network device is removed from the network device chain table; the resources corresponding to the preset structure, the device type, the running logic and the device identifier are released, and the storage space is released; the initial virtual local area network device and the host device are unbound, and the preset interface of the kernel is called to delete the packet type corresponding to the test packet in the protocol stack.
[0089] In the embodiment, after it is determined that the initial virtual local area network device is unavailable, the resources occupied by the initial virtual local area network device are released in time, and no unusable virtual local area network device is left in the kernel.
[0090] In some optional embodiments, a test packet containing the device identifier is generated, including:
[0091] Obtaining a structure corresponding to the test packet;
[0092] Obtaining the device identifier from the storage space of the initial virtual local area network device;
[0093] Generating the marking information of the initial virtual local area network device according to the device identifier;
[0094] Adding the marking information to a preset position of the structure to generate the test packet.
[0095] Specifically, the structure of the test packet is generated, for example, a sk_buff structure, which is a basic unit of packet management in the Linux kernel. The structure defines a marked data frame, as shown in Figure 2 The unmarked frame is a normal data frame without a virtual local area network mark, and the marked frame is a data frame with a virtual local area network mark sent by the virtual local area network device. Compared with the unmarked data frame, the marked data frame adds a virtual local area network mark between the source media access control address and the type, and records the device identifier in the virtual local area network mark. Both the marked data frame and the unmarked data frame include a destination media access control address, a source media access control address, a type, a data payload, and a frame check sequence (FCS).
[0096] The device identifier is obtained from the storage space of the initial virtual local area network device. The marking information of the initial virtual local area network device is generated according to the device identifier, for example, the device identifier is taken as the marking information.
[0097] The preset position is, for example, the virtual local area network mark in the marked data frame. The marking information is added to the preset position of the structure to generate the test packet, for example, the virtual local area network mark is added to the sk_buff structure, that is, the device identifier of the virtual local area network device being registered is added to the corresponding position of the test packet.
[0098] In addition, when sending a packet through a network device under the kernel, the vlan_dev_hard_start_xmit function of the device is usually called, which is registered or specified in the initialization stage of the device. The ndo_start_xmit function is passed to the network device that has been registered in the kernel through vlan_netdev_ops. The specific implementation process is as follows: first, adding a virtual local area network mark to the data packet; configuring the physical transmission port of the data packet under the virtual local area network; and putting the data packet into the network device queue and sending it out by the physical transmission port.
[0099] In the embodiment, according to the device identifier, the marking information of the initial virtual local area network device is generated, the marking information is added to the preset position of the structure, and the test packet is generated. The device identifier of the initial virtual local area network device is added to the test packet, which facilitates the subsequent target device to determine whether the identifier in the received test packet is consistent with the test identifier, and to determine whether the function of the initial virtual local area network device is normal.
[0100] In some optional embodiments, after the virtual local area network device is successfully registered, the virtual local area network device can also be actively revoked or deleted, and the specific process can include steps A1 to A3.
[0101] Step A1, the access switch receives the offline notification sent by the virtual server.
[0102] Step A2, the access switch revokes the virtual local area network attribute of the virtual local area network device of the network side interface of the access switch according to the offline notification.
[0103] Step A3, the access switch sends a GVRP leave protocol packet (GVRP Leave packet, GVRP Leave Control Packet) to the aggregation switch through the network side interface.
[0104] Specifically, the access switch revoking the virtual local area network attribute of the network side interface of the access switch according to the offline notification includes: the access switch revokes the virtual local area network attribute of the user side interface which is the same as the virtual local area network attribute of the virtual server; traversing all user side interfaces of the access switch, determining whether there is a user side interface activating the virtual local area network attribute of the virtual server; if there is no user side interface activating the virtual local area network attribute of the virtual server, the access switch revokes the virtual local area network attribute of the network side interface which is the same as the virtual local area network attribute of the virtual server.
[0105] In the embodiment, by defining the interface type of the access switch, after receiving the offline notification of the virtual server, the diffusion behavior of the protocol packet and the revocation behavior of the virtual local area network attribute are controlled according to the interface type of the access switch, thereby reducing the maintenance cost and saving the network and server resources.
[0106] In some optional embodiments, another virtual local area network device registration method is provided, which can solve the same technical problems as steps S101 to S105, such as Figure 3 As shown in the figure, the method comprises:
[0107] checking a real network device; applying a virtual local area network device memory resource; connecting the virtual local area network device to the real network; configuring a virtual local area network device attribute; registering the virtual local area network device to a network device; joining the virtual local area network device to a virtual local area network group; creating a test message type; creating a test message processing function; creating a virtual local area network test data message; sending the virtual local area network test data message; judging whether a received virtual local area network identifier is consistent with a new virtual local area network device identifier; if not, deleting the new virtual local area network device in the network device and releasing the virtual local area network device memory resource; if yes, deleting the test message type; and completing the virtual local area network device registration.
[0108] In the embodiment, the existing virtual local area network device registration method is improved. After the virtual local area network device is registered, the transmission and reception test of the virtual local area network test data message through the physical transmission port is performed, so that once the virtual local area network device is registered, the virtual local area network device is available. The situation that the virtual local area network device can be successfully registered but cannot normally use the device to transmit and receive the virtual local area network data message in the existing virtual local area network device registration method is avoided, and the debugging cost of the virtual local area network function is reduced. After the improved virtual local area network device registration method is used, the virtual local area network device can be successfully registered only when it is ensured that the physical transmission port can successfully transmit and receive the virtual local area network message.
[0109] In the embodiment, a virtual local area network device registration apparatus is also provided, which is used to implement the above-described embodiments and preferred embodiments, and will not be described again. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the apparatus described in the following embodiments is preferably implemented in software, implementation in hardware or a combination of software and hardware is also possible and contemplated.
[0110] The embodiment provides a virtual local area network device registration apparatus, as shown in Figure 4 The apparatus comprises:
[0111] A registration module 401 is configured to register an initial virtual local area network device and determine a device identifier of the initial virtual local area network device.
[0112] A generation module 402 is configured to generate a test message containing the device identifier.
[0113] A sending module 403 is configured to send the test message to a target device, so that the target device judges whether an identifier contained in an intermediate message is consistent with the device identifier, wherein the intermediate message is the test message received by the target device.
[0114] The releasing module 404 is configured to release the resource occupied by the initial virtual local area network device in a case where the target device does not receive the test packet or the identifier contained in the intermediate packet is inconsistent with the device identifier.
[0115] The setting module 405 is configured to set the initial virtual local area network device as the target virtual local area network device in a case where the identifier contained in the intermediate packet is consistent with the device identifier.
[0116] In some optional embodiments, the sending module 403 includes:
[0117] The first determining unit is configured to determine a host device bound to the initial virtual local area network device.
[0118] The setting unit is configured to set an address of the host device as a target address, where the target device includes the host device.
[0119] The second determining unit is configured to determine a physical transmission port by using a preset packet sending function, and put the test packet into a network device queue, where the physical transmission port is used to send the test packet in the network device queue to the target address.
[0120] In some optional embodiments, the apparatus further includes:
[0121] The judging module is configured to monitor a sending process of the test packet by the physical transmission port within a preset time, and judge whether the target device receives the test packet within the preset time.
[0122] The first signal generating module is configured to generate a first signal in a case where the target device does not receive the test packet within the preset time, where the first signal is used to represent that the target device does not receive the test packet.
[0123] The second signal generating module is configured to compare the identifier contained in the intermediate packet with the device identifier in a case where the target device receives the test packet within the preset time, and generate a second signal or a third signal according to a comparison result, where the second signal is used to represent that the identifier contained in the intermediate packet is inconsistent with the device identifier, and the third signal is used to represent that the identifier contained in the intermediate packet is consistent with the device identifier.
[0124] In some optional embodiments, the second signal generating module includes:
[0125] The third determining unit is configured to determine a packet type corresponding to the intermediate packet by using the host device, and determine a packet processing function according to the packet type.
[0126] The extracting unit is configured to extract the identifier contained in the intermediate packet from the intermediate packet according to the packet processing function.
[0127] A comparison unit is configured to acquire a device identifier from the host device, and compare the identifier included in the intermediate message with the device identifier.
[0128] In some optional embodiments, the registration module 401 comprises:
[0129] A creation unit is configured to create an initial network device based on a preset structure, and allocate a corresponding storage space for the initial network device;
[0130] A fourth determination unit is configured to determine an initialization function corresponding to the initial network device, and determine a device type of the initial network device by using the initialization function;
[0131] A fifth determination unit is configured to determine a running logic of the initial network device;
[0132] A sixth determination unit is configured to determine a device identifier and a binding host device of the initial network device, record the device identifier to the host device, and record the device identifier and information of the host device to the storage space;
[0133] A registration unit is configured to register the initial network device into a network device linked list of the kernel, and obtain an initial virtual local area network device according to the initial network device, the storage space, the device type, and the running logic.
[0134] In some optional embodiments, the release module 404 comprises:
[0135] A first release unit is configured to remove the initial network device from the network device linked list by using a resource release function in the kernel;
[0136] A second release unit is configured to release resources corresponding to the preset structure, the device type, the running logic, and the device identifier, and release the storage space;
[0137] A third release unit is configured to unbind the initial virtual local area network device and the host device, and call a preset interface of the kernel to delete a message type corresponding to the test message in a protocol stack.
[0138] In some optional embodiments, the generation module 402 comprises:
[0139] A first acquisition unit is configured to acquire a structure corresponding to the test message;
[0140] A second acquisition unit is configured to acquire the device identifier from the storage space of the initial virtual local area network device;
[0141] A first generation unit is configured to generate marking information of the initial virtual local area network device according to the device identifier;
[0142] A second generation unit is configured to add the marking information to a preset position of the structure, and generate the test message.
[0143] Further functional descriptions of the above modules and units are the same as those in the corresponding embodiments described above, and will not be repeated here.
[0144] In this embodiment, the virtual LAN device registration device is presented in the form of a functional unit. Here, a unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that execute one or more software or fixed programs, and / or other devices that can provide the above functions.
[0145] This invention also provides a computer device having the above-described features. Figure 4 The virtual LAN device registration device shown.
[0146] Please see Figure 5 , Figure 5 This is a schematic diagram of the structure of a computer device provided in an optional embodiment of the present invention, such as... Figure 5 As shown, the computer device includes one or more processors 10, memory 20, and interfaces for connecting the components, including high-speed interfaces and low-speed interfaces. The components communicate with each other via different buses and can be mounted on a common motherboard or otherwise installed as needed. The processors can process instructions executed within the computer device, including instructions stored in or on memory to display graphical information of a GUI on external input / output devices (such as display devices coupled to the interfaces). In some alternative implementations, multiple processors and / or multiple buses can be used with multiple memories and multiple memory modules, if desired. Similarly, multiple computer devices can be connected, each providing some of the necessary operations (e.g., as a server array, a group of blade servers, or a multiprocessor system). Figure 5 Take a processor 10 as an example.
[0147] Processor 10 may be a central processing unit, a network processor, or a combination thereof. Processor 10 may further include an integrated circuit, a programmable logic device, or a combination thereof. The programmable logic device may be a complex programmable logic device, a field-programmable gate array (FPGA), a general-purpose array logic (GPA), or any combination thereof.
[0148] The memory 20 stores instructions executable by at least one processor 10 to cause at least one processor 10 to perform the method shown in the above embodiments.
[0149] The memory 20 can include a program storage area and a data storage area. The program storage area can store an operating system, application programs required for at least one function, etc. The data storage area can store data created by the computer device, etc. In addition, the memory 20 can include a high-speed random access memory, and can also include a non-transitory memory such as at least one disk storage device, a flash memory device, or other non-transitory solid state memory device. In some alternative embodiments, the memory 20 can optionally include memory that is remotely located with respect to the processor 10, and which can be connected to the computer device through a network. Examples of such networks include, but are not limited to, the Internet, an enterprise intranet, a local area network, a mobile communications network, and combinations thereof.
[0150] The memory 20 can include a volatile memory, such as a random access memory, and / or can include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid state memory device. The memory 20 can also include an array of memories of the same kind or of different kinds.
[0151] The computer device also includes a communications interface 30 for communicating with other devices or communications networks.
[0152] The embodiments of the present application also provide a computer non-volatile readable storage medium. The above-mentioned method according to the embodiments of the present application can be implemented in hardware, firmware, or recorded in a storage medium, or stored in a remote storage medium or a non-transitory machine readable storage medium and stored in a local storage medium by downloading through a network, so that the method described herein can be processed by such software on a storage medium using a general-purpose computer, a special-purpose processor, or programmable or special-purpose hardware. The storage medium can be a magnetic disk, an optical disk, a read-only memory, a random access memory, a flash memory, a hard disk, or a solid state disk, etc. Further, the storage medium can also include a combination of the above-mentioned kinds of memories. It can be understood that the computer, processor, microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code, when the software or computer code is accessed and executed by the computer, processor, or hardware, the method shown in the above embodiments is implemented.
[0153] Part of the present application can be applied as a computer program product, for example, computer program instructions, when executed by a computer, through the operation of the computer, the method and / or technical solutions according to the present application can be called or provided. Those skilled in the art should understand that the form of computer program instructions in computer readable medium includes but is not limited to source file, executable file, installation package file and the like, and accordingly, the way of computer program instructions executed by computer includes but is not limited to: the computer directly executes the instructions, or the computer compiles the instructions and then executes the corresponding compiled program, or the computer reads and executes the instructions, or the computer reads and installs the instructions and then executes the corresponding installed program. Here, the computer readable medium can be any available computer non-volatile readable storage medium or communication medium accessible to the computer.
[0154] Although the embodiments of the present application are described in conjunction with the drawings, various modifications and changes can be made by those skilled in the art without departing from the spirit and scope of the present application, and such modifications and changes fall within the scope defined by the present application.
Claims
1. A method for registering a virtual local area network (VLAN) device, characterized in that, The method comprises: registering an initial virtual local area network device and determining a device identifier of the initial virtual local area network device; generating a test packet containing the device identifier; sending the test packet to a target device to enable the target device to determine whether an identifier contained in an intermediate packet received by the target device is consistent with the device identifier, wherein the intermediate packet is the test packet received by the target device; releasing resources occupied by the initial virtual local area network device in a case where the target device does not receive the test packet or the identifier contained in the intermediate packet is inconsistent with the device identifier; setting the initial virtual local area network device as a target virtual local area network device in a case where the identifier contained in the intermediate packet is consistent with the device identifier.
2. The method of claim 1, wherein, The sending of the test packet to the target device comprises: determining a host device bound to the initial virtual local area network device; setting an address of the host device as a target address, wherein the target device comprises the host device; determining a physical transmission port by using a preset packet sending function and putting the test packet into a network device queue, wherein the physical transmission port is used to send the test packet in the network device queue to the target address.
3. The method of claim 2, wherein, After the sending of the test packet to the target device, the method further comprises: monitoring a sending process of the test packet by the physical transmission port within a preset time to determine whether the target device receives the test packet within the preset time; generating a first signal in a case where the target device does not receive the test packet within the preset time, wherein the first signal is used to represent that the target device does not receive the test packet; comparing the identifier contained in the intermediate packet with the device identifier in a case where the target device receives the test packet within the preset time and generating a second signal or a third signal according to a comparison result, wherein the second signal is used to represent that the identifier contained in the intermediate packet is inconsistent with the device identifier and the third signal is used to represent that the identifier contained in the intermediate packet is consistent with the device identifier.
4. The method of claim 3, wherein, The comparison of the identifier contained in the intermediate packet with the device identifier comprises: determining a packet type corresponding to the intermediate packet by using the host device and determining a packet processing function according to the packet type; extracting the identifier contained in the intermediate packet from the intermediate packet according to the packet processing function; obtaining the device identifier from the host device and comparing the identifier contained in the intermediate packet with the device identifier.
5. The method of claim 1, wherein, The registration of the initial virtual local area network device comprises: creating an initial network device based on a preset structure and allocating a corresponding storage space to the initial network device; determining an initialization function corresponding to the initial network device and determining a device type of the initial network device by using the initialization function; determining a running logic of the initial network device; determining a device identifier and a bound host device of the initial network device, recording the device identifier to the host device, and recording the device identifier and information of the host device to the storage space; registering the initial network device into a network device linked list of a kernel, and obtaining the initial virtual local area network device according to the initial network device, the storage space, the device type, and the running logic.
6. The method of claim 5, wherein, the releasing of the resources occupied by the initial virtual local area network device includes: removing the initial network device from the network device linked list by using a resource releasing function in the kernel; releasing the resources corresponding to the preset structure, the device type, the running logic, and the device identifier, and releasing the storage space; unbinding the initial virtual local area network device and the host device, and calling a preset interface of the kernel to delete a message type corresponding to the test message in a protocol stack.
7. The method of claim 5, wherein, the generating of the test message containing the device identifier includes: obtaining a structure corresponding to the test message; obtaining the device identifier from the storage space of the initial virtual local area network device; generating marking information of the initial virtual local area network device according to the device identifier; adding the marking information to a preset position of the structure to generate the test message.
8. A virtual local area network device registration apparatus, characterized by comprising: the apparatus includes: a registration module configured to register an initial virtual local area network device and determine a device identifier of the initial virtual local area network device; a generation module configured to generate a test message containing the device identifier; a sending module configured to send the test message to a target device, so that the target device judges whether an identifier contained in an intermediate message is consistent with the device identifier, wherein the intermediate message is a test message received by the target device; a releasing module configured to release resources occupied by the initial virtual local area network device in a case that the target device does not receive the test message, or the identifier contained in the intermediate message is not consistent with the device identifier; a setting module configured to set the initial virtual local area network device as a target virtual local area network device in a case that the identifier contained in the intermediate message is consistent with the device identifier.
9. A computer device, comprising: include: a memory and a processor, which are communicatively connected, and the memory stores computer instructions, and the processor executes the computer instructions to perform the virtual local area network device registration method in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, the computer readable storage medium stores computer instructions, and the computer instructions are used to make a computer execute the virtual local area network device registration method in any one of claims 1 to 7.
Citation Information
Patent Citations
Network testing method, computer equipment, network equipment and readable storage medium
CN116886584A
Locating virtual machine(s) within virtual networks
US20160352579A1