diff options
author | Tetsuya Murakami <tetsuya.mrk@gmail.com> | 2019-12-10 00:18:47 -0800 |
---|---|---|
committer | Ole Trøan <otroan@employees.org> | 2019-12-17 20:43:14 +0000 |
commit | 77022b88e90c47754c4046e49eeae9c960044597 (patch) | |
tree | 05ae306dc196750daa290324ba55ca09501ba5f5 /src/plugins/srv6-mobile/node.c | |
parent | 10a8bda37eed33ada1e7c6ece7bda1fe066ba541 (diff) |
srv6-mobile
Type: fix
Plug-in for IPv6 Segment Routing Mobile
Fix the packet forwarding issue on GTP4/6.D when configuring only 1 segment in SRH.
Signed-off-by: Tetsuya Murakami <tetsuya.mrk@gmail.com>
Change-Id: I3a1d14b82821fc6e038d4ef719fd2aa006df2903
Signed-off-by: Tetsuya Murakami <tetsuya.mrk@gmail.com>
Diffstat (limited to 'src/plugins/srv6-mobile/node.c')
-rw-r--r-- | src/plugins/srv6-mobile/node.c | 489 |
1 files changed, 379 insertions, 110 deletions
diff --git a/src/plugins/srv6-mobile/node.c b/src/plugins/srv6-mobile/node.c index eb9a20e3c53..de3bc4a6f0d 100644 --- a/src/plugins/srv6-mobile/node.c +++ b/src/plugins/srv6-mobile/node.c @@ -129,10 +129,6 @@ 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, @@ -173,14 +169,6 @@ 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 @@ -258,20 +246,22 @@ hash_uword_to_u16 (uword * key) #endif } -static inline void -gtp_type_set (gtpu_header_t * gtpu, u16 tag) +static inline u8 +gtpu_type_get (u16 tag) { u16 val; val = clib_net_to_host_u16 (tag); if (val & SRH_TAG_ECHO_REPLY) - gtpu->type = GTPU_TYPE_ECHO_REPLY; + return GTPU_TYPE_ECHO_REPLY; else if (val & SRH_TAG_ECHO_REQUEST) - gtpu->type = GTPU_TYPE_ECHO_REQUEST; + return GTPU_TYPE_ECHO_REQUEST; else if (val & SRH_TAG_ERROR_INDICATION) - gtpu->type = GTPU_TYPE_ERROR_INDICATION; + return GTPU_TYPE_ERROR_INDICATION; else if (val & SRH_TAG_END_MARKER) - gtpu->type = GTPU_TYPE_END_MARKER; + return GTPU_TYPE_END_MARKER; + + return GTPU_TYPE_GTPU; } // Function for SRv6 GTP4.E function. @@ -343,10 +333,12 @@ VLIB_NODE_FN (srv6_end_m_gtp4_e) (vlib_main_t * vm, } else { + u8 gtpu_type = 0; u16 tag = 0; - u32 teid; + u32 teid = 0; u8 *teid8p = (u8 *) & teid; u8 qfi = 0; + u16 seq = 0; u32 index; u32 offset, shift; u32 hdrlen = 0; @@ -383,16 +375,29 @@ VLIB_NODE_FN (srv6_end_m_gtp4_e) (vlib_main_t * vm, offset = ls0->localsid_len / 8; shift = ls0->localsid_len % 8; + gtpu_type = gtpu_type_get (tag); + if (PREDICT_TRUE (shift == 0)) { clib_memcpy_fast (&dst4.as_u8[0], &dst0.as_u8[offset], 4); qfi = dst0.as_u8[offset + 4]; - clib_memcpy_fast (teid8p, &dst0.as_u8[offset + 5], 4); + if (gtpu_type == GTPU_TYPE_ECHO_REQUEST + || gtpu_type == GTPU_TYPE_ECHO_REPLY + || gtpu_type == GTPU_TYPE_ERROR_INDICATION) + { + clib_memcpy_fast (&seq, &dst0.as_u8[offset + 5], 2); + } + else + { + clib_memcpy_fast (teid8p, &dst0.as_u8[offset + 5], 4); + } } else { + u8 *sp; + for (index = 0; index < 4; index++) { dst4.as_u8[index] = dst0.as_u8[offset + index] << shift; @@ -403,12 +408,27 @@ VLIB_NODE_FN (srv6_end_m_gtp4_e) (vlib_main_t * vm, qfi |= dst0.as_u8[offset + 4] << shift; qfi |= dst0.as_u8[offset + 5] >> (8 - shift); - for (index = 0; index < 4; index++) + if (gtpu_type == GTPU_TYPE_ECHO_REQUEST + || gtpu_type == GTPU_TYPE_ECHO_REPLY + || gtpu_type == GTPU_TYPE_ERROR_INDICATION) + { + sp = (u8 *) & seq; + for (index = 0; index < 2; index++) + { + sp[index] = dst0.as_u8[offset + 5 + index] << shift; + sp[index] = + dst0.as_u8[offset + 6 + index] >> (8 - shift); + } + } + else { - *teid8p = dst0.as_u8[offset + 5 + index] << shift; - *teid8p |= - dst0.as_u8[offset + 6 + index] >> (8 - shift); - teid8p++; + for (index = 0; index < 4; index++) + { + *teid8p = dst0.as_u8[offset + 5 + index] << shift; + *teid8p |= + dst0.as_u8[offset + 6 + index] >> (8 - shift); + teid8p++; + } } } @@ -416,8 +436,15 @@ VLIB_NODE_FN (srv6_end_m_gtp4_e) (vlib_main_t * vm, { hdrlen = sizeof (gtpu_exthdr_t) + sizeof (gtpu_pdu_session_t); - len0 += hdrlen; } + else if (gtpu_type == GTPU_TYPE_ECHO_REQUEST + || gtpu_type == GTPU_TYPE_ECHO_REPLY + || gtpu_type == GTPU_TYPE_ERROR_INDICATION) + { + hdrlen = sizeof (gtpu_exthdr_t); + } + len0 += hdrlen; + hdrlen += sizeof (ip4_gtpu_header_t); // IPv4 GTP-U header creation. @@ -433,10 +460,7 @@ VLIB_NODE_FN (srv6_end_m_gtp4_e) (vlib_main_t * vm, hdr0->gtpu.teid = teid; hdr0->gtpu.length = clib_host_to_net_u16 (len0); - if (PREDICT_FALSE (tag != 0)) - { - gtp_type_set (&hdr0->gtpu, tag); - } + hdr0->gtpu.type = gtpu_type; if (qfi) { @@ -444,7 +468,9 @@ VLIB_NODE_FN (srv6_end_m_gtp4_e) (vlib_main_t * vm, gtpu_pdu_session_t *sess; hdr0->gtpu.ver_flags |= GTPU_EXTHDR_FLAG; + hdr0->gtpu.ext->seq = 0; + hdr0->gtpu.ext->npdu_num = 0; hdr0->gtpu.ext->nextexthdr = GTPU_EXTHDR_PDU_SESSION; @@ -465,6 +491,16 @@ VLIB_NODE_FN (srv6_end_m_gtp4_e) (vlib_main_t * vm, sess->nextexthdr = 0; } + if (gtpu_type == GTPU_TYPE_ECHO_REPLY + || gtpu_type == GTPU_TYPE_ECHO_REQUEST + || gtpu_type == GTPU_TYPE_ERROR_INDICATION) + { + hdr0->gtpu.ver_flags |= GTPU_SEQ_FLAG; + hdr0->gtpu.ext->seq = seq; + hdr0->gtpu.ext->npdu_num = 0; + hdr0->gtpu.ext->nextexthdr = 0; + } + offset = ls_param->v4src_position / 8; shift = ls_param->v4src_position % 8; @@ -618,6 +654,8 @@ VLIB_NODE_FN (srv6_t_m_gtp4_d) (vlib_main_t * vm, u8 *teidp; u8 qfi = 0; u8 *qfip = NULL; + u16 seq = 0; + u8 *seqp = NULL; u32 offset, shift, index; ip6srv_combo_header_t *ip6srv; gtpu_pdu_session_t *sess = NULL; @@ -632,10 +670,14 @@ VLIB_NODE_FN (srv6_t_m_gtp4_d) (vlib_main_t * vm, gtpu_type = hdr->gtpu.type; - if (hdr->gtpu.ver_flags & GTPU_EXTHDR_FLAG) + if (hdr->gtpu.ver_flags & (GTPU_EXTHDR_FLAG | GTPU_SEQ_FLAG)) { // Extention header. hdr_len += sizeof (gtpu_exthdr_t); + + seq = hdr->gtpu.ext->seq; + seqp = (u8 *) & seq; + if (hdr->gtpu.ext->nextexthdr == GTPU_EXTHDR_PDU_SESSION) { // PDU Session Container. @@ -682,7 +724,16 @@ VLIB_NODE_FN (srv6_t_m_gtp4_d) (vlib_main_t * vm, seg.as_u8[offset + 4] = qfi; } - clib_memcpy_fast (&seg.as_u8[offset + 5], teidp, 4); + if (gtpu_type == GTPU_TYPE_ECHO_REQUEST + || gtpu_type == GTPU_TYPE_ECHO_REPLY + || gtpu_type == GTPU_TYPE_ERROR_INDICATION) + { + clib_memcpy_fast (&seg.as_u8[offset + 5], seqp, 2); + } + else + { + clib_memcpy_fast (&seg.as_u8[offset + 5], teidp, 4); + } } else { @@ -691,10 +742,6 @@ VLIB_NODE_FN (srv6_t_m_gtp4_d) (vlib_main_t * vm, 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) @@ -711,6 +758,29 @@ VLIB_NODE_FN (srv6_t_m_gtp4_d) (vlib_main_t * vm, seg.as_u8[offset + 4] |= qfi >> shift; seg.as_u8[offset + 5] |= qfi << (8 - shift); } + + if (gtpu_type == GTPU_TYPE_ECHO_REQUEST + || gtpu_type == GTPU_TYPE_ECHO_REPLY + || gtpu_type == GTPU_TYPE_ERROR_INDICATION) + { + for (index = 0; index < 2; index++) + { + seg.as_u8[offset + 5 + index] |= + seqp[index] >> shift; + seg.as_u8[offset + 6 + index] |= + seqp[index] << (8 - shift); + } + } + else + { + for (index = 0; index < 4; index++) + { + seg.as_u8[offset + index + 5] |= + teidp[index] >> shift; + seg.as_u8[offset + index + 6] |= + teidp[index] << (8 - shift); + } + } } src6 = ls_param->v6src_prefix; @@ -785,16 +855,49 @@ VLIB_NODE_FN (srv6_t_m_gtp4_d) (vlib_main_t * vm, clib_memcpy_fast (ip6srv, sl->rewrite, vec_len (sl->rewrite)); - ip6srv->ip.protocol = IP_PROTOCOL_IPV6_ROUTE; + if (vec_len (sl->segments) > 1) + { + ip6srv->sr.tag = + clib_host_to_net_u16 (srh_tagfield[gtpu_type]); + + ip6srv->sr.segments_left += 1; + ip6srv->sr.last_entry += 1; - ip6srv->sr.tag = - clib_host_to_net_u16 (srh_tagfield[gtpu_type]); + ip6srv->sr.length += sizeof (ip6_address_t) / 8; + ip6srv->sr.segments[0] = seg; - ip6srv->sr.segments_left += 1; - ip6srv->sr.last_entry += 1; + 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 + { + ip6srv->ip.protocol = IP_PROTOCOL_IPV6_ROUTE; + + ip6srv->sr.type = ROUTING_HEADER_TYPE_SR; + + ip6srv->sr.segments_left = 1; + ip6srv->sr.last_entry = 0; + + ip6srv->sr.length = + ((sizeof (ip6_sr_header_t) + + sizeof (ip6_address_t)) / 8) - 1; + ip6srv->sr.flags = 0; - ip6srv->sr.length += sizeof (ip6_address_t) / 8; - ip6srv->sr.segments[0] = seg; + ip6srv->sr.tag = + clib_host_to_net_u16 (srh_tagfield[gtpu_type]); + + ip6srv->sr.segments[0] = seg; + if (vec_len (sl->segments)) + { + ip6srv->sr.segments[1] = sl->segments[0]; + ip6srv->sr.length += sizeof (ip6_address_t) / 8; + ip6srv->sr.last_entry++; + } + } if (PREDICT_TRUE (encap != NULL)) { @@ -842,13 +945,6 @@ VLIB_NODE_FN (srv6_t_m_gtp4_d) (vlib_main_t * vm, { 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 { @@ -1063,9 +1159,11 @@ VLIB_NODE_FN (srv6_end_m_gtp6_e) (vlib_main_t * vm, len0 = vlib_buffer_length_in_chain (vm, b0); - u32 teid; + u32 teid = 0; u8 *teid8p = (u8 *) & teid; u8 qfi = 0; + u16 seq = 0; + u8 gtpu_type = 0; u16 index; u16 offset, shift; u32 hdrlen = 0; @@ -1075,19 +1173,48 @@ VLIB_NODE_FN (srv6_end_m_gtp6_e) (vlib_main_t * vm, offset = index / 8; shift = index % 8; + gtpu_type = gtpu_type_get (tag); + if (PREDICT_TRUE (shift == 0)) { - clib_memcpy_fast (teid8p, &dst0.as_u8[offset], 4); + if (gtpu_type == GTPU_TYPE_ECHO_REQUEST + || gtpu_type == GTPU_TYPE_ECHO_REPLY + || gtpu_type == GTPU_TYPE_ERROR_INDICATION) + { + clib_memcpy_fast (&seq, &dst0.as_u8[offset], 2); + } + else + { + clib_memcpy_fast (teid8p, &dst0.as_u8[offset], 4); + } qfi = dst0.as_u8[offset + 4]; } else { - for (index = offset; index < offset + 4; index++) + u8 *sp; + + if (gtpu_type == GTPU_TYPE_ECHO_REQUEST + || gtpu_type == GTPU_TYPE_ECHO_REPLY + || gtpu_type == GTPU_TYPE_ERROR_INDICATION) { - *teid8p = dst0.as_u8[index] << shift; - *teid8p |= dst0.as_u8[index + 1] >> (8 - shift); - teid8p++; + sp = (u8 *) & seq; + for (index = 0; index < 2; index++) + { + sp[index] = dst0.as_u8[offset + index] << shift; + sp[index] = + dst0.as_u8[offset + index + 1] >> (8 - shift); + } + } + else + { + for (index = 0; index < 4; index++) + { + *teid8p = dst0.as_u8[offset + index] << shift; + *teid8p |= + dst0.as_u8[offset + index + 1] >> (8 - shift); + teid8p++; + } } qfi |= dst0.as_u8[offset + 4] << shift; @@ -1098,8 +1225,15 @@ VLIB_NODE_FN (srv6_end_m_gtp6_e) (vlib_main_t * vm, { hdrlen = sizeof (gtpu_exthdr_t) + sizeof (gtpu_pdu_session_t); - len0 += hdrlen; } + else if (gtpu_type == GTPU_TYPE_ECHO_REQUEST + || gtpu_type == GTPU_TYPE_ECHO_REPLY + || gtpu_type == GTPU_TYPE_ERROR_INDICATION) + { + hdrlen = sizeof (gtpu_exthdr_t); + } + + len0 += hdrlen; hdrlen += sizeof (ip6_gtpu_header_t); vlib_buffer_advance (b0, -(word) hdrlen); @@ -1112,10 +1246,7 @@ VLIB_NODE_FN (srv6_end_m_gtp6_e) (vlib_main_t * vm, hdr0->gtpu.teid = teid; hdr0->gtpu.length = clib_host_to_net_u16 (len0); - if (PREDICT_FALSE (tag != 0)) - { - gtp_type_set (&hdr0->gtpu, tag); - } + hdr0->gtpu.type = gtpu_type; if (qfi) { @@ -1123,6 +1254,7 @@ VLIB_NODE_FN (srv6_end_m_gtp6_e) (vlib_main_t * vm, gtpu_pdu_session_t *sess; hdr0->gtpu.ver_flags |= GTPU_EXTHDR_FLAG; + hdr0->gtpu.ext->seq = 0; hdr0->gtpu.ext->npdu_num = 0; hdr0->gtpu.ext->nextexthdr = GTPU_EXTHDR_PDU_SESSION; @@ -1144,6 +1276,16 @@ VLIB_NODE_FN (srv6_end_m_gtp6_e) (vlib_main_t * vm, sess->nextexthdr = 0; } + if (gtpu_type == GTPU_TYPE_ECHO_REQUEST + || gtpu_type == GTPU_TYPE_ECHO_REPLY + || gtpu_type == GTPU_TYPE_ERROR_INDICATION) + { + hdr0->gtpu.ver_flags |= GTPU_SEQ_FLAG; + hdr0->gtpu.ext->seq = seq; + hdr0->gtpu.ext->npdu_num = 0; + hdr0->gtpu.ext->nextexthdr = 0; + } + hdr0->udp.length = clib_host_to_net_u16 (len0 + sizeof (udp_header_t) + sizeof @@ -1241,6 +1383,8 @@ VLIB_NODE_FN (srv6_end_m_gtp6_d) (vlib_main_t * vm, u8 gtpu_type = 0; u8 qfi; u8 *qfip = NULL; + u16 seq = 0; + u8 *seqp = NULL; u32 offset, shift; u32 hdrlen; ip6_header_t *encap = NULL; @@ -1288,10 +1432,14 @@ VLIB_NODE_FN (srv6_end_m_gtp6_d) (vlib_main_t * vm, teid = hdr0->gtpu.teid; teidp = (u8 *) & teid; - if (hdr0->gtpu.ver_flags & GTPU_EXTHDR_FLAG) + if (hdr0->gtpu.ver_flags & (GTPU_EXTHDR_FLAG | GTPU_SEQ_FLAG)) { // Extention header. hdrlen += sizeof (gtpu_exthdr_t); + + seq = hdr0->gtpu.ext->seq; + seqp = (u8 *) & seq; + if (hdr0->gtpu.ext->nextexthdr == GTPU_EXTHDR_PDU_SESSION) { // PDU Session Container. @@ -1317,7 +1465,18 @@ VLIB_NODE_FN (srv6_end_m_gtp6_d) (vlib_main_t * vm, offset += 1; if (PREDICT_TRUE (shift == 0)) { - clib_memcpy_fast (&seg0.as_u8[offset], teidp, 4); + if (gtpu_type == GTPU_TYPE_ECHO_REQUEST + || gtpu_type == GTPU_TYPE_ECHO_REPLY + || gtpu_type == GTPU_TYPE_ERROR_INDICATION) + { + if (seqp) + clib_memcpy_fast (&seg0.as_u8[offset], seqp, 2); + } + else + { + clib_memcpy_fast (&seg0.as_u8[offset], teidp, 4); + } + if (qfip) { qfi = @@ -1336,11 +1495,28 @@ VLIB_NODE_FN (srv6_end_m_gtp6_d) (vlib_main_t * vm, { int idx; - for (idx = 0; idx < 4; idx++) + if (gtpu_type == GTPU_TYPE_ECHO_REQUEST + || gtpu_type == GTPU_TYPE_ECHO_REPLY + || gtpu_type == GTPU_TYPE_ERROR_INDICATION) + { + if (seqp) + { + for (idx = 0; idx < 2; idx++) + { + seg0.as_u8[offset + idx] |= seqp[idx] >> shift; + seg0.as_u8[offset + idx + 1] |= + seqp[idx] << (8 - shift); + } + } + } + else { - seg0.as_u8[offset + idx] |= teidp[idx] >> shift; - seg0.as_u8[offset + idx + 1] |= - teidp[idx] << (8 - shift); + for (idx = 0; idx < 4; idx++) + { + seg0.as_u8[offset + idx] |= teidp[idx] >> shift; + seg0.as_u8[offset + idx + 1] |= + teidp[idx] << (8 - shift); + } } if (qfip) @@ -1421,17 +1597,51 @@ VLIB_NODE_FN (srv6_end_m_gtp6_d) (vlib_main_t * vm, clib_memcpy_fast (ip6srv, sl->rewrite, vec_len (sl->rewrite)); - ip6srv->ip.src_address = src0; - ip6srv->ip.protocol = IP_PROTOCOL_IPV6_ROUTE; + if (vec_len (sl->segments) > 1) + { + ip6srv->ip.src_address = src0; - ip6srv->sr.tag = - clib_host_to_net_u16 (srh_tagfield[gtpu_type]); + ip6srv->sr.tag = + clib_host_to_net_u16 (srh_tagfield[gtpu_type]); + + ip6srv->sr.segments_left += 1; + ip6srv->sr.last_entry += 1; - ip6srv->sr.segments_left += 1; - ip6srv->sr.last_entry += 1; + ip6srv->sr.length += sizeof (ip6_address_t) / 8; + ip6srv->sr.segments[0] = seg0; - ip6srv->sr.length += sizeof (ip6_address_t) / 8; - ip6srv->sr.segments[0] = seg0; + 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 + { + ip6srv->ip.src_address = src0; + ip6srv->ip.protocol = IP_PROTOCOL_IPV6_ROUTE; + + ip6srv->sr.type = ROUTING_HEADER_TYPE_SR; + ip6srv->sr.segments_left = 1; + ip6srv->sr.last_entry = 0; + ip6srv->sr.length = + ((sizeof (ip6_sr_header_t) + + sizeof (ip6_address_t)) / 8) - 1; + ip6srv->sr.flags = 0; + + ip6srv->sr.tag = + clib_host_to_net_u16 (srh_tagfield[gtpu_type]); + + ip6srv->sr.segments[0] = seg0; + + if (vec_len (sl->segments)) + { + ip6srv->sr.segments[1] = sl->segments[0]; + ip6srv->sr.last_entry++; + ip6srv->sr.length += sizeof (ip6_address_t) / 8; + } + } if (PREDICT_TRUE (encap != NULL)) { @@ -1479,13 +1689,6 @@ VLIB_NODE_FN (srv6_end_m_gtp6_d) (vlib_main_t * vm, { 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 { @@ -1636,6 +1839,8 @@ VLIB_NODE_FN (srv6_end_m_gtp6_d_di) (vlib_main_t * vm, u8 gtpu_type = 0; u8 qfi = 0; u8 *qfip = NULL; + u16 seq = 0; + u8 *seqp = NULL; u32 offset, shift; u32 hdrlen; ip6_header_t *encap = NULL; @@ -1684,10 +1889,14 @@ VLIB_NODE_FN (srv6_end_m_gtp6_d_di) (vlib_main_t * vm, teid = hdr0->gtpu.teid; teidp = (u8 *) & teid; - if (hdr0->gtpu.ver_flags & GTPU_EXTHDR_FLAG) + if (hdr0->gtpu.ver_flags & (GTPU_EXTHDR_FLAG | GTPU_SEQ_FLAG)) { // Extention header. hdrlen += sizeof (gtpu_exthdr_t); + + seq = hdr0->gtpu.ext->seq; + seqp = (u8 *) & seq; + if (hdr0->gtpu.ext->nextexthdr == GTPU_EXTHDR_PDU_SESSION) { // PDU Session Container. @@ -1711,7 +1920,17 @@ VLIB_NODE_FN (srv6_end_m_gtp6_d_di) (vlib_main_t * vm, offset += 1; if (PREDICT_TRUE (shift == 0)) { - clib_memcpy_fast (&seg0.as_u8[offset], teidp, 4); + if (gtpu_type == GTPU_TYPE_ECHO_REQUEST + || gtpu_type == GTPU_TYPE_ECHO_REPLY + || gtpu_type == GTPU_TYPE_ERROR_INDICATION) + { + if (seqp) + clib_memcpy_fast (&seg0.as_u8[offset], seqp, 2); + } + else + { + clib_memcpy_fast (&seg0.as_u8[offset], teidp, 4); + } if (qfip) { @@ -1731,11 +1950,28 @@ VLIB_NODE_FN (srv6_end_m_gtp6_d_di) (vlib_main_t * vm, { int idx; - for (idx = 0; idx < 4; idx++) + if (gtpu_type == GTPU_TYPE_ECHO_REQUEST + || gtpu_type == GTPU_TYPE_ECHO_REPLY + || gtpu_type == GTPU_TYPE_ERROR_INDICATION) { - seg0.as_u8[offset + idx] |= teidp[idx] >> shift; - seg0.as_u8[offset + idx + 1] |= - teidp[idx] << (8 - shift); + if (seqp) + { + for (idx = 0; idx < 2; idx++) + { + seg0.as_u8[offset + idx] |= seqp[idx] >> shift; + seg0.as_u8[offset + idx + 1] |= + seqp[idx] << (8 - shift); + } + } + } + else + { + for (idx = 0; idx < 4; idx++) + { + seg0.as_u8[offset + idx] |= teidp[idx] >> shift; + seg0.as_u8[offset + idx + 1] |= + teidp[idx] << (8 - shift); + } } if (qfip) @@ -1807,13 +2043,54 @@ VLIB_NODE_FN (srv6_end_m_gtp6_d_di) (vlib_main_t * vm, clib_memcpy_fast (ip6srv, sl->rewrite, vec_len (sl->rewrite)); - ip6srv->ip.src_address = src0; + if (vec_len (sl->segments) > 1) + { + ip6srv->ip.src_address = src0; - ip6srv->sr.tag = - clib_host_to_net_u16 (srh_tagfield[gtpu_type]); + ip6srv->sr.tag = + clib_host_to_net_u16 (srh_tagfield[gtpu_type]); + + ip6srv->sr.segments_left += 2; + ip6srv->sr.last_entry += 2; - ip6srv->sr.segments_left += 2; - ip6srv->sr.last_entry += 2; + ip6srv->sr.length += ((sizeof (ip6_address_t) * 2) / 8); + + ip6srv->sr.segments[0] = dst0; + ip6srv->sr.segments[1] = seg0; + + clib_memcpy_fast (&ip6srv->sr.segments[2], + (u8 *) (sl->rewrite + + sizeof (ip6_header_t) + + sizeof (ip6_sr_header_t)), + vec_len (sl->segments) * + sizeof (ip6_address_t)); + } + else + { + ip6srv->ip.src_address = src0; + ip6srv->ip.protocol = IP_PROTOCOL_IPV6_ROUTE; + + ip6srv->sr.type = ROUTING_HEADER_TYPE_SR; + ip6srv->sr.segments_left = 2; + ip6srv->sr.last_entry = 1; + ip6srv->sr.length = + ((sizeof (ip6_sr_header_t) + + 2 * sizeof (ip6_address_t)) / 8) - 1; + ip6srv->sr.flags = 0; + + ip6srv->sr.tag = + clib_host_to_net_u16 (srh_tagfield[gtpu_type]); + + ip6srv->sr.segments[0] = dst0; + ip6srv->sr.segments[1] = seg0; + + if (vec_len (sl->segments)) + { + ip6srv->sr.segments[2] = sl->segments[0]; + ip6srv->sr.last_entry++; + ip6srv->sr.length += sizeof (ip6_address_t) / 8; + } + } } else { @@ -1823,12 +2100,18 @@ VLIB_NODE_FN (srv6_end_m_gtp6_d_di) (vlib_main_t * vm, ip6srv->ip.src_address = src0; ip6srv->ip.dst_address = seg0; + ip6srv->sr.type = ROUTING_HEADER_TYPE_SR; + ip6srv->sr.segments_left = 1; + ip6srv->sr.last_entry = 0; + ip6srv->sr.length = + ((sizeof (ip6_sr_header_t) + + sizeof (ip6_address_t)) / 8) - 1; + ip6srv->sr.flags = 0; + ip6srv->sr.tag = clib_host_to_net_u16 (srh_tagfield[gtpu_type]); - ip6srv->sr.segments_left += 1; - ip6srv->sr.last_entry += 1; - ip6srv->sr.type = ROUTING_HEADER_TYPE_SR; + ip6srv->sr.segments[0] = dst0; } ip6srv->ip.payload_length = @@ -1882,20 +2165,6 @@ VLIB_NODE_FN (srv6_end_m_gtp6_d_di) (vlib_main_t * vm, ip6srv->sr.protocol = IP_PROTOCOL_NONE; } - ip6srv->sr.length += ((sizeof (ip6_address_t) * 2) / 8); - ip6srv->sr.segments[0] = dst0; - ip6srv->sr.segments[1] = seg0; - - if (sl) - { - clib_memcpy_fast (&ip6srv->sr.segments[2], - (u8 *) (sl->rewrite + - sizeof (ip6_header_t) + - sizeof (ip6_sr_header_t)), - vec_len (sl->segments) * - sizeof (ip6_address_t)); - } - good_n++; if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE) && |