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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 * An adjacency is a representation of an attached L3 peer.
18 * Adjacency Sub-types:
19 * - neighbour: a representation of an attached L3 peer.
20 * Key:{addr,interface,link/ether-type}
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.
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.
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.
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_glean.h>
52 * Take a reference counting lock on the adjacency
54 extern void adj_lock(adj_index_t adj_index);
57 * Release a reference counting lock on the adjacency
59 extern void adj_unlock(adj_index_t adj_index);
63 * Add a child dependent to an adjacency. The child will
64 * thus be informed via its registerd back-walk function
65 * when the adjacency state changes.
67 extern u32 adj_child_add(adj_index_t adj_index,
69 fib_node_index_t child_index);
72 * Remove a child dependent
74 extern void adj_child_remove(adj_index_t adj_index,
78 * @brief Walk the Adjacencies on a given interface
80 extern void adj_walk (u32 sw_if_index,
85 * @brief Return the link type of the adjacency
87 extern vnet_link_t adj_get_link_type (adj_index_t ai);
90 * @brief Return the sw interface index of the adjacency.
92 extern u32 adj_get_sw_if_index (adj_index_t ai);
95 * @brief Return the link type of the adjacency
97 extern const u8* adj_get_rewrite (adj_index_t ai);
101 * The global adjacnecy pool. Exposed for fast/inline data-plane access
103 extern ip_adjacency_t *adj_pool;
107 * Adjacency packet counters
109 extern vlib_combined_counter_main_t adjacency_counters;
113 * Get a pointer to an adjacency object from its index
115 static inline ip_adjacency_t *
116 adj_get (adj_index_t adj_index)
118 return (vec_elt_at_index(adj_pool, adj_index));