diff --git a/configure.ac b/configure.ac index 80bc6fb4c..ab92513e5 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 +# 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 "${have_libnl}" = "no"); then - AC_MSG_ERROR([libnl development header are required]) +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 -AC_SUBST(LIBNL_CFLAGS) -AC_SUBST(LIBNL_LIBS) - -if (test "${libnl_version}" = "1"); then +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 e30ec37a6..68ee12159 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 eb0926ad0..80df09673 100644 --- a/src/nm-netlink-compat.h +++ b/src/nm-netlink-compat.h @@ -43,7 +43,7 @@ #include /* 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 891907eab..32a855e2a 100644 --- a/src/nm-system.c +++ b/src/nm-system.c @@ -60,7 +60,7 @@ #include #include -#ifdef HAVE_LIBNL3 +#if HAVE_LIBNL == 3 #include #include #endif