nl80211: use genl_ctrl_resolve()

Based on a patch for iw by Johannes Berg <johannes.berg@intel.com>

This simplifies the code quite a bit since we don't need
an nl_cache or nl_family anymore.

genl_ctrl_resolve() is available in libnl1.1, libnl2 and libnl3.

Cc: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Thomas Graf <tgraf@redhat.com>
This commit is contained in:
Thomas Graf
2011-11-10 17:34:59 +01:00
committed by Dan Williams
parent a2b1afb1e4
commit 9b05037c44
2 changed files with 4 additions and 25 deletions

View File

@@ -173,18 +173,6 @@ __nl_cache_include (struct nl_cache *cache, struct nl_object *obj, change_func_t
}
#define nl_cache_include __nl_cache_include
#include <netlink/genl/ctrl.h>
static inline int __genl_ctrl_alloc_cache(struct nl_sock *h, struct nl_cache **cache)
{
struct nl_cache *tmp = genl_ctrl_alloc_cache(h);
if (!tmp)
return -ENOMEM;
*cache = tmp;
return 0;
}
#define genl_ctrl_alloc_cache __genl_ctrl_alloc_cache
#define NLE_SUCCESS 0
#define NLE_FAILURE 1
#define NLE_INTR 2

View File

@@ -45,8 +45,7 @@
typedef struct {
WifiData parent;
struct nl_sock *nl_sock;
struct nl_cache *nl_cache;
struct genl_family *nl_family;
int id;
struct nl_cb *nl_cb;
guint32 *freqs;
int num_freqs;
@@ -81,8 +80,7 @@ static struct nl_msg *nl80211_alloc_msg (WifiDataNl80211 *nl80211,
if (!msg)
return NULL;
genlmsg_put (msg, 0, 0, genl_family_get_id (nl80211->nl_family), 0,
flags, cmd, 0);
genlmsg_put (msg, 0, 0, nl80211->id, 0, flags, cmd, 0);
NLA_PUT_U32 (msg, NL80211_ATTR_IFINDEX, nl80211->parent.ifindex);
@@ -137,10 +135,6 @@ wifi_nl80211_deinit (WifiData *parent)
{
WifiDataNl80211 *nl80211 = (WifiDataNl80211 *) parent;
if (nl80211->nl_family)
genl_family_put (nl80211->nl_family);
if (nl80211->nl_cache)
nl_cache_free (nl80211->nl_cache);
if (nl80211->nl_sock)
nl_socket_free (nl80211->nl_sock);
if (nl80211->nl_cb)
@@ -672,11 +666,8 @@ wifi_nl80211_init (const char *iface, int ifindex)
if (genl_connect (nl80211->nl_sock))
goto error;
if (genl_ctrl_alloc_cache (nl80211->nl_sock, &nl80211->nl_cache))
goto error;
nl80211->nl_family = genl_ctrl_search_by_name (nl80211->nl_cache, "nl80211");
if (nl80211->nl_family == NULL)
nl80211->id = genl_ctrl_resolve (nl80211->nl_sock, "nl80211");
if (nl80211->id < 0)
goto error;
nl80211->nl_cb = nl_cb_alloc (NL_CB_DEFAULT);