[dpdk-dev] [PATCH v2 04/12] net: add function to calculate a checksum in a mbuf

Olivier MATZ olivier.matz at 6wind.com
Tue Oct 11 15:33:47 CEST 2016


Hi Maxime,

On 10/11/2016 03:25 PM, Maxime Coquelin wrote:
>>  /**
>> + * Compute the raw (non complemented) checksum of a packet.
>> + *
>> + * @param m
>> + *   The pointer to the mbuf.
>> + * @param off
>> + *   The offset in bytes to start the checksum.
>> + * @param len
>> + *   The length in bytes of the data to ckecksum.
>> + */
>> +static inline uint16_t
>> +rte_raw_cksum_mbuf(const struct rte_mbuf *m, uint32_t off, uint32_t len)
>> +{
>> +    const struct rte_mbuf *seg;
>> +    const char *buf;
>> +    uint32_t sum, tmp;
>> +    uint32_t seglen, done;
>> +
>> +    /* easy case: all data in the first segment */
>> +    if (off + len <= rte_pktmbuf_data_len(m))
>> +        return rte_raw_cksum(rte_pktmbuf_mtod_offset(m,
>> +                const char *, off), len);
>> +
>> +    if (off + len > rte_pktmbuf_pkt_len(m))
> unlikely?

Yes, will add it.

>> +        return 0; /* invalid params, return a dummy value */
> Couldn't be better to return an error, so that the caller has a chance
> to see it is passing wrong arguments?
> The csum would be passed as an arg.

Looks much better indeed. I'll change it for next revision.


Thanks,
Olivier




More information about the dev mailing list