blob: fcc5890c7d70fcae802e79f023746755a1f8c4e5 [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>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010048#include <vnet/adj/adj_glean.h>
49
50/**
51 * @brief
52 * Take a reference counting lock on the adjacency
53 */
54extern void adj_lock(adj_index_t adj_index);
55/**
56 * @brief
57 * Release a reference counting lock on the adjacency
58 */
59extern void adj_unlock(adj_index_t adj_index);
60
61/**
62 * @brief
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.
66 */
67extern u32 adj_child_add(adj_index_t adj_index,
68 fib_node_type_t type,
69 fib_node_index_t child_index);
70/**
71 * @brief
72 * Remove a child dependent
73 */
74extern void adj_child_remove(adj_index_t adj_index,
75 u32 sibling_index);
76
77/**
Neale Rannsb80c5362016-10-08 13:03:40 +010078 * @brief Walk the Adjacencies on a given interface
79 */
80extern void adj_walk (u32 sw_if_index,
81 adj_walk_cb_t cb,
82 void *ctx);
83
84/**
85 * @brief Return the link type of the adjacency
86 */
87extern vnet_link_t adj_get_link_type (adj_index_t ai);
88
89/**
90 * @brief Return the sw interface index of the adjacency.
91 */
92extern u32 adj_get_sw_if_index (adj_index_t ai);
93
94/**
95 * @brief Return the link type of the adjacency
96 */
97extern const u8* adj_get_rewrite (adj_index_t ai);
98
99/**
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100100 * @brief
Neale Ranns6c3ebcc2016-10-02 21:20:15 +0100101 * The global adjacnecy pool. Exposed for fast/inline data-plane access
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100102 */
Neale Ranns6c3ebcc2016-10-02 21:20:15 +0100103extern ip_adjacency_t *adj_pool;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100104
105/**
106 * @brief
107 * Adjacency packet counters
108 */
109extern vlib_combined_counter_main_t adjacency_counters;
110
111/**
Neale Ranns9c6a6132017-02-21 05:33:14 -0800112 * @brief Global Config for enabling per-adjacency counters
113 * This is configurable because it comes with a non-negligible
114 * performance cost. */
115extern int adj_per_adj_counters;
116
117/**
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100118 * @brief
119 * Get a pointer to an adjacency object from its index
120 */
121static inline ip_adjacency_t *
122adj_get (adj_index_t adj_index)
123{
Neale Ranns6c3ebcc2016-10-02 21:20:15 +0100124 return (vec_elt_at_index(adj_pool, adj_index));
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100125}
126
Neale Ranns9c6a6132017-02-21 05:33:14 -0800127/**
128 * @brief Get the global configuration option for enabling per-adj counters
129 */
130static inline int
131adj_are_counters_enabled (void)
132{
133 return (adj_per_adj_counters);
134}
135
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100136#endif