Commit 6602cebb authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

net: skbuff.c cleanup

(skb->data - skb->head) can be changed by skb_headroom(skb)

Remove some uses of NET_SKBUFF_DATA_USES_OFFSET, using
(skb_end_pointer(skb) - skb->head) or
(skb_tail_pointer(skb) - skb->head) : compiler does the right thing,
and this is more readable for us ;)

(struct skb_shared_info *) casts in pskb_expand_head() to help memcpy()
to use aligned moves.
Signed-off-by: default avatarEric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 86cac58b
...@@ -685,16 +685,10 @@ static void copy_skb_header(struct sk_buff *new, const struct sk_buff *old) ...@@ -685,16 +685,10 @@ static void copy_skb_header(struct sk_buff *new, const struct sk_buff *old)
struct sk_buff *skb_copy(const struct sk_buff *skb, gfp_t gfp_mask) struct sk_buff *skb_copy(const struct sk_buff *skb, gfp_t gfp_mask)
{ {
int headerlen = skb->data - skb->head; int headerlen = skb_headroom(skb);
/* unsigned int size = (skb_end_pointer(skb) - skb->head) + skb->data_len;
* Allocate the copy buffer struct sk_buff *n = alloc_skb(size, gfp_mask);
*/
struct sk_buff *n;
#ifdef NET_SKBUFF_DATA_USES_OFFSET
n = alloc_skb(skb->end + skb->data_len, gfp_mask);
#else
n = alloc_skb(skb->end - skb->head + skb->data_len, gfp_mask);
#endif
if (!n) if (!n)
return NULL; return NULL;
...@@ -726,20 +720,14 @@ EXPORT_SYMBOL(skb_copy); ...@@ -726,20 +720,14 @@ EXPORT_SYMBOL(skb_copy);
struct sk_buff *pskb_copy(struct sk_buff *skb, gfp_t gfp_mask) struct sk_buff *pskb_copy(struct sk_buff *skb, gfp_t gfp_mask)
{ {
/* unsigned int size = skb_end_pointer(skb) - skb->head;
* Allocate the copy buffer struct sk_buff *n = alloc_skb(size, gfp_mask);
*/
struct sk_buff *n;
#ifdef NET_SKBUFF_DATA_USES_OFFSET
n = alloc_skb(skb->end, gfp_mask);
#else
n = alloc_skb(skb->end - skb->head, gfp_mask);
#endif
if (!n) if (!n)
goto out; goto out;
/* Set the data pointer */ /* Set the data pointer */
skb_reserve(n, skb->data - skb->head); skb_reserve(n, skb_headroom(skb));
/* Set the tail pointer and length */ /* Set the tail pointer and length */
skb_put(n, skb_headlen(skb)); skb_put(n, skb_headlen(skb));
/* Copy the bytes */ /* Copy the bytes */
...@@ -791,11 +779,7 @@ int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail, ...@@ -791,11 +779,7 @@ int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail,
{ {
int i; int i;
u8 *data; u8 *data;
#ifdef NET_SKBUFF_DATA_USES_OFFSET int size = nhead + (skb_end_pointer(skb) - skb->head) + ntail;
int size = nhead + skb->end + ntail;
#else
int size = nhead + (skb->end - skb->head) + ntail;
#endif
long off; long off;
BUG_ON(nhead < 0); BUG_ON(nhead < 0);
...@@ -810,13 +794,12 @@ int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail, ...@@ -810,13 +794,12 @@ int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail,
goto nodata; goto nodata;
/* Copy only real data... and, alas, header. This should be /* Copy only real data... and, alas, header. This should be
* optimized for the cases when header is void. */ * optimized for the cases when header is void.
#ifdef NET_SKBUFF_DATA_USES_OFFSET */
memcpy(data + nhead, skb->head, skb->tail); memcpy(data + nhead, skb->head, skb_tail_pointer(skb) - skb->head);
#else
memcpy(data + nhead, skb->head, skb->tail - skb->head); memcpy((struct skb_shared_info *)(data + size),
#endif skb_shinfo(skb),
memcpy(data + size, skb_end_pointer(skb),
offsetof(struct skb_shared_info, frags[skb_shinfo(skb)->nr_frags])); offsetof(struct skb_shared_info, frags[skb_shinfo(skb)->nr_frags]));
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
......
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