diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2017-02-27 12:05:20 -0800 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2017-02-27 12:13:14 -0800 |
commit | 11a6272ef82c37764ae57ee8ff64ac49e0d61352 (patch) | |
tree | b6dd052ece0cec76c8934f62082761f464c2c621 /src | |
parent | 94380b5117b82aee78504a4199697ef2e2f1c52e (diff) |
device: move sysctl toggling to open time
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/device.c | 42 |
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(); } |