25 #include <vpp/app/version.h> 34 .arc_name =
"ip4-unicast",
35 .node_name =
"det44-in2out",
37 "ip4-sv-reassembly-feature"),
40 .arc_name =
"ip4-unicast",
41 .node_name =
"det44-out2in",
43 "ip4-sv-reassembly-feature",
44 "ip4-dhcp-client-detect"),
47 .version = VPP_BUILD_VER,
48 .description =
"Deterministic NAT (CGN)",
61 .ip4.as_u32 = addr->
as_u32,
125 return VNET_API_ERROR_VALUE_EXIST;
128 if (!found && !is_add)
129 return VNET_API_ERROR_NO_SUCH_ENTRY;
139 mp->
sharing_ratio = (1 << (32 - in_plen)) / (1 << (32 - out_plen));
144 1, empty_snat_det_session);
155 if (det44_interface_is_inside(i))
157 det44_add_del_addr_to_fib(out_addr, out_plen, i->sw_if_index, is_add);
202 const char *feature_name;
211 if (tmp->sw_if_index == sw_if_index)
220 feature_name = is_inside ?
"det44-in2out" :
"det44-out2in";
227 return VNET_API_ERROR_INVALID_VALUE;
245 det44_log_err (
"det44 is already enabled on this interface");
246 return VNET_API_ERROR_INVALID_VALUE;
291 outside_fib - dm->outside_fibs);
299 if (!is_del && !found)
301 vec_add2 (dm->outside_fibs, outside_fib, 1);
309 det44_add_del_addr_to_fib(&mp->out_addr,
310 mp->out_plen, sw_if_index, !is_del);
335 vec_foreach(ses, mp->sessions)
338 if (ses->in_port && (ses->expire < now))
339 snat_det_ses_close (mp, ses);
437 vec_free (mp->sessions);
467 if (new_fib_index == old_fib_index)
476 if (i->sw_if_index == sw_if_index)
478 if (!(det44_interface_is_outside (i)))
490 if (outside_fib->fib_index == old_fib_index)
492 outside_fib->refcount--;
493 if (!outside_fib->refcount)
494 vec_del1 (dm->outside_fibs, outside_fib - dm->outside_fibs);
501 if (outside_fib->fib_index == new_fib_index)
503 outside_fib->refcount++;
511 vec_add2 (dm->outside_fibs, outside_fib, 1);
512 outside_fib->refcount = 1;
513 outside_fib->fib_index = new_fib_index;
559 #define _(v, N, str) case DET44_SESSION_##N: t = (u8 *) str; break; 563 t =
format (t,
"unknown");
574 u32 in_offset, out_offset;
576 u32 *
i = va_arg (*args,
u32 *);
580 clib_host_to_net_u32 (clib_net_to_host_u32 (det_map->
in_addr.
as_u32) +
583 clib_net_to_host_u32 (in_addr.
as_u32) -
587 clib_host_to_net_u32 (clib_net_to_host_u32 (det_map->
out_addr.
as_u32) +
591 "in %U:%d out %U:%d external host %U:%d state: %U expire: %d\n",
vlib_log_class_t vlib_log_register_class(char *class, char *subclass)
ip4_table_bind_function_t * function
int det44_plugin_enable(det44_config_t c)
int det44_plugin_disable()
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
int ip4_sv_reass_enable_disable_with_refcnt(u32 sw_if_index, int is_enable)
vnet_main_t * vnet_get_main(void)
static clib_error_t * det44_init(vlib_main_t *vm)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static f64 vlib_time_now(vlib_main_t *vm)
u32 fib_table_get_index_for_sw_if_index(fib_protocol_t proto, u32 sw_if_index)
Get the index of the FIB bound to the interface.
#define det44_log_err(...)
add paths without path extensions
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Deterministic NAT (CGN) definitions.
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
unformat_function_t unformat_vnet_sw_interface
VNET_FEATURE_INIT(ip4_det44_in2out, static)
#define DET44_INTERFACE_FLAG_IS_INSIDE
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
struct nat_timeouts_s::@74 tcp
fib_node_index_t fib_table_entry_update_one_path(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, dpo_proto_t next_hop_proto, const ip46_address_t *next_hop, u32 next_hop_sw_if_index, u32 next_hop_fib_index, u32 next_hop_weight, fib_mpls_label_t *next_hop_labels, fib_route_path_flags_t path_flags)
Update the entry to have just one path.
det44_fib_t * outside_fibs
static_always_inline u8 plugin_enabled()
u32 ip4_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
#define VLIB_INIT_FUNCTION(x)
ip4_address_t ext_host_addr
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
static void det44_update_outside_fib(ip4_main_t *im, uword opaque, u32 sw_if_index, u32 new_fib_index, u32 old_fib_index)
nat_timeouts_t det44_get_timeouts()
Aggregate type for a prefix.
fib_source_t fib_source_allocate(const char *name, fib_source_priority_t prio, fib_source_behaviour_t bh)
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
#define FIB_SOURCE_PRIORITY_HI
Some priority values that plugins might use when they are not to concerned where in the list they'll ...
snat_det_session_t * sessions
u32 vlib_process_create(vlib_main_t *vm, char *name, vlib_node_function_t *f, u32 log2_n_stack_bytes)
Create a vlib process.
u8 * format_det44_session_state(u8 *s, va_list *args)
#define pool_put(P, E)
Free an object E in pool P.
#define vec_dup(V)
Return copy of vector (no header, no alignment)
#define DET44_INTERFACE_FLAG_IS_OUTSIDE
#define vec_del1(v, i)
Delete the element at index I.
void det44_reset_timeouts()
snat_det_map_t * det_maps
#define pool_free(p)
Free a pool.
u8 * format_det_map_ses(u8 *s, va_list *args)
void det44_add_del_addr_to_fib(ip4_address_t *addr, u8 p_len, u32 sw_if_index, int is_add)
sll srl srl sll sra u16x4 i
#define vec_free(V)
Free vector's memory (no header).
void fib_table_entry_delete(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source)
Delete a FIB entry.
vlib_main_t vlib_node_runtime_t * node
int det44_set_timeouts(nat_timeouts_t *timeouts)
#define DET44_SES_PER_USER
u32 fib_table_find_or_create_and_lock(fib_protocol_t proto, u32 table_id, fib_source_t src)
Get the index of the FIB for a Table-ID.
static uword det44_expire_walk_fn(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
The 'det44-expire-walk' process's main loop.
int snat_det_add_map(ip4_address_t *in_addr, u8 in_plen, ip4_address_t *out_addr, u8 out_plen, int is_add)
Add/delete deterministic NAT mapping.
#define FIB_SOURCE_PRIORITY_LOW
#define VNET_FEATURES(...)
static vlib_main_t * vlib_get_main(void)
void det44_create_expire_walk_process()
ip4_table_bind_callback_t * table_bind_callbacks
Functions to call when interface to table biding changes.
det44_interface_t * interfaces
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
clib_error_t * det44_api_hookup(vlib_main_t *vm)
vlib_log_class_t log_class
int det44_interface_add_del(u32 sw_if_index, u8 is_inside, int is_del)
ip4_main_t ip4_main
Global ip4 main structure.
#define vec_foreach(var, vec)
Vector iterator.
u32 expire_walk_node_index
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header, unspecified alignment)
vl_api_interface_index_t sw_if_index
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)