From 79c7b91b466a66dd3d20be0b08a468490d693e78 Mon Sep 17 00:00:00 2001 From: Anatole Denis Date: Fri, 4 Oct 2019 15:39:35 +0200 Subject: dhcpv4: Also write out 0-length options When there was a 0-length generic option, it would be omitted. Rapid commit (option 80) is a 0-length option with a length tag. There could also be 0-length options in the vendor extensions, and the RFC states that they should be written out: > Any options defined subsequent to this document should contain a > length octet even if the length is fixed or zero. Signed-off-by: Anatole Denis --- dhcpv4/options_test.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'dhcpv4/options_test.go') diff --git a/dhcpv4/options_test.go b/dhcpv4/options_test.go index 6c5393c..3850d2d 100644 --- a/dhcpv4/options_test.go +++ b/dhcpv4/options_test.go @@ -194,9 +194,25 @@ func TestOptionsMarshal(t *testing.T) { 5, 1, 10, ), }, + { + // Test 0-length options + opts: Options{ + 80: []byte{}, + }, + want: []byte{80, 0}, + }, + { + // Test special options, handled by the message marshalling code + // and ignored by the options marshalling code + opts: Options{ + 0: []byte{}, // Padding + 255: []byte{}, // End of options + }, + want: nil, // not written out + }, } { t.Run(fmt.Sprintf("Test %02d", i), func(t *testing.T) { - require.Equal(t, uio.ToBigEndian(tt.opts), tt.want) + require.Equal(t, tt.want, uio.ToBigEndian(tt.opts)) }) } } -- cgit v1.2.3