1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 1982, 1986, 1990, 1993 3 * The Regents of the University of California. 4 * Copyright(c) 2010-2014 Intel Corporation. 5 * All rights reserved. 6 */ 7 8 #ifndef _RTE_GTP_H_ 9 #define _RTE_GTP_H_ 10 11 /** 12 * @file 13 * 14 * GTP-related defines 15 */ 16 17 #include <stdint.h> 18 #include <rte_byteorder.h> 19 20 /** 21 * Simplified GTP protocol header. 22 * Contains 8-bit header info, 8-bit message type, 23 * 16-bit payload length after mandatory header, 32-bit TEID. 24 * No optional fields and next extension header. 25 */ 26 __extension__ 27 struct __rte_packed_begin rte_gtp_hdr { 28 union { 29 uint8_t gtp_hdr_info; /**< GTP header info */ 30 struct { 31 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN 32 uint8_t pn:1; /**< N-PDU Number present bit */ 33 uint8_t s:1; /**< Sequence Number Present bit */ 34 uint8_t e:1; /**< Extension Present bit */ 35 uint8_t res1:1; /**< Reserved */ 36 uint8_t pt:1; /**< Protocol Type bit */ 37 uint8_t ver:3; /**< Version Number */ 38 #elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN 39 uint8_t ver:3; /**< Version Number */ 40 uint8_t pt:1; /**< Protocol Type bit */ 41 uint8_t res1:1; /**< Reserved */ 42 uint8_t e:1; /**< Extension Present bit */ 43 uint8_t s:1; /**< Sequence Number Present bit */ 44 uint8_t pn:1; /**< N-PDU Number present bit */ 45 #endif 46 }; 47 }; 48 uint8_t msg_type; /**< GTP message type */ 49 rte_be16_t plen; /**< Total payload length */ 50 rte_be32_t teid; /**< Tunnel endpoint ID */ 51 } __rte_packed_end; 52 53 /* Optional word of GTP header, present if any of E, S, PN is set. */ 54 struct __rte_packed_begin rte_gtp_hdr_ext_word { 55 rte_be16_t sqn; /**< Sequence Number. */ 56 uint8_t npdu; /**< N-PDU number. */ 57 uint8_t next_ext; /**< Next Extension Header Type. */ 58 } __rte_packed_end; 59 60 /** 61 * Optional extension for GTP with next_ext set to 0x85 62 * defined based on RFC 38415-g30. 63 */ 64 __extension__ 65 struct __rte_packed_begin rte_gtp_psc_generic_hdr { 66 uint8_t ext_hdr_len; /**< PDU ext hdr len in multiples of 4 bytes */ 67 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN 68 uint8_t type:4; /**< PDU type */ 69 uint8_t qmp:1; /**< Qos Monitoring Packet */ 70 uint8_t pad:3; /**< type specific pad bits */ 71 uint8_t spare:2; /**< type specific spare bits */ 72 uint8_t qfi:6; /**< Qos Flow Identifier */ 73 #else 74 uint8_t pad:3; /**< type specific pad bits */ 75 uint8_t qmp:1; /**< Qos Monitoring Packet */ 76 uint8_t type:4; /**< PDU type */ 77 uint8_t qfi:6; /**< Qos Flow Identifier */ 78 uint8_t spare:2; /**< type specific spare bits */ 79 #endif 80 uint8_t data[0]; /**< variable length data fields */ 81 } __rte_packed_end; 82 83 /** 84 * Optional extension for GTP with next_ext set to 0x85 85 * type0 defined based on RFC 38415-g30 86 */ 87 __extension__ 88 struct __rte_packed_begin rte_gtp_psc_type0_hdr { 89 uint8_t ext_hdr_len; /**< PDU ext hdr len in multiples of 4 bytes */ 90 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN 91 uint8_t type:4; /**< PDU type */ 92 uint8_t qmp:1; /**< Qos Monitoring Packet */ 93 uint8_t snp:1; /**< Sequence number presence */ 94 uint8_t spare_dl1:2; /**< spare down link bits */ 95 uint8_t ppp:1; /**< Paging policy presence */ 96 uint8_t rqi:1; /**< Reflective Qos Indicator */ 97 uint8_t qfi:6; /**< Qos Flow Identifier */ 98 #else 99 uint8_t spare_dl1:2; /**< spare down link bits */ 100 uint8_t snp:1; /**< Sequence number presence */ 101 uint8_t qmp:1; /**< Qos Monitoring Packet */ 102 uint8_t type:4; /**< PDU type */ 103 uint8_t qfi:6; /**< Qos Flow Identifier */ 104 uint8_t rqi:1; /**< Reflective Qos Indicator */ 105 uint8_t ppp:1; /**< Paging policy presence */ 106 #endif 107 uint8_t data[0]; /**< variable length data fields */ 108 } __rte_packed_end; 109 110 /** 111 * Optional extension for GTP with next_ext set to 0x85 112 * type1 defined based on RFC 38415-g30 113 */ 114 __extension__ 115 struct __rte_packed_begin rte_gtp_psc_type1_hdr { 116 uint8_t ext_hdr_len; /**< PDU ext hdr len in multiples of 4 bytes */ 117 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN 118 uint8_t type:4; /**< PDU type */ 119 uint8_t qmp:1; /**< Qos Monitoring Packet */ 120 uint8_t dl_delay_ind:1; /**< dl delay result presence */ 121 uint8_t ul_delay_ind:1; /**< ul delay result presence */ 122 uint8_t snp:1; /**< Sequence number presence ul */ 123 uint8_t n_delay_ind:1; /**< N3/N9 delay result presence */ 124 uint8_t spare_ul2:1; /**< spare up link bits */ 125 uint8_t qfi:6; /**< Qos Flow Identifier */ 126 #else 127 uint8_t snp:1; /**< Sequence number presence ul */ 128 uint8_t ul_delay_ind:1; /**< ul delay result presence */ 129 uint8_t dl_delay_ind:1; /**< dl delay result presence */ 130 uint8_t qmp:1; /**< Qos Monitoring Packet */ 131 uint8_t type:4; /**< PDU type */ 132 uint8_t qfi:6; /**< Qos Flow Identifier */ 133 uint8_t spare_ul2:1; /**< spare up link bits */ 134 uint8_t n_delay_ind:1; /**< N3/N9 delay result presence */ 135 #endif 136 uint8_t data[0]; /**< variable length data fields */ 137 } __rte_packed_end; 138 139 /** GTP header length */ 140 #define RTE_ETHER_GTP_HLEN \ 141 (sizeof(struct rte_udp_hdr) + sizeof(struct rte_gtp_hdr)) 142 /* GTP next protocol type */ 143 #define RTE_GTP_TYPE_IPV4 0x40 /**< GTP next protocol type IPv4 */ 144 #define RTE_GTP_TYPE_IPV6 0x60 /**< GTP next protocol type IPv6 */ 145 /* GTP destination port number */ 146 #define RTE_GTPC_UDP_PORT 2123 /**< GTP-C UDP destination port */ 147 #define RTE_GTPU_UDP_PORT 2152 /**< GTP-U UDP destination port */ 148 149 #endif /* RTE_GTP_H_ */ 150