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 * Parse an Ethernet packet to get its packet type.
34 * This function parses the network headers in mbuf data and return its
37 * If it is provided by the user, it also fills a rte_net_hdr_lens
38 * structure that contains the lengths of the parsed network
39 * headers. Each length field is valid only if the associated packet
40 * type is set. For instance, hdr_lens->l2_len is valid only if
41 * (retval & RTE_PTYPE_L2_MASK) != RTE_PTYPE_UNKNOWN.
43 * Supported packet types are:
44 * L2: Ether, Vlan, QinQ
47 * Tunnels: IPv4, IPv6, Gre, Nvgre
50 * The packet mbuf to be parsed.
52 * A pointer to a structure where the header lengths will be returned,
55 * List of layers to parse. The function will stop at the first
56 * empty layer. Examples:
57 * - To parse all known layers, use RTE_PTYPE_ALL_MASK.
58 * - To parse only L2 and L3, use RTE_PTYPE_L2_MASK | RTE_PTYPE_L3_MASK
60 * The packet type of the packet.
62 uint32_t rte_net_get_ptype(const struct rte_mbuf *m,
63 struct rte_net_hdr_lens *hdr_lens, uint32_t layers);
66 * Prepare pseudo header checksum
68 * This function prepares pseudo header checksum for TSO and non-TSO tcp/udp in
69 * provided mbufs packet data and based on the requested offload flags.
71 * - for non-TSO tcp/udp packets full pseudo-header checksum is counted and set
73 * - for TSO the IP payload length is not included in pseudo header.
75 * This function expects that used headers are in the first data segment of
76 * mbuf, are not fragmented and can be safely modified.
79 * The packet mbuf to be fixed.
81 * TX offloads flags to use with this packet.
83 * 0 if checksum is initialized properly
86 rte_net_intel_cksum_flags_prepare(struct rte_mbuf *m, uint64_t ol_flags)
88 struct ipv4_hdr *ipv4_hdr;
89 struct ipv6_hdr *ipv6_hdr;
90 struct tcp_hdr *tcp_hdr;
91 struct udp_hdr *udp_hdr;
92 uint64_t inner_l3_offset = m->l2_len;
94 if ((ol_flags & PKT_TX_OUTER_IP_CKSUM) ||
95 (ol_flags & PKT_TX_OUTER_IPV6))
96 inner_l3_offset += m->outer_l2_len + m->outer_l3_len;
98 if ((ol_flags & PKT_TX_UDP_CKSUM) == PKT_TX_UDP_CKSUM) {
99 if (ol_flags & PKT_TX_IPV4) {
100 ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *,
103 if (ol_flags & PKT_TX_IP_CKSUM)
104 ipv4_hdr->hdr_checksum = 0;
106 udp_hdr = (struct udp_hdr *)((char *)ipv4_hdr +
108 udp_hdr->dgram_cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
111 ipv6_hdr = rte_pktmbuf_mtod_offset(m, struct ipv6_hdr *,
114 udp_hdr = rte_pktmbuf_mtod_offset(m, struct udp_hdr *,
115 inner_l3_offset + m->l3_len);
116 udp_hdr->dgram_cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
119 } else if ((ol_flags & PKT_TX_TCP_CKSUM) ||
120 (ol_flags & PKT_TX_TCP_SEG)) {
121 if (ol_flags & PKT_TX_IPV4) {
122 ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *,
125 if (ol_flags & PKT_TX_IP_CKSUM)
126 ipv4_hdr->hdr_checksum = 0;
128 /* non-TSO tcp or TSO */
129 tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr +
131 tcp_hdr->cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
134 ipv6_hdr = rte_pktmbuf_mtod_offset(m, struct ipv6_hdr *,
136 /* non-TSO tcp or TSO */
137 tcp_hdr = rte_pktmbuf_mtod_offset(m, struct tcp_hdr *,
138 inner_l3_offset + m->l3_len);
139 tcp_hdr->cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
148 * Prepare pseudo header checksum
150 * This function prepares pseudo header checksum for TSO and non-TSO tcp/udp in
151 * provided mbufs packet data.
153 * - for non-TSO tcp/udp packets full pseudo-header checksum is counted and set
155 * - for TSO the IP payload length is not included in pseudo header.
157 * This function expects that used headers are in the first data segment of
158 * mbuf, are not fragmented and can be safely modified.
161 * The packet mbuf to be fixed.
163 * 0 if checksum is initialized properly
166 rte_net_intel_cksum_prepare(struct rte_mbuf *m)
168 return rte_net_intel_cksum_flags_prepare(m, m->ol_flags);
176 #endif /* _RTE_NET_PTYPE_H_ */