rootless-containers / slirp4netns

User-mode networking for unprivileged network namespaces
GNU General Public License v2.0
745 stars 83 forks source link

slirp4netns:outbound_addr= works for TCP but not UDP #282

Open rlpowell opened 2 years ago

rlpowell commented 2 years ago

I encountered this using podman; I don't use slirp4netns directly. This is copied verbatim from https://github.com/containers/podman/issues/13074 where it was closed as not a podman issue:

Description

My host's default IP is 192.168.123.137, but this routes weirdly, so for systems running as servers I need to use a different source IP, like so:

$ podman run --rm -it -p 8888:8888 -p 8888:8888/udp --network slirp4netns:outbound_addr=192.168.123.132 fedora:35 bash

When I do this and perform basic testing with nc (i.e. something like ncat -e /bin/cat -k -u -l 8888), then if it's TCP (the nc command does not have the -u), then the response packet comes out, correctly, with 192.168.123.132 as the source IP. With the -u (UDP), though, it comes out with 192.168.123.137 as the source IP

Describe the results you expected:

I expected slirp4netns:outbound_addr to work the same for both TCP and UDP

Output of podman version:

Version:      3.4.2
API Version:  3.4.2
Go Version:   go1.16.8
Built:        Sat Nov 13 16:16:48 2021
OS/Arch:      linux/amd64

Output of podman info --debug:

host:
  arch: amd64
  buildahVersion: 1.23.1
  cgroupControllers:
  - cpu
  - io
  - memory
  - pids
  cgroupManager: systemd
  cgroupVersion: v2
  conmon:
    package: conmon-2.0.30-2.fc34.x86_64
    path: /usr/bin/conmon
    version: 'conmon version 2.0.30, commit: '
  cpus: 24
  distribution:
    distribution: fedora
    version: "34"
  eventLogger: journald
  hostname: lebna
  idMappings:
    gidmap:
    - container_id: 0
      host_id: 1000
      size: 1
    - container_id: 1
      host_id: 65537000
      size: 65536
    uidmap:
    - container_id: 0
      host_id: 1000
      size: 1
    - container_id: 1
      host_id: 65537000
      size: 65536
  kernel: 5.14.9-200.fc34.x86_64
  linkmode: dynamic
  logDriver: k8s-file
  memFree: 2816819200
  memTotal: 33603751936
  ociRuntime:
    name: crun
    package: crun-1.0-1.fc34.x86_64
    path: /usr/bin/crun
    version: |-
      crun version 1.0
      commit: 139dc6971e2f1d931af520188763e984d6cdfbf8
      spec: 1.0.0
      +SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +CRIU +YAJL
  os: linux
  remoteSocket:
    path: /run/user/1000/podman/podman.sock
  security:
    apparmorEnabled: false
    capabilities: CAP_CHOWN,CAP_DAC_OVERRIDE,CAP_FOWNER,CAP_FSETID,CAP_KILL,CAP_NET_BIND_SERVICE,CAP_SETFCAP,CAP_SETGID,CAP_SETPCAP,CAP_SETUID,CAP_SYS_CHROOT
    rootless: true
    seccompEnabled: true
    seccompProfilePath: /usr/share/containers/seccomp.json
    selinuxEnabled: true
  serviceIsRemote: false
  slirp4netns:
    executable: /bin/slirp4netns
    package: slirp4netns-1.1.12-2.fc34.x86_64
    version: |-
      slirp4netns version 1.1.12
      commit: 7a104a101aa3278a2152351a082a6df71f57c9a3
      libslirp: 4.4.0
      SLIRP_CONFIG_VERSION_MAX: 3
      libseccomp: 2.5.0
  swapFree: 20606058496
  swapTotal: 25769795584
  uptime: 1594h 21m 0.44s (Approximately 66.42 days)
plugins:
  log:
  - k8s-file
  - none
  - journald
  network:
  - bridge
  - macvlan
  volume:
  - local
registries:
  search:
  - registry.fedoraproject.org
  - registry.access.redhat.com
  - docker.io
  - quay.io
store:
  configFile: /home/rlpowell/.config/containers/storage.conf
  containerStore:
    number: 1
    paused: 0
    running: 0
    stopped: 1
  graphDriverName: overlay
  graphOptions: {}
  graphRoot: /home/rlpowell/.local/share/containers/storage
  graphStatus:
    Backing Filesystem: xfs
    Native Overlay Diff: "true"
    Supports d_type: "true"
    Using metacopy: "false"
  imageStore:
    number: 3
  runRoot: /run/user/1000/containers
  volumePath: /home/rlpowell/.local/share/containers/storage/volumes
version:
  APIVersion: 3.4.2
  Built: 1636849008
  BuiltTime: Sat Nov 13 16:16:48 2021
  GitCommit: ""
  GoVersion: go1.16.8
  OsArch: linux/amd64
  Version: 3.4.2

Package info (e.g. output of rpm -q podman or apt list podman):

podman-3.4.2-1.fc34.x86_64

Have you tested with the latest version of Podman and have you checked the Podman Troubleshooting Guide? (https://github.com/containers/podman/blob/main/troubleshooting.md)

This is the latest version for my platform, and this issue is not mentioned in the troubleshooting guide.

rlpowell commented 2 years ago

Additional info:

In case it matters: --network slirp4netns:port_handler=slirp4netns,outbound_addr=192.168.123.132 also does not work.

$  rpm -q slirp4netns
slirp4netns-1.1.12-2.fc34.x86_64
AkihiroSuda commented 2 years ago

Perhaps an issue of libslirp ? https://gitlab.freedesktop.org/slirp/libslirp

rlpowell commented 2 years ago

https://gitlab.freedesktop.org/slirp/libslirp/-/issues/14 implies that this is working is libslirp, but I have no idea how to test that myself in the context of slirp4netns

rlpowell commented 2 years ago

Anyone able to confirm this?

PlugNPush commented 1 month ago

Is there any update on this issue?