From: "Daniel P. Berrange" <berrange(a)redhat.com>
To match up with the existing virNetDevSetIPv4Address, rename
ifaceGetIPAddress to virNetDevGetIPv4Address
* util/interface.h, util/interface.c: Rename API
* network/bridge_driver.c: Update for API rename
---
src/libvirt_private.syms | 2 +-
src/network/bridge_driver.c | 11 +++------
src/util/interface.c | 46 +++++++++++++++++++++++-------------------
src/util/interface.h | 3 +-
4 files changed, 32 insertions(+), 30 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 8206b23..183e4f5 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -577,7 +577,7 @@ virHookPresent;
# interface.h
ifaceCheck;
virNetDevGetIndex;
-ifaceGetIPAddress;
+virNetDevGetIPv4Address;
ifaceGetNthParent;
ifaceGetPhysicalFunction;
ifaceGetVirtualFunctionIndex;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index bad5337..3f8c8c4 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -3147,13 +3147,10 @@ networkGetNetworkAddress(const char *netname, char **netaddr)
}
if (dev_name) {
- if (ifaceGetIPAddress(dev_name, &addr)) {
- virReportSystemError(errno,
- _("Failed to get IP address for '%s'
(network '%s')"),
- dev_name, netdef->name);
- } else {
- addrptr = &addr;
- }
+ if (virNetDevGetIPv4Address(dev_name, &addr) < 0)
+ goto cleanup;
+
+ addrptr = &addr;
}
if (addrptr &&
diff --git a/src/util/interface.c b/src/util/interface.c
index 9762145..4e1ee25 100644
--- a/src/util/interface.c
+++ b/src/util/interface.c
@@ -142,60 +142,64 @@ ifaceCheck(bool reportError ATTRIBUTE_UNUSED,
/**
- * ifaceGetIPAddress:
+ * virNetDevGetIPv4Address:
* @ifname: name of the interface whose IP address we want
- * @macaddr: MAC address (VIR_MAC_BUFLEN in size)
+ * @addr: filled with the IPv4 address
*
- * This function gets the @macaddr for a given interface @ifname.
+ * This function gets the IPv4 address for the interface @ifname
+ * and stores it in @addr
*
* Returns 0 on success, -errno on failure.
*/
#ifdef __linux__
-int
-ifaceGetIPAddress(const char *ifname,
- virSocketAddrPtr addr)
+int virNetDevGetIPv4Address(const char *ifname,
+ virSocketAddrPtr addr)
{
struct ifreq ifr;
int fd;
int rc = 0;
- if (!ifname || !addr)
- return -EINVAL;
-
memset (addr, 0, sizeof(*addr));
addr->data.stor.ss_family = AF_UNSPEC;
fd = socket(AF_INET, SOCK_STREAM, 0);
- if (fd < 0)
- return -errno;
+ if (fd < 0) {
+ virReportSystemError(errno, "%s",
+ _("Unable to open control socket"));
+ return -1;
+ }
memset(&ifr, 0, sizeof(struct ifreq));
if (virStrcpyStatic(ifr.ifr_name, ifname) == NULL) {
- rc = -EINVAL;
- goto err_exit;
+ virReportSystemError(ERANGE,
+ _("invalid interface name %s"),
+ ifname);
+ goto cleanup;
}
- if (ioctl(fd, SIOCGIFADDR, (char *)&ifr) != 0) {
- rc = -errno;
- goto err_exit;
+ if (ioctl(fd, SIOCGIFADDR, (char *)&ifr) < 0) {
+ virReportSystemError(errno,
+ _("Unable to get IPv4 address for interface %s"),
ifname);
+ goto cleanup;
}
addr->data.stor.ss_family = AF_INET;
addr->len = sizeof(addr->data.inet4);
memcpy(&addr->data.inet4, &ifr.ifr_addr, addr->len);
-err_exit:
+cleanup:
VIR_FORCE_CLOSE(fd);
return rc;
}
#else
-int
-ifaceGetIPAddress(const char *ifname ATTRIBUTE_UNUSED,
- virSocketAddrPtr addr ATTRIBUTE_UNUSED)
+int virNetDevGetIPv4Address(const char *ifname ATTRIBUTE_UNUSED,
+ virSocketAddrPtr addr ATTRIBUTE_UNUSED)
{
- return -ENOSYS;
+ virReportSystemError(ENOSYS, "%s",
+ _("Unable to get IPv4 address on this platform"));
+ return -1;
}
#endif /* __linux__ */
diff --git a/src/util/interface.h b/src/util/interface.h
index aa70192..0a11ecd 100644
--- a/src/util/interface.h
+++ b/src/util/interface.h
@@ -33,7 +33,8 @@ struct nlattr;
int ifaceCheck(bool reportError, const char *ifname,
const unsigned char *macaddr, int ifindex);
-int ifaceGetIPAddress(const char *ifname, virSocketAddrPtr addr);
+int virNetDevGetIPv4Address(const char *ifname, virSocketAddrPtr addr)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
int ifaceMacvtapLinkDump(bool nltarget_kernel, const char *ifname, int ifindex,
struct nlattr **tb, unsigned char **recvbuf,
--
1.7.6.4