xref: /dpdk/lib/net/rte_gtp.h (revision fba9875559906e04eaeb74532f4cfd51194259a2)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 1982, 1986, 1990, 1993
399a2dd95SBruce Richardson  *      The Regents of the University of California.
499a2dd95SBruce Richardson  * Copyright(c) 2010-2014 Intel Corporation.
599a2dd95SBruce Richardson  * All rights reserved.
699a2dd95SBruce Richardson  */
799a2dd95SBruce Richardson 
899a2dd95SBruce Richardson #ifndef _RTE_GTP_H_
999a2dd95SBruce Richardson #define _RTE_GTP_H_
1099a2dd95SBruce Richardson 
1199a2dd95SBruce Richardson /**
1299a2dd95SBruce Richardson  * @file
1399a2dd95SBruce Richardson  *
1499a2dd95SBruce Richardson  * GTP-related defines
1599a2dd95SBruce Richardson  */
1699a2dd95SBruce Richardson 
1799a2dd95SBruce Richardson #include <stdint.h>
1899a2dd95SBruce Richardson #include <rte_byteorder.h>
1999a2dd95SBruce Richardson 
2099a2dd95SBruce Richardson /**
2199a2dd95SBruce Richardson  * Simplified GTP protocol header.
2299a2dd95SBruce Richardson  * Contains 8-bit header info, 8-bit message type,
2399a2dd95SBruce Richardson  * 16-bit payload length after mandatory header, 32-bit TEID.
2499a2dd95SBruce Richardson  * No optional fields and next extension header.
2599a2dd95SBruce Richardson  */
2699a2dd95SBruce Richardson __extension__
27*fba98755SAndre Muezerie struct __rte_packed_begin rte_gtp_hdr {
2899a2dd95SBruce Richardson 	union {
2999a2dd95SBruce Richardson 		uint8_t gtp_hdr_info; /**< GTP header info */
3099a2dd95SBruce Richardson 		struct {
3199a2dd95SBruce Richardson #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
3299a2dd95SBruce Richardson 			uint8_t pn:1;   /**< N-PDU Number present bit */
3399a2dd95SBruce Richardson 			uint8_t s:1;    /**< Sequence Number Present bit */
3499a2dd95SBruce Richardson 			uint8_t e:1;    /**< Extension Present bit */
3599a2dd95SBruce Richardson 			uint8_t res1:1; /**< Reserved */
3699a2dd95SBruce Richardson 			uint8_t pt:1;   /**< Protocol Type bit */
3799a2dd95SBruce Richardson 			uint8_t ver:3;  /**< Version Number */
3899a2dd95SBruce Richardson #elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN
3999a2dd95SBruce Richardson 			uint8_t ver:3;  /**< Version Number */
4099a2dd95SBruce Richardson 			uint8_t pt:1;   /**< Protocol Type bit */
4199a2dd95SBruce Richardson 			uint8_t res1:1; /**< Reserved */
4299a2dd95SBruce Richardson 			uint8_t e:1;    /**< Extension Present bit */
4399a2dd95SBruce Richardson 			uint8_t s:1;    /**< Sequence Number Present bit */
4499a2dd95SBruce Richardson 			uint8_t pn:1;   /**< N-PDU Number present bit */
4599a2dd95SBruce Richardson #endif
4699a2dd95SBruce Richardson 		};
4799a2dd95SBruce Richardson 	};
4899a2dd95SBruce Richardson 	uint8_t msg_type;     /**< GTP message type */
4999a2dd95SBruce Richardson 	rte_be16_t plen;      /**< Total payload length */
5099a2dd95SBruce Richardson 	rte_be32_t teid;      /**< Tunnel endpoint ID */
51*fba98755SAndre Muezerie } __rte_packed_end;
5299a2dd95SBruce Richardson 
5399a2dd95SBruce Richardson /* Optional word of GTP header, present if any of E, S, PN is set. */
54*fba98755SAndre Muezerie struct __rte_packed_begin rte_gtp_hdr_ext_word {
5599a2dd95SBruce Richardson 	rte_be16_t sqn;	      /**< Sequence Number. */
5699a2dd95SBruce Richardson 	uint8_t npdu;	      /**< N-PDU number. */
5799a2dd95SBruce Richardson 	uint8_t next_ext;     /**< Next Extension Header Type. */
58*fba98755SAndre Muezerie } __rte_packed_end;
5999a2dd95SBruce Richardson 
60e8ca1479SRaslan Darawsheh /**
61e8ca1479SRaslan Darawsheh  * Optional extension for GTP with next_ext set to 0x85
62e8ca1479SRaslan Darawsheh  * defined based on RFC 38415-g30.
63e8ca1479SRaslan Darawsheh  */
64e8ca1479SRaslan Darawsheh __extension__
65*fba98755SAndre Muezerie struct __rte_packed_begin rte_gtp_psc_generic_hdr {
66e8ca1479SRaslan Darawsheh 	uint8_t ext_hdr_len;	/**< PDU ext hdr len in multiples of 4 bytes */
67e8ca1479SRaslan Darawsheh #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
68e8ca1479SRaslan Darawsheh 	uint8_t type:4;		/**< PDU type */
69e8ca1479SRaslan Darawsheh 	uint8_t qmp:1;		/**< Qos Monitoring Packet */
70e8ca1479SRaslan Darawsheh 	uint8_t pad:3;		/**< type specific pad bits */
71e8ca1479SRaslan Darawsheh 	uint8_t spare:2;	/**< type specific spare bits */
72e8ca1479SRaslan Darawsheh 	uint8_t qfi:6;		/**< Qos Flow Identifier */
73e8ca1479SRaslan Darawsheh #else
74e8ca1479SRaslan Darawsheh 	uint8_t pad:3;		/**< type specific pad bits */
75e8ca1479SRaslan Darawsheh 	uint8_t qmp:1;		/**< Qos Monitoring Packet */
76e8ca1479SRaslan Darawsheh 	uint8_t type:4;		/**< PDU type */
770718b771SGregory Etelson 	uint8_t qfi:6;		/**< Qos Flow Identifier */
780718b771SGregory Etelson 	uint8_t spare:2;	/**< type specific spare bits */
79e8ca1479SRaslan Darawsheh #endif
80e8ca1479SRaslan Darawsheh 	uint8_t data[0];	/**< variable length data fields */
81*fba98755SAndre Muezerie } __rte_packed_end;
82e8ca1479SRaslan Darawsheh 
83e8ca1479SRaslan Darawsheh /**
84e8ca1479SRaslan Darawsheh  * Optional extension for GTP with next_ext set to 0x85
85e8ca1479SRaslan Darawsheh  * type0 defined based on RFC 38415-g30
86e8ca1479SRaslan Darawsheh  */
87e8ca1479SRaslan Darawsheh __extension__
88*fba98755SAndre Muezerie struct __rte_packed_begin rte_gtp_psc_type0_hdr {
89e8ca1479SRaslan Darawsheh 	uint8_t ext_hdr_len;	/**< PDU ext hdr len in multiples of 4 bytes */
90e8ca1479SRaslan Darawsheh #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
91e8ca1479SRaslan Darawsheh 	uint8_t type:4;		/**< PDU type */
92e8ca1479SRaslan Darawsheh 	uint8_t qmp:1;		/**< Qos Monitoring Packet */
93e8ca1479SRaslan Darawsheh 	uint8_t snp:1;		/**< Sequence number presence */
94e8ca1479SRaslan Darawsheh 	uint8_t spare_dl1:2;	/**< spare down link bits */
95e8ca1479SRaslan Darawsheh 	uint8_t ppp:1;		/**< Paging policy presence */
96e8ca1479SRaslan Darawsheh 	uint8_t rqi:1;		/**< Reflective Qos Indicator */
97e8ca1479SRaslan Darawsheh 	uint8_t qfi:6;		/**< Qos Flow Identifier */
98e8ca1479SRaslan Darawsheh #else
990718b771SGregory Etelson 	uint8_t spare_dl1:2;	/**< spare down link bits */
1000718b771SGregory Etelson 	uint8_t snp:1;		/**< Sequence number presence */
1010718b771SGregory Etelson 	uint8_t qmp:1;		/**< Qos Monitoring Packet */
1020718b771SGregory Etelson 	uint8_t type:4;		/**< PDU type */
103e8ca1479SRaslan Darawsheh 	uint8_t qfi:6;		/**< Qos Flow Identifier */
104e8ca1479SRaslan Darawsheh 	uint8_t rqi:1;		/**< Reflective Qos Indicator */
105e8ca1479SRaslan Darawsheh 	uint8_t ppp:1;		/**< Paging policy presence */
106e8ca1479SRaslan Darawsheh #endif
107e8ca1479SRaslan Darawsheh 	uint8_t data[0];	/**< variable length data fields */
108*fba98755SAndre Muezerie } __rte_packed_end;
109e8ca1479SRaslan Darawsheh 
110e8ca1479SRaslan Darawsheh /**
111e8ca1479SRaslan Darawsheh  * Optional extension for GTP with next_ext set to 0x85
112e8ca1479SRaslan Darawsheh  * type1 defined based on RFC 38415-g30
113e8ca1479SRaslan Darawsheh  */
114e8ca1479SRaslan Darawsheh __extension__
115*fba98755SAndre Muezerie struct __rte_packed_begin rte_gtp_psc_type1_hdr {
116e8ca1479SRaslan Darawsheh 	uint8_t ext_hdr_len;	/**< PDU ext hdr len in multiples of 4 bytes */
117e8ca1479SRaslan Darawsheh #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
118e8ca1479SRaslan Darawsheh 	uint8_t type:4;		/**< PDU type */
119e8ca1479SRaslan Darawsheh 	uint8_t qmp:1;		/**< Qos Monitoring Packet */
120e8ca1479SRaslan Darawsheh 	uint8_t dl_delay_ind:1;	/**< dl delay result presence */
121e8ca1479SRaslan Darawsheh 	uint8_t ul_delay_ind:1;	/**< ul delay result presence */
122e8ca1479SRaslan Darawsheh 	uint8_t snp:1;		/**< Sequence number presence ul */
123e8ca1479SRaslan Darawsheh 	uint8_t n_delay_ind:1;	/**< N3/N9 delay result presence */
124e8ca1479SRaslan Darawsheh 	uint8_t spare_ul2:1;	/**< spare up link bits */
125e8ca1479SRaslan Darawsheh 	uint8_t qfi:6;		/**< Qos Flow Identifier */
126e8ca1479SRaslan Darawsheh #else
127e8ca1479SRaslan Darawsheh 	uint8_t snp:1;		/**< Sequence number presence ul */
128e8ca1479SRaslan Darawsheh 	uint8_t ul_delay_ind:1;	/**< ul delay result presence */
129e8ca1479SRaslan Darawsheh 	uint8_t dl_delay_ind:1;	/**< dl delay result presence */
130e8ca1479SRaslan Darawsheh 	uint8_t qmp:1;		/**< Qos Monitoring Packet */
131e8ca1479SRaslan Darawsheh 	uint8_t type:4;		/**< PDU type */
1320718b771SGregory Etelson 	uint8_t qfi:6;		/**< Qos Flow Identifier */
1330718b771SGregory Etelson 	uint8_t spare_ul2:1;	/**< spare up link bits */
1340718b771SGregory Etelson 	uint8_t n_delay_ind:1;	/**< N3/N9 delay result presence */
135e8ca1479SRaslan Darawsheh #endif
136e8ca1479SRaslan Darawsheh 	uint8_t data[0];	/**< variable length data fields */
137*fba98755SAndre Muezerie } __rte_packed_end;
138e8ca1479SRaslan Darawsheh 
13999a2dd95SBruce Richardson /** GTP header length */
14099a2dd95SBruce Richardson #define RTE_ETHER_GTP_HLEN \
14199a2dd95SBruce Richardson 	(sizeof(struct rte_udp_hdr) + sizeof(struct rte_gtp_hdr))
1424a6672c2SStephen Hemminger /* GTP next protocol type */
1434a6672c2SStephen Hemminger #define RTE_GTP_TYPE_IPV4 0x40 /**< GTP next protocol type IPv4 */
1444a6672c2SStephen Hemminger #define RTE_GTP_TYPE_IPV6 0x60 /**< GTP next protocol type IPv6 */
14599a2dd95SBruce Richardson /* GTP destination port number */
14699a2dd95SBruce Richardson #define RTE_GTPC_UDP_PORT 2123 /**< GTP-C UDP destination port */
14799a2dd95SBruce Richardson #define RTE_GTPU_UDP_PORT 2152 /**< GTP-U UDP destination port */
14899a2dd95SBruce Richardson 
14999a2dd95SBruce Richardson #endif /* RTE_GTP_H_ */
150