diff options
Diffstat (limited to 'net/ipv4/tcp_output.c')
| -rw-r--r-- | net/ipv4/tcp_output.c | 58 |
1 files changed, 44 insertions, 14 deletions
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index bd62712848fa..4e004424d400 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c | |||
| @@ -59,6 +59,7 @@ int sysctl_tcp_base_mss __read_mostly = 512; | |||
| 59 | /* By default, RFC2861 behavior. */ | 59 | /* By default, RFC2861 behavior. */ |
| 60 | int sysctl_tcp_slow_start_after_idle __read_mostly = 1; | 60 | int sysctl_tcp_slow_start_after_idle __read_mostly = 1; |
| 61 | 61 | ||
| 62 | /* Account for new data that has been sent to the network. */ | ||
| 62 | static void tcp_event_new_data_sent(struct sock *sk, struct sk_buff *skb) | 63 | static void tcp_event_new_data_sent(struct sock *sk, struct sk_buff *skb) |
| 63 | { | 64 | { |
| 64 | struct tcp_sock *tp = tcp_sk(sk); | 65 | struct tcp_sock *tp = tcp_sk(sk); |
| @@ -142,6 +143,7 @@ static void tcp_cwnd_restart(struct sock *sk, struct dst_entry *dst) | |||
| 142 | tp->snd_cwnd_used = 0; | 143 | tp->snd_cwnd_used = 0; |
| 143 | } | 144 | } |
| 144 | 145 | ||
| 146 | /* Congestion state accounting after a packet has been sent. */ | ||
| 145 | static void tcp_event_data_sent(struct tcp_sock *tp, | 147 | static void tcp_event_data_sent(struct tcp_sock *tp, |
| 146 | struct sk_buff *skb, struct sock *sk) | 148 | struct sk_buff *skb, struct sock *sk) |
| 147 | { | 149 | { |
| @@ -161,6 +163,7 @@ static void tcp_event_data_sent(struct tcp_sock *tp, | |||
| 161 | icsk->icsk_ack.pingpong = 1; | 163 | icsk->icsk_ack.pingpong = 1; |
| 162 | } | 164 | } |
| 163 | 165 | ||
| 166 | /* Account for an ACK we sent. */ | ||
| 164 | static inline void tcp_event_ack_sent(struct sock *sk, unsigned int pkts) | 167 | static inline void tcp_event_ack_sent(struct sock *sk, unsigned int pkts) |
| 165 | { | 168 | { |
| 166 | tcp_dec_quickack_mode(sk, pkts); | 169 | tcp_dec_quickack_mode(sk, pkts); |
| @@ -276,6 +279,7 @@ static u16 tcp_select_window(struct sock *sk) | |||
| 276 | return new_win; | 279 | return new_win; |
| 277 | } | 280 | } |
| 278 | 281 | ||
| 282 | /* Packet ECN state for a SYN-ACK */ | ||
| 279 | static inline void TCP_ECN_send_synack(struct tcp_sock *tp, struct sk_buff *skb) | 283 | static inline void TCP_ECN_send_synack(struct tcp_sock *tp, struct sk_buff *skb) |
| 280 | { | 284 | { |
| 281 | TCP_SKB_CB(skb)->flags &= ~TCPCB_FLAG_CWR; | 285 | TCP_SKB_CB(skb)->flags &= ~TCPCB_FLAG_CWR; |
| @@ -283,6 +287,7 @@ static inline void TCP_ECN_send_synack(struct tcp_sock *tp, struct sk_buff *skb) | |||
| 283 | TCP_SKB_CB(skb)->flags &= ~TCPCB_FLAG_ECE; | 287 | TCP_SKB_CB(skb)->flags &= ~TCPCB_FLAG_ECE; |
| 284 | } | 288 | } |
| 285 | 289 | ||
| 290 | /* Packet ECN state for a SYN. */ | ||
| 286 | static inline void TCP_ECN_send_syn(struct sock *sk, struct sk_buff *skb) | 291 | static inline void TCP_ECN_send_syn(struct sock *sk, struct sk_buff *skb) |
| 287 | { | 292 | { |
| 288 | struct tcp_sock *tp = tcp_sk(sk); | 293 | struct tcp_sock *tp = tcp_sk(sk); |
| @@ -301,6 +306,9 @@ TCP_ECN_make_synack(struct request_sock *req, struct tcphdr *th) | |||
| 301 | th->ece = 1; | 306 | th->ece = 1; |
| 302 | } | 307 | } |
| 303 | 308 | ||
| 309 | /* Set up ECN state for a packet on a ESTABLISHED socket that is about to | ||
| 310 | * be sent. | ||
| 311 | */ | ||
| 304 | static inline void TCP_ECN_send(struct sock *sk, struct sk_buff *skb, | 312 | static inline void TCP_ECN_send(struct sock *sk, struct sk_buff *skb, |
| 305 | int tcp_header_len) | 313 | int tcp_header_len) |
| 306 | { | 314 | { |
| @@ -362,7 +370,9 @@ struct tcp_out_options { | |||
| 362 | __u32 tsval, tsecr; /* need to include OPTION_TS */ | 370 | __u32 tsval, tsecr; /* need to include OPTION_TS */ |
| 363 | }; | 371 | }; |
| 364 | 372 | ||
| 365 | /* Beware: Something in the Internet is very sensitive to the ordering of | 373 | /* Write previously computed TCP options to the packet. |
| 374 | * | ||
| 375 | * 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. | 376 | * 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 | 377 | * 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 | 378 | * inter-operatibility perspective it seems that we're somewhat stuck with |
| @@ -445,6 +455,9 @@ static void tcp_options_write(__be32 *ptr, struct tcp_sock *tp, | |||
| 445 | } | 455 | } |
| 446 | } | 456 | } |
| 447 | 457 | ||
| 458 | /* Compute TCP options for SYN packets. This is not the final | ||
| 459 | * network wire format yet. | ||
| 460 | */ | ||
| 448 | static unsigned tcp_syn_options(struct sock *sk, struct sk_buff *skb, | 461 | static unsigned tcp_syn_options(struct sock *sk, struct sk_buff *skb, |
| 449 | struct tcp_out_options *opts, | 462 | struct tcp_out_options *opts, |
| 450 | struct tcp_md5sig_key **md5) { | 463 | struct tcp_md5sig_key **md5) { |
| @@ -493,6 +506,7 @@ static unsigned tcp_syn_options(struct sock *sk, struct sk_buff *skb, | |||
| 493 | return size; | 506 | return size; |
| 494 | } | 507 | } |
| 495 | 508 | ||
| 509 | /* Set up TCP options for SYN-ACKs. */ | ||
| 496 | static unsigned tcp_synack_options(struct sock *sk, | 510 | static unsigned tcp_synack_options(struct sock *sk, |
| 497 | struct request_sock *req, | 511 | struct request_sock *req, |
| 498 | unsigned mss, struct sk_buff *skb, | 512 | unsigned mss, struct sk_buff *skb, |
| @@ -541,6 +555,9 @@ static unsigned tcp_synack_options(struct sock *sk, | |||
| 541 | return size; | 555 | return size; |
| 542 | } | 556 | } |
| 543 | 557 | ||
| 558 | /* Compute TCP options for ESTABLISHED sockets. This is not the | ||
| 559 | * final wire format yet. | ||
| 560 | */ | ||
| 544 | static unsigned tcp_established_options(struct sock *sk, struct sk_buff *skb, | 561 | static unsigned tcp_established_options(struct sock *sk, struct sk_buff *skb, |
| 545 | struct tcp_out_options *opts, | 562 | struct tcp_out_options *opts, |
| 546 | struct tcp_md5sig_key **md5) { | 563 | struct tcp_md5sig_key **md5) { |
| @@ -705,7 +722,7 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it, | |||
| 705 | return net_xmit_eval(err); | 722 | return net_xmit_eval(err); |
| 706 | } | 723 | } |
| 707 | 724 | ||
| 708 | /* This routine just queue's the buffer | 725 | /* This routine just queues the buffer for sending. |
| 709 | * | 726 | * |
| 710 | * NOTE: probe0 timer is not checked, do not forget tcp_push_pending_frames, | 727 | * NOTE: probe0 timer is not checked, do not forget tcp_push_pending_frames, |
| 711 | * otherwise socket can stall. | 728 | * otherwise socket can stall. |
| @@ -722,6 +739,7 @@ static void tcp_queue_skb(struct sock *sk, struct sk_buff *skb) | |||
| 722 | sk_mem_charge(sk, skb->truesize); | 739 | sk_mem_charge(sk, skb->truesize); |
| 723 | } | 740 | } |
| 724 | 741 | ||
| 742 | /* Initialize TSO segments for a packet. */ | ||
| 725 | static void tcp_set_skb_tso_segs(struct sock *sk, struct sk_buff *skb, | 743 | static void tcp_set_skb_tso_segs(struct sock *sk, struct sk_buff *skb, |
| 726 | unsigned int mss_now) | 744 | unsigned int mss_now) |
| 727 | { | 745 | { |
| @@ -909,6 +927,7 @@ static void __pskb_trim_head(struct sk_buff *skb, int len) | |||
| 909 | skb->len = skb->data_len; | 927 | skb->len = skb->data_len; |
| 910 | } | 928 | } |
| 911 | 929 | ||
| 930 | /* Remove acked data from a packet in the transmit queue. */ | ||
| 912 | int tcp_trim_head(struct sock *sk, struct sk_buff *skb, u32 len) | 931 | int tcp_trim_head(struct sock *sk, struct sk_buff *skb, u32 len) |
| 913 | { | 932 | { |
| 914 | if (skb_cloned(skb) && pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) | 933 | if (skb_cloned(skb) && pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) |
| @@ -937,7 +956,7 @@ int tcp_trim_head(struct sock *sk, struct sk_buff *skb, u32 len) | |||
| 937 | return 0; | 956 | return 0; |
| 938 | } | 957 | } |
| 939 | 958 | ||
| 940 | /* Not accounting for SACKs here. */ | 959 | /* Calculate MSS. Not accounting for SACKs here. */ |
| 941 | int tcp_mtu_to_mss(struct sock *sk, int pmtu) | 960 | int tcp_mtu_to_mss(struct sock *sk, int pmtu) |
| 942 | { | 961 | { |
| 943 | struct tcp_sock *tp = tcp_sk(sk); | 962 | struct tcp_sock *tp = tcp_sk(sk); |
| @@ -981,6 +1000,7 @@ int tcp_mss_to_mtu(struct sock *sk, int mss) | |||
| 981 | return mtu; | 1000 | return mtu; |
| 982 | } | 1001 | } |
| 983 | 1002 | ||
| 1003 | /* MTU probing init per socket */ | ||
| 984 | void tcp_mtup_init(struct sock *sk) | 1004 | void tcp_mtup_init(struct sock *sk) |
| 985 | { | 1005 | { |
| 986 | struct tcp_sock *tp = tcp_sk(sk); | 1006 | struct tcp_sock *tp = tcp_sk(sk); |
| @@ -1143,7 +1163,8 @@ static inline unsigned int tcp_cwnd_test(struct tcp_sock *tp, | |||
| 1143 | return 0; | 1163 | return 0; |
| 1144 | } | 1164 | } |
| 1145 | 1165 | ||
| 1146 | /* This must be invoked the first time we consider transmitting | 1166 | /* Intialize TSO state of a skb. |
| 1167 | * This must be invoked the first time we consider transmitting | ||
| 1147 | * SKB onto the wire. | 1168 | * SKB onto the wire. |
| 1148 | */ | 1169 | */ |
| 1149 | static int tcp_init_tso_segs(struct sock *sk, struct sk_buff *skb, | 1170 | static int tcp_init_tso_segs(struct sock *sk, struct sk_buff *skb, |
| @@ -1158,6 +1179,7 @@ static int tcp_init_tso_segs(struct sock *sk, struct sk_buff *skb, | |||
| 1158 | return tso_segs; | 1179 | return tso_segs; |
| 1159 | } | 1180 | } |
| 1160 | 1181 | ||
| 1182 | /* Minshall's variant of the Nagle send check. */ | ||
| 1161 | static inline int tcp_minshall_check(const struct tcp_sock *tp) | 1183 | static inline int tcp_minshall_check(const struct tcp_sock *tp) |
| 1162 | { | 1184 | { |
| 1163 | return after(tp->snd_sml, tp->snd_una) && | 1185 | return after(tp->snd_sml, tp->snd_una) && |
| @@ -1242,6 +1264,7 @@ static unsigned int tcp_snd_test(struct sock *sk, struct sk_buff *skb, | |||
| 1242 | return cwnd_quota; | 1264 | return cwnd_quota; |
| 1243 | } | 1265 | } |
| 1244 | 1266 | ||
| 1267 | /* Test if sending is allowed right now. */ | ||
| 1245 | int tcp_may_send_now(struct sock *sk) | 1268 | int tcp_may_send_now(struct sock *sk) |
| 1246 | { | 1269 | { |
| 1247 | struct tcp_sock *tp = tcp_sk(sk); | 1270 | struct tcp_sock *tp = tcp_sk(sk); |
| @@ -1378,6 +1401,10 @@ send_now: | |||
| 1378 | } | 1401 | } |
| 1379 | 1402 | ||
| 1380 | /* Create a new MTU probe if we are ready. | 1403 | /* Create a new MTU probe if we are ready. |
| 1404 | * MTU probe is regularly attempting to increase the path MTU by | ||
| 1405 | * deliberately sending larger packets. This discovers routing | ||
| 1406 | * changes resulting in larger path MTUs. | ||
| 1407 | * | ||
| 1381 | * Returns 0 if we should wait to probe (no cwnd available), | 1408 | * Returns 0 if we should wait to probe (no cwnd available), |
| 1382 | * 1 if a probe was sent, | 1409 | * 1 if a probe was sent, |
| 1383 | * -1 otherwise | 1410 | * -1 otherwise |
| @@ -1790,6 +1817,7 @@ static void tcp_collapse_retrans(struct sock *sk, struct sk_buff *skb) | |||
| 1790 | sk_wmem_free_skb(sk, next_skb); | 1817 | sk_wmem_free_skb(sk, next_skb); |
| 1791 | } | 1818 | } |
| 1792 | 1819 | ||
| 1820 | /* Check if coalescing SKBs is legal. */ | ||
| 1793 | static int tcp_can_collapse(struct sock *sk, struct sk_buff *skb) | 1821 | static int tcp_can_collapse(struct sock *sk, struct sk_buff *skb) |
| 1794 | { | 1822 | { |
| 1795 | if (tcp_skb_pcount(skb) > 1) | 1823 | if (tcp_skb_pcount(skb) > 1) |
| @@ -1808,6 +1836,9 @@ static int tcp_can_collapse(struct sock *sk, struct sk_buff *skb) | |||
| 1808 | return 1; | 1836 | return 1; |
| 1809 | } | 1837 | } |
| 1810 | 1838 | ||
| 1839 | /* Collapse packets in the retransmit queue to make to create | ||
| 1840 | * less packets on the wire. This is only done on retransmission. | ||
| 1841 | */ | ||
| 1811 | static void tcp_retrans_try_collapse(struct sock *sk, struct sk_buff *to, | 1842 | static void tcp_retrans_try_collapse(struct sock *sk, struct sk_buff *to, |
| 1812 | int space) | 1843 | int space) |
| 1813 | { | 1844 | { |
| @@ -1957,6 +1988,9 @@ int tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb) | |||
| 1957 | return err; | 1988 | return err; |
| 1958 | } | 1989 | } |
| 1959 | 1990 | ||
| 1991 | /* Check if we forward retransmits are possible in the current | ||
| 1992 | * window/congestion state. | ||
| 1993 | */ | ||
| 1960 | static int tcp_can_forward_retransmit(struct sock *sk) | 1994 | static int tcp_can_forward_retransmit(struct sock *sk) |
| 1961 | { | 1995 | { |
| 1962 | const struct inet_connection_sock *icsk = inet_csk(sk); | 1996 | const struct inet_connection_sock *icsk = inet_csk(sk); |
| @@ -2145,7 +2179,8 @@ void tcp_send_active_reset(struct sock *sk, gfp_t priority) | |||
| 2145 | TCP_INC_STATS(sock_net(sk), TCP_MIB_OUTRSTS); | 2179 | TCP_INC_STATS(sock_net(sk), TCP_MIB_OUTRSTS); |
| 2146 | } | 2180 | } |
| 2147 | 2181 | ||
| 2148 | /* WARNING: This routine must only be called when we have already sent | 2182 | /* Send a crossed SYN-ACK during socket establishment. |
| 2183 | * WARNING: This routine must only be called when we have already sent | ||
| 2149 | * a SYN packet that crossed the incoming SYN that caused this routine | 2184 | * a SYN packet that crossed the incoming SYN that caused this routine |
| 2150 | * to get called. If this assumption fails then the initial rcv_wnd | 2185 | * to get called. If this assumption fails then the initial rcv_wnd |
| 2151 | * and rcv_wscale values will not be correct. | 2186 | * and rcv_wscale values will not be correct. |
| @@ -2180,9 +2215,7 @@ int tcp_send_synack(struct sock *sk) | |||
| 2180 | return tcp_transmit_skb(sk, skb, 1, GFP_ATOMIC); | 2215 | return tcp_transmit_skb(sk, skb, 1, GFP_ATOMIC); |
| 2181 | } | 2216 | } |
| 2182 | 2217 | ||
| 2183 | /* | 2218 | /* Prepare a SYN-ACK. */ |
| 2184 | * Prepare a SYN-ACK. | ||
| 2185 | */ | ||
| 2186 | struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst, | 2219 | struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst, |
| 2187 | struct request_sock *req) | 2220 | struct request_sock *req) |
| 2188 | { | 2221 | { |
| @@ -2269,9 +2302,7 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst, | |||
| 2269 | return skb; | 2302 | return skb; |
| 2270 | } | 2303 | } |
| 2271 | 2304 | ||
| 2272 | /* | 2305 | /* Do all connect socket setups that can be done AF independent. */ |
| 2273 | * Do all connect socket setups that can be done AF independent. | ||
| 2274 | */ | ||
| 2275 | static void tcp_connect_init(struct sock *sk) | 2306 | static void tcp_connect_init(struct sock *sk) |
| 2276 | { | 2307 | { |
| 2277 | struct dst_entry *dst = __sk_dst_get(sk); | 2308 | struct dst_entry *dst = __sk_dst_get(sk); |
| @@ -2330,9 +2361,7 @@ static void tcp_connect_init(struct sock *sk) | |||
| 2330 | tcp_clear_retrans(tp); | 2361 | tcp_clear_retrans(tp); |
| 2331 | } | 2362 | } |
| 2332 | 2363 | ||
| 2333 | /* | 2364 | /* Build a SYN and send it off. */ |
| 2334 | * Build a SYN and send it off. | ||
| 2335 | */ | ||
| 2336 | int tcp_connect(struct sock *sk) | 2365 | int tcp_connect(struct sock *sk) |
| 2337 | { | 2366 | { |
| 2338 | struct tcp_sock *tp = tcp_sk(sk); | 2367 | struct tcp_sock *tp = tcp_sk(sk); |
| @@ -2493,6 +2522,7 @@ static int tcp_xmit_probe_skb(struct sock *sk, int urgent) | |||
| 2493 | return tcp_transmit_skb(sk, skb, 0, GFP_ATOMIC); | 2522 | return tcp_transmit_skb(sk, skb, 0, GFP_ATOMIC); |
| 2494 | } | 2523 | } |
| 2495 | 2524 | ||
| 2525 | /* Initiate keepalive or window probe from timer. */ | ||
| 2496 | int tcp_write_wakeup(struct sock *sk) | 2526 | int tcp_write_wakeup(struct sock *sk) |
| 2497 | { | 2527 | { |
| 2498 | struct tcp_sock *tp = tcp_sk(sk); | 2528 | struct tcp_sock *tp = tcp_sk(sk); |
