FD.io VPP  v16.12-rc0-308-g931be3a
Vector Packet Processing
adj_glean.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 
16 #include <vnet/adj/adj.h>
17 #include <vnet/adj/adj_internal.h>
18 #include <vnet/fib/fib_walk.h>
19 
20 /*
21  * The 'DB' of all glean adjs.
22  * There is only one glean per-interface per-protocol, so this is a per-interface
23  * vector
24  */
26 
27 static inline vlib_node_registration_t*
29 {
30  switch (proto) {
31  case FIB_PROTOCOL_IP4:
32  return (&ip4_glean_node);
33  case FIB_PROTOCOL_IP6:
34  return (&ip6_glean_node);
35  case FIB_PROTOCOL_MPLS:
36  break;
37  }
38  ASSERT(0);
39  return (NULL);
40 }
41 
42 /*
43  * adj_glean_add_or_lock
44  *
45  * The next_hop address here is used for source address selection in the DP.
46  * The glean adj is added to an interface's connected prefix, the next-hop
47  * passed here is the local prefix on the same interface.
48  */
51  u32 sw_if_index,
52  const ip46_address_t *nh_addr)
53 {
54  ip_adjacency_t * adj;
55 
57 
58  if (ADJ_INDEX_INVALID == adj_gleans[proto][sw_if_index])
59  {
60  adj = adj_alloc(proto);
61 
63  adj->ia_nh_proto = proto;
64  adj_gleans[proto][sw_if_index] = adj_get_index(adj);
65 
66  if (NULL != nh_addr)
67  {
68  adj->sub_type.glean.receive_addr = *nh_addr;
69  }
70 
71  adj->rewrite_header.data_bytes = 0;
72 
74  adj_fib_proto_2_nd(proto),
75  sw_if_index,
76  adj_get_glean_node(proto)->index,
78  &adj->rewrite_header,
79  sizeof (adj->rewrite_data));
80  }
81  else
82  {
83  adj = adj_get(adj_gleans[proto][sw_if_index]);
84  }
85 
86  adj_lock(adj_get_index(adj));
87 
88  return (adj_get_index(adj));
89 }
90 
91 void
93  u32 sw_if_index)
94 {
95  ASSERT(sw_if_index < vec_len(adj_gleans[proto]));
96 
97  adj_gleans[proto][sw_if_index] = ADJ_INDEX_INVALID;
98 }
99 
100 static clib_error_t *
102  u32 sw_if_index,
103  u32 flags)
104 {
105  /*
106  * for each glean on the interface trigger a walk back to the children
107  */
108  fib_protocol_t proto;
109  ip_adjacency_t *adj;
110 
111 
112  for (proto = FIB_PROTOCOL_IP4; proto <= FIB_PROTOCOL_IP6; proto++)
113  {
114  if (sw_if_index >= vec_len(adj_gleans[proto]) ||
115  ADJ_INDEX_INVALID == adj_gleans[proto][sw_if_index])
116  continue;
117 
118  adj = adj_get(adj_gleans[proto][sw_if_index]);
119 
120  fib_node_back_walk_ctx_t bw_ctx = {
124  };
125 
127  }
128 
129  return (NULL);
130 }
131 
133 
134 static clib_error_t *
136  u32 sw_if_index,
137  u32 is_add)
138 {
139  /*
140  * for each glean on the interface trigger a walk back to the children
141  */
142  fib_protocol_t proto;
143  ip_adjacency_t *adj;
144 
145  if (is_add)
146  {
147  /*
148  * not interested in interface additions. we will not back walk
149  * to resolve paths through newly added interfaces. Why? The control
150  * plane should have the brains to add interfaces first, then routes.
151  * So the case where there are paths with a interface that matches
152  * one just created is the case where the path resolved through an
153  * interface that was deleted, and still has not been removed. The
154  * new interface added, is NO GUARANTEE that the interface being
155  * added now, even though it may have the same sw_if_index, is the
156  * same interface that the path needs. So tough!
157  * If the control plane wants these routes to resolve it needs to
158  * remove and add them again.
159  */
160  return (NULL);
161  }
162 
163  for (proto = FIB_PROTOCOL_IP4; proto <= FIB_PROTOCOL_IP6; proto++)
164  {
165  if (sw_if_index >= vec_len(adj_gleans[proto]) ||
166  ADJ_INDEX_INVALID == adj_gleans[proto][sw_if_index])
167  continue;
168 
169  adj = adj_get(adj_gleans[proto][sw_if_index]);
170 
171  fib_node_back_walk_ctx_t bw_ctx = {
173  };
174 
176  }
177 
178  return (NULL);
179 }
180 
182 
183 u8*
184 format_adj_glean (u8* s, va_list *ap)
185 {
186  index_t index = va_arg(*ap, index_t);
187  CLIB_UNUSED(u32 indent) = va_arg(*ap, u32);
188  vnet_main_t * vnm = vnet_get_main();
189  ip_adjacency_t * adj = adj_get(index);
190 
191  return (format(s, "%U-glean: %U",
194  vnm,
196  adj->rewrite_header.sw_if_index)));
197 }
198 
199 
200 static void
202 {
203  adj_lock(dpo->dpoi_index);
204 }
205 static void
207 {
208  adj_unlock(dpo->dpoi_index);
209 }
210 
211 const static dpo_vft_t adj_glean_dpo_vft = {
213  .dv_unlock = adj_dpo_unlock,
214  .dv_format = format_adj_glean,
215 };
216 
217 /**
218  * @brief The per-protocol VLIB graph nodes that are assigned to a glean
219  * object.
220  *
221  * this means that these graph nodes are ones from which a glean is the
222  * parent object in the DPO-graph.
223  */
224 const static char* const glean_ip4_nodes[] =
225 {
226  "ip4-glean",
227  NULL,
228 };
229 const static char* const glean_ip6_nodes[] =
230 {
231  "ip6-glean",
232  NULL,
233 };
234 
235 const static char* const * const glean_nodes[DPO_PROTO_NUM] =
236 {
239  [DPO_PROTO_MPLS] = NULL,
240 };
241 
242 void
244 {
245  dpo_register(DPO_ADJACENCY_GLEAN, &adj_glean_dpo_vft, glean_nodes);
246 }
dpo_lock_fn_t dv_lock
A reference counting lock function.
Definition: dpo.h:318
void adj_glean_remove(fib_protocol_t proto, u32 sw_if_index)
Definition: adj_glean.c:92
#define VNET_REWRITE_FOR_SW_INTERFACE_ADDRESS_BROADCAST
Definition: rewrite.h:264
#define CLIB_UNUSED(x)
Definition: clib.h:79
A virtual function table regisitered for a DPO type.
Definition: dpo.h:313
void adj_lock(adj_index_t adj_index)
An adjacency is a representation of an attached L3 peer.
Definition: adj.c:189
adj_index_t adj_glean_add_or_lock(fib_protocol_t proto, u32 sw_if_index, const ip46_address_t *nh_addr)
Glean Adjacency.
Definition: adj_glean.c:50
#define NULL
Definition: clib.h:55
IP unicast adjacency.
Definition: lookup.h:174
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:41
struct _vlib_node_registration vlib_node_registration_t
void vnet_rewrite_for_sw_interface(vnet_main_t *vnm, vnet_link_t link_type, u32 sw_if_index, u32 node_index, void *dst_address, vnet_rewrite_header_t *rw, u32 max_rewrite_bytes)
Deprecated.
Definition: rewrite.c:207
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
static ip_adjacency_t * adj_get(adj_index_t adj_index)
Get a pointer to an adjacency object from its index.
Definition: adj.h:117
void dpo_register(dpo_type_t type, const dpo_vft_t *vft, const char *const *const *nodes)
For a given DPO type Register:
Definition: dpo.c:221
void fib_walk_sync(fib_node_type_t parent_type, fib_node_index_t parent_index, fib_node_back_walk_ctx_t *ctx)
Back walk all the children of a FIB node.
Definition: fib_walk.c:624
static adj_index_t * adj_gleans[FIB_PROTOCOL_MAX]
Definition: adj_glean.c:25
void adj_unlock(adj_index_t adj_index)
Release a reference counting lock on the adjacency.
Definition: adj.c:206
This packet matches an "interface route" and packets need to be passed to ARP to find rewrite string ...
Definition: lookup.h:77
static clib_error_t * adj_glean_interface_delete(vnet_main_t *vnm, u32 sw_if_index, u32 is_add)
Definition: adj_glean.c:135
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:138
fib_node_bw_reason_flag_t fnbw_reason
The reason/trigger for the backwalk.
Definition: fib_node.h:164
format_function_t format_vnet_sw_interface_name
#define ADJ_INDEX_INVALID
Invalid ADJ index - used when no adj is known likewise blazoned capitals INVALID speak volumes where ...
Definition: adj_types.h:36
static adj_index_t adj_get_index(ip_adjacency_t *adj)
Get a pointer to an adjacency object from its index.
Definition: adj_internal.h:83
vlib_node_registration_t ip6_glean_node
(constructor) VLIB_REGISTER_NODE (ip6_glean_node)
Definition: ip6_forward.c:1731
static void adj_dpo_unlock(dpo_id_t *dpo)
Definition: adj_glean.c:206
void adj_glean_module_init(void)
Module initialisation.
Definition: adj_glean.c:243
union ip_adjacency_t_::@164 sub_type
static const char *const glean_ip4_nodes[]
The per-protocol VLIB graph nodes that are assigned to a glean object.
Definition: adj_glean.c:224
static clib_error_t * adj_glean_interface_state_change(vnet_main_t *vnm, u32 sw_if_index, u32 flags)
Definition: adj_glean.c:101
static void adj_dpo_lock(dpo_id_t *dpo)
Definition: adj_glean.c:201
u8 * format_adj_glean(u8 *s, va_list *ap)
Format/display a glean adjacency.
Definition: adj_glean.c:184
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
static const char *const *const glean_nodes[DPO_PROTO_NUM]
Definition: adj_glean.c:235
static vlib_node_registration_t * adj_get_glean_node(fib_protocol_t proto)
Definition: adj_glean.c:28
Context passed between object during a back walk.
Definition: fib_node.h:160
#define VNET_SW_INTERFACE_FLAG_ADMIN_UP
Definition: interface.h:490
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
struct ip_adjacency_t_::@164::@167 glean
IP_LOOKUP_NEXT_GLEAN.
u8 * format_fib_protocol(u8 *s, va_list ap)
Definition: fib_types.c:30
VNET_SW_INTERFACE_ADD_DEL_FUNCTION(adj_glean_interface_delete)
static const char *const glean_ip6_nodes[]
Definition: adj_glean.c:229
#define DPO_PROTO_NUM
Definition: dpo.h:72
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:154
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
ip_lookup_next_t lookup_next_index
Definition: lookup.h:183
ip_adjacency_t * adj_alloc(fib_protocol_t proto)
Definition: adj.c:47
#define FIB_PROTOCOL_MAX
Definition outside of enum so it does not need to be included in non-defaulted switch statements...
Definition: fib_types.h:54
vlib_node_registration_t ip4_glean_node
(constructor) VLIB_REGISTER_NODE (ip4_glean_node)
Definition: ip4_forward.c:2065
static vnet_link_t adj_fib_proto_2_nd(fib_protocol_t fp)
Definition: adj_internal.h:64
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:418
u32 flags
Definition: vhost-user.h:75
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header, unspecified alignment)
Definition: vec.h:445
VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION(adj_glean_interface_state_change)