summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorTom Grennan <tgrennan@io.vyatta.com>2007-12-14 18:15:03 -0800
committerTom Grennan <tgrennan@io.vyatta.com>2007-12-14 18:15:03 -0800
commit8f9c81cd448ece7199aa6f97fc27338839cabfd1 (patch)
treef976569d093ec4ddce2ce59543bf56c6f4cd9af3 /scripts
parentb484ad3193f65a790e6f534902252c98b7217884 (diff)
downloadvyatta-cfg-system-8f9c81cd448ece7199aa6f97fc27338839cabfd1.tar.gz
vyatta-cfg-system-8f9c81cd448ece7199aa6f97fc27338839cabfd1.zip
move config file interface mods to udev handler
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/rl-system.init76
-rw-r--r--scripts/vyatta_net_name58
2 files changed, 41 insertions, 93 deletions
diff --git a/scripts/rl-system.init b/scripts/rl-system.init
index dbcc1526..96f648c1 100755
--- a/scripts/rl-system.init
+++ b/scripts/rl-system.init
@@ -38,85 +38,11 @@ export PATH
. /lib/lsb/init-functions
-IPROUTE2IP=ip
-INIT_PID=$$
-
## BOOTFILE is provided by ofr.init
: ${BOOTFILE:=$prefix/etc/config/config.boot}
shopt -s extglob nullglob
-# load cfg_eth_hwid array from config file as follows
-# interface {
-# ...
-# ethernet eth# {
-# ...
-# hw-id: XX:XX:XX:XX:XX:XX
-# ...
-# }
-# }
-#
-# cfg_eth_hwid=( "eth#=xx:xx:xx:xx:xx:xx" ... )
-
-declare -a cfg_net_hwid=( $( sed -ne '
- /^interfaces {/,/^}/ {
- /^ *ethernet eth[0-9]* {/,/^ $/ {
- /^ *ethernet/ {
- s/.* eth\([0-9]\+\) {$/ eth\1=/
-# hold interface name
- h
- }
- /^.*hw-id:/ {
-# translate field name
- s/.*hw-id: *//
-# tolower hex mac address
- y/ABCDEF/abcdef/
-# exchange hold and pattern space
- x
-# concatenate hold and pattern
- G
- s/\n//p
- }
- }
- }' $BOOTFILE ))
-
-add_bootfile_eth_hwid ()
-{
- local bootfile=$1 eth=$2 hwid=$3
-
- sed -i '/^interfaces {$/,/^}$/ {
- /^}$/i\
- ethernet '"$eth"' {\
- hw-id: '"$hwid"'\
- link-detect\
- }
- }' $bootfile
-}
-
-update_bootfile_eths ()
-{
- 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
-}
-
search_config_if_wan () {
grep "\<serial\>.*\<$1\>" $BOOTFILE >/dev/null
}
@@ -202,8 +128,6 @@ start () {
log_failure_msg "can\'t reset config files"
set_reboot_on_panic || \
log_failure_msg "can\'t set reboot on panic"
- update_bootfile_eths || \
- log_failure_msg "can\'t update config interfaces"
add_new_serial_if || \
log_failure_msg "can\'t add serial interfaces"
proc_flags || \
diff --git a/scripts/vyatta_net_name b/scripts/vyatta_net_name
index 56d90f14..5cc1f4c5 100644
--- a/scripts/vyatta_net_name
+++ b/scripts/vyatta_net_name
@@ -24,6 +24,7 @@
debug=
match=
attr_address=0:0:0:0:0:0
+declare -i ethn=0 last_ethn=0
test -r /etc/default/vyatta && source /etc/default/vyatta
@@ -51,8 +52,16 @@ for arg ; do
done
: ${vyatta_prefix:=/opt/vyatta}
+: ${vyatta_sbindir:=${vyatta_prefix}/sbin}
: ${vyatta_sysconfdir:=${vyatta_prefix}/etc}
: ${BOOTFILE:=${vyatta_sysconfdir:-/opt/vyatta/etc}/config/config.boot}
+: ${DEFAULT_BOOTFILE:=${vyatta_sysconfdir:-/opt/vyatta/etc}/config.boot.default}
+
+if [ ! -f $BOOTFILE ] ; then
+ cp $DEFAULT_BOOTFILE $BOOTFILE
+ chgrp quaggavty $BOOTFILE
+ chmod 660 $BOOTFILE
+fi
shopt -s extglob nullglob
@@ -93,32 +102,47 @@ declare -a cfg_net_hwid=( $( sed -ne '
for name_hwid in ${cfg_net_hwid[@]} ; do
name=${name_hwid%=*}
hwid=${name_hwid#*=}
+ ethn=${name/eth/}
+ [[ $ethn -gt $last_ethn ]] && \
+ last_ethn=$ethn
if [ "$hwid" == "$attr_address" ] ; then
+ # we mod the config file interface sub-clock in case it is missing
+ # "link-detect"
+ ${vyatta_sbindir}/mod_bootfile_eth_hwid $BOOTFILE $name $attr_address
echo $name
exit 0
fi
- [ "$name" == "$kname" ] && match=$name_hwid
+ [ "$name" == "$kname" ] && \
+ match=$name_hwid
done
-# have not found matching hwid in config, see if we can use kernel name
-if [ -n "$kname" ] ; then
- # if interface missing entirely from config
- # or it does not yet have a recorded hwid
- # it is safe to use kernel name
- if [[ -z "$match" || -z "${match#*=}" ]] ; then
- echo $kname
- exit 0
- fi
- # FIXME! need to figure out what to do here...
+[ -z "$kname" ] && \
+ exit 1
+
- # The device mac address isn't yet in the config but the config
- # has another hwid associated with the kernel name. This
- # indicates that the device may have been replaced or a new device
- # installed. Udev may not have scanned all devices yet so we
- # donot know which case.
+# have not found matching hwid in config, see if we can use kernel name
+if [ -z "$match" ] ; then
+ # the kernel interface name isnot in config
+ # so, we might as well use it
+ name=$kname
+ ${vyatta_sbindir}/add_bootfile_eth_hwid $BOOTFILE $name $attr_address
+elif [ -z "${match#*=}" ] ; then
+ # the config has this interface but the sub-block is missing the hwid
+ # so again, we might as well use the kernel name
+ name=$kname
+ ${vyatta_sbindir}/mod_bootfile_eth_hwid $BOOTFILE $name $attr_address
+else
+ # The device mac address is not in the config but the config
+ # has another hwid associated with the device name. This
+ # indicates that the device is either a replacement or new but
+ # detected earlier than the device configured with this name.
+ # Since this is non-deterministic, we make a new name.
+ (( ethn = last_ethn + 1 ))
+ name=eth$ethn
+ ${vyatta_sbindir}/add_bootfile_eth_hwid $BOOTFILE $name $attr_address
fi
-exit 1
+echo $name
# Local Variables:
# mode: shell-script