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=IUPIxZ8K; 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 D0DE25A0281 for ; Mon, 26 May 2025 16:21:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748269264; 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=kJj0+N3TWhRr55y6VqvOfGhTdVrGigRPtQxyHOewAKU=; b=IUPIxZ8KcettukJ7WF/gFM5nK1pD06bVQSIOTzYSgmm67L9uEYvJGgcogA5zl7TQm6rXvu florGhK6wWgHHAT+Y7tXHStBB7rVnEITgctO5XyKOGcYtPjB8lkT3JuwVZGcBaHgy+8dN2 XdMQKHBp2AZiIXP7T0QNmrC6HiVNc/s= 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-542-8j3VAUWHOwS7qVATCRxRLw-1; Mon, 26 May 2025 10:21:03 -0400 X-MC-Unique: 8j3VAUWHOwS7qVATCRxRLw-1 X-Mimecast-MFC-AGG-ID: 8j3VAUWHOwS7qVATCRxRLw_1748269262 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-442f90418b0so12555415e9.2 for ; Mon, 26 May 2025 07:21:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748269262; x=1748874062; 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=kJj0+N3TWhRr55y6VqvOfGhTdVrGigRPtQxyHOewAKU=; b=Jpslp1QOCmHZtg+dJ5jVnsKvXOykDx4ju34VeLRhNk9KJZcwsjGZ/Eb9OkoBWltWji z1RrsrX3GKGKFbcwCwcBQORbfS+Iq4pxh0mKtY4m0smx+tjdwEkEnf+Be+uqIg1g9oFo jKIhCgrvxcxj9olRGFiTkHqOh6SfkLOg3KBIWPNY5nvvfffK7AlLT5G7QGwntQ2uXyFV M1efDpM79nBX4YkgVKlkxK+M+2fVCKEsI5ybFNsgKfCd4RWgsCcm9urIWJZia0h9DrYH 3rgLAPaBWv1HbAsP3xjvkGs9W1Xo0ZbP7pswAEhOBex6EMK9aRkbgMBQdUB6PrT56uSV 4LPg== X-Gm-Message-State: AOJu0YwBgqd2iXK6lEa54Q9FEC+kCTaj+3GWlY0PomoS5uBfPvAUwnF8 /9T13awrERgTs3ZlQqUfnUEHSR8nDiXy07lLfLHr5pV+fFCHZtS/W+IE68ZBlFBVeT3HYAurP5x HX2ZkIenH6lgBCO3bvHmoeoS20ECRuQGN55lLTs2P8vhhx8vVMob5ke0BEFbkgNfc7B0JVUdknr ez9XBGju2RE7VO0ryw1QextzkNfXeeIGgeqbOC X-Gm-Gg: ASbGncszY8V25l5FUTvhLvqeM/1yfvjMDxReIWQxGggSy20mnhQrn0UeuHplsUHDMLL m4l6gcxzLUIhsPY//EQVfmIRBzrZxjUZHikA/qI71tFWM6eKNJT/Z+YXh65wAa7BYft5mASAYIy ZPniYjfR7StlyYr3egxwonvFgY6Tt1yp2zn330QTfe7dKfuHkL+3Jso//B+fHRDI+1znYNl+fma dHtMNhUo1o/qqASu11CchRDifwjfzypRDClkWTZFRU7Jy/x0s8LxK2oVBbE3CsPe26iH9wsv3g4 G9J0YtBpuS9VNLnuCaek+KraWq6a0sJKjSwgR2TC X-Received: by 2002:a05:600c:6308:b0:43d:2313:7b4a with SMTP id 5b1f17b1804b1-44c9141ac4emr103287365e9.3.1748269262009; Mon, 26 May 2025 07:21:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWd1fRy4Mi59nD7baZp0SifA/ppMc3wzyzM6+nMsZfZ9PfLbyjhh7zf1WXhjw0owEzZiaYZQ== X-Received: by 2002:a05:600c:6308:b0:43d:2313:7b4a with SMTP id 5b1f17b1804b1-44c9141ac4emr103286905e9.3.1748269261550; Mon, 26 May 2025 07:21:01 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-448ba3d8facsm222641885e9.6.2025.05.26.07.21.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 07:21:01 -0700 (PDT) Date: Mon, 26 May 2025 16:21:00 +0200 From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH v5 18/29] ip: Use iov_tail in ipv6_l4hdr() Message-ID: <20250526162100.7fe80a72@elisabeth> In-Reply-To: <20250417165136.2688884-19-lvivier@redhat.com> References: <20250417165136.2688884-1-lvivier@redhat.com> <20250417165136.2688884-19-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: NK_dmgKgHR7VfRJDiqa38foz7MnKRafHVjHhgAKs48E_1748269262 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: DHERVZ7VNW6GALDHHYP7ZW72NVSHGDTU X-Message-ID-Hash: DHERVZ7VNW6GALDHHYP7ZW72NVSHGDTU 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:25 +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 > --- > ip.c | 27 ++++++++++++--------------- > ip.h | 3 +-- > packet.c | 1 + > tap.c | 4 +++- > 4 files changed, 17 insertions(+), 18 deletions(-) > > diff --git a/ip.c b/ip.c > index 2cc7f6548aff..b63fbe79fb5f 100644 > --- a/ip.c > +++ b/ip.c > @@ -23,40 +23,37 @@ > > /** > * ipv6_l4hdr() - Find pointer to L4 header in IPv6 packet and extract protocol > - * @p: Packet pool, packet number @idx has IPv6 header at @offset > - * @idx: Index of packet in pool > - * @offset: Pre-calculated IPv6 header offset > + * @data: IPv6 packet > * @proto: Filled with L4 protocol number > * @dlen: Data length (payload excluding header extensions), set on return > * > * Return: pointer to L4 header, NULL if not found > */ > -char *ipv6_l4hdr(const struct pool *p, int idx, size_t offset, uint8_t *proto, > - size_t *dlen) > +bool ipv6_l4hdr(struct iov_tail *data, uint8_t *proto, size_t *dlen) Function comment should be updated to reflect this. > { > const struct ipv6_opt_hdr *o; > + struct ipv6_opt_hdr oc; > const struct ipv6hdr *ip6h; > - char *base; > + struct ipv6hdr ip6hc; Nit: partially preexisting, but these should be from longest to shortest. Usual comment about the 'c' in 'oc'. > int hdrlen; > uint8_t nh; > > - base = packet_get(p, idx, 0, 0, NULL); > - ip6h = packet_get(p, idx, offset, sizeof(*ip6h), dlen); > + ip6h = IOV_REMOVE_HEADER(data, ip6hc); > if (!ip6h) > - return NULL; > - > - offset += sizeof(*ip6h); > + return false; > + *dlen = iov_tail_size(data); > > nh = ip6h->nexthdr; > if (!IPV6_NH_OPT(nh)) > goto found; > > - while ((o = packet_get_try(p, idx, offset, sizeof(*o), dlen))) { > + while ((o = IOV_PEEK_HEADER(data, oc))) { > + *dlen = iov_tail_size(data) - sizeof(*o); > nh = o->nexthdr; > hdrlen = (o->hdrlen + 1) * 8; > > if (IPV6_NH_OPT(nh)) > - offset += hdrlen; > + iov_tail_drop(data, hdrlen); > else > goto found; > } > @@ -65,8 +62,8 @@ char *ipv6_l4hdr(const struct pool *p, int idx, size_t offset, uint8_t *proto, > > found: > if (nh == 59) > - return NULL; > + return false; > > *proto = nh; > - return base + offset; > + return true; > } > diff --git a/ip.h b/ip.h > index 471c57ee4c71..874cbe476a6b 100644 > --- a/ip.h > +++ b/ip.h > @@ -115,8 +115,7 @@ static inline uint32_t ip6_get_flow_lbl(const struct ipv6hdr *ip6h) > ip6h->flow_lbl[2]; > } > > -char *ipv6_l4hdr(const struct pool *p, int idx, size_t offset, uint8_t *proto, > - size_t *dlen); > +bool ipv6_l4hdr(struct iov_tail *data, uint8_t *proto, size_t *dlen); > > /* IPv6 link-local all-nodes multicast adddress, ff02::1 */ > static const struct in6_addr in6addr_ll_all_nodes = { > diff --git a/packet.c b/packet.c > index b6de869db176..7489010e02eb 100644 > --- a/packet.c > +++ b/packet.c > @@ -133,6 +133,7 @@ void packet_add_do(struct pool *p, struct iov_tail *data, > * > * Return: pointer to start of data range, NULL on invalid range or descriptor > */ > +/* cppcheck-suppress [staticFunction] */ > void *packet_get_try_do(const struct pool *p, size_t idx, size_t offset, > size_t len, size_t *left, const char *func, int line) > { > diff --git a/tap.c b/tap.c > index 162f19d68115..ca25ff9e90d9 100644 > --- a/tap.c > +++ b/tap.c > @@ -909,8 +909,10 @@ resume: > if (plen != check) > continue; > > - if (!(l4h = ipv6_l4hdr(in, i, sizeof(*eh), &proto, &l4len))) > + data = IOV_TAIL_FROM_BUF(ip6h, sizeof(*ip6h) + check, 0); > + if (!ipv6_l4hdr(&data, &proto, &l4len)) > continue; > + l4h = (char *)data.iov[0].iov_base + data.off; > > if (IN6_IS_ADDR_LOOPBACK(saddr) || IN6_IS_ADDR_LOOPBACK(daddr)) { > char sstr[INET6_ADDRSTRLEN], dstr[INET6_ADDRSTRLEN]; -- Stefano