#include <vppinfra/hash.h>
#include <vppinfra/error.h>
#include <vppinfra/elog.h>
+#include <nat/lib/nat_inlines.h>
typedef struct
{
u32 next_index;
u32 session_index;
u32 is_slow_path;
+ u32 is_hairpinning;
} snat_in2out_trace_t;
/* packet trace format function */
s = format (s, "%s: sw_if_index %d, next index %d, session %d", tag,
t->sw_if_index, t->next_index, t->session_index);
+ if (t->is_hairpinning)
+ {
+ s = format (s, ", with-hairpinning");
+ }
return s;
}
if (!icmp_type_is_error_message
(vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags))
{
- key0.protocol = SNAT_PROTOCOL_ICMP;
+ key0.protocol = NAT_PROTOCOL_ICMP;
key0.addr = ip0->src_address;
- key0.port = vnet_buffer (b)->ip.reass.l4_src_port; // TODO fixme should this be dst port?
+ key0.port = vnet_buffer (b)->ip.reass.l4_src_port;
}
else
{
inner_ip0 = (ip4_header_t *) (echo0 + 1);
l4_header = ip4_next_header (inner_ip0);
- key0.protocol = ip_proto_to_snat_proto (inner_ip0->protocol);
+ key0.protocol = ip_proto_to_nat_proto (inner_ip0->protocol);
key0.addr = inner_ip0->dst_address;
switch (key0.protocol)
{
- case SNAT_PROTOCOL_ICMP:
+ case NAT_PROTOCOL_ICMP:
inner_icmp0 = (icmp46_header_t *) l4_header;
inner_echo0 = (icmp_echo_header_t *) (inner_icmp0 + 1);
key0.port = inner_echo0->identifier;
break;
- case SNAT_PROTOCOL_UDP:
- case SNAT_PROTOCOL_TCP:
+ case NAT_PROTOCOL_UDP:
+ case NAT_PROTOCOL_TCP:
key0.port = ((tcp_udp_header_t *) l4_header)->dst_port;
break;
default:
snat_session_key_t * p_value,
u8 * p_dont_translate, void *d, void *e)
{
+ snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
u32 sw_if_index0;
u32 rx_fib_index0;
snat_session_key_t key0;
clib_bihash_kv_8_8_t kv0, value0;
u32 next0 = ~0;
int err;
+ vlib_main_t *vm = vlib_get_main ();
sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
rx_fib_index0 = ip4_fib_table_get_index_for_sw_if_index (sw_if_index0);
kv0.key = key0.as_u64;
- if (clib_bihash_search_8_8 (&sm->per_thread_data[thread_index].in2out, &kv0,
- &value0))
+ if (clib_bihash_search_8_8 (&tsm->in2out, &kv0, &value0))
{
if (vnet_buffer (b0)->sw_if_index[VLIB_TX] != ~0)
{
else
{
if (PREDICT_FALSE (snat_not_translate (sm, node, sw_if_index0,
- ip0, SNAT_PROTOCOL_ICMP,
+ ip0, NAT_PROTOCOL_ICMP,
rx_fib_index0,
thread_index)))
{
}
next0 = slow_path (sm, b0, ip0, rx_fib_index0, &key0, &s0, node, next0,
- thread_index, vlib_time_now (sm->vlib_main));
+ thread_index, vlib_time_now (vm));
if (PREDICT_FALSE (next0 == SNAT_IN2OUT_NEXT_DROP))
goto out;
goto out;
}
- s0 = pool_elt_at_index (sm->per_thread_data[thread_index].sessions,
- value0.value);
+ s0 = pool_elt_at_index (tsm->sessions, value0.value);
}
out:
vlib_node_runtime_t * node,
u32 next0, u32 thread_index, void *d, void *e)
{
+ vlib_main_t *vm = vlib_get_main ();
snat_session_key_t sm0;
u8 protocol;
icmp_echo_header_t *echo0, *inner_echo0 = 0;
if (PREDICT_TRUE (!ip4_is_fragment (ip0)))
{
- sum0 = ip_incremental_checksum_buffer (sm->vlib_main, b0, (u8 *) icmp0 -
- (u8 *)
- vlib_buffer_get_current (b0),
- ntohs (ip0->length) -
- ip4_header_bytes (ip0), 0);
+ sum0 =
+ ip_incremental_checksum_buffer (vm, b0,
+ (u8 *) icmp0 -
+ (u8 *) vlib_buffer_get_current (b0),
+ ntohs (ip0->length) -
+ ip4_header_bytes (ip0), 0);
checksum0 = ~ip_csum_fold (sum0);
if (PREDICT_FALSE (checksum0 != 0 && checksum0 != 0xffff))
{
switch (protocol)
{
- case SNAT_PROTOCOL_ICMP:
+ case NAT_PROTOCOL_ICMP:
inner_icmp0 = (icmp46_header_t *) l4_header;
inner_echo0 = (icmp_echo_header_t *) (inner_icmp0 + 1);
identifier);
icmp0->checksum = ip_csum_fold (sum0);
break;
- case SNAT_PROTOCOL_UDP:
- case SNAT_PROTOCOL_TCP:
+ case NAT_PROTOCOL_UDP:
+ case NAT_PROTOCOL_TCP:
old_id0 = ((tcp_udp_header_t *) l4_header)->dst_port;
new_id0 = sm0.port;
((tcp_udp_header_t *) l4_header)->dst_port = new_id0;
u32 next0,
f64 now, u32 thread_index, snat_session_t ** p_s0)
{
+ vlib_main_t *vm = vlib_get_main ();
+
next0 = icmp_in2out (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
next0, thread_index, p_s0, 0);
snat_session_t *s0 = *p_s0;
/* Accounting */
nat44_session_update_counters (s0, now,
vlib_buffer_length_in_chain
- (sm->vlib_main, b0), thread_index);
+ (vm, b0), thread_index);
/* Per-user LRU list maintenance */
nat44_session_update_lru (sm, s0, thread_index);
}
goto trace00;
}
- proto0 = ip_proto_to_snat_proto (ip0->protocol);
+ proto0 = ip_proto_to_nat_proto (ip0->protocol);
/* Next configured feature, probably ip4-lookup */
if (is_slow_path)
{
- if (PREDICT_FALSE (proto0 == ~0))
+ if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
{
if (nat_in2out_sm_unknown_proto
(sm, b0, ip0, rx_fib_index0))
goto trace00;
}
- if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP))
+ if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
{
next0 = icmp_in2out_slow_path
(sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0,
}
else
{
- if (PREDICT_FALSE (proto0 == ~0))
+ if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
{
next0 = SNAT_IN2OUT_NEXT_SLOW_PATH;
goto trace00;
}
- if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP))
+ if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
{
next0 = SNAT_IN2OUT_NEXT_SLOW_PATH;
goto trace00;
* be able to use dhcp client on the outside interface
*/
if (PREDICT_FALSE
- (proto0 == SNAT_PROTOCOL_UDP
+ (proto0 == NAT_PROTOCOL_UDP
&& (vnet_buffer (b0)->ip.reass.l4_dst_port ==
clib_host_to_net_u16
(UDP_DST_PORT_dhcp_to_server))
ip0->checksum = ip_csum_fold (sum0);
- if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
+ if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
{
if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
{
sum0 = ip_csum_update (sum0, old_port0, new_port0,
ip4_header_t /* cheat */ ,
length /* changed member */ );
- mss_clamping (sm, tcp0, &sum0);
+ mss_clamping (sm->mss_clamping, tcp0, &sum0);
tcp0->checksum = ip_csum_fold (sum0);
}
tcp_packets++;
{
if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
{
+ udp0->src_port = s0->out2in.port;
if (PREDICT_FALSE (udp0->checksum))
{
old_port0 = vnet_buffer (b0)->ip.reass.l4_src_port;
- new_port0 = udp0->src_port = s0->out2in.port;
+ new_port0 = udp0->src_port;
sum0 = udp0->checksum;
sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t, dst_address /* changed member */
);
goto trace01;
}
- proto1 = ip_proto_to_snat_proto (ip1->protocol);
+ proto1 = ip_proto_to_nat_proto (ip1->protocol);
/* Next configured feature, probably ip4-lookup */
if (is_slow_path)
{
- if (PREDICT_FALSE (proto1 == ~0))
+ if (PREDICT_FALSE (proto1 == NAT_PROTOCOL_OTHER))
{
if (nat_in2out_sm_unknown_proto
(sm, b1, ip1, rx_fib_index1))
goto trace01;
}
- if (PREDICT_FALSE (proto1 == SNAT_PROTOCOL_ICMP))
+ if (PREDICT_FALSE (proto1 == NAT_PROTOCOL_ICMP))
{
next1 = icmp_in2out_slow_path
(sm, b1, ip1, icmp1, sw_if_index1, rx_fib_index1, node,
}
else
{
- if (PREDICT_FALSE (proto1 == ~0))
+ if (PREDICT_FALSE (proto1 == NAT_PROTOCOL_OTHER))
{
next1 = SNAT_IN2OUT_NEXT_SLOW_PATH;
goto trace01;
}
- if (PREDICT_FALSE (proto1 == SNAT_PROTOCOL_ICMP))
+ if (PREDICT_FALSE (proto1 == NAT_PROTOCOL_ICMP))
{
next1 = SNAT_IN2OUT_NEXT_SLOW_PATH;
goto trace01;
* be able to use dhcp client on the outside interface
*/
if (PREDICT_FALSE
- (proto1 == SNAT_PROTOCOL_UDP
+ (proto1 == NAT_PROTOCOL_UDP
&& (vnet_buffer (b1)->ip.reass.l4_dst_port ==
clib_host_to_net_u16
(UDP_DST_PORT_dhcp_to_server))
src_address /* changed member */ );
ip1->checksum = ip_csum_fold (sum1);
- if (PREDICT_TRUE (proto1 == SNAT_PROTOCOL_TCP))
+ if (PREDICT_TRUE (proto1 == NAT_PROTOCOL_TCP))
{
if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
{
sum1 = ip_csum_update (sum1, old_port1, new_port1,
ip4_header_t /* cheat */ ,
length /* changed member */ );
- mss_clamping (sm, tcp1, &sum1);
+ mss_clamping (sm->mss_clamping, tcp1, &sum1);
tcp1->checksum = ip_csum_fold (sum1);
}
tcp_packets++;
{
if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
{
+ udp1->src_port = s1->out2in.port;
if (PREDICT_FALSE (udp1->checksum))
{
old_port1 = vnet_buffer (b1)->ip.reass.l4_src_port;
- new_port1 = udp1->src_port = s1->out2in.port;
+ new_port1 = udp1->src_port;
sum1 = udp1->checksum;
sum1 = ip_csum_update (sum1, old_addr1, new_addr1, ip4_header_t, dst_address /* changed member */
);
goto trace0;
}
- proto0 = ip_proto_to_snat_proto (ip0->protocol);
+ proto0 = ip_proto_to_nat_proto (ip0->protocol);
/* Next configured feature, probably ip4-lookup */
if (is_slow_path)
{
- if (PREDICT_FALSE (proto0 == ~0))
+ if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
{
if (nat_in2out_sm_unknown_proto
(sm, b0, ip0, rx_fib_index0))
goto trace0;
}
- if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP))
+ if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
{
next0 = icmp_in2out_slow_path
(sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
}
else
{
- if (PREDICT_FALSE (proto0 == ~0))
+ if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
{
next0 = SNAT_IN2OUT_NEXT_SLOW_PATH;
goto trace0;
}
- if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP))
+ if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
{
next0 = SNAT_IN2OUT_NEXT_SLOW_PATH;
goto trace0;
* be able to use dhcp client on the outside interface
*/
if (PREDICT_FALSE
- (proto0 == SNAT_PROTOCOL_UDP
+ (proto0 == NAT_PROTOCOL_UDP
&& (vnet_buffer (b0)->ip.reass.l4_dst_port ==
clib_host_to_net_u16
(UDP_DST_PORT_dhcp_to_server))
src_address /* changed member */ );
ip0->checksum = ip_csum_fold (sum0);
- if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
+ if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
{
if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
{
sum0 = ip_csum_update (sum0, old_port0, new_port0,
ip4_header_t /* cheat */ ,
length /* changed member */ );
- mss_clamping (sm, tcp0, &sum0);
+ mss_clamping (sm->mss_clamping, tcp0, &sum0);
tcp0->checksum = ip_csum_fold (sum0);
}
tcp_packets++;
{
if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
{
+ udp0->src_port = s0->out2in.port;
if (PREDICT_FALSE (udp0->checksum))
{
old_port0 = vnet_buffer (b0)->ip.reass.l4_src_port;
- new_port0 = udp0->src_port = s0->out2in.port;
+ new_port0 = udp0->src_port;
sum0 = udp0->checksum;
sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t, dst_address /* changed member */
);
u32 pkts_processed = 0;
snat_main_t *sm = &snat_main;
u32 stats_node_index;
+ int is_hairpinning = 0;
stats_node_index = sm->in2out_fast_node_index;
goto trace0;
}
- proto0 = ip_proto_to_snat_proto (ip0->protocol);
+ proto0 = ip_proto_to_nat_proto (ip0->protocol);
- if (PREDICT_FALSE (proto0 == ~0))
+ if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
goto trace0;
- if (PREDICT_FALSE (proto0 == SNAT_PROTOCOL_ICMP))
+ if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
{
next0 = icmp_in2out (sm, b0, ip0, icmp0, sw_if_index0,
rx_fib_index0, node, next0, ~0, 0, 0);
old_port0 = udp0->src_port;
udp0->src_port = new_port0;
- if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
+ if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
{
sum0 = tcp0->checksum;
sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
sum0 = ip_csum_update (sum0, old_port0, new_port0,
ip4_header_t /* cheat */ ,
length /* changed member */ );
- mss_clamping (sm, tcp0, &sum0);
+ mss_clamping (sm->mss_clamping, tcp0, &sum0);
tcp0->checksum = ip_csum_fold (sum0);
}
else if (udp0->checksum)
}
else
{
- if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
+ if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
{
sum0 = tcp0->checksum;
sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
ip4_header_t,
dst_address /* changed member */ );
- mss_clamping (sm, tcp0, &sum0);
+ mss_clamping (sm->mss_clamping, tcp0, &sum0);
tcp0->checksum = ip_csum_fold (sum0);
}
else if (udp0->checksum)
}
/* Hairpinning */
- snat_hairpinning (sm, b0, ip0, udp0, tcp0, proto0, 0);
+ snat_hairpinning (vm, node, sm, b0, ip0, udp0, tcp0, proto0, 0,
+ 0 /* do_trace */ );
+ is_hairpinning = 1;
trace0:
if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
vlib_add_trace (vm, node, b0, sizeof (*t));
t->sw_if_index = sw_if_index0;
t->next_index = next0;
+ t->is_hairpinning = is_hairpinning;
}
pkts_processed += next0 != SNAT_IN2OUT_NEXT_DROP;