[libvirt] [PATCHv2 1/2] util: allow sending mac addr to virNetNewLink without ifindex

Laine Stump posted 2 patches 6 years, 3 months ago
[libvirt] [PATCHv2 1/2] util: allow sending mac addr to virNetNewLink without ifindex
Posted by Laine Stump 6 years, 3 months ago
From: Laine Stump <laine@redhat.com>

Although until now, any use of the extra_args argument (a pointer to a
struct containing extra attributes to add the the RTM_NEWLINK message)
would always have the ifindex and mac set, so the code could assume it
was safe to add both to the message if extra_args != NULL. There is
now a use for setting a MAC address in the RTM_NEWLINK without setting
the ifindex, so we should check each of these separately.

Signed-off-by: Laine Stump <laine@redhat.com>
---
 src/util/virnetlink.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c
index ab41b57672..f18946061c 100644
--- a/src/util/virnetlink.c
+++ b/src/util/virnetlink.c
@@ -548,9 +548,14 @@ virNetlinkNewLink(const char *ifname,
     NETLINK_MSG_NEST_END(nl_msg, linkinfo);
 
     if (extra_args) {
-        NETLINK_MSG_PUT(nl_msg, IFLA_LINK,
+        if (extra_args->ifindex) {
+            NETLINK_MSG_PUT(nl_msg, IFLA_LINK,
                         sizeof(uint32_t), extra_args->ifindex);
-        NETLINK_MSG_PUT(nl_msg, IFLA_ADDRESS, VIR_MAC_BUFLEN, extra_args->mac);
+        }
+        if (extra_args->mac) {
+            NETLINK_MSG_PUT(nl_msg, IFLA_ADDRESS,
+                            VIR_MAC_BUFLEN, extra_args->mac);
+        }
     }
 
     if (virNetlinkCommand(nl_msg, &resp, &buflen, 0, 0, NETLINK_ROUTE, 0) < 0)
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCHv2 1/2] util: allow sending mac addr to virNetNewLink without ifindex
Posted by Jiri Denemark 6 years, 3 months ago
On Thu, Oct 17, 2019 at 21:59:48 -0400, Laine Stump wrote:
> From: Laine Stump <laine@redhat.com>
> 
> Although until now, any use of the extra_args argument (a pointer to a
> struct containing extra attributes to add the the RTM_NEWLINK message)
> would always have the ifindex and mac set, so the code could assume it
> was safe to add both to the message if extra_args != NULL. There is
> now a use for setting a MAC address in the RTM_NEWLINK without setting
> the ifindex, so we should check each of these separately.
> 
> Signed-off-by: Laine Stump <laine@redhat.com>
> ---
>  src/util/virnetlink.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)

Reviewed-by: Jiri Denemark <jdenemar@redhat.com>

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list