From patchwork Sat Mar 9 22:14:22 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Schiffer X-Patchwork-Id: 2810 Return-Path: Received-SPF: None (no SPF record) identity=mailfrom; client-ip=5.9.180.86; helo=chaos.universe-factory.net; envelope-from=mschiffer@universe-factory.net; receiver=b.a.t.m.a.n@lists.open-mesh.org Received: from chaos.universe-factory.net (chaos.universe-factory.net [5.9.180.86]) by open-mesh.org (Postfix) with ESMTP id 312FC601C9C for ; Sat, 9 Mar 2013 23:14:26 +0100 (CET) Received: from avalon.meute.ffhl (i59F44E7F.versanet.de [89.244.78.127]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by chaos.universe-factory.net (Postfix) with ESMTPSA id 42D09184930 for ; Sat, 9 Mar 2013 23:14:26 +0100 (CET) From: Matthias Schiffer To: b.a.t.m.a.n@lists.open-mesh.org Date: Sat, 9 Mar 2013 23:14:22 +0100 Message-Id: X-Mailer: git-send-email 1.8.1.5 In-Reply-To: References: Subject: [B.A.T.M.A.N.] [PATCHv5 1/2] batman-adv: split batadv_is_wifi_iface() into two functions X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 Mar 2013 22:14:27 -0000 Previously batadv_is_wifi_iface() did two things at once: looking up a net_device from an interface index, and determining if it is a wifi device. The second part is useful itself when the caller already has a net_device reference. Signed-off-by: Matthias Schiffer --- hard-interface.c | 73 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/hard-interface.c b/hard-interface.c index fd99e42..333a504 100644 --- a/hard-interface.c +++ b/hard-interface.c @@ -117,6 +117,47 @@ static int batadv_is_valid_iface(const struct net_device *net_dev) return 1; } +/* This function returns true if the net device is a 802.11 wireless device */ +static bool batadv_is_wifi_net_device(struct net_device *net_device) +{ +#ifdef CONFIG_WIRELESS_EXT + /* pre-cfg80211 drivers have to implement WEXT, so it is possible to + * check for wireless_handlers != NULL + */ + if (net_device->wireless_handlers) + return true; +#endif + + /* cfg80211 drivers have to set ieee80211_ptr */ + if (net_device->ieee80211_ptr) + return true; + + return false; +} + +/* This function returns true if the interface represented by ifindex is a + * 802.11 wireless device + */ +bool batadv_is_wifi_iface(int ifindex) +{ + struct net_device *net_device = NULL; + bool ret = false; + + if (ifindex == BATADV_NULL_IFINDEX) + goto out; + + net_device = dev_get_by_index(&init_net, ifindex); + if (!net_device) + goto out; + + ret = batadv_is_wifi_net_device(net_device); + +out: + if (net_device) + dev_put(net_device); + return ret; +} + static struct batadv_hard_iface * batadv_hardif_get_active(const struct net_device *soft_iface) { @@ -631,38 +672,6 @@ out: return NOTIFY_DONE; } -/* This function returns true if the interface represented by ifindex is a - * 802.11 wireless device - */ -bool batadv_is_wifi_iface(int ifindex) -{ - struct net_device *net_device = NULL; - bool ret = false; - - if (ifindex == BATADV_NULL_IFINDEX) - goto out; - - net_device = dev_get_by_index(&init_net, ifindex); - if (!net_device) - goto out; - -#ifdef CONFIG_WIRELESS_EXT - /* pre-cfg80211 drivers have to implement WEXT, so it is possible to - * check for wireless_handlers != NULL - */ - if (net_device->wireless_handlers) - ret = true; - else -#endif - /* cfg80211 drivers have to set ieee80211_ptr */ - if (net_device->ieee80211_ptr) - ret = true; -out: - if (net_device) - dev_put(net_device); - return ret; -} - struct notifier_block batadv_hard_if_notifier = { .notifier_call = batadv_hard_if_event, };