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 <koen@dominion.thruhere.net>
This commit is contained in:
Koen Kooi
2013-04-18 15:36:53 +02:00
parent 8f08121266
commit bc37c2ad11
4 changed files with 56 additions and 0 deletions

View File

@@ -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"

View File

@@ -0,0 +1 @@
KERNEL=="eth*", ACTION=="add", ATTR{address}=="00:00:00:00:00:00", RUN += "/usr/bin/fixmac.sh %k"

View File

@@ -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

View File

@@ -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
}