Files
Zakk 833af7dc74 refactor: use what the dependencies already provide
A read of the tree for home-grown code that a dependency or the platform
covers. Each item names what replaces it.

- IPv4 CIDR membership was a binary-string trie (infra/dataStructure/trie)
  fed with CIDRs rendered as bit strings; net.IPNet.Contains, which the
  same file already used for IPv6, does it. The trie package is gone.
- The response replay cache was an LRU with its own linked list, indexes
  and timeout strategy (infra/dataStructure/lru), of which one fixed-size
  instance existed; hashicorp/golang-lru/v2, already in go.mod, is that
  cache, typed. go mod tidy also dropped go-nanoid, which nothing imported.
- The HTTP client for subscription updates through the local proxy carried
  a CONNECT dialer of its own (pkg/util/proxyWithHttp); http.Transport's
  Proxy handles socks5:// and http:// URLs, resolves hostnames on the
  SOCKS proxy and uses CONNECT for https. Verified on the VM: a
  subscription update succeeds in both "pac" and "proxy" modes.
- core/dns/qtype.go listed nine type names in two switches before falling
  back to miekg/dns tables that contain the same names; dns.Type.String
  and dns.StringToType are the tables.
- The GUI tracked prefers-color-scheme with its own media query and
  toggled a theme-dark class nothing reads any more; Vuetify's "system"
  theme follows the OS itself. Verified in headless Chrome: auto follows
  the OS in both directions, an explicit choice overrides it.
- The AUR packages carried .INSTALL hooks whose only content was a
  coloured "Completed!" banner, duplicated in the deb/rpm after-install
  scripts; pacman and apt report that themselves. The hooks are gone, the
  release workflow stops copying them, and after_install/after_upgrade
  keep only daemon-reload and the restart.
- The tap release job downloaded eight artifacts in eight steps;
  actions/download-artifact takes a pattern with merge-multiple.
2026-09-20 16:40:34 +10:00

100 lines
1.6 KiB
Go

package netTools
import (
"net"
)
var intranet4 = []string{
"0.0.0.0/32",
"10.0.0.0/8",
"127.0.0.0/8",
"169.254.0.0/16",
"172.16.0.0/12",
"192.168.0.0/16",
"224.0.0.0/4",
"240.0.0.0/4",
}
var jokernet4 = []string{
"0.0.0.0/8",
"127.0.0.0/8",
"240.0.0.0/4",
}
var intranet6 = []string{
"::/128",
"::1/128",
"64:ff9b::/96",
"100::/64",
"2001::/32",
"2001:20::/28",
"2001:db8::/32",
"2002::/16",
"fc00::/7",
"fe80::/10",
"ff00::/8",
}
var jokernet6 = []string{
"::/128",
"::1/128",
"fc00::/7",
"ff00::/8",
}
type IPNets struct {
nets []*net.IPNet
}
var (
ipnetsIntranet4 *IPNets
ipnetsJokernet4 *IPNets
ipnetsIntranet6 *IPNets
ipnetsJokernet6 *IPNets
)
func NewIPNets(cidrs []string) (*IPNets, error) {
n := new(IPNets)
for _, cidr := range cidrs {
_, ipnet, err := net.ParseCIDR(cidr)
if err != nil {
return nil, err
}
n.nets = append(n.nets, ipnet)
}
return n, nil
}
func (n *IPNets) Match(ip net.IP) bool {
for _, n := range n.nets {
if n.Contains(ip) {
return true
}
}
return false
}
func init() {
ipnetsIntranet4, _ = NewIPNets(intranet4)
ipnetsJokernet4, _ = NewIPNets(jokernet4)
ipnetsIntranet6, _ = NewIPNets(intranet6)
ipnetsJokernet6, _ = NewIPNets(jokernet6)
}
func IsIntranet4(ipv4 *[4]byte) bool {
return ipnetsIntranet4.Match(net.IP(ipv4[:]))
}
func IsJokernet4(ipv4 *[4]byte) bool {
return ipnetsJokernet4.Match(net.IP(ipv4[:]))
}
func IsIntranet6(ipv6 *[16]byte) bool {
v6 := net.IP(ipv6[:])
return ipnetsIntranet6.Match(v6)
}
func IsJokernet6(ipv6 *[16]byte) bool {
v6 := net.IP(ipv6[:])
return ipnetsJokernet6.Match(v6)
}