52 s =
format (s,
"NAT44_OUT2IN: sw_if_index %d, next index %d, session index %d",
63 s =
format (s,
"NAT44_OUT2IN_FAST: sw_if_index %d, next index %d",
76 m = t->
do_handoff ?
"next worker" :
"same worker";
94 s =
format (s,
"NAT44_OUT2IN_REASS: sw_if_index %d, next index %d, status %s",
96 t->
cached ?
"cached" :
"translated");
107 #define foreach_snat_out2in_error \ 108 _(UNSUPPORTED_PROTOCOL, "Unsupported protocol") \ 109 _(OUT2IN_PACKETS, "Good out2in packets processed") \ 110 _(OUT_OF_PORTS, "Out of ports") \ 111 _(BAD_ICMP_TYPE, "unsupported ICMP type") \ 112 _(NO_TRANSLATION, "No translation") \ 113 _(MAX_SESSIONS_EXCEEDED, "Maximum sessions exceeded") \ 114 _(DROP_FRAGMENT, "Drop fragment") \ 115 _(MAX_REASS, "Maximum reassemblies exceeded") \ 116 _(MAX_FRAG, "Maximum fragments per reassembly exceeded") 119 #define _(sym,str) SNAT_OUT2IN_ERROR_##sym, 126 #define _(sym,string) string, 154 static inline snat_session_t *
170 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_MAX_SESSIONS_EXCEEDED];
191 s->outside_address_index = ~0;
201 kv0.
key = s->in2out.as_u64;
207 kv0.
key = s->out2in.as_u64;
215 s->out2in.addr.as_u32,
219 s->in2out.fib_index);
227 icmp46_header_t *icmp0;
232 icmp46_header_t *inner_icmp0;
251 case SNAT_PROTOCOL_ICMP:
252 inner_icmp0 = (icmp46_header_t*)l4_header;
256 case SNAT_PROTOCOL_UDP:
257 case SNAT_PROTOCOL_TCP:
261 return SNAT_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL;
271 icmp46_header_t *icmp0;
276 icmp46_header_t *inner_icmp0;
283 key0.
proto = IP_PROTOCOL_ICMP;
297 case SNAT_PROTOCOL_ICMP:
298 inner_icmp0 = (icmp46_header_t*)l4_header;
302 case SNAT_PROTOCOL_UDP:
303 case SNAT_PROTOCOL_TCP:
342 if (ip->
protocol == IP_PROTOCOL_ICMP)
347 else if (ip->
protocol == IP_PROTOCOL_UDP || ip->
protocol == IP_PROTOCOL_TCP)
368 if (clib_bihash_add_del_16_8 (&sm->
in2out_ed, &kv, 1))
390 u8 *p_dont_translate,
void *d,
void *e)
392 icmp46_header_t *icmp0;
397 snat_session_t *s0 = 0;
398 u8 dont_translate = 0;
413 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL];
437 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
455 (icmp0->type != ICMP4_echo_request || !is_addr_only)))
457 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_BAD_ICMP_TYPE];
475 icmp0->type != ICMP4_echo_request &&
478 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_BAD_ICMP_TYPE];
492 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL];
499 if (!clib_bihash_search_16_8 (&sm->
out2in_ed, &s_kv, &s_value))
516 *p_value = s0->in2out;
517 *p_dont_translate = dont_translate;
519 *(snat_session_t**)d = s0;
540 u8 *p_dont_translate,
void *d,
void *e)
542 icmp46_header_t *icmp0;
547 u8 dont_translate = 0;
573 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
579 (icmp0->type != ICMP4_echo_request || !is_addr_only) &&
582 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_BAD_ICMP_TYPE];
591 *p_dont_translate = dont_translate;
598 icmp46_header_t * icmp0,
612 icmp46_header_t *inner_icmp0;
614 u32 new_addr0, old_addr0;
615 u16 old_id0, new_id0;
623 &protocol, &sm0, &dont_translate, d, e);
632 if (checksum0 != 0 && checksum0 != 0xffff)
647 if (icmp0->checksum == 0)
648 icmp0->checksum = 0xffff;
659 sum0 = icmp0->checksum;
680 sum0 = icmp0->checksum;
687 case SNAT_PROTOCOL_ICMP:
688 inner_icmp0 = (icmp46_header_t*)l4_header;
695 sum0 = icmp0->checksum;
700 case SNAT_PROTOCOL_UDP:
701 case SNAT_PROTOCOL_TCP:
706 sum0 = icmp0->checksum;
724 icmp46_header_t * icmp0,
730 snat_session_t ** p_s0)
732 next0 =
icmp_out2in(sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
733 next0, thread_index, p_s0, 0);
734 snat_session_t * s0 = *p_s0;
738 s0->last_heard = now;
745 s0->per_user_list_head_index,
751 static snat_session_t *
765 u32 old_addr, new_addr;
783 if (!clib_bihash_search_16_8 (&sm->
out2in_ed, &s_kv, &s_value))
792 b->
error = node->
errors[SNAT_OUT2IN_ERROR_MAX_SESSIONS_EXCEEDED];
803 b->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
830 s->outside_address_index = ~0;
831 s->out2in.addr.as_u32 = old_addr;
832 s->out2in.fib_index = rx_fib_index;
833 s->in2out.addr.as_u32 = new_addr;
835 s->in2out.port = s->out2in.port = ip->
protocol;
840 if (clib_bihash_add_del_16_8 (&sm->
out2in_ed, &s_kv, 1))
847 if (clib_bihash_add_del_16_8 (&sm->
in2out_ed, &s_kv, 1))
870 static snat_session_t *
884 snat_session_t *s = 0;
887 u32 old_addr, new_addr;
889 u16 new_port, old_port;
907 if (!clib_bihash_search_16_8 (&sm->
out2in_ed, &s_kv, &s_value))
915 b->
error = node->
errors[SNAT_OUT2IN_ERROR_MAX_SESSIONS_EXCEEDED];
945 s->outside_address_index = ~0;
952 if (clib_bihash_add_del_16_8 (&sm->
out2in_ed, &s_kv, 1))
959 thread_index, &eh_key,
964 b->
error = node->
errors[SNAT_OUT2IN_ERROR_OUT_OF_PORTS];
968 key.
r_port = s->ext_host_nat_port = eh_key.
port;
976 if (clib_bihash_add_del_16_8 (&sm->
in2out_ed, &s_kv, 1))
993 old_port = tcp->dst_port;
994 tcp->dst_port = s->in2out.port;
995 new_port = tcp->dst_port;
1007 tcp->src_port = s->ext_host_nat_port;
1017 udp->
src_port = s->ext_host_nat_port;
1026 s->last_heard = now;
1042 u32 n_left_from, * from, * to_next;
1044 u32 pkts_processed = 0;
1053 while (n_left_from > 0)
1058 to_next, n_left_to_next);
1060 while (n_left_from >= 4 && n_left_to_next >= 2)
1066 u32 sw_if_index0, sw_if_index1;
1069 u32 new_addr0, old_addr0;
1070 u16 new_port0, old_port0;
1071 u32 new_addr1, old_addr1;
1072 u16 new_port1, old_port1;
1075 icmp46_header_t * icmp0, * icmp1;
1077 u32 rx_fib_index0, rx_fib_index1;
1079 snat_session_t * s0 = 0, * s1 = 0;
1097 to_next[0] = bi0 = from[0];
1098 to_next[1] = bi1 = from[1];
1102 n_left_to_next -= 2;
1113 icmp0 = (icmp46_header_t *) udp0;
1123 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1134 thread_index, now, vm, node);
1144 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
1145 next0, now, thread_index, &s0);
1171 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
1176 if (proto0 != SNAT_PROTOCOL_UDP
1178 != clib_host_to_net_u16(UDP_DST_PORT_dhcp_to_client)))
1234 old_port0 = tcp0->dst_port;
1235 tcp0->dst_port = s0->in2out.port;
1236 new_port0 = tcp0->dst_port;
1238 sum0 = tcp0->checksum;
1256 s0->last_heard = now;
1261 s0->per_user_index);
1263 s0->per_user_list_head_index,
1264 s0->per_user_index);
1285 icmp1 = (icmp46_header_t *) udp1;
1295 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1306 thread_index, now, vm, node);
1316 (sm, b1, ip1, icmp1, sw_if_index1, rx_fib_index1, node,
1317 next1, now, thread_index, &s1);
1343 b1->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
1348 if (proto1 != SNAT_PROTOCOL_UDP
1350 != clib_host_to_net_u16(UDP_DST_PORT_dhcp_to_client)))
1406 old_port1 = tcp1->dst_port;
1407 tcp1->dst_port = s1->in2out.port;
1408 new_port1 = tcp1->dst_port;
1410 sum1 = tcp1->checksum;
1428 s1->last_heard = now;
1433 s1->per_user_index);
1435 s1->per_user_list_head_index,
1436 s1->per_user_index);
1455 to_next, n_left_to_next,
1456 bi0, bi1, next0, next1);
1459 while (n_left_from > 0 && n_left_to_next > 0)
1467 u32 new_addr0, old_addr0;
1468 u16 new_port0, old_port0;
1471 icmp46_header_t * icmp0;
1475 snat_session_t * s0 = 0;
1484 n_left_to_next -= 1;
1493 icmp0 = (icmp46_header_t *) udp0;
1504 thread_index, now, vm, node);
1515 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1524 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
1525 next0, now, thread_index, &s0);
1551 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
1556 if (proto0 != SNAT_PROTOCOL_UDP
1558 != clib_host_to_net_u16(UDP_DST_PORT_dhcp_to_client)))
1614 old_port0 = tcp0->dst_port;
1615 tcp0->dst_port = s0->in2out.port;
1616 new_port0 = tcp0->dst_port;
1618 sum0 = tcp0->checksum;
1636 s0->last_heard = now;
1641 s0->per_user_index);
1643 s0->per_user_list_head_index,
1644 s0->per_user_index);
1663 to_next, n_left_to_next,
1671 SNAT_OUT2IN_ERROR_OUT2IN_PACKETS,
1678 .name =
"nat44-out2in",
1679 .vector_size =
sizeof (
u32),
1706 u32 n_left_from, *from, *to_next;
1708 u32 pkts_processed = 0;
1714 u32 *fragments_to_drop = 0;
1715 u32 *fragments_to_loopback = 0;
1721 while (n_left_from > 0)
1727 while (n_left_from > 0 && n_left_to_next > 0)
1729 u32 bi0, sw_if_index0, proto0, rx_fib_index0, new_addr0, old_addr0;
1734 nat_reass_ip4_t *reass0;
1739 snat_session_t * s0 = 0;
1740 u16 old_port0, new_port0;
1749 n_left_to_next -= 1;
1761 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_DROP_FRAGMENT];
1775 &fragments_to_drop);
1780 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_MAX_REASS];
1792 if (clib_bihash_search_8_8 (&per_thread_data->
out2in, &kv0, &value0))
1800 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
1805 if (proto0 != SNAT_PROTOCOL_UDP
1807 != clib_host_to_net_u16(UDP_DST_PORT_dhcp_to_client)))
1828 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
1832 reass0->sess_index = s0 - per_thread_data->
sessions;
1833 reass0->thread_index = thread_index;
1839 reass0->sess_index = value0.
value;
1849 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_MAX_FRAG];
1857 reass0->sess_index);
1875 old_port0 = tcp0->dst_port;
1876 tcp0->dst_port = s0->in2out.port;
1877 new_port0 = tcp0->dst_port;
1879 sum0 = tcp0->checksum;
1898 s0->last_heard = now;
1903 s0->per_user_index);
1905 s0->per_user_list_head_index,
1906 s0->per_user_index);
1930 to_next, n_left_to_next,
1934 if (n_left_from == 0 &&
vec_len (fragments_to_loopback))
1959 SNAT_OUT2IN_ERROR_OUT2IN_PACKETS,
1963 &node->
errors[SNAT_OUT2IN_ERROR_DROP_FRAGMENT],
1973 .name =
"nat44-out2in-reass",
1974 .vector_size =
sizeof (
u32),
2003 u32 n_left_from, * from, * to_next;
2005 u32 pkts_processed = 0;
2013 while (n_left_from > 0)
2018 to_next, n_left_to_next);
2020 while (n_left_from >= 4 && n_left_to_next >= 2)
2026 u32 sw_if_index0, sw_if_index1;
2030 u16 new_port0, old_port0, old_port1, new_port1;
2037 u32 rx_fib_index0, rx_fib_index1;
2038 icmp46_header_t * icmp0, * icmp1;
2055 to_next[0] = bi0 = from[0];
2056 to_next[1] = bi1 = from[1];
2060 n_left_to_next -= 2;
2075 ICMP4_time_exceeded_ttl_exceeded_in_transit,
2086 icmp0 = (icmp46_header_t *) udp0;
2088 next0 =
icmp_out2in(sm, b0, ip0, icmp0, sw_if_index0,
2089 rx_fib_index0, node, next0, thread_index,
2104 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
2109 clib_net_to_host_u16(tcp0->dst), &new_addr0);
2114 clib_warning(
"no match src %U:%d dst %U:%d for user %U",
2116 clib_net_to_host_u16 (tcp0->src),
2118 clib_net_to_host_u16 (tcp0->dst),
2121 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
2139 ses0->
state = SNAT_SESSION_TCP_CLOSE_WAIT;
2140 else if (tcp0->flags &
TCP_FLAG_ACK && ses0->
state == SNAT_SESSION_TCP_LAST_ACK)
2143 old_port0 = tcp0->dst;
2144 tcp0->dst = new_port0;
2146 sum0 = tcp0->checksum;
2191 ICMP4_time_exceeded_ttl_exceeded_in_transit,
2202 icmp1 = (icmp46_header_t *) udp1;
2204 next1 =
icmp_out2in(sm, b1, ip1, icmp1, sw_if_index1,
2205 rx_fib_index1, node, next1, thread_index,
2220 b1->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
2225 clib_net_to_host_u16(tcp1->dst), &new_addr1);
2230 clib_warning(
"no match src %U:%d dst %U:%d for user %U",
2232 clib_net_to_host_u16 (tcp1->src),
2234 clib_net_to_host_u16 (tcp1->dst),
2237 b1->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
2240 new_port1 = ses1->in_port;
2254 if (tcp1->flags &
TCP_FLAG_FIN && ses1->state == SNAT_SESSION_TCP_ESTABLISHED)
2255 ses1->state = SNAT_SESSION_TCP_CLOSE_WAIT;
2256 else if (tcp1->flags &
TCP_FLAG_ACK && ses1->state == SNAT_SESSION_TCP_LAST_ACK)
2259 old_port1 = tcp1->dst;
2260 tcp1->dst = new_port1;
2262 sum1 = tcp1->checksum;
2297 to_next, n_left_to_next,
2298 bi0, bi1, next0, next1);
2301 while (n_left_from > 0 && n_left_to_next > 0)
2310 u16 new_port0, old_port0;
2318 icmp46_header_t * icmp0;
2326 n_left_to_next -= 1;
2340 ICMP4_time_exceeded_ttl_exceeded_in_transit,
2351 icmp0 = (icmp46_header_t *) udp0;
2353 next0 =
icmp_out2in(sm, b0, ip0, icmp0, sw_if_index0,
2354 rx_fib_index0, node, next0, thread_index,
2369 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
2374 clib_net_to_host_u16(tcp0->dst), &new_addr0);
2379 clib_warning(
"no match src %U:%d dst %U:%d for user %U",
2381 clib_net_to_host_u16 (tcp0->src),
2383 clib_net_to_host_u16 (tcp0->dst),
2386 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
2404 ses0->
state = SNAT_SESSION_TCP_CLOSE_WAIT;
2405 else if (tcp0->flags &
TCP_FLAG_ACK && ses0->
state == SNAT_SESSION_TCP_LAST_ACK)
2408 old_port0 = tcp0->dst;
2409 tcp0->dst = new_port0;
2411 sum0 = tcp0->checksum;
2446 to_next, n_left_to_next,
2454 SNAT_OUT2IN_ERROR_OUT2IN_PACKETS,
2461 .name =
"nat44-det-out2in",
2462 .vector_size =
sizeof (
u32),
2502 u8 *p_dont_translate,
void *d,
void *e)
2504 icmp46_header_t *icmp0;
2508 u8 dont_translate = 0;
2512 void *l4_header = 0;
2513 icmp46_header_t *inner_icmp0;
2525 protocol = SNAT_PROTOCOL_ICMP;
2540 case SNAT_PROTOCOL_ICMP:
2541 inner_icmp0 = (icmp46_header_t*)l4_header;
2546 case SNAT_PROTOCOL_UDP:
2547 case SNAT_PROTOCOL_TCP:
2552 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL];
2574 clib_net_to_host_u16(key0.
out_port), &new_addr0);
2586 clib_warning(
"no match src %U:%d dst %U:%d for user %U",
2590 clib_net_to_host_u16 (key0.
out_port),
2592 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
2600 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_BAD_ICMP_TYPE];
2608 *p_proto = protocol;
2611 p_value->
addr = new_addr0;
2615 *p_dont_translate = dont_translate;
2633 u32 n_left_from, *from, *to_next = 0;
2640 u32 n_left_to_next_worker = 0, *to_next_worker = 0;
2641 u32 next_worker_index = 0;
2642 u32 current_worker_index = ~0;
2659 while (n_left_from > 0)
2685 if (next_worker_index != current_worker_index)
2692 handoff_queue_elt_by_worker_index);
2696 current_worker_index = next_worker_index;
2700 to_next_worker[0] = bi0;
2702 n_left_to_next_worker--;
2704 if (n_left_to_next_worker == 0)
2708 current_worker_index = ~0;
2709 handoff_queue_elt_by_worker_index[next_worker_index] = 0;
2745 for (i = 0; i <
vec_len (handoff_queue_elt_by_worker_index); i++)
2747 if (handoff_queue_elt_by_worker_index[i])
2749 hf = handoff_queue_elt_by_worker_index[
i];
2757 handoff_queue_elt_by_worker_index[
i] = 0;
2762 congested_handoff_queue_by_worker_index[
i] =
2766 current_worker_index = ~0;
2772 .name =
"nat44-out2in-worker-handoff",
2773 .vector_size =
sizeof (
u32),
2791 u32 n_left_from, * from, * to_next;
2793 u32 pkts_processed = 0;
2800 while (n_left_from > 0)
2805 to_next, n_left_to_next);
2807 while (n_left_from > 0 && n_left_to_next > 0)
2815 u32 new_addr0, old_addr0;
2816 u16 new_port0, old_port0;
2819 icmp46_header_t * icmp0;
2830 n_left_to_next -= 1;
2837 icmp0 = (icmp46_header_t *) udp0;
2848 ICMP4_time_exceeded_ttl_exceeded_in_transit,
2861 next0 =
icmp_out2in(sm, b0, ip0, icmp0, sw_if_index0,
2862 rx_fib_index0, node, next0, ~0, 0, 0);
2872 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
2877 new_port0 = sm0.
port;
2892 old_port0 = tcp0->dst_port;
2893 tcp0->dst_port = new_port0;
2895 sum0 = tcp0->checksum;
2916 sum0 = tcp0->checksum;
2940 to_next, n_left_to_next,
2948 SNAT_OUT2IN_ERROR_OUT2IN_PACKETS,
2955 .name =
"nat44-out2in-fast",
2956 .vector_size =
sizeof (
u32),
vlib_node_registration_t snat_out2in_fast_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_fast_node)
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
VLIB_NODE_FUNCTION_MULTIARCH(snat_out2in_node, snat_out2in_node_fn)
clib_bihash_16_8_t out2in_ed
sll srl srl sll sra u16x4 i
u32 icmp_match_out2in_slow(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation and create session if needed...
static u8 * format_snat_out2in_fast_trace(u8 *s, va_list *args)
static u32 icmp_out2in_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)
static int ip4_header_bytes(ip4_header_t *i)
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.
int nat_ip4_reass_add_fragment(nat_reass_ip4_t *reass, u32 bi)
Cache fragment.
static void snat_det_ses_close(snat_det_map_t *dm, snat_det_session_t *ses)
struct _vlib_node_registration vlib_node_registration_t
u32 icmp_match_out2in_det(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation and create session if needed...
u32 * fib_index_by_sw_if_index
Table index indexed by software interface.
static snat_session_t * snat_out2in_lb(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)
clib_bihash_16_8_t in2out_ed
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, u8 *twice_nat)
Match NAT44 static mapping.
u32 buffer_index[VLIB_FRAME_SIZE]
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.
struct _tcp_header tcp_header_t
static void snat_det_reverse(snat_det_map_t *dm, ip4_address_t *out_addr, u16 out_port, ip4_address_t *in_addr)
static snat_session_t * snat_out2in_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)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
static void user_session_increment(snat_main_t *sm, snat_user_t *u, u8 is_static)
u32 ip4_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
#define static_always_inline
static uword ip4_header_checksum_is_valid(ip4_header_t *i)
vlib_node_registration_t snat_det_out2in_node
(constructor) VLIB_REGISTER_NODE (snat_det_out2in_node)
ip_csum_t ip_incremental_checksum(ip_csum_t sum, void *_data, uword n_bytes)
ip4_address_t ext_host_addr
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
static void * ip4_next_header(ip4_header_t *i)
#define foreach_snat_out2in_error
static uword nat44_out2in_reass_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static uword snat_out2in_worker_handoff_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static int ip4_is_fragment(ip4_header_t *i)
snat_user_t * nat_user_get_or_create(snat_main_t *sm, ip4_address_t *addr, u32 fib_index, u32 thread_index)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
snat_det_session_t * sessions
static snat_det_map_t * snat_det_map_by_out(snat_main_t *sm, ip4_address_t *out_addr)
static void clib_dlist_addtail(dlist_elt_t *pool, u32 head_index, u32 new_index)
snat_static_mapping_t * static_mappings
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
void snat_ipfix_logging_nat44_ses_create(u32 src_ip, u32 nat_src_ip, snat_protocol_t snat_proto, u16 src_port, u16 nat_src_port, u32 vrf_id)
Generate NAT44 session create event.
static vlib_frame_queue_elt_t * vlib_get_worker_handoff_queue_elt(u32 frame_queue_index, u32 vlib_worker_index, vlib_frame_queue_elt_t **handoff_queue_elt_by_worker_index)
clib_bihash_8_8_t static_mapping_by_external
static int next_src_nat(snat_main_t *sm, ip4_header_t *ip, u32 proto, u16 src_port, u32 thread_index)
#define vlib_validate_buffer_enqueue_x2(vm, node, next_index, to_next, n_left_to_next, bi0, bi1, next0, next1)
Finish enqueueing two buffers forward in the graph.
vlib_node_registration_t snat_out2in_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_node)
#define SNAT_SESSION_FLAG_UNKNOWN_PROTO
static_always_inline void vnet_feature_next(u32 sw_if_index, u32 *next0, vlib_buffer_t *b0)
#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).
vlib_error_t error
Error code for buffers to be enqueued to error handler.
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
static u32 icmp_out2in(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)
The fine-grained event logger allows lightweight, thread-safe event logging at minimum cost...
static snat_session_t * create_session_for_static_mapping(snat_main_t *sm, vlib_buffer_t *b0, snat_session_key_t in2out, snat_session_key_t out2in, vlib_node_runtime_t *node, u32 thread_index)
Create session for static mapping.
static_always_inline uword vlib_get_thread_index(void)
u8 nat_reass_is_drop_frag(u8 is_ip6)
Get status of virtual fragmentation reassembly.
#define CLIB_PREFETCH(addr, size, type)
#define vec_free(V)
Free vector's memory (no header).
void icmp4_error_set_vnet_buffer(vlib_buffer_t *b, u8 type, u8 code, u32 data)
deterministic NAT definitions
#define clib_warning(format, args...)
#define VLIB_BUFFER_IS_TRACED
#define clib_memcpy(a, b, c)
static int ip4_is_first_fragment(ip4_header_t *i)
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 u8 * format_nat44_out2in_reass_trace(u8 *s, va_list *args)
static void create_bypass_for_fwd(snat_main_t *sm, ip4_header_t *ip)
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
snat_get_worker_function_t * worker_out2in_cb
static u32 ip_proto_to_snat_proto(u8 ip_proto)
snat_icmp_match_function_t * icmp_match_out2in_cb
#define SNAT_SESSION_FLAG_TWICE_NAT
static uword snat_det_out2in_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
#define VLIB_NODE_FLAG_TRACE
static void clib_dlist_remove(dlist_elt_t *pool, u32 index)
vlib_node_registration_t nat44_out2in_reass_node
(constructor) VLIB_REGISTER_NODE (nat44_out2in_reass_node)
snat_address_t * twice_nat_addresses
snat_session_t * nat_session_alloc_or_recycle(snat_main_t *sm, snat_user_t *u, u32 thread_index)
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
#define vec_elt(v, i)
Get vector value at index i.
vlib_node_registration_t snat_out2in_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_worker_handoff_node)
int snat_alloc_outside_address_and_port(snat_address_t *addresses, u32 fib_index, u32 thread_index, snat_session_key_t *k, u32 *address_indexp, u16 port_per_thread, u32 snat_thread_index)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static char * snat_out2in_error_strings[]
static_always_inline u8 is_interface_addr(snat_main_t *sm, vlib_node_runtime_t *node, u32 sw_if_index0, u32 ip4_addr)
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)
static_always_inline snat_out2in_error_t icmp_get_key(ip4_header_t *ip0, snat_session_key_t *p_key0)
static u8 * format_snat_out2in_trace(u8 *s, va_list *args)
nat_reass_ip4_t * nat_ip4_reass_find_or_create(ip4_address_t src, ip4_address_t dst, u16 frag_id, u8 proto, u8 reset_timeout, u32 **bi_to_drop)
Find or create reassembly.
static void vlib_put_frame_queue_elt(vlib_frame_queue_elt_t *hf)
static uword snat_out2in_fast_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static snat_det_session_t * snat_det_get_ses_by_out(snat_det_map_t *dm, ip4_address_t *in_addr, u64 out_key)
#define SNAT_SESSION_FLAG_STATIC_MAPPING
#define VLIB_REGISTER_NODE(x,...)
static vlib_thread_main_t * vlib_get_thread_main()
static uword snat_out2in_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static_always_inline void nat_send_all_to_node(vlib_main_t *vm, u32 *bi_vector, vlib_node_runtime_t *node, vlib_error_t *error, u32 next)
u16 flags
Copy of main node flags.
#define is_twice_nat_session(s)
Check if NAT session is twice NAT.
void nat_ip4_reass_get_frags(nat_reass_ip4_t *reass, u32 **bi)
Get cached fragments.
NAT plugin virtual fragmentation reassembly.
#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)
#define CLIB_CACHE_LINE_BYTES
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
static u8 maximum_sessions_exceeded(snat_main_t *sm, u32 thread_index)
snat_session_t * sessions
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
#define SNAT_SESSION_FLAG_LOAD_BALANCING
static u16 ip_csum_fold(ip_csum_t c)
u32 icmp_match_out2in_fast(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation.
static u8 * format_snat_out2in_worker_handoff_trace(u8 *s, va_list *args)
static_always_inline int icmp_get_ed_key(ip4_header_t *ip0, nat_ed_ses_key_t *p_key0)
static_always_inline u8 icmp_is_error_message(icmp46_header_t *icmp)