[ovs-discuss] DP_Packet Payload Modification

Luca Mancini luca.mancini at outlook.com
Sat Jun 6 09:08:17 UTC 2020


Hi Greg,
Here’s the devil!
This is from the file ofproto-dpif-xlate.c, my whole action for now is implemented in userspace

#define UDP_MAX_PAYLOAD_SIZE 65507
#define PACKET_BUFF_ELEMENTS 5
static int index1;
static struct my_captured_packet dp_packet_buff1[PACKET_BUFF_ELEMENTS];

struct my_captured_packet
{
    struct dp_packet packet;
    int sizeofpayload;
};
compose_buffr_action(struct xlate_ctx *ctx)
{
    //creates the buffer of packet
    if(index1 < 5 && ctx->xin->packet)
    {
        //clone incoming packet
        struct dp_packet *packet_to_store = dp_packet_clone(ctx->xin->packet);

        //build my_captured_packet array using dp_packet (not the pointer) and the payload size
        dp_packet_buff1[index1].packet = *packet_to_store;
        dp_packet_buff1[index1].sizeofpayload = dp_packet_l4_size(ctx->xin->packet) - UDP_HEADER_LEN;

        //print payload taking into account its size otherwiseugly memory overlap occurs
       VLOG_ERR("%.*s",dp_packet_buff1[index1].sizeofpayload, (char *) dp_packet_get_udp_payload(&dp_packet_buff1[index1].packet));
        index1++;
    }
    //create custom packet to send
    if(index1 == 5 )
    {
        index1 = 0;
        struct dp_packet *packetAggr;
        packetAggr = dp_packet_new(UDP_MAX_PAYLOAD_SIZE);

        struct flow flow;
        flow_extract(&dp_packet_buff1[0].packet, &flow);

        char * payload = "hello world";
        flow_compose(packetAggr, &flow, NULL, 0);
        dp_packet_put(packetAggr, payload, sizeof payload);

       int s = dp_packet_l4_size(packetAggr) - UDP_HEADER_LEN; //get length of payload to print
       VLOG_ERR("udp_pay of l4 of packet aggr: %.*s", s , (char *) dp_packet_get_udp_payload(packetAggr)); //prints “hello w”

        //extract buffer from custom packet print packets after extraction to see if I can retrieve the single dp_packets, commented out for now
       /*
       struct my_captured_packet *recvdpackets = (struct my_captured_packet *) dp_packet_data(packetAggr);
        for(int j=0; j<PACKET_BUFF_ELEMENTS; j++)
        {
            VLOG_ERR("payload #%d: %.*s", j, recvdpackets[j].sizeofpayload, (char *) dp_packet_get_udp_payload(&recvdpackets[j].packet));

        }
        */
        clear_packetBuff(dp_packet_buff1);

        }

   }

Hope this helps,

Luca

From: Gregory Rose<mailto:gvrose8192 at gmail.com>
Sent: Friday, June 5, 2020 23:05
To: Luca Mancini<mailto:luca.mancini at outlook.com>; ovs-discuss at openvswitch.org<mailto:ovs-discuss at openvswitch.org>
Subject: Re: [ovs-discuss] DP_Packet Payload Modification


On 6/5/2020 11:00 AM, Luca Mancini wrote:
>
> Hi Greg,
> I realized I didn’t give a lot of context..
> Basically, I’m implementing a custom action which is meant to buffer an x amount of dp_packets that match a certain flow, and then send a new packet directly from the switch, containing the buffer of packets, as its payload. At some other switch this payload is then meant to be extracted so that I can retrieve the buffer of dp_packets and send the single packets contained in the buffer to the correct hosts.
> My action is implemented in userspace only for now since efficiency isn’t a concern for me atm. I already implemented the buffering mechanism and it works, and now I’m trying to create this custom udp packet so that I can store the buffer in it. For now I’m only trying to create a dummy udp packet with a “hello world” string as its payload just to see if I can create this custom packet however I just can’t figure out what I’m missing. My most recent attempt is the following:
>
> 1.Extract flow from one of the previously stored dp_packets
> 2.create a new dp_packet with dp_packet_new(65035)
> 3.use flow_compose() function on new packet to create a valid packet
> 4.add payload with dp_packet_put
>
> Code:
> struct flow flow;
> flow_extract(&dp_packet_buff1[0].packet, &flow);
> flow_compose(packetAggr, &flow, NULL, 0);
> char * payload = "hello world";
> dp_packet_put(packetAggr, payload, sizeof payload);

Pseudo code looks fine but the devil is in all the other details.  I
need to see a patch to put it in context.

- Greg

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openvswitch.org/pipermail/ovs-discuss/attachments/20200606/2a4537ba/attachment.html>


More information about the discuss mailing list