CN-116208481-B - Gateway configuration method and device
Abstract
The present application relates to the field of network communications technologies, and in particular, to a gateway configuration method and device. The method is applied to an OVS virtual switch and comprises the steps of receiving a Mac address of a newly created virtual machine and custom gateway information appointed for the virtual machine, which are issued by a controller, receiving a DHCP request message sent by a target virtual machine, obtaining Mac address information of the target virtual machine carried by an appointed field of the DHCP request message, and if it is determined that the target custom gateway information corresponding to the Mac address of the target virtual machine is maintained locally, carrying the target custom gateway information in a DHCP response message and sending the DHCP response message to the target virtual machine so that the target virtual machine carries out gateway configuration based on the target custom gateway information.
Inventors
- HUANG YUNFENG
- DU HONGZHANG
Assignees
- 新华三技术有限公司
Dates
- Publication Date
- 20260505
- Application Date
- 20230210
Claims (9)
- 1. A gateway configuration method, applied to an OVS virtual switch, the method comprising: receiving a Mac address of a newly created virtual machine and custom gateway information appointed for the virtual machine, wherein the Mac address is issued by a controller; determining whether a DHCP proxy service corresponding to a subnet of the virtual machine exists, wherein one DHCP proxy service corresponds to one or more subnets; If not, establishing a DHCP proxy service corresponding to the subnet, maintaining the Mac address of the virtual machine and the custom gateway information appointed for the virtual machine in the DHCP proxy service, and adding the DHCP proxy service into an OVS bridge through an interface; if yes, maintaining the Mac address of the virtual machine and the custom gateway information appointed for the virtual machine in the DHCP proxy service; Receiving a DHCP request message sent by a target virtual machine, forwarding the DHCP request message to a corresponding DHCP proxy service, and acquiring Mac address information of the target virtual machine carried by a designated field of the DHCP request message by the DHCP proxy service; If the DHCP proxy service determines that the target custom gateway information corresponding to the Mac address of the target virtual machine is maintained locally, the target custom gateway information is carried in a designated option field of a DHCP response message and is sent to the target virtual machine, so that the target virtual machine carries out gateway configuration based on the target custom gateway information.
- 2. The method of claim 1, wherein the step of receiving the Mac address of the newly created virtual machine and the custom gateway information specified for the virtual machine issued by the controller comprises: And receiving Mac addresses of the newly-created virtual machines issued by the controller, custom gateway information appointed for the virtual machines and IP addresses distributed for the virtual machines.
- 3. The method of claim 1, wherein if the DHCP Request message is a DHCP discover message, the DHCP response message is a DHCP Offer message, and if the DHCP Request message is a DHCP Request message, the DHCP response message is a DHCP REPLY message, the target virtual machine requests/renews an IP address based on the interaction of the DHCP message, and configures a custom gateway.
- 4. The method of claim 3, wherein, After receiving a DHCP Discovery message sent by a target virtual machine, forwarding the DHCP Discovery message to a DHCP proxy service, so that the DHCP proxy service executes the step of acquiring Mac address information of the target virtual machine carried by a designated field of the DHCP Discovery message; if the DHCP proxy service determines that the target custom gateway information corresponding to the Mac address of the target virtual machine is maintained locally, carrying the target custom gateway information in a designated option field of a DHCP Offer message and sending the target custom gateway information to the target virtual machine; After receiving a DHCP Request message sent by a target virtual machine, forwarding the DHCP Request message to a DHCP proxy service, so that the DHCP proxy service executes the step of acquiring Mac address information of the target virtual machine carried by a designated field of the DHCP Request message; if the DHCP proxy service determines that the target custom gateway information corresponding to the Mac address of the target virtual machine is maintained locally, carrying the target custom gateway information in a specified option field of DHCP REPLY messages and sending the target custom gateway information to the target virtual machine, and after receiving DHCP REPLY messages carrying the target custom gateway information, carrying out gateway configuration based on the target custom gateway information by the target virtual machine.
- 5. The method of claim 1 or 2, wherein if it is determined that the target virtual machine migrates from a first source host to a second source host, retrieving a gateway configuration corresponding to the target virtual machine on the first source host, and re-issuing the gateway configuration corresponding to the target virtual machine on the second source host.
- 6. The method of claim 1 or 2, wherein if it is determined that the target virtual machine is deleted from a source host, retrieving a gateway configuration corresponding to the target virtual machine on the source host.
- 7. A gateway configuration apparatus for application to an OVS virtual switch, the apparatus comprising: the first receiving unit is used for receiving the Mac address of the newly-created virtual machine and the custom gateway information appointed for the virtual machine, which are issued by the controller; a determining unit, configured to determine whether a DHCP proxy service corresponding to a subnet of the virtual machine exists, where one DHCP proxy service corresponds to one or more subnets; if the determining unit determines that the virtual machine does not exist, the creating unit is used for creating a DHCP proxy service corresponding to the subnet, and the maintaining unit is used for maintaining the Mac address of the virtual machine and the custom gateway information appointed for the virtual machine in the DHCP proxy service, and the DHCP proxy service is added into an OVS bridge through an interface; if the determining unit determines that the virtual machine exists, the maintaining unit is used for maintaining the Mac address of the virtual machine and the custom gateway information appointed for the virtual machine in the DHCP proxy service; The second receiving unit is used for receiving a DHCP request message sent by a target virtual machine, forwarding the DHCP request message to a corresponding DHCP proxy service, and acquiring Mac address information of the target virtual machine carried by a designated field of the DHCP request message by the DHCP proxy service; And the sending unit is used for sending the target custom gateway information carried in a designated option field of a DHCP response message to the target virtual machine if the DHCP proxy service determines that the target custom gateway information corresponding to the Mac address of the target virtual machine is maintained locally, so that the target virtual machine carries out gateway configuration based on the target custom gateway information.
- 8. A gateway configuration apparatus, the gateway configuration apparatus comprising: A memory for storing program instructions; a processor for invoking program instructions stored in said memory and for performing the steps of the method according to any of claims 1-6 in accordance with the obtained program instructions.
- 9. A computer readable storage medium storing computer executable instructions for causing a computer to perform the steps of the method according to any one of claims 1-6.
Description
Gateway configuration method and device Technical Field The present application relates to the field of network communications technologies, and in particular, to a gateway configuration method and device. Background In the current host overlay scene, when a controller (embedded DHCP SERVER function) is in place or a distributed DHCP function is closed, a flexible gateway configuration function based on the granularity of a virtual machine can be realized by means of DHCP message interaction between the controller and the virtual machine. The flexible gateway refers to a gateway (e.g., VSR (virtual service router, virtual service router)) that is customized by the user and is continuously forwarded by the following node after necessary service processing (e.g., charging processing) is performed by the VSR when the virtual machine needs to access across three layers. This approach can satisfy the user's flexible service deployment approach. However, when the controller is in escape due to a fault, or a distributed DHCP function is started (i.e., the DHCP interworking function is offloaded to an OVS (Open vSwitch) for processing), the OVS can only complete the basic DHCP message Wen Jiaohu of the virtual machine, and when the OVS receives a DHCP offer message sent by the virtual machine, a flexible gateway cannot be designated/configured for the virtual machine, which results in a loss of the flexible gateway function of the virtual machine. That is, may result in the unavailability of services deployed on the flexible gateway. Disclosure of Invention The application provides a gateway configuration method and device, which are used for solving the problem that a custom gateway function is unavailable in the prior art. In a first aspect, the present application provides a gateway configuration method, applied to an OVS virtual switch, the method including: receiving a Mac address of a newly created virtual machine and custom gateway information appointed for the virtual machine, wherein the Mac address is issued by a controller; Receiving a DHCP request message sent by a target virtual machine, and acquiring Mac address information of the target virtual machine carried by a designated field of the DHCP request message; And if the target custom gateway information corresponding to the Mac address of the target virtual machine is determined to be maintained locally, carrying the target custom gateway information in a DHCP response message and sending the DHCP response message to the target virtual machine, so that the target virtual machine carries out gateway configuration based on the target custom gateway information. Optionally, the step of receiving the Mac address of the newly created virtual machine and the custom gateway information specified for the virtual machine issued by the controller includes: And receiving Mac addresses of the newly-created virtual machines issued by the controller, custom gateway information appointed for the virtual machines and IP addresses distributed for the virtual machines. Optionally, after receiving the Mac address of the newly created virtual machine and the custom gateway information specified for the virtual machine issued by the controller, the method further includes: determining whether a DHCP proxy service corresponding to a subnet of the virtual machine exists, wherein one DHCP proxy service corresponds to one or more subnets; If not, establishing a DHCP proxy service corresponding to the subnet, maintaining the Mac address of the virtual machine and the custom gateway information appointed for the virtual machine in the DHCP proxy service, and adding the DHCP proxy service into an OVS bridge through an interface; if so, maintaining the Mac address of the virtual machine and the custom gateway information appointed for the virtual machine in the DHCP proxy service. Optionally, if the DHCP Request message is a DHCP discover message, the DHCP response message is a DHCP Offer message, and if the DHCP Request message is a DHCP Request message, the DHCP response message is a DHCP REPLY message, the target virtual machine requests/renews an IP address based on the interaction of the DHCP message, and configures a custom gateway. Optionally, after receiving a DHCP discover message sent by a target virtual machine, forwarding the DHCP discover message to a DHCP proxy service, so that the DHCP proxy service performs a step of acquiring Mac address information of the target virtual machine carried in a designated field of the DHCP discover message; if the DHCP proxy service determines that the target custom gateway information corresponding to the Mac address of the target virtual machine is maintained locally, carrying the target custom gateway information in a designated option field of a DHCP Offer message and sending the target custom gateway information to the target virtual machine; After receiving a DHCP Request message sent by a target virtual machine, forwarding