X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Fnat%2Fnat.c;fp=src%2Fplugins%2Fsnat%2Fsnat.c;h=ac39be956a80aba9fde6b92f9a4bf194c44272a4;hb=2ba92e32e0197f676dd905e5edcb4ff3e1bec241;hp=315cec8a65bbef38af05daf657c313abe13f6cda;hpb=cfc997ef3da9f406afe5caad99fc98a53aab7a77;p=vpp.git diff --git a/src/plugins/snat/snat.c b/src/plugins/nat/nat.c similarity index 94% rename from src/plugins/snat/snat.c rename to src/plugins/nat/nat.c index 315cec8a65b..ac39be956a8 100644 --- a/src/plugins/snat/snat.c +++ b/src/plugins/nat/nat.c @@ -19,10 +19,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include @@ -34,64 +34,64 @@ snat_main_t snat_main; /* Hook up input features */ VNET_FEATURE_INIT (ip4_snat_in2out, static) = { .arc_name = "ip4-unicast", - .node_name = "snat-in2out", - .runs_before = VNET_FEATURES ("snat-out2in"), + .node_name = "nat44-in2out", + .runs_before = VNET_FEATURES ("nat44-out2in"), }; VNET_FEATURE_INIT (ip4_snat_out2in, static) = { .arc_name = "ip4-unicast", - .node_name = "snat-out2in", + .node_name = "nat44-out2in", .runs_before = VNET_FEATURES ("ip4-lookup"), }; VNET_FEATURE_INIT (ip4_snat_det_in2out, static) = { .arc_name = "ip4-unicast", - .node_name = "snat-det-in2out", - .runs_before = VNET_FEATURES ("snat-det-out2in"), + .node_name = "nat44-det-in2out", + .runs_before = VNET_FEATURES ("nat44-det-out2in"), }; VNET_FEATURE_INIT (ip4_snat_det_out2in, static) = { .arc_name = "ip4-unicast", - .node_name = "snat-det-out2in", + .node_name = "nat44-det-out2in", .runs_before = VNET_FEATURES ("ip4-lookup"), }; VNET_FEATURE_INIT (ip4_snat_in2out_worker_handoff, static) = { .arc_name = "ip4-unicast", - .node_name = "snat-in2out-worker-handoff", - .runs_before = VNET_FEATURES ("snat-out2in-worker-handoff"), + .node_name = "nat44-in2out-worker-handoff", + .runs_before = VNET_FEATURES ("nat44-out2in-worker-handoff"), }; VNET_FEATURE_INIT (ip4_snat_out2in_worker_handoff, static) = { .arc_name = "ip4-unicast", - .node_name = "snat-out2in-worker-handoff", + .node_name = "nat44-out2in-worker-handoff", .runs_before = VNET_FEATURES ("ip4-lookup"), }; VNET_FEATURE_INIT (ip4_snat_in2out_fast, static) = { .arc_name = "ip4-unicast", - .node_name = "snat-in2out-fast", - .runs_before = VNET_FEATURES ("snat-out2in-fast"), + .node_name = "nat44-in2out-fast", + .runs_before = VNET_FEATURES ("nat44-out2in-fast"), }; VNET_FEATURE_INIT (ip4_snat_out2in_fast, static) = { .arc_name = "ip4-unicast", - .node_name = "snat-out2in-fast", + .node_name = "nat44-out2in-fast", .runs_before = VNET_FEATURES ("ip4-lookup"), }; VNET_FEATURE_INIT (ip4_snat_hairpin_dst, static) = { .arc_name = "ip4-unicast", - .node_name = "snat-hairpin-dst", + .node_name = "nat44-hairpin-dst", .runs_before = VNET_FEATURES ("ip4-lookup"), }; /* Hook up output features */ VNET_FEATURE_INIT (ip4_snat_in2out_output, static) = { .arc_name = "ip4-output", - .node_name = "snat-in2out-output", + .node_name = "nat44-in2out-output", .runs_before = VNET_FEATURES ("interface-output"), }; VNET_FEATURE_INIT (ip4_snat_in2out_output_worker_handoff, static) = { .arc_name = "ip4-output", - .node_name = "snat-in2out-output-worker-handoff", + .node_name = "nat44-in2out-output-worker-handoff", .runs_before = VNET_FEATURES ("interface-output"), }; VNET_FEATURE_INIT (ip4_snat_hairpin_src, static) = { .arc_name = "ip4-output", - .node_name = "snat-hairpin-src", + .node_name = "nat44-hairpin-src", .runs_before = VNET_FEATURES ("interface-output"), }; @@ -210,20 +210,20 @@ static int is_snat_address_used_in_static_mapping (snat_main_t *sm, void increment_v4_address (ip4_address_t * a) { u32 v; - + v = clib_net_to_host_u32(a->as_u32) + 1; a->as_u32 = clib_host_to_net_u32(v); } -static void -snat_add_static_mapping_when_resolved (snat_main_t * sm, - ip4_address_t l_addr, - u16 l_port, - u32 sw_if_index, - u16 e_port, +static void +snat_add_static_mapping_when_resolved (snat_main_t * sm, + ip4_address_t l_addr, + u16 l_port, + u32 sw_if_index, + u16 e_port, u32 vrf_id, snat_protocol_t proto, - int addr_only, + int addr_only, int is_add) { snat_static_map_resolve_t *rp; @@ -275,13 +275,13 @@ int snat_add_static_mapping(ip4_address_t l_addr, ip4_address_t e_addr, ip4_address_t * first_int_addr; /* Might be already set... */ - first_int_addr = ip4_interface_first_address + first_int_addr = ip4_interface_first_address (sm->ip4_main, sw_if_index, 0 /* just want the address*/); /* DHCP resolution required? */ if (first_int_addr == 0) { - snat_add_static_mapping_when_resolved + snat_add_static_mapping_when_resolved (sm, l_addr, l_port, sw_if_index, e_port, vrf_id, proto, addr_only, is_add); return 0; @@ -736,15 +736,15 @@ int snat_interface_add_del (u32 sw_if_index, u8 is_inside, int is_del) snat_det_map_t * dm; if (sm->static_mapping_only && !(sm->static_mapping_connection_tracking)) - feature_name = is_inside ? "snat-in2out-fast" : "snat-out2in-fast"; + feature_name = is_inside ? "nat44-in2out-fast" : "nat44-out2in-fast"; else { if (sm->num_workers > 1 && !sm->deterministic) - feature_name = is_inside ? "snat-in2out-worker-handoff" : "snat-out2in-worker-handoff"; + feature_name = is_inside ? "nat44-in2out-worker-handoff" : "nat44-out2in-worker-handoff"; else if (sm->deterministic) - feature_name = is_inside ? "snat-det-in2out" : "snat-det-out2in"; + feature_name = is_inside ? "nat44-det-in2out" : "nat44-det-out2in"; else - feature_name = is_inside ? "snat-in2out" : "snat-out2in"; + feature_name = is_inside ? "nat44-in2out" : "nat44-out2in"; } vnet_feature_enable_disable ("ip4-unicast", feature_name, sw_if_index, @@ -815,26 +815,26 @@ int snat_interface_add_del_output_feature (u32 sw_if_index, if (is_inside) { - vnet_feature_enable_disable ("ip4-unicast", "snat-hairpin-dst", + vnet_feature_enable_disable ("ip4-unicast", "nat44-hairpin-dst", sw_if_index, !is_del, 0, 0); - vnet_feature_enable_disable ("ip4-output", "snat-hairpin-src", + vnet_feature_enable_disable ("ip4-output", "nat44-hairpin-src", sw_if_index, !is_del, 0, 0); goto fq; } if (sm->num_workers > 1) { - vnet_feature_enable_disable ("ip4-unicast", "snat-out2in-worker-handoff", + vnet_feature_enable_disable ("ip4-unicast", "nat44-out2in-worker-handoff", sw_if_index, !is_del, 0, 0); vnet_feature_enable_disable ("ip4-output", - "snat-in2out-output-worker-handoff", + "nat44-in2out-output-worker-handoff", sw_if_index, !is_del, 0, 0); } else { - vnet_feature_enable_disable ("ip4-unicast", "snat-out2in", sw_if_index, + vnet_feature_enable_disable ("ip4-unicast", "nat44-out2in", sw_if_index, !is_del, 0, 0); - vnet_feature_enable_disable ("ip4-output", "snat-in2out-output", + vnet_feature_enable_disable ("ip4-output", "nat44-in2out-output", sw_if_index, !is_del, 0, 0); } @@ -997,13 +997,13 @@ static clib_error_t * snat_init (vlib_main_t * vm) VLIB_INIT_FUNCTION (snat_init); -void snat_free_outside_address_and_port (snat_main_t * sm, - snat_session_key_t * k, +void snat_free_outside_address_and_port (snat_main_t * sm, + snat_session_key_t * k, u32 address_index) { snat_address_t *a; u16 port_host_byte_order = clib_net_to_host_u16 (k->port); - + ASSERT (address_index < vec_len (sm->addresses)); a = sm->addresses + address_index; @@ -1024,12 +1024,12 @@ void snat_free_outside_address_and_port (snat_main_t * sm, clib_warning("unknown_protocol"); return; } -} +} /** - * @brief Match SNAT static mapping. + * @brief Match NAT44 static mapping. * - * @param sm SNAT main. + * @param sm NAT main. * @param match Address and port to match. * @param mapping External or local address and port of the matched mapping. * @param by_external If 0 match by local address otherwise match by external @@ -1199,7 +1199,7 @@ add_address_command_fn (vlib_main_t * vm, start_host_order = clib_host_to_net_u32 (start_addr.as_u32); end_host_order = clib_host_to_net_u32 (end_addr.as_u32); - + if (end_host_order < start_host_order) { error = clib_error_return (0, "end address less than start address"); @@ -1213,7 +1213,7 @@ add_address_command_fn (vlib_main_t * vm, format_ip4_address, &start_addr, format_ip4_address, &end_addr, count); - + this_addr = start_addr; for (i = 0; i < count; i++) @@ -1245,8 +1245,8 @@ done: } VLIB_CLI_COMMAND (add_address_command, static) = { - .path = "snat add address", - .short_help = "snat add addresses [- ] " + .path = "nat44 add address", + .short_help = "nat44 add addresses [- ] " "[tenant-vrf ] [del]", .function = add_address_command_fn, }; @@ -1365,9 +1365,9 @@ done: } VLIB_CLI_COMMAND (set_interface_snat_command, static) = { - .path = "set interface snat", + .path = "set interface nat44", .function = snat_feature_command_fn, - .short_help = "set interface snat in out [output-feature] " + .short_help = "set interface nat44 in out [output-feature] " "[del]", }; @@ -1503,18 +1503,18 @@ done: * to to the local network host. * To create static mapping between local host address 10.0.0.3 port 6303 and * external address 4.4.4.4 port 3606 for TCP protocol use: - * vpp# snat add static mapping local tcp 10.0.0.3 6303 external 4.4.4.4 3606 - * If not runnig "static mapping only" S-NAT plugin mode use before: - * vpp# snat add address 4.4.4.4 + * vpp# nat44 add static mapping local tcp 10.0.0.3 6303 external 4.4.4.4 3606 + * If not runnig "static mapping only" NAT plugin mode use before: + * vpp# nat44 add address 4.4.4.4 * To create static mapping between local and external address use: - * vpp# snat add static mapping local 10.0.0.3 external 4.4.4.4 + * vpp# nat44 add static mapping local 10.0.0.3 external 4.4.4.4 * @cliexend ?*/ VLIB_CLI_COMMAND (add_static_mapping_command, static) = { - .path = "snat add static mapping", + .path = "nat44 add static mapping", .function = add_static_mapping_command_fn, .short_help = - "snat add static mapping local tcp|udp|icmp [] external [] [vrf ] [del]", + "nat44 add static mapping local tcp|udp|icmp [] external [] [vrf ] [del]", }; static clib_error_t * @@ -1575,15 +1575,15 @@ done: /*? * @cliexpar * @cliexstart{set snat workers} - * Set SNAT workers if 2 or more workers available, use: + * Set NAT workers if 2 or more workers available, use: * vpp# set snat workers 0-2,5 * @cliexend ?*/ VLIB_CLI_COMMAND (set_workers_command, static) = { - .path = "set snat workers", + .path = "set nat workers", .function = set_workers_command_fn, .short_help = - "set snat workers ", + "set nat workers ", }; static clib_error_t * @@ -1635,16 +1635,16 @@ done: /*? * @cliexpar * @cliexstart{snat ipfix logging} - * To enable SNAT IPFIX logging use: - * vpp# snat ipfix logging + * To enable NAT IPFIX logging use: + * vpp# nat ipfix logging * To set IPFIX exporter use: * vpp# set ipfix exporter collector 10.10.10.3 src 10.10.10.1 * @cliexend ?*/ VLIB_CLI_COMMAND (snat_ipfix_logging_enable_disable_command, static) = { - .path = "snat ipfix logging", + .path = "nat ipfix logging", .function = snat_ipfix_logging_enable_disable_command_fn, - .short_help = "snat ipfix logging [domain ] [src-port ] [disable]", + .short_help = "nat ipfix logging [domain ] [src-port ] [disable]", }; static u32 @@ -1862,7 +1862,7 @@ snat_config (vlib_main_t * vm, unformat_input_t * input) return 0; } -VLIB_CONFIG_FUNCTION (snat_config, "snat"); +VLIB_CONFIG_FUNCTION (snat_config, "nat"); u8 * format_snat_session_state (u8 * s, va_list * args) { @@ -2067,18 +2067,18 @@ show_snat_command_fn (vlib_main_t * vm, if (sm->static_mapping_only) { if (sm->static_mapping_connection_tracking) - vlib_cli_output (vm, "SNAT mode: static mapping only connection " + vlib_cli_output (vm, "NAT plugin mode: static mapping only connection " "tracking"); else - vlib_cli_output (vm, "SNAT mode: static mapping only"); + vlib_cli_output (vm, "NAT plugin mode: static mapping only"); } else if (sm->deterministic) { - vlib_cli_output (vm, "SNAT mode: deterministic mapping"); + vlib_cli_output (vm, "NAT plugin mode: deterministic mapping"); } else { - vlib_cli_output (vm, "SNAT mode: dynamic translations enabled"); + vlib_cli_output (vm, "NAT plugin mode: dynamic translations enabled"); } if (verbose > 0) @@ -2100,7 +2100,7 @@ show_snat_command_fn (vlib_main_t * vm, if (vec_len (sm->auto_add_sw_if_indices)) { - vlib_cli_output (vm, "SNAT pool addresses interfaces:"); + vlib_cli_output (vm, "NAT44 pool addresses interfaces:"); vec_foreach (sw_if_index, sm->auto_add_sw_if_indices) { vlib_cli_output (vm, "%U", format_vnet_sw_interface_name, vnm, @@ -2253,8 +2253,8 @@ show_snat_command_fn (vlib_main_t * vm, } VLIB_CLI_COMMAND (show_snat_command, static) = { - .path = "show snat", - .short_help = "show snat", + .path = "show nat44", + .short_help = "show nat44", .function = show_snat_command_fn, }; @@ -2372,7 +2372,7 @@ int snat_add_interface_address (snat_main_t *sm, u32 sw_if_index, int is_del) return 0; } } - + if (is_del) return VNET_API_ERROR_NO_SUCH_ENTRY; @@ -2437,8 +2437,8 @@ done: } VLIB_CLI_COMMAND (snat_add_interface_address_command, static) = { - .path = "snat add interface address", - .short_help = "snat add interface address [del]", + .path = "nat44 add interface address", + .short_help = "nat44 add interface address [del]", .function = snat_add_interface_address_command_fn, }; @@ -2499,12 +2499,12 @@ done: * CGN deployments. * To create deterministic mapping between inside network 10.0.0.0/18 and * outside network 1.1.1.0/30 use: - * # vpp# snat deterministic add in 10.0.0.0/18 out 1.1.1.0/30 + * # vpp# nat44 deterministic add in 10.0.0.0/18 out 1.1.1.0/30 * @cliexend ?*/ VLIB_CLI_COMMAND (snat_det_map_command, static) = { - .path = "snat deterministic add", - .short_help = "snat deterministic add in / out / [del]", + .path = "nat44 deterministic add", + .short_help = "nat44 deterministic add in / out / [del]", .function = snat_det_map_command_fn, }; @@ -2560,13 +2560,13 @@ done: * Return outside address and port range from inside address for deterministic * NAT. * To obtain outside address and port of inside host use: - * vpp# snat deterministic forward 10.0.0.2 + * vpp# nat44 deterministic forward 10.0.0.2 * 1.1.1.0:<1054-1068> * @cliexend ?*/ VLIB_CLI_COMMAND (snat_det_forward_command, static) = { - .path = "snat deterministic forward", - .short_help = "snat deterministic forward ", + .path = "nat44 deterministic forward", + .short_help = "nat44 deterministic forward ", .function = snat_det_forward_command_fn, }; @@ -2625,13 +2625,13 @@ done: * @cliexstart{snat deterministic reverse} * Return inside address from outside address and port for deterministic NAT. * To obtain inside host address from outside address and port use: - * #vpp snat deterministic reverse 1.1.1.1:1276 + * #vpp nat44 deterministic reverse 1.1.1.1:1276 * 10.0.16.16 * @cliexend ?*/ VLIB_CLI_COMMAND (snat_det_reverse_command, static) = { - .path = "snat deterministic reverse", - .short_help = "snat deterministic reverse :", + .path = "nat44 deterministic reverse", + .short_help = "nat44 deterministic reverse :", .function = snat_det_reverse_command_fn, }; @@ -2687,17 +2687,17 @@ done: * @cliexpar * @cliexstart{set snat deterministic timeout} * Set values of timeouts for deterministic NAT (in seconds), use: - * vpp# set snat deterministic timeout udp 120 tcp-established 7500 + * vpp# set nat44 deterministic timeout udp 120 tcp-established 7500 * tcp-transitory 250 icmp 90 * To reset default values use: - * vpp# set snat deterministic timeout reset + * vpp# set nat44 deterministic timeout reset * @cliexend ?*/ VLIB_CLI_COMMAND (set_timeout_command, static) = { - .path = "set snat deterministic timeout", + .path = "set nat44 deterministic timeout", .function = set_timeout_command_fn, .short_help = - "set snat deterministic timeout [udp | tcp-established " + "set nat44 deterministic timeout [udp | tcp-established " "tcp-transitory | icmp | reset]", }; @@ -2762,12 +2762,12 @@ done: * @cliexstart{snat deterministic close session out} * Close session using outside ip address and port * and external ip address and port, use: - * vpp# snat deterministic close session out 1.1.1.1:1276 2.2.2.2:2387 + * vpp# nat44 deterministic close session out 1.1.1.1:1276 2.2.2.2:2387 * @cliexend ?*/ VLIB_CLI_COMMAND (snat_det_close_sesion_out_command, static) = { - .path = "snat deterministic close session out", - .short_help = "snat deterministic close session out " + .path = "nat44 deterministic close session out", + .short_help = "nat44 deterministic close session out " ": :", .function = snat_det_close_session_out_fn, }; @@ -2831,12 +2831,12 @@ done: * @cliexstart{snat deterministic close_session_in} * Close session using inside ip address and port * and external ip address and port, use: - * vpp# snat deterministic close session in 3.3.3.3:3487 2.2.2.2:2387 + * vpp# nat44 deterministic close session in 3.3.3.3:3487 2.2.2.2:2387 * @cliexend ?*/ VLIB_CLI_COMMAND (snat_det_close_session_in_command, static) = { - .path = "snat deterministic close session in", - .short_help = "snat deterministic close session in " + .path = "nat44 deterministic close session in", + .short_help = "nat44 deterministic close session in " ": :", .function = snat_det_close_session_in_fn, };