summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/option_nii.go
blob: fc9f579f982ac8b5582bc0bc8171dba51f5d2284 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package dhcpv6

import (
	"fmt"

	"github.com/u-root/uio/uio"
)

// NetworkInterfaceType is the NIC type as defined by RFC 4578 Section 2.2
type NetworkInterfaceType uint8

// see rfc4578
const (
	NII_LANDESK_NOPXE   NetworkInterfaceType = 0
	NII_PXE_GEN_I       NetworkInterfaceType = 1
	NII_PXE_GEN_II      NetworkInterfaceType = 2
	NII_UNDI_NOEFI      NetworkInterfaceType = 3
	NII_UNDI_EFI_GEN_I  NetworkInterfaceType = 4
	NII_UNDI_EFI_GEN_II NetworkInterfaceType = 5
)

func (nit NetworkInterfaceType) String() string {
	if s, ok := niiToStringMap[nit]; ok {
		return s
	}
	return fmt.Sprintf("NetworkInterfaceType(%d, unknown)", nit)
}

var niiToStringMap = map[NetworkInterfaceType]string{
	NII_LANDESK_NOPXE:   "LANDesk service agent boot ROMs. No PXE",
	NII_PXE_GEN_I:       "First gen. PXE boot ROMs",
	NII_PXE_GEN_II:      "Second gen. PXE boot ROMs",
	NII_UNDI_NOEFI:      "UNDI 32/64 bit. UEFI drivers, no UEFI runtime",
	NII_UNDI_EFI_GEN_I:  "UNDI 32/64 bit. UEFI runtime 1st gen",
	NII_UNDI_EFI_GEN_II: "UNDI 32/64 bit. UEFI runtime 2nd gen",
}

// OptNetworkInterfaceID implements the NIC ID option for network booting as
// defined by RFC 4578 Section 2.2 and RFC 5970 Section 3.4.
type OptNetworkInterfaceID struct {
	Typ NetworkInterfaceType

	// Revision number
	Major, Minor uint8
}

// Code implements Option.Code.
func (*OptNetworkInterfaceID) Code() OptionCode {
	return OptionNII
}

// ToBytes implements Option.ToBytes.
func (op *OptNetworkInterfaceID) ToBytes() []byte {
	buf := uio.NewBigEndianBuffer(nil)
	buf.Write8(uint8(op.Typ))
	buf.Write8(op.Major)
	buf.Write8(op.Minor)
	return buf.Data()
}

func (op *OptNetworkInterfaceID) String() string {
	return fmt.Sprintf("NetworkInterfaceID: %s (Revision %d.%d)", op.Typ, op.Major, op.Minor)
}

// FromBytes builds an OptNetworkInterfaceID structure from a sequence of
// bytes. The input data does not include option code and length bytes.
func (op *OptNetworkInterfaceID) FromBytes(data []byte) error {
	buf := uio.NewBigEndianBuffer(data)
	op.Typ = NetworkInterfaceType(buf.Read8())
	op.Major = buf.Read8()
	op.Minor = buf.Read8()
	return buf.FinError()
}