summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6
diff options
context:
space:
mode:
authorChris Koch <chrisko@google.com>2019-12-28 08:41:31 -0800
committerinsomniac <insomniacslk@users.noreply.github.com>2020-03-09 11:20:54 +0000
commit59c22a151d6899aedd143445953e5906b0d11574 (patch)
tree6b930c89165f8585c3105567a2aa2ef97dd49d2b /dhcpv6
parent9f507afe0e85d11469f610304e001eb825c1c61e (diff)
v6: add IA AddressOptions (StatusCode only)
Signed-off-by: Chris Koch <chrisko@google.com>
Diffstat (limited to 'dhcpv6')
-rw-r--r--dhcpv6/option_iaaddress.go24
-rw-r--r--dhcpv6/option_iaaddress_test.go10
2 files changed, 27 insertions, 7 deletions
diff --git a/dhcpv6/option_iaaddress.go b/dhcpv6/option_iaaddress.go
index c4184e1..9752ee7 100644
--- a/dhcpv6/option_iaaddress.go
+++ b/dhcpv6/option_iaaddress.go
@@ -8,6 +8,26 @@ import (
"github.com/u-root/u-root/pkg/uio"
)
+// AddressOptions are options valid for the IAAddress option field.
+//
+// RFC 8415 Appendix C lists only the Status Code option as valid.
+type AddressOptions struct {
+ Options
+}
+
+// Status returns the status code associated with this option.
+func (ao AddressOptions) Status() *OptStatusCode {
+ opt := ao.Options.GetOne(OptionStatusCode)
+ if opt == nil {
+ return nil
+ }
+ sc, ok := opt.(*OptStatusCode)
+ if !ok {
+ return nil
+ }
+ return sc
+}
+
// OptIAAddress represents an OptionIAAddr.
//
// This module defines the OptIAAddress structure.
@@ -16,7 +36,7 @@ type OptIAAddress struct {
IPv6Addr net.IP
PreferredLifetime time.Duration
ValidLifetime time.Duration
- Options Options
+ Options AddressOptions
}
// Code returns the option's code
@@ -39,7 +59,7 @@ func (op *OptIAAddress) ToBytes() []byte {
}
func (op *OptIAAddress) String() string {
- return fmt.Sprintf("OptIAAddress{ipv6addr=%v, preferredlifetime=%v, validlifetime=%v, options=%v}",
+ return fmt.Sprintf("IAAddress: IP=%v PreferredLifetime=%v ValidLifetime=%v Options=%v",
op.IPv6Addr, op.PreferredLifetime, op.ValidLifetime, op.Options)
}
diff --git a/dhcpv6/option_iaaddress_test.go b/dhcpv6/option_iaaddress_test.go
index 4db999c..900973c 100644
--- a/dhcpv6/option_iaaddress_test.go
+++ b/dhcpv6/option_iaaddress_test.go
@@ -54,9 +54,9 @@ func TestOptIAAddressToBytes(t *testing.T) {
IPv6Addr: net.IP(ipBytes),
PreferredLifetime: 0x0a0b0c0d * time.Second,
ValidLifetime: 0x0e0f0102 * time.Second,
- Options: []Option{
+ Options: AddressOptions{[]Option{
OptElapsedTime(10 * time.Millisecond),
- },
+ }},
}
require.Equal(t, expected, opt.ToBytes())
}
@@ -74,17 +74,17 @@ func TestOptIAAddressString(t *testing.T) {
str := opt.String()
require.Contains(
t, str,
- "ipv6addr=2401:203:405:607:809:a0b:c0d:e0f",
+ "IP=2401:203:405:607:809:a0b:c0d:e0f",
"String() should return the ipv6addr",
)
require.Contains(
t, str,
- "preferredlifetime=1m10s",
+ "PreferredLifetime=1m10s",
"String() should return the preferredlifetime",
)
require.Contains(
t, str,
- "validlifetime=50s",
+ "ValidLifetime=50s",
"String() should return the validlifetime",
)
}