LCOV - code coverage report
Current view: top level - lib/gso - gso_common.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 43 0.0 %
Date: 2026-11-01 19:11:22 Functions: 0 2 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 34 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2017 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <stdbool.h>
       6                 :            : #include <errno.h>
       7                 :            : 
       8                 :            : #include <rte_memcpy.h>
       9                 :            : 
      10                 :            : #include "gso_common.h"
      11                 :            : 
      12                 :            : static inline void
      13                 :          0 : hdr_segment_init(struct rte_mbuf *hdr_segment, struct rte_mbuf *pkt,
      14                 :            :                 uint16_t pkt_hdr_offset)
      15                 :            : {
      16                 :            :         /* Copy MBUF metadata */
      17                 :          0 :         hdr_segment->nb_segs = 1;
      18                 :          0 :         hdr_segment->port = pkt->port;
      19                 :          0 :         hdr_segment->ol_flags = pkt->ol_flags;
      20                 :          0 :         hdr_segment->packet_type = pkt->packet_type;
      21                 :          0 :         hdr_segment->pkt_len = pkt_hdr_offset;
      22                 :          0 :         hdr_segment->data_len = pkt_hdr_offset;
      23                 :          0 :         hdr_segment->tx_offload = pkt->tx_offload;
      24                 :            : 
      25                 :            :         /* Copy the packet header */
      26                 :          0 :         rte_memcpy(rte_pktmbuf_mtod(hdr_segment, char *),
      27         [ #  # ]:          0 :                         rte_pktmbuf_mtod(pkt, char *),
      28                 :            :                         pkt_hdr_offset);
      29                 :          0 : }
      30                 :            : 
      31                 :            : static inline void
      32                 :            : free_gso_segment(struct rte_mbuf **pkts, uint16_t nb_pkts)
      33                 :            : {
      34                 :            :         uint16_t i;
      35                 :            : 
      36   [ #  #  #  #  :          0 :         for (i = 0; i < nb_pkts; i++)
                   #  # ]
      37                 :          0 :                 rte_pktmbuf_free(pkts[i]);
      38                 :            : }
      39                 :            : 
      40                 :            : int
      41         [ #  # ]:          0 : gso_do_segment(struct rte_mbuf *pkt,
      42                 :            :                 uint16_t pkt_hdr_offset,
      43                 :            :                 uint16_t pyld_unit_size,
      44                 :            :                 struct rte_mempool *direct_pool,
      45                 :            :                 struct rte_mempool *indirect_pool,
      46                 :            :                 struct rte_mbuf **pkts_out,
      47                 :            :                 uint16_t nb_pkts_out)
      48                 :            : {
      49                 :            :         struct rte_mbuf *pkt_in;
      50                 :            :         struct rte_mbuf *hdr_segment, *pyld_segment, *prev_segment;
      51                 :            :         uint16_t pkt_in_data_pos, segment_bytes_remaining;
      52                 :            :         uint16_t pyld_len, nb_segs;
      53                 :            :         uint16_t direct_buf_size, direct_tailroom;
      54                 :            :         bool more_in_pkt, more_out_segs;
      55                 :            : 
      56                 :            :         /*
      57                 :            :          * The header must be fully contained in pkt's first segment and must fit
      58                 :            :          * in a freshly allocated direct_pool mbuf.
      59                 :            :          */
      60                 :            :         direct_buf_size = rte_pktmbuf_data_room_size(direct_pool);
      61         [ #  # ]:          0 :         if (unlikely(direct_buf_size <= (uint16_t)RTE_PKTMBUF_HEADROOM))
      62                 :            :                 return -EINVAL;
      63                 :          0 :         direct_tailroom = direct_buf_size - RTE_PKTMBUF_HEADROOM;
      64   [ #  #  #  # ]:          0 :         if (unlikely(pkt_hdr_offset > pkt->data_len || pkt_hdr_offset > direct_tailroom))
      65                 :            :                 return -EINVAL;
      66                 :            : 
      67                 :            :         pkt_in = pkt;
      68                 :            :         nb_segs = 0;
      69                 :            :         more_in_pkt = 1;
      70                 :            :         pkt_in_data_pos = pkt_hdr_offset;
      71                 :            : 
      72         [ #  # ]:          0 :         while (more_in_pkt) {
      73         [ #  # ]:          0 :                 if (unlikely(nb_segs >= nb_pkts_out)) {
      74                 :            :                         free_gso_segment(pkts_out, nb_segs);
      75                 :            :                         return -EINVAL;
      76                 :            :                 }
      77                 :            : 
      78                 :            :                 /* Allocate a direct MBUF */
      79                 :          0 :                 hdr_segment = rte_pktmbuf_alloc(direct_pool);
      80         [ #  # ]:          0 :                 if (unlikely(hdr_segment == NULL)) {
      81                 :            :                         free_gso_segment(pkts_out, nb_segs);
      82                 :            :                         return -ENOMEM;
      83                 :            :                 }
      84                 :            :                 /* Fill the packet header */
      85                 :          0 :                 hdr_segment_init(hdr_segment, pkt, pkt_hdr_offset);
      86                 :            : 
      87                 :            :                 prev_segment = hdr_segment;
      88                 :            :                 segment_bytes_remaining = pyld_unit_size;
      89                 :            :                 more_out_segs = 1;
      90                 :            : 
      91         [ #  # ]:          0 :                 while (more_out_segs && more_in_pkt) {
      92                 :            :                         /* Allocate an indirect MBUF */
      93                 :          0 :                         pyld_segment = rte_pktmbuf_alloc(indirect_pool);
      94         [ #  # ]:          0 :                         if (unlikely(pyld_segment == NULL)) {
      95                 :          0 :                                 rte_pktmbuf_free(hdr_segment);
      96                 :            :                                 free_gso_segment(pkts_out, nb_segs);
      97                 :            :                                 return -ENOMEM;
      98                 :            :                         }
      99                 :            :                         /* Attach to current MBUF segment of pkt */
     100                 :          0 :                         rte_pktmbuf_attach(pyld_segment, pkt_in);
     101                 :            : 
     102                 :          0 :                         prev_segment->next = pyld_segment;
     103                 :            :                         prev_segment = pyld_segment;
     104                 :            : 
     105                 :            :                         pyld_len = segment_bytes_remaining;
     106         [ #  # ]:          0 :                         if (pyld_len + pkt_in_data_pos > pkt_in->data_len)
     107                 :          0 :                                 pyld_len = pkt_in->data_len - pkt_in_data_pos;
     108                 :            : 
     109                 :          0 :                         pyld_segment->data_off = pkt_in_data_pos +
     110                 :          0 :                                 pkt_in->data_off;
     111                 :          0 :                         pyld_segment->data_len = pyld_len;
     112                 :            : 
     113                 :            :                         /* Update header segment */
     114                 :          0 :                         hdr_segment->pkt_len += pyld_len;
     115                 :          0 :                         hdr_segment->nb_segs++;
     116                 :            : 
     117                 :          0 :                         pkt_in_data_pos += pyld_len;
     118                 :          0 :                         segment_bytes_remaining -= pyld_len;
     119                 :            : 
     120                 :            :                         /* Finish processing a MBUF segment of pkt */
     121         [ #  # ]:          0 :                         if (pkt_in_data_pos == pkt_in->data_len) {
     122                 :          0 :                                 pkt_in = pkt_in->next;
     123                 :            :                                 pkt_in_data_pos = 0;
     124         [ #  # ]:          0 :                                 if (pkt_in == NULL)
     125                 :            :                                         more_in_pkt = 0;
     126                 :            :                         }
     127                 :            : 
     128                 :            :                         /* Finish generating a GSO segment */
     129         [ #  # ]:          0 :                         if (segment_bytes_remaining == 0)
     130                 :            :                                 more_out_segs = 0;
     131                 :            :                 }
     132                 :          0 :                 pkts_out[nb_segs++] = hdr_segment;
     133                 :            :         }
     134                 :          0 :         return nb_segs;
     135                 :            : }

Generated by: LCOV version 1.14