summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2012-01-09 19:04:34 -0600
committerDan Williams <dcbw@redhat.com>2012-01-09 19:25:53 -0600
commit7d4f62b4c5a3866980a32cbe2da9e6088800a8a8 (patch)
treed5e213a1ac19bd5e5db8e9bbbe871bbbbd99c77d
parentfe5c5c2a01ed6e751759776230a266d2bcb5cfda (diff)
lib: fix for libnl3
-rw-r--r--lib/Makefile.am2
-rw-r--r--lib/genl.c13
-rw-r--r--lib/internal.h8
-rw-r--r--lib/libnl-compat.h114
-rw-r--r--lib/op-msg.c6
-rw-r--r--lib/op-open.c33
-rw-r--r--lib/op-reset.c2
-rw-r--r--lib/op-rfkill.c2
-rw-r--r--lib/op-state-get.c2
-rw-r--r--lib/wimax.c4
10 files changed, 150 insertions, 36 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index ca6f2f0..a20ae61 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -7,7 +7,7 @@ INCLUDES = \
$(LIBNL_CFLAGS) \
-I $(LINUX_INCLUDE_PATH)
-noinst_HEADERS = debug.h internal.h
+noinst_HEADERS = debug.h internal.h libnl-compat.h
libwimaxll_sources = \
genl.c \
diff --git a/lib/genl.c b/lib/genl.c
index 71975c0..b5a951c 100644
--- a/lib/genl.c
+++ b/lib/genl.c
@@ -45,6 +45,7 @@
#include <netlink/msg.h>
#include <netlink/attr.h>
#include "internal.h"
+#include "libnl-compat.h"
struct handler_arg {
void (*cb)(void *, const char *, int);
@@ -115,7 +116,7 @@ static int family_handler(struct nl_msg *msg, void *_arg)
* Enumerates the multicast groups available for a generic netlink
* family and calls the callback with the arguments of each.
*/
-int nl_get_multicast_groups(struct nl_handle *handle,
+int nl_get_multicast_groups(struct nl_sock *handle,
const char *family,
void (*cbf)(void *, const char *, int),
void *priv)
@@ -168,15 +169,15 @@ int nl_get_multicast_groups(struct nl_handle *handle,
}
-int genl_ctrl_get_version(struct nl_handle *nlh, const char *name)
+int genl_ctrl_get_version(struct nl_sock *nlh, const char *name)
{
int result = -ENOENT;
struct genl_family *fam;
- struct nl_cache *cache;
+ struct nl_cache *cache = NULL;
- cache = genl_ctrl_alloc_cache(nlh);
- if (cache == NULL)
- return nl_get_errno();
+ result = genl_ctrl_alloc_cache(nlh, &cache);
+ if (result != 0)
+ return result;
fam = genl_ctrl_search_by_name(cache, name);
if (fam) {
diff --git a/lib/internal.h b/lib/internal.h
index 178ac1e..81d15e0 100644
--- a/lib/internal.h
+++ b/lib/internal.h
@@ -96,8 +96,8 @@ struct wimaxll_handle {
char name[__WIMAXLL_IFNAME_LEN];
void *priv;
- struct nl_handle *nlh_tx;
- struct nl_handle *nlh_rx;
+ struct nl_sock *nlh_tx;
+ struct nl_sock *nlh_rx;
wimaxll_msg_to_user_cb_f msg_to_user_cb;
void *msg_to_user_priv;
@@ -131,9 +131,9 @@ void wimaxll_msg(struct wimaxll_handle *, const char *fmt, ...)
/* Generic Netlink utilities */
-int nl_get_multicast_groups(struct nl_handle *, const char *,
+int nl_get_multicast_groups(struct nl_sock *, const char *,
void (*cb)(void *, const char *, int),
void *);
-int genl_ctrl_get_version(struct nl_handle *, const char *);
+int genl_ctrl_get_version(struct nl_sock *, const char *);
#endif /* #ifndef __lib_internal_h__ */
diff --git a/lib/libnl-compat.h b/lib/libnl-compat.h
new file mode 100644
index 0000000..6c4ba1a
--- /dev/null
+++ b/lib/libnl-compat.h
@@ -0,0 +1,114 @@
+/*
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright (C) 2011 Caixa Magica Software.
+ * Copyright (C) 2011 Red Hat, Inc.
+ *
+ */
+#ifndef __lib_libnl_compat_h__
+#define __lib_libnl_compat_h__
+
+#include <config.h>
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+#include <netlink/utils.h>
+#include <netlink/data.h>
+
+/* libnl-2.0 compat functions */
+#ifdef HAVE_LIBNL2
+
+/* functions with similar prototypes */
+#define nlmsg_datalen nlmsg_len
+#endif /* HAVE_LIBNL2 */
+
+
+/* libnl-1.0 compat functions */
+#ifdef HAVE_LIBNL1
+
+#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 nlmsg_datalen nlmsg_len
+#define nlmsg_alloc nlmsg_new
+
+/* 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
+__genl_ctrl_alloc_cache(struct nl_sock *sk, struct nl_cache **cache)
+{
+ *cache = genl_ctrl_alloc_cache(sk);
+ return *cache ? 0 : NLE_FAILURE;
+}
+#define genl_ctrl_alloc_cache __genl_ctrl_alloc_cache
+
+#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 /* HAVE_LIBNL1 */
+
+#endif /* lib_libnl_compat_h */
diff --git a/lib/op-msg.c b/lib/op-msg.c
index e9c5091..22971c8 100644
--- a/lib/op-msg.c
+++ b/lib/op-msg.c
@@ -414,9 +414,9 @@ ssize_t wimaxll_msg_write(struct wimaxll_handle *wmx,
result = -EBADF;
if (wmx->ifidx == 0)
goto error_not_any;
- nl_msg = nlmsg_new();
+ nl_msg = nlmsg_alloc();
if (nl_msg == NULL) {
- result = nl_get_errno();
+ result = -ENOMEM;
wimaxll_msg(wmx, "E: cannot allocate generic netlink "
"message: %m\n");
goto error_msg_alloc;
@@ -425,7 +425,7 @@ ssize_t wimaxll_msg_write(struct wimaxll_handle *wmx,
wimaxll_family_id(wmx), 0, 0,
WIMAX_GNL_OP_MSG_FROM_USER, WIMAX_GNL_VERSION);
if (msg == NULL) {
- result = nl_get_errno();
+ result = -ENOMEM;
wimaxll_msg(wmx, "E: %s: error preparing message: %zd\n",
__func__, result);
goto error_msg_prep;
diff --git a/lib/op-open.c b/lib/op-open.c
index 7b7f8c5..fdf0953 100644
--- a/lib/op-open.c
+++ b/lib/op-open.c
@@ -77,6 +77,7 @@
#include "internal.h"
#define D_LOCAL 0
#include "debug.h"
+#include "libnl-compat.h"
/*
@@ -372,7 +373,7 @@ struct wimaxll_handle *wimaxll_open(const char *device)
struct wimaxll_handle *wmx;
d_fnstart(3, NULL, "(device %s)\n", device);
- result = ENOMEM;
+ result = -ENOMEM;
wmx = malloc(sizeof(*wmx));
if (wmx == NULL) {
wimaxll_msg(NULL, "E: cannot allocate WiMax handle: %m\n");
@@ -403,11 +404,10 @@ struct wimaxll_handle *wimaxll_open(const char *device)
}
/* Setup the TX side */
- wmx->nlh_tx = nl_handle_alloc();
+ wmx->nlh_tx = nl_socket_alloc();
if (wmx->nlh_tx == NULL) {
- result = nl_get_errno();
- wimaxll_msg(wmx, "E: TX: cannot allocate handle: %d (%s)\n",
- result, nl_geterror());
+ result = -ENOMEM;
+ wimaxll_msg(wmx, "E: TX: cannot allocate handle\n");
goto error_nl_handle_alloc_tx;
}
nl_socket_enable_msg_peek(wmx->nlh_tx);
@@ -415,22 +415,21 @@ struct wimaxll_handle *wimaxll_open(const char *device)
result = nl_connect(wmx->nlh_tx, NETLINK_GENERIC);
if (result < 0) {
wimaxll_msg(wmx, "E: TX: cannot connect netlink: %d (%s)\n",
- result, nl_geterror());
+ result, nl_geterror(result));
goto error_nl_connect_tx;
}
/* Set up the RX side */
- wmx->nlh_rx = nl_handle_alloc();
+ wmx->nlh_rx = nl_socket_alloc();
if (wmx->nlh_rx == NULL) {
- result = nl_get_errno();
- wimaxll_msg(wmx, "E: RX: cannot allocate handle: %d (%s)\n",
- result, nl_geterror());
+ result = -ENOMEM;
+ wimaxll_msg(wmx, "E: RX: cannot allocate handle\n");
goto error_nl_handle_alloc_rx;
}
result = nl_connect(wmx->nlh_rx, NETLINK_GENERIC);
if (result < 0) {
wimaxll_msg(wmx, "E: RX: cannot connect netlink: %d (%s)\n",
- result, nl_geterror());
+ result, nl_geterror(result));
goto error_nl_connect_rx;
}
nl_socket_enable_msg_peek(wmx->nlh_rx);
@@ -442,7 +441,7 @@ struct wimaxll_handle *wimaxll_open(const char *device)
result = nl_socket_add_membership(wmx->nlh_rx, wmx->mcg_id);
if (result < 0) {
wimaxll_msg(wmx, "E: RX: cannot join multicast group %u: %d (%s)\n",
- wmx->mcg_id, result, nl_geterror());
+ wmx->mcg_id, result, nl_geterror(result));
goto error_nl_add_membership;
}
/* Now we check if the device is a WiMAX supported device, by
@@ -465,16 +464,16 @@ error_nl_add_membership:
error_gnl_resolve:
nl_close(wmx->nlh_rx);
error_nl_connect_rx:
- nl_handle_destroy(wmx->nlh_rx);
+ nl_socket_free(wmx->nlh_rx);
error_nl_handle_alloc_rx:
nl_close(wmx->nlh_tx);
error_nl_connect_tx:
- nl_handle_destroy(wmx->nlh_tx);
+ nl_socket_free(wmx->nlh_tx);
error_nl_handle_alloc_tx:
error_no_dev:
wimaxll_free(wmx);
error_gnl_handle_alloc:
- errno = -result;
+ errno = result;
d_fnend(3, NULL, "(device %s) = NULL\n", device);
return NULL;
}
@@ -493,9 +492,9 @@ void wimaxll_close(struct wimaxll_handle *wmx)
{
d_fnstart(3, NULL, "(wmx %p)\n", wmx);
nl_close(wmx->nlh_rx);
- nl_handle_destroy(wmx->nlh_rx);
+ nl_socket_free(wmx->nlh_rx);
nl_close(wmx->nlh_tx);
- nl_handle_destroy(wmx->nlh_tx);
+ nl_socket_free(wmx->nlh_tx);
wimaxll_free(wmx);
d_fnend(3, NULL, "(wmx %p) = void\n", wmx);
}
diff --git a/lib/op-reset.c b/lib/op-reset.c
index 4ec9619..05b9b22 100644
--- a/lib/op-reset.c
+++ b/lib/op-reset.c
@@ -93,7 +93,7 @@ int wimaxll_reset(struct wimaxll_handle *wmx)
if (wmx->ifidx == 0)
goto error_not_any;
- msg = nlmsg_new();
+ msg = nlmsg_alloc();
if (msg == NULL) {
result = errno;
wimaxll_msg(wmx, "E: RESET: cannot allocate generic netlink "
diff --git a/lib/op-rfkill.c b/lib/op-rfkill.c
index 5f4cbe0..8a57001 100644
--- a/lib/op-rfkill.c
+++ b/lib/op-rfkill.c
@@ -98,7 +98,7 @@ int wimaxll_rfkill(struct wimaxll_handle *wmx, enum wimax_rf_state state)
result = -EBADF;
if (wmx->ifidx == 0)
goto error_not_any;
- msg = nlmsg_new();
+ msg = nlmsg_alloc();
if (msg == NULL) {
result = errno;
wimaxll_msg(wmx, "E: RFKILL: cannot allocate generic netlink "
diff --git a/lib/op-state-get.c b/lib/op-state-get.c
index 8090bf2..cfe9be0 100644
--- a/lib/op-state-get.c
+++ b/lib/op-state-get.c
@@ -76,7 +76,7 @@ int wimaxll_state_get(struct wimaxll_handle *wmx)
result = -EBADF;
if (wmx->ifidx == 0)
goto error_not_any;
- msg = nlmsg_new();
+ msg = nlmsg_alloc();
if (msg == NULL) {
result = errno;
wimaxll_msg(wmx, "E: STATE_GET: cannot allocate generic"
diff --git a/lib/wimax.c b/lib/wimax.c
index f82e731..af8c0cb 100644
--- a/lib/wimax.c
+++ b/lib/wimax.c
@@ -107,12 +107,12 @@ int wimaxll_gnl_ack_cb(struct nl_msg *msg, void *_ctx)
int result;
struct nlmsghdr *nl_hdr;
struct nlmsgerr *nl_err;
- size_t size = nlmsg_len(nlmsg_hdr(msg));
+ size_t size = nlmsg_datalen(nlmsg_hdr(msg));
struct wimaxll_cb_ctx *ctx = _ctx;
d_fnstart(7, NULL, "(msg %p ctx %p)\n", msg, _ctx);
nl_hdr = nlmsg_hdr(msg);
- size = nlmsg_len(nl_hdr);
+ size = nlmsg_datalen(nl_hdr);
nl_err = nlmsg_data(nl_hdr);
if (size < sizeof(*nl_err)) {