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/mfib/mfib_entry_cover.h>
17 #include <vnet/mfib/mfib_entry_src.h>
18 #include <vnet/fib/fib_node_list.h>
21 mfib_entry_cover_track (mfib_entry_t* cover,
22 fib_node_index_t covered)
24 mfib_entry_delegate_t *mfed;
26 MFIB_ENTRY_DBG(cover, "cover-track %d", covered);
28 ASSERT(mfib_entry_get_index(cover) != covered);
30 mfed = mfib_entry_delegate_get(cover, MFIB_ENTRY_DELEGATE_COVERED);
34 mfed = mfib_entry_delegate_find_or_add(cover, MFIB_ENTRY_DELEGATE_COVERED);
35 mfed->mfd_list = fib_node_list_create();
38 return (fib_node_list_push_front(mfed->mfd_list,
39 0, FIB_NODE_TYPE_MFIB_ENTRY,
44 mfib_entry_cover_untrack (mfib_entry_t* cover,
47 mfib_entry_delegate_t *mfed;
49 MFIB_ENTRY_DBG(cover, "cover-untrack @ %d", tracked_index);
51 mfed = mfib_entry_delegate_get(cover, MFIB_ENTRY_DELEGATE_COVERED);
56 fib_node_list_remove(mfed->mfd_list, tracked_index);
58 if (0 == fib_node_list_get_size(mfed->mfd_list))
60 fib_node_list_destroy(&mfed->mfd_list);
61 mfib_entry_delegate_remove(cover, MFIB_ENTRY_DELEGATE_COVERED);
66 * Internal struct to hold user supplied paraneters for the cover walk
68 typedef struct mfib_enty_cover_walk_ctx_t_ {
70 mfib_entry_covered_walk_t walk;
72 } mfib_enty_cover_walk_ctx_t;
75 mfib_entry_cover_walk_node_ptr (fib_node_ptr_t *depend,
78 mfib_enty_cover_walk_ctx_t *ctx = args;
80 ctx->walk(ctx->cover, depend->fnp_index, ctx->ctx);
87 mfib_entry_cover_walk (mfib_entry_t *cover,
88 mfib_entry_covered_walk_t walk,
91 mfib_entry_delegate_t *mfed;
93 mfed = mfib_entry_delegate_get(cover, MFIB_ENTRY_DELEGATE_COVERED);
98 mfib_enty_cover_walk_ctx_t ctx = {
104 fib_node_list_walk(mfed->mfd_list,
105 mfib_entry_cover_walk_node_ptr,
110 mfib_entry_cover_change_one (mfib_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 mfib_entry_cover_changed(covered);
134 else if (new_cover != covered)
136 const mfib_prefix_t *pfx_covered, *pfx_new_cover;
138 pfx_covered = mfib_entry_get_prefix(covered);
139 pfx_new_cover = mfib_entry_get_prefix(new_cover);
141 if (mfib_prefix_is_cover(pfx_new_cover, pfx_covered))
143 mfib_entry_cover_changed(covered);
151 mfib_entry_cover_change_notify (fib_node_index_t cover_index,
152 fib_node_index_t covered)
156 cover = mfib_entry_get(cover_index);
158 mfib_entry_cover_walk(cover,
159 mfib_entry_cover_change_one,
160 uword_to_pointer(covered, void*));
164 mfib_entry_cover_update_one (mfib_entry_t *cover,
165 fib_node_index_t covered,
168 mfib_entry_cover_updated(covered);
175 mfib_entry_cover_update_notify (mfib_entry_t *mfib_entry)
177 mfib_entry_cover_walk(mfib_entry,
178 mfib_entry_cover_update_one,