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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
22 #include <cnat/cnat_translation.h>
23 #include <cnat/cnat_session.h>
24 #include <cnat/cnat_client.h>
26 cnat_translation_t *cnat_translation_pool;
27 clib_bihash_8_8_t cnat_translation_db;
28 addr_resolution_t *tr_resolutions;
29 cnat_if_addr_add_cb_t *cnat_if_addr_add_cbs;
31 static fib_node_type_t cnat_translation_fib_node_type;
33 vlib_combined_counter_main_t cnat_translation_counters = {
34 .name = "cnat-translation",
35 .stat_segment_name = "/net/cnat-translation",
39 cnat_translation_watch_addr (index_t cti, u64 opaque, cnat_endpoint_t * ep,
40 cnat_addr_resol_type_t type)
42 addr_resolution_t *ar;
44 if (INDEX_INVALID == ep->ce_sw_if_index)
47 pool_get (tr_resolutions, ar);
48 ar->af = ep->ce_ip.version;
49 ar->sw_if_index = ep->ce_sw_if_index;
56 cnat_resolve_ep_tuple (cnat_endpoint_tuple_t * path)
58 cnat_resolve_ep (&path->src_ep);
59 cnat_resolve_ep (&path->dst_ep);
63 cnat_translation_unwatch_addr (u32 cti, cnat_addr_resol_type_t type)
65 /* Delete tr resolution entries matching translation index */
66 addr_resolution_t *ar;
67 index_t *indexes = 0, *ari;
68 pool_foreach (ar, tr_resolutions)
70 if ((cti == INDEX_INVALID || ar->cti == cti) &&
71 (ar->type == type || CNAT_RESOLV_ADDR_ANY == type))
72 vec_add1 (indexes, ar - tr_resolutions);
74 vec_foreach (ari, indexes) pool_put_index (tr_resolutions, *ari);
80 cnat_tracker_release (cnat_ep_trk_t * trk)
82 /* We only track fully resolved endpoints */
83 if (!(trk->ct_flags & CNAT_TRK_ACTIVE))
85 fib_entry_untrack (trk->ct_fei, trk->ct_sibling);
89 cnat_tracker_track (index_t cti, cnat_ep_trk_t * trk)
92 /* We only track fully resolved endpoints */
93 if (trk->ct_ep[VLIB_TX].ce_flags & CNAT_EP_FLAG_RESOLVED &&
94 trk->ct_ep[VLIB_RX].ce_flags & CNAT_EP_FLAG_RESOLVED)
95 trk->ct_flags |= CNAT_TRK_ACTIVE;
98 trk->ct_flags &= ~CNAT_TRK_ACTIVE;
102 ip_address_to_fib_prefix (&trk->ct_ep[VLIB_TX].ce_ip, &pfx);
103 trk->ct_fei = fib_entry_track (CNAT_FIB_TABLE,
105 cnat_translation_fib_node_type,
106 cti, &trk->ct_sibling);
108 fib_entry_contribute_forwarding (trk->ct_fei,
109 fib_forw_chain_type_from_fib_proto
110 (pfx.fp_proto), &trk->ct_dpo);
114 format_cnat_lb_type (u8 *s, va_list *args)
116 cnat_lb_type_t lb_type = va_arg (*args, int);
117 if (CNAT_LB_DEFAULT == lb_type)
118 s = format (s, "default");
119 else if (CNAT_LB_MAGLEV == lb_type)
120 s = format (s, "maglev");
122 s = format (s, "unknown");
127 unformat_cnat_lb_type (unformat_input_t *input, va_list *args)
129 cnat_lb_type_t *a = va_arg (*args, cnat_lb_type_t *);
130 if (unformat (input, "default"))
131 *a = CNAT_LB_DEFAULT;
132 else if (unformat (input, "maglev"))
140 * Add a translation to the bihash
142 * @param cci the ID of the parent client (invalid if vip not resolved)
143 * @param vip the translation endpoint
144 * @param proto the translation proto
145 * @param cti the translation index to be used as value
148 cnat_add_translation_to_db (index_t cci, cnat_endpoint_t * vip,
149 ip_protocol_t proto, index_t cti)
151 clib_bihash_kv_8_8_t bkey;
153 if (INDEX_INVALID == cci)
155 key = proto << 8 | 0x80 | vip->ce_ip.version;
156 key = key << 16 | vip->ce_port;
157 key = key << 32 | (u32) vip->ce_sw_if_index;
162 key = key << 16 | vip->ce_port;
163 key = key << 32 | (u32) cci;
169 clib_bihash_add_del_8_8 (&cnat_translation_db, &bkey, 1);
173 * Remove a translation from the bihash
175 * @param cci the ID of the parent client
176 * @param vip the translation endpoint
177 * @param proto the translation proto
180 cnat_remove_translation_from_db (index_t cci, cnat_endpoint_t * vip,
183 clib_bihash_kv_8_8_t bkey;
185 if (INDEX_INVALID == cci)
187 key = proto << 8 | 0x80 | vip->ce_ip.version;
188 key = key << 16 | vip->ce_port;
189 key = key << 32 | (u32) vip->ce_sw_if_index;
194 key = key << 16 | vip->ce_port;
195 key = key << 32 | (u32) cci;
200 clib_bihash_add_del_8_8 (&cnat_translation_db, &bkey, 0);
209 } cnat_maglev_entry_t;
212 cnat_maglev_entry_compare (void *_a, void *_b)
214 cnat_ep_trk_t *a = ((cnat_maglev_entry_t *) _a)->trk;
215 cnat_ep_trk_t *b = ((cnat_maglev_entry_t *) _b)->trk;
218 ip_address_cmp (&a->ct_ep[VLIB_TX].ce_ip, &b->ct_ep[VLIB_TX].ce_ip)))
220 if ((rv = a->ct_ep[VLIB_TX].ce_port - a->ct_ep[VLIB_TX].ce_port))
223 ip_address_cmp (&a->ct_ep[VLIB_RX].ce_ip, &b->ct_ep[VLIB_RX].ce_ip)))
225 if ((rv = a->ct_ep[VLIB_RX].ce_port - a->ct_ep[VLIB_RX].ce_port))
231 cnat_translation_init_maglev (cnat_translation_t *ct)
233 cnat_maglev_entry_t *backends = NULL, *bk;
234 cnat_main_t *cm = &cnat_main;
239 vec_foreach (trk, ct->ct_active_paths)
241 cnat_maglev_entry_t bk;
244 if (AF_IP4 == ip_addr_version (&trk->ct_ep[VLIB_TX].ce_ip))
247 a = ip_addr_v4 (&trk->ct_ep[VLIB_TX].ce_ip).data_u32;
248 b = (u64) trk->ct_ep[VLIB_TX].ce_port << 16 |
249 (u64) trk->ct_ep[VLIB_RX].ce_port;
250 c = ip_addr_v4 (&trk->ct_ep[VLIB_RX].ce_ip).data_u32;
251 hash_v3_mix32 (a, b, c);
252 hash_v3_finalize32 (a, b, c);
259 a = ip_addr_v6 (&trk->ct_ep[VLIB_TX].ce_ip).as_u64[0] ^
260 ip_addr_v6 (&trk->ct_ep[VLIB_TX].ce_ip).as_u64[1];
261 b = (u64) trk->ct_ep[VLIB_TX].ce_port << 16 |
262 (u64) trk->ct_ep[VLIB_RX].ce_port;
263 c = ip_addr_v6 (&trk->ct_ep[VLIB_RX].ce_ip).as_u64[0] ^
264 ip_addr_v6 (&trk->ct_ep[VLIB_RX].ce_ip).as_u64[1];
265 hash_mix64 (a, b, c);
270 bk.offset = h1 % cm->maglev_len;
271 bk.skip = h2 % (cm->maglev_len - 1) + 1;
274 vec_add1 (backends, bk);
280 vec_sort_with_function (backends, cnat_maglev_entry_compare);
282 /* Don't free if previous vector exists, just zero */
283 vec_validate (ct->lb_maglev, cm->maglev_len);
284 vec_set (ct->lb_maglev, -1);
288 vec_foreach (bk, backends)
291 u32 c = (bk->offset + next * bk->skip) % cm->maglev_len;
292 while (ct->lb_maglev[c] != (u32) -1)
295 c = (bk->offset + next * bk->skip) % cm->maglev_len;
297 ct->lb_maglev[c] = bk->index;
299 if (done == cm->maglev_len)
309 cnat_translation_stack (cnat_translation_t * ct)
311 fib_protocol_t fproto;
317 fproto = ip_address_family_to_fib_proto (ct->ct_vip.ce_ip.version);
318 dproto = fib_proto_to_dpo (fproto);
320 vec_reset_length (ct->ct_active_paths);
322 vec_foreach (trk, ct->ct_paths)
323 if (trk->ct_flags & CNAT_TRK_ACTIVE)
324 vec_add1 (ct->ct_active_paths, *trk);
326 lbi = load_balance_create (vec_len (ct->ct_active_paths),
327 fib_proto_to_dpo (fproto), IP_FLOW_HASH_DEFAULT);
330 vec_foreach (trk, ct->ct_active_paths)
331 load_balance_set_bucket (lbi, ep_idx++, &trk->ct_dpo);
333 if (ep_idx > 0 && CNAT_LB_MAGLEV == ct->lb_type)
334 cnat_translation_init_maglev (ct);
336 dpo_set (&ct->ct_lb, DPO_LOAD_BALANCE, dproto, lbi);
337 dpo_stack (cnat_client_dpo, dproto, &ct->ct_lb, &ct->ct_lb);
338 ct->flags |= CNAT_TRANSLATION_STACKED;
342 cnat_translation_delete (u32 id)
344 cnat_translation_t *ct;
347 if (pool_is_free_index (cnat_translation_pool, id))
348 return (VNET_API_ERROR_NO_SUCH_ENTRY);
350 ct = pool_elt_at_index (cnat_translation_pool, id);
352 dpo_reset (&ct->ct_lb);
354 vec_foreach (trk, ct->ct_active_paths)
355 cnat_tracker_release (trk);
357 cnat_remove_translation_from_db (ct->ct_cci, &ct->ct_vip, ct->ct_proto);
358 cnat_client_translation_deleted (ct->ct_cci);
359 cnat_translation_unwatch_addr (id, CNAT_RESOLV_ADDR_ANY);
360 pool_put (cnat_translation_pool, ct);
366 cnat_translation_update (cnat_endpoint_t *vip, ip_protocol_t proto,
367 cnat_endpoint_tuple_t *paths, u8 flags,
368 cnat_lb_type_t lb_type)
370 cnat_endpoint_tuple_t *path;
371 const cnat_client_t *cc;
372 cnat_translation_t *ct;
377 if (cnat_resolve_ep (vip))
379 /* vip only contains a sw_if_index for now */
380 ct = cnat_find_translation (vip->ce_sw_if_index, vip->ce_port, proto);
385 /* do we know of this ep's vip */
386 cci = cnat_client_add (&vip->ce_ip, flags);
387 cc = cnat_client_get (cci);
389 ct = cnat_find_translation (cc->parent_cci, vip->ce_port, proto);
394 pool_get_zero (cnat_translation_pool, ct);
396 clib_memcpy (&ct->ct_vip, vip, sizeof (*vip));
397 ct->ct_proto = proto;
399 ct->index = ct - cnat_translation_pool;
400 ct->lb_type = lb_type;
402 cnat_add_translation_to_db (cci, vip, proto, ct->index);
403 cnat_client_translation_added (cci);
405 vlib_validate_combined_counter (&cnat_translation_counters, ct->index);
406 vlib_zero_combined_counter (&cnat_translation_counters, ct->index);
410 cnat_translation_unwatch_addr (ct->index, CNAT_RESOLV_ADDR_ANY);
411 cnat_translation_watch_addr (ct->index, 0, vip,
412 CNAT_RESOLV_ADDR_TRANSLATION);
414 vec_foreach (trk, ct->ct_paths)
416 cnat_tracker_release (trk);
419 vec_reset_length (ct->ct_paths);
420 ct->flags &= ~CNAT_TRANSLATION_STACKED;
423 vec_foreach (path, paths)
425 cnat_resolve_ep_tuple (path);
426 cnat_translation_watch_addr (ct->index,
427 path_idx << 32 | VLIB_RX, &path->src_ep,
428 CNAT_RESOLV_ADDR_BACKEND);
429 cnat_translation_watch_addr (ct->index,
430 path_idx << 32 | VLIB_TX, &path->dst_ep,
431 CNAT_RESOLV_ADDR_BACKEND);
434 vec_add2 (ct->ct_paths, trk, 1);
436 clib_memcpy (&trk->ct_ep[VLIB_TX], &path->dst_ep,
437 sizeof (trk->ct_ep[VLIB_TX]));
438 clib_memcpy (&trk->ct_ep[VLIB_RX], &path->src_ep,
439 sizeof (trk->ct_ep[VLIB_RX]));
440 trk->ct_flags = path->ep_flags;
442 cnat_tracker_track (ct->index, trk);
445 cnat_translation_stack (ct);
451 cnat_translation_walk (cnat_translation_walk_cb_t cb, void *ctx)
455 pool_foreach_index (api, cnat_translation_pool)
463 format_cnat_ep_trk (u8 * s, va_list * args)
465 cnat_ep_trk_t *ck = va_arg (*args, cnat_ep_trk_t *);
466 u32 indent = va_arg (*args, u32);
468 s = format (s, "%U->%U", format_cnat_endpoint, &ck->ct_ep[VLIB_RX],
469 format_cnat_endpoint, &ck->ct_ep[VLIB_TX]);
470 s = format (s, "\n%Ufib-entry:%d", format_white_space, indent, ck->ct_fei);
471 s = format (s, "\n%U%U",
472 format_white_space, indent, format_dpo_id, &ck->ct_dpo, 6);
478 format_cnat_translation (u8 * s, va_list * args)
480 cnat_translation_t *ct = va_arg (*args, cnat_translation_t *);
481 cnat_main_t *cm = &cnat_main;
484 s = format (s, "[%d] ", ct->index);
485 s = format (s, "%U %U ", format_cnat_endpoint, &ct->ct_vip,
486 format_ip_protocol, ct->ct_proto);
487 s = format (s, "lb:%U ", format_cnat_lb_type, ct->lb_type);
489 vec_foreach (ck, ct->ct_paths)
490 s = format (s, "\n%U", format_cnat_ep_trk, ck, 2);
492 /* If printing a trace, the LB object might be deleted */
493 if (!pool_is_free_index (load_balance_pool, ct->ct_lb.dpoi_index))
495 s = format (s, "\n via:");
496 s = format (s, "\n%U%U",
497 format_white_space, 2, format_dpo_id, &ct->ct_lb, 2);
501 if (CNAT_LB_MAGLEV == ct->lb_type)
503 s = format (s, "\nmaglev backends map");
504 uword *bitmap = NULL;
505 clib_bitmap_alloc (bitmap, cm->maglev_len);
506 vec_foreach (ck, ct->ct_paths)
508 clib_bitmap_zero (bitmap);
509 for (u32 i = 0; i < vec_len (ct->lb_maglev); i++)
510 if (ct->lb_maglev[i] == bid)
511 clib_bitmap_set (bitmap, i, 1);
512 s = format (s, "\n backend#%d: %U", bid, format_bitmap_hex, bitmap);
516 clib_bitmap_free (bitmap);
522 static clib_error_t *
523 cnat_translation_show (vlib_main_t * vm,
524 unformat_input_t * input, vlib_cli_command_t * cmd)
527 cnat_translation_t *ct;
531 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
533 if (unformat (input, "%d", &cti))
536 return (clib_error_return (0, "unknown input '%U'",
537 format_unformat_error, input));
540 if (INDEX_INVALID == cti)
542 pool_foreach_index (cti, cnat_translation_pool)
544 ct = pool_elt_at_index (cnat_translation_pool, cti);
545 vlib_cli_output(vm, "%U", format_cnat_translation, ct);
550 vlib_cli_output (vm, "Invalid policy ID:%d", cti);
557 cnat_translation_purge (void)
559 /* purge all the translations */
560 index_t tri, *trp, *trs = NULL;
562 pool_foreach_index (tri, cnat_translation_pool)
567 vec_foreach (trp, trs) cnat_translation_delete (*trp);
569 ASSERT (0 == pool_elts (cnat_translation_pool));
576 VLIB_CLI_COMMAND (cnat_translation_show_cmd_node, static) = {
577 .path = "show cnat translation",
578 .function = cnat_translation_show,
579 .short_help = "show cnat translation <VIP>",
584 cnat_translation_get_node (fib_node_index_t index)
586 cnat_translation_t *ct = cnat_translation_get (index);
587 return (&(ct->ct_node));
590 static cnat_translation_t *
591 cnat_translation_get_from_node (fib_node_t * node)
593 return ((cnat_translation_t *) (((char *) node) -
594 STRUCT_OFFSET_OF (cnat_translation_t,
599 cnat_translation_last_lock_gone (fib_node_t * node)
604 * A back walk has reached this ABF policy
606 static fib_node_back_walk_rc_t
607 cnat_translation_back_walk_notify (fib_node_t * node,
608 fib_node_back_walk_ctx_t * ctx)
611 * re-stack the fmask on the n-eos of the via
613 cnat_translation_t *ct = cnat_translation_get_from_node (node);
615 /* If we have more than FIB_PATH_LIST_POPULAR paths
616 * we might get called during path tracking
617 * (cnat_tracker_track) */
618 if (!(ct->flags & CNAT_TRANSLATION_STACKED))
619 return (FIB_NODE_BACK_WALK_CONTINUE);
621 cnat_translation_stack (ct);
623 return (FIB_NODE_BACK_WALK_CONTINUE);
627 * The translation's graph node virtual function table
629 static const fib_node_vft_t cnat_translation_vft = {
630 .fnv_get = cnat_translation_get_node,
631 .fnv_last_lock = cnat_translation_last_lock_gone,
632 .fnv_back_walk = cnat_translation_back_walk_notify,
635 static clib_error_t *
636 cnat_translation_cli_add_del (vlib_main_t * vm,
637 unformat_input_t * input,
638 vlib_cli_command_t * cmd)
640 u32 del_index = INDEX_INVALID;
641 ip_protocol_t proto = IP_PROTOCOL_TCP;
643 u8 flags = CNAT_FLAG_EXCLUSIVE;
644 cnat_endpoint_tuple_t tmp, *paths = NULL, *path;
645 unformat_input_t _line_input, *line_input = &_line_input;
647 cnat_lb_type_t lb_type;
649 /* Get a line of input. */
650 if (!unformat_user (input, unformat_line_input, line_input))
653 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
655 if (unformat (line_input, "add"))
656 del_index = INDEX_INVALID;
657 else if (unformat (line_input, "del %d", &del_index))
660 if (unformat (line_input, "proto %U", unformat_ip_protocol, &proto))
662 else if (unformat (line_input, "vip %U", unformat_cnat_ep, &vip))
663 flags = CNAT_FLAG_EXCLUSIVE;
664 else if (unformat (line_input, "real %U", unformat_cnat_ep, &vip))
666 else if (unformat (line_input, "to %U", unformat_cnat_ep_tuple, &tmp))
668 vec_add2 (paths, path, 1);
669 clib_memcpy (path, &tmp, sizeof (cnat_endpoint_tuple_t));
671 else if (unformat (line_input, "%U", unformat_cnat_lb_type, &lb_type))
675 e = clib_error_return (0, "unknown input '%U'",
676 format_unformat_error, line_input);
681 if (INDEX_INVALID == del_index)
682 cnat_translation_update (&vip, proto, paths, flags, lb_type);
684 cnat_translation_delete (del_index);
688 unformat_free (line_input);
692 VLIB_CLI_COMMAND (cnat_translation_cli_add_del_command, static) =
694 .path = "cnat translation",
695 .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]]",
696 .function = cnat_translation_cli_add_del,
700 cnat_if_addr_add_del_translation_cb (addr_resolution_t * ar,
701 ip_address_t * address, u8 is_del)
703 cnat_translation_t *ct;
704 ct = cnat_translation_get (ar->cti);
705 if (!is_del && ct->ct_vip.ce_flags & CNAT_EP_FLAG_RESOLVED)
708 cnat_remove_translation_from_db (ct->ct_cci, &ct->ct_vip, ct->ct_proto);
712 ct->ct_vip.ce_flags &= ~CNAT_EP_FLAG_RESOLVED;
713 ct->ct_cci = INDEX_INVALID;
714 cnat_client_translation_deleted (ct->ct_cci);
715 /* Are there remaining addresses ? */
716 if (0 == cnat_resolve_addr (ar->sw_if_index, ar->af, address))
722 ct->ct_cci = cnat_client_add (address, ct->flags);
723 cnat_client_translation_added (ct->ct_cci);
724 ip_address_copy (&ct->ct_vip.ce_ip, address);
725 ct->ct_vip.ce_flags |= CNAT_EP_FLAG_RESOLVED;
728 cnat_add_translation_to_db (ct->ct_cci, &ct->ct_vip, ct->ct_proto,
733 cnat_if_addr_add_del_backend_cb (addr_resolution_t * ar,
734 ip_address_t * address, u8 is_del)
736 cnat_translation_t *ct;
740 u8 direction = ar->opaque & 0xf;
741 u32 path_idx = ar->opaque >> 32;
743 ct = cnat_translation_get (ar->cti);
745 trk = &ct->ct_paths[path_idx];
746 ep = &trk->ct_ep[direction];
748 if (!is_del && ep->ce_flags & CNAT_EP_FLAG_RESOLVED)
751 ASSERT (ep->ce_sw_if_index == ar->sw_if_index);
755 ep->ce_flags &= ~CNAT_EP_FLAG_RESOLVED;
756 /* Are there remaining addresses ? */
757 if (0 == cnat_resolve_addr (ar->sw_if_index, ar->af, address))
763 ip_address_copy (&ep->ce_ip, address);
764 ep->ce_flags |= CNAT_EP_FLAG_RESOLVED;
767 ct->flags &= ~CNAT_TRANSLATION_STACKED;
768 cnat_tracker_track (ar->cti, trk);
770 cnat_translation_stack (ct);
771 ct->flags |= CNAT_TRANSLATION_STACKED;
775 cnat_if_addr_add_del_callback (u32 sw_if_index, ip_address_t * address,
778 addr_resolution_t *ar;
779 pool_foreach (ar, tr_resolutions)
781 if (ar->sw_if_index != sw_if_index)
783 if (ar->af != ip_addr_version (address))
785 cnat_if_addr_add_cbs[ar->type](ar, address, is_del);
790 cnat_ip6_if_addr_add_del_callback (struct ip6_main_t *im,
791 uword opaque, u32 sw_if_index,
792 ip6_address_t * address,
793 u32 address_length, u32 if_address_index,
797 ip_address_set (&addr, address, AF_IP6);
798 cnat_if_addr_add_del_callback (sw_if_index, &addr, is_del);
802 cnat_ip4_if_addr_add_del_callback (struct ip4_main_t *im,
803 uword opaque, u32 sw_if_index,
804 ip4_address_t * address,
805 u32 address_length, u32 if_address_index,
809 ip_address_set (&addr, address, AF_IP4);
810 cnat_if_addr_add_del_callback (sw_if_index, &addr, is_del);
814 cnat_translation_register_addr_add_cb (cnat_addr_resol_type_t typ,
815 cnat_if_addr_add_cb_t fn)
817 vec_validate (cnat_if_addr_add_cbs, CNAT_ADDR_N_RESOLUTIONS);
818 cnat_if_addr_add_cbs[typ] = fn;
821 static clib_error_t *
822 cnat_translation_init (vlib_main_t * vm)
824 ip4_main_t *i4m = &ip4_main;
825 ip6_main_t *i6m = &ip6_main;
826 cnat_main_t *cm = &cnat_main;
827 cnat_translation_fib_node_type =
828 fib_node_register_new_type (&cnat_translation_vft);
830 clib_bihash_init_8_8 (&cnat_translation_db, "CNat translation DB",
831 cm->translation_hash_buckets,
832 cm->translation_hash_memory);
834 ip4_add_del_interface_address_callback_t cb4 = { 0 };
835 cb4.function = cnat_ip4_if_addr_add_del_callback;
836 vec_add1 (i4m->add_del_interface_address_callbacks, cb4);
838 ip6_add_del_interface_address_callback_t cb6 = { 0 };
839 cb6.function = cnat_ip6_if_addr_add_del_callback;
840 vec_add1 (i6m->add_del_interface_address_callbacks, cb6);
842 cnat_translation_register_addr_add_cb (CNAT_RESOLV_ADDR_BACKEND,
843 cnat_if_addr_add_del_backend_cb);
844 cnat_translation_register_addr_add_cb (CNAT_RESOLV_ADDR_TRANSLATION,
845 cnat_if_addr_add_del_translation_cb);
850 VLIB_INIT_FUNCTION (cnat_translation_init);
853 * fd.io coding-style-patch-verification: ON
856 * eval: (c-set-style "gnu")