A method and system for allocating addresses of devices connected to routers based on DHCP

By starting the DHCP proxy service on the router assigning IP addresses to the downhook devices, the problem of equipment online caused by delay in the startup time of the DHCP service is solved, and automated IP address allocation and normal service operation are realized, improving the flexibility and availability of the network.

CN118264645BActive Publication Date: 2024-11-08GUANGZHOU TOZED KANGWEI INTELLIGENT TECH CO LTD
View PDF 11 Cites 0 Cited by

Patent Information

Application Number
CN202410442529.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-04-12
Publication Date
2024-11-08
Estimated Expiration
2044-04-12

Smart Images

  • Figure CN118264645B_ABST
    Figure CN118264645B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and system for allocating addresses of devices under a router based on DHCP, comprising: responding to a system startup signal received by a router, starting a DHCP proxy service, and if the router receives a first broadcast message, replying a first unicast message to the device under the DHCP proxy service through the DHCP proxy service, so that the device under the DHCP proxy service generates a second broadcast message and sends the second broadcast message to the DHCP proxy service; obtaining a first server IP address based on the second broadcast message through the DHCP proxy service, and if the address is the same as the IP address of the DHCP proxy service, feeding back to the device under the DHCP the result of address allocation as a request for allocation of an IP address; if the router receives a startup signal of the DHCP service, exiting the DHCP proxy service, and taking over the DHCP service by using the DHCP service. By adopting the embodiments of the present invention, abnormal problems such as the device under the DHCP proxy service not being online in time or being unable to go online can be avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of DHCP client IP address allocation, and in particular to a method and system for allocating addresses of router-attached devices based on DHCP. Background Art

[0002] During the digital transformation of the tobacco industry, there are many sensor devices and network devices. These devices often run on wireless routers or 5G routers and use the Dynamic Host Configuration Protocol DHCP (Dynamic Host Configuration Protocol) to obtain Internet IP.

[0003] However, since the DHCP service on the router depends on the complete startup of the operating system and other basic services, such as configuration reading service, network service, and the need to read historical DHCP configuration files and firewall blacklist configuration files, the startup time of the DHCP service will be much slower than the startup of the router's switch network port. When the switch network port is started, the network port Link status of the router's downstream device is connected, and the downstream device will initiate the DHCP Discover protocol to obtain the IP address assigned by DHCP. However, the DHCP service on the router has not been started at this time, resulting in the downstream device being unable to obtain the correct IP address, and the cycle for the downstream device to re-initiate DHCP Discover is uncertain, ranging from 1 minute to 10 minutes. Some old devices even need to be restarted before re-initiating the DHCP Discover request, resulting in the downstream device not being able to go online in time or being unable to go online, affecting normal business services. Summary of the invention

[0004] The embodiment of the present invention provides a method and system for allocating addresses of devices connected to a router based on DHCP. The method first uses a DHCP proxy service to allocate IP addresses to the devices connected to the router, and then starts the DHCP service to take over the DHCP business, thereby avoiding abnormal problems such as the devices connected to the router not being able to go online in time or being unable to go online.

[0005] In order to solve the above technical problems, an embodiment of the present invention provides a method for allocating addresses of devices connected to a router based on DHCP, comprising:

[0006] In response to the system startup signal received by the router, the DHCP proxy service is started. If the router receives a first broadcast message sent by a downstream device, the DHCP proxy service replies to the downstream device with a first unicast message, so that the downstream device generates a second broadcast message and sends the second broadcast message to the DHCP proxy service; wherein the first unicast message includes the lease information of the downstream device requesting the allocation of an IP address;

[0007] Acquire a first server IP address based on the second broadcast message through the DHCP proxy service, and if the first server IP address is the same as the IP address of the DHCP proxy service, determine that the address allocation result of the downstream device is the requested IP address, and feed back the address allocation result to the downstream device;

[0008] After the downstream device receives the address allocation result, if the router receives a start signal of the DHCP service, the DHCP proxy service is exited, and the DHCP service is used to receive and process the information sent by the downstream device.

[0009] In the implementation of the embodiment of the present invention, when the router receives a system startup signal, the DHCP proxy service is started preferentially. If the router receives a first broadcast message sent by a downstream device, the router replies to the first unicast message to the downstream device through the DHCP proxy service, so that the downstream device generates a second broadcast message and sends the second broadcast message to the DHCP proxy service. Then the DHCP proxy service obtains the first server IP address based on the second broadcast message. If the first server IP address is the same as the IP address of the DHCP proxy service, it is determined that the address allocation result of the downstream device is a request for allocation of an IP address, and the address allocation result is fed back to the downstream device to realize automatic allocation of IP addresses, so that the downstream devices of the router can automatically obtain available IP addresses, avoiding the tedious process and conflict problems of manually configuring IP addresses, and by responding to the first broadcast message sent by the downstream devices and replying, IP addresses can be allocated to the downstream devices newly joining the network in a timely manner, thereby improving the flexibility of the router network. In addition, after allocating an IP address to the downstream device, if the router receives a startup signal from the DHCP service, it will exit the DHCP proxy service and the DHCP service will take over the DHCP service of the DHCP proxy service to avoid abnormal problems such as the downstream device not being able to go online in time or being unable to go online due to the switch board startup time on the router being earlier than the DHCP service startup time on the router, thereby ensuring the normal service of the DHCP service.

