tcp: cast timer ticks to u32 14/34814/5
authorFlorin Coras <fcoras@cisco.com>
Mon, 3 Jan 2022 18:34:52 +0000 (10:34 -0800)
committerFlorin Coras <florin.coras@gmail.com>
Thu, 6 Jan 2022 20:14:49 +0000 (20:14 +0000)
tc->rto * TCP_TO_TIMER_TICK can return garbage if not cast to u32 and
that confuses clib_max

Type: fix

Signed-off-by: Florin Coras <fcoras@cisco.com>
signed-off-by: Vipul Agrawal <Vipul.Agrawal@enea.com>
Change-Id: Ief4d29b9625e2ef2e75e0c7e3d731ab147465f6d

src/vnet/tcp/tcp.c
src/vnet/tcp/tcp_output.c
src/vnet/tcp/tcp_timer.h

index af985d2..3d3cc88 100644 (file)
@@ -1438,7 +1438,8 @@ tcp_expired_timers_dispatch (u32 * expired_timers)
 
   clib_fifo_add (wrk->pending_timers, expired_timers, n_expired);
 
-  max_loops = clib_max (1, 0.5 * TCP_TIMER_TICK * wrk->vm->loops_per_second);
+  max_loops =
+    clib_max ((u32) 0.5 * TCP_TIMER_TICK * wrk->vm->loops_per_second, 1);
   max_per_loop = clib_max ((n_left + n_expired) / max_loops, 10);
   max_per_loop = clib_min (max_per_loop, VLIB_FRAME_SIZE);
   wrk->max_timers_per_loop = clib_max (n_left ? wrk->max_timers_per_loop : 0,
index 403ddb3..dfcb4ee 100644 (file)
@@ -788,7 +788,7 @@ tcp_send_syn (tcp_connection_t * tc)
    * such that we can return if we've ran out.
    */
   tcp_timer_update (&wrk->timer_wheel, tc, TCP_TIMER_RETRANSMIT_SYN,
-                   tc->rto * TCP_TO_TIMER_TICK);
+                   (u32) tc->rto * TCP_TO_TIMER_TICK);
 
   if (PREDICT_FALSE (!vlib_buffer_alloc (vm, &bi, 1)))
     {
@@ -1478,7 +1478,7 @@ tcp_timer_retransmit_syn_handler (tcp_connection_t * tc)
   tcp_enqueue_half_open (wrk, tc, b, bi);
 
   tcp_timer_update (&wrk->timer_wheel, tc, TCP_TIMER_RETRANSMIT_SYN,
-                   tc->rto * TCP_TO_TIMER_TICK);
+                   (u32) tc->rto * TCP_TO_TIMER_TICK);
 }
 
 /**
index 4668c79..5f14a71 100644 (file)
@@ -56,7 +56,7 @@ tcp_retransmit_timer_set (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
 {
   ASSERT (tc->snd_una != tc->snd_nxt);
   tcp_timer_set (tw, tc, TCP_TIMER_RETRANSMIT,
-                clib_max (tc->rto * TCP_TO_TIMER_TICK, 1));
+                clib_max ((u32) tc->rto * TCP_TO_TIMER_TICK, 1));
 }
 
 always_inline void
@@ -70,7 +70,7 @@ tcp_persist_timer_set (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
 {
   /* Reuse RTO. It's backed off in handler */
   tcp_timer_set (tw, tc, TCP_TIMER_PERSIST,
-                clib_max (tc->rto * TCP_TO_TIMER_TICK, 1));
+                clib_max ((u32) tc->rto * TCP_TO_TIMER_TICK, 1));
 }
 
 always_inline void
@@ -81,7 +81,7 @@ tcp_persist_timer_update (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
   if (seq_leq (tc->snd_una, tc->snd_congestion + tc->burst_acked))
     interval = 1;
   else
-    interval = clib_max (tc->rto * TCP_TO_TIMER_TICK, 1);
+    interval = clib_max ((u32) tc->rto * TCP_TO_TIMER_TICK, 1);
 
   tcp_timer_update (tw, tc, TCP_TIMER_PERSIST, interval);
 }
@@ -103,7 +103,7 @@ tcp_retransmit_timer_update (tcp_timer_wheel_t * tw, tcp_connection_t * tc)
     }
   else
     tcp_timer_update (tw, tc, TCP_TIMER_RETRANSMIT,
-                     clib_max (tc->rto * TCP_TO_TIMER_TICK, 1));
+                     clib_max ((u32) tc->rto * TCP_TO_TIMER_TICK, 1));
 }
 
 always_inline u8