aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/skbuff.h13
-rw-r--r--net/ipv4/tcp.c8
-rw-r--r--net/ipv4/tcp_output.c2
3 files changed, 18 insertions, 5 deletions
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 33370271b8b2..70a3f8d49118 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -481,6 +481,7 @@ struct sk_buff {
481 union { 481 union {
482 __u32 mark; 482 __u32 mark;
483 __u32 dropcount; 483 __u32 dropcount;
484 __u32 avail_size;
484 }; 485 };
485 486
486 sk_buff_data_t transport_header; 487 sk_buff_data_t transport_header;
@@ -1366,6 +1367,18 @@ static inline int skb_tailroom(const struct sk_buff *skb)
1366} 1367}
1367 1368
1368/** 1369/**
1370 * skb_availroom - bytes at buffer end
1371 * @skb: buffer to check
1372 *
1373 * Return the number of bytes of free space at the tail of an sk_buff
1374 * allocated by sk_stream_alloc()
1375 */
1376static inline int skb_availroom(const struct sk_buff *skb)
1377{
1378 return skb_is_nonlinear(skb) ? 0 : skb->avail_size - skb->len;
1379}
1380
1381/**
1369 * skb_reserve - adjust headroom 1382 * skb_reserve - adjust headroom
1370 * @skb: buffer to alter 1383 * @skb: buffer to alter
1371 * @len: bytes to move 1384 * @len: bytes to move
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 7758a83f98ff..a5daa211a8e1 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -701,11 +701,12 @@ struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp)
701 skb = alloc_skb_fclone(size + sk->sk_prot->max_header, gfp); 701 skb = alloc_skb_fclone(size + sk->sk_prot->max_header, gfp);
702 if (skb) { 702 if (skb) {
703 if (sk_wmem_schedule(sk, skb->truesize)) { 703 if (sk_wmem_schedule(sk, skb->truesize)) {
704 skb_reserve(skb, sk->sk_prot->max_header);
704 /* 705 /*
705 * Make sure that we have exactly size bytes 706 * Make sure that we have exactly size bytes
706 * available to the caller, no more, no less. 707 * available to the caller, no more, no less.
707 */ 708 */
708 skb_reserve(skb, skb_tailroom(skb) - size); 709 skb->avail_size = size;
709 return skb; 710 return skb;
710 } 711 }
711 __kfree_skb(skb); 712 __kfree_skb(skb);
@@ -995,10 +996,9 @@ new_segment:
995 copy = seglen; 996 copy = seglen;
996 997
997 /* Where to copy to? */ 998 /* Where to copy to? */
998 if (skb_tailroom(skb) > 0) { 999 if (skb_availroom(skb) > 0) {
999 /* We have some space in skb head. Superb! */ 1000 /* We have some space in skb head. Superb! */
1000 if (copy > skb_tailroom(skb)) 1001 copy = min_t(int, copy, skb_availroom(skb));
1001 copy = skb_tailroom(skb);
1002 err = skb_add_data_nocache(sk, skb, from, copy); 1002 err = skb_add_data_nocache(sk, skb, from, copy);
1003 if (err) 1003 if (err)
1004 goto do_fault; 1004 goto do_fault;
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 364784a91939..376b2cfbb685 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -2060,7 +2060,7 @@ static void tcp_retrans_try_collapse(struct sock *sk, struct sk_buff *to,
2060 /* Punt if not enough space exists in the first SKB for 2060 /* Punt if not enough space exists in the first SKB for
2061 * the data in the second 2061 * the data in the second
2062 */ 2062 */
2063 if (skb->len > skb_tailroom(to)) 2063 if (skb->len > skb_availroom(to))
2064 break; 2064 break;
2065 2065
2066 if (after(TCP_SKB_CB(skb)->end_seq, tcp_wnd_end(tp))) 2066 if (after(TCP_SKB_CB(skb)->end_seq, tcp_wnd_end(tp)))