@@ -34,6 +34,8 @@ struct tcp_metrics_block {
3434 struct tcp_metrics_block __rcu * tcpm_next ;
3535 struct inetpeer_addr tcpm_addr ;
3636 unsigned long tcpm_stamp ;
37+ u32 tcpm_ts ;
38+ u32 tcpm_ts_stamp ;
3739 u32 tcpm_lock ;
3840 u32 tcpm_vals [TCP_METRIC_MAX ];
3941};
@@ -114,6 +116,8 @@ static void tcpm_suck_dst(struct tcp_metrics_block *tm, struct dst_entry *dst)
114116 tm -> tcpm_vals [TCP_METRIC_SSTHRESH ] = dst_metric_raw (dst , RTAX_SSTHRESH );
115117 tm -> tcpm_vals [TCP_METRIC_CWND ] = dst_metric_raw (dst , RTAX_CWND );
116118 tm -> tcpm_vals [TCP_METRIC_REORDERING ] = dst_metric_raw (dst , RTAX_REORDERING );
119+ tm -> tcpm_ts = 0 ;
120+ tm -> tcpm_ts_stamp = 0 ;
117121}
118122
119123static struct tcp_metrics_block * tcpm_new (struct dst_entry * dst ,
@@ -230,6 +234,45 @@ static struct tcp_metrics_block *__tcp_get_metrics_req(struct request_sock *req,
230234 return tm ;
231235}
232236
237+ static struct tcp_metrics_block * __tcp_get_metrics_tw (struct inet_timewait_sock * tw )
238+ {
239+ struct inet6_timewait_sock * tw6 ;
240+ struct tcp_metrics_block * tm ;
241+ struct inetpeer_addr addr ;
242+ unsigned int hash ;
243+ struct net * net ;
244+
245+ addr .family = tw -> tw_family ;
246+ switch (addr .family ) {
247+ case AF_INET :
248+ addr .addr .a4 = tw -> tw_daddr ;
249+ hash = (__force unsigned int ) addr .addr .a4 ;
250+ break ;
251+ case AF_INET6 :
252+ tw6 = inet6_twsk ((struct sock * )tw );
253+ * (struct in6_addr * )addr .addr .a6 = tw6 -> tw_v6_daddr ;
254+ hash = ((__force unsigned int ) addr .addr .a6 [0 ] ^
255+ (__force unsigned int ) addr .addr .a6 [1 ] ^
256+ (__force unsigned int ) addr .addr .a6 [2 ] ^
257+ (__force unsigned int ) addr .addr .a6 [3 ]);
258+ break ;
259+ default :
260+ return NULL ;
261+ }
262+
263+ hash ^= (hash >> 24 ) ^ (hash >> 16 ) ^ (hash >> 8 );
264+
265+ net = twsk_net (tw );
266+ hash &= net -> ipv4 .tcp_metrics_hash_mask ;
267+
268+ for (tm = rcu_dereference (net -> ipv4 .tcp_metrics_hash [hash ].chain ); tm ;
269+ tm = rcu_dereference (tm -> tcpm_next )) {
270+ if (addr_same (& tm -> tcpm_addr , & addr ))
271+ break ;
272+ }
273+ return tm ;
274+ }
275+
233276static struct tcp_metrics_block * tcp_get_metrics (struct sock * sk ,
234277 struct dst_entry * dst ,
235278 bool create )
@@ -496,7 +539,7 @@ void tcp_init_metrics(struct sock *sk)
496539 tp -> snd_cwnd_stamp = tcp_time_stamp ;
497540}
498541
499- bool tcp_peer_is_proven (struct request_sock * req , struct dst_entry * dst )
542+ bool tcp_peer_is_proven (struct request_sock * req , struct dst_entry * dst , bool paws_check )
500543{
501544 struct tcp_metrics_block * tm ;
502545 bool ret ;
@@ -506,16 +549,99 @@ bool tcp_peer_is_proven(struct request_sock *req, struct dst_entry *dst)
506549
507550 rcu_read_lock ();
508551 tm = __tcp_get_metrics_req (req , dst );
509- if (tm && tcp_metric_get (tm , TCP_METRIC_RTT ))
510- ret = true;
511- else
512- ret = false;
552+ if (paws_check ) {
553+ if (tm &&
554+ (u32 )get_seconds () - tm -> tcpm_ts_stamp < TCP_PAWS_MSL &&
555+ (s32 )(tm -> tcpm_ts - req -> ts_recent ) > TCP_PAWS_WINDOW )
556+ ret = false;
557+ else
558+ ret = true;
559+ } else {
560+ if (tm && tcp_metric_get (tm , TCP_METRIC_RTT ) && tm -> tcpm_ts_stamp )
561+ ret = true;
562+ else
563+ ret = false;
564+ }
513565 rcu_read_unlock ();
514566
515567 return ret ;
516568}
517569EXPORT_SYMBOL_GPL (tcp_peer_is_proven );
518570
571+ void tcp_fetch_timewait_stamp (struct sock * sk , struct dst_entry * dst )
572+ {
573+ struct tcp_metrics_block * tm ;
574+
575+ rcu_read_lock ();
576+ tm = tcp_get_metrics (sk , dst , true);
577+ if (tm ) {
578+ struct tcp_sock * tp = tcp_sk (sk );
579+
580+ if ((u32 )get_seconds () - tm -> tcpm_ts_stamp <= TCP_PAWS_MSL ) {
581+ tp -> rx_opt .ts_recent_stamp = tm -> tcpm_ts_stamp ;
582+ tp -> rx_opt .ts_recent = tm -> tcpm_ts ;
583+ }
584+ }
585+ rcu_read_unlock ();
586+ }
587+ EXPORT_SYMBOL_GPL (tcp_fetch_timewait_stamp );
588+
589+ /* VJ's idea. Save last timestamp seen from this destination and hold
590+ * it at least for normal timewait interval to use for duplicate
591+ * segment detection in subsequent connections, before they enter
592+ * synchronized state.
593+ */
594+ bool tcp_remember_stamp (struct sock * sk )
595+ {
596+ struct dst_entry * dst = __sk_dst_get (sk );
597+ bool ret = false;
598+
599+ if (dst ) {
600+ struct tcp_metrics_block * tm ;
601+
602+ rcu_read_lock ();
603+ tm = tcp_get_metrics (sk , dst , true);
604+ if (tm ) {
605+ struct tcp_sock * tp = tcp_sk (sk );
606+
607+ if ((s32 )(tm -> tcpm_ts - tp -> rx_opt .ts_recent ) <= 0 ||
608+ ((u32 )get_seconds () - tm -> tcpm_ts_stamp > TCP_PAWS_MSL &&
609+ tm -> tcpm_ts_stamp <= (u32 )tp -> rx_opt .ts_recent_stamp )) {
610+ tm -> tcpm_ts_stamp = (u32 )tp -> rx_opt .ts_recent_stamp ;
611+ tm -> tcpm_ts = tp -> rx_opt .ts_recent ;
612+ }
613+ ret = true;
614+ }
615+ rcu_read_unlock ();
616+ }
617+ return ret ;
618+ }
619+
620+ bool tcp_tw_remember_stamp (struct inet_timewait_sock * tw )
621+ {
622+ struct tcp_metrics_block * tm ;
623+ bool ret = false;
624+
625+ rcu_read_lock ();
626+ tm = __tcp_get_metrics_tw (tw );
627+ if (tw ) {
628+ const struct tcp_timewait_sock * tcptw ;
629+ struct sock * sk = (struct sock * ) tw ;
630+
631+ tcptw = tcp_twsk (sk );
632+ if ((s32 )(tm -> tcpm_ts - tcptw -> tw_ts_recent ) <= 0 ||
633+ ((u32 )get_seconds () - tm -> tcpm_ts_stamp > TCP_PAWS_MSL &&
634+ tm -> tcpm_ts_stamp <= (u32 )tcptw -> tw_ts_recent_stamp )) {
635+ tm -> tcpm_ts_stamp = (u32 )tcptw -> tw_ts_recent_stamp ;
636+ tm -> tcpm_ts = tcptw -> tw_ts_recent ;
637+ }
638+ ret = true;
639+ }
640+ rcu_read_unlock ();
641+
642+ return ret ;
643+ }
644+
519645static unsigned long tcpmhash_entries ;
520646static int __init set_tcpmhash_entries (char * str )
521647{
0 commit comments