Skip to content

Commit

Permalink
support set the mtu of dhcpv4_options (#2930)
Browse files Browse the repository at this point in the history
Co-authored-by: yuanliu <yuanliu@cmss.chinamobile.com>
  • Loading branch information
2 people authored and bobz965 committed Jun 13, 2023
1 parent effc111 commit 6d883dc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
18 changes: 17 additions & 1 deletion pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,23 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error {
}

var dhcpOptionsUUIDs *ovs.DHCPOptionsUUIDs
dhcpOptionsUUIDs, err = c.ovnLegacyClient.UpdateDHCPOptions(subnet.Name, subnet.Spec.CIDRBlock, subnet.Spec.Gateway, subnet.Spec.DHCPv4Options, subnet.Spec.DHCPv6Options, subnet.Spec.EnableDHCP)
var mtu int
if subnet.Spec.Vlan != "" {
mtu = 1500
} else {
switch c.config.NetworkType {
case util.NetworkTypeVxlan:
mtu = 1500 - util.VxlanHeaderLength
case util.NetworkTypeGeneve:
mtu = 1500 - util.GeneveHeaderLength
case util.NetworkTypeStt:
mtu = 1500 - util.SttHeaderLength
default:
return fmt.Errorf("invalid network type: %s", c.config.NetworkType)
}
}

dhcpOptionsUUIDs, err = c.ovnLegacyClient.UpdateDHCPOptions(subnet.Name, subnet.Spec.CIDRBlock, subnet.Spec.Gateway, subnet.Spec.DHCPv4Options, subnet.Spec.DHCPv6Options, subnet.Spec.EnableDHCP, mtu)
if err != nil {
klog.Errorf("failed to update dhcp options for switch %s, %v", subnet.Name, err)
return err
Expand Down
10 changes: 5 additions & 5 deletions pkg/ovs/ovn-nbctl-legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2767,7 +2767,7 @@ func (c *LegacyClient) createDHCPOptions(ls, cidr, optionsStr string) (dhcpOptio
return dhcpOptionsUuid, nil
}

func (c *LegacyClient) updateDHCPv4Options(ls, v4CIDR, v4Gateway, dhcpV4OptionsStr string) (dhcpV4OptionsUuid string, err error) {
func (c *LegacyClient) updateDHCPv4Options(ls, v4CIDR, v4Gateway, dhcpV4OptionsStr string, mtu int) (dhcpV4OptionsUuid string, err error) {
dhcpV4OptionsStr = strings.ReplaceAll(dhcpV4OptionsStr, " ", "")
dhcpV4Options, err := c.ListDHCPOptions(true, ls, kubeovnv1.ProtocolIPv4)
if err != nil {
Expand All @@ -2781,7 +2781,7 @@ func (c *LegacyClient) updateDHCPv4Options(ls, v4CIDR, v4Gateway, dhcpV4OptionsS
mac := util.GenerateMac()
if len(dhcpV4OptionsStr) == 0 {
// default dhcp v4 options
dhcpV4OptionsStr = fmt.Sprintf("lease_time=%d,router=%s,server_id=%s,server_mac=%s", 3600, v4Gateway, "169.254.0.254", mac)
dhcpV4OptionsStr = fmt.Sprintf("lease_time=%d,router=%s,server_id=%s,server_mac=%s,mtu=%d", 3600, v4Gateway, "169.254.0.254", mac, mtu)
}
dhcpV4OptionsUuid, err = c.createDHCPOptions(ls, v4CIDR, dhcpV4OptionsStr)
if err != nil {
Expand All @@ -2796,7 +2796,7 @@ func (c *LegacyClient) updateDHCPv4Options(ls, v4CIDR, v4Gateway, dhcpV4OptionsS
if len(mac) == 0 {
mac = util.GenerateMac()
}
dhcpV4OptionsStr = fmt.Sprintf("lease_time=%d,router=%s,server_id=%s,server_mac=%s", 3600, v4Gateway, "169.254.0.254", mac)
dhcpV4OptionsStr = fmt.Sprintf("lease_time=%d,router=%s,server_id=%s,server_mac=%s,mtu=%d", 3600, v4Gateway, "169.254.0.254", mac, mtu)
}
_, err = c.ovnNbCommand("set", "dhcp_options", v4Options.UUID, fmt.Sprintf("cidr=%s", v4CIDR),
fmt.Sprintf("options=%s", strings.ReplaceAll(dhcpV4OptionsStr, ":", "\\:")))
Expand Down Expand Up @@ -2866,7 +2866,7 @@ func (c *LegacyClient) updateDHCPv6Options(ls, v6CIDR, dhcpV6OptionsStr string)
return
}

func (c *LegacyClient) UpdateDHCPOptions(ls, cidrBlock, gateway, dhcpV4OptionsStr, dhcpV6OptionsStr string, enableDHCP bool) (dhcpOptionsUUIDs *DHCPOptionsUUIDs, err error) {
func (c *LegacyClient) UpdateDHCPOptions(ls, cidrBlock, gateway, dhcpV4OptionsStr, dhcpV6OptionsStr string, enableDHCP bool, mtu int) (dhcpOptionsUUIDs *DHCPOptionsUUIDs, err error) {
dhcpOptionsUUIDs = &DHCPOptionsUUIDs{}
if enableDHCP {
var v4CIDR, v6CIDR string
Expand All @@ -2884,7 +2884,7 @@ func (c *LegacyClient) UpdateDHCPOptions(ls, cidrBlock, gateway, dhcpV4OptionsSt
v4Gateway = gateways[0]
}

dhcpOptionsUUIDs.DHCPv4OptionsUUID, err = c.updateDHCPv4Options(ls, v4CIDR, v4Gateway, dhcpV4OptionsStr)
dhcpOptionsUUIDs.DHCPv4OptionsUUID, err = c.updateDHCPv4Options(ls, v4CIDR, v4Gateway, dhcpV4OptionsStr, mtu)
if err != nil {
klog.Errorf("update dhcp options for switch %s failed: %v", ls, err)
return nil, err
Expand Down

0 comments on commit 6d883dc

Please sign in to comment.