blob: f76ddb37863e280abacda1d7f46c64cf3e1c7a76 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * Copyright (c) 2015 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 * ip/ip_lookup.h: ip (4 or 6) lookup structures, adjacencies, ...
17 *
18 * Copyright (c) 2008 Eliot Dresselhaus
19 *
20 * Permission is hereby granted, free of charge, to any person obtaining
21 * a copy of this software and associated documentation files (the
22 * "Software"), to deal in the Software without restriction, including
23 * without limitation the rights to use, copy, modify, merge, publish,
24 * distribute, sublicense, and/or sell copies of the Software, and to
25 * permit persons to whom the Software is furnished to do so, subject to
26 * the following conditions:
27 *
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
30 *
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 */
39
Chris Luke16bcf7d2016-09-01 14:31:46 -040040/**
41 * @file
42 * Definitions for all things IP (v4|v6) unicast and multicast lookup related.
43 *
44 * - Adjacency definitions and registration.
45 * - Callbacks on route add.
46 * - Callbacks on interface address change.
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -070047 */
Ed Warnickecb9cada2015-12-08 15:45:58 -070048#ifndef included_ip_lookup_h
49#define included_ip_lookup_h
50
51#include <vnet/vnet.h>
52#include <vlib/buffer.h>
Damjan Marion102ec522016-03-29 13:18:17 +020053#include <vnet/ip/ip4_packet.h>
Pierre Pfister1dabaaf2016-04-25 14:15:15 +010054#include <vnet/ip/ip6_packet.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010055#include <vnet/fib/fib_node.h>
56#include <vnet/dpo/dpo.h>
Damjan Marion22311502016-10-28 20:30:15 +020057#include <vnet/feature/feature.h>
Neale Ranns2e7fbcc2017-03-15 04:22:25 -070058#include <vnet/rewrite.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070059
Dave Barach6f9bca22016-04-30 10:25:32 -040060/** @brief Common (IP4/IP6) next index stored in adjacency. */
Dave Barachd7cb1b52016-12-09 09:52:16 -050061typedef enum
62{
Dave Barach6f9bca22016-04-30 10:25:32 -040063 /** Adjacency to drop this packet. */
Ed Warnickecb9cada2015-12-08 15:45:58 -070064 IP_LOOKUP_NEXT_DROP,
Dave Barach6f9bca22016-04-30 10:25:32 -040065 /** Adjacency to punt this packet. */
Ed Warnickecb9cada2015-12-08 15:45:58 -070066 IP_LOOKUP_NEXT_PUNT,
67
Dave Barach6f9bca22016-04-30 10:25:32 -040068 /** This packet is for one of our own IP addresses. */
Ed Warnickecb9cada2015-12-08 15:45:58 -070069 IP_LOOKUP_NEXT_LOCAL,
70
Neale Ranns0bfe5d82016-08-25 15:29:12 +010071 /** This packet matches an "incomplete adjacency" and packets
Ed Warnickecb9cada2015-12-08 15:45:58 -070072 need to be passed to ARP to find rewrite string for
73 this destination. */
74 IP_LOOKUP_NEXT_ARP,
75
Neale Ranns0bfe5d82016-08-25 15:29:12 +010076 /** This packet matches an "interface route" and packets
77 need to be passed to ARP to find rewrite string for
78 this destination. */
79 IP_LOOKUP_NEXT_GLEAN,
80
Dave Barach6f9bca22016-04-30 10:25:32 -040081 /** This packet is to be rewritten and forwarded to the next
Ed Warnickecb9cada2015-12-08 15:45:58 -070082 processing node. This is typically the output interface but
83 might be another node for further output processing. */
84 IP_LOOKUP_NEXT_REWRITE,
85
Neale Ranns0bfe5d82016-08-25 15:29:12 +010086 /** This packets follow a load-balance */
87 IP_LOOKUP_NEXT_LOAD_BALANCE,
Ed Warnickecb9cada2015-12-08 15:45:58 -070088
Neale Ranns0bfe5d82016-08-25 15:29:12 +010089 /** This packets follow a mid-chain adjacency */
90 IP_LOOKUP_NEXT_MIDCHAIN,
Damjan Marionaca64c92016-04-13 09:48:56 +020091
Dave Barach6f9bca22016-04-30 10:25:32 -040092 /** This packets needs to go to ICMP error */
Ole Troan944f5482016-05-24 11:56:58 +020093 IP_LOOKUP_NEXT_ICMP_ERROR,
94
Neale Ranns32e1c012016-11-22 17:07:28 +000095 /** Multicast Adjacency. */
96 IP_LOOKUP_NEXT_MCAST,
97
Ed Warnickecb9cada2015-12-08 15:45:58 -070098 IP_LOOKUP_N_NEXT,
99} ip_lookup_next_t;
100
Dave Barachd7cb1b52016-12-09 09:52:16 -0500101typedef enum
102{
Ole Troanf0f85222016-06-14 21:12:32 +0200103 IP4_LOOKUP_N_NEXT = IP_LOOKUP_N_NEXT,
104} ip4_lookup_next_t;
105
Dave Barachd7cb1b52016-12-09 09:52:16 -0500106typedef enum
107{
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100108 /* Hop-by-hop header handling */
Ole Troanf0f85222016-06-14 21:12:32 +0200109 IP6_LOOKUP_NEXT_HOP_BY_HOP = IP_LOOKUP_N_NEXT,
110 IP6_LOOKUP_NEXT_ADD_HOP_BY_HOP,
111 IP6_LOOKUP_NEXT_POP_HOP_BY_HOP,
112 IP6_LOOKUP_N_NEXT,
113} ip6_lookup_next_t;
114
Damjan Marionb2707892016-04-13 11:21:07 +0200115#define IP4_LOOKUP_NEXT_NODES { \
Damjan Marionb2707892016-04-13 11:21:07 +0200116 [IP_LOOKUP_NEXT_DROP] = "ip4-drop", \
117 [IP_LOOKUP_NEXT_PUNT] = "ip4-punt", \
118 [IP_LOOKUP_NEXT_LOCAL] = "ip4-local", \
119 [IP_LOOKUP_NEXT_ARP] = "ip4-arp", \
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100120 [IP_LOOKUP_NEXT_GLEAN] = "ip4-glean", \
Neale Rannsf06aea52016-11-29 06:51:37 -0800121 [IP_LOOKUP_NEXT_REWRITE] = "ip4-rewrite", \
Neale Ranns32e1c012016-11-22 17:07:28 +0000122 [IP_LOOKUP_NEXT_MCAST] = "ip4-rewrite-mcast", \
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100123 [IP_LOOKUP_NEXT_MIDCHAIN] = "ip4-midchain", \
124 [IP_LOOKUP_NEXT_LOAD_BALANCE] = "ip4-load-balance", \
Ole Troan944f5482016-05-24 11:56:58 +0200125 [IP_LOOKUP_NEXT_ICMP_ERROR] = "ip4-icmp-error", \
Damjan Marionb2707892016-04-13 11:21:07 +0200126}
127
128#define IP6_LOOKUP_NEXT_NODES { \
Damjan Marionb2707892016-04-13 11:21:07 +0200129 [IP_LOOKUP_NEXT_DROP] = "ip6-drop", \
130 [IP_LOOKUP_NEXT_PUNT] = "ip6-punt", \
131 [IP_LOOKUP_NEXT_LOCAL] = "ip6-local", \
132 [IP_LOOKUP_NEXT_ARP] = "ip6-discover-neighbor", \
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100133 [IP_LOOKUP_NEXT_GLEAN] = "ip6-glean", \
Damjan Marionb2707892016-04-13 11:21:07 +0200134 [IP_LOOKUP_NEXT_REWRITE] = "ip6-rewrite", \
Neale Ranns32e1c012016-11-22 17:07:28 +0000135 [IP_LOOKUP_NEXT_MCAST] = "ip6-rewrite-mcast", \
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100136 [IP_LOOKUP_NEXT_MIDCHAIN] = "ip6-midchain", \
137 [IP_LOOKUP_NEXT_LOAD_BALANCE] = "ip6-load-balance", \
Ole Troan944f5482016-05-24 11:56:58 +0200138 [IP_LOOKUP_NEXT_ICMP_ERROR] = "ip6-icmp-error", \
Ole Troanf0f85222016-06-14 21:12:32 +0200139 [IP6_LOOKUP_NEXT_HOP_BY_HOP] = "ip6-hop-by-hop", \
140 [IP6_LOOKUP_NEXT_ADD_HOP_BY_HOP] = "ip6-add-hop-by-hop", \
141 [IP6_LOOKUP_NEXT_POP_HOP_BY_HOP] = "ip6-pop-hop-by-hop", \
Damjan Marionb2707892016-04-13 11:21:07 +0200142}
143
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700144/** Flow hash configuration */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700145#define IP_FLOW_HASH_SRC_ADDR (1<<0)
146#define IP_FLOW_HASH_DST_ADDR (1<<1)
147#define IP_FLOW_HASH_PROTO (1<<2)
148#define IP_FLOW_HASH_SRC_PORT (1<<3)
149#define IP_FLOW_HASH_DST_PORT (1<<4)
150#define IP_FLOW_HASH_REVERSE_SRC_DST (1<<5)
151
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700152/** Default: 5-tuple without the "reverse" bit */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700153#define IP_FLOW_HASH_DEFAULT (0x1F)
154
155#define foreach_flow_hash_bit \
156_(src, IP_FLOW_HASH_SRC_ADDR) \
157_(dst, IP_FLOW_HASH_DST_ADDR) \
158_(sport, IP_FLOW_HASH_SRC_PORT) \
159_(dport, IP_FLOW_HASH_DST_PORT) \
160_(proto, IP_FLOW_HASH_PROTO) \
161_(reverse, IP_FLOW_HASH_REVERSE_SRC_DST)
162
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100163/**
164 * A flow hash configuration is a mask of the flow hash options
165 */
166typedef u32 flow_hash_config_t;
167
Neale Ranns5e575b12016-10-03 09:40:25 +0100168/**
169 * Forward delcartion
170 */
171struct ip_adjacency_t_;
172
173/**
174 * @brief A function type for post-rewrite fixups on midchain adjacency
175 */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500176typedef void (*adj_midchain_fixup_t) (vlib_main_t * vm,
177 struct ip_adjacency_t_ * adj,
178 vlib_buffer_t * b0);
Neale Ranns5e575b12016-10-03 09:40:25 +0100179
Neale Ranns19c68d22016-12-07 15:38:14 +0000180/**
181 * @brief Flags on an IP adjacency
182 */
183typedef enum ip_adjacency_flags_t_
184{
185 /**
186 * Currently a sync walk is active. Used to prevent re-entrant walking
187 */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500188 IP_ADJ_SYNC_WALK_ACTIVE = (1 << 0),
Neale Ranns19c68d22016-12-07 15:38:14 +0000189} ip_adjacency_flags_t;
190
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700191/** @brief IP unicast adjacency.
192 @note cache aligned.
193*/
Dave Barachd7cb1b52016-12-09 09:52:16 -0500194typedef struct ip_adjacency_t_
195{
196 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700197
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700198 /** Number of adjecencies in block. Greater than 1 means multipath;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700199 otherwise equal to 1. */
200 u16 n_adj;
201
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700202 /** Next hop after ip4-lookup. */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500203 union
204 {
205 ip_lookup_next_t lookup_next_index:16;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700206 u16 lookup_next_index_as_int;
207 };
208
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100209 /** Interface address index for this local/arp adjacency. */
210 u32 if_address_index;
211
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100212 /*
213 * link/ether-type
214 */
Neale Ranns924d03a2016-10-19 08:25:46 +0100215 vnet_link_t ia_link;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100216 u8 ia_nh_proto;
217
Dave Barachd7cb1b52016-12-09 09:52:16 -0500218 union
219 {
Neale Ranns33a7dd52016-10-07 15:14:33 +0100220 /**
221 * IP_LOOKUP_NEXT_ARP/IP_LOOKUP_NEXT_REWRITE
222 *
223 * neighbour adjacency sub-type;
224 */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500225 struct
226 {
227 ip46_address_t next_hop;
228 } nbr;
Neale Ranns33a7dd52016-10-07 15:14:33 +0100229 /**
230 * IP_LOOKUP_NEXT_MIDCHAIN
231 *
232 * A nbr adj that is also recursive. Think tunnels.
233 * A nbr adj can transition to be of type MDICHAIN
234 * so be sure to leave the two structs with the next_hop
235 * fields aligned.
236 */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500237 struct
238 {
Neale Ranns32e1c012016-11-22 17:07:28 +0000239 /**
240 * The recursive next-hop
241 */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500242 ip46_address_t next_hop;
Neale Ranns32e1c012016-11-22 17:07:28 +0000243 /**
244 * The node index of the tunnel's post rewrite/TX function.
245 */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500246 u32 tx_function_node;
Neale Ranns32e1c012016-11-22 17:07:28 +0000247 /**
248 * The next DPO to use
249 */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500250 dpo_id_t next_dpo;
Neale Ranns32e1c012016-11-22 17:07:28 +0000251 /**
252 * A function to perform the post-rewrite fixup
253 */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500254 adj_midchain_fixup_t fixup_func;
255 } midchain;
Neale Ranns32e1c012016-11-22 17:07:28 +0000256 /**
257 * IP_LOOKUP_NEXT_GLEAN
258 *
259 * Glean the address to ARP for from the packet's destination
260 */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500261 struct
262 {
263 ip46_address_t receive_addr;
264 } glean;
Neale Ranns33a7dd52016-10-07 15:14:33 +0100265 } sub_type;
Damjan Marionf1bd8be2016-03-29 13:06:36 +0200266
Dave Barachd7cb1b52016-12-09 09:52:16 -0500267 CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
Dave Barachdbf19ca2016-03-15 10:21:54 +0100268
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100269 /* Rewrite in second/third cache lines */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500270 vnet_declare_rewrite (VLIB_BUFFER_PRE_DATA_SIZE);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100271
Neale Ranns5e575b12016-10-03 09:40:25 +0100272 /*
273 * member not accessed in the data plane are relgated to the
274 * remaining cachelines
275 */
276 fib_node_t ia_node;
Neale Ranns19c68d22016-12-07 15:38:14 +0000277
278 /**
279 * Flags on the adjacency
280 */
281 ip_adjacency_flags_t ia_flags;
282
Ed Warnickecb9cada2015-12-08 15:45:58 -0700283} ip_adjacency_t;
284
Dave Barachd7cb1b52016-12-09 09:52:16 -0500285STATIC_ASSERT ((STRUCT_OFFSET_OF (ip_adjacency_t, cacheline0) == 0),
286 "IP adjacency cachline 0 is not offset");
287STATIC_ASSERT ((STRUCT_OFFSET_OF (ip_adjacency_t, cacheline1) ==
288 CLIB_CACHE_LINE_BYTES),
289 "IP adjacency cachline 1 is more than one cachline size offset");
Dave Barachdbf19ca2016-03-15 10:21:54 +0100290
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100291/* An all zeros address */
292extern const ip46_address_t zero_addr;
Dave Barachdbf19ca2016-03-15 10:21:54 +0100293
Ed Warnickecb9cada2015-12-08 15:45:58 -0700294
Dave Barachd7cb1b52016-12-09 09:52:16 -0500295typedef struct
296{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700297 /* Key for mhash; in fact, just a byte offset into mhash key vector. */
298 u32 address_key;
299
300 /* Interface which has this address. */
301 u32 sw_if_index;
302
303 /* Adjacency for neighbor probe (ARP) for this interface address. */
304 u32 neighbor_probe_adj_index;
305
306 /* Address (prefix) length for this interface. */
307 u16 address_length;
308
309 /* Will be used for something eventually. Primary vs. secondary? */
310 u16 flags;
311
312 /* Next and previous pointers for doubly linked list of
313 addresses per software interface. */
314 u32 next_this_sw_interface;
315 u32 prev_this_sw_interface;
316} ip_interface_address_t;
317
Dave Barachd7cb1b52016-12-09 09:52:16 -0500318typedef enum
319{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700320 IP_LOCAL_NEXT_DROP,
321 IP_LOCAL_NEXT_PUNT,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700322 IP_LOCAL_NEXT_UDP_LOOKUP,
323 IP_LOCAL_NEXT_ICMP,
324 IP_LOCAL_N_NEXT,
325} ip_local_next_t;
326
327struct ip_lookup_main_t;
328
Dave Barachd7cb1b52016-12-09 09:52:16 -0500329typedef struct ip_lookup_main_t
330{
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100331 /* Adjacency heap. */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500332 ip_adjacency_t *adjacency_heap;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700333
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100334 /** load-balance packet/byte counters indexed by LB index. */
335 vlib_combined_counter_main_t load_balance_counters;
Dave Barachdbf19ca2016-03-15 10:21:54 +0100336
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700337 /** Pool of addresses that are assigned to interfaces. */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500338 ip_interface_address_t *if_address_pool;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700339
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700340 /** Hash table mapping address to index in interface address pool. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700341 mhash_t address_to_if_address_index;
342
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700343 /** Head of doubly linked list of interface addresses for each software interface.
Ed Warnickecb9cada2015-12-08 15:45:58 -0700344 ~0 means this interface has no address. */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500345 u32 *if_address_pool_index_by_sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700346
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700347 /** First table index to use for this interface, ~0 => none */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500348 u32 *classify_table_index_by_sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700349
Damjan Marion8b3191e2016-11-09 19:54:20 +0100350 /** Feature arc indices */
351 u8 mcast_feature_arc_index;
352 u8 ucast_feature_arc_index;
353 u8 output_feature_arc_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700354
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700355 /** Number of bytes in a fib result. Must be at least
Ed Warnickecb9cada2015-12-08 15:45:58 -0700356 sizeof (uword). First word is always adjacency index. */
357 u32 fib_result_n_bytes, fib_result_n_words;
358
Dave Barachd7cb1b52016-12-09 09:52:16 -0500359 format_function_t *format_fib_result;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700360
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700361 /** 1 for ip6; 0 for ip4. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700362 u32 is_ip6;
363
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700364 /** Either format_ip4_address_and_length or format_ip6_address_and_length. */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500365 format_function_t *format_address_and_length;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700366
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700367 /** Special adjacency format functions */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500368 format_function_t **special_adjacency_format_functions;
Dave Barach6f9bca22016-04-30 10:25:32 -0400369
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700370 /** Table mapping ip protocol to ip[46]-local node next index. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700371 u8 local_next_by_ip_protocol[256];
372
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700373 /** IP_BUILTIN_PROTOCOL_{TCP,UDP,ICMP,OTHER} by protocol in IP header. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700374 u8 builtin_protocol_by_ip_protocol[256];
375} ip_lookup_main_t;
376
377always_inline ip_adjacency_t *
Dave Barachd7cb1b52016-12-09 09:52:16 -0500378ip_get_adjacency (ip_lookup_main_t * lm, u32 adj_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700379{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500380 ip_adjacency_t *adj;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700381
Dave Barachb2ef4dd2016-03-23 08:56:01 -0400382 adj = vec_elt_at_index (lm->adjacency_heap, adj_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700383
Ed Warnickecb9cada2015-12-08 15:45:58 -0700384 return adj;
385}
386
387#define ip_prefetch_adjacency(lm,adj_index,type) \
388do { \
389 ip_adjacency_t * _adj = (lm)->adjacency_heap + (adj_index); \
390 CLIB_PREFETCH (_adj, sizeof (_adj[0]), type); \
391} while (0)
392
Dave Barachd7cb1b52016-12-09 09:52:16 -0500393clib_error_t *ip_interface_address_add_del (ip_lookup_main_t * lm,
394 u32 sw_if_index,
395 void *address,
396 u32 address_length,
397 u32 is_del, u32 * result_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700398
Dave Barachd7cb1b52016-12-09 09:52:16 -0500399u8 *format_ip_flow_hash_config (u8 * s, va_list * args);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100400
Ed Warnickecb9cada2015-12-08 15:45:58 -0700401always_inline ip_interface_address_t *
Dave Barachd7cb1b52016-12-09 09:52:16 -0500402ip_get_interface_address (ip_lookup_main_t * lm, void *addr_fib)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700403{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500404 uword *p = mhash_get (&lm->address_to_if_address_index, addr_fib);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700405 return p ? pool_elt_at_index (lm->if_address_pool, p[0]) : 0;
406}
407
Dave Barachd7cb1b52016-12-09 09:52:16 -0500408u32 fib_table_id_find_fib_index (fib_protocol_t proto, u32 table_id);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100409
Ed Warnickecb9cada2015-12-08 15:45:58 -0700410always_inline void *
Dave Barachd7cb1b52016-12-09 09:52:16 -0500411ip_interface_address_get_address (ip_lookup_main_t * lm,
412 ip_interface_address_t * a)
413{
414 return mhash_key_to_mem (&lm->address_to_if_address_index, a->address_key);
415}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700416
Dave Barachd7cb1b52016-12-09 09:52:16 -0500417/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700418#define foreach_ip_interface_address(lm,a,sw_if_index,loop,body) \
419do { \
420 vnet_main_t *_vnm = vnet_get_main(); \
421 u32 _sw_if_index = sw_if_index; \
422 vnet_sw_interface_t *_swif; \
423 _swif = vnet_get_sw_interface (_vnm, _sw_if_index); \
424 \
425 /* \
426 * Loop => honor unnumbered interface addressing. \
427 */ \
428 if (loop && _swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED) \
429 _sw_if_index = _swif->unnumbered_sw_if_index; \
430 u32 _ia = \
431 (vec_len((lm)->if_address_pool_index_by_sw_if_index) \
432 > (_sw_if_index)) \
433 ? vec_elt ((lm)->if_address_pool_index_by_sw_if_index, \
434 (_sw_if_index)) : (u32)~0; \
435 ip_interface_address_t * _a; \
436 while (_ia != ~0) \
437 { \
438 _a = pool_elt_at_index ((lm)->if_address_pool, _ia); \
439 _ia = _a->next_this_sw_interface; \
440 (a) = _a; \
441 body; \
442 } \
443} while (0)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500444/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700445
446void ip_lookup_init (ip_lookup_main_t * lm, u32 ip_lookup_node_index);
447
Ed Warnickecb9cada2015-12-08 15:45:58 -0700448#endif /* included_ip_lookup_h */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500449
450/*
451 * fd.io coding-style-patch-verification: ON
452 *
453 * Local Variables:
454 * eval: (c-set-style "gnu")
455 * End:
456 */