summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4
diff options
context:
space:
mode:
authorLoic Prylli <lprylli@netflix.com>2019-04-19 17:01:53 -0700
committerinsomniac <insomniacslk@users.noreply.github.com>2019-05-14 12:03:36 +0100
commitfcbde74dab23754aa33fbcd409327c0a1409f2a7 (patch)
tree8d4bfd185aa370da5f75f6788a11523d6cd86ed7 /dhcpv4
parent4ddd05e566105742df7c109ebf3af307b344441c (diff)
Improve compatibility with some ipv4 networks.
- dnsmasq has been seen to null-terminate the bootfile option, similar treament can occur for tftp-servername (although tftp-servername option usage is less common). - for the gateway information to be present in final packet, the Router option should be queried again in request as in discover (which matches behavior of udhcpc/dhclient). Tested: pxeboot with u-root on dnsmask/ipv4 client. Signed-off-by: Loic Prylli <lprylli@netflix.com>
Diffstat (limited to 'dhcpv4')
-rw-r--r--dhcpv4/dhcpv4.go12
-rw-r--r--dhcpv4/dhcpv4_test.go6
-rw-r--r--dhcpv4/option_string_test.go6
3 files changed, 22 insertions, 2 deletions
diff --git a/dhcpv4/dhcpv4.go b/dhcpv4/dhcpv4.go
index eb02bdc..42c62cd 100644
--- a/dhcpv4/dhcpv4.go
+++ b/dhcpv4/dhcpv4.go
@@ -242,6 +242,12 @@ func NewRequestFromOffer(offer *DHCPv4, modifiers ...Modifier) (*DHCPv4, error)
WithClientIP(offer.ClientIPAddr),
WithOption(OptRequestedIPAddress(offer.YourIPAddr)),
WithOption(OptServerIdentifier(serverIP)),
+ WithRequestedOptions(
+ OptionSubnetMask,
+ OptionRouter,
+ OptionDomainName,
+ OptionDomainNameServer,
+ ),
)...)
}
@@ -577,14 +583,16 @@ func (d *DHCPv4) RootPath() string {
//
// The Bootfile Name option is described by RFC 2132, Section 9.5.
func (d *DHCPv4) BootFileNameOption() string {
- return GetString(OptionBootfileName, d.Options)
+ name := GetString(OptionBootfileName, d.Options)
+ return strings.TrimRight(name, "\x00")
}
// TFTPServerName parses the DHCPv4 TFTP Server Name option if present.
//
// The TFTP Server Name option is described by RFC 2132, Section 9.4.
func (d *DHCPv4) TFTPServerName() string {
- return GetString(OptionTFTPServerName, d.Options)
+ name := GetString(OptionTFTPServerName, d.Options)
+ return strings.TrimRight(name, "\x00")
}
// ClassIdentifier parses the DHCPv4 Class Identifier option if present.
diff --git a/dhcpv4/dhcpv4_test.go b/dhcpv4/dhcpv4_test.go
index 106e4c4..45adc8c 100644
--- a/dhcpv4/dhcpv4_test.go
+++ b/dhcpv4/dhcpv4_test.go
@@ -229,6 +229,12 @@ func TestDHCPv4NewRequestFromOffer(t *testing.T) {
require.Equal(t, MessageTypeRequest, req.MessageType())
require.False(t, req.IsUnicast())
require.True(t, req.IsBroadcast())
+ // Following options are standard in other dhcp clients (isc-dhclient/udhcp) and required
+ // for final ACK to have all info for a proper lease setup (like used in u-root/pkgs/dhclient).
+ require.True(t, req.IsOptionRequested(OptionRouter))
+ require.True(t, req.IsOptionRequested(OptionSubnetMask))
+ require.True(t, req.IsOptionRequested(OptionDomainName))
+ require.True(t, req.IsOptionRequested(OptionDomainNameServer))
// Unicast request
offer.SetUnicast()
diff --git a/dhcpv4/option_string_test.go b/dhcpv4/option_string_test.go
index 768d0fe..9778134 100644
--- a/dhcpv4/option_string_test.go
+++ b/dhcpv4/option_string_test.go
@@ -64,6 +64,9 @@ func TestParseOptBootFileName(t *testing.T) {
m, _ = New()
require.Equal(t, "", m.BootFileNameOption())
+
+ m, _ = New(WithGeneric(OptionBootfileName, []byte{'t', 'e', 's', 't', 0}))
+ require.Equal(t, "test", m.BootFileNameOption())
}
func TestOptTFTPServerName(t *testing.T) {
@@ -79,6 +82,9 @@ func TestParseOptTFTPServerName(t *testing.T) {
m, _ = New()
require.Equal(t, "", m.TFTPServerName())
+
+ m, _ = New(WithGeneric(OptionTFTPServerName, []byte{'t', 'e', 's', 't', 0}))
+ require.Equal(t, "test", m.TFTPServerName())
}
func TestOptClassIdentifier(t *testing.T) {