No description
Find a file
Stefano Brivio c11277b94f conf: Don't pass leading ~ to parse_port_range() on exclusions
Commit 84fec4e998 ("Clean up parsing of port ranges") drops the
strspn() call before the parsing of excluded port ranges, because now
we're checking against any stray characters at every step.

However, that also has the effect of passing ~ as first character to
the new parse_port_range(), which makes no sense: we already checked
that ~ is the first character before the call, so skip it.

Alona reported this output:
  Invalid port specifier ~15000,~15001,~15006,~15008,~15020,~15021,~15090

while the whole specifier is indeed valid.

Reported-by: Alona Paz <alkaplan@redhat.com>
Fixes: 84fec4e998 ("Clean up parsing of port ranges")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2022-10-24 14:37:22 +02:00
contrib conf, log, Makefile: Add versioning information 2022-10-15 02:10:28 +02:00
doc doc/demo: Clone and use mbuto in init namespace 2022-09-22 16:53:35 +02:00
hooks hooks/pre_push: Fix upload of CI's logs and terminal capture file 2022-09-24 00:01:39 +02:00
LICENSES LICENSES: Add license text files, add missing notices, fix SPDX tags 2021-10-20 08:29:30 +02:00
test test: Move slower tests to end of test run 2022-10-15 02:10:36 +02:00
.gitignore test: Move pidfiles and nsholder sockets into state directory 2022-09-13 11:12:41 +02:00
.gitpublish Add git-publish configuration file 2022-10-22 03:45:50 +02:00
arch.c cppcheck: Reduce scope of some variables 2022-09-29 12:22:01 +02:00
arch.h treewide: Add include guards 2022-03-29 15:35:38 +02:00
arp.c tap: Remove unhelpeful vnet_pre optimization from tap_send() 2022-10-19 03:34:43 +02:00
arp.h treewide: Mark constant references as const 2022-03-29 15:35:38 +02:00
checksum.c Remove support for TCP packets from tap_ip_send() 2022-10-19 03:34:40 +02:00
checksum.h Remove support for TCP packets from tap_ip_send() 2022-10-19 03:34:40 +02:00
conf.c conf: Don't pass leading ~ to parse_port_range() on exclusions 2022-10-24 14:37:22 +02:00
conf.h treewide: Add include guards 2022-03-29 15:35:38 +02:00
dhcp.c dhcp: Use tap_udp4_send() helper in dhcp() 2022-10-19 03:35:00 +02:00
dhcp.h treewide: Mark constant references as const 2022-03-29 15:35:38 +02:00
dhcpv6.c tap: Split tap_ip6_send() into UDP and ICMP variants 2022-10-19 03:34:48 +02:00
dhcpv6.h treewide: Mark constant references as const 2022-03-29 15:35:38 +02:00
icmp.c tap: Split tap_ip4_send() into UDP and ICMP variants 2022-10-19 03:34:56 +02:00
icmp.h treewide: Mark constant references as const 2022-03-29 15:35:38 +02:00
igmp.c Mark unused functions for cppcheck 2022-09-29 12:23:03 +02:00
isolation.c isolation: Only configure UID/GID mappings in userns when spawning shell 2022-10-15 02:10:36 +02:00
isolation.h isolation: Replace drop_caps() with a version that actually does something 2022-10-15 02:10:36 +02:00
lineread.c Add cleaner line-by-line reading primitives 2022-07-06 08:10:55 +02:00
lineread.h Add cleaner line-by-line reading primitives 2022-07-06 08:10:55 +02:00
log.c conf, log, Makefile: Add versioning information 2022-10-15 02:10:28 +02:00
log.h log.h: Avoid unnecessary GNU extension for token pasting 2022-10-15 02:10:36 +02:00
Makefile conf, log, Makefile: Add versioning information 2022-10-15 02:10:28 +02:00
mld.c passt: Fix build with gcc 7, use std=c99, enable some more Clang checkers 2021-10-21 04:26:08 +02:00
ndp.c ndp: Use tap_icmp6_send() helper 2022-10-19 03:34:53 +02:00
ndp.h ndp: Remove unneeded eh_source parameter 2022-10-19 03:34:51 +02:00
netlink.c conf: Bind inbound ports with CAP_NET_BIND_SERVICE before isolate_user() 2022-10-15 02:10:36 +02:00
netlink.h conf: Bind inbound ports with CAP_NET_BIND_SERVICE before isolate_user() 2022-10-15 02:10:36 +02:00
packet.c packet: Fix off-by-one in packet_get_do() sanity checks 2022-10-15 02:10:36 +02:00
packet.h tcp: Silence warning from gcc 11.3 with -Ofast 2022-06-08 11:08:29 +02:00
passt.1 passt.1: Add David to AUTHORS 2022-10-15 02:10:36 +02:00
passt.c isolation: Clarify various self-isolation steps 2022-10-15 02:10:36 +02:00
passt.h conf, tap: Add option to quit once the client closes the connection 2022-10-15 02:10:36 +02:00
pasta.c Rename pasta_setup_ns() to pasta_spawn_cmd() 2022-10-15 02:10:36 +02:00
pasta.h isolation: Only configure UID/GID mappings in userns when spawning shell 2022-10-15 02:10:36 +02:00
pcap.c Move logging functions to a new file, log.c 2022-10-14 17:38:25 +02:00
pcap.h treewide: Mark constant references as const 2022-03-29 15:35:38 +02:00
port_fwd.h Fix widespread off-by-one error dealing with port numbers 2022-09-24 14:48:35 +02:00
qrap.1 qrap.1: Clarify it takes a qemu command, not a path 2022-05-19 15:23:53 +02:00
qrap.c qrap: Support JSON syntax for -device 2022-10-21 11:43:45 +02:00
README.md log, conf: Add support for logging to file 2022-10-14 17:38:28 +02:00
seccomp.sh cppcheck: Avoid errors due to zeroes in bitwise ORs 2022-09-29 12:22:37 +02:00
siphash.c Mark unused functions for cppcheck 2022-09-29 12:23:03 +02:00
siphash.h treewide: Add include guards 2022-03-29 15:35:38 +02:00
slirp4netns.sh podman, slirp4netns.sh: Use --netns option on pasta's command line 2022-08-30 19:43:31 +02:00
tap.c dhcp: Use tap_udp4_send() helper in dhcp() 2022-10-19 03:35:00 +02:00
tap.h tap: Split tap_ip4_send() into UDP and ICMP variants 2022-10-19 03:34:56 +02:00
tcp.c Don't create 'tap' socket for ports that are bound to loopback only 2022-10-15 02:10:36 +02:00
tcp.h tcp, tcp_splice: Fix port remapping for inbound, spliced connections 2022-10-15 02:10:36 +02:00
tcp_splice.c tcp, tcp_splice: Fix port remapping for inbound, spliced connections 2022-10-15 02:10:36 +02:00
tcp_splice.h treewide: Add include guards 2022-03-29 15:35:38 +02:00
udp.c udp: Fix port and address checks for DNS forwarder 2022-10-15 02:10:36 +02:00
udp.h conf, tcp, udp: Allow specification of interface to bind to 2022-10-15 02:10:36 +02:00
util.c Replace FWRITE with a function 2022-10-15 02:10:36 +02:00
util.h util: Set NS_FN_STACK_SIZE to one eighth of ulimit-reported maximum stack size 2022-10-22 08:46:57 +02:00

