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