MAP: Convert from DPO to input feature.
[vpp.git] / src / plugins / map / map_api.c
1 /*
2  *------------------------------------------------------------------
3  * map_api.c - vnet map api
4  *
5  * Copyright (c) 2016 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19
20 #include <map/map.h>
21 #include <map/map_msg_enum.h>
22 #include <vnet/ip/ip.h>
23 #include <vnet/fib/fib_table.h>
24 #include <vlibmemory/api.h>
25
26 #define vl_typedefs             /* define message structures */
27 #include <map/map_all_api_h.h>
28 #undef vl_typedefs
29
30 #define vl_endianfun            /* define message structures */
31 #include <map/map_all_api_h.h>
32 #undef vl_endianfun
33
34 /* instantiate all the print functions we know about */
35 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
36 #define vl_printfun
37 #include <map/map_all_api_h.h>
38 #undef vl_printfun
39
40 /* Get the API version number */
41 #define vl_api_version(n,v) static u32 api_version=(v);
42 #include <map/map_all_api_h.h>
43 #undef vl_api_version
44
45 #define REPLY_MSG_ID_BASE mm->msg_id_base
46 #include <vlibapi/api_helper_macros.h>
47
48 static void
49 vl_api_map_add_domain_t_handler (vl_api_map_add_domain_t * mp)
50 {
51   map_main_t *mm = &map_main;
52   vl_api_map_add_domain_reply_t *rmp;
53   int rv = 0;
54   u32 index;
55   u8 flags = 0;
56
57   rv =
58     map_create_domain ((ip4_address_t *) & mp->ip4_prefix.prefix,
59                        mp->ip4_prefix.len,
60                        (ip6_address_t *) & mp->ip6_prefix.prefix,
61                        mp->ip6_prefix.len,
62                        (ip6_address_t *) & mp->ip6_src.prefix,
63                        mp->ip6_src.len, mp->ea_bits_len, mp->psid_offset,
64                        mp->psid_length, &index, ntohs (mp->mtu), flags);
65
66   /* *INDENT-OFF* */
67   REPLY_MACRO2(VL_API_MAP_ADD_DOMAIN_REPLY,
68   ({
69     rmp->index = ntohl(index);
70   }));
71   /* *INDENT-ON* */
72 }
73
74 static void
75 vl_api_map_del_domain_t_handler (vl_api_map_del_domain_t * mp)
76 {
77   map_main_t *mm = &map_main;
78   vl_api_map_del_domain_reply_t *rmp;
79   int rv = 0;
80
81   rv = map_delete_domain (ntohl (mp->index));
82
83   REPLY_MACRO (VL_API_MAP_DEL_DOMAIN_REPLY);
84 }
85
86 static void
87 vl_api_map_add_del_rule_t_handler (vl_api_map_add_del_rule_t * mp)
88 {
89   map_main_t *mm = &map_main;
90   vl_api_map_del_domain_reply_t *rmp;
91   int rv = 0;
92
93   rv =
94     map_add_del_psid (ntohl (mp->index), ntohs (mp->psid),
95                       (ip6_address_t *) & mp->ip6_dst, mp->is_add);
96
97   REPLY_MACRO (VL_API_MAP_ADD_DEL_RULE_REPLY);
98 }
99
100 static void
101 vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp)
102 {
103   vl_api_map_domain_details_t *rmp;
104   map_main_t *mm = &map_main;
105   map_domain_t *d;
106   vl_api_registration_t *reg;
107
108   if (pool_elts (mm->domains) == 0)
109     return;
110
111   reg = vl_api_client_index_to_registration (mp->client_index);
112   if (!reg)
113     return;
114
115   /* *INDENT-OFF* */
116   pool_foreach(d, mm->domains,
117   ({
118     /* Make sure every field is initiated (or don't skip the clib_memset()) */
119     rmp = vl_msg_api_alloc (sizeof (*rmp));
120     rmp->_vl_msg_id = htons(VL_API_MAP_DOMAIN_DETAILS + mm->msg_id_base);
121     rmp->context = mp->context;
122     rmp->domain_index = htonl(d - mm->domains);
123     clib_memcpy(&rmp->ip6_prefix.prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix.prefix));
124     clib_memcpy(&rmp->ip4_prefix.prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix.prefix));
125     clib_memcpy(&rmp->ip6_src.prefix, &d->ip6_src, sizeof(rmp->ip6_src.prefix));
126     rmp->ip6_prefix.len = d->ip6_prefix_len;
127     rmp->ip4_prefix.len = d->ip4_prefix_len;
128     rmp->ip6_src.len = d->ip6_src_len;
129     rmp->ea_bits_len = d->ea_bits_len;
130     rmp->psid_offset = d->psid_offset;
131     rmp->psid_length = d->psid_length;
132     rmp->flags = d->flags;
133     rmp->mtu = htons(d->mtu);
134
135     vl_api_send_msg (reg, (u8 *) rmp);
136   }));
137   /* *INDENT-ON* */
138 }
139
140 static void
141 vl_api_map_rule_dump_t_handler (vl_api_map_rule_dump_t * mp)
142 {
143   vl_api_registration_t *reg;
144   u16 i;
145   ip6_address_t dst;
146   vl_api_map_rule_details_t *rmp;
147   map_main_t *mm = &map_main;
148   u32 domain_index = ntohl (mp->domain_index);
149   map_domain_t *d;
150
151   if (pool_elts (mm->domains) == 0)
152     return;
153
154   d = pool_elt_at_index (mm->domains, domain_index);
155   if (!d || !d->rules)
156     {
157       return;
158     }
159
160   reg = vl_api_client_index_to_registration (mp->client_index);
161   if (!reg)
162     return;
163
164   for (i = 0; i < (0x1 << d->psid_length); i++)
165     {
166       dst = d->rules[i];
167       if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0)
168         {
169           continue;
170         }
171       rmp = vl_msg_api_alloc (sizeof (*rmp));
172       clib_memset (rmp, 0, sizeof (*rmp));
173       rmp->_vl_msg_id = ntohs (VL_API_MAP_RULE_DETAILS + mm->msg_id_base);
174       rmp->psid = htons (i);
175       clib_memcpy (&rmp->ip6_dst, &dst, sizeof (rmp->ip6_dst));
176       rmp->context = mp->context;
177       vl_api_send_msg (reg, (u8 *) rmp);
178     }
179 }
180
181 static void
182 vl_api_map_summary_stats_t_handler (vl_api_map_summary_stats_t * mp)
183 {
184   vl_api_map_summary_stats_reply_t *rmp;
185   vlib_combined_counter_main_t *cm;
186   vlib_counter_t v;
187   int i, which;
188   u64 total_pkts[VLIB_N_RX_TX];
189   u64 total_bytes[VLIB_N_RX_TX];
190   map_main_t *mm = &map_main;
191   vl_api_registration_t *reg;
192
193   reg = vl_api_client_index_to_registration (mp->client_index);
194   if (!reg)
195     return;
196
197   rmp = vl_msg_api_alloc (sizeof (*rmp));
198   rmp->_vl_msg_id = htons (VL_API_MAP_SUMMARY_STATS_REPLY + mm->msg_id_base);
199   rmp->context = mp->context;
200   rmp->retval = 0;
201
202   if (pool_elts (mm->domains) == 0)
203     {
204       rmp->retval = -1;
205       goto out;
206     }
207
208   clib_memset (total_pkts, 0, sizeof (total_pkts));
209   clib_memset (total_bytes, 0, sizeof (total_bytes));
210
211   map_domain_counter_lock (mm);
212   vec_foreach (cm, mm->domain_counters)
213   {
214     which = cm - mm->domain_counters;
215
216     for (i = 0; i < vlib_combined_counter_n_counters (cm); i++)
217       {
218         vlib_get_combined_counter (cm, i, &v);
219         total_pkts[which] += v.packets;
220         total_bytes[which] += v.bytes;
221       }
222   }
223
224   map_domain_counter_unlock (mm);
225
226   /* Note: in network byte order! */
227   rmp->total_pkts[MAP_DOMAIN_COUNTER_RX] =
228     clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_RX]);
229   rmp->total_bytes[MAP_DOMAIN_COUNTER_RX] =
230     clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_RX]);
231   rmp->total_pkts[MAP_DOMAIN_COUNTER_TX] =
232     clib_host_to_net_u64 (total_pkts[MAP_DOMAIN_COUNTER_TX]);
233   rmp->total_bytes[MAP_DOMAIN_COUNTER_TX] =
234     clib_host_to_net_u64 (total_bytes[MAP_DOMAIN_COUNTER_TX]);
235   rmp->total_bindings = clib_host_to_net_u64 (pool_elts (mm->domains));
236   rmp->total_ip4_fragments = 0; // Not yet implemented. Should be a simple counter.
237   rmp->total_security_check[MAP_DOMAIN_COUNTER_TX] =
238     clib_host_to_net_u64 (map_error_counter_get
239                           (ip4_map_node.index, MAP_ERROR_ENCAP_SEC_CHECK));
240   rmp->total_security_check[MAP_DOMAIN_COUNTER_RX] =
241     clib_host_to_net_u64 (map_error_counter_get
242                           (ip4_map_node.index, MAP_ERROR_DECAP_SEC_CHECK));
243
244 out:
245   vl_api_send_msg (reg, (u8 *) rmp);
246 }
247
248
249 int
250 map_param_set_fragmentation (bool inner, bool ignore_df)
251 {
252   map_main_t *mm = &map_main;
253
254   mm->frag_inner = ! !inner;
255   mm->frag_ignore_df = ! !ignore_df;
256
257   return 0;
258 }
259
260 static void
261   vl_api_map_param_set_fragmentation_t_handler
262   (vl_api_map_param_set_fragmentation_t * mp)
263 {
264   map_main_t *mm = &map_main;
265   vl_api_map_param_set_fragmentation_reply_t *rmp;
266   int rv = 0;
267
268   rv = map_param_set_fragmentation (mp->inner, mp->ignore_df);
269
270   REPLY_MACRO (VL_API_MAP_PARAM_SET_FRAGMENTATION_REPLY);
271 }
272
273
274 int
275 map_param_set_icmp (ip4_address_t * icmp_src_address)
276 {
277   map_main_t *mm = &map_main;
278
279   if (icmp_src_address == 0)
280     return -1;
281
282   mm->icmp4_src_address = *icmp_src_address;
283
284   return 0;
285 }
286
287
288 static void
289 vl_api_map_param_set_icmp_t_handler (vl_api_map_param_set_icmp_t * mp)
290 {
291   map_main_t *mm = &map_main;
292   vl_api_map_param_set_icmp_reply_t *rmp;
293   int rv;
294
295   rv = map_param_set_icmp ((ip4_address_t *) & mp->ip4_err_relay_src);
296
297   REPLY_MACRO (VL_API_MAP_PARAM_SET_ICMP_REPLY);
298 }
299
300
301 int
302 map_param_set_icmp6 (u8 enable_unreachable)
303 {
304   map_main_t *mm = &map_main;
305
306   mm->icmp6_enabled = ! !enable_unreachable;
307
308   return 0;
309 }
310
311 static void
312 vl_api_map_param_set_icmp6_t_handler (vl_api_map_param_set_icmp6_t * mp)
313 {
314   map_main_t *mm = &map_main;
315   vl_api_map_param_set_icmp6_reply_t *rmp;
316   int rv;
317
318   rv = map_param_set_icmp6 (mp->enable_unreachable);
319
320   REPLY_MACRO (VL_API_MAP_PARAM_SET_ICMP6_REPLY);
321 }
322
323
324 static void
325   vl_api_map_param_add_del_pre_resolve_t_handler
326   (vl_api_map_param_add_del_pre_resolve_t * mp)
327 {
328   map_main_t *mm = &map_main;
329   vl_api_map_param_add_del_pre_resolve_reply_t *rmp;
330   int rv = 0;
331
332   map_pre_resolve ((ip4_address_t *) & mp->ip4_nh_address,
333                    (ip6_address_t *) & mp->ip6_nh_address, !mp->is_add);
334
335   REPLY_MACRO (VL_API_MAP_PARAM_ADD_DEL_PRE_RESOLVE_REPLY);
336 }
337
338
339 int
340 map_param_set_reassembly (bool is_ipv6,
341                           u16 lifetime_ms,
342                           u16 pool_size,
343                           u32 buffers,
344                           f64 ht_ratio, u32 * reass, u32 * packets)
345 {
346   u32 ps_reass = 0, ps_packets = 0;
347   u32 ht_reass = 0, ht_packets = 0;
348
349   if (is_ipv6)
350     {
351       if (pool_size != (u16) ~ 0)
352         {
353           if (pool_size > MAP_IP6_REASS_CONF_POOL_SIZE_MAX)
354             return MAP_ERR_BAD_POOL_SIZE;
355           if (map_ip6_reass_conf_pool_size
356               (pool_size, &ps_reass, &ps_packets))
357             return MAP_ERR_BAD_POOL_SIZE;
358         }
359
360       if (ht_ratio != (MAP_IP6_REASS_CONF_HT_RATIO_MAX + 1))
361         {
362           if (ht_ratio > MAP_IP6_REASS_CONF_HT_RATIO_MAX)
363             return MAP_ERR_BAD_HT_RATIO;
364           if (map_ip6_reass_conf_ht_ratio (ht_ratio, &ht_reass, &ht_packets))
365             return MAP_ERR_BAD_HT_RATIO;
366         }
367
368       if (lifetime_ms != (u16) ~ 0)
369         {
370           if (lifetime_ms > MAP_IP6_REASS_CONF_LIFETIME_MAX)
371             return MAP_ERR_BAD_LIFETIME;
372           if (map_ip6_reass_conf_lifetime (lifetime_ms))
373             return MAP_ERR_BAD_LIFETIME;
374         }
375
376       if (buffers != ~0)
377         {
378           if (buffers > MAP_IP6_REASS_CONF_BUFFERS_MAX)
379             return MAP_ERR_BAD_BUFFERS;
380           if (map_ip6_reass_conf_buffers (buffers))
381             return MAP_ERR_BAD_BUFFERS;
382         }
383
384       if (map_main.ip6_reass_conf_buffers >
385           map_main.ip6_reass_conf_pool_size *
386           MAP_IP6_REASS_MAX_FRAGMENTS_PER_REASSEMBLY)
387         {
388           return MAP_ERR_BAD_BUFFERS_TOO_LARGE;
389         }
390     }
391   else
392     {
393       if (pool_size != (u16) ~ 0)
394         {
395           if (pool_size > MAP_IP4_REASS_CONF_POOL_SIZE_MAX)
396             return MAP_ERR_BAD_POOL_SIZE;
397           if (map_ip4_reass_conf_pool_size
398               (pool_size, &ps_reass, &ps_packets))
399             return MAP_ERR_BAD_POOL_SIZE;
400         }
401
402       if (ht_ratio != (MAP_IP4_REASS_CONF_HT_RATIO_MAX + 1))
403         {
404           if (ht_ratio > MAP_IP4_REASS_CONF_HT_RATIO_MAX)
405             return MAP_ERR_BAD_HT_RATIO;
406           if (map_ip4_reass_conf_ht_ratio (ht_ratio, &ht_reass, &ht_packets))
407             return MAP_ERR_BAD_HT_RATIO;
408         }
409
410       if (lifetime_ms != (u16) ~ 0)
411         {
412           if (lifetime_ms > MAP_IP4_REASS_CONF_LIFETIME_MAX)
413             return MAP_ERR_BAD_LIFETIME;
414           if (map_ip4_reass_conf_lifetime (lifetime_ms))
415             return MAP_ERR_BAD_LIFETIME;
416         }
417
418       if (buffers != ~0)
419         {
420           if (buffers > MAP_IP4_REASS_CONF_BUFFERS_MAX)
421             return MAP_ERR_BAD_BUFFERS;
422           if (map_ip4_reass_conf_buffers (buffers))
423             return MAP_ERR_BAD_BUFFERS;
424         }
425
426       if (map_main.ip4_reass_conf_buffers >
427           map_main.ip4_reass_conf_pool_size *
428           MAP_IP4_REASS_MAX_FRAGMENTS_PER_REASSEMBLY)
429         {
430           return MAP_ERR_BAD_BUFFERS_TOO_LARGE;
431         }
432     }
433
434   if (reass)
435     *reass = ps_reass + ht_reass;
436
437   if (packets)
438     *packets = ps_packets + ht_packets;
439
440   return 0;
441 }
442
443
444 static void
445   vl_api_map_param_set_reassembly_t_handler
446   (vl_api_map_param_set_reassembly_t * mp)
447 {
448   map_main_t *mm = &map_main;
449   vl_api_map_param_set_reassembly_reply_t *rmp;
450   u32 reass = 0, packets = 0;
451   int rv;
452   f64 ht_ratio;
453
454   ht_ratio = (f64) clib_net_to_host_u64 (mp->ht_ratio);
455   if (ht_ratio == ~0)
456     ht_ratio = MAP_IP6_REASS_CONF_HT_RATIO_MAX + 1;
457
458   rv = map_param_set_reassembly (mp->is_ip6,
459                                  clib_net_to_host_u16 (mp->lifetime_ms),
460                                  clib_net_to_host_u16 (mp->pool_size),
461                                  clib_net_to_host_u32 (mp->buffers),
462                                  ht_ratio, &reass, &packets);
463
464   /*
465    * FIXME: Should the lost reass and packet counts be returned in the API?
466    */
467
468   REPLY_MACRO (VL_API_MAP_PARAM_SET_REASSEMBLY_REPLY);
469 }
470
471
472 int
473 map_param_set_security_check (bool enable, bool fragments)
474 {
475   map_main_t *mm = &map_main;
476
477   mm->sec_check = ! !enable;
478   mm->sec_check_frag = ! !fragments;
479
480   return 0;
481 }
482
483 static void
484   vl_api_map_param_set_security_check_t_handler
485   (vl_api_map_param_set_security_check_t * mp)
486 {
487   map_main_t *mm = &map_main;
488   vl_api_map_param_set_security_check_reply_t *rmp;
489   int rv;
490
491   rv = map_param_set_security_check (mp->enable, mp->fragments);
492
493   REPLY_MACRO (VL_API_MAP_PARAM_SET_SECURITY_CHECK_REPLY);
494 }
495
496
497 int
498 map_param_set_traffic_class (bool copy, u8 tc)
499 {
500   map_main_t *mm = &map_main;
501
502   mm->tc_copy = ! !copy;
503   mm->tc = tc;
504
505   return 0;
506 }
507
508 static void
509   vl_api_map_param_set_traffic_class_t_handler
510   (vl_api_map_param_set_traffic_class_t * mp)
511 {
512   map_main_t *mm = &map_main;
513   vl_api_map_param_set_traffic_class_reply_t *rmp;
514   int rv;
515
516   rv = map_param_set_traffic_class (mp->copy, mp->class);
517
518   REPLY_MACRO (VL_API_MAP_PARAM_SET_TRAFFIC_CLASS_REPLY);
519 }
520
521
522 int
523 map_param_set_tcp (u16 tcp_mss)
524 {
525   map_main_t *mm = &map_main;
526
527   mm->tcp_mss = tcp_mss;
528
529   return 0;
530 }
531
532
533 static void
534 vl_api_map_param_set_tcp_t_handler (vl_api_map_param_set_tcp_t * mp)
535 {
536   map_main_t *mm = &map_main;
537   vl_api_map_param_set_tcp_reply_t *rmp;
538   int rv = 0;
539
540   map_param_set_tcp (ntohs (mp->tcp_mss));
541   REPLY_MACRO (VL_API_MAP_PARAM_SET_TCP_REPLY);
542 }
543
544
545 static void
546 vl_api_map_param_get_t_handler (vl_api_map_param_get_t * mp)
547 {
548   map_main_t *mm = &map_main;
549   vl_api_map_param_get_reply_t *rmp;
550   vl_api_registration_t *reg;
551
552   reg = vl_api_client_index_to_registration (mp->client_index);
553   if (!reg)
554     return;
555
556   rmp = vl_msg_api_alloc (sizeof (*rmp));
557   rmp->_vl_msg_id = htons (VL_API_MAP_PARAM_GET_REPLY + mm->msg_id_base);
558   rmp->context = mp->context;
559   rmp->retval = 0;
560
561   rmp->frag_inner = mm->frag_inner;
562   rmp->frag_ignore_df = mm->frag_ignore_df;
563
564   clib_memcpy (&rmp->icmp_ip4_err_relay_src,
565                &mm->icmp4_src_address, sizeof (rmp->icmp_ip4_err_relay_src));
566
567   rmp->icmp6_enable_unreachable = mm->icmp6_enabled;
568
569   /*
570    * FIXME: How are these addresses re-extracted from the FIB?
571    * Or should a local map_main copy be kept?
572    */
573   clib_memset (&rmp->ip4_nh_address, 0, sizeof (rmp->ip4_nh_address));
574   clib_memset (&rmp->ip6_nh_address, 0, sizeof (rmp->ip6_nh_address));
575
576   rmp->ip4_lifetime_ms =
577     clib_net_to_host_u16 (mm->ip4_reass_conf_lifetime_ms);
578   rmp->ip4_pool_size = clib_net_to_host_u16 (mm->ip4_reass_conf_pool_size);
579   rmp->ip4_buffers = clib_net_to_host_u32 (mm->ip4_reass_conf_buffers);
580   rmp->ip4_ht_ratio =
581     clib_net_to_host_u64 ((u64) mm->ip4_reass_conf_ht_ratio);
582
583   rmp->ip6_lifetime_ms =
584     clib_net_to_host_u16 (mm->ip6_reass_conf_lifetime_ms);
585   rmp->ip6_pool_size = clib_net_to_host_u16 (mm->ip6_reass_conf_pool_size);
586   rmp->ip6_buffers = clib_net_to_host_u32 (mm->ip6_reass_conf_buffers);
587   rmp->ip6_ht_ratio =
588     clib_net_to_host_u64 ((u64) mm->ip6_reass_conf_ht_ratio);
589
590   rmp->sec_check_enable = mm->sec_check;
591   rmp->sec_check_fragments = mm->sec_check_frag;
592
593   rmp->tc_copy = mm->tc_copy;
594   rmp->tc_class = mm->tc;
595
596   vl_api_send_msg (reg, (u8 *) rmp);
597 }
598
599
600 int
601 map_if_enable_disable (bool is_enable, u32 sw_if_index, bool is_translation)
602 {
603   if (is_translation == false)
604     {
605       vnet_feature_enable_disable ("ip4-unicast", "ip4-map", sw_if_index,
606                                    is_enable ? 1 : 0, 0, 0);
607       vnet_feature_enable_disable ("ip6-unicast", "ip6-map", sw_if_index,
608                                    is_enable ? 1 : 0, 0, 0);
609     }
610   else
611     {
612       vnet_feature_enable_disable ("ip4-unicast", "ip4-map-t", sw_if_index,
613                                    is_enable ? 1 : 0, 0, 0);
614       vnet_feature_enable_disable ("ip6-unicast", "ip6-map-t", sw_if_index,
615                                    is_enable ? 1 : 0, 0, 0);
616     }
617   return 0;
618 }
619
620
621 static void
622 vl_api_map_if_enable_disable_t_handler (vl_api_map_if_enable_disable_t * mp)
623 {
624   map_main_t *mm = &map_main;
625   vl_api_map_if_enable_disable_reply_t *rmp;
626   int rv = 0;
627
628   VALIDATE_SW_IF_INDEX (mp);
629
630   rv =
631     map_if_enable_disable (mp->is_enable, htonl (mp->sw_if_index),
632                            mp->is_translation);
633
634   BAD_SW_IF_INDEX_LABEL;
635   REPLY_MACRO (VL_API_MAP_IF_ENABLE_DISABLE_REPLY);
636 }
637
638
639 #define foreach_map_plugin_api_msg              \
640 _(MAP_ADD_DOMAIN, map_add_domain)               \
641 _(MAP_DEL_DOMAIN, map_del_domain)               \
642 _(MAP_ADD_DEL_RULE, map_add_del_rule)           \
643 _(MAP_DOMAIN_DUMP, map_domain_dump)             \
644 _(MAP_RULE_DUMP, map_rule_dump)                 \
645 _(MAP_IF_ENABLE_DISABLE, map_if_enable_disable) \
646 _(MAP_SUMMARY_STATS, map_summary_stats)         \
647 _(MAP_PARAM_SET_FRAGMENTATION, map_param_set_fragmentation)     \
648 _(MAP_PARAM_SET_ICMP, map_param_set_icmp)       \
649 _(MAP_PARAM_SET_ICMP6, map_param_set_icmp6)     \
650 _(MAP_PARAM_ADD_DEL_PRE_RESOLVE, map_param_add_del_pre_resolve) \
651 _(MAP_PARAM_SET_REASSEMBLY, map_param_set_reassembly)           \
652 _(MAP_PARAM_SET_SECURITY_CHECK, map_param_set_security_check)   \
653 _(MAP_PARAM_SET_TRAFFIC_CLASS, map_param_set_traffic_class)     \
654 _(MAP_PARAM_SET_TCP, map_param_set_tcp) \
655 _(MAP_PARAM_GET, map_param_get)
656
657 #define vl_msg_name_crc_list
658 #include <map/map_all_api_h.h>
659 #undef vl_msg_name_crc_list
660
661 static void
662 setup_message_id_table (map_main_t * mm, api_main_t * am)
663 {
664 #define _(id,n,crc)                                                     \
665   vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + mm->msg_id_base);
666   foreach_vl_msg_name_crc_map;
667 #undef _
668 }
669
670 /* Set up the API message handling tables */
671 clib_error_t *
672 map_plugin_api_hookup (vlib_main_t * vm)
673 {
674   map_main_t *mm = &map_main;
675   u8 *name = format (0, "map_%08x%c", api_version, 0);
676
677   /* Ask for a correctly-sized block of API message decode slots */
678   mm->msg_id_base =
679     vl_msg_api_get_msg_ids ((char *) name, VL_MSG_FIRST_AVAILABLE);
680 #define _(N,n)                                                  \
681     vl_msg_api_set_handlers((VL_API_##N + mm->msg_id_base),     \
682                            #n,                                  \
683                            vl_api_##n##_t_handler,              \
684                            vl_noop_handler,                     \
685                            vl_api_##n##_t_endian,               \
686                            vl_api_##n##_t_print,                \
687                            sizeof(vl_api_##n##_t), 1);
688   foreach_map_plugin_api_msg;
689 #undef _
690
691   /*
692    * Set up the (msg_name, crc, message-id) table
693    */
694   setup_message_id_table (mm, &api_main);
695
696   vec_free (name);
697   return 0;
698 }
699
700 /*
701  * fd.io coding-style-patch-verification: ON
702  *
703  * Local Variables:
704  * eval: (c-set-style "gnu")
705  * End:
706  */