]> xenbits.xensource.com Git - libvirt.git/commitdiff
virNetDevIPCheckIPv6ForwardingCallback fixes
authorCédric Bosdonnat <cbosdonnat@suse.com>
Tue, 28 Mar 2017 14:00:24 +0000 (16:00 +0200)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 3 Apr 2017 18:23:15 +0000 (14:23 -0400)
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]

src/util/virnetdevip.c

index c9ac6baf73ea39a17bcedb2ad49e7e5dfa977492..726fa6c3e3078116499ae1648f2c4bcaf91edcd1 100644 (file)
@@ -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;
         }
     }