summaryrefslogtreecommitdiffstats
path: root/src/plugins/srv6-mobile/node.c
diff options
context:
space:
mode:
authorTetsuya Murakami <tetsuya.mrk@gmail.com>2019-12-04 18:57:46 -0800
committerOle Trøan <otroan@employees.org>2019-12-05 15:11:03 +0000
commit70d8ef89a5d9e38d4f35517c0f64009c47b76c4d (patch)
tree4dbd294a57d34dd82d755ae465847f5ede7244d7 /src/plugins/srv6-mobile/node.c
parent66cea092c7a584bb7b82000fbfad349e6f0af7e1 (diff)
srv6-mobile
Type: feature Plug-in for IPv6 Segment Routing Mobile Support the plug-in function in SR Policy. Support GTP4.D plug-in as SR Policy plug-in. Signed-off-by: Tetsuya Murakami <tetsuya.mrk@gmail.com> Change-Id: I306160b7203921d879940193868944158867c482
Diffstat (limited to 'src/plugins/srv6-mobile/node.c')
-rw-r--r--src/plugins/srv6-mobile/node.c476
1 files changed, 463 insertions, 13 deletions
diff --git a/src/plugins/srv6-mobile/node.c b/src/plugins/srv6-mobile/node.c
index 0c2c04e612e..eb9a20e3c53 100644
--- a/src/plugins/srv6-mobile/node.c
+++ b/src/plugins/srv6-mobile/node.c
@@ -113,9 +113,9 @@ format_srv6_end_rewrite_trace6 (u8 * s, va_list * args)
_(M_GTP4_E_PACKETS, "srv6 End.M.GTP4.E packets") \
_(M_GTP4_E_BAD_PACKETS, "srv6 End.M.GTP4.E bad packets")
-#define foreach_srv6_end_v4_d_error \
- _(M_GTP4_D_PACKETS, "srv6 End.M.GTP4.D packets") \
- _(M_GTP4_D_BAD_PACKETS, "srv6 End.M.GTP4.D bad packets")
+#define foreach_srv6_t_v4_d_error \
+ _(M_GTP4_D_PACKETS, "srv6 T.M.GTP4.D packets") \
+ _(M_GTP4_D_BAD_PACKETS, "srv6 T.M.GTP4.D bad packets")
#define foreach_srv6_end_v6_e_error \
_(M_GTP6_E_PACKETS, "srv6 End.M.GTP6.E packets") \
@@ -129,6 +129,10 @@ format_srv6_end_rewrite_trace6 (u8 * s, va_list * args)
_(M_GTP6_D_DI_PACKETS, "srv6 End.M.GTP6.D.DI packets") \
_(M_GTP6_D_DI_BAD_PACKETS, "srv6 End.M.GTP6.D.DI bad packets")
+#define foreach_srv6_end_v6_dt_error \
+ _(M_GTP6_DT_PACKETS, "srv6 End.M.GTP6.DT packets") \
+ _(M_GTP6_DT_BAD_PACKETS, "srv6 End.M.GTP6.DT bad packets")
+
typedef enum
{
#define _(sym,str) SRV6_END_ERROR_##sym,
@@ -139,11 +143,11 @@ typedef enum
typedef enum
{
-#define _(sym,str) SRV6_END_ERROR_##sym,
- foreach_srv6_end_v4_d_error
+#define _(sym,str) SRV6_T_ERROR_##sym,
+ foreach_srv6_t_v4_d_error
#undef _
- SRV6_END_N_V4_D_ERROR,
-} srv6_end_error_v4_d_t;
+ SRV6_T_N_V4_D_ERROR,
+} srv6_t_error_v4_d_t;
typedef enum
{
@@ -169,12 +173,26 @@ typedef enum
SRV6_END_N_V6_D_DI_ERROR,
} srv6_end_error_v6_d_di_t;
+typedef enum
+{
+#define _(sym,str) SRV6_END_ERROR_##sym,
+ foreach_srv6_end_v6_dt_error
+#undef _
+ SRV6_END_N_V6_DT_ERROR,
+} srv6_end_error_v6_dt_t;
+
static char *srv6_end_error_v4_strings[] = {
#define _(sym,string) string,
foreach_srv6_end_v4_error
#undef _
};
+static char *srv6_t_error_v4_d_strings[] = {
+#define _(sym,string) string,
+ foreach_srv6_t_v4_d_error
+#undef _
+};
+
static char *srv6_end_error_v6_e_strings[] = {
#define _(sym,string) string,
foreach_srv6_end_v6_e_error
@@ -202,6 +220,13 @@ typedef enum
typedef enum
{
+ SRV6_T_M_GTP4_D_NEXT_DROP,
+ SRV6_T_M_GTP4_D_NEXT_LOOKUP,
+ SRV6_T_M_GTP4_D_N_NEXT,
+} srv6_T_m_gtp4_d_next_t;
+
+typedef enum
+{
SRV6_END_M_GTP6_E_NEXT_DROP,
SRV6_END_M_GTP6_E_NEXT_LOOKUP,
SRV6_END_M_GTP6_E_N_NEXT,
@@ -514,6 +539,419 @@ VLIB_NODE_FN (srv6_end_m_gtp4_e) (vlib_main_t * vm,
return frame->n_vectors;
}
+// Function for SRv6 GTP4.D function.
+VLIB_NODE_FN (srv6_t_m_gtp4_d) (vlib_main_t * vm,
+ vlib_node_runtime_t * node,
+ vlib_frame_t * frame)
+{
+ srv6_t_main_v4_decap_t *sm = &srv6_t_main_v4_decap;
+ ip6_sr_main_t *sm2 = &sr_main;
+ u32 n_left_from, next_index, *from, *to_next;
+
+ u32 good_n = 0, bad_n = 0;
+
+ from = vlib_frame_vector_args (frame);
+ n_left_from = frame->n_vectors;
+ next_index = node->cached_next_index;
+
+ while (n_left_from > 0)
+ {
+ u32 n_left_to_next;
+
+ vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
+
+ while (n_left_from > 0 && n_left_to_next > 0)
+ {
+ u32 bi0;
+ vlib_buffer_t *b0;
+ ip6_sr_sl_t *sl0;
+ srv6_end_gtp4_param_t *ls_param;
+ ip4_header_t *ip4;
+
+ uword len0;
+
+ u32 next0 = SRV6_T_M_GTP4_D_NEXT_LOOKUP;
+
+ // defaults
+ bi0 = from[0];
+ to_next[0] = bi0;
+ from += 1;
+ to_next += 1;
+ n_left_from -= 1;
+ n_left_to_next -= 1;
+
+ b0 = vlib_get_buffer (vm, bi0);
+
+ sl0 =
+ pool_elt_at_index (sm2->sid_lists,
+ vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
+
+ ls_param = (srv6_end_gtp4_param_t *) sl0->plugin_mem;
+
+ len0 = vlib_buffer_length_in_chain (vm, b0);
+
+ ip4 = vlib_buffer_get_current (b0);
+
+ if (ip4->protocol != IP_PROTOCOL_UDP
+ || len0 < sizeof (ip4_gtpu_header_t))
+ {
+ next0 = SRV6_T_M_GTP4_D_NEXT_DROP;
+
+ bad_n++;
+ }
+ else
+ {
+ uword *p;
+ ip6_sr_policy_t *sr_policy = NULL;
+ ip6_sr_sl_t *sl = NULL;
+ u32 *sl_index;
+ u32 hdr_len;
+
+ ip4_gtpu_header_t *hdr;
+ ip4_address_t src, dst;
+ u8 *srcp, *dstp;
+ ip6_header_t *encap = NULL;
+ ip6_address_t seg;
+ ip6_address_t src6;
+ u8 gtpu_type;
+ u32 teid;
+ u8 *teidp;
+ u8 qfi = 0;
+ u8 *qfip = NULL;
+ u32 offset, shift, index;
+ ip6srv_combo_header_t *ip6srv;
+ gtpu_pdu_session_t *sess = NULL;
+
+ // Decap from GTP-U.
+ hdr = (ip4_gtpu_header_t *) ip4;
+
+ hdr_len = sizeof (ip4_gtpu_header_t);
+
+ teid = hdr->gtpu.teid;
+ teidp = (u8 *) & teid;
+
+ gtpu_type = hdr->gtpu.type;
+
+ if (hdr->gtpu.ver_flags & GTPU_EXTHDR_FLAG)
+ {
+ // Extention header.
+ hdr_len += sizeof (gtpu_exthdr_t);
+ if (hdr->gtpu.ext->nextexthdr == GTPU_EXTHDR_PDU_SESSION)
+ {
+ // PDU Session Container.
+ sess =
+ (gtpu_pdu_session_t *) (((char *) hdr) + hdr_len);
+ qfi = sess->u.val & ~GTPU_PDU_SESSION_P_BIT_MASK;
+ qfip = (u8 *) & qfi;
+
+ hdr_len += sizeof (gtpu_pdu_session_t);
+
+ if (sess->u.val & GTPU_PDU_SESSION_P_BIT_MASK)
+ {
+ hdr_len += sizeof (gtpu_paging_policy_t);
+ }
+ }
+ }
+
+ src = hdr->ip4.src_address;
+ srcp = (u8 *) & src;
+
+ dst = hdr->ip4.dst_address;
+ dstp = (u8 *) & dst;
+
+ seg = ls_param->sr_prefix;
+
+ offset = ls_param->sr_prefixlen / 8;
+ shift = ls_param->sr_prefixlen % 8;
+
+ if (PREDICT_TRUE (shift == 0))
+ {
+ clib_memcpy_fast (&seg.as_u8[offset], dstp, 4);
+
+ if (qfip)
+ {
+ qfi =
+ ((qfi & GTPU_PDU_SESSION_QFI_MASK) << 2) |
+ ((qfi & GTPU_PDU_SESSION_R_BIT_MASK) >> 5);
+
+ if (sess->type)
+ {
+ qfi |= SRV6_PDU_SESSION_U_BIT_MASK;
+ }
+
+ seg.as_u8[offset + 4] = qfi;
+ }
+
+ clib_memcpy_fast (&seg.as_u8[offset + 5], teidp, 4);
+ }
+ else
+ {
+ for (index = 0; index < 4; index++)
+ {
+ seg.as_u8[offset + index] |= dstp[index] >> shift;
+ seg.as_u8[offset + index + 1] |=
+ dstp[index] << (8 - shift);
+
+ seg.as_u8[offset + index + 5] |= teidp[index] >> shift;
+ seg.as_u8[offset + index + 6] |=
+ teidp[index] << (8 - shift);
+ }
+
+ if (qfip)
+ {
+ qfi =
+ ((qfi & GTPU_PDU_SESSION_QFI_MASK) << 2) |
+ ((qfi & GTPU_PDU_SESSION_R_BIT_MASK) >> 5);
+
+ if (sess->type)
+ {
+ qfi |= SRV6_PDU_SESSION_U_BIT_MASK;
+ }
+
+ seg.as_u8[offset + 4] |= qfi >> shift;
+ seg.as_u8[offset + 5] |= qfi << (8 - shift);
+ }
+ }
+
+ src6 = ls_param->v6src_prefix;
+
+ offset = ls_param->v6src_prefixlen / 8;
+ shift = ls_param->v6src_prefixlen % 8;
+
+ if (PREDICT_TRUE (shift == 0))
+ {
+ clib_memcpy_fast (&src6.as_u8[offset], srcp, 4);
+ }
+ else
+ {
+ for (index = 0; index < 4; index++)
+ {
+ src6.as_u8[offset + index] |= srcp[offset] >> shift;
+ src6.as_u8[offset + index + 1] |=
+ srcp[offset] << (8 - shift);
+ }
+ }
+
+ vlib_buffer_advance (b0, (word) hdr_len);
+
+ // Encap to SRv6.
+ if (PREDICT_TRUE (gtpu_type == GTPU_TYPE_GTPU))
+ {
+ encap = vlib_buffer_get_current (b0);
+ }
+
+ len0 = vlib_buffer_length_in_chain (vm, b0);
+
+ p =
+ mhash_get (&sm2->sr_policies_index_hash,
+ &ls_param->sr_prefix);
+ if (p)
+ {
+ sr_policy = pool_elt_at_index (sm2->sr_policies, p[0]);
+ }
+
+ if (sr_policy)
+ {
+ vec_foreach (sl_index, sr_policy->segments_lists)
+ {
+ sl = pool_elt_at_index (sm2->sid_lists, *sl_index);
+ if (sl != NULL)
+ break;
+ }
+ }
+
+ if (sl)
+ {
+ hdr_len = sizeof (ip6srv_combo_header_t);
+ hdr_len += vec_len (sl->segments) * sizeof (ip6_address_t);
+ hdr_len += sizeof (ip6_address_t);
+ }
+ else
+ {
+ hdr_len = sizeof (ip6_header_t);
+
+ if (PREDICT_FALSE (gtpu_type != GTPU_TYPE_GTPU))
+ {
+ hdr_len += sizeof (ip6_sr_header_t);
+ hdr_len += sizeof (ip6_address_t);
+ }
+ }
+
+ vlib_buffer_advance (b0, -(word) hdr_len);
+ ip6srv = vlib_buffer_get_current (b0);
+
+ if (sl)
+ {
+ clib_memcpy_fast (ip6srv, sl->rewrite,
+ vec_len (sl->rewrite));
+
+ ip6srv->ip.protocol = IP_PROTOCOL_IPV6_ROUTE;
+
+ ip6srv->sr.tag =
+ clib_host_to_net_u16 (srh_tagfield[gtpu_type]);
+
+ ip6srv->sr.segments_left += 1;
+ ip6srv->sr.last_entry += 1;
+
+ ip6srv->sr.length += sizeof (ip6_address_t) / 8;
+ ip6srv->sr.segments[0] = seg;
+
+ if (PREDICT_TRUE (encap != NULL))
+ {
+ if (ls_param->nhtype == SRV6_NHTYPE_NONE)
+ {
+ if ((clib_net_to_host_u32
+ (encap->ip_version_traffic_class_and_flow_label)
+ >> 28) == 6)
+ ip6srv->sr.protocol = IP_PROTOCOL_IPV6;
+ else
+ ip6srv->sr.protocol = IP_PROTOCOL_IP_IN_IP;
+ }
+ else if (ls_param->nhtype == SRV6_NHTYPE_IPV4)
+ {
+ ip6srv->sr.protocol = IP_PROTOCOL_IP_IN_IP;
+ if ((clib_net_to_host_u32
+ (encap->ip_version_traffic_class_and_flow_label)
+ >> 28) != 4)
+ {
+ // Bad encap packet.
+ next0 = SRV6_T_M_GTP4_D_NEXT_DROP;
+ bad_n++;
+ goto DONE;
+ }
+ }
+ else if (ls_param->nhtype == SRV6_NHTYPE_IPV6)
+ {
+ ip6srv->sr.protocol = IP_PROTOCOL_IPV6;
+ if ((clib_net_to_host_u32
+ (encap->ip_version_traffic_class_and_flow_label)
+ >> 28) != 6)
+ {
+ // Bad encap packet.
+ next0 = SRV6_T_M_GTP4_D_NEXT_DROP;
+ bad_n++;
+ goto DONE;
+ }
+ }
+ else if (ls_param->nhtype == SRV6_NHTYPE_NON_IP)
+ {
+ ip6srv->sr.protocol = IP_PROTOCOL_NONE;
+ }
+ }
+ else
+ {
+ ip6srv->sr.protocol = IP_PROTOCOL_NONE;
+ }
+
+ clib_memcpy_fast (&ip6srv->sr.segments[1],
+ (u8 *) (sl->rewrite +
+ sizeof (ip6_header_t) +
+ sizeof (ip6_sr_header_t)),
+ vec_len (sl->segments) *
+ sizeof (ip6_address_t));
+ }
+ else
+ {
+ clib_memcpy_fast (ip6srv, &sm->cache_hdr,
+ sizeof (ip6_header_t));
+
+ ip6srv->ip.dst_address = seg;
+
+ if (PREDICT_FALSE (gtpu_type != GTPU_TYPE_GTPU))
+ {
+ ip6srv->ip.protocol = IP_PROTOCOL_IPV6_ROUTE;
+
+ ip6srv->sr.protocol = IP_PROTOCOL_NONE;
+
+ ip6srv->sr.tag =
+ clib_host_to_net_u16 (srh_tagfield[gtpu_type]);
+
+ ip6srv->sr.segments_left = 0;
+ ip6srv->sr.last_entry = 0;
+
+ ip6srv->sr.length = sizeof (ip6_address_t) / 8;
+ ip6srv->sr.segments[0] = seg;
+ }
+ else
+ {
+ if (ls_param->nhtype == SRV6_NHTYPE_NONE)
+ {
+ if ((clib_net_to_host_u32
+ (encap->ip_version_traffic_class_and_flow_label)
+ >> 28) == 6)
+ ip6srv->ip.protocol = IP_PROTOCOL_IPV6;
+ else
+ ip6srv->ip.protocol = IP_PROTOCOL_IP_IN_IP;
+ }
+ else if (ls_param->nhtype == SRV6_NHTYPE_IPV4)
+ {
+ ip6srv->ip.protocol = IP_PROTOCOL_IP_IN_IP;
+ if ((clib_net_to_host_u32
+ (encap->ip_version_traffic_class_and_flow_label)
+ >> 28) != 4)
+ {
+ // Bad encap packet.
+ next0 = SRV6_T_M_GTP4_D_NEXT_DROP;
+ bad_n++;
+ goto DONE;
+ }
+ }
+ else if (ls_param->nhtype == SRV6_NHTYPE_IPV6)
+ {
+ ip6srv->ip.protocol = IP_PROTOCOL_IPV6;
+ if ((clib_net_to_host_u32
+ (encap->ip_version_traffic_class_and_flow_label)
+ >> 28) != 6)
+ {
+ // Bad encap packet.
+ next0 = SRV6_T_M_GTP4_D_NEXT_DROP;
+ bad_n++;
+ goto DONE;
+ }
+ }
+ else if (ls_param->nhtype == SRV6_NHTYPE_NON_IP)
+ {
+ ip6srv->ip.protocol = IP_PROTOCOL_NONE;
+ }
+ }
+ }
+
+ ip6srv->ip.src_address = src6;
+
+ ip6srv->ip.payload_length =
+ clib_host_to_net_u16 (len0 + hdr_len - sizeof (ip6_header_t));
+
+ good_n++;
+
+ if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE) &&
+ PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ srv6_end_rewrite_trace_t *tr =
+ vlib_add_trace (vm, node, b0, sizeof (*tr));
+ clib_memcpy (tr->src.as_u8, ip6srv->ip.src_address.as_u8,
+ sizeof (tr->src.as_u8));
+ clib_memcpy (tr->dst.as_u8, ip6srv->ip.dst_address.as_u8,
+ sizeof (tr->dst.as_u8));
+ }
+ }
+
+ DONE:
+ vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
+ n_left_to_next, bi0, next0);
+ }
+
+ vlib_put_next_frame (vm, node, next_index, n_left_to_next);
+ }
+
+ vlib_node_increment_counter (vm, sm->t_m_gtp4_d_node_index,
+ SRV6_T_ERROR_M_GTP4_D_BAD_PACKETS, bad_n);
+
+ vlib_node_increment_counter (vm, sm->t_m_gtp4_d_node_index,
+ SRV6_T_ERROR_M_GTP4_D_PACKETS, good_n);
+
+ return frame->n_vectors;
+}
+
VLIB_REGISTER_NODE (srv6_end_m_gtp4_e) =
{
.name = "srv6-end-m-gtp4-e",.vector_size = sizeof (u32),.format_trace =
@@ -522,8 +960,20 @@ VLIB_REGISTER_NODE (srv6_end_m_gtp4_e) =
srv6_end_error_v4_strings,.n_next_nodes =
SRV6_END_M_GTP4_E_N_NEXT,.next_nodes =
{
- [SRV6_END_M_GTP4_E_NEXT_DROP] =
- "error-drop",[SRV6_END_M_GTP4_E_NEXT_LOOKUP] = "ip4-lookup",}
+ [SRV6_END_M_GTP4_E_NEXT_DROP] = "error-drop",
+ [SRV6_END_M_GTP4_E_NEXT_LOOKUP] = "ip4-lookup",}
+,};
+
+VLIB_REGISTER_NODE (srv6_t_m_gtp4_d) =
+{
+ .name = "srv6-t-m-gtp4-d",.vector_size = sizeof (u32),.format_trace =
+ format_srv6_end_rewrite_trace,.type = VLIB_NODE_TYPE_INTERNAL,.n_errors =
+ ARRAY_LEN (srv6_t_error_v4_d_strings),.error_strings =
+ srv6_t_error_v4_d_strings,.n_next_nodes =
+ SRV6_T_M_GTP4_D_N_NEXT,.next_nodes =
+ {
+ [SRV6_T_M_GTP4_D_NEXT_DROP] = "error-drop",
+ [SRV6_T_M_GTP4_D_NEXT_LOOKUP] = "ip6-lookup",}
,};
// Function for SRv6 GTP6.E function
@@ -1496,8 +1946,8 @@ VLIB_REGISTER_NODE (srv6_end_m_gtp6_e) =
srv6_end_error_v6_e_strings,.n_next_nodes =
SRV6_END_M_GTP6_E_N_NEXT,.next_nodes =
{
- [SRV6_END_M_GTP6_E_NEXT_DROP] =
- "error-drop",[SRV6_END_M_GTP6_E_NEXT_LOOKUP] = "ip6-lookup",}
+ [SRV6_END_M_GTP6_E_NEXT_DROP] = "error-drop",
+ [SRV6_END_M_GTP6_E_NEXT_LOOKUP] = "ip6-lookup",}
,};
VLIB_REGISTER_NODE (srv6_end_m_gtp6_d) =
@@ -1508,8 +1958,8 @@ VLIB_REGISTER_NODE (srv6_end_m_gtp6_d) =
srv6_end_error_v6_d_strings,.n_next_nodes =
SRV6_END_M_GTP6_D_N_NEXT,.next_nodes =
{
- [SRV6_END_M_GTP6_D_NEXT_DROP] =
- "error-drop",[SRV6_END_M_GTP6_D_NEXT_LOOKUP] = "ip6-lookup",}
+ [SRV6_END_M_GTP6_D_NEXT_DROP] = "error-drop",
+ [SRV6_END_M_GTP6_D_NEXT_LOOKUP] = "ip6-lookup",}
,};
VLIB_REGISTER_NODE (srv6_end_m_gtp6_d_di) =