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 FASTRETRANS_DEBUG 1 221da177e4SLinus Torvalds 231da177e4SLinus Torvalds #include <linux/list.h> 241da177e4SLinus Torvalds #include <linux/tcp.h> 25187f1882SPaul Gortmaker #include <linux/bug.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> 33435cf559SWilliam Allen Simpson #include <linux/kref.h> 34740b0f18SEric Dumazet #include <linux/ktime.h> 353f421baaSArnaldo Carvalho de Melo 363f421baaSArnaldo Carvalho de Melo #include <net/inet_connection_sock.h> 37295ff7edSArnaldo Carvalho de Melo #include <net/inet_timewait_sock.h> 3877d8bf9cSArnaldo Carvalho de Melo #include <net/inet_hashtables.h> 391da177e4SLinus Torvalds #include <net/checksum.h> 402e6599cbSArnaldo Carvalho de Melo #include <net/request_sock.h> 411da177e4SLinus Torvalds #include <net/sock.h> 421da177e4SLinus Torvalds #include <net/snmp.h> 431da177e4SLinus Torvalds #include <net/ip.h> 44c752f073SArnaldo Carvalho de Melo #include <net/tcp_states.h> 45bdf1ee5dSIlpo Järvinen #include <net/inet_ecn.h> 460c266898SSatoru SATOH #include <net/dst.h> 47c752f073SArnaldo Carvalho de Melo 481da177e4SLinus Torvalds #include <linux/seq_file.h> 49180d8cd9SGlauber Costa #include <linux/memcontrol.h> 501da177e4SLinus Torvalds 510f7ff927SArnaldo Carvalho de Melo extern struct inet_hashinfo tcp_hashinfo; 521da177e4SLinus Torvalds 53dd24c001SEric Dumazet extern struct percpu_counter tcp_orphan_count; 545c9f3023SJoe Perches void tcp_time_wait(struct sock *sk, int state, int timeo); 551da177e4SLinus Torvalds 561da177e4SLinus Torvalds #define MAX_TCP_HEADER (128 + MAX_HEADER) 5733ad798cSAdam Langley #define MAX_TCP_OPTION_SPACE 40 581da177e4SLinus Torvalds 591da177e4SLinus Torvalds /* 601da177e4SLinus Torvalds * Never offer a window over 32767 without using window scaling. Some 611da177e4SLinus Torvalds * poor stacks do signed 16bit maths! 621da177e4SLinus Torvalds */ 631da177e4SLinus Torvalds #define MAX_TCP_WINDOW 32767U 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds /* Minimal accepted MSS. It is (60+60+8) - (20+20). */ 661da177e4SLinus Torvalds #define TCP_MIN_MSS 88U 671da177e4SLinus Torvalds 685d424d5aSJohn Heffner /* The least MTU to use for probing */ 695d424d5aSJohn Heffner #define TCP_BASE_MSS 512 705d424d5aSJohn Heffner 711da177e4SLinus Torvalds /* After receiving this amount of duplicate ACKs fast retransmit starts. */ 721da177e4SLinus Torvalds #define TCP_FASTRETRANS_THRESH 3 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds /* Maximal reordering. */ 751da177e4SLinus Torvalds #define TCP_MAX_REORDERING 127 761da177e4SLinus Torvalds 771da177e4SLinus Torvalds /* Maximal number of ACKs sent quickly to accelerate slow-start. */ 781da177e4SLinus Torvalds #define TCP_MAX_QUICKACKS 16U 791da177e4SLinus Torvalds 801da177e4SLinus Torvalds /* urg_data states */ 811da177e4SLinus Torvalds #define TCP_URG_VALID 0x0100 821da177e4SLinus Torvalds #define TCP_URG_NOTYET 0x0200 831da177e4SLinus Torvalds #define TCP_URG_READ 0x0400 841da177e4SLinus Torvalds 851da177e4SLinus Torvalds #define TCP_RETR1 3 /* 861da177e4SLinus Torvalds * This is how many retries it does before it 871da177e4SLinus Torvalds * tries to figure out if the gateway is 881da177e4SLinus Torvalds * down. Minimal RFC value is 3; it corresponds 891da177e4SLinus Torvalds * to ~3sec-8min depending on RTO. 901da177e4SLinus Torvalds */ 911da177e4SLinus Torvalds 921da177e4SLinus Torvalds #define TCP_RETR2 15 /* 931da177e4SLinus Torvalds * This should take at least 941da177e4SLinus Torvalds * 90 minutes to time out. 951da177e4SLinus Torvalds * RFC1122 says that the limit is 100 sec. 961da177e4SLinus Torvalds * 15 is ~13-30min depending on RTO. 971da177e4SLinus Torvalds */ 981da177e4SLinus Torvalds 996c9ff979SAlex Bergmann #define TCP_SYN_RETRIES 6 /* This is how many retries are done 1006c9ff979SAlex Bergmann * when active opening a connection. 1016c9ff979SAlex Bergmann * RFC1122 says the minimum retry MUST 1026c9ff979SAlex Bergmann * be at least 180secs. Nevertheless 1036c9ff979SAlex Bergmann * this value is corresponding to 1046c9ff979SAlex Bergmann * 63secs of retransmission with the 1056c9ff979SAlex Bergmann * current initial RTO. 1066c9ff979SAlex Bergmann */ 1071da177e4SLinus Torvalds 1086c9ff979SAlex Bergmann #define TCP_SYNACK_RETRIES 5 /* This is how may retries are done 1096c9ff979SAlex Bergmann * when passive opening a connection. 1106c9ff979SAlex Bergmann * This is corresponding to 31secs of 1116c9ff979SAlex Bergmann * retransmission with the current 1126c9ff979SAlex Bergmann * initial RTO. 1136c9ff979SAlex Bergmann */ 1141da177e4SLinus Torvalds 1151da177e4SLinus Torvalds #define TCP_TIMEWAIT_LEN (60*HZ) /* how long to wait to destroy TIME-WAIT 1161da177e4SLinus Torvalds * state, about 60 seconds */ 1171da177e4SLinus Torvalds #define TCP_FIN_TIMEOUT TCP_TIMEWAIT_LEN 1181da177e4SLinus Torvalds /* BSD style FIN_WAIT2 deadlock breaker. 1191da177e4SLinus Torvalds * It used to be 3min, new value is 60sec, 1201da177e4SLinus Torvalds * to combine FIN-WAIT-2 timeout with 1211da177e4SLinus Torvalds * TIME-WAIT timer. 1221da177e4SLinus Torvalds */ 1231da177e4SLinus Torvalds 1241da177e4SLinus Torvalds #define TCP_DELACK_MAX ((unsigned)(HZ/5)) /* maximal time to delay before sending an ACK */ 1251da177e4SLinus Torvalds #if HZ >= 100 1261da177e4SLinus Torvalds #define TCP_DELACK_MIN ((unsigned)(HZ/25)) /* minimal time to delay before sending an ACK */ 1271da177e4SLinus Torvalds #define TCP_ATO_MIN ((unsigned)(HZ/25)) 1281da177e4SLinus Torvalds #else 1291da177e4SLinus Torvalds #define TCP_DELACK_MIN 4U 1301da177e4SLinus Torvalds #define TCP_ATO_MIN 4U 1311da177e4SLinus Torvalds #endif 1321da177e4SLinus Torvalds #define TCP_RTO_MAX ((unsigned)(120*HZ)) 1331da177e4SLinus Torvalds #define TCP_RTO_MIN ((unsigned)(HZ/5)) 134fd4f2ceaSEric Dumazet #define TCP_TIMEOUT_INIT ((unsigned)(1*HZ)) /* RFC6298 2.1 initial RTO value */ 1359ad7c049SJerry Chu #define TCP_TIMEOUT_FALLBACK ((unsigned)(3*HZ)) /* RFC 1122 initial RTO value, now 1369ad7c049SJerry Chu * used as a fallback RTO for the 1379ad7c049SJerry Chu * initial data transmission if no 1389ad7c049SJerry Chu * valid RTT sample has been acquired, 1399ad7c049SJerry Chu * most likely due to retrans in 3WHS. 1409ad7c049SJerry Chu */ 1411da177e4SLinus Torvalds 1421da177e4SLinus Torvalds #define TCP_RESOURCE_PROBE_INTERVAL ((unsigned)(HZ/2U)) /* Maximal interval between probes 1431da177e4SLinus Torvalds * for local resources. 1441da177e4SLinus Torvalds */ 1451da177e4SLinus Torvalds 1461da177e4SLinus Torvalds #define TCP_KEEPALIVE_TIME (120*60*HZ) /* two hours */ 1471da177e4SLinus Torvalds #define TCP_KEEPALIVE_PROBES 9 /* Max of 9 keepalive probes */ 1481da177e4SLinus Torvalds #define TCP_KEEPALIVE_INTVL (75*HZ) 1491da177e4SLinus Torvalds 1501da177e4SLinus Torvalds #define MAX_TCP_KEEPIDLE 32767 1511da177e4SLinus Torvalds #define MAX_TCP_KEEPINTVL 32767 1521da177e4SLinus Torvalds #define MAX_TCP_KEEPCNT 127 1531da177e4SLinus Torvalds #define MAX_TCP_SYNCNT 127 1541da177e4SLinus Torvalds 1551da177e4SLinus Torvalds #define TCP_SYNQ_INTERVAL (HZ/5) /* Period of SYNACK timer */ 1561da177e4SLinus Torvalds 1571da177e4SLinus Torvalds #define TCP_PAWS_24DAYS (60 * 60 * 24 * 24) 1581da177e4SLinus Torvalds #define TCP_PAWS_MSL 60 /* Per-host timestamps are invalidated 1591da177e4SLinus Torvalds * after this time. It should be equal 1601da177e4SLinus Torvalds * (or greater than) TCP_TIMEWAIT_LEN 1611da177e4SLinus Torvalds * to provide reliability equal to one 1621da177e4SLinus Torvalds * provided by timewait state. 1631da177e4SLinus Torvalds */ 1641da177e4SLinus Torvalds #define TCP_PAWS_WINDOW 1 /* Replay window for per-host 1651da177e4SLinus Torvalds * timestamps. It must be less than 1661da177e4SLinus Torvalds * minimal timewait lifetime. 1671da177e4SLinus Torvalds */ 1681da177e4SLinus Torvalds /* 1691da177e4SLinus Torvalds * TCP option 1701da177e4SLinus Torvalds */ 1711da177e4SLinus Torvalds 1721da177e4SLinus Torvalds #define TCPOPT_NOP 1 /* Padding */ 1731da177e4SLinus Torvalds #define TCPOPT_EOL 0 /* End of options */ 1741da177e4SLinus Torvalds #define TCPOPT_MSS 2 /* Segment size negotiating */ 1751da177e4SLinus Torvalds #define TCPOPT_WINDOW 3 /* Window scaling */ 1761da177e4SLinus Torvalds #define TCPOPT_SACK_PERM 4 /* SACK Permitted */ 1771da177e4SLinus Torvalds #define TCPOPT_SACK 5 /* SACK Block */ 1781da177e4SLinus Torvalds #define TCPOPT_TIMESTAMP 8 /* Better RTT estimations/PAWS */ 179cfb6eeb4SYOSHIFUJI Hideaki #define TCPOPT_MD5SIG 19 /* MD5 Signature (RFC2385) */ 1802100c8d2SYuchung Cheng #define TCPOPT_EXP 254 /* Experimental */ 1812100c8d2SYuchung Cheng /* Magic number to be after the option value for sharing TCP 1822100c8d2SYuchung Cheng * experimental options. See draft-ietf-tcpm-experimental-options-00.txt 1832100c8d2SYuchung Cheng */ 1842100c8d2SYuchung Cheng #define TCPOPT_FASTOPEN_MAGIC 0xF989 1851da177e4SLinus Torvalds 1861da177e4SLinus Torvalds /* 1871da177e4SLinus Torvalds * TCP option lengths 1881da177e4SLinus Torvalds */ 1891da177e4SLinus Torvalds 1901da177e4SLinus Torvalds #define TCPOLEN_MSS 4 1911da177e4SLinus Torvalds #define TCPOLEN_WINDOW 3 1921da177e4SLinus Torvalds #define TCPOLEN_SACK_PERM 2 1931da177e4SLinus Torvalds #define TCPOLEN_TIMESTAMP 10 194cfb6eeb4SYOSHIFUJI Hideaki #define TCPOLEN_MD5SIG 18 1952100c8d2SYuchung Cheng #define TCPOLEN_EXP_FASTOPEN_BASE 4 1961da177e4SLinus Torvalds 1971da177e4SLinus Torvalds /* But this is what stacks really send out. */ 1981da177e4SLinus Torvalds #define TCPOLEN_TSTAMP_ALIGNED 12 1991da177e4SLinus Torvalds #define TCPOLEN_WSCALE_ALIGNED 4 2001da177e4SLinus Torvalds #define TCPOLEN_SACKPERM_ALIGNED 4 2011da177e4SLinus Torvalds #define TCPOLEN_SACK_BASE 2 2021da177e4SLinus Torvalds #define TCPOLEN_SACK_BASE_ALIGNED 4 2031da177e4SLinus Torvalds #define TCPOLEN_SACK_PERBLOCK 8 204cfb6eeb4SYOSHIFUJI Hideaki #define TCPOLEN_MD5SIG_ALIGNED 20 20533ad798cSAdam Langley #define TCPOLEN_MSS_ALIGNED 4 2061da177e4SLinus Torvalds 2071da177e4SLinus Torvalds /* Flags in tp->nonagle */ 2081da177e4SLinus Torvalds #define TCP_NAGLE_OFF 1 /* Nagle's algo is disabled */ 2091da177e4SLinus Torvalds #define TCP_NAGLE_CORK 2 /* Socket is corked */ 210caa20d9aSStephen Hemminger #define TCP_NAGLE_PUSH 4 /* Cork is overridden for already queued data */ 2111da177e4SLinus Torvalds 21236e31b0aSAndreas Petlund /* TCP thin-stream limits */ 21336e31b0aSAndreas Petlund #define TCP_THIN_LINEAR_RETRIES 6 /* After 6 linear retries, do exp. backoff */ 21436e31b0aSAndreas Petlund 2157eb38527SDavid S. Miller /* TCP initial congestion window as per draft-hkchu-tcpm-initcwnd-01 */ 216442b9635SDavid S. Miller #define TCP_INIT_CWND 10 217442b9635SDavid S. Miller 218cf60af03SYuchung Cheng /* Bit Flags for sysctl_tcp_fastopen */ 219cf60af03SYuchung Cheng #define TFO_CLIENT_ENABLE 1 22010467163SJerry Chu #define TFO_SERVER_ENABLE 2 22167da22d2SYuchung Cheng #define TFO_CLIENT_NO_COOKIE 4 /* Data in SYN w/o cookie option */ 222cf60af03SYuchung Cheng 22310467163SJerry Chu /* Accept SYN data w/o any cookie option */ 22410467163SJerry Chu #define TFO_SERVER_COOKIE_NOT_REQD 0x200 22510467163SJerry Chu 22610467163SJerry Chu /* Force enable TFO on all listeners, i.e., not requiring the 22710467163SJerry Chu * TCP_FASTOPEN socket option. SOCKOPT1/2 determine how to set max_qlen. 22810467163SJerry Chu */ 22910467163SJerry Chu #define TFO_SERVER_WO_SOCKOPT1 0x400 23010467163SJerry Chu #define TFO_SERVER_WO_SOCKOPT2 0x800 23110467163SJerry Chu 232295ff7edSArnaldo Carvalho de Melo extern struct inet_timewait_death_row tcp_death_row; 233295ff7edSArnaldo Carvalho de Melo 2341da177e4SLinus Torvalds /* sysctl variables for tcp */ 2351da177e4SLinus Torvalds extern int sysctl_tcp_timestamps; 2361da177e4SLinus Torvalds extern int sysctl_tcp_window_scaling; 2371da177e4SLinus Torvalds extern int sysctl_tcp_sack; 2381da177e4SLinus Torvalds extern int sysctl_tcp_fin_timeout; 2391da177e4SLinus Torvalds extern int sysctl_tcp_keepalive_time; 2401da177e4SLinus Torvalds extern int sysctl_tcp_keepalive_probes; 2411da177e4SLinus Torvalds extern int sysctl_tcp_keepalive_intvl; 2421da177e4SLinus Torvalds extern int sysctl_tcp_syn_retries; 2431da177e4SLinus Torvalds extern int sysctl_tcp_synack_retries; 2441da177e4SLinus Torvalds extern int sysctl_tcp_retries1; 2451da177e4SLinus Torvalds extern int sysctl_tcp_retries2; 2461da177e4SLinus Torvalds extern int sysctl_tcp_orphan_retries; 2471da177e4SLinus Torvalds extern int sysctl_tcp_syncookies; 2482100c8d2SYuchung Cheng extern int sysctl_tcp_fastopen; 2491da177e4SLinus Torvalds extern int sysctl_tcp_retrans_collapse; 2501da177e4SLinus Torvalds extern int sysctl_tcp_stdurg; 2511da177e4SLinus Torvalds extern int sysctl_tcp_rfc1337; 2521da177e4SLinus Torvalds extern int sysctl_tcp_abort_on_overflow; 2531da177e4SLinus Torvalds extern int sysctl_tcp_max_orphans; 2541da177e4SLinus Torvalds extern int sysctl_tcp_fack; 2551da177e4SLinus Torvalds extern int sysctl_tcp_reordering; 2561da177e4SLinus Torvalds extern int sysctl_tcp_dsack; 257a4fe34bfSEric W. Biederman extern long sysctl_tcp_mem[3]; 2581da177e4SLinus Torvalds extern int sysctl_tcp_wmem[3]; 2591da177e4SLinus Torvalds extern int sysctl_tcp_rmem[3]; 2601da177e4SLinus Torvalds extern int sysctl_tcp_app_win; 2611da177e4SLinus Torvalds extern int sysctl_tcp_adv_win_scale; 2621da177e4SLinus Torvalds extern int sysctl_tcp_tw_reuse; 2631da177e4SLinus Torvalds extern int sysctl_tcp_frto; 2641da177e4SLinus Torvalds extern int sysctl_tcp_low_latency; 26595937825SChris Leech extern int sysctl_tcp_dma_copybreak; 2661da177e4SLinus Torvalds extern int sysctl_tcp_nometrics_save; 2671da177e4SLinus Torvalds extern int sysctl_tcp_moderate_rcvbuf; 2681da177e4SLinus Torvalds extern int sysctl_tcp_tso_win_divisor; 2695d424d5aSJohn Heffner extern int sysctl_tcp_mtu_probing; 2705d424d5aSJohn Heffner extern int sysctl_tcp_base_mss; 27115d99e02SRick Jones extern int sysctl_tcp_workaround_signed_windows; 27235089bb2SDavid S. Miller extern int sysctl_tcp_slow_start_after_idle; 27336e31b0aSAndreas Petlund extern int sysctl_tcp_thin_linear_timeouts; 2747e380175SAndreas Petlund extern int sysctl_tcp_thin_dupack; 275eed530b6SYuchung Cheng extern int sysctl_tcp_early_retrans; 27646d3ceabSEric Dumazet extern int sysctl_tcp_limit_output_bytes; 277282f23c6SEric Dumazet extern int sysctl_tcp_challenge_ack_limit; 278c9bee3b7SEric Dumazet extern unsigned int sysctl_tcp_notsent_lowat; 27995bd09ebSEric Dumazet extern int sysctl_tcp_min_tso_segs; 280f54b3111SEric Dumazet extern int sysctl_tcp_autocorking; 2811da177e4SLinus Torvalds 2828d987e5cSEric Dumazet extern atomic_long_t tcp_memory_allocated; 2831748376bSEric Dumazet extern struct percpu_counter tcp_sockets_allocated; 2841da177e4SLinus Torvalds extern int tcp_memory_pressure; 2851da177e4SLinus Torvalds 2861da177e4SLinus Torvalds /* 2871da177e4SLinus Torvalds * The next routines deal with comparing 32 bit unsigned ints 2881da177e4SLinus Torvalds * and worry about wraparound (automatic with unsigned arithmetic). 2891da177e4SLinus Torvalds */ 2901da177e4SLinus Torvalds 291a2a385d6SEric Dumazet static inline bool before(__u32 seq1, __u32 seq2) 2921da177e4SLinus Torvalds { 2930d630cc0SGerrit Renker return (__s32)(seq1-seq2) < 0; 2941da177e4SLinus Torvalds } 2959a036b9cSGerrit Renker #define after(seq2, seq1) before(seq1, seq2) 2961da177e4SLinus Torvalds 2971da177e4SLinus Torvalds /* is s2<=s1<=s3 ? */ 298a2a385d6SEric Dumazet static inline bool between(__u32 seq1, __u32 seq2, __u32 seq3) 2991da177e4SLinus Torvalds { 3001da177e4SLinus Torvalds return seq3 - seq2 >= seq1 - seq2; 3011da177e4SLinus Torvalds } 3021da177e4SLinus Torvalds 303efcdbf24SArun Sharma static inline bool tcp_out_of_memory(struct sock *sk) 304efcdbf24SArun Sharma { 305efcdbf24SArun Sharma if (sk->sk_wmem_queued > SOCK_MIN_SNDBUF && 306efcdbf24SArun Sharma sk_memory_allocated(sk) > sk_prot_mem_limits(sk, 2)) 307efcdbf24SArun Sharma return true; 308efcdbf24SArun Sharma return false; 309efcdbf24SArun Sharma } 310efcdbf24SArun Sharma 311ad1af0feSDavid S. Miller static inline bool tcp_too_many_orphans(struct sock *sk, int shift) 312e4fd5da3SPavel Emelianov { 313ad1af0feSDavid S. Miller struct percpu_counter *ocp = sk->sk_prot->orphan_count; 314ad1af0feSDavid S. Miller int orphans = percpu_counter_read_positive(ocp); 315ad1af0feSDavid S. Miller 316ad1af0feSDavid S. Miller if (orphans << shift > sysctl_tcp_max_orphans) { 317ad1af0feSDavid S. Miller orphans = percpu_counter_sum_positive(ocp); 318ad1af0feSDavid S. Miller if (orphans << shift > sysctl_tcp_max_orphans) 319ad1af0feSDavid S. Miller return true; 320ad1af0feSDavid S. Miller } 321ad1af0feSDavid S. Miller return false; 322e4fd5da3SPavel Emelianov } 3231da177e4SLinus Torvalds 3245c9f3023SJoe Perches bool tcp_check_oom(struct sock *sk, int shift); 325efcdbf24SArun Sharma 326a0f82f64SFlorian Westphal /* syncookies: remember time of last synqueue overflow */ 327a0f82f64SFlorian Westphal static inline void tcp_synq_overflow(struct sock *sk) 328a0f82f64SFlorian Westphal { 329a0f82f64SFlorian Westphal tcp_sk(sk)->rx_opt.ts_recent_stamp = jiffies; 330a0f82f64SFlorian Westphal } 331a0f82f64SFlorian Westphal 332a0f82f64SFlorian Westphal /* syncookies: no recent synqueue overflow on this listening socket? */ 333a2a385d6SEric Dumazet static inline bool tcp_synq_no_recent_overflow(const struct sock *sk) 334a0f82f64SFlorian Westphal { 335a0f82f64SFlorian Westphal unsigned long last_overflow = tcp_sk(sk)->rx_opt.ts_recent_stamp; 3369ad7c049SJerry Chu return time_after(jiffies, last_overflow + TCP_TIMEOUT_FALLBACK); 337a0f82f64SFlorian Westphal } 338a0f82f64SFlorian Westphal 3391da177e4SLinus Torvalds extern struct proto tcp_prot; 3401da177e4SLinus Torvalds 34157ef42d5SPavel Emelyanov #define TCP_INC_STATS(net, field) SNMP_INC_STATS((net)->mib.tcp_statistics, field) 34257ef42d5SPavel Emelyanov #define TCP_INC_STATS_BH(net, field) SNMP_INC_STATS_BH((net)->mib.tcp_statistics, field) 34357ef42d5SPavel Emelyanov #define TCP_DEC_STATS(net, field) SNMP_DEC_STATS((net)->mib.tcp_statistics, field) 34457ef42d5SPavel Emelyanov #define TCP_ADD_STATS_USER(net, field, val) SNMP_ADD_STATS_USER((net)->mib.tcp_statistics, field, val) 345aa2ea058STom Herbert #define TCP_ADD_STATS(net, field, val) SNMP_ADD_STATS((net)->mib.tcp_statistics, field, val) 3461da177e4SLinus Torvalds 3475c9f3023SJoe Perches void tcp_tasklet_init(void); 34846d3ceabSEric Dumazet 3495c9f3023SJoe Perches void tcp_v4_err(struct sk_buff *skb, u32); 3501da177e4SLinus Torvalds 3515c9f3023SJoe Perches void tcp_shutdown(struct sock *sk, int how); 3521da177e4SLinus Torvalds 3535c9f3023SJoe Perches void tcp_v4_early_demux(struct sk_buff *skb); 3545c9f3023SJoe Perches int tcp_v4_rcv(struct sk_buff *skb); 3551da177e4SLinus Torvalds 3565c9f3023SJoe Perches int tcp_v4_tw_remember_stamp(struct inet_timewait_sock *tw); 3575c9f3023SJoe Perches int tcp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, 3587ba42910SChangli Gao size_t size); 3595c9f3023SJoe Perches int tcp_sendpage(struct sock *sk, struct page *page, int offset, size_t size, 3605c9f3023SJoe Perches int flags); 3615c9f3023SJoe Perches void tcp_release_cb(struct sock *sk); 3625c9f3023SJoe Perches void tcp_wfree(struct sk_buff *skb); 3635c9f3023SJoe Perches void tcp_write_timer_handler(struct sock *sk); 3645c9f3023SJoe Perches void tcp_delack_timer_handler(struct sock *sk); 3655c9f3023SJoe Perches int tcp_ioctl(struct sock *sk, int cmd, unsigned long arg); 3665c9f3023SJoe Perches int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb, 367cf533ea5SEric Dumazet const struct tcphdr *th, unsigned int len); 3685c9f3023SJoe Perches void tcp_rcv_established(struct sock *sk, struct sk_buff *skb, 369cf533ea5SEric Dumazet const struct tcphdr *th, unsigned int len); 3705c9f3023SJoe Perches void tcp_rcv_space_adjust(struct sock *sk); 3715c9f3023SJoe Perches void tcp_cleanup_rbuf(struct sock *sk, int copied); 3725c9f3023SJoe Perches int tcp_twsk_unique(struct sock *sk, struct sock *sktw, void *twp); 3735c9f3023SJoe Perches void tcp_twsk_destructor(struct sock *sk); 3745c9f3023SJoe Perches ssize_t tcp_splice_read(struct socket *sk, loff_t *ppos, 37553d3176bSChangli Gao struct pipe_inode_info *pipe, size_t len, 37653d3176bSChangli Gao unsigned int flags); 3779c55e01cSJens Axboe 378463c84b9SArnaldo Carvalho de Melo static inline void tcp_dec_quickack_mode(struct sock *sk, 379463c84b9SArnaldo Carvalho de Melo const unsigned int pkts) 3801da177e4SLinus Torvalds { 381463c84b9SArnaldo Carvalho de Melo struct inet_connection_sock *icsk = inet_csk(sk); 382fc6415bcSDavid S. Miller 383463c84b9SArnaldo Carvalho de Melo if (icsk->icsk_ack.quick) { 384463c84b9SArnaldo Carvalho de Melo if (pkts >= icsk->icsk_ack.quick) { 385463c84b9SArnaldo Carvalho de Melo icsk->icsk_ack.quick = 0; 3861da177e4SLinus Torvalds /* Leaving quickack mode we deflate ATO. */ 387463c84b9SArnaldo Carvalho de Melo icsk->icsk_ack.ato = TCP_ATO_MIN; 388fc6415bcSDavid S. Miller } else 389463c84b9SArnaldo Carvalho de Melo icsk->icsk_ack.quick -= pkts; 3901da177e4SLinus Torvalds } 3911da177e4SLinus Torvalds } 3921da177e4SLinus Torvalds 393bdf1ee5dSIlpo Järvinen #define TCP_ECN_OK 1 394bdf1ee5dSIlpo Järvinen #define TCP_ECN_QUEUE_CWR 2 395bdf1ee5dSIlpo Järvinen #define TCP_ECN_DEMAND_CWR 4 3967a269ffaSEric Dumazet #define TCP_ECN_SEEN 8 397bdf1ee5dSIlpo Järvinen 398fd2c3ef7SEric Dumazet enum tcp_tw_status { 3991da177e4SLinus Torvalds TCP_TW_SUCCESS = 0, 4001da177e4SLinus Torvalds TCP_TW_RST = 1, 4011da177e4SLinus Torvalds TCP_TW_ACK = 2, 4021da177e4SLinus Torvalds TCP_TW_SYN = 3 4031da177e4SLinus Torvalds }; 4041da177e4SLinus Torvalds 4051da177e4SLinus Torvalds 4065c9f3023SJoe Perches enum tcp_tw_status tcp_timewait_state_process(struct inet_timewait_sock *tw, 4071da177e4SLinus Torvalds struct sk_buff *skb, 4088feaf0c0SArnaldo Carvalho de Melo const struct tcphdr *th); 4095c9f3023SJoe Perches struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb, 4105c9f3023SJoe Perches struct request_sock *req, struct request_sock **prev, 4118336886fSJerry Chu bool fastopen); 4125c9f3023SJoe Perches int tcp_child_process(struct sock *parent, struct sock *child, 4131da177e4SLinus Torvalds struct sk_buff *skb); 4145ae344c9SNeal Cardwell void tcp_enter_loss(struct sock *sk); 4155c9f3023SJoe Perches void tcp_clear_retrans(struct tcp_sock *tp); 4165c9f3023SJoe Perches void tcp_update_metrics(struct sock *sk); 4175c9f3023SJoe Perches void tcp_init_metrics(struct sock *sk); 4185c9f3023SJoe Perches void tcp_metrics_init(void); 4195c9f3023SJoe Perches bool tcp_peer_is_proven(struct request_sock *req, struct dst_entry *dst, 420a26552afSHannes Frederic Sowa bool paws_check, bool timestamps); 4215c9f3023SJoe Perches bool tcp_remember_stamp(struct sock *sk); 4225c9f3023SJoe Perches bool tcp_tw_remember_stamp(struct inet_timewait_sock *tw); 4235c9f3023SJoe Perches void tcp_fetch_timewait_stamp(struct sock *sk, struct dst_entry *dst); 4245c9f3023SJoe Perches void tcp_disable_fack(struct tcp_sock *tp); 4255c9f3023SJoe Perches void tcp_close(struct sock *sk, long timeout); 4265c9f3023SJoe Perches void tcp_init_sock(struct sock *sk); 4275c9f3023SJoe Perches unsigned int tcp_poll(struct file *file, struct socket *sock, 42853d3176bSChangli Gao struct poll_table_struct *wait); 4295c9f3023SJoe Perches int tcp_getsockopt(struct sock *sk, int level, int optname, 4303fdadf7dSDmitry Mishin char __user *optval, int __user *optlen); 4315c9f3023SJoe Perches int tcp_setsockopt(struct sock *sk, int level, int optname, 43253d3176bSChangli Gao char __user *optval, unsigned int optlen); 4335c9f3023SJoe Perches int compat_tcp_getsockopt(struct sock *sk, int level, int optname, 43453d3176bSChangli Gao char __user *optval, int __user *optlen); 4355c9f3023SJoe Perches int compat_tcp_setsockopt(struct sock *sk, int level, int optname, 436b7058842SDavid S. Miller char __user *optval, unsigned int optlen); 4375c9f3023SJoe Perches void tcp_set_keepalive(struct sock *sk, int val); 4385c9f3023SJoe Perches void tcp_syn_ack_timeout(struct sock *sk, struct request_sock *req); 4395c9f3023SJoe Perches int tcp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, 44053d3176bSChangli Gao size_t len, int nonblock, int flags, int *addr_len); 4415c9f3023SJoe Perches void tcp_parse_options(const struct sk_buff *skb, 4421a2c6181SChristoph Paasch struct tcp_options_received *opt_rx, 4432100c8d2SYuchung Cheng int estab, struct tcp_fastopen_cookie *foc); 4445c9f3023SJoe Perches const u8 *tcp_parse_md5sig_option(const struct tcphdr *th); 4457d5d5525SYOSHIFUJI Hideaki 4461da177e4SLinus Torvalds /* 4471da177e4SLinus Torvalds * TCP v4 functions exported for the inet6 API 4481da177e4SLinus Torvalds */ 4491da177e4SLinus Torvalds 4505c9f3023SJoe Perches void tcp_v4_send_check(struct sock *sk, struct sk_buff *skb); 4514fab9071SNeal Cardwell void tcp_v4_mtu_reduced(struct sock *sk); 4525c9f3023SJoe Perches int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb); 4535c9f3023SJoe Perches struct sock *tcp_create_openreq_child(struct sock *sk, 45460236fddSArnaldo Carvalho de Melo struct request_sock *req, 4551da177e4SLinus Torvalds struct sk_buff *skb); 4565c9f3023SJoe Perches struct sock *tcp_v4_syn_recv_sock(struct sock *sk, struct sk_buff *skb, 45760236fddSArnaldo Carvalho de Melo struct request_sock *req, 4581da177e4SLinus Torvalds struct dst_entry *dst); 4595c9f3023SJoe Perches int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb); 4605c9f3023SJoe Perches int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len); 4615c9f3023SJoe Perches int tcp_connect(struct sock *sk); 4625c9f3023SJoe Perches struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst, 463e6b4d113SWilliam Allen Simpson struct request_sock *req, 4648336886fSJerry Chu struct tcp_fastopen_cookie *foc); 4655c9f3023SJoe Perches int tcp_disconnect(struct sock *sk, int flags); 4661da177e4SLinus Torvalds 467370816aeSPavel Emelyanov void tcp_finish_connect(struct sock *sk, struct sk_buff *skb); 468292e8d8cSPavel Emelyanov int tcp_send_rcvq(struct sock *sk, struct msghdr *msg, size_t size); 46963d02d15SEric Dumazet void inet_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb); 4701da177e4SLinus Torvalds 4711da177e4SLinus Torvalds /* From syncookies.c */ 4725c9f3023SJoe Perches int __cookie_v4_check(const struct iphdr *iph, const struct tcphdr *th, 4730198230bSPatrick McHardy u32 cookie); 4745c9f3023SJoe Perches struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb, 4751da177e4SLinus Torvalds struct ip_options *opt); 476e05c82d3SEric Dumazet #ifdef CONFIG_SYN_COOKIES 4778c27bd75SFlorian Westphal 47863262315SEric Dumazet /* Syncookies use a monotonic timer which increments every 60 seconds. 4798c27bd75SFlorian Westphal * This counter is used both as a hash input and partially encoded into 4808c27bd75SFlorian Westphal * the cookie value. A cookie is only validated further if the delta 4818c27bd75SFlorian Westphal * between the current counter value and the encoded one is less than this, 48263262315SEric Dumazet * i.e. a sent cookie is valid only at most for 2*60 seconds (or less if 4838c27bd75SFlorian Westphal * the counter advances immediately after a cookie is generated). 4848c27bd75SFlorian Westphal */ 4858c27bd75SFlorian Westphal #define MAX_SYNCOOKIE_AGE 2 4868c27bd75SFlorian Westphal 4878c27bd75SFlorian Westphal static inline u32 tcp_cookie_time(void) 4888c27bd75SFlorian Westphal { 48963262315SEric Dumazet u64 val = get_jiffies_64(); 49063262315SEric Dumazet 49163262315SEric Dumazet do_div(val, 60 * HZ); 49263262315SEric Dumazet return val; 4938c27bd75SFlorian Westphal } 4948c27bd75SFlorian Westphal 4955c9f3023SJoe Perches u32 __cookie_v4_init_sequence(const struct iphdr *iph, const struct tcphdr *th, 4965c9f3023SJoe Perches u16 *mssp); 49757b47553SOctavian Purdila __u32 cookie_v4_init_sequence(struct sock *sk, const struct sk_buff *skb, 49857b47553SOctavian Purdila __u16 *mss); 499e05c82d3SEric Dumazet #endif 5001da177e4SLinus Torvalds 5015c9f3023SJoe Perches __u32 cookie_init_timestamp(struct request_sock *req); 5025c9f3023SJoe Perches bool cookie_check_timestamp(struct tcp_options_received *opt, struct net *net, 5035c9f3023SJoe Perches bool *ecn_ok); 5044dfc2817SFlorian Westphal 505c6aefafbSGlenn Griffin /* From net/ipv6/syncookies.c */ 5065c9f3023SJoe Perches int __cookie_v6_check(const struct ipv6hdr *iph, const struct tcphdr *th, 50781eb6a14SPatrick McHardy u32 cookie); 5085c9f3023SJoe Perches struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb); 509e05c82d3SEric Dumazet #ifdef CONFIG_SYN_COOKIES 5105c9f3023SJoe Perches u32 __cookie_v6_init_sequence(const struct ipv6hdr *iph, 51181eb6a14SPatrick McHardy const struct tcphdr *th, u16 *mssp); 5125c9f3023SJoe Perches __u32 cookie_v6_init_sequence(struct sock *sk, const struct sk_buff *skb, 513c6aefafbSGlenn Griffin __u16 *mss); 514e05c82d3SEric Dumazet #endif 5151da177e4SLinus Torvalds /* tcp_output.c */ 5161da177e4SLinus Torvalds 5175c9f3023SJoe Perches void __tcp_push_pending_frames(struct sock *sk, unsigned int cur_mss, 5189e412ba7SIlpo Järvinen int nonagle); 5195c9f3023SJoe Perches bool tcp_may_send_now(struct sock *sk); 5205c9f3023SJoe Perches int __tcp_retransmit_skb(struct sock *, struct sk_buff *); 5215c9f3023SJoe Perches int tcp_retransmit_skb(struct sock *, struct sk_buff *); 5225c9f3023SJoe Perches void tcp_retransmit_timer(struct sock *sk); 5235c9f3023SJoe Perches void tcp_xmit_retransmit_queue(struct sock *); 5245c9f3023SJoe Perches void tcp_simple_retransmit(struct sock *); 5255c9f3023SJoe Perches int tcp_trim_head(struct sock *, struct sk_buff *, u32); 5266cc55e09SOctavian Purdila int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t); 5271da177e4SLinus Torvalds 5285c9f3023SJoe Perches void tcp_send_probe0(struct sock *); 5295c9f3023SJoe Perches void tcp_send_partial(struct sock *); 5305c9f3023SJoe Perches int tcp_write_wakeup(struct sock *); 5315c9f3023SJoe Perches void tcp_send_fin(struct sock *sk); 5325c9f3023SJoe Perches void tcp_send_active_reset(struct sock *sk, gfp_t priority); 5335c9f3023SJoe Perches int tcp_send_synack(struct sock *); 5345c9f3023SJoe Perches bool tcp_syn_flood_action(struct sock *sk, const struct sk_buff *skb, 535946cedccSEric Dumazet const char *proto); 5365c9f3023SJoe Perches void tcp_push_one(struct sock *, unsigned int mss_now); 5375c9f3023SJoe Perches void tcp_send_ack(struct sock *sk); 5385c9f3023SJoe Perches void tcp_send_delayed_ack(struct sock *sk); 5395c9f3023SJoe Perches void tcp_send_loss_probe(struct sock *sk); 5405c9f3023SJoe Perches bool tcp_schedule_loss_probe(struct sock *sk); 5411da177e4SLinus Torvalds 542a762a980SDavid S. Miller /* tcp_input.c */ 5435c9f3023SJoe Perches void tcp_resume_early_retransmit(struct sock *sk); 5445c9f3023SJoe Perches void tcp_rearm_rto(struct sock *sk); 5455c9f3023SJoe Perches void tcp_reset(struct sock *sk); 546a762a980SDavid S. Miller 5471da177e4SLinus Torvalds /* tcp_timer.c */ 5485c9f3023SJoe Perches void tcp_init_xmit_timers(struct sock *); 549463c84b9SArnaldo Carvalho de Melo static inline void tcp_clear_xmit_timers(struct sock *sk) 550463c84b9SArnaldo Carvalho de Melo { 551463c84b9SArnaldo Carvalho de Melo inet_csk_clear_xmit_timers(sk); 552463c84b9SArnaldo Carvalho de Melo } 5531da177e4SLinus Torvalds 5545c9f3023SJoe Perches unsigned int tcp_sync_mss(struct sock *sk, u32 pmtu); 5555c9f3023SJoe Perches unsigned int tcp_current_mss(struct sock *sk); 5560c54b85fSIlpo Järvinen 5570c54b85fSIlpo Järvinen /* Bound MSS / TSO packet size with the half of the window */ 5580c54b85fSIlpo Järvinen static inline int tcp_bound_to_half_wnd(struct tcp_sock *tp, int pktsize) 5590c54b85fSIlpo Järvinen { 56001f83d69SAlexey Kuznetsov int cutoff; 56101f83d69SAlexey Kuznetsov 56201f83d69SAlexey Kuznetsov /* When peer uses tiny windows, there is no use in packetizing 56301f83d69SAlexey Kuznetsov * to sub-MSS pieces for the sake of SWS or making sure there 56401f83d69SAlexey Kuznetsov * are enough packets in the pipe for fast recovery. 56501f83d69SAlexey Kuznetsov * 56601f83d69SAlexey Kuznetsov * On the other hand, for extremely large MSS devices, handling 56701f83d69SAlexey Kuznetsov * smaller than MSS windows in this way does make sense. 56801f83d69SAlexey Kuznetsov */ 56901f83d69SAlexey Kuznetsov if (tp->max_window >= 512) 57001f83d69SAlexey Kuznetsov cutoff = (tp->max_window >> 1); 57101f83d69SAlexey Kuznetsov else 57201f83d69SAlexey Kuznetsov cutoff = tp->max_window; 57301f83d69SAlexey Kuznetsov 57401f83d69SAlexey Kuznetsov if (cutoff && pktsize > cutoff) 57501f83d69SAlexey Kuznetsov return max_t(int, cutoff, 68U - tp->tcp_header_len); 5760c54b85fSIlpo Järvinen else 5770c54b85fSIlpo Järvinen return pktsize; 5780c54b85fSIlpo Järvinen } 5791da177e4SLinus Torvalds 58017b085eaSArnaldo Carvalho de Melo /* tcp.c */ 5815c9f3023SJoe Perches void tcp_get_info(const struct sock *, struct tcp_info *); 5821da177e4SLinus Torvalds 5831da177e4SLinus Torvalds /* Read 'sendfile()'-style from a TCP socket */ 5841da177e4SLinus Torvalds typedef int (*sk_read_actor_t)(read_descriptor_t *, struct sk_buff *, 5851da177e4SLinus Torvalds unsigned int, size_t); 5865c9f3023SJoe Perches int tcp_read_sock(struct sock *sk, read_descriptor_t *desc, 5871da177e4SLinus Torvalds sk_read_actor_t recv_actor); 5881da177e4SLinus Torvalds 5895c9f3023SJoe Perches void tcp_initialize_rcv_mss(struct sock *sk); 5901da177e4SLinus Torvalds 5915c9f3023SJoe Perches int tcp_mtu_to_mss(struct sock *sk, int pmtu); 5925c9f3023SJoe Perches int tcp_mss_to_mtu(struct sock *sk, int mss); 5935c9f3023SJoe Perches void tcp_mtup_init(struct sock *sk); 5945c9f3023SJoe Perches void tcp_init_buffer_space(struct sock *sk); 5955d424d5aSJohn Heffner 596f1ecd5d9SDamian Lukowski static inline void tcp_bound_rto(const struct sock *sk) 597f1ecd5d9SDamian Lukowski { 598f1ecd5d9SDamian Lukowski if (inet_csk(sk)->icsk_rto > TCP_RTO_MAX) 599f1ecd5d9SDamian Lukowski inet_csk(sk)->icsk_rto = TCP_RTO_MAX; 600f1ecd5d9SDamian Lukowski } 601f1ecd5d9SDamian Lukowski 602f1ecd5d9SDamian Lukowski static inline u32 __tcp_set_rto(const struct tcp_sock *tp) 603f1ecd5d9SDamian Lukowski { 604740b0f18SEric Dumazet return usecs_to_jiffies((tp->srtt_us >> 3) + tp->rttvar_us); 605f1ecd5d9SDamian Lukowski } 606f1ecd5d9SDamian Lukowski 60740efc6faSStephen Hemminger static inline void __tcp_fast_path_on(struct tcp_sock *tp, u32 snd_wnd) 6081da177e4SLinus Torvalds { 6091da177e4SLinus Torvalds tp->pred_flags = htonl((tp->tcp_header_len << 26) | 6101da177e4SLinus Torvalds ntohl(TCP_FLAG_ACK) | 6111da177e4SLinus Torvalds snd_wnd); 6121da177e4SLinus Torvalds } 6131da177e4SLinus Torvalds 61440efc6faSStephen Hemminger static inline void tcp_fast_path_on(struct tcp_sock *tp) 6151da177e4SLinus Torvalds { 6161da177e4SLinus Torvalds __tcp_fast_path_on(tp, tp->snd_wnd >> tp->rx_opt.snd_wscale); 6171da177e4SLinus Torvalds } 6181da177e4SLinus Torvalds 6199e412ba7SIlpo Järvinen static inline void tcp_fast_path_check(struct sock *sk) 6201da177e4SLinus Torvalds { 6219e412ba7SIlpo Järvinen struct tcp_sock *tp = tcp_sk(sk); 6229e412ba7SIlpo Järvinen 623b03efcfbSDavid S. Miller if (skb_queue_empty(&tp->out_of_order_queue) && 6241da177e4SLinus Torvalds tp->rcv_wnd && 6251da177e4SLinus Torvalds atomic_read(&sk->sk_rmem_alloc) < sk->sk_rcvbuf && 6261da177e4SLinus Torvalds !tp->urg_data) 6271da177e4SLinus Torvalds tcp_fast_path_on(tp); 6281da177e4SLinus Torvalds } 6291da177e4SLinus Torvalds 6300c266898SSatoru SATOH /* Compute the actual rto_min value */ 6310c266898SSatoru SATOH static inline u32 tcp_rto_min(struct sock *sk) 6320c266898SSatoru SATOH { 633cf533ea5SEric Dumazet const struct dst_entry *dst = __sk_dst_get(sk); 6340c266898SSatoru SATOH u32 rto_min = TCP_RTO_MIN; 6350c266898SSatoru SATOH 6360c266898SSatoru SATOH if (dst && dst_metric_locked(dst, RTAX_RTO_MIN)) 6370c266898SSatoru SATOH rto_min = dst_metric_rtt(dst, RTAX_RTO_MIN); 6380c266898SSatoru SATOH return rto_min; 6390c266898SSatoru SATOH } 6400c266898SSatoru SATOH 641740b0f18SEric Dumazet static inline u32 tcp_rto_min_us(struct sock *sk) 642740b0f18SEric Dumazet { 643740b0f18SEric Dumazet return jiffies_to_usecs(tcp_rto_min(sk)); 644740b0f18SEric Dumazet } 645740b0f18SEric Dumazet 6461da177e4SLinus Torvalds /* Compute the actual receive window we are currently advertising. 6471da177e4SLinus Torvalds * Rcv_nxt can be after the window if our peer push more data 6481da177e4SLinus Torvalds * than the offered window. 6491da177e4SLinus Torvalds */ 65040efc6faSStephen Hemminger static inline u32 tcp_receive_window(const struct tcp_sock *tp) 6511da177e4SLinus Torvalds { 6521da177e4SLinus Torvalds s32 win = tp->rcv_wup + tp->rcv_wnd - tp->rcv_nxt; 6531da177e4SLinus Torvalds 6541da177e4SLinus Torvalds if (win < 0) 6551da177e4SLinus Torvalds win = 0; 6561da177e4SLinus Torvalds return (u32) win; 6571da177e4SLinus Torvalds } 6581da177e4SLinus Torvalds 6591da177e4SLinus Torvalds /* Choose a new window, without checks for shrinking, and without 6601da177e4SLinus Torvalds * scaling applied to the result. The caller does these things 6611da177e4SLinus Torvalds * if necessary. This is a "raw" window selection. 6621da177e4SLinus Torvalds */ 6635c9f3023SJoe Perches u32 __tcp_select_window(struct sock *sk); 6641da177e4SLinus Torvalds 665ee995283SPavel Emelyanov void tcp_send_window_probe(struct sock *sk); 666ee995283SPavel Emelyanov 6671da177e4SLinus Torvalds /* TCP timestamps are only 32-bits, this causes a slight 6681da177e4SLinus Torvalds * complication on 64-bit systems since we store a snapshot 66931f34269SStephen Hemminger * of jiffies in the buffer control blocks below. We decided 67031f34269SStephen Hemminger * to use only the low 32-bits of jiffies and hide the ugly 6711da177e4SLinus Torvalds * casts with the following macro. 6721da177e4SLinus Torvalds */ 6731da177e4SLinus Torvalds #define tcp_time_stamp ((__u32)(jiffies)) 6741da177e4SLinus Torvalds 675*7faee5c0SEric Dumazet static inline u32 tcp_skb_timestamp(const struct sk_buff *skb) 676*7faee5c0SEric Dumazet { 677*7faee5c0SEric Dumazet return skb->skb_mstamp.stamp_jiffies; 678*7faee5c0SEric Dumazet } 679*7faee5c0SEric Dumazet 680*7faee5c0SEric Dumazet 681a3433f35SChangli Gao #define tcp_flag_byte(th) (((u_int8_t *)th)[13]) 682a3433f35SChangli Gao 683a3433f35SChangli Gao #define TCPHDR_FIN 0x01 684a3433f35SChangli Gao #define TCPHDR_SYN 0x02 685a3433f35SChangli Gao #define TCPHDR_RST 0x04 686a3433f35SChangli Gao #define TCPHDR_PSH 0x08 687a3433f35SChangli Gao #define TCPHDR_ACK 0x10 688a3433f35SChangli Gao #define TCPHDR_URG 0x20 689a3433f35SChangli Gao #define TCPHDR_ECE 0x40 690a3433f35SChangli Gao #define TCPHDR_CWR 0x80 691a3433f35SChangli Gao 692caa20d9aSStephen Hemminger /* This is what the send packet queuing engine uses to pass 693f86586faSEric Dumazet * TCP per-packet control information to the transmission code. 694f86586faSEric Dumazet * We also store the host-order sequence numbers in here too. 695f86586faSEric Dumazet * This is 44 bytes if IPV6 is enabled. 696f86586faSEric Dumazet * If this grows please adjust skbuff.h:skbuff->cb[xxx] size appropriately. 6971da177e4SLinus Torvalds */ 6981da177e4SLinus Torvalds struct tcp_skb_cb { 6991da177e4SLinus Torvalds union { 7001da177e4SLinus Torvalds struct inet_skb_parm h4; 701dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 7021da177e4SLinus Torvalds struct inet6_skb_parm h6; 7031da177e4SLinus Torvalds #endif 7041da177e4SLinus Torvalds } header; /* For incoming frames */ 7051da177e4SLinus Torvalds __u32 seq; /* Starting sequence number */ 7061da177e4SLinus Torvalds __u32 end_seq; /* SEQ + FIN + SYN + datalen */ 70704317dafSEric Dumazet __u32 tcp_tw_isn; /* isn chosen by tcp_timewait_state_process() */ 7084de075e0SEric Dumazet __u8 tcp_flags; /* TCP header flags. (tcp[13]) */ 709f4f9f6e7SNeal Cardwell 7101da177e4SLinus Torvalds __u8 sacked; /* State flags for SACK/FACK. */ 7111da177e4SLinus Torvalds #define TCPCB_SACKED_ACKED 0x01 /* SKB ACK'd by a SACK block */ 7121da177e4SLinus Torvalds #define TCPCB_SACKED_RETRANS 0x02 /* SKB retransmitted */ 7131da177e4SLinus Torvalds #define TCPCB_LOST 0x04 /* SKB is lost */ 7141da177e4SLinus Torvalds #define TCPCB_TAGBITS 0x07 /* All tag bits */ 7159d186cacSAndrey Vagin #define TCPCB_REPAIRED 0x10 /* SKB repaired (no skb_mstamp) */ 7161da177e4SLinus Torvalds #define TCPCB_EVER_RETRANS 0x80 /* Ever retransmitted frame */ 7179d186cacSAndrey Vagin #define TCPCB_RETRANS (TCPCB_SACKED_RETRANS|TCPCB_EVER_RETRANS| \ 7189d186cacSAndrey Vagin TCPCB_REPAIRED) 7191da177e4SLinus Torvalds 720f4f9f6e7SNeal Cardwell __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */ 721f4f9f6e7SNeal Cardwell /* 1 byte hole */ 7221da177e4SLinus Torvalds __u32 ack_seq; /* Sequence number ACK'd */ 7231da177e4SLinus Torvalds }; 7241da177e4SLinus Torvalds 7251da177e4SLinus Torvalds #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0])) 7261da177e4SLinus Torvalds 727bd14b1b2SEric Dumazet /* RFC3168 : 6.1.1 SYN packets must not have ECT/ECN bits set 728bd14b1b2SEric Dumazet * 729bd14b1b2SEric Dumazet * If we receive a SYN packet with these bits set, it means a network is 730bd14b1b2SEric Dumazet * playing bad games with TOS bits. In order to avoid possible false congestion 731bd14b1b2SEric Dumazet * notifications, we disable TCP ECN negociation. 732bd14b1b2SEric Dumazet */ 733bd14b1b2SEric Dumazet static inline void 7345d134f1cSHannes Frederic Sowa TCP_ECN_create_request(struct request_sock *req, const struct sk_buff *skb, 7355d134f1cSHannes Frederic Sowa struct net *net) 736bd14b1b2SEric Dumazet { 737bd14b1b2SEric Dumazet const struct tcphdr *th = tcp_hdr(skb); 738bd14b1b2SEric Dumazet 7395d134f1cSHannes Frederic Sowa if (net->ipv4.sysctl_tcp_ecn && th->ece && th->cwr && 740bd14b1b2SEric Dumazet INET_ECN_is_not_ect(TCP_SKB_CB(skb)->ip_dsfield)) 741bd14b1b2SEric Dumazet inet_rsk(req)->ecn_ok = 1; 742bd14b1b2SEric Dumazet } 743bd14b1b2SEric Dumazet 7441da177e4SLinus Torvalds /* Due to TSO, an SKB can be composed of multiple actual 7451da177e4SLinus Torvalds * packets. To keep these tracked properly, we use this. 7461da177e4SLinus Torvalds */ 7471da177e4SLinus Torvalds static inline int tcp_skb_pcount(const struct sk_buff *skb) 7481da177e4SLinus Torvalds { 7497967168cSHerbert Xu return skb_shinfo(skb)->gso_segs; 7501da177e4SLinus Torvalds } 7511da177e4SLinus Torvalds 7521da177e4SLinus Torvalds /* This is valid iff tcp_skb_pcount() > 1. */ 7531da177e4SLinus Torvalds static inline int tcp_skb_mss(const struct sk_buff *skb) 7541da177e4SLinus Torvalds { 7557967168cSHerbert Xu return skb_shinfo(skb)->gso_size; 7561da177e4SLinus Torvalds } 7571da177e4SLinus Torvalds 758317a76f9SStephen Hemminger /* Events passed to congestion control interface */ 759317a76f9SStephen Hemminger enum tcp_ca_event { 760317a76f9SStephen Hemminger CA_EVENT_TX_START, /* first transmit when no packets in flight */ 761317a76f9SStephen Hemminger CA_EVENT_CWND_RESTART, /* congestion window restart */ 762317a76f9SStephen Hemminger CA_EVENT_COMPLETE_CWR, /* end of congestion recovery */ 763317a76f9SStephen Hemminger CA_EVENT_LOSS, /* loss timeout */ 764317a76f9SStephen Hemminger CA_EVENT_FAST_ACK, /* in sequence ack */ 765317a76f9SStephen Hemminger CA_EVENT_SLOW_ACK, /* other ack */ 766317a76f9SStephen Hemminger }; 767317a76f9SStephen Hemminger 768317a76f9SStephen Hemminger /* 769317a76f9SStephen Hemminger * Interface for adding new TCP congestion control handlers 770317a76f9SStephen Hemminger */ 771317a76f9SStephen Hemminger #define TCP_CA_NAME_MAX 16 7723ff825b2SStephen Hemminger #define TCP_CA_MAX 128 7733ff825b2SStephen Hemminger #define TCP_CA_BUF_MAX (TCP_CA_NAME_MAX*TCP_CA_MAX) 7743ff825b2SStephen Hemminger 775164891aaSStephen Hemminger #define TCP_CONG_NON_RESTRICTED 0x1 776164891aaSStephen Hemminger 777317a76f9SStephen Hemminger struct tcp_congestion_ops { 778317a76f9SStephen Hemminger struct list_head list; 779164891aaSStephen Hemminger unsigned long flags; 780317a76f9SStephen Hemminger 781317a76f9SStephen Hemminger /* initialize private data (optional) */ 7826687e988SArnaldo Carvalho de Melo void (*init)(struct sock *sk); 783317a76f9SStephen Hemminger /* cleanup private data (optional) */ 7846687e988SArnaldo Carvalho de Melo void (*release)(struct sock *sk); 785317a76f9SStephen Hemminger 786317a76f9SStephen Hemminger /* return slow start threshold (required) */ 7876687e988SArnaldo Carvalho de Melo u32 (*ssthresh)(struct sock *sk); 788317a76f9SStephen Hemminger /* do new cwnd calculation (required) */ 78924901551SEric Dumazet void (*cong_avoid)(struct sock *sk, u32 ack, u32 acked); 790317a76f9SStephen Hemminger /* call before changing ca_state (optional) */ 7916687e988SArnaldo Carvalho de Melo void (*set_state)(struct sock *sk, u8 new_state); 792317a76f9SStephen Hemminger /* call when cwnd event occurs (optional) */ 7936687e988SArnaldo Carvalho de Melo void (*cwnd_event)(struct sock *sk, enum tcp_ca_event ev); 794317a76f9SStephen Hemminger /* new value of cwnd after loss (optional) */ 7956687e988SArnaldo Carvalho de Melo u32 (*undo_cwnd)(struct sock *sk); 796317a76f9SStephen Hemminger /* hook for packet ack accounting (optional) */ 79730cfd0baSStephen Hemminger void (*pkts_acked)(struct sock *sk, u32 num_acked, s32 rtt_us); 79873c1f4a0SArnaldo Carvalho de Melo /* get info for inet_diag (optional) */ 7996687e988SArnaldo Carvalho de Melo void (*get_info)(struct sock *sk, u32 ext, struct sk_buff *skb); 800317a76f9SStephen Hemminger 801317a76f9SStephen Hemminger char name[TCP_CA_NAME_MAX]; 802317a76f9SStephen Hemminger struct module *owner; 803317a76f9SStephen Hemminger }; 804317a76f9SStephen Hemminger 8055c9f3023SJoe Perches int tcp_register_congestion_control(struct tcp_congestion_ops *type); 8065c9f3023SJoe Perches void tcp_unregister_congestion_control(struct tcp_congestion_ops *type); 807317a76f9SStephen Hemminger 8085c9f3023SJoe Perches void tcp_init_congestion_control(struct sock *sk); 8095c9f3023SJoe Perches void tcp_cleanup_congestion_control(struct sock *sk); 8105c9f3023SJoe Perches int tcp_set_default_congestion_control(const char *name); 8115c9f3023SJoe Perches void tcp_get_default_congestion_control(char *name); 8125c9f3023SJoe Perches void tcp_get_available_congestion_control(char *buf, size_t len); 8135c9f3023SJoe Perches void tcp_get_allowed_congestion_control(char *buf, size_t len); 8145c9f3023SJoe Perches int tcp_set_allowed_congestion_control(char *allowed); 8155c9f3023SJoe Perches int tcp_set_congestion_control(struct sock *sk, const char *name); 8169f9843a7SYuchung Cheng int tcp_slow_start(struct tcp_sock *tp, u32 acked); 8175c9f3023SJoe Perches void tcp_cong_avoid_ai(struct tcp_sock *tp, u32 w); 818317a76f9SStephen Hemminger 8195f8ef48dSStephen Hemminger extern struct tcp_congestion_ops tcp_init_congestion_ops; 8205c9f3023SJoe Perches u32 tcp_reno_ssthresh(struct sock *sk); 82124901551SEric Dumazet void tcp_reno_cong_avoid(struct sock *sk, u32 ack, u32 acked); 822a8acfbacSDavid S. Miller extern struct tcp_congestion_ops tcp_reno; 823317a76f9SStephen Hemminger 8246687e988SArnaldo Carvalho de Melo static inline void tcp_set_ca_state(struct sock *sk, const u8 ca_state) 825317a76f9SStephen Hemminger { 8266687e988SArnaldo Carvalho de Melo struct inet_connection_sock *icsk = inet_csk(sk); 8276687e988SArnaldo Carvalho de Melo 8286687e988SArnaldo Carvalho de Melo if (icsk->icsk_ca_ops->set_state) 8296687e988SArnaldo Carvalho de Melo icsk->icsk_ca_ops->set_state(sk, ca_state); 8306687e988SArnaldo Carvalho de Melo icsk->icsk_ca_state = ca_state; 831317a76f9SStephen Hemminger } 832317a76f9SStephen Hemminger 8336687e988SArnaldo Carvalho de Melo static inline void tcp_ca_event(struct sock *sk, const enum tcp_ca_event event) 834317a76f9SStephen Hemminger { 8356687e988SArnaldo Carvalho de Melo const struct inet_connection_sock *icsk = inet_csk(sk); 8366687e988SArnaldo Carvalho de Melo 8376687e988SArnaldo Carvalho de Melo if (icsk->icsk_ca_ops->cwnd_event) 8386687e988SArnaldo Carvalho de Melo icsk->icsk_ca_ops->cwnd_event(sk, event); 839317a76f9SStephen Hemminger } 840317a76f9SStephen Hemminger 841e60402d0SIlpo Järvinen /* These functions determine how the current flow behaves in respect of SACK 842e60402d0SIlpo Järvinen * handling. SACK is negotiated with the peer, and therefore it can vary 843e60402d0SIlpo Järvinen * between different flows. 844e60402d0SIlpo Järvinen * 845e60402d0SIlpo Järvinen * tcp_is_sack - SACK enabled 846e60402d0SIlpo Järvinen * tcp_is_reno - No SACK 847e60402d0SIlpo Järvinen * tcp_is_fack - FACK enabled, implies SACK enabled 848e60402d0SIlpo Järvinen */ 849e60402d0SIlpo Järvinen static inline int tcp_is_sack(const struct tcp_sock *tp) 850e60402d0SIlpo Järvinen { 851e60402d0SIlpo Järvinen return tp->rx_opt.sack_ok; 852e60402d0SIlpo Järvinen } 853e60402d0SIlpo Järvinen 854a2a385d6SEric Dumazet static inline bool tcp_is_reno(const struct tcp_sock *tp) 855e60402d0SIlpo Järvinen { 856e60402d0SIlpo Järvinen return !tcp_is_sack(tp); 857e60402d0SIlpo Järvinen } 858e60402d0SIlpo Järvinen 859a2a385d6SEric Dumazet static inline bool tcp_is_fack(const struct tcp_sock *tp) 860e60402d0SIlpo Järvinen { 861ab56222aSVijay Subramanian return tp->rx_opt.sack_ok & TCP_FACK_ENABLED; 862e60402d0SIlpo Järvinen } 863e60402d0SIlpo Järvinen 864e60402d0SIlpo Järvinen static inline void tcp_enable_fack(struct tcp_sock *tp) 865e60402d0SIlpo Järvinen { 866ab56222aSVijay Subramanian tp->rx_opt.sack_ok |= TCP_FACK_ENABLED; 867e60402d0SIlpo Järvinen } 868e60402d0SIlpo Järvinen 869eed530b6SYuchung Cheng /* TCP early-retransmit (ER) is similar to but more conservative than 870eed530b6SYuchung Cheng * the thin-dupack feature. Enable ER only if thin-dupack is disabled. 871eed530b6SYuchung Cheng */ 872eed530b6SYuchung Cheng static inline void tcp_enable_early_retrans(struct tcp_sock *tp) 873eed530b6SYuchung Cheng { 874eed530b6SYuchung Cheng tp->do_early_retrans = sysctl_tcp_early_retrans && 8756ba8a3b1SNandita Dukkipati sysctl_tcp_early_retrans < 4 && !sysctl_tcp_thin_dupack && 8766ba8a3b1SNandita Dukkipati sysctl_tcp_reordering == 3; 877eed530b6SYuchung Cheng } 878eed530b6SYuchung Cheng 879eed530b6SYuchung Cheng static inline void tcp_disable_early_retrans(struct tcp_sock *tp) 880eed530b6SYuchung Cheng { 881eed530b6SYuchung Cheng tp->do_early_retrans = 0; 882eed530b6SYuchung Cheng } 883eed530b6SYuchung Cheng 88483ae4088SIlpo Järvinen static inline unsigned int tcp_left_out(const struct tcp_sock *tp) 88583ae4088SIlpo Järvinen { 88683ae4088SIlpo Järvinen return tp->sacked_out + tp->lost_out; 88783ae4088SIlpo Järvinen } 88883ae4088SIlpo Järvinen 8891da177e4SLinus Torvalds /* This determines how many packets are "in the network" to the best 8901da177e4SLinus Torvalds * of our knowledge. In many cases it is conservative, but where 8911da177e4SLinus Torvalds * detailed information is available from the receiver (via SACK 8921da177e4SLinus Torvalds * blocks etc.) we can make more aggressive calculations. 8931da177e4SLinus Torvalds * 8941da177e4SLinus Torvalds * Use this for decisions involving congestion control, use just 8951da177e4SLinus Torvalds * tp->packets_out to determine if the send queue is empty or not. 8961da177e4SLinus Torvalds * 8971da177e4SLinus Torvalds * Read this equation as: 8981da177e4SLinus Torvalds * 8991da177e4SLinus Torvalds * "Packets sent once on transmission queue" MINUS 9001da177e4SLinus Torvalds * "Packets left network, but not honestly ACKed yet" PLUS 9011da177e4SLinus Torvalds * "Packets fast retransmitted" 9021da177e4SLinus Torvalds */ 90340efc6faSStephen Hemminger static inline unsigned int tcp_packets_in_flight(const struct tcp_sock *tp) 9041da177e4SLinus Torvalds { 90583ae4088SIlpo Järvinen return tp->packets_out - tcp_left_out(tp) + tp->retrans_out; 9061da177e4SLinus Torvalds } 9071da177e4SLinus Torvalds 9080b6a05c1SIlpo Järvinen #define TCP_INFINITE_SSTHRESH 0x7fffffff 9090b6a05c1SIlpo Järvinen 9100b6a05c1SIlpo Järvinen static inline bool tcp_in_initial_slowstart(const struct tcp_sock *tp) 9110b6a05c1SIlpo Järvinen { 9120b6a05c1SIlpo Järvinen return tp->snd_ssthresh >= TCP_INFINITE_SSTHRESH; 9130b6a05c1SIlpo Järvinen } 9140b6a05c1SIlpo Järvinen 915684bad11SYuchung Cheng static inline bool tcp_in_cwnd_reduction(const struct sock *sk) 916684bad11SYuchung Cheng { 917684bad11SYuchung Cheng return (TCPF_CA_CWR | TCPF_CA_Recovery) & 918684bad11SYuchung Cheng (1 << inet_csk(sk)->icsk_ca_state); 919684bad11SYuchung Cheng } 920684bad11SYuchung Cheng 9211da177e4SLinus Torvalds /* If cwnd > ssthresh, we may raise ssthresh to be half-way to cwnd. 922684bad11SYuchung Cheng * The exception is cwnd reduction phase, when cwnd is decreasing towards 9231da177e4SLinus Torvalds * ssthresh. 9241da177e4SLinus Torvalds */ 9256687e988SArnaldo Carvalho de Melo static inline __u32 tcp_current_ssthresh(const struct sock *sk) 9261da177e4SLinus Torvalds { 9276687e988SArnaldo Carvalho de Melo const struct tcp_sock *tp = tcp_sk(sk); 928cf533ea5SEric Dumazet 929684bad11SYuchung Cheng if (tcp_in_cwnd_reduction(sk)) 9301da177e4SLinus Torvalds return tp->snd_ssthresh; 9311da177e4SLinus Torvalds else 9321da177e4SLinus Torvalds return max(tp->snd_ssthresh, 9331da177e4SLinus Torvalds ((tp->snd_cwnd >> 1) + 9341da177e4SLinus Torvalds (tp->snd_cwnd >> 2))); 9351da177e4SLinus Torvalds } 9361da177e4SLinus Torvalds 937b9c4595bSIlpo Järvinen /* Use define here intentionally to get WARN_ON location shown at the caller */ 938b9c4595bSIlpo Järvinen #define tcp_verify_left_out(tp) WARN_ON(tcp_left_out(tp) > tp->packets_out) 9391da177e4SLinus Torvalds 9405ee2c941SChristoph Paasch void tcp_enter_cwr(struct sock *sk); 9415c9f3023SJoe Perches __u32 tcp_init_cwnd(const struct tcp_sock *tp, const struct dst_entry *dst); 9421da177e4SLinus Torvalds 9436b5a5c0dSNeal Cardwell /* The maximum number of MSS of available cwnd for which TSO defers 9446b5a5c0dSNeal Cardwell * sending if not using sysctl_tcp_tso_win_divisor. 9456b5a5c0dSNeal Cardwell */ 9466b5a5c0dSNeal Cardwell static inline __u32 tcp_max_tso_deferred_mss(const struct tcp_sock *tp) 9476b5a5c0dSNeal Cardwell { 9486b5a5c0dSNeal Cardwell return 3; 9496b5a5c0dSNeal Cardwell } 9506b5a5c0dSNeal Cardwell 9511da177e4SLinus Torvalds /* Slow start with delack produces 3 packets of burst, so that 952dd9e0ddaSJohn Heffner * it is safe "de facto". This will be the default - same as 953dd9e0ddaSJohn Heffner * the default reordering threshold - but if reordering increases, 954dd9e0ddaSJohn Heffner * we must be able to allow cwnd to burst at least this much in order 955dd9e0ddaSJohn Heffner * to not pull it back when holes are filled. 9561da177e4SLinus Torvalds */ 9571da177e4SLinus Torvalds static __inline__ __u32 tcp_max_burst(const struct tcp_sock *tp) 9581da177e4SLinus Torvalds { 959dd9e0ddaSJohn Heffner return tp->reordering; 9601da177e4SLinus Torvalds } 9611da177e4SLinus Torvalds 96290840defSIlpo Järvinen /* Returns end sequence number of the receiver's advertised window */ 96390840defSIlpo Järvinen static inline u32 tcp_wnd_end(const struct tcp_sock *tp) 96490840defSIlpo Järvinen { 96590840defSIlpo Järvinen return tp->snd_una + tp->snd_wnd; 96690840defSIlpo Järvinen } 967e114a710SEric Dumazet 968e114a710SEric Dumazet /* We follow the spirit of RFC2861 to validate cwnd but implement a more 969e114a710SEric Dumazet * flexible approach. The RFC suggests cwnd should not be raised unless 970ca8a2263SNeal Cardwell * it was fully used previously. And that's exactly what we do in 971ca8a2263SNeal Cardwell * congestion avoidance mode. But in slow start we allow cwnd to grow 972ca8a2263SNeal Cardwell * as long as the application has used half the cwnd. 973e114a710SEric Dumazet * Example : 974e114a710SEric Dumazet * cwnd is 10 (IW10), but application sends 9 frames. 975e114a710SEric Dumazet * We allow cwnd to reach 18 when all frames are ACKed. 976e114a710SEric Dumazet * This check is safe because it's as aggressive as slow start which already 977e114a710SEric Dumazet * risks 100% overshoot. The advantage is that we discourage application to 978e114a710SEric Dumazet * either send more filler packets or data to artificially blow up the cwnd 979e114a710SEric Dumazet * usage, and allow application-limited process to probe bw more aggressively. 980e114a710SEric Dumazet */ 98124901551SEric Dumazet static inline bool tcp_is_cwnd_limited(const struct sock *sk) 982e114a710SEric Dumazet { 983e114a710SEric Dumazet const struct tcp_sock *tp = tcp_sk(sk); 984e114a710SEric Dumazet 985ca8a2263SNeal Cardwell /* If in slow start, ensure cwnd grows to twice what was ACKed. */ 986ca8a2263SNeal Cardwell if (tp->snd_cwnd <= tp->snd_ssthresh) 987ca8a2263SNeal Cardwell return tp->snd_cwnd < 2 * tp->max_packets_out; 988ca8a2263SNeal Cardwell 989ca8a2263SNeal Cardwell return tp->is_cwnd_limited; 990e114a710SEric Dumazet } 991f4805edeSStephen Hemminger 9929e412ba7SIlpo Järvinen static inline void tcp_check_probe_timer(struct sock *sk) 9931da177e4SLinus Torvalds { 994cf533ea5SEric Dumazet const struct tcp_sock *tp = tcp_sk(sk); 995463c84b9SArnaldo Carvalho de Melo const struct inet_connection_sock *icsk = inet_csk(sk); 9969e412ba7SIlpo Järvinen 997463c84b9SArnaldo Carvalho de Melo if (!tp->packets_out && !icsk->icsk_pending) 9983f421baaSArnaldo Carvalho de Melo inet_csk_reset_xmit_timer(sk, ICSK_TIME_PROBE0, 9993f421baaSArnaldo Carvalho de Melo icsk->icsk_rto, TCP_RTO_MAX); 10001da177e4SLinus Torvalds } 10011da177e4SLinus Torvalds 1002ee7537b6SHantzis Fotis static inline void tcp_init_wl(struct tcp_sock *tp, u32 seq) 10031da177e4SLinus Torvalds { 10041da177e4SLinus Torvalds tp->snd_wl1 = seq; 10051da177e4SLinus Torvalds } 10061da177e4SLinus Torvalds 1007ee7537b6SHantzis Fotis static inline void tcp_update_wl(struct tcp_sock *tp, u32 seq) 10081da177e4SLinus Torvalds { 10091da177e4SLinus Torvalds tp->snd_wl1 = seq; 10101da177e4SLinus Torvalds } 10111da177e4SLinus Torvalds 10121da177e4SLinus Torvalds /* 10131da177e4SLinus Torvalds * Calculate(/check) TCP checksum 10141da177e4SLinus Torvalds */ 1015ba7808eaSFrederik Deweerdt static inline __sum16 tcp_v4_check(int len, __be32 saddr, 1016ba7808eaSFrederik Deweerdt __be32 daddr, __wsum base) 10171da177e4SLinus Torvalds { 10181da177e4SLinus Torvalds return csum_tcpudp_magic(saddr,daddr,len,IPPROTO_TCP,base); 10191da177e4SLinus Torvalds } 10201da177e4SLinus Torvalds 1021b51655b9SAl Viro static inline __sum16 __tcp_checksum_complete(struct sk_buff *skb) 10221da177e4SLinus Torvalds { 1023fb286bb2SHerbert Xu return __skb_checksum_complete(skb); 10241da177e4SLinus Torvalds } 10251da177e4SLinus Torvalds 1026a2a385d6SEric Dumazet static inline bool tcp_checksum_complete(struct sk_buff *skb) 10271da177e4SLinus Torvalds { 102860476372SHerbert Xu return !skb_csum_unnecessary(skb) && 10291da177e4SLinus Torvalds __tcp_checksum_complete(skb); 10301da177e4SLinus Torvalds } 10311da177e4SLinus Torvalds 10321da177e4SLinus Torvalds /* Prequeue for VJ style copy to user, combined with checksumming. */ 10331da177e4SLinus Torvalds 103440efc6faSStephen Hemminger static inline void tcp_prequeue_init(struct tcp_sock *tp) 10351da177e4SLinus Torvalds { 10361da177e4SLinus Torvalds tp->ucopy.task = NULL; 10371da177e4SLinus Torvalds tp->ucopy.len = 0; 10381da177e4SLinus Torvalds tp->ucopy.memory = 0; 10391da177e4SLinus Torvalds skb_queue_head_init(&tp->ucopy.prequeue); 104097fc2f08SChris Leech #ifdef CONFIG_NET_DMA 104197fc2f08SChris Leech tp->ucopy.dma_chan = NULL; 104297fc2f08SChris Leech tp->ucopy.wakeup = 0; 104397fc2f08SChris Leech tp->ucopy.pinned_list = NULL; 104497fc2f08SChris Leech tp->ucopy.dma_cookie = 0; 104597fc2f08SChris Leech #endif 10461da177e4SLinus Torvalds } 10471da177e4SLinus Torvalds 10485c9f3023SJoe Perches bool tcp_prequeue(struct sock *sk, struct sk_buff *skb); 10491da177e4SLinus Torvalds 10501da177e4SLinus Torvalds #undef STATE_TRACE 10511da177e4SLinus Torvalds 10521da177e4SLinus Torvalds #ifdef STATE_TRACE 10531da177e4SLinus Torvalds static const char *statename[]={ 10541da177e4SLinus Torvalds "Unused","Established","Syn Sent","Syn Recv", 10551da177e4SLinus Torvalds "Fin Wait 1","Fin Wait 2","Time Wait", "Close", 10561da177e4SLinus Torvalds "Close Wait","Last ACK","Listen","Closing" 10571da177e4SLinus Torvalds }; 10581da177e4SLinus Torvalds #endif 10595c9f3023SJoe Perches void tcp_set_state(struct sock *sk, int state); 10601da177e4SLinus Torvalds 10615c9f3023SJoe Perches void tcp_done(struct sock *sk); 10621da177e4SLinus Torvalds 106340efc6faSStephen Hemminger static inline void tcp_sack_reset(struct tcp_options_received *rx_opt) 10641da177e4SLinus Torvalds { 10651da177e4SLinus Torvalds rx_opt->dsack = 0; 10661da177e4SLinus Torvalds rx_opt->num_sacks = 0; 10671da177e4SLinus Torvalds } 10681da177e4SLinus Torvalds 10695c9f3023SJoe Perches u32 tcp_default_init_rwnd(u32 mss); 107085f16525SYuchung Cheng 10711da177e4SLinus Torvalds /* Determine a window scaling and initial window to offer. */ 10725c9f3023SJoe Perches void tcp_select_initial_window(int __space, __u32 mss, __u32 *rcv_wnd, 10735c9f3023SJoe Perches __u32 *window_clamp, int wscale_ok, 10745c9f3023SJoe Perches __u8 *rcv_wscale, __u32 init_rcv_wnd); 10751da177e4SLinus Torvalds 10761da177e4SLinus Torvalds static inline int tcp_win_from_space(int space) 10771da177e4SLinus Torvalds { 10781da177e4SLinus Torvalds return sysctl_tcp_adv_win_scale<=0 ? 10791da177e4SLinus Torvalds (space>>(-sysctl_tcp_adv_win_scale)) : 10801da177e4SLinus Torvalds space - (space>>sysctl_tcp_adv_win_scale); 10811da177e4SLinus Torvalds } 10821da177e4SLinus Torvalds 10831da177e4SLinus Torvalds /* Note: caller must be prepared to deal with negative returns */ 10841da177e4SLinus Torvalds static inline int tcp_space(const struct sock *sk) 10851da177e4SLinus Torvalds { 10861da177e4SLinus Torvalds return tcp_win_from_space(sk->sk_rcvbuf - 10871da177e4SLinus Torvalds atomic_read(&sk->sk_rmem_alloc)); 10881da177e4SLinus Torvalds } 10891da177e4SLinus Torvalds 10901da177e4SLinus Torvalds static inline int tcp_full_space(const struct sock *sk) 10911da177e4SLinus Torvalds { 10921da177e4SLinus Torvalds return tcp_win_from_space(sk->sk_rcvbuf); 10931da177e4SLinus Torvalds } 10941da177e4SLinus Torvalds 109540efc6faSStephen Hemminger static inline void tcp_openreq_init(struct request_sock *req, 10961da177e4SLinus Torvalds struct tcp_options_received *rx_opt, 1097e0f802fbSOctavian Purdila struct sk_buff *skb, struct sock *sk) 10981da177e4SLinus Torvalds { 10992e6599cbSArnaldo Carvalho de Melo struct inet_request_sock *ireq = inet_rsk(req); 11002e6599cbSArnaldo Carvalho de Melo 11011da177e4SLinus Torvalds req->rcv_wnd = 0; /* So that tcp_send_synack() knows! */ 11024dfc2817SFlorian Westphal req->cookie_ts = 0; 11032e6599cbSArnaldo Carvalho de Melo tcp_rsk(req)->rcv_isn = TCP_SKB_CB(skb)->seq; 110410467163SJerry Chu tcp_rsk(req)->rcv_nxt = TCP_SKB_CB(skb)->seq + 1; 110586c6a2c7SNeal Cardwell tcp_rsk(req)->snt_synack = tcp_time_stamp; 11061da177e4SLinus Torvalds req->mss = rx_opt->mss_clamp; 11071da177e4SLinus Torvalds req->ts_recent = rx_opt->saw_tstamp ? rx_opt->rcv_tsval : 0; 11082e6599cbSArnaldo Carvalho de Melo ireq->tstamp_ok = rx_opt->tstamp_ok; 11092e6599cbSArnaldo Carvalho de Melo ireq->sack_ok = rx_opt->sack_ok; 11102e6599cbSArnaldo Carvalho de Melo ireq->snd_wscale = rx_opt->snd_wscale; 11112e6599cbSArnaldo Carvalho de Melo ireq->wscale_ok = rx_opt->wscale_ok; 11122e6599cbSArnaldo Carvalho de Melo ireq->acked = 0; 11132e6599cbSArnaldo Carvalho de Melo ireq->ecn_ok = 0; 1114634fb979SEric Dumazet ireq->ir_rmt_port = tcp_hdr(skb)->source; 1115b44084c2SEric Dumazet ireq->ir_num = ntohs(tcp_hdr(skb)->dest); 1116e0f802fbSOctavian Purdila ireq->ir_mark = inet_request_mark(sk, skb); 11171da177e4SLinus Torvalds } 11181da177e4SLinus Torvalds 1119843f4a55SYuchung Cheng extern void tcp_openreq_init_rwin(struct request_sock *req, 1120843f4a55SYuchung Cheng struct sock *sk, struct dst_entry *dst); 1121843f4a55SYuchung Cheng 11225c9f3023SJoe Perches void tcp_enter_memory_pressure(struct sock *sk); 11231da177e4SLinus Torvalds 11241da177e4SLinus Torvalds static inline int keepalive_intvl_when(const struct tcp_sock *tp) 11251da177e4SLinus Torvalds { 11261da177e4SLinus Torvalds return tp->keepalive_intvl ? : sysctl_tcp_keepalive_intvl; 11271da177e4SLinus Torvalds } 11281da177e4SLinus Torvalds 11291da177e4SLinus Torvalds static inline int keepalive_time_when(const struct tcp_sock *tp) 11301da177e4SLinus Torvalds { 11311da177e4SLinus Torvalds return tp->keepalive_time ? : sysctl_tcp_keepalive_time; 11321da177e4SLinus Torvalds } 11331da177e4SLinus Torvalds 1134df19a626SEric Dumazet static inline int keepalive_probes(const struct tcp_sock *tp) 1135df19a626SEric Dumazet { 1136df19a626SEric Dumazet return tp->keepalive_probes ? : sysctl_tcp_keepalive_probes; 1137df19a626SEric Dumazet } 1138df19a626SEric Dumazet 11396c37e5deSFlavio Leitner static inline u32 keepalive_time_elapsed(const struct tcp_sock *tp) 11406c37e5deSFlavio Leitner { 11416c37e5deSFlavio Leitner const struct inet_connection_sock *icsk = &tp->inet_conn; 11426c37e5deSFlavio Leitner 11436c37e5deSFlavio Leitner return min_t(u32, tcp_time_stamp - icsk->icsk_ack.lrcvtime, 11446c37e5deSFlavio Leitner tcp_time_stamp - tp->rcv_tstamp); 11456c37e5deSFlavio Leitner } 11466c37e5deSFlavio Leitner 1147463c84b9SArnaldo Carvalho de Melo static inline int tcp_fin_time(const struct sock *sk) 11481da177e4SLinus Torvalds { 1149463c84b9SArnaldo Carvalho de Melo int fin_timeout = tcp_sk(sk)->linger2 ? : sysctl_tcp_fin_timeout; 1150463c84b9SArnaldo Carvalho de Melo const int rto = inet_csk(sk)->icsk_rto; 11511da177e4SLinus Torvalds 1152463c84b9SArnaldo Carvalho de Melo if (fin_timeout < (rto << 2) - (rto >> 1)) 1153463c84b9SArnaldo Carvalho de Melo fin_timeout = (rto << 2) - (rto >> 1); 11541da177e4SLinus Torvalds 11551da177e4SLinus Torvalds return fin_timeout; 11561da177e4SLinus Torvalds } 11571da177e4SLinus Torvalds 1158a2a385d6SEric Dumazet static inline bool tcp_paws_check(const struct tcp_options_received *rx_opt, 1159c887e6d2SIlpo Järvinen int paws_win) 11601da177e4SLinus Torvalds { 1161c887e6d2SIlpo Järvinen if ((s32)(rx_opt->ts_recent - rx_opt->rcv_tsval) <= paws_win) 1162a2a385d6SEric Dumazet return true; 1163c887e6d2SIlpo Järvinen if (unlikely(get_seconds() >= rx_opt->ts_recent_stamp + TCP_PAWS_24DAYS)) 1164a2a385d6SEric Dumazet return true; 1165bc2ce894SEric Dumazet /* 1166bc2ce894SEric Dumazet * Some OSes send SYN and SYNACK messages with tsval=0 tsecr=0, 1167bc2ce894SEric Dumazet * then following tcp messages have valid values. Ignore 0 value, 1168bc2ce894SEric Dumazet * or else 'negative' tsval might forbid us to accept their packets. 1169bc2ce894SEric Dumazet */ 1170bc2ce894SEric Dumazet if (!rx_opt->ts_recent) 1171a2a385d6SEric Dumazet return true; 1172a2a385d6SEric Dumazet return false; 1173c887e6d2SIlpo Järvinen } 1174c887e6d2SIlpo Järvinen 1175a2a385d6SEric Dumazet static inline bool tcp_paws_reject(const struct tcp_options_received *rx_opt, 1176c887e6d2SIlpo Järvinen int rst) 1177c887e6d2SIlpo Järvinen { 1178c887e6d2SIlpo Järvinen if (tcp_paws_check(rx_opt, 0)) 1179a2a385d6SEric Dumazet return false; 11801da177e4SLinus Torvalds 11811da177e4SLinus Torvalds /* RST segments are not recommended to carry timestamp, 11821da177e4SLinus Torvalds and, if they do, it is recommended to ignore PAWS because 11831da177e4SLinus Torvalds "their cleanup function should take precedence over timestamps." 11841da177e4SLinus Torvalds Certainly, it is mistake. It is necessary to understand the reasons 11851da177e4SLinus Torvalds of this constraint to relax it: if peer reboots, clock may go 11861da177e4SLinus Torvalds out-of-sync and half-open connections will not be reset. 11871da177e4SLinus Torvalds Actually, the problem would be not existing if all 11881da177e4SLinus Torvalds the implementations followed draft about maintaining clock 11891da177e4SLinus Torvalds via reboots. Linux-2.2 DOES NOT! 11901da177e4SLinus Torvalds 11911da177e4SLinus Torvalds However, we can relax time bounds for RST segments to MSL. 11921da177e4SLinus Torvalds */ 11939d729f72SJames Morris if (rst && get_seconds() >= rx_opt->ts_recent_stamp + TCP_PAWS_MSL) 1194a2a385d6SEric Dumazet return false; 1195a2a385d6SEric Dumazet return true; 11961da177e4SLinus Torvalds } 11971da177e4SLinus Torvalds 1198a9c19329SPavel Emelyanov static inline void tcp_mib_init(struct net *net) 11991da177e4SLinus Torvalds { 12001da177e4SLinus Torvalds /* See RFC 2012 */ 1201cf1100a7SPavel Emelyanov TCP_ADD_STATS_USER(net, TCP_MIB_RTOALGORITHM, 1); 1202cf1100a7SPavel Emelyanov TCP_ADD_STATS_USER(net, TCP_MIB_RTOMIN, TCP_RTO_MIN*1000/HZ); 1203cf1100a7SPavel Emelyanov TCP_ADD_STATS_USER(net, TCP_MIB_RTOMAX, TCP_RTO_MAX*1000/HZ); 1204cf1100a7SPavel Emelyanov TCP_ADD_STATS_USER(net, TCP_MIB_MAXCONN, -1); 12051da177e4SLinus Torvalds } 12061da177e4SLinus Torvalds 12076a438bbeSStephen Hemminger /* from STCP */ 1208ef9da47cSIlpo Järvinen static inline void tcp_clear_retrans_hints_partial(struct tcp_sock *tp) 12090800f170SDavid S. Miller { 12106a438bbeSStephen Hemminger tp->lost_skb_hint = NULL; 1211ef9da47cSIlpo Järvinen } 1212ef9da47cSIlpo Järvinen 1213ef9da47cSIlpo Järvinen static inline void tcp_clear_all_retrans_hints(struct tcp_sock *tp) 1214ef9da47cSIlpo Järvinen { 1215ef9da47cSIlpo Järvinen tcp_clear_retrans_hints_partial(tp); 12166a438bbeSStephen Hemminger tp->retransmit_skb_hint = NULL; 1217b7689205SIlpo Järvinen } 1218b7689205SIlpo Järvinen 1219cfb6eeb4SYOSHIFUJI Hideaki /* MD5 Signature */ 1220cfb6eeb4SYOSHIFUJI Hideaki struct crypto_hash; 1221cfb6eeb4SYOSHIFUJI Hideaki 1222a915da9bSEric Dumazet union tcp_md5_addr { 1223a915da9bSEric Dumazet struct in_addr a4; 1224a915da9bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 1225a915da9bSEric Dumazet struct in6_addr a6; 1226a915da9bSEric Dumazet #endif 1227a915da9bSEric Dumazet }; 1228a915da9bSEric Dumazet 1229cfb6eeb4SYOSHIFUJI Hideaki /* - key database */ 1230cfb6eeb4SYOSHIFUJI Hideaki struct tcp_md5sig_key { 1231a915da9bSEric Dumazet struct hlist_node node; 1232cfb6eeb4SYOSHIFUJI Hideaki u8 keylen; 1233a915da9bSEric Dumazet u8 family; /* AF_INET or AF_INET6 */ 1234a915da9bSEric Dumazet union tcp_md5_addr addr; 1235a915da9bSEric Dumazet u8 key[TCP_MD5SIG_MAXKEYLEN]; 1236a915da9bSEric Dumazet struct rcu_head rcu; 1237cfb6eeb4SYOSHIFUJI Hideaki }; 1238cfb6eeb4SYOSHIFUJI Hideaki 1239cfb6eeb4SYOSHIFUJI Hideaki /* - sock block */ 1240cfb6eeb4SYOSHIFUJI Hideaki struct tcp_md5sig_info { 1241a915da9bSEric Dumazet struct hlist_head head; 1242a8afca03SEric Dumazet struct rcu_head rcu; 1243cfb6eeb4SYOSHIFUJI Hideaki }; 1244cfb6eeb4SYOSHIFUJI Hideaki 1245cfb6eeb4SYOSHIFUJI Hideaki /* - pseudo header */ 1246cfb6eeb4SYOSHIFUJI Hideaki struct tcp4_pseudohdr { 1247cfb6eeb4SYOSHIFUJI Hideaki __be32 saddr; 1248cfb6eeb4SYOSHIFUJI Hideaki __be32 daddr; 1249cfb6eeb4SYOSHIFUJI Hideaki __u8 pad; 1250cfb6eeb4SYOSHIFUJI Hideaki __u8 protocol; 1251cfb6eeb4SYOSHIFUJI Hideaki __be16 len; 1252cfb6eeb4SYOSHIFUJI Hideaki }; 1253cfb6eeb4SYOSHIFUJI Hideaki 1254cfb6eeb4SYOSHIFUJI Hideaki struct tcp6_pseudohdr { 1255cfb6eeb4SYOSHIFUJI Hideaki struct in6_addr saddr; 1256cfb6eeb4SYOSHIFUJI Hideaki struct in6_addr daddr; 1257cfb6eeb4SYOSHIFUJI Hideaki __be32 len; 1258cfb6eeb4SYOSHIFUJI Hideaki __be32 protocol; /* including padding */ 1259cfb6eeb4SYOSHIFUJI Hideaki }; 1260cfb6eeb4SYOSHIFUJI Hideaki 1261cfb6eeb4SYOSHIFUJI Hideaki union tcp_md5sum_block { 1262cfb6eeb4SYOSHIFUJI Hideaki struct tcp4_pseudohdr ip4; 1263dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 1264cfb6eeb4SYOSHIFUJI Hideaki struct tcp6_pseudohdr ip6; 1265cfb6eeb4SYOSHIFUJI Hideaki #endif 1266cfb6eeb4SYOSHIFUJI Hideaki }; 1267cfb6eeb4SYOSHIFUJI Hideaki 1268cfb6eeb4SYOSHIFUJI Hideaki /* - pool: digest algorithm, hash description and scratch buffer */ 1269cfb6eeb4SYOSHIFUJI Hideaki struct tcp_md5sig_pool { 1270cfb6eeb4SYOSHIFUJI Hideaki struct hash_desc md5_desc; 1271cfb6eeb4SYOSHIFUJI Hideaki union tcp_md5sum_block md5_blk; 1272cfb6eeb4SYOSHIFUJI Hideaki }; 1273cfb6eeb4SYOSHIFUJI Hideaki 1274cfb6eeb4SYOSHIFUJI Hideaki /* - functions */ 12755c9f3023SJoe Perches int tcp_v4_md5_hash_skb(char *md5_hash, struct tcp_md5sig_key *key, 12765c9f3023SJoe Perches const struct sock *sk, const struct request_sock *req, 1277318cf7aaSEric Dumazet const struct sk_buff *skb); 12785c9f3023SJoe Perches int tcp_md5_do_add(struct sock *sk, const union tcp_md5_addr *addr, 12795c9f3023SJoe Perches int family, const u8 *newkey, u8 newkeylen, gfp_t gfp); 12805c9f3023SJoe Perches int tcp_md5_do_del(struct sock *sk, const union tcp_md5_addr *addr, 1281a915da9bSEric Dumazet int family); 12825c9f3023SJoe Perches struct tcp_md5sig_key *tcp_v4_md5_lookup(struct sock *sk, 1283cfb6eeb4SYOSHIFUJI Hideaki struct sock *addr_sk); 1284cfb6eeb4SYOSHIFUJI Hideaki 12859501f972SYOSHIFUJI Hideaki #ifdef CONFIG_TCP_MD5SIG 12865c9f3023SJoe Perches struct tcp_md5sig_key *tcp_md5_do_lookup(struct sock *sk, 12875c9f3023SJoe Perches const union tcp_md5_addr *addr, 12885c9f3023SJoe Perches int family); 1289a915da9bSEric Dumazet #define tcp_twsk_md5_key(twsk) ((twsk)->tw_md5_key) 12909501f972SYOSHIFUJI Hideaki #else 1291a915da9bSEric Dumazet static inline struct tcp_md5sig_key *tcp_md5_do_lookup(struct sock *sk, 1292a915da9bSEric Dumazet const union tcp_md5_addr *addr, 1293a915da9bSEric Dumazet int family) 1294a915da9bSEric Dumazet { 1295a915da9bSEric Dumazet return NULL; 1296a915da9bSEric Dumazet } 12979501f972SYOSHIFUJI Hideaki #define tcp_twsk_md5_key(twsk) NULL 12989501f972SYOSHIFUJI Hideaki #endif 12999501f972SYOSHIFUJI Hideaki 13005c9f3023SJoe Perches bool tcp_alloc_md5sig_pool(void); 1301cfb6eeb4SYOSHIFUJI Hideaki 13025c9f3023SJoe Perches struct tcp_md5sig_pool *tcp_get_md5sig_pool(void); 130371cea17eSEric Dumazet static inline void tcp_put_md5sig_pool(void) 130471cea17eSEric Dumazet { 130571cea17eSEric Dumazet local_bh_enable(); 130671cea17eSEric Dumazet } 130735790c04SEric Dumazet 13085c9f3023SJoe Perches int tcp_md5_hash_header(struct tcp_md5sig_pool *, const struct tcphdr *); 13095c9f3023SJoe Perches int tcp_md5_hash_skb_data(struct tcp_md5sig_pool *, const struct sk_buff *, 131095c96174SEric Dumazet unsigned int header_len); 13115c9f3023SJoe Perches int tcp_md5_hash_key(struct tcp_md5sig_pool *hp, 1312cf533ea5SEric Dumazet const struct tcp_md5sig_key *key); 1313cfb6eeb4SYOSHIFUJI Hideaki 131410467163SJerry Chu /* From tcp_fastopen.c */ 13155c9f3023SJoe Perches void tcp_fastopen_cache_get(struct sock *sk, u16 *mss, 13165c9f3023SJoe Perches struct tcp_fastopen_cookie *cookie, int *syn_loss, 13175c9f3023SJoe Perches unsigned long *last_syn_loss); 13185c9f3023SJoe Perches void tcp_fastopen_cache_set(struct sock *sk, u16 mss, 13195c9f3023SJoe Perches struct tcp_fastopen_cookie *cookie, bool syn_lost); 1320783237e8SYuchung Cheng struct tcp_fastopen_request { 1321783237e8SYuchung Cheng /* Fast Open cookie. Size 0 means a cookie request */ 1322783237e8SYuchung Cheng struct tcp_fastopen_cookie cookie; 1323783237e8SYuchung Cheng struct msghdr *data; /* data in MSG_FASTOPEN */ 1324f5ddcbbbSEric Dumazet size_t size; 1325f5ddcbbbSEric Dumazet int copied; /* queued in tcp_connect() */ 1326783237e8SYuchung Cheng }; 1327783237e8SYuchung Cheng void tcp_free_fastopen_req(struct tcp_sock *tp); 1328783237e8SYuchung Cheng 132910467163SJerry Chu extern struct tcp_fastopen_context __rcu *tcp_fastopen_ctx; 133010467163SJerry Chu int tcp_fastopen_reset_cipher(void *key, unsigned int len); 1331843f4a55SYuchung Cheng bool tcp_try_fastopen(struct sock *sk, struct sk_buff *skb, 13325b7ed089SYuchung Cheng struct request_sock *req, 1333843f4a55SYuchung Cheng struct tcp_fastopen_cookie *foc, 1334843f4a55SYuchung Cheng struct dst_entry *dst); 1335222e83d2SHannes Frederic Sowa void tcp_fastopen_init_key_once(bool publish); 133610467163SJerry Chu #define TCP_FASTOPEN_KEY_LENGTH 16 133710467163SJerry Chu 133810467163SJerry Chu /* Fastopen key context */ 133910467163SJerry Chu struct tcp_fastopen_context { 13407ae8639cSEric Dumazet struct crypto_cipher *tfm; 134110467163SJerry Chu __u8 key[TCP_FASTOPEN_KEY_LENGTH]; 134210467163SJerry Chu struct rcu_head rcu; 134310467163SJerry Chu }; 134410467163SJerry Chu 1345fe067e8aSDavid S. Miller /* write queue abstraction */ 1346fe067e8aSDavid S. Miller static inline void tcp_write_queue_purge(struct sock *sk) 1347fe067e8aSDavid S. Miller { 1348fe067e8aSDavid S. Miller struct sk_buff *skb; 1349fe067e8aSDavid S. Miller 1350fe067e8aSDavid S. Miller while ((skb = __skb_dequeue(&sk->sk_write_queue)) != NULL) 13513ab224beSHideo Aoki sk_wmem_free_skb(sk, skb); 13523ab224beSHideo Aoki sk_mem_reclaim(sk); 13538818a9d8SIlpo Järvinen tcp_clear_all_retrans_hints(tcp_sk(sk)); 1354fe067e8aSDavid S. Miller } 1355fe067e8aSDavid S. Miller 1356cf533ea5SEric Dumazet static inline struct sk_buff *tcp_write_queue_head(const struct sock *sk) 1357fe067e8aSDavid S. Miller { 1358cd07a8eaSDavid S. Miller return skb_peek(&sk->sk_write_queue); 1359fe067e8aSDavid S. Miller } 1360fe067e8aSDavid S. Miller 1361cf533ea5SEric Dumazet static inline struct sk_buff *tcp_write_queue_tail(const struct sock *sk) 1362fe067e8aSDavid S. Miller { 1363cd07a8eaSDavid S. Miller return skb_peek_tail(&sk->sk_write_queue); 1364fe067e8aSDavid S. Miller } 1365fe067e8aSDavid S. Miller 1366cf533ea5SEric Dumazet static inline struct sk_buff *tcp_write_queue_next(const struct sock *sk, 1367cf533ea5SEric Dumazet const struct sk_buff *skb) 1368fe067e8aSDavid S. Miller { 1369cd07a8eaSDavid S. Miller return skb_queue_next(&sk->sk_write_queue, skb); 1370fe067e8aSDavid S. Miller } 1371fe067e8aSDavid S. Miller 1372cf533ea5SEric Dumazet static inline struct sk_buff *tcp_write_queue_prev(const struct sock *sk, 1373cf533ea5SEric Dumazet const struct sk_buff *skb) 1374832d11c5SIlpo Järvinen { 1375832d11c5SIlpo Järvinen return skb_queue_prev(&sk->sk_write_queue, skb); 1376832d11c5SIlpo Järvinen } 1377832d11c5SIlpo Järvinen 1378fe067e8aSDavid S. Miller #define tcp_for_write_queue(skb, sk) \ 1379cd07a8eaSDavid S. Miller skb_queue_walk(&(sk)->sk_write_queue, skb) 1380fe067e8aSDavid S. Miller 1381fe067e8aSDavid S. Miller #define tcp_for_write_queue_from(skb, sk) \ 1382cd07a8eaSDavid S. Miller skb_queue_walk_from(&(sk)->sk_write_queue, skb) 1383fe067e8aSDavid S. Miller 1384234b6860SIlpo Järvinen #define tcp_for_write_queue_from_safe(skb, tmp, sk) \ 1385cd07a8eaSDavid S. Miller skb_queue_walk_from_safe(&(sk)->sk_write_queue, skb, tmp) 1386234b6860SIlpo Järvinen 1387cf533ea5SEric Dumazet static inline struct sk_buff *tcp_send_head(const struct sock *sk) 1388fe067e8aSDavid S. Miller { 1389fe067e8aSDavid S. Miller return sk->sk_send_head; 1390fe067e8aSDavid S. Miller } 1391fe067e8aSDavid S. Miller 1392cd07a8eaSDavid S. Miller static inline bool tcp_skb_is_last(const struct sock *sk, 1393cd07a8eaSDavid S. Miller const struct sk_buff *skb) 1394cd07a8eaSDavid S. Miller { 1395cd07a8eaSDavid S. Miller return skb_queue_is_last(&sk->sk_write_queue, skb); 1396cd07a8eaSDavid S. Miller } 1397cd07a8eaSDavid S. Miller 1398cf533ea5SEric Dumazet static inline void tcp_advance_send_head(struct sock *sk, const struct sk_buff *skb) 1399fe067e8aSDavid S. Miller { 1400cd07a8eaSDavid S. Miller if (tcp_skb_is_last(sk, skb)) 1401fe067e8aSDavid S. Miller sk->sk_send_head = NULL; 1402cd07a8eaSDavid S. Miller else 1403cd07a8eaSDavid S. Miller sk->sk_send_head = tcp_write_queue_next(sk, skb); 1404fe067e8aSDavid S. Miller } 1405fe067e8aSDavid S. Miller 1406fe067e8aSDavid S. Miller static inline void tcp_check_send_head(struct sock *sk, struct sk_buff *skb_unlinked) 1407fe067e8aSDavid S. Miller { 1408fe067e8aSDavid S. Miller if (sk->sk_send_head == skb_unlinked) 1409fe067e8aSDavid S. Miller sk->sk_send_head = NULL; 1410fe067e8aSDavid S. Miller } 1411fe067e8aSDavid S. Miller 1412fe067e8aSDavid S. Miller static inline void tcp_init_send_head(struct sock *sk) 1413fe067e8aSDavid S. Miller { 1414fe067e8aSDavid S. Miller sk->sk_send_head = NULL; 1415fe067e8aSDavid S. Miller } 1416fe067e8aSDavid S. Miller 1417fe067e8aSDavid S. Miller static inline void __tcp_add_write_queue_tail(struct sock *sk, struct sk_buff *skb) 1418fe067e8aSDavid S. Miller { 1419fe067e8aSDavid S. Miller __skb_queue_tail(&sk->sk_write_queue, skb); 1420fe067e8aSDavid S. Miller } 1421fe067e8aSDavid S. Miller 1422fe067e8aSDavid S. Miller static inline void tcp_add_write_queue_tail(struct sock *sk, struct sk_buff *skb) 1423fe067e8aSDavid S. Miller { 1424fe067e8aSDavid S. Miller __tcp_add_write_queue_tail(sk, skb); 1425fe067e8aSDavid S. Miller 1426fe067e8aSDavid S. Miller /* Queue it, remembering where we must start sending. */ 14276859d494SIlpo Järvinen if (sk->sk_send_head == NULL) { 1428fe067e8aSDavid S. Miller sk->sk_send_head = skb; 14296859d494SIlpo Järvinen 14306859d494SIlpo Järvinen if (tcp_sk(sk)->highest_sack == NULL) 14316859d494SIlpo Järvinen tcp_sk(sk)->highest_sack = skb; 14326859d494SIlpo Järvinen } 1433fe067e8aSDavid S. Miller } 1434fe067e8aSDavid S. Miller 1435fe067e8aSDavid S. Miller static inline void __tcp_add_write_queue_head(struct sock *sk, struct sk_buff *skb) 1436fe067e8aSDavid S. Miller { 1437fe067e8aSDavid S. Miller __skb_queue_head(&sk->sk_write_queue, skb); 1438fe067e8aSDavid S. Miller } 1439fe067e8aSDavid S. Miller 1440fe067e8aSDavid S. Miller /* Insert buff after skb on the write queue of sk. */ 1441fe067e8aSDavid S. Miller static inline void tcp_insert_write_queue_after(struct sk_buff *skb, 1442fe067e8aSDavid S. Miller struct sk_buff *buff, 1443fe067e8aSDavid S. Miller struct sock *sk) 1444fe067e8aSDavid S. Miller { 14457de6c033SGerrit Renker __skb_queue_after(&sk->sk_write_queue, skb, buff); 1446fe067e8aSDavid S. Miller } 1447fe067e8aSDavid S. Miller 144843f59c89SDavid S. Miller /* Insert new before skb on the write queue of sk. */ 1449fe067e8aSDavid S. Miller static inline void tcp_insert_write_queue_before(struct sk_buff *new, 1450fe067e8aSDavid S. Miller struct sk_buff *skb, 1451fe067e8aSDavid S. Miller struct sock *sk) 1452fe067e8aSDavid S. Miller { 145343f59c89SDavid S. Miller __skb_queue_before(&sk->sk_write_queue, skb, new); 14546e421410SIlpo Järvinen 14556e421410SIlpo Järvinen if (sk->sk_send_head == skb) 14566e421410SIlpo Järvinen sk->sk_send_head = new; 1457fe067e8aSDavid S. Miller } 1458fe067e8aSDavid S. Miller 1459fe067e8aSDavid S. Miller static inline void tcp_unlink_write_queue(struct sk_buff *skb, struct sock *sk) 1460fe067e8aSDavid S. Miller { 1461fe067e8aSDavid S. Miller __skb_unlink(skb, &sk->sk_write_queue); 1462fe067e8aSDavid S. Miller } 1463fe067e8aSDavid S. Miller 1464a2a385d6SEric Dumazet static inline bool tcp_write_queue_empty(struct sock *sk) 1465fe067e8aSDavid S. Miller { 1466fe067e8aSDavid S. Miller return skb_queue_empty(&sk->sk_write_queue); 1467fe067e8aSDavid S. Miller } 1468fe067e8aSDavid S. Miller 146912d50c46SKrishna Kumar static inline void tcp_push_pending_frames(struct sock *sk) 147012d50c46SKrishna Kumar { 147112d50c46SKrishna Kumar if (tcp_send_head(sk)) { 147212d50c46SKrishna Kumar struct tcp_sock *tp = tcp_sk(sk); 147312d50c46SKrishna Kumar 147412d50c46SKrishna Kumar __tcp_push_pending_frames(sk, tcp_current_mss(sk), tp->nonagle); 147512d50c46SKrishna Kumar } 147612d50c46SKrishna Kumar } 147712d50c46SKrishna Kumar 1478ecb97192SNeal Cardwell /* Start sequence of the skb just after the highest skb with SACKed 1479ecb97192SNeal Cardwell * bit, valid only if sacked_out > 0 or when the caller has ensured 1480ecb97192SNeal Cardwell * validity by itself. 1481a47e5a98SIlpo Järvinen */ 1482a47e5a98SIlpo Järvinen static inline u32 tcp_highest_sack_seq(struct tcp_sock *tp) 1483a47e5a98SIlpo Järvinen { 1484a47e5a98SIlpo Järvinen if (!tp->sacked_out) 1485a47e5a98SIlpo Järvinen return tp->snd_una; 14866859d494SIlpo Järvinen 14876859d494SIlpo Järvinen if (tp->highest_sack == NULL) 14886859d494SIlpo Järvinen return tp->snd_nxt; 14896859d494SIlpo Järvinen 1490a47e5a98SIlpo Järvinen return TCP_SKB_CB(tp->highest_sack)->seq; 1491a47e5a98SIlpo Järvinen } 1492a47e5a98SIlpo Järvinen 14936859d494SIlpo Järvinen static inline void tcp_advance_highest_sack(struct sock *sk, struct sk_buff *skb) 14946859d494SIlpo Järvinen { 14956859d494SIlpo Järvinen tcp_sk(sk)->highest_sack = tcp_skb_is_last(sk, skb) ? NULL : 14966859d494SIlpo Järvinen tcp_write_queue_next(sk, skb); 14976859d494SIlpo Järvinen } 14986859d494SIlpo Järvinen 14996859d494SIlpo Järvinen static inline struct sk_buff *tcp_highest_sack(struct sock *sk) 15006859d494SIlpo Järvinen { 15016859d494SIlpo Järvinen return tcp_sk(sk)->highest_sack; 15026859d494SIlpo Järvinen } 15036859d494SIlpo Järvinen 15046859d494SIlpo Järvinen static inline void tcp_highest_sack_reset(struct sock *sk) 15056859d494SIlpo Järvinen { 15066859d494SIlpo Järvinen tcp_sk(sk)->highest_sack = tcp_write_queue_head(sk); 15076859d494SIlpo Järvinen } 15086859d494SIlpo Järvinen 15096859d494SIlpo Järvinen /* Called when old skb is about to be deleted (to be combined with new skb) */ 15106859d494SIlpo Järvinen static inline void tcp_highest_sack_combine(struct sock *sk, 15116859d494SIlpo Järvinen struct sk_buff *old, 15126859d494SIlpo Järvinen struct sk_buff *new) 15136859d494SIlpo Järvinen { 15146859d494SIlpo Järvinen if (tcp_sk(sk)->sacked_out && (old == tcp_sk(sk)->highest_sack)) 15156859d494SIlpo Järvinen tcp_sk(sk)->highest_sack = new; 15166859d494SIlpo Järvinen } 15176859d494SIlpo Järvinen 15185aa4b32fSAndreas Petlund /* Determines whether this is a thin stream (which may suffer from 15195aa4b32fSAndreas Petlund * increased latency). Used to trigger latency-reducing mechanisms. 15205aa4b32fSAndreas Petlund */ 1521a2a385d6SEric Dumazet static inline bool tcp_stream_is_thin(struct tcp_sock *tp) 15225aa4b32fSAndreas Petlund { 15235aa4b32fSAndreas Petlund return tp->packets_out < 4 && !tcp_in_initial_slowstart(tp); 15245aa4b32fSAndreas Petlund } 15255aa4b32fSAndreas Petlund 15261da177e4SLinus Torvalds /* /proc */ 15271da177e4SLinus Torvalds enum tcp_seq_states { 15281da177e4SLinus Torvalds TCP_SEQ_STATE_LISTENING, 15291da177e4SLinus Torvalds TCP_SEQ_STATE_OPENREQ, 15301da177e4SLinus Torvalds TCP_SEQ_STATE_ESTABLISHED, 15311da177e4SLinus Torvalds }; 15321da177e4SLinus Torvalds 153373cb88ecSArjan van de Ven int tcp_seq_open(struct inode *inode, struct file *file); 153473cb88ecSArjan van de Ven 15351da177e4SLinus Torvalds struct tcp_seq_afinfo { 15361da177e4SLinus Torvalds char *name; 15371da177e4SLinus Torvalds sa_family_t family; 153873cb88ecSArjan van de Ven const struct file_operations *seq_fops; 15399427c4b3SDenis V. Lunev struct seq_operations seq_ops; 15401da177e4SLinus Torvalds }; 15411da177e4SLinus Torvalds 15421da177e4SLinus Torvalds struct tcp_iter_state { 1543a4146b1bSDenis V. Lunev struct seq_net_private p; 15441da177e4SLinus Torvalds sa_family_t family; 15451da177e4SLinus Torvalds enum tcp_seq_states state; 15461da177e4SLinus Torvalds struct sock *syn_wait_sk; 1547a7cb5a49SEric W. Biederman int bucket, offset, sbucket, num; 1548a7cb5a49SEric W. Biederman kuid_t uid; 1549a8b690f9STom Herbert loff_t last_pos; 15501da177e4SLinus Torvalds }; 15511da177e4SLinus Torvalds 15525c9f3023SJoe Perches int tcp_proc_register(struct net *net, struct tcp_seq_afinfo *afinfo); 15535c9f3023SJoe Perches void tcp_proc_unregister(struct net *net, struct tcp_seq_afinfo *afinfo); 15541da177e4SLinus Torvalds 155520380731SArnaldo Carvalho de Melo extern struct request_sock_ops tcp_request_sock_ops; 1556c6aefafbSGlenn Griffin extern struct request_sock_ops tcp6_request_sock_ops; 155720380731SArnaldo Carvalho de Melo 15585c9f3023SJoe Perches void tcp_v4_destroy_sock(struct sock *sk); 155920380731SArnaldo Carvalho de Melo 156028be6e07SEric Dumazet struct sk_buff *tcp_gso_segment(struct sk_buff *skb, 1561c8f44affSMichał Mirosław netdev_features_t features); 15625c9f3023SJoe Perches struct sk_buff **tcp_gro_receive(struct sk_buff **head, struct sk_buff *skb); 15635c9f3023SJoe Perches int tcp_gro_complete(struct sk_buff *skb); 156428850dc7SDaniel Borkmann 15655c9f3023SJoe Perches void __tcp_v4_send_check(struct sk_buff *skb, __be32 saddr, __be32 daddr); 1566f4c50d99SHerbert Xu 1567c9bee3b7SEric Dumazet static inline u32 tcp_notsent_lowat(const struct tcp_sock *tp) 1568c9bee3b7SEric Dumazet { 1569c9bee3b7SEric Dumazet return tp->notsent_lowat ?: sysctl_tcp_notsent_lowat; 1570c9bee3b7SEric Dumazet } 1571c9bee3b7SEric Dumazet 1572c9bee3b7SEric Dumazet static inline bool tcp_stream_memory_free(const struct sock *sk) 1573c9bee3b7SEric Dumazet { 1574c9bee3b7SEric Dumazet const struct tcp_sock *tp = tcp_sk(sk); 1575c9bee3b7SEric Dumazet u32 notsent_bytes = tp->write_seq - tp->snd_nxt; 1576c9bee3b7SEric Dumazet 1577c9bee3b7SEric Dumazet return notsent_bytes < tcp_notsent_lowat(tp); 1578c9bee3b7SEric Dumazet } 1579c9bee3b7SEric Dumazet 158020380731SArnaldo Carvalho de Melo #ifdef CONFIG_PROC_FS 15815c9f3023SJoe Perches int tcp4_proc_init(void); 15825c9f3023SJoe Perches void tcp4_proc_exit(void); 158320380731SArnaldo Carvalho de Melo #endif 158420380731SArnaldo Carvalho de Melo 15855db92c99SOctavian Purdila int tcp_rtx_synack(struct sock *sk, struct request_sock *req); 15861fb6f159SOctavian Purdila int tcp_conn_request(struct request_sock_ops *rsk_ops, 15871fb6f159SOctavian Purdila const struct tcp_request_sock_ops *af_ops, 15881fb6f159SOctavian Purdila struct sock *sk, struct sk_buff *skb); 15895db92c99SOctavian Purdila 1590cfb6eeb4SYOSHIFUJI Hideaki /* TCP af-specific functions */ 1591cfb6eeb4SYOSHIFUJI Hideaki struct tcp_sock_af_ops { 1592cfb6eeb4SYOSHIFUJI Hideaki #ifdef CONFIG_TCP_MD5SIG 1593cfb6eeb4SYOSHIFUJI Hideaki struct tcp_md5sig_key *(*md5_lookup) (struct sock *sk, 1594cfb6eeb4SYOSHIFUJI Hideaki struct sock *addr_sk); 1595cfb6eeb4SYOSHIFUJI Hideaki int (*calc_md5_hash) (char *location, 1596cfb6eeb4SYOSHIFUJI Hideaki struct tcp_md5sig_key *md5, 1597318cf7aaSEric Dumazet const struct sock *sk, 1598318cf7aaSEric Dumazet const struct request_sock *req, 1599318cf7aaSEric Dumazet const struct sk_buff *skb); 1600cfb6eeb4SYOSHIFUJI Hideaki int (*md5_parse) (struct sock *sk, 1601cfb6eeb4SYOSHIFUJI Hideaki char __user *optval, 1602cfb6eeb4SYOSHIFUJI Hideaki int optlen); 1603cfb6eeb4SYOSHIFUJI Hideaki #endif 1604cfb6eeb4SYOSHIFUJI Hideaki }; 1605cfb6eeb4SYOSHIFUJI Hideaki 1606cfb6eeb4SYOSHIFUJI Hideaki struct tcp_request_sock_ops { 16072aec4a29SOctavian Purdila u16 mss_clamp; 1608cfb6eeb4SYOSHIFUJI Hideaki #ifdef CONFIG_TCP_MD5SIG 1609cfb6eeb4SYOSHIFUJI Hideaki struct tcp_md5sig_key *(*md5_lookup) (struct sock *sk, 1610cfb6eeb4SYOSHIFUJI Hideaki struct request_sock *req); 1611e3afe7b7SJohn Dykstra int (*calc_md5_hash) (char *location, 1612e3afe7b7SJohn Dykstra struct tcp_md5sig_key *md5, 1613318cf7aaSEric Dumazet const struct sock *sk, 1614318cf7aaSEric Dumazet const struct request_sock *req, 1615318cf7aaSEric Dumazet const struct sk_buff *skb); 1616cfb6eeb4SYOSHIFUJI Hideaki #endif 161716bea70aSOctavian Purdila void (*init_req)(struct request_sock *req, struct sock *sk, 161816bea70aSOctavian Purdila struct sk_buff *skb); 1619fb7b37a7SOctavian Purdila #ifdef CONFIG_SYN_COOKIES 1620fb7b37a7SOctavian Purdila __u32 (*cookie_init_seq)(struct sock *sk, const struct sk_buff *skb, 1621fb7b37a7SOctavian Purdila __u16 *mss); 1622fb7b37a7SOctavian Purdila #endif 1623d94e0417SOctavian Purdila struct dst_entry *(*route_req)(struct sock *sk, struct flowi *fl, 1624d94e0417SOctavian Purdila const struct request_sock *req, 1625d94e0417SOctavian Purdila bool *strict); 1626936b8bdbSOctavian Purdila __u32 (*init_seq)(const struct sk_buff *skb); 1627d6274bd8SOctavian Purdila int (*send_synack)(struct sock *sk, struct dst_entry *dst, 1628d6274bd8SOctavian Purdila struct flowi *fl, struct request_sock *req, 1629d6274bd8SOctavian Purdila u16 queue_mapping, struct tcp_fastopen_cookie *foc); 1630695da14eSOctavian Purdila void (*queue_hash_add)(struct sock *sk, struct request_sock *req, 1631695da14eSOctavian Purdila const unsigned long timeout); 1632cfb6eeb4SYOSHIFUJI Hideaki }; 1633cfb6eeb4SYOSHIFUJI Hideaki 1634fb7b37a7SOctavian Purdila #ifdef CONFIG_SYN_COOKIES 1635fb7b37a7SOctavian Purdila static inline __u32 cookie_init_sequence(const struct tcp_request_sock_ops *ops, 1636fb7b37a7SOctavian Purdila struct sock *sk, struct sk_buff *skb, 1637fb7b37a7SOctavian Purdila __u16 *mss) 1638fb7b37a7SOctavian Purdila { 1639fb7b37a7SOctavian Purdila return ops->cookie_init_seq(sk, skb, mss); 1640fb7b37a7SOctavian Purdila } 1641fb7b37a7SOctavian Purdila #else 1642fb7b37a7SOctavian Purdila static inline __u32 cookie_init_sequence(const struct tcp_request_sock_ops *ops, 1643fb7b37a7SOctavian Purdila struct sock *sk, struct sk_buff *skb, 1644fb7b37a7SOctavian Purdila __u16 *mss) 1645fb7b37a7SOctavian Purdila { 1646fb7b37a7SOctavian Purdila return 0; 1647fb7b37a7SOctavian Purdila } 1648fb7b37a7SOctavian Purdila #endif 1649fb7b37a7SOctavian Purdila 16505c9f3023SJoe Perches int tcpv4_offload_init(void); 165128850dc7SDaniel Borkmann 16525c9f3023SJoe Perches void tcp_v4_init(void); 16535c9f3023SJoe Perches void tcp_init(void); 165420380731SArnaldo Carvalho de Melo 16551da177e4SLinus Torvalds #endif /* _TCP_H */ 1656