diff options
author | Dennis Marttinen <twelho@welho.tech> | 2022-07-18 16:13:45 +0300 |
---|---|---|
committer | Dennis Marttinen <twelho@welho.tech> | 2023-03-25 16:22:07 +0200 |
commit | b46cf3bd62cbd2d8554f015d8816b77af924d335 (patch) | |
tree | 5b203691ec6b91751b663a33a20e77e67809ed44 | |
parent | e252950ab9616e463bdb9e9ea84ff279cad761c8 (diff) |
dhcpv4: implement interface for sending INFORM requests
Signed-off-by: Dennis Marttinen <twelho@welho.tech>
-rw-r--r-- | dhcpv4/nclient4/client.go | 19 |
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 |