Skip to content

Commit

Permalink
Add more randomness to underlay ipv6 by changing the start value of t…
Browse files Browse the repository at this point in the history
…he counter

Signed-off-by: Guvenc Gulce <[email protected]>
  • Loading branch information
guvenc committed Sep 21, 2023
1 parent 861c944 commit edab0c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/dp_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ static int run_service(void)
{
int result;

srand(time(NULL));
srand(rte_rdtsc());

// pre-init sanity checks
if (!dp_conf_is_conntrack_enabled() && dp_conf_is_offload_enabled()) {
Expand Down
14 changes: 11 additions & 3 deletions src/grpc/dp_grpc_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
#include "grpc/dp_grpc_api.h"
#include "grpc/dp_grpc_responder.h"

static uint32_t pfx_counter = 1;
static uint32_t pfx_counter = 0;

static __rte_always_inline void dp_generate_underlay_ipv6(uint8_t route[DP_VNF_IPV6_ADDR_SIZE])
{
rte_be32_t local = htonl(pfx_counter);
rte_be32_t local;
uint8_t random_byte;

/* First 8 bytes for host */
Expand All @@ -37,10 +37,18 @@ static __rte_always_inline void dp_generate_underlay_ipv6(uint8_t route[DP_VNF_I
/* 1 byte random value */
rte_memcpy(route + 11, &random_byte, 1);

#ifndef ENABLE_STATIC_UNDERLAY_IP
/* Start the counter from a random value as well to increase the randomness of the address */
if (pfx_counter == 0)
pfx_counter = rand() % 256;
#endif

pfx_counter++;
local = htonl(pfx_counter);

/* 4 byte counter */
rte_memcpy(route + 12, &local, 4);

pfx_counter++;
}

static int dp_insert_vnf_entry(struct dp_vnf_value *val, enum vnf_type v_type,
Expand Down

0 comments on commit edab0c3

Please sign in to comment.