[libvirt] [PATCH v2] virNetDevIPCheckIPv6ForwardingCallback fixes

Cédric Bosdonnat posted 1 patch 125 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20170328140024.11694-1-cbosdonnat@suse.com
src/util/virnetdevip.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)

[libvirt] [PATCH v2] virNetDevIPCheckIPv6ForwardingCallback fixes

Posted by Cédric Bosdonnat 125 weeks ago
Add check for more than one RTA_OIF, even though this is rather
unlikely.

Get rid of the buggy switch / break as this code won't need to
handle more attributes.

Use VIR_WARNINGS_NO_CAST_ALIGN to fix impossible to fix
util/virnetdevip.c:560:17: error: cast increases required alignment of target type [-Werror=cast-align]
---
 Diff to v1:
   * Add error message
   * Use VIR_WARNINGS_NO_CAST_ALIGN
 src/util/virnetdevip.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
index c9ac6baf7..726fa6c3e 100644
--- a/src/util/virnetdevip.c
+++ b/src/util/virnetdevip.c
@@ -556,15 +556,24 @@ virNetDevIPCheckIPv6ForwardingCallback(const struct nlmsghdr *resp,
     if (resp->nlmsg_type != RTM_NEWROUTE)
         return ret;
 
-    /* Extract a few attributes */
+    /* Extract a device ID attribute */
+    VIR_WARNINGS_NO_CAST_ALIGN
     for (rta = RTM_RTA(rtmsg); RTA_OK(rta, len); rta = RTA_NEXT(rta, len)) {
-        switch (rta->rta_type) {
-        case RTA_OIF:
+        VIR_WARNINGS_RESET
+        if (rta->rta_type == RTA_OIF) {
             oif = *(int *)RTA_DATA(rta);
 
+            /* Should never happen: netlink message would be broken */
+            if (ifname) {
+                char *ifname2 = virNetDevGetName(oif);
+                VIR_WARN("Single route has unexpected 2nd interface "
+                         "- '%s' and '%s'", ifname, ifname2);
+                VIR_FREE(ifname2);
+                break;
+            }
+
             if (!(ifname = virNetDevGetName(oif)))
                 goto error;
-            break;
         }
     }
 
-- 
2.12.0

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

Re: [libvirt] [PATCH v2] virNetDevIPCheckIPv6ForwardingCallback fixes

Posted by Cedric Bosdonnat 124 weeks ago
Hi all,

Has that one been forgotten?

On Tue, 2017-03-28 at 16:00 +0200, Cédric Bosdonnat wrote:
> Add check for more than one RTA_OIF, even though this is rather
> unlikely.
> 
> Get rid of the buggy switch / break as this code won't need to
> handle more attributes.
> 
> Use VIR_WARNINGS_NO_CAST_ALIGN to fix impossible to fix
> util/virnetdevip.c:560:17: error: cast increases required alignment of target type [-Werror=cast-align]
> ---
>  Diff to v1:
>    * Add error message
>    * Use VIR_WARNINGS_NO_CAST_ALIGN
>  src/util/virnetdevip.c | 17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
> index c9ac6baf7..726fa6c3e 100644
> --- a/src/util/virnetdevip.c
> +++ b/src/util/virnetdevip.c
> @@ -556,15 +556,24 @@ virNetDevIPCheckIPv6ForwardingCallback(const struct nlmsghdr *resp,
>      if (resp->nlmsg_type != RTM_NEWROUTE)
>          return ret;
>  
> -    /* Extract a few attributes */
> +    /* Extract a device ID attribute */
> +    VIR_WARNINGS_NO_CAST_ALIGN
>      for (rta = RTM_RTA(rtmsg); RTA_OK(rta, len); rta = RTA_NEXT(rta, len)) {
> -        switch (rta->rta_type) {
> -        case RTA_OIF:
> +        VIR_WARNINGS_RESET
> +        if (rta->rta_type == RTA_OIF) {
>              oif = *(int *)RTA_DATA(rta);
>  
> +            /* Should never happen: netlink message would be broken */
> +            if (ifname) {
> +                char *ifname2 = virNetDevGetName(oif);
> +                VIR_WARN("Single route has unexpected 2nd interface "
> +                         "- '%s' and '%s'", ifname, ifname2);
> +                VIR_FREE(ifname2);
> +                break;
> +            }
> +
>              if (!(ifname = virNetDevGetName(oif)))
>                  goto error;
> -            break;
>          }
>      }
>  

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

Re: [libvirt] [PATCH v2] virNetDevIPCheckIPv6ForwardingCallback fixes

Posted by John Ferlan 124 weeks ago

On 03/28/2017 10:00 AM, Cédric Bosdonnat wrote:
> Add check for more than one RTA_OIF, even though this is rather
> unlikely.
> 
> Get rid of the buggy switch / break as this code won't need to
> handle more attributes.
> 
> Use VIR_WARNINGS_NO_CAST_ALIGN to fix impossible to fix
> util/virnetdevip.c:560:17: error: cast increases required alignment of target type [-Werror=cast-align]
> ---
>  Diff to v1:
>    * Add error message
>    * Use VIR_WARNINGS_NO_CAST_ALIGN
>  src/util/virnetdevip.c | 17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)
> 

ACK (and pushed)

John

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