From 511d3f6aafb2c71992751c2204f863929fc64e39 Mon Sep 17 00:00:00 2001 From: Karmanyaah Malhotra Date: Fri, 7 Oct 2022 16:24:11 -0500 Subject: [PATCH] recommended fixes [2 of 2] --- cmd/serve.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/cmd/serve.go b/cmd/serve.go index be772e6..36dbf31 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -314,18 +314,19 @@ func parseIPHostPrefix(host string) (prefixes []netip.Prefix, err error) { } // not a prefix, parse as host or IP - // LookupHost forwards through if it's an IP + // LookupHost passes through an IP as is ips, err := net.LookupHost(host) - if err == nil { - for _, i := range ips { - ip, err := netip.ParseAddr(i) - if err == nil { - prefix, err := ip.Prefix(ip.BitLen()) - if err != nil { - return prefixes, errors.New(fmt.Sprint("ip", ip, " successfully parsed as IP but unable to turn into prefix. THIS SHOULD NEVER HAPPEN. err:", err.Error())) - } - prefixes = append(prefixes, prefix.Masked()) //also masked canonical ip + if err != nil { + return nil, err + } + for _, i := range ips { + ip, err := netip.ParseAddr(i) + if err == nil { + prefix, err := ip.Prefix(ip.BitLen()) + if err != nil { + return nil, fmt.Errorf("%s successfully parsed but unable to make prefix: %s", ip.String(), err.Error()) } + prefixes = append(prefixes, prefix.Masked()) //also masked canonical ip } } return