/* * l2_output.c : layer 2 output packet processing * * Copyright (c) 2013 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 /* Feature graph node names */ static char *l2output_feat_names[] = { #define _(sym,name) name, foreach_l2output_feat #undef _ }; char ** l2output_get_feat_names (void) { return l2output_feat_names; } l2output_main_t l2output_main; typedef struct { /* per-pkt trace data */ u8 src[6]; u8 dst[6]; u32 sw_if_index; } l2output_trace_t; /* packet trace format function */ static u8 * format_l2output_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 *); l2output_trace_t *t = va_arg (*args, l2output_trace_t *); s = format (s, "l2-output: sw_if_index %d dst %U src %U", t->sw_if_index, format_ethernet_address, t->dst, format_ethernet_address, t->src); return s; } static char *l2output_error_strings[] = { #define _(sym,string) string, foreach_l2output_error #undef _ }; /** * Check for split horizon violations. * Return 0 if split horizon check passes, otherwise return non-zero. * Packets should not be transmitted out an interface with the same * split-horizon group as the input interface, except if the @c shg is 0 * in which case the check always passes. */ static_always_inline u32 split_horizon_violation (u8 shg1, u8 shg2) { if (PREDICT_TRUE (shg1 == 0)) { return 0; } else { return shg1 == shg2; } } static_always_inline void l2output_vtr (vlib_node_runtime_t * node, l2_output_config_t * config, u32 feature_bitmap, vlib_buffer_t * b, u32 * next) { if (PREDICT_FALSE (config->out_vtr_flag)) { /* Perform pre-vtr EFP filter check if configured */ if (config->output_vtr.push_and_pop_bytes) { /* * Perform output vlan tag rewrite and the pre-vtr EFP filter check. * The EFP Filter only needs to be run if there is an output VTR * configured. The flag for the post-vtr EFP Filter node is used * to trigger the pre-vtr check as well. */ u32 failed1 = (feature_bitmap & L2OUTPUT_FEAT_EFP_FILTER) && (l2_efp_filter_process (b, &(config->input_vtr))); u32 failed2 = l2_vtr_process (b, &(config->output_vtr)); if (PREDICT_FALSE (failed1 | failed2)) { *next = L2OUTPUT_NEXT_DROP; if (failed2) { b->error = node->errors[L2OUTPUT_ERROR_VTR_DROP]; } if (failed1) { b->error = node->errors[L2OUTPUT_ERROR_EFP_DROP]; } } } // perform the PBB rewrite else if (config->output_pbb_vtr.push_and_pop_bytes) { u32 failed = l2_pbb_process (b, &(config->output_pbb_vtr)); if (PREDICT_FALSE (failed)) { *next = L2OUTPUT_NEXT_DROP; b->error = node->errors[L2OUTPUT_ERROR_VTR_DROP]; } } } } static vlib_node_registration_t l2output_node; static uword l2output_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { u32 n_left_from, *from, *to_next; l2output_next_t next_index; l2output_main_t *msm = &l2output_main; u32 cached_sw_if_index; u32 cached_next_index; /* Invalidate cache */ cached_sw_if_index = ~0; cached_next_index = ~0; /* warning be gone */ from = vlib_frame_vector_args (frame); n_left_from = frame->n_vectors; /* number of packets to process */ next_index = node->cached_next_index; while (n_left_from > 0) { u32 n_left_to_next; /* get space to enqueue frame to graph node "next_index" */ vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); while (n_left_from >= 8 && n_left_to_next >= 4) { u32 bi0, bi1, bi2, bi3; vlib_buffer_t *b0, *b1, *b2, *b3; u32 next0, next1, next2, next3; u32 sw_if_index0, sw_if_index1, sw_if_index2, sw_if_index3; ethernet_header_t *h0, *h1, *h2, *h3; l2_output_config_t *config0, *config1, *config2, *config3; u32 feature_bitmap0, feature_bitmap1; u32 feature_bitmap2, feature_bitmap3; /* Prefetch next iteration. */ { vlib_buffer_t *p4, *p5, *p6, *p7; p4 = vlib_get_buffer (vm, from[4]); p5 = vlib_get_buffer (vm, from[5]); p6 = vlib_get_buffer (vm, from[6]); p7 = vlib_get_buffer (vm, from[7]); /* Prefetch the buffer header for the N+2 loop iteration */ vlib_prefetch_buffer_header (p4, LOAD); vlib_prefetch_buffer_header (p5, LOAD); vlib_prefetch_buffer_header (p6, LOAD); vlib_prefetch_buffer_header (p7, LOAD); } /* speculatively enqueue b0 and b1 to the current next frame */ /* bi is "buffer index", b is pointer to the buffer */ to_next[0] = bi0 = from[0]; to_next[1] = bi1 = from[1]; to_next[2] = bi2 = from[2]; to_next[3] = bi3 = from[3]; from += 4; to_next += 4; n_left_from -= 4; n_left_to_next -= 4; b0 = vlib_get_buffer (vm, bi0); b1 = vlib_get_buffer (vm, bi1); b2 = vlib_get_buffer (vm, bi2); b3 = vlib_get_buffer (vm, bi3); /* TX interface handles */ sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX]; sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_TX]; sw_if_index2 = vnet_buffer (b2)->sw_if_index[VLIB_TX]; sw_if_index3 = vnet_buffer (b3)->sw_if_index[VLIB_TX]; if (PREDICT_FALSE ((node->flags & VLIB_NODE
# Copyright (c) 2018 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.

##############################################################################
# Check for memfd_create headers and libs
##############################################################################
check_c_source_compiles("
  #define _GNU_SOURCE
  #include <sys/mman.h>
  int main() { return memfd_create (\"/dev/false\", 0); }
" HAVE_MEMFD_CREATE)

if (HAVE_MEMFD_CREATE)
    add_definitions(-DHAVE_MEMFD_CREATE)
endif()

check_c_source_compiles("
  #define _GNU_SOURCE
  #include <sched.h>
  int main() { return getcpu (0, 0); }
" HAVE_GETCPU)

if (HAVE_GETCPU)
    add_definitions(-DHAVE_GETCPU)
endif()

check_c_source_compiles("
  #define _GNU_SOURCE
  #include <fcntl.h>
  int main() { return fcntl64 (0, 0); }
" HAVE_FCNTL64)

if (HAVE_FCNTL64)
    add_definitions(-DHAVE_FCNTL64)
endif()
* l2output_intf_config (u32 sw_if_index) { l2output_main_t *mp = &l2output_main; vec_validate (mp->configs, sw_if_index); return vec_elt_at_index (mp->configs, sw_if_index); } /** Enable (or disable) the feature in the bitmap for the given interface. */ void l2output_intf_bitmap_enable (u32 sw_if_index, u32 feature_bitmap, u32 enable) { l2output_main_t *mp = &l2output_main; l2_output_config_t *config; vec_validate (mp->configs, sw_if_index); config = vec_elt_at_index (mp->configs, sw_if_index); if (enable) { config->feature_bitmap |= feature_bitmap; } else { config->feature_bitmap &= ~feature_bitmap; } } /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */