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.c257
1 files changed, 136 insertions, 121 deletions
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 8165f5aa8c71..ba85d8831893 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -345,6 +345,11 @@ static void tcp_init_nondata_skb(struct sk_buff *skb, u32 seq, u8 flags)
345 TCP_SKB_CB(skb)->end_seq = seq; 345 TCP_SKB_CB(skb)->end_seq = seq;
346} 346}
347 347
348static inline int tcp_urg_mode(const struct tcp_sock *tp)
349{
350 return tp->snd_una != tp->snd_up;
351}
352
348#define OPTION_SACK_ADVERTISE (1 << 0) 353#define OPTION_SACK_ADVERTISE (1 << 0)
349#define OPTION_TS (1 << 1) 354#define OPTION_TS (1 << 1)
350#define OPTION_MD5 (1 << 2) 355#define OPTION_MD5 (1 << 2)
@@ -357,6 +362,17 @@ struct tcp_out_options {
357 __u32 tsval, tsecr; /* need to include OPTION_TS */ 362 __u32 tsval, tsecr; /* need to include OPTION_TS */
358}; 363};
359 364
365/* Beware: Something in the Internet is very sensitive to the ordering of
366 * TCP options, we learned this through the hard way, so be careful here.
367 * Luckily we can at least blame others for their non-compliance but from
368 * inter-operatibility perspective it seems that we're somewhat stuck with
369 * the ordering which we have been using if we want to keep working with
370 * those broken things (not that it currently hurts anybody as there isn't
371 * particular reason why the ordering would need to be changed).
372 *
373 * At least SACK_PERM as the first option is known to lead to a disaster
374 * (but it may well be that other scenarios fail similarly).
375 */
360static void tcp_options_write(__be32 *ptr, struct tcp_sock *tp, 376static void tcp_options_write(__be32 *ptr, struct tcp_sock *tp,
361 const struct tcp_out_options *opts, 377 const struct tcp_out_options *opts,
362 __u8 **md5_hash) { 378 __u8 **md5_hash) {
@@ -371,6 +387,12 @@ static void tcp_options_write(__be32 *ptr, struct tcp_sock *tp,
371 *md5_hash = NULL; 387 *md5_hash = NULL;
372 } 388 }
373 389
390 if (unlikely(opts->mss)) {
391 *ptr++ = htonl((TCPOPT_MSS << 24) |
392 (TCPOLEN_MSS << 16) |
393 opts->mss);
394 }
395
374 if (likely(OPTION_TS & opts->options)) { 396 if (likely(OPTION_TS & opts->options)) {
375 if (unlikely(OPTION_SACK_ADVERTISE & opts->options)) { 397 if (unlikely(OPTION_SACK_ADVERTISE & opts->options)) {
376 *ptr++ = htonl((TCPOPT_SACK_PERM << 24) | 398 *ptr++ = htonl((TCPOPT_SACK_PERM << 24) |
@@ -387,12 +409,6 @@ static void tcp_options_write(__be32 *ptr, struct tcp_sock *tp,
387 *ptr++ = htonl(opts->tsecr); 409 *ptr++ = htonl(opts->tsecr);
388 } 410 }
389 411
390 if (unlikely(opts->mss)) {
391 *ptr++ = htonl((TCPOPT_MSS << 24) |
392 (TCPOLEN_MSS << 16) |
393 opts->mss);
394 }
395
396 if (unlikely(OPTION_SACK_ADVERTISE & opts->options && 412 if (unlikely(OPTION_SACK_ADVERTISE & opts->options &&
397 !(OPTION_TS & opts->options))) { 413 !(OPTION_TS & opts->options))) {
398 *ptr++ = htonl((TCPOPT_NOP << 24) | 414 *ptr++ = htonl((TCPOPT_NOP << 24) |
@@ -427,7 +443,7 @@ static void tcp_options_write(__be32 *ptr, struct tcp_sock *tp,
427 443
428 if (tp->rx_opt.dsack) { 444 if (tp->rx_opt.dsack) {
429 tp->rx_opt.dsack = 0; 445 tp->rx_opt.dsack = 0;
430 tp->rx_opt.eff_sacks--; 446 tp->rx_opt.eff_sacks = tp->rx_opt.num_sacks;
431 } 447 }
432 } 448 }
433} 449}
@@ -646,7 +662,8 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it,
646 th->check = 0; 662 th->check = 0;
647 th->urg_ptr = 0; 663 th->urg_ptr = 0;
648 664
649 if (unlikely(tp->urg_mode && 665 /* The urg_mode check is necessary during a below snd_una win probe */
666 if (unlikely(tcp_urg_mode(tp) &&
650 between(tp->snd_up, tcb->seq + 1, tcb->seq + 0xFFFF))) { 667 between(tp->snd_up, tcb->seq + 1, tcb->seq + 0xFFFF))) {
651 th->urg_ptr = htons(tp->snd_up - tcb->seq); 668 th->urg_ptr = htons(tp->snd_up - tcb->seq);
652 th->urg = 1; 669 th->urg = 1;
@@ -1012,7 +1029,7 @@ unsigned int tcp_sync_mss(struct sock *sk, u32 pmtu)
1012/* Compute the current effective MSS, taking SACKs and IP options, 1029/* Compute the current effective MSS, taking SACKs and IP options,
1013 * and even PMTU discovery events into account. 1030 * and even PMTU discovery events into account.
1014 * 1031 *
1015 * LARGESEND note: !urg_mode is overkill, only frames up to snd_up 1032 * LARGESEND note: !tcp_urg_mode is overkill, only frames up to snd_up
1016 * cannot be large. However, taking into account rare use of URG, this 1033 * cannot be large. However, taking into account rare use of URG, this
1017 * is not a big flaw. 1034 * is not a big flaw.
1018 */ 1035 */
@@ -1029,7 +1046,7 @@ unsigned int tcp_current_mss(struct sock *sk, int large_allowed)
1029 1046
1030 mss_now = tp->mss_cache; 1047 mss_now = tp->mss_cache;
1031 1048
1032 if (large_allowed && sk_can_gso(sk) && !tp->urg_mode) 1049 if (large_allowed && sk_can_gso(sk) && !tcp_urg_mode(tp))
1033 doing_tso = 1; 1050 doing_tso = 1;
1034 1051
1035 if (dst) { 1052 if (dst) {
@@ -1193,7 +1210,7 @@ static inline int tcp_nagle_test(struct tcp_sock *tp, struct sk_buff *skb,
1193 /* Don't use the nagle rule for urgent data (or for the final FIN). 1210 /* Don't use the nagle rule for urgent data (or for the final FIN).
1194 * Nagle can be ignored during F-RTO too (see RFC4138). 1211 * Nagle can be ignored during F-RTO too (see RFC4138).
1195 */ 1212 */
1196 if (tp->urg_mode || (tp->frto_counter == 2) || 1213 if (tcp_urg_mode(tp) || (tp->frto_counter == 2) ||
1197 (TCP_SKB_CB(skb)->flags & TCPCB_FLAG_FIN)) 1214 (TCP_SKB_CB(skb)->flags & TCPCB_FLAG_FIN))
1198 return 1; 1215 return 1;
1199 1216
@@ -1824,6 +1841,8 @@ static void tcp_retrans_try_collapse(struct sock *sk, struct sk_buff *skb,
1824 1841
1825 /* changed transmit queue under us so clear hints */ 1842 /* changed transmit queue under us so clear hints */
1826 tcp_clear_retrans_hints_partial(tp); 1843 tcp_clear_retrans_hints_partial(tp);
1844 if (next_skb == tp->retransmit_skb_hint)
1845 tp->retransmit_skb_hint = skb;
1827 1846
1828 sk_wmem_free_skb(sk, next_skb); 1847 sk_wmem_free_skb(sk, next_skb);
1829} 1848}
@@ -1838,7 +1857,7 @@ void tcp_simple_retransmit(struct sock *sk)
1838 struct tcp_sock *tp = tcp_sk(sk); 1857 struct tcp_sock *tp = tcp_sk(sk);
1839 struct sk_buff *skb; 1858 struct sk_buff *skb;
1840 unsigned int mss = tcp_current_mss(sk, 0); 1859 unsigned int mss = tcp_current_mss(sk, 0);
1841 int lost = 0; 1860 u32 prior_lost = tp->lost_out;
1842 1861
1843 tcp_for_write_queue(skb, sk) { 1862 tcp_for_write_queue(skb, sk) {
1844 if (skb == tcp_send_head(sk)) 1863 if (skb == tcp_send_head(sk))
@@ -1849,17 +1868,13 @@ void tcp_simple_retransmit(struct sock *sk)
1849 TCP_SKB_CB(skb)->sacked &= ~TCPCB_SACKED_RETRANS; 1868 TCP_SKB_CB(skb)->sacked &= ~TCPCB_SACKED_RETRANS;
1850 tp->retrans_out -= tcp_skb_pcount(skb); 1869 tp->retrans_out -= tcp_skb_pcount(skb);
1851 } 1870 }
1852 if (!(TCP_SKB_CB(skb)->sacked & TCPCB_LOST)) { 1871 tcp_skb_mark_lost_uncond_verify(tp, skb);
1853 TCP_SKB_CB(skb)->sacked |= TCPCB_LOST;
1854 tp->lost_out += tcp_skb_pcount(skb);
1855 lost = 1;
1856 }
1857 } 1872 }
1858 } 1873 }
1859 1874
1860 tcp_clear_all_retrans_hints(tp); 1875 tcp_clear_retrans_hints_partial(tp);
1861 1876
1862 if (!lost) 1877 if (prior_lost == tp->lost_out)
1863 return; 1878 return;
1864 1879
1865 if (tcp_is_reno(tp)) 1880 if (tcp_is_reno(tp))
@@ -1934,8 +1949,8 @@ int tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb)
1934 /* Collapse two adjacent packets if worthwhile and we can. */ 1949 /* Collapse two adjacent packets if worthwhile and we can. */
1935 if (!(TCP_SKB_CB(skb)->flags & TCPCB_FLAG_SYN) && 1950 if (!(TCP_SKB_CB(skb)->flags & TCPCB_FLAG_SYN) &&
1936 (skb->len < (cur_mss >> 1)) && 1951 (skb->len < (cur_mss >> 1)) &&
1937 (tcp_write_queue_next(sk, skb) != tcp_send_head(sk)) &&
1938 (!tcp_skb_is_last(sk, skb)) && 1952 (!tcp_skb_is_last(sk, skb)) &&
1953 (tcp_write_queue_next(sk, skb) != tcp_send_head(sk)) &&
1939 (skb_shinfo(skb)->nr_frags == 0 && 1954 (skb_shinfo(skb)->nr_frags == 0 &&
1940 skb_shinfo(tcp_write_queue_next(sk, skb))->nr_frags == 0) && 1955 skb_shinfo(tcp_write_queue_next(sk, skb))->nr_frags == 0) &&
1941 (tcp_skb_pcount(skb) == 1 && 1956 (tcp_skb_pcount(skb) == 1 &&
@@ -1996,86 +2011,18 @@ int tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb)
1996 return err; 2011 return err;
1997} 2012}
1998 2013
1999/* This gets called after a retransmit timeout, and the initially 2014static int tcp_can_forward_retransmit(struct sock *sk)
2000 * retransmitted data is acknowledged. It tries to continue
2001 * resending the rest of the retransmit queue, until either
2002 * we've sent it all or the congestion window limit is reached.
2003 * If doing SACK, the first ACK which comes back for a timeout
2004 * based retransmit packet might feed us FACK information again.
2005 * If so, we use it to avoid unnecessarily retransmissions.
2006 */
2007void tcp_xmit_retransmit_queue(struct sock *sk)
2008{ 2015{
2009 const struct inet_connection_sock *icsk = inet_csk(sk); 2016 const struct inet_connection_sock *icsk = inet_csk(sk);
2010 struct tcp_sock *tp = tcp_sk(sk); 2017 struct tcp_sock *tp = tcp_sk(sk);
2011 struct sk_buff *skb;
2012 int packet_cnt;
2013
2014 if (tp->retransmit_skb_hint) {
2015 skb = tp->retransmit_skb_hint;
2016 packet_cnt = tp->retransmit_cnt_hint;
2017 } else {
2018 skb = tcp_write_queue_head(sk);
2019 packet_cnt = 0;
2020 }
2021
2022 /* First pass: retransmit lost packets. */
2023 if (tp->lost_out) {
2024 tcp_for_write_queue_from(skb, sk) {
2025 __u8 sacked = TCP_SKB_CB(skb)->sacked;
2026
2027 if (skb == tcp_send_head(sk))
2028 break;
2029 /* we could do better than to assign each time */
2030 tp->retransmit_skb_hint = skb;
2031 tp->retransmit_cnt_hint = packet_cnt;
2032
2033 /* Assume this retransmit will generate
2034 * only one packet for congestion window
2035 * calculation purposes. This works because
2036 * tcp_retransmit_skb() will chop up the
2037 * packet to be MSS sized and all the
2038 * packet counting works out.
2039 */
2040 if (tcp_packets_in_flight(tp) >= tp->snd_cwnd)
2041 return;
2042
2043 if (sacked & TCPCB_LOST) {
2044 if (!(sacked & (TCPCB_SACKED_ACKED|TCPCB_SACKED_RETRANS))) {
2045 int mib_idx;
2046
2047 if (tcp_retransmit_skb(sk, skb)) {
2048 tp->retransmit_skb_hint = NULL;
2049 return;
2050 }
2051 if (icsk->icsk_ca_state != TCP_CA_Loss)
2052 mib_idx = LINUX_MIB_TCPFASTRETRANS;
2053 else
2054 mib_idx = LINUX_MIB_TCPSLOWSTARTRETRANS;
2055 NET_INC_STATS_BH(sock_net(sk), mib_idx);
2056
2057 if (skb == tcp_write_queue_head(sk))
2058 inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
2059 inet_csk(sk)->icsk_rto,
2060 TCP_RTO_MAX);
2061 }
2062
2063 packet_cnt += tcp_skb_pcount(skb);
2064 if (packet_cnt >= tp->lost_out)
2065 break;
2066 }
2067 }
2068 }
2069
2070 /* OK, demanded retransmission is finished. */
2071 2018
2072 /* Forward retransmissions are possible only during Recovery. */ 2019 /* Forward retransmissions are possible only during Recovery. */
2073 if (icsk->icsk_ca_state != TCP_CA_Recovery) 2020 if (icsk->icsk_ca_state != TCP_CA_Recovery)
2074 return; 2021 return 0;
2075 2022
2076 /* No forward retransmissions in Reno are possible. */ 2023 /* No forward retransmissions in Reno are possible. */
2077 if (tcp_is_reno(tp)) 2024 if (tcp_is_reno(tp))
2078 return; 2025 return 0;
2079 2026
2080 /* Yeah, we have to make difficult choice between forward transmission 2027 /* Yeah, we have to make difficult choice between forward transmission
2081 * and retransmission... Both ways have their merits... 2028 * and retransmission... Both ways have their merits...
@@ -2086,43 +2033,104 @@ void tcp_xmit_retransmit_queue(struct sock *sk)
2086 */ 2033 */
2087 2034
2088 if (tcp_may_send_now(sk)) 2035 if (tcp_may_send_now(sk))
2089 return; 2036 return 0;
2090 2037
2091 /* If nothing is SACKed, highest_sack in the loop won't be valid */ 2038 return 1;
2092 if (!tp->sacked_out) 2039}
2093 return;
2094 2040
2095 if (tp->forward_skb_hint) 2041/* This gets called after a retransmit timeout, and the initially
2096 skb = tp->forward_skb_hint; 2042 * retransmitted data is acknowledged. It tries to continue
2097 else 2043 * resending the rest of the retransmit queue, until either
2044 * we've sent it all or the congestion window limit is reached.
2045 * If doing SACK, the first ACK which comes back for a timeout
2046 * based retransmit packet might feed us FACK information again.
2047 * If so, we use it to avoid unnecessarily retransmissions.
2048 */
2049void tcp_xmit_retransmit_queue(struct sock *sk)
2050{
2051 const struct inet_connection_sock *icsk = inet_csk(sk);
2052 struct tcp_sock *tp = tcp_sk(sk);
2053 struct sk_buff *skb;
2054 struct sk_buff *hole = NULL;
2055 u32 last_lost;
2056 int mib_idx;
2057 int fwd_rexmitting = 0;
2058
2059 if (!tp->lost_out)
2060 tp->retransmit_high = tp->snd_una;
2061
2062 if (tp->retransmit_skb_hint) {
2063 skb = tp->retransmit_skb_hint;
2064 last_lost = TCP_SKB_CB(skb)->end_seq;
2065 if (after(last_lost, tp->retransmit_high))
2066 last_lost = tp->retransmit_high;
2067 } else {
2098 skb = tcp_write_queue_head(sk); 2068 skb = tcp_write_queue_head(sk);
2069 last_lost = tp->snd_una;
2070 }
2099 2071
2072 /* First pass: retransmit lost packets. */
2100 tcp_for_write_queue_from(skb, sk) { 2073 tcp_for_write_queue_from(skb, sk) {
2101 if (skb == tcp_send_head(sk)) 2074 __u8 sacked = TCP_SKB_CB(skb)->sacked;
2102 break;
2103 tp->forward_skb_hint = skb;
2104 2075
2105 if (!before(TCP_SKB_CB(skb)->seq, tcp_highest_sack_seq(tp))) 2076 if (skb == tcp_send_head(sk))
2106 break; 2077 break;
2078 /* we could do better than to assign each time */
2079 if (hole == NULL)
2080 tp->retransmit_skb_hint = skb;
2107 2081
2082 /* Assume this retransmit will generate
2083 * only one packet for congestion window
2084 * calculation purposes. This works because
2085 * tcp_retransmit_skb() will chop up the
2086 * packet to be MSS sized and all the
2087 * packet counting works out.
2088 */
2108 if (tcp_packets_in_flight(tp) >= tp->snd_cwnd) 2089 if (tcp_packets_in_flight(tp) >= tp->snd_cwnd)
2109 break; 2090 return;
2091
2092 if (fwd_rexmitting) {
2093begin_fwd:
2094 if (!before(TCP_SKB_CB(skb)->seq, tcp_highest_sack_seq(tp)))
2095 break;
2096 mib_idx = LINUX_MIB_TCPFORWARDRETRANS;
2097
2098 } else if (!before(TCP_SKB_CB(skb)->seq, tp->retransmit_high)) {
2099 tp->retransmit_high = last_lost;
2100 if (!tcp_can_forward_retransmit(sk))
2101 break;
2102 /* Backtrack if necessary to non-L'ed skb */
2103 if (hole != NULL) {
2104 skb = hole;
2105 hole = NULL;
2106 }
2107 fwd_rexmitting = 1;
2108 goto begin_fwd;
2110 2109
2111 if (TCP_SKB_CB(skb)->sacked & TCPCB_TAGBITS) 2110 } else if (!(sacked & TCPCB_LOST)) {
2111 if (hole == NULL && !(sacked & TCPCB_SACKED_RETRANS))
2112 hole = skb;
2112 continue; 2113 continue;
2113 2114
2114 /* Ok, retransmit it. */ 2115 } else {
2115 if (tcp_retransmit_skb(sk, skb)) { 2116 last_lost = TCP_SKB_CB(skb)->end_seq;
2116 tp->forward_skb_hint = NULL; 2117 if (icsk->icsk_ca_state != TCP_CA_Loss)
2117 break; 2118 mib_idx = LINUX_MIB_TCPFASTRETRANS;
2119 else
2120 mib_idx = LINUX_MIB_TCPSLOWSTARTRETRANS;
2118 } 2121 }
2119 2122
2123 if (sacked & (TCPCB_SACKED_ACKED|TCPCB_SACKED_RETRANS))
2124 continue;
2125
2126 if (tcp_retransmit_skb(sk, skb))
2127 return;
2128 NET_INC_STATS_BH(sock_net(sk), mib_idx);
2129
2120 if (skb == tcp_write_queue_head(sk)) 2130 if (skb == tcp_write_queue_head(sk))
2121 inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, 2131 inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
2122 inet_csk(sk)->icsk_rto, 2132 inet_csk(sk)->icsk_rto,
2123 TCP_RTO_MAX); 2133 TCP_RTO_MAX);
2124
2125 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPFORWARDRETRANS);
2126 } 2134 }
2127} 2135}
2128 2136
@@ -2241,6 +2249,7 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
2241 struct sk_buff *skb; 2249 struct sk_buff *skb;
2242 struct tcp_md5sig_key *md5; 2250 struct tcp_md5sig_key *md5;
2243 __u8 *md5_hash_location; 2251 __u8 *md5_hash_location;
2252 int mss;
2244 2253
2245 skb = sock_wmalloc(sk, MAX_TCP_HEADER + 15, 1, GFP_ATOMIC); 2254 skb = sock_wmalloc(sk, MAX_TCP_HEADER + 15, 1, GFP_ATOMIC);
2246 if (skb == NULL) 2255 if (skb == NULL)
@@ -2251,13 +2260,17 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
2251 2260
2252 skb->dst = dst_clone(dst); 2261 skb->dst = dst_clone(dst);
2253 2262
2263 mss = dst_metric(dst, RTAX_ADVMSS);
2264 if (tp->rx_opt.user_mss && tp->rx_opt.user_mss < mss)
2265 mss = tp->rx_opt.user_mss;
2266
2254 if (req->rcv_wnd == 0) { /* ignored for retransmitted syns */ 2267 if (req->rcv_wnd == 0) { /* ignored for retransmitted syns */
2255 __u8 rcv_wscale; 2268 __u8 rcv_wscale;
2256 /* Set this up on the first call only */ 2269 /* Set this up on the first call only */
2257 req->window_clamp = tp->window_clamp ? : dst_metric(dst, RTAX_WINDOW); 2270 req->window_clamp = tp->window_clamp ? : dst_metric(dst, RTAX_WINDOW);
2258 /* tcp_full_space because it is guaranteed to be the first packet */ 2271 /* tcp_full_space because it is guaranteed to be the first packet */
2259 tcp_select_initial_window(tcp_full_space(sk), 2272 tcp_select_initial_window(tcp_full_space(sk),
2260 dst_metric(dst, RTAX_ADVMSS) - (ireq->tstamp_ok ? TCPOLEN_TSTAMP_ALIGNED : 0), 2273 mss - (ireq->tstamp_ok ? TCPOLEN_TSTAMP_ALIGNED : 0),
2261 &req->rcv_wnd, 2274 &req->rcv_wnd,
2262 &req->window_clamp, 2275 &req->window_clamp,
2263 ireq->wscale_ok, 2276 ireq->wscale_ok,
@@ -2266,9 +2279,13 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
2266 } 2279 }
2267 2280
2268 memset(&opts, 0, sizeof(opts)); 2281 memset(&opts, 0, sizeof(opts));
2282#ifdef CONFIG_SYN_COOKIES
2283 if (unlikely(req->cookie_ts))
2284 TCP_SKB_CB(skb)->when = cookie_init_timestamp(req);
2285 else
2286#endif
2269 TCP_SKB_CB(skb)->when = tcp_time_stamp; 2287 TCP_SKB_CB(skb)->when = tcp_time_stamp;
2270 tcp_header_size = tcp_synack_options(sk, req, 2288 tcp_header_size = tcp_synack_options(sk, req, mss,
2271 dst_metric(dst, RTAX_ADVMSS),
2272 skb, &opts, &md5) + 2289 skb, &opts, &md5) +
2273 sizeof(struct tcphdr); 2290 sizeof(struct tcphdr);
2274 2291
@@ -2280,7 +2297,7 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
2280 th->syn = 1; 2297 th->syn = 1;
2281 th->ack = 1; 2298 th->ack = 1;
2282 TCP_ECN_make_synack(req, th); 2299 TCP_ECN_make_synack(req, th);
2283 th->source = inet_sk(sk)->sport; 2300 th->source = ireq->loc_port;
2284 th->dest = ireq->rmt_port; 2301 th->dest = ireq->rmt_port;
2285 /* Setting of flags are superfluous here for callers (and ECE is 2302 /* Setting of flags are superfluous here for callers (and ECE is
2286 * not even correctly set) 2303 * not even correctly set)
@@ -2292,11 +2309,6 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
2292 2309
2293 /* RFC1323: The window in SYN & SYN/ACK segments is never scaled. */ 2310 /* RFC1323: The window in SYN & SYN/ACK segments is never scaled. */
2294 th->window = htons(min(req->rcv_wnd, 65535U)); 2311 th->window = htons(min(req->rcv_wnd, 65535U));
2295#ifdef CONFIG_SYN_COOKIES
2296 if (unlikely(req->cookie_ts))
2297 TCP_SKB_CB(skb)->when = cookie_init_timestamp(req);
2298 else
2299#endif
2300 tcp_options_write((__be32 *)(th + 1), tp, &opts, &md5_hash_location); 2312 tcp_options_write((__be32 *)(th + 1), tp, &opts, &md5_hash_location);
2301 th->doff = (tcp_header_size >> 2); 2313 th->doff = (tcp_header_size >> 2);
2302 TCP_INC_STATS(sock_net(sk), TCP_MIB_OUTSEGS); 2314 TCP_INC_STATS(sock_net(sk), TCP_MIB_OUTSEGS);
@@ -2342,6 +2354,9 @@ static void tcp_connect_init(struct sock *sk)
2342 if (!tp->window_clamp) 2354 if (!tp->window_clamp)
2343 tp->window_clamp = dst_metric(dst, RTAX_WINDOW); 2355 tp->window_clamp = dst_metric(dst, RTAX_WINDOW);
2344 tp->advmss = dst_metric(dst, RTAX_ADVMSS); 2356 tp->advmss = dst_metric(dst, RTAX_ADVMSS);
2357 if (tp->rx_opt.user_mss && tp->rx_opt.user_mss < tp->advmss)
2358 tp->advmss = tp->rx_opt.user_mss;
2359
2345 tcp_initialize_rcv_mss(sk); 2360 tcp_initialize_rcv_mss(sk);
2346 2361
2347 tcp_select_initial_window(tcp_full_space(sk), 2362 tcp_select_initial_window(tcp_full_space(sk),
@@ -2360,6 +2375,7 @@ static void tcp_connect_init(struct sock *sk)
2360 tcp_init_wl(tp, tp->write_seq, 0); 2375 tcp_init_wl(tp, tp->write_seq, 0);
2361 tp->snd_una = tp->write_seq; 2376 tp->snd_una = tp->write_seq;
2362 tp->snd_sml = tp->write_seq; 2377 tp->snd_sml = tp->write_seq;
2378 tp->snd_up = tp->write_seq;
2363 tp->rcv_nxt = 0; 2379 tp->rcv_nxt = 0;
2364 tp->rcv_wup = 0; 2380 tp->rcv_wup = 0;
2365 tp->copied_seq = 0; 2381 tp->copied_seq = 0;
@@ -2569,8 +2585,7 @@ int tcp_write_wakeup(struct sock *sk)
2569 tcp_event_new_data_sent(sk, skb); 2585 tcp_event_new_data_sent(sk, skb);
2570 return err; 2586 return err;
2571 } else { 2587 } else {
2572 if (tp->urg_mode && 2588 if (between(tp->snd_up, tp->snd_una + 1, tp->snd_una + 0xFFFF))
2573 between(tp->snd_up, tp->snd_una + 1, tp->snd_una + 0xFFFF))
2574 tcp_xmit_probe_skb(sk, 1); 2589 tcp_xmit_probe_skb(sk, 1);
2575 return tcp_xmit_probe_skb(sk, 0); 2590 return tcp_xmit_probe_skb(sk, 0);
2576 } 2591 }