[libvirt] [PATCH] IPv6 route check: list devices only once

Cédric Bosdonnat posted 1 patch 6 years, 12 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20170426103845.25574-1-cbosdonnat@suse.com
src/util/virnetdevip.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
[libvirt] [PATCH] IPv6 route check: list devices only once
Posted by Cédric Bosdonnat 6 years, 12 months ago
If several RA routes are found for the same device, only list that
device once in the error message.
---
 src/util/virnetdevip.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
index 09925e1d7..bf98ed8a5 100644
--- a/src/util/virnetdevip.c
+++ b/src/util/virnetdevip.c
@@ -551,6 +551,8 @@ virNetDevIPCheckIPv6ForwardingCallback(const struct nlmsghdr *resp,
     int ret = 0;
     int len = RTM_PAYLOAD(resp);
     int oif = -1;
+    size_t i;
+    bool hasDevice;
 
     /* Ignore messages other than route ones */
     if (resp->nlmsg_type != RTM_NEWROUTE)
@@ -587,7 +589,13 @@ virNetDevIPCheckIPv6ForwardingCallback(const struct nlmsghdr *resp,
     accept_ra = virNetDevIPGetAcceptRA(ifname);
     VIR_DEBUG("Checking route for device %s, accept_ra: %d", ifname, accept_ra);
 
-    if (accept_ra != 2 && VIR_APPEND_ELEMENT(data->devices, data->ndevices, ifname) < 0)
+    hasDevice = false;
+    for (i = 0; i < data->ndevices && !hasDevice; i++) {
+        if (STREQ(data->devices[i], ifname))
+            hasDevice = true;
+    }
+    if (accept_ra != 2 && !hasDevice &&
+        VIR_APPEND_ELEMENT(data->devices, data->ndevices, ifname) < 0)
         goto error;
 
  cleanup:
-- 
2.12.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] IPv6 route check: list devices only once
Posted by Laine Stump 6 years, 12 months ago
On 04/26/2017 06:38 AM, Cédric Bosdonnat wrote:
> If several RA routes are found for the same device, only list that
> device once in the error message.
> ---
>  src/util/virnetdevip.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
> index 09925e1d7..bf98ed8a5 100644
> --- a/src/util/virnetdevip.c
> +++ b/src/util/virnetdevip.c
> @@ -551,6 +551,8 @@ virNetDevIPCheckIPv6ForwardingCallback(const struct nlmsghdr *resp,
>      int ret = 0;
>      int len = RTM_PAYLOAD(resp);
>      int oif = -1;
> +    size_t i;
> +    bool hasDevice;
>  
>      /* Ignore messages other than route ones */
>      if (resp->nlmsg_type != RTM_NEWROUTE)
> @@ -587,7 +589,13 @@ virNetDevIPCheckIPv6ForwardingCallback(const struct nlmsghdr *resp,
>      accept_ra = virNetDevIPGetAcceptRA(ifname);
>      VIR_DEBUG("Checking route for device %s, accept_ra: %d", ifname, accept_ra);
>  
> -    if (accept_ra != 2 && VIR_APPEND_ELEMENT(data->devices, data->ndevices, ifname) < 0)
> +    hasDevice = false;
> +    for (i = 0; i < data->ndevices && !hasDevice; i++) {
> +        if (STREQ(data->devices[i], ifname))
> +            hasDevice = true;
> +    }
> +    if (accept_ra != 2 && !hasDevice &&
> +        VIR_APPEND_ELEMENT(data->devices, data->ndevices, ifname) < 0)
>          goto error;
>  
>   cleanup:
> 


ACK.

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