53 s =
format (s,
"NAT44_OUT2IN: sw_if_index %d, next index %d, session index %d",
64 s =
format (s,
"NAT44_OUT2IN_FAST: sw_if_index %d, next index %d",
77 m = t->
do_handoff ?
"next worker" :
"same worker";
95 s =
format (s,
"NAT44_OUT2IN_REASS: sw_if_index %d, next index %d, status %s",
97 t->
cached ?
"cached" :
"translated");
110 #define foreach_snat_out2in_error \ 111 _(UNSUPPORTED_PROTOCOL, "Unsupported protocol") \ 112 _(OUT2IN_PACKETS, "Good out2in packets processed") \ 113 _(OUT_OF_PORTS, "Out of ports") \ 114 _(BAD_ICMP_TYPE, "unsupported ICMP type") \ 115 _(NO_TRANSLATION, "No translation") \ 116 _(MAX_SESSIONS_EXCEEDED, "Maximum sessions exceeded") \ 117 _(DROP_FRAGMENT, "Drop fragment") \ 118 _(MAX_REASS, "Maximum reassemblies exceeded") \ 119 _(MAX_FRAG, "Maximum fragments per reassembly exceeded")\ 120 _(FQ_CONGESTED, "Handoff frame queue congested") 123 #define _(sym,str) SNAT_OUT2IN_ERROR_##sym, 130 #define _(sym,string) string, 157 static inline snat_session_t *
173 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_MAX_SESSIONS_EXCEEDED];
195 s->outside_address_index = ~0;
205 kv0.
key = s->in2out.as_u64;
211 kv0.
key = s->out2in.as_u64;
219 s->out2in.addr.as_u32,
223 s->in2out.fib_index);
231 icmp46_header_t *icmp0;
236 icmp46_header_t *inner_icmp0;
255 case SNAT_PROTOCOL_ICMP:
256 inner_icmp0 = (icmp46_header_t*)l4_header;
260 case SNAT_PROTOCOL_UDP:
261 case SNAT_PROTOCOL_TCP:
265 return SNAT_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL;
290 u8 *p_dont_translate,
void *d,
void *e)
292 icmp46_header_t *icmp0;
297 snat_session_t *s0 = 0;
298 u8 dont_translate = 0;
313 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL];
337 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
349 (icmp0->type != ICMP4_echo_request || !is_addr_only)))
351 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_BAD_ICMP_TYPE];
369 icmp0->type != ICMP4_echo_request &&
372 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_BAD_ICMP_TYPE];
384 *p_value = s0->in2out;
385 *p_dont_translate = dont_translate;
387 *(snat_session_t**)d = s0;
408 u8 *p_dont_translate,
void *d,
void *e)
410 icmp46_header_t *icmp0;
415 u8 dont_translate = 0;
441 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
447 (icmp0->type != ICMP4_echo_request || !is_addr_only) &&
450 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_BAD_ICMP_TYPE];
459 *p_dont_translate = dont_translate;
466 icmp46_header_t * icmp0,
480 icmp46_header_t *inner_icmp0;
482 u32 new_addr0, old_addr0;
483 u16 old_id0, new_id0;
491 &protocol, &sm0, &dont_translate, d, e);
500 if (checksum0 != 0 && checksum0 != 0xffff)
515 if (icmp0->checksum == 0)
516 icmp0->checksum = 0xffff;
527 sum0 = icmp0->checksum;
548 sum0 = icmp0->checksum;
555 case SNAT_PROTOCOL_ICMP:
556 inner_icmp0 = (icmp46_header_t*)l4_header;
563 sum0 = icmp0->checksum;
568 case SNAT_PROTOCOL_UDP:
569 case SNAT_PROTOCOL_TCP:
574 sum0 = icmp0->checksum;
592 icmp46_header_t * icmp0,
598 snat_session_t ** p_s0)
600 next0 =
icmp_out2in(sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
601 next0, thread_index, p_s0, 0);
602 snat_session_t * s0 = *p_s0;
623 u32 old_addr, new_addr;
651 u32 n_left_from, * from, * to_next;
653 u32 pkts_processed = 0;
662 while (n_left_from > 0)
667 to_next, n_left_to_next);
669 while (n_left_from >= 4 && n_left_to_next >= 2)
675 u32 sw_if_index0, sw_if_index1;
678 u32 new_addr0, old_addr0;
679 u16 new_port0, old_port0;
680 u32 new_addr1, old_addr1;
681 u16 new_port1, old_port1;
684 icmp46_header_t * icmp0, * icmp1;
686 u32 rx_fib_index0, rx_fib_index1;
688 snat_session_t * s0 = 0, * s1 = 0;
706 to_next[0] = bi0 = from[0];
707 to_next[1] = bi1 = from[1];
722 icmp0 = (icmp46_header_t *) udp0;
732 ICMP4_time_exceeded_ttl_exceeded_in_transit,
746 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL];
756 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
757 next0, now, thread_index, &s0);
787 clib_host_to_net_u16(UDP_DST_PORT_dhcp_to_client))))
796 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
828 old_port0 = tcp0->dst_port;
829 tcp0->dst_port = s0->in2out.port;
830 new_port0 = tcp0->dst_port;
832 sum0 = tcp0->checksum;
857 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
874 icmp1 = (icmp46_header_t *) udp1;
884 ICMP4_time_exceeded_ttl_exceeded_in_transit,
898 b1->
error = node->
errors[SNAT_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL];
908 (sm, b1, ip1, icmp1, sw_if_index1, rx_fib_index1, node,
909 next1, now, thread_index, &s1);
939 clib_host_to_net_u16(UDP_DST_PORT_dhcp_to_client))))
948 b1->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
980 old_port1 = tcp1->dst_port;
981 tcp1->dst_port = s1->in2out.port;
982 new_port1 = tcp1->dst_port;
984 sum1 = tcp1->checksum;
1009 && (b1->
flags & VLIB_BUFFER_IS_TRACED)))
1024 to_next, n_left_to_next,
1025 bi0, bi1, next0, next1);
1028 while (n_left_from > 0 && n_left_to_next > 0)
1036 u32 new_addr0, old_addr0;
1037 u16 new_port0, old_port0;
1040 icmp46_header_t * icmp0;
1044 snat_session_t * s0 = 0;
1053 n_left_to_next -= 1;
1062 icmp0 = (icmp46_header_t *) udp0;
1076 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL];
1087 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1096 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
1097 next0, now, thread_index, &s0);
1127 clib_host_to_net_u16(UDP_DST_PORT_dhcp_to_client))))
1136 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
1168 old_port0 = tcp0->dst_port;
1169 tcp0->dst_port = s0->in2out.port;
1170 new_port0 = tcp0->dst_port;
1172 sum0 = tcp0->checksum;
1197 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
1212 to_next, n_left_to_next,
1220 SNAT_OUT2IN_ERROR_OUT2IN_PACKETS,
1227 .name =
"nat44-out2in",
1228 .vector_size =
sizeof (
u32),
1254 u32 n_left_from, *from, *to_next;
1256 u32 pkts_processed = 0;
1262 u32 *fragments_to_drop = 0;
1263 u32 *fragments_to_loopback = 0;
1269 while (n_left_from > 0)
1275 while (n_left_from > 0 && n_left_to_next > 0)
1277 u32 bi0, sw_if_index0, proto0, rx_fib_index0, new_addr0, old_addr0;
1282 nat_reass_ip4_t *reass0;
1287 snat_session_t * s0 = 0;
1288 u16 old_port0, new_port0;
1297 n_left_to_next -= 1;
1309 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_DROP_FRAGMENT];
1323 &fragments_to_drop);
1328 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_MAX_REASS];
1341 if (clib_bihash_search_8_8 (&per_thread_data->
out2in, &kv0, &value0))
1353 == clib_host_to_net_u16(UDP_DST_PORT_dhcp_to_client))))
1363 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
1374 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
1378 reass0->sess_index = s0 - per_thread_data->
sessions;
1379 reass0->thread_index = thread_index;
1385 reass0->sess_index = value0.
value;
1395 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_MAX_FRAG];
1404 reass0->sess_index);
1422 old_port0 = tcp0->dst_port;
1423 tcp0->dst_port = s0->in2out.port;
1424 new_port0 = tcp0->dst_port;
1426 sum0 = tcp0->checksum;
1452 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
1472 to_next, n_left_to_next,
1476 if (n_left_from == 0 &&
vec_len (fragments_to_loopback))
1501 SNAT_OUT2IN_ERROR_OUT2IN_PACKETS,
1505 &node->
errors[SNAT_OUT2IN_ERROR_DROP_FRAGMENT],
1515 .name =
"nat44-out2in-reass",
1516 .vector_size =
sizeof (
u32),
1563 tag = t->
is_slow_path ?
"NAT44_OUT2IN_SLOW_PATH" :
"NAT44_OUT2IN_FAST_PATH";
1565 s =
format (s,
"%s: sw_if_index %d, next index %d, session %d", tag,
1571 static snat_session_t *
1592 b->
error = node->
errors[SNAT_OUT2IN_ERROR_MAX_SESSIONS_EXCEEDED];
1615 s->ext_host_port = e_key.
protocol == SNAT_PROTOCOL_ICMP ? 0 : udp->
src_port;
1620 s->outside_address_index = ~0;
1623 s->in2out.
protocol = s->out2in.protocol;
1630 if (clib_bihash_add_del_16_8 (&tsm->
out2in_ed, &kv, 1))
1638 thread_index, &eh_key,
1643 b->
error = node->
errors[SNAT_OUT2IN_ERROR_OUT_OF_PORTS];
1645 if (clib_bihash_add_del_16_8 (&tsm->
out2in_ed, &kv, 0))
1649 s->ext_host_nat_addr.as_u32 = eh_key.
addr.
as_u32;
1650 s->ext_host_nat_port = eh_key.
port;
1661 if (clib_bihash_add_del_16_8 (&tsm->
in2out_ed, &kv, 1))
1670 icmp46_header_t *icmp0;
1674 void *l4_header = 0;
1675 icmp46_header_t *inner_icmp0;
1682 key0.
proto = IP_PROTOCOL_ICMP;
1697 case SNAT_PROTOCOL_ICMP:
1698 inner_icmp0 = (icmp46_header_t*)l4_header;
1703 case SNAT_PROTOCOL_UDP:
1704 case SNAT_PROTOCOL_TCP:
1718 u16 dst_port,
u32 thread_index)
1725 if (!clib_bihash_search_16_8 (&tsm->
in2out_ed, &kv, &value))
1739 snat_session_t *s = 0;
1743 if (ip->
protocol == IP_PROTOCOL_ICMP)
1748 else if (ip->
protocol == IP_PROTOCOL_UDP || ip->
protocol == IP_PROTOCOL_TCP)
1768 if (!clib_bihash_search_16_8 (&tsm->
in2out_ed, &kv, &value))
1792 s->ext_host_addr = key.
r_addr;
1793 s->ext_host_port = key.
r_port;
1795 s->outside_address_index = ~0;
1796 s->out2in.addr = key.
l_addr;
1797 s->out2in.port = key.
l_port;
1799 s->out2in.fib_index = 0;
1800 s->in2out = s->out2in;
1804 if (clib_bihash_add_del_16_8 (&tsm->
in2out_ed, &kv, 1))
1808 if (ip->
protocol == IP_PROTOCOL_TCP)
1825 u8 * p_dont_translate,
void * d,
void * e)
1827 u32 next = ~0, sw_if_index, rx_fib_index;
1828 icmp46_header_t *icmp;
1832 snat_session_t *s = 0;
1833 u8 dont_translate = 0, is_addr_only;
1842 b->
error = node->
errors[SNAT_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL];
1850 if (clib_bihash_search_16_8 (&tsm->
out2in_ed, &kv, &value))
1868 b->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
1886 (icmp->type != ICMP4_echo_request || !is_addr_only)))
1888 b->
error = node->
errors[SNAT_OUT2IN_ERROR_BAD_ICMP_TYPE];
1895 thread_index, 0, 0);
1906 icmp->type != ICMP4_echo_request &&
1909 b->
error = node->
errors[SNAT_OUT2IN_ERROR_BAD_ICMP_TYPE];
1920 *p_value = s->in2out;
1921 *p_dont_translate = dont_translate;
1923 *(snat_session_t**)d = s;
1927 static snat_session_t *
1940 u32 old_addr, new_addr;
1949 rx_fib_index, 0, 0);
1951 if (!clib_bihash_search_16_8 (&tsm->
out2in_ed, &s_kv, &s_value))
1960 b->
error = node->
errors[SNAT_OUT2IN_ERROR_MAX_SESSIONS_EXCEEDED];
1968 b->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
1996 s->outside_address_index = ~0;
1997 s->out2in.addr.as_u32 = old_addr;
1998 s->out2in.fib_index = rx_fib_index;
1999 s->in2out.addr.as_u32 = new_addr;
2001 s->in2out.port = s->out2in.port = ip->
protocol;
2006 if (clib_bihash_add_del_16_8 (&tsm->
out2in_ed, &s_kv, 1))
2012 if (clib_bihash_add_del_16_8 (&tsm->
in2out_ed, &s_kv, 1))
2037 u32 n_left_from, *from, *to_next, pkts_processed = 0, stats_node_index;
2051 while (n_left_from > 0)
2057 while (n_left_from >= 4 && n_left_to_next >= 2)
2061 u32 next0, sw_if_index0, rx_fib_index0, proto0, old_addr0, new_addr0;
2062 u32 next1, sw_if_index1, rx_fib_index1, proto1, old_addr1, new_addr1;
2063 u16 old_port0, new_port0, old_port1, new_port1;
2067 icmp46_header_t *icmp0, *icmp1;
2068 snat_session_t *s0 = 0, *s1 = 0;
2090 to_next[0] = bi0 = from[0];
2091 to_next[1] = bi1 = from[1];
2095 n_left_to_next -= 2;
2112 ICMP4_time_exceeded_ttl_exceeded_in_transit,
2120 icmp0 = (icmp46_header_t *) udp0;
2128 thread_index, now, vm, node);
2140 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
2141 next0, now, thread_index, &s0);
2147 if (
PREDICT_FALSE (proto0 == ~0 || proto0 == SNAT_PROTOCOL_ICMP))
2155 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_DROP_FRAGMENT];
2164 if (clib_bihash_search_16_8 (&tsm->
out2in_ed, &kv0, &value0))
2175 &twice_nat0, &is_lb0))
2183 clib_host_to_net_u16(UDP_DST_PORT_dhcp_to_client))))
2192 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
2214 twice_nat0, is_lb0);
2248 old_port0 = tcp0->dst_port;
2249 new_port0 = tcp0->dst_port = s0->in2out.port;
2251 sum0 = tcp0->checksum;
2259 s0->ext_host_nat_addr.as_u32,
2264 tcp0->src_port = s0->ext_host_nat_port;
2276 udp0->
src_port = s0->ext_host_nat_port;
2290 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
2316 ICMP4_time_exceeded_ttl_exceeded_in_transit,
2324 icmp1 = (icmp46_header_t *) udp1;
2332 thread_index, now, vm, node);
2344 (sm, b1, ip1, icmp1, sw_if_index1, rx_fib_index1, node,
2345 next1, now, thread_index, &s1);
2351 if (
PREDICT_FALSE (proto1 == ~0 || proto1 == SNAT_PROTOCOL_ICMP))
2359 b1->
error = node->
errors[SNAT_OUT2IN_ERROR_DROP_FRAGMENT];
2368 if (clib_bihash_search_16_8 (&tsm->
out2in_ed, &kv1, &value1))
2379 &twice_nat1, &is_lb1))
2387 clib_host_to_net_u16(UDP_DST_PORT_dhcp_to_client))))
2396 b1->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
2418 twice_nat1, is_lb1);
2452 old_port1 = tcp1->dst_port;
2453 new_port1 = tcp1->dst_port = s1->in2out.port;
2455 sum1 = tcp1->checksum;
2463 s1->ext_host_nat_addr.as_u32,
2468 tcp1->src_port = s1->ext_host_nat_port;
2480 udp1->
src_port = s1->ext_host_nat_port;
2494 && (b1->
flags & VLIB_BUFFER_IS_TRACED)))
2510 to_next, n_left_to_next,
2511 bi0, bi1, next0, next1);
2514 while (n_left_from > 0 && n_left_to_next > 0)
2518 u32 next0, sw_if_index0, rx_fib_index0, proto0, old_addr0, new_addr0;
2519 u16 old_port0, new_port0;
2523 icmp46_header_t * icmp0;
2524 snat_session_t *s0 = 0;
2537 n_left_to_next -= 1;
2552 ICMP4_time_exceeded_ttl_exceeded_in_transit,
2560 icmp0 = (icmp46_header_t *) udp0;
2568 thread_index, now, vm, node);
2580 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
2581 next0, now, thread_index, &s0);
2587 if (
PREDICT_FALSE (proto0 == ~0 || proto0 == SNAT_PROTOCOL_ICMP))
2595 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_DROP_FRAGMENT];
2604 if (clib_bihash_search_16_8 (&tsm->
out2in_ed, &kv0, &value0))
2615 &twice_nat0, &is_lb0))
2623 clib_host_to_net_u16(UDP_DST_PORT_dhcp_to_client))))
2632 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
2654 twice_nat0, is_lb0);
2688 old_port0 = tcp0->dst_port;
2689 new_port0 = tcp0->dst_port = s0->in2out.port;
2691 sum0 = tcp0->checksum;
2699 s0->ext_host_nat_addr.as_u32,
2704 tcp0->src_port = s0->ext_host_nat_port;
2716 udp0->
src_port = s0->ext_host_nat_port;
2730 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
2746 to_next, n_left_to_next,
2754 SNAT_OUT2IN_ERROR_OUT2IN_PACKETS,
2769 .name =
"nat44-ed-out2in",
2770 .vector_size =
sizeof (
u32),
2803 .name =
"nat44-ed-out2in-slowpath",
2804 .vector_size =
sizeof (
u32),
2836 u32 n_left_from, * from, * to_next;
2838 u32 pkts_processed = 0;
2846 while (n_left_from > 0)
2851 to_next, n_left_to_next);
2853 while (n_left_from >= 4 && n_left_to_next >= 2)
2859 u32 sw_if_index0, sw_if_index1;
2863 u16 new_port0, old_port0, old_port1, new_port1;
2870 u32 rx_fib_index0, rx_fib_index1;
2871 icmp46_header_t * icmp0, * icmp1;
2888 to_next[0] = bi0 = from[0];
2889 to_next[1] = bi1 = from[1];
2893 n_left_to_next -= 2;
2908 ICMP4_time_exceeded_ttl_exceeded_in_transit,
2919 icmp0 = (icmp46_header_t *) udp0;
2921 next0 =
icmp_out2in(sm, b0, ip0, icmp0, sw_if_index0,
2922 rx_fib_index0, node, next0, thread_index,
2937 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
2942 clib_net_to_host_u16(tcp0->dst), &new_addr0);
2947 nat_log_info (
"no match src %U:%d dst %U:%d for user %U",
2949 clib_net_to_host_u16 (tcp0->src),
2951 clib_net_to_host_u16 (tcp0->dst),
2954 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
2972 ses0->
state = SNAT_SESSION_TCP_CLOSE_WAIT;
2973 else if (tcp0->flags &
TCP_FLAG_ACK && ses0->
state == SNAT_SESSION_TCP_LAST_ACK)
2976 old_port0 = tcp0->dst;
2977 tcp0->dst = new_port0;
2979 sum0 = tcp0->checksum;
2999 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
3024 ICMP4_time_exceeded_ttl_exceeded_in_transit,
3035 icmp1 = (icmp46_header_t *) udp1;
3037 next1 =
icmp_out2in(sm, b1, ip1, icmp1, sw_if_index1,
3038 rx_fib_index1, node, next1, thread_index,
3053 b1->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
3058 clib_net_to_host_u16(tcp1->dst), &new_addr1);
3063 nat_log_info (
"no match src %U:%d dst %U:%d for user %U",
3065 clib_net_to_host_u16 (tcp1->src),
3067 clib_net_to_host_u16 (tcp1->dst),
3070 b1->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
3073 new_port1 = ses1->in_port;
3087 if (tcp1->flags &
TCP_FLAG_FIN && ses1->state == SNAT_SESSION_TCP_ESTABLISHED)
3088 ses1->state = SNAT_SESSION_TCP_CLOSE_WAIT;
3089 else if (tcp1->flags &
TCP_FLAG_ACK && ses1->state == SNAT_SESSION_TCP_LAST_ACK)
3092 old_port1 = tcp1->dst;
3093 tcp1->dst = new_port1;
3095 sum1 = tcp1->checksum;
3115 && (b1->
flags & VLIB_BUFFER_IS_TRACED)))
3130 to_next, n_left_to_next,
3131 bi0, bi1, next0, next1);
3134 while (n_left_from > 0 && n_left_to_next > 0)
3143 u16 new_port0, old_port0;
3151 icmp46_header_t * icmp0;
3159 n_left_to_next -= 1;
3173 ICMP4_time_exceeded_ttl_exceeded_in_transit,
3184 icmp0 = (icmp46_header_t *) udp0;
3186 next0 =
icmp_out2in(sm, b0, ip0, icmp0, sw_if_index0,
3187 rx_fib_index0, node, next0, thread_index,
3202 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
3207 clib_net_to_host_u16(tcp0->dst), &new_addr0);
3212 nat_log_info (
"no match src %U:%d dst %U:%d for user %U",
3214 clib_net_to_host_u16 (tcp0->src),
3216 clib_net_to_host_u16 (tcp0->dst),
3219 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
3237 ses0->
state = SNAT_SESSION_TCP_CLOSE_WAIT;
3238 else if (tcp0->flags &
TCP_FLAG_ACK && ses0->
state == SNAT_SESSION_TCP_LAST_ACK)
3241 old_port0 = tcp0->dst;
3242 tcp0->dst = new_port0;
3244 sum0 = tcp0->checksum;
3264 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
3279 to_next, n_left_to_next,
3287 SNAT_OUT2IN_ERROR_OUT2IN_PACKETS,
3294 .name =
"nat44-det-out2in",
3295 .vector_size =
sizeof (
u32),
3334 u8 *p_dont_translate,
void *d,
void *e)
3336 icmp46_header_t *icmp0;
3340 u8 dont_translate = 0;
3344 void *l4_header = 0;
3345 icmp46_header_t *inner_icmp0;
3357 protocol = SNAT_PROTOCOL_ICMP;
3372 case SNAT_PROTOCOL_ICMP:
3373 inner_icmp0 = (icmp46_header_t*)l4_header;
3378 case SNAT_PROTOCOL_UDP:
3379 case SNAT_PROTOCOL_TCP:
3384 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL];
3406 clib_net_to_host_u16(key0.
out_port), &new_addr0);
3418 nat_log_info (
"no match src %U:%d dst %U:%d for user %U",
3422 clib_net_to_host_u16 (key0.
out_port),
3424 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
3432 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_BAD_ICMP_TYPE];
3440 *p_proto = protocol;
3443 p_value->
addr = new_addr0;
3447 *p_dont_translate = dont_translate;
3465 u32 n_left_from, *from, *to_next = 0, *to_next_drop = 0;
3473 u32 n_left_to_next_worker = 0, *to_next_worker = 0;
3474 u32 next_worker_index = 0;
3475 u32 current_worker_index = ~0;
3493 while (n_left_from > 0)
3519 if (next_worker_index != current_worker_index)
3523 congested_handoff_queue_by_worker_index);
3534 to_next_drop[0] = bi0;
3537 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_FQ_CONGESTED];
3546 handoff_queue_elt_by_worker_index);
3550 current_worker_index = next_worker_index;
3554 to_next_worker[0] = bi0;
3556 n_left_to_next_worker--;
3558 if (n_left_to_next_worker == 0)
3562 current_worker_index = ~0;
3563 handoff_queue_elt_by_worker_index[next_worker_index] = 0;
3584 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
3603 for (i = 0; i <
vec_len (handoff_queue_elt_by_worker_index); i++)
3605 if (handoff_queue_elt_by_worker_index[i])
3607 hf = handoff_queue_elt_by_worker_index[
i];
3615 handoff_queue_elt_by_worker_index[
i] = 0;
3620 congested_handoff_queue_by_worker_index[
i] =
3624 current_worker_index = ~0;
3630 .name =
"nat44-out2in-worker-handoff",
3631 .vector_size =
sizeof (
u32),
3652 u32 n_left_from, * from, * to_next;
3654 u32 pkts_processed = 0;
3661 while (n_left_from > 0)
3666 to_next, n_left_to_next);
3668 while (n_left_from > 0 && n_left_to_next > 0)
3676 u32 new_addr0, old_addr0;
3677 u16 new_port0, old_port0;
3680 icmp46_header_t * icmp0;
3691 n_left_to_next -= 1;
3698 icmp0 = (icmp46_header_t *) udp0;
3709 ICMP4_time_exceeded_ttl_exceeded_in_transit,
3722 next0 =
icmp_out2in(sm, b0, ip0, icmp0, sw_if_index0,
3723 rx_fib_index0, node, next0, ~0, 0, 0);
3733 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
3738 new_port0 = sm0.
port;
3753 old_port0 = tcp0->dst_port;
3754 tcp0->dst_port = new_port0;
3756 sum0 = tcp0->checksum;
3777 sum0 = tcp0->checksum;
3789 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
3801 to_next, n_left_to_next,
3809 SNAT_OUT2IN_ERROR_OUT2IN_PACKETS,
3816 .name =
"nat44-out2in-fast",
3817 .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)
#define nat_log_info(...)
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_always_inline u8 icmp_is_error_message(icmp46_header_t *icmp)
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.
static snat_session_t * create_session_for_static_mapping_ed(snat_main_t *sm, vlib_buffer_t *b, snat_session_key_t l_key, snat_session_key_t e_key, vlib_node_runtime_t *node, u32 thread_index, twice_nat_type_t twice_nat, u8 is_lb)
static void make_sm_kv(clib_bihash_kv_8_8_t *kv, ip4_address_t *addr, u8 proto, u32 fib_index, u16 port)
int nat_ip4_reass_add_fragment(nat_reass_ip4_t *reass, u32 bi)
Cache fragment.
#define nat_log_warn(...)
static void snat_det_ses_close(snat_det_map_t *dm, snat_det_session_t *ses)
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.
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 vlib_frame_queue_t * is_vlib_frame_queue_congested(u32 frame_queue_index, u32 index, u32 queue_hi_thresh, vlib_frame_queue_t **handoff_queue_by_worker_index)
static u8 * format_nat44_ed_out2in_trace(u8 *s, va_list *args)
static int nat44_set_tcp_session_state_o2i(snat_main_t *sm, snat_session_t *ses, tcp_header_t *tcp, u32 thread_index)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
static uword nat44_ed_out2in_node_fn_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int is_slow_path)
u32 ip4_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
static snat_session_t * nat44_ed_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 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)
ip4_address_t ext_host_addr
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
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, u8 *lb)
Match NAT44 static mapping.
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 u8 maximum_sessions_exceeded(snat_main_t *sm, u32 thread_index)
static uword snat_out2in_worker_handoff_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static void nat44_delete_session(snat_main_t *sm, snat_session_t *ses, u32 thread_index)
static uword nat44_ed_out2in_slow_path_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.
clib_bihash_16_8_t out2in_ed
snat_det_session_t * sessions
static snat_det_map_t * snat_det_map_by_out(snat_main_t *sm, ip4_address_t *out_addr)
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
#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).
#define nat_log_notice(...)
vlib_node_registration_t nat44_ed_out2in_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_out2in_node)
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.
#define VLIB_REGISTER_NODE(x,...)
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
static ip_csum_t ip_incremental_checksum(ip_csum_t sum, void *_data, uword n_bytes)
#define clib_memcpy(a, b, c)
static int ip4_is_first_fragment(ip4_header_t *i)
static void nat44_session_update_counters(snat_session_t *s, f64 now, uword bytes)
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 make_ed_kv(clib_bihash_kv_16_8_t *kv, ip4_address_t *l_addr, ip4_address_t *r_addr, u8 proto, u32 fib_index, u16 l_port, u16 r_port)
u32 icmp_match_out2in_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 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
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)
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
vlib_node_registration_t nat44_out2in_reass_node
(constructor) VLIB_REGISTER_NODE (nat44_out2in_reass_node)
snat_address_t * twice_nat_addresses
static int next_src_nat(snat_main_t *sm, ip4_header_t *ip, u8 proto, u16 src_port, u16 dst_port, u32 thread_index)
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.
struct _vlib_node_registration vlib_node_registration_t
vlib_node_registration_t snat_out2in_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_worker_handoff_node)
#define SNAT_SESSION_FLAG_FWD_BYPASS
static u32 ip_proto_to_snat_proto(u8 ip_proto)
The NAT inline functions.
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)
static void user_session_increment(snat_main_t *sm, snat_user_t *u, u8 is_static)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static char * snat_out2in_error_strings[]
static int nat_out2in_sm_unknown_proto(snat_main_t *sm, vlib_buffer_t *b, ip4_header_t *ip, u32 rx_fib_index)
snat_main_per_thread_data_t * per_thread_data
vlib_node_registration_t nat44_ed_out2in_slowpath_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_out2in_slowpath_node)
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 u8 is_interface_addr(snat_main_t *sm, vlib_node_runtime_t *node, u32 sw_if_index0, u32 ip4_addr)
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 nat44_ed_out2in_fast_path_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
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
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)
u16 flags
Copy of main node flags.
static void nat_send_all_to_node(vlib_main_t *vm, u32 *bi_vector, vlib_node_runtime_t *node, vlib_error_t *error, u32 next)
#define is_twice_nat_session(s)
Check if NAT session is twice NAT.
clib_bihash_16_8_t in2out_ed
void nat_ip4_reass_get_frags(nat_reass_ip4_t *reass, u32 **bi)
Get cached fragments.
NAT plugin virtual fragmentation reassembly.
#define VLIB_NODE_FLAG_TRACE
#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.
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 void create_bypass_for_fwd(snat_main_t *sm, ip4_header_t *ip, u32 rx_fib_index, u32 thread_index)