[ovs-discuss] DP_Packet Payload Modification

2020-06-04 Thread Luca Mancini
Hello,
This is sort of a repost from my previous question about creating a custom udp 
payload.
I figured I could just clone a received udp payload and modify its payload, do 
you think this is possible?  I tried creating a packet from 0 but I just 
couldn’t manage to do it.

I’m guessing I could do something along the lines of dp_packet_clone(), 
dp_packet_l4() to get the pointer to the UDP header and then overwrite it with 
memcpy?
Any help is really appreciated, Thanks!

Luca Mancini

___
discuss mailing list
disc...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-discuss


Re: [ovs-discuss] DP_Packet Payload Modification

2020-06-05 Thread Gregory Rose




On 6/4/2020 10:06 AM, Luca Mancini wrote:

Hello,
This is sort of a repost from my previous question about creating a custom udp 
payload.
I figured I could just clone a received udp payload and modify its payload, do 
you think this is possible?  I tried creating a packet from 0 but I just 
couldn’t manage to do it.

I’m guessing I could do something along the lines of dp_packet_clone(), 
dp_packet_l4() to get the pointer to the UDP header and then overwrite it with 
memcpy?
Any help is really appreciated, Thanks!

Luca Mancini


Luca,

I'm having a hard time understanding this.  If you want to generate a
UDP packet with custom payload why not just use scapy or some other such
tool?

- Greg
___
discuss mailing list
disc...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-discuss


Re: [ovs-discuss] DP_Packet Payload Modification

2020-06-05 Thread Luca Mancini
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);

if I print out the payload I get the string “hello w” so maybe I’m forgetting 
something when I build the new packet.
Any help is very appreciated!

Cheers,

L

From: Gregory Rose<mailto:gvrose8...@gmail.com>
Sent: Friday, June 5, 2020 18:58
To: Luca Mancini<mailto:luca.manc...@outlook.com>; 
ovs-discuss@openvswitch.org<mailto:ovs-discuss@openvswitch.org>
Subject: Re: [ovs-discuss] DP_Packet Payload Modification



On 6/4/2020 10:06 AM, Luca Mancini wrote:
> Hello,
> This is sort of a repost from my previous question about creating a custom 
> udp payload.
> I figured I could just clone a received udp payload and modify its payload, 
> do you think this is possible?  I tried creating a packet from 0 but I just 
> couldn’t manage to do it.
>
> I’m guessing I could do something along the lines of dp_packet_clone(), 
> dp_packet_l4() to get the pointer to the UDP header and then overwrite it 
> with memcpy?
> Any help is really appreciated, Thanks!
>
> Luca Mancini

Luca,

I'm having a hard time understanding this.  If you want to generate a
UDP packet with custom payload why not just use scapy or some other such
tool?

- Greg

___
discuss mailing list
disc...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-discuss


Re: [ovs-discuss] DP_Packet Payload Modification

2020-06-05 Thread Luca Mancini

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);

if I print out the payload I get the string “hello w” so maybe I’m forgetting 
something when I build the new packet.
Any help is very appreciated!

Cheers,

L


From: Gregory Rose<mailto:gvrose8...@gmail.com>
Sent: Friday, June 5, 2020 18:58
To: Luca Mancini<mailto:luca.manc...@outlook.com>; 
ovs-discuss@openvswitch.org<mailto:ovs-discuss@openvswitch.org>
Subject: Re: [ovs-discuss] DP_Packet Payload Modification



On 6/4/2020 10:06 AM, Luca Mancini wrote:
> Hello,
> This is sort of a repost from my previous question about creating a custom 
> udp payload.
> I figured I could just clone a received udp payload and modify its payload, 
> do you think this is possible?  I tried creating a packet from 0 but I just 
> couldn’t manage to do it.
>
> I’m guessing I could do something along the lines of dp_packet_clone(), 
> dp_packet_l4() to get the pointer to the UDP header and then overwrite it 
> with memcpy?
> Any help is really appreciated, Thanks!
>
> Luca Mancini

Luca,

I'm having a hard time understanding this.  If you want to generate a
UDP packet with custom payload why not just use scapy or some other such
tool?

- Greg

___
discuss mailing list
disc...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-discuss


Re: [ovs-discuss] DP_Packet Payload Modification

2020-06-05 Thread Ben Pfaff
On Fri, Jun 05, 2020 at 05:56:54PM +, Luca Mancini wrote:
> 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

