diff options
Diffstat (limited to 'dhcpv6/ztpv6/mellanox.go')
-rw-r--r-- | dhcpv6/ztpv6/mellanox.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/dhcpv6/ztpv6/mellanox.go b/dhcpv6/ztpv6/mellanox.go new file mode 100644 index 0000000..3ed8b43 --- /dev/null +++ b/dhcpv6/ztpv6/mellanox.go @@ -0,0 +1,37 @@ +package ztpv6 + +import ( + "errors" + + "github.com/insomniacslk/dhcp/dhcpv6" + "github.com/insomniacslk/dhcp/iana" +) + +type MlnxSubOption uint16 + +const ( + MlnxSubOptionModel MlnxSubOption = 1 + MlnxSubOptionPartNum MlnxSubOption = 2 + MlnxSubOptionSerial MlnxSubOption = 3 + MlnxSubOptionMac MlnxSubOption = 4 + MlnxSubOptionProfile MlnxSubOption = 5 + MlnxSubOptionRelease MlnxSubOption = 6 +) + +func getMellanoxVendorData(vendorOptsOption *dhcpv6.OptVendorOpts) (*VendorData, error) { + vd := VendorData{} + vd.VendorName = iana.EnterpriseIDMellanoxTechnologiesLTD.String() + for _, opt := range vendorOptsOption.VendorOpts { + switch MlnxSubOption(opt.Code()) { + case MlnxSubOptionSerial: + vd.Serial = string(opt.ToBytes()) + case MlnxSubOptionModel: + vd.Model = string(opt.ToBytes()) + } + } + if (vd.Serial == "") || (vd.Model == "") { + return nil, errors.New("couldn't parse Mellanox sub-option for serial or model") + } + + return &vd, nil +} |