52 tag = t->
is_slow_path ?
"SNAT_IN2OUT_SLOW_PATH" :
"SNAT_IN2OUT_FAST_PATH";
54 s =
format (s,
"%s: sw_if_index %d, next index %d, session %d", tag,
66 s =
format (s,
"SANT_IN2OUT_FAST: sw_if_index %d, next index %d",
80 m = t->
do_handoff ?
"next worker" :
"same worker";
92 #define foreach_snat_in2out_error \ 93 _(UNSUPPORTED_PROTOCOL, "Unsupported protocol") \ 94 _(IN2OUT_PACKETS, "Good in2out packets processed") \ 95 _(OUT_OF_PORTS, "Out of ports") \ 96 _(BAD_OUTSIDE_FIB, "Outside VRF ID not found") \ 97 _(BAD_ICMP_TYPE, "unsupported ICMP type") \ 98 _(NO_TRANSLATION, "No translation") 101 #define _(sym,str) SNAT_IN2OUT_ERROR_##sym, 108 #define _(sym,string) string, 159 if (sw_if_index == ~0)
169 if ((i->is_inside == 0) && (sw_if_index == i->sw_if_index))
194 if (clib_bihash_search_8_8 (&sm->out2in, &kv0, &value0))
211 snat_session_t ** sessionp,
220 u32 oldest_per_user_translation_list_index;
221 dlist_elt_t * oldest_per_user_translation_list_elt;
226 u32 address_index = ~0;
227 u32 outside_fib_index;
231 p =
hash_get (sm->ip4_main->fib_index_by_table_id, sm->outside_vrf_id);
234 b0->
error = node->
errors[SNAT_IN2OUT_ERROR_BAD_OUTSIDE_FIB];
237 outside_fib_index = p[0];
245 if (clib_bihash_search_8_8 (&sm->user_hash, &kv0, &value0))
248 pool_get (sm->per_thread_data[thread_index].users, u);
249 memset (u, 0,
sizeof (*u));
253 pool_get (sm->per_thread_data[thread_index].list_pool, per_user_list_head_elt);
256 sm->per_thread_data[thread_index].list_pool;
261 kv0.
value = u - sm->per_thread_data[thread_index].users;
264 clib_bihash_add_del_8_8 (&sm->user_hash, &kv0, 1 );
273 if (u->
nsessions >= sm->max_translations_per_user)
277 oldest_per_user_translation_list_index =
281 ASSERT (oldest_per_user_translation_list_index != ~0);
286 oldest_per_user_translation_list_index);
288 oldest_per_user_translation_list_elt =
290 oldest_per_user_translation_list_index);
293 session_index = oldest_per_user_translation_list_elt->
value;
301 kv0.
key = s->in2out.as_u64;
302 if (clib_bihash_add_del_8_8 (&sm->in2out, &kv0, 0 ))
304 kv0.
key = s->out2in.as_u64;
305 if (clib_bihash_add_del_8_8 (&sm->out2in, &kv0, 0 ))
310 s->out2in.addr.as_u32,
314 s->in2out.fib_index);
317 (sm, &s->out2in, s->outside_address_index);
318 s->outside_address_index = ~0;
325 b0->
error = node->
errors[SNAT_IN2OUT_ERROR_OUT_OF_PORTS];
328 s->outside_address_index = address_index;
332 u8 static_mapping = 1;
342 b0->
error = node->
errors[SNAT_IN2OUT_ERROR_OUT_OF_PORTS];
348 pool_get (sm->per_thread_data[thread_index].sessions, s);
349 memset (s, 0,
sizeof (*s));
351 s->outside_address_index = address_index;
364 pool_get (sm->per_thread_data[thread_index].list_pool,
365 per_user_translation_list_elt);
367 per_user_translation_list_elt -
368 sm->per_thread_data[thread_index].list_pool);
370 per_user_translation_list_elt->
value =
371 s - sm->per_thread_data[thread_index].sessions;
372 s->per_user_index = per_user_translation_list_elt -
373 sm->per_thread_data[thread_index].list_pool;
377 s->per_user_list_head_index,
378 per_user_translation_list_elt -
379 sm->per_thread_data[thread_index].list_pool);
385 s->out2in.fib_index = outside_fib_index;
389 kv0.
key = s->in2out.as_u64;
390 kv0.
value = s - sm->per_thread_data[thread_index].sessions;
391 if (clib_bihash_add_del_8_8 (&sm->in2out, &kv0, 1 ))
394 kv0.
key = s->out2in.as_u64;
395 kv0.
value = s - sm->per_thread_data[thread_index].sessions;
397 if (clib_bihash_add_del_8_8 (&sm->out2in, &kv0, 1 ))
401 worker_by_out_key.
addr = s->out2in.addr;
402 worker_by_out_key.
port = s->out2in.port;
403 worker_by_out_key.
fib_index = s->out2in.fib_index;
405 kv0.
value = thread_index;
406 clib_bihash_add_del_8_8 (&sm->worker_by_out, &kv0, 1);
410 s->out2in.addr.as_u32,
414 s->in2out.fib_index);
422 icmp46_header_t *icmp0;
427 icmp46_header_t *inner_icmp0;
446 case SNAT_PROTOCOL_ICMP:
447 inner_icmp0 = (icmp46_header_t*)l4_header;
451 case SNAT_PROTOCOL_UDP:
452 case SNAT_PROTOCOL_TCP:
456 return SNAT_IN2OUT_ERROR_UNSUPPORTED_PROTOCOL;
480 u8 *p_dont_translate,
void *d,
void *e)
483 icmp46_header_t *icmp0;
487 snat_session_t *s0 = 0;
488 u8 dont_translate = 0;
509 if (clib_bihash_search_8_8 (&sm->in2out, &kv0, &value0))
512 IP_PROTOCOL_ICMP, rx_fib_index0)))
520 b0->
error = node->
errors[SNAT_IN2OUT_ERROR_BAD_ICMP_TYPE];
525 next0 =
slow_path (sm, b0, ip0, rx_fib_index0, &key0,
526 &s0, node, next0, thread_index);
534 icmp0->type != ICMP4_echo_reply &&
537 b0->
error = node->
errors[SNAT_IN2OUT_ERROR_BAD_ICMP_TYPE];
549 *p_value = s0->out2in;
550 *p_dont_translate = dont_translate;
552 *(snat_session_t**)d = s0;
572 u8 *p_dont_translate,
void *d,
void *e)
575 icmp46_header_t *icmp0;
580 u8 dont_translate = 0;
602 IP_PROTOCOL_ICMP, rx_fib_index0)))
614 b0->
error = node->
errors[SNAT_IN2OUT_ERROR_NO_TRANSLATION];
620 (icmp0->type != ICMP4_echo_reply || !is_addr_only) &&
623 b0->
error = node->
errors[SNAT_IN2OUT_ERROR_BAD_ICMP_TYPE];
632 *p_dont_translate = dont_translate;
639 icmp46_header_t * icmp0,
653 icmp46_header_t *inner_icmp0;
655 u32 new_addr0, old_addr0;
656 u16 old_id0, new_id0;
663 next0_tmp = sm->icmp_match_in2out_cb(sm, node, thread_index, b0,
664 &protocol, &sm0, &dont_translate, d, e);
697 sum0 = icmp0->checksum;
718 sum0 = icmp0->checksum;
725 case SNAT_PROTOCOL_ICMP:
726 inner_icmp0 = (icmp46_header_t*)l4_header;
733 sum0 = icmp0->checksum;
738 case SNAT_PROTOCOL_UDP:
739 case SNAT_PROTOCOL_TCP:
744 sum0 = icmp0->checksum;
785 u32 new_dst_addr0 = 0, old_dst_addr0, ti = 0, si;
786 u16 new_dst_port0, old_dst_port0;
795 if (clib_bihash_search_8_8 (&sm->out2in, &kv0, &value0))
801 new_dst_port0 = sm0.
port;
808 if (sm->num_workers > 1)
814 if (clib_bihash_search_8_8 (&sm->worker_by_out, &kv0, &value0))
820 ti = sm->num_workers;
823 new_dst_addr0 = s0->in2out.addr.as_u32;
824 new_dst_port0 = s0->in2out.port;
838 old_dst_port0 = tcp0->dst;
843 tcp0->dst = new_dst_port0;
844 sum0 = tcp0->checksum;
861 sum0 = tcp0->checksum;
873 icmp46_header_t * icmp0,
880 snat_session_t ** p_s0)
885 u32 new_dst_addr0 = 0, old_dst_addr0, si, ti = 0;
888 next0 =
icmp_in2out(sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
889 next0, thread_index, p_s0, 0);
890 snat_session_t * s0 = *p_s0;
899 key0.
port = icmp_id0;
905 if (clib_bihash_search_8_8 (&sm->out2in, &kv0, &value0))
917 if (sm->num_workers > 1)
923 if (clib_bihash_search_8_8 (&sm->worker_by_out, &kv0, &value0))
929 ti = sm->num_workers;
932 new_dst_addr0 = s0->in2out.addr.as_u32;
935 sum0 = icmp0->checksum;
954 s0->last_heard = now;
963 s0->per_user_list_head_index,
979 u32 old_addr, new_addr;
987 if (clib_bihash_search_8_8 (&sm->static_mapping_by_local, &kv, &value))
1000 m_key.
fib_index = sm->outside_fib_index;
1002 if (clib_bihash_search_8_8 (&sm->static_mapping_by_external, &kv, &value))
1024 u32 n_left_from, * from, * to_next;
1026 u32 pkts_processed = 0;
1029 u32 stats_node_index;
1039 while (n_left_from > 0)
1044 to_next, n_left_to_next);
1046 while (n_left_from >= 4 && n_left_to_next >= 2)
1051 u32 sw_if_index0, sw_if_index1;
1054 u32 new_addr0, old_addr0, new_addr1, old_addr1;
1055 u16 old_port0, new_port0, old_port1, new_port1;
1058 icmp46_header_t * icmp0, * icmp1;
1060 u32 rx_fib_index0, rx_fib_index1;
1062 snat_session_t * s0 = 0, * s1 = 0;
1080 to_next[0] = bi0 = from[0];
1081 to_next[1] = bi1 = from[1];
1085 n_left_to_next -= 2;
1093 icmp0 = (icmp46_header_t *) udp0;
1096 rx_fib_index0 =
vec_elt (sm->ip4_main->fib_index_by_sw_if_index,
1105 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1125 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0,
1126 node, next0, now, thread_index, &s0);
1132 if (
PREDICT_FALSE (proto0 == ~0 || proto0 == SNAT_PROTOCOL_ICMP))
1146 if (
PREDICT_FALSE (clib_bihash_search_8_8 (&sm->in2out, &kv0, &value0) != 0))
1151 proto0, rx_fib_index0)))
1154 next0 =
slow_path (sm, b0, ip0, rx_fib_index0, &key0,
1155 &s0, node, next0, thread_index);
1182 old_port0 = tcp0->src_port;
1183 tcp0->src_port = s0->out2in.port;
1184 new_port0 = tcp0->src_port;
1186 sum0 = tcp0->checksum;
1206 s0->last_heard = now;
1213 s0->per_user_index);
1215 s0->per_user_list_head_index,
1216 s0->per_user_index);
1230 t->
session_index = s0 - sm->per_thread_data[thread_index].sessions;
1238 icmp1 = (icmp46_header_t *) udp1;
1241 rx_fib_index1 =
vec_elt (sm->ip4_main->fib_index_by_sw_if_index,
1248 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1268 (sm, b1, ip1, icmp1, sw_if_index1, rx_fib_index1, node,
1269 next1, now, thread_index, &s1);
1275 if (
PREDICT_FALSE (proto1 == ~0 || proto1 == SNAT_PROTOCOL_ICMP))
1289 if (
PREDICT_FALSE(clib_bihash_search_8_8 (&sm->in2out, &kv1, &value1) != 0))
1294 proto1, rx_fib_index1)))
1297 next1 =
slow_path (sm, b1, ip1, rx_fib_index1, &key1,
1298 &s1, node, next1, thread_index);
1325 old_port1 = tcp1->src_port;
1326 tcp1->src_port = s1->out2in.port;
1327 new_port1 = tcp1->src_port;
1329 sum1 = tcp1->checksum;
1349 s1->last_heard = now;
1356 s1->per_user_index);
1358 s1->per_user_list_head_index,
1359 s1->per_user_index);
1372 t->
session_index = s1 - sm->per_thread_data[thread_index].sessions;
1379 to_next, n_left_to_next,
1380 bi0, bi1, next0, next1);
1383 while (n_left_from > 0 && n_left_to_next > 0)
1391 u32 new_addr0, old_addr0;
1392 u16 old_port0, new_port0;
1395 icmp46_header_t * icmp0;
1399 snat_session_t * s0 = 0;
1408 n_left_to_next -= 1;
1416 icmp0 = (icmp46_header_t *) udp0;
1419 rx_fib_index0 =
vec_elt (sm->ip4_main->fib_index_by_sw_if_index,
1426 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1446 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
1447 next0, now, thread_index, &s0);
1453 if (
PREDICT_FALSE (proto0 == ~0 || proto0 == SNAT_PROTOCOL_ICMP))
1467 if (clib_bihash_search_8_8 (&sm->in2out, &kv0, &value0))
1472 proto0, rx_fib_index0)))
1475 next0 =
slow_path (sm, b0, ip0, rx_fib_index0, &key0,
1476 &s0, node, next0, thread_index);
1504 old_port0 = tcp0->src_port;
1505 tcp0->src_port = s0->out2in.port;
1506 new_port0 = tcp0->src_port;
1508 sum0 = tcp0->checksum;
1528 s0->last_heard = now;
1535 s0->per_user_index);
1537 s0->per_user_list_head_index,
1538 s0->per_user_index);
1552 t->
session_index = s0 - sm->per_thread_data[thread_index].sessions;
1559 to_next, n_left_to_next,
1567 SNAT_IN2OUT_ERROR_IN2OUT_PACKETS,
1582 .name =
"snat-in2out",
1583 .vector_size =
sizeof (
u32),
1615 .name =
"snat-in2out-slowpath",
1616 .vector_size =
sizeof (
u32),
1646 u32 n_left_from, * from, * to_next;
1648 u32 pkts_processed = 0;
1657 while (n_left_from > 0)
1662 to_next, n_left_to_next);
1664 while (n_left_from >= 4 && n_left_to_next >= 2)
1669 u32 sw_if_index0, sw_if_index1;
1673 u16 old_port0, new_port0, lo_port0, i0;
1674 u16 old_port1, new_port1, lo_port1, i1;
1681 u32 rx_fib_index0, rx_fib_index1;
1682 icmp46_header_t * icmp0, * icmp1;
1699 to_next[0] = bi0 = from[0];
1700 to_next[1] = bi1 = from[1];
1704 n_left_to_next -= 2;
1722 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1733 icmp0 = (icmp46_header_t *) udp0;
1735 next0 =
icmp_in2out(sm, b0, ip0, icmp0, sw_if_index0,
1736 rx_fib_index0, node, next0, thread_index,
1747 b0->
error = node->
errors[SNAT_IN2OUT_ERROR_NO_TRANSLATION];
1761 key0.
out_port = clib_host_to_net_u16 (lo_port0 +
1762 ((i0 + clib_net_to_host_u16 (tcp0->src)) % dm0->
ports_per_host));
1776 ICMP4_destination_unreachable_destination_unreachable_host,
1798 ses0->
state = SNAT_SESSION_TCP_SYN_SENT;
1799 else if (tcp0->flags &
TCP_FLAG_ACK && ses0->
state == SNAT_SESSION_TCP_SYN_SENT)
1800 ses0->
state = SNAT_SESSION_TCP_ESTABLISHED;
1801 else if (tcp0->flags &
TCP_FLAG_FIN && ses0->
state == SNAT_SESSION_TCP_ESTABLISHED)
1802 ses0->
state = SNAT_SESSION_TCP_FIN_WAIT;
1803 else if (tcp0->flags &
TCP_FLAG_ACK && ses0->
state == SNAT_SESSION_TCP_FIN_WAIT)
1805 else if (tcp0->flags &
TCP_FLAG_FIN && ses0->
state == SNAT_SESSION_TCP_CLOSE_WAIT)
1806 ses0->
state = SNAT_SESSION_TCP_LAST_ACK;
1807 else if (tcp0->flags == 0 && ses0->
state == SNAT_SESSION_UNKNOWN)
1808 ses0->
state = SNAT_SESSION_TCP_ESTABLISHED;
1810 old_port0 = tcp0->src;
1811 tcp0->src = new_port0;
1813 sum0 = tcp0->checksum;
1824 ses0->
state = SNAT_SESSION_UDP_ACTIVE;
1832 case SNAT_SESSION_UDP_ACTIVE:
1833 ses0->
expire = now + sm->udp_timeout;
1835 case SNAT_SESSION_TCP_SYN_SENT:
1836 case SNAT_SESSION_TCP_FIN_WAIT:
1837 case SNAT_SESSION_TCP_CLOSE_WAIT:
1838 case SNAT_SESSION_TCP_LAST_ACK:
1839 ses0->
expire = now + sm->tcp_transitory_timeout;
1841 case SNAT_SESSION_TCP_ESTABLISHED:
1842 ses0->
expire = now + sm->tcp_established_timeout;
1872 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1883 icmp1 = (icmp46_header_t *) udp1;
1885 next1 =
icmp_in2out(sm, b1, ip1, icmp1, sw_if_index1,
1886 rx_fib_index1, node, next1, thread_index,
1897 b1->
error = node->
errors[SNAT_IN2OUT_ERROR_NO_TRANSLATION];
1911 key1.
out_port = clib_host_to_net_u16 (lo_port1 +
1912 ((i1 + clib_net_to_host_u16 (tcp1->src)) % dm1->
ports_per_host));
1926 ICMP4_destination_unreachable_destination_unreachable_host,
1933 new_port1 = ses1->out.out_port;
1948 ses1->state = SNAT_SESSION_TCP_SYN_SENT;
1949 else if (tcp1->flags &
TCP_FLAG_ACK && ses1->state == SNAT_SESSION_TCP_SYN_SENT)
1950 ses1->state = SNAT_SESSION_TCP_ESTABLISHED;
1951 else if (tcp1->flags &
TCP_FLAG_FIN && ses1->state == SNAT_SESSION_TCP_ESTABLISHED)
1952 ses1->state = SNAT_SESSION_TCP_FIN_WAIT;
1953 else if (tcp1->flags &
TCP_FLAG_ACK && ses1->state == SNAT_SESSION_TCP_FIN_WAIT)
1955 else if (tcp1->flags &
TCP_FLAG_FIN && ses1->state == SNAT_SESSION_TCP_CLOSE_WAIT)
1956 ses1->state = SNAT_SESSION_TCP_LAST_ACK;
1957 else if (tcp1->flags == 0 && ses1->state == SNAT_SESSION_UNKNOWN)
1958 ses1->state = SNAT_SESSION_TCP_ESTABLISHED;
1960 old_port1 = tcp1->src;
1961 tcp1->src = new_port1;
1963 sum1 = tcp1->checksum;
1974 ses1->state = SNAT_SESSION_UDP_ACTIVE;
1982 case SNAT_SESSION_UDP_ACTIVE:
1983 ses1->expire = now + sm->udp_timeout;
1985 case SNAT_SESSION_TCP_SYN_SENT:
1986 case SNAT_SESSION_TCP_FIN_WAIT:
1987 case SNAT_SESSION_TCP_CLOSE_WAIT:
1988 case SNAT_SESSION_TCP_LAST_ACK:
1989 ses1->expire = now + sm->tcp_transitory_timeout;
1991 case SNAT_SESSION_TCP_ESTABLISHED:
1992 ses1->expire = now + sm->tcp_established_timeout;
2014 to_next, n_left_to_next,
2015 bi0, bi1, next0, next1);
2018 while (n_left_from > 0 && n_left_to_next > 0)
2027 u16 old_port0, new_port0, lo_port0, i0;
2035 icmp46_header_t * icmp0;
2043 n_left_to_next -= 1;
2058 ICMP4_time_exceeded_ttl_exceeded_in_transit,
2069 icmp0 = (icmp46_header_t *) udp0;
2071 next0 =
icmp_in2out(sm, b0, ip0, icmp0, sw_if_index0,
2072 rx_fib_index0, node, next0, thread_index,
2083 b0->
error = node->
errors[SNAT_IN2OUT_ERROR_NO_TRANSLATION];
2097 key0.
out_port = clib_host_to_net_u16 (lo_port0 +
2098 ((i0 + clib_net_to_host_u16 (tcp0->src)) % dm0->
ports_per_host));
2112 ICMP4_destination_unreachable_destination_unreachable_host,
2134 ses0->
state = SNAT_SESSION_TCP_SYN_SENT;
2135 else if (tcp0->flags &
TCP_FLAG_ACK && ses0->
state == SNAT_SESSION_TCP_SYN_SENT)
2136 ses0->
state = SNAT_SESSION_TCP_ESTABLISHED;
2137 else if (tcp0->flags &
TCP_FLAG_FIN && ses0->
state == SNAT_SESSION_TCP_ESTABLISHED)
2138 ses0->
state = SNAT_SESSION_TCP_FIN_WAIT;
2139 else if (tcp0->flags &
TCP_FLAG_ACK && ses0->
state == SNAT_SESSION_TCP_FIN_WAIT)
2141 else if (tcp0->flags &
TCP_FLAG_FIN && ses0->
state == SNAT_SESSION_TCP_CLOSE_WAIT)
2142 ses0->
state = SNAT_SESSION_TCP_LAST_ACK;
2143 else if (tcp0->flags == 0 && ses0->
state == SNAT_SESSION_UNKNOWN)
2144 ses0->
state = SNAT_SESSION_TCP_ESTABLISHED;
2146 old_port0 = tcp0->src;
2147 tcp0->src = new_port0;
2149 sum0 = tcp0->checksum;
2160 ses0->
state = SNAT_SESSION_UDP_ACTIVE;
2168 case SNAT_SESSION_UDP_ACTIVE:
2169 ses0->
expire = now + sm->udp_timeout;
2171 case SNAT_SESSION_TCP_SYN_SENT:
2172 case SNAT_SESSION_TCP_FIN_WAIT:
2173 case SNAT_SESSION_TCP_CLOSE_WAIT:
2174 case SNAT_SESSION_TCP_LAST_ACK:
2175 ses0->
expire = now + sm->tcp_transitory_timeout;
2177 case SNAT_SESSION_TCP_ESTABLISHED:
2178 ses0->
expire = now + sm->tcp_established_timeout;
2200 to_next, n_left_to_next,
2208 SNAT_IN2OUT_ERROR_IN2OUT_PACKETS,
2215 .name =
"snat-det-in2out",
2216 .vector_size =
sizeof (
u32),
2254 u8 *p_dont_translate,
void *d,
void *e)
2257 icmp46_header_t *icmp0;
2262 u8 dont_translate = 0;
2266 void *l4_header = 0;
2267 icmp46_header_t *inner_icmp0;
2283 protocol = SNAT_PROTOCOL_ICMP;
2295 case SNAT_PROTOCOL_ICMP:
2296 inner_icmp0 = (icmp46_header_t*)l4_header;
2300 case SNAT_PROTOCOL_UDP:
2301 case SNAT_PROTOCOL_TCP:
2305 b0->
error = node->
errors[SNAT_IN2OUT_ERROR_UNSUPPORTED_PROTOCOL];
2317 IP_PROTOCOL_ICMP, rx_fib_index0)))
2323 b0->
error = node->
errors[SNAT_IN2OUT_ERROR_NO_TRANSLATION];
2336 IP_PROTOCOL_ICMP, rx_fib_index0)))
2341 if (icmp0->type != ICMP4_echo_request)
2343 b0->
error = node->
errors[SNAT_IN2OUT_ERROR_BAD_ICMP_TYPE];
2349 key0.
out_port = clib_host_to_net_u16 (lo_port0 +
2361 b0->
error = node->
errors[SNAT_IN2OUT_ERROR_OUT_OF_PORTS];
2369 b0->
error = node->
errors[SNAT_IN2OUT_ERROR_BAD_ICMP_TYPE];
2376 ses0->
state = SNAT_SESSION_ICMP_ACTIVE;
2377 ses0->
expire = now + sm->icmp_timeout;
2380 *p_proto = protocol;
2383 p_value->
addr = new_addr0;
2384 p_value->
fib_index = sm->outside_fib_index;
2387 *p_dont_translate = dont_translate;
2405 u32 n_left_from, *from, *to_next = 0;
2412 u32 n_left_to_next_worker = 0, *to_next_worker = 0;
2413 u32 next_worker_index = 0;
2414 u32 current_worker_index = ~0;
2424 sm->first_worker_index + sm->num_workers - 1,
2431 while (n_left_from > 0)
2451 next_worker_index = sm->worker_in2out_cb(ip0, rx_fib_index0);
2457 if (next_worker_index != current_worker_index)
2464 handoff_queue_elt_by_worker_index);
2468 current_worker_index = next_worker_index;
2472 to_next_worker[0] = bi0;
2474 n_left_to_next_worker--;
2476 if (n_left_to_next_worker == 0)
2480 current_worker_index = ~0;
2481 handoff_queue_elt_by_worker_index[next_worker_index] = 0;
2517 for (i = 0; i <
vec_len (handoff_queue_elt_by_worker_index); i++)
2519 if (handoff_queue_elt_by_worker_index[i])
2521 hf = handoff_queue_elt_by_worker_index[
i];
2529 handoff_queue_elt_by_worker_index[
i] = 0;
2534 congested_handoff_queue_by_worker_index[
i] =
2538 current_worker_index = ~0;
2544 .name =
"snat-in2out-worker-handoff",
2545 .vector_size =
sizeof (
u32),
2563 u32 n_left_from, * from, * to_next;
2565 u32 pkts_processed = 0;
2567 u32 stats_node_index;
2575 while (n_left_from > 0)
2580 to_next, n_left_to_next);
2582 while (n_left_from > 0 && n_left_to_next > 0)
2590 u32 new_addr0, old_addr0;
2591 u16 old_port0, new_port0;
2594 icmp46_header_t * icmp0;
2605 n_left_to_next -= 1;
2613 icmp0 = (icmp46_header_t *) udp0;
2622 ICMP4_time_exceeded_ttl_exceeded_in_transit,
2635 next0 =
icmp_in2out(sm, b0, ip0, icmp0, sw_if_index0,
2636 rx_fib_index0, node, next0, ~0, 0, 0);
2646 b0->
error = node->
errors[SNAT_IN2OUT_ERROR_NO_TRANSLATION];
2652 new_port0 = sm0.
port;
2667 old_port0 = tcp0->src_port;
2668 tcp0->src_port = new_port0;
2670 sum0 = tcp0->checksum;
2690 sum0 = tcp0->checksum;
2715 to_next, n_left_to_next,
2723 SNAT_IN2OUT_ERROR_IN2OUT_PACKETS,
2731 .name =
"snat-in2out-fast",
2732 .vector_size =
sizeof (
u32),
ip4_address_t external_addr
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
fib_protocol_t fp_proto
protocol type
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
u32 sessions_per_user_list_head_index
static u8 * format_snat_in2out_trace(u8 *s, va_list *args)
sll srl srl sll sra u16x4 i
static uword snat_in2out_slow_path_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static void clib_dlist_init(dlist_elt_t *pool, u32 index)
static u8 * format_snat_in2out_fast_trace(u8 *s, va_list *args)
u32 icmp_match_in2out_fast(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, 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 packet SNAT translation.
int snat_alloc_outside_address_and_port(snat_main_t *sm, u32 fib_index, snat_session_key_t *k, u32 *address_indexp)
static int ip4_header_bytes(ip4_header_t *i)
static f64 vlib_time_now(vlib_main_t *vm)
static char * snat_in2out_error_strings[]
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 u8 icmp_is_error_message(icmp46_header_t *icmp)
static uword snat_in2out_worker_handoff_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
struct _vlib_node_registration vlib_node_registration_t
static uword snat_in2out_node_fn_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int is_slow_path)
static void snat_det_forward(snat_det_map_t *dm, ip4_address_t *in_addr, ip4_address_t *out_addr, u16 *lo_port)
void snat_ipfix_logging_nat44_ses_delete(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 delete event.
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.
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
struct _tcp_header tcp_header_t
VLIB_NODE_FUNCTION_MULTIARCH(snat_in2out_node, snat_in2out_fast_path_fn)
static void snat_hairpinning(snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0, udp_header_t *udp0, tcp_header_t *tcp0, u32 proto0)
Hairpinning.
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)
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
ip_csum_t ip_incremental_checksum(ip_csum_t sum, void *_data, uword n_bytes)
vlib_node_registration_t snat_in2out_fast_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_fast_node)
ip4_address_t ext_host_addr
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
static uword snat_det_in2out_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Aggregrate type for a prefix.
static u8 * format_snat_in2out_worker_handoff_trace(u8 *s, va_list *args)
static_always_inline u8 is_interface_addr(snat_main_t *sm, vlib_node_runtime_t *node, u32 sw_if_index0, u32 ip4_addr)
static void * ip4_next_header(ip4_header_t *i)
static u32 slow_path(snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0, u32 rx_fib_index0, snat_session_key_t *key0, snat_session_t **sessionp, vlib_node_runtime_t *node, u32 next0, u32 thread_index)
static void snat_in2out_unknown_proto(snat_main_t *sm, vlib_buffer_t *b, ip4_header_t *ip, u32 rx_fib_index)
vlib_node_registration_t snat_in2out_slowpath_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_slowpath_node)
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.
#define foreach_snat_in2out_error
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
deterministic NAT definitions
snat_det_session_t * sessions
static u32 icmp_in2out_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 void clib_dlist_addtail(dlist_elt_t *pool, u32 head_index, u32 new_index)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
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)
#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.
#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).
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)
Match SNAT static mapping.
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)
u32 fib_entry_get_resolving_interface(fib_node_index_t entry_index)
The fine-grained event logger allows lightweight, thread-safe event logging at minimum cost...
u32 icmp_match_in2out_slow(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, 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 packet SNAT translation and create session if needed...
static_always_inline uword vlib_get_thread_index(void)
#define CLIB_PREFETCH(addr, size, type)
vlib_node_registration_t snat_in2out_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_node)
void icmp4_error_set_vnet_buffer(vlib_buffer_t *b, u8 type, u8 code, u32 data)
#define clib_warning(format, args...)
#define VLIB_BUFFER_IS_TRACED
static uword snat_in2out_fast_static_map_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
u32 fib_node_index_t
A typedef of a node index.
8 octet key, 8 octet key value pair
static_always_inline snat_in2out_error_t icmp_get_key(ip4_header_t *ip0, snat_session_key_t *p_key0)
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
u32 icmp_match_in2out_det(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, 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 packet SNAT translation and create session if needed...
#define VLIB_NODE_FLAG_TRACE
static void clib_dlist_remove(dlist_elt_t *pool, u32 index)
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 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.
static snat_det_session_t * snat_det_find_ses_by_in(snat_det_map_t *dm, ip4_address_t *in_addr, u16 in_port, snat_det_out_key_t out_key)
static snat_det_session_t * snat_det_get_ses_by_out(snat_det_map_t *dm, ip4_address_t *in_addr, u64 out_key)
vlib_node_registration_t snat_det_in2out_node
(constructor) VLIB_REGISTER_NODE (snat_det_in2out_node)
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.
#define FIB_NODE_INDEX_INVALID
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static snat_det_map_t * snat_det_map_by_user(snat_main_t *sm, ip4_address_t *user_addr)
vlib_node_registration_t snat_in2out_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_worker_handoff_node)
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
static int snat_not_translate(snat_main_t *sm, vlib_node_runtime_t *node, u32 sw_if_index0, ip4_header_t *ip0, u32 proto0, u32 rx_fib_index0)
#define ip_csum_update(sum, old, new, type, field)
void snat_free_outside_address_and_port(snat_main_t *sm, snat_session_key_t *k, u32 address_index)
static void vlib_put_frame_queue_elt(vlib_frame_queue_elt_t *hf)
static u32 ip_proto_to_snat_proto(u8 ip_proto)
static uword snat_in2out_fast_path_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static void snat_det_ses_close(snat_det_map_t *dm, snat_det_session_t *ses)
#define VLIB_REGISTER_NODE(x,...)
static vlib_thread_main_t * vlib_get_thread_main()
u16 flags
Copy of main node flags.
#define SNAT_SESSION_FLAG_STATIC_MAPPING
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
#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_IS_TRACED: trace this buffer.
static snat_det_session_t * snat_det_ses_create(snat_det_map_t *dm, ip4_address_t *in_addr, u16 in_port, snat_det_out_key_t *out)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
#define snat_is_session_static(s)
Check if SNAT session is created from static mapping.
static u16 ip_csum_fold(ip_csum_t c)
static u32 clib_dlist_remove_head(dlist_elt_t *pool, u32 head_index)
static 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)