From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <shrivastav.shyam@gmail.com>
Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com
 [209.85.221.43]) by dpdk.org (Postfix) with ESMTP id EFC422B9A
 for <dev@dpdk.org>; Thu,  6 Dec 2018 06:52:31 +0100 (CET)
Received: by mail-wr1-f43.google.com with SMTP id j2so21985973wrw.1
 for <dev@dpdk.org>; Wed, 05 Dec 2018 21:52:31 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:references:in-reply-to:from:date:message-id:subject:to
 :cc; bh=nuHHSScF3ho0svNvs8Iu7jRbtTLHoqvSgoPrY5ZcOLQ=;
 b=Z18+oOuRaRT4sAdpFSvRp7DQAGKMamTqHd5P/f2JWcEPm9YZ2ww/pwyvLLQzA2sbqa
 Z56z/hNrg/pDpoWQhMLU1cGrjSqChq5osbmSW3lSK/i1pdgo7Nf6Dzp4Y1VK7VpC+tUX
 O2OfA2RJRZ/aTOX9rw2+t21ViaucR9tojpfoLbI/MeIhh5MtpepsjURG8FmsC9+HERYu
 JTRIjrHSCU/8zkznDi7uSJ1XUgQRD6lIjf5QCVMzsi07A9rCkfoT0/U5iSbMYmhoMhqy
 0rGdzyhwtI1qEre1rnvfdV+I2JYsA9SKZkh+dhDA5yhxpN4NXVhPMGudHKU4uGV2HiHe
 aQbg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:references:in-reply-to:from:date
 :message-id:subject:to:cc;
 bh=nuHHSScF3ho0svNvs8Iu7jRbtTLHoqvSgoPrY5ZcOLQ=;
 b=U3ZwsIsZVqVhkuPVEEW9jP5s2PLnrpYFDKYMrfFucv21UczkeelBiA28n87/FvkWSj
 VqNaMOS4gkVVnVi/PE/DcpBVAnOlBxTsNNPxMZfk2GQvwaTZ3qcEqfesUIcv/RfLeVtZ
 zmw8rL+MnE1uZ7V79Pn5IU8xLauGqT9w32QH+RBF3hpdp6cqSlVBREblHLOL/kyQ4WIv
 BR/eNSwayELTqMDDrEwah2bEa1PZtk5hQPeA3rYA6ffVz1VJNkpxrVlteMPflpHsl0YI
 Uhr414NKmqA5gH7eEFCpek2lI+qYo/MtoKOinpfGrTyyZqLLz0mBpgi9XFKXndnsBPqE
 RFAw==
X-Gm-Message-State: AA+aEWaermSLtWHZsPQChpZUTIXc7rjTvae4WPcxv28xphUi0Jpj9uq9
 UAeklSTgkA79HNJlDW+uIPevE6bUSXaDt9Mk6lY=
X-Google-Smtp-Source: AFSGD/Xa/ZO10/aviE/50oyuIxtdWqkfscY5+a9xytA4AB0KkjLzXo32tEsKFDxGltKaHjB44VTYkVc1+xMerJtJzUE=
X-Received: by 2002:a05:6000:f:: with SMTP id
 h15mr23426125wrx.248.1544075551600; 
 Wed, 05 Dec 2018 21:52:31 -0800 (PST)
MIME-Version: 1.0
References: <tencent_1D234E7425109D404F86B6466A1790162107@qq.com>
 <CAGSp03nzd4ckOGvBH9DZVwhXRz7UoEJZe2d+4uX2DejG0A4qCQ@mail.gmail.com>
In-Reply-To: <CAGSp03nzd4ckOGvBH9DZVwhXRz7UoEJZe2d+4uX2DejG0A4qCQ@mail.gmail.com>
From: Shyam Shrivastav <shrivastav.shyam@gmail.com>
Date: Thu, 6 Dec 2018 11:22:15 +0530
Message-ID: <CAGSp03mXtMRi9=KUu1w8LzuyHgLGfBrXe+HAkQMMK1Wrr_DSsw@mail.gmail.com>
To: 912873551@qq.com
Cc: dev@dpdk.org
Content-Type: text/plain; charset="UTF-8"
X-Content-Filtered-By: Mailman/MimeDel 2.1.15
Subject: Re: [dpdk-dev] About the data payload of rte_mbuf?
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Thu, 06 Dec 2018 05:52:32 -0000

And if just payload length is required one can get by subtracting
(ip-hdr-len + tcp-offset) from total length in ip header ...

On Thu, Dec 6, 2018 at 11:18 AM Shyam Shrivastav <shrivastav.shyam@gmail.com>
wrote:

>
> As per my understanding
>
> payload = (uint8_t *)tcp_hdr + (tcp_hdr->data_off << 2);
>
> should be
>
> payload = (uint8_t *)tcp_hdr + (tcp_hdr->data_off >> 4) << 2);
>
> Note that data offset is 4 most significant bits of the byte, refer tcp
> header
>
>
>
> On Thu, Dec 6, 2018 at 9:15 AM bai bakari <912873551@qq.com> wrote:
>
>> Hi,
>>
>>
>> Now, I want to get the data payload of rte_mbuf, and i wrote the
>> following code:
>>
>>
>> struct ipv4_hdr *ipv4_hdr;
>> struct tcp_hdr *tcp_hdr;
>> uint32_t payload_len, ip_len;
>> uint8_t *payload = NULL;
>>
>>
>>
>> ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *, sizeof(struct
>> ether_hdr));
>> ip_len = ntohs(ipv4_hdr->total_length);
>>
>>
>>
>> if (ipv4_hdr->next_proto_id == IPPROTO_TCP) {
>>     tcp_hdr = (struct tcp_hdr *)((uint8_t *)ipv4_hdr +
>> ((ipv4_hdr->version_ihl & 0xf) << 2));
>>     payload = (uint8_t *)tcp_hdr + (tcp_hdr->data_off << 2);
>>     payload_len = ip_len - (payload - (uint8_t *)ipv4_hdr);
>>
>> }
>>
>>
>> when i send packets using dpdk-pktgen, i found:
>> ip_len = 46
>> ip_header_len = 20
>> but the tcp_header_len=(tcp_hdr->data_off << 2)=0,
>> and (payload - (uint8_t *)ipv4_hdr) = 340 > ip_len.
>>
>>
>> I'm confused, is there any errors about the code to compute the
>> payload_len of rte_mbuf?
>> I think maybe the dpdk-pktgen cannot send the packets with payload?
>>
>>
>> I'm a beginner, anyone can help me how to compute the payload_len of
>> rte_mbuf and test it?
>>
>>
>> Thank you in advance!
>
>