11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * INET An implementation of the TCP/IP protocol suite for the LINUX 31da177e4SLinus Torvalds * operating system. INET is implemented using the BSD Socket 41da177e4SLinus Torvalds * interface as the means of communication with the user level. 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * Definitions for the TCP module. 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * Version: @(#)tcp.h 1.0.5 05/23/93 91da177e4SLinus Torvalds * 1002c30a84SJesper Juhl * Authors: Ross Biro 111da177e4SLinus Torvalds * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> 121da177e4SLinus Torvalds * 131da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or 141da177e4SLinus Torvalds * modify it under the terms of the GNU General Public License 151da177e4SLinus Torvalds * as published by the Free Software Foundation; either version 161da177e4SLinus Torvalds * 2 of the License, or (at your option) any later version. 171da177e4SLinus Torvalds */ 181da177e4SLinus Torvalds #ifndef _TCP_H 191da177e4SLinus Torvalds #define _TCP_H 201da177e4SLinus Torvalds 211da177e4SLinus Torvalds #define TCP_DEBUG 1 221da177e4SLinus Torvalds #define FASTRETRANS_DEBUG 1 231da177e4SLinus Torvalds 241da177e4SLinus Torvalds #include <linux/config.h> 251da177e4SLinus Torvalds #include <linux/list.h> 261da177e4SLinus Torvalds #include <linux/tcp.h> 271da177e4SLinus Torvalds #include <linux/slab.h> 281da177e4SLinus Torvalds #include <linux/cache.h> 291da177e4SLinus Torvalds #include <linux/percpu.h> 30fb286bb2SHerbert Xu #include <linux/skbuff.h> 313f421baaSArnaldo Carvalho de Melo 323f421baaSArnaldo Carvalho de Melo #include <net/inet_connection_sock.h> 33295ff7edSArnaldo Carvalho de Melo #include <net/inet_timewait_sock.h> 3477d8bf9cSArnaldo Carvalho de Melo #include <net/inet_hashtables.h> 351da177e4SLinus Torvalds #include <net/checksum.h> 362e6599cbSArnaldo Carvalho de Melo #include <net/request_sock.h> 371da177e4SLinus Torvalds #include <net/sock.h> 381da177e4SLinus Torvalds #include <net/snmp.h> 391da177e4SLinus Torvalds #include <net/ip.h> 40c752f073SArnaldo Carvalho de Melo #include <net/tcp_states.h> 41c752f073SArnaldo Carvalho de Melo 421da177e4SLinus Torvalds #include <linux/seq_file.h> 431da177e4SLinus Torvalds 440f7ff927SArnaldo Carvalho de Melo extern struct inet_hashinfo tcp_hashinfo; 451da177e4SLinus Torvalds 461da177e4SLinus Torvalds extern atomic_t tcp_orphan_count; 471da177e4SLinus Torvalds extern void tcp_time_wait(struct sock *sk, int state, int timeo); 481da177e4SLinus Torvalds 491da177e4SLinus Torvalds #define MAX_TCP_HEADER (128 + MAX_HEADER) 501da177e4SLinus Torvalds 511da177e4SLinus Torvalds /* 521da177e4SLinus Torvalds * Never offer a window over 32767 without using window scaling. Some 531da177e4SLinus Torvalds * poor stacks do signed 16bit maths! 541da177e4SLinus Torvalds */ 551da177e4SLinus Torvalds #define MAX_TCP_WINDOW 32767U 561da177e4SLinus Torvalds 571da177e4SLinus Torvalds /* Minimal accepted MSS. It is (60+60+8) - (20+20). */ 581da177e4SLinus Torvalds #define TCP_MIN_MSS 88U 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds /* Minimal RCV_MSS. */ 611da177e4SLinus Torvalds #define TCP_MIN_RCVMSS 536U 621da177e4SLinus Torvalds 63*5d424d5aSJohn Heffner /* The least MTU to use for probing */ 64*5d424d5aSJohn Heffner #define TCP_BASE_MSS 512 65*5d424d5aSJohn Heffner 661da177e4SLinus Torvalds /* After receiving this amount of duplicate ACKs fast retransmit starts. */ 671da177e4SLinus Torvalds #define TCP_FASTRETRANS_THRESH 3 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds /* Maximal reordering. */ 701da177e4SLinus Torvalds #define TCP_MAX_REORDERING 127 711da177e4SLinus Torvalds 721da177e4SLinus Torvalds /* Maximal number of ACKs sent quickly to accelerate slow-start. */ 731da177e4SLinus Torvalds #define TCP_MAX_QUICKACKS 16U 741da177e4SLinus Torvalds 751da177e4SLinus Torvalds /* urg_data states */ 761da177e4SLinus Torvalds #define TCP_URG_VALID 0x0100 771da177e4SLinus Torvalds #define TCP_URG_NOTYET 0x0200 781da177e4SLinus Torvalds #define TCP_URG_READ 0x0400 791da177e4SLinus Torvalds 801da177e4SLinus Torvalds #define TCP_RETR1 3 /* 811da177e4SLinus Torvalds * This is how many retries it does before it 821da177e4SLinus Torvalds * tries to figure out if the gateway is 831da177e4SLinus Torvalds * down. Minimal RFC value is 3; it corresponds 841da177e4SLinus Torvalds * to ~3sec-8min depending on RTO. 851da177e4SLinus Torvalds */ 861da177e4SLinus Torvalds 871da177e4SLinus Torvalds #define TCP_RETR2 15 /* 881da177e4SLinus Torvalds * This should take at least 891da177e4SLinus Torvalds * 90 minutes to time out. 901da177e4SLinus Torvalds * RFC1122 says that the limit is 100 sec. 911da177e4SLinus Torvalds * 15 is ~13-30min depending on RTO. 921da177e4SLinus Torvalds */ 931da177e4SLinus Torvalds 941da177e4SLinus Torvalds #define TCP_SYN_RETRIES 5 /* number of times to retry active opening a 95caa20d9aSStephen Hemminger * connection: ~180sec is RFC minimum */ 961da177e4SLinus Torvalds 971da177e4SLinus Torvalds #define TCP_SYNACK_RETRIES 5 /* number of times to retry passive opening a 98caa20d9aSStephen Hemminger * connection: ~180sec is RFC minimum */ 991da177e4SLinus Torvalds 1001da177e4SLinus Torvalds 1011da177e4SLinus Torvalds #define TCP_ORPHAN_RETRIES 7 /* number of times to retry on an orphaned 1021da177e4SLinus Torvalds * socket. 7 is ~50sec-16min. 1031da177e4SLinus Torvalds */ 1041da177e4SLinus Torvalds 1051da177e4SLinus Torvalds 1061da177e4SLinus Torvalds #define TCP_TIMEWAIT_LEN (60*HZ) /* how long to wait to destroy TIME-WAIT 1071da177e4SLinus Torvalds * state, about 60 seconds */ 1081da177e4SLinus Torvalds #define TCP_FIN_TIMEOUT TCP_TIMEWAIT_LEN 1091da177e4SLinus Torvalds /* BSD style FIN_WAIT2 deadlock breaker. 1101da177e4SLinus Torvalds * It used to be 3min, new value is 60sec, 1111da177e4SLinus Torvalds * to combine FIN-WAIT-2 timeout with 1121da177e4SLinus Torvalds * TIME-WAIT timer. 1131da177e4SLinus Torvalds */ 1141da177e4SLinus Torvalds 1151da177e4SLinus Torvalds #define TCP_DELACK_MAX ((unsigned)(HZ/5)) /* maximal time to delay before sending an ACK */ 1161da177e4SLinus Torvalds #if HZ >= 100 1171da177e4SLinus Torvalds #define TCP_DELACK_MIN ((unsigned)(HZ/25)) /* minimal time to delay before sending an ACK */ 1181da177e4SLinus Torvalds #define TCP_ATO_MIN ((unsigned)(HZ/25)) 1191da177e4SLinus Torvalds #else 1201da177e4SLinus Torvalds #define TCP_DELACK_MIN 4U 1211da177e4SLinus Torvalds #define TCP_ATO_MIN 4U 1221da177e4SLinus Torvalds #endif 1231da177e4SLinus Torvalds #define TCP_RTO_MAX ((unsigned)(120*HZ)) 1241da177e4SLinus Torvalds #define TCP_RTO_MIN ((unsigned)(HZ/5)) 1251da177e4SLinus Torvalds #define TCP_TIMEOUT_INIT ((unsigned)(3*HZ)) /* RFC 1122 initial RTO value */ 1261da177e4SLinus Torvalds 1271da177e4SLinus Torvalds #define TCP_RESOURCE_PROBE_INTERVAL ((unsigned)(HZ/2U)) /* Maximal interval between probes 1281da177e4SLinus Torvalds * for local resources. 1291da177e4SLinus Torvalds */ 1301da177e4SLinus Torvalds 1311da177e4SLinus Torvalds #define TCP_KEEPALIVE_TIME (120*60*HZ) /* two hours */ 1321da177e4SLinus Torvalds #define TCP_KEEPALIVE_PROBES 9 /* Max of 9 keepalive probes */ 1331da177e4SLinus Torvalds #define TCP_KEEPALIVE_INTVL (75*HZ) 1341da177e4SLinus Torvalds 1351da177e4SLinus Torvalds #define MAX_TCP_KEEPIDLE 32767 1361da177e4SLinus Torvalds #define MAX_TCP_KEEPINTVL 32767 1371da177e4SLinus Torvalds #define MAX_TCP_KEEPCNT 127 1381da177e4SLinus Torvalds #define MAX_TCP_SYNCNT 127 1391da177e4SLinus Torvalds 1401da177e4SLinus Torvalds #define TCP_SYNQ_INTERVAL (HZ/5) /* Period of SYNACK timer */ 1411da177e4SLinus Torvalds #define TCP_SYNQ_HSIZE 512 /* Size of SYNACK hash table */ 1421da177e4SLinus Torvalds 1431da177e4SLinus Torvalds #define TCP_PAWS_24DAYS (60 * 60 * 24 * 24) 1441da177e4SLinus Torvalds #define TCP_PAWS_MSL 60 /* Per-host timestamps are invalidated 1451da177e4SLinus Torvalds * after this time. It should be equal 1461da177e4SLinus Torvalds * (or greater than) TCP_TIMEWAIT_LEN 1471da177e4SLinus Torvalds * to provide reliability equal to one 1481da177e4SLinus Torvalds * provided by timewait state. 1491da177e4SLinus Torvalds */ 1501da177e4SLinus Torvalds #define TCP_PAWS_WINDOW 1 /* Replay window for per-host 1511da177e4SLinus Torvalds * timestamps. It must be less than 1521da177e4SLinus Torvalds * minimal timewait lifetime. 1531da177e4SLinus Torvalds */ 1541da177e4SLinus Torvalds /* 1551da177e4SLinus Torvalds * TCP option 1561da177e4SLinus Torvalds */ 1571da177e4SLinus Torvalds 1581da177e4SLinus Torvalds #define TCPOPT_NOP 1 /* Padding */ 1591da177e4SLinus Torvalds #define TCPOPT_EOL 0 /* End of options */ 1601da177e4SLinus Torvalds #define TCPOPT_MSS 2 /* Segment size negotiating */ 1611da177e4SLinus Torvalds #define TCPOPT_WINDOW 3 /* Window scaling */ 1621da177e4SLinus Torvalds #define TCPOPT_SACK_PERM 4 /* SACK Permitted */ 1631da177e4SLinus Torvalds #define TCPOPT_SACK 5 /* SACK Block */ 1641da177e4SLinus Torvalds #define TCPOPT_TIMESTAMP 8 /* Better RTT estimations/PAWS */ 1651da177e4SLinus Torvalds 1661da177e4SLinus Torvalds /* 1671da177e4SLinus Torvalds * TCP option lengths 1681da177e4SLinus Torvalds */ 1691da177e4SLinus Torvalds 1701da177e4SLinus Torvalds #define TCPOLEN_MSS 4 1711da177e4SLinus Torvalds #define TCPOLEN_WINDOW 3 1721da177e4SLinus Torvalds #define TCPOLEN_SACK_PERM 2 1731da177e4SLinus Torvalds #define TCPOLEN_TIMESTAMP 10 1741da177e4SLinus Torvalds 1751da177e4SLinus Torvalds /* But this is what stacks really send out. */ 1761da177e4SLinus Torvalds #define TCPOLEN_TSTAMP_ALIGNED 12 1771da177e4SLinus Torvalds #define TCPOLEN_WSCALE_ALIGNED 4 1781da177e4SLinus Torvalds #define TCPOLEN_SACKPERM_ALIGNED 4 1791da177e4SLinus Torvalds #define TCPOLEN_SACK_BASE 2 1801da177e4SLinus Torvalds #define TCPOLEN_SACK_BASE_ALIGNED 4 1811da177e4SLinus Torvalds #define TCPOLEN_SACK_PERBLOCK 8 1821da177e4SLinus Torvalds 1831da177e4SLinus Torvalds /* Flags in tp->nonagle */ 1841da177e4SLinus Torvalds #define TCP_NAGLE_OFF 1 /* Nagle's algo is disabled */ 1851da177e4SLinus Torvalds #define TCP_NAGLE_CORK 2 /* Socket is corked */ 186caa20d9aSStephen Hemminger #define TCP_NAGLE_PUSH 4 /* Cork is overridden for already queued data */ 1871da177e4SLinus Torvalds 188295ff7edSArnaldo Carvalho de Melo extern struct inet_timewait_death_row tcp_death_row; 189295ff7edSArnaldo Carvalho de Melo 1901da177e4SLinus Torvalds /* sysctl variables for tcp */ 1911da177e4SLinus Torvalds extern int sysctl_tcp_timestamps; 1921da177e4SLinus Torvalds extern int sysctl_tcp_window_scaling; 1931da177e4SLinus Torvalds extern int sysctl_tcp_sack; 1941da177e4SLinus Torvalds extern int sysctl_tcp_fin_timeout; 1951da177e4SLinus Torvalds extern int sysctl_tcp_keepalive_time; 1961da177e4SLinus Torvalds extern int sysctl_tcp_keepalive_probes; 1971da177e4SLinus Torvalds extern int sysctl_tcp_keepalive_intvl; 1981da177e4SLinus Torvalds extern int sysctl_tcp_syn_retries; 1991da177e4SLinus Torvalds extern int sysctl_tcp_synack_retries; 2001da177e4SLinus Torvalds extern int sysctl_tcp_retries1; 2011da177e4SLinus Torvalds extern int sysctl_tcp_retries2; 2021da177e4SLinus Torvalds extern int sysctl_tcp_orphan_retries; 2031da177e4SLinus Torvalds extern int sysctl_tcp_syncookies; 2041da177e4SLinus Torvalds extern int sysctl_tcp_retrans_collapse; 2051da177e4SLinus Torvalds extern int sysctl_tcp_stdurg; 2061da177e4SLinus Torvalds extern int sysctl_tcp_rfc1337; 2071da177e4SLinus Torvalds extern int sysctl_tcp_abort_on_overflow; 2081da177e4SLinus Torvalds extern int sysctl_tcp_max_orphans; 2091da177e4SLinus Torvalds extern int sysctl_tcp_fack; 2101da177e4SLinus Torvalds extern int sysctl_tcp_reordering; 2111da177e4SLinus Torvalds extern int sysctl_tcp_ecn; 2121da177e4SLinus Torvalds extern int sysctl_tcp_dsack; 2131da177e4SLinus Torvalds extern int sysctl_tcp_mem[3]; 2141da177e4SLinus Torvalds extern int sysctl_tcp_wmem[3]; 2151da177e4SLinus Torvalds extern int sysctl_tcp_rmem[3]; 2161da177e4SLinus Torvalds extern int sysctl_tcp_app_win; 2171da177e4SLinus Torvalds extern int sysctl_tcp_adv_win_scale; 2181da177e4SLinus Torvalds extern int sysctl_tcp_tw_reuse; 2191da177e4SLinus Torvalds extern int sysctl_tcp_frto; 2201da177e4SLinus Torvalds extern int sysctl_tcp_low_latency; 2211da177e4SLinus Torvalds extern int sysctl_tcp_nometrics_save; 2221da177e4SLinus Torvalds extern int sysctl_tcp_moderate_rcvbuf; 2231da177e4SLinus Torvalds extern int sysctl_tcp_tso_win_divisor; 2249772efb9SStephen Hemminger extern int sysctl_tcp_abc; 225*5d424d5aSJohn Heffner extern int sysctl_tcp_mtu_probing; 226*5d424d5aSJohn Heffner extern int sysctl_tcp_base_mss; 2271da177e4SLinus Torvalds 2281da177e4SLinus Torvalds extern atomic_t tcp_memory_allocated; 2291da177e4SLinus Torvalds extern atomic_t tcp_sockets_allocated; 2301da177e4SLinus Torvalds extern int tcp_memory_pressure; 2311da177e4SLinus Torvalds 2321da177e4SLinus Torvalds /* 2331da177e4SLinus Torvalds * The next routines deal with comparing 32 bit unsigned ints 2341da177e4SLinus Torvalds * and worry about wraparound (automatic with unsigned arithmetic). 2351da177e4SLinus Torvalds */ 2361da177e4SLinus Torvalds 2371da177e4SLinus Torvalds static inline int before(__u32 seq1, __u32 seq2) 2381da177e4SLinus Torvalds { 2391da177e4SLinus Torvalds return (__s32)(seq1-seq2) < 0; 2401da177e4SLinus Torvalds } 2411da177e4SLinus Torvalds 2421da177e4SLinus Torvalds static inline int after(__u32 seq1, __u32 seq2) 2431da177e4SLinus Torvalds { 2441da177e4SLinus Torvalds return (__s32)(seq2-seq1) < 0; 2451da177e4SLinus Torvalds } 2461da177e4SLinus Torvalds 2471da177e4SLinus Torvalds 2481da177e4SLinus Torvalds /* is s2<=s1<=s3 ? */ 2491da177e4SLinus Torvalds static inline int between(__u32 seq1, __u32 seq2, __u32 seq3) 2501da177e4SLinus Torvalds { 2511da177e4SLinus Torvalds return seq3 - seq2 >= seq1 - seq2; 2521da177e4SLinus Torvalds } 2531da177e4SLinus Torvalds 2541da177e4SLinus Torvalds 2551da177e4SLinus Torvalds extern struct proto tcp_prot; 2561da177e4SLinus Torvalds 2571da177e4SLinus Torvalds DECLARE_SNMP_STAT(struct tcp_mib, tcp_statistics); 2581da177e4SLinus Torvalds #define TCP_INC_STATS(field) SNMP_INC_STATS(tcp_statistics, field) 2591da177e4SLinus Torvalds #define TCP_INC_STATS_BH(field) SNMP_INC_STATS_BH(tcp_statistics, field) 2601da177e4SLinus Torvalds #define TCP_INC_STATS_USER(field) SNMP_INC_STATS_USER(tcp_statistics, field) 2611da177e4SLinus Torvalds #define TCP_DEC_STATS(field) SNMP_DEC_STATS(tcp_statistics, field) 2621da177e4SLinus Torvalds #define TCP_ADD_STATS_BH(field, val) SNMP_ADD_STATS_BH(tcp_statistics, field, val) 2631da177e4SLinus Torvalds #define TCP_ADD_STATS_USER(field, val) SNMP_ADD_STATS_USER(tcp_statistics, field, val) 2641da177e4SLinus Torvalds 2651da177e4SLinus Torvalds extern void tcp_v4_err(struct sk_buff *skb, u32); 2661da177e4SLinus Torvalds 2671da177e4SLinus Torvalds extern void tcp_shutdown (struct sock *sk, int how); 2681da177e4SLinus Torvalds 2691da177e4SLinus Torvalds extern int tcp_v4_rcv(struct sk_buff *skb); 2701da177e4SLinus Torvalds 2711da177e4SLinus Torvalds extern int tcp_v4_remember_stamp(struct sock *sk); 2721da177e4SLinus Torvalds 2738feaf0c0SArnaldo Carvalho de Melo extern int tcp_v4_tw_remember_stamp(struct inet_timewait_sock *tw); 2741da177e4SLinus Torvalds 2751da177e4SLinus Torvalds extern int tcp_sendmsg(struct kiocb *iocb, struct sock *sk, 2761da177e4SLinus Torvalds struct msghdr *msg, size_t size); 2771da177e4SLinus Torvalds extern ssize_t tcp_sendpage(struct socket *sock, struct page *page, int offset, size_t size, int flags); 2781da177e4SLinus Torvalds 2791da177e4SLinus Torvalds extern int tcp_ioctl(struct sock *sk, 2801da177e4SLinus Torvalds int cmd, 2811da177e4SLinus Torvalds unsigned long arg); 2821da177e4SLinus Torvalds 2831da177e4SLinus Torvalds extern int tcp_rcv_state_process(struct sock *sk, 2841da177e4SLinus Torvalds struct sk_buff *skb, 2851da177e4SLinus Torvalds struct tcphdr *th, 2861da177e4SLinus Torvalds unsigned len); 2871da177e4SLinus Torvalds 2881da177e4SLinus Torvalds extern int tcp_rcv_established(struct sock *sk, 2891da177e4SLinus Torvalds struct sk_buff *skb, 2901da177e4SLinus Torvalds struct tcphdr *th, 2911da177e4SLinus Torvalds unsigned len); 2921da177e4SLinus Torvalds 2931da177e4SLinus Torvalds extern void tcp_rcv_space_adjust(struct sock *sk); 2941da177e4SLinus Torvalds 2956d6ee43eSArnaldo Carvalho de Melo extern int tcp_twsk_unique(struct sock *sk, 2966d6ee43eSArnaldo Carvalho de Melo struct sock *sktw, void *twp); 2976d6ee43eSArnaldo Carvalho de Melo 298463c84b9SArnaldo Carvalho de Melo static inline void tcp_dec_quickack_mode(struct sock *sk, 299463c84b9SArnaldo Carvalho de Melo const unsigned int pkts) 3001da177e4SLinus Torvalds { 301463c84b9SArnaldo Carvalho de Melo struct inet_connection_sock *icsk = inet_csk(sk); 302fc6415bcSDavid S. Miller 303463c84b9SArnaldo Carvalho de Melo if (icsk->icsk_ack.quick) { 304463c84b9SArnaldo Carvalho de Melo if (pkts >= icsk->icsk_ack.quick) { 305463c84b9SArnaldo Carvalho de Melo icsk->icsk_ack.quick = 0; 3061da177e4SLinus Torvalds /* Leaving quickack mode we deflate ATO. */ 307463c84b9SArnaldo Carvalho de Melo icsk->icsk_ack.ato = TCP_ATO_MIN; 308fc6415bcSDavid S. Miller } else 309463c84b9SArnaldo Carvalho de Melo icsk->icsk_ack.quick -= pkts; 3101da177e4SLinus Torvalds } 3111da177e4SLinus Torvalds } 3121da177e4SLinus Torvalds 313463c84b9SArnaldo Carvalho de Melo extern void tcp_enter_quickack_mode(struct sock *sk); 3141da177e4SLinus Torvalds 3151da177e4SLinus Torvalds static inline void tcp_clear_options(struct tcp_options_received *rx_opt) 3161da177e4SLinus Torvalds { 3171da177e4SLinus Torvalds rx_opt->tstamp_ok = rx_opt->sack_ok = rx_opt->wscale_ok = rx_opt->snd_wscale = 0; 3181da177e4SLinus Torvalds } 3191da177e4SLinus Torvalds 3201da177e4SLinus Torvalds enum tcp_tw_status 3211da177e4SLinus Torvalds { 3221da177e4SLinus Torvalds TCP_TW_SUCCESS = 0, 3231da177e4SLinus Torvalds TCP_TW_RST = 1, 3241da177e4SLinus Torvalds TCP_TW_ACK = 2, 3251da177e4SLinus Torvalds TCP_TW_SYN = 3 3261da177e4SLinus Torvalds }; 3271da177e4SLinus Torvalds 3281da177e4SLinus Torvalds 3298feaf0c0SArnaldo Carvalho de Melo extern enum tcp_tw_status tcp_timewait_state_process(struct inet_timewait_sock *tw, 3301da177e4SLinus Torvalds struct sk_buff *skb, 3318feaf0c0SArnaldo Carvalho de Melo const struct tcphdr *th); 3321da177e4SLinus Torvalds 3331da177e4SLinus Torvalds extern struct sock * tcp_check_req(struct sock *sk,struct sk_buff *skb, 33460236fddSArnaldo Carvalho de Melo struct request_sock *req, 33560236fddSArnaldo Carvalho de Melo struct request_sock **prev); 3361da177e4SLinus Torvalds extern int tcp_child_process(struct sock *parent, 3371da177e4SLinus Torvalds struct sock *child, 3381da177e4SLinus Torvalds struct sk_buff *skb); 3391da177e4SLinus Torvalds extern void tcp_enter_frto(struct sock *sk); 3401da177e4SLinus Torvalds extern void tcp_enter_loss(struct sock *sk, int how); 3411da177e4SLinus Torvalds extern void tcp_clear_retrans(struct tcp_sock *tp); 3421da177e4SLinus Torvalds extern void tcp_update_metrics(struct sock *sk); 3431da177e4SLinus Torvalds 3441da177e4SLinus Torvalds extern void tcp_close(struct sock *sk, 3451da177e4SLinus Torvalds long timeout); 3461da177e4SLinus Torvalds extern unsigned int tcp_poll(struct file * file, struct socket *sock, struct poll_table_struct *wait); 3471da177e4SLinus Torvalds 3481da177e4SLinus Torvalds extern int tcp_getsockopt(struct sock *sk, int level, 3491da177e4SLinus Torvalds int optname, 3501da177e4SLinus Torvalds char __user *optval, 3511da177e4SLinus Torvalds int __user *optlen); 3521da177e4SLinus Torvalds extern int tcp_setsockopt(struct sock *sk, int level, 3531da177e4SLinus Torvalds int optname, char __user *optval, 3541da177e4SLinus Torvalds int optlen); 3551da177e4SLinus Torvalds extern void tcp_set_keepalive(struct sock *sk, int val); 3561da177e4SLinus Torvalds extern int tcp_recvmsg(struct kiocb *iocb, struct sock *sk, 3571da177e4SLinus Torvalds struct msghdr *msg, 3581da177e4SLinus Torvalds size_t len, int nonblock, 3591da177e4SLinus Torvalds int flags, int *addr_len); 3601da177e4SLinus Torvalds 3611da177e4SLinus Torvalds extern void tcp_parse_options(struct sk_buff *skb, 3621da177e4SLinus Torvalds struct tcp_options_received *opt_rx, 3631da177e4SLinus Torvalds int estab); 3641da177e4SLinus Torvalds 3651da177e4SLinus Torvalds /* 3661da177e4SLinus Torvalds * TCP v4 functions exported for the inet6 API 3671da177e4SLinus Torvalds */ 3681da177e4SLinus Torvalds 3698292a17aSArnaldo Carvalho de Melo extern void tcp_v4_send_check(struct sock *sk, int len, 3701da177e4SLinus Torvalds struct sk_buff *skb); 3711da177e4SLinus Torvalds 3721da177e4SLinus Torvalds extern int tcp_v4_conn_request(struct sock *sk, 3731da177e4SLinus Torvalds struct sk_buff *skb); 3741da177e4SLinus Torvalds 3751da177e4SLinus Torvalds extern struct sock * tcp_create_openreq_child(struct sock *sk, 37660236fddSArnaldo Carvalho de Melo struct request_sock *req, 3771da177e4SLinus Torvalds struct sk_buff *skb); 3781da177e4SLinus Torvalds 3791da177e4SLinus Torvalds extern struct sock * tcp_v4_syn_recv_sock(struct sock *sk, 3801da177e4SLinus Torvalds struct sk_buff *skb, 38160236fddSArnaldo Carvalho de Melo struct request_sock *req, 3821da177e4SLinus Torvalds struct dst_entry *dst); 3831da177e4SLinus Torvalds 3841da177e4SLinus Torvalds extern int tcp_v4_do_rcv(struct sock *sk, 3851da177e4SLinus Torvalds struct sk_buff *skb); 3861da177e4SLinus Torvalds 3871da177e4SLinus Torvalds extern int tcp_v4_connect(struct sock *sk, 3881da177e4SLinus Torvalds struct sockaddr *uaddr, 3891da177e4SLinus Torvalds int addr_len); 3901da177e4SLinus Torvalds 3911da177e4SLinus Torvalds extern int tcp_connect(struct sock *sk); 3921da177e4SLinus Torvalds 3931da177e4SLinus Torvalds extern struct sk_buff * tcp_make_synack(struct sock *sk, 3941da177e4SLinus Torvalds struct dst_entry *dst, 39560236fddSArnaldo Carvalho de Melo struct request_sock *req); 3961da177e4SLinus Torvalds 3971da177e4SLinus Torvalds extern int tcp_disconnect(struct sock *sk, int flags); 3981da177e4SLinus Torvalds 3991da177e4SLinus Torvalds extern void tcp_unhash(struct sock *sk); 4001da177e4SLinus Torvalds 4011da177e4SLinus Torvalds extern int tcp_v4_hash_connecting(struct sock *sk); 4021da177e4SLinus Torvalds 4031da177e4SLinus Torvalds 4041da177e4SLinus Torvalds /* From syncookies.c */ 4051da177e4SLinus Torvalds extern struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb, 4061da177e4SLinus Torvalds struct ip_options *opt); 4071da177e4SLinus Torvalds extern __u32 cookie_v4_init_sequence(struct sock *sk, struct sk_buff *skb, 4081da177e4SLinus Torvalds __u16 *mss); 4091da177e4SLinus Torvalds 4101da177e4SLinus Torvalds /* tcp_output.c */ 4111da177e4SLinus Torvalds 412f6302d1dSDavid S. Miller extern void __tcp_push_pending_frames(struct sock *sk, struct tcp_sock *tp, 413a2e2a59cSDavid S. Miller unsigned int cur_mss, int nonagle); 414f6302d1dSDavid S. Miller extern int tcp_may_send_now(struct sock *sk, struct tcp_sock *tp); 4151da177e4SLinus Torvalds extern int tcp_retransmit_skb(struct sock *, struct sk_buff *); 4161da177e4SLinus Torvalds extern void tcp_xmit_retransmit_queue(struct sock *); 4171da177e4SLinus Torvalds extern void tcp_simple_retransmit(struct sock *); 4181da177e4SLinus Torvalds extern int tcp_trim_head(struct sock *, struct sk_buff *, u32); 4196475be16SDavid S. Miller extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int); 4201da177e4SLinus Torvalds 4211da177e4SLinus Torvalds extern void tcp_send_probe0(struct sock *); 4221da177e4SLinus Torvalds extern void tcp_send_partial(struct sock *); 4231da177e4SLinus Torvalds extern int tcp_write_wakeup(struct sock *); 4241da177e4SLinus Torvalds extern void tcp_send_fin(struct sock *sk); 425dd0fc66fSAl Viro extern void tcp_send_active_reset(struct sock *sk, gfp_t priority); 4261da177e4SLinus Torvalds extern int tcp_send_synack(struct sock *); 427c1b4a7e6SDavid S. Miller extern void tcp_push_one(struct sock *, unsigned int mss_now); 4281da177e4SLinus Torvalds extern void tcp_send_ack(struct sock *sk); 4291da177e4SLinus Torvalds extern void tcp_send_delayed_ack(struct sock *sk); 4301da177e4SLinus Torvalds 431a762a980SDavid S. Miller /* tcp_input.c */ 432a762a980SDavid S. Miller extern void tcp_cwnd_application_limited(struct sock *sk); 433a762a980SDavid S. Miller 4341da177e4SLinus Torvalds /* tcp_timer.c */ 4351da177e4SLinus Torvalds extern void tcp_init_xmit_timers(struct sock *); 436463c84b9SArnaldo Carvalho de Melo static inline void tcp_clear_xmit_timers(struct sock *sk) 437463c84b9SArnaldo Carvalho de Melo { 438463c84b9SArnaldo Carvalho de Melo inet_csk_clear_xmit_timers(sk); 439463c84b9SArnaldo Carvalho de Melo } 4401da177e4SLinus Torvalds 4411da177e4SLinus Torvalds extern unsigned int tcp_sync_mss(struct sock *sk, u32 pmtu); 4421da177e4SLinus Torvalds extern unsigned int tcp_current_mss(struct sock *sk, int large); 4431da177e4SLinus Torvalds 44417b085eaSArnaldo Carvalho de Melo /* tcp.c */ 4451da177e4SLinus Torvalds extern void tcp_get_info(struct sock *, struct tcp_info *); 4461da177e4SLinus Torvalds 4471da177e4SLinus Torvalds /* Read 'sendfile()'-style from a TCP socket */ 4481da177e4SLinus Torvalds typedef int (*sk_read_actor_t)(read_descriptor_t *, struct sk_buff *, 4491da177e4SLinus Torvalds unsigned int, size_t); 4501da177e4SLinus Torvalds extern int tcp_read_sock(struct sock *sk, read_descriptor_t *desc, 4511da177e4SLinus Torvalds sk_read_actor_t recv_actor); 4521da177e4SLinus Torvalds 45340efc6faSStephen Hemminger extern void tcp_initialize_rcv_mss(struct sock *sk); 4541da177e4SLinus Torvalds 455*5d424d5aSJohn Heffner extern int tcp_mtu_to_mss(struct sock *sk, int pmtu); 456*5d424d5aSJohn Heffner extern int tcp_mss_to_mtu(struct sock *sk, int mss); 457*5d424d5aSJohn Heffner extern void tcp_mtup_init(struct sock *sk); 458*5d424d5aSJohn Heffner 45940efc6faSStephen Hemminger static inline void __tcp_fast_path_on(struct tcp_sock *tp, u32 snd_wnd) 4601da177e4SLinus Torvalds { 4611da177e4SLinus Torvalds tp->pred_flags = htonl((tp->tcp_header_len << 26) | 4621da177e4SLinus Torvalds ntohl(TCP_FLAG_ACK) | 4631da177e4SLinus Torvalds snd_wnd); 4641da177e4SLinus Torvalds } 4651da177e4SLinus Torvalds 46640efc6faSStephen Hemminger static inline void tcp_fast_path_on(struct tcp_sock *tp) 4671da177e4SLinus Torvalds { 4681da177e4SLinus Torvalds __tcp_fast_path_on(tp, tp->snd_wnd >> tp->rx_opt.snd_wscale); 4691da177e4SLinus Torvalds } 4701da177e4SLinus Torvalds 4711da177e4SLinus Torvalds static inline void tcp_fast_path_check(struct sock *sk, struct tcp_sock *tp) 4721da177e4SLinus Torvalds { 473b03efcfbSDavid S. Miller if (skb_queue_empty(&tp->out_of_order_queue) && 4741da177e4SLinus Torvalds tp->rcv_wnd && 4751da177e4SLinus Torvalds atomic_read(&sk->sk_rmem_alloc) < sk->sk_rcvbuf && 4761da177e4SLinus Torvalds !tp->urg_data) 4771da177e4SLinus Torvalds tcp_fast_path_on(tp); 4781da177e4SLinus Torvalds } 4791da177e4SLinus Torvalds 4801da177e4SLinus Torvalds /* Compute the actual receive window we are currently advertising. 4811da177e4SLinus Torvalds * Rcv_nxt can be after the window if our peer push more data 4821da177e4SLinus Torvalds * than the offered window. 4831da177e4SLinus Torvalds */ 48440efc6faSStephen Hemminger static inline u32 tcp_receive_window(const struct tcp_sock *tp) 4851da177e4SLinus Torvalds { 4861da177e4SLinus Torvalds s32 win = tp->rcv_wup + tp->rcv_wnd - tp->rcv_nxt; 4871da177e4SLinus Torvalds 4881da177e4SLinus Torvalds if (win < 0) 4891da177e4SLinus Torvalds win = 0; 4901da177e4SLinus Torvalds return (u32) win; 4911da177e4SLinus Torvalds } 4921da177e4SLinus Torvalds 4931da177e4SLinus Torvalds /* Choose a new window, without checks for shrinking, and without 4941da177e4SLinus Torvalds * scaling applied to the result. The caller does these things 4951da177e4SLinus Torvalds * if necessary. This is a "raw" window selection. 4961da177e4SLinus Torvalds */ 4971da177e4SLinus Torvalds extern u32 __tcp_select_window(struct sock *sk); 4981da177e4SLinus Torvalds 4991da177e4SLinus Torvalds /* TCP timestamps are only 32-bits, this causes a slight 5001da177e4SLinus Torvalds * complication on 64-bit systems since we store a snapshot 50131f34269SStephen Hemminger * of jiffies in the buffer control blocks below. We decided 50231f34269SStephen Hemminger * to use only the low 32-bits of jiffies and hide the ugly 5031da177e4SLinus Torvalds * casts with the following macro. 5041da177e4SLinus Torvalds */ 5051da177e4SLinus Torvalds #define tcp_time_stamp ((__u32)(jiffies)) 5061da177e4SLinus Torvalds 507caa20d9aSStephen Hemminger /* This is what the send packet queuing engine uses to pass 5081da177e4SLinus Torvalds * TCP per-packet control information to the transmission 5091da177e4SLinus Torvalds * code. We also store the host-order sequence numbers in 5101da177e4SLinus Torvalds * here too. This is 36 bytes on 32-bit architectures, 5111da177e4SLinus Torvalds * 40 bytes on 64-bit machines, if this grows please adjust 5121da177e4SLinus Torvalds * skbuff.h:skbuff->cb[xxx] size appropriately. 5131da177e4SLinus Torvalds */ 5141da177e4SLinus Torvalds struct tcp_skb_cb { 5151da177e4SLinus Torvalds union { 5161da177e4SLinus Torvalds struct inet_skb_parm h4; 5171da177e4SLinus Torvalds #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE) 5181da177e4SLinus Torvalds struct inet6_skb_parm h6; 5191da177e4SLinus Torvalds #endif 5201da177e4SLinus Torvalds } header; /* For incoming frames */ 5211da177e4SLinus Torvalds __u32 seq; /* Starting sequence number */ 5221da177e4SLinus Torvalds __u32 end_seq; /* SEQ + FIN + SYN + datalen */ 5231da177e4SLinus Torvalds __u32 when; /* used to compute rtt's */ 5241da177e4SLinus Torvalds __u8 flags; /* TCP header flags. */ 5251da177e4SLinus Torvalds 5261da177e4SLinus Torvalds /* NOTE: These must match up to the flags byte in a 5271da177e4SLinus Torvalds * real TCP header. 5281da177e4SLinus Torvalds */ 5291da177e4SLinus Torvalds #define TCPCB_FLAG_FIN 0x01 5301da177e4SLinus Torvalds #define TCPCB_FLAG_SYN 0x02 5311da177e4SLinus Torvalds #define TCPCB_FLAG_RST 0x04 5321da177e4SLinus Torvalds #define TCPCB_FLAG_PSH 0x08 5331da177e4SLinus Torvalds #define TCPCB_FLAG_ACK 0x10 5341da177e4SLinus Torvalds #define TCPCB_FLAG_URG 0x20 5351da177e4SLinus Torvalds #define TCPCB_FLAG_ECE 0x40 5361da177e4SLinus Torvalds #define TCPCB_FLAG_CWR 0x80 5371da177e4SLinus Torvalds 5381da177e4SLinus Torvalds __u8 sacked; /* State flags for SACK/FACK. */ 5391da177e4SLinus Torvalds #define TCPCB_SACKED_ACKED 0x01 /* SKB ACK'd by a SACK block */ 5401da177e4SLinus Torvalds #define TCPCB_SACKED_RETRANS 0x02 /* SKB retransmitted */ 5411da177e4SLinus Torvalds #define TCPCB_LOST 0x04 /* SKB is lost */ 5421da177e4SLinus Torvalds #define TCPCB_TAGBITS 0x07 /* All tag bits */ 5431da177e4SLinus Torvalds 5441da177e4SLinus Torvalds #define TCPCB_EVER_RETRANS 0x80 /* Ever retransmitted frame */ 5451da177e4SLinus Torvalds #define TCPCB_RETRANS (TCPCB_SACKED_RETRANS|TCPCB_EVER_RETRANS) 5461da177e4SLinus Torvalds 547caa20d9aSStephen Hemminger #define TCPCB_URG 0x20 /* Urgent pointer advanced here */ 5481da177e4SLinus Torvalds 5491da177e4SLinus Torvalds #define TCPCB_AT_TAIL (TCPCB_URG) 5501da177e4SLinus Torvalds 5511da177e4SLinus Torvalds __u16 urg_ptr; /* Valid w/URG flags is set. */ 5521da177e4SLinus Torvalds __u32 ack_seq; /* Sequence number ACK'd */ 5531da177e4SLinus Torvalds }; 5541da177e4SLinus Torvalds 5551da177e4SLinus Torvalds #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0])) 5561da177e4SLinus Torvalds 5571da177e4SLinus Torvalds #include <net/tcp_ecn.h> 5581da177e4SLinus Torvalds 5591da177e4SLinus Torvalds /* Due to TSO, an SKB can be composed of multiple actual 5601da177e4SLinus Torvalds * packets. To keep these tracked properly, we use this. 5611da177e4SLinus Torvalds */ 5621da177e4SLinus Torvalds static inline int tcp_skb_pcount(const struct sk_buff *skb) 5631da177e4SLinus Torvalds { 5641da177e4SLinus Torvalds return skb_shinfo(skb)->tso_segs; 5651da177e4SLinus Torvalds } 5661da177e4SLinus Torvalds 5671da177e4SLinus Torvalds /* This is valid iff tcp_skb_pcount() > 1. */ 5681da177e4SLinus Torvalds static inline int tcp_skb_mss(const struct sk_buff *skb) 5691da177e4SLinus Torvalds { 5701da177e4SLinus Torvalds return skb_shinfo(skb)->tso_size; 5711da177e4SLinus Torvalds } 5721da177e4SLinus Torvalds 5731da177e4SLinus Torvalds static inline void tcp_dec_pcount_approx(__u32 *count, 5741da177e4SLinus Torvalds const struct sk_buff *skb) 5751da177e4SLinus Torvalds { 5761da177e4SLinus Torvalds if (*count) { 5771da177e4SLinus Torvalds *count -= tcp_skb_pcount(skb); 5781da177e4SLinus Torvalds if ((int)*count < 0) 5791da177e4SLinus Torvalds *count = 0; 5801da177e4SLinus Torvalds } 5811da177e4SLinus Torvalds } 5821da177e4SLinus Torvalds 5831da177e4SLinus Torvalds static inline void tcp_packets_out_inc(struct sock *sk, 5841da177e4SLinus Torvalds struct tcp_sock *tp, 5851da177e4SLinus Torvalds const struct sk_buff *skb) 5861da177e4SLinus Torvalds { 5871da177e4SLinus Torvalds int orig = tp->packets_out; 5881da177e4SLinus Torvalds 5891da177e4SLinus Torvalds tp->packets_out += tcp_skb_pcount(skb); 5901da177e4SLinus Torvalds if (!orig) 5913f421baaSArnaldo Carvalho de Melo inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, 5923f421baaSArnaldo Carvalho de Melo inet_csk(sk)->icsk_rto, TCP_RTO_MAX); 5931da177e4SLinus Torvalds } 5941da177e4SLinus Torvalds 5951da177e4SLinus Torvalds static inline void tcp_packets_out_dec(struct tcp_sock *tp, 5961da177e4SLinus Torvalds const struct sk_buff *skb) 5971da177e4SLinus Torvalds { 5981da177e4SLinus Torvalds tp->packets_out -= tcp_skb_pcount(skb); 5991da177e4SLinus Torvalds } 6001da177e4SLinus Torvalds 601317a76f9SStephen Hemminger /* Events passed to congestion control interface */ 602317a76f9SStephen Hemminger enum tcp_ca_event { 603317a76f9SStephen Hemminger CA_EVENT_TX_START, /* first transmit when no packets in flight */ 604317a76f9SStephen Hemminger CA_EVENT_CWND_RESTART, /* congestion window restart */ 605317a76f9SStephen Hemminger CA_EVENT_COMPLETE_CWR, /* end of congestion recovery */ 606317a76f9SStephen Hemminger CA_EVENT_FRTO, /* fast recovery timeout */ 607317a76f9SStephen Hemminger CA_EVENT_LOSS, /* loss timeout */ 608317a76f9SStephen Hemminger CA_EVENT_FAST_ACK, /* in sequence ack */ 609317a76f9SStephen Hemminger CA_EVENT_SLOW_ACK, /* other ack */ 610317a76f9SStephen Hemminger }; 611317a76f9SStephen Hemminger 612317a76f9SStephen Hemminger /* 613317a76f9SStephen Hemminger * Interface for adding new TCP congestion control handlers 614317a76f9SStephen Hemminger */ 615317a76f9SStephen Hemminger #define TCP_CA_NAME_MAX 16 616317a76f9SStephen Hemminger struct tcp_congestion_ops { 617317a76f9SStephen Hemminger struct list_head list; 618317a76f9SStephen Hemminger 619317a76f9SStephen Hemminger /* initialize private data (optional) */ 6206687e988SArnaldo Carvalho de Melo void (*init)(struct sock *sk); 621317a76f9SStephen Hemminger /* cleanup private data (optional) */ 6226687e988SArnaldo Carvalho de Melo void (*release)(struct sock *sk); 623317a76f9SStephen Hemminger 624317a76f9SStephen Hemminger /* return slow start threshold (required) */ 6256687e988SArnaldo Carvalho de Melo u32 (*ssthresh)(struct sock *sk); 626317a76f9SStephen Hemminger /* lower bound for congestion window (optional) */ 6276687e988SArnaldo Carvalho de Melo u32 (*min_cwnd)(struct sock *sk); 628317a76f9SStephen Hemminger /* do new cwnd calculation (required) */ 6296687e988SArnaldo Carvalho de Melo void (*cong_avoid)(struct sock *sk, u32 ack, 630317a76f9SStephen Hemminger u32 rtt, u32 in_flight, int good_ack); 631317a76f9SStephen Hemminger /* round trip time sample per acked packet (optional) */ 6326687e988SArnaldo Carvalho de Melo void (*rtt_sample)(struct sock *sk, u32 usrtt); 633317a76f9SStephen Hemminger /* call before changing ca_state (optional) */ 6346687e988SArnaldo Carvalho de Melo void (*set_state)(struct sock *sk, u8 new_state); 635317a76f9SStephen Hemminger /* call when cwnd event occurs (optional) */ 6366687e988SArnaldo Carvalho de Melo void (*cwnd_event)(struct sock *sk, enum tcp_ca_event ev); 637317a76f9SStephen Hemminger /* new value of cwnd after loss (optional) */ 6386687e988SArnaldo Carvalho de Melo u32 (*undo_cwnd)(struct sock *sk); 639317a76f9SStephen Hemminger /* hook for packet ack accounting (optional) */ 6406687e988SArnaldo Carvalho de Melo void (*pkts_acked)(struct sock *sk, u32 num_acked); 64173c1f4a0SArnaldo Carvalho de Melo /* get info for inet_diag (optional) */ 6426687e988SArnaldo Carvalho de Melo void (*get_info)(struct sock *sk, u32 ext, struct sk_buff *skb); 643317a76f9SStephen Hemminger 644317a76f9SStephen Hemminger char name[TCP_CA_NAME_MAX]; 645317a76f9SStephen Hemminger struct module *owner; 646317a76f9SStephen Hemminger }; 647317a76f9SStephen Hemminger 648317a76f9SStephen Hemminger extern int tcp_register_congestion_control(struct tcp_congestion_ops *type); 649317a76f9SStephen Hemminger extern void tcp_unregister_congestion_control(struct tcp_congestion_ops *type); 650317a76f9SStephen Hemminger 6516687e988SArnaldo Carvalho de Melo extern void tcp_init_congestion_control(struct sock *sk); 6526687e988SArnaldo Carvalho de Melo extern void tcp_cleanup_congestion_control(struct sock *sk); 653317a76f9SStephen Hemminger extern int tcp_set_default_congestion_control(const char *name); 654317a76f9SStephen Hemminger extern void tcp_get_default_congestion_control(char *name); 6556687e988SArnaldo Carvalho de Melo extern int tcp_set_congestion_control(struct sock *sk, const char *name); 65640efc6faSStephen Hemminger extern void tcp_slow_start(struct tcp_sock *tp); 657317a76f9SStephen Hemminger 6585f8ef48dSStephen Hemminger extern struct tcp_congestion_ops tcp_init_congestion_ops; 6596687e988SArnaldo Carvalho de Melo extern u32 tcp_reno_ssthresh(struct sock *sk); 6606687e988SArnaldo Carvalho de Melo extern void tcp_reno_cong_avoid(struct sock *sk, u32 ack, 661317a76f9SStephen Hemminger u32 rtt, u32 in_flight, int flag); 6626687e988SArnaldo Carvalho de Melo extern u32 tcp_reno_min_cwnd(struct sock *sk); 663a8acfbacSDavid S. Miller extern struct tcp_congestion_ops tcp_reno; 664317a76f9SStephen Hemminger 6656687e988SArnaldo Carvalho de Melo static inline void tcp_set_ca_state(struct sock *sk, const u8 ca_state) 666317a76f9SStephen Hemminger { 6676687e988SArnaldo Carvalho de Melo struct inet_connection_sock *icsk = inet_csk(sk); 6686687e988SArnaldo Carvalho de Melo 6696687e988SArnaldo Carvalho de Melo if (icsk->icsk_ca_ops->set_state) 6706687e988SArnaldo Carvalho de Melo icsk->icsk_ca_ops->set_state(sk, ca_state); 6716687e988SArnaldo Carvalho de Melo icsk->icsk_ca_state = ca_state; 672317a76f9SStephen Hemminger } 673317a76f9SStephen Hemminger 6746687e988SArnaldo Carvalho de Melo static inline void tcp_ca_event(struct sock *sk, const enum tcp_ca_event event) 675317a76f9SStephen Hemminger { 6766687e988SArnaldo Carvalho de Melo const struct inet_connection_sock *icsk = inet_csk(sk); 6776687e988SArnaldo Carvalho de Melo 6786687e988SArnaldo Carvalho de Melo if (icsk->icsk_ca_ops->cwnd_event) 6796687e988SArnaldo Carvalho de Melo icsk->icsk_ca_ops->cwnd_event(sk, event); 680317a76f9SStephen Hemminger } 681317a76f9SStephen Hemminger 6821da177e4SLinus Torvalds /* This determines how many packets are "in the network" to the best 6831da177e4SLinus Torvalds * of our knowledge. In many cases it is conservative, but where 6841da177e4SLinus Torvalds * detailed information is available from the receiver (via SACK 6851da177e4SLinus Torvalds * blocks etc.) we can make more aggressive calculations. 6861da177e4SLinus Torvalds * 6871da177e4SLinus Torvalds * Use this for decisions involving congestion control, use just 6881da177e4SLinus Torvalds * tp->packets_out to determine if the send queue is empty or not. 6891da177e4SLinus Torvalds * 6901da177e4SLinus Torvalds * Read this equation as: 6911da177e4SLinus Torvalds * 6921da177e4SLinus Torvalds * "Packets sent once on transmission queue" MINUS 6931da177e4SLinus Torvalds * "Packets left network, but not honestly ACKed yet" PLUS 6941da177e4SLinus Torvalds * "Packets fast retransmitted" 6951da177e4SLinus Torvalds */ 69640efc6faSStephen Hemminger static inline unsigned int tcp_packets_in_flight(const struct tcp_sock *tp) 6971da177e4SLinus Torvalds { 6981da177e4SLinus Torvalds return (tp->packets_out - tp->left_out + tp->retrans_out); 6991da177e4SLinus Torvalds } 7001da177e4SLinus Torvalds 7011da177e4SLinus Torvalds /* If cwnd > ssthresh, we may raise ssthresh to be half-way to cwnd. 7021da177e4SLinus Torvalds * The exception is rate halving phase, when cwnd is decreasing towards 7031da177e4SLinus Torvalds * ssthresh. 7041da177e4SLinus Torvalds */ 7056687e988SArnaldo Carvalho de Melo static inline __u32 tcp_current_ssthresh(const struct sock *sk) 7061da177e4SLinus Torvalds { 7076687e988SArnaldo Carvalho de Melo const struct tcp_sock *tp = tcp_sk(sk); 7086687e988SArnaldo Carvalho de Melo if ((1 << inet_csk(sk)->icsk_ca_state) & (TCPF_CA_CWR | TCPF_CA_Recovery)) 7091da177e4SLinus Torvalds return tp->snd_ssthresh; 7101da177e4SLinus Torvalds else 7111da177e4SLinus Torvalds return max(tp->snd_ssthresh, 7121da177e4SLinus Torvalds ((tp->snd_cwnd >> 1) + 7131da177e4SLinus Torvalds (tp->snd_cwnd >> 2))); 7141da177e4SLinus Torvalds } 7151da177e4SLinus Torvalds 7161da177e4SLinus Torvalds static inline void tcp_sync_left_out(struct tcp_sock *tp) 7171da177e4SLinus Torvalds { 7181da177e4SLinus Torvalds if (tp->rx_opt.sack_ok && 7191da177e4SLinus Torvalds (tp->sacked_out >= tp->packets_out - tp->lost_out)) 7201da177e4SLinus Torvalds tp->sacked_out = tp->packets_out - tp->lost_out; 7211da177e4SLinus Torvalds tp->left_out = tp->sacked_out + tp->lost_out; 7221da177e4SLinus Torvalds } 7231da177e4SLinus Torvalds 72440efc6faSStephen Hemminger extern void tcp_enter_cwr(struct sock *sk); 7251da177e4SLinus Torvalds extern __u32 tcp_init_cwnd(struct tcp_sock *tp, struct dst_entry *dst); 7261da177e4SLinus Torvalds 7271da177e4SLinus Torvalds /* Slow start with delack produces 3 packets of burst, so that 7281da177e4SLinus Torvalds * it is safe "de facto". 7291da177e4SLinus Torvalds */ 7301da177e4SLinus Torvalds static __inline__ __u32 tcp_max_burst(const struct tcp_sock *tp) 7311da177e4SLinus Torvalds { 7321da177e4SLinus Torvalds return 3; 7331da177e4SLinus Torvalds } 7341da177e4SLinus Torvalds 735f4805edeSStephen Hemminger /* RFC2861 Check whether we are limited by application or congestion window 736f4805edeSStephen Hemminger * This is the inverse of cwnd check in tcp_tso_should_defer 737f4805edeSStephen Hemminger */ 738f4805edeSStephen Hemminger static inline int tcp_is_cwnd_limited(const struct sock *sk, u32 in_flight) 739f4805edeSStephen Hemminger { 740f4805edeSStephen Hemminger const struct tcp_sock *tp = tcp_sk(sk); 741f4805edeSStephen Hemminger u32 left; 742f4805edeSStephen Hemminger 743f4805edeSStephen Hemminger if (in_flight >= tp->snd_cwnd) 744f4805edeSStephen Hemminger return 1; 745f4805edeSStephen Hemminger 746f4805edeSStephen Hemminger if (!(sk->sk_route_caps & NETIF_F_TSO)) 747f4805edeSStephen Hemminger return 0; 748f4805edeSStephen Hemminger 749f4805edeSStephen Hemminger left = tp->snd_cwnd - in_flight; 750f4805edeSStephen Hemminger if (sysctl_tcp_tso_win_divisor) 751f4805edeSStephen Hemminger return left * sysctl_tcp_tso_win_divisor < tp->snd_cwnd; 752f4805edeSStephen Hemminger else 753f4805edeSStephen Hemminger return left <= tcp_max_burst(tp); 754f4805edeSStephen Hemminger } 755f4805edeSStephen Hemminger 75640efc6faSStephen Hemminger static inline void tcp_minshall_update(struct tcp_sock *tp, int mss, 7571da177e4SLinus Torvalds const struct sk_buff *skb) 7581da177e4SLinus Torvalds { 7591da177e4SLinus Torvalds if (skb->len < mss) 7601da177e4SLinus Torvalds tp->snd_sml = TCP_SKB_CB(skb)->end_seq; 7611da177e4SLinus Torvalds } 7621da177e4SLinus Torvalds 76340efc6faSStephen Hemminger static inline void tcp_check_probe_timer(struct sock *sk, struct tcp_sock *tp) 7641da177e4SLinus Torvalds { 765463c84b9SArnaldo Carvalho de Melo const struct inet_connection_sock *icsk = inet_csk(sk); 766463c84b9SArnaldo Carvalho de Melo if (!tp->packets_out && !icsk->icsk_pending) 7673f421baaSArnaldo Carvalho de Melo inet_csk_reset_xmit_timer(sk, ICSK_TIME_PROBE0, 7683f421baaSArnaldo Carvalho de Melo icsk->icsk_rto, TCP_RTO_MAX); 7691da177e4SLinus Torvalds } 7701da177e4SLinus Torvalds 77140efc6faSStephen Hemminger static inline void tcp_push_pending_frames(struct sock *sk, 7721da177e4SLinus Torvalds struct tcp_sock *tp) 7731da177e4SLinus Torvalds { 7741da177e4SLinus Torvalds __tcp_push_pending_frames(sk, tp, tcp_current_mss(sk, 1), tp->nonagle); 7751da177e4SLinus Torvalds } 7761da177e4SLinus Torvalds 77740efc6faSStephen Hemminger static inline void tcp_init_wl(struct tcp_sock *tp, u32 ack, u32 seq) 7781da177e4SLinus Torvalds { 7791da177e4SLinus Torvalds tp->snd_wl1 = seq; 7801da177e4SLinus Torvalds } 7811da177e4SLinus Torvalds 78240efc6faSStephen Hemminger static inline void tcp_update_wl(struct tcp_sock *tp, u32 ack, u32 seq) 7831da177e4SLinus Torvalds { 7841da177e4SLinus Torvalds tp->snd_wl1 = seq; 7851da177e4SLinus Torvalds } 7861da177e4SLinus Torvalds 7871da177e4SLinus Torvalds /* 7881da177e4SLinus Torvalds * Calculate(/check) TCP checksum 7891da177e4SLinus Torvalds */ 79040efc6faSStephen Hemminger static inline u16 tcp_v4_check(struct tcphdr *th, int len, 7911da177e4SLinus Torvalds unsigned long saddr, unsigned long daddr, 7921da177e4SLinus Torvalds unsigned long base) 7931da177e4SLinus Torvalds { 7941da177e4SLinus Torvalds return csum_tcpudp_magic(saddr,daddr,len,IPPROTO_TCP,base); 7951da177e4SLinus Torvalds } 7961da177e4SLinus Torvalds 79740efc6faSStephen Hemminger static inline int __tcp_checksum_complete(struct sk_buff *skb) 7981da177e4SLinus Torvalds { 799fb286bb2SHerbert Xu return __skb_checksum_complete(skb); 8001da177e4SLinus Torvalds } 8011da177e4SLinus Torvalds 80240efc6faSStephen Hemminger static inline int tcp_checksum_complete(struct sk_buff *skb) 8031da177e4SLinus Torvalds { 8041da177e4SLinus Torvalds return skb->ip_summed != CHECKSUM_UNNECESSARY && 8051da177e4SLinus Torvalds __tcp_checksum_complete(skb); 8061da177e4SLinus Torvalds } 8071da177e4SLinus Torvalds 8081da177e4SLinus Torvalds /* Prequeue for VJ style copy to user, combined with checksumming. */ 8091da177e4SLinus Torvalds 81040efc6faSStephen Hemminger static inline void tcp_prequeue_init(struct tcp_sock *tp) 8111da177e4SLinus Torvalds { 8121da177e4SLinus Torvalds tp->ucopy.task = NULL; 8131da177e4SLinus Torvalds tp->ucopy.len = 0; 8141da177e4SLinus Torvalds tp->ucopy.memory = 0; 8151da177e4SLinus Torvalds skb_queue_head_init(&tp->ucopy.prequeue); 8161da177e4SLinus Torvalds } 8171da177e4SLinus Torvalds 8181da177e4SLinus Torvalds /* Packet is added to VJ-style prequeue for processing in process 8191da177e4SLinus Torvalds * context, if a reader task is waiting. Apparently, this exciting 8201da177e4SLinus Torvalds * idea (VJ's mail "Re: query about TCP header on tcp-ip" of 07 Sep 93) 8211da177e4SLinus Torvalds * failed somewhere. Latency? Burstiness? Well, at least now we will 8221da177e4SLinus Torvalds * see, why it failed. 8)8) --ANK 8231da177e4SLinus Torvalds * 8241da177e4SLinus Torvalds * NOTE: is this not too big to inline? 8251da177e4SLinus Torvalds */ 82640efc6faSStephen Hemminger static inline int tcp_prequeue(struct sock *sk, struct sk_buff *skb) 8271da177e4SLinus Torvalds { 8281da177e4SLinus Torvalds struct tcp_sock *tp = tcp_sk(sk); 8291da177e4SLinus Torvalds 8301da177e4SLinus Torvalds if (!sysctl_tcp_low_latency && tp->ucopy.task) { 8311da177e4SLinus Torvalds __skb_queue_tail(&tp->ucopy.prequeue, skb); 8321da177e4SLinus Torvalds tp->ucopy.memory += skb->truesize; 8331da177e4SLinus Torvalds if (tp->ucopy.memory > sk->sk_rcvbuf) { 8341da177e4SLinus Torvalds struct sk_buff *skb1; 8351da177e4SLinus Torvalds 8361da177e4SLinus Torvalds BUG_ON(sock_owned_by_user(sk)); 8371da177e4SLinus Torvalds 8381da177e4SLinus Torvalds while ((skb1 = __skb_dequeue(&tp->ucopy.prequeue)) != NULL) { 8391da177e4SLinus Torvalds sk->sk_backlog_rcv(sk, skb1); 8401da177e4SLinus Torvalds NET_INC_STATS_BH(LINUX_MIB_TCPPREQUEUEDROPPED); 8411da177e4SLinus Torvalds } 8421da177e4SLinus Torvalds 8431da177e4SLinus Torvalds tp->ucopy.memory = 0; 8441da177e4SLinus Torvalds } else if (skb_queue_len(&tp->ucopy.prequeue) == 1) { 8451da177e4SLinus Torvalds wake_up_interruptible(sk->sk_sleep); 846463c84b9SArnaldo Carvalho de Melo if (!inet_csk_ack_scheduled(sk)) 847463c84b9SArnaldo Carvalho de Melo inet_csk_reset_xmit_timer(sk, ICSK_TIME_DACK, 8483f421baaSArnaldo Carvalho de Melo (3 * TCP_RTO_MIN) / 4, 8493f421baaSArnaldo Carvalho de Melo TCP_RTO_MAX); 8501da177e4SLinus Torvalds } 8511da177e4SLinus Torvalds return 1; 8521da177e4SLinus Torvalds } 8531da177e4SLinus Torvalds return 0; 8541da177e4SLinus Torvalds } 8551da177e4SLinus Torvalds 8561da177e4SLinus Torvalds 8571da177e4SLinus Torvalds #undef STATE_TRACE 8581da177e4SLinus Torvalds 8591da177e4SLinus Torvalds #ifdef STATE_TRACE 8601da177e4SLinus Torvalds static const char *statename[]={ 8611da177e4SLinus Torvalds "Unused","Established","Syn Sent","Syn Recv", 8621da177e4SLinus Torvalds "Fin Wait 1","Fin Wait 2","Time Wait", "Close", 8631da177e4SLinus Torvalds "Close Wait","Last ACK","Listen","Closing" 8641da177e4SLinus Torvalds }; 8651da177e4SLinus Torvalds #endif 8661da177e4SLinus Torvalds 86740efc6faSStephen Hemminger static inline void tcp_set_state(struct sock *sk, int state) 8681da177e4SLinus Torvalds { 8691da177e4SLinus Torvalds int oldstate = sk->sk_state; 8701da177e4SLinus Torvalds 8711da177e4SLinus Torvalds switch (state) { 8721da177e4SLinus Torvalds case TCP_ESTABLISHED: 8731da177e4SLinus Torvalds if (oldstate != TCP_ESTABLISHED) 8741da177e4SLinus Torvalds TCP_INC_STATS(TCP_MIB_CURRESTAB); 8751da177e4SLinus Torvalds break; 8761da177e4SLinus Torvalds 8771da177e4SLinus Torvalds case TCP_CLOSE: 8781da177e4SLinus Torvalds if (oldstate == TCP_CLOSE_WAIT || oldstate == TCP_ESTABLISHED) 8791da177e4SLinus Torvalds TCP_INC_STATS(TCP_MIB_ESTABRESETS); 8801da177e4SLinus Torvalds 8811da177e4SLinus Torvalds sk->sk_prot->unhash(sk); 882463c84b9SArnaldo Carvalho de Melo if (inet_csk(sk)->icsk_bind_hash && 8831da177e4SLinus Torvalds !(sk->sk_userlocks & SOCK_BINDPORT_LOCK)) 8842d8c4ce5SArnaldo Carvalho de Melo inet_put_port(&tcp_hashinfo, sk); 8851da177e4SLinus Torvalds /* fall through */ 8861da177e4SLinus Torvalds default: 8871da177e4SLinus Torvalds if (oldstate==TCP_ESTABLISHED) 8881da177e4SLinus Torvalds TCP_DEC_STATS(TCP_MIB_CURRESTAB); 8891da177e4SLinus Torvalds } 8901da177e4SLinus Torvalds 8911da177e4SLinus Torvalds /* Change state AFTER socket is unhashed to avoid closed 8921da177e4SLinus Torvalds * socket sitting in hash tables. 8931da177e4SLinus Torvalds */ 8941da177e4SLinus Torvalds sk->sk_state = state; 8951da177e4SLinus Torvalds 8961da177e4SLinus Torvalds #ifdef STATE_TRACE 8971da177e4SLinus Torvalds SOCK_DEBUG(sk, "TCP sk=%p, State %s -> %s\n",sk, statename[oldstate],statename[state]); 8981da177e4SLinus Torvalds #endif 8991da177e4SLinus Torvalds } 9001da177e4SLinus Torvalds 90140efc6faSStephen Hemminger static inline void tcp_done(struct sock *sk) 9021da177e4SLinus Torvalds { 9031da177e4SLinus Torvalds tcp_set_state(sk, TCP_CLOSE); 9041da177e4SLinus Torvalds tcp_clear_xmit_timers(sk); 9051da177e4SLinus Torvalds 9061da177e4SLinus Torvalds sk->sk_shutdown = SHUTDOWN_MASK; 9071da177e4SLinus Torvalds 9081da177e4SLinus Torvalds if (!sock_flag(sk, SOCK_DEAD)) 9091da177e4SLinus Torvalds sk->sk_state_change(sk); 9101da177e4SLinus Torvalds else 9110a5578cfSArnaldo Carvalho de Melo inet_csk_destroy_sock(sk); 9121da177e4SLinus Torvalds } 9131da177e4SLinus Torvalds 91440efc6faSStephen Hemminger static inline void tcp_sack_reset(struct tcp_options_received *rx_opt) 9151da177e4SLinus Torvalds { 9161da177e4SLinus Torvalds rx_opt->dsack = 0; 9171da177e4SLinus Torvalds rx_opt->eff_sacks = 0; 9181da177e4SLinus Torvalds rx_opt->num_sacks = 0; 9191da177e4SLinus Torvalds } 9201da177e4SLinus Torvalds 9211da177e4SLinus Torvalds /* Determine a window scaling and initial window to offer. */ 9221da177e4SLinus Torvalds extern void tcp_select_initial_window(int __space, __u32 mss, 9231da177e4SLinus Torvalds __u32 *rcv_wnd, __u32 *window_clamp, 9241da177e4SLinus Torvalds int wscale_ok, __u8 *rcv_wscale); 9251da177e4SLinus Torvalds 9261da177e4SLinus Torvalds static inline int tcp_win_from_space(int space) 9271da177e4SLinus Torvalds { 9281da177e4SLinus Torvalds return sysctl_tcp_adv_win_scale<=0 ? 9291da177e4SLinus Torvalds (space>>(-sysctl_tcp_adv_win_scale)) : 9301da177e4SLinus Torvalds space - (space>>sysctl_tcp_adv_win_scale); 9311da177e4SLinus Torvalds } 9321da177e4SLinus Torvalds 9331da177e4SLinus Torvalds /* Note: caller must be prepared to deal with negative returns */ 9341da177e4SLinus Torvalds static inline int tcp_space(const struct sock *sk) 9351da177e4SLinus Torvalds { 9361da177e4SLinus Torvalds return tcp_win_from_space(sk->sk_rcvbuf - 9371da177e4SLinus Torvalds atomic_read(&sk->sk_rmem_alloc)); 9381da177e4SLinus Torvalds } 9391da177e4SLinus Torvalds 9401da177e4SLinus Torvalds static inline int tcp_full_space(const struct sock *sk) 9411da177e4SLinus Torvalds { 9421da177e4SLinus Torvalds return tcp_win_from_space(sk->sk_rcvbuf); 9431da177e4SLinus Torvalds } 9441da177e4SLinus Torvalds 94540efc6faSStephen Hemminger static inline void tcp_openreq_init(struct request_sock *req, 9461da177e4SLinus Torvalds struct tcp_options_received *rx_opt, 9471da177e4SLinus Torvalds struct sk_buff *skb) 9481da177e4SLinus Torvalds { 9492e6599cbSArnaldo Carvalho de Melo struct inet_request_sock *ireq = inet_rsk(req); 9502e6599cbSArnaldo Carvalho de Melo 9511da177e4SLinus Torvalds req->rcv_wnd = 0; /* So that tcp_send_synack() knows! */ 9522e6599cbSArnaldo Carvalho de Melo tcp_rsk(req)->rcv_isn = TCP_SKB_CB(skb)->seq; 9531da177e4SLinus Torvalds req->mss = rx_opt->mss_clamp; 9541da177e4SLinus Torvalds req->ts_recent = rx_opt->saw_tstamp ? rx_opt->rcv_tsval : 0; 9552e6599cbSArnaldo Carvalho de Melo ireq->tstamp_ok = rx_opt->tstamp_ok; 9562e6599cbSArnaldo Carvalho de Melo ireq->sack_ok = rx_opt->sack_ok; 9572e6599cbSArnaldo Carvalho de Melo ireq->snd_wscale = rx_opt->snd_wscale; 9582e6599cbSArnaldo Carvalho de Melo ireq->wscale_ok = rx_opt->wscale_ok; 9592e6599cbSArnaldo Carvalho de Melo ireq->acked = 0; 9602e6599cbSArnaldo Carvalho de Melo ireq->ecn_ok = 0; 9612e6599cbSArnaldo Carvalho de Melo ireq->rmt_port = skb->h.th->source; 9621da177e4SLinus Torvalds } 9631da177e4SLinus Torvalds 9641da177e4SLinus Torvalds extern void tcp_enter_memory_pressure(void); 9651da177e4SLinus Torvalds 9661da177e4SLinus Torvalds static inline int keepalive_intvl_when(const struct tcp_sock *tp) 9671da177e4SLinus Torvalds { 9681da177e4SLinus Torvalds return tp->keepalive_intvl ? : sysctl_tcp_keepalive_intvl; 9691da177e4SLinus Torvalds } 9701da177e4SLinus Torvalds 9711da177e4SLinus Torvalds static inline int keepalive_time_when(const struct tcp_sock *tp) 9721da177e4SLinus Torvalds { 9731da177e4SLinus Torvalds return tp->keepalive_time ? : sysctl_tcp_keepalive_time; 9741da177e4SLinus Torvalds } 9751da177e4SLinus Torvalds 976463c84b9SArnaldo Carvalho de Melo static inline int tcp_fin_time(const struct sock *sk) 9771da177e4SLinus Torvalds { 978463c84b9SArnaldo Carvalho de Melo int fin_timeout = tcp_sk(sk)->linger2 ? : sysctl_tcp_fin_timeout; 979463c84b9SArnaldo Carvalho de Melo const int rto = inet_csk(sk)->icsk_rto; 9801da177e4SLinus Torvalds 981463c84b9SArnaldo Carvalho de Melo if (fin_timeout < (rto << 2) - (rto >> 1)) 982463c84b9SArnaldo Carvalho de Melo fin_timeout = (rto << 2) - (rto >> 1); 9831da177e4SLinus Torvalds 9841da177e4SLinus Torvalds return fin_timeout; 9851da177e4SLinus Torvalds } 9861da177e4SLinus Torvalds 9871da177e4SLinus Torvalds static inline int tcp_paws_check(const struct tcp_options_received *rx_opt, int rst) 9881da177e4SLinus Torvalds { 9891da177e4SLinus Torvalds if ((s32)(rx_opt->rcv_tsval - rx_opt->ts_recent) >= 0) 9901da177e4SLinus Torvalds return 0; 9911da177e4SLinus Torvalds if (xtime.tv_sec >= rx_opt->ts_recent_stamp + TCP_PAWS_24DAYS) 9921da177e4SLinus Torvalds return 0; 9931da177e4SLinus Torvalds 9941da177e4SLinus Torvalds /* RST segments are not recommended to carry timestamp, 9951da177e4SLinus Torvalds and, if they do, it is recommended to ignore PAWS because 9961da177e4SLinus Torvalds "their cleanup function should take precedence over timestamps." 9971da177e4SLinus Torvalds Certainly, it is mistake. It is necessary to understand the reasons 9981da177e4SLinus Torvalds of this constraint to relax it: if peer reboots, clock may go 9991da177e4SLinus Torvalds out-of-sync and half-open connections will not be reset. 10001da177e4SLinus Torvalds Actually, the problem would be not existing if all 10011da177e4SLinus Torvalds the implementations followed draft about maintaining clock 10021da177e4SLinus Torvalds via reboots. Linux-2.2 DOES NOT! 10031da177e4SLinus Torvalds 10041da177e4SLinus Torvalds However, we can relax time bounds for RST segments to MSL. 10051da177e4SLinus Torvalds */ 10061da177e4SLinus Torvalds if (rst && xtime.tv_sec >= rx_opt->ts_recent_stamp + TCP_PAWS_MSL) 10071da177e4SLinus Torvalds return 0; 10081da177e4SLinus Torvalds return 1; 10091da177e4SLinus Torvalds } 10101da177e4SLinus Torvalds 10111da177e4SLinus Torvalds #define TCP_CHECK_TIMER(sk) do { } while (0) 10121da177e4SLinus Torvalds 10131da177e4SLinus Torvalds static inline int tcp_use_frto(const struct sock *sk) 10141da177e4SLinus Torvalds { 10151da177e4SLinus Torvalds const struct tcp_sock *tp = tcp_sk(sk); 10161da177e4SLinus Torvalds 10171da177e4SLinus Torvalds /* F-RTO must be activated in sysctl and there must be some 10181da177e4SLinus Torvalds * unsent new data, and the advertised window should allow 10191da177e4SLinus Torvalds * sending it. 10201da177e4SLinus Torvalds */ 10211da177e4SLinus Torvalds return (sysctl_tcp_frto && sk->sk_send_head && 10221da177e4SLinus Torvalds !after(TCP_SKB_CB(sk->sk_send_head)->end_seq, 10231da177e4SLinus Torvalds tp->snd_una + tp->snd_wnd)); 10241da177e4SLinus Torvalds } 10251da177e4SLinus Torvalds 10261da177e4SLinus Torvalds static inline void tcp_mib_init(void) 10271da177e4SLinus Torvalds { 10281da177e4SLinus Torvalds /* See RFC 2012 */ 10291da177e4SLinus Torvalds TCP_ADD_STATS_USER(TCP_MIB_RTOALGORITHM, 1); 10301da177e4SLinus Torvalds TCP_ADD_STATS_USER(TCP_MIB_RTOMIN, TCP_RTO_MIN*1000/HZ); 10311da177e4SLinus Torvalds TCP_ADD_STATS_USER(TCP_MIB_RTOMAX, TCP_RTO_MAX*1000/HZ); 10321da177e4SLinus Torvalds TCP_ADD_STATS_USER(TCP_MIB_MAXCONN, -1); 10331da177e4SLinus Torvalds } 10341da177e4SLinus Torvalds 10356a438bbeSStephen Hemminger /*from STCP */ 10366a438bbeSStephen Hemminger static inline void clear_all_retrans_hints(struct tcp_sock *tp){ 10376a438bbeSStephen Hemminger tp->lost_skb_hint = NULL; 10386a438bbeSStephen Hemminger tp->scoreboard_skb_hint = NULL; 10396a438bbeSStephen Hemminger tp->retransmit_skb_hint = NULL; 10406a438bbeSStephen Hemminger tp->forward_skb_hint = NULL; 10416a438bbeSStephen Hemminger tp->fastpath_skb_hint = NULL; 10426a438bbeSStephen Hemminger } 10436a438bbeSStephen Hemminger 10441da177e4SLinus Torvalds /* /proc */ 10451da177e4SLinus Torvalds enum tcp_seq_states { 10461da177e4SLinus Torvalds TCP_SEQ_STATE_LISTENING, 10471da177e4SLinus Torvalds TCP_SEQ_STATE_OPENREQ, 10481da177e4SLinus Torvalds TCP_SEQ_STATE_ESTABLISHED, 10491da177e4SLinus Torvalds TCP_SEQ_STATE_TIME_WAIT, 10501da177e4SLinus Torvalds }; 10511da177e4SLinus Torvalds 10521da177e4SLinus Torvalds struct tcp_seq_afinfo { 10531da177e4SLinus Torvalds struct module *owner; 10541da177e4SLinus Torvalds char *name; 10551da177e4SLinus Torvalds sa_family_t family; 10561da177e4SLinus Torvalds int (*seq_show) (struct seq_file *m, void *v); 10571da177e4SLinus Torvalds struct file_operations *seq_fops; 10581da177e4SLinus Torvalds }; 10591da177e4SLinus Torvalds 10601da177e4SLinus Torvalds struct tcp_iter_state { 10611da177e4SLinus Torvalds sa_family_t family; 10621da177e4SLinus Torvalds enum tcp_seq_states state; 10631da177e4SLinus Torvalds struct sock *syn_wait_sk; 10641da177e4SLinus Torvalds int bucket, sbucket, num, uid; 10651da177e4SLinus Torvalds struct seq_operations seq_ops; 10661da177e4SLinus Torvalds }; 10671da177e4SLinus Torvalds 10681da177e4SLinus Torvalds extern int tcp_proc_register(struct tcp_seq_afinfo *afinfo); 10691da177e4SLinus Torvalds extern void tcp_proc_unregister(struct tcp_seq_afinfo *afinfo); 10701da177e4SLinus Torvalds 107120380731SArnaldo Carvalho de Melo extern struct request_sock_ops tcp_request_sock_ops; 107220380731SArnaldo Carvalho de Melo 107320380731SArnaldo Carvalho de Melo extern int tcp_v4_destroy_sock(struct sock *sk); 107420380731SArnaldo Carvalho de Melo 107520380731SArnaldo Carvalho de Melo #ifdef CONFIG_PROC_FS 107620380731SArnaldo Carvalho de Melo extern int tcp4_proc_init(void); 107720380731SArnaldo Carvalho de Melo extern void tcp4_proc_exit(void); 107820380731SArnaldo Carvalho de Melo #endif 107920380731SArnaldo Carvalho de Melo 108020380731SArnaldo Carvalho de Melo extern void tcp_v4_init(struct net_proto_family *ops); 108120380731SArnaldo Carvalho de Melo extern void tcp_init(void); 108220380731SArnaldo Carvalho de Melo 10831da177e4SLinus Torvalds #endif /* _TCP_H */ 1084