render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
9c6c51
From 665a535028d1512e2afabf3c2c1cc100debfa7d7 Mon Sep 17 00:00:00 2001
9c6c51
Message-Id: <665a535028d1512e2afabf3c2c1cc100debfa7d7@dist-git>
9c6c51
From: Laine Stump <laine@laine.org>
9c6c51
Date: Mon, 14 Jan 2019 11:35:03 -0500
9c6c51
Subject: [PATCH] util: add a function to insert new interfaces to
9c6c51
 IPv6CheckForwarding list
9c6c51
9c6c51
This same operation needs to be done in multiple places, so move the
9c6c51
inline code into a separate function.
9c6c51
9c6c51
Signed-off-by: Laine Stump <laine@laine.org>
9c6c51
Reviewed-by: Erik Skultety <eskultet@redhat.com>
9c6c51
(cherry picked from commit 37bb6facfc467179d6cfe6186ad6d5a55285c2c7)
9c6c51
9c6c51
https://bugzilla.redhat.com/1583131
9c6c51
9c6c51
Conflicts: src/util/virnetdevip.c - introduction of VIR_AUTOPTR upstream led to
9c6c51
     conflicts in surrounding context, and elimination of cleanup and
9c6c51
     error labels.
9c6c51
Signed-off-by: Laine Stump <laine@laine.org>
9c6c51
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
9c6c51
---
9c6c51
 src/util/virnetdevip.c | 29 ++++++++++++++++++++---------
9c6c51
 1 file changed, 20 insertions(+), 9 deletions(-)
9c6c51
9c6c51
diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
9c6c51
index 1bfbd20034..937ebcdbdb 100644
9c6c51
--- a/src/util/virnetdevip.c
9c6c51
+++ b/src/util/virnetdevip.c
9c6c51
@@ -539,6 +539,25 @@ struct virNetDevIPCheckIPv6ForwardingData {
9c6c51
     size_t ndevices;
9c6c51
 };
9c6c51
 
9c6c51
+
9c6c51
+static int
9c6c51
+virNetDevIPCheckIPv6ForwardingAddIF(struct virNetDevIPCheckIPv6ForwardingData *data,
9c6c51
+                                    char **ifname)
9c6c51
+{
9c6c51
+    size_t i;
9c6c51
+
9c6c51
+    /* add ifname to the array if it's not already there
9c6c51
+     * (ifname is char** so VIR_APPEND_ELEMENT() will move the
9c6c51
+     * original pointer out of the way and avoid having it freed)
9c6c51
+     */
9c6c51
+    for (i = 0; i < data->ndevices; i++) {
9c6c51
+        if (STREQ(data->devices[i], *ifname))
9c6c51
+            return 0;
9c6c51
+    }
9c6c51
+    return VIR_APPEND_ELEMENT(data->devices, data->ndevices, *ifname);
9c6c51
+}
9c6c51
+
9c6c51
+
9c6c51
 static int
9c6c51
 virNetDevIPCheckIPv6ForwardingCallback(struct nlmsghdr *resp,
9c6c51
                                        void *opaque)
9c6c51
@@ -551,8 +570,6 @@ virNetDevIPCheckIPv6ForwardingCallback(struct nlmsghdr *resp,
9c6c51
     int ret = 0;
9c6c51
     int len = RTM_PAYLOAD(resp);
9c6c51
     int oif = -1;
9c6c51
-    size_t i;
9c6c51
-    bool hasDevice;
9c6c51
 
9c6c51
     /* Ignore messages other than route ones */
9c6c51
     if (resp->nlmsg_type != RTM_NEWROUTE)
9c6c51
@@ -589,13 +606,7 @@ virNetDevIPCheckIPv6ForwardingCallback(struct nlmsghdr *resp,
9c6c51
     accept_ra = virNetDevIPGetAcceptRA(ifname);
9c6c51
     VIR_DEBUG("Checking route for device %s, accept_ra: %d", ifname, accept_ra);
9c6c51
 
9c6c51
-    hasDevice = false;
9c6c51
-    for (i = 0; i < data->ndevices && !hasDevice; i++) {
9c6c51
-        if (STREQ(data->devices[i], ifname))
9c6c51
-            hasDevice = true;
9c6c51
-    }
9c6c51
-    if (accept_ra != 2 && !hasDevice &&
9c6c51
-        VIR_APPEND_ELEMENT(data->devices, data->ndevices, ifname) < 0)
9c6c51
+    if (accept_ra != 2 && virNetDevIPCheckIPv6ForwardingAddIF(data, &ifname) < 0)
9c6c51
         goto error;
9c6c51
 
9c6c51
  cleanup:
9c6c51
-- 
9c6c51
2.20.1
9c6c51