passt: Plug A Simple Socket Transport

passt implements a translation layer between a Layer-2 network interface and native Layer-4 sockets (TCP, UDP, ICMP/ICMPv6 echo) on a host. It doesn't require any capabilities or privileges, and it can be used as a simple replacement for Slirp.

Overview diagram of passt

pasta: Pack A Subtle Tap Abstraction

pasta (same binary as passt, different command) offers equivalent functionality, for network namespaces: traffic is forwarded using a tap interface inside the namespace, without the need to create further interfaces on the host, hence not requiring any capabilities or privileges.

It also implements a tap bypass path for local connections: packets with a local destination address are moved directly between Layer-4 sockets, avoiding Layer-2 translations, using the splice(2) and recvmmsg(2)/sendmmsg(2) system calls for TCP and UDP, respectively.

Overview diagram of pasta

See also the man page.

Motivation

passt

When container workloads are moved to virtual machines, the network traffic is typically forwarded by interfaces operating at data link level. Some components in the containers ecosystem (such as service meshes), however, expect applications to run locally, with visible sockets and processes, for the purposes of socket redirection, monitoring, port mapping.

To solve this issue, user mode networking, as provided e.g. by libslirp, can be used. Existing solutions implement a full TCP/IP stack, replaying traffic on sockets that are local to the pod of the service mesh. This creates the illusion of application processes running on the same host, eventually separated by user namespaces.

While being almost transparent to the service mesh infrastructure, that kind of solution comes with a number of downsides:

  • three different TCP/IP stacks (guest, adaptation and host) need to be traversed for every service request
  • addressing needs to be coordinated to create the pretense of consistent addresses and routes between guest and host environments. This typically needs a NAT with masquerading, or some form of packet bridging
  • the traffic seen by the service mesh and observable externally is a distant replica of the packets forwarded to and from the guest environment:
    • TCP congestion windows and network buffering mechanisms in general operate differently from what would be naturally expected by the application
    • protocols carrying addressing information might pose additional challenges, as the applications don't see the same set of addresses and routes as they would if deployed with regular containers

