aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/tcp.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/net/tcp.h')
-rw-r--r--include/net/tcp.h134
1 files changed, 99 insertions, 35 deletions
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 03a49c703377..1b6f7d348cee 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -30,6 +30,7 @@
30#include <linux/dmaengine.h> 30#include <linux/dmaengine.h>
31#include <linux/crypto.h> 31#include <linux/crypto.h>
32#include <linux/cryptohash.h> 32#include <linux/cryptohash.h>
33#include <linux/kref.h>
33 34
34#include <net/inet_connection_sock.h> 35#include <net/inet_connection_sock.h>
35#include <net/inet_timewait_sock.h> 36#include <net/inet_timewait_sock.h>
@@ -62,9 +63,6 @@ extern void tcp_time_wait(struct sock *sk, int state, int timeo);
62/* Minimal accepted MSS. It is (60+60+8) - (20+20). */ 63/* Minimal accepted MSS. It is (60+60+8) - (20+20). */
63#define TCP_MIN_MSS 88U 64#define TCP_MIN_MSS 88U
64 65
65/* Minimal RCV_MSS. */
66#define TCP_MIN_RCVMSS 536U
67
68/* The least MTU to use for probing */ 66/* The least MTU to use for probing */
69#define TCP_BASE_MSS 512 67#define TCP_BASE_MSS 512
70 68
@@ -167,6 +165,7 @@ extern void tcp_time_wait(struct sock *sk, int state, int timeo);
167#define TCPOPT_SACK 5 /* SACK Block */ 165#define TCPOPT_SACK 5 /* SACK Block */
168#define TCPOPT_TIMESTAMP 8 /* Better RTT estimations/PAWS */ 166#define TCPOPT_TIMESTAMP 8 /* Better RTT estimations/PAWS */
169#define TCPOPT_MD5SIG 19 /* MD5 Signature (RFC2385) */ 167#define TCPOPT_MD5SIG 19 /* MD5 Signature (RFC2385) */
168#define TCPOPT_COOKIE 253 /* Cookie extension (experimental) */
170 169
171/* 170/*
172 * TCP option lengths 171 * TCP option lengths
@@ -177,6 +176,10 @@ extern void tcp_time_wait(struct sock *sk, int state, int timeo);
177#define TCPOLEN_SACK_PERM 2 176#define TCPOLEN_SACK_PERM 2
178#define TCPOLEN_TIMESTAMP 10 177#define TCPOLEN_TIMESTAMP 10
179#define TCPOLEN_MD5SIG 18 178#define TCPOLEN_MD5SIG 18
179#define TCPOLEN_COOKIE_BASE 2 /* Cookie-less header extension */
180#define TCPOLEN_COOKIE_PAIR 3 /* Cookie pair header extension */
181#define TCPOLEN_COOKIE_MIN (TCPOLEN_COOKIE_BASE+TCP_COOKIE_MIN)
182#define TCPOLEN_COOKIE_MAX (TCPOLEN_COOKIE_BASE+TCP_COOKIE_MAX)
180 183
181/* But this is what stacks really send out. */ 184/* But this is what stacks really send out. */
182#define TCPOLEN_TSTAMP_ALIGNED 12 185#define TCPOLEN_TSTAMP_ALIGNED 12
@@ -237,6 +240,7 @@ extern int sysctl_tcp_base_mss;
237extern int sysctl_tcp_workaround_signed_windows; 240extern int sysctl_tcp_workaround_signed_windows;
238extern int sysctl_tcp_slow_start_after_idle; 241extern int sysctl_tcp_slow_start_after_idle;
239extern int sysctl_tcp_max_ssthresh; 242extern int sysctl_tcp_max_ssthresh;
243extern int sysctl_tcp_cookie_size;
240 244
241extern atomic_t tcp_memory_allocated; 245extern atomic_t tcp_memory_allocated;
242extern struct percpu_counter tcp_sockets_allocated; 246extern struct percpu_counter tcp_sockets_allocated;
@@ -343,11 +347,6 @@ static inline void tcp_dec_quickack_mode(struct sock *sk,
343 347
344extern void tcp_enter_quickack_mode(struct sock *sk); 348extern void tcp_enter_quickack_mode(struct sock *sk);
345 349
346static inline void tcp_clear_options(struct tcp_options_received *rx_opt)
347{
348 rx_opt->tstamp_ok = rx_opt->sack_ok = rx_opt->wscale_ok = rx_opt->snd_wscale = 0;
349}
350
351#define TCP_ECN_OK 1 350#define TCP_ECN_OK 1
352#define TCP_ECN_QUEUE_CWR 2 351#define TCP_ECN_QUEUE_CWR 2
353#define TCP_ECN_DEMAND_CWR 4 352#define TCP_ECN_DEMAND_CWR 4
@@ -359,8 +358,7 @@ TCP_ECN_create_request(struct request_sock *req, struct tcphdr *th)
359 inet_rsk(req)->ecn_ok = 1; 358 inet_rsk(req)->ecn_ok = 1;
360} 359}
361 360
362enum tcp_tw_status 361enum tcp_tw_status {
363{
364 TCP_TW_SUCCESS = 0, 362 TCP_TW_SUCCESS = 0,
365 TCP_TW_RST = 1, 363 TCP_TW_RST = 1,
366 TCP_TW_ACK = 2, 364 TCP_TW_ACK = 2,
@@ -409,7 +407,9 @@ extern int tcp_recvmsg(struct kiocb *iocb, struct sock *sk,
409 407
410extern void tcp_parse_options(struct sk_buff *skb, 408extern void tcp_parse_options(struct sk_buff *skb,
411 struct tcp_options_received *opt_rx, 409 struct tcp_options_received *opt_rx,
412 int estab); 410 u8 **hvpp,
411 int estab,
412 struct dst_entry *dst);
413 413
414extern u8 *tcp_parse_md5sig_option(struct tcphdr *th); 414extern u8 *tcp_parse_md5sig_option(struct tcphdr *th);
415 415
@@ -443,7 +443,8 @@ extern int tcp_connect(struct sock *sk);
443 443
444extern struct sk_buff * tcp_make_synack(struct sock *sk, 444extern struct sk_buff * tcp_make_synack(struct sock *sk,
445 struct dst_entry *dst, 445 struct dst_entry *dst,
446 struct request_sock *req); 446 struct request_sock *req,
447 struct request_values *rvp);
447 448
448extern int tcp_disconnect(struct sock *sk, int flags); 449extern int tcp_disconnect(struct sock *sk, int flags);
449 450
@@ -1228,6 +1229,7 @@ static inline void tcp_write_queue_purge(struct sock *sk)
1228 while ((skb = __skb_dequeue(&sk->sk_write_queue)) != NULL) 1229 while ((skb = __skb_dequeue(&sk->sk_write_queue)) != NULL)
1229 sk_wmem_free_skb(sk, skb); 1230 sk_wmem_free_skb(sk, skb);
1230 sk_mem_reclaim(sk); 1231 sk_mem_reclaim(sk);
1232 tcp_clear_all_retrans_hints(tcp_sk(sk));
1231} 1233}
1232 1234
1233static inline struct sk_buff *tcp_write_queue_head(struct sock *sk) 1235static inline struct sk_buff *tcp_write_queue_head(struct sock *sk)
@@ -1259,29 +1261,6 @@ static inline struct sk_buff *tcp_write_queue_prev(struct sock *sk, struct sk_bu
1259#define tcp_for_write_queue_from_safe(skb, tmp, sk) \ 1261#define tcp_for_write_queue_from_safe(skb, tmp, sk) \
1260 skb_queue_walk_from_safe(&(sk)->sk_write_queue, skb, tmp) 1262 skb_queue_walk_from_safe(&(sk)->sk_write_queue, skb, tmp)
1261 1263
1262/* This function calculates a "timeout" which is equivalent to the timeout of a
1263 * TCP connection after "boundary" unsucessful, exponentially backed-off
1264 * retransmissions with an initial RTO of TCP_RTO_MIN.
1265 */
1266static inline bool retransmits_timed_out(const struct sock *sk,
1267 unsigned int boundary)
1268{
1269 unsigned int timeout, linear_backoff_thresh;
1270
1271 if (!inet_csk(sk)->icsk_retransmits)
1272 return false;
1273
1274 linear_backoff_thresh = ilog2(TCP_RTO_MAX/TCP_RTO_MIN);
1275
1276 if (boundary <= linear_backoff_thresh)
1277 timeout = ((2 << boundary) - 1) * TCP_RTO_MIN;
1278 else
1279 timeout = ((2 << linear_backoff_thresh) - 1) * TCP_RTO_MIN +
1280 (boundary - linear_backoff_thresh) * TCP_RTO_MAX;
1281
1282 return (tcp_time_stamp - tcp_sk(sk)->retrans_stamp) >= timeout;
1283}
1284
1285static inline struct sk_buff *tcp_send_head(struct sock *sk) 1264static inline struct sk_buff *tcp_send_head(struct sock *sk)
1286{ 1265{
1287 return sk->sk_send_head; 1266 return sk->sk_send_head;
@@ -1480,6 +1459,91 @@ struct tcp_request_sock_ops {
1480#endif 1459#endif
1481}; 1460};
1482 1461
1462/* Using SHA1 for now, define some constants.
1463 */
1464#define COOKIE_DIGEST_WORDS (SHA_DIGEST_WORDS)
1465#define COOKIE_MESSAGE_WORDS (SHA_MESSAGE_BYTES / 4)
1466#define COOKIE_WORKSPACE_WORDS (COOKIE_DIGEST_WORDS + COOKIE_MESSAGE_WORDS)
1467
1468extern int tcp_cookie_generator(u32 *bakery);
1469
1470/**
1471 * struct tcp_cookie_values - each socket needs extra space for the
1472 * cookies, together with (optional) space for any SYN data.
1473 *
1474 * A tcp_sock contains a pointer to the current value, and this is
1475 * cloned to the tcp_timewait_sock.
1476 *
1477 * @cookie_pair: variable data from the option exchange.
1478 *
1479 * @cookie_desired: user specified tcpct_cookie_desired. Zero
1480 * indicates default (sysctl_tcp_cookie_size).
1481 * After cookie sent, remembers size of cookie.
1482 * Range 0, TCP_COOKIE_MIN to TCP_COOKIE_MAX.
1483 *
1484 * @s_data_desired: user specified tcpct_s_data_desired. When the
1485 * constant payload is specified (@s_data_constant),
1486 * holds its length instead.
1487 * Range 0 to TCP_MSS_DESIRED.
1488 *
1489 * @s_data_payload: constant data that is to be included in the
1490 * payload of SYN or SYNACK segments when the
1491 * cookie option is present.
1492 */
1493struct tcp_cookie_values {
1494 struct kref kref;
1495 u8 cookie_pair[TCP_COOKIE_PAIR_SIZE];
1496 u8 cookie_pair_size;
1497 u8 cookie_desired;
1498 u16 s_data_desired:11,
1499 s_data_constant:1,
1500 s_data_in:1,
1501 s_data_out:1,
1502 s_data_unused:2;
1503 u8 s_data_payload[0];
1504};
1505
1506static inline void tcp_cookie_values_release(struct kref *kref)
1507{
1508 kfree(container_of(kref, struct tcp_cookie_values, kref));
1509}
1510
1511/* The length of constant payload data. Note that s_data_desired is
1512 * overloaded, depending on s_data_constant: either the length of constant
1513 * data (returned here) or the limit on variable data.
1514 */
1515static inline int tcp_s_data_size(const struct tcp_sock *tp)
1516{
1517 return (tp->cookie_values != NULL && tp->cookie_values->s_data_constant)
1518 ? tp->cookie_values->s_data_desired
1519 : 0;
1520}
1521
1522/**
1523 * struct tcp_extend_values - tcp_ipv?.c to tcp_output.c workspace.
1524 *
1525 * As tcp_request_sock has already been extended in other places, the
1526 * only remaining method is to pass stack values along as function
1527 * parameters. These parameters are not needed after sending SYNACK.
1528 *
1529 * @cookie_bakery: cryptographic secret and message workspace.
1530 *
1531 * @cookie_plus: bytes in authenticator/cookie option, copied from
1532 * struct tcp_options_received (above).
1533 */
1534struct tcp_extend_values {
1535 struct request_values rv;
1536 u32 cookie_bakery[COOKIE_WORKSPACE_WORDS];
1537 u8 cookie_plus:6,
1538 cookie_out_never:1,
1539 cookie_in_always:1;
1540};
1541
1542static inline struct tcp_extend_values *tcp_xv(struct request_values *rvp)
1543{
1544 return (struct tcp_extend_values *)rvp;
1545}
1546
1483extern void tcp_v4_init(void); 1547extern void tcp_v4_init(void);
1484extern void tcp_init(void); 1548extern void tcp_init(void);
1485 1549