|
|
7a3408 |
From 42d7166762dd388b6c235430734f9ead5a40afd5 Mon Sep 17 00:00:00 2001
|
|
|
7a3408 |
Message-Id: <42d7166762dd388b6c235430734f9ead5a40afd5@dist-git>
|
|
|
7a3408 |
From: Laine Stump <laine@laine.org>
|
|
|
7a3408 |
Date: Thu, 3 Sep 2015 12:08:24 -0400
|
|
|
7a3408 |
Subject: [PATCH] util: make virNetDev(Replace|Restore)MacAddress public
|
|
|
7a3408 |
functions
|
|
|
7a3408 |
|
|
|
7a3408 |
These functions were made static as a part of commit cbfe38c since
|
|
|
7a3408 |
they were no longer called from outside virnetdev.c. We once again
|
|
|
7a3408 |
need to call them from another file, so this patch makes them once
|
|
|
7a3408 |
again public.
|
|
|
7a3408 |
|
|
|
7a3408 |
Prerequisite for the fix for:
|
|
|
7a3408 |
|
|
|
7a3408 |
https://bugzilla.redhat.com/show_bug.cgi?id=1257004
|
|
|
7a3408 |
|
|
|
7a3408 |
(cherry picked from commit 3ce08fab8477da2c76918329523a5e6a312cef06)
|
|
|
7a3408 |
|
|
|
7a3408 |
Conflicts:
|
|
|
7a3408 |
src/util/virnetdev.c - one extra blank line in white space
|
|
|
7a3408 |
|
|
|
7a3408 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
7a3408 |
---
|
|
|
7a3408 |
src/libvirt_private.syms | 2 +
|
|
|
7a3408 |
src/util/virnetdev.c | 173 ++++++++++++++++++++++++-----------------------
|
|
|
7a3408 |
src/util/virnetdev.h | 10 +++
|
|
|
7a3408 |
3 files changed, 99 insertions(+), 86 deletions(-)
|
|
|
7a3408 |
|
|
|
7a3408 |
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
|
|
|
7a3408 |
index 434bbf3..9332194 100644
|
|
|
7a3408 |
--- a/src/libvirt_private.syms
|
|
|
7a3408 |
+++ b/src/libvirt_private.syms
|
|
|
7a3408 |
@@ -1765,7 +1765,9 @@ virNetDevGetVirtualFunctions;
|
|
|
7a3408 |
virNetDevGetVLanID;
|
|
|
7a3408 |
virNetDevIsVirtualFunction;
|
|
|
7a3408 |
virNetDevLinkDump;
|
|
|
7a3408 |
+virNetDevReplaceMacAddress;
|
|
|
7a3408 |
virNetDevReplaceNetConfig;
|
|
|
7a3408 |
+virNetDevRestoreMacAddress;
|
|
|
7a3408 |
virNetDevRestoreNetConfig;
|
|
|
7a3408 |
virNetDevRxFilterFree;
|
|
|
7a3408 |
virNetDevRxFilterModeTypeFromString;
|
|
|
7a3408 |
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
|
|
|
7a3408 |
index e4fcd81..a1a4ea1 100644
|
|
|
7a3408 |
--- a/src/util/virnetdev.c
|
|
|
7a3408 |
+++ b/src/util/virnetdev.c
|
|
|
7a3408 |
@@ -350,6 +350,92 @@ int virNetDevGetMAC(const char *ifname,
|
|
|
7a3408 |
#endif
|
|
|
7a3408 |
|
|
|
7a3408 |
|
|
|
7a3408 |
+/**
|
|
|
7a3408 |
+ * virNetDevReplaceMacAddress:
|
|
|
7a3408 |
+ * @macaddress: new MAC address for interface
|
|
|
7a3408 |
+ * @linkdev: name of interface
|
|
|
7a3408 |
+ * @stateDir: directory to store old MAC address
|
|
|
7a3408 |
+ *
|
|
|
7a3408 |
+ * Returns 0 on success, -1 on failure
|
|
|
7a3408 |
+ *
|
|
|
7a3408 |
+ */
|
|
|
7a3408 |
+int
|
|
|
7a3408 |
+virNetDevReplaceMacAddress(const char *linkdev,
|
|
|
7a3408 |
+ const virMacAddr *macaddress,
|
|
|
7a3408 |
+ const char *stateDir)
|
|
|
7a3408 |
+{
|
|
|
7a3408 |
+ virMacAddr oldmac;
|
|
|
7a3408 |
+ char *path = NULL;
|
|
|
7a3408 |
+ char macstr[VIR_MAC_STRING_BUFLEN];
|
|
|
7a3408 |
+ int ret = -1;
|
|
|
7a3408 |
+
|
|
|
7a3408 |
+ if (virNetDevGetMAC(linkdev, &oldmac) < 0)
|
|
|
7a3408 |
+ return -1;
|
|
|
7a3408 |
+
|
|
|
7a3408 |
+ if (virAsprintf(&path, "%s/%s",
|
|
|
7a3408 |
+ stateDir,
|
|
|
7a3408 |
+ linkdev) < 0)
|
|
|
7a3408 |
+ return -1;
|
|
|
7a3408 |
+ virMacAddrFormat(&oldmac, macstr);
|
|
|
7a3408 |
+ if (virFileWriteStr(path, macstr, O_CREAT|O_TRUNC|O_WRONLY) < 0) {
|
|
|
7a3408 |
+ virReportSystemError(errno, _("Unable to preserve mac for %s"),
|
|
|
7a3408 |
+ linkdev);
|
|
|
7a3408 |
+ goto cleanup;
|
|
|
7a3408 |
+ }
|
|
|
7a3408 |
+
|
|
|
7a3408 |
+ if (virNetDevSetMAC(linkdev, macaddress) < 0)
|
|
|
7a3408 |
+ goto cleanup;
|
|
|
7a3408 |
+
|
|
|
7a3408 |
+ ret = 0;
|
|
|
7a3408 |
+ cleanup:
|
|
|
7a3408 |
+ VIR_FREE(path);
|
|
|
7a3408 |
+ return ret;
|
|
|
7a3408 |
+}
|
|
|
7a3408 |
+
|
|
|
7a3408 |
+/**
|
|
|
7a3408 |
+ * virNetDevRestoreMacAddress:
|
|
|
7a3408 |
+ * @linkdev: name of interface
|
|
|
7a3408 |
+ * @stateDir: directory containing old MAC address
|
|
|
7a3408 |
+ *
|
|
|
7a3408 |
+ * Returns 0 on success, -errno on failure.
|
|
|
7a3408 |
+ *
|
|
|
7a3408 |
+ */
|
|
|
7a3408 |
+int
|
|
|
7a3408 |
+virNetDevRestoreMacAddress(const char *linkdev,
|
|
|
7a3408 |
+ const char *stateDir)
|
|
|
7a3408 |
+{
|
|
|
7a3408 |
+ int rc = -1;
|
|
|
7a3408 |
+ char *oldmacname = NULL;
|
|
|
7a3408 |
+ char *macstr = NULL;
|
|
|
7a3408 |
+ char *path = NULL;
|
|
|
7a3408 |
+ virMacAddr oldmac;
|
|
|
7a3408 |
+
|
|
|
7a3408 |
+ if (virAsprintf(&path, "%s/%s",
|
|
|
7a3408 |
+ stateDir,
|
|
|
7a3408 |
+ linkdev) < 0)
|
|
|
7a3408 |
+ return -1;
|
|
|
7a3408 |
+
|
|
|
7a3408 |
+ if (virFileReadAll(path, VIR_MAC_STRING_BUFLEN, &macstr) < 0)
|
|
|
7a3408 |
+ goto cleanup;
|
|
|
7a3408 |
+
|
|
|
7a3408 |
+ if (virMacAddrParse(macstr, &oldmac) != 0) {
|
|
|
7a3408 |
+ virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
7a3408 |
+ _("Cannot parse MAC address from '%s'"),
|
|
|
7a3408 |
+ oldmacname);
|
|
|
7a3408 |
+ goto cleanup;
|
|
|
7a3408 |
+ }
|
|
|
7a3408 |
+
|
|
|
7a3408 |
+ /*reset mac and remove file-ignore results*/
|
|
|
7a3408 |
+ rc = virNetDevSetMAC(linkdev, &oldmac);
|
|
|
7a3408 |
+ ignore_value(unlink(path));
|
|
|
7a3408 |
+
|
|
|
7a3408 |
+ cleanup:
|
|
|
7a3408 |
+ VIR_FREE(macstr);
|
|
|
7a3408 |
+ VIR_FREE(path);
|
|
|
7a3408 |
+ return rc;
|
|
|
7a3408 |
+}
|
|
|
7a3408 |
+
|
|
|
7a3408 |
+
|
|
|
7a3408 |
#if defined(SIOCGIFMTU) && defined(HAVE_STRUCT_IFREQ)
|
|
|
7a3408 |
/**
|
|
|
7a3408 |
* virNetDevGetMTU:
|
|
|
7a3408 |
@@ -1828,95 +1914,10 @@ virNetDevSysfsFile(char **pf_sysfs_device_link ATTRIBUTE_UNUSED,
|
|
|
7a3408 |
return -1;
|
|
|
7a3408 |
}
|
|
|
7a3408 |
|
|
|
7a3408 |
+
|
|
|
7a3408 |
#endif /* !__linux__ */
|
|
|
7a3408 |
#if defined(__linux__) && defined(HAVE_LIBNL) && defined(IFLA_VF_MAX)
|
|
|
7a3408 |
|
|
|
7a3408 |
-/**
|
|
|
7a3408 |
- * virNetDevReplaceMacAddress:
|
|
|
7a3408 |
- * @macaddress: new MAC address for interface
|
|
|
7a3408 |
- * @linkdev: name of interface
|
|
|
7a3408 |
- * @stateDir: directory to store old MAC address
|
|
|
7a3408 |
- *
|
|
|
7a3408 |
- * Returns 0 on success, -1 on failure
|
|
|
7a3408 |
- *
|
|
|
7a3408 |
- */
|
|
|
7a3408 |
-static int
|
|
|
7a3408 |
-virNetDevReplaceMacAddress(const char *linkdev,
|
|
|
7a3408 |
- const virMacAddr *macaddress,
|
|
|
7a3408 |
- const char *stateDir)
|
|
|
7a3408 |
-{
|
|
|
7a3408 |
- virMacAddr oldmac;
|
|
|
7a3408 |
- char *path = NULL;
|
|
|
7a3408 |
- char macstr[VIR_MAC_STRING_BUFLEN];
|
|
|
7a3408 |
- int ret = -1;
|
|
|
7a3408 |
-
|
|
|
7a3408 |
- if (virNetDevGetMAC(linkdev, &oldmac) < 0)
|
|
|
7a3408 |
- return -1;
|
|
|
7a3408 |
-
|
|
|
7a3408 |
- if (virAsprintf(&path, "%s/%s",
|
|
|
7a3408 |
- stateDir,
|
|
|
7a3408 |
- linkdev) < 0)
|
|
|
7a3408 |
- return -1;
|
|
|
7a3408 |
- virMacAddrFormat(&oldmac, macstr);
|
|
|
7a3408 |
- if (virFileWriteStr(path, macstr, O_CREAT|O_TRUNC|O_WRONLY) < 0) {
|
|
|
7a3408 |
- virReportSystemError(errno, _("Unable to preserve mac for %s"),
|
|
|
7a3408 |
- linkdev);
|
|
|
7a3408 |
- goto cleanup;
|
|
|
7a3408 |
- }
|
|
|
7a3408 |
-
|
|
|
7a3408 |
- if (virNetDevSetMAC(linkdev, macaddress) < 0)
|
|
|
7a3408 |
- goto cleanup;
|
|
|
7a3408 |
-
|
|
|
7a3408 |
- ret = 0;
|
|
|
7a3408 |
-
|
|
|
7a3408 |
- cleanup:
|
|
|
7a3408 |
- VIR_FREE(path);
|
|
|
7a3408 |
- return ret;
|
|
|
7a3408 |
-}
|
|
|
7a3408 |
-
|
|
|
7a3408 |
-/**
|
|
|
7a3408 |
- * virNetDevRestoreMacAddress:
|
|
|
7a3408 |
- * @linkdev: name of interface
|
|
|
7a3408 |
- * @stateDir: directory containing old MAC address
|
|
|
7a3408 |
- *
|
|
|
7a3408 |
- * Returns 0 on success, -errno on failure.
|
|
|
7a3408 |
- *
|
|
|
7a3408 |
- */
|
|
|
7a3408 |
-static int
|
|
|
7a3408 |
-virNetDevRestoreMacAddress(const char *linkdev,
|
|
|
7a3408 |
- const char *stateDir)
|
|
|
7a3408 |
-{
|
|
|
7a3408 |
- int rc = -1;
|
|
|
7a3408 |
- char *oldmacname = NULL;
|
|
|
7a3408 |
- char *macstr = NULL;
|
|
|
7a3408 |
- char *path = NULL;
|
|
|
7a3408 |
- virMacAddr oldmac;
|
|
|
7a3408 |
-
|
|
|
7a3408 |
- if (virAsprintf(&path, "%s/%s",
|
|
|
7a3408 |
- stateDir,
|
|
|
7a3408 |
- linkdev) < 0)
|
|
|
7a3408 |
- return -1;
|
|
|
7a3408 |
-
|
|
|
7a3408 |
- if (virFileReadAll(path, VIR_MAC_STRING_BUFLEN, &macstr) < 0)
|
|
|
7a3408 |
- goto cleanup;
|
|
|
7a3408 |
-
|
|
|
7a3408 |
- if (virMacAddrParse(macstr, &oldmac) != 0) {
|
|
|
7a3408 |
- virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
7a3408 |
- _("Cannot parse MAC address from '%s'"),
|
|
|
7a3408 |
- oldmacname);
|
|
|
7a3408 |
- goto cleanup;
|
|
|
7a3408 |
- }
|
|
|
7a3408 |
-
|
|
|
7a3408 |
- /*reset mac and remove file-ignore results*/
|
|
|
7a3408 |
- rc = virNetDevSetMAC(linkdev, &oldmac);
|
|
|
7a3408 |
- ignore_value(unlink(path));
|
|
|
7a3408 |
-
|
|
|
7a3408 |
- cleanup:
|
|
|
7a3408 |
- VIR_FREE(macstr);
|
|
|
7a3408 |
- VIR_FREE(path);
|
|
|
7a3408 |
- return rc;
|
|
|
7a3408 |
-}
|
|
|
7a3408 |
-
|
|
|
7a3408 |
|
|
|
7a3408 |
static struct nla_policy ifla_vf_policy[IFLA_VF_MAX+1] = {
|
|
|
7a3408 |
[IFLA_VF_MAC] = { .type = NLA_UNSPEC,
|
|
|
7a3408 |
diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h
|
|
|
7a3408 |
index 190b70e..3568724 100644
|
|
|
7a3408 |
--- a/src/util/virnetdev.h
|
|
|
7a3408 |
+++ b/src/util/virnetdev.h
|
|
|
7a3408 |
@@ -114,6 +114,16 @@ int virNetDevGetMAC(const char *ifname,
|
|
|
7a3408 |
virMacAddrPtr macaddr)
|
|
|
7a3408 |
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
|
|
|
7a3408 |
|
|
|
7a3408 |
+int virNetDevReplaceMacAddress(const char *linkdev,
|
|
|
7a3408 |
+ const virMacAddr *macaddress,
|
|
|
7a3408 |
+ const char *stateDir)
|
|
|
7a3408 |
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
|
|
|
7a3408 |
+ ATTRIBUTE_RETURN_CHECK;
|
|
|
7a3408 |
+
|
|
|
7a3408 |
+int virNetDevRestoreMacAddress(const char *linkdev,
|
|
|
7a3408 |
+ const char *stateDir)
|
|
|
7a3408 |
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
|
|
|
7a3408 |
+
|
|
|
7a3408 |
int virNetDevSetMTU(const char *ifname,
|
|
|
7a3408 |
int mtu)
|
|
|
7a3408 |
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
|
|
|
7a3408 |
--
|
|
|
7a3408 |
2.5.1
|
|
|
7a3408 |
|