summaryrefslogtreecommitdiffstats
path: root/src/vnet/fib/fib_entry.h
blob: 2f6e37fe69aef753dff6aadcff4330438872132b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .sx { color: #e6db74 } /* Literal.String.Other */
.highlight .sr { color: #e6db74 } /* Literal.String.Regex */
.highlight .s1 { color: #e6db74 } /* Literal.String.Single */
.highlight .ss { color: #e6db74 } /* Literal.String.Symbol */
.highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #a6e22e } /* Name.Function.Magic */
.highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */
.highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */
.highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */
.highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */
.highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */
}
@media (prefers-color-scheme: light) {
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* 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 */
}
# VPP SPAN implementation    {#span_doc}

This is a memo intended to contain documentation of the VPP SPAN implementation.
Everything that is not directly obvious should come here.


## Switched Port Analyzer (SPAN)
Port mirroring is used on a network switch to send a copy of network packets seen on one switch port to a network monitoring connection on another switch port.
Can be used by network engineers or administrators to measure performance, analyze and debug data or diagnose errors on a network.

### RX traffic node
There is one static node to mirror incoming packets.
* span-input: Creates a copy of incoming buffer due to incoming buffers can be reused internally.

Chaining: dpdk-input -> span-input ->
* original buffer is sent to ethernet-input for processing
* buffer copy is sent to interface-output

### Configuration
SPAN supports the following CLI configuration commands:

#### Enable/Disable SPAN (CLI)
	set interface span <if-name> [disable | destination <if-name>]

<if-name>: mirrored interface name
destination <if-name>: monitoring interface name
disable: delete mirroring

#### Enable/Disable SPAN (API)
SPAN supports the following API configuration command:
	sw_interface_span_enable_disable src GigabitEthernet0/8/0 dst GigabitEthernet0/9/0
	sw_interface_span_enable_disable src_sw_if_index 1 dst_sw_if_index 2

src/src_sw_if_index: mirrored interface name
dst/dst_sw_if_index: monitoring interface name

#### Remove SPAN entry (API)
SPAN supports the following API configuration command:
	sw_interface_span_enable_disable src_sw_if_index 1 dst_sw_if_index 2 disable

src_sw_if_index: mirrored interface name
dst_sw_if_index: monitoring interface name

### Configuration example

Mirror all packets on interface GigabitEthernet0/10/0 to interface GigabitEthernet0/11/0.

Configure IPv4 addresses on mirrored interface:
set interface ip address GigabitEthernet0/10/0 192.168.1.13/24
set interface state GigabitEthernet0/10/0 up

Configure IPv4 addresses on monitoring interface:
set interface ip address GigabitEthernet0/11/0 192.168.2.13/24
set interface state GigabitEthernet0/11/0 up

Configure SPAN
set span src GigabitEthernet0/10/0 dst GigabitEthernet0/11/0

### Operational data

Active SPAN mirroring CLI show command:
    show interfaces span

Active SPAN mirroring API dump command:
    sw_interface_span_dump
ref='#n436'>436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548
/*
 * 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.
 */

#ifndef __FIB_ENTRY_H__
#define __FIB_ENTRY_H__

#include <vnet/fib/fib_node.h>
#include <vnet/fib/fib_entry_delegate.h>
#include <vnet/adj/adj.h>
#include <vnet/ip/ip.h>
#include <vnet/dpo/dpo.h>

/**
 * The different sources that can create a route.
 * The sources are defined here the thier relative priority order.
 * The lower the value the higher the priority
 */
typedef enum fib_source_t_ {
    /**
     * Marker. Add new values after this one.
     */
    FIB_SOURCE_FIRST,
    /**
     * Special sources. These are for entries that are added to all
     * FIBs by default, and should never be over-ridden (hence they
     * are the highest priority)
     */
    FIB_SOURCE_SPECIAL = FIB_SOURCE_FIRST,
    /**
     * Classify. A route that links directly to a classify adj
     */
    FIB_SOURCE_CLASSIFY,
    /**
     * Route added as a result of interface configuration.
     * this will also come from the API/CLI, but the distinction is
     * that is from confiiguration on an interface, not a 'ip route' command
     */
    FIB_SOURCE_INTERFACE,
    /**
     * SRv6 and SR-MPLS
     */
    FIB_SOURCE_SR,
    /**
     * A high priority source a plugin can use
     */
    FIB_SOURCE_PLUGIN_HI,
    /**
     * From the control plane API
     */
    FIB_SOURCE_API,
    /**
     * From the CLI.
     */
    FIB_SOURCE_CLI,
    /**
     * LISP
     */
    FIB_SOURCE_LISP,
    /**
     * IPv[46] Mapping
     */
    FIB_SOURCE_MAP,
    /**
     * SIXRD
     */
    FIB_SOURCE_SIXRD,
    /**
     * DHCP
     */
    FIB_SOURCE_DHCP,
    /**
     * IPv6 Proxy ND
     */
    FIB_SOURCE_IP6_ND_PROXY,
    /**
     * Adjacency source.
     * routes created as a result of ARP/ND entries. This is lower priority
     * then the API/CLI. This is on purpose. trust me.
     */
    FIB_SOURCE_ADJ,
    /**
     * MPLS label. The prefix has been assigned a local label. This source
     * never provides forwarding information, instead it acts as a place-holder
     * so the association of label to prefix can be maintained
     */
    FIB_SOURCE_MPLS,
    /**
     * Attached Export source.
     * routes created as a result of attahced export. routes thus sourced
     * will be present in the export tables
     */
    FIB_SOURCE_AE,
    /**
     * Recursive resolution source.
     * Used to install an entry that is the resolution traget of another.
     */
    FIB_SOURCE_RR,
    /**
     * uRPF bypass/exemption.
     * Used to install an entry that is exempt from the loose uRPF check
     */
    FIB_SOURCE_URPF_EXEMPT,
    /**
     * The default route source.
     * The default route is always added to the FIB table (like the
     * special sources) but we need to be able to over-ride it with
     * 'ip route' sources when provided
     */
    FIB_SOURCE_DEFAULT_ROUTE,
    /**
     * Marker. add new entries before this one.
     */
    FIB_SOURCE_LAST = FIB_SOURCE_DEFAULT_ROUTE,
} __attribute__ ((packed)) fib_source_t;

STATIC_ASSERT (sizeof(fib_source_t) == 1,
	       "FIB too many sources");

/**
 * The maximum number of sources
 */
#define FIB_SOURCE_MAX (FIB_SOURCE_LAST+1)

#define FIB_SOURCES {					\
    [FIB_SOURCE_SPECIAL] = "special",			\
    [FIB_SOURCE_INTERFACE] = "interface",		\
    [FIB_SOURCE_API] = "API",			        \
    [FIB_SOURCE_CLI] = "CLI",			        \
    [FIB_SOURCE_ADJ] = "adjacency",			\
    [FIB_SOURCE_MAP] = "MAP",			        \
    [FIB_SOURCE_SR] = "SR",			        \
    [FIB_SOURCE_SIXRD] = "SixRD",			\
    [FIB_SOURCE_LISP] = "LISP", 			\
    [FIB_SOURCE_CLASSIFY] = "classify",			\
    [FIB_SOURCE_DHCP] = "DHCP",   			\
    [FIB_SOURCE_IP6_ND_PROXY] = "IPv6-proxy-nd",        \
    [FIB_SOURCE_RR] = "recursive-resolution",	        \
    [FIB_SOURCE_AE] = "attached_export",	        \
    [FIB_SOURCE_MPLS] = "mpls",           	        \
    [FIB_SOURCE_URPF_EXEMPT] = "urpf-exempt",	        \
    [FIB_SOURCE_DEFAULT_ROUTE] = "default-route",	\
}

#define FOR_EACH_FIB_SOURCE(_item) \
    for (_item = FIB_SOURCE_FIRST; _item < FIB_SOURCE_MAX; _item++)

/**
 * The different sources that can create a route.
 * The sources are defined here the thier relative priority order.
 * The lower the value the higher the priority
 */
typedef enum fib_entry_attribute_t_ {
    /**
     * Marker. Add new values after this one.
     */
    FIB_ENTRY_ATTRIBUTE_FIRST,
    /**
     * Connected. The prefix is configured on an interface.
     */
    FIB_ENTRY_ATTRIBUTE_CONNECTED = FIB_ENTRY_ATTRIBUTE_FIRST,
    /**
     * Attached. The prefix is attached to an interface.
     */
    FIB_ENTRY_ATTRIBUTE_ATTACHED,
    /**
     * The route is an explicit drop.
     */
    FIB_ENTRY_ATTRIBUTE_DROP,
    /**
     * The route is exclusive. The client creating the route is
     * providing an exclusive adjacency.
     */
    FIB_ENTRY_ATTRIBUTE_EXCLUSIVE,
    /**
     * The route is attached cross tables and thus imports covered
     * prefixes from the other table.
     */
    FIB_ENTRY_ATTRIBUTE_IMPORT,
    /**
     * The prefix/address is local to this device
     */
    FIB_ENTRY_ATTRIBUTE_LOCAL,
    /**
     * The prefix/address is a multicast prefix.
     *  this aplies only to MPLS. IP multicast is handled by mfib
     */
    FIB_ENTRY_ATTRIBUTE_MULTICAST,
    /**
     * The prefix/address exempted from loose uRPF check
     * To be used with caution
     */
    FIB_ENTRY_ATTRIBUTE_URPF_EXEMPT,
    /**
     * Marker. add new entries before this one.
     */
    FIB_ENTRY_ATTRIBUTE_LAST = FIB_ENTRY_ATTRIBUTE_URPF_EXEMPT,
} fib_entry_attribute_t;

#define FIB_ENTRY_ATTRIBUTES {		       		\
    [FIB_ENTRY_ATTRIBUTE_CONNECTED] = "connected",	\
    [FIB_ENTRY_ATTRIBUTE_ATTACHED]  = "attached",	\
    [FIB_ENTRY_ATTRIBUTE_IMPORT]    = "import",	        \
    [FIB_ENTRY_ATTRIBUTE_DROP]      = "drop",		\
    [FIB_ENTRY_ATTRIBUTE_EXCLUSIVE] = "exclusive",      \
    [FIB_ENTRY_ATTRIBUTE_LOCAL]     = "local",		\
    [FIB_ENTRY_ATTRIBUTE_URPF_EXEMPT] = "uRPF-exempt",  \
    [FIB_ENTRY_ATTRIBUTE_MULTICAST] = "multicast",	\
}

#define FOR_EACH_FIB_ATTRIBUTE(_item)			\
    for (_item = FIB_ENTRY_ATTRIBUTE_FIRST;		\
	 _item <= FIB_ENTRY_ATTRIBUTE_LAST;		\
	 _item++)

typedef enum fib_entry_flag_t_ {
    FIB_ENTRY_FLAG_NONE      = 0,
    FIB_ENTRY_FLAG_CONNECTED = (1 << FIB_ENTRY_ATTRIBUTE_CONNECTED),
    FIB_ENTRY_FLAG_ATTACHED  = (1 << FIB_ENTRY_ATTRIBUTE_ATTACHED),
    FIB_ENTRY_FLAG_DROP      = (1 << FIB_ENTRY_ATTRIBUTE_DROP),
    FIB_ENTRY_FLAG_EXCLUSIVE = (1 << FIB_ENTRY_ATTRIBUTE_EXCLUSIVE),
    FIB_ENTRY_FLAG_LOCAL     = (1 << FIB_ENTRY_ATTRIBUTE_LOCAL),
    FIB_ENTRY_FLAG_IMPORT    = (1 << FIB_ENTRY_ATTRIBUTE_IMPORT),
    FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT = (1 << FIB_ENTRY_ATTRIBUTE_URPF_EXEMPT),
    FIB_ENTRY_FLAG_MULTICAST = (1 << FIB_ENTRY_ATTRIBUTE_MULTICAST),
} __attribute__((packed)) fib_entry_flag_t;

/**
 * Flags for the source data
 */
typedef enum fib_entry_src_attribute_t_ {
    /**
     * Marker. Add new values after this one.
     */
    FIB_ENTRY_SRC_ATTRIBUTE_FIRST,
    /**
     * the source has been added to the entry
     */
    FIB_ENTRY_SRC_ATTRIBUTE_ADDED = FIB_ENTRY_SRC_ATTRIBUTE_FIRST,
    /**
     * the source is active/best
     */
    FIB_ENTRY_SRC_ATTRIBUTE_ACTIVE,
    /**
     * Marker. add new entries before this one.
     */
    FIB_ENTRY_SRC_ATTRIBUTE_LAST = FIB_ENTRY_SRC_ATTRIBUTE_ACTIVE,
} fib_entry_src_attribute_t;

#define FIB_ENTRY_SRC_ATTRIBUTE_MAX (FIB_ENTRY_SRC_ATTRIBUTE_LAST+1)

#define FIB_ENTRY_SRC_ATTRIBUTES {		 \
    [FIB_ENTRY_SRC_ATTRIBUTE_ADDED]  = "added",	 \
    [FIB_ENTRY_SRC_ATTRIBUTE_ACTIVE] = "active", \
}

