diff options
author | Chris Koch <chrisko@google.com> | 2019-12-28 01:20:55 -0800 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2020-03-05 15:51:55 +0000 |
commit | fc0886ce943f6f84775882b2147782a4ec26fb1f (patch) | |
tree | 0f9dd70ba4940e14260132bf5500cb8a35c5a375 /dhcpv6/dhcpv6message.go | |
parent | 189a90f002f4cb2b44e4a54f36ff9f57c53ec9d9 (diff) |
v6: add IANA Getter
Signed-off-by: Chris Koch <chrisko@google.com>
Diffstat (limited to 'dhcpv6/dhcpv6message.go')
-rw-r--r-- | dhcpv6/dhcpv6message.go | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/dhcpv6/dhcpv6message.go b/dhcpv6/dhcpv6message.go index bc87f9b..ba592d6 100644 --- a/dhcpv6/dhcpv6message.go +++ b/dhcpv6/dhcpv6message.go @@ -47,6 +47,25 @@ func (mo MessageOptions) ServerID() *Duid { return &opt.(*optServerID).Duid } +// IANA returns all Identity Association for Non-temporary Address options. +func (mo MessageOptions) IANA() []*OptIANA { + opts := mo.Get(OptionIANA) + var ianas []*OptIANA + for _, o := range opts { + ianas = append(ianas, o.(*OptIANA)) + } + return ianas +} + +// OneIANA returns the first IANA option. +func (mo MessageOptions) OneIANA() *OptIANA { + ianas := mo.IANA() + if len(ianas) == 0 { + return nil + } + return ianas[0] +} + // Message represents a DHCPv6 Message as defined by RFC 3315 Section 6. type Message struct { MessageType MessageType @@ -168,11 +187,11 @@ func NewRequestFromAdvertise(adv *Message, modifiers ...Modifier) (*Message, err // add Elapsed Time req.AddOption(&OptElapsedTime{}) // add IA_NA - iaNa := adv.GetOneOption(OptionIANA) - if iaNa == nil { + iana := adv.Options.OneIANA() + if iana == nil { return nil, fmt.Errorf("IA_NA cannot be nil in ADVERTISE when building REQUEST") } - req.AddOption(iaNa) + req.AddOption(iana) // add OptRequestedOption oro := OptRequestedOption{} oro.SetRequestedOptions([]OptionCode{ |