summaryrefslogtreecommitdiff
path: root/libpod/networking_linux.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-06-01 19:41:46 +0200
committerGitHub <noreply@github.com>2021-06-01 19:41:46 +0200
commitcbffdddce6d741eac4f3efa132016aba99683500 (patch)
tree927b74764e93a47aae61597100502acbe17f1afd /libpod/networking_linux.go
parent7a52440a6d7fe7ac1ddccf9fe7247d7abca8ecce (diff)
parent7ef3981abe2412727840a2886489a08c03a05299 (diff)
downloadpodman-cbffdddce6d741eac4f3efa132016aba99683500.tar.gz
podman-cbffdddce6d741eac4f3efa132016aba99683500.tar.bz2
podman-cbffdddce6d741eac4f3efa132016aba99683500.zip
Merge pull request #10488 from baude/machinehostnetwork
Enable port forwarding on host
Diffstat (limited to 'libpod/networking_linux.go')
-rw-r--r--libpod/networking_linux.go24
1 files changed, 23 insertions, 1 deletions
diff --git a/libpod/networking_linux.go b/libpod/networking_linux.go
index 0e8a4f768..c928e02a6 100644
--- a/libpod/networking_linux.go
+++ b/libpod/networking_linux.go
@@ -273,7 +273,6 @@ func (r *Runtime) GetRootlessCNINetNs(new bool) (*RootlessCNI, error) {
if err != nil {
return nil, errors.Wrap(err, "error creating rootless cni network namespace")
}
-
// setup slirp4netns here
path := r.config.Engine.NetworkCmdPath
if path == "" {
@@ -437,9 +436,32 @@ func (r *Runtime) GetRootlessCNINetNs(new bool) (*RootlessCNI, error) {
return rootlessCNINS, nil
}
+// setPrimaryMachineIP is used for podman-machine and it sets
+// and environment variable with the IP address of the podman-machine
+// host.
+func setPrimaryMachineIP() error {
+ // no connection is actually made here
+ conn, err := net.Dial("udp", "8.8.8.8:80")
+ if err != nil {
+ return err
+ }
+ defer func() {
+ if err := conn.Close(); err != nil {
+ logrus.Error(err)
+ }
+ }()
+ addr := conn.LocalAddr().(*net.UDPAddr)
+ return os.Setenv("PODMAN_MACHINE_HOST", addr.IP.String())
+}
+
// setUpOCICNIPod will set up the cni networks, on error it will also tear down the cni
// networks. If rootless it will join/create the rootless cni namespace.
func (r *Runtime) setUpOCICNIPod(podNetwork ocicni.PodNetwork) ([]ocicni.NetResult, error) {
+ if r.config.MachineEnabled() {
+ if err := setPrimaryMachineIP(); err != nil {
+ return nil, err
+ }
+ }
rootlessCNINS, err := r.GetRootlessCNINetNs(true)
if err != nil {
return nil, err