/* * 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 /** * the logger */ vlib_log_class_t mfib_entry_logger; /** * Pool of path extensions */ static mfib_path_ext_t *mfib_path_ext_pool; /** * String names for each source */ static const char *mfib_source_names[] = MFIB_SOURCE_NAMES; /* * Pool for all fib_entries */ mfib_entry_t *mfib_entry_pool; static fib_node_t * mfib_entry_get_node (fib_node_index_t index) { return ((fib_node_t*)mfib_entry_get(index)); } static fib_protocol_t mfib_entry_get_proto (const mfib_entry_t * mfib_entry) { return (mfib_entry->mfe_prefix.fp_proto); } fib_forward_chain_type_t mfib_entry_get_default_chain_type (const mfib_entry_t *mfib_entry) { switch (mfib_entry->mfe_prefix.fp_proto) { case FIB_PROTOCOL_IP4: return (FIB_FORW_CHAIN_TYPE_MCAST_IP4); case FIB_PROTOCOL_IP6: return (FIB_FORW_CHAIN_TYPE_MCAST_IP6); case FIB_PROTOCOL_MPLS: ASSERT(0); break; } return (FIB_FORW_CHAIN_TYPE_MCAST_IP4); } static u8 * format_mfib_entry_dpo (u8 * s, va_list * args) { index_t fei = va_arg(*args, index_t); CLIB_UNUSED(u32 indent) = va_arg(*args, u32); return (format(s, "%U", format_mfib_entry, fei, MFIB_ENTRY_FORMAT_BRIEF)); } static inline mfib_path_ext_t * mfib_entry_path_ext_get (index_t mi) { return (pool_elt_at_index(mfib_path_ext_pool, mi)); } static u8 * format_mfib_entry_path_ext (u8 * s, va_list * args) { mfib_path_ext_t *path_ext; index_t mpi = va_arg(*args, index_t); path_ext = mfib_entry_path_ext_get(mpi); return (format(s, "path:%d flags:%U", path_ext->mfpe_path, format_mfib_itf_flags, path_ext->mfpe_flags)); } u8 * format_mfib_entry (u8 * s, va_list * args) { fib_node_index_t fei, mfi; mfib_entry_t *mfib_entry; mfib_entry_src_t *msrc; u32 sw_if_index; int level; fei = va_arg (*args, fib_node_index_t); level = va_arg (*args, int); mfib_entry = mfib_entry_get(fei); s = format (s, "%U", format_mfib_prefix, &mfib_entry->mfe_prefix); s = format (s, ": %U", format_mfib_entry_flags, mfib_entry->mfe_flags); if (level >= MFIB_ENTRY_FORMAT_DETAIL) { fib_node_index_t path_index, mpi; s = format (s, "\n"); s = format (s, " fib:%d", mfib_entry->mfe_fib_index); s = format (s, " index:%d", mfib_entry_get_index(mfib_entry)); s = format (s, " locks:%d\n", mfib_entry->mfe_node.fn_locks); vec_foreach(msrc, mfib_entry->mfe_srcs) { s = format (s, " src:%s locks:%d:", mfib_source_names[msrc->mfes_src], msrc->mfes_ref_count); if (msrc->mfes_cover != FIB_NODE_INDEX_INVALID) { s = format (s, " cover:%d", msrc->mfes_cover); } s = format (s, " %U\n", format_mfib_entry_flags, msrc->mfes_flags); if (FIB_NODE_INDEX_INVALID != msrc->mfes_pl) { s = fib_path_list_format(msrc->mfes_pl, s); } s = format (s, " Extensions:\n"); hash_foreach(path_index, mpi, msrc->mfes_exts, ({ s = format(s, " %U\n", format_mfib_entry_path_ext, mpi); })); s = format (s, " Interface-Forwarding:\n"); hash_foreach(sw_if_index, mfi, msrc->mfes_itfs, ({ s = format(s, " %U\n", format_mfib_itf, mfi); })); } } s = format(s, "\n Interfaces:"); hash_foreach(sw_if_index, mfi, mfib_entry->mfe_itfs, ({ s = format(s, "\n %U", format_mfib_itf, mfi); })); if (MFIB_RPF_ID_NONE != mfib_entry->mfe_rpf_id) { s = format(s, "\n RPF-ID:%d", mfib_entry->mfe_rpf_id); } s = format(s, "\n %U-chain\n %U", format_fib_forw_chain_type, mfib_entry_get_default_chain_type(mfib_entry), format_dpo_id, &mfib_entry->mfe_rep, 2); s = format(s, "\n"); if (level >= MFIB_ENTRY_FORMAT_DETAIL2) { s = format(s, "\nchildren:"); s = fib_node_children_format(mfib_entry->mfe_node.fn_children, s); } return (s); } static mfib_entry_t* mfib_entry_from_fib_node (fib_node_t *node) { ASSERT(FIB_NODE_TYPE_MFIB_ENTRY == node->fn_type); return ((mfib_entry_t*)node); } static int mfib_entry_src_cmp_for_sort (void * v1, void * v2) { mfib_entry_src_t *esrc1 = v1, *esrc2 = v2; return (esrc1->mfes_src - esrc2->mfes_src); } static void mfib_entry_src_init (mfib_entry_t *mfib_entry, mfib_source_t source) { mfib_entry_src_t esrc = { .mfes_pl = FIB_NODE_INDEX_INVALID, .mfes_flags = MFIB_ENTRY_FLAG_NONE, .mfes_src = source, .mfes_cover = FIB_NODE_INDEX_INVALID, .mfes_sibling = FIB_NODE_INDEX_INVALID, .mfes_ref_count = 1, }; vec_add1(mfib_entry->mfe_srcs, esrc); vec_sort_with_function(mfib_entry->mfe_srcs, mfib_entry_src_cmp_for_sort); } static mfib_entry_src_t * mfib_entry_src_find (const mfib_entry_t *mfib_entry, mfib_source_t source, u32 *index) { mfib_entry_src_t *esrc; int ii; ii = 0; vec_foreach(esrc, mfib_entry->mfe_srcs) { if (esrc->mfes_src == source) { if (NULL != index) { *index = ii; } return (esrc); } else { ii++; } } return (NULL); } static mfib_entry_src_t * mfib_entry_src_find_or_create (mfib_entry_t *mfib_entry, mfib_source_t source) { mfib_entry_src_t *msrc; msrc = mfib_entry_src_find(mfib_entry, source, NULL); if (NULL == msrc) { mfib_entry_src_init(mfib_entry, source); msrc = mfib_entry_src_find(mfib_entry, source, NULL); } return (msrc); } static mfib_entry_src_t * mfib_entry_src_update (mfib_entry_t *mfib_entry, mfib_source_t source, fib_rpf_id_t rpf_id, mfib_entry_flags_t entry_flags) { mfib_entry_src_t *msrc; msrc = mfib_entry_src_find_or_create(mfib_entry, source); msrc->mfes_flags = entry_flags; msrc->mfes_rpf_id = rpf_id; return (msrc); } static mfib_entry_src_t * mfib_entry_src_update_and_lock (mfib_entry_t *mfib_entry, mfib_source_t source, fib_rpf_id_t rpf_id, mfib_entry_flags_t entry_flags) { mfib_entry_src_t *msrc; msrc = mfib_entry_src_update(mfib_entry, source, rpf_id, entry_flags); msrc->mfes_ref_count++; return (msrc); } mfib_entry_src_t* mfib_entry_get_best_src (const mfib_entry_t *mfib_entry) { mfib_entry_src_t *bsrc; /* * the enum of sources is deliberately arranged in priority order */ if (0 == vec_len(mfib_entry->mfe_srcs)) { bsrc = NULL; } else { bsrc = vec_elt_at_index(mfib_entry->mfe_srcs, 0); } return (bsrc); } static mfib_source_t mfib_entry_get_best_source (const mfib_entry_t *mfib_entry) { mfib_entry_src_t *bsrc; bsrc = mfib_entry_get_best_src(mfib_entry); return (bsrc->mfes_src); } int mfib_entry_is_sourced (fib_node_index_t mfib_entry_index, mfib_source_t source) { mfib_entry_t *mfib_entry; mfib_entry = mfib_entry_get(mfib_entry_index); return (NULL != mfib_entry_src_find(mfib_entry, source, NULL)); } int mfib_entry_is_host (fib_node_index_t mfib_entry_index) { return (mfib_prefix_is_host(mfib_entry_get_prefix(mfib_entry_index))); } static void mfib_entry_src_flush (mfib_entry_src_t *msrc) { u32 sw_if_index; index_t mfii; hash_foreach(sw_if_index, mfii, msrc->mfes_itfs, ({ mfib_itf_delete(mfib_itf_get(mfii)); })); hash_free(msrc->mfes_itfs); msrc->mfes_itfs = NULL; fib_path_list_unlock(msrc->mfes_pl); } static void mfib_entry_src_remove (mfib_entry_t *mfib_entry, mfib_source_t source) { mfib_entry_src_t *msrc; u32 index = ~0; msrc = mfib_entry_src_find(mfib_entry, source, &index); if (NULL != msrc) { ASSERT(0 != msrc->mfes_ref_count); msrc->mfes_ref
/*
  Copyright (c) 2001, 2002, 2003 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.
*/

_ (EPERM, "Operation not permitted")
_ (ENOENT, "No such file or directory")
_ (ESRCH, "No such process")
_ (EINTR, "Interrupted system call")
_ (EIO, "I/O error")
_ (ENXIO, "No such device or address")
_ (E2BIG, "Arg list too long")
_ (ENOEXEC, "Exec format error")
_ (EBADF, "Bad file number")
_ (ECHILD, "No child processes")
_ (ENOMEM, "Out of memory")
_ (EACCES, "Permission denied")
_ (EFAULT, "Bad address")
_ (ENOTBLK, "Block device required")
_ (EBUSY, "Device or resource busy")
_ (EEXIST, "File exists")
_ (EXDEV, "Cross-device link")
_ (ENODEV, "No such device")
_ (ENOTDIR, "Not a directory")
_ (EISDIR, "Is a directory")
_ (EINVAL, "Invalid argument")
_ (ENFILE, "File table overflow")
_ (EMFILE, "Too many open files")
_ (ENOTTY, "Not a typewriter")
_ (ETXTBSY, "Text file busy")
_ (EFBIG, "File too large")
_ (ENOSPC, "No space left on device")
_ (ESPIPE, "Illegal seek")
_ (EROFS, "Read-only file system")
_ (EMLINK, "Too many links")
_ (EPIPE, "Broken pipe")
_ (EDOM, "Math argument out of domain of func")
_ (ERANGE, "Math result not representable")
_ (EDEADLK, "Resource deadlock would occur")
_ (ENAMETOOLONG, "File name too long")
_ (ENOLCK, "No record locks available")
_ (ENOSYS, "Function not implemented")
_ (ENOTEMPTY, "Directory not empty")
_ (ELOOP, "Too many symbolic links encountered")
_ (EWOULDBLOCK, "Operation would block")
_ (ENOMSG, "No message of desired type")
_ (EIDRM, "Identifier removed")
_ (ECHRNG, "Channel number out of range")
_ (EL2NSYNC, "Level 2 not synchronized")
_ (EL3HLT, "Level 3 halted")
_ (EL3RST, "Level 3 reset")
_ (ELNRNG, "Link number out of range")
_ (EUNATCH, "Protocol driver not attached")
_ (ENOCSI, "No CSI structure available")
_ (EL2HLT, "Level 2 halted")
_ (EBADE, "Invalid exchange")
_ (EBADR, "Invalid request descriptor")
_ (EXFULL, "Exchange full")
_ (ENOANO, "No anode")
_ (EBADRQC, "Invalid request code")
_ (EBADSLT, "Invalid slot")
_ (EBFONT, "Bad font file format")
_ (ENOSTR, "Device not a stream")
_ (ENODATA, "No data available")
_ (ETIME, "Timer expired")
_ (ENOSR, "Out of streams resources")
_ (ENONET, "Machine is not on the network")
_ (ENOPKG, "Package not installed")
_ (EREMOTE, "Object is remote")
_ (ENOLINK, "Link has been severed")
_ (EADV, "Advertise error")
_ (ESRMNT, "Srmount error")
_ (ECOMM, "Communication error on send")
_ (EPROTO, "Protocol error")
_ (EMULTIHOP, "Multihop attempted")
_ (EDOTDOT, "RFS specific error")
_ (EBADMSG, "Not a data message")
_ (EOVERFLOW, "Value too large for defined data type")
_ (ENOTUNIQ, "Name not unique on network")
_ (EBADFD, "File descriptor in bad state")
_ (EREMCHG, "Remote address changed")
_ (ELIBACC, "Can not access a needed shared library")
_ (ELIBBAD, "Accessing a corrupted shared library")
_ (ELIBSCN, "lib section in a.out corrupted")
_ (ELIBMAX, "Attempting to link in too many shared libraries")
_ (ELIBEXEC, "Cannot exec a shared library directly")
_ (EILSEQ, "Illegal byte sequence")
_ (ERESTART, "Interrupted system call should be restarted")
_ (ESTRPIPE, "Streams pipe error")
_ (EUSERS, "Too many users")
_ (ENOTSOCK, "Socket operation on non-socket")
_ (EDESTADDRREQ, "Destination address required")
_ (EMSGSIZE, "Message too long")
_ (EPROTOTYPE, "Protocol wrong type for socket")
_ (ENOPROTOOPT, "Protocol not available")
_ (EPROTONOSUPPORT, "Protocol not supported")
_ (ESOCKTNOSUPPORT, "Socket type not supported")
_ (EOPNOTSUPP, "Operation not supported on transport endpoint")
_ (EPFNOSUPPORT, "Protocol family not supported")
_ (EAFNOSUPPORT, "Address family not supported by protocol")
_ (EADDRINUSE, "Address already in use")
_ (EADDRNOTAVAIL, "Cannot assign requested address")
_ (ENETDOWN, "Network is down")
_ (ENETUNREACH, "Network is unreachable")
_ (ENETRESET, "Network dropped connection because of reset")
_ (ECONNABORTED, "Software caused connection abort")
_ (ECONNRESET, "Connection reset by peer")
_ (ENOBUFS, "No buffer space available")
_ (EISCONN, "Transport endpoint is already connected")
_ (ENOTCONN, "Transport endpoint is not connected")
_ (ESHUTDOWN, "Cannot send after transport endpoint shutdown")
_ (ETOOMANYREFS, "Too many references: cannot splice")
_ (ETIMEDOUT, "Connection timed out")
_ (ECONNREFUSED, "Connection refused")
_ (EHOSTDOWN, "Host is down")
_ (EHOSTUNREACH, "No route to host")
_ (EALREADY, "Operation already in progress")
_ (EINPROGRESS, "Operation now in progress")
_ (ESTALE, "Stale NFS file handle")
_ (EUCLEAN, "Structure needs cleaning")
_ (ENOTNAM, "Not a XENIX named type file")
_ (ENAVAIL, "No XENIX semaphores available")
_ (EISNAM, "Is a named type file")
_ (EREMOTEIO, "Remote I/O error")
_ (EDQUOT, "Quota exceeded")
_ (ENOMEDIUM, "No medium found")
_ (EMEDIUMTYPE, "Wrong medium type")
*mfib_entry; mfib_entry_src_t *msrc; mfib_src_res_t res; mfib_entry = mfib_entry_get(mfib_entry_index); msrc = mfib_entry_get_best_src(mfib_entry); res = mfib_entry_src_cover_change(mfib_entry, msrc); if (MFIB_SRC_REEVALUATE == res) { mfib_entry_recalculate_forwarding(mfib_entry, msrc->mfes_src); } MFIB_ENTRY_DBG(mfib_entry, "cover-changed"); } /* * mfib_entry_cover_updated * * this entry is tracking its cover and that cover has been updated * (i.e. its forwarding information has changed). */ void mfib_entry_cover_updated (fib_node_index_t mfib_entry_index) { mfib_entry_t *mfib_entry; mfib_entry_src_t *msrc; mfib_src_res_t res; mfib_entry = mfib_entry_get(mfib_entry_index); msrc = mfib_entry_get_best_src(mfib_entry); res = mfib_entry_src_cover_update(mfib_entry, msrc); if (MFIB_SRC_REEVALUATE == res) { mfib_entry_recalculate_forwarding(mfib_entry, msrc->mfes_src); } MFIB_ENTRY_DBG(mfib_entry, "cover-updated"); } u32 mfib_entry_pool_size (void) { return (pool_elts(mfib_entry_pool)); } static clib_error_t * show_mfib_entry_command (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { fib_node_index_t fei; if (unformat (input, "%d", &fei)) { /* * show one in detail */ if (!pool_is_free_index(mfib_entry_pool, fei)) { vlib_cli_output (vm, "%d@%U", fei, format_mfib_entry, fei, MFIB_ENTRY_FORMAT_DETAIL2); } else { vlib_cli_output (vm, "entry %d invalid", fei); } } else { /* * show all */ vlib_cli_output (vm, "FIB Entries:"); pool_foreach_index(fei, mfib_entry_pool, ({ vlib_cli_output (vm, "%d@%U", fei, format_mfib_entry, fei, MFIB_ENTRY_FORMAT_BRIEF); })); } return (NULL); } /*? * This commnad displays an entry, or all entries, in the mfib tables indexed by their unique * numerical indentifier. ?*/ VLIB_CLI_COMMAND (show_mfib_entry, static) = { .path = "show mfib entry", .function = show_mfib_entry_command, .short_help = "show mfib entry", };