From bc37c2ad11d37fdd90dcf934c0c358f070919439 Mon Sep 17 00:00:00 2001 From: Koen Kooi Date: Thu, 18 Apr 2013 15:36:53 +0200 Subject: [PATCH] fixmac: a udev rule to generate a random MAC address when needed for eth* devices This replaces 'genmac' which only works when using 'ifupdown' as networkmanager. Signed-off-by: Koen Kooi --- recipes-bsp/fixmac/fixmac.bb | 21 +++++++++++++++++++++ recipes-bsp/fixmac/fixmac/fixmac.rules | 1 + recipes-bsp/fixmac/fixmac/fixmac.sh | 10 ++++++++++ recipes-bsp/fixmac/ranpwd_git.bb | 24 ++++++++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 recipes-bsp/fixmac/fixmac.bb create mode 100644 recipes-bsp/fixmac/fixmac/fixmac.rules create mode 100755 recipes-bsp/fixmac/fixmac/fixmac.sh create mode 100644 recipes-bsp/fixmac/ranpwd_git.bb diff --git a/recipes-bsp/fixmac/fixmac.bb b/recipes-bsp/fixmac/fixmac.bb new file mode 100644 index 0000000..3b50c77 --- /dev/null +++ b/recipes-bsp/fixmac/fixmac.bb @@ -0,0 +1,21 @@ +SUMMARY = "Provide random MAC address for devices with 00:00:00:00:00 as MAC address" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=3f40d7994397109285ec7b81fdeb3b58" + + +SRC_URI = "file://fixmac.sh \ + file://fixmac.rules" + + +do_install() { + install -d ${D}${sysconfdir}/udev/rules.d + install -m 0644 ${WORKDIR}/fixmac.rules ${D}${sysconfdir}/udev/rules.d + + install -d ${D}${bindir} + install -m 0755 ${WORKDIR}/fixmac.sh ${D}${bindir} + + sed -i -e s:/sbin:${base_sbindir}:g -e s:/etc:${sysconfdir}:g ${D}${bindir}/fixmac.sh + +} + +RDEPENDS_${PN} = "ranpwd" diff --git a/recipes-bsp/fixmac/fixmac/fixmac.rules b/recipes-bsp/fixmac/fixmac/fixmac.rules new file mode 100644 index 0000000..740361b --- /dev/null +++ b/recipes-bsp/fixmac/fixmac/fixmac.rules @@ -0,0 +1 @@ +KERNEL=="eth*", ACTION=="add", ATTR{address}=="00:00:00:00:00:00", RUN += "/usr/bin/fixmac.sh %k" diff --git a/recipes-bsp/fixmac/fixmac/fixmac.sh b/recipes-bsp/fixmac/fixmac/fixmac.sh new file mode 100755 index 0000000..9646808 --- /dev/null +++ b/recipes-bsp/fixmac/fixmac/fixmac.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +if [ -e /etc/ethernetmac.$1 ] ; then + MACADDRESS="$(cat /etc/ethernetmac.$1)" +else + MACADDRESS="$(ranpwd -m)" + echo ${MACADDRESS} > /etc/ethernetmac.$1 +fi + +/sbin/ifconfig $1 hw ether ${MACADDRESS} && /sbin/ifconfig $1 up diff --git a/recipes-bsp/fixmac/ranpwd_git.bb b/recipes-bsp/fixmac/ranpwd_git.bb new file mode 100644 index 0000000..b4e0f54 --- /dev/null +++ b/recipes-bsp/fixmac/ranpwd_git.bb @@ -0,0 +1,24 @@ +DESCRIPTION = "Random password generator" +LICENSE = "GPLv2+" +LIC_FILES_CHKSUM = "file://ranpwd.c;beginline=1;endline=11;md5=0e8585e19117526efedfaeb50c345d7a" +SECTION = "console/utils" +PV = "1.2+git${SRCPV}" +PR = "r0" + +inherit autotools + +SRC_URI = "git://git.zytor.com/utils/ranpwd.git" +SRCREV = "b62aab579e288715b82d5575befaa2b8ff210c2b" + +S="${WORKDIR}/git" + +do_configure_prepend () { + if [ ! -e acinclude.m4 -a -e aclocal.m4 ]; then + cp aclocal.m4 acinclude.m4 + fi +} + +do_install() { + install -d ${D}/${bindir} + install -m 0755 ${S}/ranpwd ${D}/${bindir}/ranpwd +}