/*
* decap.c: gtpu tunnel decap packet processing
*
- * Copyright (c) 2013 Cisco and/or its affiliates.
+ * Copyright (c) 2017 Intel and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
#include <vnet/pg/pg.h>
#include <gtpu/gtpu.h>
-vlib_node_registration_t gtpu4_input_node;
-vlib_node_registration_t gtpu6_input_node;
+extern vlib_node_registration_t gtpu4_input_node;
+extern vlib_node_registration_t gtpu6_input_node;
typedef struct {
u32 next_index;
if (is_ip4)
last_key4.as_u64 = ~0;
else
- memset (&last_key6, 0xff, sizeof (last_key6));
+ clib_memset (&last_key6, 0xff, sizeof (last_key6));
from = vlib_frame_vector_args (from_frame);
n_left_from = from_frame->n_vectors;
ip4_header_t * ip4_0, * ip4_1;
ip6_header_t * ip6_0, * ip6_1;
gtpu_header_t * gtpu0, * gtpu1;
- u32 gtpu_hdr_len0 = 0, gtpu_hdr_len1 =0 ;
+ u32 gtpu_hdr_len0, gtpu_hdr_len1;
uword * p0, * p1;
u32 tunnel_index0, tunnel_index1;
gtpu_tunnel_t * t0, * t1, * mt0 = NULL, * mt1 = NULL;
gtpu6_tunnel_key_t key6_0, key6_1;
u32 error0, error1;
u32 sw_if_index0, sw_if_index1, len0, len1;
+ u8 has_space0, has_space1;
+ u8 ver0, ver1;
/* Prefetch next iteration. */
{
/* udp leaves current_data pointing at the gtpu header */
gtpu0 = vlib_buffer_get_current (b0);
gtpu1 = vlib_buffer_get_current (b1);
- if (is_ip4) {
- vlib_buffer_advance
- (b0, -(word)(sizeof(udp_header_t)+sizeof(ip4_header_t)));
- vlib_buffer_advance
- (b1, -(word)(sizeof(udp_header_t)+sizeof(ip4_header_t)));
- ip4_0 = vlib_buffer_get_current (b0);
- ip4_1 = vlib_buffer_get_current (b1);
- } else {
- vlib_buffer_advance
- (b0, -(word)(sizeof(udp_header_t)+sizeof(ip6_header_t)));
- vlib_buffer_advance
- (b1, -(word)(sizeof(udp_header_t)+sizeof(ip6_header_t)));
- ip6_0 = vlib_buffer_get_current (b0);
- ip6_1 = vlib_buffer_get_current (b1);
- }
-
- /* pop (ip, udp, gtpu) */
- if (is_ip4) {
- vlib_buffer_advance
- (b0, sizeof(*ip4_0)+sizeof(udp_header_t));
- vlib_buffer_advance
- (b1, sizeof(*ip4_1)+sizeof(udp_header_t));
- } else {
- vlib_buffer_advance
- (b0, sizeof(*ip6_0)+sizeof(udp_header_t));
- vlib_buffer_advance
- (b1, sizeof(*ip6_1)+sizeof(udp_header_t));
- }
+ if (is_ip4)
+ {
+ ip4_0 = (void *)((u8*)gtpu0 - sizeof(udp_header_t) - sizeof(ip4_header_t));
+ ip4_1 = (void *)((u8*)gtpu1 - sizeof(udp_header_t) - sizeof(ip4_header_t));
+ }
+ else
+ {
+ ip6_0 = (void *)((u8*)gtpu0 - sizeof(udp_header_t) - sizeof(ip6_header_t));
+ ip6_1 = (void *)((u8*)gtpu1 - sizeof(udp_header_t) - sizeof(ip6_header_t));
+ }
tunnel_index0 = ~0;
error0 = 0;
tunnel_index1 = ~0;
error1 = 0;
- if (PREDICT_FALSE ((gtpu0->ver_flags & GTPU_VER_MASK) != GTPU_V1_VER))
+ /* speculatively load gtp header version field */
+ ver0 = gtpu0->ver_flags;
+ ver1 = gtpu1->ver_flags;
+
+ /*
+ * Manipulate gtpu header
+ * TBD: Manipulate Sequence Number and N-PDU Number
+ * TBD: Manipulate Next Extension Header
+ */
+ gtpu_hdr_len0 = sizeof(gtpu_header_t) - (((ver0 & GTPU_E_S_PN_BIT) == 0) * 4);
+ gtpu_hdr_len1 = sizeof(gtpu_header_t) - (((ver1 & GTPU_E_S_PN_BIT) == 0) * 4);
+
+ has_space0 = vlib_buffer_has_space (b0, gtpu_hdr_len0);
+ has_space1 = vlib_buffer_has_space (b1, gtpu_hdr_len1);
+
+ if (PREDICT_FALSE (((ver0 & GTPU_VER_MASK) != GTPU_V1_VER) | (!has_space0)))
{
- error0 = GTPU_ERROR_BAD_VER;
+ error0 = has_space0 ? GTPU_ERROR_BAD_VER : GTPU_ERROR_TOO_SMALL;
next0 = GTPU_INPUT_NEXT_DROP;
goto trace0;
}
tunnel_index0 = last_tunnel_index;
t0 = pool_elt_at_index (gtm->tunnels, tunnel_index0);
- /* Validate GTPU tunnel encap-fib index agaist packet */
+ /* Validate GTPU tunnel encap-fib index against packet */
if (PREDICT_FALSE (validate_gtpu_fib (b0, t0, is_ip4) == 0))
{
error0 = GTPU_ERROR_NO_SUCH_TUNNEL;
next0 = GTPU_INPUT_NEXT_DROP;
goto trace0;
}
- clib_memcpy (&last_key6, &key6_0, sizeof(key6_0));
+ clib_memcpy_fast (&last_key6, &key6_0, sizeof(key6_0));
tunnel_index0 = last_tunnel_index = p0[0];
}
else
tunnel_index0 = last_tunnel_index;
t0 = pool_elt_at_index (gtm->tunnels, tunnel_index0);
- /* Validate GTPU tunnel encap-fib index agaist packet */
+ /* Validate GTPU tunnel encap-fib index against packet */
if (PREDICT_FALSE (validate_gtpu_fib (b0, t0, is_ip4) == 0))
{
error0 = GTPU_ERROR_NO_SUCH_TUNNEL;
}
next0:
- /* Manipulate gtpu header */
- if (PREDICT_FALSE((gtpu0->ver_flags & GTPU_E_S_PN_BIT) != 0))
- {
- gtpu_hdr_len0 = sizeof(gtpu_header_t);
-
- /* Manipulate Sequence Number and N-PDU Number */
- /* TBD */
-
- /* Manipulate Next Extension Header */
- /* TBD */
- }
- else
- {
- gtpu_hdr_len0 = sizeof(gtpu_header_t) - 4;
- }
-
/* Pop gtpu header */
vlib_buffer_advance (b0, gtpu_hdr_len0);
tr->next_index = next0;
tr->error = error0;
tr->tunnel_index = tunnel_index0;
- tr->teid = clib_net_to_host_u32(gtpu0->teid);
+ tr->teid = has_space0 ? clib_net_to_host_u32(gtpu0->teid) : ~0;
}
- if (PREDICT_FALSE ((gtpu1->ver_flags & GTPU_VER_MASK) != GTPU_V1_VER))
+ if (PREDICT_FALSE (((ver1 & GTPU_VER_MASK) != GTPU_V1_VER) | (!has_space1)))
{
- error1 = GTPU_ERROR_BAD_VER;
+ error1 = has_space1 ? GTPU_ERROR_BAD_VER : GTPU_ERROR_TOO_SMALL;
next1 = GTPU_INPUT_NEXT_DROP;
goto trace1;
}
tunnel_index1 = last_tunnel_index;
t1 = pool_elt_at_index (gtm->tunnels, tunnel_index1);
- /* Validate GTPU tunnel encap-fib index agaist packet */
+ /* Validate GTPU tunnel encap-fib index against packet */
if (PREDICT_FALSE (validate_gtpu_fib (b1, t1, is_ip4) == 0))
{
error1 = GTPU_ERROR_NO_SUCH_TUNNEL;
goto trace1;
}
- clib_memcpy (&last_key6, &key6_1, sizeof(key6_1));
+ clib_memcpy_fast (&last_key6, &key6_1, sizeof(key6_1));
tunnel_index1 = last_tunnel_index = p1[0];
}
else
tunnel_index1 = last_tunnel_index;
t1 = pool_elt_at_index (gtm->tunnels, tunnel_index1);
- /* Validate GTPU tunnel encap-fib index agaist packet */
+ /* Validate GTPU tunnel encap-fib index against packet */
if (PREDICT_FALSE (validate_gtpu_fib (b1, t1, is_ip4) == 0))
{
error1 = GTPU_ERROR_NO_SUCH_TUNNEL;
}
next1:
- /* Manipulate gtpu header */
- if (PREDICT_FALSE((gtpu1->ver_flags & GTPU_E_S_PN_BIT) != 0))
- {
- gtpu_hdr_len1 = sizeof(gtpu_header_t);
-
- /* Manipulate Sequence Number and N-PDU Number */
- /* TBD */
-
- /* Manipulate Next Extension Header */
- /* TBD */
- }
- else
- {
- gtpu_hdr_len1 = sizeof(gtpu_header_t) - 4;
- }
-
/* Pop gtpu header */
vlib_buffer_advance (b1, gtpu_hdr_len1);
tr->next_index = next1;
tr->error = error1;
tr->tunnel_index = tunnel_index1;
- tr->teid = clib_net_to_host_u32(gtpu1->teid);
+ tr->teid = has_space1 ? clib_net_to_host_u32(gtpu1->teid) : ~0;
}
vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
ip4_header_t * ip4_0;
ip6_header_t * ip6_0;
gtpu_header_t * gtpu0;
- u32 gtpu_hdr_len0 = 0;
+ u32 gtpu_hdr_len0;
uword * p0;
u32 tunnel_index0;
gtpu_tunnel_t * t0, * mt0 = NULL;
gtpu6_tunnel_key_t key6_0;
u32 error0;
u32 sw_if_index0, len0;
+ u8 has_space0;
+ u8 ver0;
bi0 = from[0];
to_next[0] = bi0;
/* udp leaves current_data pointing at the gtpu header */
gtpu0 = vlib_buffer_get_current (b0);
if (is_ip4) {
- vlib_buffer_advance
- (b0, -(word)(sizeof(udp_header_t)+sizeof(ip4_header_t)));
- ip4_0 = vlib_buffer_get_current (b0);
+ ip4_0 = (void *)((u8*)gtpu0 - sizeof(udp_header_t) - sizeof(ip4_header_t));
} else {
- vlib_buffer_advance
- (b0, -(word)(sizeof(udp_header_t)+sizeof(ip6_header_t)));
- ip6_0 = vlib_buffer_get_current (b0);
- }
-
- /* pop (ip, udp) */
- if (is_ip4) {
- vlib_buffer_advance
- (b0, sizeof(*ip4_0)+sizeof(udp_header_t));
- } else {
- vlib_buffer_advance
- (b0, sizeof(*ip6_0)+sizeof(udp_header_t));
+ ip6_0 = (void *)((u8*)gtpu0 - sizeof(udp_header_t) - sizeof(ip6_header_t));
}
tunnel_index0 = ~0;
error0 = 0;
- if (PREDICT_FALSE ((gtpu0->ver_flags & GTPU_VER_MASK) != GTPU_V1_VER))
- {
- error0 = GTPU_ERROR_BAD_VER;
- next0 = GTPU_INPUT_NEXT_DROP;
- goto trace00;
- }
+
+ /* speculatively load gtp header version field */
+ ver0 = gtpu0->ver_flags;
+
+ /*
+ * Manipulate gtpu header
+ * TBD: Manipulate Sequence Number and N-PDU Number
+ * TBD: Manipulate Next Extension Header
+ */
+ gtpu_hdr_len0 = sizeof(gtpu_header_t) - (((ver0 & GTPU_E_S_PN_BIT) == 0) * 4);
+
+ has_space0 = vlib_buffer_has_space (b0, gtpu_hdr_len0);
+
+ if (PREDICT_FALSE (((ver0 & GTPU_VER_MASK) != GTPU_V1_VER) | (!has_space0)))
+ {
+ error0 = has_space0 ? GTPU_ERROR_BAD_VER : GTPU_ERROR_TOO_SMALL;
+ next0 = GTPU_INPUT_NEXT_DROP;
+ goto trace00;
+ }
if (is_ip4) {
key4_0.src = ip4_0->src_address.as_u32;
tunnel_index0 = last_tunnel_index;
t0 = pool_elt_at_index (gtm->tunnels, tunnel_index0);
- /* Validate GTPU tunnel encap-fib index agaist packet */
+ /* Validate GTPU tunnel encap-fib index against packet */
if (PREDICT_FALSE (validate_gtpu_fib (b0, t0, is_ip4) == 0))
{
error0 = GTPU_ERROR_NO_SUCH_TUNNEL;
next0 = GTPU_INPUT_NEXT_DROP;
goto trace00;
}
- clib_memcpy (&last_key6, &key6_0, sizeof(key6_0));
+ clib_memcpy_fast (&last_key6, &key6_0, sizeof(key6_0));
tunnel_index0 = last_tunnel_index = p0[0];
}
else
tunnel_index0 = last_tunnel_index;
t0 = pool_elt_at_index (gtm->tunnels, tunnel_index0);
- /* Validate GTPU tunnel encap-fib index agaist packet */
+ /* Validate GTPU tunnel encap-fib index against packet */
if (PREDICT_FALSE (validate_gtpu_fib (b0, t0, is_ip4) == 0))
{
error0 = GTPU_ERROR_NO_SUCH_TUNNEL;
}
next00:
- /* Manipulate gtpu header */
- if (PREDICT_FALSE((gtpu0->ver_flags & GTPU_E_S_PN_BIT) != 0))
- {
- gtpu_hdr_len0 = sizeof(gtpu_header_t);
-
- /* Manipulate Sequence Number and N-PDU Number */
- /* TBD */
-
- /* Manipulate Next Extension Header */
- /* TBD */
- }
- else
- {
- gtpu_hdr_len0 = sizeof(gtpu_header_t) - 4;
- }
-
/* Pop gtpu header */
vlib_buffer_advance (b0, gtpu_hdr_len0);
tr->next_index = next0;
tr->error = error0;
tr->tunnel_index = tunnel_index0;
- tr->teid = clib_net_to_host_u32(gtpu0->teid);
+ tr->teid = has_space0 ? clib_net_to_host_u32(gtpu0->teid) : ~0;
}
vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
to_next, n_left_to_next,
return from_frame->n_vectors;
}
-static uword
-gtpu4_input (vlib_main_t * vm,
+VLIB_NODE_FN (gtpu4_input_node) (vlib_main_t * vm,
vlib_node_runtime_t * node,
vlib_frame_t * from_frame)
{
return gtpu_input(vm, node, from_frame, /* is_ip4 */ 1);
}
-static uword
-gtpu6_input (vlib_main_t * vm,
+VLIB_NODE_FN (gtpu6_input_node) (vlib_main_t * vm,
vlib_node_runtime_t * node,
vlib_frame_t * from_frame)
{
};
VLIB_REGISTER_NODE (gtpu4_input_node) = {
- .function = gtpu4_input,
.name = "gtpu4-input",
/* Takes a vector of packets. */
.vector_size = sizeof (u32),
// $$$$ .unformat_buffer = unformat_gtpu_header,
};
-VLIB_NODE_FUNCTION_MULTIARCH (gtpu4_input_node, gtpu4_input)
-
VLIB_REGISTER_NODE (gtpu6_input_node) = {
- .function = gtpu6_input,
.name = "gtpu6-input",
/* Takes a vector of packets. */
.vector_size = sizeof (u32),
// $$$$ .unformat_buffer = unformat_gtpu_header,
};
-VLIB_NODE_FUNCTION_MULTIARCH (gtpu6_input_node, gtpu6_input)
-
-
typedef enum {
IP_GTPU_BYPASS_NEXT_DROP,
IP_GTPU_BYPASS_NEXT_GTPU,
}
/* Setup packet for next IP feature */
- vnet_feature_next(vnet_buffer(b0)->sw_if_index[VLIB_RX], &next0, b0);
- vnet_feature_next(vnet_buffer(b1)->sw_if_index[VLIB_RX], &next1, b1);
+ vnet_feature_next(&next0, b0);
+ vnet_feature_next(&next1, b1);
if (is_ip4)
{
}
flags0 = b0->flags;
- good_udp0 = (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
+ good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
/* Don't verify UDP checksum for packets with explicit zero checksum. */
good_udp0 |= udp0->checksum == 0;
/* Verify UDP checksum */
if (PREDICT_FALSE (!good_udp0))
{
- if ((flags0 & IP_BUFFER_L4_CHECKSUM_COMPUTED) == 0)
+ if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
{
if (is_ip4)
flags0 = ip4_tcp_udp_validate_checksum (vm, b0);
else
flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0);
good_udp0 =
- (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
+ (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
}
}
}
flags1 = b1->flags;
- good_udp1 = (flags1 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
+ good_udp1 = (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
/* Don't verify UDP checksum for packets with explicit zero checksum. */
good_udp1 |= udp1->checksum == 0;
/* Verify UDP checksum */
if (PREDICT_FALSE (!good_udp1))
{
- if ((flags1 & IP_BUFFER_L4_CHECKSUM_COMPUTED) == 0)
+ if ((flags1 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
{
if (is_ip4)
flags1 = ip4_tcp_udp_validate_checksum (vm, b1);
else
flags1 = ip6_tcp_udp_icmp_validate_checksum (vm, b1);
good_udp1 =
- (flags1 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
+ (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
}
}
ip60 = vlib_buffer_get_current (b0);
/* Setup packet for next IP feature */
- vnet_feature_next(vnet_buffer(b0)->sw_if_index[VLIB_RX], &next0, b0);
+ vnet_feature_next(&next0, b0);
if (is_ip4)
/* Treat IP4 frag packets as "experimental" protocol for now
}
flags0 = b0->flags;
- good_udp0 = (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
+ good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
/* Don't verify UDP checksum for packets with explicit zero checksum. */
good_udp0 |= udp0->checksum == 0;
/* Verify UDP checksum */
if (PREDICT_FALSE (!good_udp0))
{
- if ((flags0 & IP_BUFFER_L4_CHECKSUM_COMPUTED) == 0)
+ if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
{
if (is_ip4)
flags0 = ip4_tcp_udp_validate_checksum (vm, b0);
else
flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0);
good_udp0 =
- (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
+ (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
}
}
return frame->n_vectors;
}
-static uword
-ip4_gtpu_bypass (vlib_main_t * vm,
+VLIB_NODE_FN (ip4_gtpu_bypass_node) (vlib_main_t * vm,
vlib_node_runtime_t * node,
vlib_frame_t * frame)
{
}
VLIB_REGISTER_NODE (ip4_gtpu_bypass_node) = {
- .function = ip4_gtpu_bypass,
.name = "ip4-gtpu-bypass",
.vector_size = sizeof (u32),
.format_trace = format_ip4_forward_next_trace,
};
-VLIB_NODE_FUNCTION_MULTIARCH (ip4_gtpu_bypass_node,ip4_gtpu_bypass)
-
+#ifndef CLIB_MARCH_VARIANT
/* Dummy init function to get us linked in. */
clib_error_t * ip4_gtpu_bypass_init (vlib_main_t * vm)
{ return 0; }
VLIB_INIT_FUNCTION (ip4_gtpu_bypass_init);
+#endif /* CLIB_MARCH_VARIANT */
-static uword
-ip6_gtpu_bypass (vlib_main_t * vm,
+VLIB_NODE_FN (ip6_gtpu_bypass_node) (vlib_main_t * vm,
vlib_node_runtime_t * node,
vlib_frame_t * frame)
{
}
VLIB_REGISTER_NODE (ip6_gtpu_bypass_node) = {
- .function = ip6_gtpu_bypass,
.name = "ip6-gtpu-bypass",
.vector_size = sizeof (u32),
.format_trace = format_ip6_forward_next_trace,
};
-VLIB_NODE_FUNCTION_MULTIARCH (ip6_gtpu_bypass_node,ip6_gtpu_bypass)
-
+#ifndef CLIB_MARCH_VARIANT
/* Dummy init function to get us linked in. */
clib_error_t * ip6_gtpu_bypass_init (vlib_main_t * vm)
{ return 0; }
VLIB_INIT_FUNCTION (ip6_gtpu_bypass_init);
+#endif /* CLIB_MARCH_VARIANT */