Skip to content

Commit 0509e94

Browse files
committed
common: remove slirp4netns references
Also rename systemd.MoveRootlessNetnsSlirpProcessToUserSlice to systemd.MoveRootlessNetnsProcessToUserSlice. Signed-off-by: Lokesh Mandvekar <[email protected]>
1 parent 90dc316 commit 0509e94

File tree

2 files changed

+8
-74
lines changed

2 files changed

+8
-74
lines changed

common/libnetwork/internal/rootlessnetns/netns_linux.go

Lines changed: 6 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"errors"
66
"fmt"
77
"io/fs"
8-
"net"
98
"os"
109
"path/filepath"
1110
"strconv"
@@ -18,7 +17,6 @@ import (
1817
"github.com/sirupsen/logrus"
1918
"go.podman.io/common/libnetwork/pasta"
2019
"go.podman.io/common/libnetwork/resolvconf"
21-
"go.podman.io/common/libnetwork/slirp4netns"
2220
"go.podman.io/common/libnetwork/types"
2321
"go.podman.io/common/pkg/config"
2422
"go.podman.io/common/pkg/netns"
@@ -38,7 +36,7 @@ const (
3836
// infoCacheFile file name for the cache file used to store the rootless netns info.
3937
infoCacheFile = "info.json"
4038

41-
// rootlessNetNsConnPidFile is the name of the rootless netns slirp4netns/pasta pid file.
39+
// rootlessNetNsConnPidFile is the name of the rootless netns pasta pid file.
4240
rootlessNetNsConnPidFile = "rootless-netns-conn.pid"
4341

4442
// persistentCNIDir is the directory where the CNI files are stored.
@@ -114,7 +112,7 @@ func (n *Netns) getOrCreateNetns() (ns.NetNS, bool, error) {
114112
pidPath := n.getPath(rootlessNetNsConnPidFile)
115113
pid, err := readPidFile(pidPath)
116114
if err == nil {
117-
// quick check if pasta/slirp4netns are still running
115+
// quick check if pasta are still running
118116
err := unix.Kill(pid, 0)
119117
if err == nil {
120118
if err := n.deserializeInfo(); err != nil {
@@ -156,14 +154,12 @@ func (n *Netns) getOrCreateNetns() (ns.NetNS, bool, error) {
156154
}
157155
}
158156
switch strings.ToLower(n.config.Network.DefaultRootlessNetworkCmd) {
159-
case "", slirp4netns.BinaryName:
160-
err = n.setupSlirp4netns(nsPath)
161-
case pasta.BinaryName:
157+
case "", pasta.BinaryName:
162158
err = n.setupPasta(nsPath)
163159
default:
164160
err = fmt.Errorf("invalid rootless network command %q", n.config.Network.DefaultRootlessNetworkCmd)
165161
}
166-
// If pasta or slirp4netns fail here we need to get rid of the netns again to not leak it,
162+
// If pasta fails here we need to get rid of the netns again to not leak it,
167163
// otherwise the next command thinks the netns was successfully setup.
168164
if err != nil {
169165
if nerr := netns.UnmountNS(nsPath); nerr != nil {
@@ -222,7 +218,7 @@ func (n *Netns) setupPasta(nsPath string) error {
222218
return fmt.Errorf("unable to decode pasta PID: %w", err)
223219
}
224220

225-
if err := systemd.MoveRootlessNetnsSlirpProcessToUserSlice(pid); err != nil {
221+
if err := systemd.MoveRootlessNetnsProcessToUserSlice(pid); err != nil {
226222
// only log this, it is not fatal but can lead to issues when running podman inside systemd units
227223
logrus.Errorf("failed to move the rootless netns pasta process to the systemd user.slice: %v", err)
228224
}
@@ -253,68 +249,6 @@ func (n *Netns) setupPasta(nsPath string) error {
253249
return nil
254250
}
255251

256-
func (n *Netns) setupSlirp4netns(nsPath string) error {
257-
res, err := slirp4netns.Setup(&slirp4netns.SetupOptions{
258-
Config: n.config,
259-
ContainerID: "rootless-netns",
260-
Netns: nsPath,
261-
})
262-
if err != nil {
263-
return wrapError("start slirp4netns", err)
264-
}
265-
// create pid file for the slirp4netns process
266-
// this is need to kill the process in the cleanup
267-
pid := strconv.Itoa(res.Pid)
268-
err = os.WriteFile(n.getPath(rootlessNetNsConnPidFile), []byte(pid), 0o600)
269-
if err != nil {
270-
return wrapError("write slirp4netns pid file", err)
271-
}
272-
273-
if systemd.RunsOnSystemd() {
274-
// move to systemd scope to prevent systemd from killing it
275-
err = systemd.MoveRootlessNetnsSlirpProcessToUserSlice(res.Pid)
276-
if err != nil {
277-
// only log this, it is not fatal but can lead to issues when running podman inside systemd units
278-
logrus.Errorf("failed to move the rootless netns slirp4netns process to the systemd user.slice: %v", err)
279-
}
280-
}
281-
282-
// build a new resolv.conf file which uses the slirp4netns dns server address
283-
resolveIP, err := slirp4netns.GetDNS(res.Subnet)
284-
if err != nil {
285-
return wrapError("determine default slirp4netns DNS address", err)
286-
}
287-
nameservers := []string{resolveIP.String()}
288-
289-
netnsIP, err := slirp4netns.GetIP(res.Subnet)
290-
if err != nil {
291-
return wrapError("determine default slirp4netns ip address", err)
292-
}
293-
294-
if err := resolvconf.New(&resolvconf.Params{
295-
Path: n.getPath(resolvConfName),
296-
// fake the netns since we want to filter localhost
297-
Namespaces: []specs.LinuxNamespace{
298-
{Type: specs.NetworkNamespace},
299-
},
300-
IPv6Enabled: res.IPv6,
301-
KeepHostServers: true,
302-
Nameservers: nameservers,
303-
}); err != nil {
304-
return wrapError("create resolv.conf", err)
305-
}
306-
307-
n.info = &types.RootlessNetnsInfo{
308-
IPAddresses: []net.IP{*netnsIP},
309-
DnsForwardIps: nameservers,
310-
}
311-
if err := n.serializeInfo(); err != nil {
312-
return wrapError("serialize info", err)
313-
}
314-
315-
return nil
316-
}
317-
318252
func (n *Netns) cleanupRootlessNetns() error {
319253
pidFile := n.getPath(rootlessNetNsConnPidFile)
320254
pid, err := readPidFile(pidFile)
@@ -324,7 +258,7 @@ func (n *Netns) cleanupRootlessNetns() error {
324258
return nil
325259
}
326260
if err == nil {
327-
// kill the slirp/pasta process so we do not leak it
261+
// kill the pasta process so we do not leak it
328262
err = unix.Kill(pid, unix.SIGTERM)
329263
if err == unix.ESRCH {
330264
err = nil

common/pkg/systemd/systemd_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ func moveProcessToScope(pid int, slice, scope string) error {
5858
return err
5959
}
6060

61-
// MoveRootlessNetnsSlirpProcessToUserSlice moves the slirp4netns process for the rootless netns
61+
// MoveRootlessNetnsProcessToUserSlice moves the process for the rootless netns
6262
// into a different scope so that systemd does not kill it with a container.
63-
func MoveRootlessNetnsSlirpProcessToUserSlice(pid int) error {
63+
func MoveRootlessNetnsProcessToUserSlice(pid int) error {
6464
randBytes := make([]byte, 4)
6565
_, err := rand.Read(randBytes)
6666
if err != nil {

0 commit comments

Comments
 (0)