aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Dumazet <eric.dumazet@gmail.com>2010-09-01 01:25:10 -0400
committerDavid S. Miller <davem@davemloft.net>2010-09-01 13:57:55 -0400
commit6602cebb5bcac1fccf2850541f8bf9fcc8c86dee (patch)
treef3fb30ed089106bf9a5f209edc7b1f9be1338571
parent86cac58b71227cc34a3d0e78f19585c0eff49ea3 (diff)
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: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/core/skbuff.c47
1 files changed, 15 insertions, 32 deletions
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index e2535fb4985d..231dff0dde2e 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -685,16 +685,10 @@ static void copy_skb_header(struct sk_buff *new, const struct sk_buff *old)
685 685
686struct sk_buff *skb_copy(const struct sk_buff *skb, gfp_t gfp_mask) 686struct sk_buff *skb_copy(const struct sk_buff *skb, gfp_t gfp_mask)
687{ 687{
688 int headerlen = skb->data - skb->head; 688 int headerlen = skb_headroom(skb);
689 /* 689 unsigned int size = (skb_end_pointer(skb) - skb->head) + skb->data_len;
690 * Allocate the copy buffer 690 struct sk_buff *n = alloc_skb(size, gfp_mask);
691 */ 691
692 struct sk_buff *n;
693#ifdef NET_SKBUFF_DATA_USES_OFFSET
694 n = alloc_skb(skb->end + skb->data_len, gfp_mask);
695#else
696 n = alloc_skb(skb->end - skb->head + skb->data_len, gfp_mask);
697#endif
698 if (!n) 692 if (!n)
699 return NULL; 693 return NULL;
700 694
@@ -726,20 +720,14 @@ EXPORT_SYMBOL(skb_copy);
726 720
727struct sk_buff *pskb_copy(struct sk_buff *skb, gfp_t gfp_mask) 721struct sk_buff *pskb_copy(struct sk_buff *skb, gfp_t gfp_mask)
728{ 722{
729 /* 723 unsigned int size = skb_end_pointer(skb) - skb->head;
730 * Allocate the copy buffer 724 struct sk_buff *n = alloc_skb(size, gfp_mask);
731 */ 725
732 struct sk_buff *n;
733#ifdef NET_SKBUFF_DATA_USES_OFFSET
734 n = alloc_skb(skb->end, gfp_mask);
735#else
736 n = alloc_skb(skb->end - skb->head, gfp_mask);
737#endif
738 if (!n) 726 if (!n)
739 goto out; 727 goto out;
740 728
741 /* Set the data pointer */ 729 /* Set the data pointer */
742 skb_reserve(n, skb->data - skb->head); 730 skb_reserve(n, skb_headroom(skb));
743 /* Set the tail pointer and length */ 731 /* Set the tail pointer and length */
744 skb_put(n, skb_headlen(skb)); 732 skb_put(n, skb_headlen(skb));
745 /* Copy the bytes */ 733 /* Copy the bytes */
@@ -791,11 +779,7 @@ int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail,
791{ 779{
792 int i; 780 int i;
793 u8 *data; 781 u8 *data;
794#ifdef NET_SKBUFF_DATA_USES_OFFSET 782 int size = nhead + (skb_end_pointer(skb) - skb->head) + ntail;
795 int size = nhead + skb->end + ntail;
796#else
797 int size = nhead + (skb->end - skb->head) + ntail;
798#endif
799 long off; 783 long off;
800 784
801 BUG_ON(nhead < 0); 785 BUG_ON(nhead < 0);
@@ -810,13 +794,12 @@ int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail,
810 goto nodata; 794 goto nodata;
811 795
812 /* Copy only real data... and, alas, header. This should be 796 /* Copy only real data... and, alas, header. This should be
813 * optimized for the cases when header is void. */ 797 * optimized for the cases when header is void.
814#ifdef NET_SKBUFF_DATA_USES_OFFSET 798 */
815 memcpy(data + nhead, skb->head, skb->tail); 799 memcpy(data + nhead, skb->head, skb_tail_pointer(skb) - skb->head);
816#else 800
817 memcpy(data + nhead, skb->head, skb->tail - skb->head); 801 memcpy((struct skb_shared_info *)(data + size),
818#endif 802 skb_shinfo(skb),
819 memcpy(data + size, skb_end_pointer(skb),
820 offsetof(struct skb_shared_info, frags[skb_shinfo(skb)->nr_frags])); 803 offsetof(struct skb_shared_info, frags[skb_shinfo(skb)->nr_frags]));
821 804
822 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) 805 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)