Skip to content

Commit

Permalink
incusd/main_forknet: Handle background renewals
Browse files Browse the repository at this point in the history
Closes lxc#1106

Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
  • Loading branch information
stgraber committed Oct 23, 2024
1 parent 7911c75 commit ed4af38
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cmd/incusd/main_forknet.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,21 @@ func (c *cmdForknet) RunDHCP(cmd *cobra.Command, args []string) error {
return nil
}

// Handle DHCP renewal.
for {
// Wait until it's renewal time.
time.Sleep(lease.Offer.IPAddressRenewalTime(time.Minute))

// Renew the lease.
newLease, err := client.Renew(context.Background(), lease, dhcpv4.WithOption(dhcpv4.OptHostName(hostname)))
if err != nil {
fmt.Fprintf(os.Stderr, "Giving up on DHCP, couldn't renew the lease for %q\n", iface)
return nil
}

lease = newLease
}

return nil
}

Expand Down

0 comments on commit ed4af38

Please sign in to comment.