- sm->deterministic = 0;
- sm->out2in_dpo = 0;
-
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (input, "translation hash buckets %d", &translation_buckets))
- ;
- else if (unformat (input, "translation hash memory %d",
- &translation_memory_size));
- else if (unformat (input, "user hash buckets %d", &user_buckets))
- ;
- else if (unformat (input, "user hash memory %d",
- &user_memory_size))
- ;
- else if (unformat (input, "max translations per user %d",
- &max_translations_per_user))
- ;
- else if (unformat (input, "outside VRF id %d",
- &outside_vrf_id))
- ;
- else if (unformat (input, "inside VRF id %d",
- &inside_vrf_id))
- ;
- else if (unformat (input, "static mapping only"))
- {
- static_mapping_only = 1;
- if (unformat (input, "connection tracking"))
- static_mapping_connection_tracking = 1;
- }
- else if (unformat (input, "deterministic"))
- sm->deterministic = 1;
- else if (unformat (input, "nat64 bib hash buckets %d",
- &nat64_bib_buckets))
- ;
- else if (unformat (input, "nat64 bib hash memory %d",
- &nat64_bib_memory_size))
- ;
- else if (unformat (input, "nat64 st hash buckets %d", &nat64_st_buckets))
- ;
- else if (unformat (input, "nat64 st hash memory %d",
- &nat64_st_memory_size))
- ;
- else if (unformat (input, "out2in dpo"))
- sm->out2in_dpo = 1;
- else if (unformat (input, "dslite ce"))
- dslite_set_ce(dm, 1);
- else
- return clib_error_return (0, "unknown input '%U'",
- format_unformat_error, input);
- }
-
- /* for show commands, etc. */
- sm->translation_buckets = translation_buckets;
- sm->translation_memory_size = translation_memory_size;
- /* do not exceed load factor 10 */
- sm->max_translations = 10 * translation_buckets;
- sm->user_buckets = user_buckets;
- sm->user_memory_size = user_memory_size;
- sm->max_translations_per_user = max_translations_per_user;
- sm->outside_vrf_id = outside_vrf_id;
- sm->outside_fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4,
- outside_vrf_id,
- FIB_SOURCE_PLUGIN_HI);
- sm->inside_vrf_id = inside_vrf_id;
- sm->inside_fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4,
- inside_vrf_id,
- FIB_SOURCE_PLUGIN_HI);
- sm->static_mapping_only = static_mapping_only;
- sm->static_mapping_connection_tracking = static_mapping_connection_tracking;
-
- nat64_set_hash(nat64_bib_buckets, nat64_bib_memory_size, nat64_st_buckets,
- nat64_st_memory_size);
-
- if (sm->deterministic)
- {
- sm->in2out_node_index = snat_det_in2out_node.index;
- sm->in2out_output_node_index = ~0;
- sm->out2in_node_index = snat_det_out2in_node.index;
- sm->icmp_match_in2out_cb = icmp_match_in2out_det;
- sm->icmp_match_out2in_cb = icmp_match_out2in_det;
- }
- else
- {
- sm->worker_in2out_cb = snat_get_worker_in2out_cb;
- sm->worker_out2in_cb = snat_get_worker_out2in_cb;
- sm->in2out_node_index = snat_in2out_node.index;
- sm->in2out_output_node_index = snat_in2out_output_node.index;
- sm->out2in_node_index = snat_out2in_node.index;
- if (!static_mapping_only ||
- (static_mapping_only && static_mapping_connection_tracking))
- {
- sm->icmp_match_in2out_cb = icmp_match_in2out_slow;
- sm->icmp_match_out2in_cb = icmp_match_out2in_slow;
-
- vec_foreach (tsm, sm->per_thread_data)
- {
- clib_bihash_init_8_8 (&tsm->in2out, "in2out", translation_buckets,
- translation_memory_size);
-
- clib_bihash_init_8_8 (&tsm->out2in, "out2in", translation_buckets,
- translation_memory_size);
-
- clib_bihash_init_8_8 (&tsm->user_hash, "users", user_buckets,
- user_memory_size);
- }
-
- clib_bihash_init_16_8 (&sm->in2out_ed, "in2out-ed",
- translation_buckets, translation_memory_size);
-
- clib_bihash_init_16_8 (&sm->out2in_ed, "out2in-ed",
- translation_buckets, translation_memory_size);
- }
- else
- {
- sm->icmp_match_in2out_cb = icmp_match_in2out_fast;
- sm->icmp_match_out2in_cb = icmp_match_out2in_fast;
- }
- clib_bihash_init_8_8 (&sm->static_mapping_by_local,
- "static_mapping_by_local", static_mapping_buckets,
- static_mapping_memory_size);
-
- clib_bihash_init_8_8 (&sm->static_mapping_by_external,
- "static_mapping_by_external", static_mapping_buckets,
- static_mapping_memory_size);
- }
-
- return 0;
-}
-
-VLIB_CONFIG_FUNCTION (snat_config, "nat");
-
-u8 * format_snat_session_state (u8 * s, va_list * args)
-{
- u32 i = va_arg (*args, u32);
- u8 *t = 0;
-
- switch (i)
- {
-#define _(v, N, str) case SNAT_SESSION_##N: t = (u8 *) str; break;
- foreach_snat_session_state
-#undef _
- default:
- t = format (t, "unknown");
- }
- s = format (s, "%s", t);
- return s;
-}
-
-u8 * format_snat_key (u8 * s, va_list * args)
-{
- snat_session_key_t * key = va_arg (*args, snat_session_key_t *);
-
- s = format (s, "%U proto %U port %d fib %d",
- format_ip4_address, &key->addr,
- format_snat_protocol, key->protocol,
- clib_net_to_host_u16 (key->port), key->fib_index);
- return s;
-}
-
-u8 * format_snat_session (u8 * s, va_list * args)
-{
- snat_main_t * sm __attribute__((unused)) = va_arg (*args, snat_main_t *);
- snat_session_t * sess = va_arg (*args, snat_session_t *);
-
- if (snat_is_unk_proto_session (sess))
- {
- s = format (s, " i2o %U proto %u fib %u\n",
- format_ip4_address, &sess->in2out.addr,
- clib_net_to_host_u16 (sess->in2out.port),
- sess->in2out.fib_index);
- s = format (s, " o2i %U proto %u fib %u\n",
- format_ip4_address, &sess->out2in.addr,
- clib_net_to_host_u16 (sess->out2in.port),
- sess->out2in.fib_index);
- }
- else
- {
- s = format (s, " i2o %U\n", format_snat_key, &sess->in2out);
- s = format (s, " o2i %U\n", format_snat_key, &sess->out2in);
- }
- if (is_twice_nat_session (sess))
- {
- s = format (s, " external host o2i %U:%d i2o %U:%d\n",
- format_ip4_address, &sess->ext_host_addr,
- clib_net_to_host_u16 (sess->ext_host_port),
- format_ip4_address, &sess->ext_host_nat_addr,
- clib_net_to_host_u16 (sess->ext_host_nat_port));
- }
- else
- {
- if (sess->ext_host_addr.as_u32)
- s = format (s, " external host %U\n",
- format_ip4_address, &sess->ext_host_addr);
- }
- s = format (s, " last heard %.2f\n", sess->last_heard);
- s = format (s, " total pkts %d, total bytes %lld\n",
- sess->total_pkts, sess->total_bytes);
- if (snat_is_session_static (sess))
- s = format (s, " static translation\n");