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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <vnet/fib/fib_entry.h>
17 #include <vnet/fib/fib_entry_src.h>
18 #include <vnet/fib/fib_path_list.h>
19 #include <vnet/fib/fib_path_ext.h>
22 * Source initialisation Function
25 fib_entry_src_api_init (fib_entry_src_t *src)
30 * Source deinitialisation Function
33 fib_entry_src_api_deinit (fib_entry_src_t *src)
38 fib_entry_src_api_path_swap (fib_entry_src_t *src,
39 const fib_entry_t *entry,
40 fib_path_list_flags_t pl_flags,
41 const fib_route_path_t *rpaths)
43 const fib_route_path_t *rpath;
45 fib_path_ext_list_flush(&src->fes_path_exts);
47 src->fes_pl = fib_path_list_create((FIB_PATH_LIST_FLAG_SHARED | pl_flags),
50 vec_foreach(rpath, rpaths)
52 if (NULL != rpath->frp_label_stack)
54 fib_path_ext_list_push_back(&src->fes_path_exts,
63 fib_entry_src_api_path_add (fib_entry_src_t *src,
64 const fib_entry_t *entry,
65 fib_path_list_flags_t pl_flags,
66 const fib_route_path_t *rpaths)
68 const fib_route_path_t *rpath;
70 if (FIB_NODE_INDEX_INVALID == src->fes_pl)
73 fib_path_list_create((FIB_PATH_LIST_FLAG_SHARED | pl_flags), rpaths);
78 fib_path_list_copy_and_path_add(src->fes_pl,
79 (FIB_PATH_LIST_FLAG_SHARED | pl_flags),
84 * re-resolve all the path-extensions with the new path-list
86 fib_path_ext_list_resolve(&src->fes_path_exts, src->fes_pl);
89 * if the path has a label we need to add a path extension
91 vec_foreach(rpath, rpaths)
93 if (NULL != rpath->frp_label_stack)
95 fib_path_ext_list_insert(&src->fes_path_exts,
104 fib_entry_src_api_path_remove (fib_entry_src_t *src,
105 fib_path_list_flags_t pl_flags,
106 const fib_route_path_t *rpaths)
108 const fib_route_path_t *rpath;
110 if (FIB_NODE_INDEX_INVALID != src->fes_pl)
113 fib_path_list_copy_and_path_remove(src->fes_pl,
114 (FIB_PATH_LIST_FLAG_SHARED | pl_flags),
117 * remove the path-extension for the path
119 vec_foreach(rpath, rpaths)
121 fib_path_ext_list_remove(&src->fes_path_exts, FIB_PATH_EXT_MPLS, rpath);
124 * resolve the remaining extensions
126 fib_path_ext_list_resolve(&src->fes_path_exts, src->fes_pl);
131 fib_entry_src_api_add (fib_entry_src_t *src,
132 const fib_entry_t *entry,
133 fib_entry_flag_t flags,
137 if (FIB_ENTRY_FLAG_NONE != flags)
139 src->fes_pl = fib_path_list_create_special(
141 fib_entry_src_flags_2_path_list_flags(flags),
147 fib_entry_src_api_remove (fib_entry_src_t *src)
149 src->fes_pl = FIB_NODE_INDEX_INVALID;
152 const static fib_entry_src_vft_t api_src_vft = {
153 .fesv_init = fib_entry_src_api_init,
154 .fesv_deinit = fib_entry_src_api_deinit,
155 .fesv_add = fib_entry_src_api_add,
156 .fesv_remove = fib_entry_src_api_remove,
157 .fesv_path_add = fib_entry_src_api_path_add,
158 .fesv_path_swap = fib_entry_src_api_path_swap,
159 .fesv_path_remove = fib_entry_src_api_path_remove,
163 fib_entry_src_api_register (void)
165 fib_entry_src_register(FIB_SOURCE_PLUGIN_HI, &api_src_vft);
166 fib_entry_src_register(FIB_SOURCE_PLUGIN_LOW, &api_src_vft);
167 fib_entry_src_register(FIB_SOURCE_API, &api_src_vft);
168 fib_entry_src_register(FIB_SOURCE_CLI, &api_src_vft);
169 fib_entry_src_register(FIB_SOURCE_6RD, &api_src_vft);
170 fib_entry_src_register(FIB_SOURCE_DHCP, &api_src_vft);
171 fib_entry_src_register(FIB_SOURCE_IP6_ND_PROXY, &api_src_vft);
172 fib_entry_src_register(FIB_SOURCE_IP6_ND, &api_src_vft);
173 fib_entry_src_register(FIB_SOURCE_SR, &api_src_vft);