diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-03-09 17:14:22 -0500 |
---|---|---|
committer | Antonio Quartulli <ordex@autistici.org> | 2013-05-28 20:44:53 -0400 |
commit | de68d1003d9eb0a5f7d4714315614e4bc956f68e (patch) | |
tree | 9019a95f51e7dce7837afb3910cb2e52362ee1f9 /net/batman-adv | |
parent | 06ecf24bdf2b7afc6c8fd13de6dba2a96dd331b6 (diff) |
batman-adv: split batadv_is_wifi_iface() into two functions
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 <mschiffer@universe-factory.net>
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Signed-off-by: Antonio Quartulli <ordex@autistici.org>
Diffstat (limited to 'net/batman-adv')
-rw-r--r-- | net/batman-adv/hard-interface.c | 84 |
1 files changed, 52 insertions, 32 deletions
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c index b6504eac0ed8..d5ec67b63253 100644 --- a/net/batman-adv/hard-interface.c +++ b/net/batman-adv/hard-interface.c | |||
@@ -117,6 +117,58 @@ static int batadv_is_valid_iface(const struct net_device *net_dev) | |||
117 | return 1; | 117 | return 1; |
118 | } | 118 | } |
119 | 119 | ||
120 | /** | ||
121 | * batadv_is_wifi_netdev - check if the given net_device struct is a wifi | ||
122 | * interface | ||
123 | * @net_device: the device to check | ||
124 | * | ||
125 | * Returns true if the net device is a 802.11 wireless device, false otherwise. | ||
126 | */ | ||
127 | static bool batadv_is_wifi_netdev(struct net_device *net_device) | ||
128 | { | ||
129 | #ifdef CONFIG_WIRELESS_EXT | ||
130 | /* pre-cfg80211 drivers have to implement WEXT, so it is possible to | ||
131 | * check for wireless_handlers != NULL | ||
132 | */ | ||
133 | if (net_device->wireless_handlers) | ||
134 | return true; | ||
135 | #endif | ||
136 | |||
137 | /* cfg80211 drivers have to set ieee80211_ptr */ | ||
138 | if (net_device->ieee80211_ptr) | ||
139 | return true; | ||
140 | |||
141 | return false; | ||
142 | } | ||
143 | |||
144 | /** | ||
145 | * batadv_is_wifi_iface - check if the given interface represented by ifindex | ||
146 | * is a wifi interface | ||
147 | * @ifindex: interface index to check | ||
148 | * | ||
149 | * Returns true if the interface represented by ifindex is a 802.11 wireless | ||
150 | * device, false otherwise. | ||
151 | */ | ||
152 | bool batadv_is_wifi_iface(int ifindex) | ||
153 | { | ||
154 | struct net_device *net_device = NULL; | ||
155 | bool ret = false; | ||
156 | |||
157 | if (ifindex == BATADV_NULL_IFINDEX) | ||
158 | goto out; | ||
159 | |||
160 | net_device = dev_get_by_index(&init_net, ifindex); | ||
161 | if (!net_device) | ||
162 | goto out; | ||
163 | |||
164 | ret = batadv_is_wifi_netdev(net_device); | ||
165 | |||
166 | out: | ||
167 | if (net_device) | ||
168 | dev_put(net_device); | ||
169 | return ret; | ||
170 | } | ||
171 | |||
120 | static struct batadv_hard_iface * | 172 | static struct batadv_hard_iface * |
121 | batadv_hardif_get_active(const struct net_device *soft_iface) | 173 | batadv_hardif_get_active(const struct net_device *soft_iface) |
122 | { | 174 | { |
@@ -657,38 +709,6 @@ out: | |||
657 | return NOTIFY_DONE; | 709 | return NOTIFY_DONE; |
658 | } | 710 | } |
659 | 711 | ||
660 | /* This function returns true if the interface represented by ifindex is a | ||
661 | * 802.11 wireless device | ||
662 | */ | ||
663 | bool batadv_is_wifi_iface(int ifindex) | ||
664 | { | ||
665 | struct net_device *net_device = NULL; | ||
666 | bool ret = false; | ||
667 | |||
668 | if (ifindex == BATADV_NULL_IFINDEX) | ||
669 | goto out; | ||
670 | |||
671 | net_device = dev_get_by_index(&init_net, ifindex); | ||
672 | if (!net_device) | ||
673 | goto out; | ||
674 | |||
675 | #ifdef CONFIG_WIRELESS_EXT | ||
676 | /* pre-cfg80211 drivers have to implement WEXT, so it is possible to | ||
677 | * check for wireless_handlers != NULL | ||
678 | */ | ||
679 | if (net_device->wireless_handlers) | ||
680 | ret = true; | ||
681 | else | ||
682 | #endif | ||
683 | /* cfg80211 drivers have to set ieee80211_ptr */ | ||
684 | if (net_device->ieee80211_ptr) | ||
685 | ret = true; | ||
686 | out: | ||
687 | if (net_device) | ||
688 | dev_put(net_device); | ||
689 | return ret; | ||
690 | } | ||
691 | |||
692 | struct notifier_block batadv_hard_if_notifier = { | 712 | struct notifier_block batadv_hard_if_notifier = { |
693 | .notifier_call = batadv_hard_if_event, | 713 | .notifier_call = batadv_hard_if_event, |
694 | }; | 714 | }; |