On Fri, Oct 10, 2014 at 02:04:04PM +0200, Cédric Bosdonnat wrote:
Add a default implementation of virNetDevSetIPv4Address using
netlink
and libnl. This avoids requiring /usr/sbin/ip or /usr/sbin/ifconfig
external binaries.
---
src/libvirt_private.syms | 1 +
src/util/virnetdev.c | 136 +++++++++++++++++++++++++++++++++++++++++++++--
src/util/virnetlink.c | 38 +++++++++++++
src/util/virnetlink.h | 2 +
4 files changed, 174 insertions(+), 3 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index b55bf35..f96387f 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1710,6 +1710,7 @@ virNetlinkEventServiceLocalPid;
virNetlinkEventServiceStart;
virNetlinkEventServiceStop;
virNetlinkEventServiceStopAll;
+virNetlinkGetErrorCode;
virNetlinkShutdown;
virNetlinkStartup;
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index db5623a..e4a005a 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -786,6 +786,88 @@ int virNetDevGetVLanID(const char *ifname ATTRIBUTE_UNUSED,
#endif /* ! SIOCGIFVLAN */
+#if defined(__linux__) && defined(HAVE_LIBNL)
+
+static int
+virNetDevGetIPAddressBinary(virSocketAddr *addr, void **data, size_t *len)
+{
+ if (!addr)
+ return -1;
+
+ switch (VIR_SOCKET_ADDR_FAMILY(addr)) {
+ case AF_INET:
+ *data = &addr->data.inet4.sin_addr;
+ *len = sizeof(struct in_addr);
+ break;
+ case AF_INET6:
+ *data = &addr->data.inet6.sin6_addr;
+ *len = sizeof(struct in6_addr);
+ break;
+ default:
+ return -1;
+ }
+ return 0;
+}
+
+static struct nl_msg
+*virNetDevCreateNetlinkAddressMessage(int messageType,
I'd normally expect the '*' on the same line as the return
type.
+ const char *ifname,
+ virSocketAddr *addr,
+ unsigned int prefix,
+ virSocketAddr *broadcast)
+{
ACK
Regards,
Daniel
--
|:
http://berrange.com -o-
http://www.flickr.com/photos/dberrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|:
http://entangle-photo.org -o-
http://live.gnome.org/gtk-vnc :|