diff mbox

[RFC] mac80211_hwsim: Adds parameter use_hwsim_mon which can be used to disable hwism0

Message ID 1446239145-21119-1-git-send-email-arwelle@cert.org (mailing list archive)
State Rejected
Delegated to: Johannes Berg
Headers show

Commit Message

arwelle@cert.org Oct. 30, 2015, 9:05 p.m. UTC
From: Adam Welle <arwelle@cert.org>

A new parameter, use_hwsim_mon has been created to implement new functionalilty. use_hwsim_mon defaults to true so that normal operation remains the same. When set to false, the hwsim0 device is not created. This value is also checked before calling functions which would transmit data to the hwsim0 device.

Signed-off-by: Adam Welle <arwelle@cert.org>
---
 drivers/net/wireless/mac80211_hwsim.c | 49 +++++++++++++++++++++--------------
 1 file changed, 30 insertions(+), 19 deletions(-)

Comments

Johannes Berg Nov. 2, 2015, 12:24 p.m. UTC | #1
On Fri, 2015-10-30 at 17:05 -0400, arwelle@cert.org wrote:
> From: Adam Welle <arwelle@cert.org>
> 
> A new parameter, use_hwsim_mon has been created to implement new 
> functionalilty. use_hwsim_mon defaults to true so that normal 
> operation remains the same. When set to false, the hwsim0 device is 
> not created. This value is also checked before calling functions 
> which would transmit data to the hwsim0 device.

I understand the use case (since you explained it to me off-list), but
I don't think I want to apply this since in almost all cases having
hwsim0 around but unused isn't actually harmful.

FWIW,

> -	mac80211_hwsim_monitor_rx(hw, skb, channel);
> +	if (use_hwsim_mon)
> +		mac80211_hwsim_monitor_rx(hw, skb, channel);

Had I wanted to apply this, I'd probably have insisted to move the
check into the function instead of outside of it, since that leaves no
chances of getting it wrong when changing the code in the future.

johannes
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index ee46f46..8e48869 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -61,6 +61,10 @@  static bool support_p2p_device = true;
 module_param(support_p2p_device, bool, 0444);
 MODULE_PARM_DESC(support_p2p_device, "Support P2P-Device interface type");
 
+static bool use_hwsim_mon = true;
+module_param(use_hwsim_mon, bool, 0444);
+MODULE_PARM_DESC(use_hwsim_mon, "Create and use hwsim0 monitor device");
+
 /**
  * enum hwsim_regtest - the type of regulatory tests we offer
  *
@@ -1292,7 +1296,8 @@  static void mac80211_hwsim_tx(struct ieee80211_hw *hw,
 				       ARRAY_SIZE(txi->control.rates));
 
 	txi->rate_driver_data[0] = channel;
-	mac80211_hwsim_monitor_rx(hw, skb, channel);
+	if (use_hwsim_mon)
+		mac80211_hwsim_monitor_rx(hw, skb, channel);
 
 	/* wmediumd mode check */
 	_portid = ACCESS_ONCE(wmediumd_portid);
@@ -1305,7 +1310,7 @@  static void mac80211_hwsim_tx(struct ieee80211_hw *hw,
 	data->tx_bytes += skb->len;
 	ack = mac80211_hwsim_tx_frame_no_nl(hw, skb, channel);
 
-	if (ack && skb->len >= 16) {
+	if (ack && skb->len >= 16 && use_hwsim_mon) {
 		struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
 		mac80211_hwsim_monitor_ack(channel, hdr->addr2);
 	}
@@ -1402,7 +1407,8 @@  static void mac80211_hwsim_tx_frame(struct ieee80211_hw *hw,
 				       ARRAY_SIZE(txi->control.rates));
 	}
 
-	mac80211_hwsim_monitor_rx(hw, skb, chan);
+	if (use_hwsim_mon)
+		mac80211_hwsim_monitor_rx(hw, skb, chan);
 
 	if (_pid)
 		return mac80211_hwsim_tx_frame_nl(hw, skb, _pid);
@@ -3260,26 +3266,28 @@  static int __init init_mac80211_hwsim(void)
 			goto out_free_radios;
 	}
 
-	hwsim_mon = alloc_netdev(0, "hwsim%d", NET_NAME_UNKNOWN,
+	if (use_hwsim_mon) {
+		hwsim_mon = alloc_netdev(0, "hwsim%d", NET_NAME_UNKNOWN,
 				 hwsim_mon_setup);
-	if (hwsim_mon == NULL) {
-		err = -ENOMEM;
-		goto out_free_radios;
-	}
+		if (hwsim_mon == NULL) {
+			err = -ENOMEM;
+			goto out_free_radios;
+		}
 
-	rtnl_lock();
-	err = dev_alloc_name(hwsim_mon, hwsim_mon->name);
-	if (err < 0) {
-		rtnl_unlock();
-		goto out_free_radios;
-	}
+		rtnl_lock();
+		err = dev_alloc_name(hwsim_mon, hwsim_mon->name);
+		if (err < 0) {
+			rtnl_unlock();
+			goto out_free_radios;
+		}
 
-	err = register_netdevice(hwsim_mon);
-	if (err < 0) {
+		err = register_netdevice(hwsim_mon);
+		if (err < 0) {
+			rtnl_unlock();
+			goto out_free_mon;
+		}
 		rtnl_unlock();
-		goto out_free_mon;
 	}
-	rtnl_unlock();
 
 	return 0;
 
@@ -3300,7 +3308,10 @@  static void __exit exit_mac80211_hwsim(void)
 	hwsim_exit_netlink();
 
 	mac80211_hwsim_free();
-	unregister_netdev(hwsim_mon);
+
+	if (hwsim_mon)
+		unregister_netdev(hwsim_mon);
+
 	platform_driver_unregister(&mac80211_hwsim_driver);
 }
 module_exit(exit_mac80211_hwsim);