Dynamic allocation method, device, equipment and product of netlink number
By dynamically allocating the netlink sockets of kernel modules and applications, the problems of insufficient and conflicts in the existing technology are solved, and automated netlink number management and non-aware conflict handling of applications are realized.
Patent Information
- Application Number
- CN202510031516.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-09
- Publication Date
- 2025-04-18
- Estimated Expiration
- 2045-01-09
AI Technical Summary
In the prior art, the maximum value specified by the netlink number in the kernel is only 32, resulting in very few netlink numbers used by third-party applications, and there are problems such as insufficient netlink numbers or conflicts in use.
By determining whether the predefined netlink number in the kernel module is in use, dynamically create netlink sockets for the kernel module and application, ensuring that the application can automatically obtain a dynamic netlink number to avoid conflicts.
It realizes automatic duplication checking and dynamic allocation of netlink numbers, ensuring the correct and effective creation of application netlink sockets, and automatically dealing with netlink number conflict issues without application modification.
Smart Images

Figure CN119440882B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer systems, and in particular relates to a method, device, equipment and product for dynamically allocating a netlink number. Background Art
[0002] With the rapid development of computer and network technology, more and more applications are developed and adapted on Linux systems, and more and more applications involve kernel and non-kernel interaction. As an important means of kernel and non-kernel interaction, netlink communication will be used by more and more applications. Under existing technical conditions, the maximum value of netlink number in the kernel is only 32, and most of them have been reserved by the kernel for various kernel function modules. There are very few netlink numbers left for third-party applications. When more and more applications use netlink communication, there will be insufficient netlink numbers or different applications will use the same netlink number, resulting in conflicts in the use of netlink numbers. Summary of the invention
[0003] In view of this, the present invention aims to overcome the defects in the prior art and proposes a method, device, equipment and product for dynamically allocating netlink numbers.
[0004] To achieve the above object, the technical solution of the present invention is achieved as follows:
[0005] In a first aspect, the present invention discloses a method for dynamically allocating a netlink number, comprising:
[0006] Determine whether the predefined netlink number in the kernel module is in use. If the predefined netlink number is not in use, create a kernel module netlink socket based on the predefined netlink number; if the predefined netlink number is in use, create a kernel module netlink socket with an unused netlink number;
[0007] Determine the netlink number that the application chooses to use based on the matching relationship between the application and the kernel module;
[0008] Create a netlink socket for the application based on the netlink number you choose to use.
[0009] In one embodiment of the present invention, determining whether a predefined netlink number in a kernel module is in use includes: determining whether the predefined netlink number already exists in a currently used netlink number set in a kernel layer netlink information list.
[0010] In another embodiment of the present invention, if the predefined netlink number has been used, a netlink socket of the kernel module is created with an unused netlink number, including: determining that the unused netlink number starts from the predefined netlink number, traversing all netlink numbers until an unused netlink number is determined.
[0011] In another embodiment of the present invention, determining the netlink number selected for use by the application program according to the matching relationship between the application program and the kernel module includes:
[0012] If only one kernel module has a predefined netlink number that is the same as the application's predefined netlink number, the application creates a netlink socket based on the same predefined netlink number.
[0013] If the predefined netlink numbers of at least two kernel modules are the same as the predefined netlink number of the application, the netlink number selected by the application is determined according to the matching relationship between the application and the kernel modules with the same predefined netlink number.
[0014] In another embodiment of the present invention, determining the netlink number selected for use by the application program according to a matching relationship between the application program and a kernel module with the same predefined netlink number includes:
[0015] If the application name corresponding to the kernel module with the same predefined netlink number is the same as the application, the application creates a netlink socket based on the currently used netlink number of this kernel module;
[0016] In this embodiment, if the application name corresponding to the kernel module with the same predefined netlink number is the same as the application, it includes: determining the application name corresponding to the kernel module according to the kernel layer netlink information list.
[0017] In another embodiment, if the application name corresponding to the kernel module with the same predefined netlink number is the same as the application, it includes: determining the application name corresponding to the kernel module according to an application layer configuration file.
[0018] If the application name corresponding to the kernel module of the same predefined netlink number is different from the application program, the correspondence between the application program and the kernel module is supplemented, and the application program creates a netlink socket based on the currently used netlink number of the kernel module corresponding to the correspondence.
[0019] In a second aspect, the present invention discloses a device for dynamically allocating a netlink number, the device comprising:
[0020] The first creation module is used to determine whether the predefined netlink number in the kernel module is in use. If the predefined netlink number is not in use, a kernel module netlink socket is created based on the predefined netlink number; if the predefined netlink number is in use, a netlink socket of the kernel module is created with an unused netlink number;
[0021] Determine the netlink number module, which is used to determine the netlink number selected by the application based on the matching relationship between the application and the kernel module;
[0022] The second creation module creates the netlink socket of the application based on the netlink number selected for use.
[0023] In a third aspect, the present invention discloses an electronic device, comprising: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors execute the above method.
[0024] In a fourth aspect, the present invention discloses a computer program product, including a computer program, characterized in that the computer program implements the above method when executed by a processor.
[0025] Compared with the prior art, the present invention has the following advantages:
[0026] The present invention discloses a method, device, equipment and product for dynamically allocating a netlink number. By determining whether a predefined netlink number in a kernel module is in use, creating a netlink socket of the kernel module, determining a netlink number selected for use by an application program and creating a netlink socket of the application program, the netlink number can be automatically checked for duplicates, and a dynamic netlink number can be automatically allocated to the application program according to the usage of the system netlink number for normal use by the application program. The correct and effective creation of the netlink socket of the application program can be ensured, so that each application program can automatically handle the problem of netlink number conflict without modification and without perception. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] The accompanying drawings, which constitute a part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.
[0028] In the attached picture:
[0029] Figure 1 A schematic diagram of an application scenario of a method for dynamically allocating a netlink number according to an embodiment of the present invention;
[0030] Figure 2 A schematic diagram of a method for dynamically allocating a netlink number according to an embodiment of the present invention;
[0031] Figure 3 A schematic diagram of a method for dynamically allocating a netlink number according to an embodiment of the present invention to determine a netlink number selected for use by an application program;
[0032] Figure 4 A schematic diagram of a dynamic allocation device for a netlink number according to an embodiment of the present invention;
[0033] Figure 5 The present invention is a schematic diagram of an electronic device for dynamically allocating a netlink number according to an embodiment of the present invention. DETAILED DESCRIPTION
[0034] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments may be combined with each other.
[0035] In the description of the present invention, it should be further explained that the terms "first", "second", etc. are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first", "second", etc. may explicitly or implicitly include one or more of the features. In the description of the present invention, unless otherwise specified, "plurality" means two or more.
[0036] The present invention discloses a method, device, equipment and product for dynamically allocating a netlink number, and the application scenarios are as follows: Figure 1 As shown in the figure, the application outside the kernel communicates with the corresponding kernel module through netlink to realize the interaction inside and outside the kernel. The specific process is that the kernel module establishes a netlink socket in the kernel, and the application establishes a netlink socket outside the kernel. The two keep corresponding and consistent to realize netlink communication.
[0037] Under existing technical conditions, the maximum value of the netlink number in the kernel is 32, and most of them have been reserved by the kernel for various functional modules. There are very few netlink numbers left for third-party applications. When more and more applications use netlink communication, there will be insufficient netlink numbers or different applications will use the same netlink number, resulting in conflicts in the use of netlink numbers.
[0038] The present invention discloses a method, device, equipment and product for dynamically allocating a netlink number. By determining whether a predefined netlink number in a kernel module is in use, creating a netlink socket of the kernel module, determining a netlink number selected for use by an application and creating a netlink socket of the application, the netlink number can be automatically checked for duplicates. According to the usage of the netlink number in the system, a dynamic netlink number is automatically allocated to the application for normal use by the application. The correct and effective creation of the netlink socket of the application is guaranteed, so that each application can automatically handle the netlink number conflict problem without modification and perception.
[0039] The present invention will be described in detail below with reference to the accompanying drawings and in conjunction with embodiments.
[0040] The terms involved in the method, device, equipment and product for dynamically allocating a netlink number disclosed in the present invention are explained as follows:
[0041] Predefined netlink number: The netlink number defined in the kernel module and application may not be used by the current kernel module and application, but may be occupied by other applications;
[0042] Currently used netlink number: The netlink number that is being used normally by the current kernel module to communicate with applications outside the kernel;
[0043] Application name: The program name of the application that uses and creates the netlink socket;
[0044] Application layer configuration file: used to record the correspondence between kernel modules and applications;
[0045] Kernel layer netlink information list: records in real time the module name of each kernel module that creates a netlink socket, the corresponding predefined netlink number, the currently used netlink number after duplicate checking, and the corresponding out-of-kernel application;
[0046] In-kernel and out-kernel interaction files: used for in-kernel and out-kernel interaction of netlink information lists. For example, out-kernel applications can obtain the kernel-layer netlink information list through this file, and write the application name to the kernel-layer netlink information list.
[0047] Graphical prompt box: used to remind users whether the kernel module corresponding to the current application is correct. If it is incorrect, users can edit it directly in the prompt box, pass the correct kernel module name into the kernel layer netlink information list, and synchronously record it in the application layer configuration file outside the kernel.
[0048] An embodiment of the present invention is disclosed as follows Figure 1 As shown, a method for dynamically allocating a netlink number includes:
[0049] Step S201, determining whether the predefined netlink number in the kernel module is in use, if the predefined netlink number is not in use, creating a kernel module netlink socket based on the predefined netlink number; if the predefined netlink number is in use, creating a kernel module netlink socket with an unused netlink number;
[0050] In this embodiment, after the netlink socket of the kernel module is created, the name of the kernel module, the predefined netlink number and the currently used netlink number are written into the kernel layer netlink information list for subsequent out-of-kernel applications to view.
[0051] Determining whether a predefined netlink number in a kernel module of an application is in use includes: determining whether the predefined netlink number already exists in a currently used netlink number set in a kernel layer netlink information list.
[0052] If the predefined netlink number is already in use, a netlink socket of the kernel module is created with an unused netlink number, including: determining that the unused netlink number starts from the predefined netlink number, increments upward, and traverses all netlink numbers until an unused netlink number is determined.
[0053] In this embodiment, when a conflict occurs in the netlink number of an application, it is necessary to dynamically process the netlink number used in the application and the netlink number used in the kernel module at the same time, and ensure that the processed netlink numbers of the two are the same, so that the kernel module and the application can establish normal netlink interactive communication.
[0054] Step S202, determining the netlink number selected by the application according to the matching relationship between the application and the kernel module;
[0055] In step S202, the predefined netlink number in the application is written into the kernel through the intra-kernel and extra-kernel interactive files, and all data records whose predefined netlink numbers in the kernel layer netlink information list are the same as the predefined netlink numbers of the application input from the extra-kernel are obtained;
[0056] Step S203, based on the selected netlink number, create a netlink socket for the application.
[0057] This embodiment determines whether the predefined netlink number in the kernel module is in use, creates the netlink socket of the kernel module, determines the netlink number selected for use by the application, and creates the netlink socket of the application. It can automatically check the duplicate of the netlink number and ensure the correct and effective creation of the netlink socket of the application, so that each application can automatically handle the netlink number conflict problem without modification and without perception.
[0058] In this embodiment, after the netlink socket of the application is created, the correspondence between the kernel module and the application is synchronously written back to the kernel layer netlink information list through the kernel internal and external interaction files.
[0059] In another embodiment of the present invention, Figure 3 As shown in the figure, based on the matching relationship between the application and the kernel module, the netlink number selected by the application is determined, including:
[0060] If only one kernel module has a predefined netlink number that is the same as the application's predefined netlink number, the application creates a netlink socket based on the same predefined netlink number.
[0061] In this embodiment, if only one kernel module has a predefined netlink number that is the same as the predefined netlink number of the application, it means that only one kernel module currently predefines and uses the netlink number.
[0062] If the predefined netlink numbers of at least two kernel modules are the same as the predefined netlink number of the application, the netlink number selected by the application is determined according to the matching relationship between the application and the kernel modules with the same predefined netlink number.
[0063] like Figure 3 As shown, according to the matching relationship between the application and the kernel module with the same predefined netlink number, the netlink number selected by the application is determined, including:
[0064] If the application name corresponding to the kernel module with the same predefined netlink number is the same as the application, the application creates a netlink socket based on the currently used netlink number of this kernel module;
[0065] In this embodiment, if the application name corresponding to the kernel module with the same predefined netlink number is the same as the application, it includes: determining the application name corresponding to the kernel module according to the kernel layer netlink information list, and the kernel layer netlink information list is used to record the correspondence between the determined kernel module and the application in real time.
[0066] In this embodiment, if the application name corresponding to the kernel module with the same predefined netlink number is the same as the application, it may also include: determining the application name corresponding to the kernel module according to the application layer configuration file, and the application layer configuration file is used to record the correspondence between the determined kernel module and the application.
[0067] In this embodiment, the application layer configuration file pre-stores and records the corresponding relationship between the kernel module and the application program.
[0068] In another embodiment of the present invention, Figure 3 As shown, if the application name corresponding to the kernel module of the same predefined netlink number is different from the application, the correspondence between the application and the kernel module is supplemented, and the application creates a netlink socket based on the currently used netlink number of the kernel module corresponding to the correspondence.
[0069] In this embodiment, if there is no relevant record of the application and the corresponding kernel module in the application layer configuration file, a graphic prompt box is popped up to the user, asking the user to enter the name of the kernel module corresponding to the out-of-core application in the graphic prompt box, and then the kernel module name is matched based on the kernel layer netlink information list obtained according to the kernel module entered by the user;
[0070] In this embodiment, a method is set in which the user can fill in the name of the kernel module corresponding to the out-of-core application in the graphic prompt box, which can improve the applicability of the method and enrich the functions that the method can provide.
[0071] On this basis, if the out-of-core application still does not match the corresponding kernel module, it means that the kernel module corresponding to the current application has not been loaded, then the application is directly returned and the socket creation fails.
[0072] A practical application example of the present invention is as follows:
[0073] There are applications A and B in the system. The corresponding kernel modules are represented by Am and Bm respectively, and the applications outside the kernel are represented by Ap and Bp. The predefined netlink number of the kernel modules and applications of applications A and B is 26. Therefore, when applications A and B need to run in the system at the same time, a netlink number conflict will occur, resulting in a failure to create a netlink socket for a later executed application.
[0074] If application A runs first and application B runs later, the actual application process of the method disclosed in the present invention is as follows:
[0075] The application layer configuration file outside the kernel configures the correspondence between the kernel modules and application programs of each application in advance, for example: Am:Ap and Bm:Bp;
[0076] When application A is running, it is detected that netlink number 26 is not occupied. Therefore, after application A is running, the netlink socket of the kernel module and the netlink socket of the application are created, the record in the kernel netlink information list is (26:26:Am:Ap), which means: predefined netlink number: currently used netlink number: kernel module name: application name;
[0077] When application B is running, it first loads kernel module Bm and creates a netlink socket for the kernel module. At this time, it is detected that netlink number 26 is already occupied. Through duplicate checking, it is found that number 27 is not occupied and can be used. Therefore, the netlink number used to create the netlink socket in kernel module Bm is changed from 26 to 27. After the netlink socket of the kernel module is successfully created, the relevant information about application B in the netlink information list written into the kernel is (26:27:Bm:null);
[0078] When the application B runs the out-of-core application Bp, the predefined netlink number 26 in Bp is passed to the kernel, and all data records with the predefined netlink number 26 recorded in the netlink information list are obtained and passed to the out-of-core application Bp;
[0079] According to the data returned by the kernel, application Bp determines the records (26:26:Am:Ap) and (26:27:Bm:null) based on the sameness of the predefined netlink number 26. It is found that the application Ap and null corresponding to application Bp both fail to match.
[0080] In another case, if the application Bp finds that there is already a record of the same application Bp based on the sameness of the predefined netlink number 26, the application Bp directly creates a netlink socket based on the netlink number currently used by this record;
[0081] Further, when both the application Ap and null corresponding to the application Bp fail to match, the application Bp combines the application Bp with the kernel module in the kernel layer netlink information list to obtain two combinations of Am:Bp and Bm:Bp, and searches for them in the application layer configuration file with the corresponding relationship configured in advance, and the application layer configuration file includes the corresponding relationship Am:Ap and Bm:Bp configured in advance;
[0082] The combination Bm:Bp successfully matches the record Bm:Bp in the application layer configuration file, indicating that the kernel module corresponding to the application Bp is Bm. Finally, the current netlink number used by the kernel module Bm recorded in the netlink information list is 27.
[0083] The application Bp uses netlink number 27 to create a netlink socket. After the netlink socket is successfully created, the Bp program name information is written back to the kernel netlink information list. The corresponding application B information is (26:27:Bm:Bp).
[0084] At this point, applications A and B with conflicting netlink numbers can automatically resolve the conflict without any notice and run normally.
[0085] like Figure 4 As shown, the present invention also discloses a dynamic allocation device for a netlink number, comprising:
[0086] The first creation module 401 is used to determine whether the predefined netlink number in the kernel module is in use. If the predefined netlink number is not in use, a netlink socket of the kernel module is created based on the predefined netlink number; if the predefined netlink number is in use, a netlink socket of the kernel module is created with an unused netlink number;
[0087] The netlink number determination module 402 is used to determine the netlink number selected for use by the application program according to the matching relationship between the application program and the kernel module;
[0088] The second creation module 403 creates a netlink socket of the application based on the selected netlink number.
[0089] The netlink number determination module 402 further includes: a first determination module and a second determination module:
[0090] A first determination module is used for, if only one kernel module has a predefined netlink number that is the same as the predefined netlink number of the application, then the application creates a netlink socket of the application based on the same predefined netlink number;
[0091] The second determination module is used to determine the netlink number selected by the application program according to the matching relationship between the application program and the kernel module with the same predefined netlink number if the predefined netlink numbers of at least two kernel modules are the same as the predefined netlink number of the application program.
[0092] The present invention also discloses an electronic device, such as Figure 5 As shown, an embodiment is disclosed, which is a block diagram of an electronic device suitable for dynamic allocation of the above-mentioned netlink number.
[0093] The electronic device 50 of this embodiment includes a processor 501, which can perform various appropriate actions and processes according to the program stored in the ROM 502 or the program loaded from the storage part 508 to the RAM 503. The processor 501 may include, for example, a general-purpose microprocessor, an instruction set processor and / or a related chipset and / or a dedicated microprocessor, etc. The processor 501 may also include an onboard memory for caching purposes. The processor 501 may include a single processing unit or multiple processing units for performing different actions of the method flow according to the embodiment of the present invention.
[0094] In RAM503, various programs and data required for the operation of electronic device 50 are stored. Processor 501, ROM502 and RAM503 are connected to each other via bus 504, and processor 501 performs various operations of the method flow according to the embodiment of the present invention by executing the program in ROM502 and / or RAM503. It should be noted that the program can also be stored in one or more memories other than ROM502 and RAM503, and processor 501 can also perform various operations of the method flow according to the embodiment of the present invention by executing the program stored in one or more memories.
[0095] According to an embodiment of the present invention, the electronic device 50 may further include an I / O interface 505, which is also connected to the bus 504. The electronic device 50 may further include one or more of the following components connected to the I / O interface 505: an input portion 506 including a keyboard, a mouse, etc.; an output portion 507 including a cathode ray tube, a liquid crystal display, and a speaker; a storage portion 508 including a hard disk, etc.; and a communication portion 509 including a network interface card such as a LAN card, a modem, etc. The communication portion 509 performs communication processing via a network such as the Internet. A drive 5010 is also connected to the I / O interface 505 as needed. A removable medium 5011, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 5010 as needed, so that a computer program read therefrom is installed into the storage portion 508 as needed.
[0096] Embodiments of the present invention also include a computer program product.
[0097] The computer program product includes a computer program, which contains program codes for executing the method provided by the embodiment of the present invention. When the computer program product runs on an electronic device, the program codes are used to enable the electronic device to implement the method provided by the embodiment of the present invention.
[0098] In one embodiment, the computer program may rely on a tangible storage medium such as an optical storage device or a magnetic storage device. In another embodiment, the computer program may also be transmitted and distributed in the form of a signal on a network medium. The program code included in the computer program may be transmitted using any appropriate network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0099] According to an embodiment of the present invention, the program code for executing the computer program provided by the embodiment of the present invention can be written by any combination of one or more programming languages, and specifically, these computing programs can be implemented using high-level process and / or object-oriented programming languages. Programming languages include but are not limited to programming languages such as Java, C++, python, C language or similar. The program code can be executed completely on the user computing device, partially on the user device, partially on the remote computing device, or completely on the remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, including a local area network or a wide area network, or can be connected to an external computing device.
[0100] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present invention. In this regard, each box in the flowchart or block diagram may represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box may also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions. It can be understood by those skilled in the art that the features recorded in the various embodiments and / or claims of the present invention can be combined and / or combined in various ways, even if such a combination or combination is not explicitly recorded in the present invention. In particular, without departing from the spirit and teaching of the present invention, the features described in the various embodiments and / or claims of the present invention may be combined and / or combined in a variety of ways. All of these combinations and / or combinations fall within the scope of the present invention.
[0101] The embodiments of the present invention are described above. However, these embodiments are only for the purpose of illustration, and are not intended to limit the scope of the present invention. Although the embodiments are described above, this does not mean that the measures in the various embodiments cannot be used in combination. The scope of the present invention is limited by the attached claims and their equivalents. Without departing from the scope of the present invention, those skilled in the art may make various substitutions and modifications, which should all fall within the scope of the present invention.
Claims
1. A method for dynamically allocating a netlink number, characterized in that: include: Determine whether a predefined netlink number in the kernel module is in use, if the predefined netlink number is not in use, create a kernel module netlink socket based on the predefined netlink number; if the predefined netlink number is in use, create a netlink socket of the kernel module with an unused netlink number; After creating the kernel module's netlink socket, write the kernel module's name, predefined netlink number, and currently used netlink number into the kernel layer netlink information list for subsequent out-of-kernel applications to view; Determine the netlink number selected by the application program for use according to the matching relationship between the application program and the kernel module; Based on the selected netlink number, create a netlink socket for the application; After the netlink socket is successfully created, the program name information is written back to the kernel netlink information list; Determining the netlink number selected for use by the application program according to the matching relationship between the application program and the kernel module comprises: Write the predefined netlink number in the application into the kernel through the interaction file between the kernel and the outside, and obtain all data records of the kernel layer netlink information list whose predefined netlink number is the same as the predefined netlink number of the application passed in from outside the kernel; If the predefined netlink number of only one kernel module is the same as the predefined netlink number of the application, the application creates a netlink socket of the application based on the same predefined netlink number; If the predefined netlink numbers of at least two of the kernel modules are the same as the predefined netlink number of the application, the netlink number selected for use by the application is determined according to a matching relationship between the application and the kernel modules with the same predefined netlink number.
2. A method for dynamically allocating a netlink number according to claim 1, characterized in that: The determining whether the predefined netlink number in the kernel module is in use includes: determining whether the predefined netlink number already exists in a currently used netlink number set in a kernel layer netlink information list.
3. A method for dynamically allocating a netlink number according to claim 1, characterized in that: If the predefined netlink number has been used, creating a netlink socket of the kernel module with an unused netlink number includes: determining that the unused netlink number starts from the predefined netlink number, traversing all netlink numbers until an unused netlink number is determined.
4. A method for dynamically allocating a netlink number according to claim 1, characterized in that: The determining, based on a matching relationship between the application and the kernel module having the same predefined netlink number, the netlink number selected for use by the application comprises: If the application name corresponding to the kernel module with the same predefined netlink number is the same as the application, the application creates a netlink socket based on the currently used netlink number of the kernel module; If the application name corresponding to the kernel module with the same predefined netlink number is different from the application, the correspondence between the application and the kernel module is supplemented, and the application creates a netlink socket based on the currently used netlink number of the kernel module corresponding to the correspondence.
5. A method for dynamically allocating a netlink number according to claim 4, characterized in that: If the application name corresponding to the kernel module with the same predefined netlink number is the same as the application, it includes: determining the application name corresponding to the kernel module according to the kernel layer netlink information list, and the kernel layer netlink information list is used to record the determined correspondence between the kernel module and the application in real time.
6. A method for dynamically allocating a netlink number according to claim 5, characterized in that: If the application name corresponding to the kernel module with the same predefined netlink number is the same as the application, it includes: determining the application name corresponding to the kernel module according to an application layer configuration file, and the application layer configuration file is used to record the determined correspondence between the kernel module and the application.
7. A dynamic allocation device for a netlink number, characterized in that: The device comprises: The first creation module is used to determine whether the predefined netlink number in the kernel module is in use. If the predefined netlink number is not in use, a kernel module netlink socket is created based on the predefined netlink number; if the predefined netlink number is in use, a netlink socket of the kernel module is created with an unused netlink number; after the netlink socket of the kernel module is created, the name of the kernel module, the predefined netlink number and the currently used netlink number are written into a kernel layer netlink information list for subsequent out-of-kernel applications to view; A netlink number determination module is used to determine the netlink number selected by the application according to the matching relationship between the application and the kernel module; the predefined netlink number in the application is written into the kernel through the kernel and the kernel interaction file, and all data records of all predefined netlink numbers in the kernel layer netlink information list that are the same as the predefined netlink number of the application input from outside the kernel are obtained; if only one of the kernel modules has the same predefined netlink number as the predefined netlink number of the application, the application creates a netlink socket of the application based on the same predefined netlink number; if at least two of the kernel modules have the same predefined netlink number as the predefined netlink number of the application, the netlink number selected by the application is determined according to the matching relationship between the application and the kernel module with the same predefined netlink number; The second creation module creates a netlink socket of the application based on the selected netlink number, and writes the program name information back to the kernel netlink information list after the netlink socket is successfully created.
8. An electronic device, characterized in that: include: one or more processors; A storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors are caused to perform the method according to any one of claims 1 to 6.
9. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Cross-state communication method and channel drive device
CN109343977A
Addressing method for cross-domain network
CN113259499A