summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Šimerda <psimerda@redhat.com>2012-11-22 16:09:35 +0100
committerPavel Šimerda <psimerda@redhat.com>2012-11-22 18:03:16 +0100
commit423d766b03b94be683bf6f46e92fdd6dfcedd121 (patch)
treed3eb8e54475077e61701ba3ffeabea0a8dbe52e5
parent56550a984f9827fce12fb9b641e2e6fced10c4e3 (diff)
build: implement libnl version selection
Until we remove libnl-1.x and libnl-2.x support, it should be possible to choose the libnl version at build time. This is mostly important for testing legacy libnl support but it also helps distributions that ship other tools built agains them. (https://bugs.gentoo.org/show_bug.cgi?id=441750)
-rw-r--r--configure.ac82
-rw-r--r--src/nm-netlink-compat.c4
-rw-r--r--src/nm-netlink-compat.h16
-rw-r--r--src/nm-system.c2
4 files changed, 54 insertions, 50 deletions
diff --git a/configure.ac b/configure.ac
index 80bc6fb4c8..ab92513e5c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -316,44 +316,44 @@ esac
AM_CONDITIONAL(SUSPEND_RESUME_UPOWER, test "x$with_suspend_resume" = "xupower")
AM_CONDITIONAL(SUSPEND_RESUME_SYSTEMD, test "x$with_suspend_resume" = "xsystemd")
-
-have_libnl="no"
-PKG_CHECK_MODULES(LIBNL3, libnl-3.0, [have_libnl3=yes], [have_libnl3=no])
-PKG_CHECK_MODULES(LIBNL_ROUTE3, libnl-route-3.0, [have_libnl_route3=yes], [have_libnl_route3=no])
-PKG_CHECK_MODULES(LIBNL_GENL3, libnl-genl-3.0, [have_libnl_genl3=yes], [have_libnl_genl3=no])
-if (test "${have_libnl3}" = "yes" -a "${have_libnl_route3}" = "yes" -a "${have_libnl_genl3}" = "yes"); then
- AC_DEFINE(HAVE_LIBNL3, 1, [Define if you require specific libnl-3 support])
- LIBNL_CFLAGS="$LIBNL3_CFLAGS $LIBNL_ROUTE3_CFLAGS $LIBNL_GENL3_CFLAGS"
- LIBNL_LIBS="$LIBNL3_LIBS $LIBNL_ROUTE3_LIBS $LIBNL_GENL3_LIBS"
- libnl_version="3"
- have_libnl="yes"
-else
- PKG_CHECK_MODULES(LIBNL2, libnl-2.0, [have_libnl2=yes], [have_libnl2=no])
- if (test "${have_libnl2}" = "yes"); then
- AC_DEFINE(HAVE_LIBNL2, 1, [Define if you require specific libnl-2 support])
- LIBNL_CFLAGS="$LIBNL2_CFLAGS"
- LIBNL_LIBS="$LIBNL2_LIBS"
- libnl_version="2"
- have_libnl="yes"
- else
- PKG_CHECK_MODULES(LIBNL1, libnl-1 >= 1.0-pre8, [have_libnl1=yes], [have_libnl1=no])
- if (test "${have_libnl1}" = "yes"); then
- AC_DEFINE(HAVE_LIBNL1, 1, [Define if you require libnl-1 legacy support])
- LIBNL_CFLAGS="$LIBNL1_CFLAGS"
- LIBNL_LIBS="$LIBNL1_LIBS"
- libnl_version="1"
- have_libnl="yes"
- fi
- fi
-fi
-
-if (test "${have_libnl}" = "no"); then
- AC_MSG_ERROR([libnl development header are required])
-fi
-AC_SUBST(LIBNL_CFLAGS)
-AC_SUBST(LIBNL_LIBS)
-
-if (test "${libnl_version}" = "1"); then
+# libnl support for the linux platform
+AC_ARG_WITH(libnl, AS_HELP_STRING([--with-libnl=1|2|3], [Select libnl version (default: latest available)]))
+# default to "yes"
+AS_IF([test -z "$with_libnl"], with_libnl=yes)
+# test for various libnl versions
+if test "$with_libnl" = "yes" -o "$with_libnl" = "3"; then
+ PKG_CHECK_MODULES(LIBNL3, libnl-3.0 libnl-route-3.0 libnl-genl-3.0,
+ [with_libnl=3], [test "$with_libnl" = "3" && with_libnl=no])
+ AS_IF([test "$with_libnl" = "no"],
+ AC_MSG_ERROR([libnl 3.x could not be found]))
+fi
+if test "$with_libnl" = "yes" -o "$with_libnl" = "2"; then
+ PKG_CHECK_MODULES(LIBNL2, libnl-2.0,
+ [with_libnl=2], [test "$with_libnl" = "2" && with_libnl=no])
+ AS_IF([test "$with_libnl" = "no"],
+ AC_MSG_ERROR([libnl 2.x could not be found]))
+fi
+if test "$with_libnl" = "yes" -o "$with_libnl" = "1"; then
+ PKG_CHECK_MODULES(LIBNL1, libnl-1 >= 1.0-pre8,
+ [with_libnl=1], [test "$with_libnl" = "1" && with_libnl=no])
+ AS_IF([test "$with_libnl" = "no"],
+ AC_MSG_ERROR([libnl 1.x could not be found]))
+fi
+if test "$with_libnl" = "yes"; then
+ AC_MSG_ERROR([libnl library could not be found])
+ with_libnl=no
+fi
+if ! echo "$with_libnl" | grep -q "^[[1-3]]$"; then
+ AC_MSG_ERROR([unsupported libnl version: $with_libnl])
+fi
+# add variables, conditionals and defines
+if test "$with_libnl" != "no"; then
+ AC_DEFINE_UNQUOTED(HAVE_LIBNL, $with_libnl, [libnl version])
+ AC_SUBST(LIBNL_CFLAGS, "$LIBNL3_CFLAGS$LIBNL2_CFLAGS$LIBNL1_CFLAGS")
+ AC_SUBST(LIBNL_LIBS, "$LIBNL3_LIBS$LIBNL2_LIBS$LIBNL1_LIBS")
+fi
+# additional tests
+if test "with_libnl" = "1"; then
NM_LIBNL_CHECK
fi
@@ -765,7 +765,11 @@ echo " nmstatedir: $nmstatedir"
echo " nmrundir: $nmrundir"
echo
-echo Configuration plugins:
+echo "Platform interaction:"
+echo " libnl: $with_libnl"
+echo
+
+echo "Configuration plugins"
echo " ifcfg-rh: ${enable_ifcfg_rh}"
echo " ifcfg-suse: ${enable_ifcfg_suse}"
echo " ifupdown: ${enable_ifupdown}"
diff --git a/src/nm-netlink-compat.c b/src/nm-netlink-compat.c
index e30ec37a63..68ee12159f 100644
--- a/src/nm-netlink-compat.c
+++ b/src/nm-netlink-compat.c
@@ -29,7 +29,7 @@
#include "nm-logging.h"
#include "nm-netlink-compat.h"
-#ifndef HAVE_LIBNL1
+#if HAVE_LIBNL != 1
struct rtnl_nexthop *
nm_netlink_get_nh (struct rtnl_route * route)
{
@@ -93,7 +93,7 @@ rtnl_route_get_dst_len(struct rtnl_route * rtnlroute)
}
#endif
-#ifdef HAVE_LIBNL1
+#if HAVE_LIBNL == 1
int
nl_compat_error (int err)
{
diff --git a/src/nm-netlink-compat.h b/src/nm-netlink-compat.h
index eb0926ad07..80df096730 100644
--- a/src/nm-netlink-compat.h
+++ b/src/nm-netlink-compat.h
@@ -43,7 +43,7 @@
#include <config.h>
/* libnl-1 API compatibility for libnl-2/3*/
-#ifndef HAVE_LIBNL1
+#if HAVE_LIBNL != 1
struct rtnl_nexthop * nm_netlink_get_nh(struct rtnl_route *);
int rtnl_route_get_oif(struct rtnl_route *);
@@ -54,7 +54,7 @@ struct nl_addr * rtnl_route_get_gateway(struct rtnl_route *);
#endif
/* libnl-2 API compatibility for libnl-3 */
-#ifdef HAVE_LIBNL3
+#if HAVE_LIBNL == 3
static inline int
__rtnl_link_alloc_cache (struct nl_sock *h, struct nl_cache **cache)
{
@@ -65,15 +65,15 @@ __rtnl_link_alloc_cache (struct nl_sock *h, struct nl_cache **cache)
/* libnl-2.0 compat functions */
-#ifdef HAVE_LIBNL2
+#if HAVE_LIBNL == 2
/* functions with similar prototypes */
#define nlmsg_datalen nlmsg_len
-#endif /* HAVE_LIBNL2 */
+#endif
/* libnl-1.0 compat functions */
-#ifdef HAVE_LIBNL1
+#if HAVE_LIBNL == 1
#define nl_sock nl_handle
@@ -204,10 +204,10 @@ __nl_cache_include (struct nl_cache *cache, struct nl_object *obj, change_func_t
#define NLE_PERM 28
#define NLE_PKTLOC_FILE 29
-#endif /* HAVE_LIBNL1 */
+#endif
/* Stuff that only libnl3 has */
-#if defined(HAVE_LIBNL1) || defined(HAVE_LIBNL2)
+#if HAVE_LIBNL == 1 || HAVE_LIBNL == 2
static inline int
rtnl_link_bond_add (struct nl_sock *h, const char *name, void *data)
@@ -276,6 +276,6 @@ rtnl_link_delete(struct nl_sock *sk, const struct rtnl_link *l)
/* Operation only in libnl3 */
return -NLE_OPNOTSUPP;
}
-#endif /* HAVE_LIBNL1 || HAVE_LIBNL2 */
+#endif
#endif /* NM_NETLINK_COMPAT_H */
diff --git a/src/nm-system.c b/src/nm-system.c
index 891907eabb..32a855e2af 100644
--- a/src/nm-system.c
+++ b/src/nm-system.c
@@ -60,7 +60,7 @@
#include <netlink/utils.h>
#include <netlink/route/link.h>
-#ifdef HAVE_LIBNL3
+#if HAVE_LIBNL == 3
#include <netlink/route/link/bonding.h>
#include <netlink/route/link/vlan.h>
#endif