diff options
author | Akshay Navale <navale@dhcp-172-27-23-219.dhcp.thefacebook.com> | 2019-11-11 18:06:03 -0700 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2019-11-12 14:00:02 +0000 |
commit | c058740140122368226eaaf7debce03c376e6ae8 (patch) | |
tree | 30bac09cd7500576fac62b49f1eb5ef28046aa6b /dhcpv6/ztpv6/parse_vendor_options.go | |
parent | 8249c7314fb30aca426139aae111bb0a3488a236 (diff) |
[dhcpv6]Adding opt 16 when parsing vendor options
Signed-off-by: Akshay Navale <navale@dhcp-172-27-23-219.dhcp.thefacebook.com>
Diffstat (limited to 'dhcpv6/ztpv6/parse_vendor_options.go')
-rw-r--r-- | dhcpv6/ztpv6/parse_vendor_options.go | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/dhcpv6/ztpv6/parse_vendor_options.go b/dhcpv6/ztpv6/parse_vendor_options.go index 63a6a05..212733c 100644 --- a/dhcpv6/ztpv6/parse_vendor_options.go +++ b/dhcpv6/ztpv6/parse_vendor_options.go @@ -16,24 +16,36 @@ type VendorData struct { VendorName, Model, Serial string } -// ParseVendorData will try to parse dhcp6 Vendor Specific Information options data -// looking for more specific vendor data (like model, serial number, etc). -// If the options are missing we will just return nil +// ParseVendorData will try to parse dhcp6 Vendor Specific Information options +// ( 16 and 17) data looking for more specific vendor data (like model, serial +// number, etc). If the options are missing we will just return nil func ParseVendorData(packet dhcpv6.DHCPv6) (*VendorData, error) { - opt := packet.GetOneOption(dhcpv6.OptionVendorOpts) - if opt == nil { - return nil, errors.New("vendor options not found") + // check for both options 16 and 17 if both are present will use opt 17 + opt16 := packet.GetOneOption(dhcpv6.OptionVendorClass) + opt17 := packet.GetOneOption(dhcpv6.OptionVendorOpts) + if (opt16 == nil) && (opt17 == nil) { + return nil, errors.New("no vendor options or vendor class found") } vd := VendorData{} - vo := opt.(*dhcpv6.OptVendorOpts).VendorOpts + vData := []string{} - for _, opt := range vo { - optData := string(opt.(*dhcpv6.OptionGeneric).OptionData) + if opt17 != nil { + vo := opt17.(*dhcpv6.OptVendorOpts).VendorOpts + for _, opt := range vo { + vData = append(vData, string(opt.(*dhcpv6.OptionGeneric).OptionData)) + } + } else { + data := opt16.(*dhcpv6.OptVendorClass).Data + for _, d := range data { + vData = append(vData, string(d)) + } + } + for _, d := range vData { switch { // Arista;DCS-0000;00.00;ZZZ00000000 - case strings.HasPrefix(optData, "Arista;"): - p := strings.Split(optData, ";") + case strings.HasPrefix(d, "Arista;"): + p := strings.Split(d, ";") if len(p) < 4 { return nil, errVendorOptionMalformed } @@ -44,8 +56,8 @@ func ParseVendorData(packet dhcpv6.DHCPv6) (*VendorData, error) { return &vd, nil // ZPESystems:NSC:000000000 - case strings.HasPrefix(optData, "ZPESystems:"): - p := strings.Split(optData, ":") + case strings.HasPrefix(d, "ZPESystems:"): + p := strings.Split(d, ":") if len(p) < 3 { return nil, errVendorOptionMalformed } |