summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/ztpv6/mellanox.go
blob: 3ed8b439bdbf4cf98dae1347495410e9b56f464f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
}