From: Danny Kukawka <danny.kukawka@bisect.de>
To: "David S. Miller" <davem@davemloft.net>
Cc: "Danny Kukawka" <dkukawka@suse.de>,
"Eric Dumazet" <eric.dumazet@gmail.com>,
"Michał Mirosław" <mirq-linux@rere.qmqm.pl>,
"Jiri Pirko" <jpirko@redhat.com>,
"Ben Hutchings" <bhutchings@solarflare.com>,
"Neil Horman" <nhorman@tuxdriver.com>,
"Randy Dunlap" <rdunlap@xenotime.net>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/8] net: validate MAC address directly in dev_set_mac_address()
Date: Wed, 29 Feb 2012 16:42:49 +0100 [thread overview]
Message-ID: <1330530176-24952-2-git-send-email-danny.kukawka@bisect.de> (raw)
In-Reply-To: <1330530176-24952-1-git-send-email-danny.kukawka@bisect.de>
Validate the given MAC address directly in dev_set_mac_address()
if a .ndo_validate_addr function is available before calling
the .ndo_set_mac_address function.
Changed .ndo_validate_addr to take a second parameter containing
a sockaddr struct to be checked instead of the net_device dev_addr.
The behaviour of .ndo_validate_addr is now: if the second parameter
is NULL the net_device->dev_addr gets validate, if != NULL
the given parameter/sockaddr gets validated instead.
Removed is_valid_ether_addr() check from eth_mac_addr() since
this is now done in dev_set_mac_address(). Adapted eth_validate_addr()
to the changes.
Signed-off-by: Danny Kukawka <danny.kukawka@bisect.de>
---
include/linux/etherdevice.h | 2 +-
include/linux/netdevice.h | 7 +++++--
net/core/dev.c | 7 ++++++-
net/ethernet/eth.c | 12 +++++++++---
4 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
index 8a18358..ee3091f 100644
--- a/include/linux/etherdevice.h
+++ b/include/linux/etherdevice.h
@@ -44,7 +44,7 @@ extern void eth_header_cache_update(struct hh_cache *hh,
const unsigned char *haddr);
extern int eth_mac_addr(struct net_device *dev, void *p);
extern int eth_change_mtu(struct net_device *dev, int new_mtu);
-extern int eth_validate_addr(struct net_device *dev);
+extern int eth_validate_addr(struct net_device *dev, void *addr);
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index f1b7d03..08186e3 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -772,8 +772,10 @@ struct netdev_fcoe_hbainfo {
* needs to be changed. If this interface is not defined, the
* mac address can not be changed.
*
- * int (*ndo_validate_addr)(struct net_device *dev);
+ * int (*ndo_validate_addr)(struct net_device *dev, void *addr);
* Test if Media Access Control address is valid for the device.
+ * If addr is NULL the Media Access Control address of the device
+ * get validated, otherwise the MAC of the net_device.
*
* int (*ndo_do_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd);
* Called when a user request an ioctl which can't be handled by
@@ -919,7 +921,8 @@ struct net_device_ops {
void (*ndo_set_rx_mode)(struct net_device *dev);
int (*ndo_set_mac_address)(struct net_device *dev,
void *addr);
- int (*ndo_validate_addr)(struct net_device *dev);
+ int (*ndo_validate_addr)(struct net_device *dev,
+ void *addr);
int (*ndo_do_ioctl)(struct net_device *dev,
struct ifreq *ifr, int cmd);
int (*ndo_set_config)(struct net_device *dev,
diff --git a/net/core/dev.c b/net/core/dev.c
index 763a0ed..b26a287 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1162,7 +1162,7 @@ static int __dev_open(struct net_device *dev)
set_bit(__LINK_STATE_START, &dev->state);
if (ops->ndo_validate_addr)
- ret = ops->ndo_validate_addr(dev);
+ ret = ops->ndo_validate_addr(dev, NULL);
if (!ret && ops->ndo_open)
ret = ops->ndo_open(dev);
@@ -4820,6 +4820,11 @@ int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa)
return -EINVAL;
if (!netif_device_present(dev))
return -ENODEV;
+ if (ops->ndo_validate_addr) {
+ err = ops->ndo_validate_addr(dev, sa);
+ if (err)
+ return err;
+ }
err = ops->ndo_set_mac_address(dev, sa);
if (!err)
call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c
index a93af86..d25cc7a 100644
--- a/net/ethernet/eth.c
+++ b/net/ethernet/eth.c
@@ -285,8 +285,6 @@ int eth_mac_addr(struct net_device *dev, void *p)
if (netif_running(dev))
return -EBUSY;
- if (!is_valid_ether_addr(addr->sa_data))
- return -EADDRNOTAVAIL;
memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
/* if device marked as NET_ADDR_RANDOM, reset it */
dev->addr_assign_type &= ~NET_ADDR_RANDOM;
@@ -311,8 +309,16 @@ int eth_change_mtu(struct net_device *dev, int new_mtu)
}
EXPORT_SYMBOL(eth_change_mtu);
-int eth_validate_addr(struct net_device *dev)
+int eth_validate_addr(struct net_device *dev, void *addr)
{
+ struct sockaddr *saddr;
+
+ if (addr) {
+ saddr = addr;
+ if (!is_valid_ether_addr(saddr->sa_data))
+ return -EADDRNOTAVAIL;
+ }
+
if (!is_valid_ether_addr(dev->dev_addr))
return -EADDRNOTAVAIL;
--
1.7.8.3
next prev parent reply other threads:[~2012-02-29 15:43 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-29 16:08 [PATCH 0/8] validate MAC address before call .ndo_set_mac_address Danny Kukawka
2012-02-29 15:42 ` Danny Kukawka [this message]
2012-02-29 15:42 ` [PATCH 2/8] bnx2x: adopt bnx2x_validate_addr() to .ndo_validate_addr changes Danny Kukawka
2012-02-29 16:22 ` Dmitry Kravkov
2012-02-29 17:08 ` Danny Kukawka
2012-02-29 17:16 ` Dmitry Kravkov
2012-02-29 17:20 ` Dmitry Kravkov
2012-02-29 15:42 ` [PATCH 3/8] cris/eth_v10: use dev_set_mac_address() instead of e100_set_mac_address() Danny Kukawka
2012-03-01 9:33 ` Jesper Nilsson
2012-02-29 15:42 ` [PATCH 4/8] bcm63xx_enet: use dev_set_mac_address() instead of bcm_enet_set_mac_address() Danny Kukawka
2012-02-29 15:49 ` Florian Fainelli
2012-02-29 15:42 ` [PATCH 5/8] ethoc: add .ndo_validate_addr to net_device_ops Danny Kukawka
2012-02-29 15:42 ` [PATCH 6/8] lantiq_etop: use dev_set_mac_address() instead of ltq_etop_set_mac_address() Danny Kukawka
2012-02-29 15:42 ` [PATCH 7/8] neterion/s2io: fix s2io_set_mac_addr() to prevent double checks Danny Kukawka
2012-02-29 15:42 ` [PATCH 8/8] octeon: use dev_set_mac_address() instead of octeon_mgmt_set_mac_address() Danny Kukawka
2012-02-29 15:58 ` [PATCH 0/8] validate MAC address before call .ndo_set_mac_address Ben Hutchings
2012-02-29 16:14 ` Danny Kukawka
2012-02-29 16:24 ` Danny Kukawka
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=1330530176-24952-2-git-send-email-danny.kukawka@bisect.de \
--to=danny.kukawka@bisect.de \
--cc=bhutchings@solarflare.com \
--cc=davem@davemloft.net \
--cc=dkukawka@suse.de \
--cc=eric.dumazet@gmail.com \
--cc=jpirko@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mirq-linux@rere.qmqm.pl \
--cc=netdev@vger.kernel.org \
--cc=nhorman@tuxdriver.com \
--cc=rdunlap@xenotime.net \
/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).