diff options
author | Anatole Denis <Natolumin@users.noreply.github.com> | 2019-09-16 20:06:53 +0200 |
---|---|---|
committer | Pablo Mazzini <pmazzini@gmail.com> | 2019-09-16 19:06:53 +0100 |
commit | 834a63bade8aa8927af8b4c9842f0ad0345289d4 (patch) | |
tree | 5d34579eef422919518b0e7a1e53fcef346d79ce | |
parent | bff32b6395da8a13cbe6e9e7e3a303515ced45b2 (diff) |
dhcpv4: Mark all options as requested absent PRL (#315)
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 <natolumin@unverle.fr>
-rw-r--r-- | dhcpv4/dhcpv4.go | 15 | ||||
-rw-r--r-- | 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)) } |