diff options
Diffstat (limited to 'dhcpv6/ztpv6/parse_vendor_options.go')
-rw-r--r-- | dhcpv6/ztpv6/parse_vendor_options.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/dhcpv6/ztpv6/parse_vendor_options.go b/dhcpv6/ztpv6/parse_vendor_options.go index 212733c..3aef837 100644 --- a/dhcpv6/ztpv6/parse_vendor_options.go +++ b/dhcpv6/ztpv6/parse_vendor_options.go @@ -2,9 +2,12 @@ package ztpv6 import ( "errors" + "fmt" + "strconv" "strings" "github.com/insomniacslk/dhcp/dhcpv6" + "github.com/insomniacslk/dhcp/iana" ) var ( @@ -66,6 +69,27 @@ func ParseVendorData(packet dhcpv6.DHCPv6) (*VendorData, error) { vd.Model = p[1] vd.Serial = p[2] return &vd, nil + + // For Ciena the class identifier (opt 60) is written in the following format: + // {vendor iana code}-{product}-{type} + // For Ciena the iana code is 1271 + // The product type is a number that maps to a Ciena product + // The type is used to identified different subtype of the product. + // An example can be ‘1271-23422Z11-123’. + case strings.HasPrefix(d, strconv.Itoa(int(iana.EnterpriseIDCienaCorporation))): + v := strings.Split(d, "-") + if len(v) < 3 { + return nil, errVendorOptionMalformed + } + duid := packet.(*dhcpv6.Message).Options.ClientID() + if duid.Type != dhcpv6.DUID_EN { + return nil, errors.New(fmt.Sprintf("Unexpected DUID type %d for Ciena", duid.Type)) + } + + vd.VendorName = iana.EnterpriseIDCienaCorporation.String() + vd.Model = v[1] + "-" + v[2] + vd.Serial = string(duid.EnterpriseIdentifier) + return &vd, nil } } return nil, errors.New("failed to parse vendor option data") |