I'd use a local controller for this. Then you don't have to implement
anything in OVS at all.
___
discuss mailing list
disc...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-discuss


Re: [ovs-discuss] DP_Packet Payload Modification

2020-06-05 Thread Luca Mancini
Hi Ben,
I thought controllers didn’t have access to the complete packet but just the 
(packet_in msgs), so I was told to implement this in the switches and use the 
controller just as the “brain”.
I’d much rather work on a controller to be honest, however, do you not think 
its doable at all in OVS?

Cheers,

Luca

From: Ben Pfaff<mailto:b...@ovn.org>
Sent: Friday, June 5, 2020 21:32
To: Luca Mancini<mailto:luca.manc...@outlook.com>
Cc: Gregory Rose<mailto:gvrose8...@gmail.com>; 
ovs-discuss@openvswitch.org<mailto:ovs-discuss@openvswitch.org>
Subject: Re: [ovs-discuss] DP_Packet Payload Modification

On Fri, Jun 05, 2020 at 05:56:54PM +, Luca Mancini wrote:
> 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

I'd use a local controller for this. Then you don't have to implement
anything in OVS at all.

___
discuss mailing list
disc...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-discuss


Re: [ovs-discuss] DP_Packet Payload Modification

2020-06-05 Thread Ben Pfaff
The controller can get as much of the packet as it wants.  The number of
bytes to send is an operand of the action that sends a packet to the
controller.

Of course it's doable in OVS--but it's going to be more work and you'll
have to understand OVS internals instead of OpenFlow.

On Fri, Jun 05, 2020 at 07:47:56PM +, Luca Mancini wrote:
> Hi Ben,
> I thought controllers didn’t have access to the complete packet but just the 
> (packet_in msgs), so I was told to implement this in the switches and use the 
> controller just as the “brain”.
> I’d much rather work on a controller to be honest, however, do you not think 
> its doable at all in OVS?
> 
> Cheers,
> 
> Luca
> 
> From: Ben Pfaff<mailto:b...@ovn.org>
> Sent: Friday, June 5, 2020 21:32
> To: Luca Mancini<mailto:luca.manc...@outlook.com>
> Cc: Gregory Rose<mailto:gvrose8...@gmail.com>; 
> ovs-discuss@openvswitch.org<mailto:ovs-discuss@openvswitch.org>
> Subject: Re: [ovs-discuss] DP_Packet Payload Modification
> 
> On Fri, Jun 05, 2020 at 05:56:54PM +, Luca Mancini wrote:
> > 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
> 
> I'd use a local controller for this. Then you don't have to implement
> anything in OVS at all.
> 
___
discuss mailing list
disc...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-discuss


Re: [ovs-discuss] DP_Packet Payload Modification

2020-06-05 Thread luca . mancini
I think I'm at a decent point already considering it's part of a thesis work so i have time. As i said I already implemented the buffering part, i need a way to create a custom packet and then send it, all from userspace and that's about it i think.The fact that you're saying it's doable already makes me feel relieved! Going back on the original question, does the dp_packet class have all I need to create a valid packet or is there something else i should be looking at?Luca On Jun 5, 2020 22:18, Ben Pfaff  wrote:The controller can get as much of the packet as it wants.  The number of

bytes to send is an operand of the action that sends a packet to the

controller.



Of course it's doable in OVS--but it's going to be more work and you'll

have to understand OVS internals instead of OpenFlow.



On Fri, Jun 05, 2020 at 07:47:56PM +, Luca Mancini wrote:

> Hi Ben,

> I thought controllers didn’t have access to the complete packet but just the (packet_in msgs), so I was told to implement this in the switches and use the controller just as the “brain”.

> I’d much rather work on a controller to be honest, however, do you not think its doable at all in OVS?

> 

> Cheers,

> 

> Luca

> 

> From: Ben Pfaff

> Sent: Friday, June 5, 2020 21:32

> To: Luca Mancini

> Cc: Gregory Rose; ovs-discuss@openvswitch.org

> Subject: Re: [ovs-discuss] DP_Packet Payload Modification

> 

> On Fri, Jun 05, 2020 at 05:56:54PM +, Luca Mancini wrote:

> > 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

> 

> I'd use a local controller for this. Then you don't have to implement

> anything in OVS at all.

> 


___
discuss mailing list
disc...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-discuss


Re: [ovs-discuss] DP_Packet Payload Modification

2020-06-05 Thread Gregory Rose



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
___
discuss mailing list
disc...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-discuss


Re: [ovs-discuss] DP_Packet Payload Modification

2020-06-06 Thread Luca Mancini
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; jmailto:gvrose8...@gmail.com>
Sent: Friday, June 5, 2020 23:05
To: Luca Mancini<mailto:luca.manc...@outlook.com>; 
ovs-discuss@openvswitch.org<mailto:ovs-discuss@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

___
discuss mailing list
disc...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-discuss


Re: [ovs-discuss] DP_Packet Payload Modification

2020-06-06 Thread Luca Mancini

UPDATE:
I made a mistake when calculating the size of the dummy string  when adding it 
with dp_packet_put, if I change it to
char payload [] = “hello world”
everything works fine, however if I add the actual buffer of packets as its 
payload (instead of the dummy string), when printing the packets some packet 
fields are zeroed out, even though the extraction works….

Packet structure when I do
dp_packet_put(packetAggr, dummystring, sizeof dummystring);
packetaggr: 
udp,vlan_tci=0x,dl_src=00:00:00:00:00:01,dl_dst=00:00:00:00:00:02,nw_src=10.0.0.1,nw_dst=10.0.0.2,nw_tos=0,nw_ecn=0,nw_ttl=64,tp_src=33199,tp_dst=444
 udp_csum:6870

Packet structure when I do
dp_packet_put(packetAggr, dp_packet_buff1, sizeof dp_packet_buff1);
packetaggr: 
ip,vlan_tci=0x,dl_src=00:00:00:00:00:01,dl_dst=00:00:00:00:00:02,nw_src=0.0.0.0,nw_dst=0.0.0.0,nw_proto=0,nw_tos=0,nw_ecn=0,nw_ttl=0

starting from nw_src everything is zeroed out, so it makes me think it’s 
getting overwritten, but the payload is extracted correctly with 
dp_packet_get_udp_paylaod meaning the payload is most likely aligned correctly. 
Any thoughts of what is happening?



Luca

From: Luca Mancini<mailto:luca.manc...@outlook.com>
Sent: Saturday, June 6, 2020 11:08
To: Gregory Rose<mailto:gvrose8...@gmail.com>
Cc: ovs-discuss@openvswitch.org<mailto:ovs-discuss@openvswitch.org>
Subject: Re: [ovs-discuss] DP_Packet Payload Modification

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; jmailto:gvrose8...@gmail.com>
Sent: Friday, June 5, 2020 23:05
To: Luca Mancini<mailto:luca.manc...@outlook.com>; 
ovs-discuss@openvswitch.org<mailto:ovs-discuss@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_pac

Re: [ovs-discuss] DP_Packet Payload Modification [Solved I think]

2020-06-06 Thread Luca Mancini
Sorry for making a mess of this thread but I think I solved the issue.
I noticed by doing some pointer prints that I was overwriting the whole l4 
space including the header causing a mess with packet allignment so I used 
memcpy instead of dp_packet_put:

memcpy((char *) dp_packet_l4(packetAggr) + UDP_HEADER_LEN, dp_packet_buff1, 
sizeof(dp_packet_buff1));

packet is now complete and extraction of payload works, now I’ll start working 
on the sending part which is probably not as easy as I think.

Thanks for the help!

Luca

From: Luca Mancini<mailto:luca.manc...@outlook.com>
Sent: Saturday, June 6, 2020 15:40
To: Luca Mancini<mailto:luca.manc...@outlook.com>; 
ovs-discuss@openvswitch.org<mailto:ovs-discuss@openvswitch.org>; Gregory 
Rose<mailto:gvrose8...@gmail.com>
Subject: RE: [ovs-discuss] DP_Packet Payload Modification


UPDATE:
I made a mistake when calculating the size of the dummy string  when adding it 
with dp_packet_put, if I change it to
char payload [] = “hello world”
everything works fine, however if I add the actual buffer of packets as its 
payload (instead of the dummy string), when printing the packets some packet 
fields are zeroed out, even though the extraction works….

Packet structure when I do
dp_packet_put(packetAggr, dummystring, sizeof dummystring);
packetaggr: 
udp,vlan_tci=0x,dl_src=00:00:00:00:00:01,dl_dst=00:00:00:00:00:02,nw_src=10.0.0.1,nw_dst=10.0.0.2,nw_tos=0,nw_ecn=0,nw_ttl=64,tp_src=33199,tp_dst=444
 udp_csum:6870

