netns_linux: remove special handling for tests.
With netns handling localhost now, existing tests no longer need special handling. The tests set up their connections to localhost, and the connections work without fuss. Remove the special handling for tests. Also remove the hostinfo.TestCase support, since this was the only use of it. It can be added back later if really needed, but it would be better to try to make tests work without special cases. Signed-off-by: Denton Gentry <dgentry@tailscale.com>pull/2429/head
parent
d2480fd508
commit
e28bc49e5f
|
@ -22,7 +22,7 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep
|
|||
tailscale.com/derp from tailscale.com/derp/derphttp
|
||||
tailscale.com/derp/derphttp from tailscale.com/net/netcheck
|
||||
tailscale.com/disco from tailscale.com/derp
|
||||
tailscale.com/hostinfo from tailscale.com/net/interfaces+
|
||||
tailscale.com/hostinfo from tailscale.com/net/interfaces
|
||||
tailscale.com/ipn from tailscale.com/cmd/tailscale/cli+
|
||||
tailscale.com/ipn/ipnstate from tailscale.com/cmd/tailscale/cli+
|
||||
tailscale.com/metrics from tailscale.com/derp
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
package hostinfo
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"io"
|
||||
"os"
|
||||
"runtime"
|
||||
|
@ -29,7 +28,6 @@ const (
|
|||
Heroku = EnvType("hr")
|
||||
AzureAppService = EnvType("az")
|
||||
AWSFargate = EnvType("fg")
|
||||
TestCase = EnvType("tc")
|
||||
)
|
||||
|
||||
var envType atomic.Value // of EnvType
|
||||
|
@ -44,11 +42,6 @@ func GetEnvType() EnvType {
|
|||
}
|
||||
|
||||
func getEnvType() EnvType {
|
||||
// inTestCase needs to go first. If running tests in a container, we want
|
||||
// the environment to be TestCase not the type of container.
|
||||
if inTestCase() {
|
||||
return TestCase
|
||||
}
|
||||
if inKnative() {
|
||||
return KNative
|
||||
}
|
||||
|
@ -91,13 +84,6 @@ func InContainer() bool {
|
|||
return ret
|
||||
}
|
||||
|
||||
func inTestCase() bool {
|
||||
if flag.CommandLine.Lookup("test.v") != nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func inKnative() bool {
|
||||
// https://cloud.google.com/run/docs/reference/container-contract#env-vars
|
||||
if os.Getenv("K_REVISION") != "" && os.Getenv("K_CONFIGURATION") != "" &&
|
||||
|
|
|
@ -15,7 +15,6 @@ import (
|
|||
"syscall"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
"tailscale.com/hostinfo"
|
||||
"tailscale.com/net/interfaces"
|
||||
)
|
||||
|
||||
|
@ -75,14 +74,6 @@ func useSocketMark() bool {
|
|||
// ignoreErrors returns true if we should ignore setsocketopt errors in
|
||||
// this instance.
|
||||
func ignoreErrors() bool {
|
||||
// If we're in a test, ignore errors. Assume the test knows
|
||||
// what it's doing and will do its own skips or permission
|
||||
// checks if it's setting up a world that needs netns to work.
|
||||
// But by default, assume that tests don't need netns and it's
|
||||
// harmless to ignore the sockopts failing.
|
||||
if hostinfo.GetEnvType() == hostinfo.TestCase {
|
||||
return true
|
||||
}
|
||||
if os.Getuid() != 0 {
|
||||
// only root can manipulate these socket flags
|
||||
return true
|
||||
|
@ -95,9 +86,6 @@ func ignoreErrors() bool {
|
|||
// It's intentionally the same signature as net.Dialer.Control
|
||||
// and net.ListenConfig.Control.
|
||||
func control(network, address string, c syscall.RawConn) error {
|
||||
if hostinfo.GetEnvType() == hostinfo.TestCase {
|
||||
return nil
|
||||
}
|
||||
if isLocalhost(address) {
|
||||
// Don't bind to an interface for localhost connections.
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue