summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorinsomniac <insomniacslk@users.noreply.github.com>2018-07-13 16:37:12 +0100
committerGitHub <noreply@github.com>2018-07-13 16:37:12 +0100
commit64be267cddfcb7151c2b5b849638c6abd9c211b7 (patch)
tree9be18cd1d9a07cf45d9f8bf56a0b2fe5077371c1
parent1a0dca7b99b8e48208f7b130ee78c7c588558147 (diff)
parent382d61320c478be8e39240a15a1f3d18d4a034ac (diff)
Optiana GetOneOption (#85)
-rw-r--r--dhcpv6/option_nontemporaryaddress.go6
-rw-r--r--dhcpv6/option_nontemporaryaddress_test.go21
2 files changed, 27 insertions, 0 deletions
diff --git a/dhcpv6/option_nontemporaryaddress.go b/dhcpv6/option_nontemporaryaddress.go
index 9f91b18..5debeec 100644
--- a/dhcpv6/option_nontemporaryaddress.go
+++ b/dhcpv6/option_nontemporaryaddress.go
@@ -45,6 +45,12 @@ func (op *OptIANA) String() string {
op.IaId, op.T1, op.T2, op.Options)
}
+// GetOneOption will get an option of the give type from the Options field, if
+// it is present. It will return `nil` otherwise
+func (op *OptIANA) GetOneOption(code OptionCode) Option {
+ return getOption(op.Options, code)
+}
+
// DelOption will remove all the options that match a Option code.
func (op *OptIANA) DelOption(code OptionCode) {
op.Options = delOption(op.Options, code)
diff --git a/dhcpv6/option_nontemporaryaddress_test.go b/dhcpv6/option_nontemporaryaddress_test.go
index a9e7087..54df8f0 100644
--- a/dhcpv6/option_nontemporaryaddress_test.go
+++ b/dhcpv6/option_nontemporaryaddress_test.go
@@ -1,6 +1,7 @@
package dhcpv6
import (
+ "net"
"testing"
"github.com/stretchr/testify/require"
@@ -39,6 +40,26 @@ func TestOptIANAParseOptIANAInvalidOptions(t *testing.T) {
require.Error(t, err)
}
+func TestOptIANAGetOneOption(t *testing.T) {
+ oaddr := &OptIAAddress{
+ IPv6Addr: net.ParseIP("::1"),
+ }
+ opt := OptIANA{
+ Options: []Option{&OptElapsedTime{}, oaddr},
+ }
+ require.Equal(t, oaddr, opt.GetOneOption(OPTION_IAADDR))
+}
+
+func TestOptIANAGetOneOptionMissingOpt(t *testing.T) {
+ oaddr := &OptIAAddress{
+ IPv6Addr: net.ParseIP("::1"),
+ }
+ opt := OptIANA{
+ Options: []Option{&OptElapsedTime{}, oaddr},
+ }
+ require.Equal(t, nil, opt.GetOneOption(DNS_RECURSIVE_NAME_SERVER))
+}
+
func TestOptIANADelOption(t *testing.T) {
optiana1 := OptIANA{}
optiana2 := OptIANA{}