From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id EEF935A0285 for ; Thu, 21 Dec 2023 08:02:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1703142161; bh=ZR4XEGNQ7AA2rBIiRS5Y8RQhwhs6QgErt2DxAxZ+5ks=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lAM7/OieLM5WAqM3t3CafCuegIBWlPwEjjKzhKRKm3CfIGU2wOk2FV4/jqG6/lpgX i4L83cHtVaFfCyC0+Sec/Jh8hMVOXNhX0MDma9P70ilm7RvvjGuH9DA8qqgYdJBtCw mta2Ng8inMF64r0kHYPeB6c2UfJW06dVMKvzFjQdIfVbjikwsGpmsBU7H9oVRL/Axw 3oXgRQK+3vJnjjGqRqQAORwr663dN+0a1sSfFyhAHUSQHxwoaN7EA3W2wPcy7N4cpk d+CkvDY/bhGZ7YjqEZStZ0+yxa/Skw9t6p37BwQGY577bpuWhxFUEFcZd4VbyFssnY ytagFS2YVHHvg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4SwhFs1G9Vz4xSX; Thu, 21 Dec 2023 18:02:41 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH v3 12/15] icmp: Populate and use host side flow information Date: Thu, 21 Dec 2023 18:02:34 +1100 Message-ID: <20231221070237.1422557-13-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231221070237.1422557-1-david@gibson.dropbear.id.au> References: <20231221070237.1422557-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: OHDPDEZ56R6ZOYNYUVFNETWTH3PF4QSV X-Message-ID-Hash: OHDPDEZ56R6ZOYNYUVFNETWTH3PF4QSV X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Complete filling out the common flow information for "ping" flows by storing the host side information for the ping socket. We can only retrieve this from the socket after we send the echo-request, because that's when the kernel will assign an ID. Signed-off-by: David Gibson --- icmp.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/icmp.c b/icmp.c index 53ad087..917c810 100644 --- a/icmp.c +++ b/icmp.c @@ -310,11 +310,41 @@ int icmp_tap_handler(const struct ctx *c, uint8_t pif, int af, if (sendto(pingf->sock, pkt, plen, MSG_NOSIGNAL, &sa.sa, sl) < 0) { debug("%s: failed to relay request to socket: %s", pname, strerror(errno)); - } else { - debug("%s: echo request to socket, ID: %"PRIu16", seq: %"PRIu16, - pname, id, seq); + if (flow) + goto cancel; + } + + debug("%s: echo request to socket, ID: %"PRIu16", seq: %"PRIu16, + pname, id, seq); + + if (!flow) + /* Nothing more to do for an existing flow */ + return 1; + + /* We need to wait until after the sendto() to fill in the SOCKSIDE + * information, so that we can find out the host side id the kernel + * assigned. If there's no bind address specified, this will still have + * 0.0.0.0 or :: as the host side forwarding address. There's not + * really anything we can do to fill that in, which means we can never + * insert the SOCKSIDE of a ping flow into the hash table. + */ + if (flowside_from_sock(SOCKFSIDE(pingf), PIF_HOST, pingf->sock, + NULL, &sa) < 0) { + err("%s: Failed to get local name for outgoing ping socket", + pname); + goto cancel; } + /* We want the id as the "port" on both sides */ + SOCKFSIDE(pingf)->eport = SOCKFSIDE(pingf)->fport; + + FLOW_FWD_DBG(pingf, SOCKSIDE); + + return 1; +cancel: + /* Something went wrong, back out creation of the flow */ + icmp_ping_close(c, pingf); + flow_alloc_cancel(flow); return 1; } -- 2.43.0