39 s =
format (s,
"GTPU decap from gtpu_tunnel%d teid %d next %d error %d",
44 s =
format (s,
"GTPU decap error - tunnel for teid %d does not exist",
66 u32 last_tunnel_index = ~0;
67 gtpu4_tunnel_key_t last_key4;
68 gtpu6_tunnel_key_t last_key6;
69 u32 pkts_decapsulated = 0;
71 u32 stats_sw_if_index, stats_n_packets, stats_n_bytes;
74 last_key4.as_u64 = ~0;
82 stats_sw_if_index =
node->runtime_data[0];
83 stats_n_packets = stats_n_bytes = 0;
90 to_next, n_left_to_next);
99 u32 gtpu_hdr_len0, gtpu_hdr_len1;
101 u32 tunnel_index0, tunnel_index1;
103 gtpu4_tunnel_key_t key4_0, key4_1;
104 gtpu6_tunnel_key_t key6_0, key6_1;
106 u32 sw_if_index0, sw_if_index1, len0, len1;
107 u8 has_space0, has_space1;
173 error0 = has_space0 ? GTPU_ERROR_BAD_VER : GTPU_ERROR_TOO_SMALL;
174 next0 = GTPU_INPUT_NEXT_DROP;
181 key4_0.teid = gtpu0->
teid;
190 error0 = GTPU_ERROR_NO_SUCH_TUNNEL;
191 next0 = GTPU_INPUT_NEXT_DROP;
194 last_key4.as_u64 = key4_0.as_u64;
195 tunnel_index0 = last_tunnel_index = p0[0];
198 tunnel_index0 = last_tunnel_index;
204 error0 = GTPU_ERROR_NO_SUCH_TUNNEL;
205 next0 = GTPU_INPUT_NEXT_DROP;
215 key4_0.teid = gtpu0->
teid;
224 error0 = GTPU_ERROR_NO_SUCH_TUNNEL;
225 next0 = GTPU_INPUT_NEXT_DROP;
229 key6_0.src.as_u64[0] = ip6_0->
src_address.as_u64[0];
230 key6_0.src.as_u64[1] = ip6_0->
src_address.as_u64[1];
231 key6_0.teid = gtpu0->
teid;
235 if (
PREDICT_FALSE (memcmp(&key6_0, &last_key6,
sizeof(last_key6)) != 0))
240 error0 = GTPU_ERROR_NO_SUCH_TUNNEL;
241 next0 = GTPU_INPUT_NEXT_DROP;
245 tunnel_index0 = last_tunnel_index = p0[0];
248 tunnel_index0 = last_tunnel_index;
254 error0 = GTPU_ERROR_NO_SUCH_TUNNEL;
255 next0 = GTPU_INPUT_NEXT_DROP;
265 key6_0.src.as_u64[0] = ip6_0->
dst_address.as_u64[0];
266 key6_0.src.as_u64[1] = ip6_0->
dst_address.as_u64[1];
267 key6_0.teid = gtpu0->
teid;
275 error0 = GTPU_ERROR_NO_SUCH_TUNNEL;
276 next0 = GTPU_INPUT_NEXT_DROP;
294 sw_if_index0 = (mt0) ? mt0->
sw_if_index : sw_if_index0;
296 pkts_decapsulated ++;
297 stats_n_packets += 1;
298 stats_n_bytes += len0;
304 stats_n_packets -= 1;
305 stats_n_bytes -= len0;
310 stats_n_packets, stats_n_bytes);
312 stats_n_bytes = len0;
313 stats_sw_if_index = sw_if_index0;
317 b0->
error = error0 ?
node->errors[error0] : 0;
326 tr->
teid = has_space0 ? clib_net_to_host_u32(gtpu0->
teid) : ~0;
331 error1 = has_space1 ? GTPU_ERROR_BAD_VER : GTPU_ERROR_TOO_SMALL;
332 next1 = GTPU_INPUT_NEXT_DROP;
339 key4_1.teid = gtpu1->
teid;
348 error1 = GTPU_ERROR_NO_SUCH_TUNNEL;
349 next1 = GTPU_INPUT_NEXT_DROP;
352 last_key4.as_u64 = key4_1.as_u64;
353 tunnel_index1 = last_tunnel_index = p1[0];
356 tunnel_index1 = last_tunnel_index;
362 error1 = GTPU_ERROR_NO_SUCH_TUNNEL;
363 next1 = GTPU_INPUT_NEXT_DROP;
373 key4_1.teid = gtpu1->
teid;
382 error1 = GTPU_ERROR_NO_SUCH_TUNNEL;
383 next1 = GTPU_INPUT_NEXT_DROP;
387 key6_1.src.as_u64[0] = ip6_1->
src_address.as_u64[0];
388 key6_1.src.as_u64[1] = ip6_1->
src_address.as_u64[1];
389 key6_1.teid = gtpu1->
teid;
393 if (
PREDICT_FALSE (memcmp(&key6_1, &last_key6,
sizeof(last_key6)) != 0))
399 error1 = GTPU_ERROR_NO_SUCH_TUNNEL;
400 next1 = GTPU_INPUT_NEXT_DROP;
405 tunnel_index1 = last_tunnel_index = p1[0];
408 tunnel_index1 = last_tunnel_index;
414 error1 = GTPU_ERROR_NO_SUCH_TUNNEL;
415 next1 = GTPU_INPUT_NEXT_DROP;
425 key6_1.src.as_u64[0] = ip6_1->
dst_address.as_u64[0];
426 key6_1.src.as_u64[1] = ip6_1->
dst_address.as_u64[1];
427 key6_1.teid = gtpu1->
teid;
435 error1 = GTPU_ERROR_NO_SUCH_TUNNEL;
436 next1 = GTPU_INPUT_NEXT_DROP;
454 sw_if_index1 = (mt1) ? mt1->sw_if_index : sw_if_index1;
456 pkts_decapsulated ++;
457 stats_n_packets += 1;
458 stats_n_bytes += len1;
464 stats_n_packets -= 1;
465 stats_n_bytes -= len1;
470 stats_n_packets, stats_n_bytes);
472 stats_n_bytes = len1;
473 stats_sw_if_index = sw_if_index1;
477 b1->
error = error1 ?
node->errors[error1] : 0;
486 tr->
teid = has_space1 ? clib_net_to_host_u32(gtpu1->
teid) : ~0;
490 to_next, n_left_to_next,
491 bi0, bi1, next0, next1);
506 gtpu4_tunnel_key_t key4_0;
507 gtpu6_tunnel_key_t key6_0;
509 u32 sw_if_index0, len0;
547 error0 = has_space0 ? GTPU_ERROR_BAD_VER : GTPU_ERROR_TOO_SMALL;
548 next0 = GTPU_INPUT_NEXT_DROP;
554 key4_0.teid = gtpu0->
teid;
563 error0 = GTPU_ERROR_NO_SUCH_TUNNEL;
564 next0 = GTPU_INPUT_NEXT_DROP;
567 last_key4.as_u64 = key4_0.as_u64;
568 tunnel_index0 = last_tunnel_index = p0[0];
571 tunnel_index0 = last_tunnel_index;
577 error0 = GTPU_ERROR_NO_SUCH_TUNNEL;
578 next0 = GTPU_INPUT_NEXT_DROP;
588 key4_0.teid = gtpu0->
teid;
597 error0 = GTPU_ERROR_NO_SUCH_TUNNEL;
598 next0 = GTPU_INPUT_NEXT_DROP;
602 key6_0.src.as_u64[0] = ip6_0->
src_address.as_u64[0];
603 key6_0.src.as_u64[1] = ip6_0->
src_address.as_u64[1];
604 key6_0.teid = gtpu0->
teid;
608 if (
PREDICT_FALSE (memcmp(&key6_0, &last_key6,
sizeof(last_key6)) != 0))
613 error0 = GTPU_ERROR_NO_SUCH_TUNNEL;
614 next0 = GTPU_INPUT_NEXT_DROP;
618 tunnel_index0 = last_tunnel_index = p0[0];
621 tunnel_index0 = last_tunnel_index;
627 error0 = GTPU_ERROR_NO_SUCH_TUNNEL;
628 next0 = GTPU_INPUT_NEXT_DROP;
638 key6_0.src.as_u64[0] = ip6_0->
dst_address.as_u64[0];
639 key6_0.src.as_u64[1] = ip6_0->
dst_address.as_u64[1];
640 key6_0.teid = gtpu0->
teid;
648 error0 = GTPU_ERROR_NO_SUCH_TUNNEL;
649 next0 = GTPU_INPUT_NEXT_DROP;
667 sw_if_index0 = (mt0) ? mt0->
sw_if_index : sw_if_index0;
669 pkts_decapsulated ++;
670 stats_n_packets += 1;
671 stats_n_bytes += len0;
677 stats_n_packets -= 1;
678 stats_n_bytes -= len0;
683 stats_n_packets, stats_n_bytes);
685 stats_n_bytes = len0;
686 stats_sw_if_index = sw_if_index0;
690 b0->
error = error0 ?
node->errors[error0] : 0;
699 tr->
teid = has_space0 ? clib_net_to_host_u32(gtpu0->
teid) : ~0;
702 to_next, n_left_to_next,
711 GTPU_ERROR_DECAPSULATED,
719 thread_index, stats_sw_if_index, stats_n_packets, stats_n_bytes);
720 node->runtime_data[0] = stats_sw_if_index;
741 #define gtpu_error(n,s) s,
748 .name =
"gtpu4-input",
750 .vector_size =
sizeof (
u32),
757 #define _(s,n) [GTPU_INPUT_NEXT_##s] = n,
768 .name =
"gtpu6-input",
770 .vector_size =
sizeof (
u32),
777 #define _(s,n) [GTPU_INPUT_NEXT_##s] = n,
802 vtep4_key_t last_vtep4;
804 vtep6_key_t last_vtep6;
831 u32 bi0, ip_len0, udp_len0, flags0, next0;
832 u32 bi1, ip_len1, udp_len1, flags1, next1;
833 i32 len_diff0, len_diff1;
834 u8 error0, good_udp0, proto0;
835 u8 error1, good_udp1, proto1;
846 bi0 = to_next[0] =
from[0];
847 bi1 = to_next[1] =
from[1];
885 if (proto0 != IP_PROTOCOL_UDP)
893 if (udp0->
dst_port != clib_host_to_net_u16 (UDP_DST_PORT_GTPU))
899 #ifdef CLIB_HAVE_VEC512
900 if (!vtep4_check_vector (>m->
vtep_table, b0, ip40, &last_vtep4,
914 good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
921 ip_len0 = clib_net_to_host_u16 (ip40->
length);
924 udp_len0 = clib_net_to_host_u16 (udp0->
length);
925 len_diff0 = ip_len0 - udp_len0;
930 if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
937 (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
943 error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM;
944 error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH;
948 error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM;
949 error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH;
954 b0->
error = error0 ? error_node->
errors[error0] : 0;
964 if (proto1 != IP_PROTOCOL_UDP)
972 if (udp1->
dst_port != clib_host_to_net_u16 (UDP_DST_PORT_GTPU))
978 #ifdef CLIB_HAVE_VEC512
979 if (!vtep4_check_vector (>m->
vtep_table, b1, ip41, &last_vtep4,
993 good_udp1 = (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
1000 ip_len1 = clib_net_to_host_u16 (ip41->
length);
1003 udp_len1 = clib_net_to_host_u16 (udp1->
length);
1004 len_diff1 = ip_len1 - udp_len1;
1009 if ((flags1 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
1016 (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
1022 error1 = good_udp1 ? 0 : IP4_ERROR_UDP_CHECKSUM;
1023 error1 = (len_diff1 >= 0) ? error1 : IP4_ERROR_UDP_LENGTH;
1027 error1 = good_udp1 ? 0 : IP6_ERROR_UDP_CHECKSUM;
1028 error1 = (len_diff1 >= 0) ? error1 : IP6_ERROR_UDP_LENGTH;
1033 b1->
error = error1 ? error_node->
errors[error1] : 0;
1043 to_next, n_left_to_next,
1044 bi0, bi1, next0, next1);
1053 u32 bi0, ip_len0, udp_len0, flags0, next0;
1055 u8 error0, good_udp0, proto0;
1057 bi0 = to_next[0] =
from[0];
1061 n_left_to_next -= 1;
1080 if (proto0 != IP_PROTOCOL_UDP)
1088 if (udp0->
dst_port != clib_host_to_net_u16 (UDP_DST_PORT_GTPU))
1094 #ifdef CLIB_HAVE_VEC512
1095 if (!vtep4_check_vector (>m->
vtep_table, b0, ip40, &last_vtep4,
1109 good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
1116 ip_len0 = clib_net_to_host_u16 (ip40->
length);
1119 udp_len0 = clib_net_to_host_u16 (udp0->
length);
1120 len_diff0 = ip_len0 - udp_len0;
1125 if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
1132 (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
1138 error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM;
1139 error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH;
1143 error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM;
1144 error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH;
1149 b0->
error = error0 ? error_node->
errors[error0] : 0;
1159 to_next, n_left_to_next,
1166 return frame->n_vectors;
1177 .name =
"ip4-gtpu-bypass",
1178 .vector_size =
sizeof (
u32),
1190 #ifndef CLIB_MARCH_VARIANT
1206 .name =
"ip6-gtpu-bypass",
1207 .vector_size =
sizeof (
u32),
1219 #ifndef CLIB_MARCH_VARIANT
1226 #define foreach_gtpu_flow_error \
1227 _(NONE, "no error") \
1228 _(PAYLOAD_ERROR, "Payload type errors") \
1229 _(IP_CHECKSUM_ERROR, "Rx ip checksum errors") \
1230 _(IP_HEADER_ERROR, "Rx ip header errors") \
1231 _(UDP_CHECKSUM_ERROR, "Rx udp checksum errors") \
1232 _(UDP_LENGTH_ERROR, "Rx udp length errors")
1236 #define _(f,s) GTPU_FLOW_ERROR_##f,
1239 #define gtpu_error(n,s) GTPU_FLOW_ERROR_##n,
1249 #define gtpu_error(n,s) s,
1256 #define gtpu_local_need_csum_check(_b) \
1257 (!(_b->flags & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED || \
1258 (_b->flags & VNET_BUFFER_F_OFFLOAD && \
1259 vnet_buffer (_b)->oflags & VNET_BUFFER_OFFLOAD_F_UDP_CKSUM)))
1261 #define gtpu_local_csum_is_valid(_b) \
1262 ((_b->flags & VNET_BUFFER_F_L4_CHECKSUM_CORRECT || \
1263 (_b->flags & VNET_BUFFER_F_OFFLOAD && \
1264 vnet_buffer (_b)->oflags & VNET_BUFFER_OFFLOAD_F_UDP_CKSUM)) != 0)
1273 if ((
flags & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
1280 return (
flags & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
1288 u16 ip_len = clib_net_to_host_u16 (ip4_hdr->
length);
1299 u16 ip_len = clib_net_to_host_u16 (ip4_hdr->
length);
1300 u16 udp_len = clib_net_to_host_u16 (udp_hdr->
length);
1301 return udp_len > ip_len;
1307 u8 error0 = GTPU_FLOW_ERROR_NONE;
1309 error0 = GTPU_FLOW_ERROR_IP_HEADER_ERROR;
1311 error0 = GTPU_FLOW_ERROR_UDP_LENGTH_ERROR;
1313 error0 = GTPU_FLOW_ERROR_UDP_CHECKSUM_ERROR;
1327 u32 pkts_decapsulated = 0;
1329 u32 stats_sw_if_index, stats_n_packets, stats_n_bytes;
1330 u8 ip_err0, ip_err1, udp_err0, udp_err1, csum_err0, csum_err1;
1336 stats_sw_if_index =
node->runtime_data[0];
1337 stats_n_packets = stats_n_bytes = 0;
1344 to_next, n_left_to_next);
1352 u32 gtpu_hdr_len0, gtpu_hdr_len1;
1353 u32 tunnel_index0, tunnel_index1;
1356 u32 sw_if_index0, sw_if_index1, len0, len1;
1357 u8 has_space0 = 0, has_space1 = 0;
1380 n_left_to_next -= 2;
1413 if (ip_err0 || udp_err0 || csum_err0)
1415 next0 = GTPU_INPUT_NEXT_DROP;
1433 error0 = has_space0 ? GTPU_ERROR_BAD_VER : GTPU_ERROR_TOO_SMALL;
1434 next0 = GTPU_INPUT_NEXT_DROP;
1451 error0 = GTPU_FLOW_ERROR_PAYLOAD_ERROR;
1452 next0 = GTPU_INPUT_NEXT_DROP;
1462 pkts_decapsulated ++;
1463 stats_n_packets += 1;
1464 stats_n_bytes += len0;
1470 stats_n_packets -= 1;
1471 stats_n_bytes -= len0;
1472 if (stats_n_packets)
1476 stats_n_packets, stats_n_bytes);
1477 stats_n_packets = 1;
1478 stats_n_bytes = len0;
1479 stats_sw_if_index = sw_if_index0;
1483 b0->
error = error0 ?
node->errors[error0] : 0;
1492 tr->
teid = has_space0 ? clib_net_to_host_u32(gtpu0->
teid) : ~0;
1495 if (ip_err1 || udp_err1 || csum_err1)
1497 next1 = GTPU_INPUT_NEXT_DROP;
1514 error1 = has_space1 ? GTPU_ERROR_BAD_VER : GTPU_ERROR_TOO_SMALL;
1515 next1 = GTPU_INPUT_NEXT_DROP;
1532 error1 = GTPU_FLOW_ERROR_PAYLOAD_ERROR;
1533 next1 = GTPU_INPUT_NEXT_DROP;
1549 pkts_decapsulated ++;
1550 stats_n_packets += 1;
1551 stats_n_bytes += len1;
1557 stats_n_packets -= 1;
1558 stats_n_bytes -= len1;
1559 if (stats_n_packets)
1563 stats_n_packets, stats_n_bytes);
1564 stats_n_packets = 1;
1565 stats_n_bytes = len1;
1566 stats_sw_if_index = sw_if_index1;
1570 b1->
error = error1 ?
node->errors[error1] : 0;
1579 tr->
teid = has_space1 ? clib_net_to_host_u32(gtpu1->
teid) : ~0;
1583 to_next, n_left_to_next,
1584 bi0, bi1, next0, next1);
1597 u32 sw_if_index0, len0;
1606 n_left_to_next -= 1;
1621 if (ip_err0 || udp_err0 || csum_err0)
1623 next0 = GTPU_INPUT_NEXT_DROP;
1644 error0 = has_space0 ? GTPU_ERROR_BAD_VER : GTPU_ERROR_TOO_SMALL;
1645 next0 = GTPU_INPUT_NEXT_DROP;
1661 error0 = GTPU_FLOW_ERROR_PAYLOAD_ERROR;
1662 next0 = GTPU_INPUT_NEXT_DROP;
1672 pkts_decapsulated ++;
1673 stats_n_packets += 1;
1674 stats_n_bytes += len0;
1680 stats_n_packets -= 1;
1681 stats_n_bytes -= len0;
1682 if (stats_n_packets)
1686 stats_n_packets, stats_n_bytes);
1687 stats_n_packets = 1;
1688 stats_n_bytes = len0;
1689 stats_sw_if_index = sw_if_index0;
1692 b0->
error = error0 ?
node->errors[error0] : 0;
1701 tr->
teid = has_space0 ? clib_net_to_host_u32(gtpu0->
teid) : ~0;
1704 to_next, n_left_to_next,
1713 GTPU_ERROR_DECAPSULATED,
1717 if (stats_n_packets)
1721 thread_index, stats_sw_if_index, stats_n_packets, stats_n_bytes);
1722 node->runtime_data[0] = stats_sw_if_index;
1737 #ifndef CLIB_MULTIARCH_VARIANT
1739 .name =
"gtpu4-flow-input",
1741 .vector_size =
sizeof (
u32),
1750 #define _(s,n) [GTPU_INPUT_NEXT_##s] = n,