lncfg+config: use address string in IsLoopback

This commit is contained in:
Wilmer Paulino 2018-06-27 18:27:05 -07:00
parent 17399994e4
commit bbeb8b2ddd
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F
3 changed files with 5 additions and 8 deletions

@ -875,10 +875,7 @@ func loadConfig() (*config, error) {
// inbound support is enabled. // inbound support is enabled.
if cfg.Tor.V2 || cfg.Tor.V3 { if cfg.Tor.V2 || cfg.Tor.V3 {
for _, addr := range cfg.Listeners { for _, addr := range cfg.Listeners {
// Due to the addresses being normalized above, we can if lncfg.IsLoopback(addr.String()) {
// skip checking the error.
host, _, _ := net.SplitHostPort(addr.String())
if lncfg.IsLoopback(addr) {
continue continue
} }

@ -52,7 +52,7 @@ func EnforceSafeAuthentication(addrs []net.Addr, macaroonsActive bool) error {
// on. If it's a localhost address, we'll skip it, otherwise, we'll // on. If it's a localhost address, we'll skip it, otherwise, we'll
// return an error if macaroons are inactive. // return an error if macaroons are inactive.
for _, addr := range addrs { for _, addr := range addrs {
if IsLoopback(addr) || IsUnix(addr) { if IsLoopback(addr.String()) || IsUnix(addr) {
continue continue
} }
@ -79,9 +79,9 @@ func TlsListenOnAddress(addr net.Addr,
} }
// IsLoopback returns true if an address describes a loopback interface. // IsLoopback returns true if an address describes a loopback interface.
func IsLoopback(addr net.Addr) bool { func IsLoopback(addr string) bool {
for _, loopback := range loopBackAddrs { for _, loopback := range loopBackAddrs {
if strings.Contains(addr.String(), loopback) { if strings.Contains(addr, loopback) {
return true return true
} }
} }

@ -100,7 +100,7 @@ func TestAddresses(t *testing.T) {
netAddr.Network(), netAddr.String(), netAddr.Network(), netAddr.String(),
) )
} }
isAddrLoopback := IsLoopback(normalized[0]) isAddrLoopback := IsLoopback(normalized[0].String())
if testVector.isLoopback != isAddrLoopback { if testVector.isLoopback != isAddrLoopback {
t.Fatalf("#%v: mismatched loopback detection: expected "+ t.Fatalf("#%v: mismatched loopback detection: expected "+
"%v, got %v for addr %s", "%v, got %v for addr %s",