From e87114a6e449d7a2e458b5529923e5668dfa3a11 Mon Sep 17 00:00:00 2001 From: Christopher Koch Date: Fri, 28 Dec 2018 20:19:14 -0800 Subject: dhcpv4: simplify option parsing. option's codes and lengths were being parsed twice: once in ParseOption and once in each option type's Parse implementation. Consolidate such that it only happens once. Additionally, only pass data to options that they should parse -- we know the length before the Parse function is called, so the option only gets to see the data it needs to see. Also, use uio.Lexer to simplify parsing code in general. Easier to read and reason about. --- dhcpv4/bsdp/bsdp.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'dhcpv4/bsdp/bsdp.go') diff --git a/dhcpv4/bsdp/bsdp.go b/dhcpv4/bsdp/bsdp.go index 3f97602..6bc0cfd 100644 --- a/dhcpv4/bsdp/bsdp.go +++ b/dhcpv4/bsdp/bsdp.go @@ -23,7 +23,7 @@ const AppleVendorID = "AAPLBSDPC" type ReplyConfig struct { ServerIP net.IP ServerHostname, BootFileName string - ServerPriority int + ServerPriority uint16 Images []BootImage DefaultImage, SelectedImage *BootImage } @@ -36,7 +36,7 @@ func ParseBootImageListFromAck(ack dhcpv4.DHCPv4) ([]BootImage, error) { if opt == nil { return nil, errors.New("ParseBootImageListFromAck: could not find vendor-specific option") } - vendorOpt, err := ParseOptVendorSpecificInformation(opt.ToBytes()) + vendorOpt, err := ParseOptVendorSpecificInformation(opt.ToBytes()[2:]) if err != nil { return nil, err } @@ -60,7 +60,7 @@ func MessageTypeFromPacket(packet *dhcpv4.DHCPv4) *MessageType { err error ) for _, opt := range packet.GetOption(dhcpv4.OptionVendorSpecificInformation) { - if vendorOpts, err = ParseOptVendorSpecificInformation(opt.ToBytes()); err == nil { + if vendorOpts, err = ParseOptVendorSpecificInformation(opt.ToBytes()[2:]); err == nil { if o := vendorOpts.GetOneOption(OptionMessageType); o != nil { if optMessageType, ok := o.(*OptMessageType); ok { return &optMessageType.Type -- cgit v1.2.3