[0010] As a preferred solution, the method for allocating addresses of devices connected to a router based on DHCP further includes:

[0011] If the lease time of the downstream device is equal to the preset value and the DHCP proxy service has not exited, a renewal request is made to the DHCP proxy service through the downstream device; wherein the preset value is equal to 1 / N of the preset DHCP lease time of the downstream device for requesting allocation of an IP address, N>1, and the preset DHCP lease time is greater than or equal to 10 seconds and less than or equal to 30 seconds.

[0012] A preferred solution for implementing the embodiment of the present invention is that after using the DHCP service to receive and process the information sent by the downstream device, if the lease time of the downstream device is equal to 1 / N of the preset DHCP lease time of the downstream device for requesting allocation of an IP address, a renewal request is initiated to the DHCP proxy service through the downstream device, so that the renewal can be completed before the lease expires as much as possible, thereby ensuring the connectivity and normal operation of the downstream device of the router in the network.

[0013] As a preferred solution, after receiving and processing the information sent by the downstream device using the DHCP service, if the lease time of the downstream device is equal to a preset value, requesting renewal from the DHCP proxy service through the downstream device is specifically as follows:

[0014] If the lease time of the downstream device is equal to the preset value and the DHCP proxy service has not exited, the second broadcast message is updated through the downstream device based on the first unicast message, and the updated second broadcast message is initiated to the DHCP proxy service; wherein the first unicast message includes the preset DHCP lease time of the downstream device for requesting the allocation of an IP address;

[0015] Through the DHCP proxy service, a second server IP address is obtained based on the updated second broadcast message. If the second server IP address is the same as the IP address of the DHCP proxy service, it is determined that the address allocation result of the downstream device is the requested IP address, the DHCP lease time of the downstream device is restored to the preset DHCP lease time, and the address allocation result is fed back to the downstream device.

[0016] A preferred solution for implementing the embodiment of the present invention is that when the lease time of the downstream device is equal to 1 / N of the preset DHCP lease time of the downstream device requesting the allocation of an IP address, the second broadcast message is updated, and the second server IP address is obtained based on the updated second broadcast message. If the second server IP address is the same as the IP address of the DHCP proxy service, the DHCP lease time of the downstream device is directly restored to the preset DHCP lease time, and the address allocation result is fed back to the downstream device, thereby reducing unnecessary address allocation and renewal operations and improving the utilization efficiency of network resources.

[0017] As a preferred solution, the system startup signal received by the response router starts the DHCP proxy service. If the router receives a first broadcast message sent by a downstream device, the DHCP proxy service replies to the downstream device with a first unicast message, so that the downstream device generates a second broadcast message and sends the second broadcast message to the DHCP proxy service. Specifically,

[0018] In response to the system startup signal received by the router, the DHCP proxy service is started. If the router receives a first broadcast message sent by a downstream device, the MAC address of the downstream device is obtained from the first broadcast message through the DHCP proxy service, and according to the MAC address of the downstream device, an address search is performed in the temporary IP address pool of the DHCP proxy service to obtain the requested IP address of the downstream device, and then a first unicast message is generated based on a preset DHCP lease time of the requested IP address of the downstream device, and the first unicast message is sent to the downstream device;

[0019] When the downstream device receives the first unicast message, the downstream device generates the second broadcast message and sends the second broadcast message to the DHCP proxy service.

[0020] The preferred solution of the embodiment of the present invention is to search in the temporary IP address pool according to the MAC address of the downstream device, so as to dynamically allocate IP addresses to devices newly added to the network, thereby supporting rapid access of mobile devices and temporary visitors and improving the flexibility and availability of the network.

[0021] As a preferred solution, the first server IP address is obtained based on the second broadcast message through the DHCP proxy service, and if the first server IP address is the same as the IP address of the DHCP proxy service, the address allocation result of the downstream device is determined to be the requested IP address, and the address allocation result is fed back to the downstream device, specifically:

[0022] Obtaining the first server IP address from the opt on field of the second broadcast message through the DHCP proxy service;

[0023] If the first server IP address is the same as the IP address of the DHCP proxy service, it is determined that the address allocation result of the downstream device is the requested IP address, and a DHCP ACK packet is replied to the downstream device through the DHCP proxy service to complete the address allocation for the downstream device; wherein the DHCP ACK packet includes a DHCP ACK message and the address allocation result of the downstream device.

