diff options
author | Chas Williams <3chas3@gmail.com> | 2018-06-02 17:49:53 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-06-04 16:05:16 -0400 |
commit | 4e24f2dd516ed85fc8fd568ceae589ad0a07b7d5 (patch) | |
tree | 5b3a946e4ef6861a1f8f808bd86208fcbb058eef /drivers/net/tun.c | |
parent | 4cd328f83916ce1df69bed43c84af75e0c3d6f2d (diff) |
Allow ethtool to change tun link settings
Let user space set whatever it would like to advertise for the
tun interface. Preserve the existing defaults.
Signed-off-by: Chas Williams <3chas3@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/tun.c')
-rw-r--r-- | drivers/net/tun.c | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c index c94fffee5ea9..067fc9e7e3ed 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c | |||
@@ -81,6 +81,9 @@ | |||
81 | #include <linux/uaccess.h> | 81 | #include <linux/uaccess.h> |
82 | #include <linux/proc_fs.h> | 82 | #include <linux/proc_fs.h> |
83 | 83 | ||
84 | static void tun_default_link_ksettings(struct net_device *dev, | ||
85 | struct ethtool_link_ksettings *cmd); | ||
86 | |||
84 | /* Uncomment to enable debugging */ | 87 | /* Uncomment to enable debugging */ |
85 | /* #define TUN_DEBUG 1 */ | 88 | /* #define TUN_DEBUG 1 */ |
86 | 89 | ||
@@ -242,6 +245,7 @@ struct tun_struct { | |||
242 | struct bpf_prog __rcu *xdp_prog; | 245 | struct bpf_prog __rcu *xdp_prog; |
243 | struct tun_prog __rcu *steering_prog; | 246 | struct tun_prog __rcu *steering_prog; |
244 | struct tun_prog __rcu *filter_prog; | 247 | struct tun_prog __rcu *filter_prog; |
248 | struct ethtool_link_ksettings link_ksettings; | ||
245 | }; | 249 | }; |
246 | 250 | ||
247 | struct veth { | 251 | struct veth { |
@@ -2295,6 +2299,7 @@ static void tun_setup(struct net_device *dev) | |||
2295 | 2299 | ||
2296 | tun->owner = INVALID_UID; | 2300 | tun->owner = INVALID_UID; |
2297 | tun->group = INVALID_GID; | 2301 | tun->group = INVALID_GID; |
2302 | tun_default_link_ksettings(dev, &tun->link_ksettings); | ||
2298 | 2303 | ||
2299 | dev->ethtool_ops = &tun_ethtool_ops; | 2304 | dev->ethtool_ops = &tun_ethtool_ops; |
2300 | dev->needs_free_netdev = true; | 2305 | dev->needs_free_netdev = true; |
@@ -3326,8 +3331,8 @@ static struct miscdevice tun_miscdev = { | |||
3326 | 3331 | ||
3327 | /* ethtool interface */ | 3332 | /* ethtool interface */ |
3328 | 3333 | ||
3329 | static int tun_get_link_ksettings(struct net_device *dev, | 3334 | static void tun_default_link_ksettings(struct net_device *dev, |
3330 | struct ethtool_link_ksettings *cmd) | 3335 | struct ethtool_link_ksettings *cmd) |
3331 | { | 3336 | { |
3332 | ethtool_link_ksettings_zero_link_mode(cmd, supported); | 3337 | ethtool_link_ksettings_zero_link_mode(cmd, supported); |
3333 | ethtool_link_ksettings_zero_link_mode(cmd, advertising); | 3338 | ethtool_link_ksettings_zero_link_mode(cmd, advertising); |
@@ -3336,6 +3341,23 @@ static int tun_get_link_ksettings(struct net_device *dev, | |||
3336 | cmd->base.port = PORT_TP; | 3341 | cmd->base.port = PORT_TP; |
3337 | cmd->base.phy_address = 0; | 3342 | cmd->base.phy_address = 0; |
3338 | cmd->base.autoneg = AUTONEG_DISABLE; | 3343 | cmd->base.autoneg = AUTONEG_DISABLE; |
3344 | } | ||
3345 | |||
3346 | static int tun_get_link_ksettings(struct net_device *dev, | ||
3347 | struct ethtool_link_ksettings *cmd) | ||
3348 | { | ||
3349 | struct tun_struct *tun = netdev_priv(dev); | ||
3350 | |||
3351 | memcpy(cmd, &tun->link_ksettings, sizeof(*cmd)); | ||
3352 | return 0; | ||
3353 | } | ||
3354 | |||
3355 | static int tun_set_link_ksettings(struct net_device *dev, | ||
3356 | const struct ethtool_link_ksettings *cmd) | ||
3357 | { | ||
3358 | struct tun_struct *tun = netdev_priv(dev); | ||
3359 | |||
3360 | memcpy(&tun->link_ksettings, cmd, sizeof(*cmd)); | ||
3339 | return 0; | 3361 | return 0; |
3340 | } | 3362 | } |
3341 | 3363 | ||
@@ -3406,6 +3428,7 @@ static const struct ethtool_ops tun_ethtool_ops = { | |||
3406 | .get_coalesce = tun_get_coalesce, | 3428 | .get_coalesce = tun_get_coalesce, |
3407 | .set_coalesce = tun_set_coalesce, | 3429 | .set_coalesce = tun_set_coalesce, |
3408 | .get_link_ksettings = tun_get_link_ksettings, | 3430 | .get_link_ksettings = tun_get_link_ksettings, |
3431 | .set_link_ksettings = tun_set_link_ksettings, | ||
3409 | }; | 3432 | }; |
3410 | 3433 | ||
3411 | static int tun_queue_resize(struct tun_struct *tun) | 3434 | static int tun_queue_resize(struct tun_struct *tun) |