Allow user to change the device's MAC address.
[cascardo/kernel/samples/netdev/.git] / ndeth.c
diff --git a/ndeth.c b/ndeth.c
index ec6be59..613ef64 100644 (file)
--- a/ndeth.c
+++ b/ndeth.c
 #include <linux/module.h>
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
+#include <linux/workqueue.h>
 
 MODULE_LICENSE("GPL");
 
+static void work_ndeth(struct work_struct *work)
+{
+       printk(KERN_DEBUG "doing ndeth work\n");
+}
+
+static DECLARE_DELAYED_WORK(ndeth_work, work_ndeth);
+
 static int ndeth_open(struct net_device *dev)
 {
        printk(KERN_DEBUG "ndeth open\n");
+       schedule_delayed_work(&ndeth_work, 4 * HZ);
        return 0;
 }
 
 static int ndeth_stop(struct net_device *dev)
 {
        printk(KERN_DEBUG "ndeth stop\n");
+       cancel_delayed_work_sync(&ndeth_work);
        return 0;
 }
 
@@ -45,6 +55,7 @@ static const struct net_device_ops ndeth_ops = {
        .ndo_open = ndeth_open,
        .ndo_stop = ndeth_stop,
        .ndo_start_xmit = ndeth_tx,
+       .ndo_set_mac_address = eth_mac_addr,
 };
 
 struct net_device *ndeth;
@@ -52,10 +63,13 @@ struct net_device *ndeth;
 static __init int ndeth_init(void)
 {
        int r = -ENOMEM;
+       char addr[ETH_ALEN];
        ndeth = alloc_etherdev(0);
        if (!ndeth)
                goto out;
        ndeth->netdev_ops = &ndeth_ops;
+       random_ether_addr(addr);
+       memcpy(ndeth->dev_addr, addr, ETH_ALEN);
        r = register_netdev(ndeth);
        if (r)
                goto reg_out;