diff options
Diffstat (limited to 'recipes-core/net-persistent-mac')
4 files changed, 67 insertions, 0 deletions
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..17111c0 --- /dev/null +++ b/recipes-core/net-persistent-mac/net-persistent-mac.bb | |||
@@ -0,0 +1,23 @@ | |||
1 | SUMMARY = "Network device MAC persistency" | ||
2 | DESCRIPTION = "Provides support to store/restore the MAC of a specific network device" | ||
3 | SECTION = "base" | ||
4 | LICENSE = "MIT" | ||
5 | LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" | ||
6 | |||
7 | inherit update-rc.d | ||
8 | |||
9 | INITSCRIPT_NAME = "net-persistent-mac" | ||
10 | INITSCRIPT_PARAMS = "start 39 S ." | ||
11 | |||
12 | SRC_URI = "file://init \ | ||
13 | file://default" | ||
14 | |||
15 | do_install () { | ||
16 | install -d ${D}${sysconfdir}/init.d | ||
17 | install -m 0755 ${WORKDIR}/init ${D}${sysconfdir}/init.d/${PN} | ||
18 | |||
19 | install -d ${D}${sysconfdir}/default | ||
20 | install -m 0644 ${WORKDIR}/default ${D}${sysconfdir}/default/${PN} | ||
21 | } | ||
22 | |||
23 | 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/imx233-olinuxino-maxi/default b/recipes-core/net-persistent-mac/net-persistent-mac/imx233-olinuxino-maxi/default new file mode 100644 index 0000000..fe4a054 --- /dev/null +++ b/recipes-core/net-persistent-mac/net-persistent-mac/imx233-olinuxino-maxi/default | |||
@@ -0,0 +1 @@ | |||
INTERFACES="usb0" | |||
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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | ### BEGIN INIT INFO | ||
4 | # Provides: net-persistent-mac | ||
5 | # Required-Start: $local_fs | ||
6 | # Required-Stop: | ||
7 | # Default-Start: S | ||
8 | # Default-Stop: | ||
9 | # X-Start-Before: networking | ||
10 | # Short-Description: restore MAC during boot process | ||
11 | ### END INIT INFO | ||
12 | |||
13 | set -e | ||
14 | |||
15 | [ -f /etc/default/net-persistent-mac ] && . /etc/default/net-persistent-mac | ||
16 | |||
17 | MAC_DIR="/var/lib/net-persistent-mac" | ||
18 | |||
19 | for if in $INTERFACES; do | ||
20 | mkdir -p "$MAC_DIR" | ||
21 | IF_FILE="$MAC_DIR/$if.mac" | ||
22 | IF_MAC="/sys/class/net/$if/address" | ||
23 | |||
24 | # Store MAC for reuse | ||
25 | if [ ! -r "$IF_FILE" ]; then | ||
26 | if [ -e "$IF_MAC" ]; then | ||
27 | echo "Storing MAC for $if for future use." > /dev/stderr | ||
28 | cat "$IF_MAC" > "$IF_FILE" | ||
29 | else | ||
30 | echo "Failed to read MAC for $if; skiping device." | ||
31 | fi | ||
32 | fi | ||
33 | |||
34 | if [ -r "$IF_FILE" ]; then | ||
35 | # Restore MAC setting | ||
36 | WANTED_MAC=`cat $IF_FILE` | ||
37 | if [ "$WANTED_MAC" != "`cat $IF_MAC`" ]; then | ||
38 | echo "Setting MAC of $if to $WANTED_MAC." | ||
39 | ifconfig $if hw ether "$WANTED_MAC" | ||
40 | fi | ||
41 | fi | ||
42 | done | ||