summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/option_iaprefix.go
diff options
context:
space:
mode:
Diffstat (limited to 'dhcpv6/option_iaprefix.go')
-rw-r--r--dhcpv6/option_iaprefix.go22
1 files changed, 16 insertions, 6 deletions
diff --git a/dhcpv6/option_iaprefix.go b/dhcpv6/option_iaprefix.go
index 7260d2c..abd7a34 100644
--- a/dhcpv6/option_iaprefix.go
+++ b/dhcpv6/option_iaprefix.go
@@ -3,6 +3,7 @@ package dhcpv6
import (
"fmt"
"net"
+ "time"
"github.com/u-root/u-root/pkg/uio"
)
@@ -12,8 +13,8 @@ import (
// This module defines the OptIAPrefix structure.
// https://www.ietf.org/rfc/rfc3633.txt
type OptIAPrefix struct {
- PreferredLifetime uint32
- ValidLifetime uint32
+ PreferredLifetime time.Duration
+ ValidLifetime time.Duration
prefixLength byte
ipv6Prefix net.IP
Options Options
@@ -26,8 +27,12 @@ func (op *OptIAPrefix) Code() OptionCode {
// ToBytes marshals this option according to RFC 3633, Section 10.
func (op *OptIAPrefix) ToBytes() []byte {
buf := uio.NewBigEndianBuffer(nil)
- buf.Write32(op.PreferredLifetime)
- buf.Write32(op.ValidLifetime)
+
+ t1 := Duration{op.PreferredLifetime}
+ t1.Marshal(buf)
+ t2 := Duration{op.ValidLifetime}
+ t2.Marshal(buf)
+
buf.Write8(op.prefixLength)
buf.WriteBytes(op.ipv6Prefix.To16())
buf.WriteBytes(op.Options.ToBytes())
@@ -73,8 +78,13 @@ func (op *OptIAPrefix) DelOption(code OptionCode) {
func ParseOptIAPrefix(data []byte) (*OptIAPrefix, error) {
buf := uio.NewBigEndianBuffer(data)
var opt OptIAPrefix
- opt.PreferredLifetime = buf.Read32()
- opt.ValidLifetime = buf.Read32()
+
+ var t1, t2 Duration
+ t1.Unmarshal(buf)
+ t2.Unmarshal(buf)
+ opt.PreferredLifetime = t1.Duration
+ opt.ValidLifetime = t2.Duration
+
opt.prefixLength = buf.Read8()
opt.ipv6Prefix = net.IP(buf.CopyN(net.IPv6len))
if err := opt.Options.FromBytes(buf.ReadAll()); err != nil {