[PATCH 1/1] Support libnl-3 as well as libnl-1

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

 



configure.ac:
Check for libnl-3.  If found, find libnl-route-3.  If not found,
do the original check to look for libnl-1.

src/util/virnetlink.c:
support libnl3 api.  I could play games to make the patch smaller,
but this would just hide what is actually needing to be done at
the expense of clarity.

src/Makefile.am and daemon/Makefile.am:
Add LIBNL_ROUTE3_{LIBS,CFLAGS}
Unfortunately libnl3 moves netlink/msg.h to /usr/include/libnl3/netlink/msg.h,
which is the reason why the LIBNL_CFLAGS need to be added to a bunch of
places where they weren't needed with libnl1.  Those spots probaby don't
actually need to also have LIBNL*LIBS added, but while I may be looking at
it wrong, it seemed right to do so.

I haven't gotten as far as to compile this into a package on
ubuntu, but the source does build with libnl-3 as well as with
libnl-1.

Signed-off-by: Serge Hallyn <serge.hallyn@xxxxxxxxxxxxx>
---
 configure.ac          |   24 ++++++++++++-----
 daemon/Makefile.am    |    5 +++-
 src/Makefile.am       |   25 ++++++++++++------
 src/util/virnetlink.c |   70 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 108 insertions(+), 16 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..1d3cd2e 100644
--- a/src/util/virnetlink.c
+++ b/src/util/virnetlink.c
@@ -67,7 +67,11 @@ struct _virNetlinkEventSrvPrivate {
     virMutex lock;
     int eventwatch;
     int netlinkfd;
+#ifdef HAVE_LIBNL1
     struct nl_handle *netlinknh;
+#else
+    struct nl_sock *netlinksock;
+#endif
     /*Events*/
     int handled;
     size_t handlesCount;
@@ -121,15 +125,31 @@ int virNetlinkCommand(struct nl_msg *nl_msg,
     int fd;
     int n;
     struct nlmsghdr *nlmsg = nlmsg_hdr(nl_msg);
+#ifdef HAVE_LIBNL1
     struct nl_handle *nlhandle = nl_handle_alloc();
+#else
+    struct nl_sock *nlsock = nl_socket_alloc();
+#endif
 
+#ifdef HAVE_LIBNL1
     if (!nlhandle) {
+#else
+    if (!nlsock) {
+#endif
         virReportSystemError(errno,
+#ifdef HAVE_LIBNL1
                              "%s", _("cannot allocate nlhandle for netlink"));
+#else
+                             "%s", _("cannot allocate nlsock for netlink"));
+#endif
         return -1;
     }
 
+#ifdef HAVE_LIBNL1
     if (nl_connect(nlhandle, NETLINK_ROUTE) < 0) {
+#else
+    if (nl_connect(nlsock, NETLINK_ROUTE) < 0) {
+#endif
         virReportSystemError(errno,
                              "%s", _("cannot connect to netlink socket"));
         rc = -1;
@@ -140,7 +160,11 @@ int virNetlinkCommand(struct nl_msg *nl_msg,
 
     nlmsg->nlmsg_pid = getpid();
 
+#ifdef HAVE_LIBNL1
     nbytes = nl_send_auto_complete(nlhandle, nl_msg);
+#else
+    nbytes = nl_send_auto_complete(nlsock, nl_msg);
+#endif
     if (nbytes < 0) {
         virReportSystemError(errno,
                              "%s", _("cannot send to netlink socket"));
@@ -148,7 +172,11 @@ int virNetlinkCommand(struct nl_msg *nl_msg,
         goto error;
     }
 
+#ifdef HAVE_LIBNL1
     fd = nl_socket_get_fd(nlhandle);
+#else
+    fd = nl_socket_get_fd(nlsock);
+#endif
 
     FD_ZERO(&readfds);
     FD_SET(fd, &readfds);
@@ -165,7 +193,11 @@ int virNetlinkCommand(struct nl_msg *nl_msg,
         goto error;
     }
 
+#ifdef HAVE_LIBNL1
     *respbuflen = nl_recv(nlhandle, &nladdr, respbuf, NULL);
+#else
+    *respbuflen = nl_recv(nlsock, &nladdr, respbuf, NULL);
+#endif
     if (*respbuflen <= 0) {
         virReportSystemError(errno,
                              "%s", _("nl_recv failed"));
@@ -178,7 +210,11 @@ error:
         *respbuflen = 0;
     }
 
+#ifdef HAVE_LIBNL1
     nl_handle_destroy(nlhandle);
+#else
+    nl_socket_free(nlsock);
+#endif
     return rc;
 }
 
@@ -233,7 +269,11 @@ virNetlinkEventCallback(int watch,
     int i, length;
     bool handled = false;
 
+#ifdef HAVE_LIBNL1
     length = nl_recv(srv->netlinknh, &peer, &msg, &creds);
+#else
+    length = nl_recv(srv->netlinksock, &peer, &msg, &creds);
+#endif
 
     if (length == 0)
         return;
@@ -284,8 +324,13 @@ virNetlinkEventServiceStop(void)
         return 0;
 
     virNetlinkEventServerLock(srv);
+#ifdef HAVE_LIBNL1
     nl_close(srv->netlinknh);
     nl_handle_destroy(srv->netlinknh);
+#else
+    nl_close(srv->netlinksock);
+    nl_socket_free(srv->netlinksock);
+#endif
     virEventRemoveHandle(srv->eventwatch);
 
     /* free any remaining clients on the list */
@@ -346,21 +391,37 @@ virNetlinkEventServiceStart(void)
     virNetlinkEventServerLock(srv);
 
     /* Allocate a new socket and get fd */
+#ifdef HAVE_LIBNL1
     srv->netlinknh = nl_handle_alloc();
+#else
+    srv->netlinksock = nl_socket_alloc();
+#endif
 
+#ifdef HAVE_LIBNL1
     if (!srv->netlinknh) {
+#else
+    if (!srv->netlinksock) {
+#endif
         virReportSystemError(errno,
                              "%s", _("cannot allocate nlhandle for virNetlinkEvent server"));
         goto error_locked;
     }
 
+#ifdef HAVE_LIBNL1
     if (nl_connect(srv->netlinknh, NETLINK_ROUTE) < 0) {
+#else
+    if (nl_connect(srv->netlinksock, NETLINK_ROUTE) < 0) {
+#endif
         virReportSystemError(errno,
                              "%s", _("cannot connect to netlink socket"));
         goto error_server;
     }
 
+#ifdef HAVE_LIBNL1
     fd = nl_socket_get_fd(srv->netlinknh);
+#else
+    fd = nl_socket_get_fd(srv->netlinksock);
+#endif
 
     if (fd < 0) {
         virReportSystemError(errno,
@@ -368,7 +429,11 @@ virNetlinkEventServiceStart(void)
         goto error_server;
     }
 
+#ifdef HAVE_LIBNL1
     if (nl_socket_set_nonblocking(srv->netlinknh)) {
+#else
+    if (nl_socket_set_nonblocking(srv->netlinksock)) {
+#endif
         virReportSystemError(errno, "%s",
                              _("cannot set netlink socket nonblocking"));
         goto error_server;
@@ -391,8 +456,13 @@ virNetlinkEventServiceStart(void)
 
 error_server:
     if (ret < 0) {
+#ifdef HAVE_LIBNL1
         nl_close(srv->netlinknh);
         nl_handle_destroy(srv->netlinknh);
+#else
+        nl_close(srv->netlinksock);
+        nl_socket_free(srv->netlinksock);
+#endif
     }
 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]