render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
edecca
From 46d50fe9ca30e8377995fea2b7d59239b46a0cfa Mon Sep 17 00:00:00 2001
edecca
Message-Id: <46d50fe9ca30e8377995fea2b7d59239b46a0cfa@dist-git>
edecca
From: Laine Stump <laine@laine.org>
edecca
Date: Mon, 14 Jan 2019 11:35:04 -0500
edecca
Subject: [PATCH] util: use nlmsg_find_attr() instead of an open-coded loop
edecca
edecca
This is about the same number of code lines, but is simpler, and more
edecca
consistent with what will be added to check another attribute in a
edecca
coming patch.
edecca
edecca
As a side effect, it
edecca
edecca
Resolves: https://bugzilla.redhat.com/1583131
edecca
edecca
Signed-off-by: Laine Stump <laine@laine.org>
edecca
Reviewed-by: Erik Skultety <eskultet@redhat.com>
edecca
(cherry picked from commit 7282f455aaaa8bf2f73236aa9ec6b65b33c0fcdb)
edecca
edecca
Conflicts: src/util/virnetdevip.c -  more blowback from the addition of VIR_AUTOPTR
edecca
                             upstream.
edecca
Signed-off-by: Laine Stump <laine@laine.org>
edecca
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
edecca
---
edecca
 src/util/virnetdevip.c | 52 ++++++++++++++++++------------------------
edecca
 1 file changed, 22 insertions(+), 30 deletions(-)
edecca
edecca
diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
edecca
index 937ebcdbdb..d56f4f05f3 100644
edecca
--- a/src/util/virnetdevip.c
edecca
+++ b/src/util/virnetdevip.c
edecca
@@ -564,50 +564,42 @@ virNetDevIPCheckIPv6ForwardingCallback(struct nlmsghdr *resp,
edecca
 {
edecca
     struct rtmsg *rtmsg = NLMSG_DATA(resp);
edecca
     int accept_ra = -1;
edecca
-    struct rtattr *rta;
edecca
+    struct rtattr *rta_attr;
edecca
     char *ifname = NULL;
edecca
+    int ifindex = -1;
edecca
     struct virNetDevIPCheckIPv6ForwardingData *data = opaque;
edecca
     int ret = 0;
edecca
-    int len = RTM_PAYLOAD(resp);
edecca
-    int oif = -1;
edecca
 
edecca
     /* Ignore messages other than route ones */
edecca
     if (resp->nlmsg_type != RTM_NEWROUTE)
edecca
         return ret;
edecca
 
edecca
-    /* Extract a device ID attribute */
edecca
-    VIR_WARNINGS_NO_CAST_ALIGN
edecca
-    for (rta = RTM_RTA(rtmsg); RTA_OK(rta, len); rta = RTA_NEXT(rta, len)) {
edecca
-        VIR_WARNINGS_RESET
edecca
-        if (rta->rta_type == RTA_OIF) {
edecca
-            oif = *(int *)RTA_DATA(rta);
edecca
-
edecca
-            /* Should never happen: netlink message would be broken */
edecca
-            if (ifname) {
edecca
-                char *ifname2 = virNetDevGetName(oif);
edecca
-                VIR_WARN("Single route has unexpected 2nd interface "
edecca
-                         "- '%s' and '%s'", ifname, ifname2);
edecca
-                VIR_FREE(ifname2);
edecca
-                break;
edecca
-            }
edecca
-
edecca
-            if (!(ifname = virNetDevGetName(oif)))
edecca
-                goto error;
edecca
-        }
edecca
-    }
edecca
-
edecca
     /* No need to do anything else for non RA routes */
edecca
     if (rtmsg->rtm_protocol != RTPROT_RA)
edecca
         goto cleanup;
edecca
 
edecca
-    data->hasRARoutes = true;
edecca
+    rta_attr = (struct rtattr *)nlmsg_find_attr(resp, sizeof(struct rtmsg), RTA_OIF);
edecca
+    if (rta_attr) {
edecca
+        /* This is a single path route, with interface used to reach
edecca
+         * nexthop in the RTA_OIF attribute.
edecca
+         */
edecca
+        ifindex = *(int *)RTA_DATA(rta_attr);
edecca
+        ifname = virNetDevGetName(ifindex);
edecca
 
edecca
-    /* Check the accept_ra value for the interface */
edecca
-    accept_ra = virNetDevIPGetAcceptRA(ifname);
edecca
-    VIR_DEBUG("Checking route for device %s, accept_ra: %d", ifname, accept_ra);
edecca
+        if (!ifname)
edecca
+            goto error;
edecca
 
edecca
-    if (accept_ra != 2 && virNetDevIPCheckIPv6ForwardingAddIF(data, &ifname) < 0)
edecca
-        goto error;
edecca
+        accept_ra = virNetDevIPGetAcceptRA(ifname);
edecca
+
edecca
+        VIR_DEBUG("Checking route for device %s (%d), accept_ra: %d",
edecca
+                  ifname, ifindex, accept_ra);
edecca
+
edecca
+        if (accept_ra != 2 && virNetDevIPCheckIPv6ForwardingAddIF(data, &ifname) < 0)
edecca
+            goto error;
edecca
+
edecca
+        data->hasRARoutes = true;
edecca
+        goto cleanup;
edecca
+    }
edecca
 
edecca
  cleanup:
edecca
     VIR_FREE(ifname);
edecca
-- 
edecca
2.20.1
edecca