X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Fnat%2Fnat44-ed%2Fnat44_ed_classify.c;fp=src%2Fplugins%2Fnat%2Fnat44_classify.c;h=5a9f4e42657d953db6f8efe2f2c8f8932834564a;hb=0eaf4e6784efb2d058fe2f031578251b6bcc0aa8;hp=85f8c64afd5b75bc9185fdcf2714a4ee171ae081;hpb=5db2f4a4312112ab57043ce88f10edc4acc141ec;p=vpp.git diff --git a/src/plugins/nat/nat44_classify.c b/src/plugins/nat/nat44-ed/nat44_ed_classify.c similarity index 70% rename from src/plugins/nat/nat44_classify.c rename to src/plugins/nat/nat44-ed/nat44_ed_classify.c index 85f8c64afd5..5a9f4e42657 100644 --- a/src/plugins/nat/nat44_classify.c +++ b/src/plugins/nat/nat44-ed/nat44_ed_classify.c @@ -20,9 +20,9 @@ #include #include #include -#include -#include -#include + +#include +#include #define foreach_nat44_classify_error \ _(NEXT_IN2OUT, "next in2out") \ @@ -37,12 +37,6 @@ typedef enum NAT44_CLASSIFY_N_ERROR, } nat44_classify_error_t; -static char *nat44_classify_error_strings[] = { -#define _(sym,string) string, - foreach_nat44_classify_error -#undef _ -}; - typedef enum { NAT44_CLASSIFY_NEXT_IN2OUT, @@ -69,118 +63,13 @@ format_nat44_classify_trace (u8 * s, va_list * args) s = format (s, "nat44-classify: fragment cached"); else { - next = t->next_in2out ? "nat44-in2out" : "nat44-out2in"; + next = t->next_in2out ? "nat44-ed-in2out" : "nat44-ed-out2in"; s = format (s, "nat44-classify: next %s", next); } return s; } -static inline uword -nat44_classify_node_fn_inline (vlib_main_t * vm, - vlib_node_runtime_t * node, - vlib_frame_t * frame) -{ - u32 n_left_from, *from, *to_next; - nat44_classify_next_t next_index; - snat_main_t *sm = &snat_main; - snat_static_mapping_t *m; - u32 next_in2out = 0, next_out2in = 0; - - from = vlib_frame_vector_args (frame); - n_left_from = frame->n_vectors; - next_index = node->cached_next_index; - - while (n_left_from > 0) - { - u32 n_left_to_next; - - vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); - - while (n_left_from > 0 && n_left_to_next > 0) - { - u32 bi0; - vlib_buffer_t *b0; - u32 next0 = NAT44_CLASSIFY_NEXT_IN2OUT; - ip4_header_t *ip0; - snat_address_t *ap; - clib_bihash_kv_8_8_t kv0, value0; - - /* speculatively enqueue b0 to the current next frame */ - bi0 = from[0]; - to_next[0] = bi0; - from += 1; - to_next += 1; - n_left_from -= 1; - n_left_to_next -= 1; - - b0 = vlib_get_buffer (vm, bi0); - ip0 = vlib_buffer_get_current (b0); - - /* *INDENT-OFF* */ - vec_foreach (ap, sm->addresses) - { - if (ip0->dst_address.as_u32 == ap->addr.as_u32) - { - next0 = NAT44_CLASSIFY_NEXT_OUT2IN; - goto enqueue0; - } - } - /* *INDENT-ON* */ - - if (PREDICT_FALSE (pool_elts (sm->static_mappings))) - { - init_nat_k (&kv0, ip0->dst_address, 0, 0, 0); - /* try to classify the fragment based on IP header alone */ - if (!clib_bihash_search_8_8 (&sm->static_mapping_by_external, - &kv0, &value0)) - { - m = pool_elt_at_index (sm->static_mappings, value0.value); - if (m->local_addr.as_u32 != m->external_addr.as_u32) - next0 = NAT44_CLASSIFY_NEXT_OUT2IN; - goto enqueue0; - } - init_nat_k (&kv0, ip0->dst_address, - vnet_buffer (b0)->ip.reass.l4_dst_port, 0, - ip_proto_to_nat_proto (ip0->protocol)); - if (!clib_bihash_search_8_8 - (&sm->static_mapping_by_external, &kv0, &value0)) - { - m = pool_elt_at_index (sm->static_mappings, value0.value); - if (m->local_addr.as_u32 != m->external_addr.as_u32) - next0 = NAT44_CLASSIFY_NEXT_OUT2IN; - } - } - - enqueue0: - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) - && (b0->flags & VLIB_BUFFER_IS_TRACED))) - { - nat44_classify_trace_t *t = - vlib_add_trace (vm, node, b0, sizeof (*t)); - t->cached = 0; - t->next_in2out = next0 == NAT44_CLASSIFY_NEXT_IN2OUT ? 1 : 0; - } - - next_in2out += next0 == NAT44_CLASSIFY_NEXT_IN2OUT; - next_out2in += next0 == NAT44_CLASSIFY_NEXT_OUT2IN; - - /* verify speculative enqueue, maybe switch current next frame */ - vlib_validate_buffer_enqueue_x1 (vm, node, next_index, - to_next, n_left_to_next, - bi0, next0); - } - - vlib_put_next_frame (vm, node, next_index, n_left_to_next); - } - - vlib_node_increment_counter (vm, node->node_index, - NAT44_CLASSIFY_ERROR_NEXT_IN2OUT, next_in2out); - vlib_node_increment_counter (vm, node->node_index, - NAT44_CLASSIFY_ERROR_NEXT_OUT2IN, next_out2in); - return frame->n_vectors; -} - static inline uword nat44_handoff_classify_node_fn_inline (vlib_main_t * vm, vlib_node_runtime_t * node, @@ -222,7 +111,6 @@ nat44_handoff_classify_node_fn_inline (vlib_main_t * vm, b0 = vlib_get_buffer (vm, bi0); ip0 = vlib_buffer_get_current (b0); - /* *INDENT-OFF* */ vec_foreach (ap, sm->addresses) { if (ip0->dst_address.as_u32 == ap->addr.as_u32) @@ -231,7 +119,6 @@ nat44_handoff_classify_node_fn_inline (vlib_main_t * vm, goto enqueue0; } } - /* *INDENT-ON* */ if (PREDICT_FALSE (pool_elts (sm->static_mappings))) { @@ -374,7 +261,6 @@ nat44_ed_classify_node_fn_inline (vlib_main_t * vm, /* session doesn't exist so continue in code */ } - /* *INDENT-OFF* */ vec_foreach (ap, sm->addresses) { if (ip0->dst_address.as_u32 == ap->addr.as_u32) @@ -383,7 +269,6 @@ nat44_ed_classify_node_fn_inline (vlib_main_t * vm, goto enqueue0; } } - /* *INDENT-ON* */ if (PREDICT_FALSE (pool_elts (sm->static_mappings))) { @@ -438,30 +323,6 @@ nat44_ed_classify_node_fn_inline (vlib_main_t * vm, return frame->n_vectors; } -VLIB_NODE_FN (nat44_classify_node) (vlib_main_t * vm, - vlib_node_runtime_t * node, - vlib_frame_t * frame) -{ - return nat44_classify_node_fn_inline (vm, node, frame); -} - -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (nat44_classify_node) = { - .name = "nat44-classify", - .vector_size = sizeof (u32), - .format_trace = format_nat44_classify_trace, - .type = VLIB_NODE_TYPE_INTERNAL, - .n_errors = ARRAY_LEN(nat44_classify_error_strings), - .error_strings = nat44_classify_error_strings, - .n_next_nodes = NAT44_CLASSIFY_N_NEXT, - .next_nodes = { - [NAT44_CLASSIFY_NEXT_IN2OUT] = "nat44-in2out", - [NAT44_CLASSIFY_NEXT_OUT2IN] = "nat44-out2in", - [NAT44_CLASSIFY_NEXT_DROP] = "error-drop", - }, -}; -/* *INDENT-ON* */ - VLIB_NODE_FN (nat44_ed_classify_node) (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) @@ -469,7 +330,6 @@ VLIB_NODE_FN (nat44_ed_classify_node) (vlib_main_t * vm, return nat44_ed_classify_node_fn_inline (vm, node, frame); } -/* *INDENT-OFF* */ VLIB_REGISTER_NODE (nat44_ed_classify_node) = { .name = "nat44-ed-classify", .vector_size = sizeof (u32), @@ -477,7 +337,6 @@ VLIB_REGISTER_NODE (nat44_ed_classify_node) = { .format_trace = format_nat44_classify_trace, .type = VLIB_NODE_TYPE_INTERNAL, }; -/* *INDENT-ON* */ VLIB_NODE_FN (nat44_handoff_classify_node) (vlib_main_t * vm, vlib_node_runtime_t * node, @@ -486,7 +345,6 @@ VLIB_NODE_FN (nat44_handoff_classify_node) (vlib_main_t * vm, return nat44_handoff_classify_node_fn_inline (vm, node, frame); } -/* *INDENT-OFF* */ VLIB_REGISTER_NODE (nat44_handoff_classify_node) = { .name = "nat44-handoff-classify", .vector_size = sizeof (u32), @@ -495,8 +353,6 @@ VLIB_REGISTER_NODE (nat44_handoff_classify_node) = { .type = VLIB_NODE_TYPE_INTERNAL, }; -/* *INDENT-ON* */ - /* * fd.io coding-style-patch-verification: ON *