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 18:11:44 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2021-03-17 09:57:44 +00: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 06:34:53 +00:00
|
|
|
* for qemu/UNIX domain socket mode
|
|
|
|
*
|
|
|
|
* PASTA - Pack A Subtle Tap Abstraction
|
|
|
|
* for network namespace/tap device mode
|
2021-03-17 09:57:44 +00: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 02:26:08 +00:00
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/ip_icmp.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <limits.h>
|
2021-03-17 09:57:44 +00: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 02:26:08 +00: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 12:02:47 +00: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 06:34:53 +00:00
|
|
|
#include "util.h"
|
2024-03-06 05:58:33 +00:00
|
|
|
#include "ip.h"
|
2021-03-17 09:57:44 +00:00
|
|
|
#include "passt.h"
|
|
|
|
#include "tap.h"
|
2022-09-24 07:53:15 +00:00
|
|
|
#include "log.h"
|
2024-02-28 11:25:04 +00:00
|
|
|
#include "siphash.h"
|
|
|
|
#include "inany.h"
|
2021-03-17 09:57:44 +00:00
|
|
|
#include "icmp.h"
|
2024-02-29 04:15:32 +00:00
|
|
|
#include "flow_table.h"
|
2021-03-17 09:57:44 +00: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 06:34:53 +00:00
|
|
|
#define ICMP_ECHO_TIMEOUT 60 /* s, timeout for ICMP socket activity */
|
2022-09-24 09:08:23 +00: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 06:34:53 +00:00
|
|
|
|
2021-05-21 09:14:50 +00:00
|
|
|
/* Indexed by ICMP echo identifier */
|
2024-02-29 04:15:32 +00:00
|
|
|
static struct icmp_ping_flow *icmp_id_map[IP_VERSIONS][ICMP_NUM_IDS];
|
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 06:34:53 +00:00
|
|
|
|
2024-07-17 04:52:18 +00: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 09:57:44 +00:00
|
|
|
/**
|
2024-01-16 05:16:15 +00:00
|
|
|
* icmp_sock_handler() - Handle new data from ICMP or ICMPv6 socket
|
2021-03-17 09:57:44 +00: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 06:34:53 +00:00
|
|
|
* @ref: epoll reference
|
2021-03-17 09:57:44 +00:00
|
|
|
*/
|
2024-02-29 04:15:34 +00:00
|
|
|
void icmp_sock_handler(const struct ctx *c, union epoll_ref ref)
|
2021-03-17 09:57:44 +00:00
|
|
|
{
|
2024-07-17 04:52:18 +00:00
|
|
|
struct icmp_ping_flow *pingf = ping_at_sidx(ref.flowside);
|
2024-02-28 11:25:04 +00:00
|
|
|
union sockaddr_inany sr;
|
2023-08-11 05:12:24 +00:00
|
|
|
socklen_t sl = sizeof(sr);
|
2024-02-28 11:25:04 +00:00
|
|
|
char buf[USHRT_MAX];
|
2024-01-16 05:16:15 +00:00
|
|
|
uint16_t seq;
|
2021-03-17 09:57:44 +00:00
|
|
|
ssize_t n;
|
|
|
|
|
2023-08-11 05:12:24 +00:00
|
|
|
if (c->no_icmp)
|
|
|
|
return;
|
2021-03-17 09:57:44 +00:00
|
|
|
|
2024-02-29 04:15:32 +00:00
|
|
|
ASSERT(pingf);
|
|
|
|
|
2024-01-16 05:16:15 +00:00
|
|
|
n = recvfrom(ref.fd, buf, sizeof(buf), 0, &sr.sa, &sl);
|
2024-01-16 05:16:16 +00:00
|
|
|
if (n < 0) {
|
2024-02-29 04:15:33 +00:00
|
|
|
flow_err(pingf, "recvfrom() error: %s", strerror(errno));
|
2021-03-17 09:57:44 +00:00
|
|
|
return;
|
2024-01-16 05:16:16 +00:00
|
|
|
}
|
2021-03-17 09:57:44 +00:00
|
|
|
|
2024-02-29 04:15:34 +00:00
|
|
|
if (pingf->f.type == FLOW_PING4) {
|
2024-01-16 05:16:15 +00:00
|
|
|
struct icmphdr *ih4 = (struct icmphdr *)buf;
|
2021-07-26 13:26:36 +00:00
|
|
|
|
2024-02-29 04:15:34 +00:00
|
|
|
if (sr.sa_family != AF_INET || (size_t)n < sizeof(*ih4) ||
|
|
|
|
ih4->type != ICMP_ECHOREPLY)
|
2024-01-16 05:16:17 +00:00
|
|
|
goto unexpected;
|
|
|
|
|
2024-01-16 05:16:15 +00:00
|
|
|
/* Adjust packet back to guest-side ID */
|
2024-02-29 04:15:34 +00:00
|
|
|
ih4->un.echo.id = htons(pingf->id);
|
2024-01-16 05:16:15 +00:00
|
|
|
seq = ntohs(ih4->un.echo.sequence);
|
2024-02-29 04:15:34 +00:00
|
|
|
} else if (pingf->f.type == FLOW_PING6) {
|
2024-01-16 05:16:15 +00:00
|
|
|
struct icmp6hdr *ih6 = (struct icmp6hdr *)buf;
|
2021-07-26 13:26:36 +00:00
|
|
|
|
2024-02-29 04:15:34 +00:00
|
|
|
if (sr.sa_family != AF_INET6 || (size_t)n < sizeof(*ih6) ||
|
2024-01-16 05:16:17 +00:00
|
|
|
ih6->icmp6_type != ICMPV6_ECHO_REPLY)
|
|
|
|
goto unexpected;
|
|
|
|
|
2024-01-16 05:16:15 +00:00
|
|
|
/* Adjust packet back to guest-side ID */
|
2024-02-29 04:15:34 +00:00
|
|
|
ih6->icmp6_identifier = htons(pingf->id);
|
2024-01-16 05:16:15 +00:00
|
|
|
seq = ntohs(ih6->icmp6_sequence);
|
|
|
|
} else {
|
|
|
|
ASSERT(0);
|
2023-08-11 05:12:24 +00: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 06:34:53 +00:00
|
|
|
|
2023-08-11 05:12:24 +00:00
|
|
|
/* In PASTA mode, we'll get any reply we send, discard them. */
|
|
|
|
if (c->mode == MODE_PASTA) {
|
2024-02-29 04:15:32 +00:00
|
|
|
if (pingf->seq == seq)
|
2023-08-11 05:12:24 +00:00
|
|
|
return;
|
2022-10-26 15:45:48 +00:00
|
|
|
|
2024-02-29 04:15:32 +00:00
|
|
|
pingf->seq = seq;
|
2021-03-17 09:57:44 +00:00
|
|
|
}
|
2023-08-11 05:12:24 +00:00
|
|
|
|
2024-02-29 04:15:33 +00:00
|
|
|
flow_dbg(pingf, "echo reply to tap, ID: %"PRIu16", seq: %"PRIu16,
|
2024-02-29 04:15:34 +00:00
|
|
|
pingf->id, seq);
|
2024-02-29 04:15:33 +00:00
|
|
|
|
2024-02-29 04:15:34 +00:00
|
|
|
if (pingf->f.type == FLOW_PING4)
|
2024-01-16 05:16:15 +00:00
|
|
|
tap_icmp4_send(c, sr.sa4.sin_addr, tap_ip4_daddr(c), buf, n);
|
2024-02-29 04:15:34 +00:00
|
|
|
else if (pingf->f.type == FLOW_PING6)
|
2024-01-16 05:16:15 +00:00
|
|
|
tap_icmp6_send(c, &sr.sa6.sin6_addr,
|
|
|
|
tap_ip6_daddr(c, &sr.sa6.sin6_addr), buf, n);
|
2024-01-16 05:16:17 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
unexpected:
|
2024-02-29 04:15:33 +00:00
|
|
|
flow_err(pingf, "Unexpected packet on ping socket");
|
2021-03-17 09:57:44 +00:00
|
|
|
}
|
|
|
|
|
2024-01-16 05:16:18 +00:00
|
|
|
/**
|
2024-02-29 04:15:32 +00:00
|
|
|
* icmp_ping_close() - Close and clean up a ping flow
|
2024-01-16 05:16:18 +00:00
|
|
|
* @c: Execution context
|
2024-02-29 04:15:32 +00:00
|
|
|
* @pingf: ping flow entry to close
|
2024-01-16 05:16:18 +00:00
|
|
|
*/
|
2024-02-29 04:15:32 +00:00
|
|
|
static void icmp_ping_close(const struct ctx *c,
|
|
|
|
const struct icmp_ping_flow *pingf)
|
2024-01-16 05:16:18 +00:00
|
|
|
{
|
2024-02-29 04:15:32 +00:00
|
|
|
uint16_t id = pingf->id;
|
|
|
|
|
|
|
|
epoll_ctl(c->epollfd, EPOLL_CTL_DEL, pingf->sock, NULL);
|
|
|
|
close(pingf->sock);
|
|
|
|
|
|
|
|
if (pingf->f.type == FLOW_PING4)
|
|
|
|
icmp_id_map[V4][id] = NULL;
|
|
|
|
else
|
|
|
|
icmp_id_map[V6][id] = NULL;
|
2024-01-16 05:16:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* icmp_ping_new() - Prepare a new ping socket for a new id
|
|
|
|
* @c: Execution context
|
2024-02-29 04:15:32 +00:00
|
|
|
* @id_sock: Pointer to ping flow entry slot in icmp_id_map[] to update
|
2024-01-16 05:16:18 +00:00
|
|
|
* @af: Address family, AF_INET or AF_INET6
|
|
|
|
* @id: ICMP id for the new socket
|
2024-07-18 05:26:27 +00:00
|
|
|
* @saddr: Source address
|
|
|
|
* @daddr: Destination address
|
2024-01-16 05:16:18 +00:00
|
|
|
*
|
2024-02-29 04:15:32 +00:00
|
|
|
* Return: Newly opened ping flow, or NULL on failure
|
2024-01-16 05:16:18 +00:00
|
|
|
*/
|
2024-02-29 04:15:32 +00:00
|
|
|
static struct icmp_ping_flow *icmp_ping_new(const struct ctx *c,
|
|
|
|
struct icmp_ping_flow **id_sock,
|
2024-07-18 05:26:27 +00:00
|
|
|
sa_family_t af, uint16_t id,
|
|
|
|
const void *saddr, const void *daddr)
|
2024-01-16 05:16:18 +00:00
|
|
|
{
|
2024-02-29 04:15:32 +00:00
|
|
|
uint8_t flowtype = af == AF_INET ? FLOW_PING4 : FLOW_PING6;
|
2024-02-29 04:15:34 +00:00
|
|
|
union epoll_ref ref = { .type = EPOLL_TYPE_PING };
|
2024-02-29 04:15:32 +00:00
|
|
|
union flow *flow = flow_alloc();
|
|
|
|
struct icmp_ping_flow *pingf;
|
2024-01-16 05:16:18 +00:00
|
|
|
const void *bind_addr;
|
|
|
|
const char *bind_if;
|
2024-02-29 04:15:32 +00:00
|
|
|
|
|
|
|
if (!flow)
|
|
|
|
return NULL;
|
|
|
|
|
2024-07-18 05:26:27 +00:00
|
|
|
flow_initiate_af(flow, PIF_TAP, af, saddr, id, daddr, id);
|
2024-07-18 05:26:28 +00:00
|
|
|
/* FIXME: Record outbound source address when known */
|
|
|
|
flow_target_af(flow, PIF_HOST, af, NULL, 0, daddr, 0);
|
2024-05-21 05:57:06 +00:00
|
|
|
pingf = FLOW_SET_TYPE(flow, flowtype, ping);
|
2024-02-29 04:15:32 +00:00
|
|
|
|
|
|
|
pingf->seq = -1;
|
|
|
|
pingf->id = id;
|
2024-01-16 05:16:18 +00: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 05:57:06 +00:00
|
|
|
ref.flowside = FLOW_SIDX(flow, TGTSIDE);
|
2024-07-05 10:43:59 +00:00
|
|
|
pingf->sock = sock_l4(c, af, EPOLL_TYPE_PING, bind_addr, bind_if,
|
2024-02-29 04:15:34 +00:00
|
|
|
0, ref.data);
|
2024-01-16 05:16:18 +00:00
|
|
|
|
2024-02-29 04:15:32 +00:00
|
|
|
if (pingf->sock < 0) {
|
2024-01-16 05:16:18 +00: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 04:15:32 +00:00
|
|
|
if (pingf->sock > FD_REF_MAX)
|
2024-01-16 05:16:18 +00:00
|
|
|
goto cancel;
|
|
|
|
|
2024-02-29 04:15:33 +00:00
|
|
|
flow_dbg(pingf, "new socket %i for echo ID %"PRIu16, pingf->sock, id);
|
2024-01-16 05:16:18 +00:00
|
|
|
|
2024-02-29 04:15:33 +00:00
|
|
|
*id_sock = pingf;
|
2024-01-16 05:16:18 +00:00
|
|
|
|
2024-05-21 05:57:05 +00:00
|
|
|
FLOW_ACTIVATE(pingf);
|
|
|
|
|
2024-02-29 04:15:32 +00:00
|
|
|
return pingf;
|
2024-01-16 05:16:18 +00:00
|
|
|
|
|
|
|
cancel:
|
2024-02-29 04:15:32 +00:00
|
|
|
flow_alloc_cancel(flow);
|
|
|
|
return NULL;
|
2024-01-16 05:16:18 +00:00
|
|
|
}
|
|
|
|
|
2021-03-17 09:57:44 +00:00
|
|
|
/**
|
|
|
|
* icmp_tap_handler() - Handle packets from tap
|
|
|
|
* @c: Execution context
|
2023-11-07 01:40:16 +00:00
|
|
|
* @pif: pif on which the packet is arriving
|
2021-03-17 09:57:44 +00:00
|
|
|
* @af: Address family, AF_INET or AF_INET6
|
2023-08-22 05:29:53 +00: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 12:02:47 +00: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 06:34:53 +00:00
|
|
|
* @now: Current timestamp
|
2021-04-22 11:39:36 +00:00
|
|
|
*
|
|
|
|
* Return: count of consumed packets (always 1, even if malformed)
|
2021-03-17 09:57:44 +00:00
|
|
|
*/
|
2024-02-19 07:56:46 +00:00
|
|
|
int icmp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
|
2023-08-22 05:29:53 +00:00
|
|
|
const void *saddr, const void *daddr,
|
2022-03-26 06:23:21 +00:00
|
|
|
const struct pool *p, const struct timespec *now)
|
2021-03-17 09:57:44 +00:00
|
|
|
{
|
2024-02-28 11:25:04 +00:00
|
|
|
union sockaddr_inany sa = { .sa_family = af };
|
2024-01-16 05:16:14 +00:00
|
|
|
const socklen_t sl = af == AF_INET ? sizeof(sa.sa4) : sizeof(sa.sa6);
|
2024-02-29 04:15:32 +00:00
|
|
|
struct icmp_ping_flow *pingf, **id_sock;
|
2024-05-01 06:53:49 +00:00
|
|
|
size_t dlen, l4len;
|
2024-01-16 05:16:14 +00:00
|
|
|
uint16_t id, seq;
|
|
|
|
void *pkt;
|
2021-04-22 11:39:36 +00:00
|
|
|
|
2023-08-22 05:29:53 +00:00
|
|
|
(void)saddr;
|
2024-02-29 04:15:32 +00:00
|
|
|
ASSERT(pif == PIF_TAP);
|
2023-08-22 05:29:53 +00:00
|
|
|
|
2021-03-17 09:57:44 +00:00
|
|
|
if (af == AF_INET) {
|
2024-01-16 05:16:08 +00:00
|
|
|
const struct icmphdr *ih;
|
2021-03-17 09:57:44 +00:00
|
|
|
|
2024-05-01 06:53:49 +00:00
|
|
|
if (!(pkt = packet_get(p, 0, 0, sizeof(*ih), &dlen)))
|
2021-04-22 11:39:36 +00:00
|
|
|
return 1;
|
2021-03-17 09:57:44 +00:00
|
|
|
|
2024-01-16 05:16:14 +00:00
|
|
|
ih = (struct icmphdr *)pkt;
|
2024-05-01 06:53:49 +00:00
|
|
|
l4len = dlen + sizeof(*ih);
|
2024-01-16 05:16:14 +00:00
|
|
|
|
2024-01-16 05:16:10 +00:00
|
|
|
if (ih->type != ICMP_ECHO)
|
2022-04-05 05:10:30 +00:00
|
|
|
return 1;
|
|
|
|
|
2024-01-16 05:16:14 +00:00
|
|
|
id = ntohs(ih->un.echo.id);
|
|
|
|
id_sock = &icmp_id_map[V4][id];
|
|
|
|
seq = ntohs(ih->un.echo.sequence);
|
|
|
|
sa.sa4.sin_addr = *(struct in_addr *)daddr;
|
|
|
|
} else if (af == AF_INET6) {
|
|
|
|
const struct icmp6hdr *ih;
|
2021-03-17 09:57:44 +00:00
|
|
|
|
2024-05-01 06:53:49 +00:00
|
|
|
if (!(pkt = packet_get(p, 0, 0, sizeof(*ih), &dlen)))
|
2024-01-16 05:16:14 +00: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 06:34:53 +00:00
|
|
|
|
2024-01-16 05:16:14 +00:00
|
|
|
ih = (struct icmp6hdr *)pkt;
|
2024-05-01 06:53:49 +00:00
|
|
|
l4len = dlen + sizeof(*ih);
|
2022-10-26 15:45:48 +00:00
|
|
|
|
2024-01-16 05:16:14 +00:00
|
|
|
if (ih->icmp6_type != ICMPV6_ECHO_REQUEST)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
id = ntohs(ih->icmp6_identifier);
|
|
|
|
id_sock = &icmp_id_map[V6][id];
|
|
|
|
seq = ntohs(ih->icmp6_sequence);
|
|
|
|
sa.sa6.sin6_addr = *(struct in6_addr *)daddr;
|
|
|
|
sa.sa6.sin6_scope_id = c->ifi6;
|
|
|
|
} else {
|
|
|
|
ASSERT(0);
|
|
|
|
}
|
2021-05-21 09:14:53 +00:00
|
|
|
|
2024-02-29 04:15:32 +00:00
|
|
|
if (!(pingf = *id_sock))
|
2024-07-18 05:26:27 +00:00
|
|
|
if (!(pingf = icmp_ping_new(c, id_sock, af, id, saddr, daddr)))
|
2024-01-16 05:16:14 +00:00
|
|
|
return 1;
|
2021-04-22 11:39:36 +00:00
|
|
|
|
2024-02-29 04:15:32 +00:00
|
|
|
pingf->ts = now->tv_sec;
|
2024-01-16 05:16:14 +00:00
|
|
|
|
2024-05-01 06:53:49 +00:00
|
|
|
if (sendto(pingf->sock, pkt, l4len, MSG_NOSIGNAL, &sa.sa, sl) < 0) {
|
2024-02-29 04:15:33 +00:00
|
|
|
flow_dbg(pingf, "failed to relay request to socket: %s",
|
|
|
|
strerror(errno));
|
2024-01-16 05:16:14 +00:00
|
|
|
} else {
|
2024-02-29 04:15:33 +00:00
|
|
|
flow_dbg(pingf,
|
|
|
|
"echo request to socket, ID: %"PRIu16", seq: %"PRIu16,
|
|
|
|
id, seq);
|
2024-01-16 05:16:14 +00: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 06:34:53 +00:00
|
|
|
|
|
|
|
return 1;
|
2021-03-17 09:57:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-02-29 04:15:32 +00: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 06:34:53 +00:00
|
|
|
* @c: Execution context
|
2024-05-21 05:57:03 +00:00
|
|
|
* @pingf: Ping flow to check for timeout
|
2024-01-16 00:50:32 +00:00
|
|
|
* @now: Current timestamp
|
2024-02-29 04:15:32 +00: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 06:34:53 +00:00
|
|
|
*/
|
2024-05-21 05:57:03 +00:00
|
|
|
bool icmp_ping_timer(const struct ctx *c, const struct icmp_ping_flow *pingf,
|
2024-02-29 04:15:32 +00: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 06:34:53 +00:00
|
|
|
{
|
2024-02-29 04:15:32 +00:00
|
|
|
if (now->tv_sec - pingf->ts <= ICMP_ECHO_TIMEOUT)
|
|
|
|
return false;
|
2022-10-26 15:55:53 +00:00
|
|
|
|
2024-02-29 04:15:32 +00:00
|
|
|
icmp_ping_close(c, pingf);
|
|
|
|
return true;
|
2022-10-26 15:55:53 +00:00
|
|
|
}
|