diff mbox

[V4,07/12] net/colo.c: Make vnet_hdr_len as packet property

Message ID 1494553288-30764-8-git-send-email-zhangchen.fnst@cn.fujitsu.com
State New
Headers show

Commit Message

Zhang Chen May 12, 2017, 1:41 a.m. UTC
We can use this property flush and send packet with vnet_hdr_len.

Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
---
 net/colo-compare.c    | 8 ++++++--
 net/colo.c            | 3 ++-
 net/colo.h            | 4 +++-
 net/filter-rewriter.c | 2 +-
 4 files changed, 12 insertions(+), 5 deletions(-)

Comments

Jason Wang May 15, 2017, 4:05 a.m. UTC | #1
On 2017年05月12日 09:41, Zhang Chen wrote:
> We can use this property flush and send packet with vnet_hdr_len.
>
> Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>

Then I think it's not necessary to store vnet_hdr_len in SocketReadState?

Thanks

> ---
>   net/colo-compare.c    | 8 ++++++--
>   net/colo.c            | 3 ++-
>   net/colo.h            | 4 +++-
>   net/filter-rewriter.c | 2 +-
>   4 files changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/net/colo-compare.c b/net/colo-compare.c
> index 99a6912..87a9529 100644
> --- a/net/colo-compare.c
> +++ b/net/colo-compare.c
> @@ -122,9 +122,13 @@ static int packet_enqueue(CompareState *s, int mode)
>       Connection *conn;
>   
>       if (mode == PRIMARY_IN) {
> -        pkt = packet_new(s->pri_rs.buf, s->pri_rs.packet_len);
> +        pkt = packet_new(s->pri_rs.buf,
> +                         s->pri_rs.packet_len,
> +                         s->pri_rs.vnet_hdr_len);
>       } else {
> -        pkt = packet_new(s->sec_rs.buf, s->sec_rs.packet_len);
> +        pkt = packet_new(s->sec_rs.buf,
> +                         s->sec_rs.packet_len,
> +                         s->sec_rs.vnet_hdr_len);
>       }
>   
>       if (parse_packet_early(pkt)) {
> diff --git a/net/colo.c b/net/colo.c
> index 8cc166b..180eaed 100644
> --- a/net/colo.c
> +++ b/net/colo.c
> @@ -153,13 +153,14 @@ void connection_destroy(void *opaque)
>       g_slice_free(Connection, conn);
>   }
>   
> -Packet *packet_new(const void *data, int size)
> +Packet *packet_new(const void *data, int size, int vnet_hdr_len)
>   {
>       Packet *pkt = g_slice_new(Packet);
>   
>       pkt->data = g_memdup(data, size);
>       pkt->size = size;
>       pkt->creation_ms = qemu_clock_get_ms(QEMU_CLOCK_HOST);
> +    pkt->vnet_hdr_len = vnet_hdr_len;
>   
>       return pkt;
>   }
> diff --git a/net/colo.h b/net/colo.h
> index 7c524f3..caedb0d 100644
> --- a/net/colo.h
> +++ b/net/colo.h
> @@ -43,6 +43,8 @@ typedef struct Packet {
>       int size;
>       /* Time of packet creation, in wall clock ms */
>       int64_t creation_ms;
> +    /* Get vnet_hdr_len from filter */
> +    uint32_t vnet_hdr_len;
>   } Packet;
>   
>   typedef struct ConnectionKey {
> @@ -82,7 +84,7 @@ Connection *connection_get(GHashTable *connection_track_table,
>                              ConnectionKey *key,
>                              GQueue *conn_list);
>   void connection_hashtable_reset(GHashTable *connection_track_table);
> -Packet *packet_new(const void *data, int size);
> +Packet *packet_new(const void *data, int size, int vnet_hdr_len);
>   void packet_destroy(void *opaque, void *user_data);
>   
>   #endif /* QEMU_COLO_PROXY_H */
> diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c
> index afa06e8..63256c7 100644
> --- a/net/filter-rewriter.c
> +++ b/net/filter-rewriter.c
> @@ -158,7 +158,7 @@ static ssize_t colo_rewriter_receive_iov(NetFilterState *nf,
>       char *buf = g_malloc0(size);
>   
>       iov_to_buf(iov, iovcnt, 0, buf, size);
> -    pkt = packet_new(buf, size);
> +    pkt = packet_new(buf, size, 0);
>       g_free(buf);
>   
>       /*
Zhang Chen May 15, 2017, 8:03 a.m. UTC | #2
On 05/15/2017 12:05 PM, Jason Wang wrote:
>
>
> On 2017年05月12日 09:41, Zhang Chen wrote:
>> We can use this property flush and send packet with vnet_hdr_len.
>>
>> Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
>
> Then I think it's not necessary to store vnet_hdr_len in SocketReadState?

Do you means we keep the patch 05/12 in original?

Thanks
Zhang Chen

>
> Thanks
>
>> ---
>>   net/colo-compare.c    | 8 ++++++--
>>   net/colo.c            | 3 ++-
>>   net/colo.h            | 4 +++-
>>   net/filter-rewriter.c | 2 +-
>>   4 files changed, 12 insertions(+), 5 deletions(-)
>>
>> diff --git a/net/colo-compare.c b/net/colo-compare.c
>> index 99a6912..87a9529 100644
>> --- a/net/colo-compare.c
>> +++ b/net/colo-compare.c
>> @@ -122,9 +122,13 @@ static int packet_enqueue(CompareState *s, int 
>> mode)
>>       Connection *conn;
>>         if (mode == PRIMARY_IN) {
>> -        pkt = packet_new(s->pri_rs.buf, s->pri_rs.packet_len);
>> +        pkt = packet_new(s->pri_rs.buf,
>> +                         s->pri_rs.packet_len,
>> +                         s->pri_rs.vnet_hdr_len);
>>       } else {
>> -        pkt = packet_new(s->sec_rs.buf, s->sec_rs.packet_len);
>> +        pkt = packet_new(s->sec_rs.buf,
>> +                         s->sec_rs.packet_len,
>> +                         s->sec_rs.vnet_hdr_len);
>>       }
>>         if (parse_packet_early(pkt)) {
>> diff --git a/net/colo.c b/net/colo.c
>> index 8cc166b..180eaed 100644
>> --- a/net/colo.c
>> +++ b/net/colo.c
>> @@ -153,13 +153,14 @@ void connection_destroy(void *opaque)
>>       g_slice_free(Connection, conn);
>>   }
>>   -Packet *packet_new(const void *data, int size)
>> +Packet *packet_new(const void *data, int size, int vnet_hdr_len)
>>   {
>>       Packet *pkt = g_slice_new(Packet);
>>         pkt->data = g_memdup(data, size);
>>       pkt->size = size;
>>       pkt->creation_ms = qemu_clock_get_ms(QEMU_CLOCK_HOST);
>> +    pkt->vnet_hdr_len = vnet_hdr_len;
>>         return pkt;
>>   }
>> diff --git a/net/colo.h b/net/colo.h
>> index 7c524f3..caedb0d 100644
>> --- a/net/colo.h
>> +++ b/net/colo.h
>> @@ -43,6 +43,8 @@ typedef struct Packet {
>>       int size;
>>       /* Time of packet creation, in wall clock ms */
>>       int64_t creation_ms;
>> +    /* Get vnet_hdr_len from filter */
>> +    uint32_t vnet_hdr_len;
>>   } Packet;
>>     typedef struct ConnectionKey {
>> @@ -82,7 +84,7 @@ Connection *connection_get(GHashTable 
>> *connection_track_table,
>>                              ConnectionKey *key,
>>                              GQueue *conn_list);
>>   void connection_hashtable_reset(GHashTable *connection_track_table);
>> -Packet *packet_new(const void *data, int size);
>> +Packet *packet_new(const void *data, int size, int vnet_hdr_len);
>>   void packet_destroy(void *opaque, void *user_data);
>>     #endif /* QEMU_COLO_PROXY_H */
>> diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c
>> index afa06e8..63256c7 100644
>> --- a/net/filter-rewriter.c
>> +++ b/net/filter-rewriter.c
>> @@ -158,7 +158,7 @@ static ssize_t 
>> colo_rewriter_receive_iov(NetFilterState *nf,
>>       char *buf = g_malloc0(size);
>>         iov_to_buf(iov, iovcnt, 0, buf, size);
>> -    pkt = packet_new(buf, size);
>> +    pkt = packet_new(buf, size, 0);
>>       g_free(buf);
>>         /*
>
>
>
> .
>
Jason Wang May 15, 2017, 8:18 a.m. UTC | #3
On 2017年05月15日 16:03, Zhang Chen wrote:
>
>
> On 05/15/2017 12:05 PM, Jason Wang wrote:
>>
>>
>> On 2017年05月12日 09:41, Zhang Chen wrote:
>>> We can use this property flush and send packet with vnet_hdr_len.
>>>
>>> Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
>>
>> Then I think it's not necessary to store vnet_hdr_len in 
>> SocketReadState?
>
> Do you means we keep the patch 05/12 in original?
>
> Thanks
> Zhang Chen
>

I mean we could fetch vnet_hdr_len from the buf directly. Or is there 
any advantage to store it in SocketReadState?

Thanks
Zhang Chen May 23, 2017, 11:59 a.m. UTC | #4
On 05/15/2017 04:18 PM, Jason Wang wrote:
>
>
> On 2017年05月15日 16:03, Zhang Chen wrote:
>>
>>
>> On 05/15/2017 12:05 PM, Jason Wang wrote:
>>>
>>>
>>> On 2017年05月12日 09:41, Zhang Chen wrote:
>>>> We can use this property flush and send packet with vnet_hdr_len.
>>>>
>>>> Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
>>>
>>> Then I think it's not necessary to store vnet_hdr_len in 
>>> SocketReadState?
>>
>> Do you means we keep the patch 05/12 in original?
>>
>> Thanks
>> Zhang Chen
>>
>
> I mean we could fetch vnet_hdr_len from the buf directly. Or is there 
> any advantage to store it in SocketReadState?

No, The rs->buf did't have the vnet_hdr_len field.
In the net_fill_rstate(), when case = 2, we override the rs->buf by real 
net packet data,
So, the vnet_hdr_len field and packet_len field didn't be include in the 
last rs->buf.

Thanks
Zhang Chen

>
> Thanks
>
>
>
>
diff mbox

Patch

diff --git a/net/colo-compare.c b/net/colo-compare.c
index 99a6912..87a9529 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -122,9 +122,13 @@  static int packet_enqueue(CompareState *s, int mode)
     Connection *conn;
 
     if (mode == PRIMARY_IN) {
-        pkt = packet_new(s->pri_rs.buf, s->pri_rs.packet_len);
+        pkt = packet_new(s->pri_rs.buf,
+                         s->pri_rs.packet_len,
+                         s->pri_rs.vnet_hdr_len);
     } else {
-        pkt = packet_new(s->sec_rs.buf, s->sec_rs.packet_len);
+        pkt = packet_new(s->sec_rs.buf,
+                         s->sec_rs.packet_len,
+                         s->sec_rs.vnet_hdr_len);
     }
 
     if (parse_packet_early(pkt)) {
diff --git a/net/colo.c b/net/colo.c
index 8cc166b..180eaed 100644
--- a/net/colo.c
+++ b/net/colo.c
@@ -153,13 +153,14 @@  void connection_destroy(void *opaque)
     g_slice_free(Connection, conn);
 }
 
-Packet *packet_new(const void *data, int size)
+Packet *packet_new(const void *data, int size, int vnet_hdr_len)
 {
     Packet *pkt = g_slice_new(Packet);
 
     pkt->data = g_memdup(data, size);
     pkt->size = size;
     pkt->creation_ms = qemu_clock_get_ms(QEMU_CLOCK_HOST);
+    pkt->vnet_hdr_len = vnet_hdr_len;
 
     return pkt;
 }
diff --git a/net/colo.h b/net/colo.h
index 7c524f3..caedb0d 100644
--- a/net/colo.h
+++ b/net/colo.h
@@ -43,6 +43,8 @@  typedef struct Packet {
     int size;
     /* Time of packet creation, in wall clock ms */
     int64_t creation_ms;
+    /* Get vnet_hdr_len from filter */
+    uint32_t vnet_hdr_len;
 } Packet;
 
 typedef struct ConnectionKey {
@@ -82,7 +84,7 @@  Connection *connection_get(GHashTable *connection_track_table,
                            ConnectionKey *key,
                            GQueue *conn_list);
 void connection_hashtable_reset(GHashTable *connection_track_table);
-Packet *packet_new(const void *data, int size);
+Packet *packet_new(const void *data, int size, int vnet_hdr_len);
 void packet_destroy(void *opaque, void *user_data);
 
 #endif /* QEMU_COLO_PROXY_H */
diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c
index afa06e8..63256c7 100644
--- a/net/filter-rewriter.c
+++ b/net/filter-rewriter.c
@@ -158,7 +158,7 @@  static ssize_t colo_rewriter_receive_iov(NetFilterState *nf,
     char *buf = g_malloc0(size);
 
     iov_to_buf(iov, iovcnt, 0, buf, size);
-    pkt = packet_new(buf, size);
+    pkt = packet_new(buf, size, 0);
     g_free(buf);
 
     /*