aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-10-26 16:39:39 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-10-27 14:20:00 +0200
commitf581e7e011c144706f74af35258cc6a75d3f556c (patch)
treeee9e1d29ac28bd5de9a8187837ef6049e88d8c9c
parentcurve25519-x86_64: this was relicensed to BSD-3-Clause upstream (diff)
downloadwireguard-monolithic-historical-f581e7e011c144706f74af35258cc6a75d3f556c.tar.xz
wireguard-monolithic-historical-f581e7e011c144706f74af35258cc6a75d3f556c.zip
device: do not clear keys on sleep for PM_AUTOSLEEP
This way other devices that use Android style wakelocks will also have the same semantics. We also move this logic into the handler so that it's slightly cleaner and gives us some opportunity to leave a normal comment. Suggested-by: Theodore Ts'o <tytso@mit.edu> Suggested-by: Andrew Lunn <andrew@lunn.ch> Suggested-by: Sultan Alsawaf <sultanxda@gmail.com>
-rw-r--r--src/device.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/device.c b/src/device.c
index 010fb28..877000b 100644
--- a/src/device.c
+++ b/src/device.c
@@ -66,13 +66,20 @@ static int wg_open(struct net_device *dev)
return 0;
}
-#if defined(CONFIG_PM_SLEEP) && !defined(CONFIG_ANDROID)
+#ifdef CONFIG_PM_SLEEP
static int wg_pm_notification(struct notifier_block *nb, unsigned long action,
void *data)
{
struct wg_device *wg;
struct wg_peer *peer;
+ /* If the machine is constantly suspending and resuming, as part of
+ * its normal operation rather than as a somewhat rare event, then we
+ * don't actually want to clear keys.
+ */
+ if (IS_ENABLED(CONFIG_PM_AUTOSLEEP) || IS_ENABLED(CONFIG_ANDROID))
+ return 0;
+
if (action != PM_HIBERNATION_PREPARE && action != PM_SUSPEND_PREPARE)
return 0;
@@ -418,7 +425,7 @@ int __init wg_device_init(void)
{
int ret;
-#if defined(CONFIG_PM_SLEEP) && !defined(CONFIG_ANDROID)
+#ifdef CONFIG_PM_SLEEP
ret = register_pm_notifier(&pm_notifier);
if (ret)
return ret;
@@ -437,7 +444,7 @@ int __init wg_device_init(void)
error_netdevice:
unregister_netdevice_notifier(&netdevice_notifier);
error_pm:
-#if defined(CONFIG_PM_SLEEP) && !defined(CONFIG_ANDROID)
+#ifdef CONFIG_PM_SLEEP
unregister_pm_notifier(&pm_notifier);
#endif
return ret;
@@ -447,7 +454,7 @@ void wg_device_uninit(void)
{
rtnl_link_unregister(&link_ops);
unregister_netdevice_notifier(&netdevice_notifier);
-#if defined(CONFIG_PM_SLEEP) && !defined(CONFIG_ANDROID)
+#ifdef CONFIG_PM_SLEEP
unregister_pm_notifier(&pm_notifier);
#endif
rcu_barrier_bh();