aboutsummaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container_internal_linux.go6
-rw-r--r--libpod/networking_linux.go37
-rw-r--r--libpod/reset.go17
3 files changed, 46 insertions, 14 deletions
diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go
index 5cc2a78fc..86d8586d0 100644
--- a/libpod/container_internal_linux.go
+++ b/libpod/container_internal_linux.go
@@ -510,6 +510,9 @@ func (c *Container) generateSpec(ctx context.Context) (*spec.Spec, error) {
if c.IsReadOnly() && dstPath != "/dev/shm" {
newMount.Options = append(newMount.Options, "ro", "nosuid", "noexec", "nodev")
}
+ if dstPath == "/dev/shm" && c.state.BindMounts["/dev/shm"] == c.config.ShmDir {
+ newMount.Options = append(newMount.Options, "nosuid", "noexec", "nodev")
+ }
if !MountExists(g.Mounts(), dstPath) {
g.AddMount(newMount)
} else {
@@ -1570,6 +1573,9 @@ func (c *Container) restore(ctx context.Context, options ContainerCheckpointOpti
if c.IsReadOnly() && dstPath != "/dev/shm" {
newMount.Options = append(newMount.Options, "ro", "nosuid", "noexec", "nodev")
}
+ if dstPath == "/dev/shm" && c.state.BindMounts["/dev/shm"] == c.config.ShmDir {
+ newMount.Options = append(newMount.Options, "nosuid", "noexec", "nodev")
+ }
if !MountExists(g.Mounts(), dstPath) {
g.AddMount(newMount)
}
diff --git a/libpod/networking_linux.go b/libpod/networking_linux.go
index f3707a77d..f490ac626 100644
--- a/libpod/networking_linux.go
+++ b/libpod/networking_linux.go
@@ -834,21 +834,25 @@ func (r *Runtime) teardownNetNS(ctr *Container) error {
return nil
}
-func getContainerNetNS(ctr *Container) (string, error) {
+func getContainerNetNS(ctr *Container) (string, *Container, error) {
if ctr.state.NetNS != nil {
- return ctr.state.NetNS.Path(), nil
+ return ctr.state.NetNS.Path(), nil, nil
}
if ctr.config.NetNsCtr != "" {
c, err := ctr.runtime.GetContainer(ctr.config.NetNsCtr)
if err != nil {
- return "", err
+ return "", nil, err
}
if err = c.syncContainer(); err != nil {
- return "", err
+ return "", c, err
}
- return getContainerNetNS(c)
+ netNs, c2, err := getContainerNetNS(c)
+ if c2 != nil {
+ c = c2
+ }
+ return netNs, c, err
}
- return "", nil
+ return "", nil, nil
}
// isBridgeNetMode checks if the given network mode is bridge.
@@ -919,12 +923,8 @@ func (r *Runtime) reloadContainerNetwork(ctr *Container) (map[string]types.Statu
func getContainerNetIO(ctr *Container) (*netlink.LinkStatistics, error) {
var netStats *netlink.LinkStatistics
- // With slirp4netns, we can't collect statistics at present.
- // For now, we allow stats to at least run by returning nil
- if rootless.IsRootless() || ctr.config.NetMode.IsSlirp4netns() {
- return netStats, nil
- }
- netNSPath, netPathErr := getContainerNetNS(ctr)
+
+ netNSPath, otherCtr, netPathErr := getContainerNetNS(ctr)
if netPathErr != nil {
return nil, netPathErr
}
@@ -933,9 +933,18 @@ func getContainerNetIO(ctr *Container) (*netlink.LinkStatistics, error) {
// this is a valid state and thus return no error, nor any statistics
return nil, nil
}
+
+ // FIXME get the interface from the container netstatus
+ dev := "eth0"
+ netMode := ctr.config.NetMode
+ if otherCtr != nil {
+ netMode = otherCtr.config.NetMode
+ }
+ if netMode.IsSlirp4netns() {
+ dev = "tap0"
+ }
err := ns.WithNetNSPath(netNSPath, func(_ ns.NetNS) error {
- // FIXME get the interface from the container netstatus
- link, err := netlink.LinkByName("eth0")
+ link, err := netlink.LinkByName(dev)
if err != nil {
return err
}
diff --git a/libpod/reset.go b/libpod/reset.go
index 2b2b586bc..28d0ee3f6 100644
--- a/libpod/reset.go
+++ b/libpod/reset.go
@@ -7,6 +7,7 @@ import (
"path/filepath"
"github.com/containers/common/libimage"
+ "github.com/containers/common/libnetwork/types"
"github.com/containers/podman/v4/libpod/define"
"github.com/containers/podman/v4/pkg/errorhandling"
"github.com/containers/podman/v4/pkg/rootless"
@@ -70,6 +71,22 @@ func (r *Runtime) Reset(ctx context.Context) error {
}
}
+ // remove all networks
+ nets, err := r.network.NetworkList()
+ if err != nil {
+ return err
+ }
+ for _, net := range nets {
+ // do not delete the default network
+ if net.Name == r.network.DefaultNetworkName() {
+ continue
+ }
+ // ignore not exists errors because of the TOCTOU problem
+ if err := r.network.NetworkRemove(net.Name); err != nil && !errors.Is(err, types.ErrNoSuchNetwork) {
+ logrus.Errorf("Removing network %s: %v", net.Name, err)
+ }
+ }
+
xdgRuntimeDir := filepath.Clean(os.Getenv("XDG_RUNTIME_DIR"))
_, prevError := r.store.Shutdown(true)
graphRoot := filepath.Clean(r.store.GraphRoot())