build: drop libnl 1.x and 2.x support, require libnl >= 3.2.7

This commit is contained in:
Pavel Šimerda 2013-01-23 10:18:59 +01:00
parent 418a428975
commit 663859c180
7 changed files with 11 additions and 490 deletions

View file

@ -320,46 +320,11 @@ AM_CONDITIONAL(SUSPEND_RESUME_UPOWER, test "x$with_suspend_resume" = "xupower")
AM_CONDITIONAL(SUSPEND_RESUME_SYSTEMD, test "x$with_suspend_resume" = "xsystemd")
# 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
PKG_CHECK_MODULES(LIBNL, libnl-3.0 >= 3.2.7 libnl-route-3.0 libnl-genl-3.0)
AC_SUBST(LIBNL_CFLAGS)
AC_SUBST(LIBNL_LIBS)
# uuid library
PKG_CHECK_MODULES(UUID, uuid)
AC_SUBST(UUID_CFLAGS)
AC_SUBST(UUID_LIBS)

View file

@ -1,62 +0,0 @@
AC_DEFUN([NM_LIBNL_CHECK], [
AC_MSG_CHECKING([for libnl address caching bug])
save_CFLAGS="$CFLAGS"
save_LDFLAGS="$LDFLAGS"
CFLAGS="$CFLAGS $LIBNL_CFLAGS"
LDFLAGS="$LDFLAGS $LIBNL_LIBS"
AC_RUN_IFELSE([AC_LANG_PROGRAM([[
#include <stdio.h>
#include <netlink/route/addr.h>
#include <netlink/object-api.h>
]],
[[
struct nl_handle *nlh;
struct nl_cache *cache;
struct nl_object *obj;
nlh = nl_handle_alloc ();
if (nl_connect (nlh, NETLINK_ROUTE) < 0) {
fprintf (stderr, "couldn't connect to netlink: %s", nl_geterror ());
return 3;
}
cache = rtnl_addr_alloc_cache (nlh);
if (!cache || nl_cache_nitems (cache) == 0) {
fprintf (stderr, "couldn't fill address cache: %s", nl_geterror ());
return 3;
}
obj = nl_cache_get_first (cache);
if (nl_object_identical (obj, obj))
return 0;
nl_cache_get_ops (cache)->co_obj_ops->oo_id_attrs &= ~0x80;
if (nl_object_identical (obj, obj))
return 1;
else
return 2;
]])], libnl_bug=$?, libnl_bug=$?, libnl_bug=cross)
CFLAGS="$save_CFLAGS"
LDFLAGS="$save_LDFLAGS"
case $libnl_bug in
0) AC_MSG_RESULT([no])
;;
1) AC_MSG_RESULT([yes, using workaround])
AC_DEFINE(LIBNL_NEEDS_ADDR_CACHING_WORKAROUND, 1, [Define this to hack around buggy libnl rtnl_addr caching])
;;
2) AC_MSG_RESULT([yes, and workaround doesn't work])
AC_MSG_ERROR([Installed libnl has broken address caching; please patch or upgrade])
;;
cross) AC_MSG_RESULT([cross-compiling... assuming it works!])
;;
*) AC_MSG_RESULT([?])
AC_MSG_ERROR([libnl test program failed])
;;
esac
])

View file

