Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ovn: Port more functions to libovsdb #926

Merged
merged 3 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/server/network/driver_ovn.go
Original file line number Diff line number Diff line change
Expand Up @@ -2447,7 +2447,7 @@ func (n *ovn) setup(update bool) error {
recursiveDNSServer = uplinkNet.dnsIPv6[0] // OVN only supports 1 RA DNS server.
}

err = n.state.OVNNB.LogicalRouterPortSetIPv6Advertisements(n.getRouterIntPortName(), &networkOVN.OVNIPv6RAOpts{
err = n.state.OVNNB.UpdateLogicalRouterPort(context.TODO(), n.getRouterIntPortName(), &networkOVN.OVNIPv6RAOpts{
AddressMode: adressMode,
SendPeriodic: true,
DNSSearchList: n.getDNSSearchList(),
Expand All @@ -2463,7 +2463,7 @@ func (n *ovn) setup(update bool) error {
return fmt.Errorf("Failed setting internal router port IPv6 advertisement settings: %w", err)
}
} else {
err = n.state.OVNNB.LogicalRouterPortDeleteIPv6Advertisements(n.getRouterIntPortName())
err = n.state.OVNNB.UpdateLogicalRouterPort(context.TODO(), n.getRouterIntPortName(), &networkOVN.OVNIPv6RAOpts{})
if err != nil {
return fmt.Errorf("Failed removing internal router port IPv6 advertisement settings: %w", err)
}
Expand Down
84 changes: 34 additions & 50 deletions internal/server/network/ovn/ovn_nb_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,72 +817,56 @@ func (o *NB) DeleteLogicalRouterPort(ctx context.Context, routerName OVNRouter,
return nil
}

// LogicalRouterPortSetIPv6Advertisements sets the IPv6 router advertisement options on a router port.
func (o *NB) LogicalRouterPortSetIPv6Advertisements(portName OVNRouterPort, opts *OVNIPv6RAOpts) error {
args := []string{"set", "logical_router_port", string(portName),
fmt.Sprintf("ipv6_ra_configs:send_periodic=%t", opts.SendPeriodic),
// UpdateLogicalRouterPort updates properties of a logical router port.
func (o *NB) UpdateLogicalRouterPort(ctx context.Context, portName OVNRouterPort, ipv6ra *OVNIPv6RAOpts) error {
lrp, err := o.GetLogicalRouterPort(ctx, portName)
if err != nil {
return err
}

var removeRAConfigKeys []string

if opts.AddressMode != "" {
args = append(args, fmt.Sprintf("ipv6_ra_configs:address_mode=%s", string(opts.AddressMode)))
} else {
removeRAConfigKeys = append(removeRAConfigKeys, "address_mode")
}
if ipv6ra != nil {
ipv6conf := map[string]string{}

if opts.MaxInterval > 0 {
args = append(args, fmt.Sprintf("ipv6_ra_configs:max_interval=%d", opts.MaxInterval/time.Second))
} else {
removeRAConfigKeys = append(removeRAConfigKeys, "max_interval")
}
if ipv6ra.AddressMode != "" {
ipv6conf["address_mode"] = string(ipv6ra.AddressMode)
}

if opts.MinInterval > 0 {
args = append(args, fmt.Sprintf("ipv6_ra_configs:min_interval=%d", opts.MinInterval/time.Second))
} else {
removeRAConfigKeys = append(removeRAConfigKeys, "min_interval")
}
if ipv6ra.MaxInterval > 0 {
ipv6conf["max_interval"] = fmt.Sprintf("%d", ipv6ra.MaxInterval/time.Second)
}

if opts.MTU > 0 {
args = append(args, fmt.Sprintf("ipv6_ra_configs:mtu=%d", opts.MTU))
} else {
removeRAConfigKeys = append(removeRAConfigKeys, "mtu")
}
if ipv6ra.MinInterval > 0 {
ipv6conf["min_interval"] = fmt.Sprintf("%d", ipv6ra.MinInterval/time.Second)
}

if len(opts.DNSSearchList) > 0 {
args = append(args, fmt.Sprintf("ipv6_ra_configs:dnssl=%s", strings.Join(opts.DNSSearchList, ",")))
} else {
removeRAConfigKeys = append(removeRAConfigKeys, "dnssl")
}
if ipv6ra.MTU > 0 {
ipv6conf["mtu"] = fmt.Sprintf("%d", ipv6ra.MTU)
}

if opts.RecursiveDNSServer != nil {
args = append(args, fmt.Sprintf("ipv6_ra_configs:rdnss=%s", opts.RecursiveDNSServer.String()))
} else {
removeRAConfigKeys = append(removeRAConfigKeys, "rdnss")
}
if len(ipv6ra.DNSSearchList) > 0 {
ipv6conf["dnssl"] = strings.Join(ipv6ra.DNSSearchList, ",")
}

// Clear any unused keys first.
if len(removeRAConfigKeys) > 0 {
removeArgs := append([]string{"remove", "logical_router_port", string(portName), "ipv6_ra_configs"}, removeRAConfigKeys...)
_, err := o.nbctl(removeArgs...)
if err != nil {
return err
if ipv6ra.RecursiveDNSServer != nil {
ipv6conf["rdnss"] = ipv6ra.RecursiveDNSServer.String()
}

lrp.Ipv6RaConfigs = ipv6conf
}

// Configure IPv6 Router Advertisements.
_, err := o.nbctl(args...)
// Update the record.
operations, err := o.client.Where(lrp).Update(lrp)
if err != nil {
return err
}

return nil
}
// Apply the changes.
resp, err := o.client.Transact(ctx, operations...)
if err != nil {
return err
}

// LogicalRouterPortDeleteIPv6Advertisements removes the IPv6 RA announcement settings from a router port.
func (o *NB) LogicalRouterPortDeleteIPv6Advertisements(portName OVNRouterPort) error {
// Delete IPv6 Router Advertisements.
_, err := o.nbctl("clear", "logical_router_port", string(portName), "ipv6_ra_configs")
_, err = ovsdb.CheckOperationResults(resp, operations)
if err != nil {
return err
}
Expand Down
Loading