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> 343f421baaSArnaldo Carvalho de Melo 353f421baaSArnaldo Carvalho de Melo #include <net/inet_connection_sock.h> 36295ff7edSArnaldo Carvalho de Melo #include <net/inet_timewait_sock.h> 3777d8bf9cSArnaldo Carvalho de Melo #include <net/inet_hashtables.h> 381da177e4SLinus Torvalds #include <net/checksum.h> 392e6599cbSArnaldo Carvalho de Melo #include <net/request_sock.h> 401da177e4SLinus Torvalds #include <net/sock.h> 411da177e4SLinus Torvalds #include <net/snmp.h> 421da177e4SLinus Torvalds #include <net/ip.h> 43c752f073SArnaldo Carvalho de Melo #include <net/tcp_states.h> 44bdf1ee5dSIlpo Järvinen #include <net/inet_ecn.h> 450c266898SSatoru SATOH #include <net/dst.h> 46c752f073SArnaldo Carvalho de Melo 471da177e4SLinus Torvalds #include <linux/seq_file.h> 48180d8cd9SGlauber Costa #include <linux/memcontrol.h> 491da177e4SLinus Torvalds 500f7ff927SArnaldo Carvalho de Melo extern struct inet_hashinfo tcp_hashinfo; 511da177e4SLinus Torvalds 52dd24c001SEric Dumazet extern struct percpu_counter tcp_orphan_count; 531da177e4SLinus Torvalds extern void tcp_time_wait(struct sock *sk, int state, int timeo); 541da177e4SLinus Torvalds 551da177e4SLinus Torvalds #define MAX_TCP_HEADER (128 + MAX_HEADER) 5633ad798cSAdam Langley #define MAX_TCP_OPTION_SPACE 40 571da177e4SLinus Torvalds 581da177e4SLinus Torvalds /* 591da177e4SLinus Torvalds * Never offer a window over 32767 without using window scaling. Some 601da177e4SLinus Torvalds * poor stacks do signed 16bit maths! 611da177e4SLinus Torvalds */ 621da177e4SLinus Torvalds #define MAX_TCP_WINDOW 32767U 631da177e4SLinus Torvalds 64356f0398SNandita Dukkipati /* Offer an initial receive window of 10 mss. */ 65356f0398SNandita Dukkipati #define TCP_DEFAULT_INIT_RCVWND 10 66356f0398SNandita Dukkipati 671da177e4SLinus Torvalds /* Minimal accepted MSS. It is (60+60+8) - (20+20). */ 681da177e4SLinus Torvalds #define TCP_MIN_MSS 88U 691da177e4SLinus Torvalds 705d424d5aSJohn Heffner /* The least MTU to use for probing */ 715d424d5aSJohn Heffner #define TCP_BASE_MSS 512 725d424d5aSJohn Heffner 731da177e4SLinus Torvalds /* After receiving this amount of duplicate ACKs fast retransmit starts. */ 741da177e4SLinus Torvalds #define TCP_FASTRETRANS_THRESH 3 751da177e4SLinus Torvalds 761da177e4SLinus Torvalds /* Maximal reordering. */ 771da177e4SLinus Torvalds #define TCP_MAX_REORDERING 127 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds /* Maximal number of ACKs sent quickly to accelerate slow-start. */ 801da177e4SLinus Torvalds #define TCP_MAX_QUICKACKS 16U 811da177e4SLinus Torvalds 821da177e4SLinus Torvalds /* urg_data states */ 831da177e4SLinus Torvalds #define TCP_URG_VALID 0x0100 841da177e4SLinus Torvalds #define TCP_URG_NOTYET 0x0200 851da177e4SLinus Torvalds #define TCP_URG_READ 0x0400 861da177e4SLinus Torvalds 871da177e4SLinus Torvalds #define TCP_RETR1 3 /* 881da177e4SLinus Torvalds * This is how many retries it does before it 891da177e4SLinus Torvalds * tries to figure out if the gateway is 901da177e4SLinus Torvalds * down. Minimal RFC value is 3; it corresponds 911da177e4SLinus Torvalds * to ~3sec-8min depending on RTO. 921da177e4SLinus Torvalds */ 931da177e4SLinus Torvalds 941da177e4SLinus Torvalds #define TCP_RETR2 15 /* 951da177e4SLinus Torvalds * This should take at least 961da177e4SLinus Torvalds * 90 minutes to time out. 971da177e4SLinus Torvalds * RFC1122 says that the limit is 100 sec. 981da177e4SLinus Torvalds * 15 is ~13-30min depending on RTO. 991da177e4SLinus Torvalds */ 1001da177e4SLinus Torvalds 1011da177e4SLinus Torvalds #define TCP_SYN_RETRIES 5 /* number of times to retry active opening a 102caa20d9aSStephen Hemminger * connection: ~180sec is RFC minimum */ 1031da177e4SLinus Torvalds 1041da177e4SLinus Torvalds #define TCP_SYNACK_RETRIES 5 /* number of times to retry passive opening a 105caa20d9aSStephen Hemminger * connection: ~180sec is RFC minimum */ 1061da177e4SLinus Torvalds 1071da177e4SLinus Torvalds #define TCP_TIMEWAIT_LEN (60*HZ) /* how long to wait to destroy TIME-WAIT 1081da177e4SLinus Torvalds * state, about 60 seconds */ 1091da177e4SLinus Torvalds #define TCP_FIN_TIMEOUT TCP_TIMEWAIT_LEN 1101da177e4SLinus Torvalds /* BSD style FIN_WAIT2 deadlock breaker. 1111da177e4SLinus Torvalds * It used to be 3min, new value is 60sec, 1121da177e4SLinus Torvalds * to combine FIN-WAIT-2 timeout with 1131da177e4SLinus Torvalds * TIME-WAIT timer. 1141da177e4SLinus Torvalds */ 1151da177e4SLinus Torvalds 1161da177e4SLinus Torvalds #define TCP_DELACK_MAX ((unsigned)(HZ/5)) /* maximal time to delay before sending an ACK */ 1171da177e4SLinus Torvalds #if HZ >= 100 1181da177e4SLinus Torvalds #define TCP_DELACK_MIN ((unsigned)(HZ/25)) /* minimal time to delay before sending an ACK */ 1191da177e4SLinus Torvalds #define TCP_ATO_MIN ((unsigned)(HZ/25)) 1201da177e4SLinus Torvalds #else 1211da177e4SLinus Torvalds #define TCP_DELACK_MIN 4U 1221da177e4SLinus Torvalds #define TCP_ATO_MIN 4U 1231da177e4SLinus Torvalds #endif 1241da177e4SLinus Torvalds #define TCP_RTO_MAX ((unsigned)(120*HZ)) 1251da177e4SLinus Torvalds #define TCP_RTO_MIN ((unsigned)(HZ/5)) 126fd4f2ceaSEric Dumazet #define TCP_TIMEOUT_INIT ((unsigned)(1*HZ)) /* RFC6298 2.1 initial RTO value */ 1279ad7c049SJerry Chu #define TCP_TIMEOUT_FALLBACK ((unsigned)(3*HZ)) /* RFC 1122 initial RTO value, now 1289ad7c049SJerry Chu * used as a fallback RTO for the 1299ad7c049SJerry Chu * initial data transmission if no 1309ad7c049SJerry Chu * valid RTT sample has been acquired, 1319ad7c049SJerry Chu * most likely due to retrans in 3WHS. 1329ad7c049SJerry Chu */ 1331da177e4SLinus Torvalds 1341da177e4SLinus Torvalds #define TCP_RESOURCE_PROBE_INTERVAL ((unsigned)(HZ/2U)) /* Maximal interval between probes 1351da177e4SLinus Torvalds * for local resources. 1361da177e4SLinus Torvalds */ 1371da177e4SLinus Torvalds 1381da177e4SLinus Torvalds #define TCP_KEEPALIVE_TIME (120*60*HZ) /* two hours */ 1391da177e4SLinus Torvalds #define TCP_KEEPALIVE_PROBES 9 /* Max of 9 keepalive probes */ 1401da177e4SLinus Torvalds #define TCP_KEEPALIVE_INTVL (75*HZ) 1411da177e4SLinus Torvalds 1421da177e4SLinus Torvalds #define MAX_TCP_KEEPIDLE 32767 1431da177e4SLinus Torvalds #define MAX_TCP_KEEPINTVL 32767 1441da177e4SLinus Torvalds #define MAX_TCP_KEEPCNT 127 1451da177e4SLinus Torvalds #define MAX_TCP_SYNCNT 127 1461da177e4SLinus Torvalds 1471da177e4SLinus Torvalds #define TCP_SYNQ_INTERVAL (HZ/5) /* Period of SYNACK timer */ 1481da177e4SLinus Torvalds 1491da177e4SLinus Torvalds #define TCP_PAWS_24DAYS (60 * 60 * 24 * 24) 1501da177e4SLinus Torvalds #define TCP_PAWS_MSL 60 /* Per-host timestamps are invalidated 1511da177e4SLinus Torvalds * after this time. It should be equal 1521da177e4SLinus Torvalds * (or greater than) TCP_TIMEWAIT_LEN 1531da177e4SLinus Torvalds * to provide reliability equal to one 1541da177e4SLinus Torvalds * provided by timewait state. 1551da177e4SLinus Torvalds */ 1561da177e4SLinus Torvalds #define TCP_PAWS_WINDOW 1 /* Replay window for per-host 1571da177e4SLinus Torvalds * timestamps. It must be less than 1581da177e4SLinus Torvalds * minimal timewait lifetime. 1591da177e4SLinus Torvalds */ 1601da177e4SLinus Torvalds /* 1611da177e4SLinus Torvalds * TCP option 1621da177e4SLinus Torvalds */ 1631da177e4SLinus Torvalds 1641da177e4SLinus Torvalds #define TCPOPT_NOP 1 /* Padding */ 1651da177e4SLinus Torvalds #define TCPOPT_EOL 0 /* End of options */ 1661da177e4SLinus Torvalds #define TCPOPT_MSS 2 /* Segment size negotiating */ 1671da177e4SLinus Torvalds #define TCPOPT_WINDOW 3 /* Window scaling */ 1681da177e4SLinus Torvalds #define TCPOPT_SACK_PERM 4 /* SACK Permitted */ 1691da177e4SLinus Torvalds #define TCPOPT_SACK 5 /* SACK Block */ 1701da177e4SLinus Torvalds #define TCPOPT_TIMESTAMP 8 /* Better RTT estimations/PAWS */ 171cfb6eeb4SYOSHIFUJI Hideaki #define TCPOPT_MD5SIG 19 /* MD5 Signature (RFC2385) */ 172435cf559SWilliam Allen Simpson #define TCPOPT_COOKIE 253 /* Cookie extension (experimental) */ 1732100c8d2SYuchung Cheng #define TCPOPT_EXP 254 /* Experimental */ 1742100c8d2SYuchung Cheng /* Magic number to be after the option value for sharing TCP 1752100c8d2SYuchung Cheng * experimental options. See draft-ietf-tcpm-experimental-options-00.txt 1762100c8d2SYuchung Cheng */ 1772100c8d2SYuchung Cheng #define TCPOPT_FASTOPEN_MAGIC 0xF989 1781da177e4SLinus Torvalds 1791da177e4SLinus Torvalds /* 1801da177e4SLinus Torvalds * TCP option lengths 1811da177e4SLinus Torvalds */ 1821da177e4SLinus Torvalds 1831da177e4SLinus Torvalds #define TCPOLEN_MSS 4 1841da177e4SLinus Torvalds #define TCPOLEN_WINDOW 3 1851da177e4SLinus Torvalds #define TCPOLEN_SACK_PERM 2 1861da177e4SLinus Torvalds #define TCPOLEN_TIMESTAMP 10 187cfb6eeb4SYOSHIFUJI Hideaki #define TCPOLEN_MD5SIG 18 1882100c8d2SYuchung Cheng #define TCPOLEN_EXP_FASTOPEN_BASE 4 189435cf559SWilliam Allen Simpson #define TCPOLEN_COOKIE_BASE 2 /* Cookie-less header extension */ 190435cf559SWilliam Allen Simpson #define TCPOLEN_COOKIE_PAIR 3 /* Cookie pair header extension */ 191435cf559SWilliam Allen Simpson #define TCPOLEN_COOKIE_MIN (TCPOLEN_COOKIE_BASE+TCP_COOKIE_MIN) 192435cf559SWilliam Allen Simpson #define TCPOLEN_COOKIE_MAX (TCPOLEN_COOKIE_BASE+TCP_COOKIE_MAX) 1931da177e4SLinus Torvalds 1941da177e4SLinus Torvalds /* But this is what stacks really send out. */ 1951da177e4SLinus Torvalds #define TCPOLEN_TSTAMP_ALIGNED 12 1961da177e4SLinus Torvalds #define TCPOLEN_WSCALE_ALIGNED 4 1971da177e4SLinus Torvalds #define TCPOLEN_SACKPERM_ALIGNED 4 1981da177e4SLinus Torvalds #define TCPOLEN_SACK_BASE 2 1991da177e4SLinus Torvalds #define TCPOLEN_SACK_BASE_ALIGNED 4 2001da177e4SLinus Torvalds #define TCPOLEN_SACK_PERBLOCK 8 201cfb6eeb4SYOSHIFUJI Hideaki #define TCPOLEN_MD5SIG_ALIGNED 20 20233ad798cSAdam Langley #define TCPOLEN_MSS_ALIGNED 4 2031da177e4SLinus Torvalds 2041da177e4SLinus Torvalds /* Flags in tp->nonagle */ 2051da177e4SLinus Torvalds #define TCP_NAGLE_OFF 1 /* Nagle's algo is disabled */ 2061da177e4SLinus Torvalds #define TCP_NAGLE_CORK 2 /* Socket is corked */ 207caa20d9aSStephen Hemminger #define TCP_NAGLE_PUSH 4 /* Cork is overridden for already queued data */ 2081da177e4SLinus Torvalds 20936e31b0aSAndreas Petlund /* TCP thin-stream limits */ 21036e31b0aSAndreas Petlund #define TCP_THIN_LINEAR_RETRIES 6 /* After 6 linear retries, do exp. backoff */ 21136e31b0aSAndreas Petlund 2127eb38527SDavid S. Miller /* TCP initial congestion window as per draft-hkchu-tcpm-initcwnd-01 */ 213442b9635SDavid S. Miller #define TCP_INIT_CWND 10 214442b9635SDavid S. Miller 215295ff7edSArnaldo Carvalho de Melo extern struct inet_timewait_death_row tcp_death_row; 216295ff7edSArnaldo Carvalho de Melo 2171da177e4SLinus Torvalds /* sysctl variables for tcp */ 2181da177e4SLinus Torvalds extern int sysctl_tcp_timestamps; 2191da177e4SLinus Torvalds extern int sysctl_tcp_window_scaling; 2201da177e4SLinus Torvalds extern int sysctl_tcp_sack; 2211da177e4SLinus Torvalds extern int sysctl_tcp_fin_timeout; 2221da177e4SLinus Torvalds extern int sysctl_tcp_keepalive_time; 2231da177e4SLinus Torvalds extern int sysctl_tcp_keepalive_probes; 2241da177e4SLinus Torvalds extern int sysctl_tcp_keepalive_intvl; 2251da177e4SLinus Torvalds extern int sysctl_tcp_syn_retries; 2261da177e4SLinus Torvalds extern int sysctl_tcp_synack_retries; 2271da177e4SLinus Torvalds extern int sysctl_tcp_retries1; 2281da177e4SLinus Torvalds extern int sysctl_tcp_retries2; 2291da177e4SLinus Torvalds extern int sysctl_tcp_orphan_retries; 2301da177e4SLinus Torvalds extern int sysctl_tcp_syncookies; 2312100c8d2SYuchung Cheng extern int sysctl_tcp_fastopen; 2321da177e4SLinus Torvalds extern int sysctl_tcp_retrans_collapse; 2331da177e4SLinus Torvalds extern int sysctl_tcp_stdurg; 2341da177e4SLinus Torvalds extern int sysctl_tcp_rfc1337; 2351da177e4SLinus Torvalds extern int sysctl_tcp_abort_on_overflow; 2361da177e4SLinus Torvalds extern int sysctl_tcp_max_orphans; 2371da177e4SLinus Torvalds extern int sysctl_tcp_fack; 2381da177e4SLinus Torvalds extern int sysctl_tcp_reordering; 2391da177e4SLinus Torvalds extern int sysctl_tcp_ecn; 2401da177e4SLinus Torvalds extern int sysctl_tcp_dsack; 2411da177e4SLinus Torvalds extern int sysctl_tcp_wmem[3]; 2421da177e4SLinus Torvalds extern int sysctl_tcp_rmem[3]; 2431da177e4SLinus Torvalds extern int sysctl_tcp_app_win; 2441da177e4SLinus Torvalds extern int sysctl_tcp_adv_win_scale; 2451da177e4SLinus Torvalds extern int sysctl_tcp_tw_reuse; 2461da177e4SLinus Torvalds extern int sysctl_tcp_frto; 2473cfe3baaSIlpo Järvinen extern int sysctl_tcp_frto_response; 2481da177e4SLinus Torvalds extern int sysctl_tcp_low_latency; 24995937825SChris Leech extern int sysctl_tcp_dma_copybreak; 2501da177e4SLinus Torvalds extern int sysctl_tcp_nometrics_save; 2511da177e4SLinus Torvalds extern int sysctl_tcp_moderate_rcvbuf; 2521da177e4SLinus Torvalds extern int sysctl_tcp_tso_win_divisor; 2539772efb9SStephen Hemminger extern int sysctl_tcp_abc; 2545d424d5aSJohn Heffner extern int sysctl_tcp_mtu_probing; 2555d424d5aSJohn Heffner extern int sysctl_tcp_base_mss; 25615d99e02SRick Jones extern int sysctl_tcp_workaround_signed_windows; 25735089bb2SDavid S. Miller extern int sysctl_tcp_slow_start_after_idle; 258886236c1SJohn Heffner extern int sysctl_tcp_max_ssthresh; 259519855c5SWilliam Allen Simpson extern int sysctl_tcp_cookie_size; 26036e31b0aSAndreas Petlund extern int sysctl_tcp_thin_linear_timeouts; 2617e380175SAndreas Petlund extern int sysctl_tcp_thin_dupack; 262eed530b6SYuchung Cheng extern int sysctl_tcp_early_retrans; 26346d3ceabSEric Dumazet extern int sysctl_tcp_limit_output_bytes; 264282f23c6SEric Dumazet extern int sysctl_tcp_challenge_ack_limit; 2651da177e4SLinus Torvalds 2668d987e5cSEric Dumazet extern atomic_long_t tcp_memory_allocated; 2671748376bSEric Dumazet extern struct percpu_counter tcp_sockets_allocated; 2681da177e4SLinus Torvalds extern int tcp_memory_pressure; 2691da177e4SLinus Torvalds 2701da177e4SLinus Torvalds /* 2711da177e4SLinus Torvalds * The next routines deal with comparing 32 bit unsigned ints 2721da177e4SLinus Torvalds * and worry about wraparound (automatic with unsigned arithmetic). 2731da177e4SLinus Torvalds */ 2741da177e4SLinus Torvalds 275a2a385d6SEric Dumazet static inline bool before(__u32 seq1, __u32 seq2) 2761da177e4SLinus Torvalds { 2770d630cc0SGerrit Renker return (__s32)(seq1-seq2) < 0; 2781da177e4SLinus Torvalds } 2799a036b9cSGerrit Renker #define after(seq2, seq1) before(seq1, seq2) 2801da177e4SLinus Torvalds 2811da177e4SLinus Torvalds /* is s2<=s1<=s3 ? */ 282a2a385d6SEric Dumazet static inline bool between(__u32 seq1, __u32 seq2, __u32 seq3) 2831da177e4SLinus Torvalds { 2841da177e4SLinus Torvalds return seq3 - seq2 >= seq1 - seq2; 2851da177e4SLinus Torvalds } 2861da177e4SLinus Torvalds 287efcdbf24SArun Sharma static inline bool tcp_out_of_memory(struct sock *sk) 288efcdbf24SArun Sharma { 289efcdbf24SArun Sharma if (sk->sk_wmem_queued > SOCK_MIN_SNDBUF && 290efcdbf24SArun Sharma sk_memory_allocated(sk) > sk_prot_mem_limits(sk, 2)) 291efcdbf24SArun Sharma return true; 292efcdbf24SArun Sharma return false; 293efcdbf24SArun Sharma } 294efcdbf24SArun Sharma 295ad1af0feSDavid S. Miller static inline bool tcp_too_many_orphans(struct sock *sk, int shift) 296e4fd5da3SPavel Emelianov { 297ad1af0feSDavid S. Miller struct percpu_counter *ocp = sk->sk_prot->orphan_count; 298ad1af0feSDavid S. Miller int orphans = percpu_counter_read_positive(ocp); 299ad1af0feSDavid S. Miller 300ad1af0feSDavid S. Miller if (orphans << shift > sysctl_tcp_max_orphans) { 301ad1af0feSDavid S. Miller orphans = percpu_counter_sum_positive(ocp); 302ad1af0feSDavid S. Miller if (orphans << shift > sysctl_tcp_max_orphans) 303ad1af0feSDavid S. Miller return true; 304ad1af0feSDavid S. Miller } 305ad1af0feSDavid S. Miller return false; 306e4fd5da3SPavel Emelianov } 3071da177e4SLinus Torvalds 308efcdbf24SArun Sharma extern bool tcp_check_oom(struct sock *sk, int shift); 309efcdbf24SArun Sharma 310a0f82f64SFlorian Westphal /* syncookies: remember time of last synqueue overflow */ 311a0f82f64SFlorian Westphal static inline void tcp_synq_overflow(struct sock *sk) 312a0f82f64SFlorian Westphal { 313a0f82f64SFlorian Westphal tcp_sk(sk)->rx_opt.ts_recent_stamp = jiffies; 314a0f82f64SFlorian Westphal } 315a0f82f64SFlorian Westphal 316a0f82f64SFlorian Westphal /* syncookies: no recent synqueue overflow on this listening socket? */ 317a2a385d6SEric Dumazet static inline bool tcp_synq_no_recent_overflow(const struct sock *sk) 318a0f82f64SFlorian Westphal { 319a0f82f64SFlorian Westphal unsigned long last_overflow = tcp_sk(sk)->rx_opt.ts_recent_stamp; 3209ad7c049SJerry Chu return time_after(jiffies, last_overflow + TCP_TIMEOUT_FALLBACK); 321a0f82f64SFlorian Westphal } 322a0f82f64SFlorian Westphal 3231da177e4SLinus Torvalds extern struct proto tcp_prot; 3241da177e4SLinus Torvalds 32557ef42d5SPavel Emelyanov #define TCP_INC_STATS(net, field) SNMP_INC_STATS((net)->mib.tcp_statistics, field) 32657ef42d5SPavel Emelyanov #define TCP_INC_STATS_BH(net, field) SNMP_INC_STATS_BH((net)->mib.tcp_statistics, field) 32757ef42d5SPavel Emelyanov #define TCP_DEC_STATS(net, field) SNMP_DEC_STATS((net)->mib.tcp_statistics, field) 32857ef42d5SPavel Emelyanov #define TCP_ADD_STATS_USER(net, field, val) SNMP_ADD_STATS_USER((net)->mib.tcp_statistics, field, val) 329aa2ea058STom Herbert #define TCP_ADD_STATS(net, field, val) SNMP_ADD_STATS((net)->mib.tcp_statistics, field, val) 3301da177e4SLinus Torvalds 3314acb4190SGlauber Costa extern void tcp_init_mem(struct net *net); 3324acb4190SGlauber Costa 33346d3ceabSEric Dumazet extern void tcp_tasklet_init(void); 33446d3ceabSEric Dumazet 3351da177e4SLinus Torvalds extern void tcp_v4_err(struct sk_buff *skb, u32); 3361da177e4SLinus Torvalds 3371da177e4SLinus Torvalds extern void tcp_shutdown (struct sock *sk, int how); 3381da177e4SLinus Torvalds 339160eb5a6SDavid S. Miller extern void tcp_v4_early_demux(struct sk_buff *skb); 3401da177e4SLinus Torvalds extern int tcp_v4_rcv(struct sk_buff *skb); 3411da177e4SLinus Torvalds 3424670fd81SDavid S. Miller extern struct inet_peer *tcp_v4_get_peer(struct sock *sk); 3438feaf0c0SArnaldo Carvalho de Melo extern int tcp_v4_tw_remember_stamp(struct inet_timewait_sock *tw); 3447ba42910SChangli Gao extern int tcp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, 3457ba42910SChangli Gao size_t size); 3467ba42910SChangli Gao extern int tcp_sendpage(struct sock *sk, struct page *page, int offset, 34753d3176bSChangli Gao size_t size, int flags); 34846d3ceabSEric Dumazet extern void tcp_release_cb(struct sock *sk); 34953d3176bSChangli Gao extern int tcp_ioctl(struct sock *sk, int cmd, unsigned long arg); 35053d3176bSChangli Gao extern int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb, 351cf533ea5SEric Dumazet const struct tcphdr *th, unsigned int len); 35253d3176bSChangli Gao extern int tcp_rcv_established(struct sock *sk, struct sk_buff *skb, 353cf533ea5SEric Dumazet const struct tcphdr *th, unsigned int len); 3541da177e4SLinus Torvalds extern void tcp_rcv_space_adjust(struct sock *sk); 3550e4b4992SChris Leech extern void tcp_cleanup_rbuf(struct sock *sk, int copied); 35653d3176bSChangli Gao extern int tcp_twsk_unique(struct sock *sk, struct sock *sktw, void *twp); 357cfb6eeb4SYOSHIFUJI Hideaki extern void tcp_twsk_destructor(struct sock *sk); 3589c55e01cSJens Axboe extern ssize_t tcp_splice_read(struct socket *sk, loff_t *ppos, 35953d3176bSChangli Gao struct pipe_inode_info *pipe, size_t len, 36053d3176bSChangli Gao unsigned int flags); 3619c55e01cSJens Axboe 362463c84b9SArnaldo Carvalho de Melo static inline void tcp_dec_quickack_mode(struct sock *sk, 363463c84b9SArnaldo Carvalho de Melo const unsigned int pkts) 3641da177e4SLinus Torvalds { 365463c84b9SArnaldo Carvalho de Melo struct inet_connection_sock *icsk = inet_csk(sk); 366fc6415bcSDavid S. Miller 367463c84b9SArnaldo Carvalho de Melo if (icsk->icsk_ack.quick) { 368463c84b9SArnaldo Carvalho de Melo if (pkts >= icsk->icsk_ack.quick) { 369463c84b9SArnaldo Carvalho de Melo icsk->icsk_ack.quick = 0; 3701da177e4SLinus Torvalds /* Leaving quickack mode we deflate ATO. */ 371463c84b9SArnaldo Carvalho de Melo icsk->icsk_ack.ato = TCP_ATO_MIN; 372fc6415bcSDavid S. Miller } else 373463c84b9SArnaldo Carvalho de Melo icsk->icsk_ack.quick -= pkts; 3741da177e4SLinus Torvalds } 3751da177e4SLinus Torvalds } 3761da177e4SLinus Torvalds 377bdf1ee5dSIlpo Järvinen #define TCP_ECN_OK 1 378bdf1ee5dSIlpo Järvinen #define TCP_ECN_QUEUE_CWR 2 379bdf1ee5dSIlpo Järvinen #define TCP_ECN_DEMAND_CWR 4 3807a269ffaSEric Dumazet #define TCP_ECN_SEEN 8 381bdf1ee5dSIlpo Järvinen 382fd2c3ef7SEric Dumazet enum tcp_tw_status { 3831da177e4SLinus Torvalds TCP_TW_SUCCESS = 0, 3841da177e4SLinus Torvalds TCP_TW_RST = 1, 3851da177e4SLinus Torvalds TCP_TW_ACK = 2, 3861da177e4SLinus Torvalds TCP_TW_SYN = 3 3871da177e4SLinus Torvalds }; 3881da177e4SLinus Torvalds 3891da177e4SLinus Torvalds 3908feaf0c0SArnaldo Carvalho de Melo extern enum tcp_tw_status tcp_timewait_state_process(struct inet_timewait_sock *tw, 3911da177e4SLinus Torvalds struct sk_buff *skb, 3928feaf0c0SArnaldo Carvalho de Melo const struct tcphdr *th); 3931da177e4SLinus Torvalds extern struct sock * tcp_check_req(struct sock *sk,struct sk_buff *skb, 39460236fddSArnaldo Carvalho de Melo struct request_sock *req, 39560236fddSArnaldo Carvalho de Melo struct request_sock **prev); 39653d3176bSChangli Gao extern int tcp_child_process(struct sock *parent, struct sock *child, 3971da177e4SLinus Torvalds struct sk_buff *skb); 398a2a385d6SEric Dumazet extern bool tcp_use_frto(struct sock *sk); 3991da177e4SLinus Torvalds extern void tcp_enter_frto(struct sock *sk); 4001da177e4SLinus Torvalds extern void tcp_enter_loss(struct sock *sk, int how); 4011da177e4SLinus Torvalds extern void tcp_clear_retrans(struct tcp_sock *tp); 4021da177e4SLinus Torvalds extern void tcp_update_metrics(struct sock *sk); 4034aabd8efSDavid S. Miller extern void tcp_init_metrics(struct sock *sk); 40451c5d0c4SDavid S. Miller extern void tcp_metrics_init(void); 40581166dd6SDavid S. Miller extern bool tcp_peer_is_proven(struct request_sock *req, struct dst_entry *dst, bool paws_check); 40681166dd6SDavid S. Miller extern bool tcp_remember_stamp(struct sock *sk); 40781166dd6SDavid S. Miller extern bool tcp_tw_remember_stamp(struct inet_timewait_sock *tw); 4081fe4c481SYuchung Cheng extern void tcp_fastopen_cache_get(struct sock *sk, u16 *mss, 4091fe4c481SYuchung Cheng struct tcp_fastopen_cookie *cookie); 4101fe4c481SYuchung Cheng extern void tcp_fastopen_cache_set(struct sock *sk, u16 mss, 4111fe4c481SYuchung Cheng struct tcp_fastopen_cookie *cookie); 41281166dd6SDavid S. Miller extern void tcp_fetch_timewait_stamp(struct sock *sk, struct dst_entry *dst); 4134aabd8efSDavid S. Miller extern void tcp_disable_fack(struct tcp_sock *tp); 41453d3176bSChangli Gao extern void tcp_close(struct sock *sk, long timeout); 415900f65d3SNeal Cardwell extern void tcp_init_sock(struct sock *sk); 41653d3176bSChangli Gao extern unsigned int tcp_poll(struct file * file, struct socket *sock, 41753d3176bSChangli Gao struct poll_table_struct *wait); 41853d3176bSChangli Gao extern int tcp_getsockopt(struct sock *sk, int level, int optname, 4193fdadf7dSDmitry Mishin char __user *optval, int __user *optlen); 42053d3176bSChangli Gao extern int tcp_setsockopt(struct sock *sk, int level, int optname, 42153d3176bSChangli Gao char __user *optval, unsigned int optlen); 42253d3176bSChangli Gao extern int compat_tcp_getsockopt(struct sock *sk, int level, int optname, 42353d3176bSChangli Gao char __user *optval, int __user *optlen); 42453d3176bSChangli Gao extern int compat_tcp_setsockopt(struct sock *sk, int level, int optname, 425b7058842SDavid S. Miller char __user *optval, unsigned int optlen); 4261da177e4SLinus Torvalds extern void tcp_set_keepalive(struct sock *sk, int val); 42753d3176bSChangli Gao extern void tcp_syn_ack_timeout(struct sock *sk, struct request_sock *req); 42853d3176bSChangli Gao extern int tcp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, 42953d3176bSChangli Gao size_t len, int nonblock, int flags, int *addr_len); 430cf533ea5SEric Dumazet extern void tcp_parse_options(const struct sk_buff *skb, 431cf533ea5SEric Dumazet struct tcp_options_received *opt_rx, const u8 **hvpp, 4322100c8d2SYuchung Cheng int estab, struct tcp_fastopen_cookie *foc); 433cf533ea5SEric Dumazet extern const u8 *tcp_parse_md5sig_option(const struct tcphdr *th); 4347d5d5525SYOSHIFUJI Hideaki 4351da177e4SLinus Torvalds /* 4361da177e4SLinus Torvalds * TCP v4 functions exported for the inet6 API 4371da177e4SLinus Torvalds */ 4381da177e4SLinus Torvalds 43953d3176bSChangli Gao extern void tcp_v4_send_check(struct sock *sk, struct sk_buff *skb); 44053d3176bSChangli Gao extern int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb); 4411da177e4SLinus Torvalds extern struct sock * tcp_create_openreq_child(struct sock *sk, 44260236fddSArnaldo Carvalho de Melo struct request_sock *req, 4431da177e4SLinus Torvalds struct sk_buff *skb); 44453d3176bSChangli Gao extern struct sock * tcp_v4_syn_recv_sock(struct sock *sk, struct sk_buff *skb, 44560236fddSArnaldo Carvalho de Melo struct request_sock *req, 4461da177e4SLinus Torvalds struct dst_entry *dst); 44753d3176bSChangli Gao extern int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb); 44853d3176bSChangli Gao extern int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, 4491da177e4SLinus Torvalds int addr_len); 4501da177e4SLinus Torvalds extern int tcp_connect(struct sock *sk); 45153d3176bSChangli Gao extern struct sk_buff * tcp_make_synack(struct sock *sk, struct dst_entry *dst, 452e6b4d113SWilliam Allen Simpson struct request_sock *req, 453e6b4d113SWilliam Allen Simpson struct request_values *rvp); 4541da177e4SLinus Torvalds extern int tcp_disconnect(struct sock *sk, int flags); 4551da177e4SLinus Torvalds 456370816aeSPavel Emelyanov void tcp_connect_init(struct sock *sk); 457370816aeSPavel Emelyanov void tcp_finish_connect(struct sock *sk, struct sk_buff *skb); 458292e8d8cSPavel Emelyanov int tcp_send_rcvq(struct sock *sk, struct msghdr *msg, size_t size); 4591da177e4SLinus Torvalds 4601da177e4SLinus Torvalds /* From syncookies.c */ 4612051f11fSFlorian Westphal extern __u32 syncookie_secret[2][16-4+SHA_DIGEST_WORDS]; 4621da177e4SLinus Torvalds extern struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb, 4631da177e4SLinus Torvalds struct ip_options *opt); 464e05c82d3SEric Dumazet #ifdef CONFIG_SYN_COOKIES 4651da177e4SLinus Torvalds extern __u32 cookie_v4_init_sequence(struct sock *sk, struct sk_buff *skb, 4661da177e4SLinus Torvalds __u16 *mss); 467e05c82d3SEric Dumazet #else 468e05c82d3SEric Dumazet static inline __u32 cookie_v4_init_sequence(struct sock *sk, 469e05c82d3SEric Dumazet struct sk_buff *skb, 470e05c82d3SEric Dumazet __u16 *mss) 471e05c82d3SEric Dumazet { 472e05c82d3SEric Dumazet return 0; 473e05c82d3SEric Dumazet } 474e05c82d3SEric Dumazet #endif 4751da177e4SLinus Torvalds 4764dfc2817SFlorian Westphal extern __u32 cookie_init_timestamp(struct request_sock *req); 477172d69e6SFlorian Westphal extern bool cookie_check_timestamp(struct tcp_options_received *opt, bool *); 4784dfc2817SFlorian Westphal 479c6aefafbSGlenn Griffin /* From net/ipv6/syncookies.c */ 480c6aefafbSGlenn Griffin extern struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb); 481e05c82d3SEric Dumazet #ifdef CONFIG_SYN_COOKIES 482cf533ea5SEric Dumazet extern __u32 cookie_v6_init_sequence(struct sock *sk, const struct sk_buff *skb, 483c6aefafbSGlenn Griffin __u16 *mss); 484e05c82d3SEric Dumazet #else 485e05c82d3SEric Dumazet static inline __u32 cookie_v6_init_sequence(struct sock *sk, 486e05c82d3SEric Dumazet struct sk_buff *skb, 487e05c82d3SEric Dumazet __u16 *mss) 488e05c82d3SEric Dumazet { 489e05c82d3SEric Dumazet return 0; 490e05c82d3SEric Dumazet } 491e05c82d3SEric Dumazet #endif 4921da177e4SLinus Torvalds /* tcp_output.c */ 4931da177e4SLinus Torvalds 4949e412ba7SIlpo Järvinen extern void __tcp_push_pending_frames(struct sock *sk, unsigned int cur_mss, 4959e412ba7SIlpo Järvinen int nonagle); 496a2a385d6SEric Dumazet extern bool tcp_may_send_now(struct sock *sk); 4971da177e4SLinus Torvalds extern int tcp_retransmit_skb(struct sock *, struct sk_buff *); 498f1ecd5d9SDamian Lukowski extern void tcp_retransmit_timer(struct sock *sk); 4991da177e4SLinus Torvalds extern void tcp_xmit_retransmit_queue(struct sock *); 5001da177e4SLinus Torvalds extern void tcp_simple_retransmit(struct sock *); 5011da177e4SLinus Torvalds extern int tcp_trim_head(struct sock *, struct sk_buff *, u32); 5026475be16SDavid S. Miller extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int); 5031da177e4SLinus Torvalds 5041da177e4SLinus Torvalds extern void tcp_send_probe0(struct sock *); 5051da177e4SLinus Torvalds extern void tcp_send_partial(struct sock *); 5061da177e4SLinus Torvalds extern int tcp_write_wakeup(struct sock *); 5071da177e4SLinus Torvalds extern void tcp_send_fin(struct sock *sk); 508dd0fc66fSAl Viro extern void tcp_send_active_reset(struct sock *sk, gfp_t priority); 5091da177e4SLinus Torvalds extern int tcp_send_synack(struct sock *); 510a2a385d6SEric Dumazet extern bool tcp_syn_flood_action(struct sock *sk, 511946cedccSEric Dumazet const struct sk_buff *skb, 512946cedccSEric Dumazet const char *proto); 513c1b4a7e6SDavid S. Miller extern void tcp_push_one(struct sock *, unsigned int mss_now); 5141da177e4SLinus Torvalds extern void tcp_send_ack(struct sock *sk); 5151da177e4SLinus Torvalds extern void tcp_send_delayed_ack(struct sock *sk); 5161da177e4SLinus Torvalds 517a762a980SDavid S. Miller /* tcp_input.c */ 518a762a980SDavid S. Miller extern void tcp_cwnd_application_limited(struct sock *sk); 519750ea2baSYuchung Cheng extern void tcp_resume_early_retransmit(struct sock *sk); 520750ea2baSYuchung Cheng extern void tcp_rearm_rto(struct sock *sk); 521a762a980SDavid S. Miller 5221da177e4SLinus Torvalds /* tcp_timer.c */ 5231da177e4SLinus Torvalds extern void tcp_init_xmit_timers(struct sock *); 524463c84b9SArnaldo Carvalho de Melo static inline void tcp_clear_xmit_timers(struct sock *sk) 525463c84b9SArnaldo Carvalho de Melo { 526463c84b9SArnaldo Carvalho de Melo inet_csk_clear_xmit_timers(sk); 527463c84b9SArnaldo Carvalho de Melo } 5281da177e4SLinus Torvalds 5291da177e4SLinus Torvalds extern unsigned int tcp_sync_mss(struct sock *sk, u32 pmtu); 5300c54b85fSIlpo Järvinen extern unsigned int tcp_current_mss(struct sock *sk); 5310c54b85fSIlpo Järvinen 5320c54b85fSIlpo Järvinen /* Bound MSS / TSO packet size with the half of the window */ 5330c54b85fSIlpo Järvinen static inline int tcp_bound_to_half_wnd(struct tcp_sock *tp, int pktsize) 5340c54b85fSIlpo Järvinen { 53501f83d69SAlexey Kuznetsov int cutoff; 53601f83d69SAlexey Kuznetsov 53701f83d69SAlexey Kuznetsov /* When peer uses tiny windows, there is no use in packetizing 53801f83d69SAlexey Kuznetsov * to sub-MSS pieces for the sake of SWS or making sure there 53901f83d69SAlexey Kuznetsov * are enough packets in the pipe for fast recovery. 54001f83d69SAlexey Kuznetsov * 54101f83d69SAlexey Kuznetsov * On the other hand, for extremely large MSS devices, handling 54201f83d69SAlexey Kuznetsov * smaller than MSS windows in this way does make sense. 54301f83d69SAlexey Kuznetsov */ 54401f83d69SAlexey Kuznetsov if (tp->max_window >= 512) 54501f83d69SAlexey Kuznetsov cutoff = (tp->max_window >> 1); 54601f83d69SAlexey Kuznetsov else 54701f83d69SAlexey Kuznetsov cutoff = tp->max_window; 54801f83d69SAlexey Kuznetsov 54901f83d69SAlexey Kuznetsov if (cutoff && pktsize > cutoff) 55001f83d69SAlexey Kuznetsov return max_t(int, cutoff, 68U - tp->tcp_header_len); 5510c54b85fSIlpo Järvinen else 5520c54b85fSIlpo Järvinen return pktsize; 5530c54b85fSIlpo Järvinen } 5541da177e4SLinus Torvalds 55517b085eaSArnaldo Carvalho de Melo /* tcp.c */ 556cf533ea5SEric Dumazet extern void tcp_get_info(const struct sock *, struct tcp_info *); 5571da177e4SLinus Torvalds 5581da177e4SLinus Torvalds /* Read 'sendfile()'-style from a TCP socket */ 5591da177e4SLinus Torvalds typedef int (*sk_read_actor_t)(read_descriptor_t *, struct sk_buff *, 5601da177e4SLinus Torvalds unsigned int, size_t); 5611da177e4SLinus Torvalds extern int tcp_read_sock(struct sock *sk, read_descriptor_t *desc, 5621da177e4SLinus Torvalds sk_read_actor_t recv_actor); 5631da177e4SLinus Torvalds 56440efc6faSStephen Hemminger extern void tcp_initialize_rcv_mss(struct sock *sk); 5651da177e4SLinus Torvalds 56667469601SEric Dumazet extern int tcp_mtu_to_mss(struct sock *sk, int pmtu); 56767469601SEric Dumazet extern int tcp_mss_to_mtu(struct sock *sk, int mss); 5685d424d5aSJohn Heffner extern void tcp_mtup_init(struct sock *sk); 5699ad7c049SJerry Chu extern void tcp_valid_rtt_meas(struct sock *sk, u32 seq_rtt); 5705d424d5aSJohn Heffner 571f1ecd5d9SDamian Lukowski static inline void tcp_bound_rto(const struct sock *sk) 572f1ecd5d9SDamian Lukowski { 573f1ecd5d9SDamian Lukowski if (inet_csk(sk)->icsk_rto > TCP_RTO_MAX) 574f1ecd5d9SDamian Lukowski inet_csk(sk)->icsk_rto = TCP_RTO_MAX; 575f1ecd5d9SDamian Lukowski } 576f1ecd5d9SDamian Lukowski 577f1ecd5d9SDamian Lukowski static inline u32 __tcp_set_rto(const struct tcp_sock *tp) 578f1ecd5d9SDamian Lukowski { 579f1ecd5d9SDamian Lukowski return (tp->srtt >> 3) + tp->rttvar; 580f1ecd5d9SDamian Lukowski } 581f1ecd5d9SDamian Lukowski 5824aabd8efSDavid S. Miller extern void tcp_set_rto(struct sock *sk); 5834aabd8efSDavid S. Miller 58440efc6faSStephen Hemminger static inline void __tcp_fast_path_on(struct tcp_sock *tp, u32 snd_wnd) 5851da177e4SLinus Torvalds { 5861da177e4SLinus Torvalds tp->pred_flags = htonl((tp->tcp_header_len << 26) | 5871da177e4SLinus Torvalds ntohl(TCP_FLAG_ACK) | 5881da177e4SLinus Torvalds snd_wnd); 5891da177e4SLinus Torvalds } 5901da177e4SLinus Torvalds 59140efc6faSStephen Hemminger static inline void tcp_fast_path_on(struct tcp_sock *tp) 5921da177e4SLinus Torvalds { 5931da177e4SLinus Torvalds __tcp_fast_path_on(tp, tp->snd_wnd >> tp->rx_opt.snd_wscale); 5941da177e4SLinus Torvalds } 5951da177e4SLinus Torvalds 5969e412ba7SIlpo Järvinen static inline void tcp_fast_path_check(struct sock *sk) 5971da177e4SLinus Torvalds { 5989e412ba7SIlpo Järvinen struct tcp_sock *tp = tcp_sk(sk); 5999e412ba7SIlpo Järvinen 600b03efcfbSDavid S. Miller if (skb_queue_empty(&tp->out_of_order_queue) && 6011da177e4SLinus Torvalds tp->rcv_wnd && 6021da177e4SLinus Torvalds atomic_read(&sk->sk_rmem_alloc) < sk->sk_rcvbuf && 6031da177e4SLinus Torvalds !tp->urg_data) 6041da177e4SLinus Torvalds tcp_fast_path_on(tp); 6051da177e4SLinus Torvalds } 6061da177e4SLinus Torvalds 6070c266898SSatoru SATOH /* Compute the actual rto_min value */ 6080c266898SSatoru SATOH static inline u32 tcp_rto_min(struct sock *sk) 6090c266898SSatoru SATOH { 610cf533ea5SEric Dumazet const struct dst_entry *dst = __sk_dst_get(sk); 6110c266898SSatoru SATOH u32 rto_min = TCP_RTO_MIN; 6120c266898SSatoru SATOH 6130c266898SSatoru SATOH if (dst && dst_metric_locked(dst, RTAX_RTO_MIN)) 6140c266898SSatoru SATOH rto_min = dst_metric_rtt(dst, RTAX_RTO_MIN); 6150c266898SSatoru SATOH return rto_min; 6160c266898SSatoru SATOH } 6170c266898SSatoru SATOH 6181da177e4SLinus Torvalds /* Compute the actual receive window we are currently advertising. 6191da177e4SLinus Torvalds * Rcv_nxt can be after the window if our peer push more data 6201da177e4SLinus Torvalds * than the offered window. 6211da177e4SLinus Torvalds */ 62240efc6faSStephen Hemminger static inline u32 tcp_receive_window(const struct tcp_sock *tp) 6231da177e4SLinus Torvalds { 6241da177e4SLinus Torvalds s32 win = tp->rcv_wup + tp->rcv_wnd - tp->rcv_nxt; 6251da177e4SLinus Torvalds 6261da177e4SLinus Torvalds if (win < 0) 6271da177e4SLinus Torvalds win = 0; 6281da177e4SLinus Torvalds return (u32) win; 6291da177e4SLinus Torvalds } 6301da177e4SLinus Torvalds 6311da177e4SLinus Torvalds /* Choose a new window, without checks for shrinking, and without 6321da177e4SLinus Torvalds * scaling applied to the result. The caller does these things 6331da177e4SLinus Torvalds * if necessary. This is a "raw" window selection. 6341da177e4SLinus Torvalds */ 6351da177e4SLinus Torvalds extern u32 __tcp_select_window(struct sock *sk); 6361da177e4SLinus Torvalds 637ee995283SPavel Emelyanov void tcp_send_window_probe(struct sock *sk); 638ee995283SPavel Emelyanov 6391da177e4SLinus Torvalds /* TCP timestamps are only 32-bits, this causes a slight 6401da177e4SLinus Torvalds * complication on 64-bit systems since we store a snapshot 64131f34269SStephen Hemminger * of jiffies in the buffer control blocks below. We decided 64231f34269SStephen Hemminger * to use only the low 32-bits of jiffies and hide the ugly 6431da177e4SLinus Torvalds * casts with the following macro. 6441da177e4SLinus Torvalds */ 6451da177e4SLinus Torvalds #define tcp_time_stamp ((__u32)(jiffies)) 6461da177e4SLinus Torvalds 647a3433f35SChangli Gao #define tcp_flag_byte(th) (((u_int8_t *)th)[13]) 648a3433f35SChangli Gao 649a3433f35SChangli Gao #define TCPHDR_FIN 0x01 650a3433f35SChangli Gao #define TCPHDR_SYN 0x02 651a3433f35SChangli Gao #define TCPHDR_RST 0x04 652a3433f35SChangli Gao #define TCPHDR_PSH 0x08 653a3433f35SChangli Gao #define TCPHDR_ACK 0x10 654a3433f35SChangli Gao #define TCPHDR_URG 0x20 655a3433f35SChangli Gao #define TCPHDR_ECE 0x40 656a3433f35SChangli Gao #define TCPHDR_CWR 0x80 657a3433f35SChangli Gao 658caa20d9aSStephen Hemminger /* This is what the send packet queuing engine uses to pass 659f86586faSEric Dumazet * TCP per-packet control information to the transmission code. 660f86586faSEric Dumazet * We also store the host-order sequence numbers in here too. 661f86586faSEric Dumazet * This is 44 bytes if IPV6 is enabled. 662f86586faSEric Dumazet * If this grows please adjust skbuff.h:skbuff->cb[xxx] size appropriately. 6631da177e4SLinus Torvalds */ 6641da177e4SLinus Torvalds struct tcp_skb_cb { 6651da177e4SLinus Torvalds union { 6661da177e4SLinus Torvalds struct inet_skb_parm h4; 667dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 6681da177e4SLinus Torvalds struct inet6_skb_parm h6; 6691da177e4SLinus Torvalds #endif 6701da177e4SLinus Torvalds } header; /* For incoming frames */ 6711da177e4SLinus Torvalds __u32 seq; /* Starting sequence number */ 6721da177e4SLinus Torvalds __u32 end_seq; /* SEQ + FIN + SYN + datalen */ 6731da177e4SLinus Torvalds __u32 when; /* used to compute rtt's */ 6744de075e0SEric Dumazet __u8 tcp_flags; /* TCP header flags. (tcp[13]) */ 675f4f9f6e7SNeal Cardwell 6761da177e4SLinus Torvalds __u8 sacked; /* State flags for SACK/FACK. */ 6771da177e4SLinus Torvalds #define TCPCB_SACKED_ACKED 0x01 /* SKB ACK'd by a SACK block */ 6781da177e4SLinus Torvalds #define TCPCB_SACKED_RETRANS 0x02 /* SKB retransmitted */ 6791da177e4SLinus Torvalds #define TCPCB_LOST 0x04 /* SKB is lost */ 6801da177e4SLinus Torvalds #define TCPCB_TAGBITS 0x07 /* All tag bits */ 6811da177e4SLinus Torvalds #define TCPCB_EVER_RETRANS 0x80 /* Ever retransmitted frame */ 6821da177e4SLinus Torvalds #define TCPCB_RETRANS (TCPCB_SACKED_RETRANS|TCPCB_EVER_RETRANS) 6831da177e4SLinus Torvalds 684f4f9f6e7SNeal Cardwell __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */ 685f4f9f6e7SNeal Cardwell /* 1 byte hole */ 6861da177e4SLinus Torvalds __u32 ack_seq; /* Sequence number ACK'd */ 6871da177e4SLinus Torvalds }; 6881da177e4SLinus Torvalds 6891da177e4SLinus Torvalds #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0])) 6901da177e4SLinus Torvalds 691bd14b1b2SEric Dumazet /* RFC3168 : 6.1.1 SYN packets must not have ECT/ECN bits set 692bd14b1b2SEric Dumazet * 693bd14b1b2SEric Dumazet * If we receive a SYN packet with these bits set, it means a network is 694bd14b1b2SEric Dumazet * playing bad games with TOS bits. In order to avoid possible false congestion 695bd14b1b2SEric Dumazet * notifications, we disable TCP ECN negociation. 696bd14b1b2SEric Dumazet */ 697bd14b1b2SEric Dumazet static inline void 698bd14b1b2SEric Dumazet TCP_ECN_create_request(struct request_sock *req, const struct sk_buff *skb) 699bd14b1b2SEric Dumazet { 700bd14b1b2SEric Dumazet const struct tcphdr *th = tcp_hdr(skb); 701bd14b1b2SEric Dumazet 702bd14b1b2SEric Dumazet if (sysctl_tcp_ecn && th->ece && th->cwr && 703bd14b1b2SEric Dumazet INET_ECN_is_not_ect(TCP_SKB_CB(skb)->ip_dsfield)) 704bd14b1b2SEric Dumazet inet_rsk(req)->ecn_ok = 1; 705bd14b1b2SEric Dumazet } 706bd14b1b2SEric Dumazet 7071da177e4SLinus Torvalds /* Due to TSO, an SKB can be composed of multiple actual 7081da177e4SLinus Torvalds * packets. To keep these tracked properly, we use this. 7091da177e4SLinus Torvalds */ 7101da177e4SLinus Torvalds static inline int tcp_skb_pcount(const struct sk_buff *skb) 7111da177e4SLinus Torvalds { 7127967168cSHerbert Xu return skb_shinfo(skb)->gso_segs; 7131da177e4SLinus Torvalds } 7141da177e4SLinus Torvalds 7151da177e4SLinus Torvalds /* This is valid iff tcp_skb_pcount() > 1. */ 7161da177e4SLinus Torvalds static inline int tcp_skb_mss(const struct sk_buff *skb) 7171da177e4SLinus Torvalds { 7187967168cSHerbert Xu return skb_shinfo(skb)->gso_size; 7191da177e4SLinus Torvalds } 7201da177e4SLinus Torvalds 721317a76f9SStephen Hemminger /* Events passed to congestion control interface */ 722317a76f9SStephen Hemminger enum tcp_ca_event { 723317a76f9SStephen Hemminger CA_EVENT_TX_START, /* first transmit when no packets in flight */ 724317a76f9SStephen Hemminger CA_EVENT_CWND_RESTART, /* congestion window restart */ 725317a76f9SStephen Hemminger CA_EVENT_COMPLETE_CWR, /* end of congestion recovery */ 726317a76f9SStephen Hemminger CA_EVENT_FRTO, /* fast recovery timeout */ 727317a76f9SStephen Hemminger CA_EVENT_LOSS, /* loss timeout */ 728317a76f9SStephen Hemminger CA_EVENT_FAST_ACK, /* in sequence ack */ 729317a76f9SStephen Hemminger CA_EVENT_SLOW_ACK, /* other ack */ 730317a76f9SStephen Hemminger }; 731317a76f9SStephen Hemminger 732317a76f9SStephen Hemminger /* 733317a76f9SStephen Hemminger * Interface for adding new TCP congestion control handlers 734317a76f9SStephen Hemminger */ 735317a76f9SStephen Hemminger #define TCP_CA_NAME_MAX 16 7363ff825b2SStephen Hemminger #define TCP_CA_MAX 128 7373ff825b2SStephen Hemminger #define TCP_CA_BUF_MAX (TCP_CA_NAME_MAX*TCP_CA_MAX) 7383ff825b2SStephen Hemminger 739164891aaSStephen Hemminger #define TCP_CONG_NON_RESTRICTED 0x1 740164891aaSStephen Hemminger #define TCP_CONG_RTT_STAMP 0x2 741164891aaSStephen Hemminger 742317a76f9SStephen Hemminger struct tcp_congestion_ops { 743317a76f9SStephen Hemminger struct list_head list; 744164891aaSStephen Hemminger unsigned long flags; 745317a76f9SStephen Hemminger 746317a76f9SStephen Hemminger /* initialize private data (optional) */ 7476687e988SArnaldo Carvalho de Melo void (*init)(struct sock *sk); 748317a76f9SStephen Hemminger /* cleanup private data (optional) */ 7496687e988SArnaldo Carvalho de Melo void (*release)(struct sock *sk); 750317a76f9SStephen Hemminger 751317a76f9SStephen Hemminger /* return slow start threshold (required) */ 7526687e988SArnaldo Carvalho de Melo u32 (*ssthresh)(struct sock *sk); 753317a76f9SStephen Hemminger /* lower bound for congestion window (optional) */ 75472dc5b92SStephen Hemminger u32 (*min_cwnd)(const struct sock *sk); 755317a76f9SStephen Hemminger /* do new cwnd calculation (required) */ 756c3a05c60SIlpo Järvinen void (*cong_avoid)(struct sock *sk, u32 ack, u32 in_flight); 757317a76f9SStephen Hemminger /* call before changing ca_state (optional) */ 7586687e988SArnaldo Carvalho de Melo void (*set_state)(struct sock *sk, u8 new_state); 759317a76f9SStephen Hemminger /* call when cwnd event occurs (optional) */ 7606687e988SArnaldo Carvalho de Melo void (*cwnd_event)(struct sock *sk, enum tcp_ca_event ev); 761317a76f9SStephen Hemminger /* new value of cwnd after loss (optional) */ 7626687e988SArnaldo Carvalho de Melo u32 (*undo_cwnd)(struct sock *sk); 763317a76f9SStephen Hemminger /* hook for packet ack accounting (optional) */ 76430cfd0baSStephen Hemminger void (*pkts_acked)(struct sock *sk, u32 num_acked, s32 rtt_us); 76573c1f4a0SArnaldo Carvalho de Melo /* get info for inet_diag (optional) */ 7666687e988SArnaldo Carvalho de Melo void (*get_info)(struct sock *sk, u32 ext, struct sk_buff *skb); 767317a76f9SStephen Hemminger 768317a76f9SStephen Hemminger char name[TCP_CA_NAME_MAX]; 769317a76f9SStephen Hemminger struct module *owner; 770317a76f9SStephen Hemminger }; 771317a76f9SStephen Hemminger 772317a76f9SStephen Hemminger extern int tcp_register_congestion_control(struct tcp_congestion_ops *type); 773317a76f9SStephen Hemminger extern void tcp_unregister_congestion_control(struct tcp_congestion_ops *type); 774317a76f9SStephen Hemminger 7756687e988SArnaldo Carvalho de Melo extern void tcp_init_congestion_control(struct sock *sk); 7766687e988SArnaldo Carvalho de Melo extern void tcp_cleanup_congestion_control(struct sock *sk); 777317a76f9SStephen Hemminger extern int tcp_set_default_congestion_control(const char *name); 778317a76f9SStephen Hemminger extern void tcp_get_default_congestion_control(char *name); 7793ff825b2SStephen Hemminger extern void tcp_get_available_congestion_control(char *buf, size_t len); 780ce7bc3bfSStephen Hemminger extern void tcp_get_allowed_congestion_control(char *buf, size_t len); 781ce7bc3bfSStephen Hemminger extern int tcp_set_allowed_congestion_control(char *allowed); 7826687e988SArnaldo Carvalho de Melo extern int tcp_set_congestion_control(struct sock *sk, const char *name); 78340efc6faSStephen Hemminger extern void tcp_slow_start(struct tcp_sock *tp); 784758ce5c8SIlpo Järvinen extern void tcp_cong_avoid_ai(struct tcp_sock *tp, u32 w); 785317a76f9SStephen Hemminger 7865f8ef48dSStephen Hemminger extern struct tcp_congestion_ops tcp_init_congestion_ops; 7876687e988SArnaldo Carvalho de Melo extern u32 tcp_reno_ssthresh(struct sock *sk); 788c3a05c60SIlpo Järvinen extern void tcp_reno_cong_avoid(struct sock *sk, u32 ack, u32 in_flight); 78972dc5b92SStephen Hemminger extern u32 tcp_reno_min_cwnd(const struct sock *sk); 790a8acfbacSDavid S. Miller extern struct tcp_congestion_ops tcp_reno; 791317a76f9SStephen Hemminger 7926687e988SArnaldo Carvalho de Melo static inline void tcp_set_ca_state(struct sock *sk, const u8 ca_state) 793317a76f9SStephen Hemminger { 7946687e988SArnaldo Carvalho de Melo struct inet_connection_sock *icsk = inet_csk(sk); 7956687e988SArnaldo Carvalho de Melo 7966687e988SArnaldo Carvalho de Melo if (icsk->icsk_ca_ops->set_state) 7976687e988SArnaldo Carvalho de Melo icsk->icsk_ca_ops->set_state(sk, ca_state); 7986687e988SArnaldo Carvalho de Melo icsk->icsk_ca_state = ca_state; 799317a76f9SStephen Hemminger } 800317a76f9SStephen Hemminger 8016687e988SArnaldo Carvalho de Melo static inline void tcp_ca_event(struct sock *sk, const enum tcp_ca_event event) 802317a76f9SStephen Hemminger { 8036687e988SArnaldo Carvalho de Melo const struct inet_connection_sock *icsk = inet_csk(sk); 8046687e988SArnaldo Carvalho de Melo 8056687e988SArnaldo Carvalho de Melo if (icsk->icsk_ca_ops->cwnd_event) 8066687e988SArnaldo Carvalho de Melo icsk->icsk_ca_ops->cwnd_event(sk, event); 807317a76f9SStephen Hemminger } 808317a76f9SStephen Hemminger 809e60402d0SIlpo Järvinen /* These functions determine how the current flow behaves in respect of SACK 810e60402d0SIlpo Järvinen * handling. SACK is negotiated with the peer, and therefore it can vary 811e60402d0SIlpo Järvinen * between different flows. 812e60402d0SIlpo Järvinen * 813e60402d0SIlpo Järvinen * tcp_is_sack - SACK enabled 814e60402d0SIlpo Järvinen * tcp_is_reno - No SACK 815e60402d0SIlpo Järvinen * tcp_is_fack - FACK enabled, implies SACK enabled 816e60402d0SIlpo Järvinen */ 817e60402d0SIlpo Järvinen static inline int tcp_is_sack(const struct tcp_sock *tp) 818e60402d0SIlpo Järvinen { 819e60402d0SIlpo Järvinen return tp->rx_opt.sack_ok; 820e60402d0SIlpo Järvinen } 821e60402d0SIlpo Järvinen 822a2a385d6SEric Dumazet static inline bool tcp_is_reno(const struct tcp_sock *tp) 823e60402d0SIlpo Järvinen { 824e60402d0SIlpo Järvinen return !tcp_is_sack(tp); 825e60402d0SIlpo Järvinen } 826e60402d0SIlpo Järvinen 827a2a385d6SEric Dumazet static inline bool tcp_is_fack(const struct tcp_sock *tp) 828e60402d0SIlpo Järvinen { 829ab56222aSVijay Subramanian return tp->rx_opt.sack_ok & TCP_FACK_ENABLED; 830e60402d0SIlpo Järvinen } 831e60402d0SIlpo Järvinen 832e60402d0SIlpo Järvinen static inline void tcp_enable_fack(struct tcp_sock *tp) 833e60402d0SIlpo Järvinen { 834ab56222aSVijay Subramanian tp->rx_opt.sack_ok |= TCP_FACK_ENABLED; 835e60402d0SIlpo Järvinen } 836e60402d0SIlpo Järvinen 837eed530b6SYuchung Cheng /* TCP early-retransmit (ER) is similar to but more conservative than 838eed530b6SYuchung Cheng * the thin-dupack feature. Enable ER only if thin-dupack is disabled. 839eed530b6SYuchung Cheng */ 840eed530b6SYuchung Cheng static inline void tcp_enable_early_retrans(struct tcp_sock *tp) 841eed530b6SYuchung Cheng { 842eed530b6SYuchung Cheng tp->do_early_retrans = sysctl_tcp_early_retrans && 843eed530b6SYuchung Cheng !sysctl_tcp_thin_dupack && sysctl_tcp_reordering == 3; 844750ea2baSYuchung Cheng tp->early_retrans_delayed = 0; 845eed530b6SYuchung Cheng } 846eed530b6SYuchung Cheng 847eed530b6SYuchung Cheng static inline void tcp_disable_early_retrans(struct tcp_sock *tp) 848eed530b6SYuchung Cheng { 849eed530b6SYuchung Cheng tp->do_early_retrans = 0; 850eed530b6SYuchung Cheng } 851eed530b6SYuchung Cheng 85283ae4088SIlpo Järvinen static inline unsigned int tcp_left_out(const struct tcp_sock *tp) 85383ae4088SIlpo Järvinen { 85483ae4088SIlpo Järvinen return tp->sacked_out + tp->lost_out; 85583ae4088SIlpo Järvinen } 85683ae4088SIlpo Järvinen 8571da177e4SLinus Torvalds /* This determines how many packets are "in the network" to the best 8581da177e4SLinus Torvalds * of our knowledge. In many cases it is conservative, but where 8591da177e4SLinus Torvalds * detailed information is available from the receiver (via SACK 8601da177e4SLinus Torvalds * blocks etc.) we can make more aggressive calculations. 8611da177e4SLinus Torvalds * 8621da177e4SLinus Torvalds * Use this for decisions involving congestion control, use just 8631da177e4SLinus Torvalds * tp->packets_out to determine if the send queue is empty or not. 8641da177e4SLinus Torvalds * 8651da177e4SLinus Torvalds * Read this equation as: 8661da177e4SLinus Torvalds * 8671da177e4SLinus Torvalds * "Packets sent once on transmission queue" MINUS 8681da177e4SLinus Torvalds * "Packets left network, but not honestly ACKed yet" PLUS 8691da177e4SLinus Torvalds * "Packets fast retransmitted" 8701da177e4SLinus Torvalds */ 87140efc6faSStephen Hemminger static inline unsigned int tcp_packets_in_flight(const struct tcp_sock *tp) 8721da177e4SLinus Torvalds { 87383ae4088SIlpo Järvinen return tp->packets_out - tcp_left_out(tp) + tp->retrans_out; 8741da177e4SLinus Torvalds } 8751da177e4SLinus Torvalds 8760b6a05c1SIlpo Järvinen #define TCP_INFINITE_SSTHRESH 0x7fffffff 8770b6a05c1SIlpo Järvinen 8780b6a05c1SIlpo Järvinen static inline bool tcp_in_initial_slowstart(const struct tcp_sock *tp) 8790b6a05c1SIlpo Järvinen { 8800b6a05c1SIlpo Järvinen return tp->snd_ssthresh >= TCP_INFINITE_SSTHRESH; 8810b6a05c1SIlpo Järvinen } 8820b6a05c1SIlpo Järvinen 8831da177e4SLinus Torvalds /* If cwnd > ssthresh, we may raise ssthresh to be half-way to cwnd. 8841da177e4SLinus Torvalds * The exception is rate halving phase, when cwnd is decreasing towards 8851da177e4SLinus Torvalds * ssthresh. 8861da177e4SLinus Torvalds */ 8876687e988SArnaldo Carvalho de Melo static inline __u32 tcp_current_ssthresh(const struct sock *sk) 8881da177e4SLinus Torvalds { 8896687e988SArnaldo Carvalho de Melo const struct tcp_sock *tp = tcp_sk(sk); 890cf533ea5SEric Dumazet 8916687e988SArnaldo Carvalho de Melo if ((1 << inet_csk(sk)->icsk_ca_state) & (TCPF_CA_CWR | TCPF_CA_Recovery)) 8921da177e4SLinus Torvalds return tp->snd_ssthresh; 8931da177e4SLinus Torvalds else 8941da177e4SLinus Torvalds return max(tp->snd_ssthresh, 8951da177e4SLinus Torvalds ((tp->snd_cwnd >> 1) + 8961da177e4SLinus Torvalds (tp->snd_cwnd >> 2))); 8971da177e4SLinus Torvalds } 8981da177e4SLinus Torvalds 899b9c4595bSIlpo Järvinen /* Use define here intentionally to get WARN_ON location shown at the caller */ 900b9c4595bSIlpo Järvinen #define tcp_verify_left_out(tp) WARN_ON(tcp_left_out(tp) > tp->packets_out) 9011da177e4SLinus Torvalds 9023cfe3baaSIlpo Järvinen extern void tcp_enter_cwr(struct sock *sk, const int set_ssthresh); 903cf533ea5SEric Dumazet extern __u32 tcp_init_cwnd(const struct tcp_sock *tp, const struct dst_entry *dst); 9041da177e4SLinus Torvalds 9056b5a5c0dSNeal Cardwell /* The maximum number of MSS of available cwnd for which TSO defers 9066b5a5c0dSNeal Cardwell * sending if not using sysctl_tcp_tso_win_divisor. 9076b5a5c0dSNeal Cardwell */ 9086b5a5c0dSNeal Cardwell static inline __u32 tcp_max_tso_deferred_mss(const struct tcp_sock *tp) 9096b5a5c0dSNeal Cardwell { 9106b5a5c0dSNeal Cardwell return 3; 9116b5a5c0dSNeal Cardwell } 9126b5a5c0dSNeal Cardwell 9131da177e4SLinus Torvalds /* Slow start with delack produces 3 packets of burst, so that 914dd9e0ddaSJohn Heffner * it is safe "de facto". This will be the default - same as 915dd9e0ddaSJohn Heffner * the default reordering threshold - but if reordering increases, 916dd9e0ddaSJohn Heffner * we must be able to allow cwnd to burst at least this much in order 917dd9e0ddaSJohn Heffner * to not pull it back when holes are filled. 9181da177e4SLinus Torvalds */ 9191da177e4SLinus Torvalds static __inline__ __u32 tcp_max_burst(const struct tcp_sock *tp) 9201da177e4SLinus Torvalds { 921dd9e0ddaSJohn Heffner return tp->reordering; 9221da177e4SLinus Torvalds } 9231da177e4SLinus Torvalds 92490840defSIlpo Järvinen /* Returns end sequence number of the receiver's advertised window */ 92590840defSIlpo Järvinen static inline u32 tcp_wnd_end(const struct tcp_sock *tp) 92690840defSIlpo Järvinen { 92790840defSIlpo Järvinen return tp->snd_una + tp->snd_wnd; 92890840defSIlpo Järvinen } 929a2a385d6SEric Dumazet extern bool tcp_is_cwnd_limited(const struct sock *sk, u32 in_flight); 930f4805edeSStephen Hemminger 931c1bd24b7SChuck Lever static inline void tcp_minshall_update(struct tcp_sock *tp, unsigned int mss, 9321da177e4SLinus Torvalds const struct sk_buff *skb) 9331da177e4SLinus Torvalds { 9341da177e4SLinus Torvalds if (skb->len < mss) 9351da177e4SLinus Torvalds tp->snd_sml = TCP_SKB_CB(skb)->end_seq; 9361da177e4SLinus Torvalds } 9371da177e4SLinus Torvalds 9389e412ba7SIlpo Järvinen static inline void tcp_check_probe_timer(struct sock *sk) 9391da177e4SLinus Torvalds { 940cf533ea5SEric Dumazet const struct tcp_sock *tp = tcp_sk(sk); 941463c84b9SArnaldo Carvalho de Melo const struct inet_connection_sock *icsk = inet_csk(sk); 9429e412ba7SIlpo Järvinen 943463c84b9SArnaldo Carvalho de Melo if (!tp->packets_out && !icsk->icsk_pending) 9443f421baaSArnaldo Carvalho de Melo inet_csk_reset_xmit_timer(sk, ICSK_TIME_PROBE0, 9453f421baaSArnaldo Carvalho de Melo icsk->icsk_rto, TCP_RTO_MAX); 9461da177e4SLinus Torvalds } 9471da177e4SLinus Torvalds 948ee7537b6SHantzis Fotis static inline void tcp_init_wl(struct tcp_sock *tp, u32 seq) 9491da177e4SLinus Torvalds { 9501da177e4SLinus Torvalds tp->snd_wl1 = seq; 9511da177e4SLinus Torvalds } 9521da177e4SLinus Torvalds 953ee7537b6SHantzis Fotis static inline void tcp_update_wl(struct tcp_sock *tp, u32 seq) 9541da177e4SLinus Torvalds { 9551da177e4SLinus Torvalds tp->snd_wl1 = seq; 9561da177e4SLinus Torvalds } 9571da177e4SLinus Torvalds 9581da177e4SLinus Torvalds /* 9591da177e4SLinus Torvalds * Calculate(/check) TCP checksum 9601da177e4SLinus Torvalds */ 961ba7808eaSFrederik Deweerdt static inline __sum16 tcp_v4_check(int len, __be32 saddr, 962ba7808eaSFrederik Deweerdt __be32 daddr, __wsum base) 9631da177e4SLinus Torvalds { 9641da177e4SLinus Torvalds return csum_tcpudp_magic(saddr,daddr,len,IPPROTO_TCP,base); 9651da177e4SLinus Torvalds } 9661da177e4SLinus Torvalds 967b51655b9SAl Viro static inline __sum16 __tcp_checksum_complete(struct sk_buff *skb) 9681da177e4SLinus Torvalds { 969fb286bb2SHerbert Xu return __skb_checksum_complete(skb); 9701da177e4SLinus Torvalds } 9711da177e4SLinus Torvalds 972a2a385d6SEric Dumazet static inline bool tcp_checksum_complete(struct sk_buff *skb) 9731da177e4SLinus Torvalds { 97460476372SHerbert Xu return !skb_csum_unnecessary(skb) && 9751da177e4SLinus Torvalds __tcp_checksum_complete(skb); 9761da177e4SLinus Torvalds } 9771da177e4SLinus Torvalds 9781da177e4SLinus Torvalds /* Prequeue for VJ style copy to user, combined with checksumming. */ 9791da177e4SLinus Torvalds 98040efc6faSStephen Hemminger static inline void tcp_prequeue_init(struct tcp_sock *tp) 9811da177e4SLinus Torvalds { 9821da177e4SLinus Torvalds tp->ucopy.task = NULL; 9831da177e4SLinus Torvalds tp->ucopy.len = 0; 9841da177e4SLinus Torvalds tp->ucopy.memory = 0; 9851da177e4SLinus Torvalds skb_queue_head_init(&tp->ucopy.prequeue); 98697fc2f08SChris Leech #ifdef CONFIG_NET_DMA 98797fc2f08SChris Leech tp->ucopy.dma_chan = NULL; 98897fc2f08SChris Leech tp->ucopy.wakeup = 0; 98997fc2f08SChris Leech tp->ucopy.pinned_list = NULL; 99097fc2f08SChris Leech tp->ucopy.dma_cookie = 0; 99197fc2f08SChris Leech #endif 9921da177e4SLinus Torvalds } 9931da177e4SLinus Torvalds 9941da177e4SLinus Torvalds /* Packet is added to VJ-style prequeue for processing in process 9951da177e4SLinus Torvalds * context, if a reader task is waiting. Apparently, this exciting 9961da177e4SLinus Torvalds * idea (VJ's mail "Re: query about TCP header on tcp-ip" of 07 Sep 93) 9971da177e4SLinus Torvalds * failed somewhere. Latency? Burstiness? Well, at least now we will 9981da177e4SLinus Torvalds * see, why it failed. 8)8) --ANK 9991da177e4SLinus Torvalds * 10001da177e4SLinus Torvalds * NOTE: is this not too big to inline? 10011da177e4SLinus Torvalds */ 1002a2a385d6SEric Dumazet static inline bool tcp_prequeue(struct sock *sk, struct sk_buff *skb) 10031da177e4SLinus Torvalds { 10041da177e4SLinus Torvalds struct tcp_sock *tp = tcp_sk(sk); 10051da177e4SLinus Torvalds 1006f5f8d86bSEric Dumazet if (sysctl_tcp_low_latency || !tp->ucopy.task) 1007a2a385d6SEric Dumazet return false; 1008f5f8d86bSEric Dumazet 10091da177e4SLinus Torvalds __skb_queue_tail(&tp->ucopy.prequeue, skb); 10101da177e4SLinus Torvalds tp->ucopy.memory += skb->truesize; 10111da177e4SLinus Torvalds if (tp->ucopy.memory > sk->sk_rcvbuf) { 10121da177e4SLinus Torvalds struct sk_buff *skb1; 10131da177e4SLinus Torvalds 10141da177e4SLinus Torvalds BUG_ON(sock_owned_by_user(sk)); 10151da177e4SLinus Torvalds 10161da177e4SLinus Torvalds while ((skb1 = __skb_dequeue(&tp->ucopy.prequeue)) != NULL) { 1017c57943a1SPeter Zijlstra sk_backlog_rcv(sk, skb1); 1018f5f8d86bSEric Dumazet NET_INC_STATS_BH(sock_net(sk), 1019f5f8d86bSEric Dumazet LINUX_MIB_TCPPREQUEUEDROPPED); 10201da177e4SLinus Torvalds } 10211da177e4SLinus Torvalds 10221da177e4SLinus Torvalds tp->ucopy.memory = 0; 10231da177e4SLinus Torvalds } else if (skb_queue_len(&tp->ucopy.prequeue) == 1) { 1024aa395145SEric Dumazet wake_up_interruptible_sync_poll(sk_sleep(sk), 10257aedec2aSEric Dumazet POLLIN | POLLRDNORM | POLLRDBAND); 1026463c84b9SArnaldo Carvalho de Melo if (!inet_csk_ack_scheduled(sk)) 1027463c84b9SArnaldo Carvalho de Melo inet_csk_reset_xmit_timer(sk, ICSK_TIME_DACK, 10280c266898SSatoru SATOH (3 * tcp_rto_min(sk)) / 4, 10293f421baaSArnaldo Carvalho de Melo TCP_RTO_MAX); 10301da177e4SLinus Torvalds } 1031a2a385d6SEric Dumazet return true; 10321da177e4SLinus Torvalds } 10331da177e4SLinus Torvalds 10341da177e4SLinus Torvalds 10351da177e4SLinus Torvalds #undef STATE_TRACE 10361da177e4SLinus Torvalds 10371da177e4SLinus Torvalds #ifdef STATE_TRACE 10381da177e4SLinus Torvalds static const char *statename[]={ 10391da177e4SLinus Torvalds "Unused","Established","Syn Sent","Syn Recv", 10401da177e4SLinus Torvalds "Fin Wait 1","Fin Wait 2","Time Wait", "Close", 10411da177e4SLinus Torvalds "Close Wait","Last ACK","Listen","Closing" 10421da177e4SLinus Torvalds }; 10431da177e4SLinus Torvalds #endif 1044490d5046SIlpo Järvinen extern void tcp_set_state(struct sock *sk, int state); 10451da177e4SLinus Torvalds 10464ac02babSAndi Kleen extern void tcp_done(struct sock *sk); 10471da177e4SLinus Torvalds 104840efc6faSStephen Hemminger static inline void tcp_sack_reset(struct tcp_options_received *rx_opt) 10491da177e4SLinus Torvalds { 10501da177e4SLinus Torvalds rx_opt->dsack = 0; 10511da177e4SLinus Torvalds rx_opt->num_sacks = 0; 10521da177e4SLinus Torvalds } 10531da177e4SLinus Torvalds 10541da177e4SLinus Torvalds /* Determine a window scaling and initial window to offer. */ 10551da177e4SLinus Torvalds extern void tcp_select_initial_window(int __space, __u32 mss, 10561da177e4SLinus Torvalds __u32 *rcv_wnd, __u32 *window_clamp, 105731d12926Slaurent chavey int wscale_ok, __u8 *rcv_wscale, 105831d12926Slaurent chavey __u32 init_rcv_wnd); 10591da177e4SLinus Torvalds 10601da177e4SLinus Torvalds static inline int tcp_win_from_space(int space) 10611da177e4SLinus Torvalds { 10621da177e4SLinus Torvalds return sysctl_tcp_adv_win_scale<=0 ? 10631da177e4SLinus Torvalds (space>>(-sysctl_tcp_adv_win_scale)) : 10641da177e4SLinus Torvalds space - (space>>sysctl_tcp_adv_win_scale); 10651da177e4SLinus Torvalds } 10661da177e4SLinus Torvalds 10671da177e4SLinus Torvalds /* Note: caller must be prepared to deal with negative returns */ 10681da177e4SLinus Torvalds static inline int tcp_space(const struct sock *sk) 10691da177e4SLinus Torvalds { 10701da177e4SLinus Torvalds return tcp_win_from_space(sk->sk_rcvbuf - 10711da177e4SLinus Torvalds atomic_read(&sk->sk_rmem_alloc)); 10721da177e4SLinus Torvalds } 10731da177e4SLinus Torvalds 10741da177e4SLinus Torvalds static inline int tcp_full_space(const struct sock *sk) 10751da177e4SLinus Torvalds { 10761da177e4SLinus Torvalds return tcp_win_from_space(sk->sk_rcvbuf); 10771da177e4SLinus Torvalds } 10781da177e4SLinus Torvalds 107940efc6faSStephen Hemminger static inline void tcp_openreq_init(struct request_sock *req, 10801da177e4SLinus Torvalds struct tcp_options_received *rx_opt, 10811da177e4SLinus Torvalds struct sk_buff *skb) 10821da177e4SLinus Torvalds { 10832e6599cbSArnaldo Carvalho de Melo struct inet_request_sock *ireq = inet_rsk(req); 10842e6599cbSArnaldo Carvalho de Melo 10851da177e4SLinus Torvalds req->rcv_wnd = 0; /* So that tcp_send_synack() knows! */ 10864dfc2817SFlorian Westphal req->cookie_ts = 0; 10872e6599cbSArnaldo Carvalho de Melo tcp_rsk(req)->rcv_isn = TCP_SKB_CB(skb)->seq; 10881da177e4SLinus Torvalds req->mss = rx_opt->mss_clamp; 10891da177e4SLinus Torvalds req->ts_recent = rx_opt->saw_tstamp ? rx_opt->rcv_tsval : 0; 10902e6599cbSArnaldo Carvalho de Melo ireq->tstamp_ok = rx_opt->tstamp_ok; 10912e6599cbSArnaldo Carvalho de Melo ireq->sack_ok = rx_opt->sack_ok; 10922e6599cbSArnaldo Carvalho de Melo ireq->snd_wscale = rx_opt->snd_wscale; 10932e6599cbSArnaldo Carvalho de Melo ireq->wscale_ok = rx_opt->wscale_ok; 10942e6599cbSArnaldo Carvalho de Melo ireq->acked = 0; 10952e6599cbSArnaldo Carvalho de Melo ireq->ecn_ok = 0; 1096aa8223c7SArnaldo Carvalho de Melo ireq->rmt_port = tcp_hdr(skb)->source; 1097a3116ac5SKOVACS Krisztian ireq->loc_port = tcp_hdr(skb)->dest; 10981da177e4SLinus Torvalds } 10991da177e4SLinus Torvalds 11005c52ba17SPavel Emelyanov extern void tcp_enter_memory_pressure(struct sock *sk); 11011da177e4SLinus Torvalds 11021da177e4SLinus Torvalds static inline int keepalive_intvl_when(const struct tcp_sock *tp) 11031da177e4SLinus Torvalds { 11041da177e4SLinus Torvalds return tp->keepalive_intvl ? : sysctl_tcp_keepalive_intvl; 11051da177e4SLinus Torvalds } 11061da177e4SLinus Torvalds 11071da177e4SLinus Torvalds static inline int keepalive_time_when(const struct tcp_sock *tp) 11081da177e4SLinus Torvalds { 11091da177e4SLinus Torvalds return tp->keepalive_time ? : sysctl_tcp_keepalive_time; 11101da177e4SLinus Torvalds } 11111da177e4SLinus Torvalds 1112df19a626SEric Dumazet static inline int keepalive_probes(const struct tcp_sock *tp) 1113df19a626SEric Dumazet { 1114df19a626SEric Dumazet return tp->keepalive_probes ? : sysctl_tcp_keepalive_probes; 1115df19a626SEric Dumazet } 1116df19a626SEric Dumazet 11176c37e5deSFlavio Leitner static inline u32 keepalive_time_elapsed(const struct tcp_sock *tp) 11186c37e5deSFlavio Leitner { 11196c37e5deSFlavio Leitner const struct inet_connection_sock *icsk = &tp->inet_conn; 11206c37e5deSFlavio Leitner 11216c37e5deSFlavio Leitner return min_t(u32, tcp_time_stamp - icsk->icsk_ack.lrcvtime, 11226c37e5deSFlavio Leitner tcp_time_stamp - tp->rcv_tstamp); 11236c37e5deSFlavio Leitner } 11246c37e5deSFlavio Leitner 1125463c84b9SArnaldo Carvalho de Melo static inline int tcp_fin_time(const struct sock *sk) 11261da177e4SLinus Torvalds { 1127463c84b9SArnaldo Carvalho de Melo int fin_timeout = tcp_sk(sk)->linger2 ? : sysctl_tcp_fin_timeout; 1128463c84b9SArnaldo Carvalho de Melo const int rto = inet_csk(sk)->icsk_rto; 11291da177e4SLinus Torvalds 1130463c84b9SArnaldo Carvalho de Melo if (fin_timeout < (rto << 2) - (rto >> 1)) 1131463c84b9SArnaldo Carvalho de Melo fin_timeout = (rto << 2) - (rto >> 1); 11321da177e4SLinus Torvalds 11331da177e4SLinus Torvalds return fin_timeout; 11341da177e4SLinus Torvalds } 11351da177e4SLinus Torvalds 1136a2a385d6SEric Dumazet static inline bool tcp_paws_check(const struct tcp_options_received *rx_opt, 1137c887e6d2SIlpo Järvinen int paws_win) 11381da177e4SLinus Torvalds { 1139c887e6d2SIlpo Järvinen if ((s32)(rx_opt->ts_recent - rx_opt->rcv_tsval) <= paws_win) 1140a2a385d6SEric Dumazet return true; 1141c887e6d2SIlpo Järvinen if (unlikely(get_seconds() >= rx_opt->ts_recent_stamp + TCP_PAWS_24DAYS)) 1142a2a385d6SEric Dumazet return true; 1143bc2ce894SEric Dumazet /* 1144bc2ce894SEric Dumazet * Some OSes send SYN and SYNACK messages with tsval=0 tsecr=0, 1145bc2ce894SEric Dumazet * then following tcp messages have valid values. Ignore 0 value, 1146bc2ce894SEric Dumazet * or else 'negative' tsval might forbid us to accept their packets. 1147bc2ce894SEric Dumazet */ 1148bc2ce894SEric Dumazet if (!rx_opt->ts_recent) 1149a2a385d6SEric Dumazet return true; 1150a2a385d6SEric Dumazet return false; 1151c887e6d2SIlpo Järvinen } 1152c887e6d2SIlpo Järvinen 1153a2a385d6SEric Dumazet static inline bool tcp_paws_reject(const struct tcp_options_received *rx_opt, 1154c887e6d2SIlpo Järvinen int rst) 1155c887e6d2SIlpo Järvinen { 1156c887e6d2SIlpo Järvinen if (tcp_paws_check(rx_opt, 0)) 1157a2a385d6SEric Dumazet return false; 11581da177e4SLinus Torvalds 11591da177e4SLinus Torvalds /* RST segments are not recommended to carry timestamp, 11601da177e4SLinus Torvalds and, if they do, it is recommended to ignore PAWS because 11611da177e4SLinus Torvalds "their cleanup function should take precedence over timestamps." 11621da177e4SLinus Torvalds Certainly, it is mistake. It is necessary to understand the reasons 11631da177e4SLinus Torvalds of this constraint to relax it: if peer reboots, clock may go 11641da177e4SLinus Torvalds out-of-sync and half-open connections will not be reset. 11651da177e4SLinus Torvalds Actually, the problem would be not existing if all 11661da177e4SLinus Torvalds the implementations followed draft about maintaining clock 11671da177e4SLinus Torvalds via reboots. Linux-2.2 DOES NOT! 11681da177e4SLinus Torvalds 11691da177e4SLinus Torvalds However, we can relax time bounds for RST segments to MSL. 11701da177e4SLinus Torvalds */ 11719d729f72SJames Morris if (rst && get_seconds() >= rx_opt->ts_recent_stamp + TCP_PAWS_MSL) 1172a2a385d6SEric Dumazet return false; 1173a2a385d6SEric Dumazet return true; 11741da177e4SLinus Torvalds } 11751da177e4SLinus Torvalds 1176a9c19329SPavel Emelyanov static inline void tcp_mib_init(struct net *net) 11771da177e4SLinus Torvalds { 11781da177e4SLinus Torvalds /* See RFC 2012 */ 1179cf1100a7SPavel Emelyanov TCP_ADD_STATS_USER(net, TCP_MIB_RTOALGORITHM, 1); 1180cf1100a7SPavel Emelyanov TCP_ADD_STATS_USER(net, TCP_MIB_RTOMIN, TCP_RTO_MIN*1000/HZ); 1181cf1100a7SPavel Emelyanov TCP_ADD_STATS_USER(net, TCP_MIB_RTOMAX, TCP_RTO_MAX*1000/HZ); 1182cf1100a7SPavel Emelyanov TCP_ADD_STATS_USER(net, TCP_MIB_MAXCONN, -1); 11831da177e4SLinus Torvalds } 11841da177e4SLinus Torvalds 11856a438bbeSStephen Hemminger /* from STCP */ 1186ef9da47cSIlpo Järvinen static inline void tcp_clear_retrans_hints_partial(struct tcp_sock *tp) 11870800f170SDavid S. Miller { 11886a438bbeSStephen Hemminger tp->lost_skb_hint = NULL; 11896a438bbeSStephen Hemminger tp->scoreboard_skb_hint = NULL; 1190ef9da47cSIlpo Järvinen } 1191ef9da47cSIlpo Järvinen 1192ef9da47cSIlpo Järvinen static inline void tcp_clear_all_retrans_hints(struct tcp_sock *tp) 1193ef9da47cSIlpo Järvinen { 1194ef9da47cSIlpo Järvinen tcp_clear_retrans_hints_partial(tp); 11956a438bbeSStephen Hemminger tp->retransmit_skb_hint = NULL; 1196b7689205SIlpo Järvinen } 1197b7689205SIlpo Järvinen 1198cfb6eeb4SYOSHIFUJI Hideaki /* MD5 Signature */ 1199cfb6eeb4SYOSHIFUJI Hideaki struct crypto_hash; 1200cfb6eeb4SYOSHIFUJI Hideaki 1201a915da9bSEric Dumazet union tcp_md5_addr { 1202a915da9bSEric Dumazet struct in_addr a4; 1203a915da9bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 1204a915da9bSEric Dumazet struct in6_addr a6; 1205a915da9bSEric Dumazet #endif 1206a915da9bSEric Dumazet }; 1207a915da9bSEric Dumazet 1208cfb6eeb4SYOSHIFUJI Hideaki /* - key database */ 1209cfb6eeb4SYOSHIFUJI Hideaki struct tcp_md5sig_key { 1210a915da9bSEric Dumazet struct hlist_node node; 1211cfb6eeb4SYOSHIFUJI Hideaki u8 keylen; 1212a915da9bSEric Dumazet u8 family; /* AF_INET or AF_INET6 */ 1213a915da9bSEric Dumazet union tcp_md5_addr addr; 1214a915da9bSEric Dumazet u8 key[TCP_MD5SIG_MAXKEYLEN]; 1215a915da9bSEric Dumazet struct rcu_head rcu; 1216cfb6eeb4SYOSHIFUJI Hideaki }; 1217cfb6eeb4SYOSHIFUJI Hideaki 1218cfb6eeb4SYOSHIFUJI Hideaki /* - sock block */ 1219cfb6eeb4SYOSHIFUJI Hideaki struct tcp_md5sig_info { 1220a915da9bSEric Dumazet struct hlist_head head; 1221a8afca03SEric Dumazet struct rcu_head rcu; 1222cfb6eeb4SYOSHIFUJI Hideaki }; 1223cfb6eeb4SYOSHIFUJI Hideaki 1224cfb6eeb4SYOSHIFUJI Hideaki /* - pseudo header */ 1225cfb6eeb4SYOSHIFUJI Hideaki struct tcp4_pseudohdr { 1226cfb6eeb4SYOSHIFUJI Hideaki __be32 saddr; 1227cfb6eeb4SYOSHIFUJI Hideaki __be32 daddr; 1228cfb6eeb4SYOSHIFUJI Hideaki __u8 pad; 1229cfb6eeb4SYOSHIFUJI Hideaki __u8 protocol; 1230cfb6eeb4SYOSHIFUJI Hideaki __be16 len; 1231cfb6eeb4SYOSHIFUJI Hideaki }; 1232cfb6eeb4SYOSHIFUJI Hideaki 1233cfb6eeb4SYOSHIFUJI Hideaki struct tcp6_pseudohdr { 1234cfb6eeb4SYOSHIFUJI Hideaki struct in6_addr saddr; 1235cfb6eeb4SYOSHIFUJI Hideaki struct in6_addr daddr; 1236cfb6eeb4SYOSHIFUJI Hideaki __be32 len; 1237cfb6eeb4SYOSHIFUJI Hideaki __be32 protocol; /* including padding */ 1238cfb6eeb4SYOSHIFUJI Hideaki }; 1239cfb6eeb4SYOSHIFUJI Hideaki 1240cfb6eeb4SYOSHIFUJI Hideaki union tcp_md5sum_block { 1241cfb6eeb4SYOSHIFUJI Hideaki struct tcp4_pseudohdr ip4; 1242dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6) 1243cfb6eeb4SYOSHIFUJI Hideaki struct tcp6_pseudohdr ip6; 1244cfb6eeb4SYOSHIFUJI Hideaki #endif 1245cfb6eeb4SYOSHIFUJI Hideaki }; 1246cfb6eeb4SYOSHIFUJI Hideaki 1247cfb6eeb4SYOSHIFUJI Hideaki /* - pool: digest algorithm, hash description and scratch buffer */ 1248cfb6eeb4SYOSHIFUJI Hideaki struct tcp_md5sig_pool { 1249cfb6eeb4SYOSHIFUJI Hideaki struct hash_desc md5_desc; 1250cfb6eeb4SYOSHIFUJI Hideaki union tcp_md5sum_block md5_blk; 1251cfb6eeb4SYOSHIFUJI Hideaki }; 1252cfb6eeb4SYOSHIFUJI Hideaki 1253cfb6eeb4SYOSHIFUJI Hideaki /* - functions */ 125453d3176bSChangli Gao extern int tcp_v4_md5_hash_skb(char *md5_hash, struct tcp_md5sig_key *key, 1255318cf7aaSEric Dumazet const struct sock *sk, 1256318cf7aaSEric Dumazet const struct request_sock *req, 1257318cf7aaSEric Dumazet const struct sk_buff *skb); 1258a915da9bSEric Dumazet extern int tcp_md5_do_add(struct sock *sk, const union tcp_md5_addr *addr, 1259a915da9bSEric Dumazet int family, const u8 *newkey, 1260a915da9bSEric Dumazet u8 newkeylen, gfp_t gfp); 1261a915da9bSEric Dumazet extern int tcp_md5_do_del(struct sock *sk, const union tcp_md5_addr *addr, 1262a915da9bSEric Dumazet int family); 1263cfb6eeb4SYOSHIFUJI Hideaki extern struct tcp_md5sig_key *tcp_v4_md5_lookup(struct sock *sk, 1264cfb6eeb4SYOSHIFUJI Hideaki struct sock *addr_sk); 1265cfb6eeb4SYOSHIFUJI Hideaki 12669501f972SYOSHIFUJI Hideaki #ifdef CONFIG_TCP_MD5SIG 1267a915da9bSEric Dumazet extern struct tcp_md5sig_key *tcp_md5_do_lookup(struct sock *sk, 1268a915da9bSEric Dumazet const union tcp_md5_addr *addr, int family); 1269a915da9bSEric Dumazet #define tcp_twsk_md5_key(twsk) ((twsk)->tw_md5_key) 12709501f972SYOSHIFUJI Hideaki #else 1271a915da9bSEric Dumazet static inline struct tcp_md5sig_key *tcp_md5_do_lookup(struct sock *sk, 1272a915da9bSEric Dumazet const union tcp_md5_addr *addr, 1273a915da9bSEric Dumazet int family) 1274a915da9bSEric Dumazet { 1275a915da9bSEric Dumazet return NULL; 1276a915da9bSEric Dumazet } 12779501f972SYOSHIFUJI Hideaki #define tcp_twsk_md5_key(twsk) NULL 12789501f972SYOSHIFUJI Hideaki #endif 12799501f972SYOSHIFUJI Hideaki 1280765cf997SEric Dumazet extern struct tcp_md5sig_pool __percpu *tcp_alloc_md5sig_pool(struct sock *); 1281cfb6eeb4SYOSHIFUJI Hideaki extern void tcp_free_md5sig_pool(void); 1282cfb6eeb4SYOSHIFUJI Hideaki 128335790c04SEric Dumazet extern struct tcp_md5sig_pool *tcp_get_md5sig_pool(void); 128435790c04SEric Dumazet extern void tcp_put_md5sig_pool(void); 128535790c04SEric Dumazet 1286ca35a0efSEric Dumazet extern int tcp_md5_hash_header(struct tcp_md5sig_pool *, const struct tcphdr *); 1287cf533ea5SEric Dumazet extern int tcp_md5_hash_skb_data(struct tcp_md5sig_pool *, const struct sk_buff *, 128895c96174SEric Dumazet unsigned int header_len); 128949a72dfbSAdam Langley extern int tcp_md5_hash_key(struct tcp_md5sig_pool *hp, 1290cf533ea5SEric Dumazet const struct tcp_md5sig_key *key); 1291cfb6eeb4SYOSHIFUJI Hideaki 1292*783237e8SYuchung Cheng struct tcp_fastopen_request { 1293*783237e8SYuchung Cheng /* Fast Open cookie. Size 0 means a cookie request */ 1294*783237e8SYuchung Cheng struct tcp_fastopen_cookie cookie; 1295*783237e8SYuchung Cheng struct msghdr *data; /* data in MSG_FASTOPEN */ 1296*783237e8SYuchung Cheng u16 copied; /* queued in tcp_connect() */ 1297*783237e8SYuchung Cheng }; 1298*783237e8SYuchung Cheng 1299*783237e8SYuchung Cheng void tcp_free_fastopen_req(struct tcp_sock *tp); 1300*783237e8SYuchung Cheng 1301fe067e8aSDavid S. Miller /* write queue abstraction */ 1302fe067e8aSDavid S. Miller static inline void tcp_write_queue_purge(struct sock *sk) 1303fe067e8aSDavid S. Miller { 1304fe067e8aSDavid S. Miller struct sk_buff *skb; 1305fe067e8aSDavid S. Miller 1306fe067e8aSDavid S. Miller while ((skb = __skb_dequeue(&sk->sk_write_queue)) != NULL) 13073ab224beSHideo Aoki sk_wmem_free_skb(sk, skb); 13083ab224beSHideo Aoki sk_mem_reclaim(sk); 13098818a9d8SIlpo Järvinen tcp_clear_all_retrans_hints(tcp_sk(sk)); 1310fe067e8aSDavid S. Miller } 1311fe067e8aSDavid S. Miller 1312cf533ea5SEric Dumazet static inline struct sk_buff *tcp_write_queue_head(const struct sock *sk) 1313fe067e8aSDavid S. Miller { 1314cd07a8eaSDavid S. Miller return skb_peek(&sk->sk_write_queue); 1315fe067e8aSDavid S. Miller } 1316fe067e8aSDavid S. Miller 1317cf533ea5SEric Dumazet static inline struct sk_buff *tcp_write_queue_tail(const struct sock *sk) 1318fe067e8aSDavid S. Miller { 1319cd07a8eaSDavid S. Miller return skb_peek_tail(&sk->sk_write_queue); 1320fe067e8aSDavid S. Miller } 1321fe067e8aSDavid S. Miller 1322cf533ea5SEric Dumazet static inline struct sk_buff *tcp_write_queue_next(const struct sock *sk, 1323cf533ea5SEric Dumazet const struct sk_buff *skb) 1324fe067e8aSDavid S. Miller { 1325cd07a8eaSDavid S. Miller return skb_queue_next(&sk->sk_write_queue, skb); 1326fe067e8aSDavid S. Miller } 1327fe067e8aSDavid S. Miller 1328cf533ea5SEric Dumazet static inline struct sk_buff *tcp_write_queue_prev(const struct sock *sk, 1329cf533ea5SEric Dumazet const struct sk_buff *skb) 1330832d11c5SIlpo Järvinen { 1331832d11c5SIlpo Järvinen return skb_queue_prev(&sk->sk_write_queue, skb); 1332832d11c5SIlpo Järvinen } 1333832d11c5SIlpo Järvinen 1334fe067e8aSDavid S. Miller #define tcp_for_write_queue(skb, sk) \ 1335cd07a8eaSDavid S. Miller skb_queue_walk(&(sk)->sk_write_queue, skb) 1336fe067e8aSDavid S. Miller 1337fe067e8aSDavid S. Miller #define tcp_for_write_queue_from(skb, sk) \ 1338cd07a8eaSDavid S. Miller skb_queue_walk_from(&(sk)->sk_write_queue, skb) 1339fe067e8aSDavid S. Miller 1340234b6860SIlpo Järvinen #define tcp_for_write_queue_from_safe(skb, tmp, sk) \ 1341cd07a8eaSDavid S. Miller skb_queue_walk_from_safe(&(sk)->sk_write_queue, skb, tmp) 1342234b6860SIlpo Järvinen 1343cf533ea5SEric Dumazet static inline struct sk_buff *tcp_send_head(const struct sock *sk) 1344fe067e8aSDavid S. Miller { 1345fe067e8aSDavid S. Miller return sk->sk_send_head; 1346fe067e8aSDavid S. Miller } 1347fe067e8aSDavid S. Miller 1348cd07a8eaSDavid S. Miller static inline bool tcp_skb_is_last(const struct sock *sk, 1349cd07a8eaSDavid S. Miller const struct sk_buff *skb) 1350cd07a8eaSDavid S. Miller { 1351cd07a8eaSDavid S. Miller return skb_queue_is_last(&sk->sk_write_queue, skb); 1352cd07a8eaSDavid S. Miller } 1353cd07a8eaSDavid S. Miller 1354cf533ea5SEric Dumazet static inline void tcp_advance_send_head(struct sock *sk, const struct sk_buff *skb) 1355fe067e8aSDavid S. Miller { 1356cd07a8eaSDavid S. Miller if (tcp_skb_is_last(sk, skb)) 1357fe067e8aSDavid S. Miller sk->sk_send_head = NULL; 1358cd07a8eaSDavid S. Miller else 1359cd07a8eaSDavid S. Miller sk->sk_send_head = tcp_write_queue_next(sk, skb); 1360fe067e8aSDavid S. Miller } 1361fe067e8aSDavid S. Miller 1362fe067e8aSDavid S. Miller static inline void tcp_check_send_head(struct sock *sk, struct sk_buff *skb_unlinked) 1363fe067e8aSDavid S. Miller { 1364fe067e8aSDavid S. Miller if (sk->sk_send_head == skb_unlinked) 1365fe067e8aSDavid S. Miller sk->sk_send_head = NULL; 1366fe067e8aSDavid S. Miller } 1367fe067e8aSDavid S. Miller 1368fe067e8aSDavid S. Miller static inline void tcp_init_send_head(struct sock *sk) 1369fe067e8aSDavid S. Miller { 1370fe067e8aSDavid S. Miller sk->sk_send_head = NULL; 1371fe067e8aSDavid S. Miller } 1372fe067e8aSDavid S. Miller 1373fe067e8aSDavid S. Miller static inline void __tcp_add_write_queue_tail(struct sock *sk, struct sk_buff *skb) 1374fe067e8aSDavid S. Miller { 1375fe067e8aSDavid S. Miller __skb_queue_tail(&sk->sk_write_queue, skb); 1376fe067e8aSDavid S. Miller } 1377fe067e8aSDavid S. Miller 1378fe067e8aSDavid S. Miller static inline void tcp_add_write_queue_tail(struct sock *sk, struct sk_buff *skb) 1379fe067e8aSDavid S. Miller { 1380fe067e8aSDavid S. Miller __tcp_add_write_queue_tail(sk, skb); 1381fe067e8aSDavid S. Miller 1382fe067e8aSDavid S. Miller /* Queue it, remembering where we must start sending. */ 13836859d494SIlpo Järvinen if (sk->sk_send_head == NULL) { 1384fe067e8aSDavid S. Miller sk->sk_send_head = skb; 13856859d494SIlpo Järvinen 13866859d494SIlpo Järvinen if (tcp_sk(sk)->highest_sack == NULL) 13876859d494SIlpo Järvinen tcp_sk(sk)->highest_sack = skb; 13886859d494SIlpo Järvinen } 1389fe067e8aSDavid S. Miller } 1390fe067e8aSDavid S. Miller 1391fe067e8aSDavid S. Miller static inline void __tcp_add_write_queue_head(struct sock *sk, struct sk_buff *skb) 1392fe067e8aSDavid S. Miller { 1393fe067e8aSDavid S. Miller __skb_queue_head(&sk->sk_write_queue, skb); 1394fe067e8aSDavid S. Miller } 1395fe067e8aSDavid S. Miller 1396fe067e8aSDavid S. Miller /* Insert buff after skb on the write queue of sk. */ 1397fe067e8aSDavid S. Miller static inline void tcp_insert_write_queue_after(struct sk_buff *skb, 1398fe067e8aSDavid S. Miller struct sk_buff *buff, 1399fe067e8aSDavid S. Miller struct sock *sk) 1400fe067e8aSDavid S. Miller { 14017de6c033SGerrit Renker __skb_queue_after(&sk->sk_write_queue, skb, buff); 1402fe067e8aSDavid S. Miller } 1403fe067e8aSDavid S. Miller 140443f59c89SDavid S. Miller /* Insert new before skb on the write queue of sk. */ 1405fe067e8aSDavid S. Miller static inline void tcp_insert_write_queue_before(struct sk_buff *new, 1406fe067e8aSDavid S. Miller struct sk_buff *skb, 1407fe067e8aSDavid S. Miller struct sock *sk) 1408fe067e8aSDavid S. Miller { 140943f59c89SDavid S. Miller __skb_queue_before(&sk->sk_write_queue, skb, new); 14106e421410SIlpo Järvinen 14116e421410SIlpo Järvinen if (sk->sk_send_head == skb) 14126e421410SIlpo Järvinen sk->sk_send_head = new; 1413fe067e8aSDavid S. Miller } 1414fe067e8aSDavid S. Miller 1415fe067e8aSDavid S. Miller static inline void tcp_unlink_write_queue(struct sk_buff *skb, struct sock *sk) 1416fe067e8aSDavid S. Miller { 1417fe067e8aSDavid S. Miller __skb_unlink(skb, &sk->sk_write_queue); 1418fe067e8aSDavid S. Miller } 1419fe067e8aSDavid S. Miller 1420a2a385d6SEric Dumazet static inline bool tcp_write_queue_empty(struct sock *sk) 1421fe067e8aSDavid S. Miller { 1422fe067e8aSDavid S. Miller return skb_queue_empty(&sk->sk_write_queue); 1423fe067e8aSDavid S. Miller } 1424fe067e8aSDavid S. Miller 142512d50c46SKrishna Kumar static inline void tcp_push_pending_frames(struct sock *sk) 142612d50c46SKrishna Kumar { 142712d50c46SKrishna Kumar if (tcp_send_head(sk)) { 142812d50c46SKrishna Kumar struct tcp_sock *tp = tcp_sk(sk); 142912d50c46SKrishna Kumar 143012d50c46SKrishna Kumar __tcp_push_pending_frames(sk, tcp_current_mss(sk), tp->nonagle); 143112d50c46SKrishna Kumar } 143212d50c46SKrishna Kumar } 143312d50c46SKrishna Kumar 1434ecb97192SNeal Cardwell /* Start sequence of the skb just after the highest skb with SACKed 1435ecb97192SNeal Cardwell * bit, valid only if sacked_out > 0 or when the caller has ensured 1436ecb97192SNeal Cardwell * validity by itself. 1437a47e5a98SIlpo Järvinen */ 1438a47e5a98SIlpo Järvinen static inline u32 tcp_highest_sack_seq(struct tcp_sock *tp) 1439a47e5a98SIlpo Järvinen { 1440a47e5a98SIlpo Järvinen if (!tp->sacked_out) 1441a47e5a98SIlpo Järvinen return tp->snd_una; 14426859d494SIlpo Järvinen 14436859d494SIlpo Järvinen if (tp->highest_sack == NULL) 14446859d494SIlpo Järvinen return tp->snd_nxt; 14456859d494SIlpo Järvinen 1446a47e5a98SIlpo Järvinen return TCP_SKB_CB(tp->highest_sack)->seq; 1447a47e5a98SIlpo Järvinen } 1448a47e5a98SIlpo Järvinen 14496859d494SIlpo Järvinen static inline void tcp_advance_highest_sack(struct sock *sk, struct sk_buff *skb) 14506859d494SIlpo Järvinen { 14516859d494SIlpo Järvinen tcp_sk(sk)->highest_sack = tcp_skb_is_last(sk, skb) ? NULL : 14526859d494SIlpo Järvinen tcp_write_queue_next(sk, skb); 14536859d494SIlpo Järvinen } 14546859d494SIlpo Järvinen 14556859d494SIlpo Järvinen static inline struct sk_buff *tcp_highest_sack(struct sock *sk) 14566859d494SIlpo Järvinen { 14576859d494SIlpo Järvinen return tcp_sk(sk)->highest_sack; 14586859d494SIlpo Järvinen } 14596859d494SIlpo Järvinen 14606859d494SIlpo Järvinen static inline void tcp_highest_sack_reset(struct sock *sk) 14616859d494SIlpo Järvinen { 14626859d494SIlpo Järvinen tcp_sk(sk)->highest_sack = tcp_write_queue_head(sk); 14636859d494SIlpo Järvinen } 14646859d494SIlpo Järvinen 14656859d494SIlpo Järvinen /* Called when old skb is about to be deleted (to be combined with new skb) */ 14666859d494SIlpo Järvinen static inline void tcp_highest_sack_combine(struct sock *sk, 14676859d494SIlpo Järvinen struct sk_buff *old, 14686859d494SIlpo Järvinen struct sk_buff *new) 14696859d494SIlpo Järvinen { 14706859d494SIlpo Järvinen if (tcp_sk(sk)->sacked_out && (old == tcp_sk(sk)->highest_sack)) 14716859d494SIlpo Järvinen tcp_sk(sk)->highest_sack = new; 14726859d494SIlpo Järvinen } 14736859d494SIlpo Järvinen 14745aa4b32fSAndreas Petlund /* Determines whether this is a thin stream (which may suffer from 14755aa4b32fSAndreas Petlund * increased latency). Used to trigger latency-reducing mechanisms. 14765aa4b32fSAndreas Petlund */ 1477a2a385d6SEric Dumazet static inline bool tcp_stream_is_thin(struct tcp_sock *tp) 14785aa4b32fSAndreas Petlund { 14795aa4b32fSAndreas Petlund return tp->packets_out < 4 && !tcp_in_initial_slowstart(tp); 14805aa4b32fSAndreas Petlund } 14815aa4b32fSAndreas Petlund 14821da177e4SLinus Torvalds /* /proc */ 14831da177e4SLinus Torvalds enum tcp_seq_states { 14841da177e4SLinus Torvalds TCP_SEQ_STATE_LISTENING, 14851da177e4SLinus Torvalds TCP_SEQ_STATE_OPENREQ, 14861da177e4SLinus Torvalds TCP_SEQ_STATE_ESTABLISHED, 14871da177e4SLinus Torvalds TCP_SEQ_STATE_TIME_WAIT, 14881da177e4SLinus Torvalds }; 14891da177e4SLinus Torvalds 149073cb88ecSArjan van de Ven int tcp_seq_open(struct inode *inode, struct file *file); 149173cb88ecSArjan van de Ven 14921da177e4SLinus Torvalds struct tcp_seq_afinfo { 14931da177e4SLinus Torvalds char *name; 14941da177e4SLinus Torvalds sa_family_t family; 149573cb88ecSArjan van de Ven const struct file_operations *seq_fops; 14969427c4b3SDenis V. Lunev struct seq_operations seq_ops; 14971da177e4SLinus Torvalds }; 14981da177e4SLinus Torvalds 14991da177e4SLinus Torvalds struct tcp_iter_state { 1500a4146b1bSDenis V. Lunev struct seq_net_private p; 15011da177e4SLinus Torvalds sa_family_t family; 15021da177e4SLinus Torvalds enum tcp_seq_states state; 15031da177e4SLinus Torvalds struct sock *syn_wait_sk; 1504a8b690f9STom Herbert int bucket, offset, sbucket, num, uid; 1505a8b690f9STom Herbert loff_t last_pos; 15061da177e4SLinus Torvalds }; 15071da177e4SLinus Torvalds 15086f8b13bcSDaniel Lezcano extern int tcp_proc_register(struct net *net, struct tcp_seq_afinfo *afinfo); 15096f8b13bcSDaniel Lezcano extern void tcp_proc_unregister(struct net *net, struct tcp_seq_afinfo *afinfo); 15101da177e4SLinus Torvalds 151120380731SArnaldo Carvalho de Melo extern struct request_sock_ops tcp_request_sock_ops; 1512c6aefafbSGlenn Griffin extern struct request_sock_ops tcp6_request_sock_ops; 151320380731SArnaldo Carvalho de Melo 15147d06b2e0SBrian Haley extern void tcp_v4_destroy_sock(struct sock *sk); 151520380731SArnaldo Carvalho de Melo 1516a430a43dSHerbert Xu extern int tcp_v4_gso_send_check(struct sk_buff *skb); 1517c8f44affSMichał Mirosław extern struct sk_buff *tcp_tso_segment(struct sk_buff *skb, 1518c8f44affSMichał Mirosław netdev_features_t features); 1519bf296b12SHerbert Xu extern struct sk_buff **tcp_gro_receive(struct sk_buff **head, 1520bf296b12SHerbert Xu struct sk_buff *skb); 1521bf296b12SHerbert Xu extern struct sk_buff **tcp4_gro_receive(struct sk_buff **head, 1522bf296b12SHerbert Xu struct sk_buff *skb); 1523bf296b12SHerbert Xu extern int tcp_gro_complete(struct sk_buff *skb); 1524bf296b12SHerbert Xu extern int tcp4_gro_complete(struct sk_buff *skb); 1525f4c50d99SHerbert Xu 152620380731SArnaldo Carvalho de Melo #ifdef CONFIG_PROC_FS 152720380731SArnaldo Carvalho de Melo extern int tcp4_proc_init(void); 152820380731SArnaldo Carvalho de Melo extern void tcp4_proc_exit(void); 152920380731SArnaldo Carvalho de Melo #endif 153020380731SArnaldo Carvalho de Melo 1531cfb6eeb4SYOSHIFUJI Hideaki /* TCP af-specific functions */ 1532cfb6eeb4SYOSHIFUJI Hideaki struct tcp_sock_af_ops { 1533cfb6eeb4SYOSHIFUJI Hideaki #ifdef CONFIG_TCP_MD5SIG 1534cfb6eeb4SYOSHIFUJI Hideaki struct tcp_md5sig_key *(*md5_lookup) (struct sock *sk, 1535cfb6eeb4SYOSHIFUJI Hideaki struct sock *addr_sk); 1536cfb6eeb4SYOSHIFUJI Hideaki int (*calc_md5_hash) (char *location, 1537cfb6eeb4SYOSHIFUJI Hideaki struct tcp_md5sig_key *md5, 1538318cf7aaSEric Dumazet const struct sock *sk, 1539318cf7aaSEric Dumazet const struct request_sock *req, 1540318cf7aaSEric Dumazet const struct sk_buff *skb); 1541cfb6eeb4SYOSHIFUJI Hideaki int (*md5_parse) (struct sock *sk, 1542cfb6eeb4SYOSHIFUJI Hideaki char __user *optval, 1543cfb6eeb4SYOSHIFUJI Hideaki int optlen); 1544cfb6eeb4SYOSHIFUJI Hideaki #endif 1545cfb6eeb4SYOSHIFUJI Hideaki }; 1546cfb6eeb4SYOSHIFUJI Hideaki 1547cfb6eeb4SYOSHIFUJI Hideaki struct tcp_request_sock_ops { 1548cfb6eeb4SYOSHIFUJI Hideaki #ifdef CONFIG_TCP_MD5SIG 1549cfb6eeb4SYOSHIFUJI Hideaki struct tcp_md5sig_key *(*md5_lookup) (struct sock *sk, 1550cfb6eeb4SYOSHIFUJI Hideaki struct request_sock *req); 1551e3afe7b7SJohn Dykstra int (*calc_md5_hash) (char *location, 1552e3afe7b7SJohn Dykstra struct tcp_md5sig_key *md5, 1553318cf7aaSEric Dumazet const struct sock *sk, 1554318cf7aaSEric Dumazet const struct request_sock *req, 1555318cf7aaSEric Dumazet const struct sk_buff *skb); 1556cfb6eeb4SYOSHIFUJI Hideaki #endif 1557cfb6eeb4SYOSHIFUJI Hideaki }; 1558cfb6eeb4SYOSHIFUJI Hideaki 1559da5c78c8SWilliam Allen Simpson /* Using SHA1 for now, define some constants. 1560da5c78c8SWilliam Allen Simpson */ 1561da5c78c8SWilliam Allen Simpson #define COOKIE_DIGEST_WORDS (SHA_DIGEST_WORDS) 1562da5c78c8SWilliam Allen Simpson #define COOKIE_MESSAGE_WORDS (SHA_MESSAGE_BYTES / 4) 1563da5c78c8SWilliam Allen Simpson #define COOKIE_WORKSPACE_WORDS (COOKIE_DIGEST_WORDS + COOKIE_MESSAGE_WORDS) 1564da5c78c8SWilliam Allen Simpson 1565da5c78c8SWilliam Allen Simpson extern int tcp_cookie_generator(u32 *bakery); 1566da5c78c8SWilliam Allen Simpson 1567435cf559SWilliam Allen Simpson /** 1568435cf559SWilliam Allen Simpson * struct tcp_cookie_values - each socket needs extra space for the 1569435cf559SWilliam Allen Simpson * cookies, together with (optional) space for any SYN data. 1570435cf559SWilliam Allen Simpson * 1571435cf559SWilliam Allen Simpson * A tcp_sock contains a pointer to the current value, and this is 1572435cf559SWilliam Allen Simpson * cloned to the tcp_timewait_sock. 1573435cf559SWilliam Allen Simpson * 1574435cf559SWilliam Allen Simpson * @cookie_pair: variable data from the option exchange. 1575435cf559SWilliam Allen Simpson * 1576435cf559SWilliam Allen Simpson * @cookie_desired: user specified tcpct_cookie_desired. Zero 1577435cf559SWilliam Allen Simpson * indicates default (sysctl_tcp_cookie_size). 1578435cf559SWilliam Allen Simpson * After cookie sent, remembers size of cookie. 1579435cf559SWilliam Allen Simpson * Range 0, TCP_COOKIE_MIN to TCP_COOKIE_MAX. 1580435cf559SWilliam Allen Simpson * 1581435cf559SWilliam Allen Simpson * @s_data_desired: user specified tcpct_s_data_desired. When the 1582435cf559SWilliam Allen Simpson * constant payload is specified (@s_data_constant), 1583435cf559SWilliam Allen Simpson * holds its length instead. 1584435cf559SWilliam Allen Simpson * Range 0 to TCP_MSS_DESIRED. 1585435cf559SWilliam Allen Simpson * 1586435cf559SWilliam Allen Simpson * @s_data_payload: constant data that is to be included in the 1587435cf559SWilliam Allen Simpson * payload of SYN or SYNACK segments when the 1588435cf559SWilliam Allen Simpson * cookie option is present. 1589435cf559SWilliam Allen Simpson */ 1590435cf559SWilliam Allen Simpson struct tcp_cookie_values { 1591435cf559SWilliam Allen Simpson struct kref kref; 1592435cf559SWilliam Allen Simpson u8 cookie_pair[TCP_COOKIE_PAIR_SIZE]; 1593435cf559SWilliam Allen Simpson u8 cookie_pair_size; 1594435cf559SWilliam Allen Simpson u8 cookie_desired; 1595435cf559SWilliam Allen Simpson u16 s_data_desired:11, 1596435cf559SWilliam Allen Simpson s_data_constant:1, 1597435cf559SWilliam Allen Simpson s_data_in:1, 1598435cf559SWilliam Allen Simpson s_data_out:1, 1599435cf559SWilliam Allen Simpson s_data_unused:2; 1600435cf559SWilliam Allen Simpson u8 s_data_payload[0]; 1601435cf559SWilliam Allen Simpson }; 1602435cf559SWilliam Allen Simpson 1603435cf559SWilliam Allen Simpson static inline void tcp_cookie_values_release(struct kref *kref) 1604435cf559SWilliam Allen Simpson { 1605435cf559SWilliam Allen Simpson kfree(container_of(kref, struct tcp_cookie_values, kref)); 1606435cf559SWilliam Allen Simpson } 1607435cf559SWilliam Allen Simpson 1608435cf559SWilliam Allen Simpson /* The length of constant payload data. Note that s_data_desired is 1609435cf559SWilliam Allen Simpson * overloaded, depending on s_data_constant: either the length of constant 1610435cf559SWilliam Allen Simpson * data (returned here) or the limit on variable data. 1611435cf559SWilliam Allen Simpson */ 1612435cf559SWilliam Allen Simpson static inline int tcp_s_data_size(const struct tcp_sock *tp) 1613435cf559SWilliam Allen Simpson { 1614435cf559SWilliam Allen Simpson return (tp->cookie_values != NULL && tp->cookie_values->s_data_constant) 1615435cf559SWilliam Allen Simpson ? tp->cookie_values->s_data_desired 1616435cf559SWilliam Allen Simpson : 0; 1617435cf559SWilliam Allen Simpson } 1618435cf559SWilliam Allen Simpson 1619435cf559SWilliam Allen Simpson /** 1620435cf559SWilliam Allen Simpson * struct tcp_extend_values - tcp_ipv?.c to tcp_output.c workspace. 1621435cf559SWilliam Allen Simpson * 1622435cf559SWilliam Allen Simpson * As tcp_request_sock has already been extended in other places, the 1623435cf559SWilliam Allen Simpson * only remaining method is to pass stack values along as function 1624435cf559SWilliam Allen Simpson * parameters. These parameters are not needed after sending SYNACK. 1625435cf559SWilliam Allen Simpson * 1626435cf559SWilliam Allen Simpson * @cookie_bakery: cryptographic secret and message workspace. 1627435cf559SWilliam Allen Simpson * 1628435cf559SWilliam Allen Simpson * @cookie_plus: bytes in authenticator/cookie option, copied from 1629435cf559SWilliam Allen Simpson * struct tcp_options_received (above). 1630435cf559SWilliam Allen Simpson */ 1631435cf559SWilliam Allen Simpson struct tcp_extend_values { 1632435cf559SWilliam Allen Simpson struct request_values rv; 1633435cf559SWilliam Allen Simpson u32 cookie_bakery[COOKIE_WORKSPACE_WORDS]; 1634435cf559SWilliam Allen Simpson u8 cookie_plus:6, 1635435cf559SWilliam Allen Simpson cookie_out_never:1, 1636435cf559SWilliam Allen Simpson cookie_in_always:1; 1637435cf559SWilliam Allen Simpson }; 1638435cf559SWilliam Allen Simpson 1639435cf559SWilliam Allen Simpson static inline struct tcp_extend_values *tcp_xv(struct request_values *rvp) 1640435cf559SWilliam Allen Simpson { 1641435cf559SWilliam Allen Simpson return (struct tcp_extend_values *)rvp; 1642435cf559SWilliam Allen Simpson } 1643435cf559SWilliam Allen Simpson 16449b0f976fSDenis V. Lunev extern void tcp_v4_init(void); 164520380731SArnaldo Carvalho de Melo extern void tcp_init(void); 164620380731SArnaldo Carvalho de Melo 16471da177e4SLinus Torvalds #endif /* _TCP_H */ 1648