54 "NAT44_OUT2IN: sw_if_index %d, next index %d, session index %d",
66 s =
format (s,
"NAT44_OUT2IN_FAST: sw_if_index %d, next index %d",
71 #define foreach_nat44_ei_out2in_error \
72 _ (UNSUPPORTED_PROTOCOL, "unsupported protocol") \
73 _ (OUT_OF_PORTS, "out of ports") \
74 _ (BAD_ICMP_TYPE, "unsupported ICMP type") \
75 _ (NO_TRANSLATION, "no translation") \
76 _ (MAX_SESSIONS_EXCEEDED, "maximum sessions exceeded") \
77 _ (CANNOT_CREATE_USER, "cannot create NAT user")
81 #define _(sym, str) NAT44_EI_OUT2IN_ERROR_##sym,
88 #define _(sym,string) string,
101 #ifndef CLIB_MARCH_VARIANT
107 nat44_ei_session_t *s;
108 u64 sess_timeout_time;
121 if (
ctx->now >= sess_timeout_time)
124 if (clib_bihash_add_del_8_8 (&
nm->
in2out, &s_kv, 0))
128 s->in2out.addr.as_u32,
129 s->out2in.addr.as_u32,
133 s->in2out.fib_index);
136 &s->in2out.addr, s->in2out.port,
137 &s->out2in.addr, s->out2in.port, s->nat_proto);
139 nat_ha_sdel (&s->out2in.addr, s->out2in.port, &s->ext_host_addr,
140 s->ext_host_port, s->nat_proto, s->out2in.fib_index,
145 nm->
addresses,
ctx->thread_index, &s->out2in.addr, s->out2in.port,
170 static inline nat44_ei_session_t *
177 nat44_ei_session_t *s;
185 b0->
error =
node->errors[NAT44_EI_OUT2IN_ERROR_MAX_SESSIONS_EXCEEDED];
196 b0->
error =
node->errors[NAT44_EI_OUT2IN_ERROR_CANNOT_CREATE_USER];
212 s->in2out.addr = i2o_addr;
213 s->in2out.port = i2o_port;
214 s->in2out.fib_index = i2o_fib_index;
215 s->out2in.addr = o2i_addr;
216 s->out2in.port = o2i_port;
217 s->out2in.fib_index = o2i_fib_index;
218 s->nat_proto =
proto;
225 if (clib_bihash_add_or_overwrite_stale_8_8 (
231 if (clib_bihash_add_or_overwrite_stale_8_8 (
237 s->in2out.addr.as_u32,
238 s->out2in.addr.as_u32,
241 s->out2in.port, s->in2out.fib_index);
244 &s->in2out.addr, s->in2out.port, &s->out2in.addr,
245 s->out2in.port, s->nat_proto);
247 nat_ha_sadd (&s->in2out.addr, s->in2out.port, &s->out2in.addr,
248 s->out2in.port, &s->ext_host_addr, s->ext_host_port,
249 &s->ext_host_nat_addr, s->ext_host_nat_port,
250 s->nat_proto, s->in2out.fib_index, s->flags,
thread_index, 0);
255 #ifndef CLIB_MARCH_VARIANT
260 icmp46_header_t *icmp0;
264 icmp46_header_t *inner_icmp0;
272 *nat_proto = NAT_PROTOCOL_ICMP;
284 case NAT_PROTOCOL_ICMP:
285 inner_icmp0 = (icmp46_header_t *) l4_header;
289 case NAT_PROTOCOL_UDP:
290 case NAT_PROTOCOL_TCP:
294 return NAT44_EI_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL;
320 nat44_ei_session_t **p_s0,
u8 *dont_translate)
325 nat44_ei_session_t *s0 = 0;
342 b0->
error =
node->errors[NAT44_EI_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL];
349 u32 mapping_fib_index;
352 if (clib_bihash_search_8_8 (&
nm->
out2in, &kv0, &value0))
357 *
addr, *
port, *fib_index, *
proto, &mapping_addr, &mapping_port,
358 &mapping_fib_index, 1, &is_addr_only, &identity_nat))
370 b0->
error =
node->errors[NAT44_EI_OUT2IN_ERROR_NO_TRANSLATION];
385 ICMP4_echo_request || !is_addr_only)))
387 b0->
error =
node->errors[NAT44_EI_OUT2IN_ERROR_BAD_ICMP_TYPE];
399 nm, b0, mapping_addr, mapping_port, mapping_fib_index, *
addr, *
port,
416 reass.icmp_type_or_tcp_flags)))
418 b0->
error =
node->errors[NAT44_EI_OUT2IN_ERROR_BAD_ICMP_TYPE];
430 *
addr = s0->in2out.addr;
431 *
port = s0->in2out.port;
432 *fib_index = s0->in2out.fib_index;
440 #ifndef CLIB_MARCH_VARIANT
445 u16 *mapping_port,
u32 *mapping_fib_index,
447 nat44_ei_session_t **p_s0,
u8 *dont_translate)
470 mapping_addr, mapping_port,
471 mapping_fib_index, 1, &is_addr_only, 0))
480 b0->
error =
node->errors[NAT44_EI_OUT2IN_ERROR_NO_TRANSLATION];
486 (
vnet_buffer (b0)->
ip.reass.icmp_type_or_tcp_flags != ICMP4_echo_reply
488 ICMP4_echo_request || !is_addr_only)
490 reass.icmp_type_or_tcp_flags)))
492 b0->
error =
node->errors[NAT44_EI_OUT2IN_ERROR_BAD_ICMP_TYPE];
503 icmp46_header_t *icmp0,
u32 sw_if_index0,
506 nat44_ei_session_t **p_s0);
508 #ifndef CLIB_MARCH_VARIANT
511 icmp46_header_t *icmp0,
u32 sw_if_index0,
519 icmp46_header_t *inner_icmp0;
521 u32 new_addr0, old_addr0;
522 u16 old_id0, new_id0;
561 if (checksum0 != 0 && checksum0 != 0xffff)
580 if (icmp0->checksum == 0)
581 icmp0->checksum = 0xffff;
592 sum0 = icmp0->checksum;
614 sum0 = icmp0->checksum;
621 case NAT_PROTOCOL_ICMP:
622 inner_icmp0 = (icmp46_header_t *) l4_header;
629 sum0 = icmp0->checksum;
635 case NAT_PROTOCOL_UDP:
636 case NAT_PROTOCOL_TCP:
641 sum0 = icmp0->checksum;
660 u32 sw_if_index0,
u32 rx_fib_index0,
668 nat44_ei_session_t *s0 = *p_s0;
686 u32 old_addr, new_addr;
695 old_addr =
ip->dst_address.as_u32;
726 u32 sw_if_index0, sw_if_index1;
729 u32 new_addr0, old_addr0;
730 u16 new_port0, old_port0;
731 u32 new_addr1, old_addr1;
732 u16 new_port1, old_port1;
735 icmp46_header_t *icmp0, *icmp1;
736 u32 rx_fib_index0, rx_fib_index1;
738 nat44_ei_session_t *s0 = 0, *s1 = 0;
740 u8 identity_nat0, identity_nat1;
742 u16 sm_port0, sm_port1;
743 u32 sm_fib_index0, sm_fib_index1;
771 icmp0 = (icmp46_header_t *) udp0;
781 ICMP4_time_exceeded_ttl_exceeded_in_transit,
796 node->errors[NAT44_EI_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL];
809 nm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0,
node, next0,
now,
819 if (clib_bihash_search_8_8 (&
nm->
out2in, &kv0, &value0))
825 rx_fib_index0, proto0, &sm_addr0, &sm_port0, &sm_fib_index0, 1,
833 (proto0 == NAT_PROTOCOL_UDP
835 clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_client))))
844 node->errors[NAT44_EI_OUT2IN_ERROR_NO_TRANSLATION];
856 vnet_buffer (b0)->
ip.reass.l4_dst_port, rx_fib_index0, proto0,
882 old_port0 =
vnet_buffer (b0)->ip.reass.l4_dst_port;
883 new_port0 = udp0->
dst_port = s0->in2out.port;
884 sum0 = tcp0->checksum;
901 old_port0 =
vnet_buffer (b0)->ip.reass.l4_dst_port;
902 new_port0 = udp0->
dst_port = s0->in2out.port;
927 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
948 icmp1 = (icmp46_header_t *) udp1;
958 ICMP4_time_exceeded_ttl_exceeded_in_transit,
973 node->errors[NAT44_EI_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL];
985 nm, b1, ip1, icmp1, sw_if_index1, rx_fib_index1,
node, next1,
now,
995 if (clib_bihash_search_8_8 (&
nm->
out2in, &kv1, &value1))
1001 rx_fib_index1, proto1, &sm_addr1, &sm_port1, &sm_fib_index1, 1,
1009 (proto1 == NAT_PROTOCOL_UDP
1011 clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_client))))
1020 node->errors[NAT44_EI_OUT2IN_ERROR_NO_TRANSLATION];
1031 nm, b1, sm_addr1, sm_port1, sm_fib_index1, ip1->
dst_address,
1032 vnet_buffer (b1)->
ip.reass.l4_dst_port, rx_fib_index1, proto1,
1058 old_port1 =
vnet_buffer (b1)->ip.reass.l4_dst_port;
1059 new_port1 = udp1->
dst_port = s1->in2out.port;
1061 sum1 = tcp1->checksum;
1078 old_port1 =
vnet_buffer (b1)->ip.reass.l4_dst_port;
1079 new_port1 = udp1->
dst_port = s1->in2out.port;
1107 && (b1->
flags & VLIB_BUFFER_IS_TRACED)))
1137 u32 new_addr0, old_addr0;
1138 u16 new_port0, old_port0;
1141 icmp46_header_t *icmp0;
1144 nat44_ei_session_t *s0 = 0;
1159 icmp0 = (icmp46_header_t *) udp0;
1174 node->errors[NAT44_EI_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL];
1187 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1196 nm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0,
node, next0,
now,
1207 if (clib_bihash_search_8_8 (&
nm->
out2in, &kv0, &value0))
1213 rx_fib_index0, proto0, &sm_addr0, &sm_port0, &sm_fib_index0, 1,
1221 (proto0 == NAT_PROTOCOL_UDP
1223 clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_client))))
1232 node->errors[NAT44_EI_OUT2IN_ERROR_NO_TRANSLATION];
1243 nm, b0, sm_addr0, sm_port0, sm_fib_index0, ip0->
dst_address,
1244 vnet_buffer (b0)->
ip.reass.l4_dst_port, rx_fib_index0, proto0,
1270 old_port0 =
vnet_buffer (b0)->ip.reass.l4_dst_port;
1271 new_port0 = udp0->
dst_port = s0->in2out.port;
1273 sum0 = tcp0->checksum;
1290 old_port0 =
vnet_buffer (b0)->ip.reass.l4_dst_port;
1291 new_port0 = udp0->
dst_port = s0->in2out.port;
1316 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
1346 .name =
"nat44-ei-out2in",
1347 .vector_size =
sizeof (
u32),
1386 u32 new_addr0, old_addr0;
1387 u16 new_port0, old_port0;
1390 icmp46_header_t *icmp0;
1403 icmp0 = (icmp46_header_t *) udp0;
1414 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1428 rx_fib_index0,
node, next0, ~0, 0);
1433 rx_fib_index0, proto0, &sm_addr0,
1434 &sm_port0, &sm_fib_index0, 1, 0, 0))
1436 b0->
error =
node->errors[NAT44_EI_OUT2IN_ERROR_NO_TRANSLATION];
1440 new_addr0 = sm_addr0.
as_u32;
1441 new_port0 = sm_port0;
1458 sum0 = tcp0->checksum;
1483 sum0 = tcp0->checksum;
1502 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
1524 return frame->n_vectors;
1529 .name =
"nat44-ei-out2in-fast",
1530 .vector_size =
sizeof (
u32),