tun: dynamically set speed of tun
Subsystems (3)
v2 cover tun: dynamically set speed of tun
V2:
Follow the advice from Sergei, a new patch is made.
V1:
The default speed of tun is 10M while the normal nic speed is 1000M. When the speed of tun is accessed by the userspace application, the default 10M is not proper. In this case, the default tun speed is changed to 1000M. And this speed can be dynamically configured by the command "ethtool -s tunX speed 10/100/1000".
Zhu Yanjun (1):
tun: change speed from 10M to dynamically configured
drivers/net/tun.c | 42 +++++++++++++++++++++++++++++++++++++++++- include/uapi/linux/if_tun.h | 5 +++++ 2 files changed, 46 insertions(+), 1 deletion(-)
Signature · 1 line
1.9.1
PATCH v2 1/1 tun: change speed from 10M to dynamically configured
The default speed of normal nic is 1000M while the default speed of tun is 10M. Now the default speed of tun is changed to 1000M. And there are 3 options: 10M, 100M and 1000M to the speed of tun. The command "ethtool -s tun0 speed 10/100/1000" can configure the speed of tun dynamically.
--- drivers/net/tun.c | 42 +++++++++++++++++++++++++++++++++++++++++- include/uapi/linux/if_tun.h | 5 +++++ 2 files changed, 46 insertions(+), 1 deletion(-)
drivers/net/tun.c +41 -1
@@ -950,6 +950,9 @@ static void tun_net_init(struct net_device *dev) dev->addr_len =0 ; dev->mtu =1500 ; +/* Set default speed 1000M */ + tun->flags |=TUN_CTRL_SPD_1000 ; +/* Zero header length */ dev->type =ARPHRD_NONE ; dev->flags =IFF_POINTOPOINT |IFF_NOARP |IFF_MULTICAST ;
@@ -2257,9 +2260,18 @@ static struct miscdevice tun_miscdev = {static int tun_get_settings (struct net_device *dev,struct ethtool_cmd *cmd) { +struct tun_struct *tun =netdev_priv (dev); + +/* Get the speed of tun */ +if (tun->flags &TUN_CTRL_SPD_1000 ) { +ethtool_cmd_speed_set (cmd,SPEED_1000 ); + }else if (tun->flags &TUN_CTRL_SPD_100 ) { +ethtool_cmd_speed_set (cmd,SPEED_100 ); + }else +ethtool_cmd_speed_set (cmd,SPEED_10 ); + cmd->supported =0 ; cmd->advertising =0 ; -ethtool_cmd_speed_set (cmd,SPEED_10 ); cmd->duplex =DUPLEX_FULL ; cmd->port =PORT_TP ; cmd->phy_address =0 ;
@@ -2287,6 +2299,33 @@ static void tun_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info } } +static int tun_set_settings (struct net_device *dev,struct ethtool_cmd *cmd) +{ +struct tun_struct *tun =netdev_priv (dev); +u32 speed =ethtool_cmd_speed (cmd); + +/* Clear speed flag */ + tun->flags &= ~(TUN_CTRL_SPD_10 |TUN_CTRL_SPD_100 | +TUN_CTRL_SPD_1000 ); + +/* Set speed flag */ +switch (speed) { +case 10 : + tun->flags |=TUN_CTRL_SPD_10 ; +break ; +case 100 : + tun->flags |=TUN_CTRL_SPD_100 ; +break ; +case 1000 : + tun->flags |=TUN_CTRL_SPD_1000 ; +break ; +default : +tun_debug (KERN_INFO , tun,"wrong speed!\n" ); + } + +return 0 ; +} +static u32 tun_get_msglevel (struct net_device *dev) {#ifdef TUN_DEBUG
@@ -2307,6 +2346,7 @@ static void tun_set_msglevel(struct net_device *dev, u32 value)static const struct ethtool_ops tun_ethtool_ops = { .get_settings = tun_get_settings, + .set_settings = tun_set_settings, .get_drvinfo = tun_get_drvinfo, .get_msglevel = tun_get_msglevel, .set_msglevel = tun_set_msglevel,
include/uapi/linux/if_tun.h +5 -0
@@ -66,6 +66,11 @@#define IFF_PERSIST 0x0800#define IFF_NOFILTER 0x1000 +/*add speed control, default 1000M*/ +#define TUN_CTRL_SPD_10 0x0020 +#define TUN_CTRL_SPD_100 0x0040 +#define TUN_CTRL_SPD_1000 0x0080 +/* Socket options */ #define TUN_TX_TIMESTAMP 1
Signature · 1 line
1.9.1
Re: [PATCH V2 1/1] tun: change speed from 10M to dynamically configured
Shouldn't the default case of tun_set_settings() return -EINVAL instead of zero?
Quoted 116 lines · Zhu Yanjun
The default speed of normal nic is 1000M while the default speed of tun is 10M. Now the default speed of tun is changed to 1000M. And there are 3 options: 10M, 100M and 1000M to the speed of tun. The command "ethtool -s tun0 speed 10/100/1000" can configure the speed of tun dynamically.
CC Michael S. Tsirkin <[email protected]>CC Jason Wang <[email protected]>CC Al Viro <[email protected]>Reviewed-by Sergei Shtylyov <[email protected]>Signed-off-by Zhu Yanjun <[email protected]>--- drivers/net/tun.c | 42 +++++++++++++++++++++++++++++++++++++++++- include/uapi/linux/if_tun.h | 5 +++++ 2 files changed, 46 insertions(+), 1 deletion(-)drivers/net/tun.c +41
-1@@ -950,6 +950,9 @@ static void tun_net_init(struct net_device *dev) dev->addr_len =0 ; dev->mtu =1500 ; +/* Set default speed 1000M */ + tun->flags |=TUN_CTRL_SPD_1000 ; +/* Zero header length */ dev->type =ARPHRD_NONE ; dev->flags =IFF_POINTOPOINT |IFF_NOARP |IFF_MULTICAST ;@@ -2257,9 +2260,18 @@ static struct miscdevice tun_miscdev = {static int tun_get_settings (struct net_device *dev,struct ethtool_cmd *cmd) { +struct tun_struct *tun =netdev_priv (dev); + +/* Get the speed of tun */ +if (tun->flags &TUN_CTRL_SPD_1000 ) { +ethtool_cmd_speed_set (cmd,SPEED_1000 ); + }else if (tun->flags &TUN_CTRL_SPD_100 ) { +ethtool_cmd_speed_set (cmd,SPEED_100 ); + }else +ethtool_cmd_speed_set (cmd,SPEED_10 ); + cmd->supported =0 ; cmd->advertising =0 ; -ethtool_cmd_speed_set (cmd,SPEED_10 ); cmd->duplex =DUPLEX_FULL ; cmd->port =PORT_TP ; cmd->phy_address =0 ;@@ -2287,6 +2299,33 @@ static void tun_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info } } +static int tun_set_settings (struct net_device *dev,struct ethtool_cmd *cmd) +{ +struct tun_struct *tun =netdev_priv (dev); +u32 speed =ethtool_cmd_speed (cmd); + +/* Clear speed flag */ + tun->flags &= ~(TUN_CTRL_SPD_10 |TUN_CTRL_SPD_100 | +TUN_CTRL_SPD_1000 ); + +/* Set speed flag */ +switch (speed) { +case 10 : + tun->flags |=TUN_CTRL_SPD_10 ; +break ; +case 100 : + tun->flags |=TUN_CTRL_SPD_100 ; +break ; +case 1000 : + tun->flags |=TUN_CTRL_SPD_1000 ; +break ; +default : +tun_debug (KERN_INFO , tun,"wrong speed!\n" ); + } + +return 0 ; +} +static u32 tun_get_msglevel (struct net_device *dev) {#ifdef TUN_DEBUG @@ -2307,6 +2346,7 @@ static void tun_set_msglevel(struct net_device *dev, u32 value)static const struct ethtool_ops tun_ethtool_ops = { .get_settings = tun_get_settings, + .set_settings = tun_set_settings, .get_drvinfo = tun_get_drvinfo, .get_msglevel = tun_get_msglevel, .set_msglevel = tun_set_msglevel,include/uapi/linux/if_tun.h +5
-1@@ -66,6 +66,11 @@#define IFF_PERSIST 0x0800#define IFF_NOFILTER 0x1000 +/*add speed control, default 1000M*/ +#define TUN_CTRL_SPD_10 0x0020 +#define TUN_CTRL_SPD_100 0x0040 +#define TUN_CTRL_SPD_1000 0x0080 +/* Socket options */ #define TUN_TX_TIMESTAMP 1 --1.9.1
--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 4 lines
Computers are incredibly fast, accurate and stupid. Human beings are
incredibly slow, inaccurate and brilliant. Together they are powerful
beyond imagination.
A. EinsteinRe: [PATCH V2 1/1] tun: change speed from 10M to dynamically configured
Quoted 1 line · Jonathon Reinhart
Shouldn't the default case of
tun_set_settings()return-EINVALinstead of zero?
I agree with you.
Zhu Yanjun
Quoted 120 lines · Zhu Yanjun
Quoted 115 lines
The default speed of normal nic is 1000M while the default speed of tun is 10M. Now the default speed of tun is changed to 1000M. And there are 3 options: 10M, 100M and 1000M to the speed of tun. The command "ethtool -s tun0 speed 10/100/1000" can configure the speed of tun dynamically.
CC Michael S. Tsirkin <[email protected]>CC Jason Wang <[email protected]>CC Al Viro <[email protected]>Reviewed-by Sergei Shtylyov <[email protected]>Signed-off-by Zhu Yanjun <[email protected]>--- drivers/net/tun.c | 42 +++++++++++++++++++++++++++++++++++++++++- include/uapi/linux/if_tun.h | 5 +++++ 2 files changed, 46 insertions(+), 1 deletion(-)drivers/net/tun.c +41
-1@@ -950,6 +950,9 @@ static void tun_net_init(struct net_device *dev) dev->addr_len =0 ; dev->mtu =1500 ; +/* Set default speed 1000M */ + tun->flags |=TUN_CTRL_SPD_1000 ; +/* Zero header length */ dev->type =ARPHRD_NONE ; dev->flags =IFF_POINTOPOINT |IFF_NOARP |IFF_MULTICAST ;@@ -2257,9 +2260,18 @@ static struct miscdevice tun_miscdev = {static int tun_get_settings (struct net_device *dev,struct ethtool_cmd *cmd) { +struct tun_struct *tun =netdev_priv (dev); + +/* Get the speed of tun */ +if (tun->flags &TUN_CTRL_SPD_1000 ) { +ethtool_cmd_speed_set (cmd,SPEED_1000 ); + }else if (tun->flags &TUN_CTRL_SPD_100 ) { +ethtool_cmd_speed_set (cmd,SPEED_100 ); + }else +ethtool_cmd_speed_set (cmd,SPEED_10 ); + cmd->supported =0 ; cmd->advertising =0 ; -ethtool_cmd_speed_set (cmd,SPEED_10 ); cmd->duplex =DUPLEX_FULL ; cmd->port =PORT_TP ; cmd->phy_address =0 ;@@ -2287,6 +2299,33 @@ static void tun_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info } } +static int tun_set_settings (struct net_device *dev,struct ethtool_cmd *cmd) +{ +struct tun_struct *tun =netdev_priv (dev); +u32 speed =ethtool_cmd_speed (cmd); + +/* Clear speed flag */ + tun->flags &= ~(TUN_CTRL_SPD_10 |TUN_CTRL_SPD_100 | +TUN_CTRL_SPD_1000 ); + +/* Set speed flag */ +switch (speed) { +case 10 : + tun->flags |=TUN_CTRL_SPD_10 ; +break ; +case 100 : + tun->flags |=TUN_CTRL_SPD_100 ; +break ; +case 1000 : + tun->flags |=TUN_CTRL_SPD_1000 ; +break ; +default : +tun_debug (KERN_INFO , tun,"wrong speed!\n" ); + } + +return 0 ; +} +static u32 tun_get_msglevel (struct net_device *dev) {#ifdef TUN_DEBUG @@ -2307,6 +2346,7 @@ static void tun_set_msglevel(struct net_device *dev, u32 value)static const struct ethtool_ops tun_ethtool_ops = { .get_settings = tun_get_settings, + .set_settings = tun_set_settings, .get_drvinfo = tun_get_drvinfo, .get_msglevel = tun_get_msglevel, .set_msglevel = tun_set_msglevel,include/uapi/linux/if_tun.h +5
-1@@ -66,6 +66,11 @@#define IFF_PERSIST 0x0800#define IFF_NOFILTER 0x1000 +/*add speed control, default 1000M*/ +#define TUN_CTRL_SPD_10 0x0020 +#define TUN_CTRL_SPD_100 0x0040 +#define TUN_CTRL_SPD_1000 0x0080 +/* Socket options */ #define TUN_TX_TIMESTAMP 1 --1.9.1
--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH V2 1/1] tun: change speed from 10M to dynamically configured
Also in the default case, you've already cleared the existing TUN_CTRL_SPD flags,
which probably isn't what a user would expect if he passed an invalid value.
Quoted 140 lines · On Fri, Feb 13, 2015 at 12:31 AM, yzhu1 <[email protected]> wrote:
Quoted 3 lines · Jonathon Reinhart
Shouldn't the default case of
tun_set_settings()return-EINVALinstead of zero?I agree with you.
Zhu Yanjun
Quoted 129 lines
Quoted 122 lines · Zhu Yanjun
The default speed of normal nic is 1000M while the default speed of tun is 10M. Now the default speed of tun is changed to 1000M. And there are 3 options: 10M, 100M and 1000M to the speed of tun. The command "ethtool -s tun0 speed 10/100/1000" can configure the speed of tun dynamically.
CC Michael S. Tsirkin <[email protected]>CC Jason Wang <[email protected]>CC Al Viro <[email protected]>Reviewed-by Sergei Shtylyov <[email protected]>Signed-off-by Zhu Yanjun <[email protected]>--- drivers/net/tun.c | 42 +++++++++++++++++++++++++++++++++++++++++- include/uapi/linux/if_tun.h | 5 +++++ 2 files changed, 46 insertions(+), 1 deletion(-)drivers/net/tun.c +3
-0@@ -950,6 +950,9 @@ static void tun_net_init(struct net_device *dev) dev->addr_len =0 ; dev->mtu =1500 ; +/* Set default speed 1000M */ + tun->flags |=TUN_CTRL_SPD_1000 ; +/* Zero header length */ dev->type =ARPHRD_NONE ; dev->flags = IFF_POINTOPOINT | IFF_NOARP |
IFF_MULTICAST;drivers/net/tun.c +10
-1@@ -2257,9 +2260,18 @@ static struct miscdevice tun_miscdev = {static int tun_get_settings (struct net_device *dev,struct ethtool_cmd *cmd) { +struct tun_struct *tun =netdev_priv (dev); + +/* Get the speed of tun */ +if (tun->flags &TUN_CTRL_SPD_1000 ) { +ethtool_cmd_speed_set (cmd,SPEED_1000 ); + }else if (tun->flags &TUN_CTRL_SPD_100 ) { +ethtool_cmd_speed_set (cmd,SPEED_100 ); + }else +ethtool_cmd_speed_set (cmd,SPEED_10 ); + cmd->supported =0 ; cmd->advertising =0 ; -ethtool_cmd_speed_set (cmd,SPEED_10 ); cmd->duplex =DUPLEX_FULL ; cmd->port =PORT_TP ;cmd->phy_address = 0;drivers/net/tun.c +27
-0@@ -2287,6 +2299,33 @@ static void tun_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info } } +static int tun_set_settings (struct net_device *dev,struct ethtool_cmd *cmd) +{ +struct tun_struct *tun =netdev_priv (dev); +u32 speed =ethtool_cmd_speed (cmd); + +/* Clear speed flag */ + tun->flags &= ~(TUN_CTRL_SPD_10 |TUN_CTRL_SPD_100 | +TUN_CTRL_SPD_1000 ); + +/* Set speed flag */ +switch (speed) { +case 10 : + tun->flags |=TUN_CTRL_SPD_10 ; +break ; +case 100 : + tun->flags |=TUN_CTRL_SPD_100 ; +break ; +case 1000 : + tun->flags |=TUN_CTRL_SPD_1000 ; +break ; +default : +tun_debug (KERN_INFO , tun,"wrong speed!\n" ); + } + +return 0 ; +} +static u32 tun_get_msglevel (struct net_device *dev){ #ifdef TUN_DEBUGdrivers/net/tun.c +1
-0@@ -2307,6 +2346,7 @@ static void tun_set_msglevel(struct net_device *dev, u32 value)static const struct ethtool_ops tun_ethtool_ops = { .get_settings = tun_get_settings, + .set_settings = tun_set_settings, .get_drvinfo = tun_get_drvinfo, .get_msglevel = tun_get_msglevel,.set_msglevel =
tun_set_msglevel,include/uapi/linux/if_tun.h +5
-1@@ -66,6 +66,11 @@#define IFF_PERSIST 0x0800#define IFF_NOFILTER 0x1000 +/*add speed control, default 1000M*/ +#define TUN_CTRL_SPD_10 0x0020 +#define TUN_CTRL_SPD_100 0x0040 +#define TUN_CTRL_SPD_1000 0x0080 +/* Socket options */ #define TUN_TX_TIMESTAMP 1 --1.9.1
--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH V2 1/1] tun: change speed from 10M to dynamically configured
Yeah. my fault. I will correct it.
Quoted 140 lines · Jonathon Reinhart
Also in the default case, you've already cleared the existing
TUN_CTRL_SPDflags,
which probably isn't what a user would expect if he passed an invalid value.Quoted 134 lines · On Fri, Feb 13, 2015 at 12:31 AM, yzhu1 <[email protected]> wrote:
Quoted 2 lines · Jonathon Reinhart
Shouldn't the default case of
tun_set_settings()return-EINVALinstead of zero?I agree with you.
Zhu Yanjun
Quoted 126 lines
Quoted 121 lines · Zhu Yanjun
The default speed of normal nic is 1000M while the default speed of tun is 10M. Now the default speed of tun is changed to 1000M. And there are 3 options: 10M, 100M and 1000M to the speed of tun. The command "ethtool -s tun0 speed 10/100/1000" can configure the speed of tun dynamically.
CC Michael S. Tsirkin <[email protected]>CC Jason Wang <[email protected]>CC Al Viro <[email protected]>Reviewed-by Sergei Shtylyov <[email protected]>Signed-off-by Zhu Yanjun <[email protected]>--- drivers/net/tun.c | 42 +++++++++++++++++++++++++++++++++++++++++- include/uapi/linux/if_tun.h | 5 +++++ 2 files changed, 46 insertions(+), 1 deletion(-)drivers/net/tun.c +3
-0@@ -950,6 +950,9 @@ static void tun_net_init(struct net_device *dev) dev->addr_len =0 ; dev->mtu =1500 ; +/* Set default speed 1000M */ + tun->flags |=TUN_CTRL_SPD_1000 ; +/* Zero header length */ dev->type =ARPHRD_NONE ; dev->flags = IFF_POINTOPOINT | IFF_NOARP |
IFF_MULTICAST;drivers/net/tun.c +10
-1@@ -2257,9 +2260,18 @@ static struct miscdevice tun_miscdev = {static int tun_get_settings (struct net_device *dev,struct ethtool_cmd *cmd) { +struct tun_struct *tun =netdev_priv (dev); + +/* Get the speed of tun */ +if (tun->flags &TUN_CTRL_SPD_1000 ) { +ethtool_cmd_speed_set (cmd,SPEED_1000 ); + }else if (tun->flags &TUN_CTRL_SPD_100 ) { +ethtool_cmd_speed_set (cmd,SPEED_100 ); + }else +ethtool_cmd_speed_set (cmd,SPEED_10 ); + cmd->supported =0 ; cmd->advertising =0 ; -ethtool_cmd_speed_set (cmd,SPEED_10 ); cmd->duplex =DUPLEX_FULL ; cmd->port =PORT_TP ;cmd->phy_address = 0;drivers/net/tun.c +27
-0@@ -2287,6 +2299,33 @@ static void tun_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info } } +static int tun_set_settings (struct net_device *dev,struct ethtool_cmd *cmd) +{ +struct tun_struct *tun =netdev_priv (dev); +u32 speed =ethtool_cmd_speed (cmd); + +/* Clear speed flag */ + tun->flags &= ~(TUN_CTRL_SPD_10 |TUN_CTRL_SPD_100 | +TUN_CTRL_SPD_1000 ); + +/* Set speed flag */ +switch (speed) { +case 10 : + tun->flags |=TUN_CTRL_SPD_10 ; +break ; +case 100 : + tun->flags |=TUN_CTRL_SPD_100 ; +break ; +case 1000 : + tun->flags |=TUN_CTRL_SPD_1000 ; +break ; +default : +tun_debug (KERN_INFO , tun,"wrong speed!\n" ); + } + +return 0 ; +} +static u32 tun_get_msglevel (struct net_device *dev){ #ifdef TUN_DEBUGdrivers/net/tun.c +1
-0@@ -2307,6 +2346,7 @@ static void tun_set_msglevel(struct net_device *dev, u32 value)static const struct ethtool_ops tun_ethtool_ops = { .get_settings = tun_get_settings, + .set_settings = tun_set_settings, .get_drvinfo = tun_get_drvinfo, .get_msglevel = tun_get_msglevel,.set_msglevel =
tun_set_msglevel,include/uapi/linux/if_tun.h +5
-1@@ -66,6 +66,11 @@#define IFF_PERSIST 0x0800#define IFF_NOFILTER 0x1000 +/*add speed control, default 1000M*/ +#define TUN_CTRL_SPD_10 0x0020 +#define TUN_CTRL_SPD_100 0x0040 +#define TUN_CTRL_SPD_1000 0x0080 +/* Socket options */ #define TUN_TX_TIMESTAMP 1 --1.9.1
--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH V2 1/1] tun: change speed from 10M to dynamically configured
In reply to Zhu YanjunHello.
Quoted 20 lines · Zhu Yanjun
The default speed of normal nic is 1000M while the default speed of tun is 10M. Now the default speed of tun is changed to 1000M. And there are 3 options: 10M, 100M and 1000M to the speed of tun. The command "ethtool -s tun0 speed 10/100/1000" can configure the speed of tun dynamically.
CC Michael S. Tsirkin <[email protected]>CC Jason Wang <[email protected]>CC Al Viro <[email protected]>Reviewed-by Sergei Shtylyov <[email protected]>Signed-off-by Zhu Yanjun <[email protected]>--- drivers/net/tun.c | 42 +++++++++++++++++++++++++++++++++++++++++- include/uapi/linux/if_tun.h | 5 +++++ 2 files changed, 46 insertions(+), 1 deletion(-)drivers/net/tun.c +0
-0
[...]
drivers/net/tun.c static struct miscdevice tun_miscdev = { · line 2271
Quoted 13 lines
drivers/net/tun.c +9
-0@@ -2257,9 +2260,18 @@ static struct miscdevice tun_miscdev = {static int tun_get_settings (struct net_device *dev,struct ethtool_cmd *cmd) { +struct tun_struct *tun =netdev_priv (dev); + +/* Get the speed of tun */ +if (tun->flags &TUN_CTRL_SPD_1000 ) { +ethtool_cmd_speed_set (cmd,SPEED_1000 ); + }else if (tun->flags &TUN_CTRL_SPD_100 ) { +ethtool_cmd_speed_set (cmd,SPEED_100 ); + }else +ethtool_cmd_speed_set (cmd,SPEED_10 );
I probably missed it in the previous version: {} not needed here at all.
Please remove to comply with Documentation/CodingStyle.
[...]
WBR, Sergei