[0024] According to a preferred solution of the embodiment of the present invention, after confirming that the address allocation result of the downstream device is the requested IP address, the DHCP proxy service can reply to the downstream device with a DHCP ACK packet including a DHCP ACK message and the address allocation result of the downstream device, so as to notify the downstream device of the allocated IP address and other related configuration information.

[0025] As a preferred solution, the method for allocating addresses of devices connected to a router based on DHCP, after receiving and processing information sent by the connected device using the DHCP service, further comprises:

[0026] If the lease time of the downstream device is equal to a preset value, the second broadcast message is sent to the DHCP service through the downstream device, so that the DHCP service replies a NAK response message to the downstream device; wherein the preset value is equal to 1 / N of the preset DHCP lease time of the downstream device for requesting the allocation of an IP address, N>1, and the preset DHCP lease time is greater than or equal to 10 seconds and less than or equal to 30 seconds;

[0027] When the downstream device receives the NAK response message, the first broadcast message is sent to the router again through the downstream device, and then the first unicast message is replied to the downstream device through the DHCP service, so that the downstream device updates the second broadcast message and sends the updated second broadcast message to the DHCP service, and then obtains the third server IP address based on the updated second broadcast message through the DHCP service. If the third server IP address is the same as the IP address of the DHCP service, it is determined that the address allocation result of the downstream device is the requested IP address, and the address allocation result is fed back to the downstream device.

[0028] In a preferred solution for implementing the embodiment of the present invention, when the IP address of the DHCP proxy service is different from the first server IP address, it means that the allocated IP address may be in conflict or misconfigured. At this time, a NAK response message is sent to the downstream device to inform the downstream device that it has not obtained the required IP address, so that the address request and allocation are re-performed in time to ensure the normal operation of the downstream device.

[0029] In order to solve the same technical problem, an embodiment of the present invention further provides a DHCP-based router-connected device address allocation system, comprising:

[0030] a response startup module, configured to respond to a system startup signal received by the router and start the DHCP proxy service; if the router receives a first broadcast message sent by a downstream device, the DHCP proxy service replies to the downstream device with a first unicast message, so that the downstream device generates a second broadcast message and sends the second broadcast message to the DHCP proxy service; wherein the first unicast message includes lease information of the downstream device requesting the allocation of an IP address;

[0031] An address allocation module, configured to obtain a first server IP address based on the second broadcast message through the DHCP proxy service, and if the first server IP address is the same as the IP address of the DHCP proxy service, determine that the address allocation result of the downstream device is the requested IP address, and feed back the address allocation result to the downstream device;

[0032] The proxy service exit module is used to exit the DHCP proxy service after the downstream device receives the address allocation result if the router receives a start signal of the DHCP service, and use the DHCP service to receive and process the information sent by the downstream device.

[0033] As a preferred solution, the DHCP-based router-connected device address allocation system further includes:

[0034] A renewal module is used to request renewal from the DHCP proxy service through the downstream device if the lease time of the downstream device is equal to a preset value and the DHCP proxy service has not exited; wherein the preset value is equal to 1 / N of the preset DHCP lease time of the downstream device for requesting allocation of an IP address, N>1, and the preset DHCP lease time is greater than or equal to 10 seconds and less than or equal to 30 seconds.

[0035] As a preferred solution, the renewal module specifically includes:

[0036] a message updating unit, configured to update the second broadcast message based on the first unicast message through the downstream device if the lease time of the downstream device is equal to a preset value and the DHCP proxy service has not exited, and initiate the updated second broadcast message to the DHCP proxy service; wherein the first unicast message includes the preset DHCP lease time of the downstream device for requesting the allocation of an IP address;

[0037] A renewal unit is used to obtain a second server IP address based on the updated second broadcast message through the DHCP proxy service, and if the second server IP address is the same as the IP address of the DHCP proxy service, determine that the address allocation result of the downstream device is the requested IP address, restore the DHCP lease time of the downstream device to the preset DHCP lease time, and feed back the address allocation result to the downstream device.

[0038] As a preferred solution, the response initiation module specifically includes:

[0039] An address search unit is configured to start a DHCP proxy service in response to a system startup signal received by the router, and if the router receives a first broadcast message sent by a downstream device, obtain the MAC address of the downstream device from the first broadcast message through the DHCP proxy service, and perform an address search in a temporary IP address pool of the DHCP proxy service according to the MAC address of the downstream device to obtain the requested IP address of the downstream device, and then generate a first unicast message based on a preset DHCP lease time of the requested IP address of the downstream device, and send the first unicast message to the downstream device;

[0040] The message transmission unit is configured to generate the second broadcast message through the downstream device and send the second broadcast message to the DHCP proxy service when the downstream device receives the first unicast message. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] Figure 1 : A flow chart of a method for allocating addresses of devices connected to a router based on DHCP provided in Embodiment 1 of the present invention;

[0042] Figure 2 : A structural diagram of a DHCP-based router-connected device address allocation system provided in Example 1 of the present invention. DETAILED DESCRIPTION

[0043] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0044] Embodiment one:

