FD.io VPP  v17.04.2-2-ga8f93f8
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/dpo/dpo.h>
57 #include <vnet/feature/feature.h>
58 
59 /** @brief Common (IP4/IP6) next index stored in adjacency. */
60 typedef enum
61 {
62  /** Adjacency to drop this packet. */
64  /** Adjacency to punt this packet. */
66 
67  /** This packet is for one of our own IP addresses. */
69 
70  /** This packet matches an "incomplete adjacency" and packets
71  need to be passed to ARP to find rewrite string for
72  this destination. */
74 
75  /** This packet matches an "interface route" and packets
76  need to be passed to ARP to find rewrite string for
77  this destination. */
79 
80  /** This packet is to be rewritten and forwarded to the next
81  processing node. This is typically the output interface but
82  might be another node for further output processing. */
84 
85  /** This packets follow a load-balance */
87 
88  /** This packets follow a mid-chain adjacency */
90 
91  /** This packets needs to go to ICMP error */
93 
94  /** Multicast Adjacency. */
96 
99 
100 typedef enum
101 {
104 
105 typedef enum
106 {
107  /* Hop-by-hop header handling */
113 
114 #define IP4_LOOKUP_NEXT_NODES { \
115  [IP_LOOKUP_NEXT_DROP] = "ip4-drop", \
116  [IP_LOOKUP_NEXT_PUNT] = "ip4-punt", \
117  [IP_LOOKUP_NEXT_LOCAL] = "ip4-local", \
118  [IP_LOOKUP_NEXT_ARP] = "ip4-arp", \
119  [IP_LOOKUP_NEXT_GLEAN] = "ip4-glean", \
120  [IP_LOOKUP_NEXT_REWRITE] = "ip4-rewrite", \
121  [IP_LOOKUP_NEXT_MCAST] = "ip4-rewrite-mcast", \
122  [IP_LOOKUP_NEXT_MIDCHAIN] = "ip4-midchain", \
123  [IP_LOOKUP_NEXT_LOAD_BALANCE] = "ip4-load-balance", \
124  [IP_LOOKUP_NEXT_ICMP_ERROR] = "ip4-icmp-error", \
125 }
126 
127 #define IP6_LOOKUP_NEXT_NODES { \
128  [IP_LOOKUP_NEXT_DROP] = "ip6-drop", \
129  [IP_LOOKUP_NEXT_PUNT] = "ip6-punt", \
130  [IP_LOOKUP_NEXT_LOCAL] = "ip6-local", \
131  [IP_LOOKUP_NEXT_ARP] = "ip6-discover-neighbor", \
132  [IP_LOOKUP_NEXT_GLEAN] = "ip6-glean", \
133  [IP_LOOKUP_NEXT_REWRITE] = "ip6-rewrite", \
134  [IP_LOOKUP_NEXT_MCAST] = "ip6-rewrite-mcast", \
135  [IP_LOOKUP_NEXT_MIDCHAIN] = "ip6-midchain", \
136  [IP_LOOKUP_NEXT_LOAD_BALANCE] = "ip6-load-balance", \
137  [IP_LOOKUP_NEXT_ICMP_ERROR] = "ip6-icmp-error", \
138  [IP6_LOOKUP_NEXT_HOP_BY_HOP] = "ip6-hop-by-hop", \
139  [IP6_LOOKUP_NEXT_ADD_HOP_BY_HOP] = "ip6-add-hop-by-hop", \
140  [IP6_LOOKUP_NEXT_POP_HOP_BY_HOP] = "ip6-pop-hop-by-hop", \
141 }
142 
143 /** Flow hash configuration */
144 #define IP_FLOW_HASH_SRC_ADDR (1<<0)
145 #define IP_FLOW_HASH_DST_ADDR (1<<1)
146 #define IP_FLOW_HASH_PROTO (1<<2)
147 #define IP_FLOW_HASH_SRC_PORT (1<<3)
148 #define IP_FLOW_HASH_DST_PORT (1<<4)
149 #define IP_FLOW_HASH_REVERSE_SRC_DST (1<<5)
150 
151 /** Default: 5-tuple without the "reverse" bit */
152 #define IP_FLOW_HASH_DEFAULT (0x1F)
153 
154 #define foreach_flow_hash_bit \
155 _(src, IP_FLOW_HASH_SRC_ADDR) \
156 _(dst, IP_FLOW_HASH_DST_ADDR) \
157 _(sport, IP_FLOW_HASH_SRC_PORT) \
158 _(dport, IP_FLOW_HASH_DST_PORT) \
159 _(proto, IP_FLOW_HASH_PROTO) \
160 _(reverse, IP_FLOW_HASH_REVERSE_SRC_DST)
161 
162 /**
163  * A flow hash configuration is a mask of the flow hash options
164  */
166 
167 /**
168  * Forward delcartion
169  */
170 struct ip_adjacency_t_;
171 
172 /**
173  * @brief A function type for post-rewrite fixups on midchain adjacency
174  */
176  struct ip_adjacency_t_ * adj,
177  vlib_buffer_t * b0);
178 
179 /**
180  * @brief Flags on an IP adjacency
181  */
183 {
184  /**
185  * Currently a sync walk is active. Used to prevent re-entrant walking
186  */
189 
190 /** @brief IP unicast adjacency.
191  @note cache aligned.
192 */
193 typedef struct ip_adjacency_t_
194 {
195  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
196 
197  /** Number of adjecencies in block. Greater than 1 means multipath;
198  otherwise equal to 1. */
200 
201  /** Next hop after ip4-lookup. */
202  union
203  {
204  ip_lookup_next_t lookup_next_index:16;
206  };
207 
208  /** Interface address index for this local/arp adjacency. */
210 
211  /*
212  * link/ether-type
213  */
216 
217  union
218  {
219  /**
220  * IP_LOOKUP_NEXT_ARP/IP_LOOKUP_NEXT_REWRITE
221  *
222  * neighbour adjacency sub-type;
223  */
224  struct
225  {
226  ip46_address_t next_hop;
227  } nbr;
228  /**
229  * IP_LOOKUP_NEXT_MIDCHAIN
230  *
231  * A nbr adj that is also recursive. Think tunnels.
232  * A nbr adj can transition to be of type MDICHAIN
233  * so be sure to leave the two structs with the next_hop
234  * fields aligned.
235  */
236  struct
237  {
238  /**
239  * The recursive next-hop
240  */
241  ip46_address_t next_hop;
242  /**
243  * The node index of the tunnel's post rewrite/TX function.
244  */
246  /**
247  * The next DPO to use
248  */
250  /**
251  * A function to perform the post-rewrite fixup
252  */
254  } midchain;
255  /**
256  * IP_LOOKUP_NEXT_GLEAN
257  *
258  * Glean the address to ARP for from the packet's destination
259  */
260  struct
261  {
262  ip46_address_t receive_addr;
263  } glean;
264  } sub_type;
265 
266  CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
267 
268  /* Rewrite in second/third cache lines */
270 
271  /*
272  * member not accessed in the data plane are relgated to the
273  * remaining cachelines
274  */
276 
277  /**
278  * Flags on the adjacency
279  */
281 
283 
284 STATIC_ASSERT ((STRUCT_OFFSET_OF (ip_adjacency_t, cacheline0) == 0),
285  "IP adjacency cachline 0 is not offset");
288  "IP adjacency cachline 1 is more than one cachline size offset");
289 
290 /* An all zeros address */
291 extern const ip46_address_t zero_addr;
292 
293 
294 typedef struct
295 {
296  /* Key for mhash; in fact, just a byte offset into mhash key vector. */
298 
299  /* Interface which has this address. */
301 
302  /* Adjacency for neighbor probe (ARP) for this interface address. */
304 
305  /* Address (prefix) length for this interface. */
307 
308  /* Will be used for something eventually. Primary vs. secondary? */
310 
311  /* Next and previous pointers for doubly linked list of
312  addresses per software interface. */
316 
317 typedef enum
318 {
325 
326 struct ip_lookup_main_t;
327 
328 typedef struct ip_lookup_main_t
329 {
330  /* Adjacency heap. */
332 
333  /** load-balance packet/byte counters indexed by LB index. */
335 
336  /** Pool of addresses that are assigned to interfaces. */
338 
339  /** Hash table mapping address to index in interface address pool. */
341 
342  /** Head of doubly linked list of interface addresses for each software interface.
343  ~0 means this interface has no address. */
345 
346  /** First table index to use for this interface, ~0 => none */
348 
349  /** Feature arc indices */
353 
354  /** Number of bytes in a fib result. Must be at least
355  sizeof (uword). First word is always adjacency index. */
356  u32 fib_result_n_bytes, fib_result_n_words;
357 
359 
360  /** 1 for ip6; 0 for ip4. */
362 
363  /** Either format_ip4_address_and_length or format_ip6_address_and_length. */
365 
366  /** Special adjacency format functions */
368 
369  /** Table mapping ip protocol to ip[46]-local node next index. */
370  u8 local_next_by_ip_protocol[256];
371 
372  /** IP_BUILTIN_PROTOCOL_{TCP,UDP,ICMP,OTHER} by protocol in IP header. */
373  u8 builtin_protocol_by_ip_protocol[256];
375 
378 {
379  ip_adjacency_t *adj;
380 
381  adj = vec_elt_at_index (lm->adjacency_heap, adj_index);
382 
383  return adj;
384 }
385 
386 #define ip_prefetch_adjacency(lm,adj_index,type) \
387 do { \
388  ip_adjacency_t * _adj = (lm)->adjacency_heap + (adj_index); \
389  CLIB_PREFETCH (_adj, sizeof (_adj[0]), type); \
390 } while (0)
391 
393  u32 sw_if_index,
394  void *address,
395  u32 address_length,
396  u32 is_del, u32 * result_index);
397 
398 u8 *format_ip_flow_hash_config (u8 * s, va_list * args);
399 
402 {
403  uword *p = mhash_get (&lm->address_to_if_address_index, addr_fib);
404  return p ? pool_elt_at_index (lm->if_address_pool, p[0]) : 0;
405 }
406 
408 
409 always_inline void *
412 {
414 }
415 
416 /* *INDENT-OFF* */
417 #define foreach_ip_interface_address(lm,a,sw_if_index,loop,body) \
418 do { \
419  vnet_main_t *_vnm = vnet_get_main(); \
420  u32 _sw_if_index = sw_if_index; \
421  vnet_sw_interface_t *_swif; \
422  _swif = vnet_get_sw_interface (_vnm, _sw_if_index); \
423  \
424  /* \
425  * Loop => honor unnumbered interface addressing. \
426  */ \
427  if (_swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED) \
428  { \
429  if (loop) \
430  _sw_if_index = _swif->unnumbered_sw_if_index; \
431  else \
432  /* the interface is unnumbered, by the caller does not want \
433  * unnumbered interfaces considered/honoured */ \
434  break; \
435  } \
436  u32 _ia = ((vec_len((lm)->if_address_pool_index_by_sw_if_index) \
437  > (_sw_if_index)) ? \
438  vec_elt ((lm)->if_address_pool_index_by_sw_if_index, \
439  (_sw_if_index)) : \
440  (u32)~0); \
441  ip_interface_address_t * _a; \
442  while (_ia != ~0) \
443  { \
444  _a = pool_elt_at_index ((lm)->if_address_pool, _ia); \
445  _ia = _a->next_this_sw_interface; \
446  (a) = _a; \
447  body; \
448  } \
449 } while (0)
450 /* *INDENT-ON* */
451 
452 void ip_lookup_init (ip_lookup_main_t * lm, u32 ip_lookup_node_index);
453 
454 #endif /* included_ip_lookup_h */
455 
456 /*
457  * fd.io coding-style-patch-verification: ON
458  *
459  * Local Variables:
460  * eval: (c-set-style "gnu")
461  * End:
462  */
This packets follow a load-balance.
Definition: lookup.h:86
format_function_t * format_fib_result
Definition: lookup.h:358
ip_lookup_next_t
Common (IP4/IP6) next index stored in adjacency.
Definition: lookup.h:60
STATIC_ASSERT((STRUCT_OFFSET_OF(ip_adjacency_t, cacheline0)==0),"IP adjacency cachline 0 is not offset")
Definition: mhash.h:46
ip_adjacency_t * adjacency_heap
Definition: lookup.h:331
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:61
ip_interface_address_t * if_address_pool
Pool of addresses that are assigned to interfaces.
Definition: lookup.h:337
struct ip_adjacency_t_::@138::@139 nbr
IP_LOOKUP_NEXT_ARP/IP_LOOKUP_NEXT_REWRITE.
IP unicast adjacency.
Definition: lookup.h:193
#define VLIB_BUFFER_PRE_DATA_SIZE
Definition: buffer.h:51
#define STRUCT_OFFSET_OF(t, f)
Definition: clib.h:62
union ip_adjacency_t_::@138 sub_type
u8 *( format_function_t)(u8 *s, va_list *args)
Definition: format.h:48
struct ip_adjacency_t_ ip_adjacency_t
IP unicast adjacency.
adj_midchain_fixup_t fixup_func
A function to perform the post-rewrite fixup.
Definition: lookup.h:253
u32 neighbor_probe_adj_index
Definition: lookup.h:303
Multicast Adjacency.
Definition: lookup.h:95
mhash_t address_to_if_address_index
Hash table mapping address to index in interface address pool.
Definition: lookup.h:340
u8 mcast_feature_arc_index
Feature arc indices.
Definition: lookup.h:350
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
Adjacency to drop this packet.
Definition: lookup.h:63
vnet_link_t ia_link
Definition: lookup.h:214
ip46_address_t receive_addr
Definition: lookup.h:262
u8 output_feature_arc_index
Definition: lookup.h:352
ip6_lookup_next_t
Definition: lookup.h:105
This packets needs to go to ICMP error.
Definition: lookup.h:92
#define always_inline
Definition: clib.h:84
ip_adjacency_flags_t ia_flags
Flags on the adjacency.
Definition: lookup.h:280
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
ip46_address_t next_hop
The recursive next-hop.
Definition: lookup.h:226
Adjacency to punt this packet.
Definition: lookup.h:65
This packet is for one of our own IP addresses.
Definition: lookup.h:68
This packet matches an "interface route" and packets need to be passed to ARP to find rewrite string ...
Definition: lookup.h:78
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:146
dpo_id_t next_dpo
The next DPO to use.
Definition: lookup.h:249
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:397
CLIB_CACHE_LINE_ALIGN_MARK(cacheline0)
u32 * classify_table_index_by_sw_if_index
First table index to use for this interface, ~0 => none.
Definition: lookup.h:347
u16 lookup_next_index_as_int
Definition: lookup.h:205
u32 tx_function_node
The node index of the tunnel&#39;s post rewrite/TX function.
Definition: lookup.h:245
Currently a sync walk is active.
Definition: lookup.h:187
u8 * format_ip_flow_hash_config(u8 *s, va_list *args)
Definition: lookup.c:240
An node in the FIB graph.
Definition: fib_node.h:277
fib_node_t ia_node
Definition: lookup.h:275
const ip46_address_t zero_addr
Definition: lookup.c:354
vlib_main_t * vm
Definition: buffer.c:276
static ip_interface_address_t * ip_get_interface_address(ip_lookup_main_t *lm, void *addr_fib)
Definition: lookup.h:401
This packet matches an "incomplete adjacency" and packets need to be passed to ARP to find rewrite st...
Definition: lookup.h:73
u32 * if_address_pool_index_by_sw_if_index
Head of doubly linked list of interface addresses for each software interface.
Definition: lookup.h:344
vlib buffer structure definition and a few select access methods.
enum ip_adjacency_flags_t_ ip_adjacency_flags_t
Flags on an IP adjacency.
unsigned int u32
Definition: types.h:88
static uword * mhash_get(mhash_t *h, const void *key)
Definition: mhash.h:110
enum vnet_link_t_ vnet_link_t
Link Type: A description of the protocol of packets on the link.
This packets follow a mid-chain adjacency.
Definition: lookup.h:89
struct ip_adjacency_t_::@138::@140 midchain
IP_LOOKUP_NEXT_MIDCHAIN.
u32 fib_result_n_words
Definition: lookup.h:356
u32 if_address_index
Interface address index for this local/arp adjacency.
Definition: lookup.h:209
void(* adj_midchain_fixup_t)(vlib_main_t *vm, struct ip_adjacency_t_ *adj, vlib_buffer_t *b0)
A function type for post-rewrite fixups on midchain adjacency.
Definition: lookup.h:175
u32 flow_hash_config_t
A flow hash configuration is a mask of the flow hash options.
Definition: lookup.h:165
u64 uword
Definition: types.h:112
u16 n_adj
Number of adjecencies in block.
Definition: lookup.h:199
u8 ucast_feature_arc_index
Definition: lookup.h:351
u32 fib_table_id_find_fib_index(fib_protocol_t proto, u32 table_id)
Definition: lookup.c:360
unsigned short u16
Definition: types.h:57
format_function_t ** special_adjacency_format_functions
Special adjacency format functions.
Definition: lookup.h:367
unsigned char u8
Definition: types.h:56
ip_lookup_next_t lookup_next_index
Definition: lookup.h:204
u32 is_ip6
1 for ip6; 0 for ip4.
Definition: lookup.h:361
static void * mhash_key_to_mem(mhash_t *h, uword key)
Definition: mhash.h:90
A collection of combined counters.
Definition: counter.h:180
This packet is to be rewritten and forwarded to the next processing node.
Definition: lookup.h:83
ip_local_next_t
Definition: lookup.h:317
void ip_lookup_init(ip_lookup_main_t *lm, u32 ip_lookup_node_index)
Definition: lookup.c:189
ip4_lookup_next_t
Definition: lookup.h:100
static void * ip_interface_address_get_address(ip_lookup_main_t *lm, ip_interface_address_t *a)
Definition: lookup.h:410
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
vnet_declare_rewrite(VLIB_BUFFER_PRE_DATA_SIZE)
vlib_combined_counter_main_t load_balance_counters
load-balance packet/byte counters indexed by LB index.
Definition: lookup.h:334
ip_adjacency_flags_t_
Flags on an IP adjacency.
Definition: lookup.h:182
static ip_adjacency_t * ip_get_adjacency(ip_lookup_main_t *lm, u32 adj_index)
Definition: lookup.h:377
struct ip_adjacency_t_::@138::@141 glean
IP_LOOKUP_NEXT_GLEAN.
format_function_t * format_address_and_length
Either format_ip4_address_and_length or format_ip6_address_and_length.
Definition: lookup.h:364