From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Ks/ny/Uj; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id D19105A0274 for ; Thu, 27 Mar 2025 17:52:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1743094326; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rvy5wGJ29aWvqsYdffWRdEbRKcGkHOm0NWHUEsIQw2o=; b=Ks/ny/Uj22aNG1zsycCTUzIaGn1Hi4iX8GUuuTl4kCRLmngJfT8g+UlCwL+ACgNmuCpeXO xFGp4tPTwtqjntvOt5NL2rZ8/DzaRJJ+fS535F3BXfuTZTz0wsF/g/oCP+gEj5uE0VICAh uc9DkUPCiyKJ58K4TRS4U278pYfFLfw= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-445-QAnjilArOB6-iGFconJmxA-1; Thu, 27 Mar 2025 12:52:02 -0400 X-MC-Unique: QAnjilArOB6-iGFconJmxA-1 X-Mimecast-MFC-AGG-ID: QAnjilArOB6-iGFconJmxA_1743094321 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2F182180025B for ; Thu, 27 Mar 2025 16:52:01 +0000 (UTC) Received: from jmaloy-thinkpadp16vgen1.rmtcaqc.csb (unknown [10.22.80.15]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1344F180094A; Thu, 27 Mar 2025 16:51:59 +0000 (UTC) From: Jon Maloy To: passt-dev@passt.top, sbrivio@redhat.com, lvivier@redhat.com, dgibson@redhat.com, jmaloy@redhat.com Subject: [PATCH v2 2/2] udp: support traceroute with udp Date: Thu, 27 Mar 2025 12:51:55 -0400 Message-ID: <20250327165155.3354811-3-jmaloy@redhat.com> In-Reply-To: <20250327165155.3354811-1-jmaloy@redhat.com> References: <20250327165155.3354811-1-jmaloy@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: qv-tUVIW1ixPTdegRtEELtyBSSyrp5Wr-S0b5L7VCcA_1743094321 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: YR7LC6DSMS7SXZRAREWQOV2BLNMK3VRE X-Message-ID-Hash: YR7LC6DSMS7SXZRAREWQOV2BLNMK3VRE X-MailFrom: jmaloy@redhat.com 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 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: Now that ICMP pass-through from socket-to-tap and TTL/hop limit based outgoing flow separation is in place, it is easy to support UDP based traceroute functionality in direction tap-to-socket. We fix that in this commit. Signed-off-by: Jon Maloy --- v2: Using ancillary data instead of setsockopt to transfer outgoing TTL. --- udp.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/udp.c b/udp.c index 8a2c593..7361ffa 100644 --- a/udp.c +++ b/udp.c @@ -861,6 +861,7 @@ int udp_tap_handler(const struct ctx *c, uint8_t pif, uint8_t ttl, const struct pool *p, int idx, const struct timespec *now) { + char ancillary[CMSG_SPACE(sizeof(int))]; const struct flowside *toside; struct mmsghdr mm[UIO_MAXIOV]; union sockaddr_inany to_sa; @@ -868,6 +869,8 @@ int udp_tap_handler(const struct ctx *c, uint8_t pif, const struct udphdr *uh; struct udp_flow *uflow; int i, s, count = 0; + char *control = NULL; + int control_len = 0; flow_sidx_t tosidx; in_port_t src, dst; uint8_t topif; @@ -914,6 +917,22 @@ int udp_tap_handler(const struct ctx *c, uint8_t pif, pif_sockaddr(c, &to_sa, &sl, topif, &toside->eaddr, toside->eport); + if (ttl != DEFAULT_TTL) { + struct cmsghdr *cmsg = (void *) ancillary; + + if (af == AF_INET) { + cmsg->cmsg_level = IPPROTO_IP; + cmsg->cmsg_type = IP_TTL; + } else { + cmsg->cmsg_level = IPPROTO_IPV6; + cmsg->cmsg_type = IPV6_HOPLIMIT; + } + cmsg->cmsg_len = CMSG_LEN(sizeof(int)); + *((int *) CMSG_DATA(cmsg)) = ttl; + control = ancillary; + control_len = sizeof(ancillary); + } + for (i = 0; i < (int)p->count - idx; i++) { struct udphdr *uh_send; size_t len; @@ -936,8 +955,8 @@ int udp_tap_handler(const struct ctx *c, uint8_t pif, mm[i].msg_hdr.msg_iovlen = 0; } - mm[i].msg_hdr.msg_control = NULL; - mm[i].msg_hdr.msg_controllen = 0; + mm[i].msg_hdr.msg_control = control; + mm[i].msg_hdr.msg_controllen = control_len; mm[i].msg_hdr.msg_flags = 0; count++; -- 2.48.1