diff mbox

[ovs-dev,1/2] dpif-netlink: Use netlink helpers for packet_type.

Message ID 20170718223244.28449-1-joe@ovn.org
State Accepted
Headers show

Commit Message

Joe Stringer July 18, 2017, 10:32 p.m. UTC
Rather than open-coding access to netlink attribute pointers in
put_exclude_packet_type(), make use of the netlink attribute helpers.
This simplifies the following bugfix.

Signed-off-by: Joe Stringer <joe@ovn.org>
---
 lib/dpif-netlink.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Eric Garver July 19, 2017, 3:54 p.m. UTC | #1
On Tue, Jul 18, 2017 at 03:32:43PM -0700, Joe Stringer wrote:
> Rather than open-coding access to netlink attribute pointers in
> put_exclude_packet_type(), make use of the netlink attribute helpers.
> This simplifies the following bugfix.
> 
> Signed-off-by: Joe Stringer <joe@ovn.org>
> ---
>  lib/dpif-netlink.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c
> index 562f6134c3a5..63ef3de5c7d1 100644
> --- a/lib/dpif-netlink.c
> +++ b/lib/dpif-netlink.c
> @@ -3452,13 +3452,13 @@ put_exclude_packet_type(struct ofpbuf *buf, uint16_t type,
>          size_t first_chunk_size = (uint8_t *)packet_type - (uint8_t *)data;
>          size_t second_chunk_size = data_len - first_chunk_size
>                                     - packet_type_len;
> -        uint8_t *first_attr = NULL;
>          struct nlattr *next_attr = nl_attr_next(packet_type);
> +        size_t ofs;
>  
> -        first_attr = nl_msg_put_unspec_uninit(buf, type,
> -                                              data_len - packet_type_len);
> -        memcpy(first_attr, data, first_chunk_size);
> -        memcpy(first_attr + first_chunk_size, next_attr, second_chunk_size);
> +        ofs = nl_msg_start_nested(buf, type);
> +        nl_msg_put(buf, data, first_chunk_size);
> +        nl_msg_put(buf, next_attr, second_chunk_size);
> +        nl_msg_end_nested(buf, ofs);
>      } else {
>          nl_msg_put_unspec(buf, type, data, data_len);
>      }
> -- 
> 2.11.1
> 

Acked-by: Eric Garver <e@erig.me>
Joe Stringer July 19, 2017, 9:35 p.m. UTC | #2
On 19 July 2017 at 08:54, Eric Garver <e@erig.me> wrote:
> On Tue, Jul 18, 2017 at 03:32:43PM -0700, Joe Stringer wrote:
>> Rather than open-coding access to netlink attribute pointers in
>> put_exclude_packet_type(), make use of the netlink attribute helpers.
>> This simplifies the following bugfix.
>>
>> Signed-off-by: Joe Stringer <joe@ovn.org>
>> ---
>>  lib/dpif-netlink.c | 10 +++++-----
>>  1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c
>> index 562f6134c3a5..63ef3de5c7d1 100644
>> --- a/lib/dpif-netlink.c
>> +++ b/lib/dpif-netlink.c
>> @@ -3452,13 +3452,13 @@ put_exclude_packet_type(struct ofpbuf *buf, uint16_t type,
>>          size_t first_chunk_size = (uint8_t *)packet_type - (uint8_t *)data;
>>          size_t second_chunk_size = data_len - first_chunk_size
>>                                     - packet_type_len;
>> -        uint8_t *first_attr = NULL;
>>          struct nlattr *next_attr = nl_attr_next(packet_type);
>> +        size_t ofs;
>>
>> -        first_attr = nl_msg_put_unspec_uninit(buf, type,
>> -                                              data_len - packet_type_len);
>> -        memcpy(first_attr, data, first_chunk_size);
>> -        memcpy(first_attr + first_chunk_size, next_attr, second_chunk_size);
>> +        ofs = nl_msg_start_nested(buf, type);
>> +        nl_msg_put(buf, data, first_chunk_size);
>> +        nl_msg_put(buf, next_attr, second_chunk_size);
>> +        nl_msg_end_nested(buf, ofs);
>>      } else {
>>          nl_msg_put_unspec(buf, type, data, data_len);
>>      }
>> --
>> 2.11.1
>>
>
> Acked-by: Eric Garver <e@erig.me>

Thanks, applied to master.
diff mbox

Patch

diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c
index 562f6134c3a5..63ef3de5c7d1 100644
--- a/lib/dpif-netlink.c
+++ b/lib/dpif-netlink.c
@@ -3452,13 +3452,13 @@  put_exclude_packet_type(struct ofpbuf *buf, uint16_t type,
         size_t first_chunk_size = (uint8_t *)packet_type - (uint8_t *)data;
         size_t second_chunk_size = data_len - first_chunk_size
                                    - packet_type_len;
-        uint8_t *first_attr = NULL;
         struct nlattr *next_attr = nl_attr_next(packet_type);
+        size_t ofs;
 
-        first_attr = nl_msg_put_unspec_uninit(buf, type,
-                                              data_len - packet_type_len);
-        memcpy(first_attr, data, first_chunk_size);
-        memcpy(first_attr + first_chunk_size, next_attr, second_chunk_size);
+        ofs = nl_msg_start_nested(buf, type);
+        nl_msg_put(buf, data, first_chunk_size);
+        nl_msg_put(buf, next_attr, second_chunk_size);
+        nl_msg_end_nested(buf, ofs);
     } else {
         nl_msg_put_unspec(buf, type, data, data_len);
     }