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=KnomQC1Y; 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 28ADC5A0619 for ; Fri, 10 Oct 2025 10:40:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1760085620; 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=2r8KestMG4+Fjz+FEXRsCDqG0bm/qyDO/5S76V7+qzk=; b=KnomQC1YEx8rJMdyfoxiigloGZlfyRUfKYNt4UVqA8886on4jusDXWCundPTltqspW1UfY q4YZTgA3gB0YBsCXPrT0gj+qxapZ813Vd+6H2fsUtpxYEWkPK1Kg0KHDVwftQEauQK/gcr j33UcWyhKDNS+elDl/e6hg6txc6mIFA= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-207-L_d5EOUfPCCnDmq4GhgHBQ-1; Fri, 10 Oct 2025 04:40:19 -0400 X-MC-Unique: L_d5EOUfPCCnDmq4GhgHBQ-1 X-Mimecast-MFC-AGG-ID: L_d5EOUfPCCnDmq4GhgHBQ_1760085618 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-46e3e177893so11058885e9.2 for ; Fri, 10 Oct 2025 01:40:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760085617; x=1760690417; 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=2r8KestMG4+Fjz+FEXRsCDqG0bm/qyDO/5S76V7+qzk=; b=D268SrHzPM2wZsPWdObRFtFP41WJ+lCX58Szsg70BEN4XmHETYDW97U0jY1XLHbL48 tlh1PJmxYO0xedZfes+Rel2Yl1W/OPnKhmD3wDoQ5kGlfoFReGZeHfixn+r7540mprqG QqIeRWuqhOyl8qj856I96he4QbMyJa6n+5VNAOmdfQQ82zAI0X61/gyhWiHdBN/J8AO9 pSu6d322wXyKhLej4futLi2UdtDXiuCuZHDukGGBOubL2dYq998KwRuxyk2GqWcwI5xv f3H/9jg2wHodQIG+2E7JAroCf1VQr2o/DNFbTbeaIEviLVzmGjuW+WWDU21+js0oj5hp 5zhA== X-Gm-Message-State: AOJu0YwOIK14AmlSauV9Ifn7qsiK97e/9GGCNQ9FWT1Y8qp88nB5PoKB ZZLIQe3KZzxl7TI0IknXUgXEaRzhZevtcdyG6Q4E/KBRskSjAj92LM1HA0h/1P7E2BpKzA0b6k2 sXD+QtDibA5E24iF+3OCwjSb/MKzktMQ/FImN1J1sbA3ZyK0r/HxiaalgjoPM2A== X-Gm-Gg: ASbGncuiyuyMcy2yQ49SQg+o71Qy0J8hLGjizimtPH1AKTSl/ph+5TBXpwPW3SoEC4o FCFbx1EJvMe7hNZNcCW6yY5Lrter21916F9JwAgbSqqC1OV/tOLn5nXl9vuVuWJjC8mqpejfgK1 TIfYaRwbdCq9FaCehhc51oT48lEOku5WE7yxqaAYBGcz8vGi445sV2IhY4wDzQABvDaANy8iQjO nL8sYar+0yB8A/AU+gCSk65mQhQapSC/iD1GAkl92Fh6eL41pTul3aEqtIZKiIxgPT8X+WJf058 hZiXCZsRYmvrbN8xFhwc33BStA0BJIFEo9X+R9RaTMktCMkOM+3KjKxCRLj4BG5w4j8G X-Received: by 2002:a05:600c:c162:b0:45f:2cb5:ecff with SMTP id 5b1f17b1804b1-46fa9b02fa3mr85930435e9.31.1760085616740; Fri, 10 Oct 2025 01:40:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFRtQB+PpUEr/pokZwYJemdhUzwsjEvU3+pXU+BJe3troMcFeKdGqPmc2pCcLEtSfZpOySYiA== X-Received: by 2002:a05:600c:c162:b0:45f:2cb5:ecff with SMTP id 5b1f17b1804b1-46fa9b02fa3mr85930185e9.31.1760085616226; Fri, 10 Oct 2025 01:40:16 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46fb49c3e49sm33392515e9.16.2025.10.10.01.40.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Oct 2025 01:40:15 -0700 (PDT) Date: Fri, 10 Oct 2025 10:40:13 +0200 From: Stefano Brivio To: Jon Maloy Subject: Re: [PATCH v11 1/4] tap: break out building of udp header from tap_udp4_send function Message-ID: <20251010104013.171af1f7@elisabeth> In-Reply-To: <20250306180006.1921583-2-jmaloy@redhat.com> References: <20250306180006.1921583-1-jmaloy@redhat.com> <20250306180006.1921583-2-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: Zw2k1noKBHRUGmV0C6bgR_BrahiWmeCIDVG1bLuWBPk_1760085618 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: WIKUJY4WXDY5V7MM3UJQQ6CRMTETKR56 X-Message-ID-Hash: WIKUJY4WXDY5V7MM3UJQQ6CRMTETKR56 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:03 -0500 Jon Maloy wrote: > We will need to build the UDP header at other locations than in function > tap_udp4_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 | 34 +++++++++++++++++++++++++++------- > tap.h | 5 +++++ > 2 files changed, 32 insertions(+), 7 deletions(-) > > diff --git a/tap.c b/tap.c > index 44b0fc0..16e3761 100644 > --- a/tap.c > +++ b/tap.c > @@ -163,7 +163,7 @@ static void *tap_push_ip4h(struct iphdr *ip4h, struct in_addr src, > } > > /** > - * tap_udp4_send() - Send UDP over IPv4 packet > + * tap_push_uh4() - Build UDPv4 header with checksum > * @c: Execution context > * @src: IPv4 source address > * @sport: UDP source port > @@ -171,16 +171,14 @@ static void *tap_push_ip4h(struct iphdr *ip4h, struct in_addr src, > * @dport: UDP destination port > * @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_udp4_send(const struct ctx *c, struct in_addr src, in_port_t sport, > +void *tap_push_uh4(struct udphdr *uh, struct in_addr src, in_port_t sport, This patch didn't update the function comment, so it now takes a 'uh' parameter which is not obvious at all. At a first glance, one might say it's an "input" header. Please fix this. > struct in_addr dst, in_port_t dport, > const void *in, size_t dlen) > { > size_t l4len = dlen + sizeof(struct udphdr); > - char buf[USHRT_MAX]; > - struct iphdr *ip4h = tap_push_l2h(c, buf, ETH_P_IP); > - struct udphdr *uh = tap_push_ip4h(ip4h, src, dst, l4len, IPPROTO_UDP); > - char *data = (char *)(uh + 1); > const struct iovec iov = { > .iov_base = (void *)in, > .iov_len = dlen > @@ -191,8 +189,30 @@ void tap_udp4_send(const struct ctx *c, struct in_addr src, in_port_t sport, > uh->dest = htons(dport); > uh->len = htons(l4len); > csum_udp4(uh, src, dst, &payload); > - memcpy(data, in, dlen); > + return (char *)uh + sizeof(*uh); > +} > > +/** > + * tap_udp4_send() - Send UDP over IPv4 packet > + * @c: Execution context > + * @src: IPv4 source address > + * @sport: UDP source port > + * @dst: IPv4 destination address > + * @dport: UDP destination port > + * @in: UDP payload contents (not including UDP header) > + * @dlen: UDP payload length (not including UDP header) > + */ > +void tap_udp4_send(const struct ctx *c, struct in_addr src, in_port_t sport, > + struct in_addr dst, in_port_t dport, > + const void *in, size_t dlen) > +{ > + size_t l4len = dlen + sizeof(struct udphdr); > + char buf[USHRT_MAX]; > + struct iphdr *ip4h = tap_push_l2h(c, buf, ETH_P_IP); > + struct udphdr *uh = tap_push_ip4h(ip4h, src, dst, l4len, IPPROTO_UDP); > + char *data = tap_push_uh4(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 a476a12..0b3eb93 100644 > --- a/tap.h > +++ b/tap.h > @@ -6,6 +6,8 @@ > #ifndef TAP_H > #define TAP_H > > +struct udphdr; > + > /** > * struct tap_hdr - tap backend specific headers > * @vnet_len: Frame length (for qemu socket transport) > @@ -42,6 +44,9 @@ static inline void tap_hdr_update(struct tap_hdr *thdr, size_t l2len) > thdr->vnet_len = htonl(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_udp4_send(const struct ctx *c, struct in_addr src, in_port_t sport, > struct in_addr dst, in_port_t dport, > const void *in, size_t dlen); -- Stefano