libvirt/5dd607059-add-virNetDevGetName.patch
Cédric Bosdonnat 79b3a063e4 Accepting request 481947 from home:cbosdonnat:branches:Virtualization
- Fail to start network instead of losing routes if IPv6 forwarding
  is required. bsc#1025252
  Added patches:
    00d28a78b-check-accept_ra-before-enabling-ipv6-forward.patch
    3ee35d7d6-more-uses-of-SYSCTL_PATH.patch
    5dd607059-add-virNetDevGetName.patch
    754515b7d-add-virNetlinkDumpCommand.patch
    d68cb4f55-extract-the-request-sending-code-from-virNetlin.patch

OBS-URL: https://build.opensuse.org/request/show/481947
OBS-URL: https://build.opensuse.org/package/show/Virtualization/libvirt?expand=0&rev=593
2017-03-22 08:50:09 +00:00

71 lines
2.1 KiB
Diff

From 5dd607059d8a98e04024305ae4afbd038aadbdcd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= <cbosdonnat@suse.com>
Date: Wed, 15 Mar 2017 14:46:56 +0100
Subject: [PATCH 4/5] util: add virNetDevGetName() function
Add a function getting the name of a network interface out of its index.
---
src/libvirt_private.syms | 1 +
src/util/virnetdev.c | 19 +++++++++++++++++++
src/util/virnetdev.h | 2 ++
3 files changed, 22 insertions(+)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index f03925bc1..3b2cb83c4 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1995,6 +1995,7 @@ virNetDevGetIndex;
virNetDevGetLinkInfo;
virNetDevGetMAC;
virNetDevGetMTU;
+virNetDevGetName;
virNetDevGetOnline;
virNetDevGetPhysicalFunction;
virNetDevGetPromiscuous;
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index d12324878..91a5274aa 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -899,6 +899,25 @@ virNetDevGetRcvAllMulti(const char *ifname,
return virNetDevGetIFFlag(ifname, VIR_IFF_ALLMULTI, receive);
}
+char *virNetDevGetName(int ifindex)
+{
+ char name[IFNAMSIZ];
+ char *ifname = NULL;
+
+ memset(&name, 0, sizeof(name));
+
+ if (!if_indextoname(ifindex, name)) {
+ virReportSystemError(errno,
+ _("Failed to convert interface index %d to a name"),
+ ifindex);
+ goto cleanup;
+ }
+
+ ignore_value(VIR_STRDUP(ifname, name));
+
+ cleanup:
+ return ifname;
+}
/**
* virNetDevGetIndex:
diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h
index 236cf83ef..01e9c5b95 100644
--- a/src/util/virnetdev.h
+++ b/src/util/virnetdev.h
@@ -157,6 +157,8 @@ int virNetDevSetNamespace(const char *ifname, pid_t pidInNs)
int virNetDevSetName(const char *ifname, const char *newifname)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
+char *virNetDevGetName(int ifindex)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
int virNetDevGetIndex(const char *ifname, int *ifindex)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
--
2.12.0