aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/tcp_output.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv4/tcp_output.c')
-rw-r--r--net/ipv4/tcp_output.c146
1 files changed, 76 insertions, 70 deletions
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 383ce237640f..de3bd8458588 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -37,6 +37,7 @@
37#include <net/tcp.h> 37#include <net/tcp.h>
38 38
39#include <linux/compiler.h> 39#include <linux/compiler.h>
40#include <linux/gfp.h>
40#include <linux/module.h> 41#include <linux/module.h>
41 42
42/* People can turn this off for buggy TCP's found in printers etc. */ 43/* People can turn this off for buggy TCP's found in printers etc. */
@@ -183,7 +184,8 @@ static inline void tcp_event_ack_sent(struct sock *sk, unsigned int pkts)
183 */ 184 */
184void tcp_select_initial_window(int __space, __u32 mss, 185void tcp_select_initial_window(int __space, __u32 mss,
185 __u32 *rcv_wnd, __u32 *window_clamp, 186 __u32 *rcv_wnd, __u32 *window_clamp,
186 int wscale_ok, __u8 *rcv_wscale) 187 int wscale_ok, __u8 *rcv_wscale,
188 __u32 init_rcv_wnd)
187{ 189{
188 unsigned int space = (__space < 0 ? 0 : __space); 190 unsigned int space = (__space < 0 ? 0 : __space);
189 191
@@ -232,13 +234,20 @@ void tcp_select_initial_window(int __space, __u32 mss,
232 init_cwnd = 2; 234 init_cwnd = 2;
233 else if (mss > 1460) 235 else if (mss > 1460)
234 init_cwnd = 3; 236 init_cwnd = 3;
235 if (*rcv_wnd > init_cwnd * mss) 237 /* when initializing use the value from init_rcv_wnd
238 * rather than the default from above
239 */
240 if (init_rcv_wnd &&
241 (*rcv_wnd > init_rcv_wnd * mss))
242 *rcv_wnd = init_rcv_wnd * mss;
243 else if (*rcv_wnd > init_cwnd * mss)
236 *rcv_wnd = init_cwnd * mss; 244 *rcv_wnd = init_cwnd * mss;
237 } 245 }
238 246
239 /* Set the clamp no higher than max representable value */ 247 /* Set the clamp no higher than max representable value */
240 (*window_clamp) = min(65535U << (*rcv_wscale), *window_clamp); 248 (*window_clamp) = min(65535U << (*rcv_wscale), *window_clamp);
241} 249}
250EXPORT_SYMBOL(tcp_select_initial_window);
242 251
243/* Chose a new window to advertise, update state in tcp_sock for the 252/* Chose a new window to advertise, update state in tcp_sock for the
244 * socket, and return result with RFC1323 scaling applied. The return 253 * socket, and return result with RFC1323 scaling applied. The return
@@ -286,9 +295,9 @@ static u16 tcp_select_window(struct sock *sk)
286/* Packet ECN state for a SYN-ACK */ 295/* Packet ECN state for a SYN-ACK */
287static inline void TCP_ECN_send_synack(struct tcp_sock *tp, struct sk_buff *skb) 296static inline void TCP_ECN_send_synack(struct tcp_sock *tp, struct sk_buff *skb)
288{ 297{
289 TCP_SKB_CB(skb)->flags &= ~TCPCB_FLAG_CWR; 298 TCP_SKB_CB(skb)->flags &= ~TCPHDR_CWR;
290 if (!(tp->ecn_flags & TCP_ECN_OK)) 299 if (!(tp->ecn_flags & TCP_ECN_OK))
291 TCP_SKB_CB(skb)->flags &= ~TCPCB_FLAG_ECE; 300 TCP_SKB_CB(skb)->flags &= ~TCPHDR_ECE;
292} 301}
293 302
294/* Packet ECN state for a SYN. */ 303/* Packet ECN state for a SYN. */
@@ -298,7 +307,7 @@ static inline void TCP_ECN_send_syn(struct sock *sk, struct sk_buff *skb)
298 307
299 tp->ecn_flags = 0; 308 tp->ecn_flags = 0;
300 if (sysctl_tcp_ecn == 1) { 309 if (sysctl_tcp_ecn == 1) {
301 TCP_SKB_CB(skb)->flags |= TCPCB_FLAG_ECE | TCPCB_FLAG_CWR; 310 TCP_SKB_CB(skb)->flags |= TCPHDR_ECE | TCPHDR_CWR;
302 tp->ecn_flags = TCP_ECN_OK; 311 tp->ecn_flags = TCP_ECN_OK;
303 } 312 }
304} 313}
@@ -342,6 +351,7 @@ static inline void TCP_ECN_send(struct sock *sk, struct sk_buff *skb,
342 */ 351 */
343static void tcp_init_nondata_skb(struct sk_buff *skb, u32 seq, u8 flags) 352static void tcp_init_nondata_skb(struct sk_buff *skb, u32 seq, u8 flags)
344{ 353{
354 skb->ip_summed = CHECKSUM_PARTIAL;
345 skb->csum = 0; 355 skb->csum = 0;
346 356
347 TCP_SKB_CB(skb)->flags = flags; 357 TCP_SKB_CB(skb)->flags = flags;
@@ -352,7 +362,7 @@ static void tcp_init_nondata_skb(struct sk_buff *skb, u32 seq, u8 flags)
352 skb_shinfo(skb)->gso_type = 0; 362 skb_shinfo(skb)->gso_type = 0;
353 363
354 TCP_SKB_CB(skb)->seq = seq; 364 TCP_SKB_CB(skb)->seq = seq;
355 if (flags & (TCPCB_FLAG_SYN | TCPCB_FLAG_FIN)) 365 if (flags & (TCPHDR_SYN | TCPHDR_FIN))
356 seq++; 366 seq++;
357 TCP_SKB_CB(skb)->end_seq = seq; 367 TCP_SKB_CB(skb)->end_seq = seq;
358} 368}
@@ -659,7 +669,6 @@ static unsigned tcp_synack_options(struct sock *sk,
659 u8 cookie_plus = (xvp != NULL && !xvp->cookie_out_never) ? 669 u8 cookie_plus = (xvp != NULL && !xvp->cookie_out_never) ?
660 xvp->cookie_plus : 670 xvp->cookie_plus :
661 0; 671 0;
662 bool doing_ts = ireq->tstamp_ok;
663 672
664#ifdef CONFIG_TCP_MD5SIG 673#ifdef CONFIG_TCP_MD5SIG
665 *md5 = tcp_rsk(req)->af_specific->md5_lookup(sk, req); 674 *md5 = tcp_rsk(req)->af_specific->md5_lookup(sk, req);
@@ -672,7 +681,7 @@ static unsigned tcp_synack_options(struct sock *sk,
672 * rather than TS in order to fit in better with old, 681 * rather than TS in order to fit in better with old,
673 * buggy kernels, but that was deemed to be unnecessary. 682 * buggy kernels, but that was deemed to be unnecessary.
674 */ 683 */
675 doing_ts &= !ireq->sack_ok; 684 ireq->tstamp_ok &= !ireq->sack_ok;
676 } 685 }
677#else 686#else
678 *md5 = NULL; 687 *md5 = NULL;
@@ -687,7 +696,7 @@ static unsigned tcp_synack_options(struct sock *sk,
687 opts->options |= OPTION_WSCALE; 696 opts->options |= OPTION_WSCALE;
688 remaining -= TCPOLEN_WSCALE_ALIGNED; 697 remaining -= TCPOLEN_WSCALE_ALIGNED;
689 } 698 }
690 if (likely(doing_ts)) { 699 if (likely(ireq->tstamp_ok)) {
691 opts->options |= OPTION_TS; 700 opts->options |= OPTION_TS;
692 opts->tsval = TCP_SKB_CB(skb)->when; 701 opts->tsval = TCP_SKB_CB(skb)->when;
693 opts->tsecr = req->ts_recent; 702 opts->tsecr = req->ts_recent;
@@ -695,7 +704,7 @@ static unsigned tcp_synack_options(struct sock *sk,
695 } 704 }
696 if (likely(ireq->sack_ok)) { 705 if (likely(ireq->sack_ok)) {
697 opts->options |= OPTION_SACK_ADVERTISE; 706 opts->options |= OPTION_SACK_ADVERTISE;
698 if (unlikely(!doing_ts)) 707 if (unlikely(!ireq->tstamp_ok))
699 remaining -= TCPOLEN_SACKPERM_ALIGNED; 708 remaining -= TCPOLEN_SACKPERM_ALIGNED;
700 } 709 }
701 710
@@ -703,7 +712,7 @@ static unsigned tcp_synack_options(struct sock *sk,
703 * If the <SYN> options fit, the same options should fit now! 712 * If the <SYN> options fit, the same options should fit now!
704 */ 713 */
705 if (*md5 == NULL && 714 if (*md5 == NULL &&
706 doing_ts && 715 ireq->tstamp_ok &&
707 cookie_plus > TCPOLEN_COOKIE_BASE) { 716 cookie_plus > TCPOLEN_COOKIE_BASE) {
708 int need = cookie_plus; /* has TCPOLEN_COOKIE_BASE */ 717 int need = cookie_plus; /* has TCPOLEN_COOKIE_BASE */
709 718
@@ -812,7 +821,7 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it,
812 tcb = TCP_SKB_CB(skb); 821 tcb = TCP_SKB_CB(skb);
813 memset(&opts, 0, sizeof(opts)); 822 memset(&opts, 0, sizeof(opts));
814 823
815 if (unlikely(tcb->flags & TCPCB_FLAG_SYN)) 824 if (unlikely(tcb->flags & TCPHDR_SYN))
816 tcp_options_size = tcp_syn_options(sk, skb, &opts, &md5); 825 tcp_options_size = tcp_syn_options(sk, skb, &opts, &md5);
817 else 826 else
818 tcp_options_size = tcp_established_options(sk, skb, &opts, 827 tcp_options_size = tcp_established_options(sk, skb, &opts,
@@ -835,7 +844,7 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it,
835 *(((__be16 *)th) + 6) = htons(((tcp_header_size >> 2) << 12) | 844 *(((__be16 *)th) + 6) = htons(((tcp_header_size >> 2) << 12) |
836 tcb->flags); 845 tcb->flags);
837 846
838 if (unlikely(tcb->flags & TCPCB_FLAG_SYN)) { 847 if (unlikely(tcb->flags & TCPHDR_SYN)) {
839 /* RFC1323: The window in SYN & SYN/ACK segments 848 /* RFC1323: The window in SYN & SYN/ACK segments
840 * is never scaled. 849 * is never scaled.
841 */ 850 */
@@ -852,36 +861,37 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it,
852 th->urg_ptr = htons(tp->snd_up - tcb->seq); 861 th->urg_ptr = htons(tp->snd_up - tcb->seq);
853 th->urg = 1; 862 th->urg = 1;
854 } else if (after(tcb->seq + 0xFFFF, tp->snd_nxt)) { 863 } else if (after(tcb->seq + 0xFFFF, tp->snd_nxt)) {
855 th->urg_ptr = 0xFFFF; 864 th->urg_ptr = htons(0xFFFF);
856 th->urg = 1; 865 th->urg = 1;
857 } 866 }
858 } 867 }
859 868
860 tcp_options_write((__be32 *)(th + 1), tp, &opts); 869 tcp_options_write((__be32 *)(th + 1), tp, &opts);
861 if (likely((tcb->flags & TCPCB_FLAG_SYN) == 0)) 870 if (likely((tcb->flags & TCPHDR_SYN) == 0))
862 TCP_ECN_send(sk, skb, tcp_header_size); 871 TCP_ECN_send(sk, skb, tcp_header_size);
863 872
864#ifdef CONFIG_TCP_MD5SIG 873#ifdef CONFIG_TCP_MD5SIG
865 /* Calculate the MD5 hash, as we have all we need now */ 874 /* Calculate the MD5 hash, as we have all we need now */
866 if (md5) { 875 if (md5) {
867 sk->sk_route_caps &= ~NETIF_F_GSO_MASK; 876 sk_nocaps_add(sk, NETIF_F_GSO_MASK);
868 tp->af_specific->calc_md5_hash(opts.hash_location, 877 tp->af_specific->calc_md5_hash(opts.hash_location,
869 md5, sk, NULL, skb); 878 md5, sk, NULL, skb);
870 } 879 }
871#endif 880#endif
872 881
873 icsk->icsk_af_ops->send_check(sk, skb->len, skb); 882 icsk->icsk_af_ops->send_check(sk, skb);
874 883
875 if (likely(tcb->flags & TCPCB_FLAG_ACK)) 884 if (likely(tcb->flags & TCPHDR_ACK))
876 tcp_event_ack_sent(sk, tcp_skb_pcount(skb)); 885 tcp_event_ack_sent(sk, tcp_skb_pcount(skb));
877 886
878 if (skb->len != tcp_header_size) 887 if (skb->len != tcp_header_size)
879 tcp_event_data_sent(tp, skb, sk); 888 tcp_event_data_sent(tp, skb, sk);
880 889
881 if (after(tcb->end_seq, tp->snd_nxt) || tcb->seq == tcb->end_seq) 890 if (after(tcb->end_seq, tp->snd_nxt) || tcb->seq == tcb->end_seq)
882 TCP_INC_STATS(sock_net(sk), TCP_MIB_OUTSEGS); 891 TCP_ADD_STATS(sock_net(sk), TCP_MIB_OUTSEGS,
892 tcp_skb_pcount(skb));
883 893
884 err = icsk->icsk_af_ops->queue_xmit(skb, 0); 894 err = icsk->icsk_af_ops->queue_xmit(skb);
885 if (likely(err <= 0)) 895 if (likely(err <= 0))
886 return err; 896 return err;
887 897
@@ -1014,7 +1024,7 @@ int tcp_fragment(struct sock *sk, struct sk_buff *skb, u32 len,
1014 1024
1015 /* PSH and FIN should only be set in the second packet. */ 1025 /* PSH and FIN should only be set in the second packet. */
1016 flags = TCP_SKB_CB(skb)->flags; 1026 flags = TCP_SKB_CB(skb)->flags;
1017 TCP_SKB_CB(skb)->flags = flags & ~(TCPCB_FLAG_FIN | TCPCB_FLAG_PSH); 1027 TCP_SKB_CB(skb)->flags = flags & ~(TCPHDR_FIN | TCPHDR_PSH);
1018 TCP_SKB_CB(buff)->flags = flags; 1028 TCP_SKB_CB(buff)->flags = flags;
1019 TCP_SKB_CB(buff)->sacked = TCP_SKB_CB(skb)->sacked; 1029 TCP_SKB_CB(buff)->sacked = TCP_SKB_CB(skb)->sacked;
1020 1030
@@ -1180,6 +1190,7 @@ void tcp_mtup_init(struct sock *sk)
1180 icsk->icsk_mtup.search_low = tcp_mss_to_mtu(sk, sysctl_tcp_base_mss); 1190 icsk->icsk_mtup.search_low = tcp_mss_to_mtu(sk, sysctl_tcp_base_mss);
1181 icsk->icsk_mtup.probe_size = 0; 1191 icsk->icsk_mtup.probe_size = 0;
1182} 1192}
1193EXPORT_SYMBOL(tcp_mtup_init);
1183 1194
1184/* This function synchronize snd mss to current pmtu/exthdr set. 1195/* This function synchronize snd mss to current pmtu/exthdr set.
1185 1196
@@ -1223,6 +1234,7 @@ unsigned int tcp_sync_mss(struct sock *sk, u32 pmtu)
1223 1234
1224 return mss_now; 1235 return mss_now;
1225} 1236}
1237EXPORT_SYMBOL(tcp_sync_mss);
1226 1238
1227/* Compute the current effective MSS, taking SACKs and IP options, 1239/* Compute the current effective MSS, taking SACKs and IP options,
1228 * and even PMTU discovery events into account. 1240 * and even PMTU discovery events into account.
@@ -1319,8 +1331,7 @@ static inline unsigned int tcp_cwnd_test(struct tcp_sock *tp,
1319 u32 in_flight, cwnd; 1331 u32 in_flight, cwnd;
1320 1332
1321 /* Don't be strict about the congestion window for the final FIN. */ 1333 /* Don't be strict about the congestion window for the final FIN. */
1322 if ((TCP_SKB_CB(skb)->flags & TCPCB_FLAG_FIN) && 1334 if ((TCP_SKB_CB(skb)->flags & TCPHDR_FIN) && tcp_skb_pcount(skb) == 1)
1323 tcp_skb_pcount(skb) == 1)
1324 return 1; 1335 return 1;
1325 1336
1326 in_flight = tcp_packets_in_flight(tp); 1337 in_flight = tcp_packets_in_flight(tp);
@@ -1389,7 +1400,7 @@ static inline int tcp_nagle_test(struct tcp_sock *tp, struct sk_buff *skb,
1389 * Nagle can be ignored during F-RTO too (see RFC4138). 1400 * Nagle can be ignored during F-RTO too (see RFC4138).
1390 */ 1401 */
1391 if (tcp_urg_mode(tp) || (tp->frto_counter == 2) || 1402 if (tcp_urg_mode(tp) || (tp->frto_counter == 2) ||
1392 (TCP_SKB_CB(skb)->flags & TCPCB_FLAG_FIN)) 1403 (TCP_SKB_CB(skb)->flags & TCPHDR_FIN))
1393 return 1; 1404 return 1;
1394 1405
1395 if (!tcp_nagle_check(tp, skb, cur_mss, nonagle)) 1406 if (!tcp_nagle_check(tp, skb, cur_mss, nonagle))
@@ -1452,7 +1463,7 @@ int tcp_may_send_now(struct sock *sk)
1452 * packet has never been sent out before (and thus is not cloned). 1463 * packet has never been sent out before (and thus is not cloned).
1453 */ 1464 */
1454static int tso_fragment(struct sock *sk, struct sk_buff *skb, unsigned int len, 1465static int tso_fragment(struct sock *sk, struct sk_buff *skb, unsigned int len,
1455 unsigned int mss_now) 1466 unsigned int mss_now, gfp_t gfp)
1456{ 1467{
1457 struct sk_buff *buff; 1468 struct sk_buff *buff;
1458 int nlen = skb->len - len; 1469 int nlen = skb->len - len;
@@ -1462,7 +1473,7 @@ static int tso_fragment(struct sock *sk, struct sk_buff *skb, unsigned int len,
1462 if (skb->len != skb->data_len) 1473 if (skb->len != skb->data_len)
1463 return tcp_fragment(sk, skb, len, mss_now); 1474 return tcp_fragment(sk, skb, len, mss_now);
1464 1475
1465 buff = sk_stream_alloc_skb(sk, 0, GFP_ATOMIC); 1476 buff = sk_stream_alloc_skb(sk, 0, gfp);
1466 if (unlikely(buff == NULL)) 1477 if (unlikely(buff == NULL))
1467 return -ENOMEM; 1478 return -ENOMEM;
1468 1479
@@ -1478,7 +1489,7 @@ static int tso_fragment(struct sock *sk, struct sk_buff *skb, unsigned int len,
1478 1489
1479 /* PSH and FIN should only be set in the second packet. */ 1490 /* PSH and FIN should only be set in the second packet. */
1480 flags = TCP_SKB_CB(skb)->flags; 1491 flags = TCP_SKB_CB(skb)->flags;
1481 TCP_SKB_CB(skb)->flags = flags & ~(TCPCB_FLAG_FIN | TCPCB_FLAG_PSH); 1492 TCP_SKB_CB(skb)->flags = flags & ~(TCPHDR_FIN | TCPHDR_PSH);
1482 TCP_SKB_CB(buff)->flags = flags; 1493 TCP_SKB_CB(buff)->flags = flags;
1483 1494
1484 /* This packet was never sent out yet, so no SACK bits. */ 1495 /* This packet was never sent out yet, so no SACK bits. */
@@ -1509,7 +1520,7 @@ static int tcp_tso_should_defer(struct sock *sk, struct sk_buff *skb)
1509 const struct inet_connection_sock *icsk = inet_csk(sk); 1520 const struct inet_connection_sock *icsk = inet_csk(sk);
1510 u32 send_win, cong_win, limit, in_flight; 1521 u32 send_win, cong_win, limit, in_flight;
1511 1522
1512 if (TCP_SKB_CB(skb)->flags & TCPCB_FLAG_FIN) 1523 if (TCP_SKB_CB(skb)->flags & TCPHDR_FIN)
1513 goto send_now; 1524 goto send_now;
1514 1525
1515 if (icsk->icsk_ca_state != TCP_CA_Open) 1526 if (icsk->icsk_ca_state != TCP_CA_Open)
@@ -1635,7 +1646,7 @@ static int tcp_mtu_probe(struct sock *sk)
1635 1646
1636 TCP_SKB_CB(nskb)->seq = TCP_SKB_CB(skb)->seq; 1647 TCP_SKB_CB(nskb)->seq = TCP_SKB_CB(skb)->seq;
1637 TCP_SKB_CB(nskb)->end_seq = TCP_SKB_CB(skb)->seq + probe_size; 1648 TCP_SKB_CB(nskb)->end_seq = TCP_SKB_CB(skb)->seq + probe_size;
1638 TCP_SKB_CB(nskb)->flags = TCPCB_FLAG_ACK; 1649 TCP_SKB_CB(nskb)->flags = TCPHDR_ACK;
1639 TCP_SKB_CB(nskb)->sacked = 0; 1650 TCP_SKB_CB(nskb)->sacked = 0;
1640 nskb->csum = 0; 1651 nskb->csum = 0;
1641 nskb->ip_summed = skb->ip_summed; 1652 nskb->ip_summed = skb->ip_summed;
@@ -1660,7 +1671,7 @@ static int tcp_mtu_probe(struct sock *sk)
1660 sk_wmem_free_skb(sk, skb); 1671 sk_wmem_free_skb(sk, skb);
1661 } else { 1672 } else {
1662 TCP_SKB_CB(nskb)->flags |= TCP_SKB_CB(skb)->flags & 1673 TCP_SKB_CB(nskb)->flags |= TCP_SKB_CB(skb)->flags &
1663 ~(TCPCB_FLAG_FIN|TCPCB_FLAG_PSH); 1674 ~(TCPHDR_FIN|TCPHDR_PSH);
1664 if (!skb_shinfo(skb)->nr_frags) { 1675 if (!skb_shinfo(skb)->nr_frags) {
1665 skb_pull(skb, copy); 1676 skb_pull(skb, copy);
1666 if (skb->ip_summed != CHECKSUM_PARTIAL) 1677 if (skb->ip_summed != CHECKSUM_PARTIAL)
@@ -1760,7 +1771,7 @@ static int tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle,
1760 cwnd_quota); 1771 cwnd_quota);
1761 1772
1762 if (skb->len > limit && 1773 if (skb->len > limit &&
1763 unlikely(tso_fragment(sk, skb, limit, mss_now))) 1774 unlikely(tso_fragment(sk, skb, limit, mss_now, gfp)))
1764 break; 1775 break;
1765 1776
1766 TCP_SKB_CB(skb)->when = tcp_time_stamp; 1777 TCP_SKB_CB(skb)->when = tcp_time_stamp;
@@ -1794,11 +1805,6 @@ static int tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle,
1794void __tcp_push_pending_frames(struct sock *sk, unsigned int cur_mss, 1805void __tcp_push_pending_frames(struct sock *sk, unsigned int cur_mss,
1795 int nonagle) 1806 int nonagle)
1796{ 1807{
1797 struct sk_buff *skb = tcp_send_head(sk);
1798
1799 if (!skb)
1800 return;
1801
1802 /* If we are closed, the bytes will have to remain here. 1808 /* If we are closed, the bytes will have to remain here.
1803 * In time closedown will finish, we empty the write queue and 1809 * In time closedown will finish, we empty the write queue and
1804 * all will be happy. 1810 * all will be happy.
@@ -2016,7 +2022,7 @@ static void tcp_retrans_try_collapse(struct sock *sk, struct sk_buff *to,
2016 2022
2017 if (!sysctl_tcp_retrans_collapse) 2023 if (!sysctl_tcp_retrans_collapse)
2018 return; 2024 return;
2019 if (TCP_SKB_CB(skb)->flags & TCPCB_FLAG_SYN) 2025 if (TCP_SKB_CB(skb)->flags & TCPHDR_SYN)
2020 return; 2026 return;
2021 2027
2022 tcp_for_write_queue_from_safe(skb, tmp, sk) { 2028 tcp_for_write_queue_from_safe(skb, tmp, sk) {
@@ -2108,7 +2114,7 @@ int tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb)
2108 * since it is cheap to do so and saves bytes on the network. 2114 * since it is cheap to do so and saves bytes on the network.
2109 */ 2115 */
2110 if (skb->len > 0 && 2116 if (skb->len > 0 &&
2111 (TCP_SKB_CB(skb)->flags & TCPCB_FLAG_FIN) && 2117 (TCP_SKB_CB(skb)->flags & TCPHDR_FIN) &&
2112 tp->snd_una == (TCP_SKB_CB(skb)->end_seq - 1)) { 2118 tp->snd_una == (TCP_SKB_CB(skb)->end_seq - 1)) {
2113 if (!pskb_trim(skb, 0)) { 2119 if (!pskb_trim(skb, 0)) {
2114 /* Reuse, even though it does some unnecessary work */ 2120 /* Reuse, even though it does some unnecessary work */
@@ -2204,6 +2210,9 @@ void tcp_xmit_retransmit_queue(struct sock *sk)
2204 int mib_idx; 2210 int mib_idx;
2205 int fwd_rexmitting = 0; 2211 int fwd_rexmitting = 0;
2206 2212
2213 if (!tp->packets_out)
2214 return;
2215
2207 if (!tp->lost_out) 2216 if (!tp->lost_out)
2208 tp->retransmit_high = tp->snd_una; 2217 tp->retransmit_high = tp->snd_una;
2209 2218
@@ -2297,7 +2306,7 @@ void tcp_send_fin(struct sock *sk)
2297 mss_now = tcp_current_mss(sk); 2306 mss_now = tcp_current_mss(sk);
2298 2307
2299 if (tcp_send_head(sk) != NULL) { 2308 if (tcp_send_head(sk) != NULL) {
2300 TCP_SKB_CB(skb)->flags |= TCPCB_FLAG_FIN; 2309 TCP_SKB_CB(skb)->flags |= TCPHDR_FIN;
2301 TCP_SKB_CB(skb)->end_seq++; 2310 TCP_SKB_CB(skb)->end_seq++;
2302 tp->write_seq++; 2311 tp->write_seq++;
2303 } else { 2312 } else {
@@ -2314,7 +2323,7 @@ void tcp_send_fin(struct sock *sk)
2314 skb_reserve(skb, MAX_TCP_HEADER); 2323 skb_reserve(skb, MAX_TCP_HEADER);
2315 /* FIN eats a sequence byte, write_seq advanced by tcp_queue_skb(). */ 2324 /* FIN eats a sequence byte, write_seq advanced by tcp_queue_skb(). */
2316 tcp_init_nondata_skb(skb, tp->write_seq, 2325 tcp_init_nondata_skb(skb, tp->write_seq,
2317 TCPCB_FLAG_ACK | TCPCB_FLAG_FIN); 2326 TCPHDR_ACK | TCPHDR_FIN);
2318 tcp_queue_skb(sk, skb); 2327 tcp_queue_skb(sk, skb);
2319 } 2328 }
2320 __tcp_push_pending_frames(sk, mss_now, TCP_NAGLE_OFF); 2329 __tcp_push_pending_frames(sk, mss_now, TCP_NAGLE_OFF);
@@ -2339,7 +2348,7 @@ void tcp_send_active_reset(struct sock *sk, gfp_t priority)
2339 /* Reserve space for headers and prepare control bits. */ 2348 /* Reserve space for headers and prepare control bits. */
2340 skb_reserve(skb, MAX_TCP_HEADER); 2349 skb_reserve(skb, MAX_TCP_HEADER);
2341 tcp_init_nondata_skb(skb, tcp_acceptable_seq(sk), 2350 tcp_init_nondata_skb(skb, tcp_acceptable_seq(sk),
2342 TCPCB_FLAG_ACK | TCPCB_FLAG_RST); 2351 TCPHDR_ACK | TCPHDR_RST);
2343 /* Send it off. */ 2352 /* Send it off. */
2344 TCP_SKB_CB(skb)->when = tcp_time_stamp; 2353 TCP_SKB_CB(skb)->when = tcp_time_stamp;
2345 if (tcp_transmit_skb(sk, skb, 0, priority)) 2354 if (tcp_transmit_skb(sk, skb, 0, priority))
@@ -2359,11 +2368,11 @@ int tcp_send_synack(struct sock *sk)
2359 struct sk_buff *skb; 2368 struct sk_buff *skb;
2360 2369
2361 skb = tcp_write_queue_head(sk); 2370 skb = tcp_write_queue_head(sk);
2362 if (skb == NULL || !(TCP_SKB_CB(skb)->flags & TCPCB_FLAG_SYN)) { 2371 if (skb == NULL || !(TCP_SKB_CB(skb)->flags & TCPHDR_SYN)) {
2363 printk(KERN_DEBUG "tcp_send_synack: wrong queue state\n"); 2372 printk(KERN_DEBUG "tcp_send_synack: wrong queue state\n");
2364 return -EFAULT; 2373 return -EFAULT;
2365 } 2374 }
2366 if (!(TCP_SKB_CB(skb)->flags & TCPCB_FLAG_ACK)) { 2375 if (!(TCP_SKB_CB(skb)->flags & TCPHDR_ACK)) {
2367 if (skb_cloned(skb)) { 2376 if (skb_cloned(skb)) {
2368 struct sk_buff *nskb = skb_copy(skb, GFP_ATOMIC); 2377 struct sk_buff *nskb = skb_copy(skb, GFP_ATOMIC);
2369 if (nskb == NULL) 2378 if (nskb == NULL)
@@ -2377,7 +2386,7 @@ int tcp_send_synack(struct sock *sk)
2377 skb = nskb; 2386 skb = nskb;
2378 } 2387 }
2379 2388
2380 TCP_SKB_CB(skb)->flags |= TCPCB_FLAG_ACK; 2389 TCP_SKB_CB(skb)->flags |= TCPHDR_ACK;
2381 TCP_ECN_send_synack(tcp_sk(sk), skb); 2390 TCP_ECN_send_synack(tcp_sk(sk), skb);
2382 } 2391 }
2383 TCP_SKB_CB(skb)->when = tcp_time_stamp; 2392 TCP_SKB_CB(skb)->when = tcp_time_stamp;
@@ -2393,13 +2402,17 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
2393 struct tcp_extend_values *xvp = tcp_xv(rvp); 2402 struct tcp_extend_values *xvp = tcp_xv(rvp);
2394 struct inet_request_sock *ireq = inet_rsk(req); 2403 struct inet_request_sock *ireq = inet_rsk(req);
2395 struct tcp_sock *tp = tcp_sk(sk); 2404 struct tcp_sock *tp = tcp_sk(sk);
2405 const struct tcp_cookie_values *cvp = tp->cookie_values;
2396 struct tcphdr *th; 2406 struct tcphdr *th;
2397 struct sk_buff *skb; 2407 struct sk_buff *skb;
2398 struct tcp_md5sig_key *md5; 2408 struct tcp_md5sig_key *md5;
2399 int tcp_header_size; 2409 int tcp_header_size;
2400 int mss; 2410 int mss;
2411 int s_data_desired = 0;
2401 2412
2402 skb = sock_wmalloc(sk, MAX_TCP_HEADER + 15, 1, GFP_ATOMIC); 2413 if (cvp != NULL && cvp->s_data_constant && cvp->s_data_desired)
2414 s_data_desired = cvp->s_data_desired;
2415 skb = sock_wmalloc(sk, MAX_TCP_HEADER + 15 + s_data_desired, 1, GFP_ATOMIC);
2403 if (skb == NULL) 2416 if (skb == NULL)
2404 return NULL; 2417 return NULL;
2405 2418
@@ -2422,7 +2435,8 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
2422 &req->rcv_wnd, 2435 &req->rcv_wnd,
2423 &req->window_clamp, 2436 &req->window_clamp,
2424 ireq->wscale_ok, 2437 ireq->wscale_ok,
2425 &rcv_wscale); 2438 &rcv_wscale,
2439 dst_metric(dst, RTAX_INITRWND));
2426 ireq->rcv_wscale = rcv_wscale; 2440 ireq->rcv_wscale = rcv_wscale;
2427 } 2441 }
2428 2442
@@ -2451,19 +2465,15 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
2451 * not even correctly set) 2465 * not even correctly set)
2452 */ 2466 */
2453 tcp_init_nondata_skb(skb, tcp_rsk(req)->snt_isn, 2467 tcp_init_nondata_skb(skb, tcp_rsk(req)->snt_isn,
2454 TCPCB_FLAG_SYN | TCPCB_FLAG_ACK); 2468 TCPHDR_SYN | TCPHDR_ACK);
2455 2469
2456 if (OPTION_COOKIE_EXTENSION & opts.options) { 2470 if (OPTION_COOKIE_EXTENSION & opts.options) {
2457 const struct tcp_cookie_values *cvp = tp->cookie_values; 2471 if (s_data_desired) {
2458 2472 u8 *buf = skb_put(skb, s_data_desired);
2459 if (cvp != NULL &&
2460 cvp->s_data_constant &&
2461 cvp->s_data_desired > 0) {
2462 u8 *buf = skb_put(skb, cvp->s_data_desired);
2463 2473
2464 /* copy data directly from the listening socket. */ 2474 /* copy data directly from the listening socket. */
2465 memcpy(buf, cvp->s_data_payload, cvp->s_data_desired); 2475 memcpy(buf, cvp->s_data_payload, s_data_desired);
2466 TCP_SKB_CB(skb)->end_seq += cvp->s_data_desired; 2476 TCP_SKB_CB(skb)->end_seq += s_data_desired;
2467 } 2477 }
2468 2478
2469 if (opts.hash_size > 0) { 2479 if (opts.hash_size > 0) {
@@ -2480,7 +2490,7 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
2480 *tail-- ^= TCP_SKB_CB(skb)->seq + 1; 2490 *tail-- ^= TCP_SKB_CB(skb)->seq + 1;
2481 2491
2482 /* recommended */ 2492 /* recommended */
2483 *tail-- ^= ((th->dest << 16) | th->source); 2493 *tail-- ^= (((__force u32)th->dest << 16) | (__force u32)th->source);
2484 *tail-- ^= (u32)(unsigned long)cvp; /* per sockopt */ 2494 *tail-- ^= (u32)(unsigned long)cvp; /* per sockopt */
2485 2495
2486 sha_transform((__u32 *)&xvp->cookie_bakery[0], 2496 sha_transform((__u32 *)&xvp->cookie_bakery[0],
@@ -2498,7 +2508,7 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
2498 th->window = htons(min(req->rcv_wnd, 65535U)); 2508 th->window = htons(min(req->rcv_wnd, 65535U));
2499 tcp_options_write((__be32 *)(th + 1), tp, &opts); 2509 tcp_options_write((__be32 *)(th + 1), tp, &opts);
2500 th->doff = (tcp_header_size >> 2); 2510 th->doff = (tcp_header_size >> 2);
2501 TCP_INC_STATS(sock_net(sk), TCP_MIB_OUTSEGS); 2511 TCP_ADD_STATS(sock_net(sk), TCP_MIB_OUTSEGS, tcp_skb_pcount(skb));
2502 2512
2503#ifdef CONFIG_TCP_MD5SIG 2513#ifdef CONFIG_TCP_MD5SIG
2504 /* Okay, we have all we need - do the md5 hash if needed */ 2514 /* Okay, we have all we need - do the md5 hash if needed */
@@ -2510,6 +2520,7 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
2510 2520
2511 return skb; 2521 return skb;
2512} 2522}
2523EXPORT_SYMBOL(tcp_make_synack);
2513 2524
2514/* Do all connect socket setups that can be done AF independent. */ 2525/* Do all connect socket setups that can be done AF independent. */
2515static void tcp_connect_init(struct sock *sk) 2526static void tcp_connect_init(struct sock *sk)
@@ -2549,7 +2560,8 @@ static void tcp_connect_init(struct sock *sk)
2549 &tp->rcv_wnd, 2560 &tp->rcv_wnd,
2550 &tp->window_clamp, 2561 &tp->window_clamp,
2551 sysctl_tcp_window_scaling, 2562 sysctl_tcp_window_scaling,
2552 &rcv_wscale); 2563 &rcv_wscale,
2564 dst_metric(dst, RTAX_INITRWND));
2553 2565
2554 tp->rx_opt.rcv_wscale = rcv_wscale; 2566 tp->rx_opt.rcv_wscale = rcv_wscale;
2555 tp->rcv_ssthresh = tp->rcv_wnd; 2567 tp->rcv_ssthresh = tp->rcv_wnd;
@@ -2586,7 +2598,7 @@ int tcp_connect(struct sock *sk)
2586 skb_reserve(buff, MAX_TCP_HEADER); 2598 skb_reserve(buff, MAX_TCP_HEADER);
2587 2599
2588 tp->snd_nxt = tp->write_seq; 2600 tp->snd_nxt = tp->write_seq;
2589 tcp_init_nondata_skb(buff, tp->write_seq++, TCPCB_FLAG_SYN); 2601 tcp_init_nondata_skb(buff, tp->write_seq++, TCPHDR_SYN);
2590 TCP_ECN_send_syn(sk, buff); 2602 TCP_ECN_send_syn(sk, buff);
2591 2603
2592 /* Send it off. */ 2604 /* Send it off. */
@@ -2611,6 +2623,7 @@ int tcp_connect(struct sock *sk)
2611 inet_csk(sk)->icsk_rto, TCP_RTO_MAX); 2623 inet_csk(sk)->icsk_rto, TCP_RTO_MAX);
2612 return 0; 2624 return 0;
2613} 2625}
2626EXPORT_SYMBOL(tcp_connect);
2614 2627
2615/* Send out a delayed ack, the caller does the policy checking 2628/* Send out a delayed ack, the caller does the policy checking
2616 * to see if we should even be here. See tcp_input.c:tcp_ack_snd_check() 2629 * to see if we should even be here. See tcp_input.c:tcp_ack_snd_check()
@@ -2692,7 +2705,7 @@ void tcp_send_ack(struct sock *sk)
2692 2705
2693 /* Reserve space for headers and prepare control bits. */ 2706 /* Reserve space for headers and prepare control bits. */
2694 skb_reserve(buff, MAX_TCP_HEADER); 2707 skb_reserve(buff, MAX_TCP_HEADER);
2695 tcp_init_nondata_skb(buff, tcp_acceptable_seq(sk), TCPCB_FLAG_ACK); 2708 tcp_init_nondata_skb(buff, tcp_acceptable_seq(sk), TCPHDR_ACK);
2696 2709
2697 /* Send it off, this clears delayed acks for us. */ 2710 /* Send it off, this clears delayed acks for us. */
2698 TCP_SKB_CB(buff)->when = tcp_time_stamp; 2711 TCP_SKB_CB(buff)->when = tcp_time_stamp;
@@ -2726,7 +2739,7 @@ static int tcp_xmit_probe_skb(struct sock *sk, int urgent)
2726 * end to send an ack. Don't queue or clone SKB, just 2739 * end to send an ack. Don't queue or clone SKB, just
2727 * send it. 2740 * send it.
2728 */ 2741 */
2729 tcp_init_nondata_skb(skb, tp->snd_una - !urgent, TCPCB_FLAG_ACK); 2742 tcp_init_nondata_skb(skb, tp->snd_una - !urgent, TCPHDR_ACK);
2730 TCP_SKB_CB(skb)->when = tcp_time_stamp; 2743 TCP_SKB_CB(skb)->when = tcp_time_stamp;
2731 return tcp_transmit_skb(sk, skb, 0, GFP_ATOMIC); 2744 return tcp_transmit_skb(sk, skb, 0, GFP_ATOMIC);
2732} 2745}
@@ -2756,13 +2769,13 @@ int tcp_write_wakeup(struct sock *sk)
2756 if (seg_size < TCP_SKB_CB(skb)->end_seq - TCP_SKB_CB(skb)->seq || 2769 if (seg_size < TCP_SKB_CB(skb)->end_seq - TCP_SKB_CB(skb)->seq ||
2757 skb->len > mss) { 2770 skb->len > mss) {
2758 seg_size = min(seg_size, mss); 2771 seg_size = min(seg_size, mss);
2759 TCP_SKB_CB(skb)->flags |= TCPCB_FLAG_PSH; 2772 TCP_SKB_CB(skb)->flags |= TCPHDR_PSH;
2760 if (tcp_fragment(sk, skb, seg_size, mss)) 2773 if (tcp_fragment(sk, skb, seg_size, mss))
2761 return -1; 2774 return -1;
2762 } else if (!tcp_skb_pcount(skb)) 2775 } else if (!tcp_skb_pcount(skb))
2763 tcp_set_skb_tso_segs(sk, skb, mss); 2776 tcp_set_skb_tso_segs(sk, skb, mss);
2764 2777
2765 TCP_SKB_CB(skb)->flags |= TCPCB_FLAG_PSH; 2778 TCP_SKB_CB(skb)->flags |= TCPHDR_PSH;
2766 TCP_SKB_CB(skb)->when = tcp_time_stamp; 2779 TCP_SKB_CB(skb)->when = tcp_time_stamp;
2767 err = tcp_transmit_skb(sk, skb, 1, GFP_ATOMIC); 2780 err = tcp_transmit_skb(sk, skb, 1, GFP_ATOMIC);
2768 if (!err) 2781 if (!err)
@@ -2815,10 +2828,3 @@ void tcp_send_probe0(struct sock *sk)
2815 TCP_RTO_MAX); 2828 TCP_RTO_MAX);
2816 } 2829 }
2817} 2830}
2818
2819EXPORT_SYMBOL(tcp_select_initial_window);
2820EXPORT_SYMBOL(tcp_connect);
2821EXPORT_SYMBOL(tcp_make_synack);
2822EXPORT_SYMBOL(tcp_simple_retransmit);
2823EXPORT_SYMBOL(tcp_sync_mss);
2824EXPORT_SYMBOL(tcp_mtup_init);