[PATCH] Revert "nl80211: Use global netlink rtm event object"

Johannes Berg johannes
Fri Oct 28 08:37:11 PDT 2011


From: Johannes Berg <johannes.berg at intel.com>

This reverts commit 36d84860bbe09641f782fcc21b09e5a6952b4629.

This commit completely broke P2P operation.

---
I'm very unhappy now as I just spent a long time tracking this down.

TEST YOUR PATCHES!


diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index d962ac9..239f4b4 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -167,7 +167,6 @@ static void nl_destroy_handles(struct nl80211_handles *handles)
 struct nl80211_global {
 	struct dl_list interfaces;
 	int if_add_ifindex;
-	struct netlink_data *netlink;
 	struct nl_cb *nl_cb;
 	struct nl80211_handles nl;
 	struct genl_family *nl80211;
@@ -194,6 +193,7 @@ struct wpa_driver_nl80211_data {
 	u8 addr[ETH_ALEN];
 	char phyname[32];
 	void *ctx;
+	struct netlink_data *netlink;
 	int ifindex;
 	int if_removed;
 	int if_disabled;
@@ -561,32 +561,17 @@ static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv,
 }
 
 
-static struct wpa_driver_nl80211_data *
-nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len)
-{
-	struct wpa_driver_nl80211_data *drv;
-	dl_list_for_each(drv, &global->interfaces,
-			 struct wpa_driver_nl80211_data, list) {
-		if (wpa_driver_nl80211_own_ifindex(drv, idx, buf, len) ||
-		    have_ifidx(drv, idx))
-			return drv;
-	}
-	return NULL;
-}
-
-
 static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
 						 struct ifinfomsg *ifi,
 						 u8 *buf, size_t len)
 {
-	struct nl80211_global *global = ctx;
-	struct wpa_driver_nl80211_data *drv;
+	struct wpa_driver_nl80211_data *drv = ctx;
 	int attrlen, rta_len;
 	struct rtattr *attr;
 	u32 brid = 0;
 
-	drv = nl80211_find_drv(global, ifi->ifi_index, buf, len);
-	if (!drv) {
+	if (!wpa_driver_nl80211_own_ifindex(drv, ifi->ifi_index, buf, len) &&
+	    !have_ifidx(drv, ifi->ifi_index)) {
 		wpa_printf(MSG_DEBUG, "nl80211: Ignore event for foreign "
 			   "ifindex %d", ifi->ifi_index);
 		return;
@@ -628,7 +613,7 @@ static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
 	if (drv->operstate == 1 &&
 	    (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP &&
 	    !(ifi->ifi_flags & IFF_RUNNING))
-		netlink_send_oper_ifla(drv->global->netlink, drv->ifindex,
+		netlink_send_oper_ifla(drv->netlink, drv->ifindex,
 				       -1, IF_OPER_UP);
 
 	attrlen = len;
@@ -660,19 +645,11 @@ static void wpa_driver_nl80211_event_rtm_dellink(void *ctx,
 						 struct ifinfomsg *ifi,
 						 u8 *buf, size_t len)
 {
-	struct nl80211_global *global = ctx;
-	struct wpa_driver_nl80211_data *drv;
+	struct wpa_driver_nl80211_data *drv = ctx;
 	int attrlen, rta_len;
 	struct rtattr *attr;
 	u32 brid = 0;
 
-	drv = nl80211_find_drv(global, ifi->ifi_index, buf, len);
-	if (!drv) {
-		wpa_printf(MSG_DEBUG, "nl80211: Ignore dellink event for "
-			   "foreign ifindex %d", ifi->ifi_index);
-		return;
-	}
-
 	attrlen = len;
 	attr = (struct rtattr *) buf;
 
@@ -2185,6 +2162,7 @@ static void * wpa_driver_nl80211_init(void *ctx, const char *ifname,
 				      void *global_priv)
 {
 	struct wpa_driver_nl80211_data *drv;
+	struct netlink_config *cfg;
 	struct rfkill_config *rcfg;
 	struct i802_bss *bss;
 
@@ -2207,6 +2185,18 @@ static void * wpa_driver_nl80211_init(void *ctx, const char *ifname,
 
 	nl80211_get_phy_name(drv);
 
+	cfg = os_zalloc(sizeof(*cfg));
+	if (cfg == NULL)
+		goto failed;
+	cfg->ctx = drv;
+	cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink;
+	cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink;
+	drv->netlink = netlink_init(cfg);
+	if (drv->netlink == NULL) {
+		os_free(cfg);
+		goto failed;
+	}
+
 	rcfg = os_zalloc(sizeof(*rcfg));
 	if (rcfg == NULL)
 		goto failed;
@@ -2384,7 +2374,7 @@ wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv)
 		}
 	}
 
-	netlink_send_oper_ifla(drv->global->netlink, drv->ifindex,
+	netlink_send_oper_ifla(drv->netlink, drv->ifindex,
 			       1, IF_OPER_DORMANT);
 #endif /* HOSTAPD */
 
@@ -2490,8 +2480,8 @@ static void wpa_driver_nl80211_deinit(void *priv)
 	if (drv->disable_11b_rates)
 		nl80211_disable_11b_rates(drv, drv->ifindex, 0);
 
-	netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0,
-			       IF_OPER_UP);
+	netlink_send_oper_ifla(drv->netlink, drv->ifindex, 0, IF_OPER_UP);
+	netlink_deinit(drv->netlink);
 	rfkill_deinit(drv->rfkill);
 
 	eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx);
@@ -5787,7 +5777,7 @@ static int wpa_driver_nl80211_set_operstate(void *priv, int state)
 	wpa_printf(MSG_DEBUG, "%s: operstate %d->%d (%s)",
 		   __func__, drv->operstate, state, state ? "UP" : "DORMANT");
 	drv->operstate = state;
-	return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1,
+	return netlink_send_oper_ifla(drv->netlink, drv->ifindex, -1,
 				      state ? IF_OPER_UP : IF_OPER_DORMANT);
 }
 
@@ -7167,8 +7157,6 @@ static int nl80211_set_param(void *priv, const char *param)
 static void * nl80211_global_init(void)
 {
 	struct nl80211_global *global;
-	struct netlink_config *cfg;
-
 	global = os_zalloc(sizeof(*global));
 	if (global == NULL)
 		return NULL;
@@ -7176,19 +7164,6 @@ static void * nl80211_global_init(void)
 	dl_list_init(&global->interfaces);
 	global->if_add_ifindex = -1;
 
-	cfg = os_zalloc(sizeof(*cfg));
-	if (cfg == NULL)
-		goto err;
-
-	cfg->ctx = global;
-	cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink;
-	cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink;
-	global->netlink = netlink_init(cfg);
-	if (global->netlink == NULL) {
-		os_free(cfg);
-		goto err;
-	}
-
 	if (wpa_driver_nl80211_init_nl_global(global) < 0)
 		goto err;
 
@@ -7217,9 +7192,6 @@ static void nl80211_global_deinit(void *priv)
 			   dl_list_len(&global->interfaces));
 	}
 
-	if (global->netlink)
-		netlink_deinit(global->netlink);
-
 	if (global->nl80211)
 		genl_family_put(global->nl80211);
 	nl_destroy_handles(&global->nl);





More information about the Hostap mailing list