summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/option_relay_agent_information.go
blob: 56d93f2e17fbecdc07a991a9f61521b4a9dae143 (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
package dhcpv4

import (
	"fmt"
)

// RelayOptions is like Options, but stringifies using the Relay Agent Specific
// option space.
type RelayOptions struct {
	Options
}

var relayHumanizer = OptionHumanizer{
	ValueHumanizer: func(code OptionCode, data []byte) fmt.Stringer {
		return OptionGeneric{data}
	},
	CodeHumanizer: func(c uint8) OptionCode {
		return GenericOptionCode(c)
	},
}

// String prints the contained options using Relay Agent-specific option code parsing.
func (r RelayOptions) String() string {
	return r.Options.ToString(relayHumanizer)
}

// FromBytes parses relay agent options from data.
func (r *RelayOptions) FromBytes(data []byte) error {
	r.Options = make(Options)
	return r.Options.FromBytes(data)
}

// OptRelayAgentInfo returns a new DHCP Relay Agent Info option.
//
// The relay agent info option is described by RFC 3046.
func OptRelayAgentInfo(o ...Option) Option {
	return Option{Code: OptionRelayAgentInformation, Value: RelayOptions{OptionsFromList(o...)}}
}

type raiSubOptionCode uint8

func (o raiSubOptionCode) Code() uint8 {
	return uint8(o)
}

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

// AgentCircuitIDSubOption as per https://tools.ietf.org/html/rfc3046#section-2.0
const AgentCircuitIDSubOption raiSubOptionCode = 1

var raiSubOptionCodeToString = map[raiSubOptionCode]string{
	AgentCircuitIDSubOption: "Agent Circuit ID Sub-option",
}