Skip to content

Commit 7aef506

Browse files
authored
Merge pull request #482 from AkihiroSuda/dev2
pasta: set `--host-lo-to-ns-lo`; CI: update pasta
2 parents 0b4ed7b + 35080d8 commit 7aef506

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ARG UBUNTU_VERSION=24.04
33
ARG SHADOW_VERSION=4.16.0
44
ARG SLIRP4NETNS_VERSION=v1.3.1
55
ARG VPNKIT_VERSION=0.5.0
6-
ARG PASST_VERSION=2024_08_14.61c0b0d
6+
ARG PASST_VERSION=2024_12_11.09478d5
77
ARG DOCKER_VERSION=27.1.2
88
ARG DOCKER_CHANNEL=stable
99

pkg/network/pasta/pasta.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
2353
func 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

72109
const 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

Comments
 (0)