net: add copy from skb_seq_state to buffer function
Subsystems (2)
PATCH v4 1/1 net: add copy from skb_seq_state to buffer function
From: Christian Hopps <[email protected]>
Add an skb helper function to copy a range of bytes from within an existing skb_seq_state.
---
This is used in a followup patchset implementing IP-TFS/AggFrag encapsulation (https://www.rfc-editor.org/rfc/rfc9347.txt)
Patchset History:
v1 (8/9/2024)
- Created from IP-TFS patchset v9
v2 (8/9/2024)
- resend with corrected CC list.
v3 (8/15/2024)
- removed ___copy_skb_header refactoring
v4 (8/15/2024)
- change returned error from -ENOMEM to -EINVAL
--- include/linux/skbuff.h | 1 + net/core/skbuff.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+)
include/linux/skbuff.h +1 -0
@@ -1433,6 +1433,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);
net/core/skbuff.c +35 -0
@@ -4409,6 +4409,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 -EINVAL if the copy ended early +*/ +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 -EINVAL ; +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,
Signature · 1 line
2.46.0
Steffen Klassert
AppliedQuoted 21 lines · Christian Hopps
From: Christian Hopps <[email protected]>
Add an skb helper function to copy a range of bytes from within an existing
skb_seq_state.Signed-off-by Christian Hopps <[email protected]>---
This is used in a followup patchset implementing IP-TFS/AggFrag encapsulation (https://www.rfc-editor.org/rfc/rfc9347.txt)Patchset History:
v1 (8/9/2024)
- Created from IP-TFS patchset v9v2 (8/9/2024)
- resend with corrected CC list.v3 (8/15/2024)
- removed___copy_skb_headerrefactoring
Quoted 6 lines
v4 (8/15/2024)
- change returned error from-ENOMEMto-EINVAL--- include/linux/skbuff.h | 1 + net/core/skbuff.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+)
Applied, thanks Chris!
Looking forward to the IP-TFS pachset...