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.h76
1 files changed, 71 insertions, 5 deletions
diff --git a/include/net/tcp.h b/include/net/tcp.h
index f50f29faf76f..8d6b983d5099 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -262,8 +262,6 @@ extern int sysctl_tcp_low_latency;
262extern int sysctl_tcp_nometrics_save; 262extern int sysctl_tcp_nometrics_save;
263extern int sysctl_tcp_moderate_rcvbuf; 263extern int sysctl_tcp_moderate_rcvbuf;
264extern int sysctl_tcp_tso_win_divisor; 264extern int sysctl_tcp_tso_win_divisor;
265extern int sysctl_tcp_mtu_probing;
266extern int sysctl_tcp_base_mss;
267extern int sysctl_tcp_workaround_signed_windows; 265extern int sysctl_tcp_workaround_signed_windows;
268extern int sysctl_tcp_slow_start_after_idle; 266extern int sysctl_tcp_slow_start_after_idle;
269extern int sysctl_tcp_thin_linear_timeouts; 267extern int sysctl_tcp_thin_linear_timeouts;
@@ -274,6 +272,7 @@ extern int sysctl_tcp_challenge_ack_limit;
274extern unsigned int sysctl_tcp_notsent_lowat; 272extern unsigned int sysctl_tcp_notsent_lowat;
275extern int sysctl_tcp_min_tso_segs; 273extern int sysctl_tcp_min_tso_segs;
276extern int sysctl_tcp_autocorking; 274extern int sysctl_tcp_autocorking;
275extern int sysctl_tcp_invalid_ratelimit;
277 276
278extern atomic_long_t tcp_memory_allocated; 277extern atomic_long_t tcp_memory_allocated;
279extern struct percpu_counter tcp_sockets_allocated; 278extern struct percpu_counter tcp_sockets_allocated;
@@ -448,6 +447,7 @@ int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb);
448struct sock *tcp_create_openreq_child(struct sock *sk, 447struct sock *tcp_create_openreq_child(struct sock *sk,
449 struct request_sock *req, 448 struct request_sock *req,
450 struct sk_buff *skb); 449 struct sk_buff *skb);
450void tcp_ca_openreq_child(struct sock *sk, const struct dst_entry *dst);
451struct sock *tcp_v4_syn_recv_sock(struct sock *sk, struct sk_buff *skb, 451struct sock *tcp_v4_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
452 struct request_sock *req, 452 struct request_sock *req,
453 struct dst_entry *dst); 453 struct dst_entry *dst);
@@ -636,6 +636,11 @@ static inline u32 tcp_rto_min_us(struct sock *sk)
636 return jiffies_to_usecs(tcp_rto_min(sk)); 636 return jiffies_to_usecs(tcp_rto_min(sk));
637} 637}
638 638
639static inline bool tcp_ca_dst_locked(const struct dst_entry *dst)
640{
641 return dst_metric_locked(dst, RTAX_CC_ALGO);
642}
643
639/* Compute the actual receive window we are currently advertising. 644/* Compute the actual receive window we are currently advertising.
640 * Rcv_nxt can be after the window if our peer push more data 645 * Rcv_nxt can be after the window if our peer push more data
641 * than the offered window. 646 * than the offered window.
@@ -787,6 +792,8 @@ enum tcp_ca_ack_event_flags {
787#define TCP_CA_MAX 128 792#define TCP_CA_MAX 128
788#define TCP_CA_BUF_MAX (TCP_CA_NAME_MAX*TCP_CA_MAX) 793#define TCP_CA_BUF_MAX (TCP_CA_NAME_MAX*TCP_CA_MAX)
789 794
795#define TCP_CA_UNSPEC 0
796
790/* Algorithm can be set on socket without CAP_NET_ADMIN privileges */ 797/* Algorithm can be set on socket without CAP_NET_ADMIN privileges */
791#define TCP_CONG_NON_RESTRICTED 0x1 798#define TCP_CONG_NON_RESTRICTED 0x1
792/* Requires ECN/ECT set on all packets */ 799/* Requires ECN/ECT set on all packets */
@@ -794,7 +801,8 @@ enum tcp_ca_ack_event_flags {
794 801
795struct tcp_congestion_ops { 802struct tcp_congestion_ops {
796 struct list_head list; 803 struct list_head list;
797 unsigned long flags; 804 u32 key;
805 u32 flags;
798 806
799 /* initialize private data (optional) */ 807 /* initialize private data (optional) */
800 void (*init)(struct sock *sk); 808 void (*init)(struct sock *sk);
@@ -834,13 +842,24 @@ void tcp_get_available_congestion_control(char *buf, size_t len);
834void tcp_get_allowed_congestion_control(char *buf, size_t len); 842void tcp_get_allowed_congestion_control(char *buf, size_t len);
835int tcp_set_allowed_congestion_control(char *allowed); 843int tcp_set_allowed_congestion_control(char *allowed);
836int tcp_set_congestion_control(struct sock *sk, const char *name); 844int tcp_set_congestion_control(struct sock *sk, const char *name);
837void tcp_slow_start(struct tcp_sock *tp, u32 acked); 845u32 tcp_slow_start(struct tcp_sock *tp, u32 acked);
838void tcp_cong_avoid_ai(struct tcp_sock *tp, u32 w); 846void tcp_cong_avoid_ai(struct tcp_sock *tp, u32 w, u32 acked);
839 847
840u32 tcp_reno_ssthresh(struct sock *sk); 848u32 tcp_reno_ssthresh(struct sock *sk);
841void tcp_reno_cong_avoid(struct sock *sk, u32 ack, u32 acked); 849void tcp_reno_cong_avoid(struct sock *sk, u32 ack, u32 acked);
842extern struct tcp_congestion_ops tcp_reno; 850extern struct tcp_congestion_ops tcp_reno;
843 851
852struct tcp_congestion_ops *tcp_ca_find_key(u32 key);
853u32 tcp_ca_get_key_by_name(const char *name);
854#ifdef CONFIG_INET
855char *tcp_ca_get_name_by_key(u32 key, char *buffer);
856#else
857static inline char *tcp_ca_get_name_by_key(u32 key, char *buffer)
858{
859 return NULL;
860}
861#endif
862
844static inline bool tcp_ca_needs_ecn(const struct sock *sk) 863static inline bool tcp_ca_needs_ecn(const struct sock *sk)
845{ 864{
846 const struct inet_connection_sock *icsk = inet_csk(sk); 865 const struct inet_connection_sock *icsk = inet_csk(sk);
@@ -1124,6 +1143,7 @@ static inline void tcp_openreq_init(struct request_sock *req,
1124 tcp_rsk(req)->rcv_isn = TCP_SKB_CB(skb)->seq; 1143 tcp_rsk(req)->rcv_isn = TCP_SKB_CB(skb)->seq;
1125 tcp_rsk(req)->rcv_nxt = TCP_SKB_CB(skb)->seq + 1; 1144 tcp_rsk(req)->rcv_nxt = TCP_SKB_CB(skb)->seq + 1;
1126 tcp_rsk(req)->snt_synack = tcp_time_stamp; 1145 tcp_rsk(req)->snt_synack = tcp_time_stamp;
1146 tcp_rsk(req)->last_oow_ack_time = 0;
1127 req->mss = rx_opt->mss_clamp; 1147 req->mss = rx_opt->mss_clamp;
1128 req->ts_recent = rx_opt->saw_tstamp ? rx_opt->rcv_tsval : 0; 1148 req->ts_recent = rx_opt->saw_tstamp ? rx_opt->rcv_tsval : 0;
1129 ireq->tstamp_ok = rx_opt->tstamp_ok; 1149 ireq->tstamp_ok = rx_opt->tstamp_ok;
@@ -1216,6 +1236,37 @@ static inline bool tcp_paws_reject(const struct tcp_options_received *rx_opt,
1216 return true; 1236 return true;
1217} 1237}
1218 1238
1239/* Return true if we're currently rate-limiting out-of-window ACKs and
1240 * thus shouldn't send a dupack right now. We rate-limit dupacks in
1241 * response to out-of-window SYNs or ACKs to mitigate ACK loops or DoS
1242 * attacks that send repeated SYNs or ACKs for the same connection. To
1243 * do this, we do not send a duplicate SYNACK or ACK if the remote
1244 * endpoint is sending out-of-window SYNs or pure ACKs at a high rate.
1245 */
1246static inline bool tcp_oow_rate_limited(struct net *net,
1247 const struct sk_buff *skb,
1248 int mib_idx, u32 *last_oow_ack_time)
1249{
1250 /* Data packets without SYNs are not likely part of an ACK loop. */
1251 if ((TCP_SKB_CB(skb)->seq != TCP_SKB_CB(skb)->end_seq) &&
1252 !tcp_hdr(skb)->syn)
1253 goto not_rate_limited;
1254
1255 if (*last_oow_ack_time) {
1256 s32 elapsed = (s32)(tcp_time_stamp - *last_oow_ack_time);
1257
1258 if (0 <= elapsed && elapsed < sysctl_tcp_invalid_ratelimit) {
1259 NET_INC_STATS_BH(net, mib_idx);
1260 return true; /* rate-limited: don't send yet! */
1261 }
1262 }
1263
1264 *last_oow_ack_time = tcp_time_stamp;
1265
1266not_rate_limited:
1267 return false; /* not rate-limited: go ahead, send dupack now! */
1268}
1269
1219static inline void tcp_mib_init(struct net *net) 1270static inline void tcp_mib_init(struct net *net)
1220{ 1271{
1221 /* See RFC 2012 */ 1272 /* See RFC 2012 */
@@ -1693,4 +1744,19 @@ static inline struct ip_options_rcu *tcp_v4_save_options(struct sk_buff *skb)
1693 return dopt; 1744 return dopt;
1694} 1745}
1695 1746
1747/* locally generated TCP pure ACKs have skb->truesize == 2
1748 * (check tcp_send_ack() in net/ipv4/tcp_output.c )
1749 * This is much faster than dissecting the packet to find out.
1750 * (Think of GRE encapsulations, IPv4, IPv6, ...)
1751 */
1752static inline bool skb_is_tcp_pure_ack(const struct sk_buff *skb)
1753{
1754 return skb->truesize == 2;
1755}
1756
1757static inline void skb_set_tcp_pure_ack(struct sk_buff *skb)
1758{
1759 skb->truesize = 2;
1760}
1761
1696#endif /* _TCP_H */ 1762#endif /* _TCP_H */