aboutsummaryrefslogtreecommitdiff
path: root/pkg/namespaces/namespaces.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/namespaces/namespaces.go')
-rw-r--r--pkg/namespaces/namespaces.go26
1 files changed, 25 insertions, 1 deletions
diff --git a/pkg/namespaces/namespaces.go b/pkg/namespaces/namespaces.go
index 2ffbde977..b4ec04699 100644
--- a/pkg/namespaces/namespaces.go
+++ b/pkg/namespaces/namespaces.go
@@ -17,7 +17,9 @@ const (
nsType = "ns"
podType = "pod"
privateType = "private"
+ rlkFwdType = "port_handler=rootlesskit"
shareableType = "shareable"
+ slirpFwdType = "port_handler=slirp4netns"
slirpType = "slirp4netns"
)
@@ -385,7 +387,29 @@ func (n NetworkMode) IsBridge() bool {
// IsSlirp4netns indicates if we are running a rootless network stack
func (n NetworkMode) IsSlirp4netns() bool {
- return n == slirpType
+ return n == slirpType || strings.HasPrefix(string(n), slirpType+":")
+}
+
+// IsPortForwardViaRootlessKit indicates if we are doing rootless port-forwarding via rootlesskit/rootlessport
+func (n NetworkMode) IsPortForwardViaRootlessKit() bool {
+ if !n.IsSlirp4netns() {
+ return false
+ }
+ parts := strings.SplitN(string(n), ":", 2)
+ if len(parts) == 2 {
+ return parts[1] == rlkFwdType
+ }
+ return true
+}
+
+// IsPortForwardViaSlirpHostFwd indicates if we are doing rootless port-forwarding via slirp4netns add_hostfwd()
+func (n NetworkMode) IsPortForwardViaSlirpHostFwd() bool {
+ if !n.IsSlirp4netns() {
+ return false
+ }
+ // below here, implied IsSlirp4netns() == true
+ parts := strings.SplitN(string(n), ":", 2)
+ return len(parts) > 1 && parts[1] == slirpFwdType
}
// IsNS indicates a network namespace passed in by path (ns:<path>)