aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/device.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-02-27 12:05:20 -0800
committerJason A. Donenfeld <Jason@zx2c4.com>2017-02-27 12:13:14 -0800
commitf97b7e34bda436ac4572697a8770837eec7470b6 (patch)
tree044e628c0ddfcc8f91a50f2c84bf9767dc61f399 /src/device.c
parentreceive: last_rx use is discouraged and removed in recent kernels (diff)
downloadwireguard-monolithic-historical-f97b7e34bda436ac4572697a8770837eec7470b6.tar.xz
wireguard-monolithic-historical-f97b7e34bda436ac4572697a8770837eec7470b6.zip
device: move sysctl toggling to open time
Diffstat (limited to '')
-rw-r--r--src/device.c42
1 files changed, 12 insertions, 30 deletions
diff --git a/src/device.c b/src/device.c
index 11bc5aa..190e6aa 100644
--- a/src/device.c
+++ b/src/device.c
@@ -37,9 +37,19 @@ static int open_peer(struct wireguard_peer *peer, void *data)
static int open(struct net_device *dev)
{
- struct wireguard_device *wg = netdev_priv(dev);
int ret;
+ struct wireguard_device *wg = netdev_priv(dev);
struct inet6_dev *dev_v6 = __in6_dev_get(dev);
+ struct in_device *dev_v4 = __in_dev_get_rtnl(dev);
+
+ if (dev_v4) {
+ /* TODO: when we merge to mainline, put this check near the ip_rt_send_redirect
+ * call of ip_forward in net/ipv4/ip_forward.c, similar to the current secpath
+ * check, rather than turning it off like this. This is just a stop gap solution
+ * while we're an out of tree module. */
+ IN_DEV_CONF_SET(dev_v4, SEND_REDIRECTS, false);
+ IPV4_DEVCONF_ALL(dev_net(dev), SEND_REDIRECTS) = false;
+ }
if (dev_v6)
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0)
dev_v6->addr_gen_mode = IN6_ADDR_GEN_MODE_NONE;
@@ -216,27 +226,6 @@ static const struct net_device_ops netdev_ops = {
.ndo_do_ioctl = ioctl
};
-static int netdev_event(struct notifier_block *this, unsigned long event, void *ptr)
-{
- struct net_device *dev = netdev_notifier_info_to_dev(ptr);
- struct in_device *in_dev = __in_dev_get_rtnl(dev);
-
- /* TODO: when we merge to mainline, put this check near the ip_rt_send_redirect
- * call of ip_forward in net/ipv4/ip_forward.c, similar to the current secpath
- * check, rather than turning it off like this. This is just a stop gap solution
- * while we're an out of tree module. */
- if (in_dev && dev->netdev_ops == &netdev_ops && event == NETDEV_REGISTER) {
- IN_DEV_CONF_SET(in_dev, SEND_REDIRECTS, false);
- IPV4_DEVCONF_ALL(dev_net(dev), SEND_REDIRECTS) = false;
- }
- return NOTIFY_DONE;
-}
-
-static struct notifier_block netdev_notifier = {
- .notifier_call = netdev_event
-};
-
-
static void destruct(struct net_device *dev)
{
struct wireguard_device *wg = netdev_priv(dev);
@@ -388,18 +377,11 @@ static struct rtnl_link_ops link_ops __read_mostly = {
int device_init(void)
{
- int ret = register_netdevice_notifier(&netdev_notifier);
- if (ret < 0)
- return ret;
- ret = rtnl_link_register(&link_ops);
- if (ret < 0)
- unregister_netdevice_notifier(&netdev_notifier);
- return ret;
+ return rtnl_link_register(&link_ops);
}
void device_uninit(void)
{
rtnl_link_unregister(&link_ops);
- unregister_netdevice_notifier(&netdev_notifier);
rcu_barrier();
}