summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/nclient4/client.go
diff options
context:
space:
mode:
authorPablo Mazzini <pmazzini@gmail.com>2023-03-27 14:43:15 +0100
committerGitHub <noreply@github.com>2023-03-27 14:43:15 +0100
commitb11966a48d46d5e73271cfe3ab0a5cd5cf21d1a8 (patch)
tree5b203691ec6b91751b663a33a20e77e67809ed44 /dhcpv4/nclient4/client.go
parente252950ab9616e463bdb9e9ea84ff279cad761c8 (diff)
parentb46cf3bd62cbd2d8554f015d8816b77af924d335 (diff)
Merge pull request #470 from twelho/inform-from-offer
dhcpv4: implement interface for sending INFORM requests
Diffstat (limited to 'dhcpv4/nclient4/client.go')
-rw-r--r--dhcpv4/nclient4/client.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/dhcpv4/nclient4/client.go b/dhcpv4/nclient4/client.go
index d40e1a9..b4e4b56 100644
--- a/dhcpv4/nclient4/client.go
+++ b/dhcpv4/nclient4/client.go
@@ -478,6 +478,25 @@ func (c *Client) Request(ctx context.Context, modifiers ...dhcpv4.Modifier) (lea
return c.RequestFromOffer(ctx, offer, modifiers...)
}
+// Inform sends an INFORM request using the given local IP.
+// Returns the ACK response from the server on success.
+func (c *Client) Inform(ctx context.Context, localIP net.IP, modifiers ...dhcpv4.Modifier) (*dhcpv4.DHCPv4, error) {
+ request, err := dhcpv4.NewInform(c.ifaceHWAddr, localIP, modifiers...)
+ if err != nil {
+ return nil, err
+ }
+
+ // DHCP clients must not fill in the server identifier in an INFORM request as per RFC 2131 Section 4.4.1 Table 5,
+ // however, they may still unicast the request to the target server if the address is known (c.serverAddr), as per
+ // Section 4.4.3. The server must then respond with an ACK, as per Section 4.3.5.
+ response, err := c.SendAndRead(ctx, c.serverAddr, request, IsMessageType(dhcpv4.MessageTypeAck))
+ if err != nil {
+ return nil, fmt.Errorf("got an error while processing the request: %w", err)
+ }
+
+ return response, nil
+}
+
// ErrNak is returned if a DHCP server rejected our Request.
type ErrNak struct {
Offer *dhcpv4.DHCPv4