summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/option_temporaryaddress.go
blob: cc102a4a8e79a8a85c0cfb68e2f9d05559735009 (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
package dhcpv6

import (
	"fmt"

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

// OptIATA implements the identity association for non-temporary addresses
// option.
//
// This module defines the OptIATA structure, as defined by RFC 8415 Section
// 21.5.
type OptIATA struct {
	IaId    [4]byte
	Options IdentityOptions
}

// Code returns the option code for an IA_TA
func (op *OptIATA) Code() OptionCode {
	return OptionIATA
}

// ToBytes serializes IATA to DHCPv6 bytes.
func (op *OptIATA) ToBytes() []byte {
	buf := uio.NewBigEndianBuffer(nil)
	buf.WriteBytes(op.IaId[:])
	buf.WriteBytes(op.Options.ToBytes())
	return buf.Data()
}

func (op *OptIATA) String() string {
	return fmt.Sprintf("%s: {IAID=%#x, Options=%v}", op.Code(), op.IaId, op.Options)
}

// LongString returns a multi-line string representation of IATA data.
func (op *OptIATA) LongString(indentSpace int) string {
	return fmt.Sprintf("%s: IAID=%#x Options=%v", op.Code(), op.IaId, op.Options.LongString(indentSpace))
}

// FromBytes builds an OptIATA structure from a sequence of bytes.  The input
// data does not include option code and length bytes.
func (op *OptIATA) FromBytes(data []byte) error {
	buf := uio.NewBigEndianBuffer(data)
	buf.ReadBytes(op.IaId[:])

	if err := op.Options.FromBytes(buf.ReadAll()); err != nil {
		return err
	}
	return buf.FinError()
}