device.c (1136fa0c07de570dc17858745af8be169d1440ba) | device.c (2d6919c3205b141ba85fb733b2a67937ff85dc7f) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. 4 */ 5 6#include "queueing.h" 7#include "socket.h" 8#include "timers.h" --- 45 unchanged lines hidden (view full) --- 54 if (peer->persistent_keepalive_interval) 55 wg_packet_send_keepalive(peer); 56 } 57out: 58 mutex_unlock(&wg->device_update_lock); 59 return ret; 60} 61 | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. 4 */ 5 6#include "queueing.h" 7#include "socket.h" 8#include "timers.h" --- 45 unchanged lines hidden (view full) --- 54 if (peer->persistent_keepalive_interval) 55 wg_packet_send_keepalive(peer); 56 } 57out: 58 mutex_unlock(&wg->device_update_lock); 59 return ret; 60} 61 |
62#ifdef CONFIG_PM_SLEEP 63static int wg_pm_notification(struct notifier_block *nb, unsigned long action, 64 void *data) | 62static int wg_pm_notification(struct notifier_block *nb, unsigned long action, void *data) |
65{ 66 struct wg_device *wg; 67 struct wg_peer *peer; 68 69 /* If the machine is constantly suspending and resuming, as part of 70 * its normal operation rather than as a somewhat rare event, then we 71 * don't actually want to clear keys. 72 */ --- 14 unchanged lines hidden (view full) --- 87 mutex_unlock(&wg->device_update_lock); 88 } 89 rtnl_unlock(); 90 rcu_barrier(); 91 return 0; 92} 93 94static struct notifier_block pm_notifier = { .notifier_call = wg_pm_notification }; | 63{ 64 struct wg_device *wg; 65 struct wg_peer *peer; 66 67 /* If the machine is constantly suspending and resuming, as part of 68 * its normal operation rather than as a somewhat rare event, then we 69 * don't actually want to clear keys. 70 */ --- 14 unchanged lines hidden (view full) --- 85 mutex_unlock(&wg->device_update_lock); 86 } 87 rtnl_unlock(); 88 rcu_barrier(); 89 return 0; 90} 91 92static struct notifier_block pm_notifier = { .notifier_call = wg_pm_notification }; |
95#endif | |
96 | 93 |
94static int wg_vm_notification(struct notifier_block *nb, unsigned long action, void *data) 95{ 96 struct wg_device *wg; 97 struct wg_peer *peer; 98 99 rtnl_lock(); 100 list_for_each_entry(wg, &device_list, device_list) { 101 mutex_lock(&wg->device_update_lock); 102 list_for_each_entry(peer, &wg->peer_list, peer_list) 103 wg_noise_expire_current_peer_keypairs(peer); 104 mutex_unlock(&wg->device_update_lock); 105 } 106 rtnl_unlock(); 107 return 0; 108} 109 110static struct notifier_block vm_notifier = { .notifier_call = wg_vm_notification }; 111 |
|
97static int wg_stop(struct net_device *dev) 98{ 99 struct wg_device *wg = netdev_priv(dev); 100 struct wg_peer *peer; 101 struct sk_buff *skb; 102 103 mutex_lock(&wg->device_update_lock); 104 list_for_each_entry(peer, &wg->peer_list, peer_list) { --- 314 unchanged lines hidden (view full) --- 419static struct pernet_operations pernet_ops = { 420 .pre_exit = wg_netns_pre_exit 421}; 422 423int __init wg_device_init(void) 424{ 425 int ret; 426 | 112static int wg_stop(struct net_device *dev) 113{ 114 struct wg_device *wg = netdev_priv(dev); 115 struct wg_peer *peer; 116 struct sk_buff *skb; 117 118 mutex_lock(&wg->device_update_lock); 119 list_for_each_entry(peer, &wg->peer_list, peer_list) { --- 314 unchanged lines hidden (view full) --- 434static struct pernet_operations pernet_ops = { 435 .pre_exit = wg_netns_pre_exit 436}; 437 438int __init wg_device_init(void) 439{ 440 int ret; 441 |
427#ifdef CONFIG_PM_SLEEP | |
428 ret = register_pm_notifier(&pm_notifier); 429 if (ret) 430 return ret; | 442 ret = register_pm_notifier(&pm_notifier); 443 if (ret) 444 return ret; |
431#endif | |
432 | 445 |
433 ret = register_pernet_device(&pernet_ops); | 446 ret = register_random_vmfork_notifier(&vm_notifier); |
434 if (ret) 435 goto error_pm; 436 | 447 if (ret) 448 goto error_pm; 449 |
450 ret = register_pernet_device(&pernet_ops); 451 if (ret) 452 goto error_vm; 453 |
|
437 ret = rtnl_link_register(&link_ops); 438 if (ret) 439 goto error_pernet; 440 441 return 0; 442 443error_pernet: 444 unregister_pernet_device(&pernet_ops); | 454 ret = rtnl_link_register(&link_ops); 455 if (ret) 456 goto error_pernet; 457 458 return 0; 459 460error_pernet: 461 unregister_pernet_device(&pernet_ops); |
462error_vm: 463 unregister_random_vmfork_notifier(&vm_notifier); |
|
445error_pm: | 464error_pm: |
446#ifdef CONFIG_PM_SLEEP | |
447 unregister_pm_notifier(&pm_notifier); | 465 unregister_pm_notifier(&pm_notifier); |
448#endif | |
449 return ret; 450} 451 452void wg_device_uninit(void) 453{ 454 rtnl_link_unregister(&link_ops); 455 unregister_pernet_device(&pernet_ops); | 466 return ret; 467} 468 469void wg_device_uninit(void) 470{ 471 rtnl_link_unregister(&link_ops); 472 unregister_pernet_device(&pernet_ops); |
456#ifdef CONFIG_PM_SLEEP | 473 unregister_random_vmfork_notifier(&vm_notifier); |
457 unregister_pm_notifier(&pm_notifier); | 474 unregister_pm_notifier(&pm_notifier); |
458#endif | |
459 rcu_barrier(); 460} | 475 rcu_barrier(); 476} |