diff mbox

[2/2] veth: Configurable nterface MTU

Message ID m1fxi1kasv.fsf@fess.ebiederm.org
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Eric W. Biederman Feb. 26, 2009, 5:49 a.m. UTC
The limitation to only 1500 byte mtu's limits the utility of the veth
device for testing routing.

Signed-off-by: Eric Biederman <ebiederm@aristanetworks.com>
---
 drivers/net/veth.c |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)

Comments

David Miller Feb. 27, 2009, 10:49 a.m. UTC | #1
From: ebiederm@xmission.com (Eric W. Biederman)
Date: Wed, 25 Feb 2009 21:49:04 -0800

> @@ -249,6 +253,19 @@ static int veth_close(struct net_device *dev)
>  	return 0;
>  }
>  
> +static int is_valid_veth_mtu(int new_mtu)
> +{
> +	return (new_mtu >= MIN_MTU && new_mtu <= MAX_MTU);
> +}
> +
> +static int veth_change_mtu(struct net_device *dev, int new_mtu)
> +{
> +	if (is_valid_veth_mtu(new_mtu))
> +		return -EINVAL;
> +	dev->mtu = new_mtu;
> +	return 0;
> +}
> +

This validity test seems to be reversed?

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Eric W. Biederman Feb. 27, 2009, 12:41 p.m. UTC | #2
David Miller <davem@davemloft.net> writes:

> From: ebiederm@xmission.com (Eric W. Biederman)
> Date: Wed, 25 Feb 2009 21:49:04 -0800
>
>> @@ -249,6 +253,19 @@ static int veth_close(struct net_device *dev)
>>  	return 0;
>>  }
>>  
>> +static int is_valid_veth_mtu(int new_mtu)
>> +{
>> +	return (new_mtu >= MIN_MTU && new_mtu <= MAX_MTU);
>> +}
>> +
>> +static int veth_change_mtu(struct net_device *dev, int new_mtu)
>> +{
>> +	if (is_valid_veth_mtu(new_mtu))
>> +		return -EINVAL;
>> +	dev->mtu = new_mtu;
>> +	return 0;
>> +}
>> +
>
> This validity test seems to be reversed?

Crap.  You are correct. I will respin.

Eric

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller Feb. 27, 2009, 1:22 p.m. UTC | #3
From: ebiederm@xmission.com (Eric W. Biederman)
Date: Fri, 27 Feb 2009 04:41:48 -0800

> David Miller <davem@davemloft.net> writes:
> 
> > From: ebiederm@xmission.com (Eric W. Biederman)
> > Date: Wed, 25 Feb 2009 21:49:04 -0800
> >
> >> @@ -249,6 +253,19 @@ static int veth_close(struct net_device *dev)
> >>  	return 0;
> >>  }
> >>  
> >> +static int is_valid_veth_mtu(int new_mtu)
> >> +{
> >> +	return (new_mtu >= MIN_MTU && new_mtu <= MAX_MTU);
> >> +}
> >> +
> >> +static int veth_change_mtu(struct net_device *dev, int new_mtu)
> >> +{
> >> +	if (is_valid_veth_mtu(new_mtu))
> >> +		return -EINVAL;
> >> +	dev->mtu = new_mtu;
> >> +	return 0;
> >> +}
> >> +
> >
> > This validity test seems to be reversed?
> 
> Crap.  You are correct. I will respin.

Please test your patches.

This one obviously didn't get even one single "ifconfig x mtu y" type
test.  It would have failed on any in-range value.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index 124fe75..88778bb 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -19,6 +19,10 @@ 
 #define DRV_NAME	"veth"
 #define DRV_VERSION	"1.0"
 
+#define MIN_MTU 68		/* Min L3 MTU */
+#define MAX_MTU 65535		/* Max L3 MTU (arbitrary) */
+#define MTU_PAD (ETH_HLEN + 4)  /* Max difference between L2 and L3 size MTU */
+
 struct veth_net_stats {
 	unsigned long	rx_packets;
 	unsigned long	tx_packets;
@@ -159,7 +163,7 @@  static int veth_xmit(struct sk_buff *skb, struct net_device *dev)
 	cpu = smp_processor_id();
 	stats = per_cpu_ptr(priv->stats, cpu);
 
-	if (!(rcv->flags & IFF_UP))
+	if (!(rcv->flags & IFF_UP) || (skb->len > (rcv->mtu + MTU_PAD)))
 		goto outf;
 
 	skb->pkt_type = PACKET_HOST;
@@ -249,6 +253,19 @@  static int veth_close(struct net_device *dev)
 	return 0;
 }
 
+static int is_valid_veth_mtu(int new_mtu)
+{
+	return (new_mtu >= MIN_MTU && new_mtu <= MAX_MTU);
+}
+
+static int veth_change_mtu(struct net_device *dev, int new_mtu)
+{
+	if (is_valid_veth_mtu(new_mtu))
+		return -EINVAL;
+	dev->mtu = new_mtu;
+	return 0;
+}
+
 static int veth_dev_init(struct net_device *dev)
 {
 	struct veth_net_stats *stats;
@@ -277,6 +294,7 @@  static const struct net_device_ops veth_netdev_ops = {
 	.ndo_open            = veth_open,
 	.ndo_stop            = veth_close,
 	.ndo_start_xmit      = veth_xmit,
+	.ndo_change_mtu      = veth_change_mtu,
 	.ndo_get_stats       = veth_get_stats,
 	.ndo_set_mac_address = eth_mac_addr,
 };
@@ -303,6 +321,10 @@  static int veth_validate(struct nlattr *tb[], struct nlattr *data[])
 		if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
 			return -EADDRNOTAVAIL;
 	}
+	if (tb[IFLA_MTU]) {
+		if (is_valid_veth_mtu(nla_get_u32(tb[IFLA_MTU])))
+			return -EINVAL;
+	}
 	return 0;
 }