37 #define _(sym,string) string, 60 "NAT44_IN2OUT_ED_FAST_PATH";
62 s =
format (s,
"%s: sw_if_index %d, next index %d, session %d", tag,
68 #ifndef CLIB_MARCH_VARIANT 75 u64 sess_timeout_time;
89 if (ctx->
now >= sess_timeout_time)
94 l_addr = &s->out2in.addr;
95 r_addr = &s->ext_host_addr;
96 fib_index = s->out2in.fib_index;
99 proto = s->in2out.port;
106 l_port = s->out2in.port;
107 r_port = s->ext_host_port;
109 make_ed_kv (l_addr, r_addr, proto, fib_index, l_port, r_port, ~0ULL,
111 if (clib_bihash_add_del_16_8 (&tsm->
out2in_ed, &ed_kv, 0))
118 s->in2out.addr.as_u32,
119 s->out2in.addr.as_u32,
123 s->in2out.fib_index);
126 &s->in2out.addr, s->in2out.port,
127 &s->ext_host_nat_addr, s->ext_host_nat_port,
128 &s->out2in.addr, s->out2in.port,
129 &s->ext_host_addr, s->ext_host_port,
132 nat_ha_sdel (&s->out2in.addr, s->out2in.port, &s->ext_host_addr,
133 s->ext_host_port, s->out2in.protocol, s->out2in.fib_index,
141 key.
port = s->ext_host_nat_port;
143 if (a->
addr.
as_u32 == s->ext_host_nat_addr.as_u32)
170 u32 sw_if_index0,
u32 rx_fib_index0,
172 u32 thread_index, snat_session_t ** p_s0)
176 next0 =
icmp_in2out (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
177 next0, thread_index, p_s0, 0);
178 snat_session_t *s0 = *p_s0;
184 (vm, b0), thread_index);
201 u32 nat_proto,
u32 thread_index,
203 u16 port_per_thread,
u32 snat_thread_index,
206 u16 * allocated_port,
214 const u16 port_thread_offset = (port_per_thread * snat_thread_index) + 1024;
221 #define _(N, j, n, unused) \ 222 case NAT_PROTOCOL_##N: \ 223 if (a->fib_index == rx_fib_index) \ 225 u16 port = snat_random_port (1, port_per_thread); \ 226 u16 attempts = port_per_thread; \ 227 while (attempts > 0) \ 230 portnum = port_thread_offset + port; \ 231 make_ed_kv (&a->addr, &r_addr, proto, s->out2in.fib_index, \ 232 clib_host_to_net_u16 (portnum), r_port, \ 233 s - tsm->sessions, out2in_ed_kv); \ 234 int rv = clib_bihash_add_del_16_8 (&tsm->out2in_ed, out2in_ed_kv, \ 238 ++a->busy_##n##_port_refcounts[portnum]; \ 239 a->busy_##n##_ports_per_thread[thread_index]++; \ 240 a->busy_##n##_ports++; \ 241 *allocated_addr = a->addr; \ 242 *allocated_port = clib_host_to_net_u16 (portnum); \ 245 port = (port + 1) % port_per_thread; \ 248 else if (a->fib_index == ~0) \ 291 snat_session_t ** sessionp,
294 snat_session_t *s = NULL;
308 .fp_addr = {.ip4.as_u32 = r_addr.
as_u32,},
318 b->
error = node->
errors[NAT_IN2OUT_ED_ERROR_NON_SYN];
329 b->
error = node->
errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
344 (sm, key0, &key1, 0, 0, 0, &lb, 0, &identity_nat))
350 b->
error = node->
errors[NAT_IN2OUT_ED_ERROR_MAX_USER_SESS_EXCEEDED];
370 s->out2in.fib_index = outside_fib->
fib_index;
381 thread_index, r_addr, r_port, proto,
385 &allocated_port, &out2in_ed_kv))
388 b->
error = node->
errors[NAT_IN2OUT_ED_ERROR_OUT_OF_PORTS];
392 key1.
addr = allocated_addr;
393 key1.
port = allocated_port;
406 b->
error = node->
errors[NAT_IN2OUT_ED_ERROR_MAX_USER_SESS_EXCEEDED];
426 s->out2in.fib_index = outside_fib->
fib_index;
439 s->out2in.fib_index, key1.
port, r_port, s - tsm->
sessions,
441 if (clib_bihash_add_or_overwrite_stale_16_8
450 s->ext_host_addr = r_addr;
451 s->ext_host_port = r_port;
457 make_ed_kv (&l_addr, &r_addr, proto, rx_fib_index, l_port, r_port,
461 if (clib_bihash_add_or_overwrite_stale_16_8 (&tsm->
in2out_ed, &in2out_ed_kv,
470 s->in2out.addr.as_u32,
471 s->out2in.addr.as_u32,
474 s->out2in.port, s->in2out.fib_index);
477 &s->in2out.addr, s->in2out.port,
478 &s->ext_host_nat_addr, s->ext_host_nat_port,
479 &s->out2in.addr, s->out2in.port,
480 &s->ext_host_addr, s->ext_host_port,
481 s->in2out.protocol, 0);
483 nat_ha_sadd (&s->in2out.addr, s->in2out.port, &s->out2in.addr,
484 s->out2in.port, &s->ext_host_addr, s->ext_host_port,
485 &s->ext_host_nat_addr, s->ext_host_nat_port,
486 s->in2out.protocol, s->in2out.fib_index, s->flags,
495 u32 rx_fib_index,
u32 thread_index)
507 if (clib_bihash_search_16_8 (&tsm->
out2in_ed, &kv, &value))
529 u32 thread_index,
f64 now,
533 snat_session_t *s = 0;
539 if (ip->
protocol == IP_PROTOCOL_ICMP)
544 else if (ip->
protocol == IP_PROTOCOL_UDP || ip->
protocol == IP_PROTOCOL_TCP)
548 vnet_buffer (b)->ip.reass.l4_dst_port, ~0ULL, &kv);
556 if (!clib_bihash_search_16_8 (&tsm->
in2out_ed, &kv, &value))
561 if (ip->
protocol == IP_PROTOCOL_TCP)
564 (sm, now, s, b, thread_index))
585 u32 thread_index,
u32 rx_sw_if_index,
597 tx_fib_index, src_port, dst_port, ~0ULL, &kv);
598 if (!clib_bihash_search_16_8 (&tsm->
out2in_ed, &kv, &value))
613 rx_fib_index, dst_port, src_port, ~0ULL, &kv);
614 if (!clib_bihash_search_16_8 (&tsm->
in2out_ed, &kv, &value))
624 if ((nat_interface_is_inside (i)) && (rx_sw_if_index == i->sw_if_index))
634 #ifndef CLIB_MARCH_VARIANT 639 u8 * p_dont_translate,
void *d,
void *e)
643 snat_session_t *s = 0;
644 u8 dont_translate = 0;
648 u16 l_port = 0, r_port = 0;
665 if (clib_bihash_search_16_8 (&tsm->
in2out_ed, &kv, &value))
671 (sm, ip, l_port, r_port, thread_index,
681 ip, NAT_PROTOCOL_ICMP,
692 (
vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags)))
694 b->
error = node->
errors[NAT_IN2OUT_ED_ERROR_BAD_ICMP_TYPE];
701 ip->
protocol, rx_fib_index, &s, node, next,
716 (
vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags !=
718 &&
vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags !=
721 reass.icmp_type_or_tcp_flags)))
723 b->
error = node->
errors[NAT_IN2OUT_ED_ERROR_BAD_ICMP_TYPE];
732 *p_value = s->out2in;
733 *p_dont_translate = dont_translate;
735 *(snat_session_t **) d = s;
740 static snat_session_t *
752 u32 old_addr, new_addr = 0;
786 outside_fib_index = outside_fib->
fib_index;
797 rx_fib_index, 0, 0, ~0ULL, &s_kv);
799 if (!clib_bihash_search_16_8 (&tsm->
in2out_ed, &s_kv, &s_value))
808 (sm, rx_fib_index, thread_index)))
810 b->
error = node->
errors[NAT_IN2OUT_ED_ERROR_MAX_SESSIONS_EXCEEDED];
830 if (s->ext_host_addr.as_u32 == ip->dst_address.as_u32)
832 new_addr = ip->src_address.as_u32 = s->out2in.addr.as_u32;
834 make_ed_kv (&s->out2in.addr, &ip->dst_address, ip->protocol,
835 outside_fib_index, 0, 0, ~0ULL, &s_kv);
836 if (clib_bihash_search_16_8 (&tsm->out2in_ed, &s_kv, &s_value))
847 ip->
protocol, outside_fib_index, 0, 0, ~0ULL,
849 if (clib_bihash_search_16_8 (&tsm->
out2in_ed, &s_kv, &s_value))
863 b->
error = node->
errors[NAT_IN2OUT_ED_ERROR_MAX_USER_SESS_EXCEEDED];
871 s->out2in.addr.as_u32 = new_addr;
872 s->out2in.fib_index = outside_fib_index;
873 s->in2out.addr.as_u32 = old_addr;
874 s->in2out.fib_index = rx_fib_index;
875 s->in2out.port = s->out2in.port = ip->
protocol;
881 rx_fib_index, 0, 0, s - tsm->
sessions, &s_kv);
882 if (clib_bihash_add_del_16_8 (&tsm->
in2out_ed, &s_kv, 1))
886 outside_fib_index, 0, 0, s - tsm->
sessions, &s_kv);
887 if (clib_bihash_add_del_16_8 (&tsm->
out2in_ed, &s_kv, 1))
916 int is_output_feature)
918 u32 n_left_from, *from, *to_next, pkts_processed = 0, stats_node_index;
924 u32 tcp_packets = 0, udp_packets = 0, icmp_packets = 0, other_packets =
936 while (n_left_from > 0)
942 while (n_left_from > 0 && n_left_to_next > 0)
946 u32 next0, sw_if_index0, rx_fib_index0, iph_offset0 = 0, proto0,
947 new_addr0, old_addr0;
948 u16 old_port0, new_port0;
952 snat_session_t *s0 = 0;
966 if (is_output_feature)
969 iph_offset0 =
vnet_buffer (b0)->ip.reass.save_rewrite_length;
986 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1002 if (is_output_feature)
1005 (sm, ip0, thread_index, now, vm, b0)))
1021 if (clib_bihash_search_16_8 (&tsm->
in2out_ed, &kv0, &value0))
1029 if (s0->tcp_closed_timestamp)
1031 if (now >= s0->tcp_closed_timestamp)
1039 b0->
error = node->
errors[NAT_IN2OUT_ED_ERROR_TCP_CLOSED];
1046 u64 sess_timeout_time;
1047 sess_timeout_time = s0->last_heard +
1049 if (now >= sess_timeout_time)
1058 b0->
flags |= VNET_BUFFER_F_IS_NATED;
1060 if (!is_output_feature)
1074 old_port0 =
vnet_buffer (b0)->ip.reass.l4_src_port;
1080 new_port0 = udp0->
src_port = s0->out2in.port;
1081 sum0 = tcp0->checksum;
1092 s0->ext_host_addr.as_u32,
1097 reass.l4_dst_port, s0->ext_host_port,
1099 tcp0->dst_port = s0->ext_host_port;
1107 (sm, now, s0, b0, thread_index))
1113 new_port0 = udp0->
src_port = s0->out2in.port;
1124 s0->ext_host_addr.as_u32,
1130 udp0->
dst_port = s0->ext_host_port;
1140 new_port0 = udp0->
src_port = s0->out2in.port;
1143 udp0->
dst_port = s0->ext_host_port;
1153 (vm, b0), thread_index);
1159 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
1173 pkts_processed += next0 ==
vnet_buffer2 (b0)->nat.arc_next;
1176 to_next, n_left_to_next,
1184 NAT_IN2OUT_ED_ERROR_IN2OUT_PACKETS,
1187 NAT_IN2OUT_ED_ERROR_TCP_PACKETS, tcp_packets);
1189 NAT_IN2OUT_ED_ERROR_UDP_PACKETS, udp_packets);
1191 NAT_IN2OUT_ED_ERROR_ICMP_PACKETS,
1194 NAT_IN2OUT_ED_ERROR_OTHER_PACKETS,
1203 int is_output_feature)
1205 u32 n_left_from, *from, *to_next, pkts_processed = 0, stats_node_index;
1211 u32 tcp_packets = 0, udp_packets = 0, icmp_packets = 0, other_packets = 0;
1219 while (n_left_from > 0)
1225 while (n_left_from > 0 && n_left_to_next > 0)
1229 u32 next0, sw_if_index0, rx_fib_index0, iph_offset0 = 0, proto0,
1230 new_addr0, old_addr0;
1231 u16 old_port0, new_port0;
1235 icmp46_header_t *icmp0;
1236 snat_session_t *s0 = 0;
1246 n_left_to_next -= 1;
1250 if (is_output_feature)
1251 iph_offset0 =
vnet_buffer (b0)->ip.reass.save_rewrite_length;
1267 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1275 icmp0 = (icmp46_header_t *) udp0;
1294 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0,
1295 node, next0, now, thread_index, &s0);
1306 if (!clib_bihash_search_16_8 (&tsm->
in2out_ed, &kv0, &value0))
1310 if (s0->tcp_closed_timestamp && now >= s0->tcp_closed_timestamp)
1320 if (is_output_feature)
1335 (proto0 == NAT_PROTOCOL_UDP
1337 clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_server))
1345 (sm, node, sw_if_index0, ip0, proto0, rx_fib_index0,
1354 ip0->
protocol, rx_fib_index0, &s0, node, next0,
1365 b0->
flags |= VNET_BUFFER_F_IS_NATED;
1367 if (!is_output_feature)
1381 old_port0 =
vnet_buffer (b0)->ip.reass.l4_src_port;
1387 new_port0 = udp0->
src_port = s0->out2in.port;
1388 sum0 = tcp0->checksum;
1399 s0->ext_host_addr.as_u32,
1404 reass.l4_dst_port, s0->ext_host_port,
1406 tcp0->dst_port = s0->ext_host_port;
1414 (sm, now, s0, b0, thread_index))
1420 new_port0 = udp0->
src_port = s0->out2in.port;
1431 s0->ext_host_addr.as_u32,
1437 udp0->
dst_port = s0->ext_host_port;
1447 new_port0 = udp0->
src_port = s0->out2in.port;
1450 udp0->
dst_port = s0->ext_host_port;
1460 (vm, b0), thread_index);
1466 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
1480 pkts_processed += next0 ==
vnet_buffer2 (b0)->nat.arc_next;
1484 to_next, n_left_to_next,
1492 NAT_IN2OUT_ED_ERROR_IN2OUT_PACKETS,
1495 NAT_IN2OUT_ED_ERROR_TCP_PACKETS, tcp_packets);
1497 NAT_IN2OUT_ED_ERROR_UDP_PACKETS, udp_packets);
1499 NAT_IN2OUT_ED_ERROR_ICMP_PACKETS,
1502 NAT_IN2OUT_ED_ERROR_OTHER_PACKETS,
1516 .name =
"nat44-ed-in2out",
1517 .vector_size =
sizeof (
u32),
1518 .sibling_of =
"nat-default",
1536 .name =
"nat44-ed-in2out-output",
1537 .vector_size =
sizeof (
u32),
1538 .sibling_of =
"nat-default",
1556 .name =
"nat44-ed-in2out-slowpath",
1557 .vector_size =
sizeof (
u32),
1558 .sibling_of =
"nat-default",
1577 .name =
"nat44-ed-in2out-output-slowpath",
1578 .vector_size =
sizeof (
u32),
1579 .sibling_of =
"nat-default",
1607 .name =
"nat-pre-in2out",
1608 .vector_size =
sizeof (
u32),
1609 .sibling_of =
"nat-default",
ip4_address_t external_addr
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
fib_protocol_t fp_proto
protocol type
nat_outside_fib_t * outside_fibs
#define snat_is_session_static(s)
Check if SNAT session is created from static mapping.
vlib_node_registration_t nat44_ed_in2out_output_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_in2out_output_node)
#define nat_elog_info(nat_elog_str)
static u32 nat44_session_get_timeout(snat_main_t *sm, snat_session_t *s)
#define nat_elog_notice(nat_elog_str)
void nat_syslog_nat44_sadd(u32 ssubix, u32 sfibix, ip4_address_t *isaddr, u16 isport, ip4_address_t *idaddr, u16 idport, ip4_address_t *xsaddr, u16 xsport, ip4_address_t *xdaddr, u16 xdport, nat_protocol_t proto, u8 is_twicenat)
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.
static void make_sm_kv(clib_bihash_kv_8_8_t *kv, ip4_address_t *addr, u8 proto, u32 fib_index, u16 port)
void nat_free_session_data(snat_main_t *sm, snat_session_t *s, u32 thread_index, u8 is_ha)
Free NAT44 session data (lookup keys, external address port)
#define foreach_nat_in2out_ed_error
#define nat_elog_warn(nat_elog_str)
void nat_ha_sadd(ip4_address_t *in_addr, u16 in_port, ip4_address_t *out_addr, u16 out_port, ip4_address_t *eh_addr, u16 eh_port, ip4_address_t *ehn_addr, u16 ehn_port, u8 proto, u32 fib_index, u16 flags, u32 thread_index, u8 is_resync)
Create session add HA event.
#define nat44_is_ses_closed(s)
Check if NAT44 endpoint-dependent TCP session is closed.
#define VLIB_NODE_FN(node)
static void nat_ed_session_delete(snat_main_t *sm, snat_session_t *ses, u32 thread_index, int lru_delete)
static_always_inline int nat44_ed_not_translate(snat_main_t *sm, vlib_node_runtime_t *node, u32 sw_if_index, ip4_header_t *ip, u32 proto, u32 rx_fib_index, u32 thread_index)
vlib_error_t * errors
Vector of errors for this node.
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
void snat_ipfix_logging_nat44_ses_create(u32 thread_index, u32 src_ip, u32 nat_src_ip, nat_protocol_t nat_proto, u16 src_port, u16 nat_src_port, u32 vrf_id)
Generate NAT44 session create event.
struct _tcp_header tcp_header_t
#define snat_is_unk_proto_session(s)
Check if SNAT session for unknown protocol.
static snat_session_t * nat44_ed_in2out_unknown_proto(snat_main_t *sm, vlib_buffer_t *b, ip4_header_t *ip, u32 rx_fib_index, u32 thread_index, f64 now, vlib_main_t *vm, vlib_node_runtime_t *node)
static_always_inline int get_icmp_i2o_ed_key(vlib_buffer_t *b, ip4_header_t *ip0, u32 rx_fib_index, u64 value, u8 *nat_proto, u16 *l_port, u16 *r_port, clib_bihash_kv_16_8_t *kv)
static uword nat44_ed_in2out_slow_path_node_fn_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int is_output_feature)
static int snat_not_translate_fast(snat_main_t *sm, vlib_node_runtime_t *node, u32 sw_if_index0, ip4_header_t *ip0, u32 proto0, u32 rx_fib_index0)
Check if packet should be translated.
u32 ip4_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
#define static_always_inline
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
static nat_protocol_t ip_proto_to_nat_proto(u8 ip_proto)
Common NAT inline functions.
vl_api_interface_index_t sw_if_index
static_always_inline u16 snat_random_port(u16 min, u16 max)
#define SNAT_SESSION_FLAG_OUTPUT_FEATURE
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
Aggregate type for a prefix.
static_always_inline u8 icmp_type_is_error_message(u8 icmp_type)
u32 icmp_in2out(snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0, icmp46_header_t *icmp0, u32 sw_if_index0, u32 rx_fib_index0, vlib_node_runtime_t *node, u32 next0, u32 thread_index, void *d, void *e)
#define is_fwd_bypass_session(s)
Check if NAT session is forwarding bypass.
static void * ip4_next_header(ip4_header_t *i)
void snat_ipfix_logging_addresses_exhausted(u32 thread_index, u32 pool_id)
Generate NAT addresses exhausted event.
void nat_ipfix_logging_max_sessions(u32 thread_index, u32 limit)
Generate maximum session entries exceeded event.
fib_node_index_t fib_table_lookup(u32 fib_index, const fib_prefix_t *prefix)
Perfom a longest prefix match in the non-forwarding table.
int snat_static_mapping_match(snat_main_t *sm, snat_session_key_t match, snat_session_key_t *mapping, u8 by_external, u8 *is_addr_only, twice_nat_type_t *twice_nat, lb_nat_type_t *lb, ip4_address_t *ext_host_addr, u8 *is_identity_nat)
Match NAT44 static mapping.
void snat_free_outside_address_and_port(snat_address_t *addresses, u32 thread_index, snat_session_key_t *k)
Free outside address and port pair.
vl_api_fib_path_type_t type
vlib_error_t error
Error code for buffers to be enqueued to error handler.
static void mss_clamping(snat_main_t *sm, tcp_header_t *tcp, ip_csum_t *sum)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static u32 slow_path_ed(snat_main_t *sm, vlib_buffer_t *b, ip4_address_t l_addr, ip4_address_t r_addr, u16 l_port, u16 r_port, u8 proto, u32 rx_fib_index, snat_session_t **sessionp, vlib_node_runtime_t *node, u32 next, u32 thread_index, f64 now)
clib_bihash_16_8_t out2in_ed
vlib_node_registration_t nat44_ed_in2out_slowpath_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_in2out_slowpath_node)
snat_static_mapping_t * static_mappings
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
vl_api_address_union_t src_address
#define SNAT_SESSION_FLAG_UNKNOWN_PROTO
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
static_always_inline snat_session_t * nat_ed_session_alloc(snat_main_t *sm, u32 thread_index, f64 now, u8 proto)
static u8 * format_nat_pre_trace(u8 *s, va_list *args)
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
u32 fib_entry_get_resolving_interface(fib_node_index_t entry_index)
static u8 * format_nat_in2out_ed_trace(u8 *s, va_list *args)
snat_interface_t * output_feature_interfaces
vlib_node_registration_t nat_pre_in2out_node
(constructor) VLIB_REGISTER_NODE (nat_pre_in2out_node)
#define VLIB_REGISTER_NODE(x,...)
static u32 random_u32_max(void)
Maximum value returned by random_u32()
int nat44_o2i_ed_is_idle_session_cb(clib_bihash_kv_16_8_t *kv, void *arg)
vlib_node_registration_t nat44_ed_in2out_output_slowpath_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_in2out_output_slowpath_node)
sll srl srl sll sra u16x4 i
static_always_inline void vnet_feature_next(u32 *next0, vlib_buffer_t *b0)
static void nat44_session_update_counters(snat_session_t *s, f64 now, uword bytes, u32 thread_index)
u32 ed_in2out_slowpath_node_index
u32 fib_node_index_t
A typedef of a node index.
8 octet key, 8 octet key value pair
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
static_always_inline int nat_not_translate_output_feature_fwd(snat_main_t *sm, ip4_header_t *ip, u32 thread_index, f64 now, vlib_main_t *vm, vlib_buffer_t *b)
static uword nat_pre_node_fn_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, u32 def_next)
The NAT inline functions.
vlib_main_t vlib_node_runtime_t * node
void nat_syslog_nat44_sdel(u32 ssubix, u32 sfibix, ip4_address_t *isaddr, u16 isport, ip4_address_t *idaddr, u16 idport, ip4_address_t *xsaddr, u16 xsport, ip4_address_t *xdaddr, u16 xdport, nat_protocol_t proto, u8 is_twicenat)
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
vl_api_interface_index_t tx_sw_if_index
static int nat44_set_tcp_session_state_i2o(snat_main_t *sm, f64 now, snat_session_t *ses, vlib_buffer_t *b, u32 thread_index)
Set TCP session state.
static void nat44_session_update_lru(snat_main_t *sm, snat_session_t *s, u32 thread_index)
Per-user LRU list maintenance.
#define SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT
static u32 icmp_in2out_ed_slow_path(snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0, icmp46_header_t *icmp0, u32 sw_if_index0, u32 rx_fib_index0, vlib_node_runtime_t *node, u32 next0, f64 now, u32 thread_index, snat_session_t **p_s0)
void snat_ipfix_logging_nat44_ses_delete(u32 thread_index, u32 src_ip, u32 nat_src_ip, nat_protocol_t nat_proto, u16 src_port, u16 nat_src_port, u32 vrf_id)
Generate NAT44 session delete event.
vlib_node_registration_t nat44_ed_in2out_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_in2out_node)
snat_address_t * twice_nat_addresses
static_always_inline u8 nat44_ed_maximum_sessions_exceeded(snat_main_t *sm, u32 fib_index, u32 thread_index)
static vlib_main_t * vlib_get_main(void)
void nat_ha_sdel(ip4_address_t *out_addr, u16 out_port, ip4_address_t *eh_addr, u16 eh_port, u8 proto, u32 fib_index, u32 thread_index)
Create session delete HA event.
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
#define FIB_NODE_INDEX_INVALID
int nat44_i2o_ed_is_idle_session_cb(clib_bihash_kv_16_8_t *kv, void *arg)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static_always_inline u8 nat_proto_to_ip_proto(nat_protocol_t nat_proto)
VLIB buffer representation.
snat_main_per_thread_data_t * per_thread_data
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
#define ip_csum_update(sum, old, new, type, field)
snat_address_t * addresses
static u32 random_u32(u32 *seed)
32-bit random number generator
#define SNAT_SESSION_FLAG_STATIC_MAPPING
void nat44_ed_hairpinning_unknown_proto(snat_main_t *sm, vlib_buffer_t *b, ip4_header_t *ip)
static_always_inline int nat44_ed_not_translate_output_feature(snat_main_t *sm, ip4_header_t *ip, u16 src_port, u16 dst_port, u32 thread_index, u32 rx_sw_if_index, u32 tx_sw_if_index)
static int nat_ed_alloc_addr_and_port(snat_main_t *sm, u32 rx_fib_index, u32 nat_proto, u32 thread_index, ip4_address_t r_addr, u16 r_port, u8 proto, u16 port_per_thread, u32 snat_thread_index, snat_session_t *s, ip4_address_t *allocated_addr, u16 *allocated_port, clib_bihash_kv_16_8_t *out2in_ed_kv)
#define vec_foreach(var, vec)
Vector iterator.
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
u32 icmp_match_in2out_ed(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b, ip4_header_t *ip, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
u16 flags
Copy of main node flags.
#define is_twice_nat_session(s)
Check if NAT session is twice NAT.
clib_bihash_16_8_t in2out_ed
static_always_inline int nat_lru_free_one(snat_main_t *sm, int thread_index, f64 now)
#define VLIB_NODE_FLAG_TRACE
snat_session_t * sessions
static_always_inline void icmp4_error_set_vnet_buffer(vlib_buffer_t *b, u8 type, u8 code, u32 data)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
static char * nat_in2out_ed_error_strings[]
#define SNAT_SESSION_FLAG_LOAD_BALANCING
static void make_ed_kv(ip4_address_t *l_addr, ip4_address_t *r_addr, u8 proto, u32 fib_index, u16 l_port, u16 r_port, u64 value, clib_bihash_kv_16_8_t *kv)
clib_bihash_8_8_t static_mapping_by_local
static u16 ip_csum_fold(ip_csum_t c)
static uword nat44_ed_in2out_fast_path_node_fn_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int is_output_feature)
static bool tcp_flags_is_init(u8 f)
Check if client initiating TCP connection (received SYN from client)