aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/fib/fib_entry_src_rr.c
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2018-02-21 04:57:17 -0800
committerNeale Ranns <nranns@cisco.com>2018-03-20 23:59:06 +0000
commit2303cb181b51f63c909cd506125c1f832432865a (patch)
treeea2389593abc50790e06b6ac2e80f2a38c536942 /src/vnet/fib/fib_entry_src_rr.c
parentf55957e71c58e38770b12af0720e9d19a8f6a8d6 (diff)
FIB Interpose Source
The interpose source allows the source/provider to insert/interpose a DPO in the forwarding chain of the FIB entry ahead of the forwarding provided by the next best source. For example if the API source (i.e the 'control plane') has provided an adjacency for forwarding, then an interpose source (e.g. a monitoring service) couold interpose a replicatte DPO to copy the traffic to another location AND forward using the API's adjacency. To use the interose feature an existing source (i.e FIB_SOURCE_PLUGIN_HI) cn specifiy as a flag FIB_ENTRY_FLAG_INTERPOSE and provide a DPO to interpose. One might also consider using interpose in conjunction with FIB_ENTRY_FLAG_COVER_INHERIT to ensure the interpose object affects all prefixes in the sub-tree. Change-Id: I8b2737b985f8f7c08123406d0491881def347b52 Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'src/vnet/fib/fib_entry_src_rr.c')
-rw-r--r--src/vnet/fib/fib_entry_src_rr.c42
1 files changed, 22 insertions, 20 deletions
diff --git a/src/vnet/fib/fib_entry_src_rr.c b/src/vnet/fib/fib_entry_src_rr.c
index b6f4bc3ba45..8e477362374 100644
--- a/src/vnet/fib/fib_entry_src_rr.c
+++ b/src/vnet/fib/fib_entry_src_rr.c
@@ -20,6 +20,7 @@
#include <vnet/dpo/drop_dpo.h>
#include "fib_entry_src.h"
+#include "fib_entry_src_rr.h"
#include "fib_entry_cover.h"
#include "fib_entry.h"
#include "fib_table.h"
@@ -29,7 +30,7 @@
*
* Resolve via a connected cover.
*/
-static void
+void
fib_entry_src_rr_resolve_via_connected (fib_entry_src_t *src,
const fib_entry_t *fib_entry,
const fib_entry_t *cover)
@@ -53,7 +54,8 @@ fib_entry_src_rr_resolve_via_connected (fib_entry_src_t *src,
* shortly to over-rule this RR source.
*/
src->fes_pl = fib_path_list_create(FIB_PATH_LIST_FLAG_NONE, paths);
- src->fes_entry_flags = fib_entry_get_flags(fib_entry_get_index(cover));
+ src->fes_entry_flags |= (fib_entry_get_flags(fib_entry_get_index(cover)) &
+ FIB_ENTRY_FLAGS_RR_INHERITED);
vec_free(paths);
}
@@ -65,8 +67,8 @@ fib_entry_src_rr_resolve_via_connected (fib_entry_src_t *src,
static void
fib_entry_src_rr_init (fib_entry_src_t *src)
{
- src->rr.fesr_cover = FIB_NODE_INDEX_INVALID;
- src->rr.fesr_sibling = FIB_NODE_INDEX_INVALID;
+ src->u.rr.fesr_cover = FIB_NODE_INDEX_INVALID;
+ src->u.rr.fesr_sibling = FIB_NODE_INDEX_INVALID;
}
@@ -84,7 +86,7 @@ fib_entry_src_rr_init (fib_entry_src_t *src)
* the loop will break when the cover changes, and this function
* will be called again when that happens.
*/
-static void
+void
fib_entry_src_rr_use_covers_pl (fib_entry_src_t *src,
const fib_entry_t *fib_entry,
const fib_entry_t *cover)
@@ -132,14 +134,14 @@ fib_entry_src_rr_activate (fib_entry_src_t *src,
return (!0);
}
- src->rr.fesr_cover = fib_table_get_less_specific(fib_entry->fe_fib_index,
+ src->u.rr.fesr_cover = fib_table_get_less_specific(fib_entry->fe_fib_index,
&fib_entry->fe_prefix);
- ASSERT(FIB_NODE_INDEX_INVALID != src->rr.fesr_cover);
+ ASSERT(FIB_NODE_INDEX_INVALID != src->u.rr.fesr_cover);
- cover = fib_entry_get(src->rr.fesr_cover);
+ cover = fib_entry_get(src->u.rr.fesr_cover);
- src->rr.fesr_sibling =
+ src->u.rr.fesr_sibling =
fib_entry_cover_track(cover, fib_entry_get_index(fib_entry));
/*
@@ -175,11 +177,11 @@ fib_entry_src_rr_deactivate (fib_entry_src_t *src,
/*
* remove the depednecy on the covering entry
*/
- if (FIB_NODE_INDEX_INVALID != src->rr.fesr_cover)
+ if (FIB_NODE_INDEX_INVALID != src->u.rr.fesr_cover)
{
- cover = fib_entry_get(src->rr.fesr_cover);
- fib_entry_cover_untrack(cover, src->rr.fesr_sibling);
- src->rr.fesr_cover = FIB_NODE_INDEX_INVALID;
+ cover = fib_entry_get(src->u.rr.fesr_cover);
+ fib_entry_cover_untrack(cover, src->u.rr.fesr_sibling);
+ src->u.rr.fesr_cover = FIB_NODE_INDEX_INVALID;
}
fib_path_list_unlock(src->fes_pl);
@@ -187,7 +189,7 @@ fib_entry_src_rr_deactivate (fib_entry_src_t *src,
src->fes_entry_flags = FIB_ENTRY_FLAG_NONE;
}
-static fib_entry_src_cover_res_t
+fib_entry_src_cover_res_t
fib_entry_src_rr_cover_change (fib_entry_src_t *src,
const fib_entry_t *fib_entry)
{
@@ -196,7 +198,7 @@ fib_entry_src_rr_cover_change (fib_entry_src_t *src,
.bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
};
- if (FIB_NODE_INDEX_INVALID == src->rr.fesr_cover)
+ if (FIB_NODE_INDEX_INVALID == src->u.rr.fesr_cover)
{
/*
* the source may be added, but it is not active
@@ -210,7 +212,7 @@ fib_entry_src_rr_cover_change (fib_entry_src_t *src,
* entry inserted benaeth it. That does not necessarily mean that this
* entry is covered by the new prefix. check that
*/
- if (src->rr.fesr_cover != fib_table_get_less_specific(fib_entry->fe_fib_index,
+ if (src->u.rr.fesr_cover != fib_table_get_less_specific(fib_entry->fe_fib_index,
&fib_entry->fe_prefix))
{
fib_entry_src_rr_deactivate(src, fib_entry);
@@ -230,7 +232,7 @@ fib_entry_src_rr_cover_change (fib_entry_src_t *src,
* This entry's cover has updated its forwarding info. This entry
* will need to re-inheret.
*/
-static fib_entry_src_cover_res_t
+fib_entry_src_cover_res_t
fib_entry_src_rr_cover_update (fib_entry_src_t *src,
const fib_entry_t *fib_entry)
{
@@ -241,7 +243,7 @@ fib_entry_src_rr_cover_update (fib_entry_src_t *src,
fib_node_index_t old_path_list;
fib_entry_t *cover;
- if (FIB_NODE_INDEX_INVALID == src->rr.fesr_cover)
+ if (FIB_NODE_INDEX_INVALID == src->u.rr.fesr_cover)
{
/*
* the source may be added, but it is not active
@@ -250,7 +252,7 @@ fib_entry_src_rr_cover_update (fib_entry_src_t *src,
return (res);
}
- cover = fib_entry_get(src->rr.fesr_cover);
+ cover = fib_entry_get(src->u.rr.fesr_cover);
old_path_list = src->fes_pl;
/*
@@ -280,7 +282,7 @@ static u8*
fib_entry_src_rr_format (fib_entry_src_t *src,
u8* s)
{
- return (format(s, " cover:%d", src->rr.fesr_cover));
+ return (format(s, " cover:%d", src->u.rr.fesr_cover));
}
const static fib_entry_src_vft_t rr_src_vft = {
} /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
/*
 * 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.
 */
/*
 * format.c: generic network formatting/unformating
 *
 * 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.
 */

#include <vlib/vlib.h>

u8 *
format_vlib_rx_tx (u8 * s, va_list * args)
{
  vlib_rx_or_tx_t r = va_arg (*args, vlib_rx_or_tx_t);
  char *t;

  switch (r)
    {
    case VLIB_RX:
      t = "rx";
      break;
    case VLIB_TX:
      t = "tx";
      break;
    default:
      t = "INVALID";
      break;
    }

  vec_add (s, t, strlen (t));
  return s;
}

u8 *
format_vlib_read_write (u8 * s, va_list * args)
{
  vlib_rx_or_tx_t r = va_arg (*args, vlib_rx_or_tx_t);
  char *t;

  switch (r)
    {
    case VLIB_READ:
      t = "read";
      break;
    case VLIB_WRITE:
      t = "write";
      break;
    default:
      t = "INVALID";
      break;
    }

  vec_add (s, t, strlen (t));
  return s;
}

/* Formats buffer data as printable ascii or as hex. */
u8 *
format_vlib_buffer_data (u8 * s, va_list * args)
{
  u8 *data = va_arg (*args, u8 *);
  u32 n_data_bytes = va_arg (*args, u32);
  u32 i, is_printable;

  is_printable = 1;
  for (i = 0; i < n_data_bytes && is_printable; i++)
    {
      u8 c = data[i];
      if (c < 0x20)
	is_printable = 0;
      else if (c >= 0x7f)
	is_printable = 0;
    }

  if (is_printable)
    vec_add (s, data, n_data_bytes);
  else
    s = format (s, "%U", format_hex_bytes, data, n_data_bytes);

  return s;
}

/* Enable/on => 1; disable/off => 0. */
uword
unformat_vlib_enable_disable (unformat_input_t * input, va_list * args)
{
  int *result = va_arg (*args, int *);
  int enable;

  if (unformat (input, "enable") || unformat (input, "on"))
    enable = 1;
  else if (unformat (input, "disable") || unformat (input, "off"))
    enable = 0;
  else
    return 0;

  *result = enable;
  return 1;
}

/* rx/tx => VLIB_RX/VLIB_TX. */
uword
unformat_vlib_rx_tx (unformat_input_t * input, va_list * args)
{
  int *result = va_arg (*args, int *);
  if (unformat (input, "rx"))
    *result = VLIB_RX;
  else if (unformat (input, "tx"))
    *result = VLIB_TX;
  else
    return 0;
  return 1;
}

/* Parse an int either %d or 0x%x. */
uword
unformat_vlib_number (unformat_input_t * input, va_list * args)
{
  int *result = va_arg (*args, int *);

  return (unformat (input, "0x%x", result) || unformat (input, "%d", result));
}

/* Parse a-zA-Z0-9_ token and hash to value. */
uword
unformat_vlib_number_by_name (unformat_input_t * input, va_list * args)
{
  uword *hash = va_arg (*args, uword *);
  int *result = va_arg (*args, int *);
  uword *p;
  u8 *token;
  int i;

  if (!unformat_user (input, unformat_token, "a-zA-Z0-9_", &token))
    return 0;

  /* Null terminate. */
  if (vec_len (token) > 0 && token[vec_len (token) - 1] != 0)
    vec_add1 (token, 0);

  /* Check for exact match. */
  p = hash_get_mem (hash, token);
  if (p)
    goto done;

  /* Convert to upper case & try match. */
  for (i = 0; i < vec_len (token); i++)
    if (token[i] >= 'a' && token[i] <= 'z')
      token[i] = 'A' + token[i] - 'a';
  p = hash_get_mem (hash, token);

done:
  vec_free (token);
  if (p)
    *result = p[0];
  return p != 0;
}

/* Parse a filename to dump debug info */
uword
unformat_vlib_tmpfile (unformat_input_t * input, va_list * args)
{
  u8 **chroot_filename = va_arg (*args, u8 **);
  u8 *filename;

  if (!unformat (input, "%s", &filename))
    return 0;

  /* Brain-police user path input */
  if (strstr ((char *) filename, "..") || index ((char *) filename, '/'))
    {
      vec_free (filename);
      return 0;
    }

  *chroot_filename = format (0, "/tmp/%s%c", filename, 0);
  vec_free (filename);

  return 1;
}

u8 *
format_vlib_thread_name (u8 * s, va_list * args)
{
  u32 thread_index = va_arg (*args, u32);

  if (thread_index == 0)
    return format (s, "main");

  if (thread_index < vec_len (vlib_worker_threads))
    return format (s, "%s", vlib_worker_threads[thread_index].name);
  return s;
}

u8 *
format_vlib_thread_name_and_index (u8 * s, va_list * args)
{
  u32 thread_index = va_arg (*args, u32);

  return format (s, "%U (%u)", format_vlib_thread_name, thread_index,
		 thread_index);
}

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */