control/controlhttp: rename a param from addr to optAddr for clarity

And update docs.

Updates #cleanup
Updates #13597 (tangentially; noted this cleanup while debugging)

Change-Id: I62440294c78b0bb3f5673be10318dd89af1e1bfe
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2024-10-01 20:07:58 -07:00 committed by Brad Fitzpatrick
parent f49d218cfe
commit 6b03e18975

View File

@ -297,9 +297,11 @@ func (d *Dialer) clock() tstime.Clock {
var debugNoiseDial = envknob.RegisterBool("TS_DEBUG_NOISE_DIAL") var debugNoiseDial = envknob.RegisterBool("TS_DEBUG_NOISE_DIAL")
// dialHost connects to the configured Dialer.Hostname and upgrades the // dialHost connects to the configured Dialer.Hostname and upgrades the
// connection into a controlbase.Conn. If addr is valid, then no DNS is used // connection into a controlbase.Conn.
// and the connection will be made to the provided address. //
func (a *Dialer) dialHost(ctx context.Context, addr netip.Addr) (*ClientConn, error) { // If optAddr is valid, then no DNS is used and the connection will be made to the
// provided address.
func (a *Dialer) dialHost(ctx context.Context, optAddr netip.Addr) (*ClientConn, error) {
// Create one shared context used by both port 80 and port 443 dials. // Create one shared context used by both port 80 and port 443 dials.
// If port 80 is still in flight when 443 returns, this deferred cancel // If port 80 is still in flight when 443 returns, this deferred cancel
// will stop the port 80 dial. // will stop the port 80 dial.
@ -330,11 +332,11 @@ type tryURLRes struct {
ch := make(chan tryURLRes) // must be unbuffered ch := make(chan tryURLRes) // must be unbuffered
try := func(u *url.URL) { try := func(u *url.URL) {
if debugNoiseDial() { if debugNoiseDial() {
a.logf("trying noise dial (%v, %v) ...", u, addr) a.logf("trying noise dial (%v, %v) ...", u, optAddr)
} }
cbConn, err := a.dialURL(ctx, u, addr) cbConn, err := a.dialURL(ctx, u, optAddr)
if debugNoiseDial() { if debugNoiseDial() {
a.logf("noise dial (%v, %v) = (%v, %v)", u, addr, cbConn, err) a.logf("noise dial (%v, %v) = (%v, %v)", u, optAddr, cbConn, err)
} }
select { select {
case ch <- tryURLRes{u, cbConn, err}: case ch <- tryURLRes{u, cbConn, err}:
@ -388,12 +390,15 @@ type tryURLRes struct {
} }
// dialURL attempts to connect to the given URL. // dialURL attempts to connect to the given URL.
func (a *Dialer) dialURL(ctx context.Context, u *url.URL, addr netip.Addr) (*ClientConn, error) { //
// If optAddr is valid, then no DNS is used and the connection will be made to the
// provided address.
func (a *Dialer) dialURL(ctx context.Context, u *url.URL, optAddr netip.Addr) (*ClientConn, error) {
init, cont, err := controlbase.ClientDeferred(a.MachineKey, a.ControlKey, a.ProtocolVersion) init, cont, err := controlbase.ClientDeferred(a.MachineKey, a.ControlKey, a.ProtocolVersion)
if err != nil { if err != nil {
return nil, err return nil, err
} }
netConn, err := a.tryURLUpgrade(ctx, u, addr, init) netConn, err := a.tryURLUpgrade(ctx, u, optAddr, init)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -439,19 +444,20 @@ func isLoopback(a net.Addr) bool {
ImpactsConnectivity: true, ImpactsConnectivity: true,
}) })
// tryURLUpgrade connects to u, and tries to upgrade it to a net.Conn. If addr // tryURLUpgrade connects to u, and tries to upgrade it to a net.Conn.
// is valid, then no DNS is used and the connection will be made to the //
// provided address. // If optAddr is valid, then no DNS is used and the connection will be made to
// the provided address.
// //
// Only the provided ctx is used, not a.ctx. // Only the provided ctx is used, not a.ctx.
func (a *Dialer) tryURLUpgrade(ctx context.Context, u *url.URL, addr netip.Addr, init []byte) (_ net.Conn, retErr error) { func (a *Dialer) tryURLUpgrade(ctx context.Context, u *url.URL, optAddr netip.Addr, init []byte) (_ net.Conn, retErr error) {
var dns *dnscache.Resolver var dns *dnscache.Resolver
// If we were provided an address to dial, then create a resolver that just // If we were provided an address to dial, then create a resolver that just
// returns that value; otherwise, fall back to DNS. // returns that value; otherwise, fall back to DNS.
if addr.IsValid() { if optAddr.IsValid() {
dns = &dnscache.Resolver{ dns = &dnscache.Resolver{
SingleHostStaticResult: []netip.Addr{addr}, SingleHostStaticResult: []netip.Addr{optAddr},
SingleHost: u.Hostname(), SingleHost: u.Hostname(),
Logf: a.Logf, // not a.logf method; we want to propagate nil-ness Logf: a.Logf, // not a.logf method; we want to propagate nil-ness
} }