diff options
Diffstat (limited to 'include/net/tcp.h')
-rw-r--r-- | include/net/tcp.h | 131 |
1 files changed, 97 insertions, 34 deletions
diff --git a/include/net/tcp.h b/include/net/tcp.h index 03a49c703377..34f5cc24d903 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; | |||
237 | extern int sysctl_tcp_workaround_signed_windows; | 240 | extern int sysctl_tcp_workaround_signed_windows; |
238 | extern int sysctl_tcp_slow_start_after_idle; | 241 | extern int sysctl_tcp_slow_start_after_idle; |
239 | extern int sysctl_tcp_max_ssthresh; | 242 | extern int sysctl_tcp_max_ssthresh; |
243 | extern int sysctl_tcp_cookie_size; | ||
240 | 244 | ||
241 | extern atomic_t tcp_memory_allocated; | 245 | extern atomic_t tcp_memory_allocated; |
242 | extern struct percpu_counter tcp_sockets_allocated; | 246 | extern struct percpu_counter tcp_sockets_allocated; |
@@ -343,11 +347,6 @@ static inline void tcp_dec_quickack_mode(struct sock *sk, | |||
343 | 347 | ||
344 | extern void tcp_enter_quickack_mode(struct sock *sk); | 348 | extern void tcp_enter_quickack_mode(struct sock *sk); |
345 | 349 | ||
346 | static 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 | ||
362 | enum tcp_tw_status | 361 | enum 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,6 +407,7 @@ extern int tcp_recvmsg(struct kiocb *iocb, struct sock *sk, | |||
409 | 407 | ||
410 | extern void tcp_parse_options(struct sk_buff *skb, | 408 | extern void tcp_parse_options(struct sk_buff *skb, |
411 | struct tcp_options_received *opt_rx, | 409 | struct tcp_options_received *opt_rx, |
410 | u8 **hvpp, | ||
412 | int estab); | 411 | int estab); |
413 | 412 | ||
414 | extern u8 *tcp_parse_md5sig_option(struct tcphdr *th); | 413 | extern u8 *tcp_parse_md5sig_option(struct tcphdr *th); |
@@ -443,7 +442,8 @@ extern int tcp_connect(struct sock *sk); | |||
443 | 442 | ||
444 | extern struct sk_buff * tcp_make_synack(struct sock *sk, | 443 | extern struct sk_buff * tcp_make_synack(struct sock *sk, |
445 | struct dst_entry *dst, | 444 | struct dst_entry *dst, |
446 | struct request_sock *req); | 445 | struct request_sock *req, |
446 | struct request_values *rvp); | ||
447 | 447 | ||
448 | extern int tcp_disconnect(struct sock *sk, int flags); | 448 | extern int tcp_disconnect(struct sock *sk, int flags); |
449 | 449 | ||
@@ -1228,6 +1228,7 @@ static inline void tcp_write_queue_purge(struct sock *sk) | |||
1228 | while ((skb = __skb_dequeue(&sk->sk_write_queue)) != NULL) | 1228 | while ((skb = __skb_dequeue(&sk->sk_write_queue)) != NULL) |
1229 | sk_wmem_free_skb(sk, skb); | 1229 | sk_wmem_free_skb(sk, skb); |
1230 | sk_mem_reclaim(sk); | 1230 | sk_mem_reclaim(sk); |
1231 | tcp_clear_all_retrans_hints(tcp_sk(sk)); | ||
1231 | } | 1232 | } |
1232 | 1233 | ||
1233 | static inline struct sk_buff *tcp_write_queue_head(struct sock *sk) | 1234 | static inline struct sk_buff *tcp_write_queue_head(struct sock *sk) |
@@ -1259,29 +1260,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) \ | 1260 | #define tcp_for_write_queue_from_safe(skb, tmp, sk) \ |
1260 | skb_queue_walk_from_safe(&(sk)->sk_write_queue, skb, tmp) | 1261 | skb_queue_walk_from_safe(&(sk)->sk_write_queue, skb, tmp) |
1261 | 1262 | ||
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 | */ | ||
1266 | static 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 | |||
1285 | static inline struct sk_buff *tcp_send_head(struct sock *sk) | 1263 | static inline struct sk_buff *tcp_send_head(struct sock *sk) |
1286 | { | 1264 | { |
1287 | return sk->sk_send_head; | 1265 | return sk->sk_send_head; |
@@ -1480,6 +1458,91 @@ struct tcp_request_sock_ops { | |||
1480 | #endif | 1458 | #endif |
1481 | }; | 1459 | }; |
1482 | 1460 | ||
1461 | /* Using SHA1 for now, define some constants. | ||
1462 | */ | ||
1463 | #define COOKIE_DIGEST_WORDS (SHA_DIGEST_WORDS) | ||
1464 | #define COOKIE_MESSAGE_WORDS (SHA_MESSAGE_BYTES / 4) | ||
1465 | #define COOKIE_WORKSPACE_WORDS (COOKIE_DIGEST_WORDS + COOKIE_MESSAGE_WORDS) | ||
1466 | |||
1467 | extern int tcp_cookie_generator(u32 *bakery); | ||
1468 | |||
1469 | /** | ||
1470 | * struct tcp_cookie_values - each socket needs extra space for the | ||
1471 | * cookies, together with (optional) space for any SYN data. | ||
1472 | * | ||
1473 | * A tcp_sock contains a pointer to the current value, and this is | ||
1474 | * cloned to the tcp_timewait_sock. | ||
1475 | * | ||
1476 | * @cookie_pair: variable data from the option exchange. | ||
1477 | * | ||
1478 | * @cookie_desired: user specified tcpct_cookie_desired. Zero | ||
1479 | * indicates default (sysctl_tcp_cookie_size). | ||
1480 | * After cookie sent, remembers size of cookie. | ||
1481 | * Range 0, TCP_COOKIE_MIN to TCP_COOKIE_MAX. | ||
1482 | * | ||
1483 | * @s_data_desired: user specified tcpct_s_data_desired. When the | ||
1484 | * constant payload is specified (@s_data_constant), | ||
1485 | * holds its length instead. | ||
1486 | * Range 0 to TCP_MSS_DESIRED. | ||
1487 | * | ||
1488 | * @s_data_payload: constant data that is to be included in the | ||
1489 | * payload of SYN or SYNACK segments when the | ||
1490 | * cookie option is present. | ||
1491 | */ | ||
1492 | struct tcp_cookie_values { | ||
1493 | struct kref kref; | ||
1494 | u8 cookie_pair[TCP_COOKIE_PAIR_SIZE]; | ||
1495 | u8 cookie_pair_size; | ||
1496 | u8 cookie_desired; | ||
1497 | u16 s_data_desired:11, | ||
1498 | s_data_constant:1, | ||
1499 | s_data_in:1, | ||
1500 | s_data_out:1, | ||
1501 | s_data_unused:2; | ||
1502 | u8 s_data_payload[0]; | ||
1503 | }; | ||
1504 | |||
1505 | static inline void tcp_cookie_values_release(struct kref *kref) | ||
1506 | { | ||
1507 | kfree(container_of(kref, struct tcp_cookie_values, kref)); | ||
1508 | } | ||
1509 | |||
1510 | /* The length of constant payload data. Note that s_data_desired is | ||
1511 | * overloaded, depending on s_data_constant: either the length of constant | ||
1512 | * data (returned here) or the limit on variable data. | ||
1513 | */ | ||
1514 | static inline int tcp_s_data_size(const struct tcp_sock *tp) | ||
1515 | { | ||
1516 | return (tp->cookie_values != NULL && tp->cookie_values->s_data_constant) | ||
1517 | ? tp->cookie_values->s_data_desired | ||
1518 | : 0; | ||
1519 | } | ||
1520 | |||
1521 | /** | ||
1522 | * struct tcp_extend_values - tcp_ipv?.c to tcp_output.c workspace. | ||
1523 | * | ||
1524 | * As tcp_request_sock has already been extended in other places, the | ||
1525 | * only remaining method is to pass stack values along as function | ||
1526 | * parameters. These parameters are not needed after sending SYNACK. | ||
1527 | * | ||
1528 | * @cookie_bakery: cryptographic secret and message workspace. | ||
1529 | * | ||
1530 | * @cookie_plus: bytes in authenticator/cookie option, copied from | ||
1531 | * struct tcp_options_received (above). | ||
1532 | */ | ||
1533 | struct tcp_extend_values { | ||
1534 | struct request_values rv; | ||
1535 | u32 cookie_bakery[COOKIE_WORKSPACE_WORDS]; | ||
1536 | u8 cookie_plus:6, | ||
1537 | cookie_out_never:1, | ||
1538 | cookie_in_always:1; | ||
1539 | }; | ||
1540 | |||
1541 | static inline struct tcp_extend_values *tcp_xv(struct request_values *rvp) | ||
1542 | { | ||
1543 | return (struct tcp_extend_values *)rvp; | ||
1544 | } | ||
1545 | |||
1483 | extern void tcp_v4_init(void); | 1546 | extern void tcp_v4_init(void); |
1484 | extern void tcp_init(void); | 1547 | extern void tcp_init(void); |
1485 | 1548 | ||