From c6e96c67ce760c6f71391d491c631e800e9bf141 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Mon, 28 Mar 2022 12:47:23 +0200 Subject: [PATCH 1/3] lncfg: normal TCP resolution for unspecified IPs Use normal TCP resolution for any unspecified IP (0.0.0.0 or ::) instead of using the Tor resolver. --- docs/release-notes/release-notes-0.15.0.md | 4 ++++ lncfg/address.go | 19 +++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/docs/release-notes/release-notes-0.15.0.md b/docs/release-notes/release-notes-0.15.0.md index 24ecd3f53..df96fd3f2 100644 --- a/docs/release-notes/release-notes-0.15.0.md +++ b/docs/release-notes/release-notes-0.15.0.md @@ -67,6 +67,9 @@ then watch it on chain. Taproot script spends are also supported through the * [Fixed node shutdown in forward interceptor itests](https://github.com/lightningnetwork/lnd/pull/6362). * [Fixed a bug that would cause lnd to be unable to parse certain PSBT blobs](https://github.com/lightningnetwork/lnd/pull/6383). + +* [Use normal TCP resolution, instead of Tor DNS resolution, for addresses + using the all-interfaces IP](https://github.com/lightningnetwork/lnd/pull/6376). ## Misc @@ -213,6 +216,7 @@ gRPC performance metrics (latency to process `GetInfo`, etc)](https://github.com * Carsten Otto * Dan Bolser * Daniel McNally +* Elle Mouton * ErikEk * Eugene Siegel * henta diff --git a/lncfg/address.go b/lncfg/address.go index afb4188dd..929f39700 100644 --- a/lncfg/address.go +++ b/lncfg/address.go @@ -134,6 +134,16 @@ func isIPv6Host(host string) bool { return v6Addr.To4() == nil } +// isUnspecifiedHost returns true if the host IP is considered unspecified. +func isUnspecifiedHost(host string) bool { + addr := net.ParseIP(host) + if addr == nil { + return false + } + + return addr.IsUnspecified() +} + // IsUnix returns true if an address describes an Unix socket address. func IsUnix(addr net.Addr) bool { return strings.HasPrefix(addr.Network(), "unix") @@ -230,17 +240,18 @@ func ParseAddressString(strAddress string, defaultPort string, } // Otherwise, we'll attempt the resolve the host. The Tor - // resolver is unable to resolve local or IPv6 addresses, so - // we'll use the system resolver instead. + // resolver is unable to resolve local addresses, + // IPv6 addresses, or the all-interfaces address, so we'll use + // the system resolver instead for those. if rawHost == "" || IsLoopback(rawHost) || - isIPv6Host(rawHost) { + isIPv6Host(rawHost) || isUnspecifiedHost(rawHost) { return net.ResolveTCPAddr("tcp", addrWithPort) } // If we've reached this point, then it's possible that this // resolve returns an error if it isn't able to resolve the - // host. For eaxmple, local entries in /etc/hosts will fail to + // host. For example, local entries in /etc/hosts will fail to // be resolved by Tor. In order to handle this case, we'll fall // back to the normal system resolver if we fail with an // identifiable error. From c582438a4e31d6017d1ebe4c08741f8c3feb70e4 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Tue, 29 Mar 2022 08:47:01 +0200 Subject: [PATCH 2/3] lncfg: use net pkg IsLoopback method Use the IsLoopback method provided by the net package instead of using hardcoded loopback addresses. --- lncfg/address.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lncfg/address.go b/lncfg/address.go index 929f39700..0f7c35761 100644 --- a/lncfg/address.go +++ b/lncfg/address.go @@ -14,10 +14,6 @@ import ( "github.com/lightningnetwork/lnd/tor" ) -var ( - loopBackAddrs = []string{"localhost", "127.0.0.1", "[::1]"} -) - // TCPResolver is a function signature that resolves an address on a given // network. type TCPResolver = func(network, addr string) (*net.TCPAddr, error) @@ -112,14 +108,18 @@ func TLSListenOnAddress(addr net.Addr, } // IsLoopback returns true if an address describes a loopback interface. -func IsLoopback(addr string) bool { - for _, loopback := range loopBackAddrs { - if strings.Contains(addr, loopback) { - return true - } +func IsLoopback(host string) bool { + if strings.Contains(host, "localhost") { + return true } - return false + rawHost, _, _ := net.SplitHostPort(host) + addr := net.ParseIP(rawHost) + if addr == nil { + return false + } + + return addr.IsLoopback() } // isIPv6Host returns true if the host is IPV6 and false otherwise. From 2bf2939b84209bd125810448f557c1f433246463 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Thu, 31 Mar 2022 09:49:09 +0200 Subject: [PATCH 3/3] go.mod: update btcd to include tor resolver fix --- go.mod | 2 +- go.sum | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index c2cf2bf6b..ae8735c71 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ require ( github.com/NebulousLabs/fastrand v0.0.0-20181203155948-6fb6489aac4e // indirect github.com/NebulousLabs/go-upnp v0.0.0-20180202185039-29b680b06c82 github.com/Yawning/aez v0.0.0-20211027044916-e49e68abd344 - github.com/btcsuite/btcd v0.22.0-beta.0.20220316175102-8d5c75c28923 + github.com/btcsuite/btcd v0.22.0-beta.0.20220330201728-074266215c26 github.com/btcsuite/btcd/btcec/v2 v2.1.3 github.com/btcsuite/btcd/btcutil v1.1.1 github.com/btcsuite/btcd/btcutil/psbt v1.1.2 diff --git a/go.sum b/go.sum index 4abb2ad43..5f951f7c6 100644 --- a/go.sum +++ b/go.sum @@ -74,8 +74,9 @@ github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13P github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M= github.com/btcsuite/btcd v0.22.0-beta.0.20220204213055-eaf0459ff879/go.mod h1:osu7EoKiL36UThEgzYPqdRaxeo0NU8VoXqgcnwpey0g= github.com/btcsuite/btcd v0.22.0-beta.0.20220207191057-4dc4ff7963b4/go.mod h1:7alexyj/lHlOtr2PJK7L/+HDJZpcGDn/pAU98r7DY08= -github.com/btcsuite/btcd v0.22.0-beta.0.20220316175102-8d5c75c28923 h1:6H47xWODLXYDuzHapvx4dauPqFjegX4+rHgUkFQPvfw= github.com/btcsuite/btcd v0.22.0-beta.0.20220316175102-8d5c75c28923/go.mod h1:taIcYprAW2g6Z9S0gGUxyR+zDwimyDMK5ePOX+iJ2ds= +github.com/btcsuite/btcd v0.22.0-beta.0.20220330201728-074266215c26 h1:dgH5afJcotX4eXo7+bXp8Z7lOw0FyVxXQwvtkN+jab4= +github.com/btcsuite/btcd v0.22.0-beta.0.20220330201728-074266215c26/go.mod h1:taIcYprAW2g6Z9S0gGUxyR+zDwimyDMK5ePOX+iJ2ds= github.com/btcsuite/btcd/btcec/v2 v2.1.0/go.mod h1:2VzYrv4Gm4apmbVVsSq5bqf1Ec8v56E48Vt0Y/umPgA= github.com/btcsuite/btcd/btcec/v2 v2.1.1/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE= github.com/btcsuite/btcd/btcec/v2 v2.1.3 h1:xM/n3yIhHAhHy04z4i43C8p4ehixJZMsnrVJkgl+MTE=