Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2017 Intel Corporation 3 : : */ 4 : : 5 : : #ifndef _GSO_COMMON_H_ 6 : : #define _GSO_COMMON_H_ 7 : : 8 : : #include <stdint.h> 9 : : 10 : : #include <rte_ip.h> 11 : : #include <rte_tcp.h> 12 : : #include <rte_udp.h> 13 : : 14 : : #define IS_FRAGMENTED(frag_off) (((frag_off) & RTE_IPV4_HDR_OFFSET_MASK) != 0 \ 15 : : || ((frag_off) & RTE_IPV4_HDR_MF_FLAG) == RTE_IPV4_HDR_MF_FLAG) 16 : : 17 : : #define TCP_HDR_PSH_MASK ((uint8_t)0x08) 18 : : #define TCP_HDR_FIN_MASK ((uint8_t)0x01) 19 : : 20 : : #define IS_IPV4_TCP(flag) (((flag) & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_IPV4 | \ 21 : : RTE_MBUF_F_TX_TUNNEL_MASK)) == \ 22 : : (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_IPV4)) 23 : : 24 : : #define IS_IPV4_VXLAN_TCP4(flag) (((flag) & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_IPV4 | \ 25 : : RTE_MBUF_F_TX_OUTER_IPV4 | RTE_MBUF_F_TX_TUNNEL_MASK)) == \ 26 : : (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_IPV4 | RTE_MBUF_F_TX_OUTER_IPV4 | \ 27 : : RTE_MBUF_F_TX_TUNNEL_VXLAN)) 28 : : 29 : : #define IS_IPV4_VXLAN_UDP4(flag) (((flag) & (RTE_MBUF_F_TX_UDP_SEG | RTE_MBUF_F_TX_IPV4 | \ 30 : : RTE_MBUF_F_TX_OUTER_IPV4 | RTE_MBUF_F_TX_TUNNEL_MASK)) == \ 31 : : (RTE_MBUF_F_TX_UDP_SEG | RTE_MBUF_F_TX_IPV4 | RTE_MBUF_F_TX_OUTER_IPV4 | \ 32 : : RTE_MBUF_F_TX_TUNNEL_VXLAN)) 33 : : 34 : : #define IS_IPV4_GRE_TCP4(flag) (((flag) & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_IPV4 | \ 35 : : RTE_MBUF_F_TX_OUTER_IPV4 | RTE_MBUF_F_TX_TUNNEL_MASK)) == \ 36 : : (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_IPV4 | RTE_MBUF_F_TX_OUTER_IPV4 | \ 37 : : RTE_MBUF_F_TX_TUNNEL_GRE)) 38 : : 39 : : #define IS_IPV4_UDP(flag) (((flag) & (RTE_MBUF_F_TX_UDP_SEG | RTE_MBUF_F_TX_IPV4 | \ 40 : : RTE_MBUF_F_TX_TUNNEL_MASK)) == \ 41 : : (RTE_MBUF_F_TX_UDP_SEG | RTE_MBUF_F_TX_IPV4)) 42 : : 43 : : /** 44 : : * Internal function which updates the UDP header of a packet, following 45 : : * segmentation. This is required to update the header's datagram length field. 46 : : * 47 : : * @param pkt 48 : : * The packet containing the UDP header. 49 : : * @param udp_offset 50 : : * The offset of the UDP header from the start of the packet. 51 : : */ 52 : : static inline void 53 : : update_udp_header(struct rte_mbuf *pkt, uint16_t udp_offset) 54 : : { 55 : : struct rte_udp_hdr *udp_hdr; 56 : : 57 : 0 : udp_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_udp_hdr *, 58 : : udp_offset); 59 [ # # ]: 0 : udp_hdr->dgram_len = rte_cpu_to_be_16(pkt->pkt_len - udp_offset); 60 : 0 : } 61 : : 62 : : /** 63 : : * Internal function which updates the TCP header of a packet, following 64 : : * segmentation. This is required to update the header's 'sent' sequence 65 : : * number, and also to clear 'PSH' and 'FIN' flags for non-tail segments. 66 : : * 67 : : * @param pkt 68 : : * The packet containing the TCP header. 69 : : * @param l4_offset 70 : : * The offset of the TCP header from the start of the packet. 71 : : * @param sent_seq 72 : : * The sent sequence number. 73 : : * @param non-tail 74 : : * Indicates whether or not this is a tail segment. 75 : : */ 76 : : static inline void 77 : 0 : update_tcp_header(struct rte_mbuf *pkt, uint16_t l4_offset, uint32_t sent_seq, 78 : : uint8_t non_tail) 79 : : { 80 : : struct rte_tcp_hdr *tcp_hdr; 81 : : 82 : 0 : tcp_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_tcp_hdr *, 83 : : l4_offset); 84 [ # # ]: 0 : tcp_hdr->sent_seq = rte_cpu_to_be_32(sent_seq); 85 [ # # ]: 0 : if (likely(non_tail)) 86 : 0 : tcp_hdr->tcp_flags &= (~(TCP_HDR_PSH_MASK | 87 : : TCP_HDR_FIN_MASK)); 88 : 0 : } 89 : : 90 : : /** 91 : : * Internal function which updates the IPv4 header of a packet, following 92 : : * segmentation. This is required to update the header's 'total_length' field, 93 : : * to reflect the reduced length of the now-segmented packet. Furthermore, the 94 : : * header's 'packet_id' field must be updated to reflect the new ID of the 95 : : * now-segmented packet. 96 : : * 97 : : * @param pkt 98 : : * The packet containing the IPv4 header. 99 : : * @param l3_offset 100 : : * The offset of the IPv4 header from the start of the packet. 101 : : * @param id 102 : : * The new ID of the packet. 103 : : */ 104 : : static inline void 105 : 0 : update_ipv4_header(struct rte_mbuf *pkt, uint16_t l3_offset, uint16_t id) 106 : : { 107 : : struct rte_ipv4_hdr *ipv4_hdr; 108 : : 109 : 0 : ipv4_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *, 110 : : l3_offset); 111 [ # # ]: 0 : ipv4_hdr->total_length = rte_cpu_to_be_16(pkt->pkt_len - l3_offset); 112 [ # # ]: 0 : ipv4_hdr->packet_id = rte_cpu_to_be_16(id); 113 : 0 : } 114 : : 115 : : /** 116 : : * Internal function which divides the input packet into small segments. 117 : : * Each of the newly-created segments is organized as a two-segment MBUF, 118 : : * where the first segment is a standard mbuf, which stores a copy of 119 : : * packet header, and the second is an indirect mbuf which points to a 120 : : * section of data in the input packet. 121 : : * 122 : : * @param pkt 123 : : * Packet to segment. 124 : : * @param pkt_hdr_offset 125 : : * Packet header offset, measured in bytes. 126 : : * @param pyld_unit_size 127 : : * The max payload length of a GSO segment. 128 : : * @param direct_pool 129 : : * MBUF pool used for allocating direct buffers for output segments. 130 : : * @param indirect_pool 131 : : * MBUF pool used for allocating indirect buffers for output segments. 132 : : * @param pkts_out 133 : : * Pointer array used to keep the mbuf addresses of output segments. If 134 : : * the memory space in pkts_out is insufficient, gso_do_segment() fails 135 : : * and returns -EINVAL. 136 : : * @param nb_pkts_out 137 : : * The max number of items that pkts_out can keep. 138 : : * 139 : : * @return 140 : : * - The number of segments created in the event of success. 141 : : * - Return -ENOMEM if run out of memory in MBUF pools. 142 : : * - Return -EINVAL for invalid parameters. 143 : : */ 144 : : int gso_do_segment(struct rte_mbuf *pkt, 145 : : uint16_t pkt_hdr_offset, 146 : : uint16_t pyld_unit_size, 147 : : struct rte_mempool *direct_pool, 148 : : struct rte_mempool *indirect_pool, 149 : : struct rte_mbuf **pkts_out, 150 : : uint16_t nb_pkts_out); 151 : : #endif