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

Request previous IP address in discovery #10098

Merged
merged 1 commit into from
Jan 9, 2025
Merged
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
18 changes: 14 additions & 4 deletions internal/app/machined/pkg/controllers/network/operator/dhcp4.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ func (d *DHCP4) knownHostname(hostname network.HostnameStatusSpec) bool {
// be assigned to the associated so that unicast operations can bind successfully.
func (d *DHCP4) waitForNetworkReady(ctx context.Context) error {
// If an IP address has been registered, wait for the address association to be ready
if len(d.addresses) > 0 {
if addresses := d.AddressSpecs(); len(addresses) > 0 {
_, err := d.state.WatchFor(ctx,
resource.NewMetadata(
network.NamespaceName,
network.AddressStatusType,
network.AddressID(d.linkName, d.addresses[0].Address),
network.AddressID(d.linkName, addresses[0].Address),
resource.VersionUndefined,
),
state.WithPhases(resource.PhaseRunning),
Expand Down Expand Up @@ -159,7 +159,7 @@ func (d *DHCP4) Run(ctx context.Context, notifyCh chan<- struct{}) {
// Perform a lease request or renewal
leaseTime, err := d.requestRenew(ctx, hostname)
if err != nil && !errors.Is(err, context.Canceled) {
d.logger.Warn("request/renew failed", zap.Error(err), zap.String("link", d.linkName))
d.logger.Warn("DHCP request/renew failed", zap.Error(err), zap.String("link", d.linkName))
}

if err == nil {
Expand Down Expand Up @@ -235,7 +235,7 @@ func (d *DHCP4) Run(ctx context.Context, notifyCh chan<- struct{}) {
d.lease = nil

d.logger.Debug("restarting DHCP sequence due to hostname change",
zap.Strings("dhcp_hostname", xslices.Map(d.hostname, func(spec network.HostnameSpecSpec) string {
zap.Strings("dhcp_hostname", xslices.Map(d.HostnameSpecs(), func(spec network.HostnameSpecSpec) string {
return spec.Hostname
})),
)
Expand Down Expand Up @@ -532,13 +532,23 @@ func (d *DHCP4) requestRenew(ctx context.Context, hostname network.HostnameStatu
//nolint:errcheck
defer client.Close()

addresses := d.AddressSpecs()

switch {
case d.lease != nil && !d.lease.ACK.ServerIPAddr.IsUnspecified():
d.logger.Debug("DHCP RENEW", zap.String("link", d.linkName))
d.lease, err = client.Renew(ctx, d.lease, mods...)
case d.lease != nil && d.lease.Offer != nil:
d.logger.Debug("DHCP REQUEST FROM OFFER", zap.String("link", d.linkName))
d.lease, err = client.RequestFromOffer(ctx, d.lease.Offer, mods...)
case len(addresses) >= 1:
previousIPAddress := net.IP(addresses[0].Address.Addr().AsSlice())

d.logger.Debug("DHCP REQUEST with previous IP", zap.String("link", d.linkName), zap.Stringer("previous_ip", previousIPAddress))

d.lease, err = client.Request(ctx, dhcpv4.PrependModifiers(mods,
dhcpv4.WithOption(dhcpv4.OptRequestedIPAddress(previousIPAddress)),
)...)
default:
d.logger.Debug("DHCP REQUEST", zap.String("link", d.linkName))
d.lease, err = client.Request(ctx, mods...)
Expand Down