summaryrefslogtreecommitdiff
path: root/libpod/networking_common.go
diff options
context:
space:
mode:
authorDoug Rabson <dfr@rabson.org>2022-09-09 11:07:00 +0100
committerDoug Rabson <dfr@rabson.org>2022-09-12 16:28:36 +0100
commit2bf050f1d1f39c3587fc98f9d66d0faa57cbd5f0 (patch)
tree85cfd5f0c214b9ca6934a77e596e284a6e3fe42b /libpod/networking_common.go
parent3d7f9f67a7fc07f5cba11a58f29ef824eccf3dc1 (diff)
downloadpodman-2bf050f1d1f39c3587fc98f9d66d0faa57cbd5f0.tar.gz
podman-2bf050f1d1f39c3587fc98f9d66d0faa57cbd5f0.tar.bz2
podman-2bf050f1d1f39c3587fc98f9d66d0faa57cbd5f0.zip
libpod: Move setUpNetwork and getCNIPodName to networking_common.go
[NO NEW TESTS NEEDED] Signed-off-by: Doug Rabson <dfr@rabson.org>
Diffstat (limited to 'libpod/networking_common.go')
-rw-r--r--libpod/networking_common.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/libpod/networking_common.go b/libpod/networking_common.go
index a49a4c53c..8ff05b46a 100644
--- a/libpod/networking_common.go
+++ b/libpod/networking_common.go
@@ -40,3 +40,38 @@ func (c *Container) getNetworkOptions(networkOpts map[string]types.PerNetworkOpt
}
return opts
}
+
+// setUpNetwork will set up the the networks, on error it will also tear down the cni
+// networks. If rootless it will join/create the rootless network namespace.
+func (r *Runtime) setUpNetwork(ns string, opts types.NetworkOptions) (map[string]types.StatusBlock, error) {
+ rootlessNetNS, err := r.GetRootlessNetNs(true)
+ if err != nil {
+ return nil, err
+ }
+ var results map[string]types.StatusBlock
+ setUpPod := func() error {
+ results, err = r.network.Setup(ns, types.SetupOptions{NetworkOptions: opts})
+ return err
+ }
+ // rootlessNetNS is nil if we are root
+ if rootlessNetNS != nil {
+ // execute the setup in the rootless net ns
+ err = rootlessNetNS.Do(setUpPod)
+ rootlessNetNS.Lock.Unlock()
+ } else {
+ err = setUpPod()
+ }
+ return results, err
+}
+
+// getCNIPodName return the pod name (hostname) used by CNI and the dnsname plugin.
+// If we are in the pod network namespace use the pod name otherwise the container name
+func getCNIPodName(c *Container) string {
+ if c.config.NetMode.IsPod() || c.IsInfra() {
+ pod, err := c.runtime.state.Pod(c.PodID())
+ if err == nil {
+ return pod.Name()
+ }
+ }
+ return c.Name()
+}