summaryrefslogtreecommitdiffstats
path: root/src/plugins/nat/nat_inlines.h
diff options
context:
space:
mode:
authorKlement Sekera <ksekera@cisco.com>2020-06-08 11:10:55 +0000
committerOle Trøan <otroan@employees.org>2020-06-16 09:05:15 +0000
commitcf9bb22a9483b97b00b7dcacc35b37ae0fcaefbe (patch)
tree9060c60156842464828e63a2255a79619ed1374d /src/plugins/nat/nat_inlines.h
parent9ebbb5c41620066d45915020569db9e4316450a5 (diff)
nat: improve outside port selection & perf
Prefer using source port form packet as outside port if possible. Type: improvement Signed-off-by: Klement Sekera <ksekera@cisco.com> Change-Id: I5c25f6a42386f38c9a6cc95bd7dda9f090b49817
Diffstat (limited to 'src/plugins/nat/nat_inlines.h')
-rw-r--r--src/plugins/nat/nat_inlines.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/plugins/nat/nat_inlines.h b/src/plugins/nat/nat_inlines.h
index 40ac3d307a8..67411750c95 100644
--- a/src/plugins/nat/nat_inlines.h
+++ b/src/plugins/nat/nat_inlines.h
@@ -813,6 +813,21 @@ increment_v4_address (ip4_address_t * a)
a->as_u32 = clib_host_to_net_u32 (v);
}
+static_always_inline u16
+snat_random_port (u16 min, u16 max)
+{
+ snat_main_t *sm = &snat_main;
+ u32 rwide;
+ u16 r;
+
+ rwide = random_u32 (&sm->random_seed);
+ r = rwide & 0xFFFF;
+ if (r >= min && r <= max)
+ return r;
+
+ return min + (rwide % (max - min + 1));
+}
+
#endif /* __included_nat_inlines_h__ */
/*