File: mellanox.go

package info (click to toggle)
golang-github-insomniacslk-dhcp 0.0~git20250417.5f8cf70-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 1,096 kB
  • sloc: makefile: 3
file content (37 lines) | stat: -rw-r--r-- 942 bytes parent folder | download
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
}