FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
fib_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 
17 #include <vnet/fib/fib_entry_src.h>
18 #include <vnet/fib/fib_node_list.h>
20 
21 u32
23  fib_node_index_t covered)
24 {
26 
27  FIB_ENTRY_DBG(cover, "cover-track %d", covered);
28 
29  ASSERT(fib_entry_get_index(cover) != covered);
30 
32 
33  if (NULL == fed)
34  {
37  }
38 
39  return (fib_node_list_push_front(fed->fd_list,
41  covered));
42 }
43 
44 void
46  u32 tracked_index)
47 {
49 
50  FIB_ENTRY_DBG(cover, "cover-untrack @ %d", tracked_index);
51 
53 
54  if (NULL == fed)
55  return;
56 
57  fib_node_list_remove(fed->fd_list, tracked_index);
58 
59  if (0 == fib_node_list_get_size(fed->fd_list))
60  {
63  }
64 }
65 
66 /**
67  * Internal struct to hold user supplied parameters for the cover walk
68  */
72  void *ctx;
74 
75 static walk_rc_t
77  void *args)
78 {
80 
81  ctx->walk(ctx->cover, depend->fnp_index, ctx->ctx);
82 
83  return (WALK_CONTINUE);
84 }
85 
86 void
89  void *args)
90 {
92 
94 
95  if (NULL == fed)
96  return;
97 
99  .cover = cover,
100  .walk = walk,
101  .ctx = args,
102  };
103 
106  &ctx);
107 }
108 
109 static walk_rc_t
111  fib_node_index_t covered,
112  void *args)
113 {
114  fib_node_index_t new_cover;
115 
116  /*
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.
121  *
122  * The checks below are to determine if new_cover is a cover for covered.
123  */
124  new_cover = pointer_to_uword(args);
125 
126  if (FIB_NODE_INDEX_INVALID == new_cover)
127  {
128  /*
129  * nothing has been inserted, which implies the cover was removed.
130  * 'cover' is thus the new cover.
131  */
132  fib_entry_cover_changed(covered);
133  }
134  else if (new_cover != covered)
135  {
136  const fib_prefix_t *pfx_covered, *pfx_new_cover;
137 
138  pfx_covered = fib_entry_get_prefix(covered);
139  pfx_new_cover = fib_entry_get_prefix(new_cover);
140 
141  if (fib_prefix_is_cover(pfx_new_cover, pfx_covered))
142  {
143  fib_entry_cover_changed(covered);
144  }
145  }
146  return (WALK_CONTINUE);
147 }
148 
149 void
151  fib_node_index_t covered)
152 {
153  fib_entry_t *cover;
154 
155  cover = fib_entry_get(cover_index);
156 
157  fib_entry_cover_walk(cover,
159  uword_to_pointer(covered, void*));
160 }
161 
162 static walk_rc_t
164  fib_node_index_t covered,
165  void *args)
166 {
167  fib_entry_cover_updated(covered);
168 
169  return (WALK_CONTINUE);
170 }
171 
172 void
174 {
175  fib_entry_cover_walk(fib_entry,
177  NULL);
178 }
FIB_NODE_TYPE_ENTRY
@ FIB_NODE_TYPE_ENTRY
Definition: fib_node.h:33
fib_enty_cover_walk_ctx_t_
Internal struct to hold user supplied parameters for the cover walk.
Definition: fib_entry_cover.c:69
fib_entry_delegate_remove
void fib_entry_delegate_remove(fib_entry_t *fib_entry, fib_entry_delegate_type_t type)
Definition: fib_entry_delegate.c:72
fib_enty_cover_walk_ctx_t_::cover
fib_entry_t * cover
Definition: fib_entry_cover.c:70
WALK_CONTINUE
@ WALK_CONTINUE
Definition: interface_funcs.h:174
fib_entry_get_prefix
const fib_prefix_t * fib_entry_get_prefix(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:1728
fib_enty_cover_walk_ctx_t_::walk
fib_entry_covered_walk_t walk
Definition: fib_entry_cover.c:71
fib_entry_t_
An entry in a FIB table.
Definition: fib_entry.h:305
fib_entry_cover_updated
void fib_entry_cover_updated(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:1337
pointer_to_uword
static uword pointer_to_uword(const void *p)
Definition: types.h:131
fib_entry_cover_change_one
static walk_rc_t fib_entry_cover_change_one(fib_entry_t *cover, fib_node_index_t covered, void *args)
Definition: fib_entry_cover.c:110
FIB_NODE_INDEX_INVALID
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:30
fib_entry_delegate.h
fib_entry_delegate_find
fib_entry_delegate_t * fib_entry_delegate_find(const fib_entry_t *fib_entry, fib_entry_delegate_type_t type)
Definition: fib_entry_delegate.c:65
fib_entry_cover_walk
void fib_entry_cover_walk(fib_entry_t *cover, fib_entry_covered_walk_t walk, void *args)
Definition: fib_entry_cover.c:87
fib_entry_src.h
fib_entry_cover_update_notify
void fib_entry_cover_update_notify(fib_entry_t *fib_entry)
Definition: fib_entry_cover.c:173
fib_entry_cover.h
fib_entry_cover_walk_node_ptr
static walk_rc_t fib_entry_cover_walk_node_ptr(fib_node_ptr_t *depend, void *args)
Definition: fib_entry_cover.c:76
fib_node_index_t
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
fib_entry_get_index
fib_node_index_t fib_entry_get_index(const fib_entry_t *fib_entry)
Definition: fib_entry.c:63
fib_entry_covered_walk_t
walk_rc_t(* fib_entry_covered_walk_t)(fib_entry_t *cover, fib_node_index_t covered, void *ctx)
callback function used when walking the covered entries
Definition: fib_entry_cover.h:24
fib_entry_delegate_find_or_add
fib_entry_delegate_t * fib_entry_delegate_find_or_add(fib_entry_t *fib_entry, fib_entry_delegate_type_t fdt)
Definition: fib_entry_delegate.c:118
FIB_ENTRY_DBG
#define FIB_ENTRY_DBG(_e, _fmt, _args...)
Definition: fib_entry_src.h:28
fib_enty_cover_walk_ctx_t_::ctx
void * ctx
Definition: fib_entry_cover.c:72
fib_node_ptr_t_
A representation of one pointer to another node.
Definition: fib_node.h:195
fib_node_ptr_t_::fnp_index
fib_node_index_t fnp_index
node's index
Definition: fib_node.h:203
FIB_ENTRY_DELEGATE_COVERED
@ FIB_ENTRY_DELEGATE_COVERED
Dependency list of covered entries.
Definition: fib_entry_delegate.h:45
fib_entry_delegate_t_::fd_list
fib_node_list_t fd_list
For the cover tracking.
Definition: fib_entry_delegate.h:133
fib_entry_get
fib_entry_t * fib_entry_get(fib_node_index_t index)
Definition: fib_entry.c:51
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
fib_entry_cover_change_notify
void fib_entry_cover_change_notify(fib_node_index_t cover_index, fib_node_index_t covered)
Definition: fib_entry_cover.c:150
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
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
fib_enty_cover_walk_ctx_t
struct fib_enty_cover_walk_ctx_t_ fib_enty_cover_walk_ctx_t
Internal struct to hold user supplied parameters for the cover walk.
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
fib_prefix_is_cover
int fib_prefix_is_cover(const fib_prefix_t *p1, const fib_prefix_t *p2)
Compare two prefixes for covering relationship.
Definition: fib_types.c:212
fib_entry_cover_untrack
void fib_entry_cover_untrack(fib_entry_t *cover, u32 tracked_index)
Definition: fib_entry_cover.c:45
fib_entry_cover_track
u32 fib_entry_cover_track(fib_entry_t *cover, fib_node_index_t covered)
Definition: fib_entry_cover.c:22
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
fib_entry_delegate_t_
A Delagate is a means to implmenet the Delagation design pattern; the extension of an objects functio...
Definition: fib_entry_delegate.h:99
fib_entry_cover_update_one
static walk_rc_t fib_entry_cover_update_one(fib_entry_t *cover, fib_node_index_t covered, void *args)
Definition: fib_entry_cover.c:163
fib_entry_cover_changed
void fib_entry_cover_changed(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:1261
walk_rc_t
enum walk_rc_t_ walk_rc_t
Walk return code.
fib_prefix_t_
Aggregate type for a prefix.
Definition: fib_types.h:202