From 427d11cea22a049c2369be32de0decb1157134fe Mon Sep 17 00:00:00 2001 From: Pablo Mazzini Date: Sun, 25 Apr 2021 17:16:44 +0100 Subject: netboot: DNS not mandatory --- netboot/netconf.go | 12 ++---------- netboot/netconf_test.go | 29 ----------------------------- 2 files changed, 2 insertions(+), 39 deletions(-) (limited to 'netboot') diff --git a/netboot/netconf.go b/netboot/netconf.go index 7fc38e2..85cfafb 100644 --- a/netboot/netconf.go +++ b/netboot/netconf.go @@ -61,11 +61,7 @@ func GetNetConfFromPacketv6(d *dhcpv6.Message) (*NetConf, error) { }) } // get DNS configuration - dns := d.Options.DNS() - if len(dns) == 0 { - return nil, errors.New("no option DNS Recursive Name Servers found") - } - netconf.DNSServers = dns + netconf.DNSServers = d.Options.DNS() domains := d.Options.DomainSearchList() if domains != nil { @@ -110,11 +106,7 @@ func GetNetConfFromPacketv4(d *dhcpv4.DHCPv4) (*NetConf, error) { }) // get DNS configuration - dnsServers := d.DNS() - if len(dnsServers) == 0 { - return nil, errors.New("no dns servers options in response packet") - } - netconf.DNSServers = dnsServers + netconf.DNSServers = d.DNS() // get domain search list dnsSearchList := d.DomainSearch() diff --git a/netboot/netconf_test.go b/netboot/netconf_test.go index 8b1f5f7..e2541cd 100644 --- a/netboot/netconf_test.go +++ b/netboot/netconf_test.go @@ -34,25 +34,6 @@ func TestGetNetConfFromPacketv6Invalid(t *testing.T) { require.Error(t, err) } -func TestGetNetConfFromPacketv6NoAddrsNoDNS(t *testing.T) { - adv := getAdv(dhcpv6.WithIANA()) - _, err := GetNetConfFromPacketv6(adv) - require.Error(t, err) -} - -func TestGetNetConfFromPacketv6NoDNS(t *testing.T) { - addrs := []dhcpv6.OptIAAddress{ - dhcpv6.OptIAAddress{ - IPv6Addr: net.ParseIP("::1"), - PreferredLifetime: 3600 * time.Second, - ValidLifetime: 5200 * time.Second, - }, - } - adv := getAdv(dhcpv6.WithIANA(addrs...)) - _, err := GetNetConfFromPacketv6(adv) - require.Error(t, err) -} - func TestGetNetConfFromPacketv6NoSearchList(t *testing.T) { addrs := []dhcpv6.OptIAAddress{ dhcpv6.OptIAAddress{ @@ -129,16 +110,6 @@ func TestGetNetConfFromPacketv4NoLeaseTime(t *testing.T) { require.Error(t, err) } -func TestGetNetConfFromPacketv4NoDNS(t *testing.T) { - d, _ := dhcpv4.New( - dhcpv4.WithNetmask(net.IPv4Mask(255, 255, 255, 0)), - dhcpv4.WithLeaseTime(uint32(0)), - dhcpv4.WithYourIP(net.ParseIP("10.0.0.1")), - ) - _, err := GetNetConfFromPacketv4(d) - require.Error(t, err) -} - func TestGetNetConfFromPacketv4EmptyDNSList(t *testing.T) { d, _ := dhcpv4.New( dhcpv4.WithNetmask(net.IPv4Mask(255, 255, 255, 0)), -- cgit v1.2.3