Skip to content

Commit

Permalink
new: add inline static ips
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Feb 20, 2024
1 parent bd64e4e commit 362291c
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion route/staticDNS.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func createEntries(items map[string][]string) map[string]StaticDNSEntry {
if ip.Is4() {
entry.IPv4 = append(entry.IPv4, ip)
} else {
entry.IPv4 = append(entry.IPv6, ip)
entry.IPv6 = append(entry.IPv6, ip)
}
}
entries[domain] = entry
Expand Down Expand Up @@ -79,6 +79,24 @@ func lookupStaticIP(domain string, strategy uint8, entries map[string]StaticDNSE
}
return []netip.Addr{ipaddr}, nil
}
if strings.Contains(domain, ",") {
entry := StaticDNSEntry{}
for _, ipString := range strings.Split(domain, ",") {
ip, err := netip.ParseAddr(ipString)
if err != nil {
fmt.Printf("Invalid IP address for domain %s: %s\n", domain, ipString)
continue
}

if ip.Is4() {
entry.IPv4 = append(entry.IPv4, ip)
} else {
entry.IPv6 = append(entry.IPv6, ip)
}
}
entries[domain] = entry
return lookupStaticIP(domain, strategy, entries)
}
return nil, fmt.Errorf("NotFound")
}

Expand Down

0 comments on commit 362291c

Please sign in to comment.