[0045] Please refer to Figure 1, a method for allocating addresses of devices connected to a router based on DHCP is provided in an embodiment of the present invention. The method comprises steps S1 to S3, and each step is specifically as follows:

[0046] In this embodiment, before executing step S1, the system may be pre-set according to steps S01 to S02.

[0047] Step S01, develop a UDP program and implement the DHCP protocol stack function, and configure the DHCP proxy service to start with the highest priority of the system. Wherein, the DHCP proxy service is configured to start with the highest priority of the system, and when the system starts, the DHCP proxy service is started first.

[0048] Step S02, setting lease information: the lease information is in option, option code = 51; the preset DHCP lease time can be set to 10 seconds according to the DHCP proxy service configuration.

[0049] Step S1, responding to the system startup signal received by the router, starting the DHCP proxy service. If the router receives a first broadcast message sent by a downstream device, the router replies to the first unicast message to the downstream device through the DHCP proxy service, so that the downstream device generates a second broadcast message and sends the second broadcast message to the DHCP proxy service.

[0050] The first unicast message includes the lease information of the downstream device requesting the allocation of an IP address.

[0051] It should be noted that the Dynamic Host Configuration Protocol DHCP is a network management protocol used to centrally manage and configure user IP addresses dynamically. In traditional technical solutions, the DHCP protocol is defined by RFC 2131 and adopts a client / server communication mode. The client (DHCP Client) submits a configuration request to the server (DHCP Server), and the DHCP Server dynamically allocates an IP address, subnet mask, and default gateway address to each device on the network. The DHCP protocol uses UDP as a transmission protocol. The DHCP client sends a request message to port 68 of the DHCP server, and the DHCP server responds with a reply message to port 67 of the DHCP client. Only the DHCP server in the same network segment as the DHCP client can receive the DHCP DI SCOVER message broadcast by the DHCP client. When the DHCP client and the DHCP server are not in the same network segment, a DHCP relay must be deployed to forward the DHCP message between the DHCP client and the DHCP server.

[0052] In this embodiment, since the DHCP protocol interaction is carried out through UDP port 67, after the DHCP proxy service is started, the client's DHCP proxy service is required to listen to port 67 of DHCP and listen to UDP broadcast packets to receive the DHCP request (i.e., the first broadcast message) from the client (i.e., the downstream device of the router), and while listening to port 67 receiving the DHCP request, obtain the destination IP address of the port sending the DHCP request as 255.255.255.255 (i.e., the MAC address of the downstream device) and the source IP address of port 67 as 0.0.0.0.

[0053] As a preferred solution, step S1 includes step S11 to step S12, and each step is specifically as follows:

[0054] Step S11, responding to the system startup signal received by the router, starting the DHCP proxy service, if the router receives the first broadcast message sent by the downstream device, then through the DHCP proxy service, the MAC address of the downstream device is obtained from the first broadcast message, and according to the MAC address of the downstream device, the address is searched in the temporary IP address pool of the DHCP proxy service to obtain the requested IP address of the downstream device, and then based on the preset DHCP lease time of the requested IP address of the downstream device, a first unicast message is generated, and the first unicast message is sent to the downstream device via the switching network port in unicast mode.

[0055] It should be noted that in addition to the DHCP service, configuration management service, firewall service and switch network port, the router also has a DHCP proxy service. Among them, the switch network port is used to receive messages transmitted by one or more downstream devices. When the router receives the first broadcast message sent by any downstream device, it can reply to the first unicast message to the downstream device through the DHCP proxy service.

[0056] In this embodiment, the first broadcast message is a DHCP Discover message, and the first unicast message is a DHCPoffer message. The DHCP Discover message carries information such as the MAC address of the downstream device, and the MAC address of the downstream device is located in the flags field in the DHCP Discover message. In addition, the DHCP offer message carries IP address lease information and other configuration information, and the IP address lease information includes but is not limited to the preset DHCP lease time for the downstream device to request the allocation of an IP address. The DHCP offer message is sent to the downstream device mainly to inform the downstream device that the DHCP proxy service can provide an IP address for the downstream device.

[0057] Regarding step S11 of "obtaining the MAC address of the downstream device from the first broadcast message through the DHCP proxy service, and performing an address lookup in the temporary IP address pool of the DHCP proxy service based on the MAC address of the downstream device to obtain the requested allocated IP address of the downstream device", it may specifically include the following steps S03 to S04.

[0058] Step S03: Obtain the MAC address of the downstream device from the first broadcast message through the DHCP proxy service.

[0059] Step S04, through the DHCP proxy service, perform an address search in the temporary IP address pool of the DHCP proxy service; if an IP address in the "Expired" state can be found, that is, an IP address that has been allocated to a downstream device and has expired, then the "Expired" IP address will be used as the requested IP address for the downstream device; if no "Expired" IP address is found, then a random search for an "Idle" IP address in the temporary IP address pool of the DHCP proxy service will be performed as the requested IP address for the downstream device, such as allocating 172.16.16.1.

