From f21204494064e28e9f0bb20f71a6071bead0d0e8 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Wed, 26 Oct 2022 17:55:53 +0200 Subject: icmp: Don't discard first reply sequence for a given echo ID In pasta mode, ICMP and ICMPv6 echo sockets relay back to us any reply we send: we're on the same host as the target, after all. We discard them by comparing the last sequence we sent with the sequence we receive. However, on the first reply for a given identifier, the sequence might be zero, depending on the implementation of ping(8): we need another value to indicate we haven't sent any sequence number, yet. Use -1 as initialiser in the echo identifier map. This is visible with Busybox's ping, and was reported by Paul on the integration at https://github.com/containers/podman/pull/16141, with: $ podman run --net=pasta alpine ping -c 2 192.168.188.1 ...where only the second reply would be routed back. Reported-by: Paul Holzinger Fixes: 33482d5bf293 ("passt: Add PASTA mode, major rework") Signed-off-by: Stefano Brivio Reviewed-by: David Gibson --- icmp.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'icmp.c') diff --git a/icmp.c b/icmp.c index 9caa7e6..4ee847f 100644 --- a/icmp.c +++ b/icmp.c @@ -44,12 +44,12 @@ /** * struct icmp_id_sock - Tracking information for single ICMP echo identifier * @sock: Bound socket for identifier - * @seq: Last sequence number sent to tap, host order + * @seq: Last sequence number sent to tap, host order, -1: not sent yet * @ts: Last associated activity from tap, seconds */ struct icmp_id_sock { int sock; - uint16_t seq; + int seq; time_t ts; }; @@ -273,6 +273,7 @@ static void icmp_timer_one(const struct ctx *c, int v6, uint16_t id, epoll_ctl(c->epollfd, EPOLL_CTL_DEL, id_map->sock, NULL); close(id_map->sock); id_map->sock = 0; + id_map->seq = -1; } /** @@ -301,3 +302,14 @@ v6: goto v6; } } + +/** + * icmp_init() - Initialise sequences in ID map to -1 (no sequence sent yet) + */ +void icmp_init(void) +{ + unsigned i; + + for (i = 0; i < ICMP_NUM_IDS; i++) + icmp_id_map[V4][i].seq = icmp_id_map[V6][i].seq = -1; +} -- cgit v1.2.3