summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/dhcpv6message.go
diff options
context:
space:
mode:
authorChris Koch <chrisko@google.com>2019-12-28 02:44:19 -0800
committerinsomniac <insomniacslk@users.noreply.github.com>2020-03-05 15:51:55 +0000
commit3b6f190b53285624aaba864ca57892d3b2a2bec4 (patch)
tree3464a136e12ce57a95c01e94a6804758fba3fa24 /dhcpv6/dhcpv6message.go
parent20d19b1f0dd7e6c43af491199d8bd121d5c8a0c8 (diff)
v6: RequestedOptions getter
Signed-off-by: Chris Koch <chrisko@google.com>
Diffstat (limited to 'dhcpv6/dhcpv6message.go')
-rw-r--r--dhcpv6/dhcpv6message.go35
1 files changed, 18 insertions, 17 deletions
diff --git a/dhcpv6/dhcpv6message.go b/dhcpv6/dhcpv6message.go
index 1bc8670..28853f1 100644
--- a/dhcpv6/dhcpv6message.go
+++ b/dhcpv6/dhcpv6message.go
@@ -79,6 +79,19 @@ func (mo MessageOptions) Status() *OptStatusCode {
return sc
}
+// RequestedOptions returns the Options Requested Option.
+func (mo MessageOptions) RequestedOptions() OptionCodes {
+ opt := mo.Options.GetOne(OptionORO)
+ if opt == nil {
+ return nil
+ }
+ oro, ok := opt.(*optRequestedOption)
+ if !ok {
+ return nil
+ }
+ return oro.OptionCodes
+}
+
// Message represents a DHCPv6 Message as defined by RFC 3315 Section 6.
type Message struct {
MessageType MessageType
@@ -123,12 +136,10 @@ func NewSolicit(hwaddr net.HardwareAddr, modifiers ...Modifier) (*Message, error
}
m.MessageType = MessageTypeSolicit
m.AddOption(OptClientID(duid))
- oro := new(OptRequestedOption)
- oro.SetRequestedOptions([]OptionCode{
+ m.AddOption(OptRequestedOption(
OptionDNSRecursiveNameServer,
OptionDomainSearchList,
- })
- m.AddOption(oro)
+ ))
m.AddOption(&OptElapsedTime{})
if len(hwaddr) < 4 {
return nil, errors.New("short hardware addrss: less than 4 bytes")
@@ -205,13 +216,10 @@ func NewRequestFromAdvertise(adv *Message, modifiers ...Modifier) (*Message, err
return nil, fmt.Errorf("IA_NA cannot be nil in ADVERTISE when building REQUEST")
}
req.AddOption(iana)
- // add OptRequestedOption
- oro := OptRequestedOption{}
- oro.SetRequestedOptions([]OptionCode{
+ req.AddOption(OptRequestedOption(
OptionDNSRecursiveNameServer,
OptionDomainSearchList,
- })
- req.AddOption(&oro)
+ ))
// add OPTION_VENDOR_CLASS, only if present in the original request
// TODO implement OptionVendorClass
vClass := adv.GetOneOption(OptionVendorClass)
@@ -303,14 +311,7 @@ func (m *Message) IsNetboot() bool {
// IsOptionRequested takes an OptionCode and returns true if that option is
// within the requested options of the DHCPv6 message.
func (m *Message) IsOptionRequested(requested OptionCode) bool {
- for _, optoro := range m.GetOption(OptionORO) {
- for _, o := range optoro.(*OptRequestedOption).RequestedOptions() {
- if o == requested {
- return true
- }
- }
- }
- return false
+ return m.Options.RequestedOptions().Contains(requested)
}
// String returns a short human-readable string for this message.