diff options
author | Chris Koch <chrisko@google.com> | 2020-02-10 14:23:38 -0800 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2020-03-05 15:51:55 +0000 |
commit | 54c911b4349d9fc445ad10c5399db12a58dfcec9 (patch) | |
tree | 889b1475b1d6b6228dc7f014b53d18864277df7c | |
parent | 05d8a93081707e4eccd5893799c998a384d3652e (diff) |
v6: add FQDN option getter
Signed-off-by: Chris Koch <chrisko@google.com>
-rw-r--r-- | dhcpv6/dhcpv6message.go | 12 | ||||
-rw-r--r-- | dhcpv6/modifiers_test.go | 4 |
2 files changed, 14 insertions, 2 deletions
diff --git a/dhcpv6/dhcpv6message.go b/dhcpv6/dhcpv6message.go index ced5f9e..8ba7943 100644 --- a/dhcpv6/dhcpv6message.go +++ b/dhcpv6/dhcpv6message.go @@ -168,6 +168,18 @@ func (mo MessageOptions) ElapsedTime() time.Duration { return 0 } +// FQDN returns the FQDN option as defined by RFC 4704. +func (mo MessageOptions) FQDN() *OptFQDN { + opt := mo.Options.GetOne(OptionFQDN) + if opt == nil { + return nil + } + if fqdn, ok := opt.(*OptFQDN); ok { + return fqdn + } + return nil +} + // Message represents a DHCPv6 Message as defined by RFC 3315 Section 6. type Message struct { MessageType MessageType diff --git a/dhcpv6/modifiers_test.go b/dhcpv6/modifiers_test.go index ff8022c..e31cd29 100644 --- a/dhcpv6/modifiers_test.go +++ b/dhcpv6/modifiers_test.go @@ -90,8 +90,8 @@ func TestWithDomainSearchList(t *testing.T) { func TestWithFQDN(t *testing.T) { var d Message WithFQDN(4, "cnos.localhost")(&d) - require.Equal(t, 1, len(d.Options)) - ofqdn := d.Options[0].(*OptFQDN) + require.Equal(t, 1, len(d.Options.Options)) + ofqdn := d.Options.FQDN() require.Equal(t, OptionFQDN, ofqdn.Code()) require.Equal(t, uint8(4), ofqdn.Flags) require.Equal(t, "cnos.localhost", ofqdn.DomainName) |