[0060] The DHCP proxy service temporary IP address pool includes but is not limited to IP addresses in the range [172.16.16.1-172.16.16.254].

[0061] Step S12: When the downstream device receives the first unicast message, the downstream device generates a second broadcast message, and sends the second broadcast message to the DHCP proxy service via the switch network port in a broadcast manner.

[0062] In this embodiment, the second broadcast message is a DHCP Request message, which is used to request the DHCP proxy service to allocate the requested IP address obtained in step S11 to the downstream device.

[0063] Step S2, through the DHCP proxy service, obtain the first server IP address based on the second broadcast message. If the first server IP address is the same as the IP address of the DHCP proxy service, determine that the address allocation result of the downstream device is a request for an allocated IP address, and feedback the address allocation result to the downstream device so that the downstream device obtains an allocated IP, and the lease time is 10 seconds.

[0064] As a preferred solution, step S2 includes step S21 to step S22, and each step is specifically as follows:

[0065] Step S21: Obtain the first server IP address from the opt field of the second broadcast message through the DHCP proxy service.

[0066] Step S22: If the first server IP address is the same as the IP address of the DHCP proxy service, it is determined that the address allocation result of the downstream device is a request for IP address allocation, and a DHCP ACK packet is replied to the downstream device through the DHCP proxy service to complete the address allocation to the downstream device.

[0067] The DHCP ACK packet includes a DHCP ACK message and the address allocation result of the downstream device.

[0068] It should be noted that based on the logic of the DHCP protocol, there may be multiple DHCP servers in the local area network, and the downstream device will select a DHCP server, which is the server IP field in the opt i on. Therefore, if the first server IP address obtained from the opt i on field of the second broadcast message is the same as the IP address of the DHCP proxy service, it indicates that the address allocation for the downstream device is completed.

[0069] Step S3, after the downstream device receives the address allocation result, if the router receives the start signal of the DHCP service, it exits the DHCP proxy service and uses the DHCP service to receive and process the information sent by the downstream device, that is, the DHCP service takes over the DHCP service.

[0070] In this embodiment, before the DHCP service is started, the DHCP proxy service handles the DHCP service, that is, it is responsible for receiving and processing information sent by the downstream device and other related services. After the router receives the system startup signal, after a certain period of time, the service initialization, specifically: first the configuration management service, then the firewall service, until the DHCP startup is completed, the DHCP service sends an exit message to the DHCP proxy service through the socket mechanism to exit the DHCP proxy service, and the DHCP service takes over the DHCP service.

[0071] As a preferred solution, after executing step S2, a renewal process is also included. For details of the process, please refer to step S4.

[0072] Step S4: If the lease time of the downstream device is equal to the preset value and the DHCP proxy service has not exited, a request for renewal is made to the DHCP proxy service through the downstream device.

[0073] The preset value is equal to 1 / N of the preset DHCP lease time of the downstream device for requesting the allocation of an IP address, N>1, and the preset DHCP lease time is greater than or equal to 10 seconds and less than or equal to 30 seconds. In this embodiment, the preset DHCP lease time can be set to 10 seconds according to the DHCP proxy service configuration, and N is set to 2, that is, the preset value is 5 seconds.

[0074] It should be noted that the effect of setting the lease to 10 seconds and the preset value to 5 seconds is to ensure that the downstream device will initiate a DHCP renewal request again in 5 seconds, which solves the problem in the prior art that the downstream device does not obtain the DHCP request for a long time and needs to re-initiate the DHCP request.

[0075] As an example, according to the DHCP protocol standard, N can be set to 2, that is, when the lease time of the downstream device reaches half of the preset DHCP lease time for requesting the allocation of an IP address by the downstream device, the downstream device will initiate a DHCP Request message to the DHCP proxy service to request renewal.

[0076] As a preferred solution, step S4 includes step S41 to step S42, and each step is specifically as follows:

[0077] Step S41, if the lease time of the downstream device is equal to the preset value and the DHCP proxy service has not exited, the second broadcast message is updated based on the first unicast message through the downstream device, and the updated second broadcast message is initiated to the DHCP proxy service; wherein the first unicast message includes the preset DHCP lease time of the downstream device requesting the allocation of an IP address.

[0078] Step S42, through the DHCP proxy service, obtain the second server IP address based on the updated second broadcast message. If the second server IP address is the same as the IP address of the DHCP proxy service, determine that the address allocation result of the downstream device is a request for IP address allocation, restore the DHCP lease time of the downstream device to the preset DHCP lease time, and feedback the address allocation result to the downstream device.

[0079] It should be noted that when the DHCP function is turned on, as long as the client (i.e., the device connected to the router) is in the state of automatically obtaining an IP address, the server (i.e., the DHCP proxy service) will dynamically assign an IP address to the client. If the client has a manually configured IP address, the client will not apply for an IP address from the server again.

