[PATCH 5/6] wext: Use one global netlink socket instead of one per interface.

Jouni Malinen j
Sat Dec 4 13:12:02 PST 2010


On Fri, Dec 03, 2010 at 04:55:04PM -0800, Ben Greear wrote:
> This saves a lot of work for the kernel and for wpa_supplicant
> since each netlink message no longer has to be dupplicated for
> each interface.

Is there any good reason for improving WEXT rather than nl80211? I would
welcome this type of change for nl80211 much rather than here..
driver_wext.c is a bit problematic for this since it is used by number
of other driver wrappers and that may make the proper implementation
difficult. driver_nl80211.c would not have such issue.


> +/* One netlink instance per program, not per vif.
> + */
> +static struct netlink_data *netlink = NULL;
> +static int netlink_refcnt = 0;
> +static struct wpa_driver_wext_data* all_driver_data = NULL;

These should be stored in global data structure that is initialized in
global_init() handler (and that is the part that may be difficult to add
for driver_wext.c without breaking other driver wrappers). Sett
driver_nl80211.c for an example on how to maintain the global structure
and interface list (struct nl80211_global and use of global_init() and
init2()).


> @@ -794,16 +817,20 @@ void * wpa_driver_wext_init(void *ctx, const char *ifname)
> +	if (netlink_refcnt == 0) {
> +		struct netlink_config *cfg;
> +		cfg = os_zalloc(sizeof(*cfg));
> +		if (cfg == NULL)
> +			goto err1;
> +		cfg->ctx = NULL;
> +		cfg->newlink_cb = wpa_driver_wext_event_rtm_newlink;
> +		cfg->dellink_cb = wpa_driver_wext_event_rtm_dellink;
> +		netlink = netlink_init(cfg);
> +		if (netlink == NULL) {
> +			os_free(cfg);
> +			goto err2;
> +		}
> +		netlink_refcnt++;
>  	}

This type of refcounting and single instance stuff is exactly what the
global_init() was added for, so we should not extend init() for this.

> @@ -933,8 +967,12 @@ void wpa_driver_wext_deinit(void *priv)
>  	 */
>  	wpa_driver_wext_disconnect(drv);
>  
> -	netlink_send_oper_ifla(drv->netlink, drv->ifindex, 0, IF_OPER_UP);
> -	netlink_deinit(drv->netlink);
> +	netlink_send_oper_ifla(netlink, drv->ifindex, 0, IF_OPER_UP);
> +	if (--netlink_refcnt <= 0) {
> +		netlink_deinit(netlink);
> +		netlink = NULL;
> +		netlink_refcnt = 0;
> +	}

And obviously the same comment for deinit vs. global_deinit.

-- 
Jouni Malinen                                            PGP id EFC895FA



More information about the Hostap mailing list