session: make port range configurable 05/39605/3
authorNathan Skrzypczak <nathan.skrzypczak@gmail.com>
Tue, 3 Oct 2023 11:54:15 +0000 (13:54 +0200)
committerFlorin Coras <florin.coras@gmail.com>
Tue, 3 Oct 2023 16:28:36 +0000 (16:28 +0000)
Type: feature

This patch makes the port range used by the transport layer
configurable in the manner of sysctl's ip_local_port_range.

Change-Id: Ie17f776538311b29d1dca64643a3a0bd74cb90a6
Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
src/vnet/session/session.c
src/vnet/session/session.h
src/vnet/session/transport.c

index 1f73eef..23c58ef 100644 (file)
@@ -2171,6 +2171,8 @@ session_main_init (vlib_main_t * vm)
   smm->use_private_rx_mqs = 0;
   smm->no_adaptive = 0;
   smm->last_transport_proto_type = TRANSPORT_PROTO_HTTP;
+  smm->port_allocator_min_src_port = 1024;
+  smm->port_allocator_max_src_port = 65535;
 
   return 0;
 }
@@ -2268,6 +2270,10 @@ session_config_fn (vlib_main_t * vm, unformat_input_t * input)
       else if (unformat (input, "local-endpoints-table-buckets %d",
                         &smm->local_endpoints_table_buckets))
        ;
+      else if (unformat (input, "min-src-port %d", &tmp))
+       smm->port_allocator_min_src_port = tmp;
+      else if (unformat (input, "max-src-port %d", &tmp))
+       smm->port_allocator_max_src_port = tmp;
       else if (unformat (input, "enable"))
        smm->session_enable_asap = 1;
       else if (unformat (input, "use-app-socket-api"))
index 4de7bb2..ebaad5a 100644 (file)
@@ -267,6 +267,10 @@ typedef struct session_main_
   u32 local_endpoints_table_memory;
   u32 local_endpoints_table_buckets;
 
+  /** Transport source port allocation range */
+  u16 port_allocator_min_src_port;
+  u16 port_allocator_max_src_port;
+
   /** Preallocate session config parameter */
   u32 preallocated_sessions;
 
index bfd85eb..0012ba2 100644 (file)
@@ -35,6 +35,8 @@ typedef struct transport_main_
   local_endpoint_t *local_endpoints;
   u32 *lcl_endpts_freelist;
   u32 port_allocator_seed;
+  u16 port_allocator_min_src_port;
+  u16 port_allocator_max_src_port;
   u8 lcl_endpts_cleanup_pending;
   clib_spinlock_t local_endpoints_lock;
 } transport_main_t;
@@ -597,8 +599,9 @@ int
 transport_alloc_local_port (u8 proto, ip46_address_t *lcl_addr,
                            transport_endpoint_cfg_t *rmt)
 {
-  u16 min = 1024, max = 65535; /* XXX configurable ? */
   transport_main_t *tm = &tp_main;
+  u16 min = tm->port_allocator_min_src_port;
+  u16 max = tm->port_allocator_max_src_port;
   int tries, limit;
 
   limit = max - min;
@@ -971,6 +974,8 @@ transport_init (void)
 
   /* Initialize [port-allocator] random number seed */
   tm->port_allocator_seed = (u32) clib_cpu_time_now ();
+  tm->port_allocator_min_src_port = smm->port_allocator_min_src_port;
+  tm->port_allocator_max_src_port = smm->port_allocator_max_src_port;
 
   clib_bihash_init_24_8 (&tm->local_endpoints_table, "local endpoints table",
                         smm->local_endpoints_table_buckets,