summaryrefslogtreecommitdiffhomepage
path: root/netboot
diff options
context:
space:
mode:
authorChris Koch <chrisko@google.com>2019-12-28 06:30:10 -0800
committerChris K <c@chrisko.ch>2020-01-02 06:40:00 -0700
commit9a95b101e205d121810f3922999e1af1d39e4c43 (patch)
treea8e7787a32f68ba96ecea1eb1b9402bd8cfe86f6 /netboot
parentb3fbc9f9fdd5ac725d73f2a9109e59d4947f067d (diff)
v6: use time.Duration for duration fields
Signed-off-by: Chris Koch <chrisko@google.com>
Diffstat (limited to 'netboot')
-rw-r--r--netboot/netconf.go10
-rw-r--r--netboot/netconf_test.go21
2 files changed, 16 insertions, 15 deletions
diff --git a/netboot/netconf.go b/netboot/netconf.go
index 2ce658b..96bfff2 100644
--- a/netboot/netconf.go
+++ b/netboot/netconf.go
@@ -20,8 +20,8 @@ import (
// AddrConf holds a single IP address configuration for a NIC
type AddrConf struct {
IPNet net.IPNet
- PreferredLifetime int
- ValidLifetime int
+ PreferredLifetime time.Duration
+ ValidLifetime time.Duration
}
// NetConf holds multiple IP configuration for a NIC, and DNS configuration
@@ -55,8 +55,8 @@ func GetNetConfFromPacketv6(d *dhcpv6.Message) (*NetConf, error) {
IP: iaaddr.IPv6Addr,
Mask: netmask,
},
- PreferredLifetime: int(iaaddr.PreferredLifetime),
- ValidLifetime: int(iaaddr.ValidLifetime),
+ PreferredLifetime: iaaddr.PreferredLifetime,
+ ValidLifetime: iaaddr.ValidLifetime,
})
}
// get DNS configuration
@@ -110,7 +110,7 @@ func GetNetConfFromPacketv4(d *dhcpv4.DHCPv4) (*NetConf, error) {
Mask: netmask,
},
PreferredLifetime: 0,
- ValidLifetime: int(leaseTime / time.Second),
+ ValidLifetime: leaseTime,
})
// get DNS configuration
diff --git a/netboot/netconf_test.go b/netboot/netconf_test.go
index 1341af4..8b1f5f7 100644
--- a/netboot/netconf_test.go
+++ b/netboot/netconf_test.go
@@ -4,6 +4,7 @@ import (
"log"
"net"
"testing"
+ "time"
"github.com/insomniacslk/dhcp/dhcpv4"
"github.com/insomniacslk/dhcp/dhcpv6"
@@ -43,8 +44,8 @@ func TestGetNetConfFromPacketv6NoDNS(t *testing.T) {
addrs := []dhcpv6.OptIAAddress{
dhcpv6.OptIAAddress{
IPv6Addr: net.ParseIP("::1"),
- PreferredLifetime: 3600,
- ValidLifetime: 5200,
+ PreferredLifetime: 3600 * time.Second,
+ ValidLifetime: 5200 * time.Second,
},
}
adv := getAdv(dhcpv6.WithIANA(addrs...))
@@ -56,8 +57,8 @@ func TestGetNetConfFromPacketv6NoSearchList(t *testing.T) {
addrs := []dhcpv6.OptIAAddress{
dhcpv6.OptIAAddress{
IPv6Addr: net.ParseIP("::1"),
- PreferredLifetime: 3600,
- ValidLifetime: 5200,
+ PreferredLifetime: 3600 * time.Second,
+ ValidLifetime: 5200 * time.Second,
},
}
adv := getAdv(
@@ -72,8 +73,8 @@ func TestGetNetConfFromPacketv6(t *testing.T) {
addrs := []dhcpv6.OptIAAddress{
dhcpv6.OptIAAddress{
IPv6Addr: net.ParseIP("::1"),
- PreferredLifetime: 3600,
- ValidLifetime: 5200,
+ PreferredLifetime: 3600 * time.Second,
+ ValidLifetime: 5200 * time.Second,
},
}
adv := getAdv(
@@ -86,8 +87,8 @@ func TestGetNetConfFromPacketv6(t *testing.T) {
// check addresses
require.Equal(t, 1, len(netconf.Addresses))
require.Equal(t, net.ParseIP("::1"), netconf.Addresses[0].IPNet.IP)
- require.Equal(t, 3600, netconf.Addresses[0].PreferredLifetime)
- require.Equal(t, 5200, netconf.Addresses[0].ValidLifetime)
+ require.Equal(t, 3600*time.Second, netconf.Addresses[0].PreferredLifetime)
+ require.Equal(t, 5200*time.Second, netconf.Addresses[0].ValidLifetime)
// check DNSes
require.Equal(t, 1, len(netconf.DNSServers))
require.Equal(t, net.ParseIP("fe80::1"), netconf.DNSServers[0])
@@ -212,8 +213,8 @@ func TestGetNetConfFromPacketv4(t *testing.T) {
// check addresses
require.Equal(t, 1, len(netconf.Addresses))
require.Equal(t, net.ParseIP("10.0.0.1"), netconf.Addresses[0].IPNet.IP)
- require.Equal(t, 0, netconf.Addresses[0].PreferredLifetime)
- require.Equal(t, 5200, netconf.Addresses[0].ValidLifetime)
+ require.Equal(t, time.Duration(0), netconf.Addresses[0].PreferredLifetime)
+ require.Equal(t, 5200*time.Second, netconf.Addresses[0].ValidLifetime)
// check DNSes
require.Equal(t, 2, len(netconf.DNSServers))
require.Equal(t, net.ParseIP("10.10.0.1").To4(), netconf.DNSServers[0])