summaryrefslogtreecommitdiff
path: root/src/util/virnetdevip.c
diff options
context:
space:
mode:
authorLaine Stump <laine@laine.org>2019-01-07 15:55:31 -0500
committerLaine Stump <laine@laine.org>2019-01-10 12:36:40 -0500
commit37bb6facfc467179d6cfe6186ad6d5a55285c2c7 (patch)
treed1057b4094b1b2b9f472de341a83c3c1792b697f /src/util/virnetdevip.c
parent0ea259b6bf3c89bb3b144eba38bc0bd32e516107 (diff)
downloadlibvirt-37bb6facfc467179d6cfe6186ad6d5a55285c2c7.tar.gz
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>
Diffstat (limited to 'src/util/virnetdevip.c')
-rw-r--r--src/util/virnetdevip.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
index 4c869739ee..72048e4b45 100644
--- a/src/util/virnetdevip.c
+++ b/src/util/virnetdevip.c
@@ -505,6 +505,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)
@@ -515,8 +534,6 @@ virNetDevIPCheckIPv6ForwardingCallback(struct nlmsghdr *resp,
struct virNetDevIPCheckIPv6ForwardingData *data = opaque;
int len = RTM_PAYLOAD(resp);
int oif = -1;
- size_t i;
- bool hasDevice;
VIR_AUTOFREE(char *) ifname = NULL;
/* Ignore messages other than route ones */
@@ -553,13 +570,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)
return -1;
return 0;