nat: Final NAT44 EI/ED split patch
[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 (&addr, clib_net_to_host_u16 (mp->port),
307                             clib_net_to_host_u32 (mp->path_mtu));
308
309   REPLY_MACRO (VL_API_NAT44_EI_HA_SET_LISTENER_REPLY);
310 }
311
312 static void
313 vl_api_nat44_ei_ha_get_listener_t_handler (
314   vl_api_nat44_ei_ha_get_listener_t *mp)
315 {
316   nat44_ei_main_t *nm = &nat44_ei_main;
317   vl_api_nat44_ei_ha_get_listener_reply_t *rmp;
318   int rv = 0;
319   ip4_address_t addr;
320   u16 port;
321   u32 path_mtu;
322
323   nat_ha_get_listener (&addr, &port, &path_mtu);
324
325   REPLY_MACRO2 (VL_API_NAT44_EI_HA_GET_LISTENER_REPLY, ({
326                   clib_memcpy (rmp->ip_address, &addr, sizeof (ip4_address_t));
327                   rmp->port = clib_host_to_net_u16 (port);
328                   rmp->path_mtu = clib_host_to_net_u32 (path_mtu);
329                 }))
330 }
331
332 static void
333 vl_api_nat44_ei_ha_set_failover_t_handler (
334   vl_api_nat44_ei_ha_set_failover_t *mp)
335 {
336   nat44_ei_main_t *nm = &nat44_ei_main;
337   vl_api_nat44_ei_ha_set_failover_reply_t *rmp;
338   ip4_address_t addr;
339   int rv;
340
341   memcpy (&addr, &mp->ip_address, sizeof (addr));
342   rv =
343     nat_ha_set_failover (&addr, clib_net_to_host_u16 (mp->port),
344                          clib_net_to_host_u32 (mp->session_refresh_interval));
345
346   REPLY_MACRO (VL_API_NAT44_EI_HA_SET_FAILOVER_REPLY);
347 }
348
349 static void
350 vl_api_nat44_ei_ha_get_failover_t_handler (
351   vl_api_nat44_ei_ha_get_failover_t *mp)
352 {
353   nat44_ei_main_t *nm = &nat44_ei_main;
354   vl_api_nat44_ei_ha_get_failover_reply_t *rmp;
355   int rv = 0;
356   ip4_address_t addr;
357   u16 port;
358   u32 session_refresh_interval;
359
360   nat_ha_get_failover (&addr, &port, &session_refresh_interval);
361
362   REPLY_MACRO2 (VL_API_NAT44_EI_HA_GET_FAILOVER_REPLY, ({
363                   clib_memcpy (rmp->ip_address, &addr, sizeof (ip4_address_t));
364                   rmp->port = clib_host_to_net_u16 (port);
365                   rmp->session_refresh_interval =
366                     clib_host_to_net_u32 (session_refresh_interval);
367                 }))
368 }
369
370 static void
371 vl_api_nat44_ei_ha_flush_t_handler (vl_api_nat44_ei_ha_flush_t *mp)
372 {
373   nat44_ei_main_t *nm = &nat44_ei_main;
374   vl_api_nat44_ei_ha_flush_reply_t *rmp;
375   int rv = 0;
376
377   nat_ha_flush (0);
378
379   REPLY_MACRO (VL_API_NAT44_EI_HA_FLUSH_REPLY);
380 }
381
382 static void
383 nat_ha_resync_completed_event_cb (u32 client_index, u32 pid, u32 missed_count)
384 {
385   nat44_ei_main_t *nm = &nat44_ei_main;
386   vl_api_registration_t *reg;
387   vl_api_nat44_ei_ha_resync_completed_event_t *mp;
388
389   reg = vl_api_client_index_to_registration (client_index);
390   if (!reg)
391     return;
392
393   mp = vl_msg_api_alloc (sizeof (*mp));
394   clib_memset (mp, 0, sizeof (*mp));
395   mp->client_index = client_index;
396   mp->pid = pid;
397   mp->missed_count = clib_host_to_net_u32 (missed_count);
398   mp->_vl_msg_id =
399     ntohs (VL_API_NAT44_EI_HA_RESYNC_COMPLETED_EVENT + nm->msg_id_base);
400
401   vl_api_send_msg (reg, (u8 *) mp);
402 }
403
404 static void
405 vl_api_nat44_ei_ha_resync_t_handler (vl_api_nat44_ei_ha_resync_t *mp)
406 {
407   nat44_ei_main_t *nm = &nat44_ei_main;
408   vl_api_nat44_ei_ha_resync_reply_t *rmp;
409   int rv;
410
411   rv = nat_ha_resync (
412     mp->client_index, mp->pid,
413     mp->want_resync_event ? nat_ha_resync_completed_event_cb : NULL);
414
415   REPLY_MACRO (VL_API_NAT44_EI_HA_RESYNC_REPLY);
416 }
417
418 static void
419 vl_api_nat44_ei_del_user_t_handler (vl_api_nat44_ei_del_user_t *mp)
420 {
421   nat44_ei_main_t *nm = &nat44_ei_main;
422   vl_api_nat44_ei_del_user_reply_t *rmp;
423   ip4_address_t addr;
424   int rv;
425   memcpy (&addr.as_u8, mp->ip_address, 4);
426   rv = nat44_ei_user_del (&addr, ntohl (mp->fib_index));
427   REPLY_MACRO (VL_API_NAT44_EI_DEL_USER_REPLY);
428 }
429
430 static void
431 vl_api_nat44_ei_add_del_address_range_t_handler (
432   vl_api_nat44_ei_add_del_address_range_t *mp)
433 {
434   nat44_ei_main_t *nm = &nat44_ei_main;
435   vl_api_nat44_ei_add_del_address_range_reply_t *rmp;
436   ip4_address_t this_addr;
437   u8 is_add;
438   u32 start_host_order, end_host_order;
439   u32 vrf_id;
440   int i, count;
441   int rv = 0;
442   u32 *tmp;
443
444   if (nm->static_mapping_only)
445     {
446       rv = VNET_API_ERROR_FEATURE_DISABLED;
447       goto send_reply;
448     }
449
450   is_add = mp->is_add;
451
452   tmp = (u32 *) mp->first_ip_address;
453   start_host_order = clib_host_to_net_u32 (tmp[0]);
454   tmp = (u32 *) mp->last_ip_address;
455   end_host_order = clib_host_to_net_u32 (tmp[0]);
456
457   count = (end_host_order - start_host_order) + 1;
458
459   vrf_id = clib_host_to_net_u32 (mp->vrf_id);
460
461   if (count > 1024)
462     nat44_ei_log_info ("%U - %U, %d addresses...", format_ip4_address,
463                        mp->first_ip_address, format_ip4_address,
464                        mp->last_ip_address, count);
465
466   memcpy (&this_addr.as_u8, mp->first_ip_address, 4);
467
468   for (i = 0; i < count; i++)
469     {
470       if (is_add)
471         rv = nat44_ei_add_address (nm, &this_addr, vrf_id);
472       else
473         rv = nat44_ei_del_address (nm, this_addr, 0);
474
475       if (rv)
476         goto send_reply;
477
478       if (nm->out2in_dpo)
479         nat44_ei_add_del_address_dpo (this_addr, is_add);
480
481       increment_v4_address (&this_addr);
482     }
483
484 send_reply:
485   REPLY_MACRO (VL_API_NAT44_EI_ADD_DEL_ADDRESS_RANGE_REPLY);
486 }
487
488 static void
489 send_nat44_ei_address_details (nat44_ei_address_t *a,
490                                vl_api_registration_t *reg, u32 context)
491 {
492   vl_api_nat44_ei_address_details_t *rmp;
493   nat44_ei_main_t *nm = &nat44_ei_main;
494
495   rmp = vl_msg_api_alloc (sizeof (*rmp));
496   clib_memset (rmp, 0, sizeof (*rmp));
497   rmp->_vl_msg_id = ntohs (VL_API_NAT44_EI_ADDRESS_DETAILS + nm->msg_id_base);
498   clib_memcpy (rmp->ip_address, &(a->addr), 4);
499   if (a->fib_index != ~0)
500     {
501       fib_table_t *fib = fib_table_get (a->fib_index, FIB_PROTOCOL_IP4);
502       rmp->vrf_id = ntohl (fib->ft_table_id);
503     }
504   else
505     rmp->vrf_id = ~0;
506   rmp->context = context;
507
508   vl_api_send_msg (reg, (u8 *) rmp);
509 }
510
511 static void
512 vl_api_nat44_ei_address_dump_t_handler (vl_api_nat44_ei_address_dump_t *mp)
513 {
514   vl_api_registration_t *reg;
515   nat44_ei_main_t *nm = &nat44_ei_main;
516   nat44_ei_address_t *a;
517
518   reg = vl_api_client_index_to_registration (mp->client_index);
519   if (!reg)
520     return;
521
522   vec_foreach (a, nm->addresses)
523     {
524       send_nat44_ei_address_details (a, reg, mp->context);
525     }
526 }
527
528 static void
529 vl_api_nat44_ei_interface_add_del_feature_t_handler (
530   vl_api_nat44_ei_interface_add_del_feature_t *mp)
531 {
532   nat44_ei_main_t *nm = &nat44_ei_main;
533   vl_api_nat44_ei_interface_add_del_feature_reply_t *rmp;
534   u32 sw_if_index = ntohl (mp->sw_if_index);
535   u8 is_del;
536   int rv = 0;
537
538   is_del = !mp->is_add;
539
540   VALIDATE_SW_IF_INDEX (mp);
541
542   rv = nat44_ei_interface_add_del (sw_if_index, mp->flags & NAT44_EI_IF_INSIDE,
543                                    is_del);
544
545   BAD_SW_IF_INDEX_LABEL;
546
547   REPLY_MACRO (VL_API_NAT44_EI_INTERFACE_ADD_DEL_FEATURE_REPLY);
548 }
549
550 static void
551 send_nat44_ei_interface_details (nat44_ei_interface_t *i,
552                                  vl_api_registration_t *reg, u32 context)
553 {
554   vl_api_nat44_ei_interface_details_t *rmp;
555   nat44_ei_main_t *nm = &nat44_ei_main;
556
557   rmp = vl_msg_api_alloc (sizeof (*rmp));
558   clib_memset (rmp, 0, sizeof (*rmp));
559   rmp->_vl_msg_id =
560     ntohs (VL_API_NAT44_EI_INTERFACE_DETAILS + nm->msg_id_base);
561   rmp->sw_if_index = ntohl (i->sw_if_index);
562
563   if (nat44_ei_interface_is_inside (i))
564     rmp->flags |= NAT44_EI_IF_INSIDE;
565   if (nat44_ei_interface_is_outside (i))
566     rmp->flags |= NAT44_EI_IF_OUTSIDE;
567
568   rmp->context = context;
569
570   vl_api_send_msg (reg, (u8 *) rmp);
571 }
572
573 static void
574 vl_api_nat44_ei_interface_dump_t_handler (vl_api_nat44_ei_interface_dump_t *mp)
575 {
576   vl_api_registration_t *reg;
577   nat44_ei_main_t *nm = &nat44_ei_main;
578   nat44_ei_interface_t *i;
579
580   reg = vl_api_client_index_to_registration (mp->client_index);
581   if (!reg)
582     return;
583
584   pool_foreach (i, nm->interfaces)
585     {
586       send_nat44_ei_interface_details (i, reg, mp->context);
587     }
588 }
589
590 static void
591 vl_api_nat44_ei_interface_add_del_output_feature_t_handler (
592   vl_api_nat44_ei_interface_add_del_output_feature_t *mp)
593 {
594   nat44_ei_main_t *nm = &nat44_ei_main;
595   vl_api_nat44_ei_interface_add_del_output_feature_reply_t *rmp;
596   u32 sw_if_index = ntohl (mp->sw_if_index);
597   int rv = 0;
598
599   VALIDATE_SW_IF_INDEX (mp);
600
601   rv = nat44_ei_interface_add_del_output_feature (
602     sw_if_index, mp->flags & NAT44_EI_IF_INSIDE, !mp->is_add);
603
604   BAD_SW_IF_INDEX_LABEL;
605   REPLY_MACRO (VL_API_NAT44_EI_INTERFACE_ADD_DEL_OUTPUT_FEATURE_REPLY);
606 }
607
608 static void
609 send_nat44_ei_interface_output_feature_details (nat44_ei_interface_t *i,
610                                                 vl_api_registration_t *reg,
611                                                 u32 context)
612 {
613   vl_api_nat44_ei_interface_output_feature_details_t *rmp;
614   nat44_ei_main_t *nm = &nat44_ei_main;
615
616   rmp = vl_msg_api_alloc (sizeof (*rmp));
617   clib_memset (rmp, 0, sizeof (*rmp));
618   rmp->_vl_msg_id =
619     ntohs (VL_API_NAT44_EI_INTERFACE_OUTPUT_FEATURE_DETAILS + nm->msg_id_base);
620   rmp->sw_if_index = ntohl (i->sw_if_index);
621   rmp->context = context;
622
623   if (nat44_ei_interface_is_inside (i))
624     rmp->flags |= NAT44_EI_IF_INSIDE;
625
626   vl_api_send_msg (reg, (u8 *) rmp);
627 }
628
629 static void
630 vl_api_nat44_ei_interface_output_feature_dump_t_handler (
631   vl_api_nat44_ei_interface_output_feature_dump_t *mp)
632 {
633   vl_api_registration_t *reg;
634   nat44_ei_main_t *nm = &nat44_ei_main;
635   nat44_ei_interface_t *i;
636
637   reg = vl_api_client_index_to_registration (mp->client_index);
638   if (!reg)
639     return;
640
641   pool_foreach (i, nm->output_feature_interfaces)
642     {
643       send_nat44_ei_interface_output_feature_details (i, reg, mp->context);
644     }
645 }
646
647 static void
648 vl_api_nat44_ei_add_del_static_mapping_t_handler (
649   vl_api_nat44_ei_add_del_static_mapping_t *mp)
650 {
651   nat44_ei_main_t *nm = &nat44_ei_main;
652   vl_api_nat44_ei_add_del_static_mapping_reply_t *rmp;
653   ip4_address_t local_addr, external_addr;
654   u16 local_port = 0, external_port = 0;
655   u32 vrf_id, external_sw_if_index;
656   int rv = 0;
657   nat_protocol_t proto;
658   u8 *tag = 0;
659
660   memcpy (&local_addr.as_u8, mp->local_ip_address, 4);
661   memcpy (&external_addr.as_u8, mp->external_ip_address, 4);
662
663   if (!(mp->flags & NAT44_EI_ADDR_ONLY_MAPPING))
664     {
665       local_port = mp->local_port;
666       external_port = mp->external_port;
667     }
668
669   vrf_id = clib_net_to_host_u32 (mp->vrf_id);
670   external_sw_if_index = clib_net_to_host_u32 (mp->external_sw_if_index);
671   proto = ip_proto_to_nat_proto (mp->protocol);
672
673   mp->tag[sizeof (mp->tag) - 1] = 0;
674   tag = format (0, "%s", mp->tag);
675   vec_terminate_c_string (tag);
676
677   rv = nat44_ei_add_del_static_mapping (
678     local_addr, external_addr, local_port, external_port, proto,
679     external_sw_if_index, vrf_id, mp->flags & NAT44_EI_ADDR_ONLY_MAPPING, 0,
680     tag, mp->is_add);
681
682   vec_free (tag);
683
684   REPLY_MACRO (VL_API_NAT44_EI_ADD_DEL_STATIC_MAPPING_REPLY);
685 }
686
687 static void
688 send_nat44_ei_static_mapping_details (nat44_ei_static_mapping_t *m,
689                                       vl_api_registration_t *reg, u32 context)
690 {
691   vl_api_nat44_ei_static_mapping_details_t *rmp;
692   nat44_ei_main_t *nm = &nat44_ei_main;
693   u32 len = sizeof (*rmp);
694
695   rmp = vl_msg_api_alloc (len);
696   clib_memset (rmp, 0, len);
697   rmp->_vl_msg_id =
698     ntohs (VL_API_NAT44_EI_STATIC_MAPPING_DETAILS + nm->msg_id_base);
699
700   clib_memcpy (rmp->local_ip_address, &(m->local_addr), 4);
701   clib_memcpy (rmp->external_ip_address, &(m->external_addr), 4);
702   rmp->external_sw_if_index = ~0;
703   rmp->vrf_id = htonl (m->vrf_id);
704   rmp->context = context;
705
706   if (nat44_ei_is_addr_only_static_mapping (m))
707     {
708       rmp->flags |= NAT44_EI_ADDR_ONLY_MAPPING;
709     }
710   else
711     {
712       rmp->protocol = nat_proto_to_ip_proto (m->proto);
713       rmp->external_port = m->external_port;
714       rmp->local_port = m->local_port;
715     }
716
717   if (m->tag)
718     strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
719
720   vl_api_send_msg (reg, (u8 *) rmp);
721 }
722
723 static void
724 send_nat44_ei_static_map_resolve_details (nat44_ei_static_map_resolve_t *m,
725                                           vl_api_registration_t *reg,
726                                           u32 context)
727 {
728   vl_api_nat44_ei_static_mapping_details_t *rmp;
729   nat44_ei_main_t *nm = &nat44_ei_main;
730
731   rmp = vl_msg_api_alloc (sizeof (*rmp));
732   clib_memset (rmp, 0, sizeof (*rmp));
733   rmp->_vl_msg_id =
734     ntohs (VL_API_NAT44_EI_STATIC_MAPPING_DETAILS + nm->msg_id_base);
735   clib_memcpy (rmp->local_ip_address, &(m->l_addr), 4);
736   rmp->external_sw_if_index = htonl (m->sw_if_index);
737   rmp->vrf_id = htonl (m->vrf_id);
738   rmp->context = context;
739
740   if (m->addr_only)
741     {
742       rmp->flags |= NAT44_EI_ADDR_ONLY_MAPPING;
743     }
744   else
745     {
746       rmp->protocol = nat_proto_to_ip_proto (m->proto);
747       rmp->external_port = m->e_port;
748       rmp->local_port = m->l_port;
749     }
750   if (m->tag)
751     strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
752
753   vl_api_send_msg (reg, (u8 *) rmp);
754 }
755
756 static void
757 vl_api_nat44_ei_static_mapping_dump_t_handler (
758   vl_api_nat44_ei_static_mapping_dump_t *mp)
759 {
760   vl_api_registration_t *reg;
761   nat44_ei_main_t *nm = &nat44_ei_main;
762   nat44_ei_static_mapping_t *m;
763   nat44_ei_static_map_resolve_t *rp;
764   int j;
765
766   reg = vl_api_client_index_to_registration (mp->client_index);
767   if (!reg)
768     return;
769
770   pool_foreach (m, nm->static_mappings)
771     {
772       if (!nat44_ei_is_identity_static_mapping (m))
773         send_nat44_ei_static_mapping_details (m, reg, mp->context);
774     }
775
776   for (j = 0; j < vec_len (nm->to_resolve); j++)
777     {
778       rp = nm->to_resolve + j;
779       if (!rp->identity_nat)
780         send_nat44_ei_static_map_resolve_details (rp, reg, mp->context);
781     }
782 }
783
784 static void
785 vl_api_nat44_ei_add_del_identity_mapping_t_handler (
786   vl_api_nat44_ei_add_del_identity_mapping_t *mp)
787 {
788   nat44_ei_main_t *nm = &nat44_ei_main;
789   vl_api_nat44_ei_add_del_identity_mapping_reply_t *rmp;
790   ip4_address_t addr;
791   u16 port = 0;
792   u32 vrf_id, sw_if_index;
793   int rv = 0;
794   nat_protocol_t proto = NAT_PROTOCOL_OTHER;
795   u8 *tag = 0;
796
797   if (!(mp->flags & NAT44_EI_ADDR_ONLY_MAPPING))
798     {
799       port = mp->port;
800       proto = ip_proto_to_nat_proto (mp->protocol);
801     }
802   vrf_id = clib_net_to_host_u32 (mp->vrf_id);
803   sw_if_index = clib_net_to_host_u32 (mp->sw_if_index);
804   if (sw_if_index != ~0)
805     addr.as_u32 = 0;
806   else
807     memcpy (&addr.as_u8, mp->ip_address, 4);
808   mp->tag[sizeof (mp->tag) - 1] = 0;
809   tag = format (0, "%s", mp->tag);
810   vec_terminate_c_string (tag);
811
812   rv = nat44_ei_add_del_static_mapping (
813     addr, addr, port, port, proto, sw_if_index, vrf_id,
814     mp->flags & NAT44_EI_ADDR_ONLY_MAPPING, 1, tag, mp->is_add);
815
816   vec_free (tag);
817
818   REPLY_MACRO (VL_API_NAT44_EI_ADD_DEL_IDENTITY_MAPPING_REPLY);
819 }
820
821 static void
822 send_nat44_ei_identity_mapping_details (nat44_ei_static_mapping_t *m,
823                                         int index, vl_api_registration_t *reg,
824                                         u32 context)
825 {
826   vl_api_nat44_ei_identity_mapping_details_t *rmp;
827   nat44_ei_main_t *nm = &nat44_ei_main;
828   nat44_ei_lb_addr_port_t *local = pool_elt_at_index (m->locals, index);
829
830   rmp = vl_msg_api_alloc (sizeof (*rmp));
831   clib_memset (rmp, 0, sizeof (*rmp));
832   rmp->_vl_msg_id =
833     ntohs (VL_API_NAT44_EI_IDENTITY_MAPPING_DETAILS + nm->msg_id_base);
834
835   if (nat44_ei_is_addr_only_static_mapping (m))
836     rmp->flags |= NAT44_EI_ADDR_ONLY_MAPPING;
837
838   clib_memcpy (rmp->ip_address, &(m->local_addr), 4);
839   rmp->port = m->local_port;
840   rmp->sw_if_index = ~0;
841   rmp->vrf_id = htonl (local->vrf_id);
842   rmp->protocol = nat_proto_to_ip_proto (m->proto);
843   rmp->context = context;
844   if (m->tag)
845     strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
846
847   vl_api_send_msg (reg, (u8 *) rmp);
848 }
849
850 static void
851 send_nat44_ei_identity_map_resolve_details (nat44_ei_static_map_resolve_t *m,
852                                             vl_api_registration_t *reg,
853                                             u32 context)
854 {
855   vl_api_nat44_ei_identity_mapping_details_t *rmp;
856   nat44_ei_main_t *nm = &nat44_ei_main;
857   rmp = vl_msg_api_alloc (sizeof (*rmp));
858   clib_memset (rmp, 0, sizeof (*rmp));
859   rmp->_vl_msg_id =
860     ntohs (VL_API_NAT44_EI_IDENTITY_MAPPING_DETAILS + nm->msg_id_base);
861
862   if (m->addr_only)
863     rmp->flags = (vl_api_nat44_ei_config_flags_t) NAT44_EI_ADDR_ONLY_MAPPING;
864
865   rmp->port = m->l_port;
866   rmp->sw_if_index = htonl (m->sw_if_index);
867   rmp->vrf_id = htonl (m->vrf_id);
868   rmp->protocol = nat_proto_to_ip_proto (m->proto);
869   rmp->context = context;
870   if (m->tag)
871     strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag));
872
873   vl_api_send_msg (reg, (u8 *) rmp);
874 }
875
876 static void
877 vl_api_nat44_ei_identity_mapping_dump_t_handler (
878   vl_api_nat44_ei_identity_mapping_dump_t *mp)
879 {
880   vl_api_registration_t *reg;
881   nat44_ei_main_t *nm = &nat44_ei_main;
882   nat44_ei_static_mapping_t *m;
883   nat44_ei_static_map_resolve_t *rp;
884   int j;
885
886   reg = vl_api_client_index_to_registration (mp->client_index);
887   if (!reg)
888     return;
889
890   pool_foreach (m, nm->static_mappings)
891     {
892       if (nat44_ei_is_identity_static_mapping (m))
893         {
894           pool_foreach_index (j, m->locals)
895             {
896               send_nat44_ei_identity_mapping_details (m, j, reg, mp->context);
897             }
898         }
899     }
900
901   for (j = 0; j < vec_len (nm->to_resolve); j++)
902     {
903       rp = nm->to_resolve + j;
904       if (rp->identity_nat)
905         send_nat44_ei_identity_map_resolve_details (rp, reg, mp->context);
906     }
907 }
908
909 static void
910 vl_api_nat44_ei_add_del_interface_addr_t_handler (
911   vl_api_nat44_ei_add_del_interface_addr_t *mp)
912 {
913   nat44_ei_main_t *nm = &nat44_ei_main;
914   vl_api_nat44_ei_add_del_interface_addr_reply_t *rmp;
915   u32 sw_if_index = ntohl (mp->sw_if_index);
916   int rv = 0;
917   u8 is_del;
918
919   is_del = !mp->is_add;
920
921   VALIDATE_SW_IF_INDEX (mp);
922
923   rv = nat44_ei_add_interface_address (nm, sw_if_index, is_del);
924
925   BAD_SW_IF_INDEX_LABEL;
926   REPLY_MACRO (VL_API_NAT44_EI_ADD_DEL_INTERFACE_ADDR_REPLY);
927 }
928
929 static void
930 send_nat44_ei_interface_addr_details (u32 sw_if_index,
931                                       vl_api_registration_t *reg, u32 context)
932 {
933   vl_api_nat44_ei_interface_addr_details_t *rmp;
934   nat44_ei_main_t *nm = &nat44_ei_main;
935
936   rmp = vl_msg_api_alloc (sizeof (*rmp));
937   clib_memset (rmp, 0, sizeof (*rmp));
938   rmp->_vl_msg_id =
939     ntohs (VL_API_NAT44_EI_INTERFACE_ADDR_DETAILS + nm->msg_id_base);
940   rmp->sw_if_index = ntohl (sw_if_index);
941   rmp->context = context;
942
943   vl_api_send_msg (reg, (u8 *) rmp);
944 }
945
946 static void
947 vl_api_nat44_ei_interface_addr_dump_t_handler (
948   vl_api_nat44_ei_interface_addr_dump_t *mp)
949 {
950   vl_api_registration_t *reg;
951   nat44_ei_main_t *nm = &nat44_ei_main;
952   u32 *i;
953
954   reg = vl_api_client_index_to_registration (mp->client_index);
955   if (!reg)
956     return;
957
958   vec_foreach (i, nm->auto_add_sw_if_indices)
959     send_nat44_ei_interface_addr_details (*i, reg, mp->context);
960 }
961
962 static void
963 send_nat44_ei_user_details (nat44_ei_user_t *u, vl_api_registration_t *reg,
964                             u32 context)
965 {
966   vl_api_nat44_ei_user_details_t *rmp;
967   nat44_ei_main_t *nm = &nat44_ei_main;
968   ip4_main_t *im = &ip4_main;
969
970   rmp = vl_msg_api_alloc (sizeof (*rmp));
971   clib_memset (rmp, 0, sizeof (*rmp));
972   rmp->_vl_msg_id = ntohs (VL_API_NAT44_EI_USER_DETAILS + nm->msg_id_base);
973
974   if (!pool_is_free_index (im->fibs, u->fib_index))
975     {
976       fib_table_t *fib = fib_table_get (u->fib_index, FIB_PROTOCOL_IP4);
977       rmp->vrf_id = ntohl (fib->ft_table_id);
978     }
979
980   clib_memcpy (rmp->ip_address, &(u->addr), 4);
981   rmp->nsessions = ntohl (u->nsessions);
982   rmp->nstaticsessions = ntohl (u->nstaticsessions);
983   rmp->context = context;
984
985   vl_api_send_msg (reg, (u8 *) rmp);
986 }
987
988 static void
989 vl_api_nat44_ei_user_dump_t_handler (vl_api_nat44_ei_user_dump_t *mp)
990 {
991   vl_api_registration_t *reg;
992   nat44_ei_main_t *nm = &nat44_ei_main;
993   nat44_ei_main_per_thread_data_t *tnm;
994   nat44_ei_user_t *u;
995
996   reg = vl_api_client_index_to_registration (mp->client_index);
997   if (!reg)
998     return;
999
1000   vec_foreach (tnm, nm->per_thread_data)
1001     {
1002       pool_foreach (u, tnm->users)
1003         {
1004           send_nat44_ei_user_details (u, reg, mp->context);
1005         }
1006     }
1007 }
1008
1009 static void
1010 send_nat44_ei_user_session_details (nat44_ei_session_t *s,
1011                                     vl_api_registration_t *reg, u32 context)
1012 {
1013   vl_api_nat44_ei_user_session_details_t *rmp;
1014   nat44_ei_main_t *nm = &nat44_ei_main;
1015
1016   rmp = vl_msg_api_alloc (sizeof (*rmp));
1017   clib_memset (rmp, 0, sizeof (*rmp));
1018   rmp->_vl_msg_id =
1019     ntohs (VL_API_NAT44_EI_USER_SESSION_DETAILS + nm->msg_id_base);
1020   clib_memcpy (rmp->outside_ip_address, (&s->out2in.addr), 4);
1021   clib_memcpy (rmp->inside_ip_address, (&s->in2out.addr), 4);
1022
1023   if (nat44_ei_is_session_static (s))
1024     rmp->flags |= NAT44_EI_STATIC_MAPPING;
1025
1026   rmp->last_heard = clib_host_to_net_u64 ((u64) s->last_heard);
1027   rmp->total_bytes = clib_host_to_net_u64 (s->total_bytes);
1028   rmp->total_pkts = ntohl (s->total_pkts);
1029   rmp->context = context;
1030   if (nat44_ei_is_unk_proto_session (s))
1031     {
1032       rmp->outside_port = 0;
1033       rmp->inside_port = 0;
1034       rmp->protocol = ntohs (s->in2out.port);
1035     }
1036   else
1037     {
1038       rmp->outside_port = s->out2in.port;
1039       rmp->inside_port = s->in2out.port;
1040       rmp->protocol = ntohs (nat_proto_to_ip_proto (s->nat_proto));
1041     }
1042   vl_api_send_msg (reg, (u8 *) rmp);
1043 }
1044
1045 static void
1046 vl_api_nat44_ei_user_session_dump_t_handler (
1047   vl_api_nat44_ei_user_session_dump_t *mp)
1048 {
1049   vl_api_registration_t *reg;
1050   nat44_ei_main_t *nm = &nat44_ei_main;
1051   nat44_ei_main_per_thread_data_t *tnm;
1052   nat44_ei_session_t *s;
1053   clib_bihash_kv_8_8_t key, value;
1054   nat44_ei_user_key_t ukey;
1055   nat44_ei_user_t *u;
1056   u32 session_index, head_index, elt_index;
1057   dlist_elt_t *head, *elt;
1058   ip4_header_t ip;
1059
1060   reg = vl_api_client_index_to_registration (mp->client_index);
1061   if (!reg)
1062     return;
1063
1064   clib_memcpy (&ukey.addr, mp->ip_address, 4);
1065   ip.src_address.as_u32 = ukey.addr.as_u32;
1066   ukey.fib_index = fib_table_find (FIB_PROTOCOL_IP4, ntohl (mp->vrf_id));
1067   key.key = ukey.as_u64;
1068   if (nm->num_workers > 1)
1069     tnm = vec_elt_at_index (nm->per_thread_data,
1070                             nm->worker_in2out_cb (&ip, ukey.fib_index, 0));
1071   else
1072     tnm = vec_elt_at_index (nm->per_thread_data, nm->num_workers);
1073
1074   if (clib_bihash_search_8_8 (&tnm->user_hash, &key, &value))
1075     return;
1076   u = pool_elt_at_index (tnm->users, value.value);
1077   if (!u->nsessions && !u->nstaticsessions)
1078     return;
1079
1080   head_index = u->sessions_per_user_list_head_index;
1081   head = pool_elt_at_index (tnm->list_pool, head_index);
1082   elt_index = head->next;
1083   elt = pool_elt_at_index (tnm->list_pool, elt_index);
1084   session_index = elt->value;
1085   while (session_index != ~0)
1086     {
1087       s = pool_elt_at_index (tnm->sessions, session_index);
1088
1089       send_nat44_ei_user_session_details (s, reg, mp->context);
1090
1091       elt_index = elt->next;
1092       elt = pool_elt_at_index (tnm->list_pool, elt_index);
1093       session_index = elt->value;
1094     }
1095 }
1096
1097 static void
1098 vl_api_nat44_ei_del_session_t_handler (vl_api_nat44_ei_del_session_t *mp)
1099 {
1100   nat44_ei_main_t *nm = &nat44_ei_main;
1101   vl_api_nat44_ei_del_session_reply_t *rmp;
1102   ip4_address_t addr, eh_addr;
1103   u16 port;
1104   u32 vrf_id;
1105   int rv = 0;
1106   u8 is_in;
1107   nat_protocol_t proto;
1108
1109   memcpy (&addr.as_u8, mp->address, 4);
1110   port = mp->port;
1111   vrf_id = clib_net_to_host_u32 (mp->vrf_id);
1112   proto = ip_proto_to_nat_proto (mp->protocol);
1113   memcpy (&eh_addr.as_u8, mp->ext_host_address, 4);
1114
1115   // is session inside ?
1116   is_in = mp->flags & NAT44_EI_IF_INSIDE;
1117
1118   rv = nat44_ei_del_session (nm, &addr, port, proto, vrf_id, is_in);
1119
1120   REPLY_MACRO (VL_API_NAT44_EI_DEL_SESSION_REPLY);
1121 }
1122
1123 static void
1124 vl_api_nat44_ei_forwarding_enable_disable_t_handler (
1125   vl_api_nat44_ei_forwarding_enable_disable_t *mp)
1126 {
1127   nat44_ei_main_t *nm = &nat44_ei_main;
1128   vl_api_nat44_ei_forwarding_enable_disable_reply_t *rmp;
1129   int rv = 0;
1130   u32 *ses_to_be_removed = 0, *ses_index;
1131   nat44_ei_main_per_thread_data_t *tnm;
1132   nat44_ei_session_t *s;
1133
1134   nm->forwarding_enabled = mp->enable != 0;
1135
1136   if (mp->enable == 0)
1137     {
1138       vec_foreach (tnm, nm->per_thread_data)
1139         {
1140           vec_foreach (ses_index, ses_to_be_removed)
1141             {
1142               s = pool_elt_at_index (tnm->sessions, ses_index[0]);
1143               nat44_ei_free_session_data (nm, s, tnm - nm->per_thread_data, 0);
1144               nat44_ei_delete_session (nm, s, tnm - nm->per_thread_data);
1145             }
1146
1147           vec_free (ses_to_be_removed);
1148         }
1149     }
1150
1151   REPLY_MACRO (VL_API_NAT44_EI_FORWARDING_ENABLE_DISABLE_REPLY);
1152 }
1153
1154 static void
1155 vl_api_nat44_ei_set_fq_options_t_handler (vl_api_nat44_ei_set_fq_options_t *mp)
1156 {
1157   nat44_ei_main_t *nm = &nat44_ei_main;
1158   vl_api_nat44_ei_set_fq_options_reply_t *rmp;
1159   int rv = 0;
1160   u32 frame_queue_nelts = ntohl (mp->frame_queue_nelts);
1161   rv = nat44_ei_set_frame_queue_nelts (frame_queue_nelts);
1162   REPLY_MACRO (VL_API_NAT44_EI_SET_FQ_OPTIONS_REPLY);
1163 }
1164
1165 static void
1166 vl_api_nat44_ei_show_fq_options_t_handler (
1167   vl_api_nat44_ei_show_fq_options_t *mp)
1168 {
1169   nat44_ei_main_t *nm = &nat44_ei_main;
1170   vl_api_nat44_ei_show_fq_options_reply_t *rmp;
1171   int rv = 0;
1172   /* clang-format off */
1173   REPLY_MACRO2_ZERO (VL_API_NAT44_EI_SHOW_FQ_OPTIONS_REPLY,
1174   ({
1175     rmp->frame_queue_nelts = htonl (nm->frame_queue_nelts);
1176   }));
1177   /* clang-format on */
1178 }
1179
1180 /* API definitions */
1181 #include <vnet/format_fns.h>
1182 #include <nat/nat44-ei/nat44_ei.api.c>
1183
1184 /* Set up the API message handling tables */
1185 clib_error_t *
1186 nat44_ei_api_hookup (vlib_main_t *vm)
1187 {
1188   nat44_ei_main_t *nm = &nat44_ei_main;
1189   nm->msg_id_base = setup_message_id_table ();
1190   return 0;
1191 }
1192
1193 /*
1194  * fd.io coding-style-patch-verification: ON
1195  *
1196  * Local Variables:
1197  * eval: (c-set-style "gnu")
1198  * End:
1199  */