FD.io VPP  v17.01.1-3-gc6833f8
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  * - rewrite: an adj with no key, but with a rewrite string.
28  *
29  * The API to create and update the adjacency is very sub-type specific. This
30  * is intentional as it encourages the user to carefully consider which adjacency
31  * sub-type they are really using, and hence assign it data in the appropriate
32  * sub-type space in the union of sub-types. This prevents the adj becoming a
33  * disorganised dumping group for 'my features needs a u16 somewhere' data. It
34  * is important to enforce this approach as space in the adjacency is a premium,
35  * as we need it to fit in 1 cache line.
36  *
37  * the API is also based around an index to an ajdacency not a raw pointer. This
38  * is so the user doesn't suffer the same limp inducing firearm injuries that
39  * the author suffered as the adjacenices can realloc.
40  */
41 
42 #ifndef __ADJ_H__
43 #define __ADJ_H__
44 
45 #include <vnet/ip/lookup.h>
46 #include <vnet/adj/adj_types.h>
47 #include <vnet/adj/adj_nbr.h>
48 #include <vnet/adj/adj_rewrite.h>
49 #include <vnet/adj/adj_glean.h>
50 
51 /**
52  * @brief
53  * Take a reference counting lock on the adjacency
54  */
55 extern void adj_lock(adj_index_t adj_index);
56 /**
57  * @brief
58  * Release a reference counting lock on the adjacency
59  */
60 extern void adj_unlock(adj_index_t adj_index);
61 
62 /**
63  * @brief
64  * Add a child dependent to an adjacency. The child will
65  * thus be informed via its registerd back-walk function
66  * when the adjacency state changes.
67  */
68 extern u32 adj_child_add(adj_index_t adj_index,
70  fib_node_index_t child_index);
71 /**
72  * @brief
73  * Remove a child dependent
74  */
75 extern void adj_child_remove(adj_index_t adj_index,
76  u32 sibling_index);
77 
78 /**
79  * @brief Walk the Adjacencies on a given interface
80  */
81 extern void adj_walk (u32 sw_if_index,
82  adj_walk_cb_t cb,
83  void *ctx);
84 
85 /**
86  * @brief Return the link type of the adjacency
87  */
89 
90 /**
91  * @brief Return the sw interface index of the adjacency.
92  */
94 
95 /**
96  * @brief Return the link type of the adjacency
97  */
98 extern const u8* adj_get_rewrite (adj_index_t ai);
99 
100 /**
101  * @brief
102  * The global adjacnecy pool. Exposed for fast/inline data-plane access
103  */
104 extern ip_adjacency_t *adj_pool;
105 
106 /**
107  * @brief
108  * Adjacency packet counters
109  */
111 
112 /**
113  * @brief
114  * Get a pointer to an adjacency object from its index
115  */
116 static inline ip_adjacency_t *
117 adj_get (adj_index_t adj_index)
118 {
119  return (vec_elt_at_index(adj_pool, adj_index));
120 }
121 
122 #endif
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:228
enum fib_node_type_t_ fib_node_type_t
The types of nodes in a FIB graph.
bad routing header type(not 4)") sr_error (NO_MORE_SEGMENTS
Definitions for all things IP (v4|v6) unicast and multicast lookup related.
IP unicast adjacency.
Definition: lookup.h:188
void adj_walk(u32 sw_if_index, adj_walk_cb_t cb, void *ctx)
Walk the Adjacencies on a given interface.
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
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
ip_adjacency_t * adj_pool
The global adjacnecy pool.
Definition: adj.c:35
void adj_lock(adj_index_t adj_index)
An adjacency is a representation of an attached L3 peer.
Definition: adj.c:192
const u8 * adj_get_rewrite(adj_index_t ai)
Return the link type of the adjacency.
Definition: adj.c:288
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
unsigned int u32
Definition: types.h:88
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:262
vlib_combined_counter_main_t adjacency_counters
Adjacency packet counters.
Definition: adj.c:30
unsigned char u8
Definition: types.h:56
void adj_child_remove(adj_index_t adj_index, u32 sibling_index)
Remove a child dependent.
Definition: adj.c:245
u32 adj_get_sw_if_index(adj_index_t ai)
Return the sw interface index of the adjacency.
Definition: adj.c:275
A collection of combined counters.
Definition: counter.h:212
void adj_unlock(adj_index_t adj_index)
Release a reference counting lock on the adjacency.
Definition: adj.c:209