FD.io VPP  v17.10-9-gd594711
Vector Packet Processing
adj.h
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  * An adjacency is a representation of an attached L3 peer.
17  *
18  * Adjacency Sub-types:
19  * - neighbour: a representation of an attached L3 peer.
20  * Key:{addr,interface,link/ether-type}
21  * SHARED
22  * - glean: used to drive ARP/ND for packets destined to a local sub-net.
23  * 'glean' mean use the packet's destination address as the target
24  * address in the ARP packet.
25  * UNSHARED. Only one per-interface.
26  * - midchain: a nighbour adj on a virtual/tunnel interface.
27  *
28  * The API to create and update the adjacency is very sub-type specific. This
29  * is intentional as it encourages the user to carefully consider which adjacency
30  * sub-type they are really using, and hence assign it data in the appropriate
31  * sub-type space in the union of sub-types. This prevents the adj becoming a
32  * disorganised dumping group for 'my features needs a u16 somewhere' data. It
33  * is important to enforce this approach as space in the adjacency is a premium,
34  * as we need it to fit in 1 cache line.
35  *
36  * the API is also based around an index to an ajdacency not a raw pointer. This
37  * is so the user doesn't suffer the same limp inducing firearm injuries that
38  * the author suffered as the adjacenices can realloc.
39  */
40 
41 #ifndef __ADJ_H__
42 #define __ADJ_H__
43 
44 #include <vnet/adj/adj_types.h>
45 #include <vnet/adj/adj_nbr.h>
46 #include <vnet/adj/adj_glean.h>
47 #include <vnet/adj/rewrite.h>
48 
49 /** @brief Common (IP4/IP6) next index stored in adjacency. */
50 typedef enum
51 {
52  /** Adjacency to drop this packet. */
54  /** Adjacency to punt this packet. */
56 
57  /** This packet is for one of our own IP addresses. */
59 
60  /** This packet matches an "incomplete adjacency" and packets
61  need to be passed to ARP to find rewrite string for
62  this destination. */
64 
65  /** This packet matches an "interface route" and packets
66  need to be passed to ARP to find rewrite string for
67  this destination. */
69 
70  /** This packet is to be rewritten and forwarded to the next
71  processing node. This is typically the output interface but
72  might be another node for further output processing. */
74 
75  /** This packets follow a mid-chain adjacency */
77 
78  /** This packets needs to go to ICMP error */
80 
81  /** Multicast Adjacency. */
83 
84  /** Multicast Midchain Adjacency. An Adjacency for sending macst packets
85  * on a tunnel/virtual interface */
87 
89 } __attribute__ ((packed)) ip_lookup_next_t;
90 
91 typedef enum
92 {
95 
96 typedef enum
97 {
98  /* Hop-by-hop header handling */
104 
105 #define IP4_LOOKUP_NEXT_NODES { \
106  [IP_LOOKUP_NEXT_DROP] = "ip4-drop", \
107  [IP_LOOKUP_NEXT_PUNT] = "ip4-punt", \
108  [IP_LOOKUP_NEXT_LOCAL] = "ip4-local", \
109  [IP_LOOKUP_NEXT_ARP] = "ip4-arp", \
110  [IP_LOOKUP_NEXT_GLEAN] = "ip4-glean", \
111  [IP_LOOKUP_NEXT_REWRITE] = "ip4-rewrite", \
112  [IP_LOOKUP_NEXT_MCAST] = "ip4-rewrite-mcast", \
113  [IP_LOOKUP_NEXT_MIDCHAIN] = "ip4-midchain", \
114  [IP_LOOKUP_NEXT_MCAST_MIDCHAIN] = "ip4-mcast-midchain", \
115  [IP_LOOKUP_NEXT_ICMP_ERROR] = "ip4-icmp-error", \
116 }
117 
118 #define IP6_LOOKUP_NEXT_NODES { \
119  [IP_LOOKUP_NEXT_DROP] = "ip6-drop", \
120  [IP_LOOKUP_NEXT_PUNT] = "ip6-punt", \
121  [IP_LOOKUP_NEXT_LOCAL] = "ip6-local", \
122  [IP_LOOKUP_NEXT_ARP] = "ip6-discover-neighbor", \
123  [IP_LOOKUP_NEXT_GLEAN] = "ip6-glean", \
124  [IP_LOOKUP_NEXT_REWRITE] = "ip6-rewrite", \
125  [IP_LOOKUP_NEXT_MCAST] = "ip6-rewrite-mcast", \
126  [IP_LOOKUP_NEXT_MIDCHAIN] = "ip6-midchain", \
127  [IP_LOOKUP_NEXT_MCAST_MIDCHAIN] = "ip6-mcast-midchain", \
128  [IP_LOOKUP_NEXT_ICMP_ERROR] = "ip6-icmp-error", \
129  [IP6_LOOKUP_NEXT_HOP_BY_HOP] = "ip6-hop-by-hop", \
130  [IP6_LOOKUP_NEXT_ADD_HOP_BY_HOP] = "ip6-add-hop-by-hop", \
131  [IP6_LOOKUP_NEXT_POP_HOP_BY_HOP] = "ip6-pop-hop-by-hop", \
132 }
133 
134 /**
135  * Forward delcartion
136  */
137 struct ip_adjacency_t_;
138 
139 /**
140  * @brief A function type for post-rewrite fixups on midchain adjacency
141  */
143  struct ip_adjacency_t_ * adj,
144  vlib_buffer_t * b0);
145 
146 /**
147  * @brief Flags on an IP adjacency
148  */
150 {
152 
153  /**
154  * Currently a sync walk is active. Used to prevent re-entrant walking
155  */
157 
158  /**
159  * Packets TX through the midchain do not increment the interface
160  * counters. This should be used when the adj is associated with an L2
161  * interface and that L2 interface is in a bridege domain. In that case
162  * the packet will have traversed the interface's TX node, and hence have
163  * been counted, before it traverses ths midchain
164  */
166 } __attribute__ ((packed)) adj_flags_t;
167 
168 /**
169  * @brief IP unicast adjacency.
170  * @note cache aligned.
171  *
172  * An adjacency is a represenation of a peer on a particular link.
173  */
174 typedef struct ip_adjacency_t_
175 {
176  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
177 
178  /**
179  * Linkage into the FIB node grpah. First member since this type
180  * has 8 byte alignment requirements.
181  */
183 
184  /**
185  * Next hop after ip4-lookup.
186  * This is not accessed in the rewrite nodes.
187  * 1-bytes
188  */
190 
191  /**
192  * link/ether-type
193  * 1 bytes
194  */
196 
197  /**
198  * The protocol of the neighbor/peer. i.e. the protocol with
199  * which to interpret the 'next-hop' attirbutes of the sub-types.
200  * 1-btyes
201  */
203 
204  /**
205  * Flags on the adjacency
206  * 1-bytes
207  */
208  adj_flags_t ia_flags;
209 
210  union
211  {
212  /**
213  * IP_LOOKUP_NEXT_ARP/IP_LOOKUP_NEXT_REWRITE
214  *
215  * neighbour adjacency sub-type;
216  */
217  struct
218  {
219  ip46_address_t next_hop;
220  } nbr;
221  /**
222  * IP_LOOKUP_NEXT_MIDCHAIN
223  *
224  * A nbr adj that is also recursive. Think tunnels.
225  * A nbr adj can transition to be of type MDICHAIN
226  * so be sure to leave the two structs with the next_hop
227  * fields aligned.
228  */
229  struct
230  {
231  /**
232  * The recursive next-hop.
233  * This field MUST be at the same memory location as
234  * sub_type.nbr.next_hop
235  */
236  ip46_address_t next_hop;
237  /**
238  * The next DPO to use
239  */
241  /**
242  * A function to perform the post-rewrite fixup
243  */
245  } midchain;
246  /**
247  * IP_LOOKUP_NEXT_GLEAN
248  *
249  * Glean the address to ARP for from the packet's destination.
250  * Technically these aren't adjacencies, i.e. they are not a
251  * representation of a peer. One day we might untangle this coupling
252  * and use a new Glean DPO.
253  */
254  struct
255  {
256  ip46_address_t receive_addr;
257  } glean;
258  } sub_type;
259 
260  CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
261 
262  /* Rewrite in second/third cache lines */
264 
265  /**
266  * more control plane members that do not fit on the first cacheline
267  */
268  /**
269  * A sorted vector of delegates
270  */
272 
274 
275 STATIC_ASSERT ((STRUCT_OFFSET_OF (ip_adjacency_t, cacheline0) == 0),
276  "IP adjacency cachline 0 is not offset");
279  "IP adjacency cachline 1 is more than one cachline size offset");
280 
281 /**
282  * @brief
283  * Take a reference counting lock on the adjacency
284  */
285 extern void adj_lock(adj_index_t adj_index);
286 /**
287  * @brief
288  * Release a reference counting lock on the adjacency
289  */
290 extern void adj_unlock(adj_index_t adj_index);
291 
292 /**
293  * @brief
294  * Add a child dependent to an adjacency. The child will
295  * thus be informed via its registerd back-walk function
296  * when the adjacency state changes.
297  */
298 extern u32 adj_child_add(adj_index_t adj_index,
299  fib_node_type_t type,
300  fib_node_index_t child_index);
301 /**
302  * @brief
303  * Remove a child dependent
304  */
305 extern void adj_child_remove(adj_index_t adj_index,
306  u32 sibling_index);
307 
308 /**
309  * @brief Walk the Adjacencies on a given interface
310  */
311 extern void adj_walk (u32 sw_if_index,
312  adj_walk_cb_t cb,
313  void *ctx);
314 
315 /**
316  * @brief Return the link type of the adjacency
317  */
319 
320 /**
321  * @brief Return the sw interface index of the adjacency.
322  */
324 
325 /**
326  * @brief Return true if the adjacency is 'UP', i.e. can be used for forwarding.
327  * 0 is down, !0 is up.
328  */
329 extern int adj_is_up (adj_index_t ai);
330 
331 /**
332  * @brief Return the link type of the adjacency
333  */
334 extern const u8* adj_get_rewrite (adj_index_t ai);
335 
336 /**
337  * @brief Notify the adjacency subsystem that the features settings for
338  * an interface have changed
339  */
340 extern void adj_feature_update (u32 sw_if_index, u8 arc_index, u8 is_enable);
341 
342 /**
343  * @brief
344  * The global adjacnecy pool. Exposed for fast/inline data-plane access
345  */
346 extern ip_adjacency_t *adj_pool;
347 
348 /**
349  * @brief
350  * Adjacency packet counters
351  */
353 
354 /**
355  * @brief Global Config for enabling per-adjacency counters
356  * This is configurable because it comes with a non-negligible
357  * performance cost. */
358 extern int adj_per_adj_counters;
359 
360 /**
361  * @brief
362  * Get a pointer to an adjacency object from its index
363  */
364 static inline ip_adjacency_t *
365 adj_get (adj_index_t adj_index)
366 {
367  return (vec_elt_at_index(adj_pool, adj_index));
368 }
369 
370 /**
371  * @brief Get the global configuration option for enabling per-adj counters
372  */
373 static inline int
375 {
376  return (adj_per_adj_counters);
377 }
378 
379 #endif
int adj_is_up(adj_index_t ai)
Return true if the adjacency is &#39;UP&#39;, i.e.
Definition: adj.c:382
adj_flags_t ia_flags
Flags on the adjacency 1-bytes.
Definition: adj.h:208
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:68
u32 adj_child_add(adj_index_t adj_index, fib_node_type_t type, fib_node_index_t child_index)
Add a child dependent to an adjacency.
Definition: adj.c:248
enum fib_node_type_t_ fib_node_type_t
The types of nodes in a FIB graph.
ip_adjacency_flags_t_
Flags on an IP adjacency.
Definition: adj.h:149
Multicast Adjacency.
Definition: adj.h:82
IP unicast adjacency.
Definition: adj.h:174
#define VLIB_BUFFER_PRE_DATA_SIZE
Definition: buffer.h:52
This packet is to be rewritten and forwarded to the next processing node.
Definition: adj.h:73
#define STRUCT_OFFSET_OF(t, f)
Definition: clib.h:62
adj_midchain_fixup_t fixup_func
A function to perform the post-rewrite fixup.
Definition: adj.h:244
struct ip_adjacency_t_::@38::@40 midchain
IP_LOOKUP_NEXT_MIDCHAIN.
ip_lookup_next_t
An adjacency is a representation of an attached L3 peer.
Definition: adj.h:50
void adj_walk(u32 sw_if_index, adj_walk_cb_t cb, void *ctx)
Walk the Adjacencies on a given interface.
Definition: adj.c:335
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
struct ip_adjacency_t_ ip_adjacency_t
IP unicast adjacency.
vnet_link_t ia_link
link/ether-type 1 bytes
Definition: adj.h:195
Adjacency to punt this packet.
Definition: adj.h:55
ip46_address_t receive_addr
Definition: adj.h:256
static ip_adjacency_t * adj_get(adj_index_t adj_index)
Get a pointer to an adjacency object from its index.
Definition: adj.h:365
enum ip_adjacency_flags_t_ adj_flags_t
Flags on an IP adjacency.
ip6_lookup_next_t
Definition: adj.h:96
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
ip46_address_t next_hop
The recursive next-hop.
Definition: adj.h:219
A Delagate is a means to implement the Delagation design pattern; the extension of an object&#39;s functi...
Definition: adj_delegate.h:61
struct ip_adjacency_t_::@38::@41 glean
IP_LOOKUP_NEXT_GLEAN.
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:150
dpo_id_t next_dpo
The next DPO to use.
Definition: adj.h:240
struct ip_adjacency_t_::@38::@39 nbr
IP_LOOKUP_NEXT_ARP/IP_LOOKUP_NEXT_REWRITE.
ip_adjacency_t * adj_pool
The global adjacnecy pool.
Definition: adj.c:30
This packet matches an "interface route" and packets need to be passed to ARP to find rewrite string ...
Definition: adj.h:68
void adj_lock(adj_index_t adj_index)
Take a reference counting lock on the adjacency.
Definition: adj.c:212
An node in the FIB graph.
Definition: fib_node.h:279
fib_node_t ia_node
Linkage into the FIB node grpah.
Definition: adj.h:182
const u8 * adj_get_rewrite(adj_index_t ai)
Return the link type of the adjacency.
Definition: adj.c:408
union ip_adjacency_t_::@38 sub_type
Currently a sync walk is active.
Definition: adj.h:156
This packet matches an "incomplete adjacency" and packets need to be passed to ARP to find rewrite st...
Definition: adj.h:63
Adjacency to drop this packet.
Definition: adj.h:53
vlib_main_t * vm
Definition: buffer.c:283
Multicast Midchain Adjacency.
Definition: adj.h:86
Packets TX through the midchain do not increment the interface counters.
Definition: adj.h:165
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:28
adj_walk_rc_t(* adj_walk_cb_t)(adj_index_t ai, void *ctx)
Call back function when walking adjacencies.
Definition: adj_types.h:50
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
void adj_feature_update(u32 sw_if_index, u8 arc_index, u8 is_enable)
Notify the adjacency subsystem that the features settings for an interface have changed.
Definition: adj.c:316
This packets follow a mid-chain adjacency.
Definition: adj.h:76
unsigned int u32
Definition: types.h:88
long ctx[MAX_CONNS]
Definition: main.c:95
enum vnet_link_t_ vnet_link_t
Link Type: A description of the protocol of packets on the link.
vnet_link_t adj_get_link_type(adj_index_t ai)
Return the link type of the adjacency.
Definition: adj.c:355
vlib_combined_counter_main_t adjacency_counters
Adjacency packet counters.
Definition: adj.c:25
This packets needs to go to ICMP error.
Definition: adj.h:79
This packet is for one of our own IP addresses.
Definition: adj.h:58
fib_protocol_t ia_nh_proto
The protocol of the neighbor/peer.
Definition: adj.h:202
ip4_lookup_next_t
Definition: adj.h:91
#define vnet_declare_rewrite(total_bytes)
Definition: rewrite.h:112
void(* adj_midchain_fixup_t)(vlib_main_t *vm, struct ip_adjacency_t_ *adj, vlib_buffer_t *b0)
A function type for post-rewrite fixups on midchain adjacency.
Definition: adj.h:142
unsigned char u8
Definition: types.h:56
ip_lookup_next_t lookup_next_index
Next hop after ip4-lookup.
Definition: adj.h:189
void adj_child_remove(adj_index_t adj_index, u32 sibling_index)
Remove a child dependent.
Definition: adj.c:265
u32 adj_get_sw_if_index(adj_index_t ai)
Return the sw interface index of the adjacency.
Definition: adj.c:368
A collection of combined counters.
Definition: counter.h:180
STATIC_ASSERT((STRUCT_OFFSET_OF(ip_adjacency_t, cacheline0)==0),"IP adjacency cachline 0 is not offset")
int adj_per_adj_counters
Global Config for enabling per-adjacency counters This is configurable because it comes with a non-ne...
Definition: adj.c:36
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
void adj_unlock(adj_index_t adj_index)
Release a reference counting lock on the adjacency.
Definition: adj.c:229
static int adj_are_counters_enabled(void)
Get the global configuration option for enabling per-adj counters.
Definition: adj.h:374
struct adj_delegate_t_ * ia_delegates
more control plane members that do not fit on the first cacheline
Definition: adj.h:271