[0080] As a preferred solution, after executing step S3 to enable the DHCP service to take over the DHCP service, steps S5 to S6 are further included, and each step is specifically as follows:

[0081] Step S5, if the lease time of the downstream device is equal to the preset value, a second broadcast message is sent to the DHCP service through the downstream device to request renewal. However, since the DHCP service does not have a lease record of the DHCP proxy service, the IP address cannot be allocated normally. Therefore, the DHCP service directly replies with a NAK response message to the downstream device to notify the user that a suitable IP address cannot be allocated.

[0082] The preset value is equal to 1 / N of the preset DHCP lease time of the downstream device for requesting the allocation of an IP address, N>1, and the preset DHCP lease time is greater than or equal to 10 seconds and less than or equal to 30 seconds. In this embodiment, the preset DHCP lease time is 10 seconds, and N is set to 2, that is, the preset value is 5 seconds.

[0083] In step S6, when the downstream device receives the NAK response message, since the downstream device has not received the correct DHCP ACK message at this time, the first broadcast message is sent to the router again through the downstream device. At this time, the DHCP service in the router has officially taken over the DHCP service. The first unicast message is replied to the downstream device through the DHCP service, so that the downstream device updates the second broadcast message and sends the updated second broadcast message to the DHCP service. Then, the third server IP address is obtained based on the updated second broadcast message through the DHCP service. If the third server IP address is the same as the IP address of the DHCP service, it is determined that the address allocation result of the downstream device is a request for allocation of an IP address, and the address allocation result is fed back to the downstream device.

[0084] Please refer to Figure 2 , is a structural diagram of a method system for allocating addresses of router-attached devices based on DHCP provided by an embodiment of the present invention, the system includes a response start module M1, an address allocation module M2 and an agent service exit module M3, and the specifics of each module are as follows:

[0085] The response startup module M1 is used to respond to the system startup signal received by the router and start the DHCP proxy service. If the router receives a first broadcast message sent by a downstream device, the router replies to the downstream device with a first unicast message through the DHCP proxy service, so that the downstream device generates a second broadcast message and sends the second broadcast message to the DHCP proxy service; wherein the first unicast message includes the lease information of the downstream device requesting the allocation of an IP address;

[0086] The address allocation module M2 is used to obtain the first server IP address based on the second broadcast message through the DHCP proxy service, and if the first server IP address is the same as the IP address of the DHCP proxy service, determine that the address allocation result of the downstream device is a request for allocation of an IP address, and feedback the address allocation result to the downstream device;

[0087] The proxy service exit module M3 is used to exit the DHCP proxy service after the downstream device receives the address allocation result, if the router receives the start signal of the DHCP service, and use the DHCP service to receive and process the information sent by the downstream device.

[0088] As a preferred option, please refer to Figure 2 The embodiment of the present invention provides a method system for allocating addresses of devices connected to a router based on DHCP, and further includes a renewal module M4, which is specifically as follows:

[0089] The renewal module M4 is used to request renewal from the DHCP proxy service through the downstream device if the lease time of the downstream device is equal to a preset value and the DHCP proxy service has not exited; wherein the preset value is equal to 1 / N of the preset DHCP lease time of the downstream device for requesting allocation of an IP address, N>1, and the preset DHCP lease time is greater than or equal to 10 seconds and less than or equal to 30 seconds.

[0090] As a preferred solution, the renewal module M4 specifically includes a message updating unit 41 and a renewal unit 42, and the details of each unit are as follows:

[0091] The message updating unit 41 is used for updating the second broadcast message based on the first unicast message through the downstream device if the lease time of the downstream device is equal to the preset value and the DHCP proxy service has not exited, and initiating the updated second broadcast message to the DHCP proxy service; wherein the first unicast message includes the preset DHCP lease time of the downstream device for requesting the allocation of an IP address;

[0092] The renewal unit 42 is used to obtain the second server IP address based on the updated second broadcast message through the DHCP proxy service. If the second server IP address is the same as the IP address of the DHCP proxy service, it is determined that the address allocation result of the downstream device is a request for allocation of an IP address, the DHCP lease time of the downstream device is restored to the preset DHCP lease time, and the address allocation result is fed back to the downstream device.

[0093] As a preferred solution, the response start module M1 specifically includes an address search unit 11 and a message transmission unit 12, and the details of each unit are as follows:

[0094] The address search unit 11 is used to respond to the system startup signal received by the router and start the DHCP proxy service. If the router receives a first broadcast message sent by a downstream device, the DHCP proxy service obtains the MAC address of the downstream device from the first broadcast message, and performs an address search in the temporary IP address pool of the DHCP proxy service according to the MAC address of the downstream device to obtain the requested IP address of the downstream device, and then generates a first unicast message based on the preset DHCP lease time of the requested IP address of the downstream device, and sends the first unicast message to the downstream device;

[0095] The message transmission unit 12 is used for generating a second broadcast message and sending the second broadcast message to the DHCP proxy service through the downstream device when the downstream device receives the first unicast message.

