Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: nss myhostname incorrectly handles gateway and outbound hostnames #56387

Closed
mateusz834 opened this issue Oct 24, 2022 · 3 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@mateusz834
Copy link
Member

mateusz834 commented Oct 24, 2022

nss-myhostname(8):

•The hostname "_gateway" is resolved to all current default routing gateway addresses, ordered by their metric. (...)
•The hostname "_outbound" is resolved to the local IPv4 and IPv6 addresses that are most likely used for communication with other hosts. (...)

But it only checks for the "gateway" hostname which is incorrect, it should check for "_gateway" (as defined in man page), and _outbound.

go/src/net/conf.go

Lines 249 to 251 in 7e72d38

if isLocalhost(hostname) || isGateway(hostname) {
return fallbackOrder
}

go/src/net/conf.go

Lines 348 to 352 in 7e72d38

// isGateway reports whether h should be considered a "gateway"
// name for the myhostname NSS module.
func isGateway(h string) bool {
return stringsEqualFold(h, "gateway")
}

package main

import (
	"fmt"
	"net"
)

func main() {
	fmt.Println(net.LookupHost("localhost"))
	fmt.Println(net.LookupHost("_gateway"))
	fmt.Println(net.LookupHost("_outbound"))
}
[mateusz@arch testtt]$  GODEBUG=netdns=2 go run main.go
go package net: confVal.netCgo = false  netGo = false
go package net: dynamic selection of DNS resolver
go package net: hostLookupOrder(localhost) = cgo
[::1 127.0.0.1] <nil>
go package net: hostLookupOrder(_gateway) = files,dns
[] lookup _gateway on 81.26.0.10:53: no such host
go package net: hostLookupOrder(_outbound) = files,dns
[] lookup _outbound on 81.26.0.10:53: no such host
@mateusz834
Copy link
Member Author

With this linked CL it should work fine.

[mateusz@arch testtt]$ GODEBUG=netdns=2 go run main.go
go package net: confVal.netCgo = false  netGo = false
go package net: dynamic selection of DNS resolver
go package net: hostLookupOrder(localhost) = cgo
[::1 127.0.0.1] <nil>
go package net: hostLookupOrder(_gateway) = cgo
[10.100.0.1] <nil>
go package net: hostLookupOrder(_outbound) = cgo
[10.100.5.228] <nil>

@gopherbot
Copy link

Change https://go.dev/cl/445075 mentions this issue: net: handle correctly the _gateway and _outbound hostnames for nss myhostname

@seankhliao
Copy link
Member

cc @ianlancetaylor @neild

@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 24, 2022
@seankhliao seankhliao added this to the Backlog milestone Oct 24, 2022
@golang golang locked and limited conversation to collaborators Nov 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants