netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Garzik <jeff@garzik.org>
To: David Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org, davej@redhat.com,
	auke-jan.h.kok@intel.com, ajax@redhat.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] e1000, e1000e valid-addr fixes
Date: Tue, 23 Oct 2007 22:20:30 -0400	[thread overview]
Message-ID: <471EABEE.8030900@garzik.org> (raw)
In-Reply-To: <20071023.180744.115914004.davem@davemloft.net>

[-- Attachment #1: Type: text/plain, Size: 649 bytes --]

David Miller wrote:
> From: Jeff Garzik <jeff@garzik.org>
> Date: Tue, 23 Oct 2007 21:03:36 -0400
> 
>> I'm wondering if there is a way to avoid adding
>>
>> 	if (!is_valid_ether_addr(dev->dev_addr))
>> 		return -EINVAL;
>>
>> to every ethernet driver's ->open() hook.
> 
> The first idea I get is:
> 
> 1) Create netdev->validate_dev_addr().
> 
> 2) If it exists, invoke it before ->open(), abort
>    and return if any errors signaled.
> 
> etherdev init hooks up a function that does the above
> check, which allows us to avoid editing every ethernet
> driver
> 
> What do you think?

Seems sane to me.  Something like this (attached)?

	Jeff




[-- Attachment #2: patch.validate-addr --]
[-- Type: text/plain, Size: 2000 bytes --]

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 4a3f54e..962d1de 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -669,6 +669,8 @@ struct net_device
 #define HAVE_SET_MAC_ADDR  		 
 	int			(*set_mac_address)(struct net_device *dev,
 						   void *addr);
+#define HAVE_VALIDATE_ADDR  		 
+	int			(*validate_addr)(struct net_device *dev);
 #define HAVE_PRIVATE_IOCTL
 	int			(*do_ioctl)(struct net_device *dev,
 					    struct ifreq *ifr, int cmd);
diff --git a/net/core/dev.c b/net/core/dev.c
index 8726589..f861555 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1007,17 +1007,20 @@ int dev_open(struct net_device *dev)
 	 *	Call device private open method
 	 */
 	set_bit(__LINK_STATE_START, &dev->state);
-	if (dev->open) {
+
+	if (dev->validate_addr)
+		ret = dev->validate_addr(dev);
+
+	if (!ret && dev->open)
 		ret = dev->open(dev);
-		if (ret)
-			clear_bit(__LINK_STATE_START, &dev->state);
-	}
 
 	/*
 	 *	If it went open OK then:
 	 */
 
-	if (!ret) {
+	if (ret)
+		clear_bit(__LINK_STATE_START, &dev->state);
+	else {
 		/*
 		 *	Set the flags.
 		 */
@@ -1038,6 +1041,7 @@ int dev_open(struct net_device *dev)
 		 */
 		call_netdevice_notifiers(NETDEV_UP, dev);
 	}
+
 	return ret;
 }
 
diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c
index ed8a3d4..5471cd2 100644
--- a/net/ethernet/eth.c
+++ b/net/ethernet/eth.c
@@ -298,6 +298,14 @@ static int eth_change_mtu(struct net_device *dev, int new_mtu)
 	return 0;
 }
 
+static int eth_validate_addr(struct net_device *dev)
+{
+	if (!is_valid_ether_addr(dev->dev_addr))
+		return -EINVAL;
+	
+	return 0;
+}
+
 const struct header_ops eth_header_ops ____cacheline_aligned = {
 	.create		= eth_header,
 	.parse		= eth_header_parse,
@@ -317,6 +325,7 @@ void ether_setup(struct net_device *dev)
 
 	dev->change_mtu		= eth_change_mtu;
 	dev->set_mac_address 	= eth_mac_addr;
+	dev->validate_addr	= eth_validate_addr;
 
 	dev->type		= ARPHRD_ETHER;
 	dev->hard_header_len 	= ETH_HLEN;

  reply	other threads:[~2007-10-24  2:20 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <11931515302013-git-send-email-ajax@redhat.com>
     [not found] ` <471E1ECD.80002@intel.com>
     [not found]   ` <1193156487.26974.39.camel@localhost.localdomain>
     [not found]     ` <471E2AD0.1000500@intel.com>
2007-10-23 20:40       ` [PATCH] Add eeprom_bad_csum_allow module option to e1000 Jeff Garzik
2007-10-23 21:01         ` Kok, Auke
2007-10-23 21:51           ` David Miller
2007-10-23 21:20         ` Dave Jones
2007-10-23 21:38           ` Alan Cox
2007-10-23 21:53           ` David Miller
2007-10-23 23:19             ` Kok, Auke
2007-10-24  0:55             ` [PATCH] e1000, e1000e valid-addr fixes Jeff Garzik
2007-10-24  1:03               ` Jeff Garzik
2007-10-24  1:07                 ` David Miller
2007-10-24  2:20                   ` Jeff Garzik [this message]
2007-10-24  2:23                     ` David Miller
2007-11-01 18:04                       ` Kok, Auke
2007-11-01 18:47                         ` Jeff Garzik
2007-11-01 18:11                     ` Stephen Hemminger
2007-11-01 19:31                       ` Jeff Garzik
2007-10-24  1:15               ` Adrian Bunk
2007-10-23 23:03           ` [PATCH] Add eeprom_bad_csum_allow module option to e1000 Kok, Auke
2007-10-23 23:53             ` Stephen Hemminger
2007-10-24  5:38             ` Dave Jones
2007-10-23 21:48         ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=471EABEE.8030900@garzik.org \
    --to=jeff@garzik.org \
    --cc=ajax@redhat.com \
    --cc=auke-jan.h.kok@intel.com \
    --cc=davej@redhat.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).