From patchwork Fri Feb 17 21:18:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 1549 Return-Path: Received: from v3-1039.vlinux.de (narfation.org [79.140.41.39]) by open-mesh.org (Postfix) with ESMTPS id DA76660087F for ; Fri, 17 Feb 2012 22:18:51 +0100 (CET) Authentication-Results: open-mesh.org; dkim=pass (1024-bit key) header.i=@narfation.org; dkim-adsp=pass Received: from sven-desktop.home.narfation.org (p57AA114C.dip0.t-ipconnect.de [87.170.17.76]) by v3-1039.vlinux.de (Postfix) with ESMTPSA id 41C809408F for ; Fri, 17 Feb 2012 22:21:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=narfation.org; s=mail; t=1329513667; bh=QPkNPShAJDsFIMG6lY6AEAUOkKI/T0DYtiFno1D2nGI=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References; b=lriCkNXS4hJXmAR72w2W6wrlSnphrgWKygflUC40dbzKCSL3RFehLitsVtwHHuzXg gLAlSILoEssSAMxD3kTLK4jjRRrpG+2SpVHJy9RCbNUC1su3kjKg5UybI59jzSDFb0 r2F/UuTda2qEbWjucJBLb9od9CxL9LzFtYRIEe1Y= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Fri, 17 Feb 2012 22:18:46 +0100 Message-Id: <1329513526-18980-1-git-send-email-sven@narfation.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1329493411-25750-7-git-send-email-danny.kukawka@bisect.de> References: <1329493411-25750-7-git-send-email-danny.kukawka@bisect.de> Subject: [B.A.T.M.A.N.] [PATCH] batman-adv: use eth_hw_addr_random() instead of random_ether_addr() X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.13 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Feb 2012 21:18:52 -0000 From: Danny Kukawka Use eth_hw_addr_random() instead of calling random_ether_addr() to set addr_assign_type correctly to NET_ADDR_RANDOM. Remove dev_addr in interface_setup(), it's not needed anymore. Reset the state to NET_ADDR_PERM as soon as the MAC get changed via .ndo_set_mac_address. v2: use bitops, adapt to eth_hw_addr_random() Signed-off-by: Danny Kukawka [sven@narfation.org: Backported it to linux 2.6.29] Signed-off-by: Sven Eckelmann --- Important: This patch was already applied by David S. Miller in net-next.git and will be part of linux 3.3. So we have to apply this one in next. This patch should also never be sent to David (he already has it). The merge of next into master will be a little bit messy. Just delete the definition of dev_hw_addr_random in compat.h and use eth_hw_addr_random in soft-interface.c compat.h | 14 ++++++++++++++ soft-interface.c | 5 ++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/compat.h b/compat.h index 7f86b41..95b8706 100644 --- a/compat.h +++ b/compat.h @@ -104,6 +104,10 @@ static inline int __param_set_copystring(const char *val, } #define param_set_copystring __param_set_copystring +/* hack for dev->addr_assign_type &= ~NET_ADDR_RANDOM; */ +#define addr_assign_type ifindex +#define NET_ADDR_RANDOM 0 + #endif /* < KERNEL_VERSION(2, 6, 36) */ @@ -126,4 +130,14 @@ void free_rcu_tt_local_entry(struct rcu_head *rcu); #endif /* < KERNEL_VERSION(3, 0, 0) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0) + +static inline void eth_hw_addr_random(struct net_device *dev) +{ + random_ether_addr(dev->dev_addr); +} + +#endif /* < KERNEL_VERSION(3, 0, 0) */ + #endif /* _NET_BATMAN_ADV_COMPAT_H_ */ diff --git a/soft-interface.c b/soft-interface.c index 2ffdc74..37fbcb5 100644 --- a/soft-interface.c +++ b/soft-interface.c @@ -541,6 +541,7 @@ static int interface_set_mac_addr(struct net_device *dev, void *p) } memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); + dev->addr_assign_type &= ~NET_ADDR_RANDOM; return 0; } @@ -783,7 +784,6 @@ static const struct net_device_ops bat_netdev_ops = { static void interface_setup(struct net_device *dev) { struct bat_priv *priv = netdev_priv(dev); - char dev_addr[ETH_ALEN]; ether_setup(dev); @@ -800,8 +800,7 @@ static void interface_setup(struct net_device *dev) dev->hard_header_len = BAT_HEADER_LEN; /* generate random address */ - random_ether_addr(dev_addr); - memcpy(dev->dev_addr, dev_addr, ETH_ALEN); + eth_hw_addr_random(dev); SET_ETHTOOL_OPS(dev, &bat_ethtool_ops);