blob: 57dec6d90b41d18bc384fb5b366ab5392a2a9a0e [file] [log] [blame]
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001/*
2 * Copyright (c) 2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/**
17 * Given a route of the form;
18 * q.r.s.t/Y
19 * via <interface> <next-hop>
20 *
21 * The prefix is: q.r.s.t./Y
22 * the path is: 'via <interface> <next-hop>
23 *
24 * The path is the description of where to send the traffic, and the
25 * the prefix is a description of which traffic to send.
26 * It is the aim of the FIB to resolve the path, i.e. to find the corresponding
27 * adjacency to match the path's description.
28 */
29
30#ifndef __FIB_PATH_H__
31#define __FIB_PATH_H__
32
33#include <vnet/ip/ip.h>
34#include <vnet/dpo/load_balance.h>
35
36#include <vnet/fib/fib_types.h>
37#include <vnet/adj/adj_types.h>
Neale Rannsd792d9c2017-10-21 10:53:20 -070038#include <vnet/bier/bier_types.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010039
40/**
41 * Enurmeration of path configuration attributes
42 */
43typedef enum fib_path_cfg_attribute_t_ {
44 /**
45 * Marker. Add new types after this one.
46 */
47 FIB_PATH_CFG_ATTRIBUTE_FIRST = 0,
48 /**
49 * The path is forced to a drop, whatever the next-hop info says.
50 * something somewhere knows better...
51 */
52 FIB_PATH_CFG_ATTRIBUTE_DROP = FIB_PATH_CFG_ATTRIBUTE_FIRST,
53 /**
54 * The path uses an adj that is exclusive. I.e. it is known only by
55 * the source of the route.
56 */
57 FIB_PATH_CFG_ATTRIBUTE_EXCLUSIVE,
58 /**
59 * Recursion constraint via host
60 */
61 FIB_PATH_CFG_ATTRIBUTE_RESOLVE_HOST,
62 /**
63 * Recursion constraint via attached
64 */
65 FIB_PATH_CFG_ATTRIBUTE_RESOLVE_ATTACHED,
66 /**
Neale Ranns4b919a52017-03-11 05:55:21 -080067 * The path is attached
68 */
69 FIB_PATH_CFG_ATTRIBUTE_ATTACHED,
70 /**
Neale Ranns0bfe5d82016-08-25 15:29:12 +010071 * The path is a for-us path
72 */
Neale Ranns0f26c5a2017-03-01 15:12:11 -080073 FIB_PATH_CFG_ATTRIBUTE_INTF_RX,
74 /**
75 * The path is a deag with rpf-id
76 */
77 FIB_PATH_CFG_ATTRIBUTE_RPF_ID,
78 /**
79 * The path is an interface recieve
80 */
Neale Ranns0bfe5d82016-08-25 15:29:12 +010081 FIB_PATH_CFG_ATTRIBUTE_LOCAL,
82 /**
Neale Ranns054c03a2017-10-13 05:15:07 -070083 * The deag path does a source lookup
Neale Rannsda78f952017-05-24 09:15:43 -070084 */
Neale Ranns054c03a2017-10-13 05:15:07 -070085 FIB_PATH_CFG_ATTRIBUTE_DEAG_SRC,
Neale Rannsda78f952017-05-24 09:15:43 -070086 /**
Neale Ranns0bfe5d82016-08-25 15:29:12 +010087 * Marker. Add new types before this one, then update it.
88 */
Neale Ranns054c03a2017-10-13 05:15:07 -070089 FIB_PATH_CFG_ATTRIBUTE_LAST = FIB_PATH_CFG_ATTRIBUTE_DEAG_SRC,
Neale Ranns0bfe5d82016-08-25 15:29:12 +010090} __attribute__ ((packed)) fib_path_cfg_attribute_t;
91
92/**
93 * The maximum number of path attributes
94 */
95#define FIB_PATH_CFG_ATTRIBUTE_MAX (FIB_PATH_CFG_ATTRIBUTE_LAST + 1)
96
97#define FIB_PATH_CFG_ATTRIBUTES { \
98 [FIB_PATH_CFG_ATTRIBUTE_DROP] = "drop", \
99 [FIB_PATH_CFG_ATTRIBUTE_EXCLUSIVE] = "exclusive", \
100 [FIB_PATH_CFG_ATTRIBUTE_RESOLVE_HOST] = "resolve-host", \
101 [FIB_PATH_CFG_ATTRIBUTE_RESOLVE_ATTACHED] = "resolve-attached", \
102 [FIB_PATH_CFG_ATTRIBUTE_LOCAL] = "local", \
Neale Ranns4b919a52017-03-11 05:55:21 -0800103 [FIB_PATH_CFG_ATTRIBUTE_ATTACHED] = "attached", \
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800104 [FIB_PATH_CFG_ATTRIBUTE_INTF_RX] = "interface-rx", \
105 [FIB_PATH_CFG_ATTRIBUTE_RPF_ID] = "rpf-id", \
Neale Ranns054c03a2017-10-13 05:15:07 -0700106 [FIB_PATH_CFG_ATTRIBUTE_DEAG_SRC] = "deag-src", \
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100107}
108
109#define FOR_EACH_FIB_PATH_CFG_ATTRIBUTE(_item) \
110 for (_item = FIB_PATH_CFG_ATTRIBUTE_FIRST; \
111 _item <= FIB_PATH_CFG_ATTRIBUTE_LAST; \
112 _item++)
113
114/**
115 * Path config flags from the attributes
116 */
117typedef enum fib_path_cfg_flags_t_ {
118 FIB_PATH_CFG_FLAG_NONE = 0,
119 FIB_PATH_CFG_FLAG_DROP = (1 << FIB_PATH_CFG_ATTRIBUTE_DROP),
120 FIB_PATH_CFG_FLAG_EXCLUSIVE = (1 << FIB_PATH_CFG_ATTRIBUTE_EXCLUSIVE),
121 FIB_PATH_CFG_FLAG_RESOLVE_HOST = (1 << FIB_PATH_CFG_ATTRIBUTE_RESOLVE_HOST),
122 FIB_PATH_CFG_FLAG_RESOLVE_ATTACHED = (1 << FIB_PATH_CFG_ATTRIBUTE_RESOLVE_ATTACHED),
123 FIB_PATH_CFG_FLAG_LOCAL = (1 << FIB_PATH_CFG_ATTRIBUTE_LOCAL),
Neale Ranns4b919a52017-03-11 05:55:21 -0800124 FIB_PATH_CFG_FLAG_ATTACHED = (1 << FIB_PATH_CFG_ATTRIBUTE_ATTACHED),
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800125 FIB_PATH_CFG_FLAG_INTF_RX = (1 << FIB_PATH_CFG_ATTRIBUTE_INTF_RX),
126 FIB_PATH_CFG_FLAG_RPF_ID = (1 << FIB_PATH_CFG_ATTRIBUTE_RPF_ID),
Neale Ranns054c03a2017-10-13 05:15:07 -0700127 FIB_PATH_CFG_FLAG_DEAG_SRC = (1 << FIB_PATH_CFG_ATTRIBUTE_DEAG_SRC),
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100128} __attribute__ ((packed)) fib_path_cfg_flags_t;
129
Neale Ranns710071b2018-09-24 12:36:26 +0000130typedef enum fib_path_format_flags_t_
131{
132 FIB_PATH_FORMAT_FLAGS_NONE = 0,
133 FIB_PATH_FORMAT_FLAGS_ONE_LINE = (1 << 0),
134} fib_format_path_flags_t;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100135
Neale Ranns91286372017-12-05 13:24:04 -0800136extern u8 *format_fib_path(u8 *s, va_list *args);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100137
138extern fib_node_index_t fib_path_create(fib_node_index_t pl_index,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100139 const fib_route_path_t *path);
140extern fib_node_index_t fib_path_create_special(fib_node_index_t pl_index,
Neale Rannsda78f952017-05-24 09:15:43 -0700141 dpo_proto_t nh_proto,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100142 fib_path_cfg_flags_t flags,
143 const dpo_id_t *dpo);
144
145extern int fib_path_cmp(fib_node_index_t path_index1,
146 fib_node_index_t path_index2);
147extern int fib_path_cmp_for_sort(void * a1, void * a2);
148extern int fib_path_cmp_w_route_path(fib_node_index_t path_index,
149 const fib_route_path_t *rpath);
150extern fib_node_index_t fib_path_copy(fib_node_index_t path_index,
151 fib_node_index_t path_list_index);
152extern int fib_path_resolve(fib_node_index_t path_index);
153extern int fib_path_is_resolved(fib_node_index_t path_index);
Neale Rannsf12a83f2017-04-18 09:09:40 -0700154extern int fib_path_is_recursive_constrained(fib_node_index_t path_index);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100155extern int fib_path_is_exclusive(fib_node_index_t path_index);
156extern int fib_path_is_deag(fib_node_index_t path_index);
157extern int fib_path_is_looped(fib_node_index_t path_index);
Neale Rannsda78f952017-05-24 09:15:43 -0700158extern dpo_proto_t fib_path_get_proto(fib_node_index_t path_index);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100159extern void fib_path_destroy(fib_node_index_t path_index);
160extern uword fib_path_hash(fib_node_index_t path_index);
161extern load_balance_path_t * fib_path_append_nh_for_multipath_hash(
162 fib_node_index_t path_index,
163 fib_forward_chain_type_t fct,
164 load_balance_path_t *hash_key);
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800165extern void fib_path_stack_mpls_disp(fib_node_index_t path_index,
166 dpo_proto_t payload_proto,
Neale Ranns31ed7442018-02-23 05:29:09 -0800167 fib_mpls_lsp_mode_t mode,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800168 dpo_id_t *dpo);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100169extern void fib_path_contribute_forwarding(fib_node_index_t path_index,
170 fib_forward_chain_type_t type,
171 dpo_id_t *dpo);
Neale Ranns3ee44042016-10-03 13:05:48 +0100172extern void fib_path_contribute_urpf(fib_node_index_t path_index,
173 index_t urpf);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100174extern adj_index_t fib_path_get_adj(fib_node_index_t path_index);
175extern int fib_path_recursive_loop_detect(fib_node_index_t path_index,
176 fib_node_index_t **entry_indicies);
177extern u32 fib_path_get_resolving_interface(fib_node_index_t fib_entry_index);
Neale Rannsd792d9c2017-10-21 10:53:20 -0700178extern index_t fib_path_get_resolving_index(fib_node_index_t path_index);
Neale Ranns57b58602017-07-15 07:37:25 -0700179extern u16 fib_path_get_weight(fib_node_index_t path_index);
180extern u16 fib_path_get_preference(fib_node_index_t path_index);
Neale Rannsd792d9c2017-10-21 10:53:20 -0700181extern u32 fib_path_get_rpf_id(fib_node_index_t path_index);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100182
183extern void fib_path_module_init(void);
Neale Ranns81424992017-05-18 03:03:22 -0700184extern fib_path_list_walk_rc_t fib_path_encode(fib_node_index_t path_list_index,
185 fib_node_index_t path_index,
Neale Ranns775f73c2018-12-20 03:01:49 -0800186 const struct fib_path_ext_t_ *ext_list,
Neale Ranns81424992017-05-18 03:03:22 -0700187 void *ctx);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100188
189#endif