X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Fnat%2Fnat44-ei%2Fnat44_ei.h;h=b8b339b8e894f4ae9da8da485f9cef46a47830ea;hb=730c1a40978a321b0788c3240db1c32274937249;hp=b9212df44bd19d7f671e03ef1a21deec8388f701;hpb=0eaf4e6784efb2d058fe2f031578251b6bcc0aa8;p=vpp.git diff --git a/src/plugins/nat/nat44-ei/nat44_ei.h b/src/plugins/nat/nat44-ei/nat44_ei.h index b9212df44bd..b8b339b8e89 100644 --- a/src/plugins/nat/nat44-ei/nat44_ei.h +++ b/src/plugins/nat/nat44-ei/nat44_ei.h @@ -32,9 +32,11 @@ #include #include #include +#include #include #include +#include /* default number of worker handoff frame queue elements */ #define NAT_FQ_NELTS_DEFAULT 64 @@ -61,8 +63,9 @@ typedef enum #define NAT44_EI_SESSION_FLAG_UNKNOWN_PROTO (1 << 1) /* Static mapping flags */ -#define NAT44_EI_STATIC_MAPPING_FLAG_ADDR_ONLY (1 << 0) -#define NAT44_EI_STATIC_MAPPING_FLAG_IDENTITY_NAT (1 << 1) +#define NAT44_EI_SM_FLAG_ADDR_ONLY (1 << 0) +#define NAT44_EI_SM_FLAG_IDENTITY_NAT (1 << 1) +#define NAT44_EI_SM_FLAG_SWITCH_ADDRESS (1 << 2) typedef struct { @@ -71,7 +74,7 @@ typedef struct #define _(N, i, n, s) \ u32 busy_##n##_ports; \ u32 *busy_##n##_ports_per_thread; \ - u32 busy_##n##_port_refcounts[65535]; + u32 busy_##n##_port_refcounts[0xffff + 1]; foreach_nat_protocol #undef _ } nat44_ei_address_t; @@ -81,8 +84,8 @@ clib_error_t *nat44_ei_api_hookup (vlib_main_t *vm); /* NAT address and port allocation function */ typedef int (nat44_ei_alloc_out_addr_and_port_function_t) ( nat44_ei_address_t *addresses, u32 fib_index, u32 thread_index, - nat_protocol_t proto, ip4_address_t *addr, u16 *port, u16 port_per_thread, - u32 snat_thread_index); + nat_protocol_t proto, ip4_address_t s_addr, ip4_address_t *addr, u16 *port, + u16 port_per_thread, u32 snat_thread_index); typedef struct { @@ -137,13 +140,9 @@ typedef struct u32 vrf_id; u32 flags; nat_protocol_t proto; - u8 addr_only; - u8 identity_nat; - u8 exact; u8 *tag; } nat44_ei_static_map_resolve_t; -// TODO: cleanup/redo (there is no lb in EI nat) typedef struct { /* backend IP address */ @@ -160,7 +159,7 @@ typedef struct typedef struct { - /* prefered pool address */ + /* preferred pool address */ ip4_address_t pool_addr; /* local IP address */ ip4_address_t local_addr; @@ -301,20 +300,10 @@ typedef struct } nat44_ei_main_per_thread_data_t; -/* Return worker thread index for given packet */ -typedef u32 (nat44_ei_get_worker_in2out_function_t) (ip4_header_t *ip, - u32 rx_fib_index, - u8 is_output); - -typedef u32 (nat44_ei_get_worker_out2in_function_t) (vlib_buffer_t *b, - ip4_header_t *ip, - u32 rx_fib_index, - u8 is_output); - typedef struct { u32 cached_sw_if_index; - u32 cached_ip4_address; + uword *cached_presence_by_ip4_address; } nat44_ei_runtime_t; typedef struct @@ -348,6 +337,8 @@ typedef struct nat44_ei_main_s /* Interface pool */ nat44_ei_interface_t *interfaces; nat44_ei_interface_t *output_feature_interfaces; + // broken api backward compatibility + nat44_ei_interface_t *output_feature_dummy_interfaces; /* Is translation memory size calculated or user defined */ u8 translation_memory_size_set; @@ -366,8 +357,6 @@ typedef struct nat44_ei_main_s u32 num_workers; u32 first_worker_index; u32 *workers; - nat44_ei_get_worker_in2out_function_t *worker_in2out_cb; - nat44_ei_get_worker_out2in_function_t *worker_out2in_cb; u16 port_per_thread; /* Main lookup tables */ @@ -494,9 +483,17 @@ typedef struct nat44_ei_main_s extern nat44_ei_main_t nat44_ei_main; int nat44_ei_plugin_enable (nat44_ei_config_t c); - int nat44_ei_plugin_disable (); +int nat44_ei_add_interface (u32 sw_if_index, u8 is_inside); +int nat44_ei_del_interface (u32 sw_if_index, u8 is_inside); +int nat44_ei_add_output_interface (u32 sw_if_index); +int nat44_ei_del_output_interface (u32 sw_if_index); +int nat44_ei_add_address (ip4_address_t *addr, u32 vrf_id); +int nat44_ei_del_address (ip4_address_t addr, u8 delete_sm); +int nat44_ei_add_interface_address (u32 sw_if_index); +int nat44_ei_del_interface_address (u32 sw_if_index); + /** * @brief Delete specific NAT44 EI user and his sessions * @@ -543,29 +540,14 @@ void nat44_ei_set_alloc_mape (u16 psid, u16 psid_offset, u16 psid_length); */ void nat44_ei_set_alloc_range (u16 start_port, u16 end_port); -/** - * @brief Add/delete NAT44-EI static mapping - * - * @param l_addr local IPv4 address - * @param e_addr external IPv4 address - * @param l_port local port number - * @param e_port external port number - * @param proto L4 protocol - * @param sw_if_index use interface address as external IPv4 address - * @param vrf_id local VRF ID - * @param addr_only 1 = 1:1NAT, 0 = 1:1NAPT - * @param identity_nat identity NAT - * @param tag opaque string tag - * @param is_add 1 = add, 0 = delete - * - * @return 0 on success, non-zero value otherwise +int nat44_ei_add_static_mapping (ip4_address_t l_addr, ip4_address_t e_addr, + u16 l_port, u16 e_port, nat_protocol_t proto, + u32 vrf_id, u32 sw_if_index, u32 flags, + ip4_address_t pool_addr, u8 *tag); - */ -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); +int nat44_ei_del_static_mapping (ip4_address_t l_addr, ip4_address_t e_addr, + u16 l_port, u16 e_port, nat_protocol_t proto, + u32 vrf_id, u32 sw_if_index, u32 flags); /** * @brief Delete NAT44-EI session @@ -630,9 +612,6 @@ int nat44_ei_set_outside_address_and_port (nat44_ei_address_t *addresses, ip4_address_t addr, u16 port, nat_protocol_t protocol); -int nat44_ei_del_address (nat44_ei_main_t *nm, ip4_address_t addr, - u8 delete_sm); - void nat44_ei_free_session_data (nat44_ei_main_t *nm, nat44_ei_session_t *s, u32 thread_index, u8 is_ha); @@ -640,20 +619,9 @@ int nat44_ei_set_workers (uword *bitmap); void nat44_ei_add_del_address_dpo (ip4_address_t addr, u8 is_add); -int nat44_ei_add_address (nat44_ei_main_t *nm, ip4_address_t *addr, - u32 vrf_id); - void nat44_ei_delete_session (nat44_ei_main_t *nm, nat44_ei_session_t *ses, u32 thread_index); -int nat44_ei_interface_add_del (u32 sw_if_index, u8 is_inside, int is_del); - -int nat44_ei_interface_add_del_output_feature (u32 sw_if_index, u8 is_inside, - int is_del); - -int nat44_ei_add_interface_address (nat44_ei_main_t *nm, u32 sw_if_index, - int is_del); - /* Call back functions for clib_bihash_add_or_overwrite_stale */ int nat44_i2o_is_idle_session_cb (clib_bihash_kv_8_8_t *kv, void *arg); int nat44_o2i_is_idle_session_cb (clib_bihash_kv_8_8_t *kv, void *arg); @@ -675,20 +643,47 @@ u32 nat44_ei_icmp_hairpinning (nat44_ei_main_t *nm, vlib_buffer_t *b0, int nat44_ei_set_frame_queue_nelts (u32 frame_queue_nelts); -#define nat44_ei_is_session_static(sp) \ - (sp->flags & NAT44_EI_SESSION_FLAG_STATIC_MAPPING) -#define nat44_ei_is_unk_proto_session(sp) \ - (sp->flags & NAT44_EI_SESSION_FLAG_UNKNOWN_PROTO) +always_inline bool +nat44_ei_is_session_static (nat44_ei_session_t *s) +{ + return (s->flags & NAT44_EI_SESSION_FLAG_STATIC_MAPPING); +} + +always_inline bool +nat44_ei_is_unk_proto_session (nat44_ei_session_t *s) +{ + return (s->flags & NAT44_EI_SESSION_FLAG_UNKNOWN_PROTO); +} + +always_inline bool +nat44_ei_interface_is_inside (nat44_ei_interface_t *i) +{ + return (i->flags & NAT44_EI_INTERFACE_FLAG_IS_INSIDE); +} + +always_inline bool +nat44_ei_interface_is_outside (nat44_ei_interface_t *i) +{ + return (i->flags & NAT44_EI_INTERFACE_FLAG_IS_OUTSIDE); +} + +always_inline bool +is_sm_addr_only (u32 f) +{ + return (f & NAT44_EI_SM_FLAG_ADDR_ONLY); +} -#define nat44_ei_interface_is_inside(ip) \ - (ip->flags & NAT44_EI_INTERFACE_FLAG_IS_INSIDE) -#define nat44_ei_interface_is_outside(ip) \ - (ip->flags & NAT44_EI_INTERFACE_FLAG_IS_OUTSIDE) +always_inline bool +is_sm_identity_nat (u32 f) +{ + return (f & NAT44_EI_SM_FLAG_IDENTITY_NAT); +} -#define nat44_ei_is_addr_only_static_mapping(mp) \ - (mp->flags & NAT44_EI_STATIC_MAPPING_FLAG_ADDR_ONLY) -#define nat44_ei_is_identity_static_mapping(mp) \ - (mp->flags & NAT44_EI_STATIC_MAPPING_FLAG_IDENTITY_NAT) +always_inline bool +is_sm_switch_address (u32 f) +{ + return (f & NAT44_EI_SM_FLAG_SWITCH_ADDRESS); +} /* logging */ #define nat44_ei_log_err(...) \