Commit 493fe69e authored by Jean-Claude BAU's avatar Jean-Claude BAU

New Startup behavior related to the DHCP service availability

After a general cut in the electrical power supply, the switch can restart before than other generic systems (routeurs, serveurs, DHCP & NTP services,...).
It results that the switch might be not well configured if these services cannot be reached and especially the DHCP service.

So, a new behavior has been introduced to wait for the availability of the DHCP service (if configured) to get the source of the dot-config file and to setup the management port.
parents ea7f0af8 75c6b639
...@@ -45,6 +45,7 @@ config DOTCONF_SOURCE_REMOTE ...@@ -45,6 +45,7 @@ config DOTCONF_SOURCE_REMOTE
config DOTCONF_SOURCE_FORCE_DHCP config DOTCONF_SOURCE_FORCE_DHCP
bool "Force to get the URL to a dot-config via DHCP" bool "Force to get the URL to a dot-config via DHCP"
depends on ETH0_DHCP
help help
Retrieve a URL to the dot-config via DHCP at boot. Retrieve a URL to the dot-config via DHCP at boot.
The URL can be configured in the "filename" configuration field of The URL can be configured in the "filename" configuration field of
...@@ -1152,7 +1153,7 @@ config FAN_HYSTERESIS ...@@ -1152,7 +1153,7 @@ config FAN_HYSTERESIS
be used during development to reduce noise generated by a switch. be used during development to reduce noise generated by a switch.
Don't use in production as this may affect the synchronization Don't use in production as this may affect the synchronization
performance. performance.
config FAN_HYSTERESIS_T_DISABLE config FAN_HYSTERESIS_T_DISABLE
int "Disable fans temperature" int "Disable fans temperature"
default 60 default 60
......
...@@ -203,6 +203,7 @@ static int libwr_cfg_read_kconfig(struct kc **all_configs, ...@@ -203,6 +203,7 @@ static int libwr_cfg_read_kconfig(struct kc **all_configs,
struct kc *kc; struct kc *kc;
int ret = 0; int ret = 0;
int len; int len;
int helpIndentation=-1; // Not in help
/* Prevent infinite recursion */ /* Prevent infinite recursion */
if (depth_level >= READ_KCONFIG_MAX_DEPTH) { if (depth_level >= READ_KCONFIG_MAX_DEPTH) {
...@@ -227,10 +228,34 @@ static int libwr_cfg_read_kconfig(struct kc **all_configs, ...@@ -227,10 +228,34 @@ static int libwr_cfg_read_kconfig(struct kc **all_configs,
return -1; return -1;
while (fgets(s, sizeof(s), f)) { while (fgets(s, sizeof(s), f)) {
char *ss=s; char *ss=s;
int indentation=0;
/* Remove leading spaces */ /* The indentation must be measured to make the difference between
while ( *ss==' ' || *ss=='\t') * a key word or a text in help section
*/
/* Remove leading spaces and measure indentation */
while ( *ss==' ' || *ss=='\t') {
indentation++;
ss++; ss++;
}
if (helpIndentation==-1 ) {
// Not in help section
if (strncmp(ss,"help",4)==0 || strncmp(ss,"---help---",10)==0 ) {
// Enter in help section
helpIndentation=indentation;
continue;
}
} else {
// In help section
if ( indentation>=helpIndentation )
continue; // Still in help section
helpIndentation=-1; // Exiting help section
}
if ( *ss==0 || *ss=='\n' || *ss=='#' )
continue;
if (sscanf(ss, "source %s", name) == 1) { if (sscanf(ss, "source %s", name) == 1) {
/* Recursive call for sourced files */ /* Recursive call for sourced files */
......
...@@ -10,12 +10,28 @@ dotconfig=/wr/etc/dot-config ...@@ -10,12 +10,28 @@ dotconfig=/wr/etc/dot-config
tmpconfig=/tmp/dot-config tmpconfig=/tmp/dot-config
tmpdir=/tmp tmpdir=/tmp
log_output=/dev/kmsg log_output=/dev/kmsg
management_port=eth0
me=`basename "$0"`
set -o pipefail # The return value of a pipeline is the status of set -o pipefail # The return value of a pipeline is the status of
# the last command to exit with a non-zero status, # the last command to exit with a non-zero status,
# or zero if no command exited with a non-zero status # or zero if no command exited with a non-zero status
# Needed for return value ($?) of xxx in "xxx | tee yyy" # Needed for return value ($?) of xxx in "xxx | tee yyy"
#
# This function is looping forever until DHCP is reachable
#
wait_dhcp_forever()
{
while : ; do
udhcpc -n -q -i $management_port
if [ "$?" -eq "0" ]; then
break
fi
echo "$me: waiting DHCP service...."
sleep 5
done
}
rm -f "$tmpdir"/dot-config_source rm -f "$tmpdir"/dot-config_source
...@@ -58,40 +74,44 @@ if [ "$CONFIG_DOTCONF_SOURCE_REMOTE" = "y" ] || [ "$CONFIG_DOTCONF_SOURCE_TRY_DH ...@@ -58,40 +74,44 @@ if [ "$CONFIG_DOTCONF_SOURCE_REMOTE" = "y" ] || [ "$CONFIG_DOTCONF_SOURCE_TRY_DH
# get URL via DHCP # get URL via DHCP
if [ "$CONFIG_DOTCONF_SOURCE_TRY_DHCP" = "y" ] \ if [ "$CONFIG_DOTCONF_SOURCE_TRY_DHCP" = "y" ] \
|| [ "$CONFIG_DOTCONF_SOURCE_FORCE_DHCP" = "y" ]; then || [ "$CONFIG_DOTCONF_SOURCE_FORCE_DHCP" = "y" ]; then
if [ "$CONFIG_DOTCONF_SOURCE_TRY_DHCP" = "y" ]; then if [ "$CONFIG_DOTCONF_SOURCE_TRY_DHCP" = "y" ]; then
echo "try_dhcp" > "$tmpdir"/dot-config_source echo "try_dhcp" > "$tmpdir"/dot-config_source
fi fi
if [ "$CONFIG_DOTCONF_SOURCE_FORCE_DHCP" = "y" ]; then if [ "$CONFIG_DOTCONF_SOURCE_FORCE_DHCP" = "y" ]; then
echo "force_dhcp" > "$tmpdir"/dot-config_source echo "force_dhcp" > "$tmpdir"/dot-config_source
fi fi
# up eth0 to allow dhcp requests # up management port to allow dhcp requests
ifconfig eth0 up ifconfig $management_port up
# let udhcpc run /wr/bin/dhcp_get_filename.sh script to get "filename" if [ "$CONFIG_DOTCONF_SOURCE_FORCE_DHCP" = "y" ] && [ "$CONFIG_ETH0_DHCP" = "y" ]; then
# from DHCP (which contain url with dot-config). # Wait DHCP forever only if DHCP is also forced on management port
/sbin/udhcpc -i eth0 -s /wr/bin/dhcp_get_filename.sh -O bootfile -o \ wait_dhcp_forever
-n -q -f -t 5 &>/dev/null fi
if [ -f "$tmpdir"/dot-config_source_url ]; then # let udhcpc run /wr/bin/dhcp_get_filename.sh script to get "filename"
# replace CONFIG_DOTCONF_URL with one gotten from dhcp # from DHCP (which contain url with dot-config).
CONFIG_DOTCONF_URL=`cat "$tmpdir"/dot-config_source_url` /sbin/udhcpc -i $management_port -s /wr/bin/dhcp_get_filename.sh -O bootfile -o \
echo "Got dot-config's URL ("$CONFIG_DOTCONF_URL") via DHCP" | tee $log_output >& 2 -n -q -f -t 5 &>/dev/null
else if [ -f "$tmpdir"/dot-config_source_url ]; then
echo "dhcp_error" > "$tmpdir"/dot-config_status # replace CONFIG_DOTCONF_URL with one gotten from dhcp
echo "Unable to get dot-config's URL via DHCP, using old dot-config" | tee $log_output >& 2 CONFIG_DOTCONF_URL=`cat "$tmpdir"/dot-config_source_url`
# apply old dot-config echo "Got dot-config's URL ("$CONFIG_DOTCONF_URL") via DHCP" | tee $log_output >& 2
/wr/bin/apply_dot-config else
exit echo "dhcp_error" > "$tmpdir"/dot-config_status
fi echo "Unable to get dot-config's URL via DHCP, using old dot-config" | tee $log_output >& 2
# apply old dot-config
/wr/bin/apply_dot-config
exit
fi
fi fi
# replace IPADDR and MACADDR, to have a device-specific name # replace IPADDR and MACADDR, to have a device-specific name
macaddr=$(cat /sys/class/net/eth0/address) macaddr=$(cat /sys/class/net/${management_port}/address)
ipaddr=$(ifconfig eth0 | grep inet | cut -d: -f 2 | cut '-d ' -f 1) ipaddr=$(ifconfig ${management_port} | grep inet | cut -d: -f 2 | cut '-d ' -f 1)
if [ -z "$ipaddr" ]; then if [ -z "$ipaddr" ]; then
# if no IP address available from barebox try to get IP from old dot-config # if no IP address available from barebox try to get IP from old dot-config
# /etc/init.d/network will run later again # /etc/init.d/network will run later again
/etc/init.d/network /etc/init.d/network
ipaddr=$(ifconfig eth0 | grep inet | cut -d: -f 2 | cut '-d ' -f 1) ipaddr=$(ifconfig ${management_port} | grep inet | cut -d: -f 2 | cut '-d ' -f 1)
fi fi
host_name=`hostname` host_name=`hostname`
URL=$(echo $CONFIG_DOTCONF_URL | \ URL=$(echo $CONFIG_DOTCONF_URL | \
......
...@@ -6,12 +6,29 @@ ...@@ -6,12 +6,29 @@
dotconfig=/wr/etc/dot-config dotconfig=/wr/etc/dot-config
int_file=/etc/network/interfaces int_file=/etc/network/interfaces
log_output=/dev/kmsg log_output=/dev/kmsg
management_port=eth0
me=`basename "$0"`
#
# This function is looping forever until DHCP is reachable
#
wait_dhcp_forever()
{
while : ; do
udhcpc -n -q -i $management_port
if [ "$?" -eq "0" ]; then
break
fi
echo "$me: waiting DHCP service ...."
sleep 5
done
}
# no matter what we do keep lo up # no matter what we do keep lo up
ifup lo &> /dev/null ifup lo &> /dev/null
if grep -q '/ nfs' /proc/mounts; then if grep -q '/ nfs' /proc/mounts; then
echo "Running via NFS: leaving eth0 config alone" | tee $log_output echo "Running via NFS: leaving $management_port config alone" | tee $log_output
exit 0 exit 0
fi fi
...@@ -22,13 +39,13 @@ fi ...@@ -22,13 +39,13 @@ fi
# kill all previous instances of udhcpc # kill all previous instances of udhcpc
killall udhcpc &> /dev/null killall udhcpc &> /dev/null
# put eth0 down in case it was up before, but it is not so simple # put management port down in case it was up before, but it is not so simple
# ifdown to change /var/run/ifstate # ifdown to change /var/run/ifstate
# flush to aviod ifup complains # flush to aviod ifup complains
# down to take link down (after reboot ifdown does not put link down) # down to take link down (after reboot ifdown does not put link down)
ifdown eth0 &> /dev/null ifdown $management_port &> /dev/null
ip addr flush dev eth0 ip addr flush dev $management_port
ip link set eth0 down ip link set $management_port down
# wait after down to make udhcpc to work properly # wait after down to make udhcpc to work properly
sleep 1 sleep 1
...@@ -40,7 +57,7 @@ if [ "$CONFIG_ETH0_STATIC" = "y" ] || [ "$CONFIG_ETH0_DHCP_ONCE" = "y" ]; then ...@@ -40,7 +57,7 @@ if [ "$CONFIG_ETH0_STATIC" = "y" ] || [ "$CONFIG_ETH0_DHCP_ONCE" = "y" ]; then
echo "iface lo inet loopback" >> $int_file echo "iface lo inet loopback" >> $int_file
echo "" >> $int_file echo "" >> $int_file
echo "iface eth0 inet static" >> $int_file echo "iface $management_port inet static" >> $int_file
if [ "$CONFIG_ETH0_IP" ]; then if [ "$CONFIG_ETH0_IP" ]; then
echo " address $CONFIG_ETH0_IP" >> $int_file echo " address $CONFIG_ETH0_IP" >> $int_file
fi fi
...@@ -61,8 +78,8 @@ fi ...@@ -61,8 +78,8 @@ fi
if [ "$CONFIG_HOSTNAME_STATIC" = "y" ]; then if [ "$CONFIG_HOSTNAME_STATIC" = "y" ]; then
if [ -z "$CONFIG_HOSTNAME_STRING" ]; then if [ -z "$CONFIG_HOSTNAME_STRING" ]; then
echo "empty CONFIG_HOSTNAME_STRING! use wrs" | tee $log_output echo "empty CONFIG_HOSTNAME_STRING! use wrs" | tee $log_output
CONFIG_HOSTNAME_STRING="wrs" CONFIG_HOSTNAME_STRING="wrs"
fi fi
/bin/hostname "$CONFIG_HOSTNAME_STRING" /bin/hostname "$CONFIG_HOSTNAME_STRING"
echo "$CONFIG_HOSTNAME_STRING" | tee $log_output > /etc/hostname echo "$CONFIG_HOSTNAME_STRING" | tee $log_output > /etc/hostname
...@@ -73,19 +90,19 @@ fi ...@@ -73,19 +90,19 @@ fi
if [ "$CONFIG_ETH0_DHCP_ONCE" = "y" ]; then if [ "$CONFIG_ETH0_DHCP_ONCE" = "y" ]; then
echo "Try DHCP to get IP" | tee $log_output echo "Try DHCP to get IP" | tee $log_output
# try dhcp, if fail use static IP # try dhcp, if fail use static IP
udhcpc -i eth0 -n $DHCP_OPT_EXTRA | tee $log_output udhcpc -i $management_port -n $DHCP_OPT_EXTRA | tee $log_output
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to obtain IP address via DHCP, set static IP" | tee $log_output echo "Failed to obtain IP address via DHCP, set static IP" | tee $log_output
CONFIG_ETH0_STATIC="y" CONFIG_ETH0_STATIC="y"
else else
exit exit
fi fi
fi fi
if [ "$CONFIG_ETH0_STATIC" = "y" ]; then if [ "$CONFIG_ETH0_STATIC" = "y" ]; then
# ifup to use static parameters from /etc/netwrok/interfaces # ifup to use static parameters from /etc/netwrok/interfaces
echo "Using static IP" | tee $log_output echo "Using static IP" | tee $log_output
ifup eth0 ifup $management_port
exit exit
fi fi
...@@ -94,4 +111,5 @@ fi ...@@ -94,4 +111,5 @@ fi
echo "Using DHCP to get IP" | tee $log_output echo "Using DHCP to get IP" | tee $log_output
# redirect output from udhcpc into syslog and output about the first lease to # redirect output from udhcpc into syslog and output about the first lease to
# the kernel log (syslog is not started at this point) # the kernel log (syslog is not started at this point)
udhcpc -S -b -i eth0 $DHCP_OPT_EXTRA | tee $log_output wait_dhcp_forever
udhcpc -S -b -i $management_port $DHCP_OPT_EXTRA | tee $log_output
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment