Files
podman/pkg/machine/connection.go
Paul Holzinger ce07860a1c machine: fix default connection URL to use 127.0.0.1
gvproxy listens on 127.0.0.1, using localhost as hostname can result in
the client trying to connect to the ipv6 localhost (`::1`). This will
fail as shown in the issue. This switches the hostname in the system
connection to 127.0.0.1 to fix this problem.
I switched the qemu, hyperV and WSL backend. I haven't touched the
applehv code because it uses two different ips and I am not sure what is
the correct thing there. I leave this to Brent to figure out.

[NO NEW TESTS NEEDED]

[1] https://github.com/containers/gvisor-tap-vsock/blob/main/cmd/gvproxy/main.go#L197-L199

Fixes #16470

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-05-16 10:55:31 +02:00

92 lines
1.8 KiB
Go

//go:build amd64 || arm64
// +build amd64 arm64
package machine
import (
"errors"
"fmt"
"github.com/containers/common/pkg/config"
)
const LocalhostIP = "127.0.0.1"
func AddConnection(uri fmt.Stringer, name, identity string, isDefault bool) error {
if len(identity) < 1 {
return errors.New("identity must be defined")
}
cfg, err := config.ReadCustomConfig()
if err != nil {
return err
}
if _, ok := cfg.Engine.ServiceDestinations[name]; ok {
return errors.New("cannot overwrite connection")
}
if isDefault {
cfg.Engine.ActiveService = name
}
dst := config.Destination{
URI: uri.String(),
IsMachine: true,
}
dst.Identity = identity
if cfg.Engine.ServiceDestinations == nil {
cfg.Engine.ServiceDestinations = map[string]config.Destination{
name: dst,
}
cfg.Engine.ActiveService = name
} else {
cfg.Engine.ServiceDestinations[name] = dst
}
return cfg.Write()
}
func AnyConnectionDefault(name ...string) (bool, error) {
cfg, err := config.ReadCustomConfig()
if err != nil {
return false, err
}
for _, n := range name {
if n == cfg.Engine.ActiveService {
return true, nil
}
}
return false, nil
}
func ChangeDefault(name string) error {
cfg, err := config.ReadCustomConfig()
if err != nil {
return err
}
cfg.Engine.ActiveService = name
return cfg.Write()
}
func RemoveConnections(names ...string) error {
cfg, err := config.ReadCustomConfig()
if err != nil {
return err
}
for _, name := range names {
if _, ok := cfg.Engine.ServiceDestinations[name]; ok {
delete(cfg.Engine.ServiceDestinations, name)
} else {
return fmt.Errorf("unable to find connection named %q", name)
}
if cfg.Engine.ActiveService == name {
cfg.Engine.ActiveService = ""
for service := range cfg.Engine.ServiceDestinations {
cfg.Engine.ActiveService = service
break
}
}
}
return cfg.Write()
}