* [PATCH] dummy -- support hardware address
@ 2004-04-08 18:08 Stephen Hemminger
2004-04-08 21:54 ` David S. Miller
0 siblings, 1 reply; 8+ messages in thread
From: Stephen Hemminger @ 2004-04-08 18:08 UTC (permalink / raw)
To: David S. Miller; +Cc: netdev
Dummy device comes in handy for testing, but it always has address
of all zero's which isn't a valid ethernet address. This generates
a simple fake address and allows changing the address.
diff -Nru a/drivers/net/dummy.c b/drivers/net/dummy.c
--- a/drivers/net/dummy.c Thu Apr 8 11:03:02 2004
+++ b/drivers/net/dummy.c Thu Apr 8 11:03:02 2004
@@ -86,6 +86,15 @@
return dev->priv;
}
+
+static int dummy_set_address(struct net_device *dev, void *p)
+{
+ struct sockaddr *sa = p;
+
+ memcpy(dev->dev_addr, sa->sa_data, dev->addr_len);
+ return 0;
+}
+
static struct net_device **dummies;
/* Number of dummy devices to be set up by this module. */
@@ -101,6 +110,16 @@
if (!dev_dummy)
return -ENOMEM;
+
+ /* Generate intial fake hardware address */
+ dev_dummy->dev_addr[0] = 0x00;
+ dev_dummy->dev_addr[1] = 0xdd;
+ dev_dummy->dev_addr[2] = 0xdd;
+ dev_dummy->dev_addr[3] = index >> 16;
+ dev_dummy->dev_addr[4] = index >> 8;
+ dev_dummy->dev_addr[5] = index;
+
+ dev_dummy->set_mac_address = dummy_set_address;
if ((err = register_netdev(dev_dummy))) {
free_netdev(dev_dummy);
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] dummy -- support hardware address
2004-04-08 18:08 [PATCH] dummy -- support hardware address Stephen Hemminger
@ 2004-04-08 21:54 ` David S. Miller
2004-04-08 22:09 ` Stephen Hemminger
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: David S. Miller @ 2004-04-08 21:54 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev
Stephen, why don't you do what usbnet does? Look at usbnet_init()
where it goes:
get_random_bytes (node_id, sizeof node_id);
node_id [0] &= 0xfe; // clear multicast bit
node_id [0] |= 0x02; // set local assignment bit (IEEE802)
I distinctly remember Alan Cox saying this was the right way
do this and avoid conflicts with Vendor assigned IDs.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] dummy -- support hardware address
2004-04-08 21:54 ` David S. Miller
@ 2004-04-08 22:09 ` Stephen Hemminger
2004-04-09 18:45 ` [PATCH] (1/4) add random_ether_addr to ether_device.h Stephen Hemminger
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Stephen Hemminger @ 2004-04-08 22:09 UTC (permalink / raw)
To: David S. Miller; +Cc: netdev
On Thu, 8 Apr 2004 14:54:03 -0700
"David S. Miller" <davem@redhat.com> wrote:
>
> Stephen, why don't you do what usbnet does? Look at usbnet_init()
> where it goes:
>
> get_random_bytes (node_id, sizeof node_id);
> node_id [0] &= 0xfe; // clear multicast bit
> node_id [0] |= 0x02; // set local assignment bit (IEEE802)
>
> I distinctly remember Alan Cox saying this was the right way
> do this and avoid conflicts with Vendor assigned IDs.
That would work better, just worried about draining the entropy pool
when I create 1000 dummies in a test script.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] (1/4) add random_ether_addr to ether_device.h
2004-04-08 21:54 ` David S. Miller
2004-04-08 22:09 ` Stephen Hemminger
@ 2004-04-09 18:45 ` Stephen Hemminger
2004-04-09 18:45 ` [PATCH] (3/4) usb gadget -- use random_ether_addr Stephen Hemminger
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Stephen Hemminger @ 2004-04-09 18:45 UTC (permalink / raw)
To: David S. Miller; +Cc: netdev, linux-usb-devel
Since generating a random ethernet address needs to be done
in several drivers, add a random_ether_addr function to etherdevice.h
diff -Nru a/include/linux/etherdevice.h b/include/linux/etherdevice.h
--- a/include/linux/etherdevice.h Fri Apr 9 11:33:59 2004
+++ b/include/linux/etherdevice.h Fri Apr 9 11:33:59 2004
@@ -25,6 +25,7 @@
#define _LINUX_ETHERDEVICE_H
#include <linux/if_ether.h>
+#include <linux/random.h>
#ifdef __KERNEL__
extern int eth_header(struct sk_buff *skb, struct net_device *dev,
@@ -64,6 +65,19 @@
return !(addr[0]&1) && memcmp( addr, zaddr, 6);
}
+/**
+ * random_ether_addr - Generate software assigned random Ethernet address
+ * @addr: Pointer to a six-byte array containing the Ethernet address
+ *
+ * Generate a random Ethernet address (MAC) that is not multicast
+ * and has the local assigned bit set.
+ */
+static inline void random_ether_addr(u8 *addr)
+{
+ get_random_bytes (addr, ETH_ALEN);
+ addr [0] &= 0xfe; /* clear multicast bit */
+ addr [0] |= 0x02; /* set local assignment bit (IEEE802) */
+}
#endif
#endif /* _LINUX_ETHERDEVICE_H */
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] (3/4) usb gadget -- use random_ether_addr
2004-04-08 21:54 ` David S. Miller
2004-04-08 22:09 ` Stephen Hemminger
2004-04-09 18:45 ` [PATCH] (1/4) add random_ether_addr to ether_device.h Stephen Hemminger
@ 2004-04-09 18:45 ` Stephen Hemminger
2004-04-09 18:45 ` [PATCH] (2/4) set random address in dummy Stephen Hemminger
2004-04-09 18:47 ` [PATCH] (4/4) usbnet -- use random_ether_addr Stephen Hemminger
4 siblings, 0 replies; 8+ messages in thread
From: Stephen Hemminger @ 2004-04-09 18:45 UTC (permalink / raw)
To: David S. Miller; +Cc: netdev, linux-usb-devel
Use new common code in ether_device.h for random_ether_addr.
Same exact code just in one common place.
diff -Nru a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
--- a/drivers/usb/gadget/ether.c Fri Apr 9 11:39:51 2004
+++ b/drivers/usb/gadget/ether.c Fri Apr 9 11:39:51 2004
@@ -1804,17 +1804,13 @@
/* one random address for the gadget device ... both of these could
* reasonably come from an id prom or a module parameter.
*/
- get_random_bytes (net->dev_addr, ETH_ALEN);
- net->dev_addr [0] &= 0xfe; // clear multicast bit
- net->dev_addr [0] |= 0x02; // set local assignment bit (IEEE802)
+ random_ether_addr(net->dev_addr);
#ifdef DEV_CONFIG_CDC
/* ... another address for the host, on the other end of the
* link, gets exported through CDC (see CDC spec table 41)
*/
- get_random_bytes (node_id, sizeof node_id);
- node_id [0] &= 0xfe; // clear multicast bit
- node_id [0] |= 0x02; // set local assignment bit (IEEE802)
+ random_ether_addr(node_id);
snprintf (ethaddr, sizeof ethaddr, "%02X%02X%02X%02X%02X%02X",
node_id [0], node_id [1], node_id [2],
node_id [3], node_id [4], node_id [5]);
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] (2/4) set random address in dummy
2004-04-08 21:54 ` David S. Miller
` (2 preceding siblings ...)
2004-04-09 18:45 ` [PATCH] (3/4) usb gadget -- use random_ether_addr Stephen Hemminger
@ 2004-04-09 18:45 ` Stephen Hemminger
2004-04-09 18:47 ` [PATCH] (4/4) usbnet -- use random_ether_addr Stephen Hemminger
4 siblings, 0 replies; 8+ messages in thread
From: Stephen Hemminger @ 2004-04-09 18:45 UTC (permalink / raw)
To: David S. Miller; +Cc: netdev, linux-usb-devel
Fix several things in dummy device to make it more useable.
* add MODULE_PARAM_DESC for num_dummies
* set initial random ether address
* allow changing address
diff -Nru a/drivers/net/dummy.c b/drivers/net/dummy.c
--- a/drivers/net/dummy.c Fri Apr 9 11:33:59 2004
+++ b/drivers/net/dummy.c Fri Apr 9 11:33:59 2004
@@ -32,6 +32,7 @@
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
#include <linux/init.h>
#include <linux/moduleparam.h>
@@ -40,6 +41,17 @@
static int dummy_xmit(struct sk_buff *skb, struct net_device *dev);
static struct net_device_stats *dummy_get_stats(struct net_device *dev);
+static int dummy_set_address(struct net_device *dev, void *p)
+{
+ struct sockaddr *sa = p;
+
+ if (!is_valid_ether_addr(sa->sa_data))
+ return -EADDRNOTAVAIL;
+
+ memcpy(dev->dev_addr, sa->sa_data, ETH_ALEN);
+ return 0;
+}
+
/* fake multicast ability */
static void set_multicast_list(struct net_device *dev)
{
@@ -58,6 +70,7 @@
dev->get_stats = dummy_get_stats;
dev->hard_start_xmit = dummy_xmit;
dev->set_multicast_list = set_multicast_list;
+ dev->set_mac_address = dummy_set_address;
#ifdef CONFIG_NET_FASTROUTE
dev->accept_fastpath = dummy_accept_fastpath;
#endif
@@ -68,6 +81,7 @@
dev->flags |= IFF_NOARP;
dev->flags &= ~IFF_MULTICAST;
SET_MODULE_OWNER(dev);
+ random_ether_addr(dev->dev_addr);
}
static int dummy_xmit(struct sk_buff *skb, struct net_device *dev)
@@ -90,6 +104,7 @@
/* Number of dummy devices to be set up by this module. */
module_param(numdummies, int, 0);
+MODULE_PARM_DESC(numdimmies, "Number of dummy psuedo devices");
static int __init dummy_init_one(int index)
{
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] (4/4) usbnet -- use random_ether_addr
2004-04-08 21:54 ` David S. Miller
` (3 preceding siblings ...)
2004-04-09 18:45 ` [PATCH] (2/4) set random address in dummy Stephen Hemminger
@ 2004-04-09 18:47 ` Stephen Hemminger
2004-04-10 4:16 ` David S. Miller
4 siblings, 1 reply; 8+ messages in thread
From: Stephen Hemminger @ 2004-04-09 18:47 UTC (permalink / raw)
To: David S. Miller; +Cc: netdev, linux-usb-devel
Same code to generate random_ether_address is in ether_device.h (patch1)
so use it for usbnet.
diff -Nru a/drivers/usb/net/usbnet.c b/drivers/usb/net/usbnet.c
--- a/drivers/usb/net/usbnet.c Fri Apr 9 11:41:19 2004
+++ b/drivers/usb/net/usbnet.c Fri Apr 9 11:41:19 2004
@@ -3414,9 +3414,7 @@
< sizeof (struct cdc_state)));
#endif
- get_random_bytes (node_id, sizeof node_id);
- node_id [0] &= 0xfe; // clear multicast bit
- node_id [0] |= 0x02; // set local assignment bit (IEEE802)
+ random_ether_addr(node_id);
return usb_register(&usbnet_driver);
}
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] (4/4) usbnet -- use random_ether_addr
2004-04-09 18:47 ` [PATCH] (4/4) usbnet -- use random_ether_addr Stephen Hemminger
@ 2004-04-10 4:16 ` David S. Miller
0 siblings, 0 replies; 8+ messages in thread
From: David S. Miller @ 2004-04-10 4:16 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev, linux-usb-devel
All 4 patches applied, thanks Stephen.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2004-04-10 4:16 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-08 18:08 [PATCH] dummy -- support hardware address Stephen Hemminger
2004-04-08 21:54 ` David S. Miller
2004-04-08 22:09 ` Stephen Hemminger
2004-04-09 18:45 ` [PATCH] (1/4) add random_ether_addr to ether_device.h Stephen Hemminger
2004-04-09 18:45 ` [PATCH] (3/4) usb gadget -- use random_ether_addr Stephen Hemminger
2004-04-09 18:45 ` [PATCH] (2/4) set random address in dummy Stephen Hemminger
2004-04-09 18:47 ` [PATCH] (4/4) usbnet -- use random_ether_addr Stephen Hemminger
2004-04-10 4:16 ` David S. Miller
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).