Commit ede57d58 authored by Richard Gobert's avatar Richard Gobert Committed by Jakub Kicinski

net: helper function skb_len_add

Move the len fields manipulation in the skbs to a helper function.
There is a comment specifically requesting this and there are several
other areas in the code displaying the same pattern which can be
refactored.
This improves code readability.
Signed-off-by: default avatarRichard Gobert <richardbgobert@gmail.com>
Link: https://lore.kernel.org/r/20220622160853.GA6478@debianSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 1da9e274
...@@ -2351,6 +2351,18 @@ static inline unsigned int skb_pagelen(const struct sk_buff *skb) ...@@ -2351,6 +2351,18 @@ static inline unsigned int skb_pagelen(const struct sk_buff *skb)
return skb_headlen(skb) + __skb_pagelen(skb); return skb_headlen(skb) + __skb_pagelen(skb);
} }
/**
* skb_len_add - adds a number to len fields of skb
* @skb: buffer to add len to
* @delta: number of bytes to add
*/
static inline void skb_len_add(struct sk_buff *skb, int delta)
{
skb->len += delta;
skb->data_len += delta;
skb->truesize += delta;
}
/** /**
* __skb_fill_page_desc - initialise a paged fragment in an skb * __skb_fill_page_desc - initialise a paged fragment in an skb
* @skb: buffer containing fragment to be initialised * @skb: buffer containing fragment to be initialised
......
...@@ -2219,9 +2219,7 @@ static inline int skb_copy_to_page_nocache(struct sock *sk, struct iov_iter *fro ...@@ -2219,9 +2219,7 @@ static inline int skb_copy_to_page_nocache(struct sock *sk, struct iov_iter *fro
if (err) if (err)
return err; return err;
skb->len += copy; skb_len_add(skb, copy);
skb->data_len += copy;
skb->truesize += copy;
sk_wmem_queued_add(sk, copy); sk_wmem_queued_add(sk, copy);
sk_mem_charge(sk, copy); sk_mem_charge(sk, copy);
return 0; return 0;
......
...@@ -3195,9 +3195,7 @@ skb_zerocopy(struct sk_buff *to, struct sk_buff *from, int len, int hlen) ...@@ -3195,9 +3195,7 @@ skb_zerocopy(struct sk_buff *to, struct sk_buff *from, int len, int hlen)
} }
} }
to->truesize += len + plen; skb_len_add(to, len + plen);
to->len += len + plen;
to->data_len += len + plen;
if (unlikely(skb_orphan_frags(from, GFP_ATOMIC))) { if (unlikely(skb_orphan_frags(from, GFP_ATOMIC))) {
skb_tx_error(from); skb_tx_error(from);
...@@ -3634,13 +3632,8 @@ int skb_shift(struct sk_buff *tgt, struct sk_buff *skb, int shiftlen) ...@@ -3634,13 +3632,8 @@ int skb_shift(struct sk_buff *tgt, struct sk_buff *skb, int shiftlen)
tgt->ip_summed = CHECKSUM_PARTIAL; tgt->ip_summed = CHECKSUM_PARTIAL;
skb->ip_summed = CHECKSUM_PARTIAL; skb->ip_summed = CHECKSUM_PARTIAL;
/* Yak, is it really working this way? Some helper please? */ skb_len_add(skb, -shiftlen);
skb->len -= shiftlen; skb_len_add(tgt, shiftlen);
skb->data_len -= shiftlen;
skb->truesize -= shiftlen;
tgt->len += shiftlen;
tgt->data_len += shiftlen;
tgt->truesize += shiftlen;
return shiftlen; return shiftlen;
} }
......
...@@ -502,9 +502,7 @@ int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info * ...@@ -502,9 +502,7 @@ int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *
nfrags++; nfrags++;
skb->len += tailen; skb_len_add(skb, tailen);
skb->data_len += tailen;
skb->truesize += tailen;
if (sk && sk_fullsock(sk)) if (sk && sk_fullsock(sk))
refcount_add(tailen, &sk->sk_wmem_alloc); refcount_add(tailen, &sk->sk_wmem_alloc);
......
...@@ -1214,9 +1214,7 @@ static int __ip_append_data(struct sock *sk, ...@@ -1214,9 +1214,7 @@ static int __ip_append_data(struct sock *sk,
pfrag->offset += copy; pfrag->offset += copy;
skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], copy); skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], copy);
skb->len += copy; skb_len_add(skb, copy);
skb->data_len += copy;
skb->truesize += copy;
wmem_alloc_delta += copy; wmem_alloc_delta += copy;
} else { } else {
err = skb_zerocopy_iter_dgram(skb, from, copy); err = skb_zerocopy_iter_dgram(skb, from, copy);
...@@ -1443,9 +1441,7 @@ ssize_t ip_append_page(struct sock *sk, struct flowi4 *fl4, struct page *page, ...@@ -1443,9 +1441,7 @@ ssize_t ip_append_page(struct sock *sk, struct flowi4 *fl4, struct page *page,
skb->csum = csum_block_add(skb->csum, csum, skb->len); skb->csum = csum_block_add(skb->csum, csum, skb->len);
} }
skb->len += len; skb_len_add(skb, len);
skb->data_len += len;
skb->truesize += len;
refcount_add(len, &sk->sk_wmem_alloc); refcount_add(len, &sk->sk_wmem_alloc);
offset += len; offset += len;
size -= len; size -= len;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment