[PATCH 1/1] support libnl-3 (v2)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



configure.ac+Makefile.am: 
support libnl-3 as well as libnl-1

src/util/virnetlink.c:
support libnl3 api.  To minimize impact on code flow with #ifdefs as
requested by Stefan Berger, do some #defines at the top.

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.

Stefan, 
in this version I may have gone too far :) if you prefer I just
stick to using 'struct nl_socket nlhandle' and leave the rest
with explicit #ifdefs, let me know.  But this version leaves the
original code flow unencumbered by ifdefs and easier to read and
vet.

Signed-off-by: Serge Hallyn <serge.hallyn@xxxxxxxxxxxxx>
---
 configure.ac          |   24 +++++++++++++++++-------
 daemon/Makefile.am    |    5 ++++-
 src/Makefile.am       |   25 +++++++++++++++++--------
 src/util/virnetlink.c |   22 ++++++++++++++++------
 4 files changed, 54 insertions(+), 22 deletions(-)

diff --git a/configure.ac b/configure.ac
index a819898..ab40e1d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2626,19 +2626,29 @@ 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])
+    ],
+        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/daemon/Makefile.am b/daemon/Makefile.am
index 24cce8f..8074803 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -95,6 +95,7 @@ libvirtd_SOURCES = $(DAEMON_SOURCES)
 libvirtd_CFLAGS = \
 	$(LIBXML_CFLAGS) $(GNUTLS_CFLAGS) $(SASL_CFLAGS) \
 	$(XDR_CFLAGS) $(POLKIT_CFLAGS) $(DBUS_CFLAGS) \
+	$(LIBNL_CFLAGS) $(LIBNL_ROUTE3_CFLAGS) \
 	$(WARN_CFLAGS) \
 	$(COVERAGE_CFLAGS) \
 	-DQEMUD_PID_FILE="\"$(QEMUD_PID_FILE)\"" \
@@ -109,7 +110,9 @@ libvirtd_LDADD =					\
 	$(GNUTLS_LIBS)					\
 	$(SASL_LIBS)					\
 	$(DBUS_LIBS)					\
-	$(POLKIT_LIBS)
+	$(POLKIT_LIBS)					\
+	$(LIBNL_LIBS)					\
+	$(LIBNL_ROUTE3_LIBS)
 
 if WITH_DTRACE_PROBES
 libvirtd_LDADD += ../src/probes.o
diff --git a/src/Makefile.am b/src/Makefile.am
index e48dfa5..c159c1e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -576,10 +576,10 @@ libvirt_util_la_SOURCES =					\
 		$(UTIL_SOURCES)
 libvirt_util_la_CFLAGS = $(CAPNG_CFLAGS) $(YAJL_CFLAGS) $(LIBNL_CFLAGS) \
 		$(AM_CFLAGS) $(AUDIT_CFLAGS) $(DEVMAPPER_CFLAGS) \
-		$(DBUS_CFLAGS)
+		$(DBUS_CFLAGS) $(LIBNL_ROUTE3_CFLAGS)
 libvirt_util_la_LIBADD = $(CAPNG_LIBS) $(YAJL_LIBS) $(LIBNL_LIBS) \
 		$(THREAD_LIBS) $(AUDIT_LIBS) $(DEVMAPPER_LIBS) \
-		$(RT_LIBS) $(DBUS_LIBS)
+		$(RT_LIBS) $(DBUS_LIBS) $(LIBNL_ROUTE3_LIBS)
 
 
 noinst_LTLIBRARIES += libvirt_conf.la
@@ -809,12 +809,16 @@ endif
 libvirt_driver_qemu_la_CFLAGS = $(NUMACTL_CFLAGS) \
                                 $(GNUTLS_CFLAGS) \
                                 $(LIBXML_CFLAGS) \
+                                $(LIBNL_CFLAGS) \
+                                $(LIBNL_ROUTE3_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) \
+				$(LIBNL_ROUTE3_LIBS)
 if WITH_DRIVER_MODULES
 libvirt_driver_qemu_la_LIBADD += ../gnulib/lib/libgnu.la
 libvirt_driver_qemu_la_LDFLAGS += -module -avoid-version
