/**
* @brief Check if packet should be translated
*
- * Packets aimed at outside interface and external addresss with active session
+ * Packets aimed at outside interface and external address with active session
* should be translated.
*
* @param sm NAT main
u32 sw_if_index0, ip4_header_t * ip0, u32 proto0,
u32 rx_fib_index0)
{
+ if (sm->out2in_dpo)
+ return 0;
+
fib_node_index_t fei = FIB_NODE_INDEX_INVALID;
fib_prefix_t pfx = {
.fp_proto = FIB_PROTOCOL_IP4,
if (PREDICT_FALSE (maximum_sessions_exceeded(sm, thread_index)))
{
b0->error = node->errors[SNAT_IN2OUT_ERROR_MAX_SESSIONS_EXCEEDED];
+ nat_ipfix_logging_max_sessions(sm->max_translations);
return SNAT_IN2OUT_NEXT_DROP;
}
return SNAT_IN2OUT_NEXT_DROP;
}
- s = nat_session_alloc_or_recycle (sm, u, thread_index);
- if (!s)
- {
- clib_warning ("create NAT session failed");
- return SNAT_IN2OUT_NEXT_DROP;
- }
-
/* First try to match static mapping by local address and port */
if (snat_static_mapping_match (sm, *key0, &key1, 0, 0, 0))
{
else
{
u->nstaticsessions++;
- s->flags |= SNAT_SESSION_FLAG_STATIC_MAPPING;
}
+ s = nat_session_alloc_or_recycle (sm, u, thread_index);
+ if (!s)
+ {
+ clib_warning ("create NAT session failed");
+ return SNAT_IN2OUT_NEXT_DROP;
+ }
+
+ if (address_index == ~0)
+ s->flags |= SNAT_SESSION_FLAG_STATIC_MAPPING;
s->outside_address_index = address_index;
s->in2out = *key0;
s->out2in = key1;
return -1; /* success */
}
+static_always_inline int
+icmp_get_ed_key(ip4_header_t *ip0, nat_ed_ses_key_t *p_key0)
+{
+ icmp46_header_t *icmp0;
+ nat_ed_ses_key_t key0;
+ icmp_echo_header_t *echo0, *inner_echo0 = 0;
+ ip4_header_t *inner_ip0 = 0;
+ void *l4_header = 0;
+ icmp46_header_t *inner_icmp0;
+
+ icmp0 = (icmp46_header_t *) ip4_next_header (ip0);
+ echo0 = (icmp_echo_header_t *)(icmp0+1);
+
+ if (!icmp_is_error_message (icmp0))
+ {
+ key0.proto = IP_PROTOCOL_ICMP;
+ key0.l_addr = ip0->src_address;
+ key0.r_addr = ip0->dst_address;
+ key0.l_port = key0.r_port = echo0->identifier;
+ }
+ else
+ {
+ inner_ip0 = (ip4_header_t *)(echo0+1);
+ l4_header = ip4_next_header (inner_ip0);
+ key0.proto = inner_ip0->protocol;
+ key0.r_addr = inner_ip0->src_address;
+ key0.l_addr = inner_ip0->dst_address;
+ switch (ip_proto_to_snat_proto (inner_ip0->protocol))
+ {
+ case SNAT_PROTOCOL_ICMP:
+ inner_icmp0 = (icmp46_header_t*)l4_header;
+ inner_echo0 = (icmp_echo_header_t *)(inner_icmp0+1);
+ key0.r_port = key0.l_port = inner_echo0->identifier;
+ break;
+ case SNAT_PROTOCOL_UDP:
+ case SNAT_PROTOCOL_TCP:
+ key0.l_port = ((tcp_udp_header_t*)l4_header)->dst_port;
+ key0.r_port = ((tcp_udp_header_t*)l4_header)->src_port;
+ break;
+ default:
+ return SNAT_IN2OUT_ERROR_UNSUPPORTED_PROTOCOL;
+ }
+ }
+ *p_key0 = key0;
+ return 0;
+}
+
/**
* Get address and port values to be used for ICMP packet translation
* and create session if needed
goto out;
}
- s0 = pool_elt_at_index (sm->per_thread_data[thread_index].sessions,
- value0.value);
+ if (PREDICT_FALSE (value0.value == ~0ULL))
+ {
+ nat_ed_ses_key_t key;
+ clib_bihash_kv_16_8_t s_kv, s_value;
+
+ key.as_u64[0] = 0;
+ key.as_u64[1] = 0;
+ if (icmp_get_ed_key (ip0, &key))
+ {
+ b0->error = node->errors[SNAT_IN2OUT_ERROR_UNSUPPORTED_PROTOCOL];
+ next0 = SNAT_IN2OUT_NEXT_DROP;
+ goto out;
+ }
+ key.fib_index = rx_fib_index0;
+ s_kv.key[0] = key.as_u64[0];
+ s_kv.key[1] = key.as_u64[1];
+ if (!clib_bihash_search_16_8 (&sm->in2out_ed, &s_kv, &s_value))
+ s0 = pool_elt_at_index (sm->per_thread_data[thread_index].sessions,
+ s_value.value);
+ else
+ {
+ next0 = SNAT_IN2OUT_NEXT_DROP;
+ goto out;
+ }
+ }
+ else
+ s0 = pool_elt_at_index (sm->per_thread_data[thread_index].sessions,
+ value0.value);
}
out:
if (PREDICT_FALSE (maximum_sessions_exceeded(sm, thread_index)))
{
b->error = node->errors[SNAT_IN2OUT_ERROR_MAX_SESSIONS_EXCEEDED];
+ nat_ipfix_logging_max_sessions(sm->max_translations);
return 0;
}
if (PREDICT_FALSE (maximum_sessions_exceeded (sm, thread_index)))
{
b->error = node->errors[SNAT_IN2OUT_ERROR_MAX_SESSIONS_EXCEEDED];
+ nat_ipfix_logging_max_sessions(sm->max_translations);
return 0;
}
{
s0 = snat_in2out_lb(sm, b0, ip0, rx_fib_index0,
thread_index, now, vm, node);
- if (!s0)
+ if (!s0 && !sm->forwarding_enabled)
next0 = SNAT_IN2OUT_NEXT_DROP;
goto trace00;
}
{
s1 = snat_in2out_lb(sm, b1, ip1, rx_fib_index1,
thread_index, now, vm, node);
- if (!s1)
+ if (!s1 && !sm->forwarding_enabled)
next1 = SNAT_IN2OUT_NEXT_DROP;
goto trace01;
}
{
s0 = snat_in2out_lb(sm, b0, ip0, rx_fib_index0,
thread_index, now, vm, node);
- if (!s0)
+ if (!s0 && !sm->forwarding_enabled)
next0 = SNAT_IN2OUT_NEXT_DROP;
goto trace0;
}