25 #define NAT44_EI_EXPECTED_ARGUMENT "expected required argument(s)" 32 nat44_ei_session_t *sess = va_arg (*args, nat44_ei_session_t *);
38 &sess->in2out.addr, sess->in2out.port, sess->in2out.fib_index);
41 &sess->out2in.addr, sess->out2in.port, sess->out2in.fib_index);
47 clib_net_to_host_u16 (sess->in2out.port),
48 sess->in2out.fib_index);
51 clib_net_to_host_u16 (sess->out2in.port),
52 sess->out2in.fib_index);
56 s =
format (s,
" last heard %.2f\n", sess->last_heard);
57 s =
format (s,
" total pkts %d, total bytes %lld\n", sess->total_pkts,
60 s =
format (s,
" static translation\n");
62 s =
format (s,
" dynamic translation\n");
72 nat44_ei_user_t *u = va_arg (*args, nat44_ei_user_t *);
73 int verbose = va_arg (*args,
int);
75 u32 elt_index, head_index;
77 nat44_ei_session_t *sess;
79 s =
format (s,
"%U: %d dynamic translations, %d static translations\n",
85 if (u->nsessions || u->nstaticsessions)
87 head_index = u->sessions_per_user_list_head_index;
90 elt_index = head->
next;
92 session_index = elt->
value;
94 while (session_index != ~0)
100 elt_index = elt->
next;
102 session_index = elt->
value;
141 s =
format (s,
"%U local %U:%d external %U:%d vrf %d",
180 u8 enable_set = 0, enable = 0, mode_set = 0;
187 if (!mode_set &&
unformat (line_input,
"static-mapping-only"))
191 if (
unformat (line_input,
"connection-tracking"))
196 else if (!mode_set &&
unformat (line_input,
"out2in-dpo"))
211 else if (!enable_set)
214 if (
unformat (line_input,
"disable"))
216 else if (
unformat (line_input,
"enable"))
297 case VNET_API_ERROR_INVALID_WORKER:
300 case VNET_API_ERROR_FEATURE_DISABLED:
347 if (!
unformat (line_input,
"%d", &log_level))
375 u8 enable_set = 0, enable = 0;
382 if (
unformat (line_input,
"domain %d", &domain_id))
386 else if (
unformat (line_input,
"disable"))
388 else if (!enable_set)
391 if (
unformat (line_input,
"disable"))
393 else if (
unformat (line_input,
"enable"))
433 else if (
unformat (input,
"verbose"))
464 u32 psid, psid_offset, psid_length, port_start, port_end;
471 if (
unformat (line_input,
"default"))
474 "map-e psid %d psid-offset %d psid-len %d", &psid,
475 &psid_offset, &psid_length))
478 else if (
unformat (line_input,
"port-range %d - %d", &port_start,
481 if (port_end <= port_start)
484 0,
"The end-port must be greater than start-port");
512 case NAT44_EI_ADDR_AND_PORT_ALLOC_ALG_##N: \ 517 default : s =
format (s,
"unknown");
536 case NAT44_EI_ADDR_AND_PORT_ALLOC_ALG_MAPE:
540 case NAT44_EI_ADDR_AND_PORT_ALLOC_ALG_RANGE:
565 if (
unformat (line_input,
"disable"))
567 else if (
unformat (line_input,
"%d", &mss))
603 u32 port, session_refresh_interval = 10;
614 else if (
unformat (line_input,
"refresh-interval %u",
615 &session_refresh_interval))
652 else if (
unformat (line_input,
"path-mtu %u", &path_mtu))
678 u32 path_mtu, session_refresh_interval, resync_ack_missed;
697 session_refresh_interval);
706 vlib_cli_output (vm,
" completed (%d ACK missed)\n", resync_ack_missed);
738 u32 start_host_order, end_host_order;
753 else if (
unformat (line_input,
"tenant-vrf %u", &vrf_id))
757 else if (
unformat (line_input,
"del"))
773 start_host_order = clib_host_to_net_u32 (start_addr.
as_u32);
774 end_host_order = clib_host_to_net_u32 (end_addr.
as_u32);
776 if (end_host_order < start_host_order)
782 count = (end_host_order - start_host_order) + 1;
790 for (i = 0; i <
count; i++)
799 case VNET_API_ERROR_VALUE_EXIST:
802 case VNET_API_ERROR_NO_SUCH_ENTRY:
805 case VNET_API_ERROR_UNSPECIFIED:
808 case VNET_API_ERROR_FEATURE_DISABLED:
839 vm,
" tenant VRF: %u",
843 #define _(N, i, n, s) \ 844 vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s); 859 u32 *inside_sw_if_indices = 0;
860 u32 *outside_sw_if_indices = 0;
861 u8 is_output_feature = 0;
874 vec_add1 (inside_sw_if_indices, sw_if_index);
877 vec_add1 (outside_sw_if_indices, sw_if_index);
878 else if (
unformat (line_input,
"output-feature"))
879 is_output_feature = 1;
880 else if (
unformat (line_input,
"del"))
890 if (
vec_len (inside_sw_if_indices))
892 for (i = 0; i <
vec_len (inside_sw_if_indices); i++)
894 sw_if_index = inside_sw_if_indices[
i];
895 if (is_output_feature)
901 0,
"%s %U failed", is_del ?
"del" :
"add",
911 0,
"%s %U failed", is_del ?
"del" :
"add",
919 if (
vec_len (outside_sw_if_indices))
921 for (i = 0; i <
vec_len (outside_sw_if_indices); i++)
923 sw_if_index = outside_sw_if_indices[
i];
924 if (is_output_feature)
930 0,
"%s %U failed", is_del ?
"del" :
"add",
940 0,
"%s %U failed", is_del ?
"del" :
"add",
996 int is_add = 1, addr_only = 1,
rv;
1019 else if (
unformat (line_input,
"external %U %u",
1030 else if (
unformat (line_input,
"del"))
1045 0,
"address only mapping doesn't support protocol");
1049 else if (!proto_set)
1056 l_addr, e_addr, clib_host_to_net_u16 (l_port),
1057 clib_host_to_net_u16 (e_port), proto, sw_if_index,
vrf_id, addr_only, 0, 0,
1062 case VNET_API_ERROR_INVALID_VALUE:
1065 case VNET_API_ERROR_NO_SUCH_ENTRY:
1071 case VNET_API_ERROR_NO_SUCH_FIB:
1074 case VNET_API_ERROR_VALUE_EXIST:
1077 case VNET_API_ERROR_FEATURE_DISABLED:
1121 else if (
unformat (line_input,
"del"))
1132 addr, addr, clib_host_to_net_u16 (port), clib_host_to_net_u16 (port),
1133 proto, sw_if_index,
vrf_id, addr_only, 1, 0, is_add);
1137 case VNET_API_ERROR_INVALID_VALUE:
1140 case VNET_API_ERROR_NO_SUCH_ENTRY:
1146 case VNET_API_ERROR_NO_SUCH_FIB:
1149 case VNET_API_ERROR_VALUE_EXIST:
1202 else if (
unformat (line_input,
"del"))
1221 0,
"nat44_ei_add_interface_address returned %d", rv);
1267 if (
unformat (line_input,
"detail"))
1285 vlib_cli_output (vm,
"-------- thread %d %s: %d sessions --------\n", i,
1314 else if (
unformat (line_input,
"fib %u", &fib_index))
1366 else if (
unformat (line_input,
"in"))
1371 else if (
unformat (line_input,
"out"))
1413 u8 enable_set = 0, enable = 0;
1423 if (
unformat (line_input,
"disable"))
1425 else if (
unformat (line_input,
"enable"))
1461 else if (
unformat (line_input,
"tcp-established %u",
1464 else if (
unformat (line_input,
"tcp-transitory %u",
1469 else if (
unformat (line_input,
"reset"))
1521 "nat44 ei <enable [sessions <max-number>] [users <max-number>] " 1522 "[static-mappig-only [connection-tracking]|out2in-dpo] [inside-vrf " 1523 "<vrf-id>] [outside-vrf <vrf-id>] [user-sessions <max-number>]>|disable",
1535 .path =
"set nat44 ei workers",
1537 .short_help =
"set nat44 ei workers <workers-list>",
1551 .path =
"show nat44 ei workers",
1552 .short_help =
"show nat44 ei workers",
1567 .path =
"set nat44 ei timeout",
1569 .short_help =
"set nat44 ei timeout [udp <sec> | tcp-established <sec> " 1570 "tcp-transitory <sec> | icmp <sec> | reset]",
1585 .path =
"show nat44 ei timeouts",
1586 .short_help =
"show nat44 ei timeouts",
1598 .path =
"nat44 ei set logging level",
1600 .short_help =
"nat44 ei set logging level <level>",
1613 .path =
"nat44 ei ipfix logging",
1615 .short_help =
"nat44 ei ipfix logging <enable [domain <domain-id>] " 1616 "[src-port <port>]>|disable",
1633 .path =
"nat44 ei addr-port-assignment-alg",
1634 .short_help =
"nat44 ei addr-port-assignment-alg <alg-name> [<alg-params>]",
1645 .path =
"show nat44 ei addr-port-assignment-alg",
1646 .short_help =
"show nat44 ei addr-port-assignment-alg",
1661 .path =
"nat44 ei mss-clamping",
1662 .short_help =
"nat44 ei mss-clamping <mss-value>|disable",
1673 .path =
"show nat44 ei mss-clamping",
1674 .short_help =
"show nat44 ei mss-clamping",
1685 .path =
"nat44 ei ha failover",
1687 "nat44 ei ha failover <ip4-address>:<port> [refresh-interval <sec>]",
1698 .path =
"nat44 ei ha listener",
1700 "nat44 ei ha listener <ip4-address>:<port> [path-mtu <path-mtu>]",
1711 .path =
"show nat44 ei ha",
1712 .short_help =
"show nat44 ei ha",
1723 .path =
"nat44 ei ha flush",
1724 .short_help =
"nat44 ei ha flush",
1735 .path =
"nat44 ei ha resync",
1736 .short_help =
"nat44 ei ha resync",
1747 .path =
"show nat44 ei hash tables",
1748 .short_help =
"show nat44 ei hash tables [detail|verbose]",
1764 .path =
"nat44 ei add address",
1765 .short_help =
"nat44 ei add address <ip4-range-start> [- <ip4-range-end>] " 1766 "[tenant-vrf <vrf-id>] [del]",
1789 .path =
"show nat44 ei addresses",
1790 .short_help =
"show nat44 ei addresses",
1805 .path =
"set interface nat44 ei",
1808 "set interface nat44 ei in <intfc> out <intfc> [output-feature] " 1823 .path =
"show nat44 ei interfaces",
1824 .short_help =
"show nat44 ei interfaces",
1848 .path =
"nat44 ei add static mapping",
1850 .short_help =
"nat44 ei add static mapping tcp|udp|icmp local <addr> " 1851 "[<port|icmp-echo-id>] " 1852 "external <addr> [<port|icmp-echo-id>] [vrf <table-id>] [del]",
1869 .path =
"nat44 ei add identity mapping",
1872 "nat44 ei add identity mapping <ip4-addr>|external <interface> " 1873 "[<protocol> <port>] [vrf <table-id>] [del]",
1891 .path =
"show nat44 ei static mappings",
1892 .short_help =
"show nat44 ei static mappings",
1905 .path =
"nat44 ei add interface address",
1906 .short_help =
"nat44 ei add interface address <interface> [del]",
1920 .path =
"show nat44 ei interface address",
1921 .short_help =
"show nat44 ei interface address",
1932 .path =
"show nat44 ei sessions",
1933 .short_help =
"show nat44 ei sessions [detail]",
1945 .path =
"nat44 ei del user",
1946 .short_help =
"nat44 ei del user <addr> [fib <index>]",
1958 .path =
"clear nat44 ei sessions",
1959 .short_help =
"clear nat44 ei sessions",
1973 .path =
"nat44 ei del session",
1974 .short_help =
"nat44 ei del session in|out <addr>:<port> tcp|udp|icmp [vrf " 1975 "<id>] [external-host <addr>:<port>]",
1992 .path =
"nat44 ei forwarding",
1993 .short_help =
"nat44 ei forwarding enable|disable",
vl_api_address_t end_addr
#define vec_foreach_index(var, v)
Iterate over vector indices.
static clib_error_t * nat44_ei_enable_disable_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
int nat44_ei_add_interface_address(nat44_ei_main_t *nm, u32 sw_if_index, int is_del)
int nat_ha_set_failover(vlib_main_t *vm, ip4_address_t *addr, u16 port, u32 session_refresh_interval)
Set HA failover (remote settings)
u8 * format_nat44_ei_addr_and_port_alloc_alg(u8 *s, va_list *args)
nat44_ei_interface_t * interfaces
#define pool_foreach(VAR, POOL)
Iterate through pool.
static clib_error_t * nat44_ei_show_alloc_addr_and_port_alg_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
vl_api_address_t start_addr
nat44_ei_lb_addr_port_t * locals
int nat44_ei_add_del_static_mapping(ip4_address_t l_addr, ip4_address_t e_addr, u16 l_port, u16 e_port, nat_protocol_t proto, u32 sw_if_index, u32 vrf_id, u8 addr_only, u8 identity_nat, u8 *tag, u8 is_add)
Add/delete NAT44-EI static mapping.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static clib_error_t * nat44_ei_show_hash_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
NAT44 endpoint independent plugin declarations.
nat44_ei_session_t * sessions
static clib_error_t * nat44_ei_set_alloc_addr_and_port_alg_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
unformat_function_t unformat_nat_protocol
unformat_function_t unformat_vnet_sw_interface
static clib_error_t * nat44_ei_ipfix_logging_enable_disable_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
int nat44_ei_plugin_disable()
int nat_ipfix_logging_enable_disable(int enable, u32 domain_id, u16 src_port)
Enable/disable NAT plugin IPFIX logging.
clib_bihash_8_8_t static_mapping_by_external
int nat44_ei_user_del(ip4_address_t *addr, u32 fib_index)
Delete specific NAT44 EI user and his sessions.
format_function_t format_vnet_sw_if_index_name
static_always_inline void nat_reset_timeouts(nat_timeouts_t *timeouts)
#define nat44_ei_is_addr_only_static_mapping(mp)
int nat44_ei_interface_add_del(u32 sw_if_index, u8 is_inside, int is_del)
int nat_ha_set_listener(vlib_main_t *vm, ip4_address_t *addr, u16 port, u32 path_mtu)
Set HA listener (local settings)
nat44_ei_static_mapping_t * static_mappings
void nat44_ei_set_alloc_range(u16 start_port, u16 end_port)
Set address and port assignment algorithm for port range.
int nat44_ei_set_workers(uword *bitmap)
u8 * format_nat44_ei_user(u8 *s, va_list *args)
nat44_ei_main_per_thread_data_t * tnm
nat44_ei_address_t * addresses
static clib_error_t * nat44_ei_clear_sessions_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static clib_error_t * nat_show_workers_commnad_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static clib_error_t * set_timeout_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static clib_error_t * nat44_ei_show_static_mappings_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
description fragment has unexpected format
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define clib_error_return(e, args...)
vnet_main_t * vnet_get_main(void)
int nat44_ei_del_session(nat44_ei_main_t *nm, ip4_address_t *addr, u16 port, nat_protocol_t proto, u32 vrf_id, int is_in)
Delete NAT44-EI session.
static clib_error_t * nat_ha_failover_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define nat44_ei_is_session_static(sp)
int nat44_ei_del_address(nat44_ei_main_t *nm, ip4_address_t addr, u8 delete_sm)
static clib_error_t * nat_ha_flush_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
int nat44_ei_add_address(nat44_ei_main_t *nm, ip4_address_t *addr, u32 vrf_id)
vlib_worker_thread_t * vlib_worker_threads
u8 * format_nat44_ei_static_mapping(u8 *s, va_list *args)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
vl_api_interface_index_t sw_if_index
nat44_ei_static_map_resolve_t * to_resolve
static clib_error_t * nat_ha_resync_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
nat44_ei_interface_t * output_feature_interfaces
format_function_t format_nat_protocol
int nat44_ei_interface_add_del_output_feature(u32 sw_if_index, u8 is_inside, int is_del)
static clib_error_t * nat_show_timeouts_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static clib_error_t * set_workers_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
u8 * format_nat44_ei_session(u8 *s, va_list *args)
static clib_error_t * add_address_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
clib_bihash_8_8_t static_mapping_by_local
u32 * auto_add_sw_if_indices
static clib_error_t * add_identity_mapping_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
vl_api_ip_port_and_mask_t src_port
static clib_error_t * nat_show_ha_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
void nat44_ei_set_alloc_default()
Set address and port assignment algorithm to default/standard.
struct nat_timeouts_t::@732 tcp
nat44_ei_main_per_thread_data_t * per_thread_data
int nat44_ei_plugin_enable(nat44_ei_config_t c)
u32 ft_table_id
Table ID (hash key) for this FIB.
static clib_error_t * nat44_ei_del_user_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static clib_error_t * nat_show_mss_clamping_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
sll srl srl sll sra u16x4 i
static clib_error_t * nat44_ei_forwarding_set_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define vec_free(V)
Free vector's memory (no header).
static clib_error_t * nat_ha_listener_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
__clib_export uword unformat_bitmap_list(unformat_input_t *input, va_list *va)
unformat a list of bit ranges into a bitmap (eg "0-3,5-7,11" )
static clib_error_t * nat44_ei_show_sessions_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define nat44_ei_is_identity_static_mapping(mp)
#define VLIB_CLI_COMMAND(x,...)
static clib_error_t * add_static_mapping_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
static clib_error_t * nat44_ei_feature_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static clib_error_t * nat_set_mss_clamping_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
ip4_address_t external_addr
void nat_ha_get_failover(ip4_address_t *addr, u16 *port, u32 *session_refresh_interval)
Get HA failover/remote settings.
#define NAT44_EI_EXPECTED_ARGUMENT
int nat_ha_resync(u32 client_index, u32 pid, nat_ha_resync_event_cb_t event_callback)
Resync HA (resend existing sessions to new failover)
#define clib_bitmap_free(v)
Free a bitmap.
void nat44_ei_set_alloc_mape(u16 psid, u16 psid_offset, u16 psid_length)
Set address and port assignment algorithm for MAP-E CE.
void nat44_ei_add_del_address_dpo(ip4_address_t addr, u8 is_add)
#define nat44_ei_log_info(...)
void nat_ha_flush(u8 is_resync)
Flush the current HA data (for testing)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
void nat44_ei_sessions_clear()
Clear all active NAT44-EI sessions.
#define nat44_ei_is_unk_proto_session(sp)
static clib_error_t * nat44_ei_del_session_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
nat44_ei_main_t nat44_ei_main
void nat_ha_get_resync_status(u8 *in_resync, u32 *resync_ack_missed)
Get resync status.
fib_table_t * fib_table_get(fib_node_index_t index, fib_protocol_t proto)
Get a pointer to a FIB table.
u8 * format_nat44_ei_static_map_to_resolve(u8 *s, va_list *args)
static clib_error_t * nat44_ei_show_interface_address_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static void increment_v4_address(ip4_address_t *a)
NAT port/address allocation lib.
static clib_error_t * nat44_ei_set_log_level_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define vec_foreach(var, vec)
Vector iterator.
void nat_ha_get_listener(ip4_address_t *addr, u16 *port, u32 *path_mtu)
Get HA listener/local configuration.
nat44_ei_addr_and_port_alloc_alg_t addr_and_port_alloc_alg
static unsigned char * print(const cJSON *const item, cJSON_bool format, const internal_hooks *const hooks)
#define nat44_ei_interface_is_inside(ip)
static clib_error_t * nat44_ei_show_interfaces_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
clib_bihash_8_8_t user_hash
#define nat44_ei_interface_is_outside(ip)
static clib_error_t * nat44_ei_add_interface_address_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static clib_error_t * nat44_ei_show_addresses_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static uword pool_elts(void *v)
Number of active elements in a pool.