mirror of
git://git.yoctoproject.org/meta-intel.git
synced 2025-07-19 12:59:03 +02:00
genmac: Replace RANDOM_MAC in network/interfaces with a randomly generated MAC
For machines that do not have a MAC in hardware and with drivers that don't generate a random one in the kernel, this init script will replace the string RANDOM_MAC in the network/interfaces file with one generated with "ranpwd -m". Care is taken to ensure multiple interfaces can use RANDOM_MAC and receive unique addresses. ranpwd generates MACs with the locally administered bit set and the multicast bit disabled. Signed-off-by: Darren Hart <dvhart@linux.intel.com> Signed-off-by: Joshua Lock <josh@linux.intel.com>
This commit is contained in:
parent
7b1d216a13
commit
c42364375a
46
meta-sys940x/recipes-bsp/genmac/files/genmac
Normal file
46
meta-sys940x/recipes-bsp/genmac/files/genmac
Normal file
|
@ -0,0 +1,46 @@
|
|||
#!/bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: Random MAC address generator
|
||||
# Required-Start: $syslog
|
||||
# Required-Stop: $syslog
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Set a random MAC for tagged interfaces
|
||||
# Description: Set a random MAC for interfaces with RANDOM_MAC
|
||||
### END INIT INFO
|
||||
|
||||
# Author: Darren Hart <dvhart@linux.intel.com>
|
||||
# Based on /etc/init.d/skeleton
|
||||
|
||||
PATH=/sbin:/usr/sbin:/bin:/usr/bin
|
||||
DESC="Set a random MAC for tagged interfaces"
|
||||
NAME=genmac
|
||||
RANPWD=`which ranpwd`
|
||||
SCRIPTNAME=/etc/init.d/$NAME
|
||||
|
||||
# Exit if ranpwd is not installed
|
||||
[ -x "$RANPWD" ] || exit 0
|
||||
|
||||
do_start() {
|
||||
# Replace every occurence of RANDOM_MAC with a unique locally
|
||||
# administered, unicast, randomly generated MAC address.
|
||||
while grep -q RANDOM_MAC /etc/network/interfaces; do
|
||||
sed -i "1,/RANDOM_MAC/s/RANDOM_MAC/$($RANPWD -m)/" /etc/network/interfaces
|
||||
done
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
echo "$NAME: Setting random MAC addresses"
|
||||
do_start
|
||||
;;
|
||||
stop)
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $SCRIPTNAME {start|stop}" >&2
|
||||
exit 3
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0
|
||||
|
30
meta-sys940x/recipes-bsp/genmac/genmac.bb
Normal file
30
meta-sys940x/recipes-bsp/genmac/genmac.bb
Normal file
|
@ -0,0 +1,30 @@
|
|||
SUMMARY = "Provide a basic init script to generate a random MAC"
|
||||
DESCRIPTION = "Set the MAC from the config file."
|
||||
SECTION = "base"
|
||||
LICENSE = "MIT"
|
||||
LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=3f40d7994397109285ec7b81fdeb3b58"
|
||||
|
||||
PR = "r0"
|
||||
|
||||
inherit update-rc.d
|
||||
|
||||
RDEPENDS_${PN} = "ranpwd"
|
||||
|
||||
SRC_URI = "file://genmac"
|
||||
|
||||
INITSCRIPT_NAME = "genmac"
|
||||
# Run as early as possible to ensure we are before the networking scripts
|
||||
INITSCRIPT_PARAMS = "start 39 S ."
|
||||
|
||||
do_install() {
|
||||
install -d ${D}${sysconfdir} \
|
||||
${D}${sysconfdir}/init.d
|
||||
install -m 0755 ${WORKDIR}/${INITSCRIPT_NAME} ${D}${sysconfdir}/init.d
|
||||
cat ${WORKDIR}/${INITSCRIPT_NAME} | \
|
||||
sed -e 's,/etc,${sysconfdir},g' \
|
||||
-e 's,/usr/sbin,${sbindir},g' \
|
||||
-e 's,/var,${localstatedir},g' \
|
||||
-e 's,/usr/bin,${bindir},g' \
|
||||
-e 's,/usr,${prefix},g' > ${D}${sysconfdir}/init.d/${INITSCRIPT_NAME}
|
||||
chmod 755 ${D}${sysconfdir}/init.d/${INITSCRIPT_NAME}
|
||||
}
|
Loading…
Reference in New Issue
Block a user