From: Mark McLoughlin <markmc@redhat.com> Date: Wed, 26 Nov 2008 17:40:08 +0000 Subject: [net] tun: jumbo frame support Message-id: 1227721208.24571.1.camel@blaa O-Subject: [RHEL5.3 PATCH] tun: jumbo frame support Bugzilla: 473110 RH-Acked-by: Chris Wright <chrisw@redhat.com> RH-Acked-by: Neil Horman <nhorman@redhat.com> RH-Acked-by: Herbert Xu <herbert.xu@redhat.com> RH-Acked-by: David Miller <davem@redhat.com> https://bugzilla.redhat.com/473110 This is a trivial patch to allow users to configure tun/tap with an MTU larger than 1500 bytes The only limit there is on tx frame size is the size of the application's buffer when it reads from the file descriptor, so we shouldn't prevent users from configuring a larger MTU size where the application is known to support it. This patch was included in 2.6.24: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=4885a50476b95fa0f4caad179a80783508c2fe86 Tested locally with no obvious problems; the performance team has tested this too and found that using jumbo frames (9000 byte MTU) can improve external->guest throughput by over 300%. Signed-off-by: Mark McLoughlin <markmc@redhat.com> diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 0f5a11d..9a35086 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -174,6 +174,18 @@ static struct net_device_stats *tun_net_stats(struct net_device *dev) return &tun->stats; } +#define MIN_MTU 68 +#define MAX_MTU 65535 + +static int +tun_net_change_mtu(struct net_device *dev, int new_mtu) +{ + if (new_mtu < MIN_MTU || new_mtu + dev->hard_header_len > MAX_MTU) + return -EINVAL; + dev->mtu = new_mtu; + return 0; +} + /* Initialize net device. */ static void tun_net_init(struct net_device *dev) { @@ -185,6 +197,7 @@ static void tun_net_init(struct net_device *dev) dev->hard_header_len = 0; dev->addr_len = 0; dev->mtu = 1500; + dev->change_mtu = tun_net_change_mtu; /* Zero header length */ dev->type = ARPHRD_NONE; @@ -194,9 +207,10 @@ static void tun_net_init(struct net_device *dev) case TUN_TAP_DEV: /* Ethernet TAP Device */ + ether_setup(dev); + dev->change_mtu = tun_net_change_mtu; dev->set_multicast_list = tun_net_mclist; - ether_setup(dev); random_ether_addr(dev->dev_addr); dev->tx_queue_len = TUN_READQ_SIZE; /* We prefer our own queue length */ break;