From: Serge Hallyn <serge.hallyn@xxxxxxxxxxxxx> configure.ac: check for libnl-3 in addition to libnl-1 src/Makefile.am: link against libnl when needed src/util/virnetlink.c: support libnl3 api. To minimize impact on code flow, wrap the differences under the virNetlink* namespace. Unfortunately libnl3 moves netlink/msg.h to /usr/include/libnl3/netlink/msg.h, so the LIBNL_CFLAGS need to be added to a bunch of places where they weren't needed with libnl1. Signed-off-by: Serge Hallyn <serge.hallyn@xxxxxxxxxxxxx> Signed-off-by: Eric Blake <eblake@xxxxxxxxxx> --- So far, I've tested under libnl-1 on Fedora 16. I'm also firing up my Ubuntu VM and upgrading it to 12.04, if I can reproduce the build failure pre-patch and a successful build post-patch, then I will push this under the build-breaker rule. Or I will push it if I get a positive review in the meantime. configure.ac | 25 +++++++++++++++++++------ src/Makefile.am | 15 ++++++++++----- src/util/virnetlink.c | 24 +++++++++++++++++------- 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/configure.ac b/configure.ac index a819898..30eff91 100644 --- a/configure.ac +++ b/configure.ac @@ -2626,18 +2626,31 @@ AM_CONDITIONAL([WITH_VIRTUALPORT], [test "$with_virtualport" = "yes"]) dnl netlink library +LIBNL_ROUTE3_CFLAGS="" +LIBNL_ROUTE3_LIBS="" LIBNL_CFLAGS="" LIBNL_LIBS="" have_libnl=no if test "$with_linux" = "yes"; then - PKG_CHECK_MODULES([LIBNL], [libnl-1 >= $LIBNL_REQUIRED], [ + PKG_CHECK_MODULES([LIBNL], [libnl-3.0], [ have_libnl=yes - AC_DEFINE_UNQUOTED([HAVE_LIBNL], 1, [whether the netlink library is available]) - ], [ - if test "$with_macvtap" = "yes"; then - AC_MSG_ERROR([libnl-devel >= $LIBNL_REQUIRED is required for macvtap support]) - fi + AC_DEFINE([HAVE_LIBNL3], [1], [Use libnl-3.0]) + AC_DEFINE([HAVE_LIBNL], [1], [whether the netlink library is available]) + PKG_CHECK_MODULES([LIBNL_ROUTE3], [libnl-route-3.0]) + LIBNL_CFLAGS="$LIBNL_CFLAGS $LIBNL_ROUTE3_CFLAGS" + LIBNL_LIBS="$LIBNL_LIBS $LIBNL_ROUTE3_LIBS" + ], [PKG_CHECK_MODULES([LIBNL], [libnl-1 >= $LIBNL_REQUIRED], [ + have_libnl=yes + AC_DEFINE_UNQUOTED([HAVE_LIBNL], [1], + [whether the netlink library is available]) + AC_DEFINE_UNQUOTED([HAVE_LIBNL1], [1], + [whether the netlink v1 library is available]) + ], [ + if test "$with_macvtap" = "yes"; then + AC_MSG_ERROR([libnl-devel >= $LIBNL_REQUIRED is required for macvtap support]) + fi + ]) ]) fi AM_CONDITIONAL([HAVE_LIBNL], [test "$have_libnl" = "yes"]) diff --git a/src/Makefile.am b/src/Makefile.am index e48dfa5..0dadc29 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -809,12 +809,14 @@ endif libvirt_driver_qemu_la_CFLAGS = $(NUMACTL_CFLAGS) \ $(GNUTLS_CFLAGS) \ $(LIBXML_CFLAGS) \ + $(LIBNL_CFLAGS) \ -I$(top_srcdir)/src/conf $(AM_CFLAGS) libvirt_driver_qemu_la_LDFLAGS = $(AM_LDFLAGS) libvirt_driver_qemu_la_LIBADD = $(NUMACTL_LIBS) \ $(CAPNG_LIBS) \ $(GNUTLS_LIBS) \ - $(LIBXML_LIBS) + $(LIBXML_LIBS) \ + $(LIBNL_LIBS) if WITH_DRIVER_MODULES libvirt_driver_qemu_la_LIBADD += ../gnulib/lib/libgnu.la libvirt_driver_qemu_la_LDFLAGS += -module -avoid-version @@ -840,8 +842,9 @@ noinst_LTLIBRARIES += libvirt_driver_lxc.la #libvirt_la_BUILT_LIBADD += libvirt_driver_lxc.la endif libvirt_driver_lxc_la_CFLAGS = \ + $(LIBNL_CFLAGS) \ -I$(top_srcdir)/src/conf $(AM_CFLAGS) -libvirt_driver_lxc_la_LIBADD = $(CAPNG_LIBS) +libvirt_driver_lxc_la_LIBADD = $(CAPNG_LIBS) $(LIBNL_LIBS) if WITH_SECDRIVER_SELINUX libvirt_driver_lxc_la_LIBADD += $(SELINUX_LIBS) endif @@ -941,9 +944,10 @@ noinst_LTLIBRARIES += libvirt_driver_network.la #libvirt_la_BUILT_LIBADD += libvirt_driver_network.la endif libvirt_driver_network_la_CFLAGS = \ + $(LIBNL_CFLAGS) \ -I$(top_srcdir)/src/conf $(AM_CFLAGS) if WITH_DRIVER_MODULES -libvirt_driver_network_la_LIBADD = ../gnulib/lib/libgnu.la +libvirt_driver_network_la_LIBADD = ../gnulib/lib/libgnu.la $(LIBNL_LIBS) libvirt_driver_network_la_LDFLAGS = -module -avoid-version $(AM_LDFLAGS) endif libvirt_driver_network_la_SOURCES = $(NETWORK_DRIVER_SOURCES) @@ -1086,9 +1090,9 @@ libvirt_la_BUILT_LIBADD += libvirt_driver_nwfilter.la noinst_LTLIBRARIES += libvirt_driver_nwfilter.la endif libvirt_driver_nwfilter_la_CFLAGS = $(LIBPCAP_CFLAGS) \ - -I$(top_srcdir)/src/conf $(AM_CFLAGS) + -I$(top_srcdir)/src/conf $(LIBNL_CFLAGS) $(AM_CFLAGS) libvirt_driver_nwfilter_la_LDFLAGS = $(LD_AMFLAGS) -libvirt_driver_nwfilter_la_LIBADD = $(LIBPCAP_LIBS) +libvirt_driver_nwfilter_la_LIBADD = $(LIBPCAP_LIBS) $(LIBNL_LIBS) if WITH_DRIVER_MODULES libvirt_driver_nwfilter_la_LIBADD += ../gnulib/lib/libgnu.la libvirt_driver_nwfilter_la_LDFLAGS += -module -avoid-version @@ -1540,6 +1544,7 @@ libvirt_lxc_CFLAGS = \ $(YAJL_CFLAGS) \ $(AUDIT_CFLAGS) \ $(DBUS_CFLAGS) \ + $(LIBNL_CFLAGS) \ -I$(top_srcdir)/src/conf \ $(AM_CFLAGS) if HAVE_LIBBLKID diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index b2e9d51..74f43ac 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011 Red Hat, Inc. + * Copyright (C) 2010-2012 Red Hat, Inc. * Copyright (C) 2010-2012 IBM Corporation * * This library is free software; you can redistribute it and/or @@ -60,6 +60,16 @@ struct virNetlinkEventHandle { int deleted; }; +# ifdef HAVE_LIBNL1 +# define virNetlinkAlloc nl_handle_alloc +# define virNetlinkFree nl_handle_destroy +typedef struct nl_handle virNetlinkHandle; +# else +# define virNetlinkAlloc nl_socket_alloc +# define virNetlinkFree nl_socket_free +typedef struct nl_sock virNetlinkHandle; +# endif + typedef struct _virNetlinkEventSrvPrivate virNetlinkEventSrvPrivate; typedef virNetlinkEventSrvPrivate *virNetlinkEventSrvPrivatePtr; struct _virNetlinkEventSrvPrivate { @@ -67,7 +77,7 @@ struct _virNetlinkEventSrvPrivate { virMutex lock; int eventwatch; int netlinkfd; - struct nl_handle *netlinknh; + virNetlinkHandle *netlinknh; /*Events*/ int handled; size_t handlesCount; @@ -121,7 +131,7 @@ int virNetlinkCommand(struct nl_msg *nl_msg, int fd; int n; struct nlmsghdr *nlmsg = nlmsg_hdr(nl_msg); - struct nl_handle *nlhandle = nl_handle_alloc(); + virNetlinkHandle *nlhandle = virNetlinkAlloc(); if (!nlhandle) { virReportSystemError(errno, @@ -178,7 +188,7 @@ error: *respbuflen = 0; } - nl_handle_destroy(nlhandle); + virNetlinkFree(nlhandle); return rc; } @@ -285,7 +295,7 @@ virNetlinkEventServiceStop(void) virNetlinkEventServerLock(srv); nl_close(srv->netlinknh); - nl_handle_destroy(srv->netlinknh); + virNetlinkFree(srv->netlinknh); virEventRemoveHandle(srv->eventwatch); /* free any remaining clients on the list */ @@ -346,7 +356,7 @@ virNetlinkEventServiceStart(void) virNetlinkEventServerLock(srv); /* Allocate a new socket and get fd */ - srv->netlinknh = nl_handle_alloc(); + srv->netlinknh = virNetlinkAlloc(); if (!srv->netlinknh) { virReportSystemError(errno, @@ -392,7 +402,7 @@ virNetlinkEventServiceStart(void) error_server: if (ret < 0) { nl_close(srv->netlinknh); - nl_handle_destroy(srv->netlinknh); + virNetlinkFree(srv->netlinknh); } error_locked: virNetlinkEventServerUnlock(srv); -- 1.7.7.6 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list