From 99670d895682d3a7ae23fbb0e9f5a3eb68d1fa33 Mon Sep 17 00:00:00 2001 From: Adrian Alonso Date: Tue, 3 Jul 2012 21:26:06 -0500 Subject: [PATCH] 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 Acked-by: Adrian Alonso --- .../net-persistent-mac/net-persistent-mac.bb | 23 ++++++++++ .../net-persistent-mac/default | 1 + .../net-persistent-mac/init | 42 +++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 recipes-core/net-persistent-mac/net-persistent-mac.bb create mode 100644 recipes-core/net-persistent-mac/net-persistent-mac/default create mode 100644 recipes-core/net-persistent-mac/net-persistent-mac/init 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