summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-01-08 16:59:02 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-01-23 15:49:56 +0100
commit8e6f5a1d3bd462ff54cdb86f2938bfaa4223ccc9 (patch)
tree17b45bd4ccfdec3592f0f1a3becc3d62948804b8 /include
parent4d1d3dddcb3f26000e66cd0a9b8b16f7c2eb41bb (diff)
downloadlinux-stable-8e6f5a1d3bd462ff54cdb86f2938bfaa4223ccc9.tar.gz
linux-stable-8e6f5a1d3bd462ff54cdb86f2938bfaa4223ccc9.tar.bz2
linux-stable-8e6f5a1d3bd462ff54cdb86f2938bfaa4223ccc9.zip
net: introduce skb_list_walk_safe for skb segment walking
commit dcfea72e79b0aa7a057c8f6024169d86a1bbc84b upstream. As part of the continual effort to remove direct usage of skb->next and skb->prev, this patch adds a helper for iterating through the singly-linked variant of skb lists, which are used for lists of GSO packet. The name "skb_list_..." has been chosen to match the existing function, "kfree_skb_list, which also operates on these singly-linked lists, and the "..._walk_safe" part is the same idiom as elsewhere in the kernel. This patch removes the helper from wireguard and puts it into linux/skbuff.h, while making it a bit more robust for general usage. In particular, parenthesis are added around the macro argument usage, and it now accounts for trying to iterate through an already-null skb pointer, which will simply run the iteration zero times. This latter enhancement means it can be used to replace both do { ... } while and while (...) open-coded idioms. This should take care of these three possible usages, which match all current methods of iterations. skb_list_walk_safe(segs, skb, next) { ... } skb_list_walk_safe(skb, skb, next) { ... } skb_list_walk_safe(segs, skb, segs) { ... } Gcc appears to generate efficient code for each of these. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: David S. Miller <davem@davemloft.net> [ Just the skbuff.h changes for backporting - gregkh] Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include')
-rw-r--r--include/linux/skbuff.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 703ce71caeac..881038a0e1c8 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -1363,6 +1363,11 @@ static inline void skb_mark_not_on_list(struct sk_buff *skb)
skb->next = NULL;
}
+/* Iterate through singly-linked GSO fragments of an skb. */
+#define skb_list_walk_safe(first, skb, next) \
+ for ((skb) = (first), (next) = (skb) ? (skb)->next : NULL; (skb); \
+ (skb) = (next), (next) = (skb) ? (skb)->next : NULL)
+
static inline void skb_list_del_init(struct sk_buff *skb)
{
__list_del_entry(&skb->list);