hs-test: add libunwind dependency to vpp dockerfile
[vpp.git] / src / plugins / nsh / nsh_api.c
1 /*
2  * nsh_api.c - nsh mapping api
3  *
4  * Copyright (c) 2019 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #include <vnet/vnet.h>
18 #include <vnet/plugin/plugin.h>
19 #include <nsh/nsh.h>
20
21 #include <vlibapi/api.h>
22 #include <vlibmemory/api.h>
23 #include <vpp/app/version.h>
24 #include <vlibapi/api_helper_macros.h>
25
26 #include <plugins/nsh/nsh.api_enum.h>
27 #include <plugins/nsh/nsh.api_types.h>
28
29 /**
30  * @brief CLI function for NSH admin up/down
31  *
32  * @param *vnm
33  * @param nsh_hw_if
34  * @param flag
35  *
36  * @return *rc
37  *
38  */
39 static clib_error_t *
40 nsh_interface_admin_up_down (vnet_main_t * vnm, u32 nsh_hw_if, u32 flags)
41 {
42   if (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
43     vnet_hw_interface_set_flags (vnm, nsh_hw_if,
44                                  VNET_HW_INTERFACE_FLAG_LINK_UP);
45   else
46     vnet_hw_interface_set_flags (vnm, nsh_hw_if, 0);
47
48   return 0;
49 }
50
51 /**
52  * @brief Naming for NSH tunnel
53  *
54  * @param *s formatting string
55  * @param *args
56  *
57  * @return *s formatted string
58  *
59  */
60 static u8 *
61 format_nsh_name (u8 * s, va_list * args)
62 {
63   u32 dev_instance = va_arg (*args, u32);
64   return format (s, "nsh_tunnel%d", dev_instance);
65 }
66
67 VNET_DEVICE_CLASS (nsh_device_class, static) = {
68   .name = "NSH",
69   .format_device_name = format_nsh_name,
70   .admin_up_down_function = nsh_interface_admin_up_down,
71 };
72
73 static void send_nsh_entry_details
74   (nsh_entry_t * t, vl_api_registration_t * rp, u32 context)
75 {
76   vl_api_nsh_entry_details_t *rmp;
77   nsh_main_t *nm = &nsh_main;
78
79   rmp = vl_msg_api_alloc (sizeof (*rmp));
80   clib_memset (rmp, 0, sizeof (*rmp));
81
82   rmp->_vl_msg_id = ntohs ((VL_API_NSH_ENTRY_DETAILS) + nm->msg_id_base);
83   rmp->ver_o_c = t->nsh_base.ver_o_c;
84   rmp->ttl = (t->nsh_base.ver_o_c & NSH_TTL_H4_MASK) << 2 |
85     (t->nsh_base.length & NSH_TTL_L2_MASK) >> 6;
86   rmp->length = t->nsh_base.length & NSH_LEN_MASK;
87   rmp->md_type = t->nsh_base.md_type;
88   rmp->next_protocol = t->nsh_base.next_protocol;
89   rmp->nsp_nsi = htonl (t->nsh_base.nsp_nsi);
90
91   if (t->nsh_base.md_type == 1)
92     {
93       rmp->tlv_length = 4;
94       rmp->c1 = htonl (t->md.md1_data.c1);
95       rmp->c2 = htonl (t->md.md1_data.c2);
96       rmp->c3 = htonl (t->md.md1_data.c3);
97       rmp->c4 = htonl (t->md.md1_data.c4);
98     }
99   else if (t->nsh_base.md_type == 2)
100     {
101       rmp->tlv_length = t->tlvs_len;
102       clib_memcpy (rmp->tlv, t->tlvs_data, t->tlvs_len);
103     }
104
105   rmp->context = context;
106
107   vl_api_send_msg (rp, (u8 *) rmp);
108 }
109
110 static void send_nsh_map_details
111   (nsh_map_t * t, vl_api_registration_t * rp, u32 context)
112 {
113   vl_api_nsh_map_details_t *rmp;
114   nsh_main_t *nm = &nsh_main;
115
116   rmp = vl_msg_api_alloc (sizeof (*rmp));
117   clib_memset (rmp, 0, sizeof (*rmp));
118
119   rmp->_vl_msg_id = ntohs ((VL_API_NSH_MAP_DETAILS) + nm->msg_id_base);
120   rmp->nsp_nsi = htonl (t->nsp_nsi);
121   rmp->mapped_nsp_nsi = htonl (t->mapped_nsp_nsi);
122   rmp->nsh_action = htonl (t->nsh_action);
123   rmp->sw_if_index = htonl (t->sw_if_index);
124   rmp->rx_sw_if_index = htonl (t->rx_sw_if_index);
125   rmp->next_node = htonl (t->next_node);
126
127   rmp->context = context;
128
129   vl_api_send_msg (rp, (u8 *) rmp);
130 }
131
132 static void
133 vl_api_nsh_map_dump_t_handler (vl_api_nsh_map_dump_t * mp)
134 {
135   nsh_main_t *nm = &nsh_main;
136   nsh_map_t *t;
137   u32 map_index;
138   vl_api_registration_t *rp;
139
140   rp = vl_api_client_index_to_registration (mp->client_index);
141   if (rp == 0)
142     return;
143
144   map_index = ntohl (mp->map_index);
145
146   if (~0 == map_index)
147     {
148       pool_foreach (t, nm->nsh_mappings)
149       {
150         send_nsh_map_details (t, rp, mp->context);
151       }
152     }
153   else
154     {
155       if (map_index >= vec_len (nm->nsh_mappings))
156         {
157           return;
158         }
159       t = &nm->nsh_mappings[map_index];
160       send_nsh_map_details (t, rp, mp->context);
161     }
162 }
163
164 /** API message handler */
165 static void
166 vl_api_nsh_add_del_map_t_handler (vl_api_nsh_add_del_map_t * mp)
167 {
168   vl_api_nsh_add_del_map_reply_t *rmp;
169   int rv;
170   nsh_add_del_map_args_t _a = { 0 }, *a = &_a;
171   u32 map_index = ~0;
172
173   a->is_add = mp->is_add;
174   a->map.nsp_nsi = ntohl (mp->nsp_nsi);
175   a->map.mapped_nsp_nsi = ntohl (mp->mapped_nsp_nsi);
176   a->map.nsh_action = ntohl (mp->nsh_action);
177   a->map.sw_if_index = ntohl (mp->sw_if_index);
178   a->map.rx_sw_if_index = ntohl (mp->rx_sw_if_index);
179   a->map.next_node = ntohl (mp->next_node);
180
181   rv = nsh_add_del_map (a, &map_index);
182
183   if ((a->map.next_node == NSH_NODE_NEXT_ENCAP_VXLAN4)
184       | (a->map.next_node == NSH_NODE_NEXT_ENCAP_VXLAN6))
185     {
186       rv = nsh_add_del_proxy_session (a);
187     }
188
189   REPLY_MACRO2 (VL_API_NSH_ADD_DEL_MAP_REPLY, (
190                                                 {
191                                                 rmp->map_index =
192                                                 htonl (map_index);
193                                                 }
194                 ));
195 }
196
197 int
198 nsh_header_rewrite (nsh_entry_t * nsh_entry)
199 {
200   u8 *rw = 0;
201   int len = 0;
202   nsh_base_header_t *nsh_base;
203   nsh_md1_data_t *nsh_md1;
204   nsh_main_t *nm = &nsh_main;
205   nsh_md2_data_t *opt0;
206   nsh_md2_data_t *limit0;
207   nsh_md2_data_t *nsh_md2;
208   nsh_option_map_t _nsh_option, *nsh_option = &_nsh_option;
209   u8 old_option_size = 0;
210   u8 new_option_size = 0;
211
212   vec_free (nsh_entry->rewrite);
213   if (nsh_entry->nsh_base.md_type == 1)
214     {
215       len = sizeof (nsh_base_header_t) + sizeof (nsh_md1_data_t);
216     }
217   else if (nsh_entry->nsh_base.md_type == 2)
218     {
219       /* set to maxim, maybe dataplane will add more TLVs */
220       len = MAX_NSH_HEADER_LEN;
221     }
222   vec_validate_aligned (rw, len - 1, CLIB_CACHE_LINE_BYTES);
223   clib_memset (rw, 0, len);
224
225   nsh_base = (nsh_base_header_t *) rw;
226   nsh_base->ver_o_c = nsh_entry->nsh_base.ver_o_c;
227   nsh_base->length = nsh_entry->nsh_base.length;
228   nsh_base->md_type = nsh_entry->nsh_base.md_type;
229   nsh_base->next_protocol = nsh_entry->nsh_base.next_protocol;
230   nsh_base->nsp_nsi = clib_host_to_net_u32 (nsh_entry->nsh_base.nsp_nsi);
231
232   if (nsh_base->md_type == 1)
233     {
234       nsh_md1 = (nsh_md1_data_t *) (rw + sizeof (nsh_base_header_t));
235       nsh_md1->c1 = clib_host_to_net_u32 (nsh_entry->md.md1_data.c1);
236       nsh_md1->c2 = clib_host_to_net_u32 (nsh_entry->md.md1_data.c2);
237       nsh_md1->c3 = clib_host_to_net_u32 (nsh_entry->md.md1_data.c3);
238       nsh_md1->c4 = clib_host_to_net_u32 (nsh_entry->md.md1_data.c4);
239       nsh_entry->rewrite_size = 24;
240     }
241   else if (nsh_base->md_type == 2)
242     {
243       opt0 = (nsh_md2_data_t *) (nsh_entry->tlvs_data);
244       limit0 = (nsh_md2_data_t *) ((u8 *) opt0 + nsh_entry->tlvs_len);
245
246       nsh_md2 = (nsh_md2_data_t *) (rw + sizeof (nsh_base_header_t));
247       nsh_entry->rewrite_size = sizeof (nsh_base_header_t);
248
249       while (opt0 < limit0)
250         {
251           old_option_size = sizeof (nsh_md2_data_t) + opt0->length;
252           /* round to 4-byte */
253           old_option_size = ((old_option_size + 3) >> 2) << 2;
254
255           nsh_option = nsh_md2_lookup_option (opt0->class, opt0->type);
256           if (nsh_option == NULL)
257             {
258               goto next_tlv_md2;
259             }
260
261           if (nm->add_options[nsh_option->option_id] != NULL)
262             {
263               if (0 != nm->add_options[nsh_option->option_id] ((u8 *) nsh_md2,
264                                                                &new_option_size))
265                 {
266                   goto next_tlv_md2;
267                 }
268
269               /* round to 4-byte */
270               new_option_size = ((new_option_size + 3) >> 2) << 2;
271
272               nsh_entry->rewrite_size += new_option_size;
273               nsh_md2 =
274                 (nsh_md2_data_t *) (((u8 *) nsh_md2) + new_option_size);
275               opt0 = (nsh_md2_data_t *) (((u8 *) opt0) + old_option_size);
276             }
277           else
278             {
279             next_tlv_md2:
280               opt0 = (nsh_md2_data_t *) (((u8 *) opt0) + old_option_size);
281             }
282
283         }
284     }
285
286   nsh_entry->rewrite = rw;
287   nsh_base->length = (nsh_base->length & NSH_TTL_L2_MASK) |
288     ((nsh_entry->rewrite_size >> 2) & NSH_LEN_MASK);
289
290   return 0;
291 }
292
293 extern vnet_hw_interface_class_t nsh_hw_class;
294
295 /**
296  * Action function to add or del an nsh map.
297  * Shared by both CLI and binary API
298  **/
299 int
300 nsh_add_del_map (nsh_add_del_map_args_t * a, u32 * map_indexp)
301 {
302   nsh_main_t *nm = &nsh_main;
303   vnet_main_t *vnm = nm->vnet_main;
304   nsh_map_t *map = 0;
305   u32 key, *key_copy;
306   uword *entry;
307   hash_pair_t *hp;
308   u32 map_index = ~0;
309   vnet_hw_interface_t *hi;
310   u32 nsh_hw_if = ~0;
311   u32 nsh_sw_if = ~0;
312
313   /* net order, so data plane could use nsh header to lookup directly */
314   key = clib_host_to_net_u32 (a->map.nsp_nsi);
315
316   entry = hash_get_mem (nm->nsh_mapping_by_key, &key);
317
318   if (a->is_add)
319     {
320       /* adding an entry, must not already exist */
321       if (entry)
322         return -1;              //TODO API_ERROR_INVALID_VALUE;
323
324       pool_get_aligned (nm->nsh_mappings, map, CLIB_CACHE_LINE_BYTES);
325       clib_memset (map, 0, sizeof (*map));
326
327       /* copy from arg structure */
328       map->nsp_nsi = a->map.nsp_nsi;
329       map->mapped_nsp_nsi = a->map.mapped_nsp_nsi;
330       map->nsh_action = a->map.nsh_action;
331       map->sw_if_index = a->map.sw_if_index;
332       map->rx_sw_if_index = a->map.rx_sw_if_index;
333       map->next_node = a->map.next_node;
334       map->adj_index = a->map.adj_index;
335
336
337       key_copy = clib_mem_alloc (sizeof (*key_copy));
338       clib_memcpy (key_copy, &key, sizeof (*key_copy));
339
340       hash_set_mem (nm->nsh_mapping_by_key, key_copy, map - nm->nsh_mappings);
341       map_index = map - nm->nsh_mappings;
342
343       if (vec_len (nm->free_nsh_tunnel_hw_if_indices) > 0)
344         {
345           nsh_hw_if = nm->free_nsh_tunnel_hw_if_indices
346             [vec_len (nm->free_nsh_tunnel_hw_if_indices) - 1];
347           vec_dec_len (nm->free_nsh_tunnel_hw_if_indices, 1);
348
349           hi = vnet_get_hw_interface (vnm, nsh_hw_if);
350           hi->dev_instance = map_index;
351           hi->hw_instance = hi->dev_instance;
352         }
353       else
354         {
355           nsh_hw_if = vnet_register_interface
356             (vnm, nsh_device_class.index, map_index, nsh_hw_class.index,
357              map_index);
358           hi = vnet_get_hw_interface (vnm, nsh_hw_if);
359           hi->output_node_index = nsh_aware_vnf_proxy_node.index;
360         }
361
362       map->nsh_hw_if = nsh_hw_if;
363       map->nsh_sw_if = nsh_sw_if = hi->sw_if_index;
364       vec_validate_init_empty (nm->tunnel_index_by_sw_if_index, nsh_sw_if,
365                                ~0);
366       nm->tunnel_index_by_sw_if_index[nsh_sw_if] = key;
367
368       vnet_sw_interface_set_flags (vnm, hi->sw_if_index,
369                                    VNET_SW_INTERFACE_FLAG_ADMIN_UP);
370     }
371   else
372     {
373       if (!entry)
374         return -2;              //TODO API_ERROR_NO_SUCH_ENTRY;
375
376       map = pool_elt_at_index (nm->nsh_mappings, entry[0]);
377
378       vnet_sw_interface_set_flags (vnm, map->nsh_sw_if,
379                                    VNET_SW_INTERFACE_FLAG_ADMIN_DOWN);
380       vec_add1 (nm->free_nsh_tunnel_hw_if_indices, map->nsh_sw_if);
381       nm->tunnel_index_by_sw_if_index[map->nsh_sw_if] = ~0;
382
383       hp = hash_get_pair (nm->nsh_mapping_by_key, &key);
384       key_copy = (void *) (hp->key);
385       hash_unset_mem (nm->nsh_mapping_by_key, &key);
386       clib_mem_free (key_copy);
387
388       pool_put (nm->nsh_mappings, map);
389     }
390
391   if (map_indexp)
392     *map_indexp = map_index;
393
394   return 0;
395 }
396
397 /**
398  * Action function to add or del an nsh-proxy-session.
399  * Shared by both CLI and binary API
400  **/
401 int
402 nsh_add_del_proxy_session (nsh_add_del_map_args_t * a)
403 {
404   nsh_main_t *nm = &nsh_main;
405   nsh_proxy_session_t *proxy = 0;
406   nsh_proxy_session_by_key_t key, *key_copy;
407   uword *entry;
408   hash_pair_t *hp;
409   u32 nsp = 0, nsi = 0;
410
411   clib_memset (&key, 0, sizeof (key));
412   key.transport_type = a->map.next_node;
413   key.transport_index = a->map.sw_if_index;
414
415   entry = hash_get_mem (nm->nsh_proxy_session_by_key, &key);
416
417   if (a->is_add)
418     {
419       /* adding an entry, must not already exist */
420       if (entry)
421         return -1;              //TODO API_ERROR_INVALID_VALUE;
422
423       pool_get_aligned (nm->nsh_proxy_sessions, proxy, CLIB_CACHE_LINE_BYTES);
424       clib_memset (proxy, 0, sizeof (*proxy));
425
426       /* Nsi needs to minus 1 within NSH-Proxy */
427       nsp = (a->map.nsp_nsi >> NSH_NSP_SHIFT) & NSH_NSP_MASK;
428       nsi = a->map.nsp_nsi & NSH_NSI_MASK;
429       if (nsi == 0)
430         return -1;
431
432       nsi = nsi - 1;
433       /* net order, so could use it to lookup nsh map table directly */
434       proxy->nsp_nsi = clib_host_to_net_u32 ((nsp << NSH_NSP_SHIFT) | nsi);
435
436       key_copy = clib_mem_alloc (sizeof (*key_copy));
437       clib_memcpy (key_copy, &key, sizeof (*key_copy));
438
439       hash_set_mem (nm->nsh_proxy_session_by_key, key_copy,
440                     proxy - nm->nsh_proxy_sessions);
441     }
442   else
443     {
444       if (!entry)
445         return -2;              //TODO API_ERROR_NO_SUCH_ENTRY;
446
447       proxy = pool_elt_at_index (nm->nsh_proxy_sessions, entry[0]);
448       hp = hash_get_pair (nm->nsh_proxy_session_by_key, &key);
449       key_copy = (void *) (hp->key);
450       hash_unset_mem (nm->nsh_proxy_session_by_key, &key);
451       clib_mem_free (key_copy);
452
453       pool_put (nm->nsh_proxy_sessions, proxy);
454     }
455
456   return 0;
457 }
458
459 /**
460  * Action function for adding an NSH entry
461  * nsh_add_del_entry_args_t *a: host order
462  */
463 int
464 nsh_add_del_entry (nsh_add_del_entry_args_t * a, u32 * entry_indexp)
465 {
466   nsh_main_t *nm = &nsh_main;
467   nsh_entry_t *nsh_entry = 0;
468   u32 key, *key_copy;
469   uword *entry_id;
470   hash_pair_t *hp;
471   u32 entry_index = ~0;
472   u8 tlvs_len = 0;
473   u8 *data = 0;
474
475   /* host order, because nsh map table stores nsp_nsi in host order */
476   key = a->nsh_entry.nsh_base.nsp_nsi;
477
478   entry_id = hash_get_mem (nm->nsh_entry_by_key, &key);
479
480   if (a->is_add)
481     {
482       /* adding an entry, must not already exist */
483       if (entry_id)
484         return -1;              // TODO VNET_API_ERROR_INVALID_VALUE;
485
486       pool_get_aligned (nm->nsh_entries, nsh_entry, CLIB_CACHE_LINE_BYTES);
487       clib_memset (nsh_entry, 0, sizeof (*nsh_entry));
488
489       /* copy from arg structure */
490 #define _(x) nsh_entry->nsh_base.x = a->nsh_entry.nsh_base.x;
491       foreach_copy_nsh_base_hdr_field;
492 #undef _
493
494       if (a->nsh_entry.nsh_base.md_type == 1)
495         {
496           nsh_entry->md.md1_data.c1 = a->nsh_entry.md.md1_data.c1;
497           nsh_entry->md.md1_data.c2 = a->nsh_entry.md.md1_data.c2;
498           nsh_entry->md.md1_data.c3 = a->nsh_entry.md.md1_data.c3;
499           nsh_entry->md.md1_data.c4 = a->nsh_entry.md.md1_data.c4;
500         }
501       else if (a->nsh_entry.nsh_base.md_type == 2)
502         {
503           vec_free (nsh_entry->tlvs_data);
504           tlvs_len = a->nsh_entry.tlvs_len;
505           vec_validate_aligned (data, tlvs_len - 1, CLIB_CACHE_LINE_BYTES);
506
507           clib_memcpy (data, a->nsh_entry.tlvs_data, tlvs_len);
508           nsh_entry->tlvs_data = data;
509           nsh_entry->tlvs_len = tlvs_len;
510           vec_free (a->nsh_entry.tlvs_data);
511         }
512
513       nsh_header_rewrite (nsh_entry);
514
515       key_copy = clib_mem_alloc (sizeof (*key_copy));
516       clib_memcpy (key_copy, &key, sizeof (*key_copy));
517
518       hash_set_mem (nm->nsh_entry_by_key, key_copy,
519                     nsh_entry - nm->nsh_entries);
520       entry_index = nsh_entry - nm->nsh_entries;
521     }
522   else
523     {
524       if (!entry_id)
525         return -2;              //TODO API_ERROR_NO_SUCH_ENTRY;
526
527       nsh_entry = pool_elt_at_index (nm->nsh_entries, entry_id[0]);
528       hp = hash_get_pair (nm->nsh_entry_by_key, &key);
529       key_copy = (void *) (hp->key);
530       hash_unset_mem (nm->nsh_entry_by_key, &key);
531       clib_mem_free (key_copy);
532
533       vec_free (nsh_entry->tlvs_data);
534       vec_free (nsh_entry->rewrite);
535       pool_put (nm->nsh_entries, nsh_entry);
536     }
537
538   if (entry_indexp)
539     *entry_indexp = entry_index;
540
541   return 0;
542 }
543
544
545 /** API message handler */
546 static void vl_api_nsh_add_del_entry_t_handler
547   (vl_api_nsh_add_del_entry_t * mp)
548 {
549   vl_api_nsh_add_del_entry_reply_t *rmp;
550   int rv;
551   nsh_add_del_entry_args_t _a = { 0 }, *a = &_a;
552   u32 entry_index = ~0;
553   u8 tlvs_len = 0;
554   u8 *data = 0;
555
556   a->is_add = mp->is_add;
557   a->nsh_entry.nsh_base.ver_o_c =
558     (mp->ver_o_c & 0xF0) | ((mp->ttl & NSH_LEN_MASK) >> 2);
559   a->nsh_entry.nsh_base.length =
560     (mp->length & NSH_LEN_MASK) | ((mp->ttl & 0x3) << 6);
561   a->nsh_entry.nsh_base.md_type = mp->md_type;
562   a->nsh_entry.nsh_base.next_protocol = mp->next_protocol;
563   a->nsh_entry.nsh_base.nsp_nsi = ntohl (mp->nsp_nsi);
564   if (mp->md_type == 1)
565     {
566       a->nsh_entry.md.md1_data.c1 = ntohl (mp->c1);
567       a->nsh_entry.md.md1_data.c2 = ntohl (mp->c2);
568       a->nsh_entry.md.md1_data.c3 = ntohl (mp->c3);
569       a->nsh_entry.md.md1_data.c4 = ntohl (mp->c4);
570     }
571   else if (mp->md_type == 2)
572     {
573       tlvs_len = mp->tlv_length;
574       vec_validate_aligned (data, tlvs_len - 1, CLIB_CACHE_LINE_BYTES);
575
576       clib_memcpy (data, mp->tlv, tlvs_len);
577       a->nsh_entry.tlvs_data = data;
578       a->nsh_entry.tlvs_len = tlvs_len;
579     }
580
581   rv = nsh_add_del_entry (a, &entry_index);
582
583   REPLY_MACRO2 (VL_API_NSH_ADD_DEL_ENTRY_REPLY, (
584                                                   {
585                                                   rmp->entry_index =
586                                                   htonl (entry_index);
587                                                   }
588                 ));
589 }
590
591 static void
592 vl_api_nsh_entry_dump_t_handler (vl_api_nsh_entry_dump_t * mp)
593 {
594   nsh_main_t *nm = &nsh_main;
595   nsh_entry_t *t;
596   u32 entry_index;
597   vl_api_registration_t *rp;
598
599   rp = vl_api_client_index_to_registration (mp->client_index);
600   if (rp == 0)
601     return;
602
603   entry_index = ntohl (mp->entry_index);
604
605   if (~0 == entry_index)
606     {
607       pool_foreach (t, nm->nsh_entries)
608       {
609         send_nsh_entry_details (t, rp, mp->context);
610       }
611     }
612   else
613     {
614       if (entry_index >= vec_len (nm->nsh_entries))
615         {
616           return;
617         }
618       t = &nm->nsh_entries[entry_index];
619       send_nsh_entry_details (t, rp, mp->context);
620     }
621 }
622
623 #include <nsh/nsh.api.c>
624
625 /* Set up the API message handling tables */
626 clib_error_t *
627 nsh_api_init (vlib_main_t * vm, nsh_main_t * nm)
628 {
629   /* Add our API messages to the global name_crc hash table */
630   nm->msg_id_base = setup_message_id_table ();
631
632   return 0;
633 }
634
635 /*
636  * fd.io coding-style-patch-verification: ON
637  *
638  * Local Variables:
639  * eval: (c-set-style "gnu")
640  * End:
641  */