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/list.h> 251da177e4SLinus Torvalds #include <linux/tcp.h> 261da177e4SLinus Torvalds #include <linux/slab.h> 271da177e4SLinus Torvalds #include <linux/cache.h> 281da177e4SLinus Torvalds #include <linux/percpu.h> 29fb286bb2SHerbert Xu #include <linux/skbuff.h> 3097fc2f08SChris Leech #include <linux/dmaengine.h> 31cfb6eeb4SYOSHIFUJI Hideaki #include <linux/crypto.h> 32c6aefafbSGlenn Griffin #include <linux/cryptohash.h> 333f421baaSArnaldo Carvalho de Melo 343f421baaSArnaldo Carvalho de Melo #include <net/inet_connection_sock.h> 35295ff7edSArnaldo Carvalho de Melo #include <net/inet_timewait_sock.h> 3677d8bf9cSArnaldo Carvalho de Melo #include <net/inet_hashtables.h> 371da177e4SLinus Torvalds #include <net/checksum.h> 382e6599cbSArnaldo Carvalho de Melo #include <net/request_sock.h> 391da177e4SLinus Torvalds #include <net/sock.h> 401da177e4SLinus Torvalds #include <net/snmp.h> 411da177e4SLinus Torvalds #include <net/ip.h> 42c752f073SArnaldo Carvalho de Melo #include <net/tcp_states.h> 43bdf1ee5dSIlpo Järvinen #include <net/inet_ecn.h> 44c752f073SArnaldo Carvalho de Melo 451da177e4SLinus Torvalds #include <linux/seq_file.h> 461da177e4SLinus Torvalds 470f7ff927SArnaldo Carvalho de Melo extern struct inet_hashinfo tcp_hashinfo; 481da177e4SLinus Torvalds 491da177e4SLinus Torvalds extern atomic_t tcp_orphan_count; 501da177e4SLinus Torvalds extern void tcp_time_wait(struct sock *sk, int state, int timeo); 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds #define MAX_TCP_HEADER (128 + MAX_HEADER) 531da177e4SLinus Torvalds 541da177e4SLinus Torvalds /* 551da177e4SLinus Torvalds * Never offer a window over 32767 without using window scaling. Some 561da177e4SLinus Torvalds * poor stacks do signed 16bit maths! 571da177e4SLinus Torvalds */ 581da177e4SLinus Torvalds #define MAX_TCP_WINDOW 32767U 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds /* Minimal accepted MSS. It is (60+60+8) - (20+20). */ 611da177e4SLinus Torvalds #define TCP_MIN_MSS 88U 621da177e4SLinus Torvalds 631da177e4SLinus Torvalds /* Minimal RCV_MSS. */ 641da177e4SLinus Torvalds #define TCP_MIN_RCVMSS 536U 651da177e4SLinus Torvalds 665d424d5aSJohn Heffner /* The least MTU to use for probing */ 675d424d5aSJohn Heffner #define TCP_BASE_MSS 512 685d424d5aSJohn Heffner 691da177e4SLinus Torvalds /* After receiving this amount of duplicate ACKs fast retransmit starts. */ 701da177e4SLinus Torvalds #define TCP_FASTRETRANS_THRESH 3 711da177e4SLinus Torvalds 721da177e4SLinus Torvalds /* Maximal reordering. */ 731da177e4SLinus Torvalds #define TCP_MAX_REORDERING 127 741da177e4SLinus Torvalds 751da177e4SLinus Torvalds /* Maximal number of ACKs sent quickly to accelerate slow-start. */ 761da177e4SLinus Torvalds #define TCP_MAX_QUICKACKS 16U 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds /* urg_data states */ 791da177e4SLinus Torvalds #define TCP_URG_VALID 0x0100 801da177e4SLinus Torvalds #define TCP_URG_NOTYET 0x0200 811da177e4SLinus Torvalds #define TCP_URG_READ 0x0400 821da177e4SLinus Torvalds 831da177e4SLinus Torvalds #define TCP_RETR1 3 /* 841da177e4SLinus Torvalds * This is how many retries it does before it 851da177e4SLinus Torvalds * tries to figure out if the gateway is 861da177e4SLinus Torvalds * down. Minimal RFC value is 3; it corresponds 871da177e4SLinus Torvalds * to ~3sec-8min depending on RTO. 881da177e4SLinus Torvalds */ 891da177e4SLinus Torvalds 901da177e4SLinus Torvalds #define TCP_RETR2 15 /* 911da177e4SLinus Torvalds * This should take at least 921da177e4SLinus Torvalds * 90 minutes to time out. 931da177e4SLinus Torvalds * RFC1122 says that the limit is 100 sec. 941da177e4SLinus Torvalds * 15 is ~13-30min depending on RTO. 951da177e4SLinus Torvalds */ 961da177e4SLinus Torvalds 971da177e4SLinus Torvalds #define TCP_SYN_RETRIES 5 /* number of times to retry active opening a 98caa20d9aSStephen Hemminger * connection: ~180sec is RFC minimum */ 991da177e4SLinus Torvalds 1001da177e4SLinus Torvalds #define TCP_SYNACK_RETRIES 5 /* number of times to retry passive opening a 101caa20d9aSStephen Hemminger * connection: ~180sec is RFC minimum */ 1021da177e4SLinus Torvalds 1031da177e4SLinus Torvalds 1041da177e4SLinus Torvalds #define TCP_ORPHAN_RETRIES 7 /* number of times to retry on an orphaned 1051da177e4SLinus Torvalds * socket. 7 is ~50sec-16min. 1061da177e4SLinus Torvalds */ 1071da177e4SLinus Torvalds 1081da177e4SLinus Torvalds 1091da177e4SLinus Torvalds #define TCP_TIMEWAIT_LEN (60*HZ) /* how long to wait to destroy TIME-WAIT 1101da177e4SLinus Torvalds * state, about 60 seconds */ 1111da177e4SLinus Torvalds #define TCP_FIN_TIMEOUT TCP_TIMEWAIT_LEN 1121da177e4SLinus Torvalds /* BSD style FIN_WAIT2 deadlock breaker. 1131da177e4SLinus Torvalds * It used to be 3min, new value is 60sec, 1141da177e4SLinus Torvalds * to combine FIN-WAIT-2 timeout with 1151da177e4SLinus Torvalds * TIME-WAIT timer. 1161da177e4SLinus Torvalds */ 1171da177e4SLinus Torvalds 1181da177e4SLinus Torvalds #define TCP_DELACK_MAX ((unsigned)(HZ/5)) /* maximal time to delay before sending an ACK */ 1191da177e4SLinus Torvalds #if HZ >= 100 1201da177e4SLinus Torvalds #define TCP_DELACK_MIN ((unsigned)(HZ/25)) /* minimal time to delay before sending an ACK */ 1211da177e4SLinus Torvalds #define TCP_ATO_MIN ((unsigned)(HZ/25)) 1221da177e4SLinus Torvalds #else 1231da177e4SLinus Torvalds #define TCP_DELACK_MIN 4U 1241da177e4SLinus Torvalds #define TCP_ATO_MIN 4U 1251da177e4SLinus Torvalds #endif 1261da177e4SLinus Torvalds #define TCP_RTO_MAX ((unsigned)(120*HZ)) 1271da177e4SLinus Torvalds #define TCP_RTO_MIN ((unsigned)(HZ/5)) 1281da177e4SLinus Torvalds #define TCP_TIMEOUT_INIT ((unsigned)(3*HZ)) /* RFC 1122 initial RTO value */ 1291da177e4SLinus Torvalds 1301da177e4SLinus Torvalds #define TCP_RESOURCE_PROBE_INTERVAL ((unsigned)(HZ/2U)) /* Maximal interval between probes 1311da177e4SLinus Torvalds * for local resources. 1321da177e4SLinus Torvalds */ 1331da177e4SLinus Torvalds 1341da177e4SLinus Torvalds #define TCP_KEEPALIVE_TIME (120*60*HZ) /* two hours */ 1351da177e4SLinus Torvalds #define TCP_KEEPALIVE_PROBES 9 /* Max of 9 keepalive probes */ 1361da177e4SLinus Torvalds #define TCP_KEEPALIVE_INTVL (75*HZ) 1371da177e4SLinus Torvalds 1381da177e4SLinus Torvalds #define MAX_TCP_KEEPIDLE 32767 1391da177e4SLinus Torvalds #define MAX_TCP_KEEPINTVL 32767 1401da177e4SLinus Torvalds #define MAX_TCP_KEEPCNT 127 1411da177e4SLinus Torvalds #define MAX_TCP_SYNCNT 127 142ec3c0982SPatrick McManus #define MAX_TCP_ACCEPT_DEFERRED 65535 1431da177e4SLinus Torvalds 1441da177e4SLinus Torvalds #define TCP_SYNQ_INTERVAL (HZ/5) /* Period of SYNACK timer */ 1451da177e4SLinus Torvalds 1461da177e4SLinus Torvalds #define TCP_PAWS_24DAYS (60 * 60 * 24 * 24) 1471da177e4SLinus Torvalds #define TCP_PAWS_MSL 60 /* Per-host timestamps are invalidated 1481da177e4SLinus Torvalds * after this time. It should be equal 1491da177e4SLinus Torvalds * (or greater than) TCP_TIMEWAIT_LEN 1501da177e4SLinus Torvalds * to provide reliability equal to one 1511da177e4SLinus Torvalds * provided by timewait state. 1521da177e4SLinus Torvalds */ 1531da177e4SLinus Torvalds #define TCP_PAWS_WINDOW 1 /* Replay window for per-host 1541da177e4SLinus Torvalds * timestamps. It must be less than 1551da177e4SLinus Torvalds * minimal timewait lifetime. 1561da177e4SLinus Torvalds */ 1571da177e4SLinus Torvalds /* 1581da177e4SLinus Torvalds * TCP option 1591da177e4SLinus Torvalds */ 1601da177e4SLinus Torvalds 1611da177e4SLinus Torvalds #define TCPOPT_NOP 1 /* Padding */ 1621da177e4SLinus Torvalds #define TCPOPT_EOL 0 /* End of options */ 1631da177e4SLinus Torvalds #define TCPOPT_MSS 2 /* Segment size negotiating */ 1641da177e4SLinus Torvalds #define TCPOPT_WINDOW 3 /* Window scaling */ 1651da177e4SLinus Torvalds #define TCPOPT_SACK_PERM 4 /* SACK Permitted */ 1661da177e4SLinus Torvalds #define TCPOPT_SACK 5 /* SACK Block */ 1671da177e4SLinus Torvalds #define TCPOPT_TIMESTAMP 8 /* Better RTT estimations/PAWS */ 168cfb6eeb4SYOSHIFUJI Hideaki #define TCPOPT_MD5SIG 19 /* MD5 Signature (RFC2385) */ 1691da177e4SLinus Torvalds 1701da177e4SLinus Torvalds /* 1711da177e4SLinus Torvalds * TCP option lengths 1721da177e4SLinus Torvalds */ 1731da177e4SLinus Torvalds 1741da177e4SLinus Torvalds #define TCPOLEN_MSS 4 1751da177e4SLinus Torvalds #define TCPOLEN_WINDOW 3 1761da177e4SLinus Torvalds #define TCPOLEN_SACK_PERM 2 1771da177e4SLinus Torvalds #define TCPOLEN_TIMESTAMP 10 178cfb6eeb4SYOSHIFUJI Hideaki #define TCPOLEN_MD5SIG 18 1791da177e4SLinus Torvalds 1801da177e4SLinus Torvalds /* But this is what stacks really send out. */ 1811da177e4SLinus Torvalds #define TCPOLEN_TSTAMP_ALIGNED 12 1821da177e4SLinus Torvalds #define TCPOLEN_WSCALE_ALIGNED 4 1831da177e4SLinus Torvalds #define TCPOLEN_SACKPERM_ALIGNED 4 1841da177e4SLinus Torvalds #define TCPOLEN_SACK_BASE 2 1851da177e4SLinus Torvalds #define TCPOLEN_SACK_BASE_ALIGNED 4 1861da177e4SLinus Torvalds #define TCPOLEN_SACK_PERBLOCK 8 187cfb6eeb4SYOSHIFUJI Hideaki #define TCPOLEN_MD5SIG_ALIGNED 20 1881da177e4SLinus Torvalds 1891da177e4SLinus Torvalds /* Flags in tp->nonagle */ 1901da177e4SLinus Torvalds #define TCP_NAGLE_OFF 1 /* Nagle's algo is disabled */ 1911da177e4SLinus Torvalds #define TCP_NAGLE_CORK 2 /* Socket is corked */ 192caa20d9aSStephen Hemminger #define TCP_NAGLE_PUSH 4 /* Cork is overridden for already queued data */ 1931da177e4SLinus Torvalds 194295ff7edSArnaldo Carvalho de Melo extern struct inet_timewait_death_row tcp_death_row; 195295ff7edSArnaldo Carvalho de Melo 1961da177e4SLinus Torvalds /* sysctl variables for tcp */ 1971da177e4SLinus Torvalds extern int sysctl_tcp_timestamps; 1981da177e4SLinus Torvalds extern int sysctl_tcp_window_scaling; 1991da177e4SLinus Torvalds extern int sysctl_tcp_sack; 2001da177e4SLinus Torvalds extern int sysctl_tcp_fin_timeout; 2011da177e4SLinus Torvalds extern int sysctl_tcp_keepalive_time; 2021da177e4SLinus Torvalds extern int sysctl_tcp_keepalive_probes; 2031da177e4SLinus Torvalds extern int sysctl_tcp_keepalive_intvl; 2041da177e4SLinus Torvalds extern int sysctl_tcp_syn_retries; 2051da177e4SLinus Torvalds extern int sysctl_tcp_synack_retries; 2061da177e4SLinus Torvalds extern int sysctl_tcp_retries1; 2071da177e4SLinus Torvalds extern int sysctl_tcp_retries2; 2081da177e4SLinus Torvalds extern int sysctl_tcp_orphan_retries; 2091da177e4SLinus Torvalds extern int sysctl_tcp_syncookies; 2101da177e4SLinus Torvalds extern int sysctl_tcp_retrans_collapse; 2111da177e4SLinus Torvalds extern int sysctl_tcp_stdurg; 2121da177e4SLinus Torvalds extern int sysctl_tcp_rfc1337; 2131da177e4SLinus Torvalds extern int sysctl_tcp_abort_on_overflow; 2141da177e4SLinus Torvalds extern int sysctl_tcp_max_orphans; 2151da177e4SLinus Torvalds extern int sysctl_tcp_fack; 2161da177e4SLinus Torvalds extern int sysctl_tcp_reordering; 2171da177e4SLinus Torvalds extern int sysctl_tcp_ecn; 2181da177e4SLinus Torvalds extern int sysctl_tcp_dsack; 2191da177e4SLinus Torvalds extern int sysctl_tcp_mem[3]; 2201da177e4SLinus Torvalds extern int sysctl_tcp_wmem[3]; 2211da177e4SLinus Torvalds extern int sysctl_tcp_rmem[3]; 2221da177e4SLinus Torvalds extern int sysctl_tcp_app_win; 2231da177e4SLinus Torvalds extern int sysctl_tcp_adv_win_scale; 2241da177e4SLinus Torvalds extern int sysctl_tcp_tw_reuse; 2251da177e4SLinus Torvalds extern int sysctl_tcp_frto; 2263cfe3baaSIlpo Järvinen extern int sysctl_tcp_frto_response; 2271da177e4SLinus Torvalds extern int sysctl_tcp_low_latency; 22895937825SChris Leech extern int sysctl_tcp_dma_copybreak; 2291da177e4SLinus Torvalds extern int sysctl_tcp_nometrics_save; 2301da177e4SLinus Torvalds extern int sysctl_tcp_moderate_rcvbuf; 2311da177e4SLinus Torvalds extern int sysctl_tcp_tso_win_divisor; 2329772efb9SStephen Hemminger extern int sysctl_tcp_abc; 2335d424d5aSJohn Heffner extern int sysctl_tcp_mtu_probing; 2345d424d5aSJohn Heffner extern int sysctl_tcp_base_mss; 23515d99e02SRick Jones extern int sysctl_tcp_workaround_signed_windows; 23635089bb2SDavid S. Miller extern int sysctl_tcp_slow_start_after_idle; 237886236c1SJohn Heffner extern int sysctl_tcp_max_ssthresh; 2381da177e4SLinus Torvalds 2391da177e4SLinus Torvalds extern atomic_t tcp_memory_allocated; 2401da177e4SLinus Torvalds extern atomic_t tcp_sockets_allocated; 2411da177e4SLinus Torvalds extern int tcp_memory_pressure; 2421da177e4SLinus Torvalds 2431da177e4SLinus Torvalds /* 2441da177e4SLinus Torvalds * The next routines deal with comparing 32 bit unsigned ints 2451da177e4SLinus Torvalds * and worry about wraparound (automatic with unsigned arithmetic). 2461da177e4SLinus Torvalds */ 2471da177e4SLinus Torvalds 2481da177e4SLinus Torvalds static inline int before(__u32 seq1, __u32 seq2) 2491da177e4SLinus Torvalds { 2500d630cc0SGerrit Renker return (__s32)(seq1-seq2) < 0; 2511da177e4SLinus Torvalds } 2529a036b9cSGerrit Renker #define after(seq2, seq1) before(seq1, seq2) 2531da177e4SLinus Torvalds 2541da177e4SLinus Torvalds /* is s2<=s1<=s3 ? */ 2551da177e4SLinus Torvalds static inline int between(__u32 seq1, __u32 seq2, __u32 seq3) 2561da177e4SLinus Torvalds { 2571da177e4SLinus Torvalds return seq3 - seq2 >= seq1 - seq2; 2581da177e4SLinus Torvalds } 2591da177e4SLinus Torvalds 260e4fd5da3SPavel Emelianov static inline int tcp_too_many_orphans(struct sock *sk, int num) 261e4fd5da3SPavel Emelianov { 262e4fd5da3SPavel Emelianov return (num > sysctl_tcp_max_orphans) || 263e4fd5da3SPavel Emelianov (sk->sk_wmem_queued > SOCK_MIN_SNDBUF && 264e4fd5da3SPavel Emelianov atomic_read(&tcp_memory_allocated) > sysctl_tcp_mem[2]); 265e4fd5da3SPavel Emelianov } 2661da177e4SLinus Torvalds 2671da177e4SLinus Torvalds extern struct proto tcp_prot; 2681da177e4SLinus Torvalds 2691da177e4SLinus Torvalds DECLARE_SNMP_STAT(struct tcp_mib, tcp_statistics); 2701da177e4SLinus Torvalds #define TCP_INC_STATS(field) SNMP_INC_STATS(tcp_statistics, field) 2711da177e4SLinus Torvalds #define TCP_INC_STATS_BH(field) SNMP_INC_STATS_BH(tcp_statistics, field) 2721da177e4SLinus Torvalds #define TCP_INC_STATS_USER(field) SNMP_INC_STATS_USER(tcp_statistics, field) 2731da177e4SLinus Torvalds #define TCP_DEC_STATS(field) SNMP_DEC_STATS(tcp_statistics, field) 2741da177e4SLinus Torvalds #define TCP_ADD_STATS_BH(field, val) SNMP_ADD_STATS_BH(tcp_statistics, field, val) 2751da177e4SLinus Torvalds #define TCP_ADD_STATS_USER(field, val) SNMP_ADD_STATS_USER(tcp_statistics, field, val) 2761da177e4SLinus Torvalds 2771da177e4SLinus Torvalds extern void tcp_v4_err(struct sk_buff *skb, u32); 2781da177e4SLinus Torvalds 2791da177e4SLinus Torvalds extern void tcp_shutdown (struct sock *sk, int how); 2801da177e4SLinus Torvalds 2811da177e4SLinus Torvalds extern int tcp_v4_rcv(struct sk_buff *skb); 2821da177e4SLinus Torvalds 2831da177e4SLinus Torvalds extern int tcp_v4_remember_stamp(struct sock *sk); 2841da177e4SLinus Torvalds 2858feaf0c0SArnaldo Carvalho de Melo extern int tcp_v4_tw_remember_stamp(struct inet_timewait_sock *tw); 2861da177e4SLinus Torvalds 2873516ffb0SDavid S. Miller extern int tcp_sendmsg(struct kiocb *iocb, struct socket *sock, 2881da177e4SLinus Torvalds struct msghdr *msg, size_t size); 2891da177e4SLinus Torvalds extern ssize_t tcp_sendpage(struct socket *sock, struct page *page, int offset, size_t size, int flags); 2901da177e4SLinus Torvalds 2911da177e4SLinus Torvalds extern int tcp_ioctl(struct sock *sk, 2921da177e4SLinus Torvalds int cmd, 2931da177e4SLinus Torvalds unsigned long arg); 2941da177e4SLinus Torvalds 2951da177e4SLinus Torvalds extern int tcp_rcv_state_process(struct sock *sk, 2961da177e4SLinus Torvalds struct sk_buff *skb, 2971da177e4SLinus Torvalds struct tcphdr *th, 2981da177e4SLinus Torvalds unsigned len); 2991da177e4SLinus Torvalds 3001da177e4SLinus Torvalds extern int tcp_rcv_established(struct sock *sk, 3011da177e4SLinus Torvalds struct sk_buff *skb, 3021da177e4SLinus Torvalds struct tcphdr *th, 3031da177e4SLinus Torvalds unsigned len); 3041da177e4SLinus Torvalds 3051da177e4SLinus Torvalds extern void tcp_rcv_space_adjust(struct sock *sk); 3061da177e4SLinus Torvalds 3070e4b4992SChris Leech extern void tcp_cleanup_rbuf(struct sock *sk, int copied); 3080e4b4992SChris Leech 3096d6ee43eSArnaldo Carvalho de Melo extern int tcp_twsk_unique(struct sock *sk, 3106d6ee43eSArnaldo Carvalho de Melo struct sock *sktw, void *twp); 3116d6ee43eSArnaldo Carvalho de Melo 312cfb6eeb4SYOSHIFUJI Hideaki extern void tcp_twsk_destructor(struct sock *sk); 313cfb6eeb4SYOSHIFUJI Hideaki 3149c55e01cSJens Axboe extern ssize_t tcp_splice_read(struct socket *sk, loff_t *ppos, 3159c55e01cSJens Axboe struct pipe_inode_info *pipe, size_t len, unsigned int flags); 3169c55e01cSJens Axboe 317463c84b9SArnaldo Carvalho de Melo static inline void tcp_dec_quickack_mode(struct sock *sk, 318463c84b9SArnaldo Carvalho de Melo const unsigned int pkts) 3191da177e4SLinus Torvalds { 320463c84b9SArnaldo Carvalho de Melo struct inet_connection_sock *icsk = inet_csk(sk); 321fc6415bcSDavid S. Miller 322463c84b9SArnaldo Carvalho de Melo if (icsk->icsk_ack.quick) { 323463c84b9SArnaldo Carvalho de Melo if (pkts >= icsk->icsk_ack.quick) { 324463c84b9SArnaldo Carvalho de Melo icsk->icsk_ack.quick = 0; 3251da177e4SLinus Torvalds /* Leaving quickack mode we deflate ATO. */ 326463c84b9SArnaldo Carvalho de Melo icsk->icsk_ack.ato = TCP_ATO_MIN; 327fc6415bcSDavid S. Miller } else 328463c84b9SArnaldo Carvalho de Melo icsk->icsk_ack.quick -= pkts; 3291da177e4SLinus Torvalds } 3301da177e4SLinus Torvalds } 3311da177e4SLinus Torvalds 332463c84b9SArnaldo Carvalho de Melo extern void tcp_enter_quickack_mode(struct sock *sk); 3331da177e4SLinus Torvalds 3341da177e4SLinus Torvalds static inline void tcp_clear_options(struct tcp_options_received *rx_opt) 3351da177e4SLinus Torvalds { 3361da177e4SLinus Torvalds rx_opt->tstamp_ok = rx_opt->sack_ok = rx_opt->wscale_ok = rx_opt->snd_wscale = 0; 3371da177e4SLinus Torvalds } 3381da177e4SLinus Torvalds 339bdf1ee5dSIlpo Järvinen #define TCP_ECN_OK 1 340bdf1ee5dSIlpo Järvinen #define TCP_ECN_QUEUE_CWR 2 341bdf1ee5dSIlpo Järvinen #define TCP_ECN_DEMAND_CWR 4 342bdf1ee5dSIlpo Järvinen 343bdf1ee5dSIlpo Järvinen static __inline__ void 344bdf1ee5dSIlpo Järvinen TCP_ECN_create_request(struct request_sock *req, struct tcphdr *th) 345bdf1ee5dSIlpo Järvinen { 346bdf1ee5dSIlpo Järvinen if (sysctl_tcp_ecn && th->ece && th->cwr) 347bdf1ee5dSIlpo Järvinen inet_rsk(req)->ecn_ok = 1; 348bdf1ee5dSIlpo Järvinen } 349bdf1ee5dSIlpo Järvinen 3501da177e4SLinus Torvalds enum tcp_tw_status 3511da177e4SLinus Torvalds { 3521da177e4SLinus Torvalds TCP_TW_SUCCESS = 0, 3531da177e4SLinus Torvalds TCP_TW_RST = 1, 3541da177e4SLinus Torvalds TCP_TW_ACK = 2, 3551da177e4SLinus Torvalds TCP_TW_SYN = 3 3561da177e4SLinus Torvalds }; 3571da177e4SLinus Torvalds 3581da177e4SLinus Torvalds 3598feaf0c0SArnaldo Carvalho de Melo extern enum tcp_tw_status tcp_timewait_state_process(struct inet_timewait_sock *tw, 3601da177e4SLinus Torvalds struct sk_buff *skb, 3618feaf0c0SArnaldo Carvalho de Melo const struct tcphdr *th); 3621da177e4SLinus Torvalds 3631da177e4SLinus Torvalds extern struct sock * tcp_check_req(struct sock *sk,struct sk_buff *skb, 36460236fddSArnaldo Carvalho de Melo struct request_sock *req, 36560236fddSArnaldo Carvalho de Melo struct request_sock **prev); 3661da177e4SLinus Torvalds extern int tcp_child_process(struct sock *parent, 3671da177e4SLinus Torvalds struct sock *child, 3681da177e4SLinus Torvalds struct sk_buff *skb); 36946d0de4eSIlpo Järvinen extern int tcp_use_frto(struct sock *sk); 3701da177e4SLinus Torvalds extern void tcp_enter_frto(struct sock *sk); 3711da177e4SLinus Torvalds extern void tcp_enter_loss(struct sock *sk, int how); 3721da177e4SLinus Torvalds extern void tcp_clear_retrans(struct tcp_sock *tp); 3731da177e4SLinus Torvalds extern void tcp_update_metrics(struct sock *sk); 3741da177e4SLinus Torvalds 3751da177e4SLinus Torvalds extern void tcp_close(struct sock *sk, 3761da177e4SLinus Torvalds long timeout); 3771da177e4SLinus Torvalds extern unsigned int tcp_poll(struct file * file, struct socket *sock, struct poll_table_struct *wait); 3781da177e4SLinus Torvalds 3791da177e4SLinus Torvalds extern int tcp_getsockopt(struct sock *sk, int level, 3801da177e4SLinus Torvalds int optname, 3811da177e4SLinus Torvalds char __user *optval, 3821da177e4SLinus Torvalds int __user *optlen); 3831da177e4SLinus Torvalds extern int tcp_setsockopt(struct sock *sk, int level, 3841da177e4SLinus Torvalds int optname, char __user *optval, 3851da177e4SLinus Torvalds int optlen); 3863fdadf7dSDmitry Mishin extern int compat_tcp_getsockopt(struct sock *sk, 3873fdadf7dSDmitry Mishin int level, int optname, 3883fdadf7dSDmitry Mishin char __user *optval, int __user *optlen); 3893fdadf7dSDmitry Mishin extern int compat_tcp_setsockopt(struct sock *sk, 3903fdadf7dSDmitry Mishin int level, int optname, 3913fdadf7dSDmitry Mishin char __user *optval, int optlen); 3921da177e4SLinus Torvalds extern void tcp_set_keepalive(struct sock *sk, int val); 3931da177e4SLinus Torvalds extern int tcp_recvmsg(struct kiocb *iocb, struct sock *sk, 3941da177e4SLinus Torvalds struct msghdr *msg, 3951da177e4SLinus Torvalds size_t len, int nonblock, 3961da177e4SLinus Torvalds int flags, int *addr_len); 3971da177e4SLinus Torvalds 3981da177e4SLinus Torvalds extern void tcp_parse_options(struct sk_buff *skb, 3991da177e4SLinus Torvalds struct tcp_options_received *opt_rx, 4001da177e4SLinus Torvalds int estab); 4011da177e4SLinus Torvalds 4021da177e4SLinus Torvalds /* 4031da177e4SLinus Torvalds * TCP v4 functions exported for the inet6 API 4041da177e4SLinus Torvalds */ 4051da177e4SLinus Torvalds 4068292a17aSArnaldo Carvalho de Melo extern void tcp_v4_send_check(struct sock *sk, int len, 4071da177e4SLinus Torvalds struct sk_buff *skb); 4081da177e4SLinus Torvalds 4091da177e4SLinus Torvalds extern int tcp_v4_conn_request(struct sock *sk, 4101da177e4SLinus Torvalds struct sk_buff *skb); 4111da177e4SLinus Torvalds 4121da177e4SLinus Torvalds extern struct sock * tcp_create_openreq_child(struct sock *sk, 41360236fddSArnaldo Carvalho de Melo struct request_sock *req, 4141da177e4SLinus Torvalds struct sk_buff *skb); 4151da177e4SLinus Torvalds 4161da177e4SLinus Torvalds extern struct sock * tcp_v4_syn_recv_sock(struct sock *sk, 4171da177e4SLinus Torvalds struct sk_buff *skb, 41860236fddSArnaldo Carvalho de Melo struct request_sock *req, 4191da177e4SLinus Torvalds struct dst_entry *dst); 4201da177e4SLinus Torvalds 4211da177e4SLinus Torvalds extern int tcp_v4_do_rcv(struct sock *sk, 4221da177e4SLinus Torvalds struct sk_buff *skb); 4231da177e4SLinus Torvalds 4241da177e4SLinus Torvalds extern int tcp_v4_connect(struct sock *sk, 4251da177e4SLinus Torvalds struct sockaddr *uaddr, 4261da177e4SLinus Torvalds int addr_len); 4271da177e4SLinus Torvalds 4281da177e4SLinus Torvalds extern int tcp_connect(struct sock *sk); 4291da177e4SLinus Torvalds 4301da177e4SLinus Torvalds extern struct sk_buff * tcp_make_synack(struct sock *sk, 4311da177e4SLinus Torvalds struct dst_entry *dst, 43260236fddSArnaldo Carvalho de Melo struct request_sock *req); 4331da177e4SLinus Torvalds 4341da177e4SLinus Torvalds extern int tcp_disconnect(struct sock *sk, int flags); 4351da177e4SLinus Torvalds 4361da177e4SLinus Torvalds extern void tcp_unhash(struct sock *sk); 4371da177e4SLinus Torvalds 4381da177e4SLinus Torvalds /* From syncookies.c */ 4392051f11fSFlorian Westphal extern __u32 syncookie_secret[2][16-4+SHA_DIGEST_WORDS]; 4401da177e4SLinus Torvalds extern struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb, 4411da177e4SLinus Torvalds struct ip_options *opt); 4421da177e4SLinus Torvalds extern __u32 cookie_v4_init_sequence(struct sock *sk, struct sk_buff *skb, 4431da177e4SLinus Torvalds __u16 *mss); 4441da177e4SLinus Torvalds 445*4dfc2817SFlorian Westphal extern __u32 cookie_init_timestamp(struct request_sock *req); 446*4dfc2817SFlorian Westphal extern void cookie_check_timestamp(struct tcp_options_received *tcp_opt); 447*4dfc2817SFlorian Westphal 448c6aefafbSGlenn Griffin /* From net/ipv6/syncookies.c */ 449c6aefafbSGlenn Griffin extern struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb); 450c6aefafbSGlenn Griffin extern __u32 cookie_v6_init_sequence(struct sock *sk, struct sk_buff *skb, 451c6aefafbSGlenn Griffin __u16 *mss); 452c6aefafbSGlenn Griffin 4531da177e4SLinus Torvalds /* tcp_output.c */ 4541da177e4SLinus Torvalds 4559e412ba7SIlpo Järvinen extern void __tcp_push_pending_frames(struct sock *sk, unsigned int cur_mss, 4569e412ba7SIlpo Järvinen int nonagle); 4579e412ba7SIlpo Järvinen extern int tcp_may_send_now(struct sock *sk); 4581da177e4SLinus Torvalds extern int tcp_retransmit_skb(struct sock *, struct sk_buff *); 4591da177e4SLinus Torvalds extern void tcp_xmit_retransmit_queue(struct sock *); 4601da177e4SLinus Torvalds extern void tcp_simple_retransmit(struct sock *); 4611da177e4SLinus Torvalds extern int tcp_trim_head(struct sock *, struct sk_buff *, u32); 4626475be16SDavid S. Miller extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int); 4631da177e4SLinus Torvalds 4641da177e4SLinus Torvalds extern void tcp_send_probe0(struct sock *); 4651da177e4SLinus Torvalds extern void tcp_send_partial(struct sock *); 4661da177e4SLinus Torvalds extern int tcp_write_wakeup(struct sock *); 4671da177e4SLinus Torvalds extern void tcp_send_fin(struct sock *sk); 468dd0fc66fSAl Viro extern void tcp_send_active_reset(struct sock *sk, gfp_t priority); 4691da177e4SLinus Torvalds extern int tcp_send_synack(struct sock *); 470c1b4a7e6SDavid S. Miller extern void tcp_push_one(struct sock *, unsigned int mss_now); 4711da177e4SLinus Torvalds extern void tcp_send_ack(struct sock *sk); 4721da177e4SLinus Torvalds extern void tcp_send_delayed_ack(struct sock *sk); 4731da177e4SLinus Torvalds 474a762a980SDavid S. Miller /* tcp_input.c */ 475a762a980SDavid S. Miller extern void tcp_cwnd_application_limited(struct sock *sk); 476a762a980SDavid S. Miller 4771da177e4SLinus Torvalds /* tcp_timer.c */ 4781da177e4SLinus Torvalds extern void tcp_init_xmit_timers(struct sock *); 479463c84b9SArnaldo Carvalho de Melo static inline void tcp_clear_xmit_timers(struct sock *sk) 480463c84b9SArnaldo Carvalho de Melo { 481463c84b9SArnaldo Carvalho de Melo inet_csk_clear_xmit_timers(sk); 482463c84b9SArnaldo Carvalho de Melo } 4831da177e4SLinus Torvalds 4841da177e4SLinus Torvalds extern unsigned int tcp_sync_mss(struct sock *sk, u32 pmtu); 4851da177e4SLinus Torvalds extern unsigned int tcp_current_mss(struct sock *sk, int large); 4861da177e4SLinus Torvalds 48717b085eaSArnaldo Carvalho de Melo /* tcp.c */ 4881da177e4SLinus Torvalds extern void tcp_get_info(struct sock *, struct tcp_info *); 4891da177e4SLinus Torvalds 4901da177e4SLinus Torvalds /* Read 'sendfile()'-style from a TCP socket */ 4911da177e4SLinus Torvalds typedef int (*sk_read_actor_t)(read_descriptor_t *, struct sk_buff *, 4921da177e4SLinus Torvalds unsigned int, size_t); 4931da177e4SLinus Torvalds extern int tcp_read_sock(struct sock *sk, read_descriptor_t *desc, 4941da177e4SLinus Torvalds sk_read_actor_t recv_actor); 4951da177e4SLinus Torvalds 49640efc6faSStephen Hemminger extern void tcp_initialize_rcv_mss(struct sock *sk); 4971da177e4SLinus Torvalds 4985d424d5aSJohn Heffner extern int tcp_mtu_to_mss(struct sock *sk, int pmtu); 4995d424d5aSJohn Heffner extern int tcp_mss_to_mtu(struct sock *sk, int mss); 5005d424d5aSJohn Heffner extern void tcp_mtup_init(struct sock *sk); 5015d424d5aSJohn Heffner 50240efc6faSStephen Hemminger static inline void __tcp_fast_path_on(struct tcp_sock *tp, u32 snd_wnd) 5031da177e4SLinus Torvalds { 5041da177e4SLinus Torvalds tp->pred_flags = htonl((tp->tcp_header_len << 26) | 5051da177e4SLinus Torvalds ntohl(TCP_FLAG_ACK) | 5061da177e4SLinus Torvalds snd_wnd); 5071da177e4SLinus Torvalds } 5081da177e4SLinus Torvalds 50940efc6faSStephen Hemminger static inline void tcp_fast_path_on(struct tcp_sock *tp) 5101da177e4SLinus Torvalds { 5111da177e4SLinus Torvalds __tcp_fast_path_on(tp, tp->snd_wnd >> tp->rx_opt.snd_wscale); 5121da177e4SLinus Torvalds } 5131da177e4SLinus Torvalds 5149e412ba7SIlpo Järvinen static inline void tcp_fast_path_check(struct sock *sk) 5151da177e4SLinus Torvalds { 5169e412ba7SIlpo Järvinen struct tcp_sock *tp = tcp_sk(sk); 5179e412ba7SIlpo Järvinen 518b03efcfbSDavid S. Miller if (skb_queue_empty(&tp->out_of_order_queue) && 5191da177e4SLinus Torvalds tp->rcv_wnd && 5201da177e4SLinus Torvalds atomic_read(&sk->sk_rmem_alloc) < sk->sk_rcvbuf && 5211da177e4SLinus Torvalds !tp->urg_data) 5221da177e4SLinus Torvalds tcp_fast_path_on(tp); 5231da177e4SLinus Torvalds } 5241da177e4SLinus Torvalds 5251da177e4SLinus Torvalds /* Compute the actual receive window we are currently advertising. 5261da177e4SLinus Torvalds * Rcv_nxt can be after the window if our peer push more data 5271da177e4SLinus Torvalds * than the offered window. 5281da177e4SLinus Torvalds */ 52940efc6faSStephen Hemminger static inline u32 tcp_receive_window(const struct tcp_sock *tp) 5301da177e4SLinus Torvalds { 5311da177e4SLinus Torvalds s32 win = tp->rcv_wup + tp->rcv_wnd - tp->rcv_nxt; 5321da177e4SLinus Torvalds 5331da177e4SLinus Torvalds if (win < 0) 5341da177e4SLinus Torvalds win = 0; 5351da177e4SLinus Torvalds return (u32) win; 5361da177e4SLinus Torvalds } 5371da177e4SLinus Torvalds 5381da177e4SLinus Torvalds /* Choose a new window, without checks for shrinking, and without 5391da177e4SLinus Torvalds * scaling applied to the result. The caller does these things 5401da177e4SLinus Torvalds * if necessary. This is a "raw" window selection. 5411da177e4SLinus Torvalds */ 5421da177e4SLinus Torvalds extern u32 __tcp_select_window(struct sock *sk); 5431da177e4SLinus Torvalds 5441da177e4SLinus Torvalds /* TCP timestamps are only 32-bits, this causes a slight 5451da177e4SLinus Torvalds * complication on 64-bit systems since we store a snapshot 54631f34269SStephen Hemminger * of jiffies in the buffer control blocks below. We decided 54731f34269SStephen Hemminger * to use only the low 32-bits of jiffies and hide the ugly 5481da177e4SLinus Torvalds * casts with the following macro. 5491da177e4SLinus Torvalds */ 5501da177e4SLinus Torvalds #define tcp_time_stamp ((__u32)(jiffies)) 5511da177e4SLinus Torvalds 552caa20d9aSStephen Hemminger /* This is what the send packet queuing engine uses to pass 5531da177e4SLinus Torvalds * TCP per-packet control information to the transmission 5541da177e4SLinus Torvalds * code. We also store the host-order sequence numbers in 5551da177e4SLinus Torvalds * here too. This is 36 bytes on 32-bit architectures, 5561da177e4SLinus Torvalds * 40 bytes on 64-bit machines, if this grows please adjust 5571da177e4SLinus Torvalds * skbuff.h:skbuff->cb[xxx] size appropriately. 5581da177e4SLinus Torvalds */ 5591da177e4SLinus Torvalds struct tcp_skb_cb { 5601da177e4SLinus Torvalds union { 5611da177e4SLinus Torvalds struct inet_skb_parm h4; 5621da177e4SLinus Torvalds #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE) 5631da177e4SLinus Torvalds struct inet6_skb_parm h6; 5641da177e4SLinus Torvalds #endif 5651da177e4SLinus Torvalds } header; /* For incoming frames */ 5661da177e4SLinus Torvalds __u32 seq; /* Starting sequence number */ 5671da177e4SLinus Torvalds __u32 end_seq; /* SEQ + FIN + SYN + datalen */ 5681da177e4SLinus Torvalds __u32 when; /* used to compute rtt's */ 5691da177e4SLinus Torvalds __u8 flags; /* TCP header flags. */ 5701da177e4SLinus Torvalds 5711da177e4SLinus Torvalds /* NOTE: These must match up to the flags byte in a 5721da177e4SLinus Torvalds * real TCP header. 5731da177e4SLinus Torvalds */ 5741da177e4SLinus Torvalds #define TCPCB_FLAG_FIN 0x01 5751da177e4SLinus Torvalds #define TCPCB_FLAG_SYN 0x02 5761da177e4SLinus Torvalds #define TCPCB_FLAG_RST 0x04 5771da177e4SLinus Torvalds #define TCPCB_FLAG_PSH 0x08 5781da177e4SLinus Torvalds #define TCPCB_FLAG_ACK 0x10 5791da177e4SLinus Torvalds #define TCPCB_FLAG_URG 0x20 5801da177e4SLinus Torvalds #define TCPCB_FLAG_ECE 0x40 5811da177e4SLinus Torvalds #define TCPCB_FLAG_CWR 0x80 5821da177e4SLinus Torvalds 5831da177e4SLinus Torvalds __u8 sacked; /* State flags for SACK/FACK. */ 5841da177e4SLinus Torvalds #define TCPCB_SACKED_ACKED 0x01 /* SKB ACK'd by a SACK block */ 5851da177e4SLinus Torvalds #define TCPCB_SACKED_RETRANS 0x02 /* SKB retransmitted */ 5861da177e4SLinus Torvalds #define TCPCB_LOST 0x04 /* SKB is lost */ 5871da177e4SLinus Torvalds #define TCPCB_TAGBITS 0x07 /* All tag bits */ 5881da177e4SLinus Torvalds 5891da177e4SLinus Torvalds #define TCPCB_EVER_RETRANS 0x80 /* Ever retransmitted frame */ 5901da177e4SLinus Torvalds #define TCPCB_RETRANS (TCPCB_SACKED_RETRANS|TCPCB_EVER_RETRANS) 5911da177e4SLinus Torvalds 5921da177e4SLinus Torvalds __u16 urg_ptr; /* Valid w/URG flags is set. */ 5931da177e4SLinus Torvalds __u32 ack_seq; /* Sequence number ACK'd */ 5941da177e4SLinus Torvalds }; 5951da177e4SLinus Torvalds 5961da177e4SLinus Torvalds #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0])) 5971da177e4SLinus Torvalds 5981da177e4SLinus Torvalds /* Due to TSO, an SKB can be composed of multiple actual 5991da177e4SLinus Torvalds * packets. To keep these tracked properly, we use this. 6001da177e4SLinus Torvalds */ 6011da177e4SLinus Torvalds static inline int tcp_skb_pcount(const struct sk_buff *skb) 6021da177e4SLinus Torvalds { 6037967168cSHerbert Xu return skb_shinfo(skb)->gso_segs; 6041da177e4SLinus Torvalds } 6051da177e4SLinus Torvalds 6061da177e4SLinus Torvalds /* This is valid iff tcp_skb_pcount() > 1. */ 6071da177e4SLinus Torvalds static inline int tcp_skb_mss(const struct sk_buff *skb) 6081da177e4SLinus Torvalds { 6097967168cSHerbert Xu return skb_shinfo(skb)->gso_size; 6101da177e4SLinus Torvalds } 6111da177e4SLinus Torvalds 612af610b4cSIlpo Järvinen static inline void tcp_dec_pcount_approx_int(__u32 *count, const int decr) 6131da177e4SLinus Torvalds { 6141da177e4SLinus Torvalds if (*count) { 615af610b4cSIlpo Järvinen *count -= decr; 6161da177e4SLinus Torvalds if ((int)*count < 0) 6171da177e4SLinus Torvalds *count = 0; 6181da177e4SLinus Torvalds } 6191da177e4SLinus Torvalds } 6201da177e4SLinus Torvalds 621af610b4cSIlpo Järvinen static inline void tcp_dec_pcount_approx(__u32 *count, 622af610b4cSIlpo Järvinen const struct sk_buff *skb) 623af610b4cSIlpo Järvinen { 624af610b4cSIlpo Järvinen tcp_dec_pcount_approx_int(count, tcp_skb_pcount(skb)); 625af610b4cSIlpo Järvinen } 626af610b4cSIlpo Järvinen 627317a76f9SStephen Hemminger /* Events passed to congestion control interface */ 628317a76f9SStephen Hemminger enum tcp_ca_event { 629317a76f9SStephen Hemminger CA_EVENT_TX_START, /* first transmit when no packets in flight */ 630317a76f9SStephen Hemminger CA_EVENT_CWND_RESTART, /* congestion window restart */ 631317a76f9SStephen Hemminger CA_EVENT_COMPLETE_CWR, /* end of congestion recovery */ 632317a76f9SStephen Hemminger CA_EVENT_FRTO, /* fast recovery timeout */ 633317a76f9SStephen Hemminger CA_EVENT_LOSS, /* loss timeout */ 634317a76f9SStephen Hemminger CA_EVENT_FAST_ACK, /* in sequence ack */ 635317a76f9SStephen Hemminger CA_EVENT_SLOW_ACK, /* other ack */ 636317a76f9SStephen Hemminger }; 637317a76f9SStephen Hemminger 638317a76f9SStephen Hemminger /* 639317a76f9SStephen Hemminger * Interface for adding new TCP congestion control handlers 640317a76f9SStephen Hemminger */ 641317a76f9SStephen Hemminger #define TCP_CA_NAME_MAX 16 6423ff825b2SStephen Hemminger #define TCP_CA_MAX 128 6433ff825b2SStephen Hemminger #define TCP_CA_BUF_MAX (TCP_CA_NAME_MAX*TCP_CA_MAX) 6443ff825b2SStephen Hemminger 645164891aaSStephen Hemminger #define TCP_CONG_NON_RESTRICTED 0x1 646164891aaSStephen Hemminger #define TCP_CONG_RTT_STAMP 0x2 647164891aaSStephen Hemminger 648317a76f9SStephen Hemminger struct tcp_congestion_ops { 649317a76f9SStephen Hemminger struct list_head list; 650164891aaSStephen Hemminger unsigned long flags; 651317a76f9SStephen Hemminger 652317a76f9SStephen Hemminger /* initialize private data (optional) */ 6536687e988SArnaldo Carvalho de Melo void (*init)(struct sock *sk); 654317a76f9SStephen Hemminger /* cleanup private data (optional) */ 6556687e988SArnaldo Carvalho de Melo void (*release)(struct sock *sk); 656317a76f9SStephen Hemminger 657317a76f9SStephen Hemminger /* return slow start threshold (required) */ 6586687e988SArnaldo Carvalho de Melo u32 (*ssthresh)(struct sock *sk); 659317a76f9SStephen Hemminger /* lower bound for congestion window (optional) */ 66072dc5b92SStephen Hemminger u32 (*min_cwnd)(const struct sock *sk); 661317a76f9SStephen Hemminger /* do new cwnd calculation (required) */ 662c3a05c60SIlpo Järvinen void (*cong_avoid)(struct sock *sk, u32 ack, u32 in_flight); 663317a76f9SStephen Hemminger /* call before changing ca_state (optional) */ 6646687e988SArnaldo Carvalho de Melo void (*set_state)(struct sock *sk, u8 new_state); 665317a76f9SStephen Hemminger /* call when cwnd event occurs (optional) */ 6666687e988SArnaldo Carvalho de Melo void (*cwnd_event)(struct sock *sk, enum tcp_ca_event ev); 667317a76f9SStephen Hemminger /* new value of cwnd after loss (optional) */ 6686687e988SArnaldo Carvalho de Melo u32 (*undo_cwnd)(struct sock *sk); 669317a76f9SStephen Hemminger /* hook for packet ack accounting (optional) */ 67030cfd0baSStephen Hemminger void (*pkts_acked)(struct sock *sk, u32 num_acked, s32 rtt_us); 67173c1f4a0SArnaldo Carvalho de Melo /* get info for inet_diag (optional) */ 6726687e988SArnaldo Carvalho de Melo void (*get_info)(struct sock *sk, u32 ext, struct sk_buff *skb); 673317a76f9SStephen Hemminger 674317a76f9SStephen Hemminger char name[TCP_CA_NAME_MAX]; 675317a76f9SStephen Hemminger struct module *owner; 676317a76f9SStephen Hemminger }; 677317a76f9SStephen Hemminger 678317a76f9SStephen Hemminger extern int tcp_register_congestion_control(struct tcp_congestion_ops *type); 679317a76f9SStephen Hemminger extern void tcp_unregister_congestion_control(struct tcp_congestion_ops *type); 680317a76f9SStephen Hemminger 6816687e988SArnaldo Carvalho de Melo extern void tcp_init_congestion_control(struct sock *sk); 6826687e988SArnaldo Carvalho de Melo extern void tcp_cleanup_congestion_control(struct sock *sk); 683317a76f9SStephen Hemminger extern int tcp_set_default_congestion_control(const char *name); 684317a76f9SStephen Hemminger extern void tcp_get_default_congestion_control(char *name); 6853ff825b2SStephen Hemminger extern void tcp_get_available_congestion_control(char *buf, size_t len); 686ce7bc3bfSStephen Hemminger extern void tcp_get_allowed_congestion_control(char *buf, size_t len); 687ce7bc3bfSStephen Hemminger extern int tcp_set_allowed_congestion_control(char *allowed); 6886687e988SArnaldo Carvalho de Melo extern int tcp_set_congestion_control(struct sock *sk, const char *name); 68940efc6faSStephen Hemminger extern void tcp_slow_start(struct tcp_sock *tp); 690317a76f9SStephen Hemminger 6915f8ef48dSStephen Hemminger extern struct tcp_congestion_ops tcp_init_congestion_ops; 6926687e988SArnaldo Carvalho de Melo extern u32 tcp_reno_ssthresh(struct sock *sk); 693c3a05c60SIlpo Järvinen extern void tcp_reno_cong_avoid(struct sock *sk, u32 ack, u32 in_flight); 69472dc5b92SStephen Hemminger extern u32 tcp_reno_min_cwnd(const struct sock *sk); 695a8acfbacSDavid S. Miller extern struct tcp_congestion_ops tcp_reno; 696317a76f9SStephen Hemminger 6976687e988SArnaldo Carvalho de Melo static inline void tcp_set_ca_state(struct sock *sk, const u8 ca_state) 698317a76f9SStephen Hemminger { 6996687e988SArnaldo Carvalho de Melo struct inet_connection_sock *icsk = inet_csk(sk); 7006687e988SArnaldo Carvalho de Melo 7016687e988SArnaldo Carvalho de Melo if (icsk->icsk_ca_ops->set_state) 7026687e988SArnaldo Carvalho de Melo icsk->icsk_ca_ops->set_state(sk, ca_state); 7036687e988SArnaldo Carvalho de Melo icsk->icsk_ca_state = ca_state; 704317a76f9SStephen Hemminger } 705317a76f9SStephen Hemminger 7066687e988SArnaldo Carvalho de Melo static inline void tcp_ca_event(struct sock *sk, const enum tcp_ca_event event) 707317a76f9SStephen Hemminger { 7086687e988SArnaldo Carvalho de Melo const struct inet_connection_sock *icsk = inet_csk(sk); 7096687e988SArnaldo Carvalho de Melo 7106687e988SArnaldo Carvalho de Melo if (icsk->icsk_ca_ops->cwnd_event) 7116687e988SArnaldo Carvalho de Melo icsk->icsk_ca_ops->cwnd_event(sk, event); 712317a76f9SStephen Hemminger } 713317a76f9SStephen Hemminger 714e60402d0SIlpo Järvinen /* These functions determine how the current flow behaves in respect of SACK 715e60402d0SIlpo Järvinen * handling. SACK is negotiated with the peer, and therefore it can vary 716e60402d0SIlpo Järvinen * between different flows. 717e60402d0SIlpo Järvinen * 718e60402d0SIlpo Järvinen * tcp_is_sack - SACK enabled 719e60402d0SIlpo Järvinen * tcp_is_reno - No SACK 720e60402d0SIlpo Järvinen * tcp_is_fack - FACK enabled, implies SACK enabled 721e60402d0SIlpo Järvinen */ 722e60402d0SIlpo Järvinen static inline int tcp_is_sack(const struct tcp_sock *tp) 723e60402d0SIlpo Järvinen { 724e60402d0SIlpo Järvinen return tp->rx_opt.sack_ok; 725e60402d0SIlpo Järvinen } 726e60402d0SIlpo Järvinen 727e60402d0SIlpo Järvinen static inline int tcp_is_reno(const struct tcp_sock *tp) 728e60402d0SIlpo Järvinen { 729e60402d0SIlpo Järvinen return !tcp_is_sack(tp); 730e60402d0SIlpo Järvinen } 731e60402d0SIlpo Järvinen 732e60402d0SIlpo Järvinen static inline int tcp_is_fack(const struct tcp_sock *tp) 733e60402d0SIlpo Järvinen { 734e60402d0SIlpo Järvinen return tp->rx_opt.sack_ok & 2; 735e60402d0SIlpo Järvinen } 736e60402d0SIlpo Järvinen 737e60402d0SIlpo Järvinen static inline void tcp_enable_fack(struct tcp_sock *tp) 738e60402d0SIlpo Järvinen { 739e60402d0SIlpo Järvinen tp->rx_opt.sack_ok |= 2; 740e60402d0SIlpo Järvinen } 741e60402d0SIlpo Järvinen 74283ae4088SIlpo Järvinen static inline unsigned int tcp_left_out(const struct tcp_sock *tp) 74383ae4088SIlpo Järvinen { 74483ae4088SIlpo Järvinen return tp->sacked_out + tp->lost_out; 74583ae4088SIlpo Järvinen } 74683ae4088SIlpo Järvinen 7471da177e4SLinus Torvalds /* This determines how many packets are "in the network" to the best 7481da177e4SLinus Torvalds * of our knowledge. In many cases it is conservative, but where 7491da177e4SLinus Torvalds * detailed information is available from the receiver (via SACK 7501da177e4SLinus Torvalds * blocks etc.) we can make more aggressive calculations. 7511da177e4SLinus Torvalds * 7521da177e4SLinus Torvalds * Use this for decisions involving congestion control, use just 7531da177e4SLinus Torvalds * tp->packets_out to determine if the send queue is empty or not. 7541da177e4SLinus Torvalds * 7551da177e4SLinus Torvalds * Read this equation as: 7561da177e4SLinus Torvalds * 7571da177e4SLinus Torvalds * "Packets sent once on transmission queue" MINUS 7581da177e4SLinus Torvalds * "Packets left network, but not honestly ACKed yet" PLUS 7591da177e4SLinus Torvalds * "Packets fast retransmitted" 7601da177e4SLinus Torvalds */ 76140efc6faSStephen Hemminger static inline unsigned int tcp_packets_in_flight(const struct tcp_sock *tp) 7621da177e4SLinus Torvalds { 76383ae4088SIlpo Järvinen return tp->packets_out - tcp_left_out(tp) + tp->retrans_out; 7641da177e4SLinus Torvalds } 7651da177e4SLinus Torvalds 7661da177e4SLinus Torvalds /* If cwnd > ssthresh, we may raise ssthresh to be half-way to cwnd. 7671da177e4SLinus Torvalds * The exception is rate halving phase, when cwnd is decreasing towards 7681da177e4SLinus Torvalds * ssthresh. 7691da177e4SLinus Torvalds */ 7706687e988SArnaldo Carvalho de Melo static inline __u32 tcp_current_ssthresh(const struct sock *sk) 7711da177e4SLinus Torvalds { 7726687e988SArnaldo Carvalho de Melo const struct tcp_sock *tp = tcp_sk(sk); 7736687e988SArnaldo Carvalho de Melo if ((1 << inet_csk(sk)->icsk_ca_state) & (TCPF_CA_CWR | TCPF_CA_Recovery)) 7741da177e4SLinus Torvalds return tp->snd_ssthresh; 7751da177e4SLinus Torvalds else 7761da177e4SLinus Torvalds return max(tp->snd_ssthresh, 7771da177e4SLinus Torvalds ((tp->snd_cwnd >> 1) + 7781da177e4SLinus Torvalds (tp->snd_cwnd >> 2))); 7791da177e4SLinus Torvalds } 7801da177e4SLinus Torvalds 781b9c4595bSIlpo Järvinen /* Use define here intentionally to get WARN_ON location shown at the caller */ 782b9c4595bSIlpo Järvinen #define tcp_verify_left_out(tp) WARN_ON(tcp_left_out(tp) > tp->packets_out) 7831da177e4SLinus Torvalds 7843cfe3baaSIlpo Järvinen extern void tcp_enter_cwr(struct sock *sk, const int set_ssthresh); 7851da177e4SLinus Torvalds extern __u32 tcp_init_cwnd(struct tcp_sock *tp, struct dst_entry *dst); 7861da177e4SLinus Torvalds 7871da177e4SLinus Torvalds /* Slow start with delack produces 3 packets of burst, so that 7881da177e4SLinus Torvalds * it is safe "de facto". 7891da177e4SLinus Torvalds */ 7901da177e4SLinus Torvalds static __inline__ __u32 tcp_max_burst(const struct tcp_sock *tp) 7911da177e4SLinus Torvalds { 7921da177e4SLinus Torvalds return 3; 7931da177e4SLinus Torvalds } 7941da177e4SLinus Torvalds 79590840defSIlpo Järvinen /* Returns end sequence number of the receiver's advertised window */ 79690840defSIlpo Järvinen static inline u32 tcp_wnd_end(const struct tcp_sock *tp) 79790840defSIlpo Järvinen { 79890840defSIlpo Järvinen return tp->snd_una + tp->snd_wnd; 79990840defSIlpo Järvinen } 800cea14e0eSIlpo Järvinen extern int tcp_is_cwnd_limited(const struct sock *sk, u32 in_flight); 801f4805edeSStephen Hemminger 802c1bd24b7SChuck Lever static inline void tcp_minshall_update(struct tcp_sock *tp, unsigned int mss, 8031da177e4SLinus Torvalds const struct sk_buff *skb) 8041da177e4SLinus Torvalds { 8051da177e4SLinus Torvalds if (skb->len < mss) 8061da177e4SLinus Torvalds tp->snd_sml = TCP_SKB_CB(skb)->end_seq; 8071da177e4SLinus Torvalds } 8081da177e4SLinus Torvalds 8099e412ba7SIlpo Järvinen static inline void tcp_check_probe_timer(struct sock *sk) 8101da177e4SLinus Torvalds { 8119e412ba7SIlpo Järvinen struct tcp_sock *tp = tcp_sk(sk); 812463c84b9SArnaldo Carvalho de Melo const struct inet_connection_sock *icsk = inet_csk(sk); 8139e412ba7SIlpo Järvinen 814463c84b9SArnaldo Carvalho de Melo if (!tp->packets_out && !icsk->icsk_pending) 8153f421baaSArnaldo Carvalho de Melo inet_csk_reset_xmit_timer(sk, ICSK_TIME_PROBE0, 8163f421baaSArnaldo Carvalho de Melo icsk->icsk_rto, TCP_RTO_MAX); 8171da177e4SLinus Torvalds } 8181da177e4SLinus Torvalds 8199e412ba7SIlpo Järvinen static inline void tcp_push_pending_frames(struct sock *sk) 8201da177e4SLinus Torvalds { 8219e412ba7SIlpo Järvinen struct tcp_sock *tp = tcp_sk(sk); 8229e412ba7SIlpo Järvinen 8239e412ba7SIlpo Järvinen __tcp_push_pending_frames(sk, tcp_current_mss(sk, 1), tp->nonagle); 8241da177e4SLinus Torvalds } 8251da177e4SLinus Torvalds 82640efc6faSStephen Hemminger static inline void tcp_init_wl(struct tcp_sock *tp, u32 ack, u32 seq) 8271da177e4SLinus Torvalds { 8281da177e4SLinus Torvalds tp->snd_wl1 = seq; 8291da177e4SLinus Torvalds } 8301da177e4SLinus Torvalds 83140efc6faSStephen Hemminger static inline void tcp_update_wl(struct tcp_sock *tp, u32 ack, u32 seq) 8321da177e4SLinus Torvalds { 8331da177e4SLinus Torvalds tp->snd_wl1 = seq; 8341da177e4SLinus Torvalds } 8351da177e4SLinus Torvalds 8361da177e4SLinus Torvalds /* 8371da177e4SLinus Torvalds * Calculate(/check) TCP checksum 8381da177e4SLinus Torvalds */ 839ba7808eaSFrederik Deweerdt static inline __sum16 tcp_v4_check(int len, __be32 saddr, 840ba7808eaSFrederik Deweerdt __be32 daddr, __wsum base) 8411da177e4SLinus Torvalds { 8421da177e4SLinus Torvalds return csum_tcpudp_magic(saddr,daddr,len,IPPROTO_TCP,base); 8431da177e4SLinus Torvalds } 8441da177e4SLinus Torvalds 845b51655b9SAl Viro static inline __sum16 __tcp_checksum_complete(struct sk_buff *skb) 8461da177e4SLinus Torvalds { 847fb286bb2SHerbert Xu return __skb_checksum_complete(skb); 8481da177e4SLinus Torvalds } 8491da177e4SLinus Torvalds 85040efc6faSStephen Hemminger static inline int tcp_checksum_complete(struct sk_buff *skb) 8511da177e4SLinus Torvalds { 85260476372SHerbert Xu return !skb_csum_unnecessary(skb) && 8531da177e4SLinus Torvalds __tcp_checksum_complete(skb); 8541da177e4SLinus Torvalds } 8551da177e4SLinus Torvalds 8561da177e4SLinus Torvalds /* Prequeue for VJ style copy to user, combined with checksumming. */ 8571da177e4SLinus Torvalds 85840efc6faSStephen Hemminger static inline void tcp_prequeue_init(struct tcp_sock *tp) 8591da177e4SLinus Torvalds { 8601da177e4SLinus Torvalds tp->ucopy.task = NULL; 8611da177e4SLinus Torvalds tp->ucopy.len = 0; 8621da177e4SLinus Torvalds tp->ucopy.memory = 0; 8631da177e4SLinus Torvalds skb_queue_head_init(&tp->ucopy.prequeue); 86497fc2f08SChris Leech #ifdef CONFIG_NET_DMA 86597fc2f08SChris Leech tp->ucopy.dma_chan = NULL; 86697fc2f08SChris Leech tp->ucopy.wakeup = 0; 86797fc2f08SChris Leech tp->ucopy.pinned_list = NULL; 86897fc2f08SChris Leech tp->ucopy.dma_cookie = 0; 86997fc2f08SChris Leech #endif 8701da177e4SLinus Torvalds } 8711da177e4SLinus Torvalds 8721da177e4SLinus Torvalds /* Packet is added to VJ-style prequeue for processing in process 8731da177e4SLinus Torvalds * context, if a reader task is waiting. Apparently, this exciting 8741da177e4SLinus Torvalds * idea (VJ's mail "Re: query about TCP header on tcp-ip" of 07 Sep 93) 8751da177e4SLinus Torvalds * failed somewhere. Latency? Burstiness? Well, at least now we will 8761da177e4SLinus Torvalds * see, why it failed. 8)8) --ANK 8771da177e4SLinus Torvalds * 8781da177e4SLinus Torvalds * NOTE: is this not too big to inline? 8791da177e4SLinus Torvalds */ 88040efc6faSStephen Hemminger static inline int tcp_prequeue(struct sock *sk, struct sk_buff *skb) 8811da177e4SLinus Torvalds { 8821da177e4SLinus Torvalds struct tcp_sock *tp = tcp_sk(sk); 8831da177e4SLinus Torvalds 8841da177e4SLinus Torvalds if (!sysctl_tcp_low_latency && tp->ucopy.task) { 8851da177e4SLinus Torvalds __skb_queue_tail(&tp->ucopy.prequeue, skb); 8861da177e4SLinus Torvalds tp->ucopy.memory += skb->truesize; 8871da177e4SLinus Torvalds if (tp->ucopy.memory > sk->sk_rcvbuf) { 8881da177e4SLinus Torvalds struct sk_buff *skb1; 8891da177e4SLinus Torvalds 8901da177e4SLinus Torvalds BUG_ON(sock_owned_by_user(sk)); 8911da177e4SLinus Torvalds 8921da177e4SLinus Torvalds while ((skb1 = __skb_dequeue(&tp->ucopy.prequeue)) != NULL) { 8931da177e4SLinus Torvalds sk->sk_backlog_rcv(sk, skb1); 8941da177e4SLinus Torvalds NET_INC_STATS_BH(LINUX_MIB_TCPPREQUEUEDROPPED); 8951da177e4SLinus Torvalds } 8961da177e4SLinus Torvalds 8971da177e4SLinus Torvalds tp->ucopy.memory = 0; 8981da177e4SLinus Torvalds } else if (skb_queue_len(&tp->ucopy.prequeue) == 1) { 8991da177e4SLinus Torvalds wake_up_interruptible(sk->sk_sleep); 900463c84b9SArnaldo Carvalho de Melo if (!inet_csk_ack_scheduled(sk)) 901463c84b9SArnaldo Carvalho de Melo inet_csk_reset_xmit_timer(sk, ICSK_TIME_DACK, 9023f421baaSArnaldo Carvalho de Melo (3 * TCP_RTO_MIN) / 4, 9033f421baaSArnaldo Carvalho de Melo TCP_RTO_MAX); 9041da177e4SLinus Torvalds } 9051da177e4SLinus Torvalds return 1; 9061da177e4SLinus Torvalds } 9071da177e4SLinus Torvalds return 0; 9081da177e4SLinus Torvalds } 9091da177e4SLinus Torvalds 9101da177e4SLinus Torvalds 9111da177e4SLinus Torvalds #undef STATE_TRACE 9121da177e4SLinus Torvalds 9131da177e4SLinus Torvalds #ifdef STATE_TRACE 9141da177e4SLinus Torvalds static const char *statename[]={ 9151da177e4SLinus Torvalds "Unused","Established","Syn Sent","Syn Recv", 9161da177e4SLinus Torvalds "Fin Wait 1","Fin Wait 2","Time Wait", "Close", 9171da177e4SLinus Torvalds "Close Wait","Last ACK","Listen","Closing" 9181da177e4SLinus Torvalds }; 9191da177e4SLinus Torvalds #endif 920490d5046SIlpo Järvinen extern void tcp_set_state(struct sock *sk, int state); 9211da177e4SLinus Torvalds 9224ac02babSAndi Kleen extern void tcp_done(struct sock *sk); 9231da177e4SLinus Torvalds 92440efc6faSStephen Hemminger static inline void tcp_sack_reset(struct tcp_options_received *rx_opt) 9251da177e4SLinus Torvalds { 9261da177e4SLinus Torvalds rx_opt->dsack = 0; 9271da177e4SLinus Torvalds rx_opt->eff_sacks = 0; 9281da177e4SLinus Torvalds rx_opt->num_sacks = 0; 9291da177e4SLinus Torvalds } 9301da177e4SLinus Torvalds 9311da177e4SLinus Torvalds /* Determine a window scaling and initial window to offer. */ 9321da177e4SLinus Torvalds extern void tcp_select_initial_window(int __space, __u32 mss, 9331da177e4SLinus Torvalds __u32 *rcv_wnd, __u32 *window_clamp, 9341da177e4SLinus Torvalds int wscale_ok, __u8 *rcv_wscale); 9351da177e4SLinus Torvalds 9361da177e4SLinus Torvalds static inline int tcp_win_from_space(int space) 9371da177e4SLinus Torvalds { 9381da177e4SLinus Torvalds return sysctl_tcp_adv_win_scale<=0 ? 9391da177e4SLinus Torvalds (space>>(-sysctl_tcp_adv_win_scale)) : 9401da177e4SLinus Torvalds space - (space>>sysctl_tcp_adv_win_scale); 9411da177e4SLinus Torvalds } 9421da177e4SLinus Torvalds 9431da177e4SLinus Torvalds /* Note: caller must be prepared to deal with negative returns */ 9441da177e4SLinus Torvalds static inline int tcp_space(const struct sock *sk) 9451da177e4SLinus Torvalds { 9461da177e4SLinus Torvalds return tcp_win_from_space(sk->sk_rcvbuf - 9471da177e4SLinus Torvalds atomic_read(&sk->sk_rmem_alloc)); 9481da177e4SLinus Torvalds } 9491da177e4SLinus Torvalds 9501da177e4SLinus Torvalds static inline int tcp_full_space(const struct sock *sk) 9511da177e4SLinus Torvalds { 9521da177e4SLinus Torvalds return tcp_win_from_space(sk->sk_rcvbuf); 9531da177e4SLinus Torvalds } 9541da177e4SLinus Torvalds 95540efc6faSStephen Hemminger static inline void tcp_openreq_init(struct request_sock *req, 9561da177e4SLinus Torvalds struct tcp_options_received *rx_opt, 9571da177e4SLinus Torvalds struct sk_buff *skb) 9581da177e4SLinus Torvalds { 9592e6599cbSArnaldo Carvalho de Melo struct inet_request_sock *ireq = inet_rsk(req); 9602e6599cbSArnaldo Carvalho de Melo 9611da177e4SLinus Torvalds req->rcv_wnd = 0; /* So that tcp_send_synack() knows! */ 962*4dfc2817SFlorian Westphal req->cookie_ts = 0; 9632e6599cbSArnaldo Carvalho de Melo tcp_rsk(req)->rcv_isn = TCP_SKB_CB(skb)->seq; 9641da177e4SLinus Torvalds req->mss = rx_opt->mss_clamp; 9651da177e4SLinus Torvalds req->ts_recent = rx_opt->saw_tstamp ? rx_opt->rcv_tsval : 0; 9662e6599cbSArnaldo Carvalho de Melo ireq->tstamp_ok = rx_opt->tstamp_ok; 9672e6599cbSArnaldo Carvalho de Melo ireq->sack_ok = rx_opt->sack_ok; 9682e6599cbSArnaldo Carvalho de Melo ireq->snd_wscale = rx_opt->snd_wscale; 9692e6599cbSArnaldo Carvalho de Melo ireq->wscale_ok = rx_opt->wscale_ok; 9702e6599cbSArnaldo Carvalho de Melo ireq->acked = 0; 9712e6599cbSArnaldo Carvalho de Melo ireq->ecn_ok = 0; 972aa8223c7SArnaldo Carvalho de Melo ireq->rmt_port = tcp_hdr(skb)->source; 9731da177e4SLinus Torvalds } 9741da177e4SLinus Torvalds 9751da177e4SLinus Torvalds extern void tcp_enter_memory_pressure(void); 9761da177e4SLinus Torvalds 9771da177e4SLinus Torvalds static inline int keepalive_intvl_when(const struct tcp_sock *tp) 9781da177e4SLinus Torvalds { 9791da177e4SLinus Torvalds return tp->keepalive_intvl ? : sysctl_tcp_keepalive_intvl; 9801da177e4SLinus Torvalds } 9811da177e4SLinus Torvalds 9821da177e4SLinus Torvalds static inline int keepalive_time_when(const struct tcp_sock *tp) 9831da177e4SLinus Torvalds { 9841da177e4SLinus Torvalds return tp->keepalive_time ? : sysctl_tcp_keepalive_time; 9851da177e4SLinus Torvalds } 9861da177e4SLinus Torvalds 987463c84b9SArnaldo Carvalho de Melo static inline int tcp_fin_time(const struct sock *sk) 9881da177e4SLinus Torvalds { 989463c84b9SArnaldo Carvalho de Melo int fin_timeout = tcp_sk(sk)->linger2 ? : sysctl_tcp_fin_timeout; 990463c84b9SArnaldo Carvalho de Melo const int rto = inet_csk(sk)->icsk_rto; 9911da177e4SLinus Torvalds 992463c84b9SArnaldo Carvalho de Melo if (fin_timeout < (rto << 2) - (rto >> 1)) 993463c84b9SArnaldo Carvalho de Melo fin_timeout = (rto << 2) - (rto >> 1); 9941da177e4SLinus Torvalds 9951da177e4SLinus Torvalds return fin_timeout; 9961da177e4SLinus Torvalds } 9971da177e4SLinus Torvalds 9981da177e4SLinus Torvalds static inline int tcp_paws_check(const struct tcp_options_received *rx_opt, int rst) 9991da177e4SLinus Torvalds { 10001da177e4SLinus Torvalds if ((s32)(rx_opt->rcv_tsval - rx_opt->ts_recent) >= 0) 10011da177e4SLinus Torvalds return 0; 10029d729f72SJames Morris if (get_seconds() >= rx_opt->ts_recent_stamp + TCP_PAWS_24DAYS) 10031da177e4SLinus Torvalds return 0; 10041da177e4SLinus Torvalds 10051da177e4SLinus Torvalds /* RST segments are not recommended to carry timestamp, 10061da177e4SLinus Torvalds and, if they do, it is recommended to ignore PAWS because 10071da177e4SLinus Torvalds "their cleanup function should take precedence over timestamps." 10081da177e4SLinus Torvalds Certainly, it is mistake. It is necessary to understand the reasons 10091da177e4SLinus Torvalds of this constraint to relax it: if peer reboots, clock may go 10101da177e4SLinus Torvalds out-of-sync and half-open connections will not be reset. 10111da177e4SLinus Torvalds Actually, the problem would be not existing if all 10121da177e4SLinus Torvalds the implementations followed draft about maintaining clock 10131da177e4SLinus Torvalds via reboots. Linux-2.2 DOES NOT! 10141da177e4SLinus Torvalds 10151da177e4SLinus Torvalds However, we can relax time bounds for RST segments to MSL. 10161da177e4SLinus Torvalds */ 10179d729f72SJames Morris if (rst && get_seconds() >= rx_opt->ts_recent_stamp + TCP_PAWS_MSL) 10181da177e4SLinus Torvalds return 0; 10191da177e4SLinus Torvalds return 1; 10201da177e4SLinus Torvalds } 10211da177e4SLinus Torvalds 10221da177e4SLinus Torvalds #define TCP_CHECK_TIMER(sk) do { } while (0) 10231da177e4SLinus Torvalds 10241da177e4SLinus Torvalds static inline void tcp_mib_init(void) 10251da177e4SLinus Torvalds { 10261da177e4SLinus Torvalds /* See RFC 2012 */ 10271da177e4SLinus Torvalds TCP_ADD_STATS_USER(TCP_MIB_RTOALGORITHM, 1); 10281da177e4SLinus Torvalds TCP_ADD_STATS_USER(TCP_MIB_RTOMIN, TCP_RTO_MIN*1000/HZ); 10291da177e4SLinus Torvalds TCP_ADD_STATS_USER(TCP_MIB_RTOMAX, TCP_RTO_MAX*1000/HZ); 10301da177e4SLinus Torvalds TCP_ADD_STATS_USER(TCP_MIB_MAXCONN, -1); 10311da177e4SLinus Torvalds } 10321da177e4SLinus Torvalds 10336a438bbeSStephen Hemminger /* from STCP */ 10340800f170SDavid S. Miller static inline void tcp_clear_retrans_hints_partial(struct tcp_sock *tp) 10350800f170SDavid S. Miller { 10366a438bbeSStephen Hemminger tp->lost_skb_hint = NULL; 10376a438bbeSStephen Hemminger tp->scoreboard_skb_hint = NULL; 10386a438bbeSStephen Hemminger tp->retransmit_skb_hint = NULL; 10396a438bbeSStephen Hemminger tp->forward_skb_hint = NULL; 1040b7689205SIlpo Järvinen } 1041b7689205SIlpo Järvinen 10420800f170SDavid S. Miller static inline void tcp_clear_all_retrans_hints(struct tcp_sock *tp) 10430800f170SDavid S. Miller { 1044b7689205SIlpo Järvinen tcp_clear_retrans_hints_partial(tp); 10456a438bbeSStephen Hemminger } 10466a438bbeSStephen Hemminger 1047cfb6eeb4SYOSHIFUJI Hideaki /* MD5 Signature */ 1048cfb6eeb4SYOSHIFUJI Hideaki struct crypto_hash; 1049cfb6eeb4SYOSHIFUJI Hideaki 1050cfb6eeb4SYOSHIFUJI Hideaki /* - key database */ 1051cfb6eeb4SYOSHIFUJI Hideaki struct tcp_md5sig_key { 1052cfb6eeb4SYOSHIFUJI Hideaki u8 *key; 1053cfb6eeb4SYOSHIFUJI Hideaki u8 keylen; 1054cfb6eeb4SYOSHIFUJI Hideaki }; 1055cfb6eeb4SYOSHIFUJI Hideaki 1056cfb6eeb4SYOSHIFUJI Hideaki struct tcp4_md5sig_key { 1057f8ab18d2SDavid S. Miller struct tcp_md5sig_key base; 1058cfb6eeb4SYOSHIFUJI Hideaki __be32 addr; 1059cfb6eeb4SYOSHIFUJI Hideaki }; 1060cfb6eeb4SYOSHIFUJI Hideaki 1061cfb6eeb4SYOSHIFUJI Hideaki struct tcp6_md5sig_key { 1062f8ab18d2SDavid S. Miller struct tcp_md5sig_key base; 1063cfb6eeb4SYOSHIFUJI Hideaki #if 0 1064cfb6eeb4SYOSHIFUJI Hideaki u32 scope_id; /* XXX */ 1065cfb6eeb4SYOSHIFUJI Hideaki #endif 1066cfb6eeb4SYOSHIFUJI Hideaki struct in6_addr addr; 1067cfb6eeb4SYOSHIFUJI Hideaki }; 1068cfb6eeb4SYOSHIFUJI Hideaki 1069cfb6eeb4SYOSHIFUJI Hideaki /* - sock block */ 1070cfb6eeb4SYOSHIFUJI Hideaki struct tcp_md5sig_info { 1071cfb6eeb4SYOSHIFUJI Hideaki struct tcp4_md5sig_key *keys4; 1072cfb6eeb4SYOSHIFUJI Hideaki #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 1073cfb6eeb4SYOSHIFUJI Hideaki struct tcp6_md5sig_key *keys6; 1074cfb6eeb4SYOSHIFUJI Hideaki u32 entries6; 1075cfb6eeb4SYOSHIFUJI Hideaki u32 alloced6; 1076cfb6eeb4SYOSHIFUJI Hideaki #endif 1077cfb6eeb4SYOSHIFUJI Hideaki u32 entries4; 1078cfb6eeb4SYOSHIFUJI Hideaki u32 alloced4; 1079cfb6eeb4SYOSHIFUJI Hideaki }; 1080cfb6eeb4SYOSHIFUJI Hideaki 1081cfb6eeb4SYOSHIFUJI Hideaki /* - pseudo header */ 1082cfb6eeb4SYOSHIFUJI Hideaki struct tcp4_pseudohdr { 1083cfb6eeb4SYOSHIFUJI Hideaki __be32 saddr; 1084cfb6eeb4SYOSHIFUJI Hideaki __be32 daddr; 1085cfb6eeb4SYOSHIFUJI Hideaki __u8 pad; 1086cfb6eeb4SYOSHIFUJI Hideaki __u8 protocol; 1087cfb6eeb4SYOSHIFUJI Hideaki __be16 len; 1088cfb6eeb4SYOSHIFUJI Hideaki }; 1089cfb6eeb4SYOSHIFUJI Hideaki 1090cfb6eeb4SYOSHIFUJI Hideaki struct tcp6_pseudohdr { 1091cfb6eeb4SYOSHIFUJI Hideaki struct in6_addr saddr; 1092cfb6eeb4SYOSHIFUJI Hideaki struct in6_addr daddr; 1093cfb6eeb4SYOSHIFUJI Hideaki __be32 len; 1094cfb6eeb4SYOSHIFUJI Hideaki __be32 protocol; /* including padding */ 1095cfb6eeb4SYOSHIFUJI Hideaki }; 1096cfb6eeb4SYOSHIFUJI Hideaki 1097cfb6eeb4SYOSHIFUJI Hideaki union tcp_md5sum_block { 1098cfb6eeb4SYOSHIFUJI Hideaki struct tcp4_pseudohdr ip4; 1099cfb6eeb4SYOSHIFUJI Hideaki #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 1100cfb6eeb4SYOSHIFUJI Hideaki struct tcp6_pseudohdr ip6; 1101cfb6eeb4SYOSHIFUJI Hideaki #endif 1102cfb6eeb4SYOSHIFUJI Hideaki }; 1103cfb6eeb4SYOSHIFUJI Hideaki 1104cfb6eeb4SYOSHIFUJI Hideaki /* - pool: digest algorithm, hash description and scratch buffer */ 1105cfb6eeb4SYOSHIFUJI Hideaki struct tcp_md5sig_pool { 1106cfb6eeb4SYOSHIFUJI Hideaki struct hash_desc md5_desc; 1107cfb6eeb4SYOSHIFUJI Hideaki union tcp_md5sum_block md5_blk; 1108cfb6eeb4SYOSHIFUJI Hideaki }; 1109cfb6eeb4SYOSHIFUJI Hideaki 1110cfb6eeb4SYOSHIFUJI Hideaki #define TCP_MD5SIG_MAXKEYS (~(u32)0) /* really?! */ 1111cfb6eeb4SYOSHIFUJI Hideaki 1112cfb6eeb4SYOSHIFUJI Hideaki /* - functions */ 1113cfb6eeb4SYOSHIFUJI Hideaki extern int tcp_v4_calc_md5_hash(char *md5_hash, 1114cfb6eeb4SYOSHIFUJI Hideaki struct tcp_md5sig_key *key, 1115cfb6eeb4SYOSHIFUJI Hideaki struct sock *sk, 1116cfb6eeb4SYOSHIFUJI Hideaki struct dst_entry *dst, 1117cfb6eeb4SYOSHIFUJI Hideaki struct request_sock *req, 1118cfb6eeb4SYOSHIFUJI Hideaki struct tcphdr *th, 11199cb5734eSYOSHIFUJI Hideaki int protocol, 11209cb5734eSYOSHIFUJI Hideaki unsigned int tcplen); 1121cfb6eeb4SYOSHIFUJI Hideaki extern struct tcp_md5sig_key *tcp_v4_md5_lookup(struct sock *sk, 1122cfb6eeb4SYOSHIFUJI Hideaki struct sock *addr_sk); 1123cfb6eeb4SYOSHIFUJI Hideaki 1124cfb6eeb4SYOSHIFUJI Hideaki extern int tcp_v4_md5_do_add(struct sock *sk, 1125cfb6eeb4SYOSHIFUJI Hideaki __be32 addr, 1126cfb6eeb4SYOSHIFUJI Hideaki u8 *newkey, 1127cfb6eeb4SYOSHIFUJI Hideaki u8 newkeylen); 1128cfb6eeb4SYOSHIFUJI Hideaki 1129cfb6eeb4SYOSHIFUJI Hideaki extern int tcp_v4_md5_do_del(struct sock *sk, 11308e5200f5SAl Viro __be32 addr); 1131cfb6eeb4SYOSHIFUJI Hideaki 1132cfb6eeb4SYOSHIFUJI Hideaki extern struct tcp_md5sig_pool **tcp_alloc_md5sig_pool(void); 1133cfb6eeb4SYOSHIFUJI Hideaki extern void tcp_free_md5sig_pool(void); 1134cfb6eeb4SYOSHIFUJI Hideaki 1135cfb6eeb4SYOSHIFUJI Hideaki extern struct tcp_md5sig_pool *__tcp_get_md5sig_pool(int cpu); 1136cfb6eeb4SYOSHIFUJI Hideaki extern void __tcp_put_md5sig_pool(void); 1137cfb6eeb4SYOSHIFUJI Hideaki 1138cfb6eeb4SYOSHIFUJI Hideaki static inline 1139cfb6eeb4SYOSHIFUJI Hideaki struct tcp_md5sig_pool *tcp_get_md5sig_pool(void) 1140cfb6eeb4SYOSHIFUJI Hideaki { 1141cfb6eeb4SYOSHIFUJI Hideaki int cpu = get_cpu(); 1142cfb6eeb4SYOSHIFUJI Hideaki struct tcp_md5sig_pool *ret = __tcp_get_md5sig_pool(cpu); 1143cfb6eeb4SYOSHIFUJI Hideaki if (!ret) 1144cfb6eeb4SYOSHIFUJI Hideaki put_cpu(); 1145cfb6eeb4SYOSHIFUJI Hideaki return ret; 1146cfb6eeb4SYOSHIFUJI Hideaki } 1147cfb6eeb4SYOSHIFUJI Hideaki 1148cfb6eeb4SYOSHIFUJI Hideaki static inline void tcp_put_md5sig_pool(void) 1149cfb6eeb4SYOSHIFUJI Hideaki { 1150cfb6eeb4SYOSHIFUJI Hideaki __tcp_put_md5sig_pool(); 1151cfb6eeb4SYOSHIFUJI Hideaki put_cpu(); 1152cfb6eeb4SYOSHIFUJI Hideaki } 1153cfb6eeb4SYOSHIFUJI Hideaki 1154fe067e8aSDavid S. Miller /* write queue abstraction */ 1155fe067e8aSDavid S. Miller static inline void tcp_write_queue_purge(struct sock *sk) 1156fe067e8aSDavid S. Miller { 1157fe067e8aSDavid S. Miller struct sk_buff *skb; 1158fe067e8aSDavid S. Miller 1159fe067e8aSDavid S. Miller while ((skb = __skb_dequeue(&sk->sk_write_queue)) != NULL) 11603ab224beSHideo Aoki sk_wmem_free_skb(sk, skb); 11613ab224beSHideo Aoki sk_mem_reclaim(sk); 1162fe067e8aSDavid S. Miller } 1163fe067e8aSDavid S. Miller 1164fe067e8aSDavid S. Miller static inline struct sk_buff *tcp_write_queue_head(struct sock *sk) 1165fe067e8aSDavid S. Miller { 1166fe067e8aSDavid S. Miller struct sk_buff *skb = sk->sk_write_queue.next; 1167fe067e8aSDavid S. Miller if (skb == (struct sk_buff *) &sk->sk_write_queue) 1168fe067e8aSDavid S. Miller return NULL; 1169fe067e8aSDavid S. Miller return skb; 1170fe067e8aSDavid S. Miller } 1171fe067e8aSDavid S. Miller 1172fe067e8aSDavid S. Miller static inline struct sk_buff *tcp_write_queue_tail(struct sock *sk) 1173fe067e8aSDavid S. Miller { 1174fe067e8aSDavid S. Miller struct sk_buff *skb = sk->sk_write_queue.prev; 1175fe067e8aSDavid S. Miller if (skb == (struct sk_buff *) &sk->sk_write_queue) 1176fe067e8aSDavid S. Miller return NULL; 1177fe067e8aSDavid S. Miller return skb; 1178fe067e8aSDavid S. Miller } 1179fe067e8aSDavid S. Miller 1180fe067e8aSDavid S. Miller static inline struct sk_buff *tcp_write_queue_next(struct sock *sk, struct sk_buff *skb) 1181fe067e8aSDavid S. Miller { 1182fe067e8aSDavid S. Miller return skb->next; 1183fe067e8aSDavid S. Miller } 1184fe067e8aSDavid S. Miller 1185fe067e8aSDavid S. Miller #define tcp_for_write_queue(skb, sk) \ 1186fe067e8aSDavid S. Miller for (skb = (sk)->sk_write_queue.next; \ 1187fe067e8aSDavid S. Miller (skb != (struct sk_buff *)&(sk)->sk_write_queue); \ 1188fe067e8aSDavid S. Miller skb = skb->next) 1189fe067e8aSDavid S. Miller 1190fe067e8aSDavid S. Miller #define tcp_for_write_queue_from(skb, sk) \ 1191fe067e8aSDavid S. Miller for (; (skb != (struct sk_buff *)&(sk)->sk_write_queue);\ 1192fe067e8aSDavid S. Miller skb = skb->next) 1193fe067e8aSDavid S. Miller 1194234b6860SIlpo Järvinen #define tcp_for_write_queue_from_safe(skb, tmp, sk) \ 1195234b6860SIlpo Järvinen for (tmp = skb->next; \ 1196234b6860SIlpo Järvinen (skb != (struct sk_buff *)&(sk)->sk_write_queue); \ 1197234b6860SIlpo Järvinen skb = tmp, tmp = skb->next) 1198234b6860SIlpo Järvinen 1199fe067e8aSDavid S. Miller static inline struct sk_buff *tcp_send_head(struct sock *sk) 1200fe067e8aSDavid S. Miller { 1201fe067e8aSDavid S. Miller return sk->sk_send_head; 1202fe067e8aSDavid S. Miller } 1203fe067e8aSDavid S. Miller 1204fe067e8aSDavid S. Miller static inline void tcp_advance_send_head(struct sock *sk, struct sk_buff *skb) 1205fe067e8aSDavid S. Miller { 1206fe067e8aSDavid S. Miller sk->sk_send_head = skb->next; 1207fe067e8aSDavid S. Miller if (sk->sk_send_head == (struct sk_buff *)&sk->sk_write_queue) 1208fe067e8aSDavid S. Miller sk->sk_send_head = NULL; 1209fe067e8aSDavid S. Miller } 1210fe067e8aSDavid S. Miller 1211fe067e8aSDavid S. Miller static inline void tcp_check_send_head(struct sock *sk, struct sk_buff *skb_unlinked) 1212fe067e8aSDavid S. Miller { 1213fe067e8aSDavid S. Miller if (sk->sk_send_head == skb_unlinked) 1214fe067e8aSDavid S. Miller sk->sk_send_head = NULL; 1215fe067e8aSDavid S. Miller } 1216fe067e8aSDavid S. Miller 1217fe067e8aSDavid S. Miller static inline void tcp_init_send_head(struct sock *sk) 1218fe067e8aSDavid S. Miller { 1219fe067e8aSDavid S. Miller sk->sk_send_head = NULL; 1220fe067e8aSDavid S. Miller } 1221fe067e8aSDavid S. Miller 1222fe067e8aSDavid S. Miller static inline void __tcp_add_write_queue_tail(struct sock *sk, struct sk_buff *skb) 1223fe067e8aSDavid S. Miller { 1224fe067e8aSDavid S. Miller __skb_queue_tail(&sk->sk_write_queue, skb); 1225fe067e8aSDavid S. Miller } 1226fe067e8aSDavid S. Miller 1227fe067e8aSDavid S. Miller static inline void tcp_add_write_queue_tail(struct sock *sk, struct sk_buff *skb) 1228fe067e8aSDavid S. Miller { 1229fe067e8aSDavid S. Miller __tcp_add_write_queue_tail(sk, skb); 1230fe067e8aSDavid S. Miller 1231fe067e8aSDavid S. Miller /* Queue it, remembering where we must start sending. */ 12326859d494SIlpo Järvinen if (sk->sk_send_head == NULL) { 1233fe067e8aSDavid S. Miller sk->sk_send_head = skb; 12346859d494SIlpo Järvinen 12356859d494SIlpo Järvinen if (tcp_sk(sk)->highest_sack == NULL) 12366859d494SIlpo Järvinen tcp_sk(sk)->highest_sack = skb; 12376859d494SIlpo Järvinen } 1238fe067e8aSDavid S. Miller } 1239fe067e8aSDavid S. Miller 1240fe067e8aSDavid S. Miller static inline void __tcp_add_write_queue_head(struct sock *sk, struct sk_buff *skb) 1241fe067e8aSDavid S. Miller { 1242fe067e8aSDavid S. Miller __skb_queue_head(&sk->sk_write_queue, skb); 1243fe067e8aSDavid S. Miller } 1244fe067e8aSDavid S. Miller 1245fe067e8aSDavid S. Miller /* Insert buff after skb on the write queue of sk. */ 1246fe067e8aSDavid S. Miller static inline void tcp_insert_write_queue_after(struct sk_buff *skb, 1247fe067e8aSDavid S. Miller struct sk_buff *buff, 1248fe067e8aSDavid S. Miller struct sock *sk) 1249fe067e8aSDavid S. Miller { 1250fe067e8aSDavid S. Miller __skb_append(skb, buff, &sk->sk_write_queue); 1251fe067e8aSDavid S. Miller } 1252fe067e8aSDavid S. Miller 1253fe067e8aSDavid S. Miller /* Insert skb between prev and next on the write queue of sk. */ 1254fe067e8aSDavid S. Miller static inline void tcp_insert_write_queue_before(struct sk_buff *new, 1255fe067e8aSDavid S. Miller struct sk_buff *skb, 1256fe067e8aSDavid S. Miller struct sock *sk) 1257fe067e8aSDavid S. Miller { 1258fe067e8aSDavid S. Miller __skb_insert(new, skb->prev, skb, &sk->sk_write_queue); 12596e421410SIlpo Järvinen 12606e421410SIlpo Järvinen if (sk->sk_send_head == skb) 12616e421410SIlpo Järvinen sk->sk_send_head = new; 1262fe067e8aSDavid S. Miller } 1263fe067e8aSDavid S. Miller 1264fe067e8aSDavid S. Miller static inline void tcp_unlink_write_queue(struct sk_buff *skb, struct sock *sk) 1265fe067e8aSDavid S. Miller { 1266fe067e8aSDavid S. Miller __skb_unlink(skb, &sk->sk_write_queue); 1267fe067e8aSDavid S. Miller } 1268fe067e8aSDavid S. Miller 1269fe067e8aSDavid S. Miller static inline int tcp_skb_is_last(const struct sock *sk, 1270fe067e8aSDavid S. Miller const struct sk_buff *skb) 1271fe067e8aSDavid S. Miller { 1272fe067e8aSDavid S. Miller return skb->next == (struct sk_buff *)&sk->sk_write_queue; 1273fe067e8aSDavid S. Miller } 1274fe067e8aSDavid S. Miller 1275fe067e8aSDavid S. Miller static inline int tcp_write_queue_empty(struct sock *sk) 1276fe067e8aSDavid S. Miller { 1277fe067e8aSDavid S. Miller return skb_queue_empty(&sk->sk_write_queue); 1278fe067e8aSDavid S. Miller } 1279fe067e8aSDavid S. Miller 1280a47e5a98SIlpo Järvinen /* Start sequence of the highest skb with SACKed bit, valid only if 1281a47e5a98SIlpo Järvinen * sacked > 0 or when the caller has ensured validity by itself. 1282a47e5a98SIlpo Järvinen */ 1283a47e5a98SIlpo Järvinen static inline u32 tcp_highest_sack_seq(struct tcp_sock *tp) 1284a47e5a98SIlpo Järvinen { 1285a47e5a98SIlpo Järvinen if (!tp->sacked_out) 1286a47e5a98SIlpo Järvinen return tp->snd_una; 12876859d494SIlpo Järvinen 12886859d494SIlpo Järvinen if (tp->highest_sack == NULL) 12896859d494SIlpo Järvinen return tp->snd_nxt; 12906859d494SIlpo Järvinen 1291a47e5a98SIlpo Järvinen return TCP_SKB_CB(tp->highest_sack)->seq; 1292a47e5a98SIlpo Järvinen } 1293a47e5a98SIlpo Järvinen 12946859d494SIlpo Järvinen static inline void tcp_advance_highest_sack(struct sock *sk, struct sk_buff *skb) 12956859d494SIlpo Järvinen { 12966859d494SIlpo Järvinen tcp_sk(sk)->highest_sack = tcp_skb_is_last(sk, skb) ? NULL : 12976859d494SIlpo Järvinen tcp_write_queue_next(sk, skb); 12986859d494SIlpo Järvinen } 12996859d494SIlpo Järvinen 13006859d494SIlpo Järvinen static inline struct sk_buff *tcp_highest_sack(struct sock *sk) 13016859d494SIlpo Järvinen { 13026859d494SIlpo Järvinen return tcp_sk(sk)->highest_sack; 13036859d494SIlpo Järvinen } 13046859d494SIlpo Järvinen 13056859d494SIlpo Järvinen static inline void tcp_highest_sack_reset(struct sock *sk) 13066859d494SIlpo Järvinen { 13076859d494SIlpo Järvinen tcp_sk(sk)->highest_sack = tcp_write_queue_head(sk); 13086859d494SIlpo Järvinen } 13096859d494SIlpo Järvinen 13106859d494SIlpo Järvinen /* Called when old skb is about to be deleted (to be combined with new skb) */ 13116859d494SIlpo Järvinen static inline void tcp_highest_sack_combine(struct sock *sk, 13126859d494SIlpo Järvinen struct sk_buff *old, 13136859d494SIlpo Järvinen struct sk_buff *new) 13146859d494SIlpo Järvinen { 13156859d494SIlpo Järvinen if (tcp_sk(sk)->sacked_out && (old == tcp_sk(sk)->highest_sack)) 13166859d494SIlpo Järvinen tcp_sk(sk)->highest_sack = new; 13176859d494SIlpo Järvinen } 13186859d494SIlpo Järvinen 13191da177e4SLinus Torvalds /* /proc */ 13201da177e4SLinus Torvalds enum tcp_seq_states { 13211da177e4SLinus Torvalds TCP_SEQ_STATE_LISTENING, 13221da177e4SLinus Torvalds TCP_SEQ_STATE_OPENREQ, 13231da177e4SLinus Torvalds TCP_SEQ_STATE_ESTABLISHED, 13241da177e4SLinus Torvalds TCP_SEQ_STATE_TIME_WAIT, 13251da177e4SLinus Torvalds }; 13261da177e4SLinus Torvalds 13271da177e4SLinus Torvalds struct tcp_seq_afinfo { 13281da177e4SLinus Torvalds struct module *owner; 13291da177e4SLinus Torvalds char *name; 13301da177e4SLinus Torvalds sa_family_t family; 13311da177e4SLinus Torvalds int (*seq_show) (struct seq_file *m, void *v); 13321da177e4SLinus Torvalds struct file_operations *seq_fops; 13331da177e4SLinus Torvalds }; 13341da177e4SLinus Torvalds 13351da177e4SLinus Torvalds struct tcp_iter_state { 1336f40c8174SDaniel Lezcano struct net *net; 13371da177e4SLinus Torvalds sa_family_t family; 13381da177e4SLinus Torvalds enum tcp_seq_states state; 13391da177e4SLinus Torvalds struct sock *syn_wait_sk; 13401da177e4SLinus Torvalds int bucket, sbucket, num, uid; 13411da177e4SLinus Torvalds struct seq_operations seq_ops; 13421da177e4SLinus Torvalds }; 13431da177e4SLinus Torvalds 13446f8b13bcSDaniel Lezcano extern int tcp_proc_register(struct net *net, struct tcp_seq_afinfo *afinfo); 13456f8b13bcSDaniel Lezcano extern void tcp_proc_unregister(struct net *net, struct tcp_seq_afinfo *afinfo); 13461da177e4SLinus Torvalds 134720380731SArnaldo Carvalho de Melo extern struct request_sock_ops tcp_request_sock_ops; 1348c6aefafbSGlenn Griffin extern struct request_sock_ops tcp6_request_sock_ops; 134920380731SArnaldo Carvalho de Melo 135020380731SArnaldo Carvalho de Melo extern int tcp_v4_destroy_sock(struct sock *sk); 135120380731SArnaldo Carvalho de Melo 1352a430a43dSHerbert Xu extern int tcp_v4_gso_send_check(struct sk_buff *skb); 1353576a30ebSHerbert Xu extern struct sk_buff *tcp_tso_segment(struct sk_buff *skb, int features); 1354f4c50d99SHerbert Xu 135520380731SArnaldo Carvalho de Melo #ifdef CONFIG_PROC_FS 135620380731SArnaldo Carvalho de Melo extern int tcp4_proc_init(void); 135720380731SArnaldo Carvalho de Melo extern void tcp4_proc_exit(void); 135820380731SArnaldo Carvalho de Melo #endif 135920380731SArnaldo Carvalho de Melo 1360cfb6eeb4SYOSHIFUJI Hideaki /* TCP af-specific functions */ 1361cfb6eeb4SYOSHIFUJI Hideaki struct tcp_sock_af_ops { 1362cfb6eeb4SYOSHIFUJI Hideaki #ifdef CONFIG_TCP_MD5SIG 1363cfb6eeb4SYOSHIFUJI Hideaki struct tcp_md5sig_key *(*md5_lookup) (struct sock *sk, 1364cfb6eeb4SYOSHIFUJI Hideaki struct sock *addr_sk); 1365cfb6eeb4SYOSHIFUJI Hideaki int (*calc_md5_hash) (char *location, 1366cfb6eeb4SYOSHIFUJI Hideaki struct tcp_md5sig_key *md5, 1367cfb6eeb4SYOSHIFUJI Hideaki struct sock *sk, 1368cfb6eeb4SYOSHIFUJI Hideaki struct dst_entry *dst, 1369cfb6eeb4SYOSHIFUJI Hideaki struct request_sock *req, 1370cfb6eeb4SYOSHIFUJI Hideaki struct tcphdr *th, 13719cb5734eSYOSHIFUJI Hideaki int protocol, 13729cb5734eSYOSHIFUJI Hideaki unsigned int len); 1373cfb6eeb4SYOSHIFUJI Hideaki int (*md5_add) (struct sock *sk, 1374cfb6eeb4SYOSHIFUJI Hideaki struct sock *addr_sk, 1375cfb6eeb4SYOSHIFUJI Hideaki u8 *newkey, 1376cfb6eeb4SYOSHIFUJI Hideaki u8 len); 1377cfb6eeb4SYOSHIFUJI Hideaki int (*md5_parse) (struct sock *sk, 1378cfb6eeb4SYOSHIFUJI Hideaki char __user *optval, 1379cfb6eeb4SYOSHIFUJI Hideaki int optlen); 1380cfb6eeb4SYOSHIFUJI Hideaki #endif 1381cfb6eeb4SYOSHIFUJI Hideaki }; 1382cfb6eeb4SYOSHIFUJI Hideaki 1383cfb6eeb4SYOSHIFUJI Hideaki struct tcp_request_sock_ops { 1384cfb6eeb4SYOSHIFUJI Hideaki #ifdef CONFIG_TCP_MD5SIG 1385cfb6eeb4SYOSHIFUJI Hideaki struct tcp_md5sig_key *(*md5_lookup) (struct sock *sk, 1386cfb6eeb4SYOSHIFUJI Hideaki struct request_sock *req); 1387cfb6eeb4SYOSHIFUJI Hideaki #endif 1388cfb6eeb4SYOSHIFUJI Hideaki }; 1389cfb6eeb4SYOSHIFUJI Hideaki 13909b0f976fSDenis V. Lunev extern void tcp_v4_init(void); 139120380731SArnaldo Carvalho de Melo extern void tcp_init(void); 139220380731SArnaldo Carvalho de Melo 13931da177e4SLinus Torvalds #endif /* _TCP_H */ 1394