Packet structure when I do
dp_packet_put(packetAggr, dp_packet_buff1, sizeof dp_packet_buff1);
packetaggr: 
ip,vlan_tci=0x,dl_src=00:00:00:00:00:01,dl_dst=00:00:00:00:00:02,nw_src=0.0.0.0,nw_dst=0.0.0.0,nw_proto=0,nw_tos=0,nw_ecn=0,nw_ttl=0

starting from nw_src everything is zeroed out, so it makes me think it’s 
getting overwritten, but the payload is extracted correctly with 
dp_packet_get_udp_paylaod meaning the payload is most likely aligned correctly. 
Any thoughts of what is happening?



Luca

From: Luca Mancini<mailto:luca.manc...@outlook.com>
Sent: Saturday, June 6, 2020 11:08
To: Gregory Rose<mailto:gvrose8...@gmail.com>
Cc: ovs-discuss@openvswitch.org<mailto:ovs-discuss@openvswitch.org>
Subject: Re: [ovs-discuss] DP_Packet Payload Modification

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; jmailto:gvrose8...@gmail.com>
Sent: Friday, June 5, 2020 23:05
To: Luca Mancini<mailto:luca.manc...@outlook.com>; 
ovs-discuss@openvswitch.org<mailto:ovs-discuss@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 

Re: [ovs-discuss] DP_Packet Payload Modification [Solved I think]

2020-06-09 Thread Gregory Rose




On 6/6/2020 7:16 AM, Luca Mancini wrote:

Sorry for making a mess of this thread but I think I solved the issue.
I noticed by doing some pointer prints that I was overwriting the whole l4 
space including the header causing a mess with packet allignment so I used 
memcpy instead of dp_packet_put:

memcpy((char *) dp_packet_l4(packetAggr) + UDP_HEADER_LEN, dp_packet_buff1, 
sizeof(dp_packet_buff1));

packet is now complete and extraction of payload works, now I’ll start working 
on the sending part which is probably not as easy as I think.

Thanks for the help!



I'm not sure how much help I was but I'm glad you've got it figured out.

Good luck!

- Greg


Luca

From: Luca Mancini<mailto:luca.manc...@outlook.com>
Sent: Saturday, June 6, 2020 15:40
To: Luca Mancini<mailto:luca.manc...@outlook.com>; 
ovs-discuss@openvswitch.org<mailto:ovs-discuss@openvswitch.org>; Gregory 
Rose<mailto:gvrose8...@gmail.com>
Subject: RE: [ovs-discuss] DP_Packet Payload Modification


UPDATE:
I made a mistake when calculating the size of the dummy string  when adding it 
with dp_packet_put, if I change it to
char payload [] = “hello world”
everything works fine, however if I add the actual buffer of packets as its 
payload (instead of the dummy string), when printing the packets some packet 
fields are zeroed out, even though the extraction works….

Packet structure when I do
dp_packet_put(packetAggr, dummystring, sizeof dummystring);
packetaggr: 
udp,vlan_tci=0x,dl_src=00:00:00:00:00:01,dl_dst=00:00:00:00:00:02,nw_src=10.0.0.1,nw_dst=10.0.0.2,nw_tos=0,nw_ecn=0,nw_ttl=64,tp_src=33199,tp_dst=444
 udp_csum:6870

Packet structure when I do
dp_packet_put(packetAggr, dp_packet_buff1, sizeof dp_packet_buff1);
packetaggr: 
ip,vlan_tci=0x,dl_src=00:00:00:00:00:01,dl_dst=00:00:00:00:00:02,nw_src=0.0.0.0,nw_dst=0.0.0.0,nw_proto=0,nw_tos=0,nw_ecn=0,nw_ttl=0

starting from nw_src everything is zeroed out, so it makes me think it’s 
getting overwritten, but the payload is extracted correctly with 
dp_packet_get_udp_paylaod meaning the payload is most likely aligned correctly. 
Any thoughts of what is happening?



Luca

From: Luca Mancini<mailto:luca.manc...@outlook.com>
Sent: Saturday, June 6, 2020 11:08
To: Gregory Rose<mailto:gvrose8...@gmail.com>
Cc: ovs-discuss@openvswitch.org<mailto:ovs-discuss@openvswitch.org>
Subject: Re: [ovs-discuss] DP_Packet Payload Modification

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; jmailto:gvrose8...@gmail.com>
Sent: Friday, June 5, 2020 23:05
To: Luca Mancini<mailto:luca.manc...@outlook.com>; 
ovs-discuss@openvswitch.org<mailto:ovs-discuss@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 m