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_cover.h>
17 #include <vnet/fib/fib_entry_src.h>
18 #include <vnet/fib/fib_node_list.h>
19 #include <vnet/fib/fib_entry_delegate.h>
22 fib_entry_cover_track (fib_entry_t* cover,
23 fib_node_index_t covered)
25 fib_entry_delegate_t *fed;
27 FIB_ENTRY_DBG(cover, "cover-track %d", covered);
29 ASSERT(fib_entry_get_index(cover) != covered);
31 fed = fib_entry_delegate_find(cover, FIB_ENTRY_DELEGATE_COVERED);
35 fed = fib_entry_delegate_find_or_add(cover, FIB_ENTRY_DELEGATE_COVERED);
36 fed->fd_list = fib_node_list_create();
39 return (fib_node_list_push_front(fed->fd_list,
40 0, FIB_NODE_TYPE_ENTRY,
45 fib_entry_cover_untrack (fib_entry_t* cover,
48 fib_entry_delegate_t *fed;
50 FIB_ENTRY_DBG(cover, "cover-untrack @ %d", tracked_index);
52 fed = fib_entry_delegate_find(cover, FIB_ENTRY_DELEGATE_COVERED);
57 fib_node_list_remove(fed->fd_list, tracked_index);
59 if (0 == fib_node_list_get_size(fed->fd_list))
61 fib_node_list_destroy(&fed->fd_list);
62 fib_entry_delegate_remove(cover, FIB_ENTRY_DELEGATE_COVERED);
67 * Internal struct to hold user supplied parameters for the cover walk
69 typedef struct fib_enty_cover_walk_ctx_t_ {
71 fib_entry_covered_walk_t walk;
73 } fib_enty_cover_walk_ctx_t;
76 fib_entry_cover_walk_node_ptr (fib_node_ptr_t *depend,
79 fib_enty_cover_walk_ctx_t *ctx = args;
81 ctx->walk(ctx->cover, depend->fnp_index, ctx->ctx);
83 return (WALK_CONTINUE);
87 fib_entry_cover_walk (fib_entry_t *cover,
88 fib_entry_covered_walk_t walk,
91 fib_entry_delegate_t *fed;
93 fed = fib_entry_delegate_find(cover, FIB_ENTRY_DELEGATE_COVERED);
98 fib_enty_cover_walk_ctx_t ctx = {
104 fib_node_list_walk(fed->fd_list,
105 fib_entry_cover_walk_node_ptr,
110 fib_entry_cover_change_one (fib_entry_t *cover,
111 fib_node_index_t covered,
114 fib_node_index_t new_cover;
117 * The 3 entries involved here are:
118 * cover - the least specific. It will cover both the others
119 * new_cover - the enty just inserted below the cover
120 * covered - the entry that was tracking the cover.
122 * The checks below are to determine if new_cover is a cover for covered.
124 new_cover = pointer_to_uword(args);
126 if (FIB_NODE_INDEX_INVALID == new_cover)
129 * nothing has been inserted, which implies the cover was removed.
130 * 'cover' is thus the new cover.
132 fib_entry_cover_changed(covered);
134 else if (new_cover != covered)
136 const fib_prefix_t *pfx_covered, *pfx_new_cover;
138 pfx_covered = fib_entry_get_prefix(covered);
139 pfx_new_cover = fib_entry_get_prefix(new_cover);
141 if (fib_prefix_is_cover(pfx_new_cover, pfx_covered))
143 fib_entry_cover_changed(covered);
146 return (WALK_CONTINUE);
150 fib_entry_cover_change_notify (fib_node_index_t cover_index,
151 fib_node_index_t covered)
155 cover = fib_entry_get(cover_index);
157 fib_entry_cover_walk(cover,
158 fib_entry_cover_change_one,
159 uword_to_pointer(covered, void*));
163 fib_entry_cover_update_one (fib_entry_t *cover,
164 fib_node_index_t covered,
167 fib_entry_cover_updated(covered);
169 return (WALK_CONTINUE);
173 fib_entry_cover_update_notify (fib_entry_t *fib_entry)
175 fib_entry_cover_walk(fib_entry,
176 fib_entry_cover_update_one,