@@ -840,8 +844,9 @@ noinst_LTLIBRARIES += libvirt_driver_lxc.la
 #libvirt_la_BUILT_LIBADD += libvirt_driver_lxc.la
 endif
 libvirt_driver_lxc_la_CFLAGS = \
+		$(LIBNL_CFLAGS) $(LIBNL_ROUTE3_CFLAGS) \
 		-I$(top_srcdir)/src/conf $(AM_CFLAGS)
-libvirt_driver_lxc_la_LIBADD = $(CAPNG_LIBS)
+libvirt_driver_lxc_la_LIBADD = $(CAPNG_LIBS) $(LIBNL_LIBS) $(LIBNL_ROUTE3_LIBS)
 if WITH_SECDRIVER_SELINUX
 libvirt_driver_lxc_la_LIBADD += $(SELINUX_LIBS)
 endif
@@ -941,9 +946,10 @@ noinst_LTLIBRARIES += libvirt_driver_network.la
 #libvirt_la_BUILT_LIBADD += libvirt_driver_network.la
 endif
 libvirt_driver_network_la_CFLAGS = \
+		$(LIBNL_CFLAGS) $(LIBNL_ROUTE3_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) $(LIBNL_ROUTE3_LIBS)
 libvirt_driver_network_la_LDFLAGS = -module -avoid-version $(AM_LDFLAGS)
 endif
 libvirt_driver_network_la_SOURCES = $(NETWORK_DRIVER_SOURCES)
@@ -1086,9 +1092,10 @@ 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) \
+		$(LIBNL_ROUTE3_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) $(LIBNL_ROUTE3_LIBS)
 if WITH_DRIVER_MODULES
 libvirt_driver_nwfilter_la_LIBADD += ../gnulib/lib/libgnu.la
 libvirt_driver_nwfilter_la_LDFLAGS += -module -avoid-version
@@ -1522,7 +1529,7 @@ libvirt_lxc_LDFLAGS = $(WARN_CFLAGS) $(AM_LDFLAGS)
 libvirt_lxc_LDADD = $(CAPNG_LIBS) $(YAJL_LIBS) \
 		$(LIBXML_LIBS) $(NUMACTL_LIBS) $(THREAD_LIBS) \
 		$(LIBNL_LIBS) $(AUDIT_LIBS) $(DEVMAPPER_LIBS) \
-		$(RT_LIBS) $(DBUS_LIBS) \
+		$(RT_LIBS) $(DBUS_LIBS) $(LIBNL_ROUTE3_LIBS) \
 		../gnulib/lib/libgnu.la
 if WITH_DTRACE_PROBES
 libvirt_lxc_LDADD += probes.o
@@ -1540,6 +1547,8 @@ libvirt_lxc_CFLAGS =				\
 		$(YAJL_CFLAGS)			\
 		$(AUDIT_CFLAGS)			\
 		$(DBUS_CFLAGS)			\
+		$(LIBNL_CFLAGS)			\
+		$(LIBNL_ROUTE3_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..596a917 100644
--- a/src/util/virnetlink.c
+++ b/src/util/virnetlink.c
@@ -60,6 +60,16 @@ struct virNetlinkEventHandle {
     int deleted;
 };
 
+#ifdef HAVE_LIBNL1
+#define nl_alloc nl_handle_alloc
+#define nl_free nl_handle_destroy
+typedef struct nl_handle nlhandle_t;
+#else
+#define nl_alloc nl_socket_alloc
+#define nl_free nl_socket_free
+typedef struct nl_sock nlhandle_t;
+#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;
+    nlhandle_t *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();
+    nlhandle_t *nlhandle = nl_alloc();
 
     if (!nlhandle) {
         virReportSystemError(errno,
@@ -178,7 +188,7 @@ error:
         *respbuflen = 0;
     }
 
-    nl_handle_destroy(nlhandle);
+    nl_free(nlhandle);
     return rc;
 }
 
@@ -285,7 +295,7 @@ virNetlinkEventServiceStop(void)
 
     virNetlinkEventServerLock(srv);
     nl_close(srv->netlinknh);
-    nl_handle_destroy(srv->netlinknh);
+    nl_free(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 = nl_alloc();
 
     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);
+        nl_free(srv->netlinknh);
     }
 error_locked:
     virNetlinkEventServerUnlock(srv);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]