blob: e85625db7ee16c4b6e5b6db8e146455c74b70791 [file] [log] [blame]
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001/*
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 */
55extern void adj_lock(adj_index_t adj_index);
56/**
57 * @brief
58 * Release a reference counting lock on the adjacency
59 */
60extern 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 */
68extern u32 adj_child_add(adj_index_t adj_index,
69 fib_node_type_t type,
70 fib_node_index_t child_index);
71/**
72 * @brief
73 * Remove a child dependent
74 */
75extern void adj_child_remove(adj_index_t adj_index,
76 u32 sibling_index);
77
78/**
Neale Rannsb80c5362016-10-08 13:03:40 +010079 * @brief Walk the Adjacencies on a given interface
80 */
81extern 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 */
88extern vnet_link_t adj_get_link_type (adj_index_t ai);
89
90/**
91 * @brief Return the sw interface index of the adjacency.
92 */
93extern u32 adj_get_sw_if_index (adj_index_t ai);
94
95/**
96 * @brief Return the link type of the adjacency
97 */
98extern const u8* adj_get_rewrite (adj_index_t ai);
99
100/**
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100101 * @brief
Neale Ranns6c3ebcc2016-10-02 21:20:15 +0100102 * The global adjacnecy pool. Exposed for fast/inline data-plane access
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100103 */
Neale Ranns6c3ebcc2016-10-02 21:20:15 +0100104extern ip_adjacency_t *adj_pool;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100105
106/**
107 * @brief
108 * Adjacency packet counters
109 */
110extern vlib_combined_counter_main_t adjacency_counters;
111
112/**
113 * @brief
114 * Get a pointer to an adjacency object from its index
115 */
116static inline ip_adjacency_t *
117adj_get (adj_index_t adj_index)
118{
Neale Ranns6c3ebcc2016-10-02 21:20:15 +0100119 return (vec_elt_at_index(adj_pool, adj_index));
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100120}
121
122#endif