diff options
author | Chris Koch <chrisko@google.com> | 2019-12-28 06:30:10 -0800 |
---|---|---|
committer | Chris K <c@chrisko.ch> | 2020-01-02 06:40:00 -0700 |
commit | 9a95b101e205d121810f3922999e1af1d39e4c43 (patch) | |
tree | a8e7787a32f68ba96ecea1eb1b9402bd8cfe86f6 /dhcpv6/option_iaaddress.go | |
parent | b3fbc9f9fdd5ac725d73f2a9109e59d4947f067d (diff) |
v6: use time.Duration for duration fields
Signed-off-by: Chris Koch <chrisko@google.com>
Diffstat (limited to 'dhcpv6/option_iaaddress.go')
-rw-r--r-- | dhcpv6/option_iaaddress.go | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/dhcpv6/option_iaaddress.go b/dhcpv6/option_iaaddress.go index 882e627..c4184e1 100644 --- a/dhcpv6/option_iaaddress.go +++ b/dhcpv6/option_iaaddress.go @@ -3,6 +3,7 @@ package dhcpv6 import ( "fmt" "net" + "time" "github.com/u-root/u-root/pkg/uio" ) @@ -13,8 +14,8 @@ import ( // https://www.ietf.org/rfc/rfc3633.txt type OptIAAddress struct { IPv6Addr net.IP - PreferredLifetime uint32 - ValidLifetime uint32 + PreferredLifetime time.Duration + ValidLifetime time.Duration Options Options } @@ -27,8 +28,12 @@ func (op *OptIAAddress) Code() OptionCode { func (op *OptIAAddress) ToBytes() []byte { buf := uio.NewBigEndianBuffer(nil) buf.WriteBytes(op.IPv6Addr.To16()) - buf.Write32(op.PreferredLifetime) - buf.Write32(op.ValidLifetime) + + t1 := Duration{op.PreferredLifetime} + t1.Marshal(buf) + t2 := Duration{op.ValidLifetime} + t2.Marshal(buf) + buf.WriteBytes(op.Options.ToBytes()) return buf.Data() } @@ -45,8 +50,13 @@ func ParseOptIAAddress(data []byte) (*OptIAAddress, error) { var opt OptIAAddress buf := uio.NewBigEndianBuffer(data) opt.IPv6Addr = net.IP(buf.CopyN(net.IPv6len)) - 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 + if err := opt.Options.FromBytes(buf.ReadAll()); err != nil { return nil, err } |