summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChris Koch <chrisko@google.com>2021-12-09 14:09:52 -0800
committerinsomniac <insomniacslk@users.noreply.github.com>2021-12-09 22:37:15 +0000
commit7d93572ebe8e3ba39a15bc7b70757c83a5fb8352 (patch)
treeeed2be62c2c6803c8b7ec2a25ea505305ea01c96
parentad197bcd36fd5fde44d2eacc50c5aa7aef87a742 (diff)
dhcpv4: remove server IP from REQUEST messages
RFC 2131 Section 4.4.1 specifies that REQUEST messages should set 'siaddr' to 0. Signed-off-by: Chris Koch <chrisko@google.com>
-rw-r--r--dhcpv4/dhcpv4.go13
-rw-r--r--dhcpv4/dhcpv4_test.go4
2 files changed, 2 insertions, 15 deletions
diff --git a/dhcpv4/dhcpv4.go b/dhcpv4/dhcpv4.go
index 6be9425..fae08fb 100644
--- a/dhcpv4/dhcpv4.go
+++ b/dhcpv4/dhcpv4.go
@@ -232,22 +232,13 @@ func NewInform(hwaddr net.HardwareAddr, localIP net.IP, modifiers ...Modifier) (
// NewRequestFromOffer builds a DHCPv4 request from an offer.
func NewRequestFromOffer(offer *DHCPv4, modifiers ...Modifier) (*DHCPv4, error) {
- // find server IP address
- serverIP := offer.ServerIdentifier()
- if serverIP == nil {
- if offer.ServerIPAddr == nil || offer.ServerIPAddr.IsUnspecified() {
- return nil, fmt.Errorf("missing Server IP Address in DHCP Offer")
- }
- serverIP = offer.ServerIPAddr
- }
-
return New(PrependModifiers(modifiers,
WithReply(offer),
WithMessageType(MessageTypeRequest),
- WithServerIP(serverIP),
WithClientIP(offer.ClientIPAddr),
WithOption(OptRequestedIPAddress(offer.YourIPAddr)),
- WithOption(OptServerIdentifier(serverIP)),
+ // This is usually the server IP.
+ WithOptionCopied(offer, OptionServerIdentifier),
WithRequestedOptions(
OptionSubnetMask,
OptionRouter,
diff --git a/dhcpv4/dhcpv4_test.go b/dhcpv4/dhcpv4_test.go
index 4392b65..5d60b52 100644
--- a/dhcpv4/dhcpv4_test.go
+++ b/dhcpv4/dhcpv4_test.go
@@ -231,10 +231,6 @@ func TestDHCPv4NewRequestFromOffer(t *testing.T) {
require.NoError(t, err)
offer.SetBroadcast()
offer.UpdateOption(OptMessageType(MessageTypeOffer))
- _, err = NewRequestFromOffer(offer)
- require.Error(t, err)
-
- // Now add the option so it doesn't error out.
offer.UpdateOption(OptServerIdentifier(net.IPv4(192, 168, 0, 1)))
// Broadcast request