@@ -19,6 +19,36 @@ import (
1919 "github.com/rootless-containers/rootlesskit/v2/pkg/network/iputils"
2020)
2121
22+ type Features struct {
23+ // Has `--host-lo-to-ns-lo` (introduced in passt 2024_10_30.ee7d0b6)
24+ // https://passt.top/passt/commit/?id=b4dace8f462b346ae2135af1f8d681a99a849a5f
25+ HasHostLoToNsLo bool
26+ }
27+
28+ func DetectFeatures (binary string ) (* Features , error ) {
29+ if binary == "" {
30+ return nil , errors .New ("got empty pasta binary" )
31+ }
32+ realBinary , err := exec .LookPath (binary )
33+ if err != nil {
34+ return nil , fmt .Errorf ("pasta binary %q is not installed: %w" , binary , err )
35+ }
36+ cmd := exec .Command (realBinary , "--version" )
37+ b , err := cmd .CombinedOutput ()
38+ if err != nil {
39+ return nil , fmt .Errorf (`command "%s --version" failed, make sure pasta is installed: %q: %w` ,
40+ realBinary , string (b ), err )
41+ }
42+ f := Features {
43+ HasHostLoToNsLo : false ,
44+ }
45+ cmd = exec .Command (realBinary , "--host-lo-to-ns-lo" , "--version" )
46+ if cmd .Run () == nil {
47+ f .HasHostLoToNsLo = true
48+ }
49+ return & f , nil
50+ }
51+
2252// NewParentDriver instantiates new parent driver.
2353func NewParentDriver (logWriter io.Writer , binary string , mtu int , ipnet * net.IPNet , ifname string ,
2454 disableHostLoopback , enableIPv6 , implicitPortForwarding bool ) (network.ParentDriver , error ) {
@@ -44,6 +74,11 @@ func NewParentDriver(logWriter io.Writer, binary string, mtu int, ipnet *net.IPN
4474 ifname = "tap0"
4575 }
4676
77+ feat , err := DetectFeatures (binary )
78+ if err != nil {
79+ return nil , err
80+ }
81+
4782 return & parentDriver {
4883 logWriter : logWriter ,
4984 binary : binary ,
@@ -53,6 +88,7 @@ func NewParentDriver(logWriter io.Writer, binary string, mtu int, ipnet *net.IPN
5388 enableIPv6 : enableIPv6 ,
5489 ifname : ifname ,
5590 implicitPortForwarding : implicitPortForwarding ,
91+ feat : feat ,
5692 }, nil
5793}
5894
@@ -67,6 +103,7 @@ type parentDriver struct {
67103 infoMu sync.RWMutex
68104 implicitPortForwarding bool
69105 info func () * api.NetworkDriverInfo
106+ feat * Features
70107}
71108
72109const DriverName = "pasta"
@@ -129,6 +166,15 @@ func (d *parentDriver) ConfigureNetwork(childPID int, stateDir, detachedNetNSPat
129166 opts = append (opts , "--tcp-ports=none" ,
130167 "--udp-ports=none" )
131168 }
169+ if d .feat != nil {
170+ if d .feat .HasHostLoToNsLo {
171+ // Needed to keep `docker run -p 127.0.0.1:8080:80` functional with
172+ // passt >= 2024_10_30.ee7d0b6
173+ //
174+ // https://github.com/rootless-containers/rootlesskit/pull/482#issuecomment-2591798590
175+ opts = append (opts , "--host-lo-to-ns-lo" )
176+ }
177+ }
132178 if detachedNetNSPath == "" {
133179 opts = append (opts , strconv .Itoa (childPID ))
134180 } else {
0 commit comments