427140ffb927bd94efffbeb42d4ad5c71f2dac62
[vpp.git] / src / plugins / nat / nat44-ei / nat44_ei_api.c
1 /*
2  * Copyright (c) 2020 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <vnet/ip/ip_types_api.h>
18 #include <vlibmemory/api.h>
19
20 #include <vnet/fib/fib_table.h>
21
22 #include <nat/lib/nat_inlines.h>
23 #include <nat/lib/ipfix_logging.h>
24
25 #include <nat/nat44-ei/nat44_ei.api_enum.h>
26 #include <nat/nat44-ei/nat44_ei.api_types.h>
27
28 #include <nat/nat44-ei/nat44_ei_ha.h>
29 #include <nat/nat44-ei/nat44_ei.h>
30
31 #define REPLY_MSG_ID_BASE nm->msg_id_base
32 #include <vlibapi/api_helper_macros.h>
33
34 static void
35 vl_api_nat44_ei_show_running_config_t_handler (
36   vl_api_nat44_ei_show_running_config_t *mp)
37 {
38   vl_api_nat44_ei_show_running_config_reply_t *rmp;
39   nat44_ei_main_t *nm = &nat44_ei_main;
40   nat44_ei_config_t *rc = &nm->rconfig;
41   int rv = 0;
42
43   REPLY_MACRO2_ZERO (
44     VL_API_NAT44_EI_SHOW_RUNNING_CONFIG_REPLY, ({
45       rmp->inside_vrf = htonl (rc->inside_vrf);
46       rmp->outside_vrf = htonl (rc->outside_vrf);
47       rmp->users = htonl (rc->users);
48       rmp->sessions = htonl (rc->sessions);
49       rmp->user_sessions = htonl (rc->user_sessions);
50
51       rmp->user_buckets = htonl (nm->user_buckets);
52       rmp->translation_buckets = htonl (nm->translation_buckets);
53
54       rmp->timeouts.udp = htonl (nm->timeouts.udp);
55       rmp->timeouts.tcp_established = htonl (nm->timeouts.tcp.established);
56       rmp->timeouts.tcp_transitory = htonl (nm->timeouts.tcp.transitory);
57       rmp->timeouts.icmp = htonl (nm->timeouts.icmp);
58
59       rmp->forwarding_enabled = nm->forwarding_enabled == 1;
60       // consider how to split functionality between subplugins
61       rmp->ipfix_logging_enabled = nat_ipfix_logging_enabled ();
62
63       if (rc->static_mapping_only)
64         rmp->flags |= NAT44_EI_STATIC_MAPPING_ONLY;
65       if (rc->connection_tracking)
66         rmp->flags |= NAT44_EI_CONNECTION_TRACKING;
67       if (rc->out2in_dpo)
68         rmp->flags |= NAT44_EI_OUT2IN_DPO;
69     }));
70 }
71
72 static void
73 vl_api_nat44_ei_set_workers_t_handler (vl_api_nat44_ei_set_workers_t *mp)
74 {
75   nat44_ei_main_t *nm = &nat44_ei_main;
76   vl_api_nat44_ei_set_workers_reply_t *rmp;
77   int rv = 0;
78   uword *bitmap = 0;
79   u64 mask;
80
81   mask = clib_net_to_host_u64 (mp->worker_mask);
82
83   if (nm->num_workers < 2)
84     {
85       rv = VNET_API_ERROR_FEATURE_DISABLED;
86       goto send_reply;
87     }
88
89   bitmap = clib_bitmap_set_multiple (bitmap, 0, mask, BITS (mask));
90   rv = nat44_ei_set_workers (bitmap);
91   clib_bitmap_free (bitmap);
92
93 send_reply:
94   REPLY_MACRO (VL_API_NAT44_EI_SET_WORKERS_REPLY);
95 }
96
97 static void
98 send_nat_worker_details (u32 worker_index, vl_api_registration_t *reg,
99                          u32 context)
100 {
101   vl_api_nat44_ei_worker_details_t *rmp;
102   nat44_ei_main_t *nm = &nat44_ei_main;
103   vlib_worker_thread_t *w =
104     vlib_worker_threads + worker_index + nm->first_worker_index;
105
106   rmp = vl_msg_api_alloc (sizeof (*rmp));
107   clib_memset (rmp, 0, sizeof (*rmp));
108   rmp->_vl_msg_id = ntohs (VL_API_NAT44_EI_WORKER_DETAILS + nm->msg_id_base);
109   rmp->context = context;
110   rmp->worker_index = htonl (worker_index);
111   rmp->lcore_id = htonl (w->cpu_id);
112   strncpy ((char *) rmp->name, (char *) w->name, ARRAY_LEN (rmp->name) - 1);
113
114   vl_api_send_msg (reg, (u8 *) rmp);
115 }
116
117 static void
118 vl_api_nat44_ei_worker_dump_t_handler (vl_api_nat44_ei_worker_dump_t *mp)
119 {
120   vl_api_registration_t *reg;
121   nat44_ei_main_t *nm = &nat44_ei_main;
122   u32 *worker_index;
123
124   reg = vl_api_client_index_to_registration (mp->client_index);
125   if (!reg)
126     return;
127
128   vec_foreach (worker_index, nm->workers)
129     {
130       send_nat_worker_details (*worker_index, reg, mp->context);
131     }
132 }
133
134 static void
135 vl_api_nat44_ei_set_log_level_t_handler (vl_api_nat44_ei_set_log_level_t *mp)
136 {
137   nat44_ei_main_t *nm = &nat44_ei_main;
138   vl_api_nat44_ei_set_log_level_reply_t *rmp;
139   int rv = 0;
140
141   if (nm->log_level > NAT_LOG_DEBUG)
142     rv = VNET_API_ERROR_UNSUPPORTED;
143   else
144     nm->log_level = mp->log_level;
145
146   REPLY_MACRO (VL_API_NAT44_EI_SET_LOG_LEVEL_REPLY);
147 }
148
149 static void
150 vl_api_nat44_ei_plugin_enable_disable_t_handler (
151   vl_api_nat44_ei_plugin_enable_disable_t *mp)
152 {
153   nat44_ei_main_t *nm = &nat44_ei_main;
154   nat44_ei_config_t c = { 0 };
155   vl_api_nat44_ei_plugin_enable_disable_reply_t *rmp;
156   int rv = 0;
157
158   if (mp->enable)
159     {
160       c.static_mapping_only = mp->flags & NAT44_EI_STATIC_MAPPING_ONLY;
161       c.connection_tracking = mp->flags & NAT44_EI_CONNECTION_TRACKING;
162       c.out2in_dpo = mp->flags & NAT44_EI_OUT2IN_DPO;
163
164       c.inside_vrf = ntohl (mp->inside_vrf);
165       c.outside_vrf = ntohl (mp->outside_vrf);
166
167       c.users = ntohl (mp->users);
168
169       c.sessions = ntohl (mp->sessions);
170
171       c.user_sessions = ntohl (mp->user_sessions);
172
173       rv = nat44_ei_plugin_enable (c);
174     }
175   else
176     rv = nat44_ei_plugin_disable ();
177
178   REPLY_MACRO (VL_API_NAT44_EI_PLUGIN_ENABLE_DISABLE_REPLY);
179 }
180
181 static void
182 vl_api_nat44_ei_ipfix_enable_disable_t_handler (
183   vl_api_nat44_ei_ipfix_enable_disable_t *mp)
184 {
185   nat44_ei_main_t *nm = &nat44_ei_main;
186   vl_api_nat44_ei_ipfix_enable_disable_reply_t *rmp;
187   int rv = 0;
188
189   rv = nat_ipfix_logging_enable_disable (mp->enable,
190                                          clib_host_to_net_u32 (mp->domain_id),
191                                          clib_host_to_net_u16 (mp->src_port));
192
193   REPLY_MACRO (VL_API_NAT44_EI_IPFIX_ENABLE_DISABLE_REPLY);
194 }
195
196 static void
197 vl_api_nat44_ei_set_timeouts_t_handler (vl_api_nat44_ei_set_timeouts_t *mp)
198 {
199   nat44_ei_main_t *nm = &nat44_ei_main;
200   vl_api_nat44_ei_set_timeouts_reply_t *rmp;
201   int rv = 0;
202
203   nm->timeouts.udp = ntohl (mp->udp);
204   nm->timeouts.tcp.established = ntohl (mp->tcp_established);
205   nm->timeouts.tcp.transitory = ntohl (mp->tcp_transitory);
206   nm->timeouts.icmp = ntohl (mp->icmp);
207
208   REPLY_MACRO (VL_API_NAT44_EI_SET_TIMEOUTS_REPLY);
209 }
210
211 static void
212 vl_api_nat44_ei_set_addr_and_port_alloc_alg_t_handler (
213   vl_api_nat44_ei_set_addr_and_port_alloc_alg_t *mp)
214 {
215   nat44_ei_main_t *nm = &nat44_ei_main;
216   vl_api_nat44_ei_set_addr_and_port_alloc_alg_reply_t *rmp;
217   int rv = 0;
218   u16 port_start, port_end;
219
220   switch (mp->alg)
221     {
222     case NAT44_EI_ADDR_AND_PORT_ALLOC_ALG_DEFAULT:
223       nat44_ei_set_alloc_default ();
224       break;
225     case NAT44_EI_ADDR_AND_PORT_ALLOC_ALG_MAPE:
226       nat44_ei_set_alloc_mape (ntohs (mp->psid), mp->psid_offset,
227                                mp->psid_length);
228       break;
229     case NAT44_EI_ADDR_AND_PORT_ALLOC_ALG_RANGE:
230       port_start = ntohs (mp->start_port);
231       port_end = ntohs (mp->end_port);
232       if (port_end <= port_start)
233         {
234           rv = VNET_API_ERROR_INVALID_VALUE;
235           goto send_reply;
236         }
237       nat44_ei_set_alloc_range (port_start, port_end);
238       break;
239     default:
240       rv = VNET_API_ERROR_INVALID_VALUE;
241       break;
242     }
243
244 send_reply:
245   REPLY_MACRO (VL_API_NAT44_EI_SET_ADDR_AND_PORT_ALLOC_ALG_REPLY);
246 }
247
248 static void
249 vl_api_nat44_ei_get_addr_and_port_alloc_alg_t_handler (
250   vl_api_nat44_ei_get_addr_and_port_alloc_alg_t *mp)
251 {
252   nat44_ei_main_t *nm = &nat44_ei_main;
253   vl_api_nat44_ei_get_addr_and_port_alloc_alg_reply_t *rmp;
254   int rv = 0;
255
256   REPLY_MACRO2 (VL_API_NAT44_EI_GET_ADDR_AND_PORT_ALLOC_ALG_REPLY, ({
257                   rmp->alg = nm->addr_and_port_alloc_alg;
258                   rmp->psid_offset = nm->psid_offset;
259                   rmp->psid_length = nm->psid_length;
260                   rmp->psid = htons (nm->psid);
261                   rmp->start_port = htons (nm->start_port);
262                   rmp->end_port = htons (nm->end_port);
263                 }))
264 }
265
266 static void
267 vl_api_nat44_ei_set_mss_clamping_t_handler (
268   vl_api_nat44_ei_set_mss_clamping_t *mp)
269 {
270   nat44_ei_main_t *nm = &nat44_ei_main;
271   vl_api_nat44_ei_set_mss_clamping_reply_t *rmp;
272   int rv = 0;
273
274   if (mp->enable)
275     nm->mss_clamping = ntohs (mp->mss_value);
276   else
277     nm->mss_clamping = 0;
278
279   REPLY_MACRO (VL_API_NAT44_EI_SET_MSS_CLAMPING_REPLY);
280 }
281
282 static void
283 vl_api_nat44_ei_get_mss_clamping_t_handler (
284   vl_api_nat44_ei_get_mss_clamping_t *mp)
285 {
286   nat44_ei_main_t *nm = &nat44_ei_main;
287   vl_api_nat44_ei_get_mss_clamping_reply_t *rmp;
288   int rv = 0;
289
290   REPLY_MACRO2 (VL_API_NAT44_EI_GET_MSS_CLAMPING_REPLY, ({
291                   rmp->enable = nm->mss_clamping ? 1 : 0;
292                   rmp->mss_value = htons (nm->mss_clamping);
293                 }))
294 }
295
296 static void
297 vl_api_nat44_ei_ha_set_listener_t_handler (
298   vl_api_nat44_ei_ha_set_listener_t *mp)
299 {
300   nat44_ei_main_t *nm = &nat44_ei_main;
301   vl_api_nat44_ei_ha_set_listener_reply_t *rmp;
302   ip4_address_t addr;
303   int rv;
304
305   memcpy (&addr, &mp->ip_address, sizeof (addr));
306   rv = nat_ha_set_listener (vlib_get_main (), &addr,
307                             clib_net_to_host_u16 (mp->port),
308                             clib_net_to_host_u32 (mp->path_mtu));
309
310   REPLY_MACRO (VL_API_NAT44_EI_HA_SET_LISTENER_REPLY);
311 }
312
313 static void
314 vl_api_nat44_ei_ha_get_listener_t_handler (
315   vl_api_nat44_ei_ha_get_listener_t *mp)
316 {
317   nat44_ei_main_t *nm = &nat44_ei_main;
318   vl_api_nat44_ei_ha_get_listener_reply_t *rmp;
319   int rv = 0;
320   ip4_address_t addr;
321   u16 port;
322   u32 path_mtu;
323
324   nat_ha_get_listener (&addr, &port, &path_mtu);
325
326   REPLY_MACRO2 (VL_API_NAT44_EI_HA_GET_LISTENER_REPLY, ({
327                   clib_memcpy (rmp->ip_address, &addr, sizeof (ip4_address_t));
328                   rmp->port = clib_host_to_net_u16 (port);
329                   rmp->path_mtu = clib_host_to_net_u32 (path_mtu);
330                 }))
331 }
332
333 static void
334 vl_api_nat44_ei_ha_set_failover_t_handler (
335   vl_api_nat44_ei_ha_set_failover_t *mp)
336 {
337   nat44_ei_main_t *nm = &nat44_ei_main;
338   vl_api_nat44_ei_ha_set_failover_reply_t *rmp;
339   ip4_address_t addr;
340   int rv;
341
342   memcpy (&addr, &mp->ip_address, sizeof (addr));
343   rv = nat_ha_set_failover (
344     vlib_get_main (), &addr, clib_net_to_host_u16 (mp->port),
345     clib_net_to_host_u32 (mp->session_refresh_interval));
346
347   REPLY_MACRO (VL_API_NAT44_EI_HA_SET_FAILOVER_REPLY);
348 }
349
350 static void
351 vl_api_nat44_ei_ha_get_failover_t_handler (
352   vl_api_nat44_ei_ha_get_failover_t *mp)
353 {
354   nat44_ei_main_t *nm = &nat44_ei_main;
355   vl_api_nat44_ei_ha_get_failover_reply_t *rmp;
356   int rv = 0;
357   ip4_address_t addr;
358   u16 port;
359   u32 session_refresh_interval;
360
361   nat_ha_get_failover (&addr, &port, &session_refresh_interval);
362
363   REPLY_MACRO2 (VL_API_NAT44_EI_HA_GET_FAILOVER_REPLY, ({
364                   clib_memcpy (rmp->ip_address, &addr, sizeof (ip4_address_t));
365                   rmp->port = clib_host_to_net_u16 (port);
366                   rmp->session_refresh_interval =
367                     clib_host_to_net_u32 (session_refresh_interval);
368                 }))
369 }
370
371 static void
372 vl_api_nat44_ei_ha_flush_t_handler (vl_api_nat44_ei_ha_flush_t *mp)
373 {
374   nat44_ei_main_t *nm = &nat44_ei_main;
375   vl_api_nat44_ei_ha_flush_reply_t *rmp;
376   int rv = 0;
377
378   nat_ha_flush (0);
379
380   REPLY_MACRO (VL_API_NAT44_EI_HA_FLUSH_REPLY);
381 }
382
383 static void
384 nat_ha_resync_completed_event_cb (u32 client_index, u32 pid, u32 missed_count)
385 {
386   nat44_ei_main_t *nm = &nat44_ei_main;
387   vl_api_registration_t *reg;
388   vl_api_nat44_ei_ha_resync_completed_event_t *mp;
389
390   reg = vl_api_client_index_to_registration (client_index);
391   if (!reg)
392     return;
393
394   mp = vl_msg_api_alloc (sizeof (*mp));
395   clib_memset (mp, 0, sizeof (*mp));
396   mp->client_index = client_index;
397   mp->pid = pid;
398   mp->missed_count = clib_host_to_net_u32 (missed_count);
399   mp->_vl_msg_id =
400     ntohs (VL_API_NAT44_EI_HA_RESYNC_COMPLETED_EVENT + nm->msg_id_base);
401
402   vl_api_send_msg (reg, (u8 *) mp);
403 }
404
405 static void
406 vl_api_nat44_ei_ha_resync_t_handler (vl_api_nat44_ei_ha_resync_t *mp)
407 {
408   nat44_ei_main_t *nm = &nat44_ei_main;
409   vl_api_nat44_ei_ha_resync_reply_t *rmp;
410   int rv;
411
412   rv = nat_ha_resync (
413     mp->client_index, mp->pid,
414     mp->want_resync_event ? nat_ha_resync_completed_event_cb : NULL);
415
416   REPLY_MACRO (VL_API_NAT44_EI_HA_RESYNC_REPLY);
417 }
418
419 static void
420 vl_api_nat44_ei_del_user_t_handler (vl_api_nat44_ei_del_user_t *mp)
421 {
422   nat44_ei_main_t *nm = &nat44_ei_main;
423   vl_api_nat44_ei_del_user_reply_t *rmp;
424   ip4_address_t addr;
425   int rv;
426   memcpy (&addr.as_u8, mp->ip_address, 4);
427   rv = nat44_ei_user_del (&addr, ntohl (mp->fib_index));
428   REPLY_MACRO (VL_API_NAT44_EI_DEL_USER_REPLY);
429 }
430
431 static void
432 vl_api_nat44_ei_add_del_address_range_t_handler (
433   vl_api_nat44_ei_add_del_address_range_t *mp)
434 {
435   nat44_ei_main_t *nm = &nat44_ei_main;
436   vl_api_nat44_ei_add_del_address_range_reply_t *rmp;
437   ip4_address_t this_addr;
438   u8 is_add;
439   u32 start_host_order, end_host_order;
440   u32 vrf_id;
441   int i, count;
442   int rv = 0;
443   u32 *tmp;
444
445   if (nm->static_mapping_only)
446     {
447       rv = VNET_API_ERROR_FEATURE_DISABLED;
448       goto send_reply;
449     }
450
451   is_add = mp->is_add;
452
453   tmp = (u32 *) mp->first_ip_address;
454   start_host_order = clib_host_to_net_u32 (tmp[0]);
455   tmp = (u32 *) mp->last_ip_address;
456   end_host_order = clib_host_to_net_u32 (tmp[0]);
457
458   count = (end_host_order - start_host_order) + 1;
459
460   vrf_id = clib_host_to_net_u32 (mp->vrf_id);
461
462   if (count > 1024)
463     nat44_ei_log_info ("%U - %U, %d addresses...", format_ip4_address,
464                        mp->first_ip_address, format_ip4_address,
465                        mp->last_ip_address, count);
466
467   memcpy (&this_addr.as_u8, mp->first_ip_address, 4);
468
469   for (i = 0; i < count; i++)
470     {
471       if (is_add)
472         rv = nat44_ei_add_address (nm, &this_addr, vrf_id);
473       else
474         rv = nat44_ei_del_address (nm, this_addr, 0);
475
476       if (rv)
477         goto send_reply;
478
479       if (nm->out2in_dpo)
480         nat44_ei_add_del_address_dpo (this_addr, is_add);
481
482       increment_v4_address (&this_addr);
483     }
484
485 send_reply:
486   REPLY_MACRO (VL_API_NAT44_EI_ADD_DEL_ADDRESS_RANGE_REPLY);
487 }
488
489 static void
490 send_nat44_ei_address_details (nat44_ei_address_t *a,
491                                vl_api_registration_t *reg, u32 context)
492 {
493   vl_api_nat44_ei_address_details_t *rmp;
494   nat44_ei_main_t *nm = &nat44_ei_main;
495
496   rmp = vl_msg_api_alloc (sizeof (*rmp));
497   clib_memset (rmp, 0, sizeof (*rmp));
498   rmp->_vl_msg_id = ntohs (VL_API_NAT44_EI_ADDRESS_DETAILS + nm->msg_id_base);
499   clib_memcpy (rmp->ip_address, &(a->addr), 4);
500   if (a->fib_index != ~0)
501     {
502       fib_table_t *fib = fib_table_get (a->fib_index, FIB_PROTOCOL_IP4);
503       rmp->vrf_id = ntohl (fib->ft_table_id);
504     }
505   else
506     rmp->vrf_id = ~0;
507   rmp->context = context;
508
509   vl_api_send_msg (reg, (u8 *) rmp);
510 }
511
512 static void
513 vl_api_nat44_ei_address_dump_t_handler (vl_api_nat44_ei_address_dump_t *mp)
514 {
515   vl_api_registration_t *reg;
516   nat44_ei_main_t *nm = &nat44_ei_main;
517   nat44_ei_address_t *a;
518
519   reg = vl_api_client_index_to_registration (mp->client_index);
520   if (!reg)
521     return;
522
523   vec_foreach (a, nm->addresses)
524     {
525       send_nat44_ei_address_details (a, reg, mp->context);
526     }
527 }
528
529 static void
530 vl_api_nat44_ei_interface_add_del_feature_t_handler (
531   vl_api_nat44_ei_interface_add_del_feature_t *mp)
532 {
533   nat44_ei_main_t *nm = &nat44_ei_main;
534   vl_api_nat44_ei_interface_add_del_feature_reply_t *rmp;
535   u32 sw_if_index = ntohl (mp->sw_if_index);
536   u8 is_del;
537   int rv = 0;
538
539   is_del = !mp->is_add;
540
541   VALIDATE_SW_IF_INDEX (mp);
542
543   rv = nat44_ei_interface_add_del (sw_if_index, mp->flags & NAT44_EI_IF_INSIDE,
544                                    is_del);
545
546   BAD_SW_IF_INDEX_LABEL;
547
548   REPLY_MACRO (VL_API_NAT44_EI_INTERFACE_ADD_DEL_FEATURE_REPLY);
549 }
550
551 static void
552 send_nat44_ei_interface_details (nat44_ei_interface_t *i,
553                                  vl_api_registration_t *reg, u32 context)
554 {
555   vl_api_nat44_ei_interface_details_t *rmp;
556   nat44_ei_main_t *nm = &nat44_ei_main;
557
558   rmp = vl_msg_api_alloc (sizeof (*rmp));
559   clib_memset (rmp, 0, sizeof (*rmp));
560   rmp->_vl_msg_id =
561     ntohs (VL_API_NAT44_EI_INTERFACE_DETAILS + nm->msg_id_base);
562   rmp->sw_if_index = ntohl (i->sw_if_index);
563
564   if (nat44_ei_interface_is_inside (i))
565     rmp->flags |= NAT44_EI_IF_INSIDE;
566   if (nat44_ei_interface_is_outside (i))
567     rmp->flags |= NAT44_EI_IF_OUTSIDE;
568
569   rmp->context = context;
570
571   vl_api_send_msg (reg, (u8 *) rmp);
572 }
573
574 static void
575 vl_api_nat44_ei_interface_dump_t_handler (vl_api_nat44_ei_interface_dump_t *mp)
576 {
577   vl_api_registration_t *reg;
578   nat44_ei_main_t *nm = &nat44_ei_main;
579   nat44_ei_interface_t *i;
580
581   reg = vl_api_client_index_to_registration (mp->client_index);
582   if (!reg)
583     return;
584
585   pool_foreach (i, nm->interfaces)
586     {
587       send_nat44_ei_interface_details (i, reg, mp->context);
588     }
589 }
590
591 static void
592 vl_api_nat44_ei_interface_add_del_output_feature_t_handler (
593   vl_api_nat44_ei_interface_add_del_output_feature_t *mp)
594 {
595   nat44_ei_main_t *nm = &nat44_ei_main;
596   vl_api_nat44_ei_interface_add_del_output_feature_reply_t *rmp;
597   u32 sw_if_index = ntohl (mp->sw_if_index);
598   int rv = 0;
599
600   VALIDATE_SW_IF_INDEX (mp);
601
602   rv = nat44_ei_interface_add_del_output_feature (
603     sw_if_index, mp->flags & NAT44_EI_IF_INSIDE, !mp->is_add);
604
605   BAD_SW_IF_INDEX_LABEL;
606   REPLY_MACRO (VL_API_NAT44_EI_INTERFACE_ADD_DEL_OUTPUT_FEATURE_REPLY);
607 }
608
609 static void
610 send_nat44_ei_interface_output_feature_details (nat44_ei_interface_t *i,
611                                                 vl_api_registration_t *reg,
612                                                 u32 context)
613 {
614   vl_api_nat44_ei_interface_output_feature_details_t *rmp;
615   nat44_ei_main_t *nm = &nat44_ei_main;
616
617   rmp = vl_msg_api_alloc (sizeof (*rmp));
618   clib_memset (rmp, 0, sizeof (*rmp));
619   rmp->_vl_msg_id =
620     ntohs (VL_API_NAT44_EI_INTERFACE_OUTPUT_FEATURE_DETAILS + nm->msg_id_base);
621   rmp->sw_if_index = ntohl (i->sw_if_index);
622   rmp->context = context;
623
624   if (nat44_ei_interface_is_inside (i))
625     rmp->flags |= NAT44_EI_IF_INSIDE;
626
627   vl_api_send_msg (reg, (u8 *) rmp);
628 }
629
630 static void
631 vl_api_nat44_ei_interface_output_feature_dump_t_handler (
632   vl_api_nat44_ei_interface_output_feature_dump_t *mp)
633 {
634   vl_api_registration_t *reg;
635   nat44_ei_main_t *nm = &nat44_ei_main;
636   nat44_ei_interface_t *i;
637
638   reg = vl_api_client_index_to_registration (mp->client_index);
639   if (!reg)
640     return;
641
642   pool_foreach (i, nm->output_feature_interfaces)
643     {
644       send_nat44_ei_interface_output_feature_details (i, reg, mp->context);
645     }
646 }
647
648 static void
649 vl_api_nat44_ei_add_del_static_mapping_t_handler (
650   vl_api_nat44_ei_add_del_static_mapping_t *mp)
651 {
652   nat44_ei_main_t *nm = &nat44_ei_main;
653   vl_api_nat44_ei_add_del_static_mapping_reply_t *rmp;
654   ip4_address_t local_addr, external_addr;
655   u16 local_port = 0, external_port = 0;
656   u32 vrf_id, external_sw_if_index;
657   int rv = 0;
658   nat_protocol_t proto;
659   u8 *tag = 0;
660
661   memcpy (&local_addr.as_u8, mp->local_ip_address, 4);
662   memcpy (&external_addr.as_u8, mp->external_ip_address, 4);
663
664   if (!(mp->flags & NAT44_EI_ADDR_ONLY_MAPPING))
665     {
666       local_port = mp->local_port;
667       external_port = mp->external_port;
668     }
669
670   vrf_id = clib_net_to_host_u32 (mp->vrf_id);
671   external_sw_if_index = clib_net_to_host_u32 (mp->external_sw_if_index);
672   proto = ip_proto_to_nat_proto (mp->protocol);
673
674   mp->tag[sizeof (mp->tag) - 1] = 0;
675   tag = format (0, "%s", mp->tag);
676   vec_terminate_c_string (tag);
677
678   rv = nat44_ei_add_del_static_mapping (
679     local_addr, external_addr, local_port, external_port, proto,
680     external_sw_if_index, vrf_id, mp->flags & NAT44_EI_ADDR_ONLY_MAPPING, 0,
681     tag, mp->is_add);
682
683   vec_free (tag);
684
685   REPLY_MACRO (VL_API_NAT44_EI_ADD_DEL_STATIC_MAPPING_REPLY);
686 }
687
688 static void
689 send_nat44_ei_static_mapping_details (nat44_ei_static_mapping_t *m,
690                                       vl_api_registration_t *reg, u32 context)
691 {
692   vl_api_nat44_ei_static_mapping_details_t *rmp;
693   nat44_ei_main_t *nm = &nat44_ei_main;
694   u32 len = sizeof (*rmp);
695
696   rmp = vl_msg_api_alloc (len);
697   clib_memset (rmp, 0, len);
698   rmp->_vl_msg_id =
699     ntohs (VL_API_NAT44_EI_STATIC_MAPPING_DETAILS + nm->msg_id_base);
700
701   clib_memcpy (rmp->local_ip_address, &(m->local_addr), 4);
702   clib_memcpy (rmp->external_ip_address, &(m->external_addr), 4);
703   rmp->external_sw_if_index = ~0;
704   rmp->vrf_id = htonl (m->vrf_id);
705   rmp->context = context;
706
707   if (nat44_ei_is_addr_only_static_mapping (m))
708     {
709       rmp->flags |= NAT44_EI_ADDR_ONLY_MAPPING;
710     }
711   else
712     {
713       rmp->protocol = nat_proto_to_ip_proto (m->proto);
714       rmp->external_port = m->external_port;
715       rmp->local_port = m->local_port;
716     }
717
718   if (m->tag)
719     strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
720
721   vl_api_send_msg (reg, (u8 *) rmp);
722 }
723
724 static void
725 send_nat44_ei_static_map_resolve_details (nat44_ei_static_map_resolve_t *m,
726                                           vl_api_registration_t *reg,
727                                           u32 context)
728 {
729   vl_api_nat44_ei_static_mapping_details_t *rmp;
730   nat44_ei_main_t *nm = &nat44_ei_main;
731
732   rmp = vl_msg_api_alloc (sizeof (*rmp));
733   clib_memset (rmp, 0, sizeof (*rmp));
734   rmp->_vl_msg_id =
735     ntohs (VL_API_NAT44_EI_STATIC_MAPPING_DETAILS + nm->msg_id_base);
736   clib_memcpy (rmp->local_ip_address, &(m->l_addr), 4);
737   rmp->external_sw_if_index = htonl (m->sw_if_index);
738   rmp->vrf_id = htonl (m->vrf_id);
739   rmp->context = context;
740
741   if (m->addr_only)
742     {
743       rmp->flags |= NAT44_EI_ADDR_ONLY_MAPPING;
744     }
745   else
746     {
747       rmp->protocol = nat_proto_to_ip_proto (m->proto);
748       rmp->external_port = m->e_port;
749       rmp->local_port = m->l_port;
750     }
751   if (m->tag)
752     strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
753
754   vl_api_send_msg (reg, (u8 *) rmp);
755 }
756
757 static void
758 vl_api_nat44_ei_static_mapping_dump_t_handler (
759   vl_api_nat44_ei_static_mapping_dump_t *mp)
760 {
761   vl_api_registration_t *reg;
762   nat44_ei_main_t *nm = &nat44_ei_main;
763   nat44_ei_static_mapping_t *m;
764   nat44_ei_static_map_resolve_t *rp;
765   int j;
766
767   reg = vl_api_client_index_to_registration (mp->client_index);
768   if (!reg)
769     return;
770
771   pool_foreach (m, nm->static_mappings)
772     {
773       if (!nat44_ei_is_identity_static_mapping (m))
774         send_nat44_ei_static_mapping_details (m, reg, mp->context);
775     }
776
777   for (j = 0; j < vec_len (nm->to_resolve); j++)
778     {
779       rp = nm->to_resolve + j;
780       if (!rp->identity_nat)
781         send_nat44_ei_static_map_resolve_details (rp, reg, mp->context);
782     }
783 }
784
785 static void
786 vl_api_nat44_ei_add_del_identity_mapping_t_handler (
787   vl_api_nat44_ei_add_del_identity_mapping_t *mp)
788 {
789   nat44_ei_main_t *nm = &nat44_ei_main;
790   vl_api_nat44_ei_add_del_identity_mapping_reply_t *rmp;
791   ip4_address_t addr;
792   u16 port = 0;
793   u32 vrf_id, sw_if_index;
794   int rv = 0;
795   nat_protocol_t proto = NAT_PROTOCOL_OTHER;
796   u8 *tag = 0;
797
798   if (!(mp->flags & NAT44_EI_ADDR_ONLY_MAPPING))
799     {
800       port = mp->port;
801       proto = ip_proto_to_nat_proto (mp->protocol);
802     }
803   vrf_id = clib_net_to_host_u32 (mp->vrf_id);
804   sw_if_index = clib_net_to_host_u32 (mp->sw_if_index);
805   if (sw_if_index != ~0)
806     addr.as_u32 = 0;
807   else
808     memcpy (&addr.as_u8, mp->ip_address, 4);
809   mp->tag[sizeof (mp->tag) - 1] = 0;
810   tag = format (0, "%s", mp->tag);
811   vec_terminate_c_string (tag);
812
813   rv = nat44_ei_add_del_static_mapping (
814     addr, addr, port, port, proto, sw_if_index, vrf_id,
815     mp->flags & NAT44_EI_ADDR_ONLY_MAPPING, 1, tag, mp->is_add);
816
817   vec_free (tag);
818
819   REPLY_MACRO (VL_API_NAT44_EI_ADD_DEL_IDENTITY_MAPPING_REPLY);
820 }
821
822 static void
823 send_nat44_ei_identity_mapping_details (nat44_ei_static_mapping_t *m,
824                                         int index, vl_api_registration_t *reg,
825                                         u32 context)
826 {
827   vl_api_nat44_ei_identity_mapping_details_t *rmp;
828   nat44_ei_main_t *nm = &nat44_ei_main;
829   nat44_ei_lb_addr_port_t *local = pool_elt_at_index (m->locals, index);
830
831   rmp = vl_msg_api_alloc (sizeof (*rmp));
832   clib_memset (rmp, 0, sizeof (*rmp));
833   rmp->_vl_msg_id =
834     ntohs (VL_API_NAT44_EI_IDENTITY_MAPPING_DETAILS + nm->msg_id_base);
835
836   if (nat44_ei_is_addr_only_static_mapping (m))
837     rmp->flags |= NAT44_EI_ADDR_ONLY_MAPPING;
838
839   clib_memcpy (rmp->ip_address, &(m->local_addr), 4);
840   rmp->port = m->local_port;
841   rmp->sw_if_index = ~0;
842   rmp->vrf_id = htonl (local->vrf_id);
843   rmp->protocol = nat_proto_to_ip_proto (m->proto);
844   rmp->context = context;
845   if (m->tag)
846     strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
847
848   vl_api_send_msg (reg, (u8 *) rmp);
849 }
850
851 static void
852 send_nat44_ei_identity_map_resolve_details (nat44_ei_static_map_resolve_t *m,
853                                             vl_api_registration_t *reg,
854                                             u32 context)
855 {
856   vl_api_nat44_ei_identity_mapping_details_t *rmp;
857   nat44_ei_main_t *nm = &nat44_ei_main;
858   rmp = vl_msg_api_alloc (sizeof (*rmp));
859   clib_memset (rmp, 0, sizeof (*rmp));
860   rmp->_vl_msg_id =
861     ntohs (VL_API_NAT44_EI_IDENTITY_MAPPING_DETAILS + nm->msg_id_base);
862
863   if (m->addr_only)
864     rmp->flags = (vl_api_nat44_ei_config_flags_t) NAT44_EI_ADDR_ONLY_MAPPING;
865
866   rmp->port = m->l_port;
867   rmp->sw_if_index = htonl (m->sw_if_index);
868   rmp->vrf_id = htonl (m->vrf_id);
869   rmp->protocol = nat_proto_to_ip_proto (m->proto);
870   rmp->context = context;
871   if (m->tag)
872     strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
873
874   vl_api_send_msg (reg, (u8 *) rmp);
875 }
876
877 static void
878 vl_api_nat44_ei_identity_mapping_dump_t_handler (
879   vl_api_nat44_ei_identity_mapping_dump_t *mp)
880 {
881   vl_api_registration_t *reg;
882   nat44_ei_main_t *nm = &nat44_ei_main;
883   nat44_ei_static_mapping_t *m;
884   nat44_ei_static_map_resolve_t *rp;
885   int j;
886
887   reg = vl_api_client_index_to_registration (mp->client_index);
888   if (!reg)
889     return;
890
891   pool_foreach (m, nm->static_mappings)
892     {
893       if (nat44_ei_is_identity_static_mapping (m))
894         {
895           pool_foreach_index (j, m->locals)
896             {
897               send_nat44_ei_identity_mapping_details (m, j, reg, mp->context);
898             }
899         }
900     }
901
902   for (j = 0; j < vec_len (nm->to_resolve); j++)
903     {
904       rp = nm->to_resolve + j;
905       if (rp->identity_nat)
906         send_nat44_ei_identity_map_resolve_details (rp, reg, mp->context);
907     }
908 }
909
910 static void
911 vl_api_nat44_ei_add_del_interface_addr_t_handler (
912   vl_api_nat44_ei_add_del_interface_addr_t *mp)
913 {
914   nat44_ei_main_t *nm = &nat44_ei_main;
915   vl_api_nat44_ei_add_del_interface_addr_reply_t *rmp;
916   u32 sw_if_index = ntohl (mp->sw_if_index);
917   int rv = 0;
918   u8 is_del;
919
920   is_del = !mp->is_add;
921
922   VALIDATE_SW_IF_INDEX (mp);
923
924   rv = nat44_ei_add_interface_address (nm, sw_if_index, is_del);
925
926   BAD_SW_IF_INDEX_LABEL;
927   REPLY_MACRO (VL_API_NAT44_EI_ADD_DEL_INTERFACE_ADDR_REPLY);
928 }
929
930 static void
931 send_nat44_ei_interface_addr_details (u32 sw_if_index,
932                                       vl_api_registration_t *reg, u32 context)
933 {
934   vl_api_nat44_ei_interface_addr_details_t *rmp;
935   nat44_ei_main_t *nm = &nat44_ei_main;
936
937   rmp = vl_msg_api_alloc (sizeof (*rmp));
938   clib_memset (rmp, 0, sizeof (*rmp));
939   rmp->_vl_msg_id =
940     ntohs (VL_API_NAT44_EI_INTERFACE_ADDR_DETAILS + nm->msg_id_base);
941   rmp->sw_if_index = ntohl (sw_if_index);
942   rmp->context = context;
943
944   vl_api_send_msg (reg, (u8 *) rmp);
945 }
946
947 static void
948 vl_api_nat44_ei_interface_addr_dump_t_handler (
949   vl_api_nat44_ei_interface_addr_dump_t *mp)
950 {
951   vl_api_registration_t *reg;
952   nat44_ei_main_t *nm = &nat44_ei_main;
953   u32 *i;
954
955   reg = vl_api_client_index_to_registration (mp->client_index);
956   if (!reg)
957     return;
958
959   vec_foreach (i, nm->auto_add_sw_if_indices)
960     send_nat44_ei_interface_addr_details (*i, reg, mp->context);
961 }
962
963 static void
964 send_nat44_ei_user_details (nat44_ei_user_t *u, vl_api_registration_t *reg,
965                             u32 context)
966 {
967   vl_api_nat44_ei_user_details_t *rmp;
968   nat44_ei_main_t *nm = &nat44_ei_main;
969   ip4_main_t *im = &ip4_main;
970
971   rmp = vl_msg_api_alloc (sizeof (*rmp));
972   clib_memset (rmp, 0, sizeof (*rmp));
973   rmp->_vl_msg_id = ntohs (VL_API_NAT44_EI_USER_DETAILS + nm->msg_id_base);
974
975   if (!pool_is_free_index (im->fibs, u->fib_index))
976     {
977       fib_table_t *fib = fib_table_get (u->fib_index, FIB_PROTOCOL_IP4);
978       rmp->vrf_id = ntohl (fib->ft_table_id);
979     }
980
981   clib_memcpy (rmp->ip_address, &(u->addr), 4);
982   rmp->nsessions = ntohl (u->nsessions);
983   rmp->nstaticsessions = ntohl (u->nstaticsessions);
984   rmp->context = context;
985
986   vl_api_send_msg (reg, (u8 *) rmp);
987 }
988
989 static void
990 vl_api_nat44_ei_user_dump_t_handler (vl_api_nat44_ei_user_dump_t *mp)
991 {
992   vl_api_registration_t *reg;
993   nat44_ei_main_t *nm = &nat44_ei_main;
994   nat44_ei_main_per_thread_data_t *tnm;
995   nat44_ei_user_t *u;
996
997   reg = vl_api_client_index_to_registration (mp->client_index);
998   if (!reg)
999     return;
1000
1001   vec_foreach (tnm, nm->per_thread_data)
1002     {
1003       pool_foreach (u, tnm->users)
1004         {
1005           send_nat44_ei_user_details (u, reg, mp->context);
1006         }
1007     }
1008 }
1009
1010 static void
1011 send_nat44_ei_user_session_details (nat44_ei_session_t *s,
1012                                     vl_api_registration_t *reg, u32 context)
1013 {
1014   vl_api_nat44_ei_user_session_details_t *rmp;
1015   nat44_ei_main_t *nm = &nat44_ei_main;
1016
1017   rmp = vl_msg_api_alloc (sizeof (*rmp));
1018   clib_memset (rmp, 0, sizeof (*rmp));
1019   rmp->_vl_msg_id =
1020     ntohs (VL_API_NAT44_EI_USER_SESSION_DETAILS + nm->msg_id_base);
1021   clib_memcpy (rmp->outside_ip_address, (&s->out2in.addr), 4);
1022   clib_memcpy (rmp->inside_ip_address, (&s->in2out.addr), 4);
1023
1024   if (nat44_ei_is_session_static (s))
1025     rmp->flags |= NAT44_EI_STATIC_MAPPING;
1026
1027   rmp->last_heard = clib_host_to_net_u64 ((u64) s->last_heard);
1028   rmp->total_bytes = clib_host_to_net_u64 (s->total_bytes);
1029   rmp->total_pkts = ntohl (s->total_pkts);
1030   rmp->context = context;
1031   if (nat44_ei_is_unk_proto_session (s))
1032     {
1033       rmp->outside_port = 0;
1034       rmp->inside_port = 0;
1035       rmp->protocol = ntohs (s->in2out.port);
1036     }
1037   else
1038     {
1039       rmp->outside_port = s->out2in.port;
1040       rmp->inside_port = s->in2out.port;
1041       rmp->protocol = ntohs (nat_proto_to_ip_proto (s->nat_proto));
1042     }
1043   vl_api_send_msg (reg, (u8 *) rmp);
1044 }
1045
1046 static void
1047 vl_api_nat44_ei_user_session_dump_t_handler (
1048   vl_api_nat44_ei_user_session_dump_t *mp)
1049 {
1050   vl_api_registration_t *reg;
1051   nat44_ei_main_t *nm = &nat44_ei_main;
1052   nat44_ei_main_per_thread_data_t *tnm;
1053   nat44_ei_session_t *s;
1054   clib_bihash_kv_8_8_t key, value;
1055   nat44_ei_user_key_t ukey;
1056   nat44_ei_user_t *u;
1057   u32 session_index, head_index, elt_index;
1058   dlist_elt_t *head, *elt;
1059   ip4_header_t ip;
1060
1061   reg = vl_api_client_index_to_registration (mp->client_index);
1062   if (!reg)
1063     return;
1064
1065   clib_memcpy (&ukey.addr, mp->ip_address, 4);
1066   ip.src_address.as_u32 = ukey.addr.as_u32;
1067   ukey.fib_index = fib_table_find (FIB_PROTOCOL_IP4, ntohl (mp->vrf_id));
1068   key.key = ukey.as_u64;
1069   if (nm->num_workers > 1)
1070     tnm = vec_elt_at_index (
1071       nm->per_thread_data,
1072       nat44_ei_get_in2out_worker_index (&ip, ukey.fib_index, 0));
1073   else
1074     tnm = vec_elt_at_index (nm->per_thread_data, nm->num_workers);
1075
1076   if (clib_bihash_search_8_8 (&tnm->user_hash, &key, &value))
1077     return;
1078   u = pool_elt_at_index (tnm->users, value.value);
1079   if (!u->nsessions && !u->nstaticsessions)
1080     return;
1081
1082   head_index = u->sessions_per_user_list_head_index;
1083   head = pool_elt_at_index (tnm->list_pool, head_index);
1084   elt_index = head->next;
1085   elt = pool_elt_at_index (tnm->list_pool, elt_index);
1086   session_index = elt->value;
1087   while (session_index != ~0)
1088     {
1089       s = pool_elt_at_index (tnm->sessions, session_index);
1090
1091       send_nat44_ei_user_session_details (s, reg, mp->context);
1092
1093       elt_index = elt->next;
1094       elt = pool_elt_at_index (tnm->list_pool, elt_index);
1095       session_index = elt->value;
1096     }
1097 }
1098
1099 static void
1100 vl_api_nat44_ei_del_session_t_handler (vl_api_nat44_ei_del_session_t *mp)
1101 {
1102   nat44_ei_main_t *nm = &nat44_ei_main;
1103   vl_api_nat44_ei_del_session_reply_t *rmp;
1104   ip4_address_t addr, eh_addr;
1105   u16 port;
1106   u32 vrf_id;
1107   int rv = 0;
1108   u8 is_in;
1109   nat_protocol_t proto;
1110
1111   memcpy (&addr.as_u8, mp->address, 4);
1112   port = mp->port;
1113   vrf_id = clib_net_to_host_u32 (mp->vrf_id);
1114   proto = ip_proto_to_nat_proto (mp->protocol);
1115   memcpy (&eh_addr.as_u8, mp->ext_host_address, 4);
1116
1117   // is session inside ?
1118   is_in = mp->flags & NAT44_EI_IF_INSIDE;
1119
1120   rv = nat44_ei_del_session (nm, &addr, port, proto, vrf_id, is_in);
1121
1122   REPLY_MACRO (VL_API_NAT44_EI_DEL_SESSION_REPLY);
1123 }
1124
1125 static void
1126 vl_api_nat44_ei_forwarding_enable_disable_t_handler (
1127   vl_api_nat44_ei_forwarding_enable_disable_t *mp)
1128 {
1129   nat44_ei_main_t *nm = &nat44_ei_main;
1130   vl_api_nat44_ei_forwarding_enable_disable_reply_t *rmp;
1131   int rv = 0;
1132   u32 *ses_to_be_removed = 0, *ses_index;
1133   nat44_ei_main_per_thread_data_t *tnm;
1134   nat44_ei_session_t *s;
1135
1136   nm->forwarding_enabled = mp->enable != 0;
1137
1138   if (mp->enable == 0)
1139     {
1140       vec_foreach (tnm, nm->per_thread_data)
1141         {
1142           vec_foreach (ses_index, ses_to_be_removed)
1143             {
1144               s = pool_elt_at_index (tnm->sessions, ses_index[0]);
1145               nat44_ei_free_session_data (nm, s, tnm - nm->per_thread_data, 0);
1146               nat44_ei_delete_session (nm, s, tnm - nm->per_thread_data);
1147             }
1148
1149           vec_free (ses_to_be_removed);
1150         }
1151     }
1152
1153   REPLY_MACRO (VL_API_NAT44_EI_FORWARDING_ENABLE_DISABLE_REPLY);
1154 }
1155
1156 static void
1157 vl_api_nat44_ei_set_fq_options_t_handler (vl_api_nat44_ei_set_fq_options_t *mp)
1158 {
1159   nat44_ei_main_t *nm = &nat44_ei_main;
1160   vl_api_nat44_ei_set_fq_options_reply_t *rmp;
1161   int rv = 0;
1162   u32 frame_queue_nelts = ntohl (mp->frame_queue_nelts);
1163   rv = nat44_ei_set_frame_queue_nelts (frame_queue_nelts);
1164   REPLY_MACRO (VL_API_NAT44_EI_SET_FQ_OPTIONS_REPLY);
1165 }
1166
1167 static void
1168 vl_api_nat44_ei_show_fq_options_t_handler (
1169   vl_api_nat44_ei_show_fq_options_t *mp)
1170 {
1171   nat44_ei_main_t *nm = &nat44_ei_main;
1172   vl_api_nat44_ei_show_fq_options_reply_t *rmp;
1173   int rv = 0;
1174   /* clang-format off */
1175   REPLY_MACRO2_ZERO (VL_API_NAT44_EI_SHOW_FQ_OPTIONS_REPLY,
1176   ({
1177     rmp->frame_queue_nelts = htonl (nm->frame_queue_nelts);
1178   }));
1179   /* clang-format on */
1180 }
1181
1182 /* API definitions */
1183 #include <vnet/format_fns.h>
1184 #include <nat/nat44-ei/nat44_ei.api.c>
1185
1186 /* Set up the API message handling tables */
1187 clib_error_t *
1188 nat44_ei_api_hookup (vlib_main_t *vm)
1189 {
1190   nat44_ei_main_t *nm = &nat44_ei_main;
1191   nm->msg_id_base = setup_message_id_table ();
1192   return 0;
1193 }
1194
1195 /*
1196  * fd.io coding-style-patch-verification: ON
1197  *
1198  * Local Variables:
1199  * eval: (c-set-style "gnu")
1200  * End:
1201  */