passt implements a thinner layer between guest and host, that only implements what's strictly needed to pretend processes are running locally. The TCP adaptation doesn't keep per-connection packet buffers, and reflects observed sending windows and acknowledgements between the two sides. This TCP adaptation is needed as passt runs without the CAP_NET_RAW capability: it can't create raw IP sockets on the pod, and therefore needs to map packets at Layer-2 to Layer-4 sockets offered by the host kernel.

See also a detailed illustration of the problem and what lead to this approach.

pasta

On Linux, regular users can create network namespaces and run application services inside them. However, connecting namespaces to other namespaces and to external hosts requires the creation of network interfaces, such as veth pairs, which needs in turn elevated privileges or the CAP_NET_ADMIN capability. pasta, similarly to slirp4netns, solves this problem by creating a tap interface available to processes in the namespace, and mapping network traffic outside the namespace using native Layer-4 sockets.

Existing approaches typically implement a full, generic TCP/IP stack for this translation between data and transport layers, without the possibility of speeding up local connections, and usually requiring NAT. pasta:

  • avoids the need for a generic, full-fledged TCP/IP stack by coordinating TCP connection dynamics between sender and receiver
  • offers a fast bypass path for local connections: if a process connects to another process on the same host across namespaces, data is directly forwarded using pairs of Layer-4 sockets
  • with default options, maps routing and addressing information to the namespace, avoiding any need for NAT

Features

: done/supported, : out of scope, 🛠: in progress/being considered : nice-to-have, eventually

Protocols

  • IPv4
    • all features, except for
    • fragmentation
  • IPv6
    • all features, except for
    • fragmentation
    • jumbograms
  • TCP
  • UDP
  • ICMP/ICMPv6 Echo
  • IGMP/MLD proxy
  • SCTP

Portability

Security

  • no dynamic memory allocation (sbrk(2), brk(2), mmap(2) blocked via seccomp)
  • root operation not allowed outside user namespaces
  • all capabilities dropped, other than CAP_NET_BIND_SERVICE (if granted)
  • with default options, user, mount, IPC, UTS, PID namespaces are detached
  • no external dependencies (other than a standard C library)
  • restrictive seccomp profiles (30 syscalls allowed for passt, 41 for pasta on x86_64)
  • examples of AppArmor and SELinux profiles available
  • static checkers in continuous integration (clang-tidy, cppcheck)
  • clearly defined boundary-checked packet abstraction
  • 🛠️ ~5 000 LoC target
  • fuzzing, packetdrill tests
  • stricter synflood protection
  • 💡 add your ideas

Configurability

  • all addresses, ports, port ranges
  • optional NAT, not required
  • all protocols
  • pasta: auto-detection of bound ports
  • 🛠 run-time configuration of port ranges without autodetection
  • 🛠 configuration of port ranges for autodetection
  • 💡 add your ideas

Performance

  • maximum two (cache hot) copies on every data path
  • pasta: zero-copy for local connections by design (no configuration needed)
  • generalised coalescing and batching on every path for every supported protocol
  • 4 to 50 times IPv4 TCP throughput of existing, conceptually similar solutions depending on MTU (UDP and IPv6 hard to compare)
  • 🛠 vhost-user support for maximum one copy on every data path and lower request-response latency
  • multithreading
  • raw IP socket support if CAP_NET_RAW is granted
  • eBPF support (might not improve performance over vhost-user)

Interfaces

  • qemu, libvirt support with qrap wrapper
  • out-of-tree patches for qemu and libvirt available
  • bug-to-bug compatible slirp4netns replacement (rootless Podman, RootlessKit)
  • out-of-tree patch for Podman available
  • out-of-tree patch for Kata Containers available
  • 🛠 native qemu, libvirt support
  • 🛠 native Podman integration
  • drop-in replacement for VPNKit (rootless Docker)

Availability

  • official packages for Fedora
  • unofficial packages for CentOS Stream, EPEL, Mageia
  • unofficial packages from x86_64 static builds for other RPM-based distributions and Debian
  • testing on non-x86_64 architectures (aarch64, armv7l, i386, ppc64, ppc64le, s390x)
  • example Debian package files
  • 🛠 official openSUSE packages
  • official packages for Debian (RFP), Arch Linux

Services

  • built-in ARP proxy
  • minimalistic DHCP server
  • minimalistic NDP proxy with router advertisements and SLAAC support
  • minimalistic DHCPv6 server
  • fine-grained configurability of DHCP, NDP, DHCPv6 options

Interfaces and Environment

passt exchanges packets with qemu via UNIX domain socket, using the socket back-end in qemu. Currently, qemu can only connect to a listening process via TCP. Two temporary solutions are available:

  • a patch for qemu
  • a wrapper, qrap, that connects to a UNIX domain socket and starts qemu, which can now use the file descriptor that's already opened

This approach, compared to using a tap device, doesn't require any security capabilities, as we don't need to create any interface.

pasta runs out of the box with any recent (post-3.8) Linux kernel.

Services

passt and pasta provide some minimalistic implementations of networking services:

  • ARP proxy, that resolves the address of the host (which is used as gateway) to the original MAC address of the host
  • DHCP server, a simple implementation handing out one single IPv4 address to the guest or namespace, namely, the same address as the first one configured for the upstream host interface, and passing the nameservers configured on the host
  • NDP proxy, which can also assign prefix and nameserver using SLAAC
  • DHCPv6 server: a simple implementation handing out one single IPv6 address to the guest or namespace, namely, the the same address as the first one configured for the upstream host interface, and passing the nameservers configured on the host

Addresses

For IPv4, the guest or namespace is assigned, via DHCP, the same address as the upstream interface of the host, and the same default gateway as the default gateway of the host. Addresses are translated in case the guest is seen using a different address from the assigned one.

For IPv6, the guest or namespace is assigned, via SLAAC, the same prefix as the upstream interface of the host, the same default route as the default route of the host, and, if a DHCPv6 client is running in the guest or namespace, also the same address as the upstream address of the host. This means that, with a DHCPv6 client in the guest or namespace, addresses don't need to be translated. Should the client use a different address, the destination address is translated for packets going to the guest or to the namespace.

Local connections with passt

For UDP and TCP, for both IPv4 and IPv6, packets from the host addressed to a loopback address are forwarded to the guest with their source address changed to the address of the gateway or first hop of the default route. This mapping is reversed on the other way.

Local connections with pasta

Packets addressed to a loopback address in either namespace are directly forwarded to the corresponding (or configured) port in the other namespace. Similarly as passt, packets from the non-init namespace addressed to the default gateway, which are therefore sent via the tap device, will have their destination address translated to the loopback address.

Protocols

passt and pasta support TCP, UDP and ICMP/ICMPv6 echo (requests and replies). More details about the TCP implementation are described in the theory of operation, and similarly for UDP.

An IGMP/MLD proxy is currently work in progress.

Ports

passt

To avoid the need for explicit port mapping configuration, passt can bind to all unbound non-ephemeral (0-49152) TCP and UDP ports. Binding to low ports (0-1023) will fail without additional capabilities, and ports already bound (service proxies, etc.) will also not be used. Smaller subsets of ports, with port translations, are also configurable.

UDP ephemeral ports are bound dynamically, as the guest uses them.

If all ports are forwarded, service proxies and other services running in the container need to be started before passt starts.

pasta

With default options, pasta scans for bound ports on init and non-init namespaces, and automatically forwards them from the other side. Port forwarding is fully configurable with command line options.

Demo

pasta

passt

Continuous Integration

See also the test logs.

Performance

Try it

passt

  • build from source:

      git clone https://passt.top/passt
      cd passt
      make
    
  • have a look at the man page for synopsis and options:

      man ./passt.1
    
  • run the demo script, that detaches user and network namespaces, configures the new network namespace using pasta, starts passt and, optionally, qemu:

      doc/demo.sh
    
  • alternatively, you can use libvirt, with this patch, to start qemu (with these patches), and this kind of network interface configuration:

      <interface type='client'>
        <mac address='52:54:00:02:6b:60'/>
        <source path='/tmp/passt.socket'/>
        <model type='virtio'/>
        <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
      </interface>
    
  • and that's it, you should now have TCP connections, UDP, and ICMP/ICMPv6 echo working from/to the guest for IPv4 and IPv6

  • to connect to a service on the VM, just connect to the same port directly with the address of the current network namespace

pasta

  • build from source:

      git clone https://passt.top/passt
      cd passt
      make
    
  • have a look at the man page for synopsis and options:

      man ./pasta.1
    
  • start pasta with:

      ./pasta
    
  • you're now inside a new user and network namespace. For IPv6, SLAAC happens right away as pasta sets up the interface, but DHCPv6 support is available as well. For IPv4, configure the interface with a DHCP client:

      dhclient
    

    and, optionally:

      dhclient -6
    
    • alternatively, start pasta as:

        ./pasta --config-net
      

      to let pasta configure networking in the namespace by itself, using netlink

    • ...or run the demo script:

        doc/demo.sh
      
  • and that's it, you should now have TCP connections, UDP, and ICMP/ICMPv6 echo working from/to the namespace for IPv4 and IPv6

  • to connect to a service inside the namespace, just connect to the same port using the loopback address.

Contribute

Mailing Lists

  • Submit, review patches, and discuss development ideas on passt-dev

  • Ask your questions and discuss usage needs on passt-user

Bug Reports and Feature Requests

Chat

  • Somebody might be available on IRC

Security and Vulnerability Reports

  • Please send an email to passt-sec, private list, no subscription required