diff options
author | Marcel Moolenaar <mmoolena@amazon.com> | 2021-02-19 10:05:28 -0800 |
---|---|---|
committer | Chris K <c@chrisko.ch> | 2021-03-06 14:40:58 -0800 |
commit | 62c5e6a9631be9fe5122f4a43f937e99df1c208f (patch) | |
tree | a6676fb53e93f0678b306d7b3ed8f3303ae9b3cd /dhcpv4/dhcpv4.go | |
parent | cc9239ac62943a78e89ef4880c8ebdd0ca9ae21e (diff) |
Pad packets after the 'end' option to be more conformant
RFC 2131 gives two examples of padding in section 4.1. For both the
examples, the 'end' option preceeds the padding with the 'pad' option.
These examples relate to overloading pre-defined fields for options,
not padding the packet for a minimal size.
Older versions of the U-Boot firmware support DHCP, but do not expect
the 'pad' option. The firmware logs the following warning for each
occurence:
*** Unhandled DHCP Option in OFFER/ACK: 0
This warning disappears when the 'end' option preceeds the 'pad'
option.
Signed-off-by: Marcel Moolenaar <mmoolena@amazon.com>
Diffstat (limited to 'dhcpv4/dhcpv4.go')
-rw-r--r-- | dhcpv4/dhcpv4.go | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/dhcpv4/dhcpv4.go b/dhcpv4/dhcpv4.go index c09e76a..4dc05ad 100644 --- a/dhcpv4/dhcpv4.go +++ b/dhcpv4/dhcpv4.go @@ -520,21 +520,19 @@ func (d *DHCPv4) ToBytes() []byte { // Write all options. d.Options.Marshal(buf) + // Finish the options. + buf.Write8(OptionEnd.Code()) + // DHCP is based on BOOTP, and BOOTP messages have a minimum length of // 300 bytes per RFC 951. This not stated explicitly, but if you sum up // all the bytes in the message layout, you'll get 300 bytes. // // Some DHCP servers and relay agents care about this BOOTP legacy B.S. // and "conveniently" drop messages that are less than 300 bytes long. - // - // We subtract one byte for the OptionEnd option. - if buf.Len()+1 < bootpMinLen { - buf.WriteBytes(bytes.Repeat([]byte{OptionPad.Code()}, bootpMinLen-1-buf.Len())) + if buf.Len() < bootpMinLen { + buf.WriteBytes(bytes.Repeat([]byte{OptionPad.Code()}, bootpMinLen-buf.Len())) } - // Finish the packet. - buf.Write8(OptionEnd.Code()) - return buf.Data() } |