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=TH5fcgOP; 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 4EE0B5A0280 for ; Mon, 26 May 2025 16:20:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748269226; 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=L9Lq6ujgSDFaR7X160OTvnBvkwkpjmRv1r2GWBtSuys=; b=TH5fcgOPhpVjae9yAJn+bBWzXO41seQ+R7qV2LzLrj8IrIGZrs2GKhwxJc+bq2tdw13z5s R4LdouldhbX+QTd3mKJ6TEK1arlJSwd/xo+VEdTe2oPOhBsip3XgDL0YBxFfj2vQOS9rPd 6G0HDaqweTOX66Ycq8QK6EyGCnlIny8= 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-414-UsPTWLt8OtiHOJzXXBE-Bg-1; Mon, 26 May 2025 10:20:25 -0400 X-MC-Unique: UsPTWLt8OtiHOJzXXBE-Bg-1 X-Mimecast-MFC-AGG-ID: UsPTWLt8OtiHOJzXXBE-Bg_1748269224 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3a1f6c5f4f2so636023f8f.2 for ; Mon, 26 May 2025 07:20:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748269223; x=1748874023; 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=L9Lq6ujgSDFaR7X160OTvnBvkwkpjmRv1r2GWBtSuys=; b=Gk2hchI/zzmpcD28V1DkfSbvddntXHKEFj61bhyErHuZoIDYEFu3Gp0fI7ACKIROUi V1qLBrmAZB4l3ZQy9DSoxHKmqRWcwfrglHdOJolCumsyGRnnxo/q17LmeM/HXBCWdDuj rXSFXcnVQ2D4pnb/sIKngQcAH69PmRsCv9hpDsMI2gsjy5wRIoKjFXPwAHZ96+UthLll FCrZ/lmgyybMleVWzwgvt/Cl8XiSqax6+vEoOXV5J4vmq21vPto+vgAtFssEK+s+k5eG MdR9R2NY+bU86BGYaoFW+HuHVPBFWm1CPTye2jZfNqdMRrmLCCAKbdw6kveQnTvxp1oh d6vQ== X-Gm-Message-State: AOJu0YyLrYl0CcilAkw9p2wRFshAXxsjp7a2LSISfTkabdJO1FDg0zdT VDKyELF+zxcImGMY1oVwS5OXRWhXrhvsydjPDO3pg+VBcIm2bkpmTTMS8CxWmwu70VJ21RIz8Of UsUbhEkzri7zyOeyOz4iRB72o20vfztrtPRNSKpMuXJsqDU0gYBA0QD8bT+gX5i0hPIioXjuka8 LuJoBYYpiEpXhgrc1ec9y2L1MGaEOhNKrb+THW X-Gm-Gg: ASbGncv/SJhIjPzwIgY8V1WNrLv+dwYNB69PZEsHkPyBeRSAnpgGKcm6h2lxUD6v5rF uFJ3303HyOFz3frDQooEmCNzz2RGNloj5HIk6PGDAKlQ3mo9+Cequ7vObBl87mj5WBLmjMJynJ6 2qYN7Iw8mU9GDRyNPNo6odpy+7TD0ussO/e2XT8+I0yOl/HoBDeRlknMaPOFICoxMMBe0nfKV5w Rt26I0lGasbXJdaO3jxkyMbFcu+1NThAeFrGrC2oq6d8a/17WHFrhU32STz07/D+9VD1i4yBzja j/MzNyqcp8pdWUYUN6si9Uc= X-Received: by 2002:a05:6000:1881:b0:3a4:c6bc:995b with SMTP id ffacd0b85a97d-3a4cb47b7f7mr7835743f8f.35.1748269223341; Mon, 26 May 2025 07:20:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGe+vIrff2VCUaDxlfSPzgJaym3NagMabODWEHmX2eL+CbvEYoX2f9zDl1OhNKfYQthpSTXpg== X-Received: by 2002:a05:6000:1881:b0:3a4:c6bc:995b with SMTP id ffacd0b85a97d-3a4cb47b7f7mr7835716f8f.35.1748269222903; Mon, 26 May 2025 07:20:22 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-447f3dd94f1sm244761975e9.35.2025.05.26.07.20.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 07:20:22 -0700 (PDT) Date: Mon, 26 May 2025 16:20:21 +0200 From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH v5 11/29] tcp: Convert tcp_tap_handler() to use iov_tail Message-ID: <20250526162021.629b64e2@elisabeth> In-Reply-To: <20250417165136.2688884-12-lvivier@redhat.com> References: <20250417165136.2688884-1-lvivier@redhat.com> <20250417165136.2688884-12-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: ggR5b60OqP_Omd3FqesIoJ1Imt7A_PJ-ALjs7WuIAWs_1748269224 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: SGCVNTNKWYPPTUUMAQ3JQJOLYE7FMZXD X-Message-ID-Hash: SGCVNTNKWYPPTUUMAQ3JQJOLYE7FMZXD 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:18 +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 > --- > tcp.c | 31 ++++++++++++++++++++++++------- > 1 file changed, 24 insertions(+), 7 deletions(-) > > diff --git a/tcp.c b/tcp.c > index 9c6bc529205e..67d656a1cf97 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -310,6 +310,16 @@ > #include "tcp_buf.h" > #include "tcp_vu.h" > > +/* > + * The size of TCP header (including options) is given by doff (Data Offset) > + * that is a 4-bit value specifying the number of 32-bit words in the header. > + * The maximum value of doff is 15 [(1 << 4) - 1]. > + * The maximum length in bytes of options is 15 minus the number of 32-bit > + * words in the minimal TCP header (5) multiplied by the length of a 32-bit > + * word (4). Now that you explain why, I guess it would be nicer to use the same calculation for OPTLEN_MAX (pre-existing in some sense, but doing 16 - 6 becomes more confusing now). > + */ > +#define OPTLEN_MAX (((1UL << 4) - 6) * 4UL) > + > #ifndef __USE_MISC > /* From Linux UAPI, missing in netinet/tcp.h provided by musl */ > struct tcp_repair_opt { > @@ -1957,7 +1967,10 @@ int tcp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af, > { > struct tcp_tap_conn *conn; > const struct tcphdr *th; > - size_t optlen, len; > + char optsc[OPTLEN_MAX]; > + struct iov_tail data; > + size_t optlen, l4len; > + struct tcphdr thc; > const char *opts; > union flow *flow; > flow_sidx_t sidx; > @@ -1966,15 +1979,19 @@ int tcp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af, > > (void)pif; > > - th = packet_get(p, idx, 0, sizeof(*th), &len); > + if (!packet_data(p, idx, &data)) > + return 1; > + > + l4len = iov_tail_size(&data); > + > + th = IOV_REMOVE_HEADER(&data, thc); > if (!th) > return 1; > - len += sizeof(*th); > > optlen = th->doff * 4UL - sizeof(*th); > /* Static checkers might fail to see this: */ > - optlen = MIN(optlen, ((1UL << 4) /* from doff width */ - 6) * 4UL); > - opts = packet_get(p, idx, sizeof(*th), optlen, NULL); > + optlen = MIN(optlen, OPTLEN_MAX); > + opts = (char *)iov_remove_header_(&data, &optsc[0], optlen, 1); > > sidx = flow_lookup_af(c, IPPROTO_TCP, PIF_TAP, af, saddr, daddr, > ntohs(th->source), ntohs(th->dest)); > @@ -1986,7 +2003,7 @@ int tcp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af, > tcp_conn_from_tap(c, af, saddr, daddr, th, > opts, optlen, now); > else > - tcp_rst_no_conn(c, af, saddr, daddr, flow_lbl, th, len); > + tcp_rst_no_conn(c, af, saddr, daddr, flow_lbl, th, l4len); > return 1; > } > > @@ -1994,7 +2011,7 @@ int tcp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af, > ASSERT(pif_at_sidx(sidx) == PIF_TAP); > conn = &flow->tcp; > > - flow_trace(conn, "packet length %zu from tap", len); > + flow_trace(conn, "packet length %zu from tap", l4len); > > if (th->rst) { > conn_event(c, conn, CLOSED); -- Stefano