summaryrefslogtreecommitdiff
path: root/internal/namespace/ops.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/namespace/ops.go')
-rw-r--r--internal/namespace/ops.go80
1 files changed, 80 insertions, 0 deletions
diff --git a/internal/namespace/ops.go b/internal/namespace/ops.go
new file mode 100644
index 0000000..b2b5e10
--- /dev/null
+++ b/internal/namespace/ops.go
@@ -0,0 +1,80 @@
+package namespace
+
+import (
+ "os"
+
+ "git.theodohertyfamily.com/wg-wrap/internal/paths"
+)
+
+// Ops defines the set of operations required by the Manager to handle
+// namespace isolation, lifecycle, and synchronization.
+type Ops interface {
+ IsIsolated() bool
+ Bootstrap() error
+ BootstrapJoin(pid int) error
+ RegisterProcess(pm *paths.PathManager, profile string) error
+ UnregisterProcess(pm *paths.PathManager, profile string) error
+ PruneStalePids(pm *paths.PathManager, profile string) error
+ IsLastProcess(pm *paths.PathManager, profile string) (bool, error)
+ PinNamespace(pm *paths.PathManager, profile string) error
+ UnpinNamespace(pm *paths.PathManager, profile string) error
+ FindActiveProfilePid(pm *paths.PathManager, profile string) (int, error)
+ AcquireProfileLock(pm *paths.PathManager, profile string) (*os.File, error)
+ ReleaseProfileLock(file *os.File)
+}
+
+// linuxOps is the concrete implementation of Ops for Linux systems.
+type linuxOps struct{}
+
+// NewLinuxOps returns a new instance of the Linux-specific namespace operations.
+func NewLinuxOps() Ops {
+ return &linuxOps{}
+}
+
+func (l *linuxOps) IsIsolated() bool {
+ return IsIsolated()
+}
+
+func (l *linuxOps) Bootstrap() error {
+ return Bootstrap()
+}
+
+func (l *linuxOps) BootstrapJoin(pid int) error {
+ return BootstrapJoin(pid)
+}
+
+func (l *linuxOps) RegisterProcess(pm *paths.PathManager, profile string) error {
+ return RegisterProcess(pm, profile)
+}
+
+func (l *linuxOps) UnregisterProcess(pm *paths.PathManager, profile string) error {
+ return UnregisterProcess(pm, profile)
+}
+
+func (l *linuxOps) PruneStalePids(pm *paths.PathManager, profile string) error {
+ return PruneStalePids(pm, profile)
+}
+
+func (l *linuxOps) IsLastProcess(pm *paths.PathManager, profile string) (bool, error) {
+ return IsLastProcess(pm, profile)
+}
+
+func (l *linuxOps) PinNamespace(pm *paths.PathManager, profile string) error {
+ return PinNamespace(pm, profile)
+}
+
+func (l *linuxOps) UnpinNamespace(pm *paths.PathManager, profile string) error {
+ return UnpinNamespace(pm, profile)
+}
+
+func (l *linuxOps) FindActiveProfilePid(pm *paths.PathManager, profile string) (int, error) {
+ return FindActiveProfilePid(pm, profile)
+}
+
+func (l *linuxOps) AcquireProfileLock(pm *paths.PathManager, profile string) (*os.File, error) {
+ return AcquireProfileLock(pm, profile)
+}
+
+func (l *linuxOps) ReleaseProfileLock(file *os.File) {
+ ReleaseProfileLock(file)
+}