@ -29,8 +29,7 @@
#include "nm-logging.h"
#include "nm-netlink-compat.h"
#if HAVE_LIBNL != 1
struct rtnl_nexthop *
static struct rtnl_nexthop *
nm_netlink_get_nh (struct rtnl_route * route)
{
int hops;
@ -91,152 +90,3 @@ rtnl_route_get_dst_len(struct rtnl_route * rtnlroute)
dst = rtnl_route_get_dst(rtnlroute);
return nl_addr_get_prefixlen(dst);
}
#endif
#if HAVE_LIBNL == 1
int
nl_compat_error (int err)
{
err = abs (err);
if (err == EEXIST)
err = NLE_EXIST;
else if (err == ENOENT || err == ESRCH)
err = NLE_OBJ_NOTFOUND;
else if (err == ERANGE)
err = NLE_RANGE;
return -err;
}
int
rtnl_link_vlan_get_id (struct rtnl_link *l)
{
int fd;
struct vlan_ioctl_args if_request;
char *if_name = NULL;
memset (&if_request, 0, sizeof (struct vlan_ioctl_args));
if ((if_name = rtnl_link_get_name (l)) == NULL)
return -1;
g_strlcpy (if_request.device1, if_name, sizeof (if_request.device1));
if ((fd = socket (AF_INET, SOCK_STREAM, 0)) < 0) {
nm_log_err (LOGD_DEVICE, "couldn't open control socket.");
return -1;
}
if_request.cmd = GET_VLAN_VID_CMD;
if (ioctl (fd, SIOCSIFVLAN, &if_request) < 0) {
nm_log_err (LOGD_DEVICE, "couldn't get vlan id for %s.", if_name);
goto err_out;
}
close(fd);
return if_request.u.VID;
err_out:
close(fd);
return -1;
}
int
rtnl_link_vlan_set_flags (struct rtnl_link *l, unsigned int flags)
{
int fd;
struct vlan_ioctl_args if_request;
char *if_name = NULL;
if ((if_name = rtnl_link_get_name (l)) == NULL)
return -1;
if ((fd = socket (AF_INET, SOCK_STREAM, 0)) < 0) {
nm_log_err (LOGD_DEVICE, "couldn't open control socket.");
return -1;
}
memset (&if_request, 0, sizeof (struct vlan_ioctl_args));
g_strlcpy (if_request.device1, if_name, sizeof (if_request.device1));
if_request.cmd = SET_VLAN_FLAG_CMD;
if_request.u.flag = flags;
if (ioctl (fd, SIOCSIFVLAN, &if_request) < 0) {
nm_log_err (LOGD_DEVICE, "couldn't set flag in device %s.", if_name);
goto err_out;
}
close(fd);
return 0;
err_out:
close(fd);
return -1;
}
int
rtnl_link_vlan_set_ingress_map (struct rtnl_link *l, int from, uint32_t to)
{
int fd;
struct vlan_ioctl_args if_request;
char *if_name = NULL;
if ((if_name = rtnl_link_get_name (l)) == NULL)
return -1;
if ((fd = socket (AF_INET, SOCK_STREAM, 0)) < 0) {
nm_log_err (LOGD_DEVICE, "couldn't open control socket.");
return -1;
}
memset (&if_request, 0, sizeof (struct vlan_ioctl_args));
g_strlcpy (if_request.device1, if_name, sizeof (if_request.device1));
if_request.cmd = SET_VLAN_INGRESS_PRIORITY_CMD;
if_request.u.skb_priority = from;
if_request.vlan_qos = to;
if (ioctl (fd, SIOCSIFVLAN, &if_request) < 0) {
nm_log_err (LOGD_DEVICE, "couldn't set ingress map on device %s.", if_name);
goto err_out;
}
close(fd);
return 0;
err_out:
close(fd);
return -1;
}
int
rtnl_link_vlan_set_egress_map (struct rtnl_link *l, int from, uint32_t to)
{
int fd;
struct vlan_ioctl_args if_request;
char *if_name = NULL;
if ((if_name = rtnl_link_get_name (l)) == NULL)
return -1;
if ((fd = socket (AF_INET, SOCK_STREAM, 0)) < 0) {
nm_log_err (LOGD_DEVICE, "couldn't open control socket.");
return -1;
}
memset (&if_request, 0, sizeof (struct vlan_ioctl_args));
g_strlcpy (if_request.device1, if_name, sizeof (if_request.device1));
if_request.cmd = SET_VLAN_EGRESS_PRIORITY_CMD;
if_request.u.skb_priority = from;
if_request.vlan_qos = to;
if (ioctl (fd, SIOCSIFVLAN, &if_request) < 0) {
nm_log_err (LOGD_DEVICE, "couldn't set egress map on device %s.", if_name);
goto err_out;
}
close(fd);
return 0;
err_out:
close(fd);
return -1;
}
#endif

View file

@ -30,7 +30,6 @@
#include <netlink/route/route.h>
#include <netlink/route/addr.h>
#include <netlink/netlink.h>
#include <netlink/cache.h>
#include <netlink/utils.h>
@ -42,240 +41,12 @@
#include <config.h>
/* libnl-1 API compatibility for libnl-2/3*/
#if HAVE_LIBNL != 1
/* libnl-1 API compatibility for libnl-3 */
struct rtnl_nexthop * nm_netlink_get_nh(struct rtnl_route *);
int rtnl_route_get_oif(struct rtnl_route *);
int rtnl_route_set_oif(struct rtnl_route *, int);
int rtnl_route_set_gateway(struct rtnl_route *, struct nl_addr *);
int rtnl_route_get_dst_len(struct rtnl_route *);
struct nl_addr * rtnl_route_get_gateway(struct rtnl_route *);
#endif
/* libnl-2 API compatibility for libnl-3 */
#if HAVE_LIBNL == 3
static inline int
__rtnl_link_alloc_cache (struct nl_sock *h, struct nl_cache **cache)
{
return rtnl_link_alloc_cache (h, AF_UNSPEC, cache);
}
#define rtnl_link_alloc_cache __rtnl_link_alloc_cache
#endif
/* libnl-2.0 compat functions */
#if HAVE_LIBNL == 2
/* functions with similar prototypes */
#define nlmsg_datalen nlmsg_len
#endif
/* libnl-1.0 compat functions */
#if HAVE_LIBNL == 1
#define nl_sock nl_handle
/* libnl-1.0 functions with similar prototypes */
#define nl_socket_alloc nl_handle_alloc
#define nl_socket_alloc_cb nl_handle_alloc_cb
#define nl_socket_free nl_handle_destroy
#define nl_socket_set_passcred nl_set_passcred
#define nl_socket_disable_seq_check nl_disable_sequence_check
#define rtnl_route_set_priority rtnl_route_set_prio
#define nlmsg_datalen nlmsg_len
/* auxiliary functions */
int nl_compat_error (int);
/* libnl-1.0 functions with modified prototypes in libnl-2/3*/
static inline const char *
__nl_geterror (int err)
{
/* err is set, can be parsed */
return nl_geterror ();
}
#define nl_geterror __nl_geterror
static inline int
__rtnl_addr_alloc_cache (struct nl_sock *h, struct nl_cache **cache)
{
g_return_val_if_fail (cache != NULL, -EINVAL);
*cache = rtnl_addr_alloc_cache (h);
return *cache ? 0 : -ENOMEM;
}
#define rtnl_addr_alloc_cache __rtnl_addr_alloc_cache
static inline int
__rtnl_route_alloc_cache (struct nl_sock *h, int family, int flags, struct nl_cache **cache)
{
g_return_val_if_fail (cache != NULL, -EINVAL);
*cache = rtnl_route_alloc_cache (h);
return *cache ? 0 : -ENOMEM;
}
#define rtnl_route_alloc_cache __rtnl_route_alloc_cache
static inline int
__rtnl_link_alloc_cache (struct nl_sock *h, struct nl_cache **cache)
{
g_return_val_if_fail (cache != NULL, -EINVAL);
*cache = rtnl_link_alloc_cache (h);
return *cache ? 0 : -ENOMEM;
}
#define rtnl_link_alloc_cache __rtnl_link_alloc_cache
static inline int
__rtnl_route_get_metric (struct rtnl_route *route, int metric, unsigned int *value)
{
g_return_val_if_fail (value != NULL, -EINVAL);
*value = rtnl_route_get_metric (route, metric);
return 0;
}
#define rtnl_route_get_metric __rtnl_route_get_metric
static inline int
__rtnl_addr_add (struct nl_sock *h, struct rtnl_addr *addr, int flags)
{
return nl_compat_error (rtnl_addr_add (h, addr, flags));
}
#define rtnl_addr_add __rtnl_addr_add
static inline int
__rtnl_route_add (struct nl_sock *sk, struct rtnl_route *route, int flags)
{
return nl_compat_error (rtnl_route_add (sk, route, flags));
}
#define rtnl_route_add __rtnl_route_add
static inline int
rtnl_route_delete (struct nl_sock *h, struct rtnl_route *route, int flags)
{
return nl_compat_error (rtnl_route_del (h, route, flags));
}
#define rtnl_route_del rtnl_route_delete
static inline int
__rtnl_link_change (struct nl_sock *h, struct rtnl_link *old, struct rtnl_link *tmpl, int flags)
{
return nl_compat_error (rtnl_link_change (h, old, tmpl,flags));
}
#define rtnl_link_change __rtnl_link_change
static inline int
__nl_cache_include (struct nl_cache *cache, struct nl_object *obj, change_func_t cb, void *data)
{
return nl_cache_include (cache, obj, cb);
}
#define nl_cache_include __nl_cache_include
#define NLE_SUCCESS 0
#define NLE_FAILURE 1
#define NLE_INTR 2
#define NLE_BAD_SOCK 3
#define NLE_AGAIN 4
#define NLE_NOMEM 5
#define NLE_EXIST 6
#define NLE_INVAL 7
#define NLE_RANGE 8
#define NLE_MSGSIZE 9
#define NLE_OPNOTSUPP 10
#define NLE_AF_NOSUPPORT 11
#define NLE_OBJ_NOTFOUND 12
#define NLE_NOATTR 13
#define NLE_MISSING_ATTR 14
#define NLE_AF_MISMATCH 15
#define NLE_SEQ_MISMATCH 16
#define NLE_MSG_OVERFLOW 17
#define NLE_MSG_TRUNC 18
#define NLE_NOADDR 19
#define NLE_SRCRT_NOSUPPORT 20
#define NLE_MSG_TOOSHORT 21
#define NLE_MSGTYPE_NOSUPPORT 22
#define NLE_OBJ_MISMATCH 23
#define NLE_NOCACHE 24
#define NLE_BUSY 25
#define NLE_PROTO_MISMATCH 26
#define NLE_NOACCESS 27
#define NLE_PERM 28
#define NLE_PKTLOC_FILE 29
#endif
/* Stuff that only libnl3 has */
#if HAVE_LIBNL == 1 || HAVE_LIBNL == 2
static inline int
rtnl_link_bond_add (struct nl_sock *h, const char *name, void *data)
{
/* Bonding only in libnl3 */
return -NLE_OPNOTSUPP;
}
static inline int
rtnl_link_get_kernel (struct nl_sock *h, int f, const char *name, struct rtnl_link **out_link)
{
/* Bonding only in libnl3 */
return -NLE_OPNOTSUPP;
}
static inline char *
rtnl_link_get_type (struct rtnl_link *rtnl_link)
{
/* Bonding only in libnl3 */
return NULL;
}
static inline int
rtnl_link_bond_enslave_ifindex (struct nl_sock *h, int master_ifidx, int slave_ifidx)
{
/* Bonding only in libnl3 */
return -NLE_OPNOTSUPP;
}
static inline int
rtnl_link_bond_release_ifindex (struct nl_sock *h, int slave_ifidx)
{
/* Bonding only in libnl3 */
return -NLE_OPNOTSUPP;
}
static inline int
rtnl_link_vlan_set_id (struct rtnl_link *l, int id)
{
/* VLAN only in libnl3 */
return -NLE_OPNOTSUPP;
}
int rtnl_link_vlan_get_id (struct rtnl_link *l);
int rtnl_link_vlan_set_flags (struct rtnl_link *l, unsigned int flags);
int rtnl_link_vlan_set_ingress_map (struct rtnl_link *l, int from, uint32_t to);
int rtnl_link_vlan_set_egress_map (struct rtnl_link *l, int from, uint32_t to);
static inline int
rtnl_link_set_type (struct rtnl_link *l, const char *type)
{
/* Operation only in libnl3 */
return -NLE_OPNOTSUPP;
}
static inline int
rtnl_link_add (struct nl_sock *sk, struct rtnl_link *l, int flags)
{
/* Operation only in libnl3 */
return -NLE_OPNOTSUPP;
}
static inline int
rtnl_link_delete(struct nl_sock *sk, const struct rtnl_link *l)
{
/* Operation only in libnl3 */
return -NLE_OPNOTSUPP;
}
#endif
#endif /* NM_NETLINK_COMPAT_H */

View file

@ -408,7 +408,7 @@ sync_connection_setup (NMNetlinkMonitor *self, GError **error)
nl_cache_free (addr_cache);
#endif
err = rtnl_link_alloc_cache (priv->nlh_sync, &priv->link_cache);
err = rtnl_link_alloc_cache (priv->nlh_sync, AF_UNSPEC, &priv->link_cache);
if (err < 0) {
g_set_error (error, NM_NETLINK_MONITOR_ERROR,
NM_NETLINK_MONITOR_ERROR_NETLINK_ALLOC_LINK_CACHE,

View file

@ -60,11 +60,8 @@
#include <netlink/netlink.h>
#include <netlink/utils.h>
#include <netlink/route/link.h>
#if HAVE_LIBNL == 3
#include <netlink/route/link/bonding.h>
#include <netlink/route/link/vlan.h>
#endif
#if !HAVE_VLAN_FLAG_LOOSE_BINDING
/* Older kernels don't have this flag */
@ -1927,7 +1924,7 @@ nm_system_get_iface_vlan_info (int ifindex,
if (!nlh)
return FALSE;
ret = rtnl_link_alloc_cache (nlh, &cache);
ret = rtnl_link_alloc_cache (nlh, AF_UNSPEC, &cache);
g_return_val_if_fail (ret == 0, FALSE);
g_return_val_if_fail (cache != NULL, FALSE);
@ -2304,7 +2301,7 @@ nm_system_del_vlan_iface (const char *iface)
nlh = nm_netlink_get_default_handle ();
g_return_val_if_fail (nlh != NULL, FALSE);
ret = rtnl_link_alloc_cache (nlh, &cache);
ret = rtnl_link_alloc_cache (nlh, AF_UNSPEC, &cache);
g_return_val_if_fail (ret == 0, FALSE);
g_return_val_if_fail (cache != NULL, FALSE);

View file

@ -33,6 +33,7 @@
#include <netlink/genl/genl.h>
#include <netlink/genl/family.h>
#include <netlink/genl/ctrl.h>
#include <netlink/route/link.h>
#include <linux/nl80211.h>
@ -40,7 +41,6 @@
#include "wifi-utils-nl80211.h"
#include "nm-logging.h"
#include "nm-utils.h"
#include "nm-netlink-compat.h"
typedef struct {
WifiData parent;
@ -813,7 +813,7 @@ iface_to_index (struct nl_sock *nl_sock, const char *iface)
int err, ifindex;
/* name to index */
err = rtnl_link_alloc_cache (nl_sock, &link_cache);
err = rtnl_link_alloc_cache (nl_sock, AF_UNSPEC, &link_cache);
if (err < 0) {
nm_log_warn (LOGD_HW, "failed to allocate link cache: (%d) %s",
err, nl_geterror (err));