[0096] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0097] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:

[0098] The present invention provides a method and system for allocating addresses to devices connected to a router based on DHCP. When the router receives a system startup signal, the DHCP proxy service is started first. If the router receives a first broadcast message sent by the device connected to the router, the DHCP proxy service is used to reply a first unicast message to the device connected to the router, so that the device connected to the router generates a second broadcast message and sends the second broadcast message to the DHCP proxy service. Then, the DHCP proxy service obtains a first server IP address based on the second broadcast message. If the first server IP address is the same as the IP address of the DHCP proxy service, it is determined that the address allocation result of the device connected to the router is a request for allocation of an IP address, and the address allocation result is fed back to the device connected to the router, thereby realizing automatic allocation of IP addresses. This enables the device connected to the router to automatically obtain an available IP address, thereby avoiding the tedious process and conflict problems of manually configuring the IP address. Furthermore, by responding to and replying to the first broadcast message sent by the device connected to the router, an IP address can be allocated to the device connected to the router that has newly joined the network in a timely manner, thereby improving the flexibility of the router network. In addition, after allocating an IP address to the downstream device, if the router receives a startup signal from the DHCP service, it will exit the DHCP proxy service and the DHCP service will take over the DHCP service of the DHCP proxy service to avoid abnormal problems such as the downstream device not being able to go online in time or being unable to go online due to the switch board startup time on the router being earlier than the DHCP service startup time on the router, thereby ensuring the normal service of the DHCP service.

[0099] The specific embodiments described above further illustrate the purpose, technical solutions and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. It is particularly pointed out that for those skilled in the art, any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the scope of protection of the present invention.

Claims

1. A method for allocating addresses of devices connected to a router based on DHCP, characterized in that: include: In response to the system startup signal received by the router, the DHCP proxy service is started. If the router receives a first broadcast message sent by a downstream device, the DHCP proxy service replies to the downstream device with a first unicast message, so that the downstream device generates a second broadcast message and sends the second broadcast message to the DHCP proxy service; wherein the first unicast message includes the lease information of the downstream device requesting the allocation of an IP address; Obtaining the first server IP address based on the second broadcast message through the DHCP proxy service, and if the first server IP address is the same as the IP address of the DHCP proxy service, determining that the address allocation result of the downstream device is the requested IP address, and feeding back the address allocation result to the downstream device; After the downstream device receives the address allocation result, if the router receives a start signal of the DHCP service, the router exits the DHCP proxy service and uses the DHCP service to receive and process the information sent by the downstream device; The system startup signal received by the response router starts the DHCP proxy service. If the router receives a first broadcast message sent by a downstream device, the DHCP proxy service replies to the downstream device with a first unicast message, so that the downstream device generates a second broadcast message and sends the second broadcast message to the DHCP proxy service. Specifically, In response to the system startup signal received by the router, the DHCP proxy service is started. If the router receives a first broadcast message sent by a downstream device, the MAC address of the downstream device is obtained from the first broadcast message through the DHCP proxy service, and according to the MAC address of the downstream device, an address search is performed in the temporary IP address pool of the DHCP proxy service to obtain the requested IP address of the downstream device, and then a first unicast message is generated based on a preset DHCP lease time of the requested IP address of the downstream device, and the first unicast message is sent to the downstream device; When the downstream device receives the first unicast message, the downstream device generates the second broadcast message and sends the second broadcast message to the DHCP proxy service.

2. A method for allocating addresses of devices connected to a router based on DHCP as claimed in claim 1, characterized in that: Also includes: If the lease time of the downstream device is equal to the preset value and the DHCP proxy service has not exited, a renewal request is made to the DHCP proxy service through the downstream device; wherein the preset value is equal to 1 / N of the preset DHCP lease time of the downstream device for requesting allocation of an IP address, N>1, and the preset DHCP lease time is greater than or equal to 10 seconds and less than or equal to 30 seconds.

3. A method for allocating addresses of devices connected to a router based on DHCP as claimed in claim 2, characterized in that: If the lease time of the downstream device is equal to the preset value, a request for renewal is made to the DHCP proxy service through the downstream device, specifically: If the lease time of the downstream device is equal to the preset value and the DHCP proxy service has not exited, the second broadcast message is updated through the downstream device based on the first unicast message, and the updated second broadcast message is initiated to the DHCP proxy service; wherein the first unicast message includes the preset DHCP lease time of the downstream device for requesting the allocation of an IP address; Through the DHCP proxy service, a second server IP address is obtained based on the updated second broadcast message. If the second server IP address is the same as the IP address of the DHCP proxy service, the address allocation result of the downstream device is determined to be the requested IP address, the DHCP lease time of the downstream device is restored to the preset DHCP lease time, and the address allocation result is fed back to the downstream device.

