blob: 5d0f8444ec3e7fc8a6334cedae55b5569b3de0cf [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 * @brief
17 * Neighbour Adjacency sub-type. These adjs represent an L3 peer on a
18 * connected link.
19 */
20
21#ifndef __ADJ_NBR_H__
22#define __ADJ_NBR_H__
23
24#include <vnet/vnet.h>
25#include <vnet/adj/adj_types.h>
26#include <vnet/fib/fib_node.h>
27#include <vnet/dpo/dpo.h>
28
29/**
30 * @brief
31 * Add (and lock) a new or lock an existing neighbour adjacency
32 *
33 * @param nh_proto
34 * The protocol for the next-hop address (v4 or v6)
35 *
36 * @param link_type
37 * A description of the protocol of the packets that will forward
38 * through this adj. On an ethernet interface this is the MAC header's
39 * ether-type
40 *
41 * @param nh_addr
42 * The address of the next-hop/peer to send the packet to
43 *
44 * @param sw_if_index
45 * The interface on which the peer resides
46 */
47extern adj_index_t adj_nbr_add_or_lock(fib_protocol_t nh_proto,
Neale Ranns924d03a2016-10-19 08:25:46 +010048 vnet_link_t link_type,
Neale Ranns0bfe5d82016-08-25 15:29:12 +010049 const ip46_address_t *nh_addr,
50 u32 sw_if_index);
51
52/**
53 * @brief
54 * Add (and lock) a new or lock an existing neighbour adjacency
55 *
56 * @param nh_proto
57 * The protocol for the next-hop address (v4 or v6)
58 *
59 * @param link_type
60 * A description of the protocol of the packets that will forward
61 * through this adj. On an ethernet interface this is the MAC header's
62 * ether-type
63 *
64 * @param nh_addr
65 * The address of the next-hop/peer to send the packet to
66 *
67 * @param sw_if_index
68 * The interface on which the peer resides
69 *
70 * @param rewrite
71 * The rewrite to prepend to packets
72 */
73extern adj_index_t adj_nbr_add_or_lock_w_rewrite(fib_protocol_t nh_proto,
Neale Ranns924d03a2016-10-19 08:25:46 +010074 vnet_link_t link_type,
Neale Ranns0bfe5d82016-08-25 15:29:12 +010075 const ip46_address_t *nh_addr,
76 u32 sw_if_index,
77 u8 *rewrite);
Neale Rannsb80c5362016-10-08 13:03:40 +010078/**
79 * @brief When adding a rewrite to an adjacency these are flags that
80 * apply to that rewrite
81 */
82typedef enum adj_nbr_rewrite_flag_t_
83{
84 ADJ_NBR_REWRITE_FLAG_NONE,
85
86 /**
87 * An indication that the rewrite is incomplete, i.e. that it describes the
88 * ARP/ND rewrite when probing.
89 */
90 ADJ_NBR_REWRITE_FLAG_INCOMPLETE = ADJ_NBR_REWRITE_FLAG_NONE,
91
92 /**
93 * An indication that the rewrite is complete, i.e. that it fully describes
94 * the link-layer addressing for the desintation.
95 * The opposite of this is an incomplete rewrite that describes the ARP/ND
96 * rewrite when probing.
97 */
98 ADJ_NBR_REWRITE_FLAG_COMPLETE = (1 << 0),
99} adj_nbr_rewrite_flag_t;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100100
101/**
102 * @brief
103 * Update the rewrite string for an existing adjacecny.
104 *
105 * @param
106 * The index of the adj to update
107 *
108 * @param
109 * The new rewrite
110 */
111extern void adj_nbr_update_rewrite(adj_index_t adj_index,
Neale Rannsb80c5362016-10-08 13:03:40 +0100112 adj_nbr_rewrite_flag_t flags,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100113 u8 *rewrite);
114
115/**
116 * @brief
117 * Format aa incomplete neigbour (ARP) adjacency
118 */
119extern u8* format_adj_nbr_incomplete(u8* s, va_list *ap);
120
121/**
122 * @brief
123 * Format a neigbour (REWRITE) adjacency
124 */
125extern u8* format_adj_nbr(u8* s, va_list *ap);
126
127/**
Neale Rannsb80c5362016-10-08 13:03:40 +0100128 * @brief Walk the neighbour Adjacencies on a given interface
129 */
130extern void adj_nbr_walk (u32 sw_if_index,
131 fib_protocol_t adj_nh_proto,
132 adj_walk_cb_t cb,
133 void *ctx);
134/**
135 * @brief Walk the neighbour Adjacencies on a given interface with a given next-hop
136 */
137void
138adj_nbr_walk_nh (u32 sw_if_index,
139 fib_protocol_t adj_nh_proto,
140 const ip46_address_t *nh,
141 adj_walk_cb_t cb,
142 void *ctx);
143
144/**
145 * @brief Walk adjacencies on a link with a given v4 next-hop.
146 * that is visit the adjacencies with different link types.
147 */
148void
149adj_nbr_walk_nh4 (u32 sw_if_index,
150 const ip4_address_t *addr,
151 adj_walk_cb_t cb,
152 void *ctx);
153
154/**
155 * @brief Walk adjacencies on a link with a given v6 next-hop.
156 * that is visit the adjacencies with different link types.
157 */
158void
159adj_nbr_walk_nh6 (u32 sw_if_index,
160 const ip6_address_t *addr,
161 adj_walk_cb_t cb,
162 void *ctx);
163
164/**
Florin Corasf9d05682018-04-26 08:26:52 -0700165 * @brief Lookup neighbor adjancency.
166 */
167adj_index_t
168adj_nbr_find (fib_protocol_t nh_proto,
169 vnet_link_t link_type,
170 const ip46_address_t *nh_addr,
171 u32 sw_if_index);
172/**
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100173 * @brief
174 * Module initialisation
175 */
176extern void adj_nbr_module_init(void);
177
178/**
179 * @brief
180 * Return the size of the adjacency database. for testing purposes
181 */
182extern u32 adj_nbr_db_size(void);
183
184#endif