FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
mfib_entry_cover.c
Go to the documentation of this file.
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 
18 #include <vnet/fib/fib_node_list.h>
19 
20 u32
22  fib_node_index_t covered)
23 {
25 
26  MFIB_ENTRY_DBG(cover, "cover-track %d", covered);
27 
28  ASSERT(mfib_entry_get_index(cover) != covered);
29 
31 
32  if (NULL == mfed)
33  {
36  }
37 
38  return (fib_node_list_push_front(mfed->mfd_list,
40  covered));
41 }
42 
43 void
45  u32 tracked_index)
46 {
48 
49  MFIB_ENTRY_DBG(cover, "cover-untrack @ %d", tracked_index);
50 
52 
53  if (NULL == mfed)
54  return;
55 
56  fib_node_list_remove(mfed->mfd_list, tracked_index);
57 
58  if (0 == fib_node_list_get_size(mfed->mfd_list))
59  {
62  }
63 }
64 
65 /**
66  * Internal struct to hold user supplied paraneters for the cover walk
67  */
71  void *ctx;
73 
74 static walk_rc_t
76  void *args)
77 {
79 
80  ctx->walk(ctx->cover, depend->fnp_index, ctx->ctx);
81 
82  return (WALK_CONTINUE);
83 }
84 
85 void
88  void *args)
89 {
91 
93 
94  if (NULL == mfed)
95  return;
96 
98  .cover = cover,
99  .walk = walk,
100  .ctx = args,
101  };
102 
105  &ctx);
106 }
107 
108 static int
110  fib_node_index_t covered,
111  void *args)
112 {
113  fib_node_index_t new_cover;
114 
115  /*
116  * The 3 entries involved here are:
117  * cover - the least specific. It will cover both the others
118  * new_cover - the enty just inserted below the cover
119  * covered - the entry that was tracking the cover.
120  *
121  * The checks below are to determine if new_cover is a cover for covered.
122  */
123  new_cover = pointer_to_uword(args);
124 
125  if (FIB_NODE_INDEX_INVALID == new_cover)
126  {
127  /*
128  * nothing has been inserted, which implies the cover was removed.
129  * 'cover' is thus the new cover.
130  */
131  mfib_entry_cover_changed(covered);
132  }
133  else if (new_cover != covered)
134  {
135  const mfib_prefix_t *pfx_covered, *pfx_new_cover;
136 
137  pfx_covered = mfib_entry_get_prefix(covered);
138  pfx_new_cover = mfib_entry_get_prefix(new_cover);
139 
140  if (mfib_prefix_is_cover(pfx_new_cover, pfx_covered))
141  {
142  mfib_entry_cover_changed(covered);
143  }
144  }
145  /* continue */
146  return (1);
147 }
148 
149 void
151  fib_node_index_t covered)
152 {
153  mfib_entry_t *cover;
154 
155  cover = mfib_entry_get(cover_index);
156 
157  mfib_entry_cover_walk(cover,
159  uword_to_pointer(covered, void*));
160 }
161 
162 static int
164  fib_node_index_t covered,
165  void *args)
166 {
167  mfib_entry_cover_updated(covered);
168 
169  /* continue */
170  return (1);
171 }
172 
173 void
175 {
176  mfib_entry_cover_walk(mfib_entry,
178  NULL);
179 }
WALK_CONTINUE
@ WALK_CONTINUE
Definition: interface_funcs.h:174
mfib_enty_cover_walk_ctx_t_::cover
mfib_entry_t * cover
Definition: mfib_entry_cover.c:69
mfib_entry_cover_update_one
static int mfib_entry_cover_update_one(mfib_entry_t *cover, fib_node_index_t covered, void *args)
Definition: mfib_entry_cover.c:163
mfib_entry_cover_updated
void mfib_entry_cover_updated(fib_node_index_t mfib_entry_index)
Definition: mfib_entry.c:1595
mfib_entry_src.h
pointer_to_uword
static uword pointer_to_uword(const void *p)
Definition: types.h:131
mfib_entry_delegate_get
mfib_entry_delegate_t * mfib_entry_delegate_get(const mfib_entry_t *mfib_entry, mfib_entry_delegate_type_t type)
Definition: mfib_entry_delegate.c:47
mfib_prefix_t_
Aggregate type for a prefix.
Definition: mfib_types.h:24
mfib_enty_cover_walk_ctx_t_::ctx
void * ctx
Definition: mfib_entry_cover.c:71
mfib_entry_delegate_find_or_add
mfib_entry_delegate_t * mfib_entry_delegate_find_or_add(mfib_entry_t *mfib_entry, mfib_entry_delegate_type_t fdt)
Definition: mfib_entry_delegate.c:92
FIB_NODE_INDEX_INVALID
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:30
mfib_entry_get_index
static fib_node_index_t mfib_entry_get_index(const mfib_entry_t *mfe)
Definition: mfib_entry.h:205
mfib_entry_covered_walk_t
int(* mfib_entry_covered_walk_t)(mfib_entry_t *cover, fib_node_index_t covered, void *ctx)
callback function used when walking the covered entries
Definition: mfib_entry_cover.h:24
mfib_entry_cover_change_notify
void mfib_entry_cover_change_notify(fib_node_index_t cover_index, fib_node_index_t covered)
Definition: mfib_entry_cover.c:150
MFIB_ENTRY_DELEGATE_COVERED
@ MFIB_ENTRY_DELEGATE_COVERED
Dependency list of covered entries.
Definition: mfib_entry_delegate.h:30
mfib_entry_get
static mfib_entry_t * mfib_entry_get(fib_node_index_t index)
Definition: mfib_entry.h:200
MFIB_ENTRY_DBG
#define MFIB_ENTRY_DBG(_e, _fmt, _args...)
Definition: mfib_entry.h:100
mfib_entry_cover_untrack
void mfib_entry_cover_untrack(mfib_entry_t *cover, u32 tracked_index)
Definition: mfib_entry_cover.c:44
mfib_entry_cover_walk_node_ptr
static walk_rc_t mfib_entry_cover_walk_node_ptr(fib_node_ptr_t *depend, void *args)
Definition: mfib_entry_cover.c:75
mfib_entry_cover_change_one
static int mfib_entry_cover_change_one(mfib_entry_t *cover, fib_node_index_t covered, void *args)
Definition: mfib_entry_cover.c:109
fib_node_index_t
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
mfib_entry_cover_track
u32 mfib_entry_cover_track(mfib_entry_t *cover, fib_node_index_t covered)
Definition: mfib_entry_cover.c:21
mfib_prefix_is_cover
int mfib_prefix_is_cover(const mfib_prefix_t *p1, const mfib_prefix_t *p2)
Compare two prefixes for covering relationship.
Definition: mfib_types.c:30
mfib_entry_cover_walk
void mfib_entry_cover_walk(mfib_entry_t *cover, mfib_entry_covered_walk_t walk, void *args)
Definition: mfib_entry_cover.c:86
fib_node_ptr_t_
A representation of one pointer to another node.
Definition: fib_node.h:195
FIB_NODE_TYPE_MFIB_ENTRY
@ FIB_NODE_TYPE_MFIB_ENTRY
Definition: fib_node.h:34
mfib_entry_delegate_remove
void mfib_entry_delegate_remove(mfib_entry_t *mfib_entry, mfib_entry_delegate_type_t type)
Definition: mfib_entry_delegate.c:54
fib_node_ptr_t_::fnp_index
fib_node_index_t fnp_index
node's index
Definition: fib_node.h:203
mfib_enty_cover_walk_ctx_t
struct mfib_enty_cover_walk_ctx_t_ mfib_enty_cover_walk_ctx_t
Internal struct to hold user supplied paraneters for the cover walk.
mfib_entry_cover_changed
void mfib_entry_cover_changed(fib_node_index_t mfib_entry_index)
Definition: mfib_entry.c:1570
mfib_entry_delegate_t_::mfd_list
fib_node_list_t mfd_list
For the cover tracking.
Definition: mfib_entry_delegate.h:74
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
u32
unsigned int u32
Definition: types.h:88
fib_node_list_remove
void fib_node_list_remove(fib_node_list_t list, u32 sibling)
Definition: fib_node_list.c:234
mfib_enty_cover_walk_ctx_t_::walk
mfib_entry_covered_walk_t walk
Definition: mfib_entry_cover.c:70
fib_node_list_get_size
u32 fib_node_list_get_size(fib_node_list_t list)
Definition: fib_node_list.c:313
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
mfib_entry_cover_update_notify
void mfib_entry_cover_update_notify(mfib_entry_t *mfib_entry)
Definition: mfib_entry_cover.c:174
fib_node_list_walk
void fib_node_list_walk(fib_node_list_t list, fib_node_list_walk_cb_t fn, void *args)
Walk the list of node.
Definition: fib_node_list.c:354
mfib_entry_t_
An entry in a FIB table.
Definition: mfib_entry.h:32
mfib_enty_cover_walk_ctx_t_
Internal struct to hold user supplied paraneters for the cover walk.
Definition: mfib_entry_cover.c:68
mfib_entry_get_prefix
const mfib_prefix_t * mfib_entry_get_prefix(fib_node_index_t mfib_entry_index)
Definition: mfib_entry.c:1489
fib_node_list_push_front
u32 fib_node_list_push_front(fib_node_list_t list, int owner_id, fib_node_type_t type, fib_node_index_t index)
Insert an element at the from of the list.
Definition: fib_node_list.c:156
fib_node_list_create
fib_node_list_t fib_node_list_create(void)
Create a new node list.
Definition: fib_node_list.c:125
uword_to_pointer
#define uword_to_pointer(u, type)
Definition: types.h:136
fib_node_list_destroy
void fib_node_list_destroy(fib_node_list_t *list)
Definition: fib_node_list.c:137
fib_node_list.h
mfib_entry_cover.h
mfib_entry_delegate_t_
A Delagate is a means to implmenet the Delagation design pattern; the extension of an objects functio...
Definition: mfib_entry_delegate.h:52
walk_rc_t
enum walk_rc_t_ walk_rc_t
Walk return code.