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,
u32 rx_fib_index)
1724 rx_fib_index, src_port, dst_port);
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];
1876 thread_index, rx_fib_index))
1887 (icmp->type != ICMP4_echo_request || !is_addr_only)))
1889 b->
error = node->
errors[SNAT_OUT2IN_ERROR_BAD_ICMP_TYPE];
1896 thread_index, 0, 0);
1907 icmp->type != ICMP4_echo_request &&
1910 b->
error = node->
errors[SNAT_OUT2IN_ERROR_BAD_ICMP_TYPE];
1921 *p_value = s->in2out;
1922 *p_dont_translate = dont_translate;
1924 *(snat_session_t**)d = s;
1928 static snat_session_t *
1941 u32 old_addr, new_addr;
1950 rx_fib_index, 0, 0);
1952 if (!clib_bihash_search_16_8 (&tsm->
out2in_ed, &s_kv, &s_value))
1961 b->
error = node->
errors[SNAT_OUT2IN_ERROR_MAX_SESSIONS_EXCEEDED];
1969 b->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
1997 s->outside_address_index = ~0;
1998 s->out2in.addr.as_u32 = old_addr;
1999 s->out2in.fib_index = rx_fib_index;
2000 s->in2out.addr.as_u32 = new_addr;
2002 s->in2out.port = s->out2in.port = ip->
protocol;
2007 if (clib_bihash_add_del_16_8 (&tsm->
out2in_ed, &s_kv, 1))
2013 if (clib_bihash_add_del_16_8 (&tsm->
in2out_ed, &s_kv, 1))
2038 u32 n_left_from, *from, *to_next, pkts_processed = 0, stats_node_index;
2052 while (n_left_from > 0)
2058 while (n_left_from >= 4 && n_left_to_next >= 2)
2062 u32 next0, sw_if_index0, rx_fib_index0, proto0, old_addr0, new_addr0;
2063 u32 next1, sw_if_index1, rx_fib_index1, proto1, old_addr1, new_addr1;
2064 u16 old_port0, new_port0, old_port1, new_port1;
2068 icmp46_header_t *icmp0, *icmp1;
2069 snat_session_t *s0 = 0, *s1 = 0;
2091 to_next[0] = bi0 = from[0];
2092 to_next[1] = bi1 = from[1];
2096 n_left_to_next -= 2;
2113 ICMP4_time_exceeded_ttl_exceeded_in_transit,
2121 icmp0 = (icmp46_header_t *) udp0;
2129 thread_index, now, vm, node);
2141 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
2142 next0, now, thread_index, &s0);
2148 if (
PREDICT_FALSE (proto0 == ~0 || proto0 == SNAT_PROTOCOL_ICMP))
2156 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_DROP_FRAGMENT];
2165 if (clib_bihash_search_16_8 (&tsm->
out2in_ed, &kv0, &value0))
2176 &twice_nat0, &is_lb0))
2184 clib_host_to_net_u16(UDP_DST_PORT_dhcp_to_client))))
2193 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
2200 thread_index, rx_fib_index0))
2215 twice_nat0, is_lb0);
2249 old_port0 = tcp0->dst_port;
2250 new_port0 = tcp0->dst_port = s0->in2out.port;
2252 sum0 = tcp0->checksum;
2260 s0->ext_host_nat_addr.as_u32,
2265 tcp0->src_port = s0->ext_host_nat_port;
2277 udp0->
src_port = s0->ext_host_nat_port;
2291 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
2317 ICMP4_time_exceeded_ttl_exceeded_in_transit,
2325 icmp1 = (icmp46_header_t *) udp1;
2333 thread_index, now, vm, node);
2345 (sm, b1, ip1, icmp1, sw_if_index1, rx_fib_index1, node,
2346 next1, now, thread_index, &s1);
2352 if (
PREDICT_FALSE (proto1 == ~0 || proto1 == SNAT_PROTOCOL_ICMP))
2360 b1->
error = node->
errors[SNAT_OUT2IN_ERROR_DROP_FRAGMENT];
2369 if (clib_bihash_search_16_8 (&tsm->
out2in_ed, &kv1, &value1))
2380 &twice_nat1, &is_lb1))
2388 clib_host_to_net_u16(UDP_DST_PORT_dhcp_to_client))))
2397 b1->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
2404 thread_index, rx_fib_index1))
2419 twice_nat1, is_lb1);
2453 old_port1 = tcp1->dst_port;
2454 new_port1 = tcp1->dst_port = s1->in2out.port;
2456 sum1 = tcp1->checksum;
2464 s1->ext_host_nat_addr.as_u32,
2469 tcp1->src_port = s1->ext_host_nat_port;
2481 udp1->
src_port = s1->ext_host_nat_port;
2495 && (b1->
flags & VLIB_BUFFER_IS_TRACED)))
2511 to_next, n_left_to_next,
2512 bi0, bi1, next0, next1);
2515 while (n_left_from > 0 && n_left_to_next > 0)
2519 u32 next0, sw_if_index0, rx_fib_index0, proto0, old_addr0, new_addr0;
2520 u16 old_port0, new_port0;
2524 icmp46_header_t * icmp0;
2525 snat_session_t *s0 = 0;
2538 n_left_to_next -= 1;
2553 ICMP4_time_exceeded_ttl_exceeded_in_transit,
2561 icmp0 = (icmp46_header_t *) udp0;
2569 thread_index, now, vm, node);
2581 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
2582 next0, now, thread_index, &s0);
2588 if (
PREDICT_FALSE (proto0 == ~0 || proto0 == SNAT_PROTOCOL_ICMP))
2596 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_DROP_FRAGMENT];
2605 if (clib_bihash_search_16_8 (&tsm->
out2in_ed, &kv0, &value0))
2616 &twice_nat0, &is_lb0))
2624 clib_host_to_net_u16(UDP_DST_PORT_dhcp_to_client))))
2633 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
2640 thread_index, rx_fib_index0))
2655 twice_nat0, is_lb0);
2689 old_port0 = tcp0->dst_port;
2690 new_port0 = tcp0->dst_port = s0->in2out.port;
2692 sum0 = tcp0->checksum;
2700 s0->ext_host_nat_addr.as_u32,
2705 tcp0->src_port = s0->ext_host_nat_port;
2717 udp0->
src_port = s0->ext_host_nat_port;
2731 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
2747 to_next, n_left_to_next,
2755 SNAT_OUT2IN_ERROR_OUT2IN_PACKETS,
2770 .name =
"nat44-ed-out2in",
2771 .vector_size =
sizeof (
u32),
2804 .name =
"nat44-ed-out2in-slowpath",
2805 .vector_size =
sizeof (
u32),
2837 u32 n_left_from, * from, * to_next;
2839 u32 pkts_processed = 0;
2847 while (n_left_from > 0)
2852 to_next, n_left_to_next);
2854 while (n_left_from >= 4 && n_left_to_next >= 2)
2860 u32 sw_if_index0, sw_if_index1;
2864 u16 new_port0, old_port0, old_port1, new_port1;
2871 u32 rx_fib_index0, rx_fib_index1;
2872 icmp46_header_t * icmp0, * icmp1;
2889 to_next[0] = bi0 = from[0];
2890 to_next[1] = bi1 = from[1];
2894 n_left_to_next -= 2;
2909 ICMP4_time_exceeded_ttl_exceeded_in_transit,
2920 icmp0 = (icmp46_header_t *) udp0;
2922 next0 =
icmp_out2in(sm, b0, ip0, icmp0, sw_if_index0,
2923 rx_fib_index0, node, next0, thread_index,
2938 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
2943 clib_net_to_host_u16(tcp0->dst), &new_addr0);
2948 nat_log_info (
"no match src %U:%d dst %U:%d for user %U",
2950 clib_net_to_host_u16 (tcp0->src),
2952 clib_net_to_host_u16 (tcp0->dst),
2955 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
2973 ses0->
state = SNAT_SESSION_TCP_CLOSE_WAIT;
2974 else if (tcp0->flags &
TCP_FLAG_ACK && ses0->
state == SNAT_SESSION_TCP_LAST_ACK)
2977 old_port0 = tcp0->dst;
2978 tcp0->dst = new_port0;
2980 sum0 = tcp0->checksum;
3000 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
3025 ICMP4_time_exceeded_ttl_exceeded_in_transit,
3036 icmp1 = (icmp46_header_t *) udp1;
3038 next1 =
icmp_out2in(sm, b1, ip1, icmp1, sw_if_index1,
3039 rx_fib_index1, node, next1, thread_index,
3054 b1->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
3059 clib_net_to_host_u16(tcp1->dst), &new_addr1);
3064 nat_log_info (
"no match src %U:%d dst %U:%d for user %U",
3066 clib_net_to_host_u16 (tcp1->src),
3068 clib_net_to_host_u16 (tcp1->dst),
3071 b1->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
3074 new_port1 = ses1->in_port;
3088 if (tcp1->flags &
TCP_FLAG_FIN && ses1->state == SNAT_SESSION_TCP_ESTABLISHED)
3089 ses1->state = SNAT_SESSION_TCP_CLOSE_WAIT;
3090 else if (tcp1->flags &
TCP_FLAG_ACK && ses1->state == SNAT_SESSION_TCP_LAST_ACK)
3093 old_port1 = tcp1->dst;
3094 tcp1->dst = new_port1;
3096 sum1 = tcp1->checksum;
3116 && (b1->
flags & VLIB_BUFFER_IS_TRACED)))
3131 to_next, n_left_to_next,
3132 bi0, bi1, next0, next1);
3135 while (n_left_from > 0 && n_left_to_next > 0)
3144 u16 new_port0, old_port0;
3152 icmp46_header_t * icmp0;
3160 n_left_to_next -= 1;
3174 ICMP4_time_exceeded_ttl_exceeded_in_transit,
3185 icmp0 = (icmp46_header_t *) udp0;
3187 next0 =
icmp_out2in(sm, b0, ip0, icmp0, sw_if_index0,
3188 rx_fib_index0, node, next0, thread_index,
3203 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
3208 clib_net_to_host_u16(tcp0->dst), &new_addr0);
3213 nat_log_info (
"no match src %U:%d dst %U:%d for user %U",
3215 clib_net_to_host_u16 (tcp0->src),
3217 clib_net_to_host_u16 (tcp0->dst),
3220 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
3238 ses0->
state = SNAT_SESSION_TCP_CLOSE_WAIT;
3239 else if (tcp0->flags &
TCP_FLAG_ACK && ses0->
state == SNAT_SESSION_TCP_LAST_ACK)
3242 old_port0 = tcp0->dst;
3243 tcp0->dst = new_port0;
3245 sum0 = tcp0->checksum;
3265 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
3280 to_next, n_left_to_next,
3288 SNAT_OUT2IN_ERROR_OUT2IN_PACKETS,
3295 .name =
"nat44-det-out2in",
3296 .vector_size =
sizeof (
u32),
3335 u8 *p_dont_translate,
void *d,
void *e)
3337 icmp46_header_t *icmp0;
3341 u8 dont_translate = 0;
3345 void *l4_header = 0;
3346 icmp46_header_t *inner_icmp0;
3358 protocol = SNAT_PROTOCOL_ICMP;
3373 case SNAT_PROTOCOL_ICMP:
3374 inner_icmp0 = (icmp46_header_t*)l4_header;
3379 case SNAT_PROTOCOL_UDP:
3380 case SNAT_PROTOCOL_TCP:
3385 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL];
3407 clib_net_to_host_u16(key0.
out_port), &new_addr0);
3419 nat_log_info (
"no match src %U:%d dst %U:%d for user %U",
3423 clib_net_to_host_u16 (key0.
out_port),
3425 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
3433 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_BAD_ICMP_TYPE];
3441 *p_proto = protocol;
3444 p_value->
addr = new_addr0;
3448 *p_dont_translate = dont_translate;
3466 u32 n_left_from, *from, *to_next = 0, *to_next_drop = 0;
3474 u32 n_left_to_next_worker = 0, *to_next_worker = 0;
3475 u32 next_worker_index = 0;
3476 u32 current_worker_index = ~0;
3494 while (n_left_from > 0)
3520 if (next_worker_index != current_worker_index)
3524 congested_handoff_queue_by_worker_index);
3535 to_next_drop[0] = bi0;
3538 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_FQ_CONGESTED];
3547 handoff_queue_elt_by_worker_index);
3551 current_worker_index = next_worker_index;
3555 to_next_worker[0] = bi0;
3557 n_left_to_next_worker--;
3559 if (n_left_to_next_worker == 0)
3563 current_worker_index = ~0;
3564 handoff_queue_elt_by_worker_index[next_worker_index] = 0;
3585 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
3604 for (i = 0; i <
vec_len (handoff_queue_elt_by_worker_index); i++)
3606 if (handoff_queue_elt_by_worker_index[i])
3608 hf = handoff_queue_elt_by_worker_index[
i];
3616 handoff_queue_elt_by_worker_index[
i] = 0;
3621 congested_handoff_queue_by_worker_index[
i] =
3625 current_worker_index = ~0;
3631 .name =
"nat44-out2in-worker-handoff",
3632 .vector_size =
sizeof (
u32),
3653 u32 n_left_from, * from, * to_next;
3655 u32 pkts_processed = 0;
3662 while (n_left_from > 0)
3667 to_next, n_left_to_next);
3669 while (n_left_from > 0 && n_left_to_next > 0)
3677 u32 new_addr0, old_addr0;
3678 u16 new_port0, old_port0;
3681 icmp46_header_t * icmp0;
3692 n_left_to_next -= 1;
3699 icmp0 = (icmp46_header_t *) udp0;
3710 ICMP4_time_exceeded_ttl_exceeded_in_transit,
3723 next0 =
icmp_out2in(sm, b0, ip0, icmp0, sw_if_index0,
3724 rx_fib_index0, node, next0, ~0, 0, 0);
3734 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
3739 new_port0 = sm0.
port;
3754 old_port0 = tcp0->dst_port;
3755 tcp0->dst_port = new_port0;
3757 sum0 = tcp0->checksum;
3778 sum0 = tcp0->checksum;
3790 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
3802 to_next, n_left_to_next,
3810 SNAT_OUT2IN_ERROR_OUT2IN_PACKETS,
3817 .name =
"nat44-out2in-fast",
3818 .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)
#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.
static int next_src_nat(snat_main_t *sm, ip4_header_t *ip, u8 proto, u16 src_port, u16 dst_port, u32 thread_index, u32 rx_fib_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,...)
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
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)
int nat_ip4_reass_add_fragment(nat_reass_ip4_t *reass, u32 bi, u32 **bi_to_drop)
Cache fragment.
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)