aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorHerbert Xu ~{PmVHI~} <herbert@gondor.apana.org.au>2006-06-05 18:03:37 -0400
committerDavid S. Miller <davem@davemloft.net>2006-06-05 18:03:37 -0400
commitf291196979ca80cdef199ca2b55e2758e8c23a0d (patch)
treeb1dc4a5390d8bf2f2ab486b8b6a8e3a6297cf4e7 /net
parent364212e0df05efee43d87270b476fc5c9ad2c651 (diff)
[TCP]: Avoid skb_pull if possible when trimming head
Trimming the head of an skb by calling skb_pull can cause the packet to become unaligned if the length pulled is odd. Since the length is entirely arbitrary for a FIN packet carrying data, this is actually quite common. Unaligned data is not the end of the world, but we should avoid it if it's easily done. In this case it is trivial. Since we're discarding all of the head data it doesn't matter whether we move skb->data forward or back. However, it is still possible to have unaligned skb->data in general. So network drivers should be prepared to handle it instead of crashing. This patch also adds an unlikely marking on len < headlen since partial ACKs on head data are extremely rare in the wild. As the return value of __pskb_trim_head is no longer ever NULL that has been removed. Signed-off-by: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/ipv4/tcp_output.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 743016baa048..f33c9dddaa12 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -642,7 +642,7 @@ int tcp_fragment(struct sock *sk, struct sk_buff *skb, u32 len, unsigned int mss
642 * eventually). The difference is that pulled data not copied, but 642 * eventually). The difference is that pulled data not copied, but
643 * immediately discarded. 643 * immediately discarded.
644 */ 644 */
645static unsigned char *__pskb_trim_head(struct sk_buff *skb, int len) 645static void __pskb_trim_head(struct sk_buff *skb, int len)
646{ 646{
647 int i, k, eat; 647 int i, k, eat;
648 648
@@ -667,7 +667,6 @@ static unsigned char *__pskb_trim_head(struct sk_buff *skb, int len)
667 skb->tail = skb->data; 667 skb->tail = skb->data;
668 skb->data_len -= len; 668 skb->data_len -= len;
669 skb->len = skb->data_len; 669 skb->len = skb->data_len;
670 return skb->tail;
671} 670}
672 671
673int tcp_trim_head(struct sock *sk, struct sk_buff *skb, u32 len) 672int tcp_trim_head(struct sock *sk, struct sk_buff *skb, u32 len)
@@ -676,12 +675,11 @@ int tcp_trim_head(struct sock *sk, struct sk_buff *skb, u32 len)
676 pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) 675 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
677 return -ENOMEM; 676 return -ENOMEM;
678 677
679 if (len <= skb_headlen(skb)) { 678 /* If len == headlen, we avoid __skb_pull to preserve alignment. */
679 if (unlikely(len < skb_headlen(skb)))
680 __skb_pull(skb, len); 680 __skb_pull(skb, len);
681 } else { 681 else
682 if (__pskb_trim_head(skb, len-skb_headlen(skb)) == NULL) 682 __pskb_trim_head(skb, len - skb_headlen(skb));
683 return -ENOMEM;
684 }
685 683
686 TCP_SKB_CB(skb)->seq += len; 684 TCP_SKB_CB(skb)->seq += len;
687 skb->ip_summed = CHECKSUM_HW; 685 skb->ip_summed = CHECKSUM_HW;