Skip to content

Commit

Permalink
Append new DHCP options to existing options
Browse files Browse the repository at this point in the history
Signed-off-by: zhuanlan <[email protected]>
  • Loading branch information
Longchuanzheng committed May 9, 2024
1 parent 0068ce3 commit 5887cd6
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions pkg/ovs/ovn-nb-dhcp_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ func (c *OVNNbClient) UpdateDHCPOptions(subnet *kubeovnv1.Subnet, mtu int) (*DHC
}

func (c *OVNNbClient) updateDHCPv4Options(lsName, cidr, gateway, options string, mtu int) (uuid string, err error) {
necessaryV4DHCPOptions := []string{"lease_time", "router", "server_id", "server_mac", "mtu"}

protocol := util.CheckProtocol(cidr)
if protocol != kubeovnv1.ProtocolIPv4 {
return "", fmt.Errorf("cidr %s must be a valid ipv4 address", cidr)
Expand All @@ -115,7 +117,16 @@ func (c *OVNNbClient) updateDHCPv4Options(lsName, cidr, gateway, options string,
/* update */
if dhcpOpt != nil {
dhcpOpt.Cidr = cidr
dhcpOpt.Options = parseDHCPOptions(options)
newOptions := parseDHCPOptions(options)
// Append new options to existing options
if dhcpOpt.Options != nil {
for _, option := range necessaryV4DHCPOptions {
if _, ok := newOptions[option]; !ok {
newOptions[option] = dhcpOpt.Options[option]
}
}
}
dhcpOpt.Options = newOptions
return dhcpOpt.UUID, c.updateDHCPOptions(dhcpOpt, &dhcpOpt.Cidr, &dhcpOpt.Options)
}

Expand All @@ -134,6 +145,8 @@ func (c *OVNNbClient) updateDHCPv4Options(lsName, cidr, gateway, options string,
}

func (c *OVNNbClient) updateDHCPv6Options(lsName, cidr, options string) (uuid string, err error) {
necessaryV6DHCPOptions := []string{"server_id"}

protocol := util.CheckProtocol(cidr)
if protocol != kubeovnv1.ProtocolIPv6 {
return "", fmt.Errorf("cidr %s must be a valid ipv4 address", cidr)
Expand All @@ -157,7 +170,16 @@ func (c *OVNNbClient) updateDHCPv6Options(lsName, cidr, options string) (uuid st
/* update */
if dhcpOpt != nil {
dhcpOpt.Cidr = cidr
dhcpOpt.Options = parseDHCPOptions(options)
newOptions := parseDHCPOptions(options)
// Append new options to existing options
if dhcpOpt.Options != nil {
for _, option := range necessaryV6DHCPOptions {
if _, ok := newOptions[option]; !ok {
newOptions[option] = dhcpOpt.Options[option]
}
}
}
dhcpOpt.Options = newOptions
return dhcpOpt.UUID, c.updateDHCPOptions(dhcpOpt, &dhcpOpt.Cidr, &dhcpOpt.Options)
}

Expand Down

0 comments on commit 5887cd6

Please sign in to comment.