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=PQU7B4mp; 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 39B135A061E for ; Fri, 27 Mar 2026 18:58:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774634330; 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=F1H2nAB3ZnOG6cQeVgkfQ3zw9jFPupbSUyVE+y7GCts=; b=PQU7B4mplBVctuSfKIBIYK4kqZxTmpzsqsvmJ94JODnRtpfBdfp+riaRad6VH9oyiAmQ3Z ZIU1Lso0BDBp5tjN8DpnrIiCmutg4VcD1fSLOr0xiWGV7r7RyqcFcvITocGS5AVe8bEnDv Euep52g+U+i+RfA0hYTWGs8NjJCT44Q= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-582-uuOrMncPOkSRTnS0HK3WEQ-1; Fri, 27 Mar 2026 13:58:48 -0400 X-MC-Unique: uuOrMncPOkSRTnS0HK3WEQ-1 X-Mimecast-MFC-AGG-ID: uuOrMncPOkSRTnS0HK3WEQ_1774634328 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E1D0119560B8 for ; Fri, 27 Mar 2026 17:58:47 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.44.32.96]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EC71E1800351; Fri, 27 Mar 2026 17:58:46 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH v5 7/8] iov: Introduce IOV_PUSH_HEADER() macro Date: Fri, 27 Mar 2026 18:58:33 +0100 Message-ID: <20260327175834.831995-8-lvivier@redhat.com> In-Reply-To: <20260327175834.831995-1-lvivier@redhat.com> References: <20260327175834.831995-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: wdXURRHgcZA59fzzob7ryi__B4DZdUEe3cLJ2oQ3pOU_1774634328 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: L3K7PPGPS2G5JSPZASSXPO2RESBCVN67 X-Message-ID-Hash: L3K7PPGPS2G5JSPZASSXPO2RESBCVN67 X-MailFrom: lvivier@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: Laurent Vivier 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: Add iov_push_header_() and its typed wrapper IOV_PUSH_HEADER() to write a header into an iov_tail at the current offset and advance past it. This is the write counterpart to IOV_PEEK_HEADER() / IOV_REMOVE_HEADER(), using iov_from_buf() to copy the header data across iovec boundaries. Signed-off-by: Laurent Vivier --- iov.c | 23 +++++++++++++++++++++++ iov.h | 11 +++++++++++ 2 files changed, 34 insertions(+) diff --git a/iov.c b/iov.c index 8134b8c9f988..3b7174db3352 100644 --- a/iov.c +++ b/iov.c @@ -308,6 +308,29 @@ void *iov_peek_header_(struct iov_tail *tail, void *v, size_t len, size_t align) return v; } +/** + * iov_push_header_() - Write a new header to an IOV tail + * @tail: IOV tail to write header to + * @v: Pointer to header data to write + * @len: Length of header to write, in bytes + * + * Return: number of bytes written + */ +/* cppcheck-suppress unusedFunction */ +size_t iov_push_header_(struct iov_tail *tail, const void *v, size_t len) +{ + size_t l; + + if (!iov_tail_prune(tail)) + return 0; /* No space */ + + l = iov_from_buf(tail->iov, tail->cnt, tail->off, v, len); + + tail->off = tail->off + l; + + return l; +} + /** * iov_remove_header_() - Remove a header from an IOV tail * @tail: IOV tail to remove header from (modified) diff --git a/iov.h b/iov.h index d295d05b3bab..7f0eba4ed71c 100644 --- a/iov.h +++ b/iov.h @@ -90,6 +90,7 @@ bool iov_tail_prune(struct iov_tail *tail); size_t iov_tail_size(struct iov_tail *tail); bool iov_drop_header(struct iov_tail *tail, size_t len); void *iov_peek_header_(struct iov_tail *tail, void *v, size_t len, size_t align); +size_t iov_push_header_(struct iov_tail *tail, const void *v, size_t len); void *iov_remove_header_(struct iov_tail *tail, void *v, size_t len, size_t align); ssize_t iov_tail_clone(struct iovec *dst_iov, size_t dst_iov_cnt, struct iov_tail *tail); @@ -112,6 +113,16 @@ ssize_t iov_tail_clone(struct iovec *dst_iov, size_t dst_iov_cnt, sizeof(var_), \ __alignof__(var_)))) +/** + * IOV_PUSH_HEADER() - Write a new header to an IOV tail + * @tail_: IOV tail to write header to + * @var_: A variable containing the header data to write + * + * Return: number of bytes written + */ +#define IOV_PUSH_HEADER(tail_, var_) \ + (iov_push_header_((tail_), &(var_), sizeof(var_))) + /** * IOV_REMOVE_HEADER() - Remove and return typed header from an IOV tail * @tail_: IOV tail to remove header from (modified) -- 2.53.0