4. A method for allocating addresses of devices connected to a router based on DHCP as claimed in claim 1, characterized in that: The method of obtaining the first server IP address based on the second broadcast message through the DHCP proxy service, and if the first server IP address is the same as the IP address of the DHCP proxy service, determining that the address allocation result of the downstream device is the requested IP address, and feeding back the address allocation result to the downstream device, is specifically as follows: Obtaining the first server IP address from the option field of the second broadcast message through the DHCP proxy service; If the first server IP address is the same as the IP address of the DHCP proxy service, it is determined that the address allocation result of the downstream device is the requested IP address, and a DHCPACK packet is replied to the downstream device through the DHCP proxy service to complete the address allocation to the downstream device; wherein the DHCP ACK packet includes a DHCP ACK message and the address allocation result of the downstream device.

5. A method for allocating addresses of devices connected to a router based on DHCP as claimed in claim 1, characterized in that: After receiving and processing the information sent by the downstream device by using the DHCP service, the method further includes: If the lease time of the downstream device is equal to a preset value, the second broadcast message is sent to the DHCP service through the downstream device, so that the DHCP service replies a NAK response message to the downstream device; wherein the preset value is equal to 1 / N of the preset DHCP lease time of the downstream device for requesting the allocation of an IP address, N>1, and the preset DHCP lease time is greater than or equal to 10 seconds and less than or equal to 30 seconds; When the downstream device receives the NAK response message, the first broadcast message is sent to the router again through the downstream device, and then the first unicast message is replied to the downstream device through the DHCP service, so that the downstream device updates the second broadcast message and sends the updated second broadcast message to the DHCP service, and then obtains the third server IP address based on the updated second broadcast message through the DHCP service. If the third server IP address is the same as the IP address of the DHCP service, it is determined that the address allocation result of the downstream device is the requested IP address, and the address allocation result is fed back to the downstream device.

6. A DHCP-based router-connected device address allocation system, characterized in that: include: a response startup module, configured to respond to a system startup signal received by the router and start the DHCP proxy service; if the router receives a first broadcast message sent by a downstream device, the DHCP proxy service replies to the downstream device with a first unicast message, so that the downstream device generates a second broadcast message and sends the second broadcast message to the DHCP proxy service; wherein the first unicast message includes lease information of the downstream device requesting the allocation of an IP address; An address allocation module, configured to obtain a first server IP address based on the second broadcast message through the DHCP proxy service, and if the first server IP address is the same as the IP address of the DHCP proxy service, determine that the address allocation result of the downstream device is the requested IP address, and feed back the address allocation result to the downstream device; The proxy service exit module is used to exit the DHCP proxy service after the downstream device receives the address allocation result, if the router receives a start signal of the DHCP service, and use the DHCP service to receive and process the information sent by the downstream device; Wherein, the response initiation module specifically includes: An address search unit is configured to start a DHCP proxy service in response to a system startup signal received by the router, and if the router receives a first broadcast message sent by a downstream device, obtain the MAC address of the downstream device from the first broadcast message through the DHCP proxy service, and perform an address search in a temporary IP address pool of the DHCP proxy service according to the MAC address of the downstream device to obtain the requested IP address of the downstream device, and then generate a first unicast message based on a preset DHCP lease time of the requested IP address of the downstream device, and send the first unicast message to the downstream device; The message transmission unit is configured to generate the second broadcast message through the downstream device and send the second broadcast message to the DHCP proxy service when the downstream device receives the first unicast message.

7. A DHCP-based router-connected device address allocation system as claimed in claim 6, characterized in that: Also includes: A renewal module is used to request renewal from the DHCP proxy service through the downstream device if the lease time of the downstream device is equal to a preset value and the DHCP proxy service has not exited; wherein the preset value is equal to 1 / N of the preset DHCP lease time of the downstream device for requesting allocation of an IP address, N>1, and the preset DHCP lease time is greater than or equal to 10 seconds and less than or equal to 30 seconds.

8. A DHCP-based router-connected device address allocation system as claimed in claim 7, characterized in that: The renewal module specifically includes: a message updating unit, configured to update the second broadcast message based on the first unicast message through the downstream device if the lease time of the downstream device is equal to a preset value and the DHCP proxy service has not exited, and initiate the updated second broadcast message to the DHCP proxy service; wherein the first unicast message includes the preset DHCP lease time of the downstream device for requesting the allocation of an IP address; A renewal unit is used to obtain a second server IP address based on the updated second broadcast message through the DHCP proxy service, and if the second server IP address is the same as the IP address of the DHCP proxy service, determine that the address allocation result of the downstream device is the requested IP address, restore the DHCP lease time of the downstream device to the preset DHCP lease time, and feedback the address allocation result to the downstream device.

Citation Information

Patent Citations

  • Method for processing DHCP address allocation and DHCP relay

    CN101330531A

  • Address allocation method and equipment

    CN102238245A

  • Method and equipment for managing customer address table

    CN102325202A

  • Address distribution method and address distribution device

    CN102523316A

  • Message processing method and device

    CN107547688A