cnat: Add DHCP support
[vpp.git] / src / plugins / cnat / cnat_translation.c
1 /*
2  * Copyright (c) 2020 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #include <vnet/fib/fib_source.h>
17 #include <vnet/fib/fib_table.h>
18 #include <vnet/fib/fib_entry_track.h>
19 #include <vnet/dpo/load_balance.h>
20 #include <vnet/dpo/drop_dpo.h>
21
22 #include <cnat/cnat_translation.h>
23 #include <cnat/cnat_session.h>
24 #include <cnat/cnat_client.h>
25
26 cnat_translation_t *cnat_translation_pool;
27 clib_bihash_8_8_t cnat_translation_db;
28 addr_resolution_t *tr_resolutions;
29
30 typedef void (*cnat_if_addr_add_cb_t) (addr_resolution_t * ar,
31                                        ip_address_t * address, u8 is_del);
32 cnat_if_addr_add_cb_t *cnat_if_addr_add_cbs;
33
34 static fib_node_type_t cnat_translation_fib_node_type;
35
36 vlib_combined_counter_main_t cnat_translation_counters = {
37   .name = "cnat-translation",
38   .stat_segment_name = "/net/cnat-translation",
39 };
40
41 void
42 cnat_translation_watch_addr (index_t cti, u64 opaque, cnat_endpoint_t * ep,
43                              cnat_addr_resol_type_t type)
44 {
45   addr_resolution_t *ar;
46
47   if (INDEX_INVALID == ep->ce_sw_if_index)
48     return;
49
50   pool_get (tr_resolutions, ar);
51   ar->af = ep->ce_ip.version;
52   ar->sw_if_index = ep->ce_sw_if_index;
53   ar->type = type;
54   ar->opaque = opaque;
55   ar->cti = cti;
56 }
57
58 static void
59 cnat_resolve_ep_tuple (cnat_endpoint_tuple_t * path)
60 {
61   cnat_resolve_ep (&path->src_ep);
62   cnat_resolve_ep (&path->dst_ep);
63 }
64
65 void
66 cnat_translation_unwatch_addr (u32 cti, cnat_addr_resol_type_t type)
67 {
68   /* Delete tr resolution entries matching translation index */
69   addr_resolution_t *ar;
70   index_t *indexes = 0, *ari;
71   /* *INDENT-OFF* */
72   pool_foreach (ar, tr_resolutions, ({
73     if ((cti == INDEX_INVALID || ar->cti == cti) &&
74       (ar->type == type || CNAT_RESOLV_ADDR_ANY == type))
75       vec_add1(indexes, ar - tr_resolutions);
76   }));
77   /* *INDENT-ON* */
78   vec_foreach (ari, indexes) pool_put_index (tr_resolutions, *ari);
79
80   vec_free (indexes);
81 }
82
83 static void
84 cnat_tracker_release (cnat_ep_trk_t * trk)
85 {
86   /* We only track fully resolved endpoints */
87   if (!trk->is_active)
88     return;
89   fib_entry_untrack (trk->ct_fei, trk->ct_sibling);
90 }
91
92 static void
93 cnat_tracker_track (index_t cti, cnat_ep_trk_t * trk)
94 {
95   fib_prefix_t pfx;
96   /* We only track fully resolved endpoints */
97   trk->is_active = trk->ct_ep[VLIB_TX].ce_flags & CNAT_EP_FLAG_RESOLVED
98     && trk->ct_ep[VLIB_RX].ce_flags & CNAT_EP_FLAG_RESOLVED;
99   if (!trk->is_active)
100     return;
101
102   ip_address_to_fib_prefix (&trk->ct_ep[VLIB_TX].ce_ip, &pfx);
103   trk->ct_fei = fib_entry_track (CNAT_FIB_TABLE,
104                                  &pfx,
105                                  cnat_translation_fib_node_type,
106                                  cti, &trk->ct_sibling);
107
108   fib_entry_contribute_forwarding (trk->ct_fei,
109                                    fib_forw_chain_type_from_fib_proto
110                                    (pfx.fp_proto), &trk->ct_dpo);
111 }
112
113 /**
114  * Add a translation to the bihash
115  *
116  * @param cci the ID of the parent client (invalid if vip not resolved)
117  * @param vip the translation endpoint
118  * @param proto the translation proto
119  * @param cti the translation index to be used as value
120  */
121 static void
122 cnat_add_translation_to_db (index_t cci, cnat_endpoint_t * vip,
123                             ip_protocol_t proto, index_t cti)
124 {
125   clib_bihash_kv_8_8_t bkey;
126   u64 key;
127   if (INDEX_INVALID == cci)
128     {
129       key = proto << 8 | 0x80 | vip->ce_ip.version;
130       key = key << 16 | vip->ce_port;
131       key = key << 32 | (u32) vip->ce_sw_if_index;
132     }
133   else
134     {
135       key = proto << 8;
136       key = key << 16 | vip->ce_port;
137       key = key << 32 | (u32) cci;
138     }
139
140   bkey.key = key;
141   bkey.value = cti;
142
143   clib_bihash_add_del_8_8 (&cnat_translation_db, &bkey, 1);
144 }
145
146 /**
147  * Remove a translation from the bihash
148  *
149  * @param cci the ID of the parent client
150  * @param vip the translation endpoint
151  * @param proto the translation proto
152  */
153 static void
154 cnat_remove_translation_from_db (index_t cci, cnat_endpoint_t * vip,
155                                  ip_protocol_t proto)
156 {
157   clib_bihash_kv_8_8_t bkey;
158   u64 key;
159   if (INDEX_INVALID == cci)
160     {
161       key = proto << 8 | 0x80 | vip->ce_ip.version;
162       key = key << 16 | vip->ce_port;
163       key = key << 32 | (u32) vip->ce_sw_if_index;
164     }
165   else
166     {
167       key = proto << 8;
168       key = key << 16 | vip->ce_port;
169       key = key << 32 | (u32) cci;
170     }
171
172   bkey.key = key;
173
174   clib_bihash_add_del_8_8 (&cnat_translation_db, &bkey, 0);
175 }
176
177 static void
178 cnat_translation_stack (cnat_translation_t * ct)
179 {
180   fib_protocol_t fproto;
181   cnat_ep_trk_t *trk;
182   dpo_proto_t dproto;
183   u8 ep_idx = 0;
184   index_t lbi;
185
186   fproto = ip_address_family_to_fib_proto (ct->ct_vip.ce_ip.version);
187   dproto = fib_proto_to_dpo (fproto);
188
189   vec_foreach (trk, ct->ct_paths) if (trk->is_active)
190     ep_idx++;
191
192   lbi = load_balance_create (ep_idx, fib_proto_to_dpo (fproto),
193                              IP_FLOW_HASH_DEFAULT);
194
195   ep_idx = 0;
196   vec_foreach (trk, ct->ct_paths) if (trk->is_active)
197     load_balance_set_bucket (lbi, ep_idx++, &trk->ct_dpo);
198
199   dpo_set (&ct->ct_lb, DPO_LOAD_BALANCE, dproto, lbi);
200   dpo_stack (cnat_client_dpo, dproto, &ct->ct_lb, &ct->ct_lb);
201 }
202
203 int
204 cnat_translation_delete (u32 id)
205 {
206   cnat_translation_t *ct;
207   cnat_ep_trk_t *trk;
208
209   if (pool_is_free_index (cnat_translation_pool, id))
210     return (VNET_API_ERROR_NO_SUCH_ENTRY);
211
212   ct = pool_elt_at_index (cnat_translation_pool, id);
213
214   dpo_reset (&ct->ct_lb);
215
216   vec_foreach (trk, ct->ct_paths) cnat_tracker_release (trk);
217
218   cnat_remove_translation_from_db (ct->ct_cci, &ct->ct_vip, ct->ct_proto);
219   cnat_client_translation_deleted (ct->ct_cci);
220   cnat_translation_unwatch_addr (id, CNAT_RESOLV_ADDR_ANY);
221   pool_put (cnat_translation_pool, ct);
222
223   return (0);
224 }
225
226 u32
227 cnat_translation_update (cnat_endpoint_t * vip,
228                          ip_protocol_t proto,
229                          cnat_endpoint_tuple_t * paths, u8 flags)
230 {
231   cnat_endpoint_tuple_t *path;
232   const cnat_client_t *cc;
233   cnat_translation_t *ct;
234   cnat_ep_trk_t *trk;
235   index_t cci;
236
237   cnat_lazy_init ();
238   if (cnat_resolve_ep (vip))
239     {
240       /* vip only contains a sw_if_index for now */
241       ct = cnat_find_translation (vip->ce_sw_if_index, vip->ce_port, proto);
242       cci = INDEX_INVALID;
243     }
244   else
245     {
246       /* do we know of this ep's vip */
247       cci = cnat_client_add (&vip->ce_ip, flags);
248       cc = cnat_client_get (cci);
249
250       ct = cnat_find_translation (cc->parent_cci, vip->ce_port, proto);
251     }
252
253   if (NULL == ct)
254     {
255       pool_get_zero (cnat_translation_pool, ct);
256
257       clib_memcpy (&ct->ct_vip, vip, sizeof (*vip));
258       ct->ct_proto = proto;
259       ct->ct_cci = cci;
260       ct->index = ct - cnat_translation_pool;
261
262       cnat_add_translation_to_db (cci, vip, proto, ct->index);
263       cnat_client_translation_added (cci);
264
265       vlib_validate_combined_counter (&cnat_translation_counters, ct->index);
266       vlib_zero_combined_counter (&cnat_translation_counters, ct->index);
267     }
268   ct->flags = flags;
269
270   cnat_translation_unwatch_addr (ct->index, CNAT_RESOLV_ADDR_ANY);
271   cnat_translation_watch_addr (ct->index, 0, vip,
272                                CNAT_RESOLV_ADDR_TRANSLATION);
273
274   vec_foreach (trk, ct->ct_paths)
275   {
276     cnat_tracker_release (trk);
277   }
278
279   vec_reset_length (ct->ct_paths);
280
281   u64 path_idx = 0;
282   vec_foreach (path, paths)
283   {
284     cnat_resolve_ep_tuple (path);
285     cnat_translation_watch_addr (ct->index,
286                                  path_idx << 32 | VLIB_RX, &path->src_ep,
287                                  CNAT_RESOLV_ADDR_BACKEND);
288     cnat_translation_watch_addr (ct->index,
289                                  path_idx << 32 | VLIB_TX, &path->dst_ep,
290                                  CNAT_RESOLV_ADDR_BACKEND);
291     path_idx++;
292
293     vec_add2 (ct->ct_paths, trk, 1);
294
295     clib_memcpy (&trk->ct_ep[VLIB_TX], &path->dst_ep,
296                  sizeof (trk->ct_ep[VLIB_TX]));
297     clib_memcpy (&trk->ct_ep[VLIB_RX], &path->src_ep,
298                  sizeof (trk->ct_ep[VLIB_RX]));
299
300     cnat_tracker_track (ct->index, trk);
301   }
302
303   cnat_translation_stack (ct);
304
305   return (ct->index);
306 }
307
308 void
309 cnat_translation_walk (cnat_translation_walk_cb_t cb, void *ctx)
310 {
311   u32 api;
312
313   /* *INDENT-OFF* */
314   pool_foreach_index(api, cnat_translation_pool,
315   ({
316     if (!cb(api, ctx))
317       break;
318   }));
319   /* *INDENT-ON* */
320 }
321
322 static u8 *
323 format_cnat_ep_trk (u8 * s, va_list * args)
324 {
325   cnat_ep_trk_t *ck = va_arg (*args, cnat_ep_trk_t *);
326   u32 indent = va_arg (*args, u32);
327
328   s = format (s, "%U->%U", format_cnat_endpoint, &ck->ct_ep[VLIB_RX],
329               format_cnat_endpoint, &ck->ct_ep[VLIB_TX]);
330   s = format (s, "\n%Ufib-entry:%d", format_white_space, indent, ck->ct_fei);
331   s = format (s, "\n%U%U",
332               format_white_space, indent, format_dpo_id, &ck->ct_dpo, 6);
333
334   return (s);
335 }
336
337 u8 *
338 format_cnat_translation (u8 * s, va_list * args)
339 {
340   cnat_translation_t *ct = va_arg (*args, cnat_translation_t *);
341   cnat_ep_trk_t *ck;
342
343   s = format (s, "[%d] ", ct->index);
344   s = format (s, "%U %U", format_cnat_endpoint, &ct->ct_vip,
345               format_ip_protocol, ct->ct_proto);
346
347   vec_foreach (ck, ct->ct_paths)
348     s = format (s, "\n%U", format_cnat_ep_trk, ck, 2);
349
350   /* If printing a trace, the LB object might be deleted */
351   if (!pool_is_free_index (load_balance_pool, ct->ct_lb.dpoi_index))
352     {
353       s = format (s, "\n via:");
354       s = format (s, "\n%U%U",
355                   format_white_space, 2, format_dpo_id, &ct->ct_lb, 2);
356     }
357
358   return (s);
359 }
360
361 static clib_error_t *
362 cnat_translation_show (vlib_main_t * vm,
363                        unformat_input_t * input, vlib_cli_command_t * cmd)
364 {
365   index_t cti;
366   cnat_translation_t *ct;
367
368   cti = INDEX_INVALID;
369
370   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
371     {
372       if (unformat (input, "%d", &cti))
373         ;
374       else
375         return (clib_error_return (0, "unknown input '%U'",
376                                    format_unformat_error, input));
377     }
378
379   if (INDEX_INVALID == cti)
380     {
381       /* *INDENT-OFF* */
382       pool_foreach_index(cti, cnat_translation_pool,
383       ({
384         ct = pool_elt_at_index (cnat_translation_pool, cti);
385         vlib_cli_output(vm, "%U", format_cnat_translation, ct);
386       }));
387       /* *INDENT-ON* */
388     }
389   else
390     {
391       vlib_cli_output (vm, "Invalid policy ID:%d", cti);
392     }
393
394   return (NULL);
395 }
396
397 int
398 cnat_translation_purge (void)
399 {
400   /* purge all the translations */
401   index_t tri, *trp, *trs = NULL;
402
403   /* *INDENT-OFF* */
404   pool_foreach_index(tri, cnat_translation_pool,
405   ({
406     vec_add1(trs, tri);
407   }));
408   /* *INDENT-ON* */
409
410   vec_foreach (trp, trs) cnat_translation_delete (*trp);
411
412   ASSERT (0 == pool_elts (cnat_translation_pool));
413
414   vec_free (trs);
415
416   return (0);
417 }
418
419 /* *INDENT-OFF* */
420 VLIB_CLI_COMMAND (cnat_translation_show_cmd_node, static) = {
421   .path = "show cnat translation",
422   .function = cnat_translation_show,
423   .short_help = "show cnat translation <VIP>",
424   .is_mp_safe = 1,
425 };
426 /* *INDENT-ON* */
427
428 static fib_node_t *
429 cnat_translation_get_node (fib_node_index_t index)
430 {
431   cnat_translation_t *ct = cnat_translation_get (index);
432   return (&(ct->ct_node));
433 }
434
435 static cnat_translation_t *
436 cnat_translation_get_from_node (fib_node_t * node)
437 {
438   return ((cnat_translation_t *) (((char *) node) -
439                                   STRUCT_OFFSET_OF (cnat_translation_t,
440                                                     ct_node)));
441 }
442
443 static void
444 cnat_translation_last_lock_gone (fib_node_t * node)
445 {
446  /**/}
447
448 /*
449  * A back walk has reached this ABF policy
450  */
451 static fib_node_back_walk_rc_t
452 cnat_translation_back_walk_notify (fib_node_t * node,
453                                    fib_node_back_walk_ctx_t * ctx)
454 {
455   /*
456    * re-stack the fmask on the n-eos of the via
457    */
458   cnat_translation_t *ct = cnat_translation_get_from_node (node);
459
460   cnat_translation_stack (ct);
461
462   return (FIB_NODE_BACK_WALK_CONTINUE);
463 }
464
465 /*
466  * The translation's graph node virtual function table
467  */
468 static const fib_node_vft_t cnat_translation_vft = {
469   .fnv_get = cnat_translation_get_node,
470   .fnv_last_lock = cnat_translation_last_lock_gone,
471   .fnv_back_walk = cnat_translation_back_walk_notify,
472 };
473
474 static clib_error_t *
475 cnat_translation_cli_add_del (vlib_main_t * vm,
476                               unformat_input_t * input,
477                               vlib_cli_command_t * cmd)
478 {
479   u32 del_index = INDEX_INVALID;
480   ip_protocol_t proto = IP_PROTOCOL_TCP;
481   cnat_endpoint_t vip;
482   u8 flags = CNAT_FLAG_EXCLUSIVE;
483   cnat_endpoint_tuple_t tmp, *paths = NULL, *path;
484
485   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
486     {
487       if (unformat (input, "add"))
488         del_index = INDEX_INVALID;
489       else if (unformat (input, "del %d", &del_index))
490         ;
491       else if (unformat (input, "proto %U", unformat_ip_protocol, &proto))
492         ;
493       else if (unformat (input, "vip %U", unformat_cnat_ep, &vip))
494         flags = CNAT_FLAG_EXCLUSIVE;
495       else if (unformat (input, "real %U", unformat_cnat_ep, &vip))
496         flags = 0;
497       else if (unformat (input, "to %U", unformat_cnat_ep_tuple, &tmp))
498         {
499           pool_get (paths, path);
500           clib_memcpy (path, &tmp, sizeof (cnat_endpoint_tuple_t));
501         }
502       else
503         return (clib_error_return (0, "unknown input '%U'",
504                                    format_unformat_error, input));
505     }
506
507   if (INDEX_INVALID == del_index)
508     cnat_translation_update (&vip, proto, paths, flags);
509   else
510     cnat_translation_delete (del_index);
511
512   pool_free (paths);
513   return (NULL);
514 }
515
516 /* *INDENT-OFF* */
517 VLIB_CLI_COMMAND (cnat_translation_cli_add_del_command, static) =
518 {
519   .path = "cnat translation",
520   .short_help = "cnat translation [add|del] proto [TCP|UDP] [vip|real] [ip|sw_if_index [v6]] [port] [to [ip|sw_if_index [v6]] [port]->[ip|sw_if_index [v6]] [port]]",
521   .function = cnat_translation_cli_add_del,
522 };
523 /* *INDENT-ON* */
524
525 static void
526 cnat_if_addr_add_del_translation_cb (addr_resolution_t * ar,
527                                      ip_address_t * address, u8 is_del)
528 {
529   cnat_translation_t *ct;
530   ct = cnat_translation_get (ar->cti);
531   if (!is_del && ct->ct_vip.ce_flags & CNAT_EP_FLAG_RESOLVED)
532     return;
533
534   cnat_remove_translation_from_db (ct->ct_cci, &ct->ct_vip, ct->ct_proto);
535
536   if (is_del)
537     {
538       ct->ct_vip.ce_flags &= ~CNAT_EP_FLAG_RESOLVED;
539       ct->ct_cci = INDEX_INVALID;
540       cnat_client_translation_deleted (ct->ct_cci);
541       /* Are there remaining addresses ? */
542       if (0 == cnat_resolve_addr (ar->sw_if_index, ar->af, address))
543         is_del = 0;
544     }
545
546   if (!is_del)
547     {
548       ct->ct_cci = cnat_client_add (address, ct->flags);
549       cnat_client_translation_added (ct->ct_cci);
550       ip_address_copy (&ct->ct_vip.ce_ip, address);
551       ct->ct_vip.ce_flags |= CNAT_EP_FLAG_RESOLVED;
552     }
553
554   cnat_add_translation_to_db (ct->ct_cci, &ct->ct_vip, ct->ct_proto,
555                               ct->index);
556 }
557
558 static void
559 cnat_if_addr_add_del_backend_cb (addr_resolution_t * ar,
560                                  ip_address_t * address, u8 is_del)
561 {
562   cnat_translation_t *ct;
563   cnat_ep_trk_t *trk;
564   cnat_endpoint_t *ep;
565
566   u8 direction = ar->opaque & 0xf;
567   u32 path_idx = ar->opaque >> 32;
568
569   ct = cnat_translation_get (ar->cti);
570
571   trk = &ct->ct_paths[path_idx];
572   ep = &trk->ct_ep[direction];
573
574   if (!is_del && ep->ce_flags & CNAT_EP_FLAG_RESOLVED)
575     return;
576
577   ASSERT (ep->ce_sw_if_index == ar->sw_if_index);
578
579   if (is_del)
580     {
581       ep->ce_flags &= ~CNAT_EP_FLAG_RESOLVED;
582       /* Are there remaining addresses ? */
583       if (0 == cnat_resolve_addr (ar->sw_if_index, ar->af, address))
584         is_del = 0;
585     }
586
587   if (!is_del)
588     {
589       ip_address_copy (&ep->ce_ip, address);
590       ep->ce_flags |= CNAT_EP_FLAG_RESOLVED;
591     }
592   cnat_tracker_track (ar->cti, trk);
593
594   cnat_translation_stack (ct);
595 }
596
597 static void
598 cnat_if_addr_add_del_snat_cb (addr_resolution_t * ar, ip_address_t * address,
599                               u8 is_del)
600 {
601   cnat_endpoint_t *ep;
602   ep = AF_IP4 == ar->af ? &cnat_main.snat_ip4 : &cnat_main.snat_ip6;
603
604   if (!is_del && ep->ce_flags & CNAT_EP_FLAG_RESOLVED)
605     return;
606
607   if (is_del)
608     {
609       ep->ce_flags &= ~CNAT_EP_FLAG_RESOLVED;
610       /* Are there remaining addresses ? */
611       if (0 == cnat_resolve_addr (ar->sw_if_index, ar->af, address))
612         is_del = 0;
613     }
614
615   if (!is_del)
616     {
617       ip_address_copy (&ep->ce_ip, address);
618       ep->ce_flags |= CNAT_EP_FLAG_RESOLVED;
619     }
620
621 }
622
623 static void
624 cnat_if_addr_add_del_callback (u32 sw_if_index, ip_address_t * address,
625                                u8 is_del)
626 {
627   addr_resolution_t *ar;
628   /* *INDENT-OFF* */
629   pool_foreach (ar, tr_resolutions, ({
630     if (ar->sw_if_index != sw_if_index)
631       continue;
632     if (ar->af != ip_addr_version (address))
633       continue;
634     cnat_if_addr_add_cbs[ar->type] (ar, address, is_del);
635   }));
636   /* *INDENT-ON* */
637 }
638
639 static void
640 cnat_ip6_if_addr_add_del_callback (struct ip6_main_t *im,
641                                    uword opaque, u32 sw_if_index,
642                                    ip6_address_t * address,
643                                    u32 address_length, u32 if_address_index,
644                                    u32 is_del)
645 {
646   ip_address_t addr;
647   ip_address_set (&addr, address, AF_IP6);
648   cnat_if_addr_add_del_callback (sw_if_index, &addr, is_del);
649 }
650
651 static void
652 cnat_ip4_if_addr_add_del_callback (struct ip4_main_t *im,
653                                    uword opaque, u32 sw_if_index,
654                                    ip4_address_t * address,
655                                    u32 address_length, u32 if_address_index,
656                                    u32 is_del)
657 {
658   ip_address_t addr;
659   ip_address_set (&addr, address, AF_IP4);
660   cnat_if_addr_add_del_callback (sw_if_index, &addr, is_del);
661 }
662
663 static clib_error_t *
664 cnat_translation_init (vlib_main_t * vm)
665 {
666   ip4_main_t *i4m = &ip4_main;
667   ip6_main_t *i6m = &ip6_main;
668   cnat_main_t *cm = &cnat_main;
669   cnat_translation_fib_node_type =
670     fib_node_register_new_type (&cnat_translation_vft);
671
672   clib_bihash_init_8_8 (&cnat_translation_db, "CNat translation DB",
673                         cm->translation_hash_buckets,
674                         cm->translation_hash_memory);
675
676   ip4_add_del_interface_address_callback_t cb4;
677   cb4.function = cnat_ip4_if_addr_add_del_callback;
678   vec_add1 (i4m->add_del_interface_address_callbacks, cb4);
679
680   ip6_add_del_interface_address_callback_t cb6;
681   cb6.function = cnat_ip6_if_addr_add_del_callback;
682   vec_add1 (i6m->add_del_interface_address_callbacks, cb6);
683
684   vec_validate (cnat_if_addr_add_cbs, CNAT_ADDR_N_RESOLUTIONS);
685   cnat_if_addr_add_cbs[CNAT_RESOLV_ADDR_BACKEND] =
686     cnat_if_addr_add_del_backend_cb;
687   cnat_if_addr_add_cbs[CNAT_RESOLV_ADDR_SNAT] = cnat_if_addr_add_del_snat_cb;
688   cnat_if_addr_add_cbs[CNAT_RESOLV_ADDR_TRANSLATION] =
689     cnat_if_addr_add_del_translation_cb;
690   return (NULL);
691 }
692
693 VLIB_INIT_FUNCTION (cnat_translation_init);
694
695 /*
696  * fd.io coding-style-patch-verification: ON
697  *
698  * Local Variables:
699  * eval: (c-set-style "gnu")
700  * End:
701  */