mirror of
https://github.com/Freescale/meta-freescale-3rdparty.git
synced 2025-07-05 05:15:24 +02:00
net-persistent-mac: allow for network device MAC persistency
Some network devices do not have a fixed MAC address however this is important to allow auto-configuration in a DHCP network. To accomplish it, in a more generic way, we store the MAC and restore it *before* the network services are started thus compatible with netbase and connman configurations. Signed-off-by: Otavio Salvador <otavio@ossystems.com.br> Acked-by: Adrian Alonso <aalonso00@gmail.com>
This commit is contained in:
parent
a5998b4832
commit
99670d8956
23
recipes-core/net-persistent-mac/net-persistent-mac.bb
Normal file
23
recipes-core/net-persistent-mac/net-persistent-mac.bb
Normal file
|
@ -0,0 +1,23 @@
|
|||
SUMMARY = "Network device MAC persistency"
|
||||
DESCRIPTION = "Provides support to store/restore the MAC of a specific network device"
|
||||
SECTION = "base"
|
||||
LICENSE = "MIT"
|
||||
LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=3f40d7994397109285ec7b81fdeb3b58"
|
||||
|
||||
inherit update-rc.d
|
||||
|
||||
INITSCRIPT_NAME = "net-persistent-mac"
|
||||
INITSCRIPT_PARAMS = "start 39 S ."
|
||||
|
||||
SRC_URI = "file://init \
|
||||
file://default"
|
||||
|
||||
do_install () {
|
||||
install -d ${D}${sysconfdir}/init.d
|
||||
install -m 0755 ${WORKDIR}/init ${D}${sysconfdir}/init.d/${PN}
|
||||
|
||||
install -d ${D}${sysconfdir}/default
|
||||
install -m 0644 ${WORKDIR}/default ${D}${sysconfdir}/default/${PN}
|
||||
}
|
||||
|
||||
PACKAGE_ARCH = "${MACHINE_ARCH}"
|
|
@ -0,0 +1 @@
|
|||
INTERFACES=""
|
42
recipes-core/net-persistent-mac/net-persistent-mac/init
Normal file
42
recipes-core/net-persistent-mac/net-persistent-mac/init
Normal file
|
@ -0,0 +1,42 @@
|
|||
#!/bin/sh
|
||||
|
||||
### BEGIN INIT INFO
|
||||
# Provides: net-persistent-mac
|
||||
# Required-Start: $local_fs
|
||||
# Required-Stop:
|
||||
# Default-Start: S
|
||||
# Default-Stop:
|
||||
# X-Start-Before: networking
|
||||
# Short-Description: restore MAC during boot process
|
||||
### END INIT INFO
|
||||
|
||||
set -e
|
||||
|
||||
[ -f /etc/default/net-persistent-mac ] && . /etc/default/net-persistent-mac
|
||||
|
||||
MAC_DIR="/var/lib/net-persistent-mac"
|
||||
|
||||
for if in $INTERFACES; do
|
||||
mkdir -p "$MAC_DIR"
|
||||
IF_FILE="$MAC_DIR/$if.mac"
|
||||
IF_MAC="/sys/class/net/$if/address"
|
||||
|
||||
# Store MAC for reuse
|
||||
if [ ! -r "$IF_FILE" ]; then
|
||||
if [ -e "$IF_MAC" ]; then
|
||||
echo "Storing MAC for $if for future use." > /dev/stderr
|
||||
cat "$IF_MAC" > "$IF_FILE"
|
||||
else
|
||||
echo "Failed to read MAC for $if; skiping device."
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -r "$IF_FILE" ]; then
|
||||
# Restore MAC setting
|
||||
WANTED_MAC=`cat $IF_FILE`
|
||||
if [ "$WANTED_MAC" != "`cat $IF_MAC`" ]; then
|
||||
echo "Setting MAC of $if to $WANTED_MAC."
|
||||
ifconfig $if hw ether "$WANTED_MAC"
|
||||
fi
|
||||
fi
|
||||
done
|
Loading…
Reference in New Issue
Block a user