summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--dhcpv4/dhcpv4.go15
-rw-r--r--dhcpv4/dhcpv4_test.go6
2 files changed, 19 insertions, 2 deletions
diff --git a/dhcpv4/dhcpv4.go b/dhcpv4/dhcpv4.go
index 139c130..f85fe2e 100644
--- a/dhcpv4/dhcpv4.go
+++ b/dhcpv4/dhcpv4.go
@@ -430,7 +430,20 @@ func (d *DHCPv4) Summary() string {
// IsOptionRequested returns true if that option is within the requested
// options of the DHCPv4 message.
func (d *DHCPv4) IsOptionRequested(requested OptionCode) bool {
- for _, o := range d.ParameterRequestList() {
+ rq := d.ParameterRequestList()
+ if rq == nil {
+ // RFC2131ยง3.5
+ // Not all clients require initialization of all parameters [...]
+ // Two techniques are used to reduce the number of parameters transmitted from
+ // the server to the client. [...] Second, in its initial DHCPDISCOVER or
+ // DHCPREQUEST message, a client may provide the server with a list of specific
+ // parameters the client is interested in.
+ // We interpret this to say that all available parameters should be sent if
+ // the parameter request list is not sent at all.
+ return true
+ }
+
+ for _, o := range rq {
if o == requested {
return true
}
diff --git a/dhcpv4/dhcpv4_test.go b/dhcpv4/dhcpv4_test.go
index 839be65..ea3776c 100644
--- a/dhcpv4/dhcpv4_test.go
+++ b/dhcpv4/dhcpv4_test.go
@@ -310,9 +310,13 @@ func TestNewInform(t *testing.T) {
func TestIsOptionRequested(t *testing.T) {
pkt, err := New()
require.NoError(t, err)
+ require.True(t, pkt.IsOptionRequested(OptionDomainNameServer))
+
+ optprl := OptParameterRequestList(OptionRouter, OptionDomainName)
+ pkt.UpdateOption(optprl)
require.False(t, pkt.IsOptionRequested(OptionDomainNameServer))
- optprl := OptParameterRequestList(OptionDomainNameServer)
+ optprl = OptParameterRequestList(OptionDomainNameServer)
pkt.UpdateOption(optprl)
require.True(t, pkt.IsOptionRequested(OptionDomainNameServer))
}