diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/nat/nat44-ed/nat44_ed_in2out.c | 163 | ||||
-rw-r--r-- | src/plugins/nat/nat44-ei/nat44_ei.c | 68 | ||||
-rw-r--r-- | src/plugins/nat/nat44-ei/nat44_ei.h | 4 | ||||
-rw-r--r-- | src/plugins/nat/nat44-ei/nat44_ei_in2out.c | 4 | ||||
-rw-r--r-- | src/plugins/nat/test/test_nat44_ed.py | 39 | ||||
-rw-r--r-- | src/plugins/nat/test/test_nat44_ei.py | 44 |
6 files changed, 215 insertions, 107 deletions
diff --git a/src/plugins/nat/nat44-ed/nat44_ed_in2out.c b/src/plugins/nat/nat44-ed/nat44_ed_in2out.c index b99b3367329..59355e49ccd 100644 --- a/src/plugins/nat/nat44-ed/nat44_ed_in2out.c +++ b/src/plugins/nat/nat44-ed/nat44_ed_in2out.c @@ -165,91 +165,112 @@ snat_not_translate_fast (snat_main_t *sm, vlib_node_runtime_t *node, } static int -nat_ed_alloc_addr_and_port (snat_main_t *sm, u32 rx_fib_index, u32 nat_proto, - u32 thread_index, ip4_address_t r_addr, u16 r_port, - u8 proto, u16 port_per_thread, - u32 snat_thread_index, snat_session_t *s, - ip4_address_t *outside_addr, u16 *outside_port) +nat_ed_alloc_addr_and_port_with_snat_address ( + snat_main_t *sm, u32 nat_proto, u32 thread_index, snat_address_t *a, + u16 port_per_thread, u32 snat_thread_index, snat_session_t *s, + ip4_address_t *outside_addr, u16 *outside_port) { - int i; - snat_address_t *a, *ga = 0; - const u16 port_thread_offset = (port_per_thread * snat_thread_index) + 1024; - for (i = 0; i < vec_len (sm->addresses); i++) + s->o2i.match.daddr = a->addr; + /* first try port suggested by caller */ + u16 port = clib_net_to_host_u16 (*outside_port); + u16 port_offset = port - port_thread_offset; + if (port <= port_thread_offset || + port > port_thread_offset + port_per_thread) + { + /* need to pick a different port, suggested port doesn't fit in + * this thread's port range */ + port_offset = snat_random_port (0, port_per_thread - 1); + port = port_thread_offset + port_offset; + } + u16 attempts = ED_PORT_ALLOC_ATTEMPTS; + do { - a = sm->addresses + i; - switch (nat_proto) + if (NAT_PROTOCOL_ICMP == nat_proto) { -#define _(N, j, n, unused) \ + s->o2i.match.sport = clib_host_to_net_u16 (port); + } + s->o2i.match.dport = clib_host_to_net_u16 (port); + if (0 == nat_ed_ses_o2i_flow_hash_add_del (sm, thread_index, s, 2)) + { +#define _(N, i, n, s) \ case NAT_PROTOCOL_##N: \ - if (a->fib_index == rx_fib_index) \ - { \ - s->o2i.match.daddr = a->addr; \ - /* first try port suggested by caller */ \ - u16 port = clib_net_to_host_u16 (*outside_port); \ - u16 port_offset = port - port_thread_offset; \ - if (port <= port_thread_offset || \ - port > port_thread_offset + port_per_thread) \ - { \ - /* need to pick a different port, suggested port doesn't fit in \ - * this thread #!/usr/bin/env bash
# Copyright (c) 2021 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Recompile DPDK l3fwd sample app with patching.
set -exuo pipefail
# Assumptions:
# + There is a directory holding CSIT code to use (this script is there).
# + At least one of the following is true:
# ++ JOB_NAME environment variable is set,
# ++ or this entry script has access to arguments.
# Consequences (and specific assumptions) are multiple,
# examine tree of functions for current description.
# FIXME: Define API contract (as opposed to just help) for bootstrap.
# "set -eu" handles failures from the following two lines.
BASH_ENTRY_DIR="$(dirname $(readlink -e "${BASH_SOURCE[0]}"))"
BASH_FUNCTION_DIR="$(readlink -e "${BASH_ENTRY_DIR}/../function")"
source "${BASH_FUNCTION_DIR}/common.sh" || {
echo "Source failed." >&2
exit 1
}
source "${BASH_FUNCTION_DIR}/dpdk.sh" || die "Source failed."
common_dirs || die
dpdk_l3fwd_compile "${@}" || die
|