2020-09-17 10:48:42 +08:00
|
|
|
package resolver
|
|
|
|
|
2022-04-20 01:52:51 +08:00
|
|
|
import "net/netip"
|
2020-09-17 10:48:42 +08:00
|
|
|
|
|
|
|
var DefaultHostMapper Enhancer
|
|
|
|
|
|
|
|
type Enhancer interface {
|
|
|
|
FakeIPEnabled() bool
|
|
|
|
MappingEnabled() bool
|
2022-04-20 01:52:51 +08:00
|
|
|
IsFakeIP(netip.Addr) bool
|
|
|
|
IsFakeBroadcastIP(netip.Addr) bool
|
|
|
|
IsExistFakeIP(netip.Addr) bool
|
|
|
|
FindHostByIP(netip.Addr) (string, bool)
|
2022-03-23 01:05:43 +08:00
|
|
|
FlushFakeIP() error
|
2022-04-20 01:52:51 +08:00
|
|
|
InsertHostByIP(netip.Addr, string)
|
2022-04-13 16:47:47 +08:00
|
|
|
StoreFakePoolState()
|
2020-09-17 10:48:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func FakeIPEnabled() bool {
|
|
|
|
if mapper := DefaultHostMapper; mapper != nil {
|
|
|
|
return mapper.FakeIPEnabled()
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func MappingEnabled() bool {
|
|
|
|
if mapper := DefaultHostMapper; mapper != nil {
|
|
|
|
return mapper.MappingEnabled()
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-04-20 01:52:51 +08:00
|
|
|
func IsFakeIP(ip netip.Addr) bool {
|
2020-09-17 10:48:42 +08:00
|
|
|
if mapper := DefaultHostMapper; mapper != nil {
|
|
|
|
return mapper.IsFakeIP(ip)
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-04-20 01:52:51 +08:00
|
|
|
func IsFakeBroadcastIP(ip netip.Addr) bool {
|
2022-03-15 02:43:40 +08:00
|
|
|
if mapper := DefaultHostMapper; mapper != nil {
|
|
|
|
return mapper.IsFakeBroadcastIP(ip)
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-04-20 01:52:51 +08:00
|
|
|
func IsExistFakeIP(ip netip.Addr) bool {
|
2020-10-17 12:52:43 +08:00
|
|
|
if mapper := DefaultHostMapper; mapper != nil {
|
|
|
|
return mapper.IsExistFakeIP(ip)
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-04-20 01:52:51 +08:00
|
|
|
func InsertHostByIP(ip netip.Addr, host string) {
|
2022-03-30 23:54:52 +08:00
|
|
|
if mapper := DefaultHostMapper; mapper != nil {
|
|
|
|
mapper.InsertHostByIP(ip, host)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-20 01:52:51 +08:00
|
|
|
func FindHostByIP(ip netip.Addr) (string, bool) {
|
2020-09-17 10:48:42 +08:00
|
|
|
if mapper := DefaultHostMapper; mapper != nil {
|
|
|
|
return mapper.FindHostByIP(ip)
|
|
|
|
}
|
|
|
|
|
|
|
|
return "", false
|
|
|
|
}
|
2022-03-23 01:05:43 +08:00
|
|
|
|
|
|
|
func FlushFakeIP() error {
|
|
|
|
if mapper := DefaultHostMapper; mapper != nil {
|
|
|
|
return mapper.FlushFakeIP()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2022-04-13 05:55:08 +08:00
|
|
|
|
2022-04-13 16:47:47 +08:00
|
|
|
func StoreFakePoolState() {
|
2022-04-13 05:55:08 +08:00
|
|
|
if mapper := DefaultHostMapper; mapper != nil {
|
2022-04-13 16:47:47 +08:00
|
|
|
mapper.StoreFakePoolState()
|
2022-04-13 05:55:08 +08:00
|
|
|
}
|
|
|
|
}
|