Add IP adjacency registration function
[vpp.git] / vnet / vnet / ip / lookup.h
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 #ifndef included_ip_lookup_h
41 #define included_ip_lookup_h
42
43 #include <vnet/vnet.h>
44 #include <vlib/buffer.h>
45 #include <vnet/ip/ip4_packet.h>
46 #include <vnet/ip/ip6_packet.h>
47
48 /* Common (IP4/IP6) next index stored in adjacency. */
49 typedef enum {
50   /* Packet does not match any route in table. */
51   IP_LOOKUP_NEXT_MISS,
52
53   /* Adjacency says to drop or punt this packet. */
54   IP_LOOKUP_NEXT_DROP,
55   IP_LOOKUP_NEXT_PUNT,
56
57   /* This packet is for one of our own IP addresses. */
58   IP_LOOKUP_NEXT_LOCAL,
59
60   /* This packet matches an "interface route" and packets
61      need to be passed to ARP to find rewrite string for
62      this destination. */
63   IP_LOOKUP_NEXT_ARP,
64
65   /* This packet is to be rewritten and forwarded to the next
66      processing node.  This is typically the output interface but
67      might be another node for further output processing. */
68   IP_LOOKUP_NEXT_REWRITE,
69
70   /* This packet needs to be classified */
71   IP_LOOKUP_NEXT_CLASSIFY,
72
73   /* This packet needs to go to MAP - RFC7596, RFC7597 */
74   IP_LOOKUP_NEXT_MAP,
75
76   /* This packet needs to go to MAP with Translation - RFC7599 */
77   IP_LOOKUP_NEXT_MAP_T,
78
79   /* This packets needs to go to indirect next hop */
80   IP_LOOKUP_NEXT_INDIRECT,
81
82   IP_LOOKUP_NEXT_ICMP_ERROR,
83
84   IP_LOOKUP_N_NEXT,
85 } ip_lookup_next_t;
86
87 typedef enum {
88   IP4_LOOKUP_N_NEXT = IP_LOOKUP_N_NEXT,
89 } ip4_lookup_next_t;
90
91 typedef enum {
92   /* Hop-by-hop header handling */
93   IP6_LOOKUP_NEXT_HOP_BY_HOP = IP_LOOKUP_N_NEXT,
94   IP6_LOOKUP_NEXT_ADD_HOP_BY_HOP,
95   IP6_LOOKUP_NEXT_POP_HOP_BY_HOP,
96   IP6_LOOKUP_N_NEXT,
97 } ip6_lookup_next_t;
98
99 #define IP4_LOOKUP_NEXT_NODES {                                 \
100     [IP_LOOKUP_NEXT_MISS] = "ip4-miss",                         \
101     [IP_LOOKUP_NEXT_DROP] = "ip4-drop",                         \
102     [IP_LOOKUP_NEXT_PUNT] = "ip4-punt",                         \
103     [IP_LOOKUP_NEXT_LOCAL] = "ip4-local",                       \
104     [IP_LOOKUP_NEXT_ARP] = "ip4-arp",                           \
105     [IP_LOOKUP_NEXT_REWRITE] = "ip4-rewrite-transit",           \
106     [IP_LOOKUP_NEXT_CLASSIFY] = "ip4-classify",                 \
107     [IP_LOOKUP_NEXT_MAP] = "ip4-map",                           \
108     [IP_LOOKUP_NEXT_MAP_T] = "ip4-map-t",                       \
109     [IP_LOOKUP_NEXT_INDIRECT] = "ip4-indirect",                 \
110     [IP_LOOKUP_NEXT_ICMP_ERROR] = "ip4-icmp-error",             \
111 }
112
113 #define IP6_LOOKUP_NEXT_NODES {                                 \
114     [IP_LOOKUP_NEXT_MISS] = "ip6-miss",                         \
115     [IP_LOOKUP_NEXT_DROP] = "ip6-drop",                         \
116     [IP_LOOKUP_NEXT_PUNT] = "ip6-punt",                         \
117     [IP_LOOKUP_NEXT_LOCAL] = "ip6-local",                       \
118     [IP_LOOKUP_NEXT_ARP] = "ip6-discover-neighbor",             \
119     [IP_LOOKUP_NEXT_REWRITE] = "ip6-rewrite",                   \
120     [IP_LOOKUP_NEXT_CLASSIFY] = "ip6-classify",                 \
121     [IP_LOOKUP_NEXT_MAP] = "ip6-map",                           \
122     [IP_LOOKUP_NEXT_MAP_T] = "ip6-map-t",                       \
123     [IP_LOOKUP_NEXT_INDIRECT] = "ip6-indirect",                 \
124     [IP_LOOKUP_NEXT_ICMP_ERROR] = "ip6-icmp-error",             \
125     [IP6_LOOKUP_NEXT_HOP_BY_HOP] = "ip6-hop-by-hop",            \
126     [IP6_LOOKUP_NEXT_ADD_HOP_BY_HOP] = "ip6-add-hop-by-hop",    \
127     [IP6_LOOKUP_NEXT_POP_HOP_BY_HOP] = "ip6-pop-hop-by-hop",    \
128 }
129
130 /* Flow hash configuration */
131 #define IP_FLOW_HASH_SRC_ADDR (1<<0)
132 #define IP_FLOW_HASH_DST_ADDR (1<<1)
133 #define IP_FLOW_HASH_PROTO (1<<2)
134 #define IP_FLOW_HASH_SRC_PORT (1<<3)
135 #define IP_FLOW_HASH_DST_PORT (1<<4)
136 #define IP_FLOW_HASH_REVERSE_SRC_DST (1<<5)
137
138 /* Default: 5-tuple without the "reverse" bit */
139 #define IP_FLOW_HASH_DEFAULT (0x1F)
140
141 #define foreach_flow_hash_bit                   \
142 _(src, IP_FLOW_HASH_SRC_ADDR)                   \
143 _(dst, IP_FLOW_HASH_DST_ADDR)                   \
144 _(sport, IP_FLOW_HASH_SRC_PORT)                 \
145 _(dport, IP_FLOW_HASH_DST_PORT)                 \
146 _(proto, IP_FLOW_HASH_PROTO)                    \
147 _(reverse, IP_FLOW_HASH_REVERSE_SRC_DST)
148
149 #define IP_ADJACENCY_OPAQUE_SZ 16
150 /* IP unicast adjacency. */
151 typedef struct {
152   CLIB_CACHE_LINE_ALIGN_MARK(cacheline0);
153   /* Handle for this adjacency in adjacency heap. */
154   u32 heap_handle;
155
156   STRUCT_MARK(signature_start);
157
158   /* Interface address index for this local/arp adjacency. */
159   u32 if_address_index;
160
161   /* Number of adjecencies in block.  Greater than 1 means multipath;
162      otherwise equal to 1. */
163   u16 n_adj;
164
165   /* Next hop after ip4-lookup. */
166   union {
167     ip_lookup_next_t lookup_next_index : 16;
168     u16 lookup_next_index_as_int;
169   };
170
171   /* Force re-lookup in a different FIB. ~0 => normal behavior */
172   i16 explicit_fib_index;
173   u16 mcast_group_index;  
174
175   /* Highest possible perf subgraph arc interposition, e.g. for ip6 ioam */
176   u16 saved_lookup_next_index;
177
178   union {
179     /* IP_LOOKUP_NEXT_ARP only */
180     struct {
181       ip46_address_t next_hop;
182     } arp;
183     /* IP_LOOKUP_NEXT_CLASSIFY only */
184     struct {
185       u16 table_index;
186     } classify;
187     /* IP_LOOKUP_NEXT_INDIRECT only */
188     struct {
189         ip46_address_t next_hop;
190     } indirect;
191     u8 opaque[IP_ADJACENCY_OPAQUE_SZ];
192   };
193
194   STRUCT_MARK(signature_end);
195
196   /* Number of FIB entries sharing this adjacency */
197   u32 share_count;
198   /* Use this adjacency instead */
199   u32 next_adj_with_signature;
200
201   CLIB_CACHE_LINE_ALIGN_MARK(cacheline1);
202
203   /* Rewrite in second/third cache lines */
204   vnet_declare_rewrite (VLIB_BUFFER_PRE_DATA_SIZE);
205 } ip_adjacency_t;
206
207 static inline uword
208 vnet_ip_adjacency_signature (ip_adjacency_t * adj)
209 {
210   uword signature = 0xfeedfaceULL;
211
212   /* Skip heap handle, sum everything up to but not including share_count */
213   signature = hash_memory
214       (STRUCT_MARK_PTR(adj, signature_start),
215        STRUCT_OFFSET_OF(ip_adjacency_t, signature_end)
216        - STRUCT_OFFSET_OF(ip_adjacency_t, signature_start),
217        signature);
218
219   /* and the rewrite */
220   signature = hash_memory (&adj->rewrite_header, VLIB_BUFFER_PRE_DATA_SIZE,
221                              signature);
222   return signature;
223 }
224
225 static inline int
226 vnet_ip_adjacency_share_compare (ip_adjacency_t * a1, ip_adjacency_t *a2)
227 {
228   if (memcmp (STRUCT_MARK_PTR(a1, signature_start),
229               STRUCT_MARK_PTR(a2, signature_start),
230               STRUCT_OFFSET_OF(ip_adjacency_t, signature_end)
231               - STRUCT_OFFSET_OF(ip_adjacency_t, signature_start)))
232     return 0;
233   if (memcmp (&a1->rewrite_header, &a2->rewrite_header,
234               VLIB_BUFFER_PRE_DATA_SIZE))
235     return 0;
236   return 1;
237 }
238
239 /* Index into adjacency table. */
240 typedef u32 ip_adjacency_index_t;
241
242 typedef struct {
243   /* Directly connected next-hop adjacency index. */
244   u32 next_hop_adj_index;
245
246   /* Path weight for this adjacency. */
247   u32 weight;
248 } ip_multipath_next_hop_t;
249
250 typedef struct {
251   /* Adjacency index of first index in block. */
252   u32 adj_index;
253   
254   /* Power of 2 size of adjacency block. */
255   u32 n_adj_in_block;
256
257   /* Number of prefixes that point to this adjacency. */
258   u32 reference_count;
259
260   /* Normalized next hops are used as hash keys: they are sorted by weight
261      and weights are chosen so they add up to 1 << log2_n_adj_in_block (with
262      zero-weighted next hops being deleted).
263      Unnormalized next hops are saved so that control plane has a record of exactly
264      what the RIB told it. */
265   struct {
266     /* Number of hops in the multipath. */
267     u32 count;
268
269     /* Offset into next hop heap for this block. */
270     u32 heap_offset;
271
272     /* Heap handle used to for example free block when we're done with it. */
273     u32 heap_handle;
274   } normalized_next_hops, unnormalized_next_hops;
275 } ip_multipath_adjacency_t;
276
277 /* IP multicast adjacency. */
278 typedef struct {
279   /* Handle for this adjacency in adjacency heap. */
280   u32 heap_handle;
281
282   /* Number of adjecencies in block. */
283   u32 n_adj;
284
285   /* Rewrite string. */
286   vnet_declare_rewrite (64 - 2*sizeof(u32));
287 } ip_multicast_rewrite_t;
288
289 typedef struct {
290   /* ip4-multicast-rewrite next index. */
291   u32 next_index;
292
293   u8 n_rewrite_bytes;
294
295   u8 rewrite_string[64 - 1*sizeof(u32) - 1*sizeof(u8)];
296 } ip_multicast_rewrite_string_t;
297
298 typedef struct {
299   ip_multicast_rewrite_t * rewrite_heap;
300
301   ip_multicast_rewrite_string_t * rewrite_strings;
302
303   /* Negative rewrite string index; >= 0 sw_if_index.
304      Sorted.  Used to hash. */
305   i32 ** adjacency_id_vector;
306
307   uword * adjacency_by_id_vector;
308 } ip_multicast_lookup_main_t;
309
310 typedef struct {
311   /* Key for mhash; in fact, just a byte offset into mhash key vector. */
312   u32 address_key;
313
314   /* Interface which has this address. */
315   u32 sw_if_index;
316
317   /* Adjacency for neighbor probe (ARP) for this interface address. */
318   u32 neighbor_probe_adj_index;
319
320   /* Address (prefix) length for this interface. */
321   u16 address_length;
322
323   /* Will be used for something eventually.  Primary vs. secondary? */
324   u16 flags;
325
326   /* Next and previous pointers for doubly linked list of
327      addresses per software interface. */
328   u32 next_this_sw_interface;
329   u32 prev_this_sw_interface;
330 } ip_interface_address_t;
331
332 typedef enum {
333   IP_LOCAL_NEXT_DROP,
334   IP_LOCAL_NEXT_PUNT,
335   IP_LOCAL_NEXT_UDP_LOOKUP,
336   IP_LOCAL_NEXT_ICMP,
337   IP_LOCAL_N_NEXT,
338 } ip_local_next_t;
339
340 struct ip_lookup_main_t;
341
342 typedef void (* ip_add_del_adjacency_callback_t) (struct ip_lookup_main_t * lm,
343                                                   u32 adj_index,
344                                                   ip_adjacency_t * adj,
345                                                   u32 is_del);
346
347 typedef struct {
348   vnet_config_main_t config_main;
349
350   u32 * config_index_by_sw_if_index;
351 } ip_config_main_t;
352
353 //Function type used to register formatting of a custom adjacency formatting
354 typedef u8 *(* ip_adjacency_format_fn)(u8 * s,
355                                         struct ip_lookup_main_t * lm,
356                                         ip_adjacency_t *adj);
357
358 typedef struct ip_adj_register_struct {
359   struct ip_adj_register_struct *next;
360   char *node_name; //Name of the node for this registered adjacency
361   ip_adjacency_format_fn fn; //Formatting function of this adjacency
362   u32 *next_index; //some place where the next index to be used will be put at init
363 } ip_adj_register_t;
364
365 typedef struct ip_lookup_main_t {
366   /* Adjacency heap. */
367   ip_adjacency_t * adjacency_heap;
368
369   /* Adjacency packet/byte counters indexed by adjacency index. */
370   vlib_combined_counter_main_t adjacency_counters;
371
372   /* Heap of (next hop, weight) blocks.  Sorted by next hop. */
373   ip_multipath_next_hop_t * next_hop_heap;
374
375   /* Indexed by heap_handle from ip_adjacency_t. */
376   ip_multipath_adjacency_t * multipath_adjacencies;
377
378   /* Adjacency by signature hash */
379   uword * adj_index_by_signature;
380
381   /* Temporary vectors for looking up next hops in hash. */
382   ip_multipath_next_hop_t * next_hop_hash_lookup_key;
383   ip_multipath_next_hop_t * next_hop_hash_lookup_key_normalized;
384
385   /* Hash table mapping normalized next hops and weights
386      to multipath adjacency index. */
387   uword * multipath_adjacency_by_next_hops;
388
389   u32 * adjacency_remap_table;
390   u32 n_adjacency_remaps;
391
392   /* If average error per adjacency is less than this threshold adjacency block
393      size is accepted. */
394   f64 multipath_next_hop_error_tolerance;
395
396   /* Adjacency index for routing table misses, local punts, and drops. */
397   u32 miss_adj_index, drop_adj_index, local_adj_index;
398
399   /* Miss adjacency is always first in adjacency table. */
400 #define IP_LOOKUP_MISS_ADJ_INDEX 0
401
402   ip_add_del_adjacency_callback_t * add_del_adjacency_callbacks;
403
404   /* Pool of addresses that are assigned to interfaces. */
405   ip_interface_address_t * if_address_pool;
406
407   /* Hash table mapping address to index in interface address pool. */
408   mhash_t address_to_if_address_index;
409
410   /* Head of doubly linked list of interface addresses for each software interface.
411      ~0 means this interface has no address. */
412   u32 * if_address_pool_index_by_sw_if_index;
413
414   /* First table index to use for this interface, ~0 => none */
415   u32 * classify_table_index_by_sw_if_index;
416
417   /* rx/tx interface/feature configuration. */
418   ip_config_main_t rx_config_mains[VNET_N_CAST], tx_config_main;
419
420   /* Number of bytes in a fib result.  Must be at least
421      sizeof (uword).  First word is always adjacency index. */
422   u32 fib_result_n_bytes, fib_result_n_words;
423
424   format_function_t * format_fib_result;
425
426   /* 1 for ip6; 0 for ip4. */
427   u32 is_ip6;
428
429   /* Either format_ip4_address_and_length or format_ip6_address_and_length. */
430   format_function_t * format_address_and_length;
431
432   /* Table mapping ip protocol to ip[46]-local node next index. */
433   u8 local_next_by_ip_protocol[256];
434
435   /* IP_BUILTIN_PROTOCOL_{TCP,UDP,ICMP,OTHER} by protocol in IP header. */
436   u8 builtin_protocol_by_ip_protocol[256];
437
438   /* Registered adjacencies */
439   ip_adj_register_t *registered_adjacencies;
440 } ip_lookup_main_t;
441
442 always_inline ip_adjacency_t *
443 ip_get_adjacency (ip_lookup_main_t * lm,
444                   u32 adj_index)
445 {
446   ip_adjacency_t * adj;
447
448   adj = vec_elt_at_index (lm->adjacency_heap, adj_index);
449
450   ASSERT (adj->heap_handle != ~0);
451
452   return adj;
453 }
454
455 #define ip_prefetch_adjacency(lm,adj_index,type)                \
456 do {                                                            \
457   ip_adjacency_t * _adj = (lm)->adjacency_heap + (adj_index);   \
458   CLIB_PREFETCH (_adj, sizeof (_adj[0]), type);                 \
459 } while (0)
460
461 /* Adds a next node to ip4 or ip6 lookup node which can be then used in adjacencies.
462  * @param vlib_main pointer
463  * @param lm ip4_main.lookup_main or ip6_main.lookup_main
464  * @param reg registration structure
465  * @param next_node_index Returned index to be used in adjacencies.
466  * @return 0 on success. -1 on failure.
467  */
468 int ip_register_adjacency(vlib_main_t *vm, u8 is_ip4,
469                           ip_adj_register_t *reg);
470
471 /*
472  * Construction helpers to add IP adjacency at init.
473  */
474 #define VNET_IP_REGISTER_ADJACENCY(ip,x,...)                     \
475   __VA_ARGS__ ip_adj_register_t ip##adj_##x;                     \
476 static void __vnet_##ip##_register_adjacency_##x (void)          \
477   __attribute__((__constructor__)) ;                             \
478 static void __vnet_##ip##_register_adjacency_##x (void)          \
479 {                                                                \
480   ip_lookup_main_t *lm = &ip##_main.lookup_main;                 \
481   ip##adj_##x.next = lm->registered_adjacencies;                 \
482   lm->registered_adjacencies = &ip##adj_##x;                     \
483 }                                                                \
484 __VA_ARGS__ ip_adj_register_t ip##adj_##x
485
486 #define VNET_IP4_REGISTER_ADJACENCY(x,...)                       \
487     VNET_IP_REGISTER_ADJACENCY(ip4, x, __VA_ARGS__)
488
489 #define VNET_IP6_REGISTER_ADJACENCY(x,...)                       \
490     VNET_IP_REGISTER_ADJACENCY(ip6, x, __VA_ARGS__)
491
492 static inline void
493 ip_register_add_del_adjacency_callback(ip_lookup_main_t * lm,
494                                        ip_add_del_adjacency_callback_t cb)
495 {
496   vec_add1(lm->add_del_adjacency_callbacks, cb);
497 }
498
499 always_inline void
500 ip_call_add_del_adjacency_callbacks (ip_lookup_main_t * lm, u32 adj_index, u32 is_del)
501 {
502   ip_adjacency_t * adj;
503   uword i;
504   adj = ip_get_adjacency (lm, adj_index);
505   for (i = 0; i < vec_len (lm->add_del_adjacency_callbacks); i++)
506     lm->add_del_adjacency_callbacks[i] (lm, adj_index, adj, is_del);
507 }
508
509 /* Create new block of given number of contiguous adjacencies. */
510 ip_adjacency_t *
511 ip_add_adjacency (ip_lookup_main_t * lm,
512                   ip_adjacency_t * adj,
513                   u32 n_adj,
514                   u32 * adj_index_result);
515
516 void ip_del_adjacency (ip_lookup_main_t * lm, u32 adj_index);
517 void
518 ip_update_adjacency (ip_lookup_main_t * lm,
519                      u32 adj_index,
520                      ip_adjacency_t * copy_adj);
521
522 static inline int
523 ip_adjacency_is_multipath(ip_lookup_main_t * lm, u32 adj_index)
524 {
525   if (!vec_len(lm->multipath_adjacencies))
526     return 0;
527
528   if (vec_len(lm->multipath_adjacencies) < adj_index - 1)
529     return 0;
530
531
532   return (lm->multipath_adjacencies[adj_index].adj_index == adj_index &&
533           lm->multipath_adjacencies[adj_index].n_adj_in_block > 0);
534 }
535
536 void
537 ip_multipath_adjacency_free (ip_lookup_main_t * lm,
538                              ip_multipath_adjacency_t * a);
539
540 u32
541 ip_multipath_adjacency_add_del_next_hop (ip_lookup_main_t * lm,
542                                          u32 is_del,
543                                          u32 old_mp_adj_index,
544                                          u32 next_hop_adj_index,
545                                          u32 next_hop_weight,
546                                          u32 * new_mp_adj_index);
547
548 clib_error_t *
549 ip_interface_address_add_del (ip_lookup_main_t * lm,
550                               u32 sw_if_index,
551                               void * address,
552                               u32 address_length,
553                               u32 is_del,
554                               u32 * result_index);
555
556 always_inline ip_interface_address_t *
557 ip_get_interface_address (ip_lookup_main_t * lm, void * addr_fib)
558 {
559   uword * p = mhash_get (&lm->address_to_if_address_index, addr_fib);
560   return p ? pool_elt_at_index (lm->if_address_pool, p[0]) : 0;
561 }
562
563 always_inline void *
564 ip_interface_address_get_address (ip_lookup_main_t * lm, ip_interface_address_t * a)
565 { return mhash_key_to_mem (&lm->address_to_if_address_index, a->address_key); }
566
567 always_inline ip_interface_address_t *
568 ip_interface_address_for_packet (ip_lookup_main_t * lm, vlib_buffer_t * b, u32 sw_if_index)
569 {
570   ip_adjacency_t * adj;
571   u32 if_address_index;
572
573   adj = ip_get_adjacency (lm, vnet_buffer (b)->ip.adj_index[VLIB_TX]);
574
575   ASSERT (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP
576           || adj->lookup_next_index == IP_LOOKUP_NEXT_LOCAL);
577   if_address_index = adj->if_address_index;
578   if_address_index = (if_address_index == ~0 ?
579                       vec_elt (lm->if_address_pool_index_by_sw_if_index, sw_if_index)
580                       : if_address_index);
581
582   return (if_address_index != ~0)?pool_elt_at_index (lm->if_address_pool, if_address_index):NULL;
583 }
584
585 #define foreach_ip_interface_address(lm,a,sw_if_index,loop,body)        \
586 do {                                                                    \
587     vnet_main_t *_vnm = vnet_get_main();                                     \
588     u32 _sw_if_index = sw_if_index;                                     \
589     vnet_sw_interface_t *_swif;                                         \
590     _swif = vnet_get_sw_interface (_vnm, _sw_if_index);                 \
591                                                                         \
592     /*                                                                  \
593      * Loop => honor unnumbered interface addressing.                   \
594      */                                                                 \
595     if (loop && _swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)       \
596       _sw_if_index = _swif->unnumbered_sw_if_index;                     \
597     u32 _ia =                                                           \
598       (vec_len((lm)->if_address_pool_index_by_sw_if_index)              \
599        > (_sw_if_index))                                                \
600         ? vec_elt ((lm)->if_address_pool_index_by_sw_if_index,          \
601                    (_sw_if_index)) : (u32)~0;                           \
602     ip_interface_address_t * _a;                                        \
603     while (_ia != ~0)                                                   \
604     {                                                                   \
605         _a = pool_elt_at_index ((lm)->if_address_pool, _ia);            \
606         _ia = _a->next_this_sw_interface;                               \
607         (a) = _a;                                                       \
608         body;                                                           \
609     }                                                                   \
610 } while (0)
611
612 void ip_lookup_init (ip_lookup_main_t * lm, u32 ip_lookup_node_index);
613
614 #endif /* included_ip_lookup_h */