NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
packet_parser.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2025 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 
26 #ifndef PACKET_PARSER_H_
27 #define PACKET_PARSER_H_
28 
29 #include <stdint.h>
30 #include <stdbool.h>
31 #include <unistd.h>
32 
33 #include <doca_error.h>
34 
40 };
41 
43  size_t len; /* Total length of headers parsed */
44  uint16_t next_proto; /* Next protocol */
45  struct rte_ether_hdr *eth; /* Ethernet header */
46 };
47 
49  size_t len; /* Total length of headers parsed */
50  uint8_t ip_version; /* Version of IP */
51  uint8_t next_proto; /* Next protocol */
52  bool frag; /* Flag indicating fragmented packet */
53  union {
54  struct rte_ipv4_hdr *ipv4_hdr; /* IPv4 header */
55  struct {
56  struct rte_ipv6_hdr *hdr; /* IPv6 header */
57  struct rte_ipv6_fragment_ext *frag_ext; /* IPv6 fragmentation extension header */
58  } ipv6;
59  };
60 };
61 
63  uint8_t proto; /* Protocol ID */
64  size_t len; /* Total length of headers parsed */
65  union {
66  struct rte_udp_hdr *udp_hdr; /* UDP header, when proto==UDP */
67  struct rte_tcp_hdr *tcp_hdr; /* TCP header, when proto==TCP */
68  };
69 };
70 
72  size_t len; /* Total length of headers parsed */
73  struct rte_gtp_hdr *gtp_hdr; /* GTP protocol header */
74  struct rte_gtp_hdr_ext_word *opt_hdr; /* GTP option header */
75  struct rte_gtp_psc_type0_hdr *ext_hdr; /* GTP extension header */
76 };
77 
79  size_t len; /* Total length of headers parsed */
80  struct link_parser_ctx link_ctx; /* Link-layer parser context */
81  struct network_parser_ctx network_ctx; /* Network-layer parser context */
82  struct transport_parser_ctx transport_ctx; /* Transport-layer parser context */
83 };
84 
86  size_t len; /* Total length of headers parsed */
87  struct link_parser_ctx link_ctx; /* Link-layer parser context */
88  struct network_parser_ctx network_ctx; /* Network-layer parser context */
89  struct transport_parser_ctx transport_ctx; /* Transport-layer parser context */
90  struct gtp_parser_ctx gtp_ctx; /* GTP tunnel parser context */
91  struct conn_parser_ctx inner; /* Tunnel-encapsulated connection parser context */
92 };
93 
94 /*
95  * Parse link-layer protocol headers
96  *
97  * @data [in]: pointer to the start of the data
98  * @data_end [in]: pointer to the end of the data
99  * @ctx [out]: pointer to the parser context
100  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
101  */
102 doca_error_t link_parse(uint8_t *data, uint8_t *data_end, struct link_parser_ctx *ctx);
103 
104 /*
105  * Parse network-layer protocol headers
106  *
107  * @data [in]: pointer to the start of the data
108  * @data_end [in]: pointer to the end of the data
109  * @expected_proto [in]: expected network-layer protocol as indicated by upper layer
110  * @ctx [out]: pointer to the parser context
111  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
112  */
113 doca_error_t network_parse(uint8_t *data, uint8_t *data_end, uint16_t expected_proto, struct network_parser_ctx *ctx);
114 
115 /*
116  * Parse transport-layer protocol headers
117  *
118  * @data [in]: pointer to the start of the data
119  * @data_end [in]: pointer to the end of the data
120  * @proto [in]: transport-layer protocol as indicated by upper layer
121  * @ctx [out]: pointer to the parser context
122  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
123  */
124 doca_error_t transport_parse(uint8_t *data, uint8_t *data_end, uint8_t proto, struct transport_parser_ctx *ctx);
125 
126 /*
127  * Parse GPTU tunnel headers
128  *
129  * @data [in]: pointer to the start of the data
130  * @data_end [in]: pointer to the end of the data
131  * @ctx [out]: pointer to the parser context
132  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
133  */
134 doca_error_t gtpu_parse(uint8_t *data, uint8_t *data_end, struct gtp_parser_ctx *ctx);
135 
136 /*
137  * Parse the payload headers that identify the connection 5T
138  *
139  * @data [in]: pointer to the start of the data
140  * @data_end [in]: pointer to the end of the data
141  * @ctx [out]: pointer to the parser context
142  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
143  */
144 doca_error_t conn_parse(uint8_t *data, uint8_t *data_end, struct conn_parser_ctx *ctx);
145 
146 /*
147  * Parse a plain non-tunneled packet
148  *
149  * @data [in]: pointer to the start of the data
150  * @data_end [in]: pointer to the end of the data
151  * @ctx [out]: pointer to the parser context
152  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
153  */
154 doca_error_t plain_parse(uint8_t *data, uint8_t *data_end, struct conn_parser_ctx *ctx);
155 
156 /*
157  * Parse a tunneled packet
158  *
159  * @data [in]: pointer to the start of the data
160  * @data_end [in]: pointer to the end of the data
161  * @ctx [out]: pointer to the parser context
162  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
163  */
164 doca_error_t tunnel_parse(uint8_t *data, uint8_t *data_end, struct tun_parser_ctx *ctx);
165 
166 /*
167  * Parse a packet and establish its direction
168  *
169  * @data [in]: pointer to the start of the data
170  * @data_end [in]: pointer to the end of the data
171  * @ctx [out]: pointer to the parser context
172  * @parsed_pkt_type [out]: pointer store the incoming packet inferred type
173  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
174  */
175 doca_error_t unknown_parse(uint8_t *data,
176  uint8_t *data_end,
177  struct tun_parser_ctx *ctx,
178  enum parser_pkt_type *parsed_pkt_type);
179 
180 #endif /* PACKET_PARSER_H_ */
enum doca_error doca_error_t
DOCA API return codes.
doca_error_t unknown_parse(uint8_t *data, uint8_t *data_end, struct tun_parser_ctx *ctx, enum parser_pkt_type *parsed_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)
Definition: packet_parser.c:41
doca_error_t conn_parse(uint8_t *data, uint8_t *data_end, struct conn_parser_ctx *ctx)
parser_pkt_type
Definition: packet_parser.h:35
@ PARSER_PKT_TYPE_PLAIN
Definition: packet_parser.h:37
@ PARSER_PKT_TYPE_TUNNELED
Definition: packet_parser.h:36
@ PARSER_PKT_TYPE_NUM
Definition: packet_parser.h:39
@ PARSER_PKT_TYPE_UNKNOWN
Definition: packet_parser.h:38
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)
struct link_parser_ctx link_ctx
Definition: packet_parser.h:80
struct network_parser_ctx network_ctx
Definition: packet_parser.h:81
struct transport_parser_ctx transport_ctx
Definition: packet_parser.h:82
struct rte_gtp_hdr_ext_word * opt_hdr
Definition: packet_parser.h:74
struct rte_gtp_psc_type0_hdr * ext_hdr
Definition: packet_parser.h:75
struct rte_gtp_hdr * gtp_hdr
Definition: packet_parser.h:73
struct network_parser_ctx::@2::@4 ipv6
struct rte_ipv6_fragment_ext * frag_ext
Definition: packet_parser.h:57
struct rte_ipv6_hdr * hdr
Definition: packet_parser.h:56
struct rte_ipv4_hdr * ipv4_hdr
Definition: packet_parser.h:54
struct rte_udp_hdr * udp_hdr
Definition: packet_parser.h:66
struct rte_tcp_hdr * tcp_hdr
Definition: packet_parser.h:67
struct link_parser_ctx link_ctx
Definition: packet_parser.h:87
struct transport_parser_ctx transport_ctx
Definition: packet_parser.h:89
struct conn_parser_ctx inner
Definition: packet_parser.h:91
struct network_parser_ctx network_ctx
Definition: packet_parser.h:88
struct gtp_parser_ctx gtp_ctx
Definition: packet_parser.h:90
struct upf_accel_ctx * ctx