resolvconf.go 842 B

1234567891011121314151617181920212223242526
  1. package dns
  2. import (
  3. "regexp"
  4. )
  5. // IPLocalhost is a regex pattern for IPv4 or IPv6 loopback range.
  6. const IPLocalhost = `((127\.([0-9]{1,3}\.){2}[0-9]{1,3})|(::1)$)`
  7. // IPv4Localhost is a regex pattern for IPv4 localhost address range.
  8. const IPv4Localhost = `(127\.([0-9]{1,3}\.){2}[0-9]{1,3})`
  9. var localhostIPRegexp = regexp.MustCompile(IPLocalhost)
  10. var localhostIPv4Regexp = regexp.MustCompile(IPv4Localhost)
  11. // IsLocalhost returns true if ip matches the localhost IP regular expression.
  12. // Used for determining if nameserver settings are being passed which are
  13. // localhost addresses
  14. func IsLocalhost(ip string) bool {
  15. return localhostIPRegexp.MatchString(ip)
  16. }
  17. // IsIPv4Localhost returns true if ip matches the IPv4 localhost regular expression.
  18. func IsIPv4Localhost(ip string) bool {
  19. return localhostIPv4Regexp.MatchString(ip)
  20. }