1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016 6WIND S.A.
5 #ifndef _RTE_NET_PTYPE_H_
6 #define _RTE_NET_PTYPE_H_
18 * Structure containing header lengths associated to a packet, filled
19 * by rte_net_get_ptype().
21 struct rte_net_hdr_lens {
32 * Skip IPv6 header extensions.
34 * This function skips all IPv6 extensions, returning size of
35 * complete header including options and final protocol value.
38 * @b EXPERIMENTAL: this API may change without prior notice
41 * Protocol field of IPv6 header.
43 * The packet mbuf to be parsed.
45 * On input, must contain the offset to the first byte following
46 * IPv6 header, on output, contains offset to the first byte
47 * of next layer (after any IPv6 extension header)
49 * Contains 1 in output if packet is an IPv6 fragment.
51 * Protocol that follows IPv6 header.
52 * -1 if an error occurs during mbuf parsing.
54 int __rte_experimental
55 rte_net_skip_ip6_ext(uint16_t proto, const struct rte_mbuf *m, uint32_t *off,
59 * Parse an Ethernet packet to get its packet type.
61 * This function parses the network headers in mbuf data and return its
64 * If it is provided by the user, it also fills a rte_net_hdr_lens
65 * structure that contains the lengths of the parsed network
66 * headers. Each length field is valid only if the associated packet
67 * type is set. For instance, hdr_lens->l2_len is valid only if
68 * (retval & RTE_PTYPE_L2_MASK) != RTE_PTYPE_UNKNOWN.
70 * Supported packet types are:
71 * L2: Ether, Vlan, QinQ
74 * Tunnels: IPv4, IPv6, Gre, Nvgre
77 * The packet mbuf to be parsed.
79 * A pointer to a structure where the header lengths will be returned,
82 * List of layers to parse. The function will stop at the first
83 * empty layer. Examples:
84 * - To parse all known layers, use RTE_PTYPE_ALL_MASK.
85 * - To parse only L2 and L3, use RTE_PTYPE_L2_MASK | RTE_PTYPE_L3_MASK
87 * The packet type of the packet.
89 uint32_t rte_net_get_ptype(const struct rte_mbuf *m,
90 struct rte_net_hdr_lens *hdr_lens, uint32_t layers);
93 * Prepare pseudo header checksum
95 * This function prepares pseudo header checksum for TSO and non-TSO tcp/udp in
96 * provided mbufs packet data and based on the requested offload flags.
98 * - for non-TSO tcp/udp packets full pseudo-header checksum is counted and set
100 * - for TSO the IP payload length is not included in pseudo header.
102 * This function expects that used headers are in the first data segment of
103 * mbuf, are not fragmented and can be safely modified.
106 * The packet mbuf to be fixed.
108 * TX offloads flags to use with this packet.
110 * 0 if checksum is initialized properly
113 rte_net_intel_cksum_flags_prepare(struct rte_mbuf *m, uint64_t ol_flags)
115 struct ipv4_hdr *ipv4_hdr;
116 struct ipv6_hdr *ipv6_hdr;
117 struct tcp_hdr *tcp_hdr;
118 struct udp_hdr *udp_hdr;
119 uint64_t inner_l3_offset = m->l2_len;
121 if ((ol_flags & PKT_TX_OUTER_IP_CKSUM) ||
122 (ol_flags & PKT_TX_OUTER_IPV6))
123 inner_l3_offset += m->outer_l2_len + m->outer_l3_len;
125 if ((ol_flags & PKT_TX_UDP_CKSUM) == PKT_TX_UDP_CKSUM) {
126 if (ol_flags & PKT_TX_IPV4) {
127 ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *,
130 if (ol_flags & PKT_TX_IP_CKSUM)
131 ipv4_hdr->hdr_checksum = 0;
133 udp_hdr = (struct udp_hdr *)((char *)ipv4_hdr +
135 udp_hdr->dgram_cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
138 ipv6_hdr = rte_pktmbuf_mtod_offset(m, struct ipv6_hdr *,
141 udp_hdr = rte_pktmbuf_mtod_offset(m, struct udp_hdr *,
142 inner_l3_offset + m->l3_len);
143 udp_hdr->dgram_cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
146 } else if ((ol_flags & PKT_TX_TCP_CKSUM) ||
147 (ol_flags & PKT_TX_TCP_SEG)) {
148 if (ol_flags & PKT_TX_IPV4) {
149 ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *,
152 if (ol_flags & PKT_TX_IP_CKSUM)
153 ipv4_hdr->hdr_checksum = 0;
155 /* non-TSO tcp or TSO */
156 tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr +
158 tcp_hdr->cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
161 ipv6_hdr = rte_pktmbuf_mtod_offset(m, struct ipv6_hdr *,
163 /* non-TSO tcp or TSO */
164 tcp_hdr = rte_pktmbuf_mtod_offset(m, struct tcp_hdr *,
165 inner_l3_offset + m->l3_len);
166 tcp_hdr->cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
175 * Prepare pseudo header checksum
177 * This function prepares pseudo header checksum for TSO and non-TSO tcp/udp in
178 * provided mbufs packet data.
180 * - for non-TSO tcp/udp packets full pseudo-header checksum is counted and set
182 * - for TSO the IP payload length is not included in pseudo header.
184 * This function expects that used headers are in the first data segment of
185 * mbuf, are not fragmented and can be safely modified.
188 * The packet mbuf to be fixed.
190 * 0 if checksum is initialized properly
193 rte_net_intel_cksum_prepare(struct rte_mbuf *m)
195 return rte_net_intel_cksum_flags_prepare(m, m->ol_flags);
203 #endif /* _RTE_NET_PTYPE_H_ */