Rename functions

This commit is contained in:
Frank Denis 2026-09-07 12:11:10 +02:00
parent e54c45a936
commit 89fc43b398
10 changed files with 73 additions and 73 deletions

View file

@ -382,7 +382,7 @@ func ConfigLoad(proxy *Proxy, flags *ConfigFlags) error {
proxy.userName = config.UserName
proxy.child = *flags.Child
proxy.enableHotReload = config.EnableHotReload
proxy.outboundSource, err = parseOutboundSourcePolicy(config.OutboundSourceIPv4, config.OutboundSourceIPv6)
proxy.outboundSource, err = parseOutboundSources(config.OutboundSourceIPv4, config.OutboundSourceIPv6)
if err != nil {
return err
}
@ -398,7 +398,7 @@ func ConfigLoad(proxy *Proxy, flags *ConfigFlags) error {
if err := configureXTransport(proxy, &config); err != nil {
return err
}
logOutboundSourcePolicy(&proxy.outboundSource, proxy.xTransport.ignoreSystemDNS)
logOutboundSources(&proxy.outboundSource, proxy.xTransport.ignoreSystemDNS)
// Configure DoH client authentication
if err := configureDoHClientAuth(proxy, &config); err != nil {

View file

@ -71,8 +71,8 @@ func configureLogging(proxy *Proxy, flags *ConfigFlags, config *Config) {
}
}
// logOutboundSourcePolicy reports missing source families and effective system DNS exclusions.
func logOutboundSourcePolicy(policy *outboundSourcePolicy, ignoreSystemDNS bool) {
// logOutboundSources reports missing source families and effective system DNS exclusions.
func logOutboundSources(policy *outboundSourcePolicy, ignoreSystemDNS bool) {
if !policy.enabled() {
return
}
@ -141,7 +141,7 @@ func configureXTransport(proxy *Proxy, config *Config) error {
}
forwardDialer := netproxy.Dialer(netproxy.Direct)
if proxy.outboundSource.enabled() {
forwardDialer = &sourceAwareProxyForwardDialer{xTransport: proxy.xTransport}
forwardDialer = &proxyDialer{xTransport: proxy.xTransport}
}
proxyDialer, err := netproxy.FromURL(proxyDialerURL, forwardDialer)
if err != nil {

View file

@ -7,7 +7,7 @@
"github.com/BurntSushi/toml"
)
func TestOutboundSourceConfigTOML(t *testing.T) {
func TestOutboundSourceConfig(t *testing.T) {
tests := []struct {
name string
toml string
@ -40,7 +40,7 @@ func TestOutboundSourceConfigTOML(t *testing.T) {
if _, err := toml.Decode(test.toml, &config); err != nil {
t.Fatal(err)
}
policy, err := parseOutboundSourcePolicy(config.OutboundSourceIPv4, config.OutboundSourceIPv6)
policy, err := parseOutboundSources(config.OutboundSourceIPv4, config.OutboundSourceIPv6)
if test.wantError != "" {
if err == nil || !strings.Contains(err.Error(), test.wantError) {
t.Fatalf("error = %v, want containing %q", err, test.wantError)

View file

@ -9,8 +9,8 @@
)
func TestDNSExchangeOutboundSource(t *testing.T) {
sourceIP := usableNonLoopbackIPv4(t)
policy, err := parseOutboundSourcePolicy(sourceIP.String(), "")
sourceIP := nonLoopbackIPv4(t)
policy, err := parseOutboundSources(sourceIP.String(), "")
if err != nil {
t.Fatal(err)
}
@ -24,7 +24,7 @@ func TestDNSExchangeOutboundSource(t *testing.T) {
name = proto + "-relayed"
}
t.Run(name, func(t *testing.T) {
relayAddress, peerCh, closeServer := startOutboundDNSServer(t, proto, sourceIP, relayed, nil)
relayAddress, peerCh, closeServer := startTestDNS(t, proto, sourceIP, relayed, nil)
serverAddress := relayAddress.String()
if relayed {
serverAddress = "9.9.9.9:53"
@ -53,7 +53,7 @@ func TestDNSExchangeOutboundSource(t *testing.T) {
}
}
func startOutboundDNSServer(t *testing.T, proto string, destinationIP net.IP, relayed bool, answer func(*dns.Msg)) (net.Addr, <-chan net.IP, func()) {
func startTestDNS(t *testing.T, proto string, destinationIP net.IP, relayed bool, answer func(*dns.Msg)) (net.Addr, <-chan net.IP, func()) {
t.Helper()
peerCh := make(chan net.IP, 1)
respond := func(packet []byte) []byte {

View file

@ -21,7 +21,7 @@ type outboundTarget struct {
source netip.Addr
}
func parseOutboundSourcePolicy(ipv4Str, ipv6Str string) (outboundSourcePolicy, error) {
func parseOutboundSources(ipv4Str, ipv6Str string) (outboundSourcePolicy, error) {
var policy outboundSourcePolicy
for _, field := range []struct {
family int

View file

@ -8,7 +8,7 @@
"time"
)
func usableNonLoopbackIPv4(t *testing.T) net.IP {
func nonLoopbackIPv4(t *testing.T) net.IP {
t.Helper()
addrs, err := net.InterfaceAddrs()
if err != nil {
@ -24,8 +24,8 @@ func usableNonLoopbackIPv4(t *testing.T) net.IP {
return nil
}
func TestOutboundSourceUDPListenerLocalBypass(t *testing.T) {
policy, err := parseOutboundSourcePolicy("192.0.2.10", "2001:db8::10")
func TestListenUDPLoopback(t *testing.T) {
policy, err := parseOutboundSources("192.0.2.10", "2001:db8::10")
if err != nil {
t.Fatal(err)
}
@ -41,7 +41,7 @@ func TestOutboundSourceUDPListenerLocalBypass(t *testing.T) {
}
func TestOutboundSourceFor(t *testing.T) {
policy, err := parseOutboundSourcePolicy("192.0.2.10", "2001:db8::10")
policy, err := parseOutboundSources("192.0.2.10", "2001:db8::10")
if err != nil {
t.Fatal(err)
}
@ -83,8 +83,8 @@ func TestOutboundSourceFor(t *testing.T) {
}
}
func TestOutboundSourceDialerOptionsAndZones(t *testing.T) {
policy, err := parseOutboundSourcePolicy("192.0.2.10", "fe80::1%en0")
func TestSourceDialerOptions(t *testing.T) {
policy, err := parseOutboundSources("192.0.2.10", "fe80::1%en0")
if err != nil {
t.Fatal(err)
}
@ -105,7 +105,7 @@ func TestOutboundSourceDialerOptionsAndZones(t *testing.T) {
}
}
func TestNewDNSTransportHasIndependentDialer(t *testing.T) {
func TestDNSTransportDialerIsolation(t *testing.T) {
first := newDNSTransport()
second := newDNSTransport()
if first.Dialer.Timeout != 5*time.Second || first.Dialer.KeepAlive != 3*time.Second {
@ -117,8 +117,8 @@ func TestNewDNSTransportHasIndependentDialer(t *testing.T) {
}
}
func TestConfigureOutboundDialer(t *testing.T) {
policy, err := parseOutboundSourcePolicy("192.0.2.10", "2001:db8::10")
func TestSourceDialer(t *testing.T) {
policy, err := parseOutboundSources("192.0.2.10", "2001:db8::10")
if err != nil {
t.Fatal(err)
}
@ -136,8 +136,8 @@ func TestConfigureOutboundDialer(t *testing.T) {
}
}
func TestOutboundSourceDNSErrorContext(t *testing.T) {
policy, err := parseOutboundSourcePolicy("192.0.2.10", "")
func TestSourceDNSError(t *testing.T) {
policy, err := parseOutboundSources("192.0.2.10", "")
if err != nil {
t.Fatal(err)
}

View file

@ -9,13 +9,13 @@
"codeberg.org/miekg/dns/rdata"
)
func TestDNS64DiscoveryOutboundSource(t *testing.T) {
sourceIP := usableNonLoopbackIPv4(t)
policy, err := parseOutboundSourcePolicy(sourceIP.String(), "")
func TestDNS64SourceBinding(t *testing.T) {
sourceIP := nonLoopbackIPv4(t)
policy, err := parseOutboundSources(sourceIP.String(), "")
if err != nil {
t.Fatal(err)
}
resolver, peerCh, closeServer := startOutboundDNSServer(t, "udp", sourceIP, false, func(msg *dns.Msg) {
resolver, peerCh, closeServer := startTestDNS(t, "udp", sourceIP, false, func(msg *dns.Msg) {
msg.Answer = []dns.RR{&dns.AAAA{
Hdr: dns.Header{Name: rfc7050WKN, Class: dns.ClassINET, TTL: 60},
AAAA: rdata.AAAA{Addr: netip.MustParseAddr("64:ff9b::c000:aa")},

View file

@ -9,9 +9,9 @@
"time"
)
func TestUDPConnPool_OutboundSource(t *testing.T) {
sourceIP := usableNonLoopbackIPv4(t)
policy, err := parseOutboundSourcePolicy(sourceIP.String(), "")
func TestUDPConnPool_SourceBinding(t *testing.T) {
sourceIP := nonLoopbackIPv4(t)
policy, err := parseOutboundSources(sourceIP.String(), "")
if err != nil {
t.Fatal(err)
}
@ -64,8 +64,8 @@ func TestUDPConnPool_OutboundSource(t *testing.T) {
pool.Discard(replacement)
}
func TestUDPConnPool_OutboundSourceLoopbackBypass(t *testing.T) {
policy, err := parseOutboundSourcePolicy("192.0.2.1", "")
func TestUDPConnPool_Loopback(t *testing.T) {
policy, err := parseOutboundSources("192.0.2.1", "")
if err != nil {
t.Fatal(err)
}
@ -86,13 +86,13 @@ func TestUDPConnPool_OutboundSourceLoopbackBypass(t *testing.T) {
}
}
func TestUDPConnPool_OutboundSourceBindFailure(t *testing.T) {
destinationIP := usableNonLoopbackIPv4(t)
func TestUDPConnPool_BindFailure(t *testing.T) {
destinationIP := nonLoopbackIPv4(t)
configured := "192.0.2.1"
if destinationIP.Equal(net.ParseIP(configured)) {
configured = "198.51.100.1"
}
policy, err := parseOutboundSourcePolicy(configured, "")
policy, err := parseOutboundSources(configured, "")
if err != nil {
t.Fatal(err)
}

View file

@ -106,18 +106,18 @@ type XTransport struct {
outboundSource *outboundSourcePolicy
}
type sourceAwareProxyForwardDialer struct {
type proxyDialer struct {
xTransport *XTransport
}
var _ netproxy.Dialer = (*sourceAwareProxyForwardDialer)(nil)
var _ netproxy.ContextDialer = (*sourceAwareProxyForwardDialer)(nil)
var _ netproxy.Dialer = (*proxyDialer)(nil)
var _ netproxy.ContextDialer = (*proxyDialer)(nil)
func (dialer *sourceAwareProxyForwardDialer) Dial(network, address string) (net.Conn, error) {
func (dialer *proxyDialer) Dial(network, address string) (net.Conn, error) {
return dialer.DialContext(context.Background(), network, address)
}
func (dialer *sourceAwareProxyForwardDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
func (dialer *proxyDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
if network != "tcp" && network != "tcp4" && network != "tcp6" {
return nil, fmt.Errorf("unsupported proxy forward network %q", network)
}
@ -133,7 +133,7 @@ func (dialer *sourceAwareProxyForwardDialer) DialContext(ctx context.Context, ne
if literal, err := netip.ParseAddr(host); err == nil {
addresses = []netip.Addr{literal}
} else {
ips, _, err := dialer.xTransport.resolveProxyEndpoint(host)
ips, _, err := dialer.xTransport.resolveProxy(host)
if err != nil {
return nil, fmt.Errorf("unable to resolve proxy endpoint %q: %w", host, err)
}
@ -373,7 +373,7 @@ func (xTransport *XTransport) rebuildTransport() {
cachedIPs, _, _ := xTransport.loadCachedIPs(host)
if xTransport.outboundSource.enabled() && xTransport.proxyDialer == nil && len(cachedIPs) == 0 {
resolved, err := xTransport.coveredDestinationIPs(host, "HTTP")
resolved, err := xTransport.resolveDialIPs(host, "HTTP")
if err != nil {
return nil, err
}
@ -538,7 +538,7 @@ type udpTarget struct {
cachedIPs, _, _ := xTransport.loadCachedIPs(host)
if xTransport.outboundSource.enabled() && len(cachedIPs) == 0 {
resolved, err := xTransport.coveredDestinationIPs(host, "HTTP/3")
resolved, err := xTransport.resolveDialIPs(host, "HTTP/3")
if err != nil {
return nil, err
}
@ -599,8 +599,8 @@ type udpTarget struct {
}
}
// coveredDestinationIPs resolves through the configured DNS policy before source binding.
func (xTransport *XTransport) coveredDestinationIPs(host, kind string) ([]net.IP, error) {
// resolveDialIPs resolves through the configured DNS policy before source binding.
func (xTransport *XTransport) resolveDialIPs(host, kind string) ([]net.IP, error) {
if literal := ParseIP(host); literal != nil {
return []net.IP{literal}, nil
}
@ -608,7 +608,7 @@ func (xTransport *XTransport) coveredDestinationIPs(host, kind string) ([]net.IP
var ttl time.Duration
var err error
if xTransport.httpProxyFunction != nil && kind == "HTTP" {
ips, ttl, err = xTransport.resolveProxyEndpoint(host)
ips, ttl, err = xTransport.resolveProxy(host)
} else {
ips, ttl, err = xTransport.resolve(host, xTransport.useIPv4, xTransport.useIPv6)
}
@ -752,8 +752,8 @@ func (xTransport *XTransport) resolve(host string, returnIPv4, returnIPv6 bool)
return xTransport.resolveHost(host, returnIPv4, returnIPv6, true)
}
// resolveProxyEndpoint avoids depending on the proxy to resolve its own address.
func (xTransport *XTransport) resolveProxyEndpoint(host string) ([]net.IP, time.Duration, error) {
// resolveProxy avoids depending on the proxy to resolve its own address.
func (xTransport *XTransport) resolveProxy(host string) ([]net.IP, time.Duration, error) {
return xTransport.resolveHost(host, xTransport.useIPv4, xTransport.useIPv6, false)
}

View file

@ -16,9 +16,9 @@
"codeberg.org/miekg/dns/rdata"
)
func TestXTransportOutboundSourceDial(t *testing.T) {
sourceIP := usableNonLoopbackIPv4(t)
policy, err := parseOutboundSourcePolicy(sourceIP.String(), "")
func TestXTransportSourceBinding(t *testing.T) {
sourceIP := nonLoopbackIPv4(t)
policy, err := parseOutboundSources(sourceIP.String(), "")
if err != nil {
t.Fatal(err)
}
@ -54,8 +54,8 @@ func TestXTransportOutboundSourceDial(t *testing.T) {
}
}
func TestXTransportOutboundSourceMissingFamily(t *testing.T) {
policy, err := parseOutboundSourcePolicy("192.0.2.10", "")
func TestXTransportMissingSource(t *testing.T) {
policy, err := parseOutboundSources("192.0.2.10", "")
if err != nil {
t.Fatal(err)
}
@ -67,15 +67,15 @@ func TestXTransportOutboundSourceMissingFamily(t *testing.T) {
}
}
func TestSourceAwareProxyForwardDialer(t *testing.T) {
sourceIP := usableNonLoopbackIPv4(t)
policy, err := parseOutboundSourcePolicy(sourceIP.String(), "")
func TestProxyDialer(t *testing.T) {
sourceIP := nonLoopbackIPv4(t)
policy, err := parseOutboundSources(sourceIP.String(), "")
if err != nil {
t.Fatal(err)
}
xTransport := NewXTransport(&policy)
xTransport.timeout = time.Second
forward := &sourceAwareProxyForwardDialer{xTransport: xTransport}
forward := &proxyDialer{xTransport: xTransport}
t.Run("remote", func(t *testing.T) {
listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IPv4zero})
@ -134,16 +134,16 @@ func TestSourceAwareProxyForwardDialer(t *testing.T) {
})
}
func TestXTransportResolverOutboundSource(t *testing.T) {
sourceIP := usableNonLoopbackIPv4(t)
policy, err := parseOutboundSourcePolicy(sourceIP.String(), "")
func TestResolverSourceBinding(t *testing.T) {
sourceIP := nonLoopbackIPv4(t)
policy, err := parseOutboundSources(sourceIP.String(), "")
if err != nil {
t.Fatal(err)
}
xTransport := NewXTransport(&policy)
for _, proto := range []string{"udp", "tcp"} {
t.Run(proto, func(t *testing.T) {
resolver, peerCh, closeServer := startResolvingDNSServer(t, proto, sourceIP)
resolver, peerCh, closeServer := startTestResolver(t, proto, sourceIP)
defer closeServer()
ips, _, err := xTransport.resolveUsingResolver(proto, "example.org", resolver, true, true, false)
if err != nil {
@ -159,14 +159,14 @@ func TestXTransportResolverOutboundSource(t *testing.T) {
}
}
func startResolvingDNSServer(t *testing.T, proto string, destinationIP net.IP) (string, <-chan net.IP, func()) {
func startTestResolver(t *testing.T, proto string, destinationIP net.IP) (string, <-chan net.IP, func()) {
t.Helper()
return startResolvingDNSServerWithAnswer(t, proto, destinationIP, netip.MustParseAddr("203.0.113.5"))
return startTestResolverWithIP(t, proto, destinationIP, netip.MustParseAddr("203.0.113.5"))
}
func startResolvingDNSServerWithAnswer(t *testing.T, proto string, destinationIP net.IP, answer netip.Addr) (string, <-chan net.IP, func()) {
func startTestResolverWithIP(t *testing.T, proto string, destinationIP net.IP, answer netip.Addr) (string, <-chan net.IP, func()) {
t.Helper()
addr, peers, closeServer := startOutboundDNSServer(t, proto, destinationIP, false, func(msg *dns.Msg) {
addr, peers, closeServer := startTestDNS(t, proto, destinationIP, false, func(msg *dns.Msg) {
msg.Answer = []dns.RR{&dns.A{
Hdr: dns.Header{Name: msg.Question[0].Header().Name, Class: dns.ClassINET, TTL: 60},
A: rdata.A{Addr: answer},
@ -175,14 +175,14 @@ func startResolvingDNSServerWithAnswer(t *testing.T, proto string, destinationIP
return addr.String(), peers, closeServer
}
func TestProxyEndpointResolutionDoesNotQueryItself(t *testing.T) {
func TestProxyResolveNoRecursion(t *testing.T) {
for _, kind := range []string{"SOCKS", "HTTP"} {
t.Run(kind, func(t *testing.T) {
loopback := net.IPv4(127, 0, 0, 1)
answer := netip.MustParseAddr("127.0.0.1")
internal, internalQueries, closeInternal := startResolvingDNSServerWithAnswer(t, "udp", loopback, answer)
internal, internalQueries, closeInternal := startTestResolverWithIP(t, "udp", loopback, answer)
defer closeInternal()
bootstrap, bootstrapQueries, closeBootstrap := startResolvingDNSServerWithAnswer(t, "udp", loopback, answer)
bootstrap, bootstrapQueries, closeBootstrap := startTestResolverWithIP(t, "udp", loopback, answer)
defer closeBootstrap()
listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: loopback})
if err != nil {
@ -195,7 +195,7 @@ func TestProxyEndpointResolutionDoesNotQueryItself(t *testing.T) {
_ = conn.Close()
}
}()
policy, err := parseOutboundSourcePolicy("192.0.2.10", "")
policy, err := parseOutboundSources("192.0.2.10", "")
if err != nil {
t.Fatal(err)
}
@ -210,7 +210,7 @@ func TestProxyEndpointResolutionDoesNotQueryItself(t *testing.T) {
defer cancel()
var conn net.Conn
if kind == "SOCKS" {
forward := &sourceAwareProxyForwardDialer{xTransport: xTransport}
forward := &proxyDialer{xTransport: xTransport}
conn, err = forward.DialContext(ctx, "tcp", endpoint)
} else {
proxyURL, parseErr := url.Parse("http://" + endpoint)
@ -239,7 +239,7 @@ func TestProxyEndpointResolutionDoesNotQueryItself(t *testing.T) {
}
}
func TestSourceAwareProxyForwardDialerScopedLiteral(t *testing.T) {
func TestProxyDialerIPv6Zone(t *testing.T) {
listener, err := net.ListenTCP("tcp6", &net.TCPAddr{IP: net.IPv6loopback})
if err != nil {
t.Skipf("IPv6 loopback is unavailable: %v", err)
@ -251,14 +251,14 @@ func TestSourceAwareProxyForwardDialerScopedLiteral(t *testing.T) {
_ = conn.Close()
}
}()
policy, err := parseOutboundSourcePolicy("192.0.2.10", "")
policy, err := parseOutboundSources("192.0.2.10", "")
if err != nil {
t.Fatal(err)
}
xTransport := NewXTransport(&policy)
xTransport.ignoreSystemDNS = true
xTransport.bootstrapResolvers = nil
forward := &sourceAwareProxyForwardDialer{xTransport: xTransport}
forward := &proxyDialer{xTransport: xTransport}
endpoint := net.JoinHostPort("::1%1", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port))
conn, err := forward.DialContext(context.Background(), "tcp", endpoint)
if err != nil {