Skip to contentSkip to conversation

veth: Fix carrier detect

PATCH Applied Eric W. Biederman 3 participants 6 messages Feb 26, 2009 – Mar 2, 2009 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 veth: Fix carrier detect

The current implementation of carrier detect in veth is broken. It reports the link is down until both sides of the veth pair are administatively up and then forever after it reports link up.

So fix veth so that it only reports link up when both interfaces of the pair are administratively up.

---
 drivers/net/veth.c |   51 +++++++++++----------------------------------------
 1 files changed, 11 insertions(+), 40 deletions(-)
drivers/net/veth.c +11 -40
index 108bbbe..124fe75 100644
@@ -239,6 +239,16 @@ static int veth_open(struct net_device *dev)
 	return 0;
 }
 
+static int veth_close(struct net_device *dev)
+{
+	struct veth_priv *priv = netdev_priv(dev);
+
+	netif_carrier_off(dev);
+	netif_carrier_off(priv->peer);
+
+	return 0;
+}
+
 static int veth_dev_init(struct net_device *dev)
 {
 	struct veth_net_stats *stats;
@@ -265,6 +275,7 @@ static void veth_dev_free(struct net_device *dev)
 static const struct net_device_ops veth_netdev_ops = {
 	.ndo_init            = veth_dev_init,
 	.ndo_open            = veth_open,
+	.ndo_stop            = veth_close,
 	.ndo_start_xmit      = veth_xmit,
 	.ndo_get_stats       = veth_get_stats,
 	.ndo_set_mac_address = eth_mac_addr,
@@ -280,44 +291,6 @@ static void veth_setup(struct net_device *dev)
 	dev->destructor = veth_dev_free;
 }
 
-static void veth_change_state(struct net_device *dev)
-{
-	struct net_device *peer;
-	struct veth_priv *priv;
-
-	priv = netdev_priv(dev);
-	peer = priv->peer;
-
-	if (netif_carrier_ok(peer)) {
-		if (!netif_carrier_ok(dev))
-			netif_carrier_on(dev);
-	} else {
-		if (netif_carrier_ok(dev))
-			netif_carrier_off(dev);
-	}
-}
-
-static int veth_device_event(struct notifier_block *unused,
-			     unsigned long event, void *ptr)
-{
-	struct net_device *dev = ptr;
-
-	if (dev->netdev_ops->ndo_open != veth_open)
-		goto out;
-
-	switch (event) {
-	case NETDEV_CHANGE:
-		veth_change_state(dev);
-		break;
-	}
-out:
-	return NOTIFY_DONE;
-}
-
-static struct notifier_block veth_notifier_block __read_mostly = {
-	.notifier_call	= veth_device_event,
-};
-
 /*
  * netlink interface
  */
@@ -468,14 +441,12 @@ static struct rtnl_link_ops veth_link_ops = {
 
 static __init int veth_init(void)
 {
-	register_netdevice_notifier(&veth_notifier_block);
 	return rtnl_link_register(&veth_link_ops);
 }
 
 static __exit void veth_exit(void)
 {
 	rtnl_link_unregister(&veth_link_ops);
-	unregister_netdevice_notifier(&veth_notifier_block);
 }
 
 module_init(veth_init);
Signature · 1 line
1.6.1.2.350.g88cc
#1 lore raw

PATCH 2/2 veth: Configurable nterface MTU

The limitation to only 1500 byte mtu's limits the utility of the veth device for testing routing.

---
 drivers/net/veth.c |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)
drivers/net/veth.c +23 -1
index 124fe75..88778bb 100644
@@ -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;
 }
 
Signature · 1 line
1.6.1.2.350.g88cc
maintainer
#2 lore raw

Re: [PATCH 2/2] veth: Configurable nterface MTU

From: [email protected] (Eric W. Biederman)
Date: Wed, 25 Feb 2009 21:49:04 -0800

Quoted 7 lines
drivers/net/veth.c +3 -0
@@ -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);

drivers/net/veth.c static int veth_close(struct net_device *dev) · line 268

Quoted 10 lines
drivers/net/veth.c +10 -0
+}
+
+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?

#3 lore raw

Re: [PATCH 2/2] veth: Configurable nterface MTU

Quoted 7 lines · David Miller

From: [email protected] (Eric W. Biederman)
Date: Wed, 25 Feb 2009 21:49:04 -0800

Quoted 4 lines
drivers/net/veth.c +0 -0
@@ -249,6 +253,19 @@ static int veth_close(struct net_device *dev)
 	return 0;
 }
 
Quoted 15 lines

drivers/net/veth.c static int veth_close(struct net_device *dev) · line 268

Quoted 13 lines
drivers/net/veth.c +13 -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

#5 lore raw

Re: [PATCH 2/2] veth: Configurable nterface MTU

In reply to a message not in the archive

From: ebiederm-aS9lmoZGLiVWk0Htik3J/[email protected] (Eric W. Biederman)
Date: Fri, 27 Feb 2009 04:41:48 -0800

Quoted 25 lines
Quoted 7 lines · David Miller

From: ebiederm-aS9lmoZGLiVWk0Htik3J/[email protected] (Eric W. Biederman)
Date: Wed, 25 Feb 2009 21:49:04 -0800

Quoted 4 lines
drivers/net/veth.c +0 -0
@@ -249,6 +253,19 @@ static int veth_close(struct net_device *dev)
 	return 0;
 }
 
Quoted 15 lines

drivers/net/veth.c static int veth_close(struct net_device *dev) · line 268

Quoted 13 lines
drivers/net/veth.c +13 -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?

Quoted 1 line

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.

maintainer Applied
#6 lore raw
In reply to Eric W. Biederman

From: [email protected] (Eric W. Biederman)
Date: Wed, 25 Feb 2009 21:47:29 -0800

Quoted 9 lines

The current implementation of carrier detect in veth is broken. It reports the link is down until both sides of the veth pair are administatively up and then forever after it reports link up.

So fix veth so that it only reports link up when both interfaces of the pair are administratively up.

Applied.