github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/pkg/resolvconf/dns/resolvconf.go (about) 1 // Originally from github.com/docker/libnetwork/resolvconf/dns 2 3 package dns 4 5 import ( 6 "regexp" 7 ) 8 9 // IPLocalhost is a regex pattern for IPv4 or IPv6 loopback range. 10 const IPLocalhost = `((127\.([0-9]{1,3}\.){2}[0-9]{1,3})|(::1)$)` 11 12 // IPv4Localhost is a regex pattern for IPv4 localhost address range. 13 const IPv4Localhost = `(127\.([0-9]{1,3}\.){2}[0-9]{1,3})` 14 15 var localhostIPRegexp = regexp.MustCompile(IPLocalhost) 16 var localhostIPv4Regexp = regexp.MustCompile(IPv4Localhost) 17 18 // IsLocalhost returns true if ip matches the localhost IP regular expression. 19 // Used for determining if nameserver settings are being passed which are 20 // localhost addresses 21 func IsLocalhost(ip string) bool { 22 return localhostIPRegexp.MatchString(ip) 23 } 24 25 // IsIPv4Localhost returns true if ip matches the IPv4 localhost regular expression. 26 func IsIPv4Localhost(ip string) bool { 27 return localhostIPv4Regexp.MatchString(ip) 28 }