blob: 3dbd7b3b8e8b4381ec127e495c330dab52e294a9 [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>
Ed Warnickecb9cada2015-12-08 15:45:58 -070058
Dave Barach6f9bca22016-04-30 10:25:32 -040059/** @brief Common (IP4/IP6) next index stored in adjacency. */
Dave Barachd7cb1b52016-12-09 09:52:16 -050060typedef enum
61{
Dave Barach6f9bca22016-04-30 10:25:32 -040062 /** Adjacency to drop this packet. */
Ed Warnickecb9cada2015-12-08 15:45:58 -070063 IP_LOOKUP_NEXT_DROP,
Dave Barach6f9bca22016-04-30 10:25:32 -040064 /** Adjacency to punt this packet. */
Ed Warnickecb9cada2015-12-08 15:45:58 -070065 IP_LOOKUP_NEXT_PUNT,
66
Dave Barach6f9bca22016-04-30 10:25:32 -040067 /** This packet is for one of our own IP addresses. */
Ed Warnickecb9cada2015-12-08 15:45:58 -070068 IP_LOOKUP_NEXT_LOCAL,
69
Neale Ranns0bfe5d82016-08-25 15:29:12 +010070 /** This packet matches an "incomplete adjacency" and packets
Ed Warnickecb9cada2015-12-08 15:45:58 -070071 need to be passed to ARP to find rewrite string for
72 this destination. */
73 IP_LOOKUP_NEXT_ARP,
74
Neale Ranns0bfe5d82016-08-25 15:29:12 +010075 /** This packet matches an "interface route" and packets
76 need to be passed to ARP to find rewrite string for
77 this destination. */
78 IP_LOOKUP_NEXT_GLEAN,
79
Dave Barach6f9bca22016-04-30 10:25:32 -040080 /** This packet is to be rewritten and forwarded to the next
Ed Warnickecb9cada2015-12-08 15:45:58 -070081 processing node. This is typically the output interface but
82 might be another node for further output processing. */
83 IP_LOOKUP_NEXT_REWRITE,
84
Neale Ranns0bfe5d82016-08-25 15:29:12 +010085 /** This packets follow a load-balance */
86 IP_LOOKUP_NEXT_LOAD_BALANCE,
Ed Warnickecb9cada2015-12-08 15:45:58 -070087
Neale Ranns0bfe5d82016-08-25 15:29:12 +010088 /** This packets follow a mid-chain adjacency */
89 IP_LOOKUP_NEXT_MIDCHAIN,
Damjan Marionaca64c92016-04-13 09:48:56 +020090
Dave Barach6f9bca22016-04-30 10:25:32 -040091 /** This packets needs to go to ICMP error */
Ole Troan944f5482016-05-24 11:56:58 +020092 IP_LOOKUP_NEXT_ICMP_ERROR,
93
Ed Warnickecb9cada2015-12-08 15:45:58 -070094 IP_LOOKUP_N_NEXT,
95} ip_lookup_next_t;
96
Dave Barachd7cb1b52016-12-09 09:52:16 -050097typedef enum
98{
Ole Troanf0f85222016-06-14 21:12:32 +020099 IP4_LOOKUP_N_NEXT = IP_LOOKUP_N_NEXT,
100} ip4_lookup_next_t;
101
Dave Barachd7cb1b52016-12-09 09:52:16 -0500102typedef enum
103{
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100104 /* Hop-by-hop header handling */
Ole Troanf0f85222016-06-14 21:12:32 +0200105 IP6_LOOKUP_NEXT_HOP_BY_HOP = IP_LOOKUP_N_NEXT,
106 IP6_LOOKUP_NEXT_ADD_HOP_BY_HOP,
107 IP6_LOOKUP_NEXT_POP_HOP_BY_HOP,
108 IP6_LOOKUP_N_NEXT,
109} ip6_lookup_next_t;
110
Damjan Marionb2707892016-04-13 11:21:07 +0200111#define IP4_LOOKUP_NEXT_NODES { \
Damjan Marionb2707892016-04-13 11:21:07 +0200112 [IP_LOOKUP_NEXT_DROP] = "ip4-drop", \
113 [IP_LOOKUP_NEXT_PUNT] = "ip4-punt", \
114 [IP_LOOKUP_NEXT_LOCAL] = "ip4-local", \
115 [IP_LOOKUP_NEXT_ARP] = "ip4-arp", \
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100116 [IP_LOOKUP_NEXT_GLEAN] = "ip4-glean", \
Neale Rannsf06aea52016-11-29 06:51:37 -0800117 [IP_LOOKUP_NEXT_REWRITE] = "ip4-rewrite", \
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100118 [IP_LOOKUP_NEXT_MIDCHAIN] = "ip4-midchain", \
119 [IP_LOOKUP_NEXT_LOAD_BALANCE] = "ip4-load-balance", \
Ole Troan944f5482016-05-24 11:56:58 +0200120 [IP_LOOKUP_NEXT_ICMP_ERROR] = "ip4-icmp-error", \
Damjan Marionb2707892016-04-13 11:21:07 +0200121}
122
123#define IP6_LOOKUP_NEXT_NODES { \
Damjan Marionb2707892016-04-13 11:21:07 +0200124 [IP_LOOKUP_NEXT_DROP] = "ip6-drop", \
125 [IP_LOOKUP_NEXT_PUNT] = "ip6-punt", \
126 [IP_LOOKUP_NEXT_LOCAL] = "ip6-local", \
127 [IP_LOOKUP_NEXT_ARP] = "ip6-discover-neighbor", \
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100128 [IP_LOOKUP_NEXT_GLEAN] = "ip6-glean", \
Damjan Marionb2707892016-04-13 11:21:07 +0200129 [IP_LOOKUP_NEXT_REWRITE] = "ip6-rewrite", \
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100130 [IP_LOOKUP_NEXT_MIDCHAIN] = "ip6-midchain", \
131 [IP_LOOKUP_NEXT_LOAD_BALANCE] = "ip6-load-balance", \
Ole Troan944f5482016-05-24 11:56:58 +0200132 [IP_LOOKUP_NEXT_ICMP_ERROR] = "ip6-icmp-error", \
Ole Troanf0f85222016-06-14 21:12:32 +0200133 [IP6_LOOKUP_NEXT_HOP_BY_HOP] = "ip6-hop-by-hop", \
134 [IP6_LOOKUP_NEXT_ADD_HOP_BY_HOP] = "ip6-add-hop-by-hop", \
135 [IP6_LOOKUP_NEXT_POP_HOP_BY_HOP] = "ip6-pop-hop-by-hop", \
Damjan Marionb2707892016-04-13 11:21:07 +0200136}
137
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700138/** Flow hash configuration */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700139#define IP_FLOW_HASH_SRC_ADDR (1<<0)
140#define IP_FLOW_HASH_DST_ADDR (1<<1)
141#define IP_FLOW_HASH_PROTO (1<<2)
142#define IP_FLOW_HASH_SRC_PORT (1<<3)
143#define IP_FLOW_HASH_DST_PORT (1<<4)
144#define IP_FLOW_HASH_REVERSE_SRC_DST (1<<5)
145
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700146/** Default: 5-tuple without the "reverse" bit */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700147#define IP_FLOW_HASH_DEFAULT (0x1F)
148
149#define foreach_flow_hash_bit \
150_(src, IP_FLOW_HASH_SRC_ADDR) \
151_(dst, IP_FLOW_HASH_DST_ADDR) \
152_(sport, IP_FLOW_HASH_SRC_PORT) \
153_(dport, IP_FLOW_HASH_DST_PORT) \
154_(proto, IP_FLOW_HASH_PROTO) \
155_(reverse, IP_FLOW_HASH_REVERSE_SRC_DST)
156
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100157/**
158 * A flow hash configuration is a mask of the flow hash options
159 */
160typedef u32 flow_hash_config_t;
161
Neale Ranns5e575b12016-10-03 09:40:25 +0100162/**
163 * Forward delcartion
164 */
165struct ip_adjacency_t_;
166
167/**
168 * @brief A function type for post-rewrite fixups on midchain adjacency
169 */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500170typedef void (*adj_midchain_fixup_t) (vlib_main_t * vm,
171 struct ip_adjacency_t_ * adj,
172 vlib_buffer_t * b0);
Neale Ranns5e575b12016-10-03 09:40:25 +0100173
Neale Ranns19c68d22016-12-07 15:38:14 +0000174/**
175 * @brief Flags on an IP adjacency
176 */
177typedef enum ip_adjacency_flags_t_
178{
179 /**
180 * Currently a sync walk is active. Used to prevent re-entrant walking
181 */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500182 IP_ADJ_SYNC_WALK_ACTIVE = (1 << 0),
Neale Ranns19c68d22016-12-07 15:38:14 +0000183} ip_adjacency_flags_t;
184
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700185/** @brief IP unicast adjacency.
186 @note cache aligned.
187*/
Dave Barachd7cb1b52016-12-09 09:52:16 -0500188typedef struct ip_adjacency_t_
189{
190 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700191
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700192 /** Number of adjecencies in block. Greater than 1 means multipath;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700193 otherwise equal to 1. */
194 u16 n_adj;
195
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700196 /** Next hop after ip4-lookup. */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500197 union
198 {
199 ip_lookup_next_t lookup_next_index:16;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700200 u16 lookup_next_index_as_int;
201 };
202
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100203 /** Interface address index for this local/arp adjacency. */
204 u32 if_address_index;
205
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700206 /** Force re-lookup in a different FIB. ~0 => normal behavior */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500207 u16 mcast_group_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700208
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700209 /** Highest possible perf subgraph arc interposition, e.g. for ip6 ioam */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700210 u16 saved_lookup_next_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 Ranns33a7dd52016-10-07 15:14:33 +0100239 /**
240 * The recursive next-hop
241 */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500242 ip46_address_t next_hop;
Neale Ranns33a7dd52016-10-07 15:14:33 +0100243 /**
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 Ranns33a7dd52016-10-07 15:14:33 +0100247 /**
248 * The next DPO to use
249 */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500250 dpo_id_t next_dpo;
Neale Ranns33a7dd52016-10-07 15:14:33 +0100251 /**
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 Ranns33a7dd52016-10-07 15:14:33 +0100256 /**
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/* IP multicast adjacency. */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500295typedef struct
296{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700297 /* Handle for this adjacency in adjacency heap. */
298 u32 heap_handle;
299
300 /* Number of adjecencies in block. */
301 u32 n_adj;
302
303 /* Rewrite string. */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500304 vnet_declare_rewrite (64 - 2 * sizeof (u32));
305}
306ip_multicast_rewrite_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700307
Dave Barachd7cb1b52016-12-09 09:52:16 -0500308typedef struct
309{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700310 /* ip4-multicast-rewrite next index. */
311 u32 next_index;
312
313 u8 n_rewrite_bytes;
314
Dave Barachd7cb1b52016-12-09 09:52:16 -0500315 u8 rewrite_string[64 - 1 * sizeof (u32) - 1 * sizeof (u8)];
316}
317ip_multicast_rewrite_string_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700318
Dave Barachd7cb1b52016-12-09 09:52:16 -0500319typedef struct
320{
321 ip_multicast_rewrite_t *rewrite_heap;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700322
Dave Barachd7cb1b52016-12-09 09:52:16 -0500323 ip_multicast_rewrite_string_t *rewrite_strings;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700324
325 /* Negative rewrite string index; >= 0 sw_if_index.
326 Sorted. Used to hash. */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500327 i32 **adjacency_id_vector;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700328
Dave Barachd7cb1b52016-12-09 09:52:16 -0500329 uword *adjacency_by_id_vector;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700330} ip_multicast_lookup_main_t;
331
Dave Barachd7cb1b52016-12-09 09:52:16 -0500332typedef struct
333{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700334 /* Key for mhash; in fact, just a byte offset into mhash key vector. */
335 u32 address_key;
336
337 /* Interface which has this address. */
338 u32 sw_if_index;
339
340 /* Adjacency for neighbor probe (ARP) for this interface address. */
341 u32 neighbor_probe_adj_index;
342
343 /* Address (prefix) length for this interface. */
344 u16 address_length;
345
346 /* Will be used for something eventually. Primary vs. secondary? */
347 u16 flags;
348
349 /* Next and previous pointers for doubly linked list of
350 addresses per software interface. */
351 u32 next_this_sw_interface;
352 u32 prev_this_sw_interface;
353} ip_interface_address_t;
354
Dave Barachd7cb1b52016-12-09 09:52:16 -0500355typedef enum
356{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700357 IP_LOCAL_NEXT_DROP,
358 IP_LOCAL_NEXT_PUNT,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700359 IP_LOCAL_NEXT_UDP_LOOKUP,
360 IP_LOCAL_NEXT_ICMP,
361 IP_LOCAL_N_NEXT,
362} ip_local_next_t;
363
364struct ip_lookup_main_t;
365
Dave Barachd7cb1b52016-12-09 09:52:16 -0500366typedef struct ip_lookup_main_t
367{
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100368 /* Adjacency heap. */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500369 ip_adjacency_t *adjacency_heap;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700370
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100371 /** load-balance packet/byte counters indexed by LB index. */
372 vlib_combined_counter_main_t load_balance_counters;
Dave Barachdbf19ca2016-03-15 10:21:54 +0100373
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700374 /** Pool of addresses that are assigned to interfaces. */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500375 ip_interface_address_t *if_address_pool;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700376
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700377 /** Hash table mapping address to index in interface address pool. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700378 mhash_t address_to_if_address_index;
379
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700380 /** Head of doubly linked list of interface addresses for each software interface.
Ed Warnickecb9cada2015-12-08 15:45:58 -0700381 ~0 means this interface has no address. */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500382 u32 *if_address_pool_index_by_sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700383
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700384 /** First table index to use for this interface, ~0 => none */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500385 u32 *classify_table_index_by_sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700386
Damjan Marion8b3191e2016-11-09 19:54:20 +0100387 /** Feature arc indices */
388 u8 mcast_feature_arc_index;
389 u8 ucast_feature_arc_index;
390 u8 output_feature_arc_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700391
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700392 /** Number of bytes in a fib result. Must be at least
Ed Warnickecb9cada2015-12-08 15:45:58 -0700393 sizeof (uword). First word is always adjacency index. */
394 u32 fib_result_n_bytes, fib_result_n_words;
395
Dave Barachd7cb1b52016-12-09 09:52:16 -0500396 format_function_t *format_fib_result;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700397
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700398 /** 1 for ip6; 0 for ip4. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700399 u32 is_ip6;
400
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700401 /** Either format_ip4_address_and_length or format_ip6_address_and_length. */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500402 format_function_t *format_address_and_length;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700403
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700404 /** Special adjacency format functions */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500405 format_function_t **special_adjacency_format_functions;
Dave Barach6f9bca22016-04-30 10:25:32 -0400406
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700407 /** Table mapping ip protocol to ip[46]-local node next index. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700408 u8 local_next_by_ip_protocol[256];
409
Keith Burns (alagalah)79b5f632016-08-02 05:40:20 -0700410 /** IP_BUILTIN_PROTOCOL_{TCP,UDP,ICMP,OTHER} by protocol in IP header. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700411 u8 builtin_protocol_by_ip_protocol[256];
412} ip_lookup_main_t;
413
414always_inline ip_adjacency_t *
Dave Barachd7cb1b52016-12-09 09:52:16 -0500415ip_get_adjacency (ip_lookup_main_t * lm, u32 adj_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700416{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500417 ip_adjacency_t *adj;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700418
Dave Barachb2ef4dd2016-03-23 08:56:01 -0400419 adj = vec_elt_at_index (lm->adjacency_heap, adj_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700420
Ed Warnickecb9cada2015-12-08 15:45:58 -0700421 return adj;
422}
423
424#define ip_prefetch_adjacency(lm,adj_index,type) \
425do { \
426 ip_adjacency_t * _adj = (lm)->adjacency_heap + (adj_index); \
427 CLIB_PREFETCH (_adj, sizeof (_adj[0]), type); \
428} while (0)
429
Ed Warnickecb9cada2015-12-08 15:45:58 -0700430/* Create new block of given number of contiguous adjacencies. */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500431ip_adjacency_t *ip_add_adjacency (ip_lookup_main_t * lm,
432 ip_adjacency_t * adj,
433 u32 n_adj, u32 * adj_index_result);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700434
Dave Barachd7cb1b52016-12-09 09:52:16 -0500435clib_error_t *ip_interface_address_add_del (ip_lookup_main_t * lm,
436 u32 sw_if_index,
437 void *address,
438 u32 address_length,
439 u32 is_del, u32 * result_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700440
Dave Barachd7cb1b52016-12-09 09:52:16 -0500441u8 *format_ip_flow_hash_config (u8 * s, va_list * args);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100442
Ed Warnickecb9cada2015-12-08 15:45:58 -0700443always_inline ip_interface_address_t *
Dave Barachd7cb1b52016-12-09 09:52:16 -0500444ip_get_interface_address (ip_lookup_main_t * lm, void *addr_fib)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700445{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500446 uword *p = mhash_get (&lm->address_to_if_address_index, addr_fib);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700447 return p ? pool_elt_at_index (lm->if_address_pool, p[0]) : 0;
448}
449
Dave Barachd7cb1b52016-12-09 09:52:16 -0500450u32 fib_table_id_find_fib_index (fib_protocol_t proto, u32 table_id);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100451
Ed Warnickecb9cada2015-12-08 15:45:58 -0700452always_inline void *
Dave Barachd7cb1b52016-12-09 09:52:16 -0500453ip_interface_address_get_address (ip_lookup_main_t * lm,
454 ip_interface_address_t * a)
455{
456 return mhash_key_to_mem (&lm->address_to_if_address_index, a->address_key);
457}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700458
Dave Barachd7cb1b52016-12-09 09:52:16 -0500459/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700460#define foreach_ip_interface_address(lm,a,sw_if_index,loop,body) \
461do { \
462 vnet_main_t *_vnm = vnet_get_main(); \
463 u32 _sw_if_index = sw_if_index; \
464 vnet_sw_interface_t *_swif; \
465 _swif = vnet_get_sw_interface (_vnm, _sw_if_index); \
466 \
467 /* \
468 * Loop => honor unnumbered interface addressing. \
469 */ \
470 if (loop && _swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED) \
471 _sw_if_index = _swif->unnumbered_sw_if_index; \
472 u32 _ia = \
473 (vec_len((lm)->if_address_pool_index_by_sw_if_index) \
474 > (_sw_if_index)) \
475 ? vec_elt ((lm)->if_address_pool_index_by_sw_if_index, \
476 (_sw_if_index)) : (u32)~0; \
477 ip_interface_address_t * _a; \
478 while (_ia != ~0) \
479 { \
480 _a = pool_elt_at_index ((lm)->if_address_pool, _ia); \
481 _ia = _a->next_this_sw_interface; \
482 (a) = _a; \
483 body; \
484 } \
485} while (0)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500486/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700487
488void ip_lookup_init (ip_lookup_main_t * lm, u32 ip_lookup_node_index);
489
Ed Warnickecb9cada2015-12-08 15:45:58 -0700490#endif /* included_ip_lookup_h */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500491
492/*
493 * fd.io coding-style-patch-verification: ON
494 *
495 * Local Variables:
496 * eval: (c-set-style "gnu")
497 * End:
498 */