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=eoNSSb35; 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 A77515A0280 for ; Mon, 26 May 2025 16:20:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748269218; 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=k1RQSVCQnvPKTLirIPJeOIak6FK5X/F6FGlK/XzqhiE=; b=eoNSSb350O0AFByZyF8jD9YLUAFLHyeEDDz0VVKs0dhsY3vXSCFvRKrLZC15j6MnpmF6I1 sb4NV/GEvGZ6h/RPBkONk06QEWnx1G2dCHQZAYOdp7f06rVqA/ZpcStiLOnGUHFwtt+Zjo bW84T7Qo2zePXxZAUbZQQxKs2GtGBxg= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-601-iYz9YRoNNj66jRyQeWGdwg-1; Mon, 26 May 2025 10:20:17 -0400 X-MC-Unique: iYz9YRoNNj66jRyQeWGdwg-1 X-Mimecast-MFC-AGG-ID: iYz9YRoNNj66jRyQeWGdwg_1748269216 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3a4dcfc375aso479651f8f.2 for ; Mon, 26 May 2025 07:20:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748269215; x=1748874015; 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=k1RQSVCQnvPKTLirIPJeOIak6FK5X/F6FGlK/XzqhiE=; b=ncQovAH0quLaLCopb6hPr5HBRbG1E8/jQbVBfgXdZo/z16+tkmgnnqHQyMvlGS5I+8 2EfIIGeo9DYzlylq5k0vQjl87chHT2ZaHkL2dCHzHaYdzfZhdMxeESnGOH6VZ1ZJ1Yr4 ha23Xvgs+BYyyuf8c5XkNqODboqs8JnHVkutZy7Y+Pm7I7K/LixtUmJIWoCXviAkc0cn 3klwoR3CxwPg6JhSQB0jqXfwiEmd9zvy2BjvsBpTIQrVbGijh4ptVWqF4aqG3pedn939 uYtGf7K4fyPteqAr/L2WqXR2kQx9K3vWadc0QlkXyfKY/XQ2HhssqFT7zphQ0qKYqKkE 9EnQ== X-Gm-Message-State: AOJu0Yxzu+GouJFT78/FyfbcYJ+qXQ51J7b4nxrljefbyKexR0AVdVSp K6wlRZL587b7C0jAaJVPSwnzwx3sjjpKWC+X+6zeuMyafO1AfGW1X4Yn0sumqcKGEZw3r4eRfsH dQQueJkD/W+yI0SeisXjc7IG3LU5/Bc88YTHfhEdY9X0mEKkLlcOs7ldw635HSiI91OFlg0N73/ ZI0hiwuJiLU6HnVNAjLBYV0+H/6pnt0HMIJdvz X-Gm-Gg: ASbGncvyVB01yxFtZpJVpwgYE1rC5GYGH9V2ISylqkNiWyWsn0uRM/PPQchfkOXAncy 37kuR1nxa42tD1pyL7QnnBmqci23gwdFMjkeFjm9WYSoGVwmx4tss6R2kDY6S/h2JPsMm5j05O7 6i4Qn4YFiyhgtXBWs6zjZaSMhydARf9tgbiPs6NNr+Cy8ceXcRLCT6vjch1cKrBKCp1ahJlyM6U e3IgikULk2+Z4l+QUV3HJzKfaoEshCBjlJ1/MIPShLf+UVPxyLabJyD35bPQWtxi7tB3a5ZQNH8 1yfh/0Bv/eWRlm4LrRoje8xwsuJuLucR2GgDZdgV X-Received: by 2002:a05:6000:2911:b0:3a4:dbdf:7148 with SMTP id ffacd0b85a97d-3a4dbdf745dmr2177767f8f.49.1748269215618; Mon, 26 May 2025 07:20:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGyqwbijywZMPbr5OdjWQsSfLONxq2dsEpXT2PeXcC+F6e+2BR56auigZ4LYnyJVbLKd353PA== X-Received: by 2002:a05:6000:2911:b0:3a4:dbdf:7148 with SMTP id ffacd0b85a97d-3a4dbdf745dmr2177740f8f.49.1748269215124; Mon, 26 May 2025 07:20:15 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a4c73a4284sm9137675f8f.85.2025.05.26.07.20.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 07:20:14 -0700 (PDT) Date: Mon, 26 May 2025 16:20:13 +0200 From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH v5 10/29] udp: Convert to iov_tail Message-ID: <20250526162013.640a35e9@elisabeth> In-Reply-To: <20250417165136.2688884-11-lvivier@redhat.com> References: <20250417165136.2688884-1-lvivier@redhat.com> <20250417165136.2688884-11-lvivier@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: --_YiLILRLHxX2obBK7sIEGbd9jAAO9xsUvPMeepGFk_1748269216 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: PJI743UVFQUTGXJXASJYOIAVVWUSM5TX X-Message-ID-Hash: PJI743UVFQUTGXJXASJYOIAVVWUSM5TX 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 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, 17 Apr 2025 18:51:17 +0200 Laurent Vivier wrote: > Use packet_data() and extract headers using IOV_REMOVE_HEADER() > and IOV_PEEK_HEADER() rather than packet_get(). > > Signed-off-by: Laurent Vivier > --- > iov.c | 1 - > udp.c | 34 +++++++++++++++++++++++----------- > 2 files changed, 23 insertions(+), 12 deletions(-) > > diff --git a/iov.c b/iov.c > index bb095634246e..3e18040d22a8 100644 > --- a/iov.c > +++ b/iov.c > @@ -389,7 +389,6 @@ void *iov_remove_header_(struct iov_tail *tail, void *v, size_t len, size_t alig > * iov array, a negative value if there is not enough room in the > * destination iov array > */ > -/* cppcheck-suppress unusedFunction */ > int iov_tail_slice(struct iovec *dst_iov, size_t dst_iov_cnt, > struct iov_tail *tail, size_t *bytes) > { > diff --git a/udp.c b/udp.c > index 40af7dfc260f..27e31bc5d92d 100644 > --- a/udp.c > +++ b/udp.c > @@ -872,15 +872,20 @@ int udp_tap_handler(const struct ctx *c, uint8_t pif, > struct iovec m[UIO_MAXIOV]; > const struct udphdr *uh; > struct udp_flow *uflow; > - int i, s, count = 0; > + int i, j, s, count = 0; > + struct iov_tail data; > flow_sidx_t tosidx; > in_port_t src, dst; > + struct udphdr uhc; I'm struggling to understand what the 'c' in 'uhc' stands for ("contiguous"?), but given that it's used just twice, what about making it a bit longer, say, 'uh_storage'? > uint8_t topif; > socklen_t sl; > > ASSERT(!c->no_udp); > > - uh = packet_get(p, idx, 0, sizeof(*uh), NULL); > + if (!packet_data(p, idx, &data)) > + return 1; > + > + uh = IOV_PEEK_HEADER(&data, uhc); > if (!uh) > return 1; > > @@ -917,23 +922,30 @@ int udp_tap_handler(const struct ctx *c, uint8_t pif, > > pif_sockaddr(c, &to_sa, &sl, topif, &toside->eaddr, toside->eport); > > - for (i = 0; i < (int)p->count - idx; i++) { > - struct udphdr *uh_send; > - size_t len; > + for (i = 0, j = 0; i < (int)p->count - idx && j < UIO_MAXIOV; i++) { > + const struct udphdr *uh_send; > > - uh_send = packet_get(p, idx + i, 0, sizeof(*uh), &len); > + if (!packet_data(p, idx + i, &data)) > + return p->count - idx; > + > + uh_send = IOV_REMOVE_HEADER(&data, uhc); > if (!uh_send) > return p->count - idx; > > mm[i].msg_hdr.msg_name = &to_sa; > mm[i].msg_hdr.msg_namelen = sl; > > - if (len) { > - m[i].iov_base = (char *)(uh_send + 1); > - m[i].iov_len = len; > + if (data.cnt) { > + int cnt; > + > + cnt = iov_tail_slice(&m[j], UIO_MAXIOV - j, > + &data, NULL); > + if (cnt < 0) > + return p->count - idx; > > - mm[i].msg_hdr.msg_iov = m + i; > - mm[i].msg_hdr.msg_iovlen = 1; > + mm[i].msg_hdr.msg_iov = &m[j]; > + mm[i].msg_hdr.msg_iovlen = cnt; > + j += cnt; > } else { > mm[i].msg_hdr.msg_iov = NULL; > mm[i].msg_hdr.msg_iovlen = 0; -- Stefano