FD.io VPP  v18.01.2-1-g9b554f3
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/buffer.h>
53 #include <vnet/ip/ip4_packet.h>
54 #include <vnet/ip/ip6_packet.h>
55 #include <vnet/fib/fib_node.h>
56 #include <vnet/adj/adj.h>
57 #include <vnet/dpo/dpo.h>
58 #include <vnet/feature/feature.h>
59 
60 /** Flow hash configuration */
61 #define IP_FLOW_HASH_SRC_ADDR (1<<0)
62 #define IP_FLOW_HASH_DST_ADDR (1<<1)
63 #define IP_FLOW_HASH_PROTO (1<<2)
64 #define IP_FLOW_HASH_SRC_PORT (1<<3)
65 #define IP_FLOW_HASH_DST_PORT (1<<4)
66 #define IP_FLOW_HASH_REVERSE_SRC_DST (1<<5)
67 
68 /** Default: 5-tuple without the "reverse" bit */
69 #define IP_FLOW_HASH_DEFAULT (0x1F)
70 
71 #define foreach_flow_hash_bit \
72 _(src, IP_FLOW_HASH_SRC_ADDR) \
73 _(dst, IP_FLOW_HASH_DST_ADDR) \
74 _(sport, IP_FLOW_HASH_SRC_PORT) \
75 _(dport, IP_FLOW_HASH_DST_PORT) \
76 _(proto, IP_FLOW_HASH_PROTO) \
77 _(reverse, IP_FLOW_HASH_REVERSE_SRC_DST)
78 
79 /**
80  * A flow hash configuration is a mask of the flow hash options
81  */
83 
84 /* An all zeros address */
85 extern const ip46_address_t zero_addr;
86 
87 
88 typedef struct
89 {
90  /* Key for mhash; in fact, just a byte offset into mhash key vector. */
92 
93  /* Interface which has this address. */
95 
96  /* Address (prefix) length for this interface. */
98 
99  /* Will be used for something eventually. Primary vs. secondary? */
101 
102  /* Next and previous pointers for doubly linked list of
103  addresses per software interface. */
107 
108 typedef enum
109 {
116 
117 struct ip_lookup_main_t;
118 
119 typedef struct ip_lookup_main_t
120 {
121  /** Pool of addresses that are assigned to interfaces. */
123 
124  /** Hash table mapping address to index in interface address pool. */
126 
127  /** Head of doubly linked list of interface addresses for each software interface.
128  ~0 means this interface has no address. */
130 
131  /** First table index to use for this interface, ~0 => none */
133 
134  /** Feature arc indices */
138 
139  /** Number of bytes in a fib result. Must be at least
140  sizeof (uword). First word is always adjacency index. */
142 
143  /** 1 for ip6; 0 for ip4. */
145 
146  /** Either format_ip4_address_and_length or format_ip6_address_and_length. */
148 
149  /** Table mapping ip protocol to ip[46]-local node next index. */
151 
152  /** IP_BUILTIN_PROTOCOL_{TCP,UDP,ICMP,OTHER} by protocol in IP header. */
155 
157  u32 sw_if_index,
158  void *address,
159  u32 address_length,
160  u32 is_del, u32 * result_index);
161 
162 u8 *format_ip_flow_hash_config (u8 * s, va_list * args);
163 
166 {
167  uword *p = mhash_get (&lm->address_to_if_address_index, addr_fib);
168  return p ? pool_elt_at_index (lm->if_address_pool, p[0]) : 0;
169 }
170 
171 always_inline void *
174 {
176 }
177 
178 /* *INDENT-OFF* */
179 #define foreach_ip_interface_address(lm,a,sw_if_index,loop,body) \
180 do { \
181  vnet_main_t *_vnm = vnet_get_main(); \
182  u32 _sw_if_index = sw_if_index; \
183  vnet_sw_interface_t *_swif; \
184  _swif = vnet_get_sw_interface (_vnm, _sw_if_index); \
185  \
186  /* \
187  * Loop => honor unnumbered interface addressing. \
188  */ \
189  if (_swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED) \
190  { \
191  if (loop) \
192  _sw_if_index = _swif->unnumbered_sw_if_index; \
193  else \
194  /* the interface is unnumbered, by the caller does not want \
195  * unnumbered interfaces considered/honoured */ \
196  break; \
197  } \
198  u32 _ia = ((vec_len((lm)->if_address_pool_index_by_sw_if_index) \
199  > (_sw_if_index)) ? \
200  vec_elt ((lm)->if_address_pool_index_by_sw_if_index, \
201  (_sw_if_index)) : \
202  (u32)~0); \
203  ip_interface_address_t * _a; \
204  while (_ia != ~0) \
205  { \
206  _a = pool_elt_at_index ((lm)->if_address_pool, _ia); \
207  _ia = _a->next_this_sw_interface; \
208  (a) = _a; \
209  body; \
210  } \
211 } while (0)
212 /* *INDENT-ON* */
213 
214 typedef struct _vnet_ip_container_proxy_args
215 {
216  fib_prefix_t prefix;
217  u32 sw_if_index;
218  u8 is_add;
220 
222  * args);
223 
224 void ip_lookup_init (ip_lookup_main_t * lm, u32 ip_lookup_node_index);
225 
226 #endif /* included_ip_lookup_h */
227 
228 /*
229  * fd.io coding-style-patch-verification: ON
230  *
231  * Local Variables:
232  * eval: (c-set-style "gnu")
233  * End:
234  */
Definition: mhash.h:46
a
Definition: bitmap.h:516
clib_error_t * ip_interface_address_add_del(ip_lookup_main_t *lm, u32 sw_if_index, void *address, u32 address_length, u32 is_del, u32 *result_index)
Definition: lookup.c:62
ip_interface_address_t * if_address_pool
Pool of addresses that are assigned to interfaces.
Definition: lookup.h:122
u8 *( format_function_t)(u8 *s, va_list *args)
Definition: format.h:48
mhash_t address_to_if_address_index
Hash table mapping address to index in interface address pool.
Definition: lookup.h:125
u8 mcast_feature_arc_index
Feature arc indices.
Definition: lookup.h:135
u8 output_feature_arc_index
Definition: lookup.h:137
#define always_inline
Definition: clib.h:92
struct _vnet_ip_container_proxy_args vnet_ip_container_proxy_args_t
Aggregrate type for a prefix.
Definition: fib_types.h:172
struct ip_lookup_main_t ip_lookup_main_t
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:459
u32 * classify_table_index_by_sw_if_index
First table index to use for this interface, ~0 => none.
Definition: lookup.h:132
u8 local_next_by_ip_protocol[256]
Table mapping ip protocol to ip[46]-local node next index.
Definition: lookup.h:150
u8 * format_ip_flow_hash_config(u8 *s, va_list *args)
Definition: lookup.c:244
const ip46_address_t zero_addr
Definition: lookup.c:359
static ip_interface_address_t * ip_get_interface_address(ip_lookup_main_t *lm, void *addr_fib)
Definition: lookup.h:165
u8 builtin_protocol_by_ip_protocol[256]
IP_BUILTIN_PROTOCOL_{TCP,UDP,ICMP,OTHER} by protocol in IP header.
Definition: lookup.h:153
u32 * if_address_pool_index_by_sw_if_index
Head of doubly linked list of interface addresses for each software interface.
Definition: lookup.h:129
vlib buffer structure definition and a few select access methods.
unsigned int u32
Definition: types.h:88
static uword * mhash_get(mhash_t *h, const void *key)
Definition: mhash.h:110
u32 fib_result_n_words
Definition: lookup.h:141
clib_error_t * vnet_ip_container_proxy_add_del(vnet_ip_container_proxy_args_t *args)
Definition: lookup.c:1304
u32 flow_hash_config_t
A flow hash configuration is a mask of the flow hash options.
Definition: lookup.h:82
u64 uword
Definition: types.h:112
u8 ucast_feature_arc_index
Definition: lookup.h:136
unsigned short u16
Definition: types.h:57
unsigned char u8
Definition: types.h:56
u32 is_ip6
1 for ip6; 0 for ip4.
Definition: lookup.h:144
static void * mhash_key_to_mem(mhash_t *h, uword key)
Definition: mhash.h:90
ip_local_next_t
Definition: lookup.h:108
void ip_lookup_init(ip_lookup_main_t *lm, u32 ip_lookup_node_index)
Definition: lookup.c:203
static void * ip_interface_address_get_address(ip_lookup_main_t *lm, ip_interface_address_t *a)
Definition: lookup.h:172
u32 fib_result_n_bytes
Number of bytes in a fib result.
Definition: lookup.h:141
format_function_t * format_address_and_length
Either format_ip4_address_and_length or format_ip6_address_and_length.
Definition: lookup.h:147