Address allocation method, device and electronic device
By setting up a static address mapping table in the DHCP server and finding the static IP address of the target client, the IP address conflict problem is solved, network failure occurs, and IP address management is simplified.
Patent Information
- Application Number
- CN202111644082.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-29
- Publication Date
- 2024-11-15
- Estimated Expiration
- 2041-12-29
AI Technical Summary
In the prior art, DHCP servers are prone to conflicts between static IP addresses and dynamic IP addresses when allocating IP addresses, resulting in network failures, and cannot set both address allocation methods to static or dynamic allocation methods to completely avoid conflicts.
By setting up a static address mapping table in the DHCP server, receive the address allocation request of the target client, and find whether the static IP address of the target client exists in the static address mapping table. If it exists, assign the IP address. If it does not exist, select other static IP address to the client.
It effectively reduces the occurrence of IP address conflicts, avoids network failures, and avoids the management trouble of administrators configuring IP addresses one by one and the IP address reassignment operation of fixed terminals when switching network environments.
Smart Images

Figure CN114448932B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of address allocation technology, and in particular, to an address allocation method, device and electronic device. Background Art
[0002] General electronic terminals, including mobile phones, computers, electronic cameras, etc., will enable the Dynamic Host Configuration Protocol (DHCP). When these terminals access the network, the DHCP server will assign corresponding Internet Protocol addresses (IP addresses) to these terminals so that these terminals can access the network.
[0003] At present, there are two main ways for DHCP servers to allocate IP addresses: static allocation and dynamic allocation. The static allocation method means that the administrator will allocate a fixed IP address to the DHCP server terminal, that is, the IP address corresponding to the terminal will not change; the dynamic allocation method is that when the terminal accesses the network, the DHCP server allocates a random IP address to it, that is, the IP address corresponding to the terminal will change frequently; another way for the terminal to obtain an IP address is that the user sets the corresponding IP address on the terminal, and when the terminal accesses the network, the terminal automatically obtains the corresponding IP address without the need for DHCP server allocation.
[0004] In summary, there are usually statically assigned IP addresses, dynamically assigned IP addresses, and terminal configured IP addresses in the network. Therefore, IP address conflicts may occur in the current network environment. For example, the first IP address assigned to a computer X is static IP address A. When computer X is turned off, IP address A is idle. At this time, a device B applies for an address. The DHCP server detects that IP address A is not used by any device, so it may assign IP address A to device B. When computer X is turned on and connected to the network, since computer X is a terminal with a statically assigned IP address, the IP address corresponding to computer X is always IP address A. At this time, IP address A is used by device B, so an address conflict occurs, resulting in a network failure. Summary of the invention
[0005] The embodiments of the present application provide an address allocation method, device and electronic device to solve the problem of address conflict in the prior art.
[0006] In a first aspect, an embodiment of the present application provides an address allocation method, which is applied to a Dynamic Host Configuration Protocol DHCP server, comprising:
[0007] receiving an address allocation request sent by a target client, wherein the address allocation request includes a target media access control client identifier;
[0008] Searching whether there is a static Internet Protocol IP address corresponding to the target client identifier in a static address mapping table; wherein the static address mapping table includes a plurality of static IP addresses and client identifiers corresponding to the plurality of static IP addresses respectively;
[0009] If the static IP address corresponding to the target client identifier exists in the static address mapping table, the static IP address corresponding to the target client identifier is allocated to the target client;
[0010] If the static IP address corresponding to the target client identifier does not exist in the static address mapping table, any IP address other than the multiple static IP addresses is selected for the target client to generate a corresponding storage node.
[0011] In a second aspect, an embodiment of the present application provides an address allocation device, which is applied to a dynamic host configuration protocol DHCP server, including:
[0012] A receiving module, configured to receive an address allocation request sent by a target client, wherein the address allocation request includes a target media access control client identifier;
[0013] A search module, used to search whether there is a static Internet Protocol IP address corresponding to the target client identifier in a static address mapping table; wherein the static address mapping table includes multiple static IP addresses and client identifiers corresponding to the multiple static IP addresses respectively;
[0014] An allocation module is used to allocate the static IP address corresponding to the target client identifier to the target client if the static IP address corresponding to the target client identifier exists in the static address mapping table; if the static IP address corresponding to the target client identifier does not exist in the static address mapping table, select any IP address other than the multiple static IP addresses to the target client to generate a corresponding storage node.
[0015] In a third aspect, an embodiment of the present application provides an electronic device, including a processing component and a storage component;
[0016] The storage component stores one or more computer instructions; the one or more computer instructions are used to be called and executed by the processing component;
[0017] The processing component is used to:
[0018] receiving an address allocation request sent by a target client, wherein the address allocation request includes a target media access control client identifier;
[0019] Searching whether there is a static Internet Protocol IP address corresponding to the target client identifier in a static address mapping table; wherein the static address mapping table includes a plurality of static IP addresses and client identifiers corresponding to the plurality of static IP addresses respectively;
[0020] If the static IP address corresponding to the target client identifier exists in the static address mapping table, the static IP address corresponding to the target client identifier is allocated to the target client;
[0021] If the static IP address corresponding to the target client identifier does not exist in the static address mapping table, any IP address other than the multiple static IP addresses is selected for the target client to generate a corresponding storage node.
[0022] In a fourth aspect, an embodiment of the present application provides a computer storage medium storing a computer program, which, when executed by a computer, implements the address allocation method as described in the first aspect.
[0023] The functions can be implemented by hardware or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the functions.
[0024] In an embodiment of the present application, an address allocation method, device and electronic device are provided, which are applied to a DHCP server, wherein the method comprises: receiving an address allocation request sent by a target client, the address allocation request comprising a target client identifier; searching whether there is a static IP address corresponding to the target client identifier in a static address mapping table; wherein the static address mapping table comprises multiple static IP addresses and client identifiers corresponding to the multiple static IP addresses respectively; if there is a static IP address corresponding to the target client identifier in the static address mapping table, the static IP address corresponding to the target client identifier is allocated to the target client; if there is no static IP address corresponding to the target client identifier in the static address mapping table, any IP address other than the multiple static IP addresses is selected for the target client to generate a corresponding storage node. The embodiment of the present application reduces address conflicts by setting a static address mapping table.
[0025] These and other aspects of the present application will become more clearly understood in the description of the following embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, a brief introduction will be given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0027] Figure 1 A schematic diagram showing a flow chart of an embodiment of the address allocation method provided by the present application is shown;
[0028] Figure 2 A schematic diagram showing a flow chart of an embodiment of a method for setting a lease period corresponding to a storage node;
[0029] Figure 3 A schematic diagram of a process flow of a dynamic address mapping table management process is shown;
[0030] Figure 4 A schematic diagram showing the structure of an embodiment of an address allocation device provided by the present application is shown;
[0031] Figure 5 Shown with Figure 4 The structural diagram of the electronic device corresponding to the address allocation device shown is shown. DETAILED DESCRIPTION
[0032] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application.
[0033] In some of the processes described in the specification and claims of this application and the above-mentioned figures, multiple operations that appear in a specific order are included, but it should be clearly understood that these operations may not be executed in the order in which they appear in this article or executed in parallel. The serial numbers of the operations, such as 101, 102, etc., are only used to distinguish between different operations, and the serial numbers themselves do not represent any execution order. In addition, these processes may include more or fewer operations, and these operations may be executed in sequence or in parallel. It should be noted that the descriptions of "first", "second", etc. in this article are used to distinguish different messages, devices, modules, etc., do not represent the order of precedence, and do not limit the "first" and "second" to be different types.
[0034] Based on the above background technology, there are generally three ways for a terminal to obtain an IP address, namely, static allocation, dynamic allocation, and the user manually allocating an IP address to his or her own terminal. Since there are multiple ways of allocating IP addresses, it is inevitable that multiple terminals will use the same IP address at the same time, that is, IP address conflicts will occur, causing network anomalies on multiple terminals.
[0035] In the prior art, the IP address allocation method is set to a static allocation method or a dynamic allocation method to avoid address conflicts. Assuming that the IP address allocation method is set to a static allocation method, although the address conflicts can be avoided, the administrator needs to configure the IP address for each terminal one by one through the DHCP server, which is troublesome to manage, and some terminals are not suitable for allocation of static IP addresses. For example, when a mobile phone uses a static IP address, due to the mobility of the mobile phone, when the mobile phone switches from the network environment corresponding to the current DHCP server to the network environment corresponding to other DHCP servers, the IP address needs to be reallocated, which is troublesome to operate.
[0036] Furthermore, assuming that the IP address allocation method is set to dynamic allocation, some fixed terminals, such as cameras, need to change IP addresses frequently, which may cause troubles in use. For example, when users are looking for images taken by cameras, they need to frequently switch IP addresses to obtain the corresponding images.
[0037] In summary, when facing the problem of address conflict, it is impossible to set the address allocation mode to be static allocation mode or dynamic allocation mode.
[0038] In order to reduce the probability of address conflicts, the inventor has proposed an invention idea, in which a DHCP server receives an address allocation request sent by a target client, the address allocation request includes a target client identifier; searches a static address mapping table for a static IP address corresponding to the target client identifier; wherein the static address mapping table includes multiple static IP addresses and client identifiers corresponding to the multiple static IP addresses; if a static IP address corresponding to the target client identifier exists in the static address mapping table, the static IP address corresponding to the target client identifier is allocated to the target client; if a static IP address corresponding to the target client identifier does not exist in the static address mapping table, any IP address other than the multiple static IP addresses is selected for the target client, and a corresponding storage node is generated. The embodiment of the present application reduces address conflicts by setting a static address mapping table.
[0039] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of this application.
[0040] Figure 1A flowchart of an embodiment of the address allocation method provided by the present application is shown. The method can be executed by a DHCP server, such as Figure 1 As shown, the method includes:
[0041] 101. Receive an address allocation request sent by a target client.
[0042] The target client sending the address allocation request may be a client that has been allocated a static IP address, a client that has been allocated a dynamic IP address, or a client that has not been allocated an IP address.
[0043] Optionally, the static IP address may be an IP address allocated to the client by static configuration, and the dynamic IP address may be an IP address allocated to the client by dynamic allocation.
[0044] It is understandable that a client that has been assigned a static IP address may send an address allocation request when the client is shut down at a certain moment and powered on at the next moment, and sends an address allocation request to the DHCP server. Similarly, a client that has been assigned a dynamic IP address may send an address allocation request when the client is shut down at a certain moment and powered on at the next moment, and sends an address allocation request to the DHCP server.
[0045] Optionally, an address allocation method corresponding to a client to which an IP address has not been allocated may be determined according to the address allocation request.
[0046] Optionally, the address allocation request includes a target client identifier, wherein the target client identifier may be a Media Access Control Address (MAC) address corresponding to the target client, a device identifier corresponding to the target client, or a user account corresponding to the target client, and the like.
[0047] Correspondingly, the corresponding address allocation method can be determined according to the client identifier corresponding to the target client to which the IP address has not been allocated.
[0048] For example, if the target client is determined to be a mobile phone based on the target client identifier, the corresponding address allocation method is determined to be a dynamic allocation method. If the target client is determined to be a camera based on the target client identifier, the corresponding address allocation method is determined to be a static allocation method.
[0049] 102. Check whether there is an IP address corresponding to the target client identifier in the static address mapping table.
[0050] Wherein, each time an administrator allocates a static IP address, the static IP address and the corresponding client identifier are stored in the static address mapping table.
[0051] Optionally, each time the DHCP server is powered on, it will load the corresponding static address mapping table, thereby obtaining the corresponding relationship between the static IP address and the client identifier in the static address mapping table.
[0052] Optionally, the static address mapping table includes multiple static IP addresses and client identifiers corresponding to the multiple static IP addresses respectively.
[0053] 103. If the static IP address corresponding to the target client identifier exists in the static address mapping table, the static IP address corresponding to the target client identifier is allocated to the target client.
[0054] Since the situations of address allocation request include the above-mentioned situations, and the allocation of static IP addresses is relatively fixed, after receiving the address allocation request, it is preferred to search whether there is a target client identifier in the static address mapping table, so as to allocate the static IP address corresponding to the target client to the target client when the stored target client identifier exists.
[0055] It should be noted that after an IP address is assigned to a client as a static address, a user may think that the IP address is configured for his or her own client. However, since the IP address has been stored in the static address mapping table, the IP address cannot be assigned to other clients.
[0056] Correspondingly, when a user manually configures a static IP address that exists in the static address mapping table for himself, the user will be prompted that the IP address is unavailable.
[0057] 104. If the static IP address corresponding to the target client identifier does not exist in the static address mapping table, select any IP address other than the multiple static IP addresses for the target client to generate a corresponding storage node.
[0058] As described above, the target client sending the address allocation request may be a target client to which a dynamic IP address has been allocated.
[0059] It should be noted that in the process of loading the static address mapping table, the dynamic address mapping table will also be loaded at the same time. Therefore, when it is determined that the target client identifier does not exist in the static address mapping table, the dynamic address mapping table is first searched for the target client identifier.
[0060] Optionally, all addresses corresponding to the DHCP server include static IP addresses in the static address mapping table, dynamic IP addresses in the dynamic address mapping table, and free IP addresses. Since the DHCP server loads the dynamic address mapping table and the static address mapping table when it is turned on, there may be situations where the IP addresses are manually configured when the DHCP server is turned off. Since the static IP addresses in the static address mapping table will not be manually configured, while the dynamic IP addresses and free IP addresses in the dynamic address mapping table may be manually configured, that is, the client identifier corresponding to the dynamic IP address in the dynamic address mapping table has changed, or the free IP address may have been allocated to a certain client. Therefore, the dynamic address mapping table needs to be updated in real time.
[0061] Optionally, the above-mentioned process of real-time updating of the dynamic address mapping table can be implemented as follows: sending a request message to any IP address other than multiple static IP addresses; if a return message sent by any IP address is received, determining that the return message corresponds to a client identifier; saving any IP address and its corresponding client identifier to the allocated address mapping table; and updating the dynamic address mapping table based on the allocated address mapping table.
[0062] The request message may be an Address Resolution Protocol (ARP) message, or a Packet Internet Groper (PING) message.
[0063] If there is a corresponding client identifier for the idle address, a corresponding storage node is generated based on the idle address and the corresponding client identifier and stored in the dynamic address mapping table. If the client identifier currently corresponding to the dynamic IP address is inconsistent with the client identifier corresponding to the dynamic IP address in the dynamic address mapping table, the client identifier corresponding to the dynamic IP address in the dynamic address mapping table is replaced based on the dynamic IP address and the currently corresponding client identifier.
[0064] When the target client identifier does not exist in the static address mapping table, further searching is performed to determine whether the target client identifier exists in the dynamic address mapping table.
[0065] Optionally, selecting any IP address other than multiple static IP addresses for the target client to generate a corresponding storage node can be implemented as follows: searching from the dynamic address mapping table whether there is a dynamic IP address corresponding to the target client identifier; if there is a dynamic IP address corresponding to the target client identifier, sending a first detection message to the dynamic IP address corresponding to the target client identifier; if the first detection return message corresponding to the first detection message is not received, assigning the dynamic IP address corresponding to the target client identifier to the target client; generating a first storage node with a first storage type based on the target client identifier, the dynamic IP address corresponding to the target client identifier, and the first generation time; and storing the first storage node in the dynamic address mapping table.
[0066] The dynamic address mapping table includes a plurality of dynamic IP addresses and client identifiers corresponding to the plurality of dynamic IP addresses, and a plurality of configured IP addresses and client identifiers corresponding to the plurality of configured IP addresses.
[0067] The first detection message may be an ARP message or a PING message, etc. The first generation time is the time when the current DHCP server allocates the dynamic IP address to the target client.
[0068] Optionally, the first storage node is a storage node that normally allocates an IP address to a target client, and the first storage type corresponding to the first storage node may be a DHCP type.
[0069] It should be noted that users can manually configure IP addresses for their clients at any time. Therefore, after the DHCP server is turned on and before the corresponding IP address is assigned to the target client identifier, users may manually configure IP addresses for their clients. Therefore, after the target client identifier is found in the dynamic address mapping table, it is necessary to detect the IP address corresponding to the target client identifier to determine whether the IP address has been manually assigned to other clients.
[0070] Since the IP address corresponding to the target client identifier is assigned to the target client before the target client is shut down, if the first detection return message corresponding to the first detection message is not received, it means that the IP address has not been manually configured to other clients. At this time, the IP address can be assigned as a dynamic IP address to the target client corresponding to the target client identifier.
[0071] Correspondingly, if the target client identifier is not found in the dynamic address mapping table, it is determined that the target client sending the address allocation request is a client that has not been assigned an IP address. Optionally, after searching the dynamic address mapping table to see whether the target client identifier corresponds to a dynamic IP address, the method further includes:
[0072] If there is no dynamic IP address corresponding to the target client identifier, determine the idle IP address corresponding to the target client identifier; send a second detection message to the idle IP address corresponding to the target client identifier; if the second detection return message corresponding to the second detection message is not received, allocate the idle IP address corresponding to the target client identifier to the target client; generate a second storage node with a storage type of the first storage type based on the target client identifier, the idle IP address corresponding to the target client identifier and the second generation time; and store the second storage node in the dynamic address mapping table.
[0073] Optionally, after the DHCP server determines the idle IP address corresponding to the target client identifier, it also needs to determine whether the idle IP address is manually allocated to other clients by the user. If the second detection return message corresponding to the second detection message is not received, it means that the idle IP address has not been configured to other clients by the user.
[0074] The second detection message may be an ARP message or a PING message.
[0075] Correspondingly, the corresponding address allocation method can be determined based on the target client identifier, and the optional allocation of the idle IP address corresponding to the target client identifier to the target client can be implemented as follows: the corresponding client type is determined based on the target client identifier, and if the client type is determined to be a mobile client, the idle IP address is allocated to the target client in a dynamic allocation manner; if the client type is determined to be a fixed client, the idle IP address is allocated to the target client in a static allocation manner.
[0076] As mentioned above, the client identifier may be a MAC address, and the corresponding client type may be determined based on the MAC address, wherein a mobile client may be a mobile phone, and a fixed client may be a camera, a computer, and the like.
[0077] Correspondingly, if the idle IP address is allocated to the target client in a dynamic allocation manner, a second storage node with a storage type of the first storage type is generated based on the target client identifier, the idle IP address corresponding to the target client identifier, and the second generation time; the second storage node is stored in the dynamic address mapping table.
[0078] The second generation time is the time when the DHCP server allocates the idle IP address to the target client.
[0079] Similarly, if the idle IP address is allocated to the target client in a static allocation manner, the idle IP address and the target client identifier corresponding to the idle IP address are stored in the static address mapping table.
[0080] Furthermore, after sending the first detection message to the dynamic IP address corresponding to the target client identifier, it also includes: if a first detection return message corresponding to the first detection message is received, determining the corresponding client identifier in the first detection return message; based on the dynamic IP address corresponding to the target client identifier, the corresponding client identifier in the first detection return message, and the third generation time, generating a third storage node whose storage type is the second storage type and whose storage state is the first storage state; and storing the third storage node in the dynamic address mapping table.
[0081] The third generation time is the time when the DHCP server allocates the dynamic IP address to other clients;
[0082] If a first detection return message corresponding to the first detection message is received, it means that the dynamic IP address corresponding to the target client has been artificially allocated to other clients, then the client identifier in the first detection return message is determined, and the corresponding storage node is generated based on the dynamic IP address corresponding to the target client identifier, the corresponding client identifier in the first detection return message, and the third generation time.
[0083] Among them, the third storage node is a storage node that allocates IP addresses to other clients after detecting a conflict. The second storage type corresponding to the third storage node may be STATIC, and the first storage state may be NEW.
[0084] Optionally, if a first detection return message corresponding to the first detection message is received, an idle address may be selected and allocated to the target client.
[0085] Correspondingly, if a second detection return message corresponding to the second detection message is received, indicating that the idle IP address corresponding to the target client has been artificially allocated to other clients, the client identifier in the second detection return message is determined, and the corresponding storage node is generated based on the dynamic IP address corresponding to the target client identifier, the corresponding client identifier in the second detection return message, and the time when the second detection return message is received. And the storage type corresponding to the node is the second storage type and the storage state is the first storage state.
[0086] Correspondingly, if a second detection return message corresponding to the second detection message is received, another idle IP address can be selected and allocated to the target client.
[0087] In an embodiment of the present application, an address allocation method is provided, which is applied to a DHCP server, wherein the method includes: receiving an address allocation request sent by a target client, the address allocation request including a target client identifier; searching a static address mapping table for a static IP address corresponding to the target client identifier; wherein the static address mapping table includes multiple static IP addresses and client identifiers corresponding to the multiple static IP addresses; if a static IP address corresponding to the target client identifier exists in the static address mapping table, the static IP address corresponding to the target client identifier is allocated to the target client; if a static IP address corresponding to the target client identifier does not exist in the static address mapping table, any IP address other than the multiple static IP addresses is selected for the target client to generate a corresponding storage node. The embodiment of the present application reduces address conflicts by setting a static address mapping table and determining the allocated IP address by searching the static address mapping table after receiving an address allocation request.
[0088] Figure 2 FIG. 1 is a flow chart showing an embodiment of a method for setting a lease period corresponding to a storage node. Figure 2 As shown, the method includes:
[0089] 201. Determine an original generation time corresponding to a first storage node.
[0090] The original generation time is the time when the dynamic IP address of the first storage node was last allocated to the target client.
[0091] 202. Determine a usage lease corresponding to the first storage node based on the original generation time and the first generation time.
[0092] Optionally, determining the usage lease corresponding to the first storage node based on the original generation moment and the first generation moment includes: determining the time difference between the original generation moment and the first generation moment; if the time difference between the original generation moment and the first generation moment is less than a preset time threshold, determining the first preset lease as the usage lease of the first storage node; if the time difference between the original generation moment and the first generation moment is greater than or equal to the preset time threshold, determining the second preset lease as the usage lease of the first storage node.
[0093] The time length of the first preset lease period is shorter than the time length of the second preset lease period.
[0094] Optionally, the time difference between the original generation time and the first generation time is less than a preset time threshold, indicating that the client identification corresponding to the IP address changes frequently, so a smaller usage lease can be set; the time difference between the original generation time and the first generation time is greater than or equal to a preset time threshold, indicating that the client identification corresponding to the IP address changes not very frequently, so a longer usage lease can be set.
[0095] 203. If the first storage node does not renew its lease within the usage period, remove the first storage node from the dynamic address mapping table.
[0096] Optionally, if no renewal request is received from the target client for the dynamic IP address corresponding to the first storage node during the lease period, it means that the target client has not renewed the lease during the lease period, then the first storage node is removed from the dynamic address mapping table and the IP address corresponding to the first storage node is released as an idle IP address.
[0097] Furthermore, the DHCP server will also manage the IP addresses in the dynamic address mapping table during the process of allocating IP addresses.
[0098] Figure 3 FIG. 1 is a flow chart showing a process of managing a dynamic address mapping table. Figure 3 , the method comprising:
[0099] 301. Determine a target storage node whose storage type is a second storage type from among multiple storage nodes in a dynamic address mapping table.
[0100] 302. Detect the target storage node.
[0101] 303. If the detection result meets the requirements, the target storage node is stored in the static address mapping table.
[0102] The status types corresponding to the target storage nodes include a first status type and a second status type. The detection of the target storage nodes can be implemented as follows: for the first target storage node of the first status type, determine the IP address corresponding to the first target storage node; at a first moment, send a third detection message to the IP address corresponding to the first target storage node; if a third detection return message corresponding to the third detection message is received, modify the status type corresponding to the first target storage node to the second status type, and modify the original generation time corresponding to the first target storage node to the first moment; at a second moment, send a fourth detection message to the IP address corresponding to the first target storage node.
[0103] The first moment is the moment when the first target storage node is detected in the first state type, and the second moment is the moment when the first target storage node is detected in the second state type. The first moment is before the second moment.
[0104] It should be noted that the storage nodes in the dynamic address mapping table may be detected at predetermined intervals, for example, once every two hours or once a day. The specific predetermined period may be flexibly set according to specific circumstances.
[0105] If the detection result meets the requirements, the first target storage node is stored in the static address mapping table, including: if a fourth detection return message corresponding to the fourth detection message is received, the status value corresponding to the target storage node with a status type of the second status type is increased by 1, and the first moment corresponding to the first target storage node is modified to the second moment; when the status value is greater than the preset status value, the first target storage node is stored in the static address mapping table.
[0106] The first status type may be NEW, and the second status type may be CONFIRMED.
[0107] The storage nodes in the dynamic address mapping table whose storage state is the first storage state may be detected within a preset period.
[0108] Optionally, the preset period may be 1 hour, 2 hours, etc., and the preset period generally does not exceed one day.
[0109] The detection of the first target storage node is mainly to check whether the client corresponding to the target storage node is online.
[0110] Correspondingly, a third detection message is sent to the IP address corresponding to the first target storage node. If a third detection return message corresponding to the third detection message is received, it means that the client corresponding to the first target storage node is online, and the state type of the first target storage node is modified to the second state type. And the first moment is used as the revision time corresponding to the first target storage node.
[0111] Further, at the second moment, a fourth detection message is sent to the IP address corresponding to the first target storage node, and a fourth detection return message corresponding to the fourth detection message is received, then the state value corresponding to the first target storage node whose state type is the second state type is increased by 1, and the first moment corresponding to the first target storage node is modified to the second moment. The second moment is after the first moment.
[0112] The third detection message and the fourth detection message may both be ARP messages or PING messages.
[0113] It should be noted that when the state value corresponding to the first target storage node is greater than the preset value, it can be considered that the IP address in the target storage node is a static IP address, and the target storage node can be stored in the static address mapping table.
[0114] Correspondingly, detecting the target storage node includes: for a second target storage node of the second state type, determining an IP address corresponding to the second target storage node; and at a third moment, sending a fifth detection message to the IP address corresponding to the second target storage node.
[0115] If the detection result meets the requirements, the second target storage node is stored in the static address mapping table, including: if the fifth detection return message corresponding to the fifth detection message is not received, the status value corresponding to the second target storage node is increased by 1, and the original generation time corresponding to the second target storage node is modified to the third time; when the status value is greater than the preset status value, the second target storage node is stored in the static address mapping table.
[0116] The fifth detection message may be an ARP message or a PING message.
[0117] The third moment is the moment at which the second target storage node is detected. The third moment may be the same as or different from the first moment, and may also be the same as or different from the second moment.
[0118] It can be understood that after the target storage node is stored in the static address mapping table, the target storage node is removed from the dynamic address mapping table.
[0119] Furthermore, there may be a situation where there are no idle IP addresses in the DHCP server. Therefore, in the process of allocating addresses to target client identifiers that have not been allocated IP addresses, some IP addresses need to be released from the dynamic address mapping table.
[0120] Optionally, after searching the dynamic address mapping table for whether there is a dynamic IP address corresponding to the target client identifier, the method further includes: if there is no dynamic IP address corresponding to the target client identifier and no idle IP address is available, searching the dynamic address mapping table for whether there is a first target storage node; if there is a first target storage node in the dynamic address mapping table and the client corresponding to the first target storage node is not online at the current moment, generating a fourth storage node with a storage type of the first storage type based on the IP address of the first target storage node and the target client identifier; if there is no first target storage node in the dynamic address mapping table, searching the dynamic address mapping table for whether there is a second target storage node; if there is a second target storage node in the dynamic address mapping table and the client corresponding to the second target storage node is not online at the current moment, generating a fifth storage node with a storage type of the first storage type based on the IP address of the second target storage node and the target client identifier.
[0121] It should be noted that, when the DHCP server fails to find the corresponding IP address in the static address mapping table and the dynamic mapping table, and there is no idle IP address, the dynamic mapping table is preferentially searched for a storage node of the first state type, i.e., the first target storage node. When the first target storage node is found to exist, the first target storage node is released. At this time, the IP address corresponding to the first target storage node is an idle IP address, and the IP address corresponding to the first target storage node is allocated to the target client, and a fourth storage node including the IP address corresponding to the first target storage node, the target client identifier, and the first storage type is generated, and the fourth storage node is stored in the dynamic address mapping table. Furthermore, if the first target storage node is not found, the dynamic mapping table is searched for a storage node of the second state type, i.e., the second target storage node. When the second target storage node is found to exist, the second target storage node is released. At this time, the IP address corresponding to the second target storage node is an idle IP address, and the IP address corresponding to the second target storage node is allocated to the target client, and a fifth storage node including the IP address corresponding to the second target storage node, the target client identifier, and the second storage type is generated, and the fifth storage node is stored in the dynamic address mapping table.
[0122] Figure 4 The structure diagram of an embodiment of the address allocation device provided by the present application is shown, which is applied to a dynamic host configuration protocol DHCP server. Figure 4 The device comprises: a receiving module 41, a searching module 42 and an allocating module 43.
[0123] The receiving module 41 is used to receive an address allocation request sent by a target client, wherein the address allocation request includes a client identifier;
[0124] A search module 42 is used to search whether there is a static Internet Protocol IP address corresponding to the target client identifier in a static address mapping table; wherein the static address mapping table includes a plurality of static IP addresses and client identifiers corresponding to the plurality of static IP addresses respectively;
[0125] The allocation module 43 is used to allocate the static IP address corresponding to the target client identifier to the client if the static IP address corresponding to the target client identifier exists in the static address mapping table; if the static IP address corresponding to the target client identifier does not exist in the static address mapping table, select any IP address other than the multiple static IP addresses to the target client to generate a corresponding storage node.
[0126] Optionally, the allocation module 43 is specifically used to search from the dynamic address mapping table whether there is a dynamic IP address corresponding to the target client identifier; the dynamic address mapping table includes multiple dynamic IP addresses and client identifiers corresponding to the multiple dynamic IP addresses respectively, and multiple configuration IP addresses and client identifiers corresponding to the multiple configuration IP addresses respectively; if there is a dynamic IP address corresponding to the target client identifier, send a first detection message to the dynamic IP address corresponding to the target client identifier; if the first detection return message corresponding to the first detection message is not received, allocate the dynamic IP address corresponding to the target client identifier to the target client; generate a first storage node with a first storage type based on the target client identifier, the dynamic IP address corresponding to the target client identifier and the first generation time; and store the first storage node in the dynamic address mapping table.
[0127] Optionally, the allocation module 43 is specifically used to determine the idle IP address corresponding to the target client identifier if there is no dynamic IP address corresponding to the target client identifier; send a second detection message to the idle IP address corresponding to the target client identifier; if the second detection return message corresponding to the second detection message is not received, allocate the idle IP address corresponding to the target client identifier to the target client; generate a second storage node with a storage type of the first storage type based on the target client identifier, the idle IP address corresponding to the target client identifier and the second generation time; and store the second storage node in the dynamic address mapping table.
[0128] Optionally, the allocation module 43 is further specifically used to determine the corresponding client identifier in the first detection return message if a first detection return message corresponding to the first detection message is received; based on the dynamic IP address corresponding to the target client identifier, the corresponding client identifier in the first detection return message and the third generation time, generate a third storage node whose storage type is the second storage type and whose storage state is the first storage state; and store the third storage node in the dynamic address mapping table.
[0129] Optionally, the device also includes: an update module, used to send a client identification request message to any IP address other than the multiple static IP addresses; if a return message sent by the arbitrary IP address is received, determine that the return message corresponds to the client identification; save the arbitrary IP address and its corresponding MAC to an allocated address mapping table; and update the dynamic address mapping table based on the allocated address mapping table.
[0130] Optionally, the device also includes: a removal module, used to determine the original generation time corresponding to the first storage node; determine the usage lease corresponding to the first storage node based on the original generation time and the first generation time; if the first storage node is not renewed within the usage lease, remove the first storage node from the dynamic address mapping table.
[0131] Optionally, the removal module is specifically used to determine the time difference between the original generation moment and the first generation moment; if the time difference between the original generation moment and the first generation moment is less than a preset time threshold, the first preset lease period is determined as the usage lease period of the first storage node; if the time difference between the original generation moment and the first generation moment is greater than or equal to the preset time threshold, the second preset lease period is determined as the usage lease period of the first storage node.
[0132] Optionally, the device also includes: a storage module, used to determine a target storage node with a second storage type from multiple storage nodes in the dynamic address mapping table; detect the target storage node; if the detection result meets the requirements, store the target storage node in the static address mapping table.
[0133] Optionally, the storage module is specifically used for the status type corresponding to the first target storage node to include a first status type and a second status type. For the first target storage node of the first status type, the IP address corresponding to the first target storage node is determined; at a first moment, a third detection message is sent to the IP address corresponding to the first target storage node; if the third detection return message corresponding to the third detection message is not received, the status type corresponding to the first target storage node is modified to the second status type, and the original generation time corresponding to the first target storage node is modified to the first time; at a second moment, a fourth detection message is sent to the IP address corresponding to the first target storage node; if the detection result meets the requirements, the first target storage node is stored in the static address mapping table, including: if the fourth detection return message corresponding to the fourth detection message is not received, the status value corresponding to the first target storage node of the second status type is increased by 1, and the first time corresponding to the first target storage node is modified to the second time; when the status value is greater than the preset status value, the first target storage node is stored in the static address mapping table.
[0134] Optionally, the storage module is further specifically used to: determine the IP address corresponding to the second target storage node of the second status type; at a third moment, send a fifth detection message to the IP address corresponding to the second target storage node; if the detection result meets the requirements, store the second target storage node in the static address mapping table, including: if the fifth detection return message corresponding to the fifth detection message is not received, add 1 to the status value corresponding to the second target storage node, and modify the original generation time corresponding to the second target storage node to the third moment; when the status value is greater than the preset status value, store the second target storage node in the static address mapping table.
[0135] Optionally, the storage module is further specifically used to search whether the first target storage node exists in the static address mapping table if there is no dynamic IP address corresponding to the target client identifier and no idle IP address is available; if the first target storage node exists in the static address mapping table, generate a fourth storage node with the first storage type based on the IP address of the first target storage node and the target client identifier; if the first target storage node does not exist in the static address mapping table, search whether the second target storage node exists in the static address mapping table; if the second target storage node exists in the static address mapping table, generate a fifth storage node with the first storage type based on the IP address of the second target storage node and the target client identifier.
[0136] Figure 4 The address allocation device can execute Figure 1-3 The implementation principle and technical effect of the address allocation method described in the embodiment are not described in detail. The specific way in which each module and unit performs operations in the address allocation device in the above embodiment has been described in detail in the embodiment of the method, and will not be described in detail here.
[0137] In one possible design, Figure 4 The address allocation device of the embodiment shown can be implemented as an electronic device, such as Figure 5 As shown, the electronic device may include a storage component 501 and a processing component 502;
[0138] The storage component 501 stores one or more computer instructions, wherein the one or more computer instructions are called and executed by the processing component 502 .
[0139] The processing component 502 is used to:
[0140] Receiving an address allocation request sent by a target client, wherein the address allocation request includes a target client identifier;
[0141] Searching whether there is a static Internet Protocol IP address corresponding to the target client identifier in a static address mapping table; wherein the static address mapping table includes a plurality of static IP addresses and client identifiers corresponding to the plurality of static IP addresses respectively;
[0142] If the static IP address corresponding to the target client identifier exists in the static address mapping table, the static IP address corresponding to the target client identifier is allocated to the target client;
[0143] If the static IP address corresponding to the target client identifier does not exist in the static address mapping table, any IP address other than the multiple static IP addresses is selected for the target client to generate a corresponding storage node.
[0144] The processing component 502 may include one or more processors to execute computer instructions to complete all or part of the steps in the above method. Of course, the processing component may also be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components to perform the above method.
[0145] The storage component 501 is configured to store various types of data to support operations at the terminal. The storage component can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0146] Of course, a computing device may also include other components, such as input / output interfaces, communication components, etc.
[0147] The input / output interface provides an interface between the processing component and the peripheral interface module, which may be an output device, an input device, etc.
[0148] The communication component is configured to facilitate wired or wireless communication between the Dianxi device and other devices, etc.
[0149] Among them, the electronic device can be a physical device or an elastic computing host provided by a cloud computing platform, etc. In this case, the computing device can refer to a cloud server, and the above-mentioned processing components, storage components, etc. can be basic server resources rented or purchased from the cloud computing platform.
[0150] The present application also provides a computer-readable storage medium storing a computer program, wherein the computer program can achieve the above-mentioned Figure 1-Figure 3 The address allocation method of the illustrated embodiment.
[0151] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0152] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0153] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0154] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. An address allocation method, characterized in that: Applicable to Dynamic Host Configuration Protocol DHCP server, including: Receiving an address allocation request sent by a target client, wherein the address allocation request includes a target client identifier; Searching whether there is a static Internet Protocol IP address corresponding to the target client identifier in a static address mapping table; wherein the static address mapping table includes a plurality of static IP addresses and client identifiers corresponding to the plurality of static IP addresses respectively; If the static IP address corresponding to the target client identifier exists in the static address mapping table, the static IP address corresponding to the target client identifier is allocated to the target client; If the static IP address corresponding to the target client identifier does not exist in the static address mapping table, searching the dynamic address mapping table for a dynamic IP address corresponding to the target client identifier; if the dynamic IP address corresponding to the target client identifier exists and the dynamic IP address is not occupied by other clients, assigning the dynamic IP address to the target client; If there is no dynamic IP address corresponding to the target client identifier, determine an idle IP address, determine the client type corresponding to the target client based on the target client identifier, and determine the allocation method corresponding to the idle IP address according to the client type; If the allocation mode is a static allocation mode, the idle IP address is allocated to the target client according to the static allocation mode, and the idle IP address and the target client identifier are stored in a static address mapping table; If there is no dynamic IP address corresponding to the target client identifier and no idle IP address is available, then searching whether there is a first target storage node in the dynamic address mapping table; If the first target storage node exists in the dynamic address mapping table, assigning the IP address of the first target storage node to the target client; If the first target storage node does not exist in the dynamic address mapping table, searching whether a second target storage node exists in the dynamic address mapping table; If the second target storage node exists in the dynamic address mapping table, the IP address of the second target storage node is allocated to the target client.
2. The method according to claim 1, characterized in that The searching, from the dynamic address mapping table, whether there is a dynamic IP address corresponding to the target client identifier, and if there is a dynamic IP address corresponding to the target client identifier and the dynamic IP address is not occupied by other clients, allocating the dynamic IP address to the target client comprises: Searching whether there is a dynamic IP address corresponding to the target client identifier in a dynamic address mapping table; the dynamic address mapping table includes a plurality of dynamic IP addresses and client identifiers corresponding to the plurality of dynamic IP addresses, and a plurality of configured IP addresses and client identifiers corresponding to the plurality of configured IP addresses; If there is a dynamic IP address corresponding to the target client identifier, sending a first detection message to the dynamic IP address corresponding to the target client identifier; If the first detection return message corresponding to the first detection message is not received, assigning the dynamic IP address corresponding to the target client identifier to the target client; Generate a first storage node with a first storage type based on the target client identifier, the dynamic IP address corresponding to the target client identifier, and the first generation time; The first storage node is stored in the dynamic address mapping table.
3. The method according to claim 2, characterized in that After searching the dynamic address mapping table for whether the target client identifier corresponds to a dynamic IP address, the method further includes: If there is no dynamic IP address corresponding to the target client identifier, determining an idle IP address corresponding to the target client identifier; Sending a second detection message to the idle IP address corresponding to the target client identifier; If the second detection return message corresponding to the second detection message is not received, allocating the idle IP address corresponding to the target client identifier to the target client; Generate a second storage node whose storage type is the first storage type based on the target client identifier, the idle IP address corresponding to the target client identifier, and the second generation time; The second storage node is stored.
4. The method according to claim 2, characterized in that: After sending the first detection message to the dynamic IP address corresponding to the target client identifier, the method further includes: If a first detection return message corresponding to the first detection message is received, determining a client identifier corresponding to the first detection return message; Generate a third storage node whose storage type is the second storage type and whose storage state is the first storage state based on the dynamic IP address corresponding to the target client identifier, the corresponding client identifier in the first detection return message, and the third generation time; The third storage node is stored in the dynamic address mapping table.
5. The method according to claim 2, characterized in that: The method further comprises: Sending a client identification request message to any IP address other than the multiple static IP addresses; If a return message sent by the arbitrary IP address is received, determining that the return message corresponds to a client identifier; The arbitrary IP address and the client identifier corresponding to the arbitrary IP address are saved in an allocated address mapping table; The dynamic address mapping table is updated based on the allocated address mapping table.
6. The method according to claim 2, characterized in that After generating the first storage node with the first storage type as the first storage type based on the target client identifier, the dynamic IP address corresponding to the target client identifier and the first generation time, the method further includes: Determining an original generation time corresponding to the first storage node; Determine a usage lease corresponding to the first storage node based on the original generation time and the first generation time; If the first storage node does not renew the lease within the usage lease period, the first storage node is removed from the dynamic address mapping table.
7. The method according to claim 6, characterized in that The determining the usage lease corresponding to the first storage node based on the original generation time and the first generation time includes: Determining a time difference between the original generation time and the first generation time; If the time difference between the original generation time and the first generation time is less than a preset time threshold, determining the first preset lease period as the usage lease period of the first storage node; If the time difference between the original generation time and the first generation time is greater than or equal to the preset time threshold, the second preset lease period is determined as the usage lease period of the first storage node.
8. The method according to claim 2, characterized in that: The method further comprises: Determine a target storage node whose storage type is a second storage type from among the plurality of storage nodes in the dynamic address mapping table; Detecting the target storage node; If the detection result meets the requirements, the target storage node is stored in the static address mapping table.
9. The method according to claim 8, characterized in that The state type corresponding to the target storage node includes a first state type and a second state type, and the detecting the target storage node includes: For a first target storage node of a first status type, determining an IP address corresponding to the first target storage node; At a first moment, sending a third detection message to the IP address corresponding to the first target storage node; If the third detection return message corresponding to the third detection message is not received, the state type corresponding to the first target storage node is modified to the second state type, and the original generation time corresponding to the first target storage node is modified to the first time; At the second moment, sending a fourth detection message to the IP address corresponding to the first target storage node; If the detection result meets the requirement, storing the first target storage node in the static address mapping table includes: If the fourth detection return message corresponding to the fourth detection message is not received, then the state value corresponding to the first target storage node whose state type is the second state type is increased by 1, and the first time corresponding to the first target storage node is modified to the second time; When the state value is greater than a preset state value, the first target storage node is stored in the static address mapping table.
10. The method according to claim 9, characterized in that The detecting the target storage node comprises: For a second target storage node of a second status type, determining an IP address corresponding to the second target storage node; At a third moment, sending a fifth detection message to the IP address corresponding to the second target storage node; If the detection result meets the requirement, storing the second target storage node in the static address mapping table includes: If the fifth detection return message corresponding to the fifth detection message is not received, the state value corresponding to the second target storage node is increased by 1, and the original generation time corresponding to the second target storage node is modified to the third time.
11. The method according to claim 10, characterized in that After searching the dynamic address mapping table for whether the target client identifier corresponds to a dynamic IP address, the method further includes: If there is no dynamic IP address corresponding to the target client identifier and no idle IP address is available, searching whether the first target storage node exists in the dynamic address mapping table; If the first target storage node exists in the dynamic address mapping table, generating a fourth storage node whose storage type is the first storage type based on the IP address of the first target storage node and the target client identifier; If the first target storage node does not exist in the dynamic address mapping table, searching whether the second target storage node exists in the dynamic address mapping table; If the second target storage node exists in the dynamic address mapping table, a fifth storage node whose storage type is the first storage type is generated based on the IP address of the second target storage node and the target client identifier.
12. An address allocation device, characterized in that: Applicable to Dynamic Host Configuration Protocol DHCP server, including: A receiving module, configured to receive an address allocation request sent by a target client, wherein the address allocation request includes a target client identifier; A search module, used to search whether there is a static Internet Protocol IP address corresponding to the target client identifier in a static address mapping table; wherein the static address mapping table includes multiple static IP addresses and client identifiers corresponding to the multiple static IP addresses respectively; an allocation module, configured to allocate the static IP address corresponding to the target client identifier to the target client if the static IP address corresponding to the target client identifier exists in the static address mapping table; to search the dynamic address mapping table for a dynamic IP address corresponding to the target client identifier if the static IP address corresponding to the target client identifier does not exist in the static address mapping table, and to allocate the dynamic IP address to the target client if the dynamic IP address corresponding to the target client identifier exists and the dynamic IP address is not occupied by other clients; and to determine an idle IP address if the dynamic IP address corresponding to the target client identifier does not exist, and to determine the client type corresponding to the target client based on the target client identifier, and to determine the allocation method corresponding to the idle IP address according to the client type; If the allocation method is a static allocation method, the idle IP address is allocated to the target client according to the static allocation method, and the idle IP address and the target client identifier are stored in a static address mapping table; if there is no dynamic IP address corresponding to the target client identifier and no idle IP address is available, check whether there is a first target storage node in the dynamic address mapping table; if the first target storage node exists in the dynamic address mapping table, the IP address of the first target storage node is allocated to the target client; if the first target storage node does not exist in the dynamic address mapping table, check whether there is a second target storage node in the dynamic address mapping table; if the second target storage node exists in the dynamic address mapping table, the IP address of the second target storage node is allocated to the target client.
13. An electronic device, characterized in that: including a processing component and a storage component; The storage component stores one or more computer instructions; the one or more computer instructions are used to be called by the processing component to execute the address allocation method as described in any one of claims 1 to 11.
14. A computer storage medium, characterized in that: A computer program is stored, and when the computer program is executed by a computer, the address allocation method according to any one of claims 1 to 11 is implemented.
