/* * Copyright (c) 2016 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. */ #include #include #include #include #include #include #include #include #include #include typedef struct mfib_forward_lookup_trace_t_ { u32 entry_index; u32 fib_index; } mfib_forward_lookup_trace_t; static u8 * format_mfib_forward_lookup_trace (u8 * s, va_list * args) { CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); mfib_forward_lookup_trace_t * t = va_arg (*args, mfib_forward_lookup_trace_t *); s = format (s, "fib %d entry %d", t->fib_index, t->entry_index); return s; } /* Common trace function for all ip4-forward next nodes. */ void mfib_forward_lookup_trace (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { u32 * from, n_left; ip4_main_t * im = &ip4_main; n_left = frame->n_vectors; from = vlib_frame_vector_args (frame); while (n_left >= 4) { mfib_forward_lookup_trace_t * t0, * t1; vlib_buffer_t * b0, * b1; u32 bi0, bi1; /* Prefetch next iteration. */ vlib_prefetch_buffer_with_index (vm, from[2], LOAD); vlib_prefetch_buffer_with_index (vm, from[3], LOAD); bi0 = from[0]; bi1 = from[1]; b0 = vlib_get_buffer (vm, bi0); b1 = vlib_get_buffer (vm, bi1); if (b0->flags & VLIB_BUFFER_IS_TRACED) { t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0])); t0->entry_index = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; t0->fib_index = vec_elt (im->mfib_index_by_sw_if_index, vnet_buffer(b1)->sw_if_index[VLIB_RX]); } if (b1->flags & VLIB_BUFFER_IS_TRACED) { t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0])); t1->entry_index = vnet_buffer (b1)->ip.adj_index[VLIB_TX]; t1->fib_index = vec_elt (im->mfib_index_by_sw_if_index, vnet_buffer(b1)->sw_if_index[VLIB_RX]); } from += 2; n_left -= 2; } while (n_left >= 1) { mfib_forward_lookup_trace_t * t0; vlib_buffer_t * b0; u32 bi0; bi0 = from[0]; b0 = vlib_get_buffer (vm, bi0); if (b0->flags & VLIB_BUFFER_IS_TRACED) { t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0])); t0->entry_index = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; t0->fib_index = vec_elt (im->mfib_index_by_sw_if_index, vnet_buffer(b0)->sw_if_index[VLIB_RX]); } from += 1; n_left -= 1; } } typedef enum mfib_forward_lookup_next_t_ { MFIB_FORWARD_LOOKUP_NEXT_RPF, MFIB_FORWARD_LOOKUP_N_NEXT, } mfib_forward_lookup_next_t; static uword mfib_forward_lookup (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame, int is_v4) { u32 n_left_from, n_left_to_next, * from, * to_next; from = vlib_frame_vector_args (frame); n_left_from = frame->n_vectors; while (n_left_from > 0) { vlib_get_next_frame (vm, node, MFIB_FORWARD_LOOKUP_NEXT_RPF, to_next, n_left_to_next); while (n_left_from > 0 && n_left_to_next > 0) { fib_node_index_t mfei0; vlib_buffer_t * p0; u32 fib_index0; u32 pi0; pi0 = from[0]; to_next[0] = pi0; from += 1; to_next += 1; n_left_to_next -= 1; n_left_from -= 1; p0 = vlib_get_buffer (vm, pi0); if (is_v4) { ip4_header_t * ip0; fib_index0 = vec_elt (ip4_main.mfib_index_by_sw_if_index, vnet_buffer(p0)->sw_if_index[VLIB_RX]); ip0 = vlib_buffer_get_current (p0); mfei0 = ip4_mfib_table_lookup(ip4_mfib_get(fib_index0), &ip0->src_address, &ip0->dst_address, 64); } else { ip6_header_t * ip0; fib_index0 = vec_elt (ip6_main.mfib_index_by_sw_if_index, vnet_buffer(p0)->sw_if_index[VLIB_RX]); ip0 = vlib_buffer_get_current (p0); mfei0 = ip6_mfib_table_lookup2(ip6_mfib_get(fib_index0), &ip0->src_address, &ip0->dst_address); } vnet_buffer (p0)->ip.adj_index[VLIB_TX] = mfei0; } vlib_put_next_frame(vm, node, MFIB_FORWARD_LOOKUP_NEXT_RPF, n_left_to_next); } if (node->flags & VLIB_NODE_FLAG_TRACE) mfib_forward_lookup_trace(vm, node, frame); return frame->n_vectors; } static uword ip4_mfib_forward_lookup (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { return (mfib_forward_lookup (vm, node, frame, 1)); } VLIB_REGISTER_NODE (ip4_mfib_forward_lookup_node, static) = { .function = ip4_mfib_forward_lookup, .name = "ip4-mfib-forward-lookup", .vector_size = sizeof (u32), .format_trace = format_mfib_forward_lookup_trace, .n_next_nodes = MFIB_FORWARD_LOOKUP_N_NEXT, .next_nodes = { [MFIB_FORWARD_LOOKUP_NEXT_RPF] = "ip4-mfib-forward-rpf", }, }; VLIB_NODE_FUNCTION_MULTIARCH (ip4_mfib_forward_lookup_node, ip4_mfib_forward_lookup) static uword ip6_mfib_forward_lookup (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { return (mfib_forward_lookup (vm, node, frame, 0)); } VLIB_REGISTER_NODE (ip6_mfib_forward_lookup_node, static) = { .function = ip6_mfib_forward_lookup, .name = "ip6-mfib-forward-lookup", .vector_size = sizeof (u32), .format_trace = format_mfib_forward_lookup_trace, .n_next_nodes = MFIB_FORWARD_LOOKUP_N_NEXT, .next_nodes = { [MFIB_FORWARD_LOOKUP_NEXT_RPF] = "ip6-mfib-
/*
 * Copyright (c) 2020 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");