From 834a63bade8aa8927af8b4c9842f0ad0345289d4 Mon Sep 17 00:00:00 2001 From: Anatole Denis Date: Mon, 16 Sep 2019 20:06:53 +0200 Subject: dhcpv4: Mark all options as requested absent PRL (#315) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In DHCPv4, when the ParameterRequestList option is not present in a request, it should be assumed that the client wants to receive all the options that the server is able to send. This changes the IsOptionRequested method of dhcpv4.DHCPv4 to return true for any request in that situation. The reasoning is based on this wording in [RFC2131§3.5](https://tools.ietf.org/html/rfc2131#section-3.5): > Not all clients require initialization of all parameters listed in > Appendix A. 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. Signed-off-by: Anatole Denis --- dhcpv4/dhcpv4.go | 15 ++++++++++++++- dhcpv4/dhcpv4_test.go | 6 +++++- 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)) } -- cgit v1.2.3