summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plugins/cnat/cnat_node_feature.c38
-rw-r--r--src/plugins/cnat/cnat_translation.h5
-rw-r--r--src/plugins/cnat/cnat_types.c26
-rw-r--r--src/plugins/cnat/cnat_types.h9
4 files changed, 47 insertions, 31 deletions
diff --git a/src/plugins/cnat/cnat_node_feature.c b/src/plugins/cnat/cnat_node_feature.c
index 4585fcb5dd6..f9b6fa2a40d 100644
--- a/src/plugins/cnat/cnat_node_feature.c
+++ b/src/plugins/cnat/cnat_node_feature.c
@@ -126,19 +126,19 @@ cnat_input_feature_fn (vlib_main_t *vm, vlib_node_runtime_t *node,
clib_host_to_net_u16 (trk0->ct_ep[VLIB_TX].ce_port);
session->value.cs_port[VLIB_RX] = udp0->src_port;
- const dpo_id_t *dpo0;
- const load_balance_t *lb1;
- fib_entry_t *fib_entry;
- fib_entry = fib_entry_get (trk0->ct_fei);
-
- lb1 = load_balance_get (fib_entry->fe_lb /*[fct] */.dpoi_index);
- dpo0 = load_balance_get_bucket_i (lb1, 0);
+ if (trk0->ct_flags & CNAT_TRK_FLAG_NO_NAT)
+ {
+ const dpo_id_t *dpo0;
+ const load_balance_t *lb1;
- session->value.dpoi_next_node = dpo0->dpoi_next_node;
- session->value.cs_lbi = dpo0->dpoi_index;
+ lb1 = load_balance_get (trk0->ct_dpo.dpoi_index);
+ /* Assume backend has exactly one item in LB */
+ dpo0 = load_balance_get_bucket_i (lb1, 0);
- if (trk0->ct_flags & CNAT_TRK_FLAG_NO_NAT)
- session->value.flags |= CNAT_SESSION_FLAG_NO_NAT;
+ session->value.dpoi_next_node = dpo0->dpoi_next_node;
+ session->value.cs_lbi = dpo0->dpoi_index;
+ session->value.flags = CNAT_SESSION_FLAG_NO_NAT;
+ }
/* refcnt session in current client */
cnat_client_cnt_session (cc);
@@ -146,11 +146,13 @@ cnat_input_feature_fn (vlib_main_t *vm, vlib_node_runtime_t *node,
trace_flags |= CNAT_TRACE_SESSION_CREATED;
}
- next0 = session->value.dpoi_next_node;
- vnet_buffer (b)->ip.adj_index[VLIB_TX] = session->value.cs_lbi;
-
if (session->value.flags & CNAT_SESSION_FLAG_NO_NAT)
- goto trace;
+ {
+ /* If we don't translate, directly do the lookup & bypass arc */
+ next0 = session->value.dpoi_next_node;
+ vnet_buffer (b)->ip.adj_index[VLIB_TX] = session->value.cs_lbi;
+ goto trace;
+ }
if (AF_IP4 == ctx->af)
cnat_translation_ip4 (session, ip4, udp0);
@@ -190,8 +192,7 @@ VLIB_REGISTER_NODE (cnat_input_feature_ip4_node) = {
.type = VLIB_NODE_TYPE_INTERNAL,
.n_errors = CNAT_N_ERROR,
.error_strings = cnat_error_strings,
- .n_next_nodes = IP_LOOKUP_N_NEXT,
- .next_nodes = IP4_LOOKUP_NEXT_NODES,
+ .sibling_of = "ip4-lookup",
};
VNET_FEATURE_INIT (cnat_in_ip4_feature, static) = {
@@ -217,8 +218,7 @@ VLIB_REGISTER_NODE (cnat_input_feature_ip6_node) = {
.type = VLIB_NODE_TYPE_INTERNAL,
.n_errors = CNAT_N_ERROR,
.error_strings = cnat_error_strings,
- .n_next_nodes = IP6_LOOKUP_N_NEXT,
- .next_nodes = IP6_LOOKUP_NEXT_NODES,
+ .sibling_of = "ip6-lookup",
};
VNET_FEATURE_INIT (cnat_in_ip6_feature, static) = {
diff --git a/src/plugins/cnat/cnat_translation.h b/src/plugins/cnat/cnat_translation.h
index 3b6e694a845..97b0c908b42 100644
--- a/src/plugins/cnat/cnat_translation.h
+++ b/src/plugins/cnat/cnat_translation.h
@@ -25,11 +25,6 @@
*/
extern vlib_combined_counter_main_t cnat_translation_counters;
-typedef enum cnat_trk_flag_t_
-{
- CNAT_TRK_ACTIVE = (1 << 0),
- CNAT_TRK_FLAG_NO_NAT = (1 << 1),
-} cnat_trk_flag_t;
/**
* Data used to track an EP in the FIB
diff --git a/src/plugins/cnat/cnat_types.c b/src/plugins/cnat/cnat_types.c
index 837f40082c3..9b164c6069d 100644
--- a/src/plugins/cnat/cnat_types.c
+++ b/src/plugins/cnat/cnat_types.c
@@ -103,16 +103,28 @@ unformat_cnat_ep (unformat_input_t * input, va_list * args)
}
uword
+unformat_cnat_ep_flags (unformat_input_t *input, va_list *args)
+{
+ int *a = va_arg (*args, int *);
+ if (unformat (input, ":nonat"))
+ *a = CNAT_TRK_FLAG_NO_NAT;
+ return 1;
+}
+
+uword
unformat_cnat_ep_tuple (unformat_input_t * input, va_list * args)
{
cnat_endpoint_tuple_t *a = va_arg (*args, cnat_endpoint_tuple_t *);
- if (unformat (input, "%U->%U", unformat_cnat_ep, &a->src_ep,
- unformat_cnat_ep, &a->dst_ep))
- ;
- else if (unformat (input, "->%U", unformat_cnat_ep, &a->dst_ep))
- ;
- else if (unformat (input, "%U->", unformat_cnat_ep, &a->src_ep))
- ;
+ int flgs = 0;
+ if (unformat (input, "%U->%U%U", unformat_cnat_ep, &a->src_ep,
+ unformat_cnat_ep, &a->dst_ep, unformat_cnat_ep_flags, &flgs))
+ a->ep_flags = flgs;
+ else if (unformat (input, "->%U%U", unformat_cnat_ep, &a->dst_ep,
+ unformat_cnat_ep_flags, &flgs))
+ a->ep_flags = flgs;
+ else if (unformat (input, "%U->%U", unformat_cnat_ep, &a->src_ep,
+ unformat_cnat_ep_flags, &flgs))
+ a->ep_flags = flgs;
else
return 0;
return 1;
diff --git a/src/plugins/cnat/cnat_types.h b/src/plugins/cnat/cnat_types.h
index 47e34e1f232..c3ec74c345f 100644
--- a/src/plugins/cnat/cnat_types.h
+++ b/src/plugins/cnat/cnat_types.h
@@ -55,6 +55,15 @@
#define MIN_SRC_PORT ((u16) 0xC000)
+typedef enum cnat_trk_flag_t_
+{
+ /* Endpoint is active (static or dhcp resolved) */
+ CNAT_TRK_ACTIVE = (1 << 0),
+ /* Don't translate this endpoint, but still
+ * forward. Used by maglev for DSR */
+ CNAT_TRK_FLAG_NO_NAT = (1 << 1),
+} cnat_trk_flag_t;
+
typedef enum
{
/* Endpoint addr has been resolved */
e 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. import argparse import pathlib import subprocess BASE_DIR = subprocess.check_output('git rev-parse --show-toplevel', shell=True).strip().decode() vppapigen_bin = pathlib.Path( '%s/src/tools/vppapigen/vppapigen.py' % BASE_DIR).as_posix() src_dir_depth = 3 output_path = pathlib.Path( '%s/build-root/install-vpp-native/vpp/share/vpp/api/' % BASE_DIR) output_path_debug = pathlib.Path( '%s/build-root/install-vpp_debug-native/vpp/share/vpp/api/' % BASE_DIR) output_dir_map = { 'plugins': 'plugins', 'vlibmemory': 'core', 'vnet': 'core', 'vpp': 'core', } def api_search_globs(src_dir): globs = [] for g in output_dir_map: globs.extend(list(src_dir.glob('%s/**/*.api' % g))) return globs def api_files(src_dir): print("Searching '%s' for .api files." % src_dir.as_posix()) return [x for x in api_search_globs(src_dir)] def vppapigen(vppapigen_bin, output_path, src_dir, src_file): try: subprocess.check_output( [vppapigen_bin, '--includedir', src_dir.as_posix(), '--input', src_file.as_posix(), 'JSON', '--output', '%s/%s/%s.json' % ( output_path, output_dir_map[src_file.as_posix().split('/')[ src_dir_depth + BASE_DIR.count('/') - 1]], src_file.name)]) except KeyError: print('src_file: %s' % src_file) raise def main(): cliparser = argparse.ArgumentParser( description='VPP API JSON definition generator') cliparser.add_argument('--srcdir', action='store', default='%s/src' % BASE_DIR), cliparser.add_argument('--output', action='store', help='directory to store files'), cliparser.add_argument('--debug-target', action='store_true', default=False, help="'True' if -debug target"), args = cliparser.parse_args() src_dir = pathlib.Path(args.srcdir) output_target = output_path_debug if args.debug_target else output_path if args.output: output_dir = pathlib.Path(args.output) else: output_dir = pathlib.Path(output_target) for d in output_dir_map.values(): output_dir.joinpath(d).mkdir(exist_ok=True, parents=True) for f in output_dir.glob('**/*.api.json'): f.unlink() for f in api_files(src_dir): vppapigen(vppapigen_bin, output_dir, src_dir, f) print('json files written to: %s/.' % output_dir) if __name__ == '__main__': main()