typedef enum fib_entry_src_flag_t_ {
    FIB_ENTRY_SRC_FLAG_NONE   = 0,
    FIB_ENTRY_SRC_FLAG_ADDED  = (1 << FIB_ENTRY_SRC_ATTRIBUTE_ADDED),
    FIB_ENTRY_SRC_FLAG_ACTIVE = (1 << FIB_ENTRY_SRC_ATTRIBUTE_ACTIVE),
} __attribute__ ((packed)) fib_entry_src_flag_t;

/*
 * Keep the size of the flags field to 2 bytes, so it
 * can be placed next to the 2 bytes reference count
 */
STATIC_ASSERT (sizeof(fib_entry_src_flag_t) <= 2,
	       "FIB entry flags field size too big");

/**
 * Information related to the source of a FIB entry
 */
typedef struct fib_entry_src_t_ {
    /**
     * A vector of path extensions
     */
    fib_path_ext_list_t fes_path_exts;

    /**
     * The path-list created by the source
     */
    fib_node_index_t fes_pl;
    /**
     * Which source this info block is for
     */
    fib_source_t fes_src;
    /**
     * Flags on the source
     */
    fib_entry_src_flag_t fes_flags;

    /**
     * 1 bytes ref count. This is not the number of users of the Entry
     * (which is itself not large, due to path-list sharing), but the number
     * of times a given source has been added. Which is even fewer
     */
    u8 fes_ref_count;

    /**
     * Flags the source contributes to the entry
     */
    fib_entry_flag_t fes_entry_flags;
    
    /**
     * Source specific info
     */
    union {
	struct {
	    /**
	     * the index of the FIB entry that is the covering entry
	     */
	    fib_node_index_t fesr_cover;
	    /**
	     * This source's index in the cover's list
	     */
	    u32 fesr_sibling;
	} rr;
	struct {
	    /**
	     * the index of the FIB entry that is the covering entry
	     */
	    fib_node_index_t fesa_cover;
	    /**
	     * This source's index in the cover's list
	     */
	    u32 fesa_sibling;
	} adj;
	struct {
	    /**
	     * the index of the FIB entry that is the covering entry
	     */
	    fib_node_index_t fesi_cover;
	    /**
	     * This source's index in the cover's list
	     */
	    u32 fesi_sibling;
	} interface;
	struct {
	    /**
	     * This MPLS local label associated with the prefix.
	     */
	    mpls_label_t fesm_label;

	    /**
	     * the indicies of the LFIB entries created
	     */
	    fib_node_index_t fesm_lfes[2];
	} mpls;
	struct {
	    /**
	     * The source FIB index.
	     */
            fib_node_index_t fesl_fib_index;
	} lisp;
    };
} fib_entry_src_t;

/**
 * An entry in a FIB table.
 *
 * This entry represents a route added to the FIB that is stored
 * in one of the FIB tables.
 */
typedef struct fib_entry_t_ {
    /**
     * Base class. The entry's node representation in the graph.
     */
    fib_node_t fe_node;
    /**
     * The prefix of the route. this is const just to be sure.
     * It is the entry's key/identity and so should never change.
     */
    const fib_prefix_t fe_prefix;
    /**
     * The index of the FIB table this entry is in
     */
    u32 fe_fib_index;
    /**
     * The load-balance used for forwarding.
     *
     * We don't share the EOS and non-EOS even in case when they could be
     * because:
     *   - complexity & reliability v. memory
     *       determining the conditions where sharing is possible is non-trivial.
     *   - separate LBs means we can get the EOS bit right in the MPLS label DPO
     *     and so save a few clock cycles in the DP imposition node since we can
     *     paint the header straight on without the need to check the packet
     *     type to derive the EOS bit value.
     */
    dpo_id_t fe_lb;
    /**
     * Vector of source infos.
     * Most entries will only have 1 source. So we optimise for memory usage,
     * which is preferable since we have many entries.
     */
    fib_entry_src_t *fe_srcs;
    /**
     * the path-list for which this entry is a child. This is also the path-list
     * that is contributing forwarding for this entry.
     */
    fib_node_index_t fe_parent;
    /**
     * index of this entry in the parent's child list.
     * This is set when this entry is added as a child, but can also
     * be changed by the parent as it manages its list.
     */
    u32 fe_sibling;

    /**
     * A vector of delegates.
     */
    fib_entry_delegate_t *fe_delegates;
} fib_entry_t;

#define FOR_EACH_FIB_ENTRY_FLAG(_item) \
    for (_item = FIB_ENTRY_FLAG_FIRST; _item < FIB_ENTRY_FLAG_MAX; _item++)

#define FIB_ENTRY_FORMAT_BRIEF   (0x0)
#define FIB_ENTRY_FORMAT_DETAIL  (0x1)
#define FIB_ENTRY_FORMAT_DETAIL2 (0x2)

extern u8 *format_fib_entry (u8 * s, va_list * args);
extern u8 *format_fib_source (u8 * s, va_list * args);

extern fib_node_index_t fib_entry_create_special(u32 fib_index,
						 const fib_prefix_t *prefix,
						 fib_source_t source,
						 fib_entry_flag_t flags,
						 const dpo_id_t *dpo);

extern fib_node_index_t fib_entry_create (u32 fib_index,
					  const fib_prefix_t *prefix,
					  fib_source_t source,
					  fib_entry_flag_t flags,
					  const fib_route_path_t *paths);
extern void fib_entry_update (fib_node_index_t fib_entry_index,
			      fib_source_t source,
			      fib_entry_flag_t flags,
			      const fib_route_path_t *paths);

extern void fib_entry_path_add(fib_node_index_t fib_entry_index,
			       fib_source_t source,
			       fib_entry_flag_t flags,
			       const fib_route_path_t *rpath);
extern void fib_entry_special_add(fib_node_index_t fib_entry_index,
				  fib_source_t source,
				  fib_entry_flag_t flags,
				  const dpo_id_t *dpo);
extern void fib_entry_special_update(fib_node_index_t fib_entry_index,
				     fib_source_t source,
				     fib_entry_flag_t flags,
				     const dpo_id_t *dpo);
extern fib_entry_src_flag_t fib_entry_special_remove(fib_node_index_t fib_entry_index,
						     fib_source_t source);

extern fib_entry_src_flag_t fib_entry_path_remove(fib_node_index_t fib_entry_index,
						  fib_source_t source,
						  const fib_route_path_t *rpath);
extern fib_entry_src_flag_t fib_entry_delete(fib_node_index_t fib_entry_index,
					     fib_source_t source);

extern void fib_entry_contribute_urpf(fib_node_index_t path_index,
				      index_t urpf);
extern void fib_entry_contribute_forwarding(
    fib_node_index_t fib_entry_index,
    fib_forward_chain_type_t type,
    dpo_id_t *dpo);
extern const dpo_id_t * fib_entry_contribute_ip_forwarding(
    fib_node_index_t fib_entry_index);
extern adj_index_t fib_entry_get_adj_for_source(
    fib_node_index_t fib_entry_index,
    fib_source_t source);
extern const int fib_entry_get_dpo_for_source (
    fib_node_index_t fib_entry_index,
    fib_source_t source,
    dpo_id_t *dpo);

extern adj_index_t fib_entry_get_adj(fib_node_index_t fib_entry_index);

extern int fib_entry_cmp_for_sort(void *i1, void *i2);

extern void fib_entry_cover_changed(fib_node_index_t fib_entry);
extern void fib_entry_cover_updated(fib_node_index_t fib_entry);
extern int fib_entry_recursive_loop_detect(fib_node_index_t entry_index,
					   fib_node_index_t **entry_indicies);

extern void fib_entry_lock(fib_node_index_t fib_entry_index);
extern void fib_entry_unlock(fib_node_index_t fib_entry_index);

extern u32 fib_entry_child_add(fib_node_index_t fib_entry_index,
			       fib_node_type_t type,
			       fib_node_index_t child_index);
extern void fib_entry_child_remove(fib_node_index_t fib_entry_index,
				   u32 sibling_index);
extern u32 fib_entry_get_resolving_interface(fib_node_index_t fib_entry_index);
extern u32 fib_entry_get_resolving_interface_for_source(
    fib_node_index_t fib_entry_index,
    fib_source_t source);

extern void fib_entry_encode(fib_node_index_t fib_entry_index,
			     fib_route_path_encode_t **api_rpaths);
extern void fib_entry_get_prefix(fib_node_index_t fib_entry_index,
				 fib_prefix_t *pfx);
extern u32 fib_entry_get_fib_index(fib_node_index_t fib_entry_index);
extern void fib_entry_set_source_data(fib_node_index_t fib_entry_index,
                                      fib_source_t source,
                                      const void *data);
extern const void* fib_entry_get_source_data(fib_node_index_t fib_entry_index,
                                             fib_source_t source);

extern fib_entry_flag_t fib_entry_get_flags(fib_node_index_t fib_entry_index);
extern fib_entry_flag_t fib_entry_get_flags_for_source(
    fib_node_index_t fib_entry_index,
    fib_source_t source);
extern fib_source_t fib_entry_get_best_source(fib_node_index_t fib_entry_index);
extern int fib_entry_is_sourced(fib_node_index_t fib_entry_index,
                                fib_source_t source);

extern fib_node_index_t fib_entry_get_path_list(fib_node_index_t fib_entry_index);
extern int fib_entry_is_resolved(fib_node_index_t fib_entry_index);
extern void fib_entry_set_flow_hash_config(fib_node_index_t fib_entry_index,
                                           flow_hash_config_t hash_config);

extern void fib_entry_module_init(void);

/*
 * unsafe... beware the raw pointer.
 */
extern fib_node_index_t fib_entry_get_index(const fib_entry_t * fib_entry);
extern fib_entry_t * fib_entry_get(fib_node_index_t fib_entry_index);

/*
 * for testing purposes.
 */
extern u32 fib_entry_pool_size(void);

#endif