On Mon, Apr 30, 2012 at 12:39:34PM -0500, Serge Hallyn wrote:
configure.ac:
If libnl-1 is not found, look for libnl-3, and (the also required)
libnl-route-3.
Makefile.am:
Add cflags and libs for libnl-3 and libnl-route-3
dutil_linux.{c,h}:
Switch the libnl calls over to new api if HAVE_LINBNL3. Also do
not include <net/if.h> in that case, because <linux/if.h> is
included from the libnl3 include files, and can conflict with net/if.h.
Signed-off-by: Serge Hallyn <serge.hallyn(a)canonical.com>
---
configure.ac | 6 +++++-
src/Makefile.am | 10 ++++++----
src/dutil_linux.c | 25 +++++++++++++++++++++++++
src/dutil_linux.h | 4 ++++
4 files changed, 40 insertions(+), 5 deletions(-)
diff --git a/configure.ac b/configure.ac
index 6705a0d..41dd49d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -103,7 +103,11 @@ AM_CONDITIONAL([NETCF_INIT_SCRIPT_RED_HAT],
if test "x$with_driver" != "xmswindows"
then
PKG_CHECK_MODULES([LIBAUGEAS], [augeas >= 0.5.0])
- PKG_CHECK_MODULES([LIBNL], [libnl-1])
+ PKG_CHECK_MODULES([LIBNL], [libnl-1],
+ [AC_DEFINE([HAVE_LIBNL], [1], [Use libnl-1])],[
+ PKG_CHECK_MODULES([LIBNL],[libnl-3.0],[AC_DEFINE([HAVE_LIBNL3],[1],[Use
libnl-3.0])])
+ PKG_CHECK_MODULES([LIBNL_ROUTE3],[libnl-route-3.0])
+ ])
fi
if test "x$with_driver" = "xdebian"; then
diff --git a/src/Makefile.am b/src/Makefile.am
index b5c732a..87d18eb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,7 +3,9 @@ GNULIB= ../gnulib/lib/libgnu.la
GNULIB_CFLAGS= -I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib
AM_CFLAGS = $(NETCF_CFLAGS) $(GNULIB_CFLAGS) $(WARN_CFLAGS) \
- $(LIBXML_CFLAGS) $(LIBXSLT_CFLAGS) $(LIBAUGEAS_CFLAGS)
+ $(LIBXML_CFLAGS) $(LIBXSLT_CFLAGS) $(LIBAUGEAS_CFLAGS) $(LIBNL_CFLAGS)
$(LIBNL_ROUTE3_CFLAGS)
+
+AM_LDFLAGS = $(LIBNL_LIBS) $(LIBNL_ROUTE3_LIBS)
include_HEADERS = netcf.h
@@ -64,15 +66,15 @@ libnetcf_la_SOURCES = netcf.h netcf.c internal.h \
ref.h list.h \
xslt_ext.c $(DRIVER_SOURCES)
libnetcf_la_LDFLAGS = -Wl,--version-script=netcf.syms \
- -version-info $(LIBNETCF_VERSION_INFO) -no-undefined
-libnetcf_la_LIBADD = $(NETCF_LIBDEPS) $(GNULIB)
+ -version-info $(LIBNETCF_VERSION_INFO) -no-undefined $(LIBNL_CFLAGS)
$(LIBNL_ROUTE3_CFLAGS)
+libnetcf_la_LIBADD = $(NETCF_LIBDEPS) $(GNULIB) $(LIBNL_LIBS) $(LIBNL_ROUTE3_LIBS)
if NETCF_DRIVER_MSWINDOWS
libnetcf_la_LIBADD += -liphlpapi
endif
libnetcf_la_DEPENDENCIES = $(GNULIB) netcf.syms
ncftool_SOURCES = ncftool.c
-ncftool_LDADD = libnetcf.la $(READLINE_LIBS) $(GNULIB)
+ncftool_LDADD = libnetcf.la $(READLINE_LIBS) $(GNULIB) $(LIBNL_LIBS)
$(LIBNL_ROUTE3_LIBS)
if ! NETCF_DRIVER_MSWINDOWS
ncftransform_SOURCES = ncftransform.c
diff --git a/src/dutil_linux.c b/src/dutil_linux.c
index 4e05c49..f4b4bf7 100644
--- a/src/dutil_linux.c
+++ b/src/dutil_linux.c
@@ -54,12 +54,18 @@
#include "dutil.h"
#include "dutil_linux.h"
+#ifndef HAVE_LIBNL3
#include <net/if.h>
+#endif
#include <netlink/socket.h>
#include <netlink/cache.h>
#include <netlink/route/addr.h>
#include <netlink/route/link.h>
+#ifdef HAVE_LIBNL3
+#define RTNL_LINK_NOT_FOUND 0
+#endif
+
/* For some reason, the headers for libnl vlan functions aren't installed */
extern int rtnl_link_vlan_get_id(struct rtnl_link *link);
@@ -796,21 +802,36 @@ done:
int netlink_init(struct netcf *ncf) {
+#ifdef HAVE_LIBNL
ncf->driver->nl_sock = nl_handle_alloc();
+#elif HAVE_LIBNL3
+ int ret;
+ ncf->driver->nl_sock = nl_socket_alloc();
+#endif
if (ncf->driver->nl_sock == NULL)
goto error;
if (nl_connect(ncf->driver->nl_sock, NETLINK_ROUTE) < 0) {
goto error;
}
+#ifdef HAVE_LIBNL
ncf->driver->link_cache = rtnl_link_alloc_cache(ncf->driver->nl_sock);
if (ncf->driver->link_cache == NULL) {
+#elif HAVE_LIBNL3
+ ret = rtnl_link_alloc_cache(ncf->driver->nl_sock, AF_UNSPEC,
&ncf->driver->link_cache);
+ if (ret < 0) {
+#endif
goto error;
}
nl_cache_mngt_provide(ncf->driver->link_cache);
+#ifdef HAVE_LIBNL
ncf->driver->addr_cache = rtnl_addr_alloc_cache(ncf->driver->nl_sock);
if (ncf->driver->addr_cache == NULL) {
+#elif HAVE_LIBNL3
+ ret = rtnl_addr_alloc_cache(ncf->driver->nl_sock,
&ncf->driver->addr_cache);
+ if (ret < 0) {
+#endif
goto error;
}
nl_cache_mngt_provide(ncf->driver->addr_cache);
@@ -837,7 +858,11 @@ int netlink_close(struct netcf *ncf) {
}
if (ncf->driver->nl_sock) {
nl_close(ncf->driver->nl_sock);
+#ifdef HAVE_LIBNL
nl_handle_destroy(ncf->driver->nl_sock);
+#elif HAVE_LIBNL3
+ nl_socket_free(ncf->driver->nl_sock);
+#endif
ncf->driver->nl_sock = NULL;
}
return 0;
diff --git a/src/dutil_linux.h b/src/dutil_linux.h
index 8b10e71..81f434b 100644
--- a/src/dutil_linux.h
+++ b/src/dutil_linux.h
@@ -30,7 +30,11 @@ struct driver {
xsltStylesheetPtr put;
xsltStylesheetPtr get;
int ioctl_fd;
+#ifdef HAVE_LIBNL
struct nl_handle *nl_sock;
+#elif HAVE_LIBNL3
+ struct nl_sock *nl_sock;
+#endif
struct nl_cache *link_cache;
struct nl_cache *addr_cache;
unsigned int load_augeas : 1;
ACK, that is alot smaller diff than I expected
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 :|