26 #include <rte_ip_frag.h>
27 #include <rte_ether.h>
43 struct rte_ether_hdr *
eth;
46 eth = (
struct rte_ether_hdr *)data;
47 if (data +
sizeof(*
eth) > data_end) {
52 next_proto = rte_be_to_cpu_16(
eth->ether_type);
58 ctx->len =
sizeof(*eth);
59 ctx->next_proto = next_proto;
74 struct rte_ipv6_hdr *ipv6_hdr = (
struct rte_ipv6_hdr *)data;
75 struct rte_ipv6_fragment_ext *ipv6_frag_ext =
NULL;
76 size_t total_len =
sizeof(*ipv6_hdr);
81 if (data + total_len > data_end) {
85 proto = ipv6_hdr->proto;
87 while (proto != -EINVAL) {
88 if (proto == IPPROTO_FRAGMENT)
89 ipv6_frag_ext = (
struct rte_ipv6_fragment_ext *)(data + total_len);
93 proto = rte_ipv6_get_next_ext(data + total_len, proto, &ext_len);
95 if (data + total_len > data_end) {
96 DOCA_LOG_DBG(
"Error parsing IPv6 header with extensions");
101 ctx->next_proto = next_proto;
102 ctx->ipv6.hdr = ipv6_hdr;
105 ctx->ipv6.frag_ext = ipv6_frag_ext;
107 ctx->len = total_len;
119 if (data == data_end) {
123 version = *data >> 4;
128 DOCA_LOG_DBG(
"Expected IPv4 header, got version 0x%x", version);
133 ipv4_hdr = (
struct rte_ipv4_hdr *)data;
134 if (data +
sizeof(*
ipv4_hdr) > data_end) {
138 hdr_len = rte_ipv4_hdr_len(
ipv4_hdr);
139 if (data + hdr_len > data_end) {
146 ctx->frag = rte_ipv4_frag_pkt_is_fragmented(
ipv4_hdr);
151 DOCA_LOG_DBG(
"Expected IPv6 header, got version 0x%x", version);
178 tcp_hdr = (
struct rte_tcp_hdr *)data;
180 if (data +
sizeof(*
tcp_hdr) > data_end) {
184 hdr_len = rte_tcp_hdr_len(
tcp_hdr);
185 if (data + hdr_len > data_end) {
194 udp_hdr = (
struct rte_udp_hdr *)data;
196 if (data +
sizeof(*
udp_hdr) > data_end) {
201 ctx->len =
sizeof(*udp_hdr);
215 struct rte_gtp_psc_type0_hdr *gtpext_hdr =
NULL;
216 struct rte_gtp_hdr_ext_word *gtpopt_hdr =
NULL;
217 struct rte_gtp_hdr *gtp_hdr;
218 uint8_t *data_beg = data;
221 gtp_hdr = (
struct rte_gtp_hdr *)data;
222 if (data +
sizeof(*gtp_hdr) > data_end) {
226 data +=
sizeof(*gtp_hdr);
228 if (gtp_hdr->ver != 1) {
229 DOCA_LOG_WARN(
"Unsupported GTPU version %hhu", gtp_hdr->ver);
233 if (gtp_hdr->e || gtp_hdr->s || gtp_hdr->pn) {
234 gtpopt_hdr = (
struct rte_gtp_hdr_ext_word *)data;
235 if (data +
sizeof(*gtpopt_hdr) > data_end) {
239 data +=
sizeof(*gtpopt_hdr);
243 if (gtpopt_hdr->next_ext != 0x85) {
244 DOCA_LOG_WARN(
"Unsupported GTPU extension %hhu", gtpopt_hdr->next_ext);
248 gtpext_hdr = (
struct rte_gtp_psc_type0_hdr *)data;
250 gtpext_len =
sizeof(*gtpext_hdr) + 1;
251 if (data + gtpext_len > data_end) {
257 if (gtpext_hdr->ext_hdr_len != 1) {
258 DOCA_LOG_WARN(
"GTPU extension sizes more than 1 word are not supported %u",
259 gtpext_hdr->ext_hdr_len != 1);
263 if (gtpext_hdr->data[0]) {
264 DOCA_LOG_WARN(
"Chained GTPU extensions are not supported, type %hhu",
265 gtpext_hdr->data[0]);
271 ctx->len = data - data_beg;
272 ctx->gtp_hdr = gtp_hdr;
273 ctx->opt_hdr = gtpopt_hdr;
274 ctx->ext_hdr = gtpext_hdr;
285 ctx->len +=
ctx->network_ctx.len;
286 if (
ctx->network_ctx.frag)
293 ctx->len +=
ctx->transport_ctx.len;
305 ctx->len +=
ctx->link_ctx.len;
317 ctx->len +=
ctx->link_ctx.len;
322 ctx->len +=
ctx->network_ctx.len;
323 if (
ctx->network_ctx.frag)
330 ctx->len +=
ctx->transport_ctx.len;
335 ctx->len +=
ctx->gtp_ctx.len;
339 ctx->len +=
ctx->inner.len;
364 if (network_ctx.
frag) {
370 ctx->inner.link_ctx = link_ctx;
371 ctx->inner.network_ctx = network_ctx;
384 ctx->inner.link_ctx = link_ctx;
385 ctx->inner.network_ctx = network_ctx;
386 ctx->inner.transport_ctx = transport_ctx;
393 ctx->link_ctx = link_ctx;
394 ctx->network_ctx = network_ctx;
395 ctx->transport_ctx = transport_ctx;
401 ctx->len +=
ctx->gtp_ctx.len;
405 ctx->len +=
ctx->inner.len;
enum doca_error doca_error_t
DOCA API return codes.
@ DOCA_ERROR_INVALID_VALUE
@ DOCA_ERROR_NOT_SUPPORTED
#define DOCA_FLOW_PROTO_IPV4
#define DOCA_FLOW_PROTO_UDP
#define DOCA_FLOW_ETHER_TYPE_IPV6
#define DOCA_FLOW_PROTO_TCP
#define DOCA_FLOW_PROTO_IPV6
#define DOCA_FLOW_GTPU_DEFAULT_PORT
#define DOCA_FLOW_ETHER_TYPE_IPV4
#define DOCA_LOG_WARN(format,...)
Generates a WARNING application log message.
#define DOCA_LOG_DBG(format,...)
Generates a DEBUG application log message.
static doca_error_t ipv6_hdr_parse(const uint8_t *data, const uint8_t *data_end, struct network_parser_ctx *ctx)
DOCA_LOG_REGISTER(PACKET_PARSER)
doca_error_t unknown_parse(uint8_t *data, uint8_t *data_end, struct tun_parser_ctx *ctx, enum parser_pkt_type *parser_pkt_type)
doca_error_t gtpu_parse(uint8_t *data, uint8_t *data_end, struct gtp_parser_ctx *ctx)
doca_error_t tunnel_parse(uint8_t *data, uint8_t *data_end, struct tun_parser_ctx *ctx)
doca_error_t network_parse(uint8_t *data, uint8_t *data_end, uint16_t expected_proto, struct network_parser_ctx *ctx)
doca_error_t link_parse(uint8_t *data, uint8_t *data_end, struct link_parser_ctx *ctx)
doca_error_t conn_parse(uint8_t *data, uint8_t *data_end, struct conn_parser_ctx *ctx)
doca_error_t plain_parse(uint8_t *data, uint8_t *data_end, struct conn_parser_ctx *ctx)
doca_error_t transport_parse(uint8_t *data, uint8_t *data_end, uint8_t proto, struct transport_parser_ctx *ctx)
@ PARSER_PKT_TYPE_TUNNELED
struct rte_udp_hdr * udp_hdr
struct upf_accel_ctx * ctx