+/*
+ * Perform rate limit check per connection per second
+ * tp->t_challengeack_last is the last_time diff was greater than 1sec
+ * tp->t_challengeack_count is the number of ACKs sent (within 1sec)
+ * Return TRUE if we shouldn't send the ACK due to rate limitation
+ * Return FALSE if it is still ok to send challenge ACK
+ */
+static boolean_t
+tcp_is_ack_ratelimited(struct tcpcb *tp)
+{
+ boolean_t ret = TRUE;
+ uint32_t now = tcp_now;
+ int32_t diff = 0;
+
+ diff = timer_diff(now, 0, tp->t_challengeack_last, 0);
+ /* If it is first time or diff > 1000ms,
+ * update the challengeack_last and reset the
+ * current count of ACKs
+ */
+ if (tp->t_challengeack_last == 0 || diff >= 1000) {
+ tp->t_challengeack_last = now;
+ tp->t_challengeack_count = 0;
+ ret = FALSE;
+ } else if (tp->t_challengeack_count < tcp_challengeack_limit) {
+ ret = FALSE;
+ }
+
+ /* Careful about wrap-around */
+ if (ret == FALSE && (tp->t_challengeack_count + 1 > 0))
+ tp->t_challengeack_count++;
+
+ return (ret);
+}
+