diff --git a/recipes-core/net-persistent-mac/net-persistent-mac.bb b/recipes-core/net-persistent-mac/net-persistent-mac.bb new file mode 100644 index 0000000..0784a01 --- /dev/null +++ b/recipes-core/net-persistent-mac/net-persistent-mac.bb @@ -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}" diff --git a/recipes-core/net-persistent-mac/net-persistent-mac/default b/recipes-core/net-persistent-mac/net-persistent-mac/default new file mode 100644 index 0000000..9086f7b --- /dev/null +++ b/recipes-core/net-persistent-mac/net-persistent-mac/default @@ -0,0 +1 @@ +INTERFACES="" \ No newline at end of file diff --git a/recipes-core/net-persistent-mac/net-persistent-mac/init b/recipes-core/net-persistent-mac/net-persistent-mac/init new file mode 100644 index 0000000..a2e2863 --- /dev/null +++ b/recipes-core/net-persistent-mac/net-persistent-mac/init @@ -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