diff options
author | Pablo Mazzini <pmazzini@gmail.com> | 2022-10-01 13:27:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-01 13:27:33 +0100 |
commit | 962b81a3c7c72027180d70695556b03a90a566b5 (patch) | |
tree | 3cedc99231cbc29465eab72b0c9a1482c4060ffd /dhcpv4/nclient4/lease.go | |
parent | 043f1726f02e2908b959423a0b95a9affdc08b73 (diff) | |
parent | e6997bf8b3fab1a1d480f7bd564988164a3b6bd3 (diff) |
Merge pull request #478 from twelho/renew-return-new-lease
dhcpv4: return a new lease from Renew()
Diffstat (limited to 'dhcpv4/nclient4/lease.go')
-rw-r--r-- | dhcpv4/nclient4/lease.go | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/dhcpv4/nclient4/lease.go b/dhcpv4/nclient4/lease.go index 1895dd0..9ee3109 100644 --- a/dhcpv4/nclient4/lease.go +++ b/dhcpv4/nclient4/lease.go @@ -42,15 +42,15 @@ func (c *Client) Release(lease *Lease, modifiers ...dhcpv4.Modifier) error { // sourced from the initial offer in the lease, and the ACK of the lease is updated to the ACK of // the latest renewal. This avoids issues with DHCP servers that omit information needed to build a // completely new lease from their renewal ACK (such as the Windows DHCP Server). -func (c *Client) Renew(ctx context.Context, lease *Lease, modifiers ...dhcpv4.Modifier) error { +func (c *Client) Renew(ctx context.Context, lease *Lease, modifiers ...dhcpv4.Modifier) (*Lease, error) { if lease == nil { - return fmt.Errorf("lease is nil") + return nil, fmt.Errorf("lease is nil") } request, err := dhcpv4.NewRenewFromOffer(lease.Offer, dhcpv4.PrependModifiers(modifiers, dhcpv4.WithOption(dhcpv4.OptMaxMessageSize(MaxMessageSize)))...) if err != nil { - return fmt.Errorf("unable to create a request: %w", err) + return nil, fmt.Errorf("unable to create a request: %w", err) } // Servers are supposed to only respond to Requests containing their server identifier, @@ -61,17 +61,19 @@ func (c *Client) Renew(ctx context.Context, lease *Lease, modifiers ...dhcpv4.Mo IsCorrectServer(lease.Offer.ServerIdentifier()), IsMessageType(dhcpv4.MessageTypeAck, dhcpv4.MessageTypeNak))) if err != nil { - return fmt.Errorf("got an error while processing the request: %w", err) + return nil, fmt.Errorf("got an error while processing the request: %w", err) } if response.MessageType() == dhcpv4.MessageTypeNak { - return &ErrNak{ + return nil, &ErrNak{ Offer: lease.Offer, Nak: response, } } - // Update the ACK of the lease with the ACK of the latest renewal - lease.ACK = response - - return nil + // Return a new lease with the latest ACK and updated creation time + return &Lease{ + Offer: lease.Offer, + ACK: response, + CreationTime: time.Now(), + }, nil } |