DPDK patches and discussions
 help / color / mirror / Atom feed
* Strange behavior with rte_pktmbuf_clone cal
@ 2022-12-23  7:00 NAGENDRA BALAGANI
  2022-12-23 16:25 ` Konstantin Ananyev
  2022-12-23 16:43 ` Stephen Hemminger
  0 siblings, 2 replies; 3+ messages in thread
From: NAGENDRA BALAGANI @ 2022-12-23  7:00 UTC (permalink / raw)
  To: dev; +Cc: Kapil Kumar Jain


[-- Attachment #1.1: Type: text/plain, Size: 1798 bytes --]

Hi,

I am seeing strange behavior where rte_pktmbuf_clone is not giving desired result.
Here is the detailed info, in my dpdk application  , once I received the packet info in mbuf, I need to send the same packet to two destinations, the sequence  I should follow is,

(i)                  First, Tunnel the packet to one of desired destination, so I created the shallow copy using rte_pktmbuf_clone, had another mbuf for Outer IP Header for IPinIP tunnel and sent to NIC.

(ii)                Second, I need to modify the source and destination ip addresses of the packet and send out.

The issue, I am seeing is the tunneled packet (clone) have modified IP addresses from (ii).

Code flow:

Main()
{
Struct rte_mbuf *org_mbuf; //lets assume this org_mbuf is holding the packet info.

(i)                  Towards First destination.
Build_tunnel_packet(org_mbuf) {

-          Struct rte_mbuf *clone_buffer;
-          Allocate a clone buffer Clone_buffer = rte_pktmbuf_clone(org_mbuf, clone_pool);

-          Constructed IPinIP info in another mbuf and prepended in clone_buffer
-          Call rte_pktmbuf_tx_burst();
}

(ii)                Towards another destination.
Modify_l3_and_route(org_mbuf)
{

-          Modify L3 information of 'org_mbuf'
-          and Call rte_pkt_mbuf_tx_burst();
}

}

[cid:image001.jpg@01D916CA.5B7CCA10]

In the above screenshot, the packet 37 should tunneled as it is by adding the outer ip layer(i.e 182.16.146.*), but the inner L3 information also getting changed (which I am modifying in the second step) for some packets.
Using, rte_pktmbuf_copy(), solving the issue, but in expense of extra mbuf.


Please, help me in understanding what is wrong in the case of rte_pktmbuf_clone()?


Regards,
Nagendra



[-- Attachment #1.2: Type: text/html, Size: 15596 bytes --]

[-- Attachment #2: image001.jpg --]
[-- Type: image/jpeg, Size: 159359 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: Strange behavior with rte_pktmbuf_clone cal
  2022-12-23  7:00 Strange behavior with rte_pktmbuf_clone cal NAGENDRA BALAGANI
@ 2022-12-23 16:25 ` Konstantin Ananyev
  2022-12-23 16:43 ` Stephen Hemminger
  1 sibling, 0 replies; 3+ messages in thread
From: Konstantin Ananyev @ 2022-12-23 16:25 UTC (permalink / raw)
  To: NAGENDRA BALAGANI, dev; +Cc: Kapil Kumar Jain


[-- Attachment #1.1: Type: text/plain, Size: 2509 bytes --]

That's expected behavior.
rte_mbuf_clone() doesn't duplicate your packet data - instead
new mbuf just attaches to existing data packet.
If you need to modify one (or both) packet data after cloning -
you can use rte_pktmbuf_copy() instead.
As another alternative - have a look at examples/ip_multicast -
It demonstrates how to send sake packet to multiple ip destinations
over multiple ports without modifying the entire packet.
It looks that you are trying to do something quite similar.
Konstantin


From: NAGENDRA BALAGANI <nagendra.balagani@oracle.com>
Sent: Friday, December 23, 2022 7:01 AM
To: dev@dpdk.org
Cc: Kapil Kumar Jain <kapil.k.jain@oracle.com>
Subject: Strange behavior with rte_pktmbuf_clone cal

Hi,

I am seeing strange behavior where rte_pktmbuf_clone is not giving desired result.
Here is the detailed info, in my dpdk application  , once I received the packet info in mbuf, I need to send the same packet to two destinations, the sequence  I should follow is,

(i)                  First, Tunnel the packet to one of desired destination, so I created the shallow copy using rte_pktmbuf_clone, had another mbuf for Outer IP Header for IPinIP tunnel and sent to NIC.

(ii)                Second, I need to modify the source and destination ip addresses of the packet and send out.

The issue, I am seeing is the tunneled packet (clone) have modified IP addresses from (ii).

Code flow:

Main()
{
Struct rte_mbuf *org_mbuf; //lets assume this org_mbuf is holding the packet info.

(i)                  Towards First destination.
Build_tunnel_packet(org_mbuf) {


  *   Struct rte_mbuf *clone_buffer;

  *   Allocate a clone buffer Clone_buffer = rte_pktmbuf_clone(org_mbuf, clone_pool);


  *   Constructed IPinIP info in another mbuf and prepended in clone_buffer
  *   Call rte_pktmbuf_tx_burst();
}

(ii)                Towards another destination.
Modify_l3_and_route(org_mbuf)
{


  *   Modify L3 information of 'org_mbuf'
  *   and Call rte_pkt_mbuf_tx_burst();
}

}

[cid:image002.jpg@01D916EA.D92B9250]

In the above screenshot, the packet 37 should tunneled as it is by adding the outer ip layer(i.e 182.16.146.*), but the inner L3 information also getting changed (which I am modifying in the second step) for some packets.
Using, rte_pktmbuf_copy(), solving the issue, but in expense of extra mbuf.


Please, help me in understanding what is wrong in the case of rte_pktmbuf_clone()?


Regards,
Nagendra



[-- Attachment #1.2: Type: text/html, Size: 16426 bytes --]

[-- Attachment #2: image002.jpg --]
[-- Type: image/jpeg, Size: 87313 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Strange behavior with rte_pktmbuf_clone cal
  2022-12-23  7:00 Strange behavior with rte_pktmbuf_clone cal NAGENDRA BALAGANI
  2022-12-23 16:25 ` Konstantin Ananyev
@ 2022-12-23 16:43 ` Stephen Hemminger
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2022-12-23 16:43 UTC (permalink / raw)
  To: NAGENDRA BALAGANI; +Cc: dev, Kapil Kumar Jain

On Fri, 23 Dec 2022 07:00:40 +0000
NAGENDRA BALAGANI <nagendra.balagani@oracle.com> wrote:

> Hi,
> 
> I am seeing strange behavior where rte_pktmbuf_clone is not giving desired result.
> Here is the detailed info, in my dpdk application  , once I received the packet info in mbuf, I need to send the same packet to two destinations, the sequence  I should follow is,
> 
> (i)                  First, Tunnel the packet to one of desired destination, so I created the shallow copy using rte_pktmbuf_clone, had another mbuf for Outer IP Header for IPinIP tunnel and sent to NIC.
> 
> (ii)                Second, I need to modify the source and destination ip addresses of the packet and send out.

As you showed, that won't work like you think.
A shallow clone means that both versions share the same data area.
If you modify one one instance both change.

The best practice is to consider a clone (or any mbuf with refcount > 1) as read only.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-23 16:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-23  7:00 Strange behavior with rte_pktmbuf_clone cal NAGENDRA BALAGANI
2022-12-23 16:25 ` Konstantin Ananyev
2022-12-23 16:43 ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).