From: pat-lkml <pat-lkml@erley.org>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: linux-wireless <linux-wireless@vger.kernel.org>
Subject: Re: Userspace tools: Roadmap?
Date: Fri, 12 Dec 2008 18:48:55 -0500 [thread overview]
Message-ID: <4942F867.5020203@erley.org> (raw)
In-Reply-To: <1229121535.3565.4.camel@johannes.berg>
This converts iw to use libnl-2, and adds compatibility with libnl-1.
There is not currently a good way to detect the libnl version during
compilation, as the versioning in the netlink/version.h is defined as a
string "2.0" rather than a major and a minor number, so we must detect
it in the Makefile.
Signed-off-by: Pat Erley <pat-lkml@erley.org>
---
I'm still not very familiar with Makefile magic, so if there's a better
way to do what I'm doing in the Makefile, just let me know. Also, I'm
preparing a similar patch for crda. I'm not 100% certain on the
libnl-1.1 compatibility part as I can't get iw to build with libnl-1.1
on my system. However, with and without this patch error out in an
identical manner
---
diff --git a/Makefile b/Makefile
index df59b51..5b359f3 100644
--- a/Makefile
+++ b/Makefile
@@ -10,14 +10,28 @@ MKDIR ?= mkdir -p
INSTALL ?= install
CC ?= "gcc"
-CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs
-fno-strict-aliasing -fno-common -Werror-implicit-function-declaration
`pkg-config --cflags libnl-1`
+CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs
-fno-strict-aliasing -fno-common -Werror-implicit-function-declaration
CFLAGS += -O2 -g
-LDFLAGS += `pkg-config --libs libnl-1`
-NLVERSION = 1.0
OBJS = iw.o info.o phy.o interface.o station.o util.o mpath.o reg.o
mesh.o genl.o
ALL = iw
+NL1FOUND := $(shell pkg-config --atleast-version=1 libnl-1 && echo Y)
+NL2FOUND := $(shell pkg-config --atleast-version=2 libnl-2.0 && echo Y)
+
+ifeq ($(NL1FOUND),Y)
+NLLIBNAME = libnl-1
+endif
+
+ifeq ($(NL2FOUND),Y)
+CFLAGS += -DCONFIG_LIBNL20
+LIBS += -lnl-genl
+NLLIBNAME = libnl-2.0
+endif
+
+LDFLAGS += `pkg-config --libs $(NLLIBNAME)`
+CFLAGS += `pkg-config --cflags $(NLLIBNAME)`
+
ifeq ($(V),1)
Q=
NQ=true
@@ -29,8 +43,15 @@ endif
all: version_check $(ALL)
version_check:
- @if ! pkg-config --atleast-version=$(NLVERSION) libnl-1; then echo
"You need at least libnl version $(NLVERSION)"; exit 1; fi
-
+ifeq ($(NL2FOUND),Y)
+ @echo "Found libnl-2.0"
+else
+ifeq ($(NL1FOUND),Y)
+ @echo "Found libnl-1"
+else
+ $(error No libnl found)
+endif
+endif
version.h: version.sh
@$(NQ) ' GEN version.h'
@@ -42,7 +63,7 @@ version.h: version.sh
iw: $(OBJS)
@$(NQ) ' CC ' iw
- $(Q)$(CC) $(LDFLAGS) $(OBJS) -o iw
+ $(Q)$(CC) $(LDFLAGS) $(OBJS) $(LIBS) -o iw
check:
$(Q)$(MAKE) all CC="REAL_CC=$(CC) CHECK=\"sparse -Wall\" cgcc"
diff --git a/iw.c b/iw.c
index afae643..e9cc7f6 100644
--- a/iw.c
+++ b/iw.c
@@ -23,13 +23,24 @@
#include "iw.h"
#include "version.h"
+#ifndef CONFIG_LIBNL20
+/* libnl 2.0 compatibility code */
+
+#define nl_socket_alloc(_h) nl_handle_alloc(_h)
+#define nl_socket_free(_h) nl_handle_destroy(_h)
+#define compat_genl_ctrl_alloc_cache(_nl_handle, _nl_cache) \
+ (_nl_cache = genl_ctrl_alloc_cache(_nl_handle)) == NULL
+
+#define genl_ctrl_alloc_cache(_h,_i) compat_genl_ctrl_alloc_cache(_h,_i)
+#endif /* CONFIG_LIBNL20 */
+
static int debug = 0;
static int nl80211_init(struct nl80211_state *state)
{
int err;
- state->nl_handle = nl_handle_alloc();
+ state->nl_handle = nl_socket_alloc();
if (!state->nl_handle) {
fprintf(stderr, "Failed to allocate netlink handle.\n");
return -ENOMEM;
@@ -41,8 +52,7 @@ static int nl80211_init(struct nl80211_state *state)
goto out_handle_destroy;
}
- state->nl_cache = genl_ctrl_alloc_cache(state->nl_handle);
- if (!state->nl_cache) {
+ if (genl_ctrl_alloc_cache(state->nl_handle, &(state->nl_cache))) {
fprintf(stderr, "Failed to allocate generic netlink cache.\n");
err = -ENOMEM;
goto out_handle_destroy;
@@ -60,7 +70,7 @@ static int nl80211_init(struct nl80211_state *state)
out_cache_free:
nl_cache_free(state->nl_cache);
out_handle_destroy:
- nl_handle_destroy(state->nl_handle);
+ nl_socket_free(state->nl_handle);
return err;
}
@@ -68,7 +78,7 @@ static void nl80211_cleanup(struct nl80211_state *state)
{
genl_family_put(state->nl80211);
nl_cache_free(state->nl_cache);
- nl_handle_destroy(state->nl_handle);
+ nl_socket_free(state->nl_handle);
}
__COMMAND(NULL, NULL, NULL, 0, 0, 0, CIB_NONE, NULL);
next prev parent reply other threads:[~2008-12-12 23:48 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-07 23:29 Userspace tools: Roadmap? Dan E
2008-12-08 7:02 ` Rami Rosen
2008-12-08 8:13 ` Johannes Berg
2008-12-08 23:18 ` Dan E
2008-12-08 23:26 ` Johannes Berg
2008-12-08 23:52 ` pat-lkml
2008-12-09 0:02 ` Johannes Berg
2008-12-09 0:08 ` pat-lkml
2008-12-12 4:58 ` pat-lkml
2008-12-12 16:24 ` Pavel Roskin
2008-12-12 21:58 ` Johannes Berg
2008-12-12 22:37 ` pat-lkml
2008-12-12 22:38 ` Johannes Berg
2008-12-12 23:36 ` pat-lkml
2008-12-12 23:42 ` pat-lkml
2008-12-12 23:50 ` Johannes Berg
2008-12-12 23:48 ` pat-lkml [this message]
2008-12-13 0:05 ` Johannes Berg
2008-12-13 0:10 ` pat-lkml
2008-12-13 0:10 ` Johannes Berg
2008-12-09 0:43 ` Dan E
2008-12-09 0:51 ` Johannes Berg
2008-12-09 1:01 ` Dan E
2008-12-09 1:05 ` Johannes Berg
2009-01-15 7:52 ` David Shwatrz
2009-01-15 9:35 ` Johannes Berg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4942F867.5020203@erley.org \
--to=pat-lkml@erley.org \
--cc=johannes@sipsolutions.net \
--cc=linux-wireless@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).