Skip to content

WIP: Fix: make rebind & release compliant with RFC2131 #560 - #570

Open
lp35 wants to merge 3 commits into
insomniacslk:masterfrom
canonical:fix/renew-rebind-rfc-compliance
Open

WIP: Fix: make rebind & release compliant with RFC2131 #560 #570
lp35 wants to merge 3 commits into
insomniacslk:masterfrom
canonical:fix/renew-rebind-rfc-compliance

Conversation

@lp35

@lp35 lp35 commented Jan 16, 2026

Copy link
Copy Markdown

Hello,

Related to issue 569, this is a first overview of the modifications needed in order to be fully compliant with the RFC2131.

This PR introduces:

  • A rebind() function for dhcpv4
  • Unicasting for the renew (like the Release() function)

However actions and understanding of the DHCP protocol is still needed in order to fully comply with the RFC for people who are using this library.

This a WIP PR, which needs some love to make all of this transparent for current users, and some architecture change must be done. Indeed, during the lifetime of a nclient4, we need a way to switch between broadcasting and unicasting sockets.
To be fully compliant, this is how the users needs to implement DHCP on their side currently.

Request (as before, broadcast, source address could be 0.0.0.0):

client, err := nclient4.New("eth1")
 ...
dc.lease, err = client.Request(ctx)

Renew, Rebind & Release (unicast & broadcast, but source address must be filled):

// Little hack to force the underlying library to add our IP in the source
// address of the IP header, to fully comply with RFC.
srcIp := &net.UDPAddr{
	IP:   lease.ACK.YourIPAddr,
	Port: nclient4.ClientPort,
}

client, err = nclient4.New("eth1", nclient4.WithUnicast(srcIp))
...
dc.lease, err = client.Renew(ctx, lease)
...
dc.lease, err = client.Rebind(ctx, lease)
...
err = client.Release(lease)

Following are 2 wireshark captures of the before/after this implementation:

Before:
Before fix

After:
after fix

This is my proposal for the architecture modification:

  1. DHCP discovery done, and offer has been accepted (initial condition). IP provided by the server is 192.168.95.2 for example.
  2. (IP is applied on the network interface, application dependant method)
  3. Any call to Renew, Rebind or Release will create a new underlying socket, bound to 192.168.95.2:68, and/or will delete the previous socket.
  4. If Release or Request is called, destroy the unicast socket and setup the broadcast socket again.

Error path and recovery state can be discussed prior of any implementation!

Thanks for your time, and thank you for maintaining this library! :)
BR

@pmazzini

Copy link
Copy Markdown
Collaborator
  • Is this still WIP?
  • Can you sign the DCO?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants