Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 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> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 20 | |
| 21 | /** |
| 22 | * Source initialisation Function |
| 23 | */ |
| 24 | static void |
| 25 | fib_entry_src_api_init (fib_entry_src_t *src) |
| 26 | { |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Source deinitialisation Function |
| 31 | */ |
| 32 | static void |
| 33 | fib_entry_src_api_deinit (fib_entry_src_t *src) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | static void |
| 38 | fib_entry_src_api_path_swap (fib_entry_src_t *src, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 39 | const fib_entry_t *entry, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 40 | fib_path_list_flags_t pl_flags, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 41 | const fib_route_path_t *rpaths) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 42 | { |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 43 | const fib_route_path_t *rpath; |
| 44 | |
| 45 | fib_path_ext_list_flush(&src->fes_path_exts); |
| 46 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 47 | src->fes_pl = fib_path_list_create((FIB_PATH_LIST_FLAG_SHARED | pl_flags), |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 48 | rpaths); |
| 49 | |
| 50 | vec_foreach(rpath, rpaths) |
| 51 | { |
| 52 | if (NULL != rpath->frp_label_stack) |
| 53 | { |
| 54 | fib_path_ext_list_push_back(&src->fes_path_exts, |
| 55 | src->fes_pl, |
| 56 | FIB_PATH_EXT_MPLS, |
| 57 | rpath); |
| 58 | } |
| 59 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | static void |
| 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, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 66 | const fib_route_path_t *rpaths) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 67 | { |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 68 | const fib_route_path_t *rpath; |
| 69 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 70 | if (FIB_NODE_INDEX_INVALID == src->fes_pl) |
| 71 | { |
| 72 | src->fes_pl = |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 73 | fib_path_list_create((FIB_PATH_LIST_FLAG_SHARED | pl_flags), rpaths); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 74 | } |
| 75 | else |
| 76 | { |
| 77 | src->fes_pl = |
| 78 | fib_path_list_copy_and_path_add(src->fes_pl, |
| 79 | (FIB_PATH_LIST_FLAG_SHARED | pl_flags), |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 80 | rpaths); |
| 81 | } |
| 82 | |
| 83 | /* |
| 84 | * re-resolve all the path-extensions with the new path-list |
| 85 | */ |
| 86 | fib_path_ext_list_resolve(&src->fes_path_exts, src->fes_pl); |
| 87 | |
| 88 | /* |
| 89 | * if the path has a label we need to add a path extension |
| 90 | */ |
| 91 | vec_foreach(rpath, rpaths) |
| 92 | { |
| 93 | if (NULL != rpath->frp_label_stack) |
| 94 | { |
| 95 | fib_path_ext_list_insert(&src->fes_path_exts, |
| 96 | src->fes_pl, |
| 97 | FIB_PATH_EXT_MPLS, |
| 98 | rpath); |
| 99 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | |
| 103 | static void |
| 104 | fib_entry_src_api_path_remove (fib_entry_src_t *src, |
| 105 | fib_path_list_flags_t pl_flags, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 106 | const fib_route_path_t *rpaths) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 107 | { |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 108 | const fib_route_path_t *rpath; |
| 109 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 110 | if (FIB_NODE_INDEX_INVALID != src->fes_pl) |
| 111 | { |
| 112 | src->fes_pl = |
| 113 | fib_path_list_copy_and_path_remove(src->fes_pl, |
| 114 | (FIB_PATH_LIST_FLAG_SHARED | pl_flags), |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 115 | rpaths); |
| 116 | /* |
| 117 | * remove the path-extension for the path |
| 118 | */ |
| 119 | vec_foreach(rpath, rpaths) |
| 120 | { |
| 121 | fib_path_ext_list_remove(&src->fes_path_exts, FIB_PATH_EXT_MPLS, rpath); |
| 122 | }; |
| 123 | /* |
| 124 | * resolve the remaining extensions |
| 125 | */ |
| 126 | fib_path_ext_list_resolve(&src->fes_path_exts, src->fes_pl); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
| 130 | static void |
| 131 | fib_entry_src_api_add (fib_entry_src_t *src, |
| 132 | const fib_entry_t *entry, |
| 133 | fib_entry_flag_t flags, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 134 | dpo_proto_t proto, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 135 | const dpo_id_t *dpo) |
| 136 | { |
| 137 | if (FIB_ENTRY_FLAG_NONE != flags) |
| 138 | { |
| 139 | src->fes_pl = fib_path_list_create_special( |
| 140 | proto, |
| 141 | fib_entry_src_flags_2_path_list_flags(flags), |
| 142 | dpo); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | static void |
| 147 | fib_entry_src_api_remove (fib_entry_src_t *src) |
| 148 | { |
| 149 | src->fes_pl = FIB_NODE_INDEX_INVALID; |
| 150 | } |
| 151 | |
| 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, |
| 160 | }; |
| 161 | |
| 162 | void |
| 163 | fib_entry_src_api_register (void) |
| 164 | { |
| 165 | fib_entry_src_register(FIB_SOURCE_PLUGIN_HI, &api_src_vft); |
| 166 | fib_entry_src_register(FIB_SOURCE_API, &api_src_vft); |
| 167 | fib_entry_src_register(FIB_SOURCE_CLI, &api_src_vft); |
| 168 | fib_entry_src_register(FIB_SOURCE_DHCP, &api_src_vft); |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 169 | fib_entry_src_register(FIB_SOURCE_IP6_ND_PROXY, &api_src_vft); |
shwethab | b18e0de | 2017-03-29 11:36:37 +0000 | [diff] [blame] | 170 | fib_entry_src_register(FIB_SOURCE_SR, &api_src_vft); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 171 | } |