From patchwork Fri Aug 9 08:23:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Hopps X-Patchwork-Id: 13758533 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.chopps.org (smtp.chopps.org [54.88.81.56]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3B37418C326 for ; Fri, 9 Aug 2024 08:24:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.88.81.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723191890; cv=none; b=hKbkWJoiLavO0S4RSA7ptXo3/GT9xKXCP5IqAsF3yDsHsr0EG88u6xUfvnajmElF+AEB49/KP+3FjCrhsMlpeKyzsKN/ZZqmIAqdWR8k/hLJ+QVamI1WeHnxuiTMuMuTHuu7h+RiRj3Gq8j8yw9I4B0t00L2m+DFuMseyN7D7dk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723191890; c=relaxed/simple; bh=cbgTpwOS/qRfqB5SjxeDdukIKfKA58ahGwKHhqhrTEU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Uz4D5eZbn5i3sTWFlx6PE+IPNkxVNaadf8ef5OuE6Q7WMq03r/Q0f3Sf3gpkMqCqEXLUkdhWLzc+DnTRM7fUOa8fEODa3ogMyZUWYHfGgGGT+g+6tQzrPJn8g3XGsygN3u8xedXgUePZzIfLQp4YzRyQw6yaOiflfJUbwioQGkk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=chopps.org; spf=fail smtp.mailfrom=chopps.org; arc=none smtp.client-ip=54.88.81.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=chopps.org Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=chopps.org Received: from labnh.int.chopps.org (syn-172-222-091-149.res.spectrum.com [172.222.91.149]) (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) (Client did not present a certificate) by smtp.chopps.org (Postfix) with ESMTPSA id 507AB7D120; Fri, 9 Aug 2024 08:24:47 +0000 (UTC) From: Christian Hopps To: devel@linux-ipsec.org Cc: Steffen Klassert , netdev@vger.kernel.org, Christian Hopps , Christian Hopps Subject: [PATCH ipsec-next v1 1/2] net: refactor common skb header copy code for re-use Date: Fri, 9 Aug 2024 04:23:13 -0400 Message-ID: <20240809082314.2810408-2-chopps@chopps.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240809082314.2810408-1-chopps@chopps.org> References: <20240809082314.2810408-1-chopps@chopps.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Christian Hopps Factor out some common skb header copying code so that it can be re-used outside of skbuff. Signed-off-by: Christian Hopps --- include/linux/skbuff.h | 1 + net/core/skbuff.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 29c3ea5b6e93..8626f9a343db 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -1374,6 +1374,7 @@ struct sk_buff *skb_morph(struct sk_buff *dst, struct sk_buff *src); void skb_headers_offset_update(struct sk_buff *skb, int off); int skb_copy_ubufs(struct sk_buff *skb, gfp_t gfp_mask); struct sk_buff *skb_clone(struct sk_buff *skb, gfp_t priority); +void ___copy_skb_header(struct sk_buff *new, const struct sk_buff *old); void skb_copy_header(struct sk_buff *new, const struct sk_buff *old); struct sk_buff *skb_copy(const struct sk_buff *skb, gfp_t priority); struct sk_buff *__pskb_copy_fclone(struct sk_buff *skb, int headroom, diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 83f8cd8aa2d1..da5a47d2c9ab 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -1515,7 +1515,7 @@ EXPORT_SYMBOL(napi_consume_skb); BUILD_BUG_ON(offsetof(struct sk_buff, field) != \ offsetof(struct sk_buff, headers.field)); \ -static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old) +void ___copy_skb_header(struct sk_buff *new, const struct sk_buff *old) { new->tstamp = old->tstamp; /* We do not copy old->sk */ @@ -1524,6 +1524,12 @@ static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old) skb_dst_copy(new, old); __skb_ext_copy(new, old); __nf_copy(new, old, false); +} +EXPORT_SYMBOL_GPL(___copy_skb_header); + +static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old) +{ + ___copy_skb_header(new, old); /* Note : this field could be in the headers group. * It is not yet because we do not want to have a 16 bit hole From patchwork Fri Aug 9 08:23:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Hopps X-Patchwork-Id: 13758532 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.chopps.org (smtp.chopps.org [54.88.81.56]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 92B1118CBFA for ; Fri, 9 Aug 2024 08:24:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.88.81.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723191889; cv=none; b=uRiB7cZmoIgEfBDYwOntubT3DJPd0SGPuwIGvUpXpo1HVSRCU2Zi+Fq5npmNtAs45I5zhIQ8rSzl/kC1PZ8QImeUN0QaN+tIndWmlEhBZTsSqHdkpRFWPkONZ2N1DuPoLDnUY63QytY5/L4AZk32+Hh+CQDNhQNnt1u2owCS2yk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723191889; c=relaxed/simple; bh=nF8EzlxLvMJDyF4wqlbQUAdIv70V4gH1PtJSEMY93Qs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dmwjVLmY4978ITAewtuYFcvLGyYvg6rLYfFQdYsYpcidTYFI8Dj+IVuSZXTwjQkXl0z6iKHGYUynat3qGNt17yPRAwGFfdvgv6y/Pluy7fdwjOMA1FfUZvvJFyTNG8DK/OF0XavAxH2QM/xtjXt6b78OklUVoHwvbcDAVnL0Kwc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=chopps.org; spf=fail smtp.mailfrom=chopps.org; arc=none smtp.client-ip=54.88.81.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=chopps.org Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=chopps.org Received: from labnh.int.chopps.org (syn-172-222-091-149.res.spectrum.com [172.222.91.149]) (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) (Client did not present a certificate) by smtp.chopps.org (Postfix) with ESMTPSA id B50BD7D122; Fri, 9 Aug 2024 08:24:47 +0000 (UTC) From: Christian Hopps To: devel@linux-ipsec.org Cc: Steffen Klassert , netdev@vger.kernel.org, Christian Hopps , Christian Hopps Subject: [PATCH ipsec-next v1 2/2] net: add copy from skb_seq_state to buffer function Date: Fri, 9 Aug 2024 04:23:14 -0400 Message-ID: <20240809082314.2810408-3-chopps@chopps.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240809082314.2810408-1-chopps@chopps.org> References: <20240809082314.2810408-1-chopps@chopps.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Christian Hopps Add an skb helper function to copy a range of bytes from within an existing skb_seq_state. Signed-off-by: Christian Hopps --- include/linux/skbuff.h | 1 + net/core/skbuff.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 8626f9a343db..95f80b6d1d7c 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -1434,6 +1434,7 @@ void skb_prepare_seq_read(struct sk_buff *skb, unsigned int from, unsigned int skb_seq_read(unsigned int consumed, const u8 **data, struct skb_seq_state *st); void skb_abort_seq_read(struct skb_seq_state *st); +int skb_copy_seq_read(struct skb_seq_state *st, int offset, void *to, int len); unsigned int skb_find_text(struct sk_buff *skb, unsigned int from, unsigned int to, struct ts_config *config); diff --git a/net/core/skbuff.c b/net/core/skbuff.c index da5a47d2c9ab..2cc2d1b8d356 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -4415,6 +4415,41 @@ void skb_abort_seq_read(struct skb_seq_state *st) } EXPORT_SYMBOL(skb_abort_seq_read); +/** + * skb_copy_seq_read() - copy from a skb_seq_state to a buffer + * @st: source skb_seq_state + * @offset: offset in source + * @to: destination buffer + * @len: number of bytes to copy + * + * Copy @len bytes from @offset bytes into the source @st to the destination + * buffer @to. `offset` should increase (or be unchanged) with each subsequent + * call to this function. If offset needs to decrease from the previous use `st` + * should be reset first. + * + * Return: 0 on success or a negative error code on failure + */ +int skb_copy_seq_read(struct skb_seq_state *st, int offset, void *to, int len) +{ + const u8 *data; + u32 sqlen; + + for (;;) { + sqlen = skb_seq_read(offset, &data, st); + if (sqlen == 0) + return -ENOMEM; + if (sqlen >= len) { + memcpy(to, data, len); + return 0; + } + memcpy(to, data, sqlen); + to += sqlen; + offset += sqlen; + len -= sqlen; + } +} +EXPORT_SYMBOL(skb_copy_seq_read); + #define TS_SKB_CB(state) ((struct skb_seq_state *) &((state)->cb)) static unsigned int skb_ts_get_next_block(unsigned int offset, const u8 **text,