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 sw_if_index0, sw_if_index1;
940 u32 new_addr0, old_addr0, new_addr1, old_addr1;
941 u16 old_port0, new_port0, old_port1, new_port1;
944 icmp46_header_t *icmp0, *icmp1;
945 u32 rx_fib_index0, rx_fib_index1;
947 nat44_ei_session_t *s0 = 0, *s1 = 0;
949 u32 iph_offset0 = 0, iph_offset1 = 0;
971 if (is_output_feature)
972 iph_offset0 =
vnet_buffer (b0)->ip.reass.save_rewrite_length;
979 icmp0 = (icmp46_header_t *) udp0;
991 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1008 node->errors[NAT44_EI_IN2OUT_ERROR_UNSUPPORTED_PROTOCOL];
1020 nm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0,
node, next0,
1052 if (is_output_feature)
1066 (proto0 == NAT_PROTOCOL_UDP
1068 clib_host_to_net_u16
1069 (UDP_DST_PORT_dhcp_to_server))
1076 nm,
node, sw_if_index0, ip0, proto0, rx_fib_index0,
1083 rx_fib_index0, proto0, &s0,
node, next0,
1101 b0->
flags |= VNET_BUFFER_F_IS_NATED;
1106 if (!is_output_feature)
1119 old_port0 =
vnet_buffer (b0)->ip.reass.l4_src_port;
1120 new_port0 = udp0->
src_port = s0->out2in.port;
1121 sum0 = tcp0->checksum;
1143 old_port0 =
vnet_buffer (b0)->ip.reass.l4_src_port;
1169 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
1189 if (is_output_feature)
1190 iph_offset1 =
vnet_buffer (b1)->ip.reass.save_rewrite_length;
1197 icmp1 = (icmp46_header_t *) udp1;
1207 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1224 node->errors[NAT44_EI_IN2OUT_ERROR_UNSUPPORTED_PROTOCOL];
1236 nm, b1, ip1, icmp1, sw_if_index1, rx_fib_index1,
node, next1,
1268 if (is_output_feature)
1282 (proto1 == NAT_PROTOCOL_UDP
1284 clib_host_to_net_u16
1285 (UDP_DST_PORT_dhcp_to_server))
1292 nm,
node, sw_if_index1, ip1, proto1, rx_fib_index1,
1299 rx_fib_index1, proto1, &s1,
node, next1,
1317 b1->
flags |= VNET_BUFFER_F_IS_NATED;
1322 if (!is_output_feature)
1334 old_port1 =
vnet_buffer (b1)->ip.reass.l4_src_port;
1335 new_port1 = udp1->
src_port = s1->out2in.port;
1336 sum1 = tcp1->checksum;
1358 old_port1 =
vnet_buffer (b1)->ip.reass.l4_src_port;
1384 && (b1->
flags & VLIB_BUFFER_IS_TRACED)))
1416 u32 new_addr0, old_addr0;
1417 u16 old_port0, new_port0;
1420 icmp46_header_t *icmp0;
1423 nat44_ei_session_t *s0 = 0;
1425 u32 iph_offset0 = 0;
1431 if (is_output_feature)
1432 iph_offset0 =
vnet_buffer (b0)->ip.reass.save_rewrite_length;
1439 icmp0 = (icmp46_header_t *) udp0;
1449 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1466 node->errors[NAT44_EI_IN2OUT_ERROR_UNSUPPORTED_PROTOCOL];
1478 nm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0,
node, next0,
1506 if (clib_bihash_search_8_8 (&
nm->
in2out, &kv0, &value0))
1510 if (is_output_feature)
1524 (proto0 == NAT_PROTOCOL_UDP
1526 clib_host_to_net_u16
1527 (UDP_DST_PORT_dhcp_to_server))
1534 nm,
node, sw_if_index0, ip0, proto0, rx_fib_index0,
1541 rx_fib_index0, proto0, &s0,
node, next0,
1560 b0->
flags |= VNET_BUFFER_F_IS_NATED;
1565 if (!is_output_feature)
1577 old_port0 =
vnet_buffer (b0)->ip.reass.l4_src_port;
1578 new_port0 = udp0->
src_port = s0->out2in.port;
1579 sum0 = tcp0->checksum;
1602 old_port0 =
vnet_buffer (b0)->ip.reass.l4_src_port;
1629 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
1656 return frame->n_vectors;
1667 .name =
"nat44-ei-in2out",
1668 .vector_size =
sizeof (
u32),
1697 .name =
"nat44-ei-in2out-output",
1698 .vector_size =
sizeof (
u32),
1727 .name =
"nat44-ei-in2out-slowpath",
1728 .vector_size =
sizeof (
u32),
1757 .name =
"nat44-ei-in2out-output-slowpath",
1758 .vector_size =
sizeof (
u32),
1806 u32 new_addr0, old_addr0;
1807 u16 old_port0, new_port0;
1810 icmp46_header_t *icmp0;
1824 n_left_to_next -= 1;
1832 icmp0 = (icmp46_header_t *) udp0;
1842 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1856 rx_fib_index0,
node, next0, ~0, 0);
1862 &sm0_addr, &sm0_port, &sm0_fib_index, 0, 0, 0))
1864 b0->
error =
node->errors[NAT44_EI_IN2OUT_ERROR_NO_TRANSLATION];
1869 new_addr0 = sm0_addr.
as_u32;
1870 new_port0 = sm0_port;
1888 sum0 = tcp0->checksum;
1914 sum0 = tcp0->checksum;
1934 0 , &required_thread_index);
1939 required_thread_index;
1945 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
1964 to_next, n_left_to_next,
1975 .name =
"nat44-ei-in2out-fast",
1976 .vector_size =
sizeof (
u32),
2006 .name =
"nat44-ei-in2out-hairpinning-handoff-ip4-lookup",
2007 .vector_size =
sizeof (
u32),
2028 .name =
"nat44-ei-in2out-hairpinning-handoff-interface-output",
2029 .vector_size =
sizeof (
u32),
2071 icmp46_header_t *icmp0;
2081 n_left_to_next -= 1;
2089 icmp0 = (icmp46_header_t *) udp0;
2096 case NAT_PROTOCOL_TCP:
2098 case NAT_PROTOCOL_UDP:
2101 0 , &required_thread_index);
2103 case NAT_PROTOCOL_ICMP:
2106 &required_thread_index));
2108 case NAT_PROTOCOL_OTHER:
2121 (b0->
flags & VLIB_BUFFER_IS_TRACED)))
2139 n_left_to_next, bi0, next0);
2145 return frame->n_vectors;
2155 .name =
"nat44-ei-in2out-hairpinning-finish-ip4-lookup",
2156 .vector_size =
sizeof (
u32),
2181 .name =
"nat44-ei-in2out-hairpinning-finish-interface-output",
2182 .vector_size =
sizeof (
u32),