summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am4
-rwxr-xr-xscripts/add_bootfile_eth_hwid30
-rwxr-xr-xscripts/mod_bootfile_eth_hwid37
-rwxr-xr-xscripts/rl-system.init123
-rw-r--r--test_bootfile44
5 files changed, 141 insertions, 97 deletions
diff --git a/Makefile.am b/Makefile.am
index b3db5d18..f893bf13 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -23,6 +23,10 @@ sbin_SCRIPTS += scripts/keepalived/vyatta-keepalived.pl
sbin_SCRIPTS += scripts/keepalived/vyatta-vrrp-state.pl
sbin_SCRIPTS += scripts/keepalived/vyatta-show-vrrp.pl
sbin_SCRIPTS += scripts/telnetd.init
+sbin_SCRIPTS += scripts/add_bootfile_eth_hwid
+sbin_SCRIPTS += scripts/mod_bootfile_eth_hwid
+
+noinst_DATA = test_bootfile
share_perl5_DATA = scripts/keepalived/VyattaKeepalived.pm
diff --git a/scripts/add_bootfile_eth_hwid b/scripts/add_bootfile_eth_hwid
new file mode 100755
index 00000000..2a9cc69c
--- /dev/null
+++ b/scripts/add_bootfile_eth_hwid
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+# add ethnet interface sub-block to configure file
+
+shopt -s extglob
+
+if [[ "$*" == *--help* ]] ; then
+ echo ${0##*/} [test_]FILE INTERFACE HWID
+ exit 0
+fi
+
+if [[ "$1" == test_* ]] ; then
+ origfile=$1
+ bootfile=/tmp/${1##*/}_$$
+ cp $origfile $bootfile
+ trap "diff -c $origfile $bootfile; rm -f $bootfile; exit 0" $?
+else
+ origfile=
+ bootfile=$1
+fi
+eth=$2
+hwid=$3
+
+sed -i '/^interfaces {$/,/^}$/ {
+ /^}$/i\
+ ethernet '"$eth"' {\
+ hw-id: '"$hwid"'\
+ link-detect\
+ }
+ }' $bootfile
diff --git a/scripts/mod_bootfile_eth_hwid b/scripts/mod_bootfile_eth_hwid
new file mode 100755
index 00000000..b913d121
--- /dev/null
+++ b/scripts/mod_bootfile_eth_hwid
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+# modify interface sub-block
+
+shopt -s extglob
+
+if [[ "$*" == *--help* ]] ; then
+ echo ${0##*/} [test_]FILE INTERFACE HWID
+ exit 0
+fi
+
+if [[ "$1" == test_* ]] ; then
+ origfile=$1
+ bootfile=/tmp/${1##*/}_$$
+ cp $origfile $bootfile
+ trap "diff -c $origfile $bootfile; rm -f $bootfile; exit 0" $?
+else
+ origfile=
+ bootfile=$1
+fi
+eth=$2
+hwid=$3
+
+sed -i '/^interfaces {$/,/^}$/ {
+ /^ ethernet '"$eth"' {$/ {
+ :join
+ /\n }$/ {
+ /hw-id: / s/\(hw-id:\) [0-9a-fA-F:]\+/\1 '"$hwid"'/
+ /hw-id: /! s/}$/ hw-id: '"$hwid"'\n }/
+ /link-detect/! s/}$/ link-detect\n }/
+ b
+ }
+ N
+ b join
+ }
+}' $bootfile
+
diff --git a/scripts/rl-system.init b/scripts/rl-system.init
index 1039ac6a..dbcc1526 100755
--- a/scripts/rl-system.init
+++ b/scripts/rl-system.init
@@ -44,10 +44,9 @@ INIT_PID=$$
## BOOTFILE is provided by ofr.init
: ${BOOTFILE:=$prefix/etc/config/config.boot}
-declare -a cfg_eth_hwid
-declare -a sys_eth_mac=( `cat /sys/class/net/eth*/address` )
+shopt -s extglob nullglob
-# load hwid array from config file as follows
+# load cfg_eth_hwid array from config file as follows
# interface {
# ...
# ethernet eth# {
@@ -57,15 +56,13 @@ declare -a sys_eth_mac=( `cat /sys/class/net/eth*/address` )
# }
# }
#
-# cfg_eth_hwid[#]=xx:xx:xx:xx:xx:xx
+# cfg_eth_hwid=( "eth#=xx:xx:xx:xx:xx:xx" ... )
-load_cfg_eth_hwid ()
-{
- eval $( sed -n '
+declare -a cfg_net_hwid=( $( sed -ne '
/^interfaces {/,/^}/ {
/^ *ethernet eth[0-9]* {/,/^ $/ {
/^ *ethernet/ {
- s/.* eth\([0-9]\+\) {$/cfg_eth_hwid[\1]=/
+ s/.* eth\([0-9]\+\) {$/ eth\1=/
# hold interface name
h
}
@@ -81,86 +78,11 @@ load_cfg_eth_hwid ()
s/\n//p
}
}
- }' $BOOTFILE )
-}
-
-have_cfg_eth_hwid ()
-{
- local mac=$1
-
- for hwid in ${cfg_eth_hwid[@]} ; do
- [ $hwid == $mac ] && return 0
- done
- false
-}
-
-have_sys_eth_mac ()
-{
- local hwid=$1
-
- for mac in ${sys_eth_mac[@]} ; do
- [ $hwid == $mac ] && return 0
- done
- false
-}
-
-# update cfg table with results from system mac detection
-# first remove cfg itfs that are no longer in sys table
-# if sys mac is already in cfg table, use cfg itf assignment;
-# if sys mac isnot in cfg table but given index has hwid of
-# another sys itf, add to cfg table in first available slot
-# otherwise, [re-]assign cfg eth hwid with sys mac
-
-update_cfg_eth_hwid ()
-{
- local -i i
-
- for i in ${!cfg_eth_hwid[@]} ; do
- if ! have_sys_eth_mac ${cfg_eth_hwid[$i]} ; then
- unset cfg_eth_hwid[$i]
- fi
- done
- for i in ${!sys_eth_mac[@]} ; do
- if ! have_cfg_eth_hwid ${sys_eth_mac[$i]} ; then
- if [ -n "${cfg_eth_hwid[$i]}" ] ; then
- # cfg[#] has mac of another sys itf;
- # so, add another cfg itf for this mac
- # to the first available slot
- for (( j=0 ; true ; j++ )) ; do
- if [ -z "${cfg_eth_hwid[$j]}" ] ; then
- cfg_eth_hwid[$j]=${sys_eth_mac[$i]}
- break 1
- fi
- done
- else
- cfg_eth_hwid[$i]=${sys_eth_mac[$i]}
- fi
- fi
- done
-}
-
-mod_bootfile_eth_hwid ()
-{
- local eth=$1 hwid=$2
-
- sed -i '/^interfaces {$/,/^}$/ {
- /^ ethernet '"$eth"' {$/ {
- :join
- /\n }$/ {
- /hw-id: / s/\(hw-id:\) [0-9a-fA-F:]\+/\1 '"$hwid"'/
- /hw-id: /! s/}$/ hw-id: '"$hwid"'\n }/
- /link-detect/! s/}$/ link-detect\n }/
- q 0
- }
- N
- b join
- }
- }' $BOOTFILE
-}
+ }' $BOOTFILE ))
add_bootfile_eth_hwid ()
{
- local eth=$1 hwid=$2
+ local bootfile=$1 eth=$2 hwid=$3
sed -i '/^interfaces {$/,/^}$/ {
/^}$/i\
@@ -168,18 +90,29 @@ add_bootfile_eth_hwid ()
hw-id: '"$hwid"'\
link-detect\
}
- }' $BOOTFILE
+ }' $bootfile
}
update_bootfile_eths ()
{
- local -i i
-
- for i in ${!cfg_eth_hwid[@]} ; do
- if grep -q "ethernet eth$i {" $BOOTFILE ; then
- mod_bootfile_eth_hwid eth$i ${cfg_eth_hwid[$i]}
- else
- add_bootfile_eth_hwid eth$i ${cfg_eth_hwid[$i]}
+ for address_file in /sys/class/net/eth*/address ; do
+ eth_path=${address_file%/address}
+ eth=${eth_path##*/}
+ address=`cat $address_file`
+ match=
+ for name_hwid in ${cfg_net_hwid[@]} ; do
+ name=${name_hwid%=*}
+ hwid=${name_hwid#*=}
+ if [ $eth == "$name" ] ; then
+ ${vyatta_sbindir}/mod_bootfile_eth_hwid $BOOTFILE $eth $address
+ match=$name_hwid
+ elif [ "$address" == "$hwid" ] ; then
+ log_failure_msg "kernel $eth != config $name for $hwid"
+ return 1
+ fi
+ done
+ if [ -z "$match" ] ; then
+ ${vyatta_sbindir}/add_bootfile_eth_hwid $BOOTFILE $eth $address
fi
done
}
@@ -269,10 +202,6 @@ start () {
log_failure_msg "can\'t reset config files"
set_reboot_on_panic || \
log_failure_msg "can\'t set reboot on panic"
- load_cfg_eth_hwid || \
- log_failure_msg "can\'t load interface hwids"
- update_cfg_eth_hwid || \
- log_failure_msg "can\'t resolve interface hwids"
update_bootfile_eths || \
log_failure_msg "can\'t update config interfaces"
add_new_serial_if || \
diff --git a/test_bootfile b/test_bootfile
new file mode 100644
index 00000000..df024b69
--- /dev/null
+++ b/test_bootfile
@@ -0,0 +1,44 @@
+system {
+ ntp-server "69.59.150.135"
+ login {
+ user root {
+ authentication {
+ encrypted-password: "$1$$Ht7gBYnxI1xCdO/JOnodh."
+ }
+ }
+ user vyatta {
+ authentication {
+ encrypted-password: "$1$$Ht7gBYnxI1xCdO/JOnodh."
+ }
+ }
+ }
+ package {
+ repository community {
+ component: "main"
+ url: "http://archive.vyatta.com/vyatta"
+ }
+ }
+}
+
+interfaces {
+ loopback lo {
+ }
+ ethernet eth0 {
+ hw-id: 52:54:00:12:34:56
+ link-detect
+ }
+ ethernet eth1 {
+ link-detect
+ }
+ ethernet eth2 {
+ hw-id: 52:54:00:12:34:54
+ }
+ ethernet eth3 {
+ address: 192.168.1.1
+ }
+ ethernet eth4 {
+ }
+}
+
+/* Warning: Do not remove the following line. */
+/* === vyatta-config-version: "cluster@1:dhcp-relay@1:dhcp-server@1:firewall@1:nat@2:serial@1:webgui@1" === */