passt: Relicense to GPL 2.0, or any later version
In practical terms, passt doesn't benefit from the additional
protection offered by the AGPL over the GPL, because it's not
suitable to be executed over a computer network.
Further, restricting the distribution under the version 3 of the GPL
wouldn't provide any practical advantage either, as long as the passt
codebase is concerned, and might cause unnecessary compatibility
dilemmas.
Change licensing terms to the GNU General Public License Version 2,
or any later version, with written permission from all current and
past contributors, namely: myself, David Gibson, Laine Stump, Andrea
Bolognani, Paul Holzinger, Richard W.M. Jones, Chris Kuhn, Florian
Weimer, Giuseppe Scrivano, Stefan Hajnoczi, and Vasiliy Ulyanov.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2023-04-05 20:11:44 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2021-03-17 10:57:44 +01:00
|
|
|
|
|
|
|
/* PASST - Plug A Simple Socket Transport
|
passt: Add PASTA mode, major rework
PASTA (Pack A Subtle Tap Abstraction) provides quasi-native host
connectivity to an otherwise disconnected, unprivileged network
and user namespace, similarly to slirp4netns. Given that the
implementation is largely overlapping with PASST, no separate binary
is built: 'pasta' (and 'passt4netns' for clarity) both link to
'passt', and the mode of operation is selected depending on how the
binary is invoked. Usage example:
$ unshare -rUn
# echo $$
1871759
$ ./pasta 1871759 # From another terminal
# udhcpc -i pasta0 2>/dev/null
# ping -c1 pasta.pizza
PING pasta.pizza (64.190.62.111) 56(84) bytes of data.
64 bytes from 64.190.62.111 (64.190.62.111): icmp_seq=1 ttl=255 time=34.6 ms
--- pasta.pizza ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 34.575/34.575/34.575/0.000 ms
# ping -c1 spaghetti.pizza
PING spaghetti.pizza(2606:4700:3034::6815:147a (2606:4700:3034::6815:147a)) 56 data bytes
64 bytes from 2606:4700:3034::6815:147a (2606:4700:3034::6815:147a): icmp_seq=1 ttl=255 time=29.0 ms
--- spaghetti.pizza ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 28.967/28.967/28.967/0.000 ms
This entails a major rework, especially with regard to the storage of
tracked connections and to the semantics of epoll(7) references.
Indexing TCP and UDP bindings merely by socket proved to be
inflexible and unsuitable to handle different connection flows: pasta
also provides Layer-2 to Layer-2 socket mapping between init and a
separate namespace for local connections, using a pair of splice()
system calls for TCP, and a recvmmsg()/sendmmsg() pair for UDP local
bindings. For instance, building on the previous example:
# ip link set dev lo up
# iperf3 -s
$ iperf3 -c ::1 -Z -w 32M -l 1024k -P2 | tail -n4
[SUM] 0.00-10.00 sec 52.3 GBytes 44.9 Gbits/sec 283 sender
[SUM] 0.00-10.43 sec 52.3 GBytes 43.1 Gbits/sec receiver
iperf Done.
epoll(7) references now include a generic part in order to
demultiplex data to the relevant protocol handler, using 24
bits for the socket number, and an opaque portion reserved for
usage by the single protocol handlers, in order to track sockets
back to corresponding connections and bindings.
A number of fixes pertaining to TCP state machine and congestion
window handling are also included here.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2021-07-17 08:34:53 +02:00
|
|
|
* for qemu/UNIX domain socket mode
|
|
|
|
*
|
|
|
|
* PASTA - Pack A Subtle Tap Abstraction
|
|
|
|
* for network namespace/tap device mode
|
2021-03-17 10:57:44 +01:00
|
|
|
*
|
|
|
|
* icmp.c - ICMP/ICMPv6 echo proxy
|
|
|
|
*
|
|
|
|
* Copyright (c) 2021 Red Hat GmbH
|
|
|
|
* Author: Stefano Brivio <sbrivio@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <net/ethernet.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <netinet/in.h>
|
2021-10-21 04:26:08 +02:00
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/ip_icmp.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <limits.h>
|
2021-03-17 10:57:44 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/epoll.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2021-10-21 04:26:08 +02:00
|
|
|
#include <linux/icmpv6.h>
|
|
|
|
|
treewide: Packet abstraction with mandatory boundary checks
Implement a packet abstraction providing boundary and size checks
based on packet descriptors: packets stored in a buffer can be queued
into a pool (without storage of its own), and data can be retrieved
referring to an index in the pool, specifying offset and length.
Checks ensure data is not read outside the boundaries of buffer and
descriptors, and that packets added to a pool are within the buffer
range with valid offset and indices.
This implies a wider rework: usage of the "queueing" part of the
abstraction mostly affects tap_handler_{passt,pasta}() functions and
their callees, while the "fetching" part affects all the guest or tap
facing implementations: TCP, UDP, ICMP, ARP, NDP, DHCP and DHCPv6
handlers.
Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2022-03-25 13:02:47 +01:00
|
|
|
#include "packet.h"
|
passt: Add PASTA mode, major rework
PASTA (Pack A Subtle Tap Abstraction) provides quasi-native host
connectivity to an otherwise disconnected, unprivileged network
and user namespace, similarly to slirp4netns. Given that the
implementation is largely overlapping with PASST, no separate binary
is built: 'pasta' (and 'passt4netns' for clarity) both link to
'passt', and the mode of operation is selected depending on how the
binary is invoked. Usage example:
$ unshare -rUn
# echo $$
1871759
$ ./pasta 1871759 # From another terminal
# udhcpc -i pasta0 2>/dev/null
# ping -c1 pasta.pizza
PING pasta.pizza (64.190.62.111) 56(84) bytes of data.
64 bytes from 64.190.62.111 (64.190.62.111): icmp_seq=1 ttl=255 time=34.6 ms
--- pasta.pizza ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 34.575/34.575/34.575/0.000 ms
# ping -c1 spaghetti.pizza
PING spaghetti.pizza(2606:4700:3034::6815:147a (2606:4700:3034::6815:147a)) 56 data bytes
64 bytes from 2606:4700:3034::6815:147a (2606:4700:3034::6815:147a): icmp_seq=1 ttl=255 time=29.0 ms
--- spaghetti.pizza ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 28.967/28.967/28.967/0.000 ms
This entails a major rework, especially with regard to the storage of
tracked connections and to the semantics of epoll(7) references.
Indexing TCP and UDP bindings merely by socket proved to be
inflexible and unsuitable to handle different connection flows: pasta
also provides Layer-2 to Layer-2 socket mapping between init and a
separate namespace for local connections, using a pair of splice()
system calls for TCP, and a recvmmsg()/sendmmsg() pair for UDP local
bindings. For instance, building on the previous example:
# ip link set dev lo up
# iperf3 -s
$ iperf3 -c ::1 -Z -w 32M -l 1024k -P2 | tail -n4
[SUM] 0.00-10.00 sec 52.3 GBytes 44.9 Gbits/sec 283 sender
[SUM] 0.00-10.43 sec 52.3 GBytes 43.1 Gbits/sec receiver
iperf Done.
epoll(7) references now include a generic part in order to
demultiplex data to the relevant protocol handler, using 24
bits for the socket number, and an opaque portion reserved for
usage by the single protocol handlers, in order to track sockets
back to corresponding connections and bindings.
A number of fixes pertaining to TCP state machine and congestion
window handling are also included here.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2021-07-17 08:34:53 +02:00
|
|
|
#include "util.h"
|
2024-03-06 06:58:33 +01:00
|
|
|
#include "ip.h"
|
2021-03-17 10:57:44 +01:00
|
|
|
#include "passt.h"
|
|
|
|
#include "tap.h"
|
2022-09-24 09:53:15 +02:00
|
|
|
#include "log.h"
|
2024-02-28 12:25:04 +01:00
|
|
|
#include "siphash.h"
|
|
|
|
#include "inany.h"
|
2021-03-17 10:57:44 +01:00
|
|
|
#include "icmp.h"
|
2024-02-29 05:15:32 +01:00
|
|
|
#include "flow_table.h"
|
2021-03-17 10:57:44 +01:00
|
|
|
|
passt: Add PASTA mode, major rework
PASTA (Pack A Subtle Tap Abstraction) provides quasi-native host
connectivity to an otherwise disconnected, unprivileged network
and user namespace, similarly to slirp4netns. Given that the
implementation is largely overlapping with PASST, no separate binary
is built: 'pasta' (and 'passt4netns' for clarity) both link to
'passt', and the mode of operation is selected depending on how the
binary is invoked. Usage example:
$ unshare -rUn
# echo $$
1871759
$ ./pasta 1871759 # From another terminal
# udhcpc -i pasta0 2>/dev/null
# ping -c1 pasta.pizza
PING pasta.pizza (64.190.62.111) 56(84) bytes of data.
64 bytes from 64.190.62.111 (64.190.62.111): icmp_seq=1 ttl=255 time=34.6 ms
--- pasta.pizza ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 34.575/34.575/34.575/0.000 ms
# ping -c1 spaghetti.pizza
PING spaghetti.pizza(2606:4700:3034::6815:147a (2606:4700:3034::6815:147a)) 56 data bytes
64 bytes from 2606:4700:3034::6815:147a (2606:4700:3034::6815:147a): icmp_seq=1 ttl=255 time=29.0 ms
--- spaghetti.pizza ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 28.967/28.967/28.967/0.000 ms
This entails a major rework, especially with regard to the storage of
tracked connections and to the semantics of epoll(7) references.
Indexing TCP and UDP bindings merely by socket proved to be
inflexible and unsuitable to handle different connection flows: pasta
also provides Layer-2 to Layer-2 socket mapping between init and a
separate namespace for local connections, using a pair of splice()
system calls for TCP, and a recvmmsg()/sendmmsg() pair for UDP local
bindings. For instance, building on the previous example:
# ip link set dev lo up
# iperf3 -s
$ iperf3 -c ::1 -Z -w 32M -l 1024k -P2 | tail -n4
[SUM] 0.00-10.00 sec 52.3 GBytes 44.9 Gbits/sec 283 sender
[SUM] 0.00-10.43 sec 52.3 GBytes 43.1 Gbits/sec receiver
iperf Done.
epoll(7) references now include a generic part in order to
demultiplex data to the relevant protocol handler, using 24
bits for the socket number, and an opaque portion reserved for
usage by the single protocol handlers, in order to track sockets
back to corresponding connections and bindings.
A number of fixes pertaining to TCP state machine and congestion
window handling are also included here.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2021-07-17 08:34:53 +02:00
|
|
|
#define ICMP_ECHO_TIMEOUT 60 /* s, timeout for ICMP socket activity */
|
2022-09-24 11:08:23 +02:00
|
|
|
#define ICMP_NUM_IDS (1U << 16)
|
passt: Add PASTA mode, major rework
PASTA (Pack A Subtle Tap Abstraction) provides quasi-native host
connectivity to an otherwise disconnected, unprivileged network
and user namespace, similarly to slirp4netns. Given that the
implementation is largely overlapping with PASST, no separate binary
is built: 'pasta' (and 'passt4netns' for clarity) both link to
'passt', and the mode of operation is selected depending on how the
binary is invoked. Usage example:
$ unshare -rUn
# echo $$
1871759
$ ./pasta 1871759 # From another terminal
# udhcpc -i pasta0 2>/dev/null
# ping -c1 pasta.pizza
PING pasta.pizza (64.190.62.111) 56(84) bytes of data.
64 bytes from 64.190.62.111 (64.190.62.111): icmp_seq=1 ttl=255 time=34.6 ms
--- pasta.pizza ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 34.575/34.575/34.575/0.000 ms
# ping -c1 spaghetti.pizza
PING spaghetti.pizza(2606:4700:3034::6815:147a (2606:4700:3034::6815:147a)) 56 data bytes
64 bytes from 2606:4700:3034::6815:147a (2606:4700:3034::6815:147a): icmp_seq=1 ttl=255 time=29.0 ms
--- spaghetti.pizza ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 28.967/28.967/28.967/0.000 ms
This entails a major rework, especially with regard to the storage of
tracked connections and to the semantics of epoll(7) references.
Indexing TCP and UDP bindings merely by socket proved to be
inflexible and unsuitable to handle different connection flows: pasta
also provides Layer-2 to Layer-2 socket mapping between init and a
separate namespace for local connections, using a pair of splice()
system calls for TCP, and a recvmmsg()/sendmmsg() pair for UDP local
bindings. For instance, building on the previous example:
# ip link set dev lo up
# iperf3 -s
$ iperf3 -c ::1 -Z -w 32M -l 1024k -P2 | tail -n4
[SUM] 0.00-10.00 sec 52.3 GBytes 44.9 Gbits/sec 283 sender
[SUM] 0.00-10.43 sec 52.3 GBytes 43.1 Gbits/sec receiver
iperf Done.
epoll(7) references now include a generic part in order to
demultiplex data to the relevant protocol handler, using 24
bits for the socket number, and an opaque portion reserved for
usage by the single protocol handlers, in order to track sockets
back to corresponding connections and bindings.
A number of fixes pertaining to TCP state machine and congestion
window handling are also included here.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2021-07-17 08:34:53 +02:00
|
|
|
|
2024-07-17 06:52:18 +02:00
|
|
|
/**
|
|
|
|
* ping_at_sidx() - Get ping specific flow at given sidx
|
|
|
|
* @sidx: Flow and side to retrieve
|
|
|
|
*
|
|
|
|
* Return: ping specific flow at @sidx, or NULL of @sidx is invalid. Asserts if
|
|
|
|
* the flow at @sidx is not FLOW_PING4 or FLOW_PING6
|
|
|
|
*/
|
|
|
|
static struct icmp_ping_flow *ping_at_sidx(flow_sidx_t sidx)
|
|
|
|
{
|
|
|
|
union flow *flow = flow_at_sidx(sidx);
|
|
|
|
|
|
|
|
if (!flow)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ASSERT(flow->f.type == FLOW_PING4 || flow->f.type == FLOW_PING6);
|
|
|
|
return &flow->ping;
|
|
|
|
}
|
|
|
|
|
2021-03-17 10:57:44 +01:00
|
|
|
/**
|
2024-01-16 06:16:15 +01:00
|
|
|
* icmp_sock_handler() - Handle new data from ICMP or ICMPv6 socket
|
2021-03-17 10:57:44 +01:00
|
|
|
* @c: Execution context
|
passt: Add PASTA mode, major rework
PASTA (Pack A Subtle Tap Abstraction) provides quasi-native host
connectivity to an otherwise disconnected, unprivileged network
and user namespace, similarly to slirp4netns. Given that the
implementation is largely overlapping with PASST, no separate binary
is built: 'pasta' (and 'passt4netns' for clarity) both link to
'passt', and the mode of operation is selected depending on how the
binary is invoked. Usage example:
$ unshare -rUn
# echo $$
1871759
$ ./pasta 1871759 # From another terminal
# udhcpc -i pasta0 2>/dev/null
# ping -c1 pasta.pizza
PING pasta.pizza (64.190.62.111) 56(84) bytes of data.
64 bytes from 64.190.62.111 (64.190.62.111): icmp_seq=1 ttl=255 time=34.6 ms
--- pasta.pizza ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 34.575/34.575/34.575/0.000 ms
# ping -c1 spaghetti.pizza
PING spaghetti.pizza(2606:4700:3034::6815:147a (2606:4700:3034::6815:147a)) 56 data bytes
64 bytes from 2606:4700:3034::6815:147a (2606:4700:3034::6815:147a): icmp_seq=1 ttl=255 time=29.0 ms
--- spaghetti.pizza ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 28.967/28.967/28.967/0.000 ms
This entails a major rework, especially with regard to the storage of
tracked connections and to the semantics of epoll(7) references.
Indexing TCP and UDP bindings merely by socket proved to be
inflexible and unsuitable to handle different connection flows: pasta
also provides Layer-2 to Layer-2 socket mapping between init and a
separate namespace for local connections, using a pair of splice()
system calls for TCP, and a recvmmsg()/sendmmsg() pair for UDP local
bindings. For instance, building on the previous example:
# ip link set dev lo up
# iperf3 -s
$ iperf3 -c ::1 -Z -w 32M -l 1024k -P2 | tail -n4
[SUM] 0.00-10.00 sec 52.3 GBytes 44.9 Gbits/sec 283 sender
[SUM] 0.00-10.43 sec 52.3 GBytes 43.1 Gbits/sec receiver
iperf Done.
epoll(7) references now include a generic part in order to
demultiplex data to the relevant protocol handler, using 24
bits for the socket number, and an opaque portion reserved for
usage by the single protocol handlers, in order to track sockets
back to corresponding connections and bindings.
A number of fixes pertaining to TCP state machine and congestion
window handling are also included here.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2021-07-17 08:34:53 +02:00
|
|
|
* @ref: epoll reference
|
2021-03-17 10:57:44 +01:00
|
|
|
*/
|
2024-02-29 05:15:34 +01:00
|
|
|
void icmp_sock_handler(const struct ctx *c, union epoll_ref ref)
|
2021-03-17 10:57:44 +01:00
|
|
|
{
|
2024-07-17 06:52:18 +02:00
|
|
|
struct icmp_ping_flow *pingf = ping_at_sidx(ref.flowside);
|
2024-07-18 07:26:37 +02:00
|
|
|
const struct flowside *ini = &pingf->f.side[INISIDE];
|
2024-02-28 12:25:04 +01:00
|
|
|
union sockaddr_inany sr;
|
2023-08-11 07:12:24 +02:00
|
|
|
socklen_t sl = sizeof(sr);
|
2024-02-28 12:25:04 +01:00
|
|
|
char buf[USHRT_MAX];
|
2024-01-16 06:16:15 +01:00
|
|
|
uint16_t seq;
|
2021-03-17 10:57:44 +01:00
|
|
|
ssize_t n;
|
|
|
|
|
2023-08-11 07:12:24 +02:00
|
|
|
if (c->no_icmp)
|
|
|
|
return;
|
2021-03-17 10:57:44 +01:00
|
|
|
|
2024-02-29 05:15:32 +01:00
|
|
|
ASSERT(pingf);
|
|
|
|
|
2024-01-16 06:16:15 +01:00
|
|
|
n = recvfrom(ref.fd, buf, sizeof(buf), 0, &sr.sa, &sl);
|
2024-01-16 06:16:16 +01:00
|
|
|
if (n < 0) {
|
2024-02-29 05:15:33 +01:00
|
|
|
flow_err(pingf, "recvfrom() error: %s", strerror(errno));
|
2021-03-17 10:57:44 +01:00
|
|
|
return;
|
2024-01-16 06:16:16 +01:00
|
|
|
}
|
2021-03-17 10:57:44 +01:00
|
|
|
|
2024-02-29 05:15:34 +01:00
|
|
|
if (pingf->f.type == FLOW_PING4) {
|
2024-01-16 06:16:15 +01:00
|
|
|
struct icmphdr *ih4 = (struct icmphdr *)buf;
|
2021-07-26 15:26:36 +02:00
|
|
|
|
2024-02-29 05:15:34 +01:00
|
|
|
if (sr.sa_family != AF_INET || (size_t)n < sizeof(*ih4) ||
|
|
|
|
ih4->type != ICMP_ECHOREPLY)
|
2024-01-16 06:16:17 +01:00
|
|
|
goto unexpected;
|
|
|
|
|
2024-01-16 06:16:15 +01:00
|
|
|
/* Adjust packet back to guest-side ID */
|
2024-07-18 07:26:37 +02:00
|
|
|
ih4->un.echo.id = htons(ini->eport);
|
2024-01-16 06:16:15 +01:00
|
|
|
seq = ntohs(ih4->un.echo.sequence);
|
2024-02-29 05:15:34 +01:00
|
|
|
} else if (pingf->f.type == FLOW_PING6) {
|
2024-01-16 06:16:15 +01:00
|
|
|
struct icmp6hdr *ih6 = (struct icmp6hdr *)buf;
|
2021-07-26 15:26:36 +02:00
|
|
|
|
2024-02-29 05:15:34 +01:00
|
|
|
if (sr.sa_family != AF_INET6 || (size_t)n < sizeof(*ih6) ||
|
2024-01-16 06:16:17 +01:00
|
|
|
ih6->icmp6_type != ICMPV6_ECHO_REPLY)
|
|
|
|
goto unexpected;
|
|
|
|
|
2024-01-16 06:16:15 +01:00
|
|
|
/* Adjust packet back to guest-side ID */
|
2024-07-18 07:26:37 +02:00
|
|
|
ih6->icmp6_identifier = htons(ini->eport);
|
2024-01-16 06:16:15 +01:00
|
|
|
seq = ntohs(ih6->icmp6_sequence);
|
|
|
|
} else {
|
|
|
|
ASSERT(0);
|
2023-08-11 07:12:24 +02:00
|
|
|
}
|
passt: Add PASTA mode, major rework
PASTA (Pack A Subtle Tap Abstraction) provides quasi-native host
connectivity to an otherwise disconnected, unprivileged network
and user namespace, similarly to slirp4netns. Given that the
implementation is largely overlapping with PASST, no separate binary
is built: 'pasta' (and 'passt4netns' for clarity) both link to
'passt', and the mode of operation is selected depending on how the
binary is invoked. Usage example:
$ unshare -rUn
# echo $$
1871759
$ ./pasta 1871759 # From another terminal
# udhcpc -i pasta0 2>/dev/null
# ping -c1 pasta.pizza
PING pasta.pizza (64.190.62.111) 56(84) bytes of data.
64 bytes from 64.190.62.111 (64.190.62.111): icmp_seq=1 ttl=255 time=34.6 ms
--- pasta.pizza ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 34.575/34.575/34.575/0.000 ms
# ping -c1 spaghetti.pizza
PING spaghetti.pizza(2606:4700:3034::6815:147a (2606:4700:3034::6815:147a)) 56 data bytes
64 bytes from 2606:4700:3034::6815:147a (2606:4700:3034::6815:147a): icmp_seq=1 ttl=255 time=29.0 ms
--- spaghetti.pizza ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 28.967/28.967/28.967/0.000 ms
This entails a major rework, especially with regard to the storage of
tracked connections and to the semantics of epoll(7) references.
Indexing TCP and UDP bindings merely by socket proved to be
inflexible and unsuitable to handle different connection flows: pasta
also provides Layer-2 to Layer-2 socket mapping between init and a
separate namespace for local connections, using a pair of splice()
system calls for TCP, and a recvmmsg()/sendmmsg() pair for UDP local
bindings. For instance, building on the previous example:
# ip link set dev lo up
# iperf3 -s
$ iperf3 -c ::1 -Z -w 32M -l 1024k -P2 | tail -n4
[SUM] 0.00-10.00 sec 52.3 GBytes 44.9 Gbits/sec 283 sender
[SUM] 0.00-10.43 sec 52.3 GBytes 43.1 Gbits/sec receiver
iperf Done.
epoll(7) references now include a generic part in order to
demultiplex data to the relevant protocol handler, using 24
bits for the socket number, and an opaque portion reserved for
usage by the single protocol handlers, in order to track sockets
back to corresponding connections and bindings.
A number of fixes pertaining to TCP state machine and congestion
window handling are also included here.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2021-07-17 08:34:53 +02:00
|
|
|
|
2023-08-11 07:12:24 +02:00
|
|
|
/* In PASTA mode, we'll get any reply we send, discard them. */
|
|
|
|
if (c->mode == MODE_PASTA) {
|
2024-02-29 05:15:32 +01:00
|
|
|
if (pingf->seq == seq)
|
2023-08-11 07:12:24 +02:00
|
|
|
return;
|
2022-10-26 17:45:48 +02:00
|
|
|
|
2024-02-29 05:15:32 +01:00
|
|
|
pingf->seq = seq;
|
2021-03-17 10:57:44 +01:00
|
|
|
}
|
2023-08-11 07:12:24 +02:00
|
|
|
|
2024-02-29 05:15:33 +01:00
|
|
|
flow_dbg(pingf, "echo reply to tap, ID: %"PRIu16", seq: %"PRIu16,
|
2024-07-18 07:26:37 +02:00
|
|
|
ini->eport, seq);
|
2024-02-29 05:15:33 +01:00
|
|
|
|
2024-07-18 07:26:38 +02:00
|
|
|
if (pingf->f.type == FLOW_PING4) {
|
|
|
|
const struct in_addr *saddr = inany_v4(&ini->faddr);
|
|
|
|
const struct in_addr *daddr = inany_v4(&ini->eaddr);
|
|
|
|
|
|
|
|
ASSERT(saddr && daddr); /* Must have IPv4 addresses */
|
|
|
|
tap_icmp4_send(c, *saddr, *daddr, buf, n);
|
|
|
|
} else if (pingf->f.type == FLOW_PING6) {
|
|
|
|
const struct in6_addr *saddr = &ini->faddr.a6;
|
|
|
|
const struct in6_addr *daddr = &ini->eaddr.a6;
|
|
|
|
|
|
|
|
tap_icmp6_send(c, saddr, daddr, buf, n);
|
|
|
|
}
|
2024-01-16 06:16:17 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
unexpected:
|
2024-02-29 05:15:33 +01:00
|
|
|
flow_err(pingf, "Unexpected packet on ping socket");
|
2021-03-17 10:57:44 +01:00
|
|
|
}
|
|
|
|
|
2024-01-16 06:16:18 +01:00
|
|
|
/**
|
2024-02-29 05:15:32 +01:00
|
|
|
* icmp_ping_close() - Close and clean up a ping flow
|
2024-01-16 06:16:18 +01:00
|
|
|
* @c: Execution context
|
2024-02-29 05:15:32 +01:00
|
|
|
* @pingf: ping flow entry to close
|
2024-01-16 06:16:18 +01:00
|
|
|
*/
|
2024-02-29 05:15:32 +01:00
|
|
|
static void icmp_ping_close(const struct ctx *c,
|
|
|
|
const struct icmp_ping_flow *pingf)
|
2024-01-16 06:16:18 +01:00
|
|
|
{
|
2024-02-29 05:15:32 +01:00
|
|
|
epoll_ctl(c->epollfd, EPOLL_CTL_DEL, pingf->sock, NULL);
|
|
|
|
close(pingf->sock);
|
2024-07-18 07:26:39 +02:00
|
|
|
flow_hash_remove(c, FLOW_SIDX(pingf, INISIDE));
|
2024-01-16 06:16:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* icmp_ping_new() - Prepare a new ping socket for a new id
|
|
|
|
* @c: Execution context
|
|
|
|
* @af: Address family, AF_INET or AF_INET6
|
|
|
|
* @id: ICMP id for the new socket
|
2024-07-18 07:26:27 +02:00
|
|
|
* @saddr: Source address
|
|
|
|
* @daddr: Destination address
|
2024-01-16 06:16:18 +01:00
|
|
|
*
|
2024-02-29 05:15:32 +01:00
|
|
|
* Return: Newly opened ping flow, or NULL on failure
|
2024-01-16 06:16:18 +01:00
|
|
|
*/
|
2024-02-29 05:15:32 +01:00
|
|
|
static struct icmp_ping_flow *icmp_ping_new(const struct ctx *c,
|
2024-07-18 07:26:27 +02:00
|
|
|
sa_family_t af, uint16_t id,
|
|
|
|
const void *saddr, const void *daddr)
|
2024-01-16 06:16:18 +01:00
|
|
|
{
|
2024-02-29 05:15:32 +01:00
|
|
|
uint8_t flowtype = af == AF_INET ? FLOW_PING4 : FLOW_PING6;
|
2024-02-29 05:15:34 +01:00
|
|
|
union epoll_ref ref = { .type = EPOLL_TYPE_PING };
|
2024-02-29 05:15:32 +01:00
|
|
|
union flow *flow = flow_alloc();
|
|
|
|
struct icmp_ping_flow *pingf;
|
2024-01-16 06:16:18 +01:00
|
|
|
const void *bind_addr;
|
|
|
|
const char *bind_if;
|
2024-02-29 05:15:32 +01:00
|
|
|
|
|
|
|
if (!flow)
|
|
|
|
return NULL;
|
|
|
|
|
2024-07-18 07:26:27 +02:00
|
|
|
flow_initiate_af(flow, PIF_TAP, af, saddr, id, daddr, id);
|
2024-07-18 07:26:28 +02:00
|
|
|
/* FIXME: Record outbound source address when known */
|
|
|
|
flow_target_af(flow, PIF_HOST, af, NULL, 0, daddr, 0);
|
2024-05-21 07:57:06 +02:00
|
|
|
pingf = FLOW_SET_TYPE(flow, flowtype, ping);
|
2024-02-29 05:15:32 +01:00
|
|
|
|
|
|
|
pingf->seq = -1;
|
2024-01-16 06:16:18 +01:00
|
|
|
|
|
|
|
if (af == AF_INET) {
|
|
|
|
bind_addr = &c->ip4.addr_out;
|
|
|
|
bind_if = c->ip4.ifname_out;
|
|
|
|
} else {
|
|
|
|
bind_addr = &c->ip6.addr_out;
|
|
|
|
bind_if = c->ip6.ifname_out;
|
|
|
|
}
|
|
|
|
|
2024-05-21 07:57:06 +02:00
|
|
|
ref.flowside = FLOW_SIDX(flow, TGTSIDE);
|
2024-07-05 12:43:59 +02:00
|
|
|
pingf->sock = sock_l4(c, af, EPOLL_TYPE_PING, bind_addr, bind_if,
|
2024-02-29 05:15:34 +01:00
|
|
|
0, ref.data);
|
2024-01-16 06:16:18 +01:00
|
|
|
|
2024-02-29 05:15:32 +01:00
|
|
|
if (pingf->sock < 0) {
|
2024-01-16 06:16:18 +01:00
|
|
|
warn("Cannot open \"ping\" socket. You might need to:");
|
|
|
|
warn(" sysctl -w net.ipv4.ping_group_range=\"0 2147483647\"");
|
|
|
|
warn("...echo requests/replies will fail.");
|
|
|
|
goto cancel;
|
|
|
|
}
|
|
|
|
|
2024-02-29 05:15:32 +01:00
|
|
|
if (pingf->sock > FD_REF_MAX)
|
2024-01-16 06:16:18 +01:00
|
|
|
goto cancel;
|
|
|
|
|
2024-02-29 05:15:33 +01:00
|
|
|
flow_dbg(pingf, "new socket %i for echo ID %"PRIu16, pingf->sock, id);
|
2024-01-16 06:16:18 +01:00
|
|
|
|
2024-07-18 07:26:39 +02:00
|
|
|
flow_hash_insert(c, FLOW_SIDX(pingf, INISIDE));
|
2024-01-16 06:16:18 +01:00
|
|
|
|
2024-05-21 07:57:05 +02:00
|
|
|
FLOW_ACTIVATE(pingf);
|
|
|
|
|
2024-02-29 05:15:32 +01:00
|
|
|
return pingf;
|
2024-01-16 06:16:18 +01:00
|
|
|
|
|
|
|
cancel:
|
2024-02-29 05:15:32 +01:00
|
|
|
flow_alloc_cancel(flow);
|
|
|
|
return NULL;
|
2024-01-16 06:16:18 +01:00
|
|
|
}
|
|
|
|
|
2021-03-17 10:57:44 +01:00
|
|
|
/**
|
|
|
|
* icmp_tap_handler() - Handle packets from tap
|
|
|
|
* @c: Execution context
|
2023-11-07 02:40:16 +01:00
|
|
|
* @pif: pif on which the packet is arriving
|
2021-03-17 10:57:44 +01:00
|
|
|
* @af: Address family, AF_INET or AF_INET6
|
2023-08-22 07:29:53 +02:00
|
|
|
* @saddr: Source address
|
|
|
|
* @daddr: Destination address
|
treewide: Packet abstraction with mandatory boundary checks
Implement a packet abstraction providing boundary and size checks
based on packet descriptors: packets stored in a buffer can be queued
into a pool (without storage of its own), and data can be retrieved
referring to an index in the pool, specifying offset and length.
Checks ensure data is not read outside the boundaries of buffer and
descriptors, and that packets added to a pool are within the buffer
range with valid offset and indices.
This implies a wider rework: usage of the "queueing" part of the
abstraction mostly affects tap_handler_{passt,pasta}() functions and
their callees, while the "fetching" part affects all the guest or tap
facing implementations: TCP, UDP, ICMP, ARP, NDP, DHCP and DHCPv6
handlers.
Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2022-03-25 13:02:47 +01:00
|
|
|
* @p: Packet pool, single packet with ICMP/ICMPv6 header
|
passt: Add PASTA mode, major rework
PASTA (Pack A Subtle Tap Abstraction) provides quasi-native host
connectivity to an otherwise disconnected, unprivileged network
and user namespace, similarly to slirp4netns. Given that the
implementation is largely overlapping with PASST, no separate binary
is built: 'pasta' (and 'passt4netns' for clarity) both link to
'passt', and the mode of operation is selected depending on how the
binary is invoked. Usage example:
$ unshare -rUn
# echo $$
1871759
$ ./pasta 1871759 # From another terminal
# udhcpc -i pasta0 2>/dev/null
# ping -c1 pasta.pizza
PING pasta.pizza (64.190.62.111) 56(84) bytes of data.
64 bytes from 64.190.62.111 (64.190.62.111): icmp_seq=1 ttl=255 time=34.6 ms
--- pasta.pizza ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 34.575/34.575/34.575/0.000 ms
# ping -c1 spaghetti.pizza
PING spaghetti.pizza(2606:4700:3034::6815:147a (2606:4700:3034::6815:147a)) 56 data bytes
64 bytes from 2606:4700:3034::6815:147a (2606:4700:3034::6815:147a): icmp_seq=1 ttl=255 time=29.0 ms
--- spaghetti.pizza ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 28.967/28.967/28.967/0.000 ms
This entails a major rework, especially with regard to the storage of
tracked connections and to the semantics of epoll(7) references.
Indexing TCP and UDP bindings merely by socket proved to be
inflexible and unsuitable to handle different connection flows: pasta
also provides Layer-2 to Layer-2 socket mapping between init and a
separate namespace for local connections, using a pair of splice()
system calls for TCP, and a recvmmsg()/sendmmsg() pair for UDP local
bindings. For instance, building on the previous example:
# ip link set dev lo up
# iperf3 -s
$ iperf3 -c ::1 -Z -w 32M -l 1024k -P2 | tail -n4
[SUM] 0.00-10.00 sec 52.3 GBytes 44.9 Gbits/sec 283 sender
[SUM] 0.00-10.43 sec 52.3 GBytes 43.1 Gbits/sec receiver
iperf Done.
epoll(7) references now include a generic part in order to
demultiplex data to the relevant protocol handler, using 24
bits for the socket number, and an opaque portion reserved for
usage by the single protocol handlers, in order to track sockets
back to corresponding connections and bindings.
A number of fixes pertaining to TCP state machine and congestion
window handling are also included here.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2021-07-17 08:34:53 +02:00
|
|
|
* @now: Current timestamp
|
2021-04-22 13:39:36 +02:00
|
|
|
*
|
|
|
|
* Return: count of consumed packets (always 1, even if malformed)
|
2021-03-17 10:57:44 +01:00
|
|
|
*/
|
2024-02-19 08:56:46 +01:00
|
|
|
int icmp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
|
2023-08-22 07:29:53 +02:00
|
|
|
const void *saddr, const void *daddr,
|
2022-03-26 07:23:21 +01:00
|
|
|
const struct pool *p, const struct timespec *now)
|
2021-03-17 10:57:44 +01:00
|
|
|
{
|
2024-07-18 07:26:40 +02:00
|
|
|
struct icmp_ping_flow *pingf;
|
2024-07-18 07:26:38 +02:00
|
|
|
const struct flowside *tgt;
|
|
|
|
union sockaddr_inany sa;
|
2024-05-01 08:53:49 +02:00
|
|
|
size_t dlen, l4len;
|
2024-01-16 06:16:14 +01:00
|
|
|
uint16_t id, seq;
|
2024-07-18 07:26:39 +02:00
|
|
|
union flow *flow;
|
|
|
|
uint8_t proto;
|
2024-07-18 07:26:38 +02:00
|
|
|
socklen_t sl;
|
2024-01-16 06:16:14 +01:00
|
|
|
void *pkt;
|
2021-04-22 13:39:36 +02:00
|
|
|
|
2023-08-22 07:29:53 +02:00
|
|
|
(void)saddr;
|
2024-02-29 05:15:32 +01:00
|
|
|
ASSERT(pif == PIF_TAP);
|
2023-08-22 07:29:53 +02:00
|
|
|
|
2021-03-17 10:57:44 +01:00
|
|
|
if (af == AF_INET) {
|
2024-01-16 06:16:08 +01:00
|
|
|
const struct icmphdr *ih;
|
2021-03-17 10:57:44 +01:00
|
|
|
|
2024-05-01 08:53:49 +02:00
|
|
|
if (!(pkt = packet_get(p, 0, 0, sizeof(*ih), &dlen)))
|
2021-04-22 13:39:36 +02:00
|
|
|
return 1;
|
2021-03-17 10:57:44 +01:00
|
|
|
|
2024-01-16 06:16:14 +01:00
|
|
|
ih = (struct icmphdr *)pkt;
|
2024-05-01 08:53:49 +02:00
|
|
|
l4len = dlen + sizeof(*ih);
|
2024-01-16 06:16:14 +01:00
|
|
|
|
2024-01-16 06:16:10 +01:00
|
|
|
if (ih->type != ICMP_ECHO)
|
2022-04-05 07:10:30 +02:00
|
|
|
return 1;
|
|
|
|
|
2024-07-18 07:26:39 +02:00
|
|
|
proto = IPPROTO_ICMP;
|
2024-01-16 06:16:14 +01:00
|
|
|
id = ntohs(ih->un.echo.id);
|
|
|
|
seq = ntohs(ih->un.echo.sequence);
|
|
|
|
} else if (af == AF_INET6) {
|
|
|
|
const struct icmp6hdr *ih;
|
2021-03-17 10:57:44 +01:00
|
|
|
|
2024-05-01 08:53:49 +02:00
|
|
|
if (!(pkt = packet_get(p, 0, 0, sizeof(*ih), &dlen)))
|
2024-01-16 06:16:14 +01:00
|
|
|
return 1;
|
passt: Add PASTA mode, major rework
PASTA (Pack A Subtle Tap Abstraction) provides quasi-native host
connectivity to an otherwise disconnected, unprivileged network
and user namespace, similarly to slirp4netns. Given that the
implementation is largely overlapping with PASST, no separate binary
is built: 'pasta' (and 'passt4netns' for clarity) both link to
'passt', and the mode of operation is selected depending on how the
binary is invoked. Usage example:
$ unshare -rUn
# echo $$
1871759
$ ./pasta 1871759 # From another terminal
# udhcpc -i pasta0 2>/dev/null
# ping -c1 pasta.pizza
PING pasta.pizza (64.190.62.111) 56(84) bytes of data.
64 bytes from 64.190.62.111 (64.190.62.111): icmp_seq=1 ttl=255 time=34.6 ms
--- pasta.pizza ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 34.575/34.575/34.575/0.000 ms
# ping -c1 spaghetti.pizza
PING spaghetti.pizza(2606:4700:3034::6815:147a (2606:4700:3034::6815:147a)) 56 data bytes
64 bytes from 2606:4700:3034::6815:147a (2606:4700:3034::6815:147a): icmp_seq=1 ttl=255 time=29.0 ms
--- spaghetti.pizza ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 28.967/28.967/28.967/0.000 ms
This entails a major rework, especially with regard to the storage of
tracked connections and to the semantics of epoll(7) references.
Indexing TCP and UDP bindings merely by socket proved to be
inflexible and unsuitable to handle different connection flows: pasta
also provides Layer-2 to Layer-2 socket mapping between init and a
separate namespace for local connections, using a pair of splice()
system calls for TCP, and a recvmmsg()/sendmmsg() pair for UDP local
bindings. For instance, building on the previous example:
# ip link set dev lo up
# iperf3 -s
$ iperf3 -c ::1 -Z -w 32M -l 1024k -P2 | tail -n4
[SUM] 0.00-10.00 sec 52.3 GBytes 44.9 Gbits/sec 283 sender
[SUM] 0.00-10.43 sec 52.3 GBytes 43.1 Gbits/sec receiver
iperf Done.
epoll(7) references now include a generic part in order to
demultiplex data to the relevant protocol handler, using 24
bits for the socket number, and an opaque portion reserved for
usage by the single protocol handlers, in order to track sockets
back to corresponding connections and bindings.
A number of fixes pertaining to TCP state machine and congestion
window handling are also included here.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2021-07-17 08:34:53 +02:00
|
|
|
|
2024-01-16 06:16:14 +01:00
|
|
|
ih = (struct icmp6hdr *)pkt;
|
2024-05-01 08:53:49 +02:00
|
|
|
l4len = dlen + sizeof(*ih);
|
2022-10-26 17:45:48 +02:00
|
|
|
|
2024-01-16 06:16:14 +01:00
|
|
|
if (ih->icmp6_type != ICMPV6_ECHO_REQUEST)
|
|
|
|
return 1;
|
|
|
|
|
2024-07-18 07:26:39 +02:00
|
|
|
proto = IPPROTO_ICMPV6;
|
2024-01-16 06:16:14 +01:00
|
|
|
id = ntohs(ih->icmp6_identifier);
|
|
|
|
seq = ntohs(ih->icmp6_sequence);
|
|
|
|
} else {
|
|
|
|
ASSERT(0);
|
|
|
|
}
|
2021-05-21 11:14:53 +02:00
|
|
|
|
2024-07-18 07:26:39 +02:00
|
|
|
flow = flow_at_sidx(flow_lookup_af(c, proto, PIF_TAP,
|
|
|
|
af, saddr, daddr, id, id));
|
|
|
|
|
|
|
|
if (flow)
|
|
|
|
pingf = &flow->ping;
|
2024-07-18 07:26:40 +02:00
|
|
|
else if (!(pingf = icmp_ping_new(c, af, id, saddr, daddr)))
|
2024-07-18 07:26:39 +02:00
|
|
|
return 1;
|
2021-04-22 13:39:36 +02:00
|
|
|
|
2024-07-18 07:26:38 +02:00
|
|
|
tgt = &pingf->f.side[TGTSIDE];
|
2024-07-18 07:26:39 +02:00
|
|
|
|
|
|
|
ASSERT(flow_proto[pingf->f.type] == proto);
|
2024-02-29 05:15:32 +01:00
|
|
|
pingf->ts = now->tv_sec;
|
2024-01-16 06:16:14 +01:00
|
|
|
|
2024-07-18 07:26:38 +02:00
|
|
|
pif_sockaddr(c, &sa, &sl, PIF_HOST, &tgt->eaddr, 0);
|
2024-05-01 08:53:49 +02:00
|
|
|
if (sendto(pingf->sock, pkt, l4len, MSG_NOSIGNAL, &sa.sa, sl) < 0) {
|
2024-02-29 05:15:33 +01:00
|
|
|
flow_dbg(pingf, "failed to relay request to socket: %s",
|
|
|
|
strerror(errno));
|
2024-01-16 06:16:14 +01:00
|
|
|
} else {
|
2024-02-29 05:15:33 +01:00
|
|
|
flow_dbg(pingf,
|
|
|
|
"echo request to socket, ID: %"PRIu16", seq: %"PRIu16,
|
|
|
|
id, seq);
|
2024-01-16 06:16:14 +01:00
|
|
|
}
|
passt: Add PASTA mode, major rework
PASTA (Pack A Subtle Tap Abstraction) provides quasi-native host
connectivity to an otherwise disconnected, unprivileged network
and user namespace, similarly to slirp4netns. Given that the
implementation is largely overlapping with PASST, no separate binary
is built: 'pasta' (and 'passt4netns' for clarity) both link to
'passt', and the mode of operation is selected depending on how the
binary is invoked. Usage example:
$ unshare -rUn
# echo $$
1871759
$ ./pasta 1871759 # From another terminal
# udhcpc -i pasta0 2>/dev/null
# ping -c1 pasta.pizza
PING pasta.pizza (64.190.62.111) 56(84) bytes of data.
64 bytes from 64.190.62.111 (64.190.62.111): icmp_seq=1 ttl=255 time=34.6 ms
--- pasta.pizza ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 34.575/34.575/34.575/0.000 ms
# ping -c1 spaghetti.pizza
PING spaghetti.pizza(2606:4700:3034::6815:147a (2606:4700:3034::6815:147a)) 56 data bytes
64 bytes from 2606:4700:3034::6815:147a (2606:4700:3034::6815:147a): icmp_seq=1 ttl=255 time=29.0 ms
--- spaghetti.pizza ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 28.967/28.967/28.967/0.000 ms
This entails a major rework, especially with regard to the storage of
tracked connections and to the semantics of epoll(7) references.
Indexing TCP and UDP bindings merely by socket proved to be
inflexible and unsuitable to handle different connection flows: pasta
also provides Layer-2 to Layer-2 socket mapping between init and a
separate namespace for local connections, using a pair of splice()
system calls for TCP, and a recvmmsg()/sendmmsg() pair for UDP local
bindings. For instance, building on the previous example:
# ip link set dev lo up
# iperf3 -s
$ iperf3 -c ::1 -Z -w 32M -l 1024k -P2 | tail -n4
[SUM] 0.00-10.00 sec 52.3 GBytes 44.9 Gbits/sec 283 sender
[SUM] 0.00-10.43 sec 52.3 GBytes 43.1 Gbits/sec receiver
iperf Done.
epoll(7) references now include a generic part in order to
demultiplex data to the relevant protocol handler, using 24
bits for the socket number, and an opaque portion reserved for
usage by the single protocol handlers, in order to track sockets
back to corresponding connections and bindings.
A number of fixes pertaining to TCP state machine and congestion
window handling are also included here.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2021-07-17 08:34:53 +02:00
|
|
|
|
|
|
|
return 1;
|
2021-03-17 10:57:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-02-29 05:15:32 +01:00
|
|
|
* icmp_ping_timer() - Handler for timed events related to a given flow
|
passt: Add PASTA mode, major rework
PASTA (Pack A Subtle Tap Abstraction) provides quasi-native host
connectivity to an otherwise disconnected, unprivileged network
and user namespace, similarly to slirp4netns. Given that the
implementation is largely overlapping with PASST, no separate binary
is built: 'pasta' (and 'passt4netns' for clarity) both link to
'passt', and the mode of operation is selected depending on how the
binary is invoked. Usage example:
$ unshare -rUn
# echo $$
1871759
$ ./pasta 1871759 # From another terminal
# udhcpc -i pasta0 2>/dev/null
# ping -c1 pasta.pizza
PING pasta.pizza (64.190.62.111) 56(84) bytes of data.
64 bytes from 64.190.62.111 (64.190.62.111): icmp_seq=1 ttl=255 time=34.6 ms
--- pasta.pizza ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 34.575/34.575/34.575/0.000 ms
# ping -c1 spaghetti.pizza
PING spaghetti.pizza(2606:4700:3034::6815:147a (2606:4700:3034::6815:147a)) 56 data bytes
64 bytes from 2606:4700:3034::6815:147a (2606:4700:3034::6815:147a): icmp_seq=1 ttl=255 time=29.0 ms
--- spaghetti.pizza ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 28.967/28.967/28.967/0.000 ms
This entails a major rework, especially with regard to the storage of
tracked connections and to the semantics of epoll(7) references.
Indexing TCP and UDP bindings merely by socket proved to be
inflexible and unsuitable to handle different connection flows: pasta
also provides Layer-2 to Layer-2 socket mapping between init and a
separate namespace for local connections, using a pair of splice()
system calls for TCP, and a recvmmsg()/sendmmsg() pair for UDP local
bindings. For instance, building on the previous example:
# ip link set dev lo up
# iperf3 -s
$ iperf3 -c ::1 -Z -w 32M -l 1024k -P2 | tail -n4
[SUM] 0.00-10.00 sec 52.3 GBytes 44.9 Gbits/sec 283 sender
[SUM] 0.00-10.43 sec 52.3 GBytes 43.1 Gbits/sec receiver
iperf Done.
epoll(7) references now include a generic part in order to
demultiplex data to the relevant protocol handler, using 24
bits for the socket number, and an opaque portion reserved for
usage by the single protocol handlers, in order to track sockets
back to corresponding connections and bindings.
A number of fixes pertaining to TCP state machine and congestion
window handling are also included here.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2021-07-17 08:34:53 +02:00
|
|
|
* @c: Execution context
|
2024-05-21 07:57:03 +02:00
|
|
|
* @pingf: Ping flow to check for timeout
|
2024-01-16 01:50:32 +01:00
|
|
|
* @now: Current timestamp
|
2024-02-29 05:15:32 +01:00
|
|
|
*
|
|
|
|
* Return: true if the flow is ready to free, false otherwise
|
passt: Add PASTA mode, major rework
PASTA (Pack A Subtle Tap Abstraction) provides quasi-native host
connectivity to an otherwise disconnected, unprivileged network
and user namespace, similarly to slirp4netns. Given that the
implementation is largely overlapping with PASST, no separate binary
is built: 'pasta' (and 'passt4netns' for clarity) both link to
'passt', and the mode of operation is selected depending on how the
binary is invoked. Usage example:
$ unshare -rUn
# echo $$
1871759
$ ./pasta 1871759 # From another terminal
# udhcpc -i pasta0 2>/dev/null
# ping -c1 pasta.pizza
PING pasta.pizza (64.190.62.111) 56(84) bytes of data.
64 bytes from 64.190.62.111 (64.190.62.111): icmp_seq=1 ttl=255 time=34.6 ms
--- pasta.pizza ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 34.575/34.575/34.575/0.000 ms
# ping -c1 spaghetti.pizza
PING spaghetti.pizza(2606:4700:3034::6815:147a (2606:4700:3034::6815:147a)) 56 data bytes
64 bytes from 2606:4700:3034::6815:147a (2606:4700:3034::6815:147a): icmp_seq=1 ttl=255 time=29.0 ms
--- spaghetti.pizza ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 28.967/28.967/28.967/0.000 ms
This entails a major rework, especially with regard to the storage of
tracked connections and to the semantics of epoll(7) references.
Indexing TCP and UDP bindings merely by socket proved to be
inflexible and unsuitable to handle different connection flows: pasta
also provides Layer-2 to Layer-2 socket mapping between init and a
separate namespace for local connections, using a pair of splice()
system calls for TCP, and a recvmmsg()/sendmmsg() pair for UDP local
bindings. For instance, building on the previous example:
# ip link set dev lo up
# iperf3 -s
$ iperf3 -c ::1 -Z -w 32M -l 1024k -P2 | tail -n4
[SUM] 0.00-10.00 sec 52.3 GBytes 44.9 Gbits/sec 283 sender
[SUM] 0.00-10.43 sec 52.3 GBytes 43.1 Gbits/sec receiver
iperf Done.
epoll(7) references now include a generic part in order to
demultiplex data to the relevant protocol handler, using 24
bits for the socket number, and an opaque portion reserved for
usage by the single protocol handlers, in order to track sockets
back to corresponding connections and bindings.
A number of fixes pertaining to TCP state machine and congestion
window handling are also included here.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2021-07-17 08:34:53 +02:00
|
|
|
*/
|
2024-05-21 07:57:03 +02:00
|
|
|
bool icmp_ping_timer(const struct ctx *c, const struct icmp_ping_flow *pingf,
|
2024-02-29 05:15:32 +01:00
|
|
|
const struct timespec *now)
|
passt: Add PASTA mode, major rework
PASTA (Pack A Subtle Tap Abstraction) provides quasi-native host
connectivity to an otherwise disconnected, unprivileged network
and user namespace, similarly to slirp4netns. Given that the
implementation is largely overlapping with PASST, no separate binary
is built: 'pasta' (and 'passt4netns' for clarity) both link to
'passt', and the mode of operation is selected depending on how the
binary is invoked. Usage example:
$ unshare -rUn
# echo $$
1871759
$ ./pasta 1871759 # From another terminal
# udhcpc -i pasta0 2>/dev/null
# ping -c1 pasta.pizza
PING pasta.pizza (64.190.62.111) 56(84) bytes of data.
64 bytes from 64.190.62.111 (64.190.62.111): icmp_seq=1 ttl=255 time=34.6 ms
--- pasta.pizza ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 34.575/34.575/34.575/0.000 ms
# ping -c1 spaghetti.pizza
PING spaghetti.pizza(2606:4700:3034::6815:147a (2606:4700:3034::6815:147a)) 56 data bytes
64 bytes from 2606:4700:3034::6815:147a (2606:4700:3034::6815:147a): icmp_seq=1 ttl=255 time=29.0 ms
--- spaghetti.pizza ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 28.967/28.967/28.967/0.000 ms
This entails a major rework, especially with regard to the storage of
tracked connections and to the semantics of epoll(7) references.
Indexing TCP and UDP bindings merely by socket proved to be
inflexible and unsuitable to handle different connection flows: pasta
also provides Layer-2 to Layer-2 socket mapping between init and a
separate namespace for local connections, using a pair of splice()
system calls for TCP, and a recvmmsg()/sendmmsg() pair for UDP local
bindings. For instance, building on the previous example:
# ip link set dev lo up
# iperf3 -s
$ iperf3 -c ::1 -Z -w 32M -l 1024k -P2 | tail -n4
[SUM] 0.00-10.00 sec 52.3 GBytes 44.9 Gbits/sec 283 sender
[SUM] 0.00-10.43 sec 52.3 GBytes 43.1 Gbits/sec receiver
iperf Done.
epoll(7) references now include a generic part in order to
demultiplex data to the relevant protocol handler, using 24
bits for the socket number, and an opaque portion reserved for
usage by the single protocol handlers, in order to track sockets
back to corresponding connections and bindings.
A number of fixes pertaining to TCP state machine and congestion
window handling are also included here.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2021-07-17 08:34:53 +02:00
|
|
|
{
|
2024-02-29 05:15:32 +01:00
|
|
|
if (now->tv_sec - pingf->ts <= ICMP_ECHO_TIMEOUT)
|
|
|
|
return false;
|
2022-10-26 17:55:53 +02:00
|
|
|
|
2024-02-29 05:15:32 +01:00
|
|
|
icmp_ping_close(c, pingf);
|
|
|
|
return true;
|
2022-10-26 17:55:53 +02:00
|
|
|
}
|