57 tag = t->
is_slow_path ?
"NAT44_IN2OUT_SLOW_PATH" :
"NAT44_IN2OUT_FAST_PATH";
59 s =
format (s,
"%s: sw_if_index %d, next index %d, session %d", tag,
63 s =
format (s,
", with-hairpinning");
76 s =
format (s,
"NAT44_IN2OUT_FAST: sw_if_index %d, next index %d",
82 #define foreach_nat44_ei_in2out_error \
83 _ (UNSUPPORTED_PROTOCOL, "unsupported protocol") \
84 _ (OUT_OF_PORTS, "out of ports") \
85 _ (BAD_OUTSIDE_FIB, "outside VRF ID not found") \
86 _ (BAD_ICMP_TYPE, "unsupported ICMP type") \
87 _ (NO_TRANSLATION, "no translation") \
88 _ (MAX_SESSIONS_EXCEEDED, "maximum sessions exceeded") \
89 _ (CANNOT_CREATE_USER, "cannot create NAT user")
93 #define _(sym, str) NAT44_EI_IN2OUT_ERROR_##sym,
100 #define _(sym,string) string,
193 if (clib_bihash_search_8_8 (&
nm->
out2in, &kv0, &value0))
197 u16 placeholder_port;
198 u32 placeholder_fib_index;
201 &placeholder_addr, &placeholder_port,
202 &placeholder_fib_index, 1, 0, 0))
227 if (!clib_bihash_search_8_8 (&
nm->
out2in, &kv0, &value0))
233 if (!clib_bihash_search_8_8 (&
nm->
in2out, &kv0, &value0))
248 #ifndef CLIB_MARCH_VARIANT
254 nat44_ei_session_t *s;
255 u64 sess_timeout_time;
268 if (
ctx->now >= sess_timeout_time)
271 if (clib_bihash_add_del_8_8 (&
nm->
out2in, &s_kv, 0))
275 s->in2out.addr.as_u32,
276 s->out2in.addr.as_u32,
280 s->in2out.fib_index);
283 &s->in2out.addr, s->in2out.port,
284 &s->out2in.addr, s->out2in.port, s->nat_proto);
286 nat_ha_sdel (&s->out2in.addr, s->out2in.port, &s->ext_host_addr,
287 s->ext_host_port, s->nat_proto, s->out2in.fib_index,
292 nm->
addresses,
ctx->thread_index, &s->out2in.addr, s->out2in.port,
310 nat44_ei_session_t *s = 0;
330 b0->
error =
node->errors[NAT44_EI_IN2OUT_ERROR_MAX_SESSIONS_EXCEEDED];
339 nat_proto, &sm_addr, &sm_port,
340 &sm_fib_index, 0, 0, &identity_nat))
348 b0->
error =
node->errors[NAT44_EI_IN2OUT_ERROR_OUT_OF_PORTS];
367 b0->
error =
node->errors[NAT44_EI_IN2OUT_ERROR_CANNOT_CREATE_USER];
382 s->in2out.addr = i2o_addr;
383 s->in2out.port = i2o_port;
384 s->in2out.fib_index = rx_fib_index0;
385 s->nat_proto = nat_proto;
386 s->out2in.addr = sm_addr;
387 s->out2in.port = sm_port;
405 s->out2in.fib_index = outside_fib->
fib_index;
413 s->ext_host_port =
vnet_buffer (b0)->ip.reass.l4_dst_port;
421 if (clib_bihash_add_or_overwrite_stale_8_8 (
427 if (clib_bihash_add_or_overwrite_stale_8_8 (
433 thread_index, s->in2out.addr.as_u32, s->out2in.addr.as_u32, s->nat_proto,
434 s->in2out.port, s->out2in.port, s->in2out.fib_index);
437 s->in2out.port, &s->out2in.addr, s->out2in.port,
440 nat_ha_sadd (&s->in2out.addr, s->in2out.port, &s->out2in.addr,
441 s->out2in.port, &s->ext_host_addr, s->ext_host_port,
442 &s->ext_host_nat_addr, s->ext_host_nat_port, s->nat_proto,
448 #ifndef CLIB_MARCH_VARIANT
453 icmp46_header_t *icmp0;
457 icmp46_header_t *inner_icmp0;
465 *nat_proto = NAT_PROTOCOL_ICMP;
477 case NAT_PROTOCOL_ICMP:
478 inner_icmp0 = (icmp46_header_t *) l4_header;
482 case NAT_PROTOCOL_UDP:
483 case NAT_PROTOCOL_TCP:
487 return NAT44_EI_IN2OUT_ERROR_UNSUPPORTED_PROTOCOL;
513 nat44_ei_session_t **p_s0,
u8 *dont_translate)
518 nat44_ei_session_t *s0 = 0;
537 if (clib_bihash_search_8_8 (&
nm->
in2out, &kv0, &value0))
551 nm,
node, sw_if_index0, ip0, NAT_PROTOCOL_ICMP, *fib_index,
563 b0->
error =
node->errors[NAT44_EI_IN2OUT_ERROR_BAD_ICMP_TYPE];
588 reass.icmp_type_or_tcp_flags)))
590 b0->
error =
node->errors[NAT44_EI_IN2OUT_ERROR_BAD_ICMP_TYPE];
602 *
addr = s0->out2in.addr;
603 *
port = s0->out2in.port;
604 *fib_index = s0->out2in.fib_index;
612 #ifndef CLIB_MARCH_VARIANT
618 nat44_ei_session_t **s0,
u8 *dont_translate)
642 &sm_addr, &sm_port, &sm_fib_index, 0,
646 node, sw_if_index0, ip0, IP_PROTOCOL_ICMP, *fib_index)))
659 b0->
error =
node->errors[NAT44_EI_IN2OUT_ERROR_NO_TRANSLATION];
665 (
vnet_buffer (b0)->
ip.reass.icmp_type_or_tcp_flags != ICMP4_echo_request
667 ICMP4_echo_reply || !is_addr_only)
669 reass.icmp_type_or_tcp_flags)))
671 b0->
error =
node->errors[NAT44_EI_IN2OUT_ERROR_BAD_ICMP_TYPE];
682 icmp46_header_t *icmp0,
u32 sw_if_index0,
685 nat44_ei_session_t **p_s0);
687 #ifndef CLIB_MARCH_VARIANT
690 icmp46_header_t *icmp0,
u32 sw_if_index0,
703 icmp46_header_t *inner_icmp0;
705 u32 new_addr0, old_addr0;
706 u16 old_id0, new_id0;
707 u16 old_checksum0, new_checksum0;
759 if (icmp0->checksum == 0)
760 icmp0->checksum = 0xffff;
771 sum0 = icmp0->checksum;
793 sum0 = icmp0->checksum;
799 old_checksum0 = inner_ip0->
checksum;
804 new_checksum0 = inner_ip0->
checksum;
805 sum0 = icmp0->checksum;
813 case NAT_PROTOCOL_ICMP:
814 inner_icmp0 = (icmp46_header_t *) l4_header;
821 sum0 = icmp0->checksum;
827 case NAT_PROTOCOL_UDP:
828 case NAT_PROTOCOL_TCP:
833 sum0 = icmp0->checksum;
847 &required_thread_index))
851 vnet_buffer (b0)->snat.required_thread_index = required_thread_index;
864 u32 sw_if_index0,
u32 rx_fib_index0,
872 nat44_ei_session_t *s0 = *p_s0;
890 u32 old_addr, new_addr;
899 old_addr =
ip->src_address.as_u32;
919 int is_output_feature)
937 u32 rx_sw_if_index0, rx_sw_if_index1;
938 u32 tx_sw_if_index0, tx_sw_if_index1;
939 u32 cntr_sw_if_index0, cntr_sw_if_index1;
942 u32 new_addr0, old_addr0, new_addr1, old_addr1;
943 u16 old_port0, new_port0, old_port1, new_port1;
946 icmp46_header_t *icmp0, *icmp1;
947 u32 rx_fib_index0, rx_fib_index1;
949 nat44_ei_session_t *s0 = 0, *s1 = 0;
951 u32 iph_offset0 = 0, iph_offset1 = 0;
973 if (is_output_feature)
974 iph_offset0 =
vnet_buffer (b0)->ip.reass.save_rewrite_length;
981 icmp0 = (icmp46_header_t *) udp0;
986 is_output_feature ? tx_sw_if_index0 : rx_sw_if_index0;
996 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1013 node->errors[NAT44_EI_IN2OUT_ERROR_UNSUPPORTED_PROTOCOL];
1025 nm, b0, ip0, icmp0, rx_sw_if_index0, rx_fib_index0,
node,
1057 if (is_output_feature)
1071 (proto0 == NAT_PROTOCOL_UDP
1073 clib_host_to_net_u16
1074 (UDP_DST_PORT_dhcp_to_server))
1081 nm,
node, rx_sw_if_index0, ip0, proto0, rx_fib_index0,
1088 rx_fib_index0, proto0, &s0,
node, next0,
1106 b0->
flags |= VNET_BUFFER_F_IS_NATED;
1111 if (!is_output_feature)
1124 old_port0 =
vnet_buffer (b0)->ip.reass.l4_src_port;
1125 new_port0 = udp0->
src_port = s0->out2in.port;
1126 sum0 = tcp0->checksum;
1148 old_port0 =
vnet_buffer (b0)->ip.reass.l4_src_port;
1174 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
1194 if (is_output_feature)
1195 iph_offset1 =
vnet_buffer (b1)->ip.reass.save_rewrite_length;
1202 icmp1 = (icmp46_header_t *) udp1;
1207 is_output_feature ? tx_sw_if_index1 : rx_sw_if_index1;
1215 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1232 node->errors[NAT44_EI_IN2OUT_ERROR_UNSUPPORTED_PROTOCOL];
1244 nm, b1, ip1, icmp1, rx_sw_if_index1, rx_fib_index1,
node,
1276 if (is_output_feature)
1290 (proto1 == NAT_PROTOCOL_UDP
1292 clib_host_to_net_u16
1293 (UDP_DST_PORT_dhcp_to_server))
1300 nm,
node, rx_sw_if_index1, ip1, proto1, rx_fib_index1,
1307 rx_fib_index1, proto1, &s1,
node, next1,
1325 b1->
flags |= VNET_BUFFER_F_IS_NATED;
1330 if (!is_output_feature)
1342 old_port1 =
vnet_buffer (b1)->ip.reass.l4_src_port;
1343 new_port1 = udp1->
src_port = s1->out2in.port;
1344 sum1 = tcp1->checksum;
1366 old_port1 =
vnet_buffer (b1)->ip.reass.l4_src_port;
1392 && (b1->
flags & VLIB_BUFFER_IS_TRACED)))
1421 u32 rx_sw_if_index0;
1422 u32 tx_sw_if_index0;
1423 u32 cntr_sw_if_index0;
1426 u32 new_addr0, old_addr0;
1427 u16 old_port0, new_port0;
1430 icmp46_header_t *icmp0;
1433 nat44_ei_session_t *s0 = 0;
1435 u32 iph_offset0 = 0;
1441 if (is_output_feature)
1442 iph_offset0 =
vnet_buffer (b0)->ip.reass.save_rewrite_length;
1449 icmp0 = (icmp46_header_t *) udp0;
1454 is_output_feature ? tx_sw_if_index0 : rx_sw_if_index0;
1462 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1479 node->errors[NAT44_EI_IN2OUT_ERROR_UNSUPPORTED_PROTOCOL];
1491 nm, b0, ip0, icmp0, rx_sw_if_index0, rx_fib_index0,
node,
1519 if (clib_bihash_search_8_8 (&
nm->
in2out, &kv0, &value0))
1523 if (is_output_feature)
1537 (proto0 == NAT_PROTOCOL_UDP
1539 clib_host_to_net_u16
1540 (UDP_DST_PORT_dhcp_to_server))
1547 nm,
node, rx_sw_if_index0, ip0, proto0, rx_fib_index0,
1554 rx_fib_index0, proto0, &s0,
node, next0,
1573 b0->
flags |= VNET_BUFFER_F_IS_NATED;
1578 if (!is_output_feature)
1590 old_port0 =
vnet_buffer (b0)->ip.reass.l4_src_port;
1591 new_port0 = udp0->
src_port = s0->out2in.port;
1592 sum0 = tcp0->checksum;
1615 old_port0 =
vnet_buffer (b0)->ip.reass.l4_src_port;
1642 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
1669 return frame->n_vectors;
1680 .name =
"nat44-ei-in2out",
1681 .vector_size =
sizeof (
u32),
1710 .name =
"nat44-ei-in2out-output",
1711 .vector_size =
sizeof (
u32),
1740 .name =
"nat44-ei-in2out-slowpath",
1741 .vector_size =
sizeof (
u32),
1770 .name =
"nat44-ei-in2out-output-slowpath",
1771 .vector_size =
sizeof (
u32),
1819 u32 new_addr0, old_addr0;
1820 u16 old_port0, new_port0;
1823 icmp46_header_t *icmp0;
1837 n_left_to_next -= 1;
1845 icmp0 = (icmp46_header_t *) udp0;
1855 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1869 rx_fib_index0,
node, next0, ~0, 0);
1875 &sm0_addr, &sm0_port, &sm0_fib_index, 0, 0, 0))
1877 b0->
error =
node->errors[NAT44_EI_IN2OUT_ERROR_NO_TRANSLATION];
1882 new_addr0 = sm0_addr.
as_u32;
1883 new_port0 = sm0_port;
1901 sum0 = tcp0->checksum;
1927 sum0 = tcp0->checksum;
1947 0 , &required_thread_index);
1952 required_thread_index;
1958 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
1977 to_next, n_left_to_next,
1988 .name =
"nat44-ei-in2out-fast",
1989 .vector_size =
sizeof (
u32),
2019 .name =
"nat44-ei-in2out-hairpinning-handoff-ip4-lookup",
2020 .vector_size =
sizeof (
u32),
2041 .name =
"nat44-ei-in2out-hairpinning-handoff-interface-output",
2042 .vector_size =
sizeof (
u32),
2084 icmp46_header_t *icmp0;
2094 n_left_to_next -= 1;
2102 icmp0 = (icmp46_header_t *) udp0;
2109 case NAT_PROTOCOL_TCP:
2111 case NAT_PROTOCOL_UDP:
2114 0 , &required_thread_index);
2116 case NAT_PROTOCOL_ICMP:
2119 &required_thread_index));
2121 case NAT_PROTOCOL_OTHER:
2134 (b0->
flags & VLIB_BUFFER_IS_TRACED)))
2152 n_left_to_next, bi0, next0);
2158 return frame->n_vectors;
2168 .name =
"nat44-ei-in2out-hairpinning-finish-ip4-lookup",
2169 .vector_size =
sizeof (
u32),
2194 .name =
"nat44-ei-in2out-hairpinning-finish-interface-output",
2195 .vector_size =
sizeof (
u32),