/* * Copyright (c) 2015 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. */ /* * node.h: VLIB processing nodes * * Copyright (c) 2008 Eliot Dresselhaus * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef included_vlib_node_h #define included_vlib_node_h #include #include #include #include /* for vlib_trace_filter_t */ /* Forward declaration. */ struct vlib_node_runtime_t; struct vlib_frame_t; /* Internal nodes (including output nodes) move data from node to node (or out of the graph for output nodes). */ typedef uword (vlib_node_function_t) (struct vlib_main_t * vm, struct vlib_node_runtime_t * node, struct vlib_frame_t * frame); typedef enum { /* An internal node on the call graph (could be output). */ VLIB_NODE_TYPE_INTERNAL, /* Nodes which input data into the processing graph. Input nodes are called for each iteration of main loop. */ VLIB_NODE_TYPE_INPUT, /* Nodes to be called before all input nodes. Used, for example, to clean out driver TX rings before processing input. */ VLIB_NODE_TYPE_PRE_INPUT, /* "Process" nodes which can be suspended and later resumed. */ VLIB_NODE_TYPE_PROCESS, VLIB_N_NODE_TYPE, } vlib_node_type_t; typedef struct _vlib_node_fn_registration { vlib_node_function_t *function; int priority; struct _vlib_node_fn_registration *next_registration; } vlib_node_fn_registration_t; typedef struct _vlib_node_registration { /* Vector processing function for this node. */ vlib_node_function_t *function; /* Node function candidate registration with priority */ vlib_node_fn_registration_t *node_fn_registrations; /* Node name. */ char *name; /* Name of sibling (if applicable). */ char *sibling_of; /* Node index filled in by registration. */ u32 index; /* Type of this node. */ vlib_node_type_t type; /* Error strings indexed by error code for this node. */ char **error_strings; /* Buffer format/unformat for this node. */ format_function_t *format_buffer; unformat_function_t *unformat_buffer; /* Trace format/unformat for this node. */ format_function_t *format_trace; unformat_function_t *unformat_trace; /* Function to validate incoming frames. */ u8 *(*validate_frame) (struct vlib_main_t * vm, struct vlib_node_runtime_t *, struct vlib_frame_t * f); /* Per-node runtime data. */ void *runtime_data; /* Process stack size. */ u16 process_log2_n_stack_bytes; /* Number of bytes of per-node run time data. */ u8 runtime_data_bytes; /* State for input nodes. */ u8 state; /* Node flags. */ u16 flags; /* Size of scalar and vector arguments in bytes. */ u16 scalar_size, vector_size; /* Number of error codes used by this node. */ u16 n_errors; /* Number of next node names that follow. */ u16 n_next_nodes; /* Constructor link-list, don't ask... */ struct _vlib_node_registration *next_registration; /* Names of next nodes which this node feeds into. */ char *next_nodes[]; } vlib_node_registration_t; #define VLIB_REGISTER_NODE(x,...) \ __VA_ARGS__ vlib_node_registration_t x; \ static void __vlib_add_node_registration_##x (void) \ __attribute__((__constructor__)) ; \ static void __vlib_add_node_registration_##x (void) \ { \ vlib_main_t * vm = vlib_get_main(); \ x.next_registration = vm->node_main.node_registrations; \ vm->node_main.node_registrations = &x; \ } \ static void __vlib_rm_node_registration_##x (void) \ __attribute__((__destructor__)) ; \ static void __vlib_rm_node_registration_##x (void) \ { \ vlib_main_t * vm = vlib_get_main(); \ VLIB_REMOVE_FROM_LINKED_LIST (vm->node_main.node_registrations, \ &x, next_registration); \ } \ __VA_ARGS__ vlib_node_registration_t x #define VLIB_NODE_FN(node) \ uword CLIB_MARCH_SFX (node##_fn)(); \ static vlib_node_fn_registration_t \ CLIB_MARCH_SFX(node##_fn_registration) = \ { .function = &CLIB_MARCH_SFX (node##_fn), }; \ \ static void __clib_constructor \ CLIB_MARCH_SFX (node##_multiarch_register) (void) \ { \ extern vlib_node_registration_t node; \ vlib_node_fn_registration_t *r; \ r = & CLIB_MARCH_SFX (node##_fn_registration); \ r->priority = CLIB_MARCH_FN_PRIORITY(); \ r->next_registration = node.node_fn_registrations; \ node.node_fn_registrations = r; \ } \ uword CLIB_CPU_OPTIMIZED CLIB_MARCH_SFX (node##_fn) #if CLIB_DEBUG > 0 #define VLIB_NODE_FUNCTION_CLONE_TEMPLATE(arch, fn) #define VLIB_NODE_FUNCTION_MULTIARCH_CLONE(fn) #define VLIB_NODE_FUNCTION_MULTIARCH(node, fn) #else #define VLIB_NODE_FUNCTION_CLONE_TEMPLATE(arch, fn, tgt) \ uword \ __attribute__ ((flatten)) \ __attribute__ ((target (tgt))) \ CLIB_CPU_OPTIMIZED \ fn ## _ ## arch ( struct vlib_main_t * vm, \ struct vlib_node_runtime_t * node, \ struct vlib_frame_t * frame) \ { return fn (vm, node, frame); } #define VLIB_NODE_FUNCTION_MULTIARCH_CLONE(fn) \ foreach_march_variant(VLIB_NODE_FUNCTION_CLONE_TEMPLATE, fn) #define VLIB_NODE_FUNCTION_MULTIARCH(node, fn) \ VLIB_NODE_FUNCTION_MULTIARCH_CLONE(fn) \ CLIB_MULTIARCH_SELECT_FN(fn, static inline) \ static void __attribute__((__constructor__)) \ __vlib_node_function_multiarch_select_##node (void) \ { node.function = fn ## _multiarch_select(); } #endif always_inline vlib_node_registration_t * vlib_node_next_registered (vlib_node_registration_t * c) { c = clib_elf_section_data_next (c, c->n_next_nodes * sizeof (c->next_nodes[0])); return c; } typedef struct { /* Total calls, clock ticks and vector elements processed for this node. */ u64 calls, vectors, clocks, suspends; u64 max_clock; u64 max_clock_n; } vlib_node_stats_t; #define foreach_vlib_node_state \ /* Input node is called each iteration of main loop. \ This is the default (zero). */ \ _ (POLLING) \ /* Input node is called when device signals an interrupt. */ \ _ (INTERRUPT) \ /* Input node is never called. */ \ _ (DISABLED) typedef enum { #define _(f) VLIB_NODE_STATE_##f, foreach_vlib_node_state #undef _ VLIB_N_NODE_STATE, } vlib_node_state_t; typedef struct vlib_node_t { /* Vector processing function for this node. */ vlib_node_function_t *function; /* Node name. */ u8 *name; /* Node name index in elog string table. */ u32 name_elog_string; /* Total statistics for this node. */ vlib_node_stats_t stats_total; /* Saved values as of last clear (or zero if never cleared). Current values are always stats_total - stats_last_clear. */ vlib_node_stats_t stats_last_clear; /* Type of this node. */ vlib_node_type_t type; /* Node index. */ u32 index; /* Index of corresponding node runtime. */ u32 runtime_index; /* Runtime data for this node. */ void *runtime_data; /* Node flags. */ u16 flags; /* Processing function keeps frame. Tells node dispatching code not to free frame after dispatch is done. */ #define VLIB_NODE_FLAG_FRAME_NO_FREE_AFTER_DISPATCH (1 << 0) /* Node counts as output/drop/punt node for stats purposes. */ #define VLIB_NODE_FLAG_IS_OUTPUT (1 << 1) #define VLIB_NODE_FLAG_IS_DROP (1 << 2) #define VLIB_NODE_FLAG_IS_PUNT (1 << 3) #define VLIB_NODE_FLAG_IS_HANDOFF (1 << 4) /* Set if current node runtime has traced vectors. */ #define VLIB_NODE_FLAG_TRACE (1 << 5) #define VLIB_NODE_FLAG_SWITCH_FROM_INTERRUPT_TO_POLLING_MODE (1 << 6) #define VLIB_NODE_FLAG_SWITCH_FROM_POLLING_TO_INTERRUPT_MODE (1 << 7) /* State for input nodes. */ u8 state; /* Number of bytes of run time data. */ u8 runtime_data_bytes; /* Number of error codes used by this node. */ u16 n_errors; /* Size of scalar and vector arguments in bytes. */ u16 scalar_size, vector_size; /* Handle/index in error heap for this node. */ u32 error_heap_handle; u32 error_heap_index; /* Error strings indexed by error code for this node. */ char **error_strings; /* Vector of next node names. Only used before next_nodes array is initialized. */ char **n
/*
 * 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.
 */
/**
 * @brief The IPv4 FIB
 *
 * FIBs are composed of two prefix data-bases (akak tables). The non-forwarding
 * table contains all the routes that the control plane has programmed, the
 * forwarding table contains the sub-set of those routes that can be used to
 * forward packets.
 * In the IPv4 FIB the non-forwarding table is an array of hash tables indexed
 * by mask length, the forwarding table is an mtrie
 *
 * This IPv4 FIB is used by the protocol independent FIB. So directly using
 * this APIs in client code is not encouraged. However, this IPv4 FIB can be
 * used if all the client wants is an IPv4 prefix data-base
 */

#ifndef __IP4_FIB_H__
#define __IP4_FIB_H__

#include <vlib/vlib.h>
#include <vnet/ip/ip.h>
#include <vnet/fib/fib_entry.h>
#include <vnet/fib/fib_table.h>
#include <vnet/ip/ip4_mtrie.h>

typedef struct ip4_fib_t_
{
  /** Required for pool_get_aligned */
  CLIB_CACHE_LINE_ALIGN_MARK(cacheline0);

  /**
   * Mtrie for fast lookups. Hash is used to maintain overlapping prefixes.
   * First member so it's in the first cacheline.