Author: simon Date: 2009-12-30 00:28:34 +0000 (Wed, 30 Dec 2009) New Revision: 1518
Modified: trunk/batman-adv-kernelland/soft-interface.c trunk/batman-adv-kernelland/translation-table.c trunk/batman-adv-kernelland/translation-table.h Log: Staging: batman-adv: Allow the MAC address to be set
Some embedded devices have very limited sources of entropy for the random number generator. It has been observed that the random MAC address on the interface bat0 is not always random. When testing with a collection of identical hardware, sometimes the bat0 device the same MAC address on multiple devices, causing mayhem. This patch allows the MAC address to be set by the user.
Signed-off-by: Andrew Lunn andrew@lunn.ch Signed-off-by: Simon Wunderlich siwu@hrz.tu-chemnitz.de
Modified: trunk/batman-adv-kernelland/soft-interface.c =================================================================== --- trunk/batman-adv-kernelland/soft-interface.c 2009-12-29 15:47:31 UTC (rev 1517) +++ trunk/batman-adv-kernelland/soft-interface.c 2009-12-30 00:28:34 UTC (rev 1518) @@ -145,9 +145,19 @@ return &priv->stats; }
-int interface_set_mac_addr(struct net_device *dev, void *addr) +int interface_set_mac_addr(struct net_device *dev, void *p) { - return -EBUSY; + struct sockaddr *addr = p; + unsigned long flags; + + if (!is_valid_ether_addr(addr->sa_data)) + return -EADDRNOTAVAIL; + + hna_local_remove(dev->dev_addr, "mac address changed"); + memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); + hna_local_add(dev->dev_addr); + + return 0; }
int interface_change_mtu(struct net_device *dev, int new_mtu)
Modified: trunk/batman-adv-kernelland/translation-table.c =================================================================== --- trunk/batman-adv-kernelland/translation-table.c 2009-12-29 15:47:31 UTC (rev 1517) +++ trunk/batman-adv-kernelland/translation-table.c 2009-12-30 00:28:34 UTC (rev 1518) @@ -211,6 +211,21 @@ _hna_local_del(hna_local_entry); }
+void hna_local_remove(uint8_t *addr, char *message) +{ + struct hna_local_entry *hna_local_entry; + unsigned long flags; + + spin_lock_irqsave(&hna_local_hash_lock, flags); + + hna_local_entry = (struct hna_local_entry *) + hash_find(hna_local_hash, addr); + if (hna_local_entry) + hna_local_del(hna_local_entry, message); + + spin_unlock_irqrestore(&hna_local_hash_lock, flags); +} + void hna_local_purge(struct work_struct *work) { struct hna_local_entry *hna_local_entry;
Modified: trunk/batman-adv-kernelland/translation-table.h =================================================================== --- trunk/batman-adv-kernelland/translation-table.h 2009-12-29 15:47:31 UTC (rev 1517) +++ trunk/batman-adv-kernelland/translation-table.h 2009-12-30 00:28:34 UTC (rev 1518) @@ -23,6 +23,7 @@
int hna_local_init(void); void hna_local_add(uint8_t *addr); +void hna_local_remove(uint8_t *addr, char *message); int hna_local_fill_buffer(unsigned char *buff, int buff_len); int hna_local_fill_buffer_text(unsigned char *buff, int buff_len); void hna_local_purge(struct work_struct *work);