FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
lookup.h
Go to the documentation of this file.
1 /*
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 
40 /**
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.
47  */
48 #ifndef included_ip_lookup_h
49 #define included_ip_lookup_h
50 
51 //#include <vnet/vnet.h>
52 #include <vlib/vlib.h>
53 #include <vlib/buffer.h>
54 #include <vnet/ip/ip4_packet.h>
55 #include <vnet/ip/ip6_packet.h>
56 #include <vnet/ip/ip_types.h>
57 #include <vnet/fib/fib_node.h>
58 #include <vnet/adj/adj.h>
59 #include <vnet/dpo/dpo.h>
60 ///#include <vnet/feature/feature.h>
61 
62 /* An all zeros address */
63 extern const ip46_address_t zero_addr;
64 
66 {
68 } __clib_packed ip_interface_address_flags_t;
69 
70 typedef struct
71 {
73 
76 
77 typedef struct
78 {
79  /* key - prefix and sw_if_index */
81 
82  /* number of addresses in this prefix on the interface */
84 
85  /* index of the interface address used as a default source address */
88 
89 typedef struct
90 {
91  /* Key for mhash; in fact, just a byte offset into mhash key vector. */
93 
94  /* Interface which has this address. */
96 
97  /* Address (prefix) length for this interface. */
99 
100  /* flags relating to this prefix */
102 
103  /* Next and previous pointers for doubly linked list of
104  addresses per software interface. */
108 
109 typedef enum
110 {
118 
119 struct ip_lookup_main_t;
120 
121 typedef struct ip_lookup_main_t
122 {
123  /** Pool of addresses that are assigned to interfaces. */
125 
126  /** Hash table mapping address to index in interface address pool. */
128 
129  /** Head of doubly linked list of interface addresses for each software interface.
130  ~0 means this interface has no address. */
132 
133  /** Pool of prefixes containing addresses assigned to interfaces */
135 
136  /** Hash table mapping prefix to index in interface prefix pool */
138 
139  /** First table index to use for this interface, ~0 => none */
141 
142  /** Feature arc indices */
146 
147  /** Number of bytes in a fib result. Must be at least
148  sizeof (uword). First word is always adjacency index. */
150 
151  /** 1 for ip6; 0 for ip4. */
153 
154  /** Either format_ip4_address_and_length or format_ip6_address_and_length. */
156 
157  /** Table mapping ip protocol to ip[46]-local node next index. */
159 
160  /** IP_BUILTIN_PROTOCOL_{TCP,UDP,ICMP,OTHER} by protocol in IP header. */
163 
164 u8 *format_ip_flow_hash_config (u8 * s, va_list * args);
165 
166 
167 always_inline void
168 ip_lookup_set_buffer_fib_index (u32 * fib_index_by_sw_if_index,
169  vlib_buffer_t * b)
170 {
171  /* *INDENT-OFF* */
172  vnet_buffer (b)->ip.fib_index =
173  vec_elt (fib_index_by_sw_if_index, vnet_buffer (b)->sw_if_index[VLIB_RX]);
174  vnet_buffer (b)->ip.fib_index =
175  ((vnet_buffer (b)->sw_if_index[VLIB_TX] == (u32) ~ 0) ?
176  vnet_buffer (b)->ip.fib_index :
177  vnet_buffer (b)->sw_if_index[VLIB_TX]);
178  /* *INDENT-ON* */
179 }
180 
181 void ip_lookup_init (ip_lookup_main_t * lm, u32 ip_lookup_node_index);
182 
183 #endif /* included_ip_lookup_h */
184 /*
185  * fd.io coding-style-patch-verification: ON
186  *
187  * Local Variables:
188  * eval: (c-set-style "gnu")
189  * End:
190  */
ip_interface_address_t::sw_if_index
u32 sw_if_index
Definition: lookup.h:95
IP_INTERFACE_ADDRESS_FLAG_STALE
@ IP_INTERFACE_ADDRESS_FLAG_STALE
Definition: lookup.h:67
vlib.h
adj.h
ip_lookup_main_t::if_prefix_pool
ip_interface_prefix_t * if_prefix_pool
Pool of prefixes containing addresses assigned to interfaces.
Definition: lookup.h:134
ip_lookup_main_t::prefix_to_if_prefix_index
mhash_t prefix_to_if_prefix_index
Hash table mapping prefix to index in interface prefix pool.
Definition: lookup.h:137
ip_interface_prefix_t::key
ip_interface_prefix_key_t key
Definition: lookup.h:80
ip_lookup_main_t::is_ip6
u32 is_ip6
1 for ip6; 0 for ip4.
Definition: lookup.h:152
ip_lookup_main_t::ucast_feature_arc_index
u8 ucast_feature_arc_index
Definition: lookup.h:144
buffer.h
ip_interface_prefix_t::ref_count
u16 ref_count
Definition: lookup.h:83
IP_LOCAL_N_NEXT
@ IP_LOCAL_N_NEXT
Definition: lookup.h:116
ip_lookup_main_t::fib_result_n_bytes
u32 fib_result_n_bytes
Number of bytes in a fib result.
Definition: lookup.h:149
ip_interface_address_t::address_length
u16 address_length
Definition: lookup.h:98
mhash_t
Definition: mhash.h:46
u16
unsigned short u16
Definition: types.h:57
ip_lookup_main_t::classify_table_index_by_sw_if_index
u32 * classify_table_index_by_sw_if_index
First table index to use for this interface, ~0 => none.
Definition: lookup.h:140
ip_interface_address_t::address_key
u32 address_key
Definition: lookup.h:92
VLIB_RX
@ VLIB_RX
Definition: defs.h:46
ip_interface_prefix_t
Definition: lookup.h:77
ip_interface_prefix_key_t::sw_if_index
u32 sw_if_index
Definition: lookup.h:74
ip_local_next_t
ip_local_next_t
Definition: lookup.h:109
fib_node.h
ip6_packet.h
ip_lookup_main_t
struct ip_lookup_main_t ip_lookup_main_t
vec_elt
#define vec_elt(v, i)
Get vector value at index i.
Definition: vec_bootstrap.h:210
ip_lookup_main_t::if_address_pool_index_by_sw_if_index
u32 * if_address_pool_index_by_sw_if_index
Head of doubly linked list of interface addresses for each software interface.
Definition: lookup.h:131
IP_LOCAL_NEXT_ICMP
@ IP_LOCAL_NEXT_ICMP
Definition: lookup.h:114
dpo.h
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:441
ip_lookup_main_t::address_to_if_address_index
mhash_t address_to_if_address_index
Hash table mapping address to index in interface address pool.
Definition: lookup.h:127
ip_lookup_main_t::mcast_feature_arc_index
u8 mcast_feature_arc_index
Feature arc indices.
Definition: lookup.h:143
IP_LOCAL_NEXT_REASSEMBLY
@ IP_LOCAL_NEXT_REASSEMBLY
Definition: lookup.h:115
ip_interface_address_flags_t_
ip_interface_address_flags_t_
Definition: lookup.h:65
ip_types.h
ip_interface_prefix_key_t
Definition: lookup.h:70
ip_interface_prefix_key_t::prefix
fib_prefix_t prefix
Definition: lookup.h:72
ip4_packet.h
format_function_t
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
ip_interface_address_flags_t
enum ip_interface_address_flags_t_ ip_interface_address_flags_t
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
ip_interface_address_t::prev_this_sw_interface
u32 prev_this_sw_interface
Definition: lookup.h:106
zero_addr
const ip46_address_t zero_addr
#include <vnet/feature/feature.h>
Definition: lookup.c:182
u32
unsigned int u32
Definition: types.h:88
ip_lookup_init
void ip_lookup_init(ip_lookup_main_t *lm, u32 ip_lookup_node_index)
Definition: lookup.c:75
IP_LOCAL_NEXT_UDP_LOOKUP
@ IP_LOCAL_NEXT_UDP_LOOKUP
Definition: lookup.h:113
format_ip_flow_hash_config
u8 * format_ip_flow_hash_config(u8 *s, va_list *args)
Definition: lookup.c:118
IP_LOCAL_NEXT_DROP
@ IP_LOCAL_NEXT_DROP
Definition: lookup.h:111
ip_lookup_main_t
Definition: lookup.h:121
ip_lookup_main_t::if_address_pool
ip_interface_address_t * if_address_pool
Pool of addresses that are assigned to interfaces.
Definition: lookup.h:124
ip_lookup_set_buffer_fib_index
static void ip_lookup_set_buffer_fib_index(u32 *fib_index_by_sw_if_index, vlib_buffer_t *b)
Definition: lookup.h:168
ip_lookup_main_t::local_next_by_ip_protocol
u8 local_next_by_ip_protocol[256]
Table mapping ip protocol to ip[46]-local node next index.
Definition: lookup.h:158
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
u8
unsigned char u8
Definition: types.h:56
ip_lookup_main_t::format_address_and_length
format_function_t * format_address_and_length
Either format_ip4_address_and_length or format_ip6_address_and_length.
Definition: lookup.h:155
ip_lookup_main_t::builtin_protocol_by_ip_protocol
u8 builtin_protocol_by_ip_protocol[256]
IP_BUILTIN_PROTOCOL_{TCP,UDP,ICMP,OTHER} by protocol in IP header.
Definition: lookup.h:161
ip_interface_address_t
Definition: lookup.h:89
ip_interface_prefix_t::src_ia_index
u32 src_ia_index
Definition: lookup.h:86
ip_interface_address_t::next_this_sw_interface
u32 next_this_sw_interface
Definition: lookup.h:105
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
ip_lookup_main_t::fib_result_n_words
u32 fib_result_n_words
Definition: lookup.h:149
VLIB_TX
@ VLIB_TX
Definition: defs.h:47
ip_interface_address_t::flags
ip_interface_address_flags_t flags
Definition: lookup.h:101
IP_LOCAL_NEXT_PUNT
@ IP_LOCAL_NEXT_PUNT
Definition: lookup.h:112
fib_prefix_t_
Aggregate type for a prefix.
Definition: fib_types.h:202
ip_lookup_main_t::output_feature_arc_index
u8 output_feature_arc_index
Definition: lookup.h:145
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111