diff options
author | Klement Sekera <ksekera@cisco.com> | 2020-06-08 11:10:55 +0000 |
---|---|---|
committer | Ole Trøan <otroan@employees.org> | 2020-06-16 09:05:15 +0000 |
commit | cf9bb22a9483b97b00b7dcacc35b37ae0fcaefbe (patch) | |
tree | 9060c60156842464828e63a2255a79619ed1374d /src/plugins/nat/nat_inlines.h | |
parent | 9ebbb5c41620066d45915020569db9e4316450a5 (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.h | 15 |
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__ */ /* |