aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/ip
diff options
context:
space:
mode:
Diffstat (limited to 'src/vnet/ip')
-rw-r--r--src/vnet/ip/ip4.h5
-rw-r--r--src/vnet/ip/ip4_forward.c24
-rw-r--r--src/vnet/ip/ip4_input.c12
3 files changed, 8 insertions, 33 deletions
diff --git a/src/vnet/ip/ip4.h b/src/vnet/ip/ip4.h
index e3cbe27dd89..9cb54bdfc41 100644
--- a/src/vnet/ip/ip4.h
+++ b/src/vnet/ip/ip4.h
@@ -45,6 +45,7 @@
#include <vnet/buffer.h>
#include <vnet/feature/feature.h>
#include <vnet/ip/icmp46_packet.h>
+#include <vnet/util/throttle.h>
typedef struct ip4_mfib_t
{
@@ -156,9 +157,7 @@ typedef struct ip4_main_t
void *mtrie_mheap;
/** ARP throttling */
- uword **arp_throttle_bitmaps;
- u32 *arp_throttle_seeds;
- f64 *arp_throttle_last_seed_change_time;
+ throttle_t arp_throttle;
} ip4_main_t;
diff --git a/src/vnet/ip/ip4_forward.c b/src/vnet/ip/ip4_forward.c
index 614b6e2cb4a..d5cf011b677 100644
--- a/src/vnet/ip/ip4_forward.c
+++ b/src/vnet/ip/ip4_forward.c
@@ -1719,21 +1719,11 @@ ip4_arp_inline (vlib_main_t * vm,
uword n_left_from, n_left_to_next_drop, next_index;
u32 thread_index = vm->thread_index;
u32 seed;
- f64 time_now;
if (node->flags & VLIB_NODE_FLAG_TRACE)
ip4_forward_next_trace (vm, node, frame, VLIB_TX);
- time_now = vlib_time_now (vm);
- if (time_now - im->arp_throttle_last_seed_change_time[thread_index] > 1e-3)
- {
- (void) random_u32 (&im->arp_throttle_seeds[thread_index]);
- memset (im->arp_throttle_bitmaps[thread_index], 0,
- ARP_THROTTLE_BITS / BITS (u8));
-
- im->arp_throttle_last_seed_change_time[thread_index] = time_now;
- }
- seed = im->arp_throttle_seeds[thread_index];
+ seed = throttle_seed (&im->arp_throttle, thread_index, vlib_time_now (vm));
from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
@@ -1748,8 +1738,7 @@ ip4_arp_inline (vlib_main_t * vm,
while (n_left_from > 0 && n_left_to_next_drop > 0)
{
- u32 pi0, adj_index0, r0, w0, sw_if_index0, drop0;
- uword m0;
+ u32 pi0, adj_index0, r0, sw_if_index0, drop0;
ip_adjacency_t *adj0;
vlib_buffer_t *p0;
ip4_header_t *ip0;
@@ -1778,14 +1767,7 @@ ip4_arp_inline (vlib_main_t * vm,
r0 = adj0->sub_type.nbr.next_hop.ip4.data_u32;
}
- r0 ^= seed;
- /* Select bit number */
- r0 &= ARP_THROTTLE_BITS - 1;
- w0 = r0 / BITS (uword);
- m0 = (uword) 1 << (r0 % BITS (uword));
-
- drop0 = (im->arp_throttle_bitmaps[thread_index][w0] & m0) != 0;
- im->arp_throttle_bitmaps[thread_index][w0] |= m0;
+ drop0 = throttle_check (&im->arp_throttle, thread_index, r0, seed);
from += 1;
n_left_from -= 1;
diff --git a/src/vnet/ip/ip4_input.c b/src/vnet/ip/ip4_input.c
index 1425786a4b1..5a2ae17391f 100644
--- a/src/vnet/ip/ip4_input.c
+++ b/src/vnet/ip/ip4_input.c
@@ -41,6 +41,7 @@
#include <vnet/ethernet/ethernet.h>
#include <vnet/ppp/ppp.h>
#include <vnet/hdlc/hdlc.h>
+#include <vnet/util/throttle.h>
typedef struct
{
@@ -390,17 +391,10 @@ ip4_main_loop_enter (vlib_main_t * vm)
ip4_main_t *im = &ip4_main;
vlib_thread_main_t *tm = &vlib_thread_main;
u32 n_vlib_mains = tm->n_vlib_mains;
- int i;
+ throttle_init (&im->arp_throttle, n_vlib_mains, 1e-3);
- vec_validate (im->arp_throttle_bitmaps, n_vlib_mains);
- vec_validate (im->arp_throttle_seeds, n_vlib_mains);
- vec_validate (im->arp_throttle_last_seed_change_time, n_vlib_mains);
-
- for (i = 0; i < n_vlib_mains; i++)
- vec_validate (im->arp_throttle_bitmaps[i],
- (ARP_THROTTLE_BITS / BITS (uword)) - 1);
- return 0;
+ return (NULL);
}
VLIB_MAIN_LOOP_ENTER_FUNCTION (ip4_main_loop_enter);