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=Zhpm5iy1; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id 4EDB05A0619 for ; Fri, 10 Oct 2025 10:40:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1760085628; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nXrVeWzVvhAvcgWAl4fB6SAp5x8jwPeApSuRee5iJVQ=; b=Zhpm5iy1DBt7fWAJ+GJiDf2H7a+ZNxxgGCxMVgUc53aMlrJCiHlpmUNepe0A6evpTYDA+W LV4FsB1Qq68jw9oEqDFcMpyZMZvqPrIgXrT3aXy3hyg+w9rDPq2QLPq7yz7oMfhkhWKjMy +YTMfn++L+O4Uh/pO6EuvAwdFBgTvn0= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-542-bwkaUzdYOYCBg76drdnQyg-1; Fri, 10 Oct 2025 04:40:26 -0400 X-MC-Unique: bwkaUzdYOYCBg76drdnQyg-1 X-Mimecast-MFC-AGG-ID: bwkaUzdYOYCBg76drdnQyg_1760085626 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-46e3dcb36a1so12177445e9.2 for ; Fri, 10 Oct 2025 01:40:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760085625; x=1760690425; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=nXrVeWzVvhAvcgWAl4fB6SAp5x8jwPeApSuRee5iJVQ=; b=CyX9oNpbH6PNs/wTurRlQAJGzW5Ikxgl6tq88HffIVf1Y+7Xhn8yPWTEz5fwjlju9b jaa+ub/fWkDV24HMpcEzs/7pTxba3mVQC83dsro6vlEa2gwdXXb8FagHiyi/V/RnigNL X99NZamCxXhddKEsjwAfYuJaLiZx2jIKfNm9uFLOvYzM01UfqokiGRbLcM6ME3FKzqMd 9FSFB4BBPhX0aLLX1MuSjrinBYolOOwRt4uTm1xrbgDbJ/S3jle2XjrVpbZwmCNDdaMK //mjdC63528dZIMzdXcGbZfjoe39oicFpHnCzN6aJdwK+N5TwuEgvDVmk9tihcQOu1XQ 9InQ== X-Gm-Message-State: AOJu0YwxN9Ve7W+jOOkrZNkb73P+/c6ysZqm6yyVvCfwCXl1rVRd0c9O y/vd4VVBRoPllrFRhRYgbwcCZtt8DttS9gAUa2FYsHp5US+HRQnSbH7A9WZXSNT184XYoIP+9Sq Ml22em9rQqUOXFwGiCpby6p2ZLPrG77o1M6tjC6q+KedzF14XxbSVlw== X-Gm-Gg: ASbGncvriCh4m8BeRThZhgIo4y827QuWUlH06iwOFKDLDH9Pt0296/fpXT0gsx/1DNC vSQxS0HEMkP285Zbz+8SSVhqNptl9BF5+nfrD8kHDXnef3XkngAdDDs0tRYr/gMKnbf70vaxBZF MtEAYfaNuGYSYWgoscJiotqzMZiejP509tisaypHTp1eahjLxfI4pn41VPbWumCWdiYhyJD2N1t ZwGWwl04FEC5LdQZzIcMzYiIy1ftdjh0TaZNsySRkhSMvxKMaduAzh5mzkpAuptK47pVZsKRJgb kFg1+FXez2VhZtEOYINKXfaJDhHmF2R/X0pNBNByB/0rqEG8M8L7WHW8aJybTsVspS5Y X-Received: by 2002:a05:600c:5490:b0:46e:4744:add7 with SMTP id 5b1f17b1804b1-46fae33db7amr61216185e9.7.1760085625480; Fri, 10 Oct 2025 01:40:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG2U5ziEnuYx6Ny9mIaRmLdkzQ5eslQtV/U3I4r6dUhs8+lTOxPLOCHikEXHteYIIIwyt8tqQ== X-Received: by 2002:a05:600c:5490:b0:46e:4744:add7 with SMTP id 5b1f17b1804b1-46fae33db7amr61215825e9.7.1760085624867; Fri, 10 Oct 2025 01:40:24 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46fb49d03e2sm34416275e9.19.2025.10.10.01.40.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Oct 2025 01:40:24 -0700 (PDT) Date: Fri, 10 Oct 2025 10:40:21 +0200 From: Stefano Brivio To: Jon Maloy Subject: Re: [PATCH v11 3/4] tap: break out building of udp header from tap_udp6_send function Message-ID: <20251010104021.7cba68a0@elisabeth> In-Reply-To: <20250306180006.1921583-4-jmaloy@redhat.com> References: <20250306180006.1921583-1-jmaloy@redhat.com> <20250306180006.1921583-4-jmaloy@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: jKe-gGjPz6FAI7WXXXY68YKsu7wpIAKskO21rXubru0_1760085626 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: UQYZVCEZOIRHEE25UR5PNQK43CAXVD7H X-Message-ID-Hash: UQYZVCEZOIRHEE25UR5PNQK43CAXVD7H X-MailFrom: sbrivio@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 CC: passt-dev@passt.top, 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: On Thu, 6 Mar 2025 13:00:05 -0500 Jon Maloy wrote: > We will need to build the UDP header at other locations than in function > tap_udp6_send(), so we break that part out to a separate function. > > Reviewed-by: David Gibson > Signed-off-by: Jon Maloy > --- > v2: Fix to satisfy coverity. After feedback from S. Brivio > --- > tap.c | 40 +++++++++++++++++++++++++++++++--------- > tap.h | 4 ++++ > 2 files changed, 35 insertions(+), 9 deletions(-) > > diff --git a/tap.c b/tap.c > index 2b4ec26..27976da 100644 > --- a/tap.c > +++ b/tap.c > @@ -268,7 +268,7 @@ static void *tap_push_ip6h(struct ipv6hdr *ip6h, > } > > /** > - * tap_udp6_send() - Send UDP over IPv6 packet > + * tap_push_uh6() - Build UDPv6 header with checksum > * @c: Execution context > * @src: IPv6 source address > * @sport: UDP source port > @@ -277,18 +277,15 @@ static void *tap_push_ip6h(struct ipv6hdr *ip6h, > * @flow: Flow label > * @in: UDP payload contents (not including UDP header) > * @dlen: UDP payload length (not including UDP header) > + * > + * Return: pointer at which to write the packet's payload > */ > -void tap_udp6_send(const struct ctx *c, > +void *tap_push_uh6(struct udphdr *uh, Same here: this patch didn't update the function comment, so it now takes a 'uh' parameter which is not obvious at all. Please fix this. > const struct in6_addr *src, in_port_t sport, > const struct in6_addr *dst, in_port_t dport, > - uint32_t flow, void *in, size_t dlen) > + void *in, size_t dlen) > { > size_t l4len = dlen + sizeof(struct udphdr); > - char buf[USHRT_MAX]; > - struct ipv6hdr *ip6h = tap_push_l2h(c, buf, ETH_P_IPV6); > - struct udphdr *uh = tap_push_ip6h(ip6h, src, dst, > - l4len, IPPROTO_UDP, flow); > - char *data = (char *)(uh + 1); > const struct iovec iov = { > .iov_base = in, > .iov_len = dlen > @@ -299,8 +296,33 @@ void tap_udp6_send(const struct ctx *c, > uh->dest = htons(dport); > uh->len = htons(l4len); > csum_udp6(uh, src, dst, &payload); > - memcpy(data, in, dlen); > + return (char *)uh + sizeof(*uh); > +} > > +/** > + * tap_udp6_send() - Send UDP over IPv6 packet > + * @c: Execution context > + * @src: IPv6 source address > + * @sport: UDP source port > + * @dst: IPv6 destination address > + * @dport: UDP destination port > + * @flow: Flow label > + * @in: UDP payload contents (not including UDP header) > + * @dlen: UDP payload length (not including UDP header) > + */ > +void tap_udp6_send(const struct ctx *c, > + const struct in6_addr *src, in_port_t sport, > + const struct in6_addr *dst, in_port_t dport, > + uint32_t flow, void *in, size_t dlen) > +{ > + size_t l4len = dlen + sizeof(struct udphdr); > + char buf[USHRT_MAX]; > + struct ipv6hdr *ip6h = tap_push_l2h(c, buf, ETH_P_IPV6); > + struct udphdr *uh = tap_push_ip6h(ip6h, src, dst, > + l4len, IPPROTO_UDP, flow); > + char *data = tap_push_uh6(uh, src, sport, dst, dport, in, dlen); > + > + memcpy(data, in, dlen); > tap_send_single(c, buf, dlen + (data - buf)); > } > > diff --git a/tap.h b/tap.h > index 37da21d..b7b8cef 100644 > --- a/tap.h > +++ b/tap.h > @@ -47,6 +47,10 @@ static inline void tap_hdr_update(struct tap_hdr *thdr, size_t l2len) > void *tap_push_uh4(struct udphdr *uh, struct in_addr src, in_port_t sport, > struct in_addr dst, in_port_t dport, > const void *in, size_t dlen); > +void *tap_push_uh6(struct udphdr *uh, > + const struct in6_addr *src, in_port_t sport, > + const struct in6_addr *dst, in_port_t dport, > + void *in, size_t dlen); > void *tap_push_ip4h(struct iphdr *ip4h, struct in_addr src, > struct in_addr dst, size_t l4len, uint8_t proto); > void tap_udp4_send(const struct ctx *c, struct in_addr src, in_port_t sport, -- Stefano