A network card interface renaming method and device, electronic equipment and storage medium
By extracting the target PCIe information from the PCIe information of the network device to generate a row-based PCIe sequence, and determining the network card interface name based on the naming configuration file, the problem of inaccurate interface renaming caused by network card changes is solved, achieving accurate renaming when the network card is changed, and improving the communication security and reliability of the network device.
Patent Information
- Application Number
- CN202311354130.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-18
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2043-10-18
AI Technical Summary
When adding or replacing network cards within network devices, changes to the MAC address of the network card can lead to inaccurate renaming of the network card interface, making it difficult to effectively guarantee communication security and reliability.
By extracting the target PCIe information of all network cards from the PCIe information of network devices, a row-based PCIe sequence is generated, and the target interface name of each network card is determined based on a predefined naming configuration file, ensuring accurate renaming when the network card is changed.
In the event of a network interface card (NIC) change, it can effectively and accurately rename the NIC interface, improving the efficiency and accuracy of NIC interface renaming and ensuring the communication security and reliability of network devices.
Smart Images

Figure CN117407351B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and more specifically, to a method, apparatus, electronic device, and storage medium for renaming network interface cards (NICs). Background Technology
[0002] With the rapid development of computer technology, network devices often have at least one network interface card (NIC) inside. These NICs connect to various external networks through their interfaces to communicate with them. To ensure the security and reliability of communication between the network device and these external networks, the network device is required to rename the interfaces of each NIC during system startup and connect those interfaces to their corresponding external networks based on the new interface names.
[0003] Traditional methods for renaming network interface cards (NICs) rely on the mapping between the NIC's MAC (Media Access Control) address and its new interface name. This ensures that the interface name remains consistent after a system reboot. However, in practice, when a new NIC is added or replaced within a network device, the NIC's MAC address may change, leading to incorrect acquisition of the new interface name and making it difficult to rename NICs effectively and accurately. Summary of the Invention
[0004] The purpose of this invention is to provide a method, apparatus, electronic device, and storage medium for renaming network interface cards (NICs), so as to achieve the technical effect of effectively and accurately renaming NIC interfaces when adding or replacing NICs within a network device.
[0005] In a first aspect, embodiments of the present invention provide a method for renaming a network interface card (NIC), comprising:
[0006] Extract the target PCIe information of all network cards from the PCIe information of the network devices, and generate a row-style PCIe sequence by combining the target PCIe information of all network cards.
[0007] Based on a predefined naming configuration file, the target interface name of each network card is determined according to the row-style PCIe sequence;
[0008] Modify the interface name of each network card to the target interface name of each network card.
[0009] In the above implementation process, a row-type PCIe sequence is generated by extracting the target PCIe information of all network cards from the PCIe information of the network device. The network cards on the PCIe bus are determined based on the unchanging row-type PCIe sequence. Then, the unique target interface name of each network card is determined based on the naming configuration file. When any network card on the PCIe bus is changed, the target interface name of each network card can be accurately determined and renamed. Thus, even when a network card is added or replaced inside the network device, the network card interface can still be renamed effectively and accurately.
[0010] Furthermore, before extracting the target PCIe information of all network cards from the PCIe information of the network device, the method further includes:
[0011] Execute a bus device information query command on the network device to read the PCIE information.
[0012] In the above implementation process, by executing the bus device information query command on the network device and reading the PCIe information, it is possible to fully read all device information on the PCIe bus of the network device.
[0013] Furthermore, before extracting the target PCIe information of all network cards from the PCIe information of the network device, the method further includes:
[0014] Determine whether the PCIE information is network card information. If the PCIE information is network card information, extract the target PCIE information of all network cards from the PCIE information.
[0015] In the above implementation process, by first determining whether the PCIe information is network card information, and then extracting the target PCIe information of all network cards from the PCIe information only when the PCIe information is determined to be network card information, it is possible to avoid continuing to extract the target PCIe information of all network cards from the PCIe information when there is no network card on the PCIe bus, thereby reducing invalid operations and improving the efficiency of network card interface renaming.
[0016] Further, the step of extracting the target PCIe information of all network cards from the PCIe information of the network device, and generating a row-based PCIe sequence by combining the target PCIe information of all the network cards, specifically includes:
[0017] The basic network card information and mapped address information of each network card are extracted from the PCIE information to obtain the target PCIE information of all network cards.
[0018] For each network interface card (NIC), the basic information of the NIC and the mapped address information of the NIC are concatenated according to a preset sequence format to obtain the sequence information of the NIC;
[0019] Combine the sequence information of all the network cards to generate the row-type PCIe sequence.
[0020] In the above implementation process, by concatenating the basic network card information and mapping address information of each network card into sequence information according to a unified preset sequence format, and combining the sequence information of all network cards to generate a row-type PCIe sequence, the format of the sequence information of each network card in the row-type PCIe sequence can be kept consistent, which facilitates the rapid determination of all network cards on the PCIe bus according to the row-type PCIe sequence and helps to improve the efficiency of network card interface renaming.
[0021] Further, the preset sequence format is [the basic information of the network card, the mapping address information of the network card]; wherein, the basic information of the network card is (the bus where the network card is located - the domain where the network card is located - all ancestor nodes of the node where the network card is located - the serial number of the network card), and the mapping address information of the network card is (the mapping address number of the network card: the serial number of the network card).
[0022] In the above implementation process, by pre-setting the preset sequence format as [(the bus where the network card is located - the domain where the network card is located - all ancestor nodes of the node where the network card is located - the serial number of the network card), (the mapped address number of the network card: the serial number of the network card)], the format of the sequence information of each network card in the row PCIe sequence can be kept consistent, which makes it convenient to quickly determine all network cards on the PCIe bus according to the row PCIe sequence and improves the efficiency of renaming network card interfaces.
[0023] Furthermore, determining the target interface name of each network card based on the predefined naming configuration file and the row-style PCIe sequence specifically includes:
[0024] For each network interface card (NIC), the basic information of the NIC associated with the mapping address information in the row-type PCIe sequence is determined based on the mapping address information of the NIC.
[0025] Based on the basic information of the network card, identify the network card and determine whether the network device has the slot identification information of the network card;
[0026] When the network device has the slot identification information of the network card, the interface name corresponding to the basic information of the network card in the naming configuration file is determined as the target interface name of the network card.
[0027] In the above implementation process, by determining each network card on the PCIe bus according to the row PCIe sequence, and then, when the network device has network card slot identification information, searching for the target network card name corresponding to each network card in the naming configuration file, the target interface name of each network card can be quickly determined, which is beneficial to improving the renaming efficiency of network card interfaces.
[0028] Furthermore, the step of determining the target interface name of each network card based on a predefined naming configuration file and the row-style PCIe sequence specifically includes:
[0029] When the network device does not have the slot identification information of the network card, the interface name corresponding to the basic information of the network card in the default naming configuration file is determined as the target interface name of the network card; wherein, the default naming configuration file is generated in response to the naming configuration file supplementation request initiated by the user terminal for the row PCIe sequence.
[0030] In the above implementation process, by determining each network card on the PCIe bus according to the row-type PCIe sequence, and then searching for the target network card name corresponding to each network card from the user-configured default naming configuration file when the network device does not have network card slot identification information, the target interface name of each network card can be quickly determined, while ensuring that the target interface names of all network cards are completely determined, which helps to improve the efficiency of network card interface renaming.
[0031] Furthermore, the network interface renaming method further includes:
[0032] In response to a user terminal's request for a custom naming configuration file for the row-type PCIe sequence, a custom naming configuration file is generated.
[0033] Based on the custom naming configuration file, the target interface name of each network card is determined according to the row-style PCIe sequence.
[0034] In the above implementation process, the target interface name of each network card is determined by a user-configured custom naming configuration file, which can adapt to various application requirements for renaming network card interfaces.
[0035] Furthermore, before modifying the interface name of each network interface card to the target interface name of each network interface card, the method further includes:
[0036] Check the format of the target interface name of each network card. If the format of the target interface name of all network cards is correct, modify the interface name of each network card accordingly to the target interface name of each network card.
[0037] In the above implementation process, by first checking the format of the target interface name of all network cards, and then only modifying the interface name of each network card to the target interface name of each network card when the format of the target interface name of all network cards is correct, it is possible to further ensure that the interface name of each network card is accurately modified to the target interface name of each network card, which is conducive to improving the efficiency of renaming network card interfaces.
[0038] In a second aspect, embodiments of the present invention provide a network interface card renaming device, comprising:
[0039] The row PCIe sequence generation module is used to extract the target PCIe information of all network cards from the PCIe information of the network device, and combine the target PCIe information of all the network cards to generate a row PCIe sequence.
[0040] The network interface name determination module is used to determine the target interface name of each network card based on a predefined naming configuration file and the row-format PCIe sequence.
[0041] The network interface name modification module is used to modify the interface name of each network card to the target interface name of each network card.
[0042] Thirdly, embodiments of the present invention provide an electronic device including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor; the memory is coupled to the processor, and the processor implements the network interface renaming method as described above when executing the computer program.
[0043] Fourthly, embodiments of the present invention provide a computer-readable storage medium, the computer-readable storage medium including a stored computer program; wherein, when the computer program is executed, it controls the device where the computer-readable storage medium is located to execute the network interface renaming method described above. Attached Figure Description
[0044] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments of the present invention will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0045] Figure 1 This is a flowchart illustrating a network interface renaming method provided in the first embodiment of the present invention;
[0046] Figure 2This is a schematic diagram of PCIE information as an example of an optional embodiment of the first embodiment of the present invention;
[0047] Figure 3 This is a schematic diagram of PCIe information, representing another example of an optional embodiment of the first embodiment of the present invention.
[0048] Figure 4 This is a schematic diagram of a network card interface renaming device provided in the second embodiment of the present invention;
[0049] Figure 5 This is a schematic diagram of the structure of an electronic device provided in the third embodiment of the present invention. Detailed Implementation
[0050] The technical solutions of the present invention will now be described with reference to the accompanying drawings in the embodiments of the present invention.
[0051] It should be noted that in the description of this invention, the terms "first," "second," etc., are used only for distinguishing descriptions and should not be construed as indicating or implying relative importance. Furthermore, the step numbers in the text are only for the convenience of explaining the embodiments of this invention and are not intended to limit the order in which the steps are executed. The method provided in the embodiments of this invention can be executed by relevant terminal devices, and the following description uses a processor as the execution subject.
[0052] Please refer to Figure 1 , Figure 1 This is a flowchart illustrating a network interface renaming method according to a first embodiment of the present invention. The first embodiment of the present invention provides a network interface renaming method, including steps S101 to S103:
[0053] S101. Extract the target PCIe information of all network cards from the PCIe information of the network devices, and generate a row-style PCIe sequence by combining the target PCIe information of all network cards.
[0054] S102. Based on a predefined naming configuration file, determine the target interface name of each network card according to the row-style PCIe sequence;
[0055] S103. Modify the interface name of each network card to the target interface name of each network card.
[0056] For example, a Network Interface Controller (NIC), also known as a network adapter or network interface card, is a piece of computer hardware designed to allow computers to communicate on a computer network. The PCI (Peripheral Component Interconnect) bus is a local parallel bus in computers, while the PCIE (Peripheral Component Interconnect Express) bus is a high-speed serial computer expansion bus. A NIC can connect to the computer motherboard via the PCI bus or the newer PCIE bus, and is responsible for converting the data to be transmitted by the user into a format that other devices on the network can recognize, and then transmitting it through the network medium.
[0057] In scenarios where the network card is connected to the network device via the network device's PCIe bus, the PCIe information of the network device is read. The network device can be an industrial control computer, server, or other network device, and the PCIe information includes information about all devices on the PCIe bus. For example, if there are 10 Gigabit Ethernet cards, Gigabit Ethernet cards, and other devices on the PCIe bus, the PCIe information includes detailed information about all network cards on the PCIe bus, as well as detailed information about the other devices.
[0058] Extract the target PCIe information for all network cards from the PCIe information. For example, if there are only two network cards on the PCIe bus, a 10 Gigabit network card and a 1 Gigabit network card, extract key information from the PCIe information that does not change with network card changes, such as the basic network card information of the 10 Gigabit network card, and its mapped address information as the target PCIe information. Similarly, extract key information from the PCIe information that does not change with network card changes, such as the basic network card information of the 1 Gigabit network card, and its mapped address information as the target PCIe information. Combine the target PCIe information of all network cards to generate a row-based PCIe sequence.
[0059] Because the row-type PCIe sequence does not change with any network card change, all network cards on the PCIe bus can still be accurately identified based on the row-type PCIe sequence even if any network card on the PCIe bus is changed.
[0060] Considering practical application requirements and the interface specifications of network devices connecting to network interface cards (NICs), a naming configuration file is predefined. This configuration file contains a one-to-one correspondence between at least one NIC and at least one target interface name. Based on the row-format PCIe sequence, each NIC on the PCIe bus is identified, and then the target NIC name corresponding to each NIC is retrieved from the naming configuration file to determine the target interface name of each NIC.
[0061] When determining the target interface name of each network card on the PCIe bus, modify the interface name of each network card accordingly to the target interface name of each network card, thus completing the renaming of the network card interface.
[0062] This invention generates a row-type PCIe sequence by extracting the target PCIe information of all network cards from the PCIe information of the network device. Based on the unchanging row-type PCIe sequence, it determines each network card on the PCIe bus, and then determines the unique target interface name of each network card based on the naming configuration file. This enables accurate determination and renaming of the target interface name of each network card when any network card on the PCIe bus is changed, thus achieving effective and accurate renaming of network card interfaces even when a network card is added or replaced within the network device.
[0063] In an optional embodiment, before extracting the target PCIe information of all network cards from the PCIe information of the network device, the method further includes: executing a bus device information query command on the network device to read the PCIe information.
[0064] As an example, a bus device information query command is executed on the network device to read the PCIe information of the network device so that the target PCIe information of all network cards can be extracted from the PCIe information in the future.
[0065] For example, when the network device's internal system is Linux (an operating system), the command to query bus device information can be either `lspci`, a Linux command used to display all bus devices in the Linux system or all devices connected to that bus, or `lspci-vt`, another Linux command used to display a tree structure of all bus devices in the Linux system or all devices connected to that bus. Executing either the `lspci` or `lspci-vt` command on the network device will read its PCIe information.
[0066] Although the DPDK (Data Plane Development Kit) can also read the PCIe information of network devices, the PCIe information read by the DPDK only includes the mapped address of the node where the network card is located. The mapped address of the node where the network card is located may change as the network card is changed, so it is not suitable as a basis for renaming the network card interface.
[0067] This invention enables the comprehensive reading of all device information on the PCIe bus of a network device by executing a bus device information query command on the network device and reading PCIe information.
[0068] In an optional embodiment, before extracting the target PCIe information of all network cards from the PCIe information of the network device, the method further includes: determining whether the PCIe information is network card information, so that when the PCIe information is network card information, the target PCIe information of all network cards is extracted from the PCIe information.
[0069] As an example, when reading the PCIe information of a network device, it is determined whether the PCIe information is network card information. If the PCIe information is network card information, it is assumed that there is a network card on the PCIe bus. The basic network card information, mapping address information, and other key information that is not easily changed with changes in the network card are extracted from the PCIe information as its target PCIe information. If the PCIe information is not network card information, it is assumed that there is no network card on the PCIe bus, and the extraction of target PCIe information for all network cards from the PCIe information is stopped.
[0070] For example, you can obtain the PCI information contained in the PCIe information structure pci_dev, determine the category of the PCI information, and if the category of the PCI information is PCI_CLASS_NETWORK_ETHERNET, then the PCIe information is determined to be network card information; otherwise, the PCIe information is determined not to be network card information.
[0071] This invention, by first determining whether the PCIe information is network card information, and then extracting the target PCIe information of all network cards from the PCIe information only when the PCIe information is determined to be network card information, can avoid continuing to extract the target PCIe information of all network cards from the PCIe information when there is no network card on the PCIe bus, reduce invalid operations, and help improve the efficiency of network card interface renaming.
[0072] In an optional embodiment, the step of extracting the target PCIe information of all network cards from the PCIe information of the network device and generating a row-type PCIe sequence by combining the target PCIe information of all network cards specifically includes: extracting the basic network card information and mapped address information of each network card from the PCIe information as target PCIe information to obtain the target PCIe information of all network cards; for each network card, concatenating the basic network card information and mapped address information of the network card according to a preset sequence format to obtain the sequence information of the network card; and combining the sequence information of all network cards to generate a row-type PCIe sequence.
[0073] As an example, when the PCIe information of a network device is read, all network cards on the PCIe bus can be determined based on the PCIe information. For each network card, the basic network card information and mapped address information of that network card are extracted from the PCIe information as target PCIe information, thus obtaining the target PCIe information of that network card, and thereby obtaining the target PCIe information of all network cards.
[0074] Considering practical application requirements, a preset sequence format is set in advance. When the target PCIe information of all network cards is obtained, for each network card, the basic network card information and mapped address information of that network card are concatenated according to the preset sequence format to obtain the sequence information of that network card, thereby obtaining the sequence information of all network cards.
[0075] When the sequence information of all network cards is obtained, the sequence information of one network card is used as a row of data, and the sequence information of all network cards is combined to generate a row-based PCIe sequence.
[0076] This invention, by using a unified preset sequence format, concatenates the basic network card information and mapped address information of each network card into sequence information, and combines the sequence information of all network cards to generate a row-type PCIe sequence. This ensures that the format of the sequence information of each network card in the row-type PCIe sequence is consistent, which facilitates the rapid determination of all network cards on the PCIe bus based on the row-type PCIe sequence and improves the efficiency of network card interface renaming.
[0077] In an optional embodiment, the preset sequence format is [network card basic information, network card mapping address information]; wherein, the network card basic information is (the bus where the network card is located - the domain where the network card is located - all ancestor nodes of the node where the network card is located - the serial number of the network card), and the network card mapping address information is (network card mapping address number: network card serial number).
[0078] As an example, for each network interface card (NIC), the following information is extracted from the PCIe information: the bus where the NIC is located, the domain where the NIC is located, all ancestor nodes of the node where the NIC is located, the NIC's serial number, and the NIC's mapped address number. This information is then combined with the NIC's bus, domain, all ancestor nodes of the node where the NIC is located, and the NIC's serial number to obtain the NIC's basic information, which is (the NIC's bus - the NIC's domain - all ancestor nodes of the node where the NIC is located - the NIC's serial number). Finally, the NIC's mapped address information is obtained by combining the NIC's mapped address number and the NIC's serial number, which is (the NIC's mapped address number: the NIC's serial number). This process yields the NIC's basic information and mapped address information for all NICs.
[0079] For example, suppose the PCIe information read by executing the lspci -vt command on a network device is as follows: Figure 2 As shown, Figure 2 The PCIe information is in a tree structure. Figure 2 In the PCIE information shown, [0000:16]02.0-
[17] displays the detailed information of the 10 Gigabit network card, and [0000:e2]04.0-[e4] displays the detailed information of the gigabit network card. 02.0-
[17] is the address of the parent node of the node where the 10 Gigabit network card is located, and 04.0-[e4] is the address of the parent node of the node where the gigabit network card is located. The 17 in
[17] is the externally mapped address used by the parent node of the node where the 10 Gigabit network card is located, and the e4 in [e4] is the externally mapped address used by the parent node of the node where the gigabit network card is located. After analysis Figure 2 The PCIe information shown indicates that there are two network cards on the PCIe bus: a 10 Gigabit Ethernet card and a 1 Gigabit Ethernet card. The detailed information of these two network cards is stored in the second layer of the PCIe information structure.
[0080] As the network interface card (NIC) changes, the mapping addresses of all ancestor nodes, such as the parent node and the parent node's parent node, of the node where the NIC resides will not change unless the BIOS (Basic Input Output System) firmware of the network device is reflashed.
[0081] from Figure 2 The PCIe information shown extracts information about the 10 Gigabit Ethernet card: its bus is 0000, its domain is 16, its parent node is 02.0, its serial numbers are 00.0 and 00.1, and its mapped address is 17. This yields two sets of target PCIe information for the 10 Gigabit Ethernet card. One set contains the following information: basic network card information is 0000-16-02.0-00.0, and its mapped address is 17:00.0. The other set contains the following information: basic network card information is 0000-16-02.0-00.1, and its mapped address is 17:00.1. And from... Figure 2The PCIe information shown extracts information about gigabit network cards. The gigabit network card resides on bus 0000, in domain e2, and its parent node is 04.0. The serial numbers of the gigabit network card are 00.0, 00.1, 00.2, and 00.3, and its mapped address is e4. This yields four sets of target PCIe information for gigabit network cards. One set of target PCIe information for a gigabit network card includes: basic network card information 0000-e2-04.0-00.0, and mapped address information e4:00.0. The target PCIe interfaces are as follows: The basic information of the gigabit network card is 0000-e2-04.0-00.1, and the mapped address information is e4:00.1. The target PCIe interfaces for another group of gigabit network cards are: The basic information of the gigabit network card is 0000-e2-04.0-00.2, and the mapped address information is e4:00.2. The target PCIe interfaces for the last group of gigabit network cards are: The basic information of the gigabit network card is 0000-e2-04.0-00.3, and the mapped address information is e4:00.3.
[0082] When obtaining the basic network interface card (NIC) information and mapped address information for all NICs, for each NIC, the basic NIC information and mapped address information are concatenated according to a preset sequence format to obtain the sequence information of the NIC. The sequence information of the NIC is [the basic NIC information, the mapped address information], which is [(the bus where the NIC is located - the domain where the NIC is located - all ancestor nodes of the node where the NIC is located - the serial number of the NIC), (the mapped address number of the NIC: the serial number of the NIC)]. Thus, the sequence information of all NICs is obtained.
[0083] In the preset sequence format [network card basic information, network card mapping address information], the comma "," is mainly used to separate the network card basic information and the mapping address information. It can also be replaced with other separators such as "#" or " / ".
[0084] When the sequence information of all network cards is obtained, the sequence information of one network card is used as a row of data, and the sequence information of all network cards is combined to generate a row-based PCIe sequence.
[0085] For example, based on Figure 2 The row-based PCIe sequence generated from the PCIe information shown is as follows:
[0086] "0000-16-02.0-00.0#17:00.0"
[0087] 0000-16-02.0-00.1#17:00.1
[0088] 0000-e2-04.0-00.0#e4:00.0
[0089] 0000-e2-04.0-00.1#e4:00.1
[0090] 0000-e2-04.0-00.2#e4:00.2
[0091] 0000-e2-04.0-00.3#e4:00.3".
[0092] Figure 2 The structure of the PCIe information shown is relatively simple. In practical applications, the structure of the PCIe information read may be more complex. For example, there may be multiple network cards on the PCIe bus, and the detailed information of each network card may be stored at any level of the PCIe information structure, with varying hierarchical structures among the network cards. To address this, a row-based PCIe sequence can be generated by retaining all ancestor nodes, such as the parent node and the parent's parent node, of the network card's basic information, and by retaining only the first sequence number of the mapped address used externally by the last-level parent node of the network card's node in the network card's mapped address information.
[0093] For example, suppose the PCIe information read is as follows Figure 3 As shown, Figure 3 The PCIe information is also in a tree structure. Analysis... Figure 3 The PCIe information shown indicates that there are four network cards on the PCIe bus. The detailed information of the first, second, and third network cards is stored in the third layer of the PCIe information, while the detailed information of the fourth network card is stored in the first layer of the PCIe information.
[0094] from Figure 3 The PCIe information shown extracts information about the first network interface card (NIC), including its bus (0000), domain (00), first-level parent node (00.0), second-level parent node (00.0), and last-level parent node (01.0). The NIC's serial numbers are 00.0 and 00.1. The first serial number in the mapped address used by the last-level parent node of the first NIC is 03. This yields two sets of target PCIe information for the first NIC. The information provided includes two sets of target PCIe information for the first network card: Basic network card information: 0000-00-00.0-00.0-01.0-00.0; Mapped address information: 03:00.0. The other set of target PCIe information for the first network card includes: Basic network card information: 0000-00-00.0-00.0-01.0-00.1; Mapped address information: 03:00.1. Following this procedure will yield the basic network card information and mapped address information for all four network cards.
[0095] When the basic information and mapping address information of the four network cards are obtained, for each network card, the basic information and mapping address information of the network card are concatenated according to a preset sequence format to obtain the sequence information of the network card. The sequence information of the network card is [(the bus where the network card is located - the domain where the network card is located - all ancestor nodes of the node where the network card is located - the serial number of the network card), (the mapping address number of the network card: the serial number of the network card)], thus obtaining the sequence information of the four network cards.
[0096] When the sequence information of the four network interface cards (NICs) is obtained, the sequence information of one NIC is used as a row of data, and the sequence information of the four NICs is combined to generate a row-based PCIe sequence. Based on Figure 3 The row-based PCIe sequence generated from the PCIe information shown is as follows:
[0097] "0000-00-00.0-00.0-01.0-00.0#03:00.0
[0098] 0000-00-00.0-00.0-01.0-00.1#03:00.1
[0099] 0000-00-00.0-00.0-09.0-00.0#06:00.0
[0100] 0000-00-00.0-00.0-09.0-00.1#06:00.1
[0101] 0000-00-01.0-00.0-08.0-00.0#14:00.0
[0102] 0000-00-01.0-00.0-08.0-00.1#14:00.1
[0103] 0000-00-04.0-00.0#1b:00.0
[0104] 0000-00-04.0-00.1#1b:00.1”.
[0105] This invention, by pre-setting a preset sequence format as [(the bus where the network card is located - the domain where the network card is located - all ancestor nodes of the node where the network card is located - the serial number of the network card), (the mapped address number of the network card: the serial number of the network card)], can ensure that the format of the sequence information of each network card in the row-type PCIe sequence is consistent, which facilitates the rapid determination of all network cards on the PCIe bus according to the row-type PCIe sequence and helps to improve the efficiency of network card interface renaming.
[0106] In an optional embodiment, the preset sequence format is [network card basic information, network card mapping address information, network card manufacturing information, network card location information]; wherein, the network card basic information is (the bus where the network card is located - the domain where the network card is located - all ancestor nodes of the node where the network card is located - the network card serial number), the network card mapping address information is (the network card mapping address sequence number: the network card serial number), the network card manufacturing information is (the network card manufacturer code: the network card identifier ID), and the network card location information is (the network card slot number: the node to which the network card belongs).
[0107] As an example, considering actual application requirements, for each network interface card (NIC), the manufacturer code, identifier ID, slot number, and node to which the NIC belongs can be extracted from the PCIe information. Combining the manufacturer code and identifier ID, the manufacturing information of the NIC is obtained as (the manufacturer code of the NIC: the identifier ID of the NIC). Combining the slot number and node to which the NIC belongs, the location information of the NIC is obtained as (the slot number of the NIC: the node to which the NIC belongs). Thus, the basic information, mapped address information, manufacturing information, and location information of all NICs are obtained.
[0108] When obtaining the basic network interface card (NIC), mapped address information, manufacturing information, and location information of all NICs, for each NIC, the basic NIC information, mapped address information, manufacturing information, and location information of that NIC are concatenated according to a preset sequence format to obtain the sequence information of that NIC. The sequence information of that NIC is [the basic NIC information, the mapped address information, the manufacturing information, and the location information of the NIC], which is [(the bus where the NIC is located - the domain where the NIC is located - all ancestor nodes of the node where the NIC is located - the serial number of the NIC), (the mapped address number of the NIC: the serial number of the NIC), (the manufacturer code of the NIC: the identifier ID of the NIC), (the slot number where the NIC is located: the node to which the NIC belongs)]. Thus, the sequence information of all NICs is obtained.
[0109] When the sequence information of all network cards is obtained, the sequence information of one network card is used as a row of data, and the sequence information of all network cards is combined to generate a row-based PCIe sequence.
[0110] This invention enriches the information within the row-format PCIe sequence by adding network card manufacturing and location information to the preset sequence format, providing more reference for renaming network card interfaces and improving the efficiency of network card interface renaming.
[0111] In an optional embodiment, the step of determining the target interface name of each network card based on a predefined naming configuration file and a row-type PCIe sequence specifically includes: for each network card, determining the basic network card information associated with the mapping address information in the row-type PCIe sequence based on the network card's mapping address information; determining the network card based on the basic network card information and determining whether the network device has network card slot identification information; when the network device has network card slot identification information, determining the interface name corresponding to the basic network card information in the naming configuration file as the target interface name of the network card.
[0112] As an example, network devices such as industrial control computers (ICS) typically have network interface card (NIC) slot identification information. For instance, an ICS specifies that a gigabit NIC corresponds to the first slot (SLOT1), and the interface naming standard for the first slot (SLOT1) is eth1x. The multiple interfaces of the gigabit NIC are named eth10, eth11, ..., eth1x, respectively. A 10-gigabit NIC corresponds to the second slot (SLOT2), and the interface naming standard for the second slot (SLOT2) is eth2x. The multiple interfaces of the 10-gigabit NIC are named eth20, eth21, ..., eth2x, respectively. Network devices such as servers generally do not have NIC slot identification information.
[0113] For example, for those based on Figure 2 The row-style PCIe sequence generated from the PCIe information shown is predefined in the following naming configuration file:
[0114] "[Type of network device]"
[0115] 0000-e2-04.0 = eth1x
[0116] 0000-16-02.0 = eth2x
[0117] 0000-00-1f.0=eth0
[0118] 0000-00-1f.2=eth1”.
[0119] The naming configuration file is in INI format and contains a one-to-one correspondence between the two network cards (10 Gigabit and 1 Gigabit) and the names of the two target interfaces.
[0120] Among them, based on the underlying information, a naming configuration file is defined according to the interface naming standard of each slot of the network device, which is easy for users to understand and allows users to consider actual application needs and customize the slot number and interface naming standard of each slot of the network device.
[0121] For each network interface card (NIC), based on the NIC's mapped address information, determine the NIC's basic information associated with that mapped address information in the row-type PCIe sequence. Based on this NIC's basic information, identify the NIC and determine whether the network device has NIC slot identification information. When the network device has NIC slot identification information, determine the interface name corresponding to the NIC's basic information in the naming configuration file as the NIC's target interface name.
[0122] For example, based on the network card's mapped address information 17:00.0, the basic information of the network card associated with the mapped address information 17:00.0 in the row PCIe sequence is determined to be 0000-16-02.0-00.0. Based on the basic information of the network card 0000-16-02.0-00.0, the network card is determined to be a 10 Gigabit network card. Since the network device has network card slot identification information, the interface name eth20 corresponding to the basic information of the network card 0000-16-02.0-00.0 in the naming configuration file is determined as the target interface name of the network card.
[0123] This invention identifies each network interface card (NIC) on the PCIe bus based on the row-type PCIe sequence. Then, when the network device has NIC slot identification information, it searches for the target NIC name corresponding to each NIC in the naming configuration file. This allows for the rapid determination of the target interface name of each NIC, which helps improve the efficiency of NIC interface renaming.
[0124] In an optional embodiment, the step of determining the target interface name of each network card based on a predefined naming configuration file and according to the row PCIe sequence further includes: when the network device does not have network card slot identification information, determining the interface name corresponding to the basic information of the network card in the default naming configuration file as the target interface name of the network card; wherein, the default naming configuration file is generated in response to a naming configuration file supplement request initiated by the user terminal for the row PCIe sequence.
[0125] As an example, for each network interface card (NIC), based on the NIC's mapped address information, the basic information of the NIC associated with the mapped address information in the row PCIe sequence is determined. Based on the NIC's basic information, the NIC is identified, and it is determined whether the network device has NIC slot identification information. When the network device does not have NIC slot identification information, a naming configuration file supplementation request initiated by the user for the row PCIe sequence is responded to, and a default naming configuration file is generated, or the user's previously configured default naming configuration file is directly retrieved, and the interface name corresponding to the NIC's basic information in the default naming configuration file is determined as the target interface name of the NIC.
[0126] This invention identifies each network interface card (NIC) on the PCIe bus based on the row-type PCIe sequence. Then, even when the network device lacks NIC slot identification information, it searches for the target NIC name corresponding to each NIC in the user-configured default naming configuration file. This allows for the rapid determination of the target interface name of each NIC while ensuring the complete determination of the target interface names of all NICs, thus improving the efficiency of NIC interface renaming.
[0127] In an optional embodiment, the network interface renaming method further includes steps S104 to S105:
[0128] S104. Respond to the user terminal's request for a custom naming configuration file for the row PCIe sequence and generate a custom naming configuration file.
[0129] S105. Based on the custom naming configuration file, determine the target interface name of each network card according to the row-style PCIe sequence.
[0130] As an example, users can consider actual application needs and choose to customize the naming configuration file. The user terminal initiates a naming configuration file customization request for the row PCIe sequence. When the processor receives the naming configuration file customization request initiated by the user terminal for the row PCIe sequence, it responds to the naming configuration file customization request and generates the custom naming configuration file.
[0131] When generating the custom naming configuration file, the target interface name of each network card is determined based on the custom naming configuration file and the row-based PCIe sequence. The specific processing procedure can be found in the section above on determining the target interface name of each network card based on the naming configuration file and the row-based PCIe sequence; it will not be repeated here.
[0132] This invention determines the target interface name of each network card by using a user-configured custom naming configuration file, which can adapt to various application requirements for renaming network card interfaces.
[0133] In an optional embodiment, before modifying the interface name of each network card to the target interface name of each network card, the method further includes: checking the format of the target interface name of each network card, so that when the format of the target interface name of all network cards is correct, the interface name of each network card is modified to the target interface name of each network card.
[0134] As an example, when determining the target interface name of each network card, the format of the target interface name of each network card is checked. If the format of the target interface name of all network cards is correct, the interface name of each network card is modified accordingly to the target interface name of each network card. If the format of the target interface name of any network card is incorrect, the modification of the interface name of each network card to the target interface name of each network card is stopped, and a message indicating that the format of the target interface name of the network card is incorrect is sent to the user terminal.
[0135] This invention, by first checking the format of the target interface names of all network cards, and then only modifying the interface names of each network card to their respective target interface names when the format of the target interface names of all network cards is correct, can further ensure that the interface names of each network card are accurately modified to their respective target interface names, which is beneficial to improving the efficiency of network card interface renaming.
[0136] Please refer to Figure 4 , Figure 4 This is a schematic diagram of a network interface renaming device according to a second embodiment of the present invention. The second embodiment of the present invention provides a network interface renaming device, comprising: a row-type PCIe sequence generation module 201, used to extract target PCIe information of all network cards from the PCIe information of the network device, and generate a row-type PCIe sequence by combining the target PCIe information of all network cards; a network interface name determination module 202, used to determine the target interface name of each network card based on a predefined naming configuration file and according to the row-type PCIe sequence; and a network interface name modification module 203, used to modify the interface name of each network card to the corresponding target interface name of each network card.
[0137] In an optional embodiment, the row-type PCIe sequence generation module 201 is further configured to execute a bus device information query command on the network device to read PCIe information before extracting the target PCIe information of all network cards from the PCIe information of the network device.
[0138] In an optional embodiment, the row-type PCIe sequence generation module 201 is further configured to determine whether the PCIe information is network card information before extracting the target PCIe information of all network cards from the PCIe information of the network device, so that when the PCIe information is network card information, the target PCIe information of all network cards is extracted from the PCIe information.
[0139] In an optional embodiment, the step of extracting the target PCIe information of all network cards from the PCIe information of the network device and generating a row-type PCIe sequence by combining the target PCIe information of all network cards specifically includes: extracting the basic network card information and mapped address information of each network card from the PCIe information as target PCIe information to obtain the target PCIe information of all network cards; for each network card, concatenating the basic network card information and mapped address information of the network card according to a preset sequence format to obtain the sequence information of the network card; and combining the sequence information of all network cards to generate a row-type PCIe sequence.
[0140] In an optional embodiment, the preset sequence format is [network card basic information, network card mapping address information]; wherein, the network card basic information is (the bus where the network card is located - the domain where the network card is located - all ancestor nodes of the node where the network card is located - the serial number of the network card), and the network card mapping address information is (network card mapping address number: network card serial number).
[0141] In an optional embodiment, the step of determining the target interface name of each network card based on a predefined naming configuration file and a row-type PCIe sequence specifically includes: for each network card, determining the basic network card information associated with the mapping address information in the row-type PCIe sequence based on the network card's mapping address information; determining the network card based on the basic network card information and determining whether the network device has network card slot identification information; when the network device has network card slot identification information, determining the interface name corresponding to the basic network card information in the naming configuration file as the target interface name of the network card.
[0142] In an optional embodiment, the step of determining the target interface name of each network card based on a predefined naming configuration file and according to the row PCIe sequence further includes: when the network device does not have network card slot identification information, determining the interface name corresponding to the basic information of the network card in the default naming configuration file as the target interface name of the network card; wherein, the default naming configuration file is generated in response to a naming configuration file supplement request initiated by the user terminal for the row PCIe sequence.
[0143] In an optional embodiment, the network interface renaming device further includes: a naming configuration file customization module, used to generate a custom naming configuration file in response to a user terminal's request for custom naming configuration file for a row PCIe sequence; and a network interface name determination module 202, used to determine the target interface name of each network card based on the custom naming configuration file and the row PCIe sequence.
[0144] In an optional embodiment, before modifying the interface name of each network card to the target interface name of each network card, the method further includes: checking the format of the target interface name of each network card, so that when the format of the target interface name of all network cards is correct, the interface name of each network card is modified to the target interface name of each network card.
[0145] The specific implementation process of the functions and roles of each module in the above device can be found in the implementation process of the corresponding steps in the above method, and will not be repeated here.
[0146] Please refer to Figure 5 , Figure 5 This is a schematic diagram of the structure of an electronic device provided in the third embodiment of the present invention. The third embodiment of the present invention provides an electronic device 30, including a processor 301, a memory 302, and a computer program stored in the memory 302 and configured to be executed by the processor 301; the memory 302 is coupled to the processor 301, and when the processor 301 executes the computer program, it implements the network card interface renaming method as described in the first embodiment of the present invention, and can achieve the same beneficial effects.
[0147] When the processor 301 reads a computer program from the memory 302 via the bus 303 and executes the computer program, it can implement any of the methods included in the network card interface renaming method described in the first embodiment of the present invention.
[0148] Processor 301 can process digital signals and may include various computing architectures. For example, it may be a complex instruction set computer architecture, a reduced instruction set computer architecture, or an architecture that implements multiple instruction set combinations. In some examples, processor 301 may be a microprocessor.
[0149] The memory 302 can be used to store instructions executed by the processor 301 or data related to the execution of instructions. These instructions and / or data may include code for implementing some or all of the functions of one or more modules described in the embodiments of this invention. The processor 301 of this disclosure embodiment can be used to execute instructions in the memory 302 to implement the network interface renaming method as described in the first embodiment of this invention. The memory 302 includes dynamic random access memory, static random access memory, flash memory, optical memory, or other memories well known to those skilled in the art.
[0150] The fourth embodiment of the present invention provides a computer-readable storage medium, which includes a stored computer program; wherein, when the computer program is running, it controls the device where the computer-readable storage medium is located to execute the network card interface renaming method as described in the first embodiment of the present invention, and can achieve the same beneficial effect.
[0151] In summary, embodiments of the present invention provide a method, apparatus, electronic device, and storage medium for renaming network interface cards (NICs). The NIC renaming method includes: extracting target PCIe information for all NICs from the PCIe information of a network device; generating a row-based PCIe sequence by combining the target PCIe information of all NICs; determining the target interface name of each NIC based on a predefined naming configuration file and the row-based PCIe sequence; and modifying the interface name of each NIC accordingly to the target interface name of each NIC. Embodiments of the present invention generate a row-based PCIe sequence by extracting the target PCIe information of all NICs from the PCIe information of a network device, determining each NIC on the PCIe bus based on the unchanging row-based PCIe sequence, and then determining the unique target interface name of each NIC based on the naming configuration file. This allows for accurate determination and renaming of the target interface name of each NIC when any NIC on the PCIe bus is changed, thereby achieving effective and accurate renaming of NIC interfaces even when a new NIC is added or replaced within the network device.
[0152] In the several embodiments provided by this invention, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative; for example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0153] In addition, the functional modules in the various embodiments of the present invention can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0154] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0155] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for renaming a network interface card (NIC), characterized in that, include: Extract the target PCIe information of all network cards from the PCIe information of the network devices, and generate a row-style PCIe sequence by combining the target PCIe information of all network cards. Based on a predefined naming configuration file, the target interface name of each network card is determined according to the row-style PCIe sequence; Modify the interface name of each network card to the target interface name of each network card accordingly; Specifically, determining the target interface name of each network card based on a predefined naming configuration file and the row-style PCIe sequence includes: For each network interface card (NIC), the basic information of the NIC associated with the mapping address information in the row-type PCIe sequence is determined based on the mapping address information of the NIC. Based on the basic information of the network card, identify the network card and determine whether the network device has the slot identification information of the network card; When the network device has the slot identification information of the network card, the interface name corresponding to the basic information of the network card in the naming configuration file is determined as the target interface name of the network card.
2. The network interface renaming method according to claim 1, characterized in that, Before extracting the target PCIe information of all network cards from the PCIe information of the network device, the method further includes: Execute a bus device information query command on the network device to read the PCIE information.
3. The network interface renaming method according to claim 1 or 2, characterized in that, Before extracting the target PCIe information of all network cards from the PCIe information of the network device, the method further includes: Determine whether the PCIE information is network card information. If the PCIE information is network card information, extract the target PCIE information of all network cards from the PCIE information.
4. The network interface renaming method according to claim 1, characterized in that, The step of extracting the target PCIe information of all network cards from the PCIe information of the network device, and generating a row-based PCIe sequence by combining the target PCIe information of all the network cards, specifically includes: The basic network card information and mapped address information of each network card are extracted from the PCIE information to obtain the target PCIE information of all network cards. For each network interface card (NIC), the basic information of the NIC and the mapped address information of the NIC are concatenated according to a preset sequence format to obtain the sequence information of the NIC; Combine the sequence information of all the network cards to generate the row-type PCIe sequence.
5. The network interface renaming method according to claim 4, characterized in that, The preset sequence format is [the basic information of the network card, the mapping address information of the network card]; wherein, the basic information of the network card is (the bus where the network card is located - the domain where the network card is located - all ancestor nodes of the node where the network card is located - the serial number of the network card), and the mapping address information of the network card is (the mapping address number of the network card: the serial number of the network card).
6. The network interface renaming method according to claim 1, characterized in that, The process of determining the target interface name of each network card based on a predefined naming configuration file and the row-style PCIe sequence further includes: When the network device does not have the slot identification information of the network card, the interface name corresponding to the basic information of the network card in the default naming configuration file is determined as the target interface name of the network card; wherein, the default naming configuration file is generated in response to the naming configuration file supplementation request initiated by the user terminal for the row PCIe sequence.
7. The network interface renaming method according to claim 1, characterized in that, Also includes: In response to a user terminal's request for a custom naming configuration file for the row-type PCIe sequence, a custom naming configuration file is generated. Based on the custom naming configuration file, the target interface name of each network card is determined according to the row-style PCIe sequence.
8. The network interface renaming method according to claim 1, characterized in that, Before modifying the interface names of each network interface card to the target interface names of each network interface card, the method further includes: Check the format of the target interface name of each network card. If the format of the target interface name of all network cards is correct, modify the interface name of each network card accordingly to the target interface name of each network card.
9. A network card interface renaming device, characterized in that, include: The row PCIe sequence generation module is used to extract the target PCIe information of all network cards from the PCIe information of the network device, and combine the target PCIe information of all the network cards to generate a row PCIe sequence. The network interface name determination module is used to determine the target interface name of each network card based on a predefined naming configuration file and the row-format PCIe sequence. The network interface name modification module is used to modify the interface name of each network card to the target interface name of each network card. Specifically, determining the target interface name of each network card based on a predefined naming configuration file and the row-style PCIe sequence includes: For each network interface card (NIC), the basic information of the NIC associated with the mapping address information in the row-type PCIe sequence is determined based on the mapping address information of the NIC. Based on the basic information of the network card, identify the network card and determine whether the network device has the slot identification information of the network card; When the network device has the slot identification information of the network card, the interface name corresponding to the basic information of the network card in the naming configuration file is determined as the target interface name of the network card.
10. An electronic device, characterized in that, The device includes a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor; the memory is coupled to the processor, and the processor, when executing the computer program, implements the network interface renaming method according to any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored computer program; wherein, when the computer program is executed, it controls the device where the computer-readable storage medium is located to perform the network interface renaming method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Method for binding network card name with equipment under Linux system
CN102427483A
Method, device and equipment for renaming